blob: ba6cc54d465170de3576f32a8651fce269c659fe [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 Benjamin353577c2017-06-29 15:54:58 -04001158 // excludeFlag is the legacy shim flag to disable the version.
1159 excludeFlag string
1160 hasDTLS bool
1161 // shimTLS and shimDTLS are values the shim uses to refer to these
1162 // versions in TLS and DTLS, respectively.
1163 shimTLS, shimDTLS int
1164}
1165
1166func (vers tlsVersion) shimFlag(protocol protocol) string {
1167 if protocol == dtls {
1168 return strconv.Itoa(vers.shimDTLS)
1169 }
1170 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001171}
1172
1173var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001174 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1175 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1176 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1177 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1178 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001179}
1180
David Benjaminaa012042016-12-10 13:33:05 -05001181type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001182 name string
1183 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001184}
1185
1186var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001187 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001188 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001189 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001190 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001191 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001192 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001193 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001194 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1195 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001196 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1197 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001198 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001199 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001200 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001201 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001202 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001203 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001204 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001205 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001206 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001207 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001208 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1209 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001210 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1211 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001212 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001213 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1214 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1215 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001216 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001217}
1218
David Benjamin8b8c0062014-11-23 02:47:52 -05001219func hasComponent(suiteName, component string) bool {
1220 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1221}
1222
David Benjaminf7768e42014-08-31 02:06:47 -04001223func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001224 return hasComponent(suiteName, "GCM") ||
1225 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001226 hasComponent(suiteName, "SHA384") ||
1227 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001228}
1229
Nick Harper1fd39d82016-06-14 18:14:35 -07001230func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001231 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001232}
1233
David Benjamin8b8c0062014-11-23 02:47:52 -05001234func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001235 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001236}
1237
Adam Langleya7997f12015-05-14 17:38:50 -07001238func bigFromHex(hex string) *big.Int {
1239 ret, ok := new(big.Int).SetString(hex, 16)
1240 if !ok {
1241 panic("failed to parse hex number 0x" + hex)
1242 }
1243 return ret
1244}
1245
Adam Langley7c803a62015-06-15 15:35:05 -07001246func addBasicTests() {
1247 basicTests := []testCase{
1248 {
Adam Langley7c803a62015-06-15 15:35:05 -07001249 name: "NoFallbackSCSV",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 FailIfNotFallbackSCSV: true,
1253 },
1254 },
1255 shouldFail: true,
1256 expectedLocalError: "no fallback SCSV found",
1257 },
1258 {
1259 name: "SendFallbackSCSV",
1260 config: Config{
1261 Bugs: ProtocolBugs{
1262 FailIfNotFallbackSCSV: true,
1263 },
1264 },
1265 flags: []string{"-fallback-scsv"},
1266 },
1267 {
1268 name: "ClientCertificateTypes",
1269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001270 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001271 ClientAuth: RequestClientCert,
1272 ClientCertificateTypes: []byte{
1273 CertTypeDSSSign,
1274 CertTypeRSASign,
1275 CertTypeECDSASign,
1276 },
1277 },
1278 flags: []string{
1279 "-expect-certificate-types",
1280 base64.StdEncoding.EncodeToString([]byte{
1281 CertTypeDSSSign,
1282 CertTypeRSASign,
1283 CertTypeECDSASign,
1284 }),
1285 },
1286 },
1287 {
Adam Langley7c803a62015-06-15 15:35:05 -07001288 name: "UnauthenticatedECDH",
1289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001291 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1292 Bugs: ProtocolBugs{
1293 UnauthenticatedECDH: true,
1294 },
1295 },
1296 shouldFail: true,
1297 expectedError: ":UNEXPECTED_MESSAGE:",
1298 },
1299 {
1300 name: "SkipCertificateStatus",
1301 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001302 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1304 Bugs: ProtocolBugs{
1305 SkipCertificateStatus: true,
1306 },
1307 },
1308 flags: []string{
1309 "-enable-ocsp-stapling",
1310 },
1311 },
1312 {
1313 name: "SkipServerKeyExchange",
1314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001315 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001316 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1317 Bugs: ProtocolBugs{
1318 SkipServerKeyExchange: true,
1319 },
1320 },
1321 shouldFail: true,
1322 expectedError: ":UNEXPECTED_MESSAGE:",
1323 },
1324 {
Adam Langley7c803a62015-06-15 15:35:05 -07001325 testType: serverTest,
1326 name: "Alert",
1327 config: Config{
1328 Bugs: ProtocolBugs{
1329 SendSpuriousAlert: alertRecordOverflow,
1330 },
1331 },
1332 shouldFail: true,
1333 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1334 },
1335 {
1336 protocol: dtls,
1337 testType: serverTest,
1338 name: "Alert-DTLS",
1339 config: Config{
1340 Bugs: ProtocolBugs{
1341 SendSpuriousAlert: alertRecordOverflow,
1342 },
1343 },
1344 shouldFail: true,
1345 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1346 },
1347 {
1348 testType: serverTest,
1349 name: "FragmentAlert",
1350 config: Config{
1351 Bugs: ProtocolBugs{
1352 FragmentAlert: true,
1353 SendSpuriousAlert: alertRecordOverflow,
1354 },
1355 },
1356 shouldFail: true,
1357 expectedError: ":BAD_ALERT:",
1358 },
1359 {
1360 protocol: dtls,
1361 testType: serverTest,
1362 name: "FragmentAlert-DTLS",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 FragmentAlert: true,
1366 SendSpuriousAlert: alertRecordOverflow,
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":BAD_ALERT:",
1371 },
1372 {
1373 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001374 name: "DoubleAlert",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 DoubleAlert: true,
1378 SendSpuriousAlert: alertRecordOverflow,
1379 },
1380 },
1381 shouldFail: true,
1382 expectedError: ":BAD_ALERT:",
1383 },
1384 {
1385 protocol: dtls,
1386 testType: serverTest,
1387 name: "DoubleAlert-DTLS",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 DoubleAlert: true,
1391 SendSpuriousAlert: alertRecordOverflow,
1392 },
1393 },
1394 shouldFail: true,
1395 expectedError: ":BAD_ALERT:",
1396 },
1397 {
Adam Langley7c803a62015-06-15 15:35:05 -07001398 name: "SkipNewSessionTicket",
1399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001400 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001401 Bugs: ProtocolBugs{
1402 SkipNewSessionTicket: true,
1403 },
1404 },
1405 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001406 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001407 },
1408 {
1409 testType: serverTest,
1410 name: "FallbackSCSV",
1411 config: Config{
1412 MaxVersion: VersionTLS11,
1413 Bugs: ProtocolBugs{
1414 SendFallbackSCSV: true,
1415 },
1416 },
David Benjamin56cadc32016-12-16 19:54:11 -05001417 shouldFail: true,
1418 expectedError: ":INAPPROPRIATE_FALLBACK:",
1419 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001420 },
1421 {
1422 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001423 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001424 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001425 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001426 Bugs: ProtocolBugs{
1427 SendFallbackSCSV: true,
1428 },
1429 },
1430 },
1431 {
1432 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001433 name: "FallbackSCSV-VersionMatch-TLS12",
1434 config: Config{
1435 MaxVersion: VersionTLS12,
1436 Bugs: ProtocolBugs{
1437 SendFallbackSCSV: true,
1438 },
1439 },
1440 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1441 },
1442 {
1443 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 name: "FragmentedClientVersion",
1445 config: Config{
1446 Bugs: ProtocolBugs{
1447 MaxHandshakeRecordLength: 1,
1448 FragmentClientVersion: true,
1449 },
1450 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001451 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001452 },
1453 {
Adam Langley7c803a62015-06-15 15:35:05 -07001454 testType: serverTest,
1455 name: "HttpGET",
1456 sendPrefix: "GET / HTTP/1.0\n",
1457 shouldFail: true,
1458 expectedError: ":HTTP_REQUEST:",
1459 },
1460 {
1461 testType: serverTest,
1462 name: "HttpPOST",
1463 sendPrefix: "POST / HTTP/1.0\n",
1464 shouldFail: true,
1465 expectedError: ":HTTP_REQUEST:",
1466 },
1467 {
1468 testType: serverTest,
1469 name: "HttpHEAD",
1470 sendPrefix: "HEAD / HTTP/1.0\n",
1471 shouldFail: true,
1472 expectedError: ":HTTP_REQUEST:",
1473 },
1474 {
1475 testType: serverTest,
1476 name: "HttpPUT",
1477 sendPrefix: "PUT / HTTP/1.0\n",
1478 shouldFail: true,
1479 expectedError: ":HTTP_REQUEST:",
1480 },
1481 {
1482 testType: serverTest,
1483 name: "HttpCONNECT",
1484 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1485 shouldFail: true,
1486 expectedError: ":HTTPS_PROXY_REQUEST:",
1487 },
1488 {
1489 testType: serverTest,
1490 name: "Garbage",
1491 sendPrefix: "blah",
1492 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001493 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001494 },
1495 {
Adam Langley7c803a62015-06-15 15:35:05 -07001496 name: "RSAEphemeralKey",
1497 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001498 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1500 Bugs: ProtocolBugs{
1501 RSAEphemeralKey: true,
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":UNEXPECTED_MESSAGE:",
1506 },
1507 {
1508 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001509 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001510 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001511 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001512 },
1513 {
1514 protocol: dtls,
1515 name: "DisableEverything-DTLS",
1516 flags: []string{"-no-tls12", "-no-tls1"},
1517 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001518 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001519 },
1520 {
Adam Langley7c803a62015-06-15 15:35:05 -07001521 protocol: dtls,
1522 testType: serverTest,
1523 name: "MTU",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 MaxPacketLength: 256,
1527 },
1528 },
1529 flags: []string{"-mtu", "256"},
1530 },
1531 {
1532 protocol: dtls,
1533 testType: serverTest,
1534 name: "MTUExceeded",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 MaxPacketLength: 255,
1538 },
1539 },
1540 flags: []string{"-mtu", "256"},
1541 shouldFail: true,
1542 expectedLocalError: "dtls: exceeded maximum packet length",
1543 },
1544 {
Adam Langley7c803a62015-06-15 15:35:05 -07001545 name: "EmptyCertificateList",
1546 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001547 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001548 Bugs: ProtocolBugs{
1549 EmptyCertificateList: true,
1550 },
1551 },
1552 shouldFail: true,
1553 expectedError: ":DECODE_ERROR:",
1554 },
1555 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001556 name: "EmptyCertificateList-TLS13",
1557 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001558 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001559 Bugs: ProtocolBugs{
1560 EmptyCertificateList: true,
1561 },
1562 },
1563 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001564 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001565 },
1566 {
Adam Langley7c803a62015-06-15 15:35:05 -07001567 name: "TLSFatalBadPackets",
1568 damageFirstWrite: true,
1569 shouldFail: true,
1570 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1571 },
1572 {
1573 protocol: dtls,
1574 name: "DTLSIgnoreBadPackets",
1575 damageFirstWrite: true,
1576 },
1577 {
1578 protocol: dtls,
1579 name: "DTLSIgnoreBadPackets-Async",
1580 damageFirstWrite: true,
1581 flags: []string{"-async"},
1582 },
1583 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001584 name: "AppDataBeforeHandshake",
1585 config: Config{
1586 Bugs: ProtocolBugs{
1587 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1588 },
1589 },
1590 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001591 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001592 },
1593 {
1594 name: "AppDataBeforeHandshake-Empty",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 AppDataBeforeHandshake: []byte{},
1598 },
1599 },
1600 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001601 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001602 },
1603 {
1604 protocol: dtls,
1605 name: "AppDataBeforeHandshake-DTLS",
1606 config: Config{
1607 Bugs: ProtocolBugs{
1608 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1609 },
1610 },
1611 shouldFail: true,
1612 expectedError: ":UNEXPECTED_RECORD:",
1613 },
1614 {
1615 protocol: dtls,
1616 name: "AppDataBeforeHandshake-DTLS-Empty",
1617 config: Config{
1618 Bugs: ProtocolBugs{
1619 AppDataBeforeHandshake: []byte{},
1620 },
1621 },
1622 shouldFail: true,
1623 expectedError: ":UNEXPECTED_RECORD:",
1624 },
1625 {
Adam Langley7c803a62015-06-15 15:35:05 -07001626 name: "AppDataAfterChangeCipherSpec",
1627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001628 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001629 Bugs: ProtocolBugs{
1630 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1631 },
1632 },
1633 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001634 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001635 },
1636 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001637 name: "AppDataAfterChangeCipherSpec-Empty",
1638 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001639 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001640 Bugs: ProtocolBugs{
1641 AppDataAfterChangeCipherSpec: []byte{},
1642 },
1643 },
1644 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001645 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001646 },
1647 {
Adam Langley7c803a62015-06-15 15:35:05 -07001648 protocol: dtls,
1649 name: "AppDataAfterChangeCipherSpec-DTLS",
1650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001651 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001652 Bugs: ProtocolBugs{
1653 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1654 },
1655 },
1656 // BoringSSL's DTLS implementation will drop the out-of-order
1657 // application data.
1658 },
1659 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001660 protocol: dtls,
1661 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1662 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001663 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001664 Bugs: ProtocolBugs{
1665 AppDataAfterChangeCipherSpec: []byte{},
1666 },
1667 },
1668 // BoringSSL's DTLS implementation will drop the out-of-order
1669 // application data.
1670 },
1671 {
Adam Langley7c803a62015-06-15 15:35:05 -07001672 name: "AlertAfterChangeCipherSpec",
1673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001674 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001675 Bugs: ProtocolBugs{
1676 AlertAfterChangeCipherSpec: alertRecordOverflow,
1677 },
1678 },
1679 shouldFail: true,
1680 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1681 },
1682 {
1683 protocol: dtls,
1684 name: "AlertAfterChangeCipherSpec-DTLS",
1685 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 Bugs: ProtocolBugs{
1688 AlertAfterChangeCipherSpec: alertRecordOverflow,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "ReorderHandshakeFragments-Small-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 ReorderHandshakeFragments: true,
1700 // Small enough that every handshake message is
1701 // fragmented.
1702 MaxHandshakeRecordLength: 2,
1703 },
1704 },
1705 },
1706 {
1707 protocol: dtls,
1708 name: "ReorderHandshakeFragments-Large-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 ReorderHandshakeFragments: true,
1712 // Large enough that no handshake message is
1713 // fragmented.
1714 MaxHandshakeRecordLength: 2048,
1715 },
1716 },
1717 },
1718 {
1719 protocol: dtls,
1720 name: "MixCompleteMessageWithFragments-DTLS",
1721 config: Config{
1722 Bugs: ProtocolBugs{
1723 ReorderHandshakeFragments: true,
1724 MixCompleteMessageWithFragments: true,
1725 MaxHandshakeRecordLength: 2,
1726 },
1727 },
1728 },
1729 {
1730 name: "SendInvalidRecordType",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SendInvalidRecordType: true,
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":UNEXPECTED_RECORD:",
1738 },
1739 {
1740 protocol: dtls,
1741 name: "SendInvalidRecordType-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SendInvalidRecordType: true,
1745 },
1746 },
1747 shouldFail: true,
1748 expectedError: ":UNEXPECTED_RECORD:",
1749 },
1750 {
1751 name: "FalseStart-SkipServerSecondLeg",
1752 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001753 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001754 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1755 NextProtos: []string{"foo"},
1756 Bugs: ProtocolBugs{
1757 SkipNewSessionTicket: true,
1758 SkipChangeCipherSpec: true,
1759 SkipFinished: true,
1760 ExpectFalseStart: true,
1761 },
1762 },
1763 flags: []string{
1764 "-false-start",
1765 "-handshake-never-done",
1766 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001767 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 shimWritesFirst: true,
1770 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001771 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001772 },
1773 {
1774 name: "FalseStart-SkipServerSecondLeg-Implicit",
1775 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001776 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001777 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1778 NextProtos: []string{"foo"},
1779 Bugs: ProtocolBugs{
1780 SkipNewSessionTicket: true,
1781 SkipChangeCipherSpec: true,
1782 SkipFinished: true,
1783 },
1784 },
1785 flags: []string{
1786 "-implicit-handshake",
1787 "-false-start",
1788 "-handshake-never-done",
1789 "-advertise-alpn", "\x03foo",
1790 },
1791 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001792 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001793 },
1794 {
1795 testType: serverTest,
1796 name: "FailEarlyCallback",
1797 flags: []string{"-fail-early-callback"},
1798 shouldFail: true,
1799 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001800 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001801 },
1802 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001803 name: "FailCertCallback-Client-TLS12",
1804 config: Config{
1805 MaxVersion: VersionTLS12,
1806 ClientAuth: RequestClientCert,
1807 },
1808 flags: []string{"-fail-cert-callback"},
1809 shouldFail: true,
1810 expectedError: ":CERT_CB_ERROR:",
1811 expectedLocalError: "remote error: internal error",
1812 },
1813 {
1814 testType: serverTest,
1815 name: "FailCertCallback-Server-TLS12",
1816 config: Config{
1817 MaxVersion: VersionTLS12,
1818 },
1819 flags: []string{"-fail-cert-callback"},
1820 shouldFail: true,
1821 expectedError: ":CERT_CB_ERROR:",
1822 expectedLocalError: "remote error: internal error",
1823 },
1824 {
1825 name: "FailCertCallback-Client-TLS13",
1826 config: Config{
1827 MaxVersion: VersionTLS13,
1828 ClientAuth: RequestClientCert,
1829 },
1830 flags: []string{"-fail-cert-callback"},
1831 shouldFail: true,
1832 expectedError: ":CERT_CB_ERROR:",
1833 expectedLocalError: "remote error: internal error",
1834 },
1835 {
1836 testType: serverTest,
1837 name: "FailCertCallback-Server-TLS13",
1838 config: Config{
1839 MaxVersion: VersionTLS13,
1840 },
1841 flags: []string{"-fail-cert-callback"},
1842 shouldFail: true,
1843 expectedError: ":CERT_CB_ERROR:",
1844 expectedLocalError: "remote error: internal error",
1845 },
1846 {
Adam Langley7c803a62015-06-15 15:35:05 -07001847 protocol: dtls,
1848 name: "FragmentMessageTypeMismatch-DTLS",
1849 config: Config{
1850 Bugs: ProtocolBugs{
1851 MaxHandshakeRecordLength: 2,
1852 FragmentMessageTypeMismatch: true,
1853 },
1854 },
1855 shouldFail: true,
1856 expectedError: ":FRAGMENT_MISMATCH:",
1857 },
1858 {
1859 protocol: dtls,
1860 name: "FragmentMessageLengthMismatch-DTLS",
1861 config: Config{
1862 Bugs: ProtocolBugs{
1863 MaxHandshakeRecordLength: 2,
1864 FragmentMessageLengthMismatch: true,
1865 },
1866 },
1867 shouldFail: true,
1868 expectedError: ":FRAGMENT_MISMATCH:",
1869 },
1870 {
1871 protocol: dtls,
1872 name: "SplitFragments-Header-DTLS",
1873 config: Config{
1874 Bugs: ProtocolBugs{
1875 SplitFragments: 2,
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-Boundary-DTLS",
1884 config: Config{
1885 Bugs: ProtocolBugs{
1886 SplitFragments: dtlsRecordHeaderLen,
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: "SplitFragments-Body-DTLS",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SplitFragments: dtlsRecordHeaderLen + 1,
1898 },
1899 },
1900 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001901 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001902 },
1903 {
1904 protocol: dtls,
1905 name: "SendEmptyFragments-DTLS",
1906 config: Config{
1907 Bugs: ProtocolBugs{
1908 SendEmptyFragments: true,
1909 },
1910 },
1911 },
1912 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001913 name: "BadFinished-Client",
1914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001915 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001916 Bugs: ProtocolBugs{
1917 BadFinished: true,
1918 },
1919 },
1920 shouldFail: true,
1921 expectedError: ":DIGEST_CHECK_FAILED:",
1922 },
1923 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001924 name: "BadFinished-Client-TLS13",
1925 config: Config{
1926 MaxVersion: VersionTLS13,
1927 Bugs: ProtocolBugs{
1928 BadFinished: true,
1929 },
1930 },
1931 shouldFail: true,
1932 expectedError: ":DIGEST_CHECK_FAILED:",
1933 },
1934 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001935 testType: serverTest,
1936 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001938 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001939 Bugs: ProtocolBugs{
1940 BadFinished: true,
1941 },
1942 },
1943 shouldFail: true,
1944 expectedError: ":DIGEST_CHECK_FAILED:",
1945 },
1946 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001947 testType: serverTest,
1948 name: "BadFinished-Server-TLS13",
1949 config: Config{
1950 MaxVersion: VersionTLS13,
1951 Bugs: ProtocolBugs{
1952 BadFinished: true,
1953 },
1954 },
1955 shouldFail: true,
1956 expectedError: ":DIGEST_CHECK_FAILED:",
1957 },
1958 {
Adam Langley7c803a62015-06-15 15:35:05 -07001959 name: "FalseStart-BadFinished",
1960 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001961 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1963 NextProtos: []string{"foo"},
1964 Bugs: ProtocolBugs{
1965 BadFinished: true,
1966 ExpectFalseStart: true,
1967 },
1968 },
1969 flags: []string{
1970 "-false-start",
1971 "-handshake-never-done",
1972 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001973 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001974 },
1975 shimWritesFirst: true,
1976 shouldFail: true,
1977 expectedError: ":DIGEST_CHECK_FAILED:",
1978 },
1979 {
1980 name: "NoFalseStart-NoALPN",
1981 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001982 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001983 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1984 Bugs: ProtocolBugs{
1985 ExpectFalseStart: true,
1986 AlertBeforeFalseStartTest: alertAccessDenied,
1987 },
1988 },
1989 flags: []string{
1990 "-false-start",
1991 },
1992 shimWritesFirst: true,
1993 shouldFail: true,
1994 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1995 expectedLocalError: "tls: peer did not false start: EOF",
1996 },
1997 {
1998 name: "NoFalseStart-NoAEAD",
1999 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002000 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2002 NextProtos: []string{"foo"},
2003 Bugs: ProtocolBugs{
2004 ExpectFalseStart: true,
2005 AlertBeforeFalseStartTest: alertAccessDenied,
2006 },
2007 },
2008 flags: []string{
2009 "-false-start",
2010 "-advertise-alpn", "\x03foo",
2011 },
2012 shimWritesFirst: true,
2013 shouldFail: true,
2014 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2015 expectedLocalError: "tls: peer did not false start: EOF",
2016 },
2017 {
2018 name: "NoFalseStart-RSA",
2019 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002020 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002021 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2022 NextProtos: []string{"foo"},
2023 Bugs: ProtocolBugs{
2024 ExpectFalseStart: true,
2025 AlertBeforeFalseStartTest: alertAccessDenied,
2026 },
2027 },
2028 flags: []string{
2029 "-false-start",
2030 "-advertise-alpn", "\x03foo",
2031 },
2032 shimWritesFirst: true,
2033 shouldFail: true,
2034 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2035 expectedLocalError: "tls: peer did not false start: EOF",
2036 },
2037 {
Adam Langley7c803a62015-06-15 15:35:05 -07002038 protocol: dtls,
2039 name: "SendSplitAlert-Sync",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 SendSplitAlert: true,
2043 },
2044 },
2045 },
2046 {
2047 protocol: dtls,
2048 name: "SendSplitAlert-Async",
2049 config: Config{
2050 Bugs: ProtocolBugs{
2051 SendSplitAlert: true,
2052 },
2053 },
2054 flags: []string{"-async"},
2055 },
2056 {
2057 protocol: dtls,
2058 name: "PackDTLSHandshake",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 MaxHandshakeRecordLength: 2,
2062 PackHandshakeFragments: 20,
2063 PackHandshakeRecords: 200,
2064 },
2065 },
2066 },
2067 {
Adam Langley7c803a62015-06-15 15:35:05 -07002068 name: "SendEmptyRecords-Pass",
2069 sendEmptyRecords: 32,
2070 },
2071 {
2072 name: "SendEmptyRecords",
2073 sendEmptyRecords: 33,
2074 shouldFail: true,
2075 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2076 },
2077 {
2078 name: "SendEmptyRecords-Async",
2079 sendEmptyRecords: 33,
2080 flags: []string{"-async"},
2081 shouldFail: true,
2082 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2083 },
2084 {
David Benjamine8e84b92016-08-03 15:39:47 -04002085 name: "SendWarningAlerts-Pass",
2086 config: Config{
2087 MaxVersion: VersionTLS12,
2088 },
Adam Langley7c803a62015-06-15 15:35:05 -07002089 sendWarningAlerts: 4,
2090 },
2091 {
David Benjamine8e84b92016-08-03 15:39:47 -04002092 protocol: dtls,
2093 name: "SendWarningAlerts-DTLS-Pass",
2094 config: Config{
2095 MaxVersion: VersionTLS12,
2096 },
Adam Langley7c803a62015-06-15 15:35:05 -07002097 sendWarningAlerts: 4,
2098 },
2099 {
David Benjamine8e84b92016-08-03 15:39:47 -04002100 name: "SendWarningAlerts-TLS13",
2101 config: Config{
2102 MaxVersion: VersionTLS13,
2103 },
2104 sendWarningAlerts: 4,
2105 shouldFail: true,
2106 expectedError: ":BAD_ALERT:",
2107 expectedLocalError: "remote error: error decoding message",
2108 },
2109 {
2110 name: "SendWarningAlerts",
2111 config: Config{
2112 MaxVersion: VersionTLS12,
2113 },
Adam Langley7c803a62015-06-15 15:35:05 -07002114 sendWarningAlerts: 5,
2115 shouldFail: true,
2116 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2117 },
2118 {
David Benjamine8e84b92016-08-03 15:39:47 -04002119 name: "SendWarningAlerts-Async",
2120 config: Config{
2121 MaxVersion: VersionTLS12,
2122 },
Adam Langley7c803a62015-06-15 15:35:05 -07002123 sendWarningAlerts: 5,
2124 flags: []string{"-async"},
2125 shouldFail: true,
2126 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2127 },
David Benjaminba4594a2015-06-18 18:36:15 -04002128 {
David Benjamin24e58862017-06-14 18:45:29 -04002129 name: "SendBogusAlertType",
2130 sendBogusAlertType: true,
2131 shouldFail: true,
2132 expectedError: ":UNKNOWN_ALERT_TYPE:",
2133 expectedLocalError: "remote error: illegal parameter",
2134 },
2135 {
2136 protocol: dtls,
2137 name: "SendBogusAlertType-DTLS",
2138 sendBogusAlertType: true,
2139 shouldFail: true,
2140 expectedError: ":UNKNOWN_ALERT_TYPE:",
2141 expectedLocalError: "remote error: illegal parameter",
2142 },
2143 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002144 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002145 config: Config{
2146 MaxVersion: VersionTLS13,
2147 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002148 sendKeyUpdates: 33,
2149 keyUpdateRequest: keyUpdateNotRequested,
2150 shouldFail: true,
2151 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002152 },
2153 {
David Benjaminba4594a2015-06-18 18:36:15 -04002154 name: "EmptySessionID",
2155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002156 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002157 SessionTicketsDisabled: true,
2158 },
2159 noSessionCache: true,
2160 flags: []string{"-expect-no-session"},
2161 },
David Benjamin30789da2015-08-29 22:56:45 -04002162 {
2163 name: "Unclean-Shutdown",
2164 config: Config{
2165 Bugs: ProtocolBugs{
2166 NoCloseNotify: true,
2167 ExpectCloseNotify: true,
2168 },
2169 },
2170 shimShutsDown: true,
2171 flags: []string{"-check-close-notify"},
2172 shouldFail: true,
2173 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2174 },
2175 {
2176 name: "Unclean-Shutdown-Ignored",
2177 config: Config{
2178 Bugs: ProtocolBugs{
2179 NoCloseNotify: true,
2180 },
2181 },
2182 shimShutsDown: true,
2183 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002184 {
David Benjaminfa214e42016-05-10 17:03:10 -04002185 name: "Unclean-Shutdown-Alert",
2186 config: Config{
2187 Bugs: ProtocolBugs{
2188 SendAlertOnShutdown: alertDecompressionFailure,
2189 ExpectCloseNotify: true,
2190 },
2191 },
2192 shimShutsDown: true,
2193 flags: []string{"-check-close-notify"},
2194 shouldFail: true,
2195 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2196 },
2197 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002198 name: "LargePlaintext",
2199 config: Config{
2200 Bugs: ProtocolBugs{
2201 SendLargeRecords: true,
2202 },
2203 },
2204 messageLen: maxPlaintext + 1,
2205 shouldFail: true,
2206 expectedError: ":DATA_LENGTH_TOO_LONG:",
2207 },
2208 {
2209 protocol: dtls,
2210 name: "LargePlaintext-DTLS",
2211 config: Config{
2212 Bugs: ProtocolBugs{
2213 SendLargeRecords: true,
2214 },
2215 },
2216 messageLen: maxPlaintext + 1,
2217 shouldFail: true,
2218 expectedError: ":DATA_LENGTH_TOO_LONG:",
2219 },
2220 {
2221 name: "LargeCiphertext",
2222 config: Config{
2223 Bugs: ProtocolBugs{
2224 SendLargeRecords: true,
2225 },
2226 },
2227 messageLen: maxPlaintext * 2,
2228 shouldFail: true,
2229 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2230 },
2231 {
2232 protocol: dtls,
2233 name: "LargeCiphertext-DTLS",
2234 config: Config{
2235 Bugs: ProtocolBugs{
2236 SendLargeRecords: true,
2237 },
2238 },
2239 messageLen: maxPlaintext * 2,
2240 // Unlike the other four cases, DTLS drops records which
2241 // are invalid before authentication, so the connection
2242 // does not fail.
2243 expectMessageDropped: true,
2244 },
David Benjamindd6fed92015-10-23 17:41:12 -04002245 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002246 name: "BadHelloRequest-1",
2247 renegotiate: 1,
2248 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002249 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002250 Bugs: ProtocolBugs{
2251 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2252 },
2253 },
2254 flags: []string{
2255 "-renegotiate-freely",
2256 "-expect-total-renegotiations", "1",
2257 },
2258 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002259 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002260 },
2261 {
2262 name: "BadHelloRequest-2",
2263 renegotiate: 1,
2264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002265 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002266 Bugs: ProtocolBugs{
2267 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2268 },
2269 },
2270 flags: []string{
2271 "-renegotiate-freely",
2272 "-expect-total-renegotiations", "1",
2273 },
2274 shouldFail: true,
2275 expectedError: ":BAD_HELLO_REQUEST:",
2276 },
David Benjaminef1b0092015-11-21 14:05:44 -05002277 {
2278 testType: serverTest,
2279 name: "SupportTicketsWithSessionID",
2280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002281 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002282 SessionTicketsDisabled: true,
2283 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002284 resumeConfig: &Config{
2285 MaxVersion: VersionTLS12,
2286 },
David Benjaminef1b0092015-11-21 14:05:44 -05002287 resumeSession: true,
2288 },
David Benjamin02edcd02016-07-27 17:40:37 -04002289 {
2290 protocol: dtls,
2291 name: "DTLS-SendExtraFinished",
2292 config: Config{
2293 Bugs: ProtocolBugs{
2294 SendExtraFinished: true,
2295 },
2296 },
2297 shouldFail: true,
2298 expectedError: ":UNEXPECTED_RECORD:",
2299 },
2300 {
2301 protocol: dtls,
2302 name: "DTLS-SendExtraFinished-Reordered",
2303 config: Config{
2304 Bugs: ProtocolBugs{
2305 MaxHandshakeRecordLength: 2,
2306 ReorderHandshakeFragments: true,
2307 SendExtraFinished: true,
2308 },
2309 },
2310 shouldFail: true,
2311 expectedError: ":UNEXPECTED_RECORD:",
2312 },
David Benjamine97fb482016-07-29 09:23:07 -04002313 {
2314 testType: serverTest,
2315 name: "V2ClientHello-EmptyRecordPrefix",
2316 config: Config{
2317 // Choose a cipher suite that does not involve
2318 // elliptic curves, so no extensions are
2319 // involved.
2320 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002321 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002322 Bugs: ProtocolBugs{
2323 SendV2ClientHello: true,
2324 },
2325 },
2326 sendPrefix: string([]byte{
2327 byte(recordTypeHandshake),
2328 3, 1, // version
2329 0, 0, // length
2330 }),
2331 // A no-op empty record may not be sent before V2ClientHello.
2332 shouldFail: true,
2333 expectedError: ":WRONG_VERSION_NUMBER:",
2334 },
2335 {
2336 testType: serverTest,
2337 name: "V2ClientHello-WarningAlertPrefix",
2338 config: Config{
2339 // Choose a cipher suite that does not involve
2340 // elliptic curves, so no extensions are
2341 // involved.
2342 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002343 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002344 Bugs: ProtocolBugs{
2345 SendV2ClientHello: true,
2346 },
2347 },
2348 sendPrefix: string([]byte{
2349 byte(recordTypeAlert),
2350 3, 1, // version
2351 0, 2, // length
2352 alertLevelWarning, byte(alertDecompressionFailure),
2353 }),
2354 // A no-op warning alert may not be sent before V2ClientHello.
2355 shouldFail: true,
2356 expectedError: ":WRONG_VERSION_NUMBER:",
2357 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002358 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002359 name: "KeyUpdate-Client",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 },
2363 sendKeyUpdates: 1,
2364 keyUpdateRequest: keyUpdateNotRequested,
2365 },
2366 {
2367 testType: serverTest,
2368 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002369 config: Config{
2370 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002371 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002372 sendKeyUpdates: 1,
2373 keyUpdateRequest: keyUpdateNotRequested,
2374 },
2375 {
2376 name: "KeyUpdate-InvalidRequestMode",
2377 config: Config{
2378 MaxVersion: VersionTLS13,
2379 },
2380 sendKeyUpdates: 1,
2381 keyUpdateRequest: 42,
2382 shouldFail: true,
2383 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002384 },
David Benjaminabe94e32016-09-04 14:18:58 -04002385 {
David Benjaminbbba9392017-04-06 12:54:12 -04002386 // Test that KeyUpdates are acknowledged properly.
2387 name: "KeyUpdate-RequestACK",
2388 config: Config{
2389 MaxVersion: VersionTLS13,
2390 Bugs: ProtocolBugs{
2391 RejectUnsolicitedKeyUpdate: true,
2392 },
2393 },
2394 // Test the shim receiving many KeyUpdates in a row.
2395 sendKeyUpdates: 5,
2396 messageCount: 5,
2397 keyUpdateRequest: keyUpdateRequested,
2398 },
2399 {
2400 // Test that KeyUpdates are acknowledged properly if the
2401 // peer's KeyUpdate is discovered while a write is
2402 // pending.
2403 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2404 config: Config{
2405 MaxVersion: VersionTLS13,
2406 Bugs: ProtocolBugs{
2407 RejectUnsolicitedKeyUpdate: true,
2408 },
2409 },
2410 // Test the shim receiving many KeyUpdates in a row.
2411 sendKeyUpdates: 5,
2412 messageCount: 5,
2413 keyUpdateRequest: keyUpdateRequested,
2414 readWithUnfinishedWrite: true,
2415 flags: []string{"-async"},
2416 },
2417 {
David Benjaminabe94e32016-09-04 14:18:58 -04002418 name: "SendSNIWarningAlert",
2419 config: Config{
2420 MaxVersion: VersionTLS12,
2421 Bugs: ProtocolBugs{
2422 SendSNIWarningAlert: true,
2423 },
2424 },
2425 },
David Benjaminc241d792016-09-09 10:34:20 -04002426 {
2427 testType: serverTest,
2428 name: "ExtraCompressionMethods-TLS12",
2429 config: Config{
2430 MaxVersion: VersionTLS12,
2431 Bugs: ProtocolBugs{
2432 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2433 },
2434 },
2435 },
2436 {
2437 testType: serverTest,
2438 name: "ExtraCompressionMethods-TLS13",
2439 config: Config{
2440 MaxVersion: VersionTLS13,
2441 Bugs: ProtocolBugs{
2442 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2443 },
2444 },
2445 shouldFail: true,
2446 expectedError: ":INVALID_COMPRESSION_LIST:",
2447 expectedLocalError: "remote error: illegal parameter",
2448 },
2449 {
2450 testType: serverTest,
2451 name: "NoNullCompression-TLS12",
2452 config: Config{
2453 MaxVersion: VersionTLS12,
2454 Bugs: ProtocolBugs{
2455 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2456 },
2457 },
2458 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002459 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002460 expectedLocalError: "remote error: illegal parameter",
2461 },
2462 {
2463 testType: serverTest,
2464 name: "NoNullCompression-TLS13",
2465 config: Config{
2466 MaxVersion: VersionTLS13,
2467 Bugs: ProtocolBugs{
2468 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2469 },
2470 },
2471 shouldFail: true,
2472 expectedError: ":INVALID_COMPRESSION_LIST:",
2473 expectedLocalError: "remote error: illegal parameter",
2474 },
David Benjamin65ac9972016-09-02 21:35:25 -04002475 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002476 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002477 config: Config{
2478 MaxVersion: VersionTLS12,
2479 Bugs: ProtocolBugs{
2480 ExpectGREASE: true,
2481 },
2482 },
2483 flags: []string{"-enable-grease"},
2484 },
2485 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002486 name: "GREASE-Client-TLS13",
2487 config: Config{
2488 MaxVersion: VersionTLS13,
2489 Bugs: ProtocolBugs{
2490 ExpectGREASE: true,
2491 },
2492 },
2493 flags: []string{"-enable-grease"},
2494 },
2495 {
2496 testType: serverTest,
2497 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002498 config: Config{
2499 MaxVersion: VersionTLS13,
2500 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002501 // TLS 1.3 servers are expected to
2502 // always enable GREASE. TLS 1.3 is new,
2503 // so there is no existing ecosystem to
2504 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002505 ExpectGREASE: true,
2506 },
2507 },
David Benjamin65ac9972016-09-02 21:35:25 -04002508 },
David Benjamine3fbb362017-01-06 16:19:28 -05002509 {
2510 // Test the server so there is a large certificate as
2511 // well as application data.
2512 testType: serverTest,
2513 name: "MaxSendFragment",
2514 config: Config{
2515 Bugs: ProtocolBugs{
2516 MaxReceivePlaintext: 512,
2517 },
2518 },
2519 messageLen: 1024,
2520 flags: []string{
2521 "-max-send-fragment", "512",
2522 "-read-size", "1024",
2523 },
2524 },
2525 {
2526 // Test the server so there is a large certificate as
2527 // well as application data.
2528 testType: serverTest,
2529 name: "MaxSendFragment-TooLarge",
2530 config: Config{
2531 Bugs: ProtocolBugs{
2532 // Ensure that some of the records are
2533 // 512.
2534 MaxReceivePlaintext: 511,
2535 },
2536 },
2537 messageLen: 1024,
2538 flags: []string{
2539 "-max-send-fragment", "512",
2540 "-read-size", "1024",
2541 },
2542 shouldFail: true,
2543 expectedLocalError: "local error: record overflow",
2544 },
Adam Langley7c803a62015-06-15 15:35:05 -07002545 }
Adam Langley7c803a62015-06-15 15:35:05 -07002546 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002547
2548 // Test that very large messages can be received.
2549 cert := rsaCertificate
2550 for i := 0; i < 50; i++ {
2551 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2552 }
2553 testCases = append(testCases, testCase{
2554 name: "LargeMessage",
2555 config: Config{
2556 Certificates: []Certificate{cert},
2557 },
2558 })
2559 testCases = append(testCases, testCase{
2560 protocol: dtls,
2561 name: "LargeMessage-DTLS",
2562 config: Config{
2563 Certificates: []Certificate{cert},
2564 },
2565 })
2566
2567 // They are rejected if the maximum certificate chain length is capped.
2568 testCases = append(testCases, testCase{
2569 name: "LargeMessage-Reject",
2570 config: Config{
2571 Certificates: []Certificate{cert},
2572 },
2573 flags: []string{"-max-cert-list", "16384"},
2574 shouldFail: true,
2575 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2576 })
2577 testCases = append(testCases, testCase{
2578 protocol: dtls,
2579 name: "LargeMessage-Reject-DTLS",
2580 config: Config{
2581 Certificates: []Certificate{cert},
2582 },
2583 flags: []string{"-max-cert-list", "16384"},
2584 shouldFail: true,
2585 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2586 })
Adam Langley7c803a62015-06-15 15:35:05 -07002587}
2588
David Benjaminaa012042016-12-10 13:33:05 -05002589func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2590 const psk = "12345"
2591 const pskIdentity = "luggage combo"
2592
2593 var prefix string
2594 if protocol == dtls {
2595 if !ver.hasDTLS {
2596 return
2597 }
2598 prefix = "D"
2599 }
2600
2601 var cert Certificate
2602 var certFile string
2603 var keyFile string
2604 if hasComponent(suite.name, "ECDSA") {
2605 cert = ecdsaP256Certificate
2606 certFile = ecdsaP256CertificateFile
2607 keyFile = ecdsaP256KeyFile
2608 } else {
2609 cert = rsaCertificate
2610 certFile = rsaCertificateFile
2611 keyFile = rsaKeyFile
2612 }
2613
2614 var flags []string
2615 if hasComponent(suite.name, "PSK") {
2616 flags = append(flags,
2617 "-psk", psk,
2618 "-psk-identity", pskIdentity)
2619 }
2620 if hasComponent(suite.name, "NULL") {
2621 // NULL ciphers must be explicitly enabled.
2622 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2623 }
David Benjaminaa012042016-12-10 13:33:05 -05002624
2625 var shouldServerFail, shouldClientFail bool
2626 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2627 // BoringSSL clients accept ECDHE on SSLv3, but
2628 // a BoringSSL server will never select it
2629 // because the extension is missing.
2630 shouldServerFail = true
2631 }
2632 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2633 shouldClientFail = true
2634 shouldServerFail = true
2635 }
2636 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2637 shouldClientFail = true
2638 shouldServerFail = true
2639 }
2640 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2641 shouldClientFail = true
2642 shouldServerFail = true
2643 }
2644 if !isDTLSCipher(suite.name) && protocol == dtls {
2645 shouldClientFail = true
2646 shouldServerFail = true
2647 }
2648
2649 var sendCipherSuite uint16
2650 var expectedServerError, expectedClientError string
2651 serverCipherSuites := []uint16{suite.id}
2652 if shouldServerFail {
2653 expectedServerError = ":NO_SHARED_CIPHER:"
2654 }
2655 if shouldClientFail {
2656 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2657 // Configure the server to select ciphers as normal but
2658 // select an incompatible cipher in ServerHello.
2659 serverCipherSuites = nil
2660 sendCipherSuite = suite.id
2661 }
2662
David Benjamincdb6fe92017-02-07 16:06:48 -05002663 // For cipher suites and versions where exporters are defined, verify
2664 // that they interoperate.
2665 var exportKeyingMaterial int
2666 if ver.version > VersionSSL30 {
2667 exportKeyingMaterial = 1024
2668 }
2669
David Benjaminaa012042016-12-10 13:33:05 -05002670 testCases = append(testCases, testCase{
2671 testType: serverTest,
2672 protocol: protocol,
2673 name: prefix + ver.name + "-" + suite.name + "-server",
2674 config: Config{
2675 MinVersion: ver.version,
2676 MaxVersion: ver.version,
2677 CipherSuites: []uint16{suite.id},
2678 Certificates: []Certificate{cert},
2679 PreSharedKey: []byte(psk),
2680 PreSharedKeyIdentity: pskIdentity,
2681 Bugs: ProtocolBugs{
2682 AdvertiseAllConfiguredCiphers: true,
2683 },
2684 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002685 certFile: certFile,
2686 keyFile: keyFile,
2687 flags: flags,
2688 resumeSession: true,
2689 shouldFail: shouldServerFail,
2690 expectedError: expectedServerError,
2691 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002692 })
2693
2694 testCases = append(testCases, testCase{
2695 testType: clientTest,
2696 protocol: protocol,
2697 name: prefix + ver.name + "-" + suite.name + "-client",
2698 config: Config{
2699 MinVersion: ver.version,
2700 MaxVersion: ver.version,
2701 CipherSuites: serverCipherSuites,
2702 Certificates: []Certificate{cert},
2703 PreSharedKey: []byte(psk),
2704 PreSharedKeyIdentity: pskIdentity,
2705 Bugs: ProtocolBugs{
2706 IgnorePeerCipherPreferences: shouldClientFail,
2707 SendCipherSuite: sendCipherSuite,
2708 },
2709 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002710 flags: flags,
2711 resumeSession: true,
2712 shouldFail: shouldClientFail,
2713 expectedError: expectedClientError,
2714 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002715 })
2716
David Benjamin6f600d62016-12-21 16:06:54 -05002717 if shouldClientFail {
2718 return
2719 }
2720
2721 // Ensure the maximum record size is accepted.
2722 testCases = append(testCases, testCase{
2723 protocol: protocol,
2724 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2725 config: Config{
2726 MinVersion: ver.version,
2727 MaxVersion: ver.version,
2728 CipherSuites: []uint16{suite.id},
2729 Certificates: []Certificate{cert},
2730 PreSharedKey: []byte(psk),
2731 PreSharedKeyIdentity: pskIdentity,
2732 },
2733 flags: flags,
2734 messageLen: maxPlaintext,
2735 })
2736
2737 // Test bad records for all ciphers. Bad records are fatal in TLS
2738 // and ignored in DTLS.
2739 var shouldFail bool
2740 var expectedError string
2741 if protocol == tls {
2742 shouldFail = true
2743 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2744 }
2745
2746 testCases = append(testCases, testCase{
2747 protocol: protocol,
2748 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
2752 CipherSuites: []uint16{suite.id},
2753 Certificates: []Certificate{cert},
2754 PreSharedKey: []byte(psk),
2755 PreSharedKeyIdentity: pskIdentity,
2756 },
2757 flags: flags,
2758 damageFirstWrite: true,
2759 messageLen: maxPlaintext,
2760 shouldFail: shouldFail,
2761 expectedError: expectedError,
2762 })
David Benjaminaa012042016-12-10 13:33:05 -05002763}
2764
Adam Langley95c29f32014-06-20 12:00:00 -07002765func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002766 const bogusCipher = 0xfe00
2767
Adam Langley95c29f32014-06-20 12:00:00 -07002768 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002769 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002770 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002771 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002772 }
David Benjamin2c99d282015-09-01 10:23:00 -04002773 }
Adam Langley95c29f32014-06-20 12:00:00 -07002774 }
Adam Langleya7997f12015-05-14 17:38:50 -07002775
2776 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002777 name: "NoSharedCipher",
2778 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002779 MaxVersion: VersionTLS12,
2780 CipherSuites: []uint16{},
2781 },
2782 shouldFail: true,
2783 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2784 })
2785
2786 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002787 name: "NoSharedCipher-TLS13",
2788 config: Config{
2789 MaxVersion: VersionTLS13,
2790 CipherSuites: []uint16{},
2791 },
2792 shouldFail: true,
2793 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2794 })
2795
2796 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002797 name: "UnsupportedCipherSuite",
2798 config: Config{
2799 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002800 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002801 Bugs: ProtocolBugs{
2802 IgnorePeerCipherPreferences: true,
2803 },
2804 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002805 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002806 shouldFail: true,
2807 expectedError: ":WRONG_CIPHER_RETURNED:",
2808 })
2809
2810 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002811 name: "ServerHelloBogusCipher",
2812 config: Config{
2813 MaxVersion: VersionTLS12,
2814 Bugs: ProtocolBugs{
2815 SendCipherSuite: bogusCipher,
2816 },
2817 },
2818 shouldFail: true,
2819 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2820 })
2821 testCases = append(testCases, testCase{
2822 name: "ServerHelloBogusCipher-TLS13",
2823 config: Config{
2824 MaxVersion: VersionTLS13,
2825 Bugs: ProtocolBugs{
2826 SendCipherSuite: bogusCipher,
2827 },
2828 },
2829 shouldFail: true,
2830 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2831 })
2832
David Benjamin241ae832016-01-15 03:04:54 -05002833 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002834 testCases = append(testCases, testCase{
2835 testType: serverTest,
2836 name: "UnknownCipher",
2837 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002838 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002839 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002840 Bugs: ProtocolBugs{
2841 AdvertiseAllConfiguredCiphers: true,
2842 },
2843 },
2844 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002845
2846 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002847 testCases = append(testCases, testCase{
2848 testType: serverTest,
2849 name: "UnknownCipher-TLS13",
2850 config: Config{
2851 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002852 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002853 Bugs: ProtocolBugs{
2854 AdvertiseAllConfiguredCiphers: true,
2855 },
David Benjamin241ae832016-01-15 03:04:54 -05002856 },
2857 })
2858
David Benjamin78679342016-09-16 19:42:05 -04002859 // Test empty ECDHE_PSK identity hints work as expected.
2860 testCases = append(testCases, testCase{
2861 name: "EmptyECDHEPSKHint",
2862 config: Config{
2863 MaxVersion: VersionTLS12,
2864 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2865 PreSharedKey: []byte("secret"),
2866 },
2867 flags: []string{"-psk", "secret"},
2868 })
2869
2870 // Test empty PSK identity hints work as expected, even if an explicit
2871 // ServerKeyExchange is sent.
2872 testCases = append(testCases, testCase{
2873 name: "ExplicitEmptyPSKHint",
2874 config: Config{
2875 MaxVersion: VersionTLS12,
2876 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2877 PreSharedKey: []byte("secret"),
2878 Bugs: ProtocolBugs{
2879 AlwaysSendPreSharedKeyIdentityHint: true,
2880 },
2881 },
2882 flags: []string{"-psk", "secret"},
2883 })
David Benjamin69522112017-03-28 15:38:29 -05002884
2885 // Test that clients enforce that the server-sent certificate and cipher
2886 // suite match in TLS 1.2.
2887 testCases = append(testCases, testCase{
2888 name: "CertificateCipherMismatch-RSA",
2889 config: Config{
2890 MaxVersion: VersionTLS12,
2891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2892 Certificates: []Certificate{rsaCertificate},
2893 Bugs: ProtocolBugs{
2894 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2895 },
2896 },
2897 shouldFail: true,
2898 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2899 })
2900 testCases = append(testCases, testCase{
2901 name: "CertificateCipherMismatch-ECDSA",
2902 config: Config{
2903 MaxVersion: VersionTLS12,
2904 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2905 Certificates: []Certificate{ecdsaP256Certificate},
2906 Bugs: ProtocolBugs{
2907 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2908 },
2909 },
2910 shouldFail: true,
2911 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2912 })
2913 testCases = append(testCases, testCase{
2914 name: "CertificateCipherMismatch-Ed25519",
2915 config: Config{
2916 MaxVersion: VersionTLS12,
2917 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2918 Certificates: []Certificate{ed25519Certificate},
2919 Bugs: ProtocolBugs{
2920 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2921 },
2922 },
2923 shouldFail: true,
2924 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2925 })
2926
2927 // Test that servers decline to select a cipher suite which is
2928 // inconsistent with their configured certificate.
2929 testCases = append(testCases, testCase{
2930 testType: serverTest,
2931 name: "ServerCipherFilter-RSA",
2932 config: Config{
2933 MaxVersion: VersionTLS12,
2934 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2935 },
2936 flags: []string{
2937 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2938 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2939 },
2940 shouldFail: true,
2941 expectedError: ":NO_SHARED_CIPHER:",
2942 })
2943 testCases = append(testCases, testCase{
2944 testType: serverTest,
2945 name: "ServerCipherFilter-ECDSA",
2946 config: Config{
2947 MaxVersion: VersionTLS12,
2948 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2949 },
2950 flags: []string{
2951 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2952 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
2953 },
2954 shouldFail: true,
2955 expectedError: ":NO_SHARED_CIPHER:",
2956 })
2957 testCases = append(testCases, testCase{
2958 testType: serverTest,
2959 name: "ServerCipherFilter-Ed25519",
2960 config: Config{
2961 MaxVersion: VersionTLS12,
2962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2963 },
2964 flags: []string{
2965 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
2966 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
2967 },
2968 shouldFail: true,
2969 expectedError: ":NO_SHARED_CIPHER:",
2970 })
Adam Langley95c29f32014-06-20 12:00:00 -07002971}
2972
2973func addBadECDSASignatureTests() {
2974 for badR := BadValue(1); badR < NumBadValues; badR++ {
2975 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002976 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002977 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2978 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002979 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002980 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002981 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002982 Bugs: ProtocolBugs{
2983 BadECDSAR: badR,
2984 BadECDSAS: badS,
2985 },
2986 },
2987 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002988 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002989 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002990 testCases = append(testCases, testCase{
2991 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2992 config: Config{
2993 MaxVersion: VersionTLS13,
2994 Certificates: []Certificate{ecdsaP256Certificate},
2995 Bugs: ProtocolBugs{
2996 BadECDSAR: badR,
2997 BadECDSAS: badS,
2998 },
2999 },
3000 shouldFail: true,
3001 expectedError: ":BAD_SIGNATURE:",
3002 })
Adam Langley95c29f32014-06-20 12:00:00 -07003003 }
3004 }
3005}
3006
Adam Langley80842bd2014-06-20 12:00:00 -07003007func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003008 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003009 name: "MaxCBCPadding",
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 MaxPadding: true,
3015 },
3016 },
3017 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3018 })
David Benjamin025b3d32014-07-01 19:53:04 -04003019 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003020 name: "BadCBCPadding",
3021 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003022 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3024 Bugs: ProtocolBugs{
3025 PaddingFirstByteBad: true,
3026 },
3027 },
3028 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003029 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003030 })
3031 // OpenSSL previously had an issue where the first byte of padding in
3032 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003033 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003034 name: "BadCBCPadding255",
3035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003036 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3038 Bugs: ProtocolBugs{
3039 MaxPadding: true,
3040 PaddingFirstByteBadIf255: true,
3041 },
3042 },
3043 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3044 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003045 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003046 })
3047}
3048
Kenny Root7fdeaf12014-08-05 15:23:37 -07003049func addCBCSplittingTests() {
3050 testCases = append(testCases, testCase{
3051 name: "CBCRecordSplitting",
3052 config: Config{
3053 MaxVersion: VersionTLS10,
3054 MinVersion: VersionTLS10,
3055 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3056 },
David Benjaminac8302a2015-09-01 17:18:15 -04003057 messageLen: -1, // read until EOF
3058 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003059 flags: []string{
3060 "-async",
3061 "-write-different-record-sizes",
3062 "-cbc-record-splitting",
3063 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003064 })
3065 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003066 name: "CBCRecordSplittingPartialWrite",
3067 config: Config{
3068 MaxVersion: VersionTLS10,
3069 MinVersion: VersionTLS10,
3070 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3071 },
3072 messageLen: -1, // read until EOF
3073 flags: []string{
3074 "-async",
3075 "-write-different-record-sizes",
3076 "-cbc-record-splitting",
3077 "-partial-write",
3078 },
3079 })
3080}
3081
David Benjamin636293b2014-07-08 17:59:18 -04003082func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003083 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003084 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003085 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3086 cert, err := x509.ParseCertificate(cert.Certificate[0])
3087 if err != nil {
3088 panic(err)
3089 }
3090 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003091 }
Adam Langley2ff79332017-02-28 13:45:39 -08003092 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003093
David Benjamin636293b2014-07-08 17:59:18 -04003094 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003095 testCases = append(testCases, testCase{
3096 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003097 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003098 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003099 MinVersion: ver.version,
3100 MaxVersion: ver.version,
3101 ClientAuth: RequireAnyClientCert,
3102 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003103 },
3104 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003105 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3106 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003107 },
3108 })
3109 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003110 testType: serverTest,
3111 name: ver.name + "-Server-ClientAuth-RSA",
3112 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003113 MinVersion: ver.version,
3114 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003115 Certificates: []Certificate{rsaCertificate},
3116 },
3117 flags: []string{"-require-any-client-certificate"},
3118 })
David Benjamine098ec22014-08-27 23:13:20 -04003119 if ver.version != VersionSSL30 {
3120 testCases = append(testCases, testCase{
3121 testType: serverTest,
3122 name: ver.name + "-Server-ClientAuth-ECDSA",
3123 config: Config{
3124 MinVersion: ver.version,
3125 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003126 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003127 },
3128 flags: []string{"-require-any-client-certificate"},
3129 })
3130 testCases = append(testCases, testCase{
3131 testType: clientTest,
3132 name: ver.name + "-Client-ClientAuth-ECDSA",
3133 config: Config{
3134 MinVersion: ver.version,
3135 MaxVersion: ver.version,
3136 ClientAuth: RequireAnyClientCert,
3137 ClientCAs: certPool,
3138 },
3139 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003140 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3141 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003142 },
3143 })
3144 }
Adam Langley37646832016-08-01 16:16:46 -07003145
3146 testCases = append(testCases, testCase{
3147 name: "NoClientCertificate-" + ver.name,
3148 config: Config{
3149 MinVersion: ver.version,
3150 MaxVersion: ver.version,
3151 ClientAuth: RequireAnyClientCert,
3152 },
3153 shouldFail: true,
3154 expectedLocalError: "client didn't provide a certificate",
3155 })
3156
3157 testCases = append(testCases, testCase{
3158 // Even if not configured to expect a certificate, OpenSSL will
3159 // return X509_V_OK as the verify_result.
3160 testType: serverTest,
3161 name: "NoClientCertificateRequested-Server-" + ver.name,
3162 config: Config{
3163 MinVersion: ver.version,
3164 MaxVersion: ver.version,
3165 },
3166 flags: []string{
3167 "-expect-verify-result",
3168 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003169 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003170 })
3171
3172 testCases = append(testCases, testCase{
3173 // If a client certificate is not provided, OpenSSL will still
3174 // return X509_V_OK as the verify_result.
3175 testType: serverTest,
3176 name: "NoClientCertificate-Server-" + ver.name,
3177 config: Config{
3178 MinVersion: ver.version,
3179 MaxVersion: ver.version,
3180 },
3181 flags: []string{
3182 "-expect-verify-result",
3183 "-verify-peer",
3184 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003185 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003186 })
3187
David Benjamin1db9e1b2016-10-07 20:51:43 -04003188 certificateRequired := "remote error: certificate required"
3189 if ver.version < VersionTLS13 {
3190 // Prior to TLS 1.3, the generic handshake_failure alert
3191 // was used.
3192 certificateRequired = "remote error: handshake failure"
3193 }
Adam Langley37646832016-08-01 16:16:46 -07003194 testCases = append(testCases, testCase{
3195 testType: serverTest,
3196 name: "RequireAnyClientCertificate-" + ver.name,
3197 config: Config{
3198 MinVersion: ver.version,
3199 MaxVersion: ver.version,
3200 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003201 flags: []string{"-require-any-client-certificate"},
3202 shouldFail: true,
3203 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3204 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003205 })
3206
3207 if ver.version != VersionSSL30 {
3208 testCases = append(testCases, testCase{
3209 testType: serverTest,
3210 name: "SkipClientCertificate-" + ver.name,
3211 config: Config{
3212 MinVersion: ver.version,
3213 MaxVersion: ver.version,
3214 Bugs: ProtocolBugs{
3215 SkipClientCertificate: true,
3216 },
3217 },
3218 // Setting SSL_VERIFY_PEER allows anonymous clients.
3219 flags: []string{"-verify-peer"},
3220 shouldFail: true,
3221 expectedError: ":UNEXPECTED_MESSAGE:",
3222 })
3223 }
Adam Langley2ff79332017-02-28 13:45:39 -08003224
3225 testCases = append(testCases, testCase{
3226 testType: serverTest,
3227 name: ver.name + "-Server-CertReq-CA-List",
3228 config: Config{
3229 MinVersion: ver.version,
3230 MaxVersion: ver.version,
3231 Certificates: []Certificate{rsaCertificate},
3232 Bugs: ProtocolBugs{
3233 ExpectCertificateReqNames: caNames,
3234 },
3235 },
3236 flags: []string{
3237 "-require-any-client-certificate",
3238 "-use-client-ca-list", encodeDERValues(caNames),
3239 },
3240 })
3241
3242 testCases = append(testCases, testCase{
3243 testType: clientTest,
3244 name: ver.name + "-Client-CertReq-CA-List",
3245 config: Config{
3246 MinVersion: ver.version,
3247 MaxVersion: ver.version,
3248 Certificates: []Certificate{rsaCertificate},
3249 ClientAuth: RequireAnyClientCert,
3250 ClientCAs: certPool,
3251 },
3252 flags: []string{
3253 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3254 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3255 "-expect-client-ca-list", encodeDERValues(caNames),
3256 },
3257 })
David Benjamin636293b2014-07-08 17:59:18 -04003258 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003259
David Benjaminc032dfa2016-05-12 14:54:57 -04003260 // Client auth is only legal in certificate-based ciphers.
3261 testCases = append(testCases, testCase{
3262 testType: clientTest,
3263 name: "ClientAuth-PSK",
3264 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003265 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003266 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3267 PreSharedKey: []byte("secret"),
3268 ClientAuth: RequireAnyClientCert,
3269 },
3270 flags: []string{
3271 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3272 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3273 "-psk", "secret",
3274 },
3275 shouldFail: true,
3276 expectedError: ":UNEXPECTED_MESSAGE:",
3277 })
3278 testCases = append(testCases, testCase{
3279 testType: clientTest,
3280 name: "ClientAuth-ECDHE_PSK",
3281 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003282 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003283 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3284 PreSharedKey: []byte("secret"),
3285 ClientAuth: RequireAnyClientCert,
3286 },
3287 flags: []string{
3288 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3289 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3290 "-psk", "secret",
3291 },
3292 shouldFail: true,
3293 expectedError: ":UNEXPECTED_MESSAGE:",
3294 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003295
3296 // Regression test for a bug where the client CA list, if explicitly
3297 // set to NULL, was mis-encoded.
3298 testCases = append(testCases, testCase{
3299 testType: serverTest,
3300 name: "Null-Client-CA-List",
3301 config: Config{
3302 MaxVersion: VersionTLS12,
3303 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003304 Bugs: ProtocolBugs{
3305 ExpectCertificateReqNames: [][]byte{},
3306 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003307 },
3308 flags: []string{
3309 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003310 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003311 },
3312 })
David Benjamin636293b2014-07-08 17:59:18 -04003313}
3314
Adam Langley75712922014-10-10 16:23:43 -07003315func addExtendedMasterSecretTests() {
3316 const expectEMSFlag = "-expect-extended-master-secret"
3317
3318 for _, with := range []bool{false, true} {
3319 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003320 if with {
3321 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003322 }
3323
3324 for _, isClient := range []bool{false, true} {
3325 suffix := "-Server"
3326 testType := serverTest
3327 if isClient {
3328 suffix = "-Client"
3329 testType = clientTest
3330 }
3331
3332 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003333 // In TLS 1.3, the extension is irrelevant and
3334 // always reports as enabled.
3335 var flags []string
3336 if with || ver.version >= VersionTLS13 {
3337 flags = []string{expectEMSFlag}
3338 }
3339
Adam Langley75712922014-10-10 16:23:43 -07003340 test := testCase{
3341 testType: testType,
3342 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3343 config: Config{
3344 MinVersion: ver.version,
3345 MaxVersion: ver.version,
3346 Bugs: ProtocolBugs{
3347 NoExtendedMasterSecret: !with,
3348 RequireExtendedMasterSecret: with,
3349 },
3350 },
David Benjamin48cae082014-10-27 01:06:24 -04003351 flags: flags,
3352 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003353 }
3354 if test.shouldFail {
3355 test.expectedLocalError = "extended master secret required but not supported by peer"
3356 }
3357 testCases = append(testCases, test)
3358 }
3359 }
3360 }
3361
Adam Langleyba5934b2015-06-02 10:50:35 -07003362 for _, isClient := range []bool{false, true} {
3363 for _, supportedInFirstConnection := range []bool{false, true} {
3364 for _, supportedInResumeConnection := range []bool{false, true} {
3365 boolToWord := func(b bool) string {
3366 if b {
3367 return "Yes"
3368 }
3369 return "No"
3370 }
3371 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3372 if isClient {
3373 suffix += "Client"
3374 } else {
3375 suffix += "Server"
3376 }
3377
3378 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003379 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003380 Bugs: ProtocolBugs{
3381 RequireExtendedMasterSecret: true,
3382 },
3383 }
3384
3385 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003386 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003387 Bugs: ProtocolBugs{
3388 NoExtendedMasterSecret: true,
3389 },
3390 }
3391
3392 test := testCase{
3393 name: "ExtendedMasterSecret-" + suffix,
3394 resumeSession: true,
3395 }
3396
3397 if !isClient {
3398 test.testType = serverTest
3399 }
3400
3401 if supportedInFirstConnection {
3402 test.config = supportedConfig
3403 } else {
3404 test.config = noSupportConfig
3405 }
3406
3407 if supportedInResumeConnection {
3408 test.resumeConfig = &supportedConfig
3409 } else {
3410 test.resumeConfig = &noSupportConfig
3411 }
3412
3413 switch suffix {
3414 case "YesToYes-Client", "YesToYes-Server":
3415 // When a session is resumed, it should
3416 // still be aware that its master
3417 // secret was generated via EMS and
3418 // thus it's safe to use tls-unique.
3419 test.flags = []string{expectEMSFlag}
3420 case "NoToYes-Server":
3421 // If an original connection did not
3422 // contain EMS, but a resumption
3423 // handshake does, then a server should
3424 // not resume the session.
3425 test.expectResumeRejected = true
3426 case "YesToNo-Server":
3427 // Resuming an EMS session without the
3428 // EMS extension should cause the
3429 // server to abort the connection.
3430 test.shouldFail = true
3431 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3432 case "NoToYes-Client":
3433 // A client should abort a connection
3434 // where the server resumed a non-EMS
3435 // session but echoed the EMS
3436 // extension.
3437 test.shouldFail = true
3438 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3439 case "YesToNo-Client":
3440 // A client should abort a connection
3441 // where the server didn't echo EMS
3442 // when the session used it.
3443 test.shouldFail = true
3444 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3445 }
3446
3447 testCases = append(testCases, test)
3448 }
3449 }
3450 }
David Benjamin163c9562016-08-29 23:14:17 -04003451
3452 // Switching EMS on renegotiation is forbidden.
3453 testCases = append(testCases, testCase{
3454 name: "ExtendedMasterSecret-Renego-NoEMS",
3455 config: Config{
3456 MaxVersion: VersionTLS12,
3457 Bugs: ProtocolBugs{
3458 NoExtendedMasterSecret: true,
3459 NoExtendedMasterSecretOnRenegotiation: true,
3460 },
3461 },
3462 renegotiate: 1,
3463 flags: []string{
3464 "-renegotiate-freely",
3465 "-expect-total-renegotiations", "1",
3466 },
3467 })
3468
3469 testCases = append(testCases, testCase{
3470 name: "ExtendedMasterSecret-Renego-Upgrade",
3471 config: Config{
3472 MaxVersion: VersionTLS12,
3473 Bugs: ProtocolBugs{
3474 NoExtendedMasterSecret: true,
3475 },
3476 },
3477 renegotiate: 1,
3478 flags: []string{
3479 "-renegotiate-freely",
3480 "-expect-total-renegotiations", "1",
3481 },
3482 shouldFail: true,
3483 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3484 })
3485
3486 testCases = append(testCases, testCase{
3487 name: "ExtendedMasterSecret-Renego-Downgrade",
3488 config: Config{
3489 MaxVersion: VersionTLS12,
3490 Bugs: ProtocolBugs{
3491 NoExtendedMasterSecretOnRenegotiation: true,
3492 },
3493 },
3494 renegotiate: 1,
3495 flags: []string{
3496 "-renegotiate-freely",
3497 "-expect-total-renegotiations", "1",
3498 },
3499 shouldFail: true,
3500 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3501 })
Adam Langley75712922014-10-10 16:23:43 -07003502}
3503
David Benjamin582ba042016-07-07 12:33:25 -07003504type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003505 protocol protocol
3506 async bool
3507 splitHandshake bool
3508 packHandshakeFlight bool
3509 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003510}
3511
David Benjamin43ec06f2014-08-05 02:28:57 -04003512// Adds tests that try to cover the range of the handshake state machine, under
3513// various conditions. Some of these are redundant with other tests, but they
3514// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003515func addAllStateMachineCoverageTests() {
3516 for _, async := range []bool{false, true} {
3517 for _, protocol := range []protocol{tls, dtls} {
3518 addStateMachineCoverageTests(stateMachineTestConfig{
3519 protocol: protocol,
3520 async: async,
3521 })
3522 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003523 protocol: protocol,
3524 async: async,
3525 implicitHandshake: true,
3526 })
3527 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003528 protocol: protocol,
3529 async: async,
3530 splitHandshake: true,
3531 })
3532 if protocol == tls {
3533 addStateMachineCoverageTests(stateMachineTestConfig{
3534 protocol: protocol,
3535 async: async,
3536 packHandshakeFlight: true,
3537 })
3538 }
3539 }
3540 }
3541}
3542
3543func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 var tests []testCase
3545
3546 // Basic handshake, with resumption. Client and server,
3547 // session ID and session ticket.
3548 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003549 name: "Basic-Client",
3550 config: Config{
3551 MaxVersion: VersionTLS12,
3552 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003553 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003554 // Ensure session tickets are used, not session IDs.
3555 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 })
3557 tests = append(tests, testCase{
3558 name: "Basic-Client-RenewTicket",
3559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003561 Bugs: ProtocolBugs{
3562 RenewTicketOnResume: true,
3563 },
3564 },
David Benjamin46662482016-08-17 00:51:00 -04003565 flags: []string{"-expect-ticket-renewal"},
3566 resumeSession: true,
3567 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003568 })
3569 tests = append(tests, testCase{
3570 name: "Basic-Client-NoTicket",
3571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003572 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003573 SessionTicketsDisabled: true,
3574 },
3575 resumeSession: true,
3576 })
3577 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003578 testType: serverTest,
3579 name: "Basic-Server",
3580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003581 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003582 Bugs: ProtocolBugs{
3583 RequireSessionTickets: true,
3584 },
3585 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003587 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003588 })
3589 tests = append(tests, testCase{
3590 testType: serverTest,
3591 name: "Basic-Server-NoTickets",
3592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003593 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003594 SessionTicketsDisabled: true,
3595 },
3596 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003597 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003598 })
3599 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003600 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003601 name: "Basic-Server-EarlyCallback",
3602 config: Config{
3603 MaxVersion: VersionTLS12,
3604 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003605 flags: []string{"-use-early-callback"},
3606 resumeSession: true,
3607 })
3608
Steven Valdez143e8b32016-07-11 13:19:03 -04003609 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003610 if config.protocol == tls {
3611 tests = append(tests, testCase{
3612 name: "TLS13-1RTT-Client",
3613 config: Config{
3614 MaxVersion: VersionTLS13,
3615 MinVersion: VersionTLS13,
3616 },
David Benjamin46662482016-08-17 00:51:00 -04003617 resumeSession: true,
3618 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003619 })
3620
3621 tests = append(tests, testCase{
3622 testType: serverTest,
3623 name: "TLS13-1RTT-Server",
3624 config: Config{
3625 MaxVersion: VersionTLS13,
3626 MinVersion: VersionTLS13,
3627 },
David Benjamin46662482016-08-17 00:51:00 -04003628 resumeSession: true,
3629 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003630 // TLS 1.3 uses tickets, so the session should not be
3631 // cached statefully.
3632 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003633 })
3634
3635 tests = append(tests, testCase{
3636 name: "TLS13-HelloRetryRequest-Client",
3637 config: Config{
3638 MaxVersion: VersionTLS13,
3639 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003640 // P-384 requires a HelloRetryRequest against BoringSSL's default
3641 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003642 CurvePreferences: []CurveID{CurveP384},
3643 Bugs: ProtocolBugs{
3644 ExpectMissingKeyShare: true,
3645 },
3646 },
3647 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3648 resumeSession: true,
3649 })
3650
3651 tests = append(tests, testCase{
3652 testType: serverTest,
3653 name: "TLS13-HelloRetryRequest-Server",
3654 config: Config{
3655 MaxVersion: VersionTLS13,
3656 MinVersion: VersionTLS13,
3657 // Require a HelloRetryRequest for every curve.
3658 DefaultCurves: []CurveID{},
3659 },
3660 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3661 resumeSession: true,
3662 })
Steven Valdez2d850622017-01-11 11:34:52 -05003663
Steven Valdez2d850622017-01-11 11:34:52 -05003664 tests = append(tests, testCase{
3665 testType: clientTest,
3666 name: "TLS13-EarlyData-Client",
3667 config: Config{
3668 MaxVersion: VersionTLS13,
3669 MinVersion: VersionTLS13,
3670 MaxEarlyDataSize: 16384,
3671 },
Steven Valdeze831a812017-03-09 14:56:07 -05003672 resumeConfig: &Config{
3673 MaxVersion: VersionTLS13,
3674 MinVersion: VersionTLS13,
3675 MaxEarlyDataSize: 16384,
3676 Bugs: ProtocolBugs{
3677 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3678 },
3679 },
Steven Valdez2d850622017-01-11 11:34:52 -05003680 resumeSession: true,
3681 flags: []string{
3682 "-enable-early-data",
3683 "-expect-early-data-info",
3684 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003685 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003686 },
3687 })
3688
3689 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003690 testType: clientTest,
3691 name: "TLS13-EarlyData-TooMuchData-Client",
3692 config: Config{
3693 MaxVersion: VersionTLS13,
3694 MinVersion: VersionTLS13,
3695 MaxEarlyDataSize: 2,
3696 },
3697 resumeConfig: &Config{
3698 MaxVersion: VersionTLS13,
3699 MinVersion: VersionTLS13,
3700 MaxEarlyDataSize: 2,
3701 Bugs: ProtocolBugs{
3702 ExpectEarlyData: [][]byte{{'h', 'e'}},
3703 },
3704 },
3705 resumeShimPrefix: "llo",
3706 resumeSession: true,
3707 flags: []string{
3708 "-enable-early-data",
3709 "-expect-early-data-info",
3710 "-expect-accept-early-data",
3711 "-on-resume-shim-writes-first",
3712 },
3713 })
3714
3715 // Unfinished writes can only be tested when operations are async. EarlyData
3716 // can't be tested as part of an ImplicitHandshake in this case since
3717 // otherwise the early data will be sent as normal data.
3718 if config.async && !config.implicitHandshake {
3719 tests = append(tests, testCase{
3720 testType: clientTest,
3721 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3722 config: Config{
3723 MaxVersion: VersionTLS13,
3724 MinVersion: VersionTLS13,
3725 MaxEarlyDataSize: 16384,
3726 },
3727 resumeConfig: &Config{
3728 MaxVersion: VersionTLS13,
3729 MinVersion: VersionTLS13,
3730 MaxEarlyDataSize: 16384,
3731 Bugs: ProtocolBugs{
3732 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3733 },
3734 },
3735 resumeSession: true,
3736 flags: []string{
3737 "-enable-early-data",
3738 "-expect-early-data-info",
3739 "-expect-accept-early-data",
3740 "-on-resume-read-with-unfinished-write",
3741 "-on-resume-shim-writes-first",
3742 },
3743 })
3744
3745 // Rejected unfinished writes are discarded (from the
3746 // perspective of the calling application) on 0-RTT
3747 // reject.
3748 tests = append(tests, testCase{
3749 testType: clientTest,
3750 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3751 config: Config{
3752 MaxVersion: VersionTLS13,
3753 MinVersion: VersionTLS13,
3754 MaxEarlyDataSize: 16384,
3755 },
3756 resumeConfig: &Config{
3757 MaxVersion: VersionTLS13,
3758 MinVersion: VersionTLS13,
3759 MaxEarlyDataSize: 16384,
3760 Bugs: ProtocolBugs{
3761 AlwaysRejectEarlyData: true,
3762 },
3763 },
3764 resumeSession: true,
3765 flags: []string{
3766 "-enable-early-data",
3767 "-expect-early-data-info",
3768 "-expect-reject-early-data",
3769 "-on-resume-read-with-unfinished-write",
3770 "-on-resume-shim-writes-first",
3771 },
3772 })
3773 }
3774
3775 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003776 testType: serverTest,
3777 name: "TLS13-EarlyData-Server",
3778 config: Config{
3779 MaxVersion: VersionTLS13,
3780 MinVersion: VersionTLS13,
3781 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003782 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003783 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003784 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003785 },
3786 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003787 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003788 resumeSession: true,
3789 flags: []string{
3790 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003791 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003792 },
3793 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003794
3795 tests = append(tests, testCase{
3796 testType: serverTest,
3797 name: "TLS13-MaxEarlyData-Server",
3798 config: Config{
3799 MaxVersion: VersionTLS13,
3800 MinVersion: VersionTLS13,
3801 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003802 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003803 ExpectEarlyDataAccepted: true,
3804 },
3805 },
3806 messageCount: 2,
3807 resumeSession: true,
3808 flags: []string{
3809 "-enable-early-data",
3810 "-expect-accept-early-data",
3811 },
3812 shouldFail: true,
3813 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3814 })
David Benjamine73c7f42016-08-17 00:29:33 -04003815 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003816
David Benjamin760b1dd2015-05-15 23:33:48 -04003817 // TLS client auth.
3818 tests = append(tests, testCase{
3819 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003820 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003822 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003823 ClientAuth: RequestClientCert,
3824 },
3825 })
3826 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003827 testType: serverTest,
3828 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003829 config: Config{
3830 MaxVersion: VersionTLS12,
3831 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003832 // Setting SSL_VERIFY_PEER allows anonymous clients.
3833 flags: []string{"-verify-peer"},
3834 })
David Benjamin582ba042016-07-07 12:33:25 -07003835 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003836 tests = append(tests, testCase{
3837 testType: clientTest,
3838 name: "ClientAuth-NoCertificate-Client-SSL3",
3839 config: Config{
3840 MaxVersion: VersionSSL30,
3841 ClientAuth: RequestClientCert,
3842 },
3843 })
3844 tests = append(tests, testCase{
3845 testType: serverTest,
3846 name: "ClientAuth-NoCertificate-Server-SSL3",
3847 config: Config{
3848 MaxVersion: VersionSSL30,
3849 },
3850 // Setting SSL_VERIFY_PEER allows anonymous clients.
3851 flags: []string{"-verify-peer"},
3852 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003853 tests = append(tests, testCase{
3854 testType: clientTest,
3855 name: "ClientAuth-NoCertificate-Client-TLS13",
3856 config: Config{
3857 MaxVersion: VersionTLS13,
3858 ClientAuth: RequestClientCert,
3859 },
3860 })
3861 tests = append(tests, testCase{
3862 testType: serverTest,
3863 name: "ClientAuth-NoCertificate-Server-TLS13",
3864 config: Config{
3865 MaxVersion: VersionTLS13,
3866 },
3867 // Setting SSL_VERIFY_PEER allows anonymous clients.
3868 flags: []string{"-verify-peer"},
3869 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003870 }
3871 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003872 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003873 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003875 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003876 ClientAuth: RequireAnyClientCert,
3877 },
3878 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003879 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3880 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 },
3882 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003883 tests = append(tests, testCase{
3884 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003885 name: "ClientAuth-RSA-Client-TLS13",
3886 config: Config{
3887 MaxVersion: VersionTLS13,
3888 ClientAuth: RequireAnyClientCert,
3889 },
3890 flags: []string{
3891 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3892 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3893 },
3894 })
3895 tests = append(tests, testCase{
3896 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003897 name: "ClientAuth-ECDSA-Client",
3898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003899 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003900 ClientAuth: RequireAnyClientCert,
3901 },
3902 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003903 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3904 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003905 },
3906 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003907 tests = append(tests, testCase{
3908 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003909 name: "ClientAuth-ECDSA-Client-TLS13",
3910 config: Config{
3911 MaxVersion: VersionTLS13,
3912 ClientAuth: RequireAnyClientCert,
3913 },
3914 flags: []string{
3915 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3916 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3917 },
3918 })
3919 tests = append(tests, testCase{
3920 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003921 name: "ClientAuth-NoCertificate-OldCallback",
3922 config: Config{
3923 MaxVersion: VersionTLS12,
3924 ClientAuth: RequestClientCert,
3925 },
3926 flags: []string{"-use-old-client-cert-callback"},
3927 })
3928 tests = append(tests, testCase{
3929 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003930 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3931 config: Config{
3932 MaxVersion: VersionTLS13,
3933 ClientAuth: RequestClientCert,
3934 },
3935 flags: []string{"-use-old-client-cert-callback"},
3936 })
3937 tests = append(tests, testCase{
3938 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003939 name: "ClientAuth-OldCallback",
3940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003941 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003942 ClientAuth: RequireAnyClientCert,
3943 },
3944 flags: []string{
3945 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3946 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3947 "-use-old-client-cert-callback",
3948 },
3949 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003951 testType: clientTest,
3952 name: "ClientAuth-OldCallback-TLS13",
3953 config: Config{
3954 MaxVersion: VersionTLS13,
3955 ClientAuth: RequireAnyClientCert,
3956 },
3957 flags: []string{
3958 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3959 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3960 "-use-old-client-cert-callback",
3961 },
3962 })
3963 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003964 testType: serverTest,
3965 name: "ClientAuth-Server",
3966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003968 Certificates: []Certificate{rsaCertificate},
3969 },
3970 flags: []string{"-require-any-client-certificate"},
3971 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003972 tests = append(tests, testCase{
3973 testType: serverTest,
3974 name: "ClientAuth-Server-TLS13",
3975 config: Config{
3976 MaxVersion: VersionTLS13,
3977 Certificates: []Certificate{rsaCertificate},
3978 },
3979 flags: []string{"-require-any-client-certificate"},
3980 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003981
David Benjamin4c3ddf72016-06-29 18:13:53 -04003982 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 tests = append(tests, testCase{
3984 testType: serverTest,
3985 name: "Basic-Server-RSA",
3986 config: Config{
3987 MaxVersion: VersionTLS12,
3988 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3989 },
3990 flags: []string{
3991 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3992 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3993 },
3994 })
3995 tests = append(tests, testCase{
3996 testType: serverTest,
3997 name: "Basic-Server-ECDHE-RSA",
3998 config: Config{
3999 MaxVersion: VersionTLS12,
4000 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4001 },
4002 flags: []string{
4003 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4004 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4005 },
4006 })
4007 tests = append(tests, testCase{
4008 testType: serverTest,
4009 name: "Basic-Server-ECDHE-ECDSA",
4010 config: Config{
4011 MaxVersion: VersionTLS12,
4012 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4013 },
4014 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004015 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4016 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004017 },
4018 })
David Benjamin69522112017-03-28 15:38:29 -05004019 tests = append(tests, testCase{
4020 testType: serverTest,
4021 name: "Basic-Server-Ed25519",
4022 config: Config{
4023 MaxVersion: VersionTLS12,
4024 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4025 },
4026 flags: []string{
4027 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4028 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4029 "-enable-ed25519",
4030 },
4031 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004032
David Benjamin760b1dd2015-05-15 23:33:48 -04004033 // No session ticket support; server doesn't send NewSessionTicket.
4034 tests = append(tests, testCase{
4035 name: "SessionTicketsDisabled-Client",
4036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004037 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004038 SessionTicketsDisabled: true,
4039 },
4040 })
4041 tests = append(tests, testCase{
4042 testType: serverTest,
4043 name: "SessionTicketsDisabled-Server",
4044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004045 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004046 SessionTicketsDisabled: true,
4047 },
4048 })
4049
4050 // Skip ServerKeyExchange in PSK key exchange if there's no
4051 // identity hint.
4052 tests = append(tests, testCase{
4053 name: "EmptyPSKHint-Client",
4054 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004055 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004056 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4057 PreSharedKey: []byte("secret"),
4058 },
4059 flags: []string{"-psk", "secret"},
4060 })
4061 tests = append(tests, testCase{
4062 testType: serverTest,
4063 name: "EmptyPSKHint-Server",
4064 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004065 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004066 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4067 PreSharedKey: []byte("secret"),
4068 },
4069 flags: []string{"-psk", "secret"},
4070 })
4071
David Benjamin4c3ddf72016-06-29 18:13:53 -04004072 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004073 tests = append(tests, testCase{
4074 testType: clientTest,
4075 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004076 config: Config{
4077 MaxVersion: VersionTLS12,
4078 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004079 flags: []string{
4080 "-enable-ocsp-stapling",
4081 "-expect-ocsp-response",
4082 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004083 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004084 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004085 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004086 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004087 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004088 testType: serverTest,
4089 name: "OCSPStapling-Server",
4090 config: Config{
4091 MaxVersion: VersionTLS12,
4092 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004093 expectedOCSPResponse: testOCSPResponse,
4094 flags: []string{
4095 "-ocsp-response",
4096 base64.StdEncoding.EncodeToString(testOCSPResponse),
4097 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004098 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004099 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004100 tests = append(tests, testCase{
4101 testType: clientTest,
4102 name: "OCSPStapling-Client-TLS13",
4103 config: Config{
4104 MaxVersion: VersionTLS13,
4105 },
4106 flags: []string{
4107 "-enable-ocsp-stapling",
4108 "-expect-ocsp-response",
4109 base64.StdEncoding.EncodeToString(testOCSPResponse),
4110 "-verify-peer",
4111 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004112 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004113 })
4114 tests = append(tests, testCase{
4115 testType: serverTest,
4116 name: "OCSPStapling-Server-TLS13",
4117 config: Config{
4118 MaxVersion: VersionTLS13,
4119 },
4120 expectedOCSPResponse: testOCSPResponse,
4121 flags: []string{
4122 "-ocsp-response",
4123 base64.StdEncoding.EncodeToString(testOCSPResponse),
4124 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004125 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004126 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004127
David Benjamin4c3ddf72016-06-29 18:13:53 -04004128 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004129 for _, vers := range tlsVersions {
4130 if config.protocol == dtls && !vers.hasDTLS {
4131 continue
4132 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004133 for _, testType := range []testType{clientTest, serverTest} {
4134 suffix := "-Client"
4135 if testType == serverTest {
4136 suffix = "-Server"
4137 }
4138 suffix += "-" + vers.name
4139
4140 flag := "-verify-peer"
4141 if testType == serverTest {
4142 flag = "-require-any-client-certificate"
4143 }
4144
4145 tests = append(tests, testCase{
4146 testType: testType,
4147 name: "CertificateVerificationSucceed" + suffix,
4148 config: Config{
4149 MaxVersion: vers.version,
4150 Certificates: []Certificate{rsaCertificate},
4151 },
4152 flags: []string{
4153 flag,
4154 "-expect-verify-result",
4155 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004156 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004157 })
4158 tests = append(tests, testCase{
4159 testType: testType,
4160 name: "CertificateVerificationFail" + suffix,
4161 config: Config{
4162 MaxVersion: vers.version,
4163 Certificates: []Certificate{rsaCertificate},
4164 },
4165 flags: []string{
4166 flag,
4167 "-verify-fail",
4168 },
4169 shouldFail: true,
4170 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4171 })
4172 }
4173
4174 // By default, the client is in a soft fail mode where the peer
4175 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004176 tests = append(tests, testCase{
4177 testType: clientTest,
4178 name: "CertificateVerificationSoftFail-" + vers.name,
4179 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004180 MaxVersion: vers.version,
4181 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004182 },
4183 flags: []string{
4184 "-verify-fail",
4185 "-expect-verify-result",
4186 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004187 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004188 })
4189 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004190
David Benjamin1d4f4c02016-07-26 18:03:08 -04004191 tests = append(tests, testCase{
4192 name: "ShimSendAlert",
4193 flags: []string{"-send-alert"},
4194 shimWritesFirst: true,
4195 shouldFail: true,
4196 expectedLocalError: "remote error: decompression failure",
4197 })
4198
David Benjamin582ba042016-07-07 12:33:25 -07004199 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004200 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004201 name: "Renegotiate-Client",
4202 config: Config{
4203 MaxVersion: VersionTLS12,
4204 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004205 renegotiate: 1,
4206 flags: []string{
4207 "-renegotiate-freely",
4208 "-expect-total-renegotiations", "1",
4209 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004210 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004211
David Benjamin47921102016-07-28 11:29:18 -04004212 tests = append(tests, testCase{
4213 name: "SendHalfHelloRequest",
4214 config: Config{
4215 MaxVersion: VersionTLS12,
4216 Bugs: ProtocolBugs{
4217 PackHelloRequestWithFinished: config.packHandshakeFlight,
4218 },
4219 },
4220 sendHalfHelloRequest: true,
4221 flags: []string{"-renegotiate-ignore"},
4222 shouldFail: true,
4223 expectedError: ":UNEXPECTED_RECORD:",
4224 })
4225
David Benjamin760b1dd2015-05-15 23:33:48 -04004226 // NPN on client and server; results in post-handshake message.
4227 tests = append(tests, testCase{
4228 name: "NPN-Client",
4229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004230 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004231 NextProtos: []string{"foo"},
4232 },
4233 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004234 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004235 expectedNextProto: "foo",
4236 expectedNextProtoType: npn,
4237 })
4238 tests = append(tests, testCase{
4239 testType: serverTest,
4240 name: "NPN-Server",
4241 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004242 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004243 NextProtos: []string{"bar"},
4244 },
4245 flags: []string{
4246 "-advertise-npn", "\x03foo\x03bar\x03baz",
4247 "-expect-next-proto", "bar",
4248 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004249 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004250 expectedNextProto: "bar",
4251 expectedNextProtoType: npn,
4252 })
4253
4254 // TODO(davidben): Add tests for when False Start doesn't trigger.
4255
4256 // Client does False Start and negotiates NPN.
4257 tests = append(tests, testCase{
4258 name: "FalseStart",
4259 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004260 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004261 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4262 NextProtos: []string{"foo"},
4263 Bugs: ProtocolBugs{
4264 ExpectFalseStart: true,
4265 },
4266 },
4267 flags: []string{
4268 "-false-start",
4269 "-select-next-proto", "foo",
4270 },
4271 shimWritesFirst: true,
4272 resumeSession: true,
4273 })
4274
4275 // Client does False Start and negotiates ALPN.
4276 tests = append(tests, testCase{
4277 name: "FalseStart-ALPN",
4278 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004279 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004280 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4281 NextProtos: []string{"foo"},
4282 Bugs: ProtocolBugs{
4283 ExpectFalseStart: true,
4284 },
4285 },
4286 flags: []string{
4287 "-false-start",
4288 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004289 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004290 },
4291 shimWritesFirst: true,
4292 resumeSession: true,
4293 })
4294
David Benjamin760b1dd2015-05-15 23:33:48 -04004295 // False Start without session tickets.
4296 tests = append(tests, testCase{
4297 name: "FalseStart-SessionTicketsDisabled",
4298 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004299 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004300 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4301 NextProtos: []string{"foo"},
4302 SessionTicketsDisabled: true,
4303 Bugs: ProtocolBugs{
4304 ExpectFalseStart: true,
4305 },
4306 },
4307 flags: []string{
4308 "-false-start",
4309 "-select-next-proto", "foo",
4310 },
4311 shimWritesFirst: true,
4312 })
4313
4314 // Server parses a V2ClientHello.
4315 tests = append(tests, testCase{
4316 testType: serverTest,
4317 name: "SendV2ClientHello",
4318 config: Config{
4319 // Choose a cipher suite that does not involve
4320 // elliptic curves, so no extensions are
4321 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004322 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004323 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004324 Bugs: ProtocolBugs{
4325 SendV2ClientHello: true,
4326 },
4327 },
4328 })
4329
Nick Harper60a85cb2016-09-23 16:25:11 -07004330 // Test Channel ID
4331 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004332 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004333 continue
4334 }
4335 // Client sends a Channel ID.
4336 tests = append(tests, testCase{
4337 name: "ChannelID-Client-" + ver.name,
4338 config: Config{
4339 MaxVersion: ver.version,
4340 RequestChannelID: true,
4341 },
4342 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4343 resumeSession: true,
4344 expectChannelID: true,
4345 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004346
Nick Harper60a85cb2016-09-23 16:25:11 -07004347 // Server accepts a Channel ID.
4348 tests = append(tests, testCase{
4349 testType: serverTest,
4350 name: "ChannelID-Server-" + ver.name,
4351 config: Config{
4352 MaxVersion: ver.version,
4353 ChannelID: channelIDKey,
4354 },
4355 flags: []string{
4356 "-expect-channel-id",
4357 base64.StdEncoding.EncodeToString(channelIDBytes),
4358 },
4359 resumeSession: true,
4360 expectChannelID: true,
4361 })
4362
4363 tests = append(tests, testCase{
4364 testType: serverTest,
4365 name: "InvalidChannelIDSignature-" + ver.name,
4366 config: Config{
4367 MaxVersion: ver.version,
4368 ChannelID: channelIDKey,
4369 Bugs: ProtocolBugs{
4370 InvalidChannelIDSignature: true,
4371 },
4372 },
4373 flags: []string{"-enable-channel-id"},
4374 shouldFail: true,
4375 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4376 })
4377 }
David Benjamin30789da2015-08-29 22:56:45 -04004378
David Benjaminf8fcdf32016-06-08 15:56:13 -04004379 // Channel ID and NPN at the same time, to ensure their relative
4380 // ordering is correct.
4381 tests = append(tests, testCase{
4382 name: "ChannelID-NPN-Client",
4383 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004384 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004385 RequestChannelID: true,
4386 NextProtos: []string{"foo"},
4387 },
4388 flags: []string{
4389 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4390 "-select-next-proto", "foo",
4391 },
4392 resumeSession: true,
4393 expectChannelID: true,
4394 expectedNextProto: "foo",
4395 expectedNextProtoType: npn,
4396 })
4397 tests = append(tests, testCase{
4398 testType: serverTest,
4399 name: "ChannelID-NPN-Server",
4400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004401 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004402 ChannelID: channelIDKey,
4403 NextProtos: []string{"bar"},
4404 },
4405 flags: []string{
4406 "-expect-channel-id",
4407 base64.StdEncoding.EncodeToString(channelIDBytes),
4408 "-advertise-npn", "\x03foo\x03bar\x03baz",
4409 "-expect-next-proto", "bar",
4410 },
4411 resumeSession: true,
4412 expectChannelID: true,
4413 expectedNextProto: "bar",
4414 expectedNextProtoType: npn,
4415 })
4416
David Benjamin30789da2015-08-29 22:56:45 -04004417 // Bidirectional shutdown with the runner initiating.
4418 tests = append(tests, testCase{
4419 name: "Shutdown-Runner",
4420 config: Config{
4421 Bugs: ProtocolBugs{
4422 ExpectCloseNotify: true,
4423 },
4424 },
4425 flags: []string{"-check-close-notify"},
4426 })
4427
David Benjamine3843d42017-03-25 18:00:56 -05004428 if !config.implicitHandshake {
4429 // Bidirectional shutdown with the shim initiating. The runner,
4430 // in the meantime, sends garbage before the close_notify which
4431 // the shim must ignore. This test is disabled under implicit
4432 // handshake tests because the shim never reads or writes.
4433 tests = append(tests, testCase{
4434 name: "Shutdown-Shim",
4435 config: Config{
4436 MaxVersion: VersionTLS12,
4437 Bugs: ProtocolBugs{
4438 ExpectCloseNotify: true,
4439 },
David Benjamin30789da2015-08-29 22:56:45 -04004440 },
David Benjamine3843d42017-03-25 18:00:56 -05004441 shimShutsDown: true,
4442 sendEmptyRecords: 1,
4443 sendWarningAlerts: 1,
4444 flags: []string{"-check-close-notify"},
4445 })
4446 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004447 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004448 // TODO(davidben): DTLS 1.3 will want a similar thing for
4449 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004450 tests = append(tests, testCase{
4451 name: "SkipHelloVerifyRequest",
4452 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004453 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004454 Bugs: ProtocolBugs{
4455 SkipHelloVerifyRequest: true,
4456 },
4457 },
4458 })
4459 }
4460
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004462 test.protocol = config.protocol
4463 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004464 test.name += "-DTLS"
4465 }
David Benjamin582ba042016-07-07 12:33:25 -07004466 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004467 test.name += "-Async"
4468 test.flags = append(test.flags, "-async")
4469 } else {
4470 test.name += "-Sync"
4471 }
David Benjamin582ba042016-07-07 12:33:25 -07004472 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004473 test.name += "-SplitHandshakeRecords"
4474 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004475 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004476 test.config.Bugs.MaxPacketLength = 256
4477 test.flags = append(test.flags, "-mtu", "256")
4478 }
4479 }
David Benjamin582ba042016-07-07 12:33:25 -07004480 if config.packHandshakeFlight {
4481 test.name += "-PackHandshakeFlight"
4482 test.config.Bugs.PackHandshakeFlight = true
4483 }
David Benjamine3843d42017-03-25 18:00:56 -05004484 if config.implicitHandshake {
4485 test.name += "-ImplicitHandshake"
4486 test.flags = append(test.flags, "-implicit-handshake")
4487 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004488 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004489 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004490}
4491
Adam Langley524e7172015-02-20 16:04:00 -08004492func addDDoSCallbackTests() {
4493 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004494 for _, resume := range []bool{false, true} {
4495 suffix := "Resume"
4496 if resume {
4497 suffix = "No" + suffix
4498 }
4499
4500 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004501 testType: serverTest,
4502 name: "Server-DDoS-OK-" + suffix,
4503 config: Config{
4504 MaxVersion: VersionTLS12,
4505 },
Adam Langley524e7172015-02-20 16:04:00 -08004506 flags: []string{"-install-ddos-callback"},
4507 resumeSession: resume,
4508 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004509 testCases = append(testCases, testCase{
4510 testType: serverTest,
4511 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4512 config: Config{
4513 MaxVersion: VersionTLS13,
4514 },
4515 flags: []string{"-install-ddos-callback"},
4516 resumeSession: resume,
4517 })
Adam Langley524e7172015-02-20 16:04:00 -08004518
4519 failFlag := "-fail-ddos-callback"
4520 if resume {
4521 failFlag = "-fail-second-ddos-callback"
4522 }
4523 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004524 testType: serverTest,
4525 name: "Server-DDoS-Reject-" + suffix,
4526 config: Config{
4527 MaxVersion: VersionTLS12,
4528 },
David Benjamin2c66e072016-09-16 15:58:00 -04004529 flags: []string{"-install-ddos-callback", failFlag},
4530 resumeSession: resume,
4531 shouldFail: true,
4532 expectedError: ":CONNECTION_REJECTED:",
4533 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004534 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004535 testCases = append(testCases, testCase{
4536 testType: serverTest,
4537 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4538 config: Config{
4539 MaxVersion: VersionTLS13,
4540 },
David Benjamin2c66e072016-09-16 15:58:00 -04004541 flags: []string{"-install-ddos-callback", failFlag},
4542 resumeSession: resume,
4543 shouldFail: true,
4544 expectedError: ":CONNECTION_REJECTED:",
4545 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004546 })
Adam Langley524e7172015-02-20 16:04:00 -08004547 }
4548}
4549
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004550func addVersionNegotiationTests() {
4551 for i, shimVers := range tlsVersions {
4552 // Assemble flags to disable all newer versions on the shim.
4553 var flags []string
4554 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004555 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004556 }
4557
Steven Valdezfdd10992016-09-15 16:27:05 -04004558 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004559 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004560 protocols := []protocol{tls}
4561 if runnerVers.hasDTLS && shimVers.hasDTLS {
4562 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004563 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004564 for _, protocol := range protocols {
4565 expectedVersion := shimVers.version
4566 if runnerVers.version < shimVers.version {
4567 expectedVersion = runnerVers.version
4568 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004569
David Benjamin8b8c0062014-11-23 02:47:52 -05004570 suffix := shimVers.name + "-" + runnerVers.name
4571 if protocol == dtls {
4572 suffix += "-DTLS"
4573 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004574
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004575 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004576 clientVers := shimVers.version
4577 if clientVers > VersionTLS10 {
4578 clientVers = VersionTLS10
4579 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004580 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004581 serverVers := expectedVersion
4582 if expectedVersion >= VersionTLS13 {
4583 serverVers = VersionTLS10
4584 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004585 serverVers = versionToWire(serverVers, protocol == dtls)
4586
David Benjamin8b8c0062014-11-23 02:47:52 -05004587 testCases = append(testCases, testCase{
4588 protocol: protocol,
4589 testType: clientTest,
4590 name: "VersionNegotiation-Client-" + suffix,
4591 config: Config{
4592 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004593 Bugs: ProtocolBugs{
4594 ExpectInitialRecordVersion: clientVers,
4595 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004596 },
4597 flags: flags,
4598 expectedVersion: expectedVersion,
4599 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004600 testCases = append(testCases, testCase{
4601 protocol: protocol,
4602 testType: clientTest,
4603 name: "VersionNegotiation-Client2-" + suffix,
4604 config: Config{
4605 MaxVersion: runnerVers.version,
4606 Bugs: ProtocolBugs{
4607 ExpectInitialRecordVersion: clientVers,
4608 },
4609 },
David Benjamin353577c2017-06-29 15:54:58 -04004610 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004611 expectedVersion: expectedVersion,
4612 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004613
4614 testCases = append(testCases, testCase{
4615 protocol: protocol,
4616 testType: serverTest,
4617 name: "VersionNegotiation-Server-" + suffix,
4618 config: Config{
4619 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004620 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004621 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004622 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004623 },
4624 flags: flags,
4625 expectedVersion: expectedVersion,
4626 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004627 testCases = append(testCases, testCase{
4628 protocol: protocol,
4629 testType: serverTest,
4630 name: "VersionNegotiation-Server2-" + suffix,
4631 config: Config{
4632 MaxVersion: runnerVers.version,
4633 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004634 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004635 },
4636 },
David Benjamin353577c2017-06-29 15:54:58 -04004637 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004638 expectedVersion: expectedVersion,
4639 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004640 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004641 }
4642 }
David Benjamin95c69562016-06-29 18:15:03 -04004643
Steven Valdezfdd10992016-09-15 16:27:05 -04004644 // Test the version extension at all versions.
4645 for _, vers := range tlsVersions {
4646 protocols := []protocol{tls}
4647 if vers.hasDTLS {
4648 protocols = append(protocols, dtls)
4649 }
4650 for _, protocol := range protocols {
4651 suffix := vers.name
4652 if protocol == dtls {
4653 suffix += "-DTLS"
4654 }
4655
4656 wireVersion := versionToWire(vers.version, protocol == dtls)
4657 testCases = append(testCases, testCase{
4658 protocol: protocol,
4659 testType: serverTest,
4660 name: "VersionNegotiationExtension-" + suffix,
4661 config: Config{
4662 Bugs: ProtocolBugs{
4663 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4664 },
4665 },
4666 expectedVersion: vers.version,
4667 })
4668 }
4669
4670 }
4671
4672 // If all versions are unknown, negotiation fails.
4673 testCases = append(testCases, testCase{
4674 testType: serverTest,
4675 name: "NoSupportedVersions",
4676 config: Config{
4677 Bugs: ProtocolBugs{
4678 SendSupportedVersions: []uint16{0x1111},
4679 },
4680 },
4681 shouldFail: true,
4682 expectedError: ":UNSUPPORTED_PROTOCOL:",
4683 })
4684 testCases = append(testCases, testCase{
4685 protocol: dtls,
4686 testType: serverTest,
4687 name: "NoSupportedVersions-DTLS",
4688 config: Config{
4689 Bugs: ProtocolBugs{
4690 SendSupportedVersions: []uint16{0x1111},
4691 },
4692 },
4693 shouldFail: true,
4694 expectedError: ":UNSUPPORTED_PROTOCOL:",
4695 })
4696
4697 testCases = append(testCases, testCase{
4698 testType: serverTest,
4699 name: "ClientHelloVersionTooHigh",
4700 config: Config{
4701 MaxVersion: VersionTLS13,
4702 Bugs: ProtocolBugs{
4703 SendClientVersion: 0x0304,
4704 OmitSupportedVersions: true,
4705 },
4706 },
4707 expectedVersion: VersionTLS12,
4708 })
4709
4710 testCases = append(testCases, testCase{
4711 testType: serverTest,
4712 name: "ConflictingVersionNegotiation",
4713 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004714 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004715 SendClientVersion: VersionTLS12,
4716 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004717 },
4718 },
David Benjaminad75a662016-09-30 15:42:59 -04004719 // The extension takes precedence over the ClientHello version.
4720 expectedVersion: VersionTLS11,
4721 })
4722
4723 testCases = append(testCases, testCase{
4724 testType: serverTest,
4725 name: "ConflictingVersionNegotiation-2",
4726 config: Config{
4727 Bugs: ProtocolBugs{
4728 SendClientVersion: VersionTLS11,
4729 SendSupportedVersions: []uint16{VersionTLS12},
4730 },
4731 },
4732 // The extension takes precedence over the ClientHello version.
4733 expectedVersion: VersionTLS12,
4734 })
4735
4736 testCases = append(testCases, testCase{
4737 testType: serverTest,
4738 name: "RejectFinalTLS13",
4739 config: Config{
4740 Bugs: ProtocolBugs{
4741 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4742 },
4743 },
4744 // We currently implement a draft TLS 1.3 version. Ensure that
4745 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004746 expectedVersion: VersionTLS12,
4747 })
4748
Brian Smithf85d3232016-10-28 10:34:06 -10004749 // Test that the maximum version is selected regardless of the
4750 // client-sent order.
4751 testCases = append(testCases, testCase{
4752 testType: serverTest,
4753 name: "IgnoreClientVersionOrder",
4754 config: Config{
4755 Bugs: ProtocolBugs{
4756 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4757 },
4758 },
4759 expectedVersion: VersionTLS13,
4760 })
4761
David Benjamin95c69562016-06-29 18:15:03 -04004762 // Test for version tolerance.
4763 testCases = append(testCases, testCase{
4764 testType: serverTest,
4765 name: "MinorVersionTolerance",
4766 config: Config{
4767 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004768 SendClientVersion: 0x03ff,
4769 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004770 },
4771 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004772 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004773 })
4774 testCases = append(testCases, testCase{
4775 testType: serverTest,
4776 name: "MajorVersionTolerance",
4777 config: Config{
4778 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004779 SendClientVersion: 0x0400,
4780 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004781 },
4782 },
David Benjaminad75a662016-09-30 15:42:59 -04004783 // TLS 1.3 must be negotiated with the supported_versions
4784 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004785 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004786 })
David Benjaminad75a662016-09-30 15:42:59 -04004787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "VersionTolerance-TLS13",
4790 config: Config{
4791 Bugs: ProtocolBugs{
4792 // Although TLS 1.3 does not use
4793 // ClientHello.version, it still tolerates high
4794 // values there.
4795 SendClientVersion: 0x0400,
4796 },
4797 },
4798 expectedVersion: VersionTLS13,
4799 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004800
David Benjamin95c69562016-06-29 18:15:03 -04004801 testCases = append(testCases, testCase{
4802 protocol: dtls,
4803 testType: serverTest,
4804 name: "MinorVersionTolerance-DTLS",
4805 config: Config{
4806 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004807 SendClientVersion: 0xfe00,
4808 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004809 },
4810 },
4811 expectedVersion: VersionTLS12,
4812 })
4813 testCases = append(testCases, testCase{
4814 protocol: dtls,
4815 testType: serverTest,
4816 name: "MajorVersionTolerance-DTLS",
4817 config: Config{
4818 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004819 SendClientVersion: 0xfdff,
4820 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004821 },
4822 },
4823 expectedVersion: VersionTLS12,
4824 })
4825
4826 // Test that versions below 3.0 are rejected.
4827 testCases = append(testCases, testCase{
4828 testType: serverTest,
4829 name: "VersionTooLow",
4830 config: Config{
4831 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004832 SendClientVersion: 0x0200,
4833 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004834 },
4835 },
4836 shouldFail: true,
4837 expectedError: ":UNSUPPORTED_PROTOCOL:",
4838 })
4839 testCases = append(testCases, testCase{
4840 protocol: dtls,
4841 testType: serverTest,
4842 name: "VersionTooLow-DTLS",
4843 config: Config{
4844 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004845 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004846 },
4847 },
4848 shouldFail: true,
4849 expectedError: ":UNSUPPORTED_PROTOCOL:",
4850 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004851
David Benjamin2dc02042016-09-19 19:57:37 -04004852 testCases = append(testCases, testCase{
4853 name: "ServerBogusVersion",
4854 config: Config{
4855 Bugs: ProtocolBugs{
4856 SendServerHelloVersion: 0x1234,
4857 },
4858 },
4859 shouldFail: true,
4860 expectedError: ":UNSUPPORTED_PROTOCOL:",
4861 })
4862
David Benjamin1f61f0d2016-07-10 12:20:35 -04004863 // Test TLS 1.3's downgrade signal.
4864 testCases = append(testCases, testCase{
4865 name: "Downgrade-TLS12-Client",
4866 config: Config{
4867 Bugs: ProtocolBugs{
4868 NegotiateVersion: VersionTLS12,
4869 },
4870 },
David Benjamin592b5322016-09-30 15:15:01 -04004871 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004872 // TODO(davidben): This test should fail once TLS 1.3 is final
4873 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004874 })
4875 testCases = append(testCases, testCase{
4876 testType: serverTest,
4877 name: "Downgrade-TLS12-Server",
4878 config: Config{
4879 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004880 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004881 },
4882 },
David Benjamin592b5322016-09-30 15:15:01 -04004883 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004884 // TODO(davidben): This test should fail once TLS 1.3 is final
4885 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004886 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004887}
4888
David Benjaminaccb4542014-12-12 23:44:33 -05004889func addMinimumVersionTests() {
4890 for i, shimVers := range tlsVersions {
4891 // Assemble flags to disable all older versions on the shim.
4892 var flags []string
4893 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04004894 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05004895 }
4896
4897 for _, runnerVers := range tlsVersions {
4898 protocols := []protocol{tls}
4899 if runnerVers.hasDTLS && shimVers.hasDTLS {
4900 protocols = append(protocols, dtls)
4901 }
4902 for _, protocol := range protocols {
4903 suffix := shimVers.name + "-" + runnerVers.name
4904 if protocol == dtls {
4905 suffix += "-DTLS"
4906 }
David Benjaminaccb4542014-12-12 23:44:33 -05004907
David Benjaminaccb4542014-12-12 23:44:33 -05004908 var expectedVersion uint16
4909 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004910 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004911 if runnerVers.version >= shimVers.version {
4912 expectedVersion = runnerVers.version
4913 } else {
4914 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004915 expectedError = ":UNSUPPORTED_PROTOCOL:"
4916 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004917 }
4918
4919 testCases = append(testCases, testCase{
4920 protocol: protocol,
4921 testType: clientTest,
4922 name: "MinimumVersion-Client-" + suffix,
4923 config: Config{
4924 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004925 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004926 // Ensure the server does not decline to
4927 // select a version (versions extension) or
4928 // cipher (some ciphers depend on versions).
4929 NegotiateVersion: runnerVers.version,
4930 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004931 },
David Benjaminaccb4542014-12-12 23:44:33 -05004932 },
David Benjamin87909c02014-12-13 01:55:01 -05004933 flags: flags,
4934 expectedVersion: expectedVersion,
4935 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004936 expectedError: expectedError,
4937 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004938 })
4939 testCases = append(testCases, testCase{
4940 protocol: protocol,
4941 testType: clientTest,
4942 name: "MinimumVersion-Client2-" + suffix,
4943 config: Config{
4944 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004945 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004946 // Ensure the server does not decline to
4947 // select a version (versions extension) or
4948 // cipher (some ciphers depend on versions).
4949 NegotiateVersion: runnerVers.version,
4950 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004951 },
David Benjaminaccb4542014-12-12 23:44:33 -05004952 },
David Benjamin353577c2017-06-29 15:54:58 -04004953 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05004954 expectedVersion: expectedVersion,
4955 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004956 expectedError: expectedError,
4957 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004958 })
4959
4960 testCases = append(testCases, testCase{
4961 protocol: protocol,
4962 testType: serverTest,
4963 name: "MinimumVersion-Server-" + suffix,
4964 config: Config{
4965 MaxVersion: runnerVers.version,
4966 },
David Benjamin87909c02014-12-13 01:55:01 -05004967 flags: flags,
4968 expectedVersion: expectedVersion,
4969 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004970 expectedError: expectedError,
4971 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004972 })
4973 testCases = append(testCases, testCase{
4974 protocol: protocol,
4975 testType: serverTest,
4976 name: "MinimumVersion-Server2-" + suffix,
4977 config: Config{
4978 MaxVersion: runnerVers.version,
4979 },
David Benjamin353577c2017-06-29 15:54:58 -04004980 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05004981 expectedVersion: expectedVersion,
4982 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004983 expectedError: expectedError,
4984 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004985 })
4986 }
4987 }
4988 }
4989}
4990
David Benjamine78bfde2014-09-06 12:45:15 -04004991func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004992 // TODO(davidben): Extensions, where applicable, all move their server
4993 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4994 // tests for both. Also test interaction with 0-RTT when implemented.
4995
David Benjamin97d17d92016-07-14 16:12:00 -04004996 // Repeat extensions tests all versions except SSL 3.0.
4997 for _, ver := range tlsVersions {
4998 if ver.version == VersionSSL30 {
4999 continue
5000 }
5001
David Benjamin97d17d92016-07-14 16:12:00 -04005002 // Test that duplicate extensions are rejected.
5003 testCases = append(testCases, testCase{
5004 testType: clientTest,
5005 name: "DuplicateExtensionClient-" + ver.name,
5006 config: Config{
5007 MaxVersion: ver.version,
5008 Bugs: ProtocolBugs{
5009 DuplicateExtension: true,
5010 },
David Benjamine78bfde2014-09-06 12:45:15 -04005011 },
David Benjamin97d17d92016-07-14 16:12:00 -04005012 shouldFail: true,
5013 expectedLocalError: "remote error: error decoding message",
5014 })
5015 testCases = append(testCases, testCase{
5016 testType: serverTest,
5017 name: "DuplicateExtensionServer-" + ver.name,
5018 config: Config{
5019 MaxVersion: ver.version,
5020 Bugs: ProtocolBugs{
5021 DuplicateExtension: true,
5022 },
David Benjamine78bfde2014-09-06 12:45:15 -04005023 },
David Benjamin97d17d92016-07-14 16:12:00 -04005024 shouldFail: true,
5025 expectedLocalError: "remote error: error decoding message",
5026 })
5027
5028 // Test SNI.
5029 testCases = append(testCases, testCase{
5030 testType: clientTest,
5031 name: "ServerNameExtensionClient-" + ver.name,
5032 config: Config{
5033 MaxVersion: ver.version,
5034 Bugs: ProtocolBugs{
5035 ExpectServerName: "example.com",
5036 },
David Benjamine78bfde2014-09-06 12:45:15 -04005037 },
David Benjamin97d17d92016-07-14 16:12:00 -04005038 flags: []string{"-host-name", "example.com"},
5039 })
5040 testCases = append(testCases, testCase{
5041 testType: clientTest,
5042 name: "ServerNameExtensionClientMismatch-" + ver.name,
5043 config: Config{
5044 MaxVersion: ver.version,
5045 Bugs: ProtocolBugs{
5046 ExpectServerName: "mismatch.com",
5047 },
David Benjamine78bfde2014-09-06 12:45:15 -04005048 },
David Benjamin97d17d92016-07-14 16:12:00 -04005049 flags: []string{"-host-name", "example.com"},
5050 shouldFail: true,
5051 expectedLocalError: "tls: unexpected server name",
5052 })
5053 testCases = append(testCases, testCase{
5054 testType: clientTest,
5055 name: "ServerNameExtensionClientMissing-" + ver.name,
5056 config: Config{
5057 MaxVersion: ver.version,
5058 Bugs: ProtocolBugs{
5059 ExpectServerName: "missing.com",
5060 },
David Benjamine78bfde2014-09-06 12:45:15 -04005061 },
David Benjamin97d17d92016-07-14 16:12:00 -04005062 shouldFail: true,
5063 expectedLocalError: "tls: unexpected server name",
5064 })
5065 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005066 testType: clientTest,
5067 name: "TolerateServerNameAck-" + ver.name,
5068 config: Config{
5069 MaxVersion: ver.version,
5070 Bugs: ProtocolBugs{
5071 SendServerNameAck: true,
5072 },
5073 },
5074 flags: []string{"-host-name", "example.com"},
5075 resumeSession: true,
5076 })
5077 testCases = append(testCases, testCase{
5078 testType: clientTest,
5079 name: "UnsolicitedServerNameAck-" + ver.name,
5080 config: Config{
5081 MaxVersion: ver.version,
5082 Bugs: ProtocolBugs{
5083 SendServerNameAck: true,
5084 },
5085 },
5086 shouldFail: true,
5087 expectedError: ":UNEXPECTED_EXTENSION:",
5088 expectedLocalError: "remote error: unsupported extension",
5089 })
5090 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005091 testType: serverTest,
5092 name: "ServerNameExtensionServer-" + ver.name,
5093 config: Config{
5094 MaxVersion: ver.version,
5095 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005096 },
David Benjamin97d17d92016-07-14 16:12:00 -04005097 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005098 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005099 })
5100
5101 // Test ALPN.
5102 testCases = append(testCases, testCase{
5103 testType: clientTest,
5104 name: "ALPNClient-" + ver.name,
5105 config: Config{
5106 MaxVersion: ver.version,
5107 NextProtos: []string{"foo"},
5108 },
5109 flags: []string{
5110 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5111 "-expect-alpn", "foo",
5112 },
5113 expectedNextProto: "foo",
5114 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005115 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005116 })
5117 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005118 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005119 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005120 config: Config{
5121 MaxVersion: ver.version,
5122 Bugs: ProtocolBugs{
5123 SendALPN: "baz",
5124 },
5125 },
5126 flags: []string{
5127 "-advertise-alpn", "\x03foo\x03bar",
5128 },
5129 shouldFail: true,
5130 expectedError: ":INVALID_ALPN_PROTOCOL:",
5131 expectedLocalError: "remote error: illegal parameter",
5132 })
5133 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005134 testType: clientTest,
5135 name: "ALPNClient-AllowUnknown-" + ver.name,
5136 config: Config{
5137 MaxVersion: ver.version,
5138 Bugs: ProtocolBugs{
5139 SendALPN: "baz",
5140 },
5141 },
5142 flags: []string{
5143 "-advertise-alpn", "\x03foo\x03bar",
5144 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005145 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005146 },
5147 })
5148 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005149 testType: serverTest,
5150 name: "ALPNServer-" + ver.name,
5151 config: Config{
5152 MaxVersion: ver.version,
5153 NextProtos: []string{"foo", "bar", "baz"},
5154 },
5155 flags: []string{
5156 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5157 "-select-alpn", "foo",
5158 },
5159 expectedNextProto: "foo",
5160 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005161 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005162 })
5163 testCases = append(testCases, testCase{
5164 testType: serverTest,
5165 name: "ALPNServer-Decline-" + ver.name,
5166 config: Config{
5167 MaxVersion: ver.version,
5168 NextProtos: []string{"foo", "bar", "baz"},
5169 },
5170 flags: []string{"-decline-alpn"},
5171 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005172 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005173 })
5174
David Benjamin25fe85b2016-08-09 20:00:32 -04005175 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5176 // called once.
5177 testCases = append(testCases, testCase{
5178 testType: serverTest,
5179 name: "ALPNServer-Async-" + ver.name,
5180 config: Config{
5181 MaxVersion: ver.version,
5182 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005183 // Prior to TLS 1.3, exercise the asynchronous session callback.
5184 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005185 },
5186 flags: []string{
5187 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5188 "-select-alpn", "foo",
5189 "-async",
5190 },
5191 expectedNextProto: "foo",
5192 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005193 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005194 })
5195
David Benjamin97d17d92016-07-14 16:12:00 -04005196 var emptyString string
5197 testCases = append(testCases, testCase{
5198 testType: clientTest,
5199 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5200 config: Config{
5201 MaxVersion: ver.version,
5202 NextProtos: []string{""},
5203 Bugs: ProtocolBugs{
5204 // A server returning an empty ALPN protocol
5205 // should be rejected.
5206 ALPNProtocol: &emptyString,
5207 },
5208 },
5209 flags: []string{
5210 "-advertise-alpn", "\x03foo",
5211 },
5212 shouldFail: true,
5213 expectedError: ":PARSE_TLSEXT:",
5214 })
5215 testCases = append(testCases, testCase{
5216 testType: serverTest,
5217 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5218 config: Config{
5219 MaxVersion: ver.version,
5220 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005221 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005222 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005223 },
David Benjamin97d17d92016-07-14 16:12:00 -04005224 flags: []string{
5225 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005226 },
David Benjamin97d17d92016-07-14 16:12:00 -04005227 shouldFail: true,
5228 expectedError: ":PARSE_TLSEXT:",
5229 })
5230
5231 // Test NPN and the interaction with ALPN.
5232 if ver.version < VersionTLS13 {
5233 // Test that the server prefers ALPN over NPN.
5234 testCases = append(testCases, testCase{
5235 testType: serverTest,
5236 name: "ALPNServer-Preferred-" + ver.name,
5237 config: Config{
5238 MaxVersion: ver.version,
5239 NextProtos: []string{"foo", "bar", "baz"},
5240 },
5241 flags: []string{
5242 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5243 "-select-alpn", "foo",
5244 "-advertise-npn", "\x03foo\x03bar\x03baz",
5245 },
5246 expectedNextProto: "foo",
5247 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005248 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005249 })
5250 testCases = append(testCases, testCase{
5251 testType: serverTest,
5252 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5253 config: Config{
5254 MaxVersion: ver.version,
5255 NextProtos: []string{"foo", "bar", "baz"},
5256 Bugs: ProtocolBugs{
5257 SwapNPNAndALPN: true,
5258 },
5259 },
5260 flags: []string{
5261 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5262 "-select-alpn", "foo",
5263 "-advertise-npn", "\x03foo\x03bar\x03baz",
5264 },
5265 expectedNextProto: "foo",
5266 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005267 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005268 })
5269
5270 // Test that negotiating both NPN and ALPN is forbidden.
5271 testCases = append(testCases, testCase{
5272 name: "NegotiateALPNAndNPN-" + ver.name,
5273 config: Config{
5274 MaxVersion: ver.version,
5275 NextProtos: []string{"foo", "bar", "baz"},
5276 Bugs: ProtocolBugs{
5277 NegotiateALPNAndNPN: true,
5278 },
5279 },
5280 flags: []string{
5281 "-advertise-alpn", "\x03foo",
5282 "-select-next-proto", "foo",
5283 },
5284 shouldFail: true,
5285 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5286 })
5287 testCases = append(testCases, testCase{
5288 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5289 config: Config{
5290 MaxVersion: ver.version,
5291 NextProtos: []string{"foo", "bar", "baz"},
5292 Bugs: ProtocolBugs{
5293 NegotiateALPNAndNPN: true,
5294 SwapNPNAndALPN: true,
5295 },
5296 },
5297 flags: []string{
5298 "-advertise-alpn", "\x03foo",
5299 "-select-next-proto", "foo",
5300 },
5301 shouldFail: true,
5302 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5303 })
David Benjamin97d17d92016-07-14 16:12:00 -04005304 }
5305
5306 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005307
5308 // Resume with a corrupt ticket.
5309 testCases = append(testCases, testCase{
5310 testType: serverTest,
5311 name: "CorruptTicket-" + ver.name,
5312 config: Config{
5313 MaxVersion: ver.version,
5314 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005315 FilterTicket: func(in []byte) ([]byte, error) {
5316 in[len(in)-1] ^= 1
5317 return in, nil
5318 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005319 },
5320 },
5321 resumeSession: true,
5322 expectResumeRejected: true,
5323 })
5324 // Test the ticket callback, with and without renewal.
5325 testCases = append(testCases, testCase{
5326 testType: serverTest,
5327 name: "TicketCallback-" + ver.name,
5328 config: Config{
5329 MaxVersion: ver.version,
5330 },
5331 resumeSession: true,
5332 flags: []string{"-use-ticket-callback"},
5333 })
5334 testCases = append(testCases, testCase{
5335 testType: serverTest,
5336 name: "TicketCallback-Renew-" + ver.name,
5337 config: Config{
5338 MaxVersion: ver.version,
5339 Bugs: ProtocolBugs{
5340 ExpectNewTicket: true,
5341 },
5342 },
5343 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5344 resumeSession: true,
5345 })
5346
5347 // Test that the ticket callback is only called once when everything before
5348 // it in the ClientHello is asynchronous. This corrupts the ticket so
5349 // certificate selection callbacks run.
5350 testCases = append(testCases, testCase{
5351 testType: serverTest,
5352 name: "TicketCallback-SingleCall-" + ver.name,
5353 config: Config{
5354 MaxVersion: ver.version,
5355 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005356 FilterTicket: func(in []byte) ([]byte, error) {
5357 in[len(in)-1] ^= 1
5358 return in, nil
5359 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005360 },
5361 },
5362 resumeSession: true,
5363 expectResumeRejected: true,
5364 flags: []string{
5365 "-use-ticket-callback",
5366 "-async",
5367 },
5368 })
5369
David Benjamind4c349b2017-02-09 14:07:17 -05005370 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005371 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005372 testCases = append(testCases, testCase{
5373 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005374 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005375 config: Config{
5376 MaxVersion: ver.version,
5377 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005378 EmptyTicketSessionID: true,
5379 },
5380 },
5381 resumeSession: true,
5382 })
5383 testCases = append(testCases, testCase{
5384 testType: serverTest,
5385 name: "TicketSessionIDLength-16-" + ver.name,
5386 config: Config{
5387 MaxVersion: ver.version,
5388 Bugs: ProtocolBugs{
5389 TicketSessionIDLength: 16,
5390 },
5391 },
5392 resumeSession: true,
5393 })
5394 testCases = append(testCases, testCase{
5395 testType: serverTest,
5396 name: "TicketSessionIDLength-32-" + ver.name,
5397 config: Config{
5398 MaxVersion: ver.version,
5399 Bugs: ProtocolBugs{
5400 TicketSessionIDLength: 32,
5401 },
5402 },
5403 resumeSession: true,
5404 })
5405 testCases = append(testCases, testCase{
5406 testType: serverTest,
5407 name: "TicketSessionIDLength-33-" + ver.name,
5408 config: Config{
5409 MaxVersion: ver.version,
5410 Bugs: ProtocolBugs{
5411 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005412 },
5413 },
5414 resumeSession: true,
5415 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005416 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005417 expectedError: ":DECODE_ERROR:",
5418 })
5419 }
5420
5421 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5422 // are ignored.
5423 if ver.hasDTLS {
5424 testCases = append(testCases, testCase{
5425 protocol: dtls,
5426 name: "SRTP-Client-" + ver.name,
5427 config: Config{
5428 MaxVersion: ver.version,
5429 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5430 },
5431 flags: []string{
5432 "-srtp-profiles",
5433 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5434 },
5435 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5436 })
5437 testCases = append(testCases, testCase{
5438 protocol: dtls,
5439 testType: serverTest,
5440 name: "SRTP-Server-" + ver.name,
5441 config: Config{
5442 MaxVersion: ver.version,
5443 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5444 },
5445 flags: []string{
5446 "-srtp-profiles",
5447 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5448 },
5449 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5450 })
5451 // Test that the MKI is ignored.
5452 testCases = append(testCases, testCase{
5453 protocol: dtls,
5454 testType: serverTest,
5455 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5456 config: Config{
5457 MaxVersion: ver.version,
5458 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5459 Bugs: ProtocolBugs{
5460 SRTPMasterKeyIdentifer: "bogus",
5461 },
5462 },
5463 flags: []string{
5464 "-srtp-profiles",
5465 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5466 },
5467 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5468 })
5469 // Test that SRTP isn't negotiated on the server if there were
5470 // no matching profiles.
5471 testCases = append(testCases, testCase{
5472 protocol: dtls,
5473 testType: serverTest,
5474 name: "SRTP-Server-NoMatch-" + ver.name,
5475 config: Config{
5476 MaxVersion: ver.version,
5477 SRTPProtectionProfiles: []uint16{100, 101, 102},
5478 },
5479 flags: []string{
5480 "-srtp-profiles",
5481 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5482 },
5483 expectedSRTPProtectionProfile: 0,
5484 })
5485 // Test that the server returning an invalid SRTP profile is
5486 // flagged as an error by the client.
5487 testCases = append(testCases, testCase{
5488 protocol: dtls,
5489 name: "SRTP-Client-NoMatch-" + ver.name,
5490 config: Config{
5491 MaxVersion: ver.version,
5492 Bugs: ProtocolBugs{
5493 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5494 },
5495 },
5496 flags: []string{
5497 "-srtp-profiles",
5498 "SRTP_AES128_CM_SHA1_80",
5499 },
5500 shouldFail: true,
5501 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5502 })
5503 }
5504
5505 // Test SCT list.
5506 testCases = append(testCases, testCase{
5507 name: "SignedCertificateTimestampList-Client-" + ver.name,
5508 testType: clientTest,
5509 config: Config{
5510 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005511 },
David Benjamin97d17d92016-07-14 16:12:00 -04005512 flags: []string{
5513 "-enable-signed-cert-timestamps",
5514 "-expect-signed-cert-timestamps",
5515 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005516 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005517 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005518 })
David Benjamindaa88502016-10-04 16:32:16 -04005519
Adam Langleycfa08c32016-11-17 13:21:27 -08005520 var differentSCTList []byte
5521 differentSCTList = append(differentSCTList, testSCTList...)
5522 differentSCTList[len(differentSCTList)-1] ^= 1
5523
David Benjamindaa88502016-10-04 16:32:16 -04005524 // The SCT extension did not specify that it must only be sent on resumption as it
5525 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005526 testCases = append(testCases, testCase{
5527 name: "SendSCTListOnResume-" + ver.name,
5528 config: Config{
5529 MaxVersion: ver.version,
5530 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005531 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005532 },
David Benjamind98452d2015-06-16 14:16:23 -04005533 },
David Benjamin97d17d92016-07-14 16:12:00 -04005534 flags: []string{
5535 "-enable-signed-cert-timestamps",
5536 "-expect-signed-cert-timestamps",
5537 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005538 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005539 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005540 })
David Benjamindaa88502016-10-04 16:32:16 -04005541
David Benjamin97d17d92016-07-14 16:12:00 -04005542 testCases = append(testCases, testCase{
5543 name: "SignedCertificateTimestampList-Server-" + ver.name,
5544 testType: serverTest,
5545 config: Config{
5546 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005547 },
David Benjamin97d17d92016-07-14 16:12:00 -04005548 flags: []string{
5549 "-signed-cert-timestamps",
5550 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005551 },
David Benjamin97d17d92016-07-14 16:12:00 -04005552 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005553 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005554 })
David Benjamin53210cb2016-11-16 09:01:48 +09005555
Adam Langleycfa08c32016-11-17 13:21:27 -08005556 emptySCTListCert := *testCerts[0].cert
5557 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5558
5559 // Test empty SCT list.
5560 testCases = append(testCases, testCase{
5561 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5562 testType: clientTest,
5563 config: Config{
5564 MaxVersion: ver.version,
5565 Certificates: []Certificate{emptySCTListCert},
5566 },
5567 flags: []string{
5568 "-enable-signed-cert-timestamps",
5569 },
5570 shouldFail: true,
5571 expectedError: ":ERROR_PARSING_EXTENSION:",
5572 })
5573
5574 emptySCTCert := *testCerts[0].cert
5575 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5576
5577 // Test empty SCT in non-empty list.
5578 testCases = append(testCases, testCase{
5579 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5580 testType: clientTest,
5581 config: Config{
5582 MaxVersion: ver.version,
5583 Certificates: []Certificate{emptySCTCert},
5584 },
5585 flags: []string{
5586 "-enable-signed-cert-timestamps",
5587 },
5588 shouldFail: true,
5589 expectedError: ":ERROR_PARSING_EXTENSION:",
5590 })
5591
David Benjamin53210cb2016-11-16 09:01:48 +09005592 // Test that certificate-related extensions are not sent unsolicited.
5593 testCases = append(testCases, testCase{
5594 testType: serverTest,
5595 name: "UnsolicitedCertificateExtensions-" + ver.name,
5596 config: Config{
5597 MaxVersion: ver.version,
5598 Bugs: ProtocolBugs{
5599 NoOCSPStapling: true,
5600 NoSignedCertificateTimestamps: true,
5601 },
5602 },
5603 flags: []string{
5604 "-ocsp-response",
5605 base64.StdEncoding.EncodeToString(testOCSPResponse),
5606 "-signed-cert-timestamps",
5607 base64.StdEncoding.EncodeToString(testSCTList),
5608 },
5609 })
David Benjamin97d17d92016-07-14 16:12:00 -04005610 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005611
Paul Lietar4fac72e2015-09-09 13:44:55 +01005612 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005613 testType: clientTest,
5614 name: "ClientHelloPadding",
5615 config: Config{
5616 Bugs: ProtocolBugs{
5617 RequireClientHelloSize: 512,
5618 },
5619 },
5620 // This hostname just needs to be long enough to push the
5621 // ClientHello into F5's danger zone between 256 and 511 bytes
5622 // long.
5623 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5624 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005625
5626 // Extensions should not function in SSL 3.0.
5627 testCases = append(testCases, testCase{
5628 testType: serverTest,
5629 name: "SSLv3Extensions-NoALPN",
5630 config: Config{
5631 MaxVersion: VersionSSL30,
5632 NextProtos: []string{"foo", "bar", "baz"},
5633 },
5634 flags: []string{
5635 "-select-alpn", "foo",
5636 },
5637 expectNoNextProto: true,
5638 })
5639
5640 // Test session tickets separately as they follow a different codepath.
5641 testCases = append(testCases, testCase{
5642 testType: serverTest,
5643 name: "SSLv3Extensions-NoTickets",
5644 config: Config{
5645 MaxVersion: VersionSSL30,
5646 Bugs: ProtocolBugs{
5647 // Historically, session tickets in SSL 3.0
5648 // failed in different ways depending on whether
5649 // the client supported renegotiation_info.
5650 NoRenegotiationInfo: true,
5651 },
5652 },
5653 resumeSession: true,
5654 })
5655 testCases = append(testCases, testCase{
5656 testType: serverTest,
5657 name: "SSLv3Extensions-NoTickets2",
5658 config: Config{
5659 MaxVersion: VersionSSL30,
5660 },
5661 resumeSession: true,
5662 })
5663
5664 // But SSL 3.0 does send and process renegotiation_info.
5665 testCases = append(testCases, testCase{
5666 testType: serverTest,
5667 name: "SSLv3Extensions-RenegotiationInfo",
5668 config: Config{
5669 MaxVersion: VersionSSL30,
5670 Bugs: ProtocolBugs{
5671 RequireRenegotiationInfo: true,
5672 },
5673 },
David Benjamind2610042017-01-03 10:49:28 -05005674 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005675 })
5676 testCases = append(testCases, testCase{
5677 testType: serverTest,
5678 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5679 config: Config{
5680 MaxVersion: VersionSSL30,
5681 Bugs: ProtocolBugs{
5682 NoRenegotiationInfo: true,
5683 SendRenegotiationSCSV: true,
5684 RequireRenegotiationInfo: true,
5685 },
5686 },
David Benjamind2610042017-01-03 10:49:28 -05005687 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005688 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005689
5690 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5691 // in ServerHello.
5692 testCases = append(testCases, testCase{
5693 name: "NPN-Forbidden-TLS13",
5694 config: Config{
5695 MaxVersion: VersionTLS13,
5696 NextProtos: []string{"foo"},
5697 Bugs: ProtocolBugs{
5698 NegotiateNPNAtAllVersions: true,
5699 },
5700 },
5701 flags: []string{"-select-next-proto", "foo"},
5702 shouldFail: true,
5703 expectedError: ":ERROR_PARSING_EXTENSION:",
5704 })
5705 testCases = append(testCases, testCase{
5706 name: "EMS-Forbidden-TLS13",
5707 config: Config{
5708 MaxVersion: VersionTLS13,
5709 Bugs: ProtocolBugs{
5710 NegotiateEMSAtAllVersions: true,
5711 },
5712 },
5713 shouldFail: true,
5714 expectedError: ":ERROR_PARSING_EXTENSION:",
5715 })
5716 testCases = append(testCases, testCase{
5717 name: "RenegotiationInfo-Forbidden-TLS13",
5718 config: Config{
5719 MaxVersion: VersionTLS13,
5720 Bugs: ProtocolBugs{
5721 NegotiateRenegotiationInfoAtAllVersions: true,
5722 },
5723 },
5724 shouldFail: true,
5725 expectedError: ":ERROR_PARSING_EXTENSION:",
5726 })
5727 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005728 name: "Ticket-Forbidden-TLS13",
5729 config: Config{
5730 MaxVersion: VersionTLS12,
5731 },
5732 resumeConfig: &Config{
5733 MaxVersion: VersionTLS13,
5734 Bugs: ProtocolBugs{
5735 AdvertiseTicketExtension: true,
5736 },
5737 },
5738 resumeSession: true,
5739 shouldFail: true,
5740 expectedError: ":ERROR_PARSING_EXTENSION:",
5741 })
5742
5743 // Test that illegal extensions in TLS 1.3 are declined by the server if
5744 // offered in ClientHello. The runner's server will fail if this occurs,
5745 // so we exercise the offering path. (EMS and Renegotiation Info are
5746 // implicit in every test.)
5747 testCases = append(testCases, testCase{
5748 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005749 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005750 config: Config{
5751 MaxVersion: VersionTLS13,
5752 NextProtos: []string{"bar"},
5753 },
5754 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5755 })
David Benjamin196df5b2016-09-21 16:23:27 -04005756
David Benjamindaa88502016-10-04 16:32:16 -04005757 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5758 // tolerated.
5759 testCases = append(testCases, testCase{
5760 name: "SendOCSPResponseOnResume-TLS12",
5761 config: Config{
5762 MaxVersion: VersionTLS12,
5763 Bugs: ProtocolBugs{
5764 SendOCSPResponseOnResume: []byte("bogus"),
5765 },
5766 },
5767 flags: []string{
5768 "-enable-ocsp-stapling",
5769 "-expect-ocsp-response",
5770 base64.StdEncoding.EncodeToString(testOCSPResponse),
5771 },
5772 resumeSession: true,
5773 })
5774
David Benjamindaa88502016-10-04 16:32:16 -04005775 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005776 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005777 config: Config{
5778 MaxVersion: VersionTLS13,
5779 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005780 SendExtensionOnCertificate: testOCSPExtension,
5781 },
5782 },
5783 shouldFail: true,
5784 expectedError: ":UNEXPECTED_EXTENSION:",
5785 })
5786
5787 testCases = append(testCases, testCase{
5788 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5789 config: Config{
5790 MaxVersion: VersionTLS13,
5791 Bugs: ProtocolBugs{
5792 SendExtensionOnCertificate: testSCTExtension,
5793 },
5794 },
5795 shouldFail: true,
5796 expectedError: ":UNEXPECTED_EXTENSION:",
5797 })
5798
5799 // Test that extensions on client certificates are never accepted.
5800 testCases = append(testCases, testCase{
5801 name: "SendExtensionOnClientCertificate-TLS13",
5802 testType: serverTest,
5803 config: Config{
5804 MaxVersion: VersionTLS13,
5805 Certificates: []Certificate{rsaCertificate},
5806 Bugs: ProtocolBugs{
5807 SendExtensionOnCertificate: testOCSPExtension,
5808 },
5809 },
5810 flags: []string{
5811 "-enable-ocsp-stapling",
5812 "-require-any-client-certificate",
5813 },
5814 shouldFail: true,
5815 expectedError: ":UNEXPECTED_EXTENSION:",
5816 })
5817
5818 testCases = append(testCases, testCase{
5819 name: "SendUnknownExtensionOnCertificate-TLS13",
5820 config: Config{
5821 MaxVersion: VersionTLS13,
5822 Bugs: ProtocolBugs{
5823 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5824 },
5825 },
5826 shouldFail: true,
5827 expectedError: ":UNEXPECTED_EXTENSION:",
5828 })
5829
Adam Langleycfa08c32016-11-17 13:21:27 -08005830 var differentSCTList []byte
5831 differentSCTList = append(differentSCTList, testSCTList...)
5832 differentSCTList[len(differentSCTList)-1] ^= 1
5833
Steven Valdeza833c352016-11-01 13:39:36 -04005834 // Test that extensions on intermediates are allowed but ignored.
5835 testCases = append(testCases, testCase{
5836 name: "IgnoreExtensionsOnIntermediates-TLS13",
5837 config: Config{
5838 MaxVersion: VersionTLS13,
5839 Certificates: []Certificate{rsaChainCertificate},
5840 Bugs: ProtocolBugs{
5841 // Send different values on the intermediate. This tests
5842 // the intermediate's extensions do not override the
5843 // leaf's.
5844 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005845 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005846 },
5847 },
5848 flags: []string{
5849 "-enable-ocsp-stapling",
5850 "-expect-ocsp-response",
5851 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005852 "-enable-signed-cert-timestamps",
5853 "-expect-signed-cert-timestamps",
5854 base64.StdEncoding.EncodeToString(testSCTList),
5855 },
5856 resumeSession: true,
5857 })
5858
5859 // Test that extensions are not sent on intermediates when configured
5860 // only for a leaf.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "SendNoExtensionsOnIntermediate-TLS13",
5864 config: Config{
5865 MaxVersion: VersionTLS13,
5866 Bugs: ProtocolBugs{
5867 ExpectNoExtensionsOnIntermediate: true,
5868 },
5869 },
5870 flags: []string{
5871 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5872 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5873 "-ocsp-response",
5874 base64.StdEncoding.EncodeToString(testOCSPResponse),
5875 "-signed-cert-timestamps",
5876 base64.StdEncoding.EncodeToString(testSCTList),
5877 },
5878 })
5879
5880 // Test that extensions are not sent on client certificates.
5881 testCases = append(testCases, testCase{
5882 name: "SendNoClientCertificateExtensions-TLS13",
5883 config: Config{
5884 MaxVersion: VersionTLS13,
5885 ClientAuth: RequireAnyClientCert,
5886 },
5887 flags: []string{
5888 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5889 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5890 "-ocsp-response",
5891 base64.StdEncoding.EncodeToString(testOCSPResponse),
5892 "-signed-cert-timestamps",
5893 base64.StdEncoding.EncodeToString(testSCTList),
5894 },
5895 })
5896
5897 testCases = append(testCases, testCase{
5898 name: "SendDuplicateExtensionsOnCerts-TLS13",
5899 config: Config{
5900 MaxVersion: VersionTLS13,
5901 Bugs: ProtocolBugs{
5902 SendDuplicateCertExtensions: true,
5903 },
5904 },
5905 flags: []string{
5906 "-enable-ocsp-stapling",
5907 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005908 },
5909 resumeSession: true,
5910 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005911 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005912 })
Adam Langley9b885c52016-11-18 14:21:03 -08005913
5914 testCases = append(testCases, testCase{
5915 name: "SignedCertificateTimestampListInvalid-Server",
5916 testType: serverTest,
5917 flags: []string{
5918 "-signed-cert-timestamps",
5919 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5920 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005921 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005922 expectedError: ":INVALID_SCT_LIST:",
5923 })
David Benjamine78bfde2014-09-06 12:45:15 -04005924}
5925
David Benjamin01fe8202014-09-24 15:21:44 -04005926func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005927 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005928 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005929 // SSL 3.0 does not have tickets and TLS 1.3 does not
5930 // have session IDs, so skip their cross-resumption
5931 // tests.
5932 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5933 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5934 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005935 }
5936
David Benjamin8b8c0062014-11-23 02:47:52 -05005937 protocols := []protocol{tls}
5938 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5939 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005940 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005941 for _, protocol := range protocols {
5942 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5943 if protocol == dtls {
5944 suffix += "-DTLS"
5945 }
5946
David Benjaminece3de92015-03-16 18:02:20 -04005947 if sessionVers.version == resumeVers.version {
5948 testCases = append(testCases, testCase{
5949 protocol: protocol,
5950 name: "Resume-Client" + suffix,
5951 resumeSession: true,
5952 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005953 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005954 Bugs: ProtocolBugs{
5955 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5956 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5957 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005958 },
David Benjaminece3de92015-03-16 18:02:20 -04005959 expectedVersion: sessionVers.version,
5960 expectedResumeVersion: resumeVers.version,
5961 })
5962 } else {
David Benjamin405da482016-08-08 17:25:07 -04005963 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5964
5965 // Offering a TLS 1.3 session sends an empty session ID, so
5966 // there is no way to convince a non-lookahead client the
5967 // session was resumed. It will appear to the client that a
5968 // stray ChangeCipherSpec was sent.
5969 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5970 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005971 }
5972
David Benjaminece3de92015-03-16 18:02:20 -04005973 testCases = append(testCases, testCase{
5974 protocol: protocol,
5975 name: "Resume-Client-Mismatch" + suffix,
5976 resumeSession: true,
5977 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005978 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005979 },
David Benjaminece3de92015-03-16 18:02:20 -04005980 expectedVersion: sessionVers.version,
5981 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005982 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005983 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005984 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005985 },
5986 },
5987 expectedResumeVersion: resumeVers.version,
5988 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005989 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005990 })
5991 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005992
5993 testCases = append(testCases, testCase{
5994 protocol: protocol,
5995 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005996 resumeSession: true,
5997 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005998 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005999 },
6000 expectedVersion: sessionVers.version,
6001 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006002 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006003 },
6004 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006005 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006006 expectedResumeVersion: resumeVers.version,
6007 })
6008
David Benjamin8b8c0062014-11-23 02:47:52 -05006009 testCases = append(testCases, testCase{
6010 protocol: protocol,
6011 testType: serverTest,
6012 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006013 resumeSession: true,
6014 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006015 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006016 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006017 expectedVersion: sessionVers.version,
6018 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006019 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006020 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006021 Bugs: ProtocolBugs{
6022 SendBothTickets: true,
6023 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006024 },
6025 expectedResumeVersion: resumeVers.version,
6026 })
6027 }
David Benjamin01fe8202014-09-24 15:21:44 -04006028 }
6029 }
David Benjaminece3de92015-03-16 18:02:20 -04006030
David Benjamin4199b0d2016-11-01 13:58:25 -04006031 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006032 testCases = append(testCases, testCase{
6033 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006034 name: "ShimTicketRewritable",
6035 resumeSession: true,
6036 config: Config{
6037 MaxVersion: VersionTLS12,
6038 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6039 Bugs: ProtocolBugs{
6040 FilterTicket: func(in []byte) ([]byte, error) {
6041 in, err := SetShimTicketVersion(in, VersionTLS12)
6042 if err != nil {
6043 return nil, err
6044 }
6045 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6046 },
6047 },
6048 },
6049 flags: []string{
6050 "-ticket-key",
6051 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6052 },
6053 })
6054
6055 // Resumptions are declined if the version does not match.
6056 testCases = append(testCases, testCase{
6057 testType: serverTest,
6058 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006059 resumeSession: true,
6060 config: Config{
6061 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006062 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006063 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006064 FilterTicket: func(in []byte) ([]byte, error) {
6065 return SetShimTicketVersion(in, VersionTLS13)
6066 },
6067 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006068 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006069 flags: []string{
6070 "-ticket-key",
6071 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6072 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006073 expectResumeRejected: true,
6074 })
6075
6076 testCases = append(testCases, testCase{
6077 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006078 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006079 resumeSession: true,
6080 config: Config{
6081 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006082 Bugs: ProtocolBugs{
6083 FilterTicket: func(in []byte) ([]byte, error) {
6084 return SetShimTicketVersion(in, VersionTLS12)
6085 },
6086 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006087 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006088 flags: []string{
6089 "-ticket-key",
6090 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6091 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006092 expectResumeRejected: true,
6093 })
6094
David Benjamin4199b0d2016-11-01 13:58:25 -04006095 // Resumptions are declined if the cipher is invalid or disabled.
6096 testCases = append(testCases, testCase{
6097 testType: serverTest,
6098 name: "Resume-Server-DeclineBadCipher",
6099 resumeSession: true,
6100 config: Config{
6101 MaxVersion: VersionTLS12,
6102 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006103 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006104 FilterTicket: func(in []byte) ([]byte, error) {
6105 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6106 },
6107 },
6108 },
6109 flags: []string{
6110 "-ticket-key",
6111 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6112 },
6113 expectResumeRejected: true,
6114 })
6115
6116 testCases = append(testCases, testCase{
6117 testType: serverTest,
6118 name: "Resume-Server-DeclineBadCipher-2",
6119 resumeSession: true,
6120 config: Config{
6121 MaxVersion: VersionTLS12,
6122 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006123 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006124 FilterTicket: func(in []byte) ([]byte, error) {
6125 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6126 },
6127 },
6128 },
6129 flags: []string{
6130 "-cipher", "AES128",
6131 "-ticket-key",
6132 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6133 },
6134 expectResumeRejected: true,
6135 })
6136
David Benjaminf01f42a2016-11-16 19:05:33 +09006137 // Sessions are not resumed if they do not use the preferred cipher.
6138 testCases = append(testCases, testCase{
6139 testType: serverTest,
6140 name: "Resume-Server-CipherNotPreferred",
6141 resumeSession: true,
6142 config: Config{
6143 MaxVersion: VersionTLS12,
6144 Bugs: ProtocolBugs{
6145 ExpectNewTicket: true,
6146 FilterTicket: func(in []byte) ([]byte, error) {
6147 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6148 },
6149 },
6150 },
6151 flags: []string{
6152 "-ticket-key",
6153 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6154 },
6155 shouldFail: false,
6156 expectResumeRejected: true,
6157 })
6158
6159 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6160 // PRF hashes match, but BoringSSL will always decline such resumptions.
6161 testCases = append(testCases, testCase{
6162 testType: serverTest,
6163 name: "Resume-Server-CipherNotPreferred-TLS13",
6164 resumeSession: true,
6165 config: Config{
6166 MaxVersion: VersionTLS13,
6167 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6168 Bugs: ProtocolBugs{
6169 FilterTicket: func(in []byte) ([]byte, error) {
6170 // If the client (runner) offers ChaCha20-Poly1305 first, the
6171 // server (shim) always prefers it. Switch it to AES-GCM.
6172 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6173 },
6174 },
6175 },
6176 flags: []string{
6177 "-ticket-key",
6178 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6179 },
6180 shouldFail: false,
6181 expectResumeRejected: true,
6182 })
6183
6184 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006185 testCases = append(testCases, testCase{
6186 testType: serverTest,
6187 name: "Resume-Server-DeclineBadCipher-TLS13",
6188 resumeSession: true,
6189 config: Config{
6190 MaxVersion: VersionTLS13,
6191 Bugs: ProtocolBugs{
6192 FilterTicket: func(in []byte) ([]byte, error) {
6193 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6194 },
6195 },
6196 },
6197 flags: []string{
6198 "-ticket-key",
6199 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6200 },
6201 expectResumeRejected: true,
6202 })
6203
David Benjaminf01f42a2016-11-16 19:05:33 +09006204 // If the client does not offer the cipher from the session, decline to
6205 // resume. Clients are forbidden from doing this, but BoringSSL selects
6206 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006207 testCases = append(testCases, testCase{
6208 testType: serverTest,
6209 name: "Resume-Server-UnofferedCipher",
6210 resumeSession: true,
6211 config: Config{
6212 MaxVersion: VersionTLS12,
6213 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6214 },
6215 resumeConfig: &Config{
6216 MaxVersion: VersionTLS12,
6217 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6218 Bugs: ProtocolBugs{
6219 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6220 },
6221 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006222 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006223 })
6224
David Benjaminf01f42a2016-11-16 19:05:33 +09006225 // In TLS 1.3, clients may advertise a cipher list which does not
6226 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006227 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6228 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006229 testCases = append(testCases, testCase{
6230 testType: serverTest,
6231 name: "Resume-Server-UnofferedCipher-TLS13",
6232 resumeSession: true,
6233 config: Config{
6234 MaxVersion: VersionTLS13,
6235 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6236 },
6237 resumeConfig: &Config{
6238 MaxVersion: VersionTLS13,
6239 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6240 Bugs: ProtocolBugs{
6241 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6242 },
6243 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006244 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006245 })
6246
David Benjamin4199b0d2016-11-01 13:58:25 -04006247 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006248 testCases = append(testCases, testCase{
6249 name: "Resume-Client-CipherMismatch",
6250 resumeSession: true,
6251 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006252 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006253 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6254 },
6255 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006256 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006257 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6258 Bugs: ProtocolBugs{
6259 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6260 },
6261 },
6262 shouldFail: true,
6263 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6264 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006265
David Benjamine1cc35e2016-11-16 16:25:58 +09006266 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6267 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006268 testCases = append(testCases, testCase{
6269 name: "Resume-Client-CipherMismatch-TLS13",
6270 resumeSession: true,
6271 config: Config{
6272 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006273 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006274 },
6275 resumeConfig: &Config{
6276 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006277 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6278 },
6279 })
6280
6281 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6282 testCases = append(testCases, testCase{
6283 name: "Resume-Client-PRFMismatch-TLS13",
6284 resumeSession: true,
6285 config: Config{
6286 MaxVersion: VersionTLS13,
6287 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6288 },
6289 resumeConfig: &Config{
6290 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006291 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006292 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006293 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006294 },
6295 },
6296 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006297 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006298 })
Steven Valdeza833c352016-11-01 13:39:36 -04006299
6300 testCases = append(testCases, testCase{
6301 testType: serverTest,
6302 name: "Resume-Server-BinderWrongLength",
6303 resumeSession: true,
6304 config: Config{
6305 MaxVersion: VersionTLS13,
6306 Bugs: ProtocolBugs{
6307 SendShortPSKBinder: true,
6308 },
6309 },
6310 shouldFail: true,
6311 expectedLocalError: "remote error: error decrypting message",
6312 expectedError: ":DIGEST_CHECK_FAILED:",
6313 })
6314
6315 testCases = append(testCases, testCase{
6316 testType: serverTest,
6317 name: "Resume-Server-NoPSKBinder",
6318 resumeSession: true,
6319 config: Config{
6320 MaxVersion: VersionTLS13,
6321 Bugs: ProtocolBugs{
6322 SendNoPSKBinder: true,
6323 },
6324 },
6325 shouldFail: true,
6326 expectedLocalError: "remote error: error decoding message",
6327 expectedError: ":DECODE_ERROR:",
6328 })
6329
6330 testCases = append(testCases, testCase{
6331 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006332 name: "Resume-Server-ExtraPSKBinder",
6333 resumeSession: true,
6334 config: Config{
6335 MaxVersion: VersionTLS13,
6336 Bugs: ProtocolBugs{
6337 SendExtraPSKBinder: true,
6338 },
6339 },
6340 shouldFail: true,
6341 expectedLocalError: "remote error: illegal parameter",
6342 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6343 })
6344
6345 testCases = append(testCases, testCase{
6346 testType: serverTest,
6347 name: "Resume-Server-ExtraIdentityNoBinder",
6348 resumeSession: true,
6349 config: Config{
6350 MaxVersion: VersionTLS13,
6351 Bugs: ProtocolBugs{
6352 ExtraPSKIdentity: true,
6353 },
6354 },
6355 shouldFail: true,
6356 expectedLocalError: "remote error: illegal parameter",
6357 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6358 })
6359
6360 testCases = append(testCases, testCase{
6361 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006362 name: "Resume-Server-InvalidPSKBinder",
6363 resumeSession: true,
6364 config: Config{
6365 MaxVersion: VersionTLS13,
6366 Bugs: ProtocolBugs{
6367 SendInvalidPSKBinder: true,
6368 },
6369 },
6370 shouldFail: true,
6371 expectedLocalError: "remote error: error decrypting message",
6372 expectedError: ":DIGEST_CHECK_FAILED:",
6373 })
6374
6375 testCases = append(testCases, testCase{
6376 testType: serverTest,
6377 name: "Resume-Server-PSKBinderFirstExtension",
6378 resumeSession: true,
6379 config: Config{
6380 MaxVersion: VersionTLS13,
6381 Bugs: ProtocolBugs{
6382 PSKBinderFirst: true,
6383 },
6384 },
6385 shouldFail: true,
6386 expectedLocalError: "remote error: illegal parameter",
6387 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6388 })
David Benjamin01fe8202014-09-24 15:21:44 -04006389}
6390
Adam Langley2ae77d22014-10-28 17:29:33 -07006391func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006392 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006393 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006394 testType: serverTest,
6395 name: "Renegotiate-Server-Forbidden",
6396 config: Config{
6397 MaxVersion: VersionTLS12,
6398 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006399 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006400 shouldFail: true,
6401 expectedError: ":NO_RENEGOTIATION:",
6402 expectedLocalError: "remote error: no renegotiation",
6403 })
Adam Langley5021b222015-06-12 18:27:58 -07006404 // The server shouldn't echo the renegotiation extension unless
6405 // requested by the client.
6406 testCases = append(testCases, testCase{
6407 testType: serverTest,
6408 name: "Renegotiate-Server-NoExt",
6409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006410 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006411 Bugs: ProtocolBugs{
6412 NoRenegotiationInfo: true,
6413 RequireRenegotiationInfo: true,
6414 },
6415 },
6416 shouldFail: true,
6417 expectedLocalError: "renegotiation extension missing",
6418 })
6419 // The renegotiation SCSV should be sufficient for the server to echo
6420 // the extension.
6421 testCases = append(testCases, testCase{
6422 testType: serverTest,
6423 name: "Renegotiate-Server-NoExt-SCSV",
6424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006425 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006426 Bugs: ProtocolBugs{
6427 NoRenegotiationInfo: true,
6428 SendRenegotiationSCSV: true,
6429 RequireRenegotiationInfo: true,
6430 },
6431 },
6432 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006433 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006434 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006436 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006437 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006438 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006439 },
6440 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006441 renegotiate: 1,
6442 flags: []string{
6443 "-renegotiate-freely",
6444 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006445 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006446 },
David Benjamincdea40c2015-03-19 14:09:43 -04006447 })
6448 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006449 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006450 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006452 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006453 Bugs: ProtocolBugs{
6454 EmptyRenegotiationInfo: true,
6455 },
6456 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006457 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006458 shouldFail: true,
6459 expectedError: ":RENEGOTIATION_MISMATCH:",
6460 })
6461 testCases = append(testCases, testCase{
6462 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006463 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006464 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006465 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006466 Bugs: ProtocolBugs{
6467 BadRenegotiationInfo: true,
6468 },
6469 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006470 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006471 shouldFail: true,
6472 expectedError: ":RENEGOTIATION_MISMATCH:",
6473 })
6474 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006475 name: "Renegotiate-Client-Downgrade",
6476 renegotiate: 1,
6477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006478 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006479 Bugs: ProtocolBugs{
6480 NoRenegotiationInfoAfterInitial: true,
6481 },
6482 },
6483 flags: []string{"-renegotiate-freely"},
6484 shouldFail: true,
6485 expectedError: ":RENEGOTIATION_MISMATCH:",
6486 })
6487 testCases = append(testCases, testCase{
6488 name: "Renegotiate-Client-Upgrade",
6489 renegotiate: 1,
6490 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006491 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006492 Bugs: ProtocolBugs{
6493 NoRenegotiationInfoInInitial: true,
6494 },
6495 },
6496 flags: []string{"-renegotiate-freely"},
6497 shouldFail: true,
6498 expectedError: ":RENEGOTIATION_MISMATCH:",
6499 })
6500 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006501 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006502 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006504 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006505 Bugs: ProtocolBugs{
6506 NoRenegotiationInfo: true,
6507 },
6508 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006509 flags: []string{
6510 "-renegotiate-freely",
6511 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006512 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006513 },
David Benjamincff0b902015-05-15 23:09:47 -04006514 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006515
6516 // Test that the server may switch ciphers on renegotiation without
6517 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006518 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006519 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006520 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006521 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006522 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006523 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006524 },
6525 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006526 flags: []string{
6527 "-renegotiate-freely",
6528 "-expect-total-renegotiations", "1",
6529 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006530 })
6531 testCases = append(testCases, testCase{
6532 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006533 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006534 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006535 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6537 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006538 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006539 flags: []string{
6540 "-renegotiate-freely",
6541 "-expect-total-renegotiations", "1",
6542 },
David Benjaminb16346b2015-04-08 19:16:58 -04006543 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006544
6545 // Test that the server may not switch versions on renegotiation.
6546 testCases = append(testCases, testCase{
6547 name: "Renegotiate-Client-SwitchVersion",
6548 config: Config{
6549 MaxVersion: VersionTLS12,
6550 // Pick a cipher which exists at both versions.
6551 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6552 Bugs: ProtocolBugs{
6553 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006554 // Avoid failing early at the record layer.
6555 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006556 },
6557 },
6558 renegotiate: 1,
6559 flags: []string{
6560 "-renegotiate-freely",
6561 "-expect-total-renegotiations", "1",
6562 },
6563 shouldFail: true,
6564 expectedError: ":WRONG_SSL_VERSION:",
6565 })
6566
David Benjaminb16346b2015-04-08 19:16:58 -04006567 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006568 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006569 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006570 config: Config{
6571 MaxVersion: VersionTLS10,
6572 Bugs: ProtocolBugs{
6573 RequireSameRenegoClientVersion: true,
6574 },
6575 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006576 flags: []string{
6577 "-renegotiate-freely",
6578 "-expect-total-renegotiations", "1",
6579 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006580 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006581 testCases = append(testCases, testCase{
6582 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006583 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006584 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006585 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6587 NextProtos: []string{"foo"},
6588 },
6589 flags: []string{
6590 "-false-start",
6591 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006592 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006593 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006594 },
6595 shimWritesFirst: true,
6596 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006597
6598 // Client-side renegotiation controls.
6599 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006600 name: "Renegotiate-Client-Forbidden-1",
6601 config: Config{
6602 MaxVersion: VersionTLS12,
6603 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006604 renegotiate: 1,
6605 shouldFail: true,
6606 expectedError: ":NO_RENEGOTIATION:",
6607 expectedLocalError: "remote error: no renegotiation",
6608 })
6609 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006610 name: "Renegotiate-Client-Once-1",
6611 config: Config{
6612 MaxVersion: VersionTLS12,
6613 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006614 renegotiate: 1,
6615 flags: []string{
6616 "-renegotiate-once",
6617 "-expect-total-renegotiations", "1",
6618 },
6619 })
6620 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006621 name: "Renegotiate-Client-Freely-1",
6622 config: Config{
6623 MaxVersion: VersionTLS12,
6624 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006625 renegotiate: 1,
6626 flags: []string{
6627 "-renegotiate-freely",
6628 "-expect-total-renegotiations", "1",
6629 },
6630 })
6631 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006632 name: "Renegotiate-Client-Once-2",
6633 config: Config{
6634 MaxVersion: VersionTLS12,
6635 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006636 renegotiate: 2,
6637 flags: []string{"-renegotiate-once"},
6638 shouldFail: true,
6639 expectedError: ":NO_RENEGOTIATION:",
6640 expectedLocalError: "remote error: no renegotiation",
6641 })
6642 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006643 name: "Renegotiate-Client-Freely-2",
6644 config: Config{
6645 MaxVersion: VersionTLS12,
6646 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006647 renegotiate: 2,
6648 flags: []string{
6649 "-renegotiate-freely",
6650 "-expect-total-renegotiations", "2",
6651 },
6652 })
Adam Langley27a0d082015-11-03 13:34:10 -08006653 testCases = append(testCases, testCase{
6654 name: "Renegotiate-Client-NoIgnore",
6655 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006656 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006657 Bugs: ProtocolBugs{
6658 SendHelloRequestBeforeEveryAppDataRecord: true,
6659 },
6660 },
6661 shouldFail: true,
6662 expectedError: ":NO_RENEGOTIATION:",
6663 })
6664 testCases = append(testCases, testCase{
6665 name: "Renegotiate-Client-Ignore",
6666 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006667 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006668 Bugs: ProtocolBugs{
6669 SendHelloRequestBeforeEveryAppDataRecord: true,
6670 },
6671 },
6672 flags: []string{
6673 "-renegotiate-ignore",
6674 "-expect-total-renegotiations", "0",
6675 },
6676 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006677
David Benjamin34941c02016-10-08 11:45:31 -04006678 // Renegotiation is not allowed at SSL 3.0.
6679 testCases = append(testCases, testCase{
6680 name: "Renegotiate-Client-SSL3",
6681 config: Config{
6682 MaxVersion: VersionSSL30,
6683 },
6684 renegotiate: 1,
6685 flags: []string{
6686 "-renegotiate-freely",
6687 "-expect-total-renegotiations", "1",
6688 },
6689 shouldFail: true,
6690 expectedError: ":NO_RENEGOTIATION:",
6691 expectedLocalError: "remote error: no renegotiation",
6692 })
6693
David Benjamina1eaba12017-01-01 23:19:22 -05006694 // Renegotiation is not allowed when there is an unfinished write.
6695 testCases = append(testCases, testCase{
6696 name: "Renegotiate-Client-UnfinishedWrite",
6697 config: Config{
6698 MaxVersion: VersionTLS12,
6699 },
David Benjaminbbba9392017-04-06 12:54:12 -04006700 renegotiate: 1,
6701 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006702 flags: []string{
6703 "-async",
6704 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006705 },
6706 shouldFail: true,
6707 expectedError: ":NO_RENEGOTIATION:",
6708 // We do not successfully send the no_renegotiation alert in
6709 // this case. https://crbug.com/boringssl/130
6710 })
6711
David Benjamin07ab5d42017-02-09 20:11:41 -05006712 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006713 testCases = append(testCases, testCase{
6714 name: "StrayHelloRequest",
6715 config: Config{
6716 MaxVersion: VersionTLS12,
6717 Bugs: ProtocolBugs{
6718 SendHelloRequestBeforeEveryHandshakeMessage: true,
6719 },
6720 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006721 shouldFail: true,
6722 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006723 })
6724 testCases = append(testCases, testCase{
6725 name: "StrayHelloRequest-Packed",
6726 config: Config{
6727 MaxVersion: VersionTLS12,
6728 Bugs: ProtocolBugs{
6729 PackHandshakeFlight: true,
6730 SendHelloRequestBeforeEveryHandshakeMessage: true,
6731 },
6732 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006733 shouldFail: true,
6734 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006735 })
6736
David Benjamin12d2c482016-07-24 10:56:51 -04006737 // Test renegotiation works if HelloRequest and server Finished come in
6738 // the same record.
6739 testCases = append(testCases, testCase{
6740 name: "Renegotiate-Client-Packed",
6741 config: Config{
6742 MaxVersion: VersionTLS12,
6743 Bugs: ProtocolBugs{
6744 PackHandshakeFlight: true,
6745 PackHelloRequestWithFinished: true,
6746 },
6747 },
6748 renegotiate: 1,
6749 flags: []string{
6750 "-renegotiate-freely",
6751 "-expect-total-renegotiations", "1",
6752 },
6753 })
6754
David Benjamin397c8e62016-07-08 14:14:36 -07006755 // Renegotiation is forbidden in TLS 1.3.
6756 testCases = append(testCases, testCase{
6757 name: "Renegotiate-Client-TLS13",
6758 config: Config{
6759 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006760 Bugs: ProtocolBugs{
6761 SendHelloRequestBeforeEveryAppDataRecord: true,
6762 },
David Benjamin397c8e62016-07-08 14:14:36 -07006763 },
David Benjamin397c8e62016-07-08 14:14:36 -07006764 flags: []string{
6765 "-renegotiate-freely",
6766 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006767 shouldFail: true,
6768 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006769 })
6770
6771 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6772 testCases = append(testCases, testCase{
6773 name: "StrayHelloRequest-TLS13",
6774 config: Config{
6775 MaxVersion: VersionTLS13,
6776 Bugs: ProtocolBugs{
6777 SendHelloRequestBeforeEveryHandshakeMessage: true,
6778 },
6779 },
6780 shouldFail: true,
6781 expectedError: ":UNEXPECTED_MESSAGE:",
6782 })
David Benjamind2610042017-01-03 10:49:28 -05006783
6784 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6785 // always reads as supporting it, regardless of whether it was
6786 // negotiated.
6787 testCases = append(testCases, testCase{
6788 name: "AlwaysReportRenegotiationInfo-TLS13",
6789 config: Config{
6790 MaxVersion: VersionTLS13,
6791 Bugs: ProtocolBugs{
6792 NoRenegotiationInfo: true,
6793 },
6794 },
6795 flags: []string{
6796 "-expect-secure-renegotiation",
6797 },
6798 })
David Benjamina58baaf2017-02-28 20:54:28 -05006799
6800 // Certificates may not change on renegotiation.
6801 testCases = append(testCases, testCase{
6802 name: "Renegotiation-CertificateChange",
6803 config: Config{
6804 MaxVersion: VersionTLS12,
6805 Certificates: []Certificate{rsaCertificate},
6806 Bugs: ProtocolBugs{
6807 RenegotiationCertificate: &rsaChainCertificate,
6808 },
6809 },
6810 renegotiate: 1,
6811 flags: []string{"-renegotiate-freely"},
6812 shouldFail: true,
6813 expectedError: ":SERVER_CERT_CHANGED:",
6814 })
6815 testCases = append(testCases, testCase{
6816 name: "Renegotiation-CertificateChange-2",
6817 config: Config{
6818 MaxVersion: VersionTLS12,
6819 Certificates: []Certificate{rsaCertificate},
6820 Bugs: ProtocolBugs{
6821 RenegotiationCertificate: &rsa1024Certificate,
6822 },
6823 },
6824 renegotiate: 1,
6825 flags: []string{"-renegotiate-freely"},
6826 shouldFail: true,
6827 expectedError: ":SERVER_CERT_CHANGED:",
6828 })
David Benjaminbbf42462017-03-14 21:27:10 -04006829
6830 // We do not negotiate ALPN after the initial handshake. This is
6831 // error-prone and only risks bugs in consumers.
6832 testCases = append(testCases, testCase{
6833 testType: clientTest,
6834 name: "Renegotiation-ForbidALPN",
6835 config: Config{
6836 MaxVersion: VersionTLS12,
6837 Bugs: ProtocolBugs{
6838 // Forcibly negotiate ALPN on both initial and
6839 // renegotiation handshakes. The test stack will
6840 // internally check the client does not offer
6841 // it.
6842 SendALPN: "foo",
6843 },
6844 },
6845 flags: []string{
6846 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6847 "-expect-alpn", "foo",
6848 "-renegotiate-freely",
6849 },
6850 renegotiate: 1,
6851 shouldFail: true,
6852 expectedError: ":UNEXPECTED_EXTENSION:",
6853 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006854}
6855
David Benjamin5e961c12014-11-07 01:48:35 -05006856func addDTLSReplayTests() {
6857 // Test that sequence number replays are detected.
6858 testCases = append(testCases, testCase{
6859 protocol: dtls,
6860 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006861 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006862 replayWrites: true,
6863 })
6864
David Benjamin8e6db492015-07-25 18:29:23 -04006865 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006866 // than the retransmit window.
6867 testCases = append(testCases, testCase{
6868 protocol: dtls,
6869 name: "DTLS-Replay-LargeGaps",
6870 config: Config{
6871 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006872 SequenceNumberMapping: func(in uint64) uint64 {
6873 return in * 127
6874 },
David Benjamin5e961c12014-11-07 01:48:35 -05006875 },
6876 },
David Benjamin8e6db492015-07-25 18:29:23 -04006877 messageCount: 200,
6878 replayWrites: true,
6879 })
6880
6881 // Test the incoming sequence number changing non-monotonically.
6882 testCases = append(testCases, testCase{
6883 protocol: dtls,
6884 name: "DTLS-Replay-NonMonotonic",
6885 config: Config{
6886 Bugs: ProtocolBugs{
6887 SequenceNumberMapping: func(in uint64) uint64 {
6888 return in ^ 31
6889 },
6890 },
6891 },
6892 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006893 replayWrites: true,
6894 })
6895}
6896
Nick Harper60edffd2016-06-21 15:19:24 -07006897var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006898 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006899 id signatureAlgorithm
6900 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006901}{
Nick Harper60edffd2016-06-21 15:19:24 -07006902 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6903 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6904 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6905 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006906 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006907 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6908 // hash function doesn't have to match the curve and so the same
6909 // signature algorithm works with P-224.
6910 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006911 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6912 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6913 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006914 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6915 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6916 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05006917 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04006918 // Tests for key types prior to TLS 1.2.
6919 {"RSA", 0, testCertRSA},
6920 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006921}
6922
Nick Harper60edffd2016-06-21 15:19:24 -07006923const fakeSigAlg1 signatureAlgorithm = 0x2a01
6924const fakeSigAlg2 signatureAlgorithm = 0xff01
6925
6926func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006927 // Not all ciphers involve a signature. Advertise a list which gives all
6928 // versions a signing cipher.
6929 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006930 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006931 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6932 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6933 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6934 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006935 }
David Benjamin5208fd42016-07-13 21:43:25 -04006936
David Benjaminca3d5452016-07-14 12:51:01 -04006937 var allAlgorithms []signatureAlgorithm
6938 for _, alg := range testSignatureAlgorithms {
6939 if alg.id != 0 {
6940 allAlgorithms = append(allAlgorithms, alg.id)
6941 }
6942 }
6943
Nick Harper60edffd2016-06-21 15:19:24 -07006944 // Make sure each signature algorithm works. Include some fake values in
6945 // the list and ensure they're ignored.
6946 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006947 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006948 if (ver.version < VersionTLS12) != (alg.id == 0) {
6949 continue
6950 }
6951
6952 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6953 // or remove it in C.
6954 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006955 continue
6956 }
Nick Harper60edffd2016-06-21 15:19:24 -07006957
David Benjamin3ef76972016-10-17 17:59:54 -04006958 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006959 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006960 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006961 shouldSignFail = true
6962 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006963 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006964 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08006965 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
6966 shouldSignFail = true
6967 shouldVerifyFail = true
6968 }
6969 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
6970 // the curve has to match the hash size.
6971 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04006972 shouldSignFail = true
6973 shouldVerifyFail = true
6974 }
6975
6976 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6977 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6978 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006979 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006980
6981 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006982 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006983 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006984 }
6985 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006986 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006987 }
David Benjamin000800a2014-11-14 01:43:59 -05006988
David Benjamin1fb125c2016-07-08 18:52:12 -07006989 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006990
David Benjamin7a41d372016-07-09 11:21:54 -07006991 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006992 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006993 config: Config{
6994 MaxVersion: ver.version,
6995 ClientAuth: RequireAnyClientCert,
6996 VerifySignatureAlgorithms: []signatureAlgorithm{
6997 fakeSigAlg1,
6998 alg.id,
6999 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007000 },
David Benjamin7a41d372016-07-09 11:21:54 -07007001 },
7002 flags: []string{
7003 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7004 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7005 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007006 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007007 },
David Benjamin3ef76972016-10-17 17:59:54 -04007008 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007009 expectedError: signError,
7010 expectedPeerSignatureAlgorithm: alg.id,
7011 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007012
David Benjamin7a41d372016-07-09 11:21:54 -07007013 testCases = append(testCases, testCase{
7014 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007015 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007016 config: Config{
7017 MaxVersion: ver.version,
7018 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7019 SignSignatureAlgorithms: []signatureAlgorithm{
7020 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007021 },
David Benjamin7a41d372016-07-09 11:21:54 -07007022 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007023 SkipECDSACurveCheck: shouldVerifyFail,
7024 IgnoreSignatureVersionChecks: shouldVerifyFail,
7025 // Some signature algorithms may not be advertised.
7026 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007027 },
David Benjamin7a41d372016-07-09 11:21:54 -07007028 },
7029 flags: []string{
7030 "-require-any-client-certificate",
7031 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7032 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007033 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007034 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007035 // Resume the session to assert the peer signature
7036 // algorithm is reported on both handshakes.
7037 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007038 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007039 expectedError: verifyError,
7040 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007041
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007042 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007043 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007044 testCases = append(testCases, testCase{
7045 testType: serverTest,
7046 name: "ServerAuth-Sign" + suffix,
7047 config: Config{
7048 MaxVersion: ver.version,
7049 CipherSuites: signingCiphers,
7050 VerifySignatureAlgorithms: []signatureAlgorithm{
7051 fakeSigAlg1,
7052 alg.id,
7053 fakeSigAlg2,
7054 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007055 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007056 flags: []string{
7057 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7058 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7059 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007060 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007061 },
7062 shouldFail: shouldSignFail,
7063 expectedError: signError,
7064 expectedPeerSignatureAlgorithm: alg.id,
7065 })
7066 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007067
7068 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007069 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007070 config: Config{
7071 MaxVersion: ver.version,
7072 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007073 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007074 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007075 alg.id,
7076 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007077 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007078 SkipECDSACurveCheck: shouldVerifyFail,
7079 IgnoreSignatureVersionChecks: shouldVerifyFail,
7080 // Some signature algorithms may not be advertised.
7081 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007082 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007083 },
7084 flags: []string{
7085 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7086 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007087 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007088 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007089 // Resume the session to assert the peer signature
7090 // algorithm is reported on both handshakes.
7091 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007092 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007093 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007094 })
David Benjamin5208fd42016-07-13 21:43:25 -04007095
David Benjamin3ef76972016-10-17 17:59:54 -04007096 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007097 testCases = append(testCases, testCase{
7098 testType: serverTest,
7099 name: "ClientAuth-InvalidSignature" + suffix,
7100 config: Config{
7101 MaxVersion: ver.version,
7102 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7103 SignSignatureAlgorithms: []signatureAlgorithm{
7104 alg.id,
7105 },
7106 Bugs: ProtocolBugs{
7107 InvalidSignature: true,
7108 },
7109 },
7110 flags: []string{
7111 "-require-any-client-certificate",
7112 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007113 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007114 },
7115 shouldFail: true,
7116 expectedError: ":BAD_SIGNATURE:",
7117 })
7118
7119 testCases = append(testCases, testCase{
7120 name: "ServerAuth-InvalidSignature" + suffix,
7121 config: Config{
7122 MaxVersion: ver.version,
7123 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7124 CipherSuites: signingCiphers,
7125 SignSignatureAlgorithms: []signatureAlgorithm{
7126 alg.id,
7127 },
7128 Bugs: ProtocolBugs{
7129 InvalidSignature: true,
7130 },
7131 },
David Benjamin69522112017-03-28 15:38:29 -05007132 flags: []string{
7133 "-enable-all-curves",
7134 "-enable-ed25519",
7135 },
David Benjamin5208fd42016-07-13 21:43:25 -04007136 shouldFail: true,
7137 expectedError: ":BAD_SIGNATURE:",
7138 })
7139 }
David Benjaminca3d5452016-07-14 12:51:01 -04007140
David Benjamin3ef76972016-10-17 17:59:54 -04007141 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007142 testCases = append(testCases, testCase{
7143 name: "ClientAuth-Sign-Negotiate" + suffix,
7144 config: Config{
7145 MaxVersion: ver.version,
7146 ClientAuth: RequireAnyClientCert,
7147 VerifySignatureAlgorithms: allAlgorithms,
7148 },
7149 flags: []string{
7150 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7151 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7152 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007153 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007154 "-signing-prefs", strconv.Itoa(int(alg.id)),
7155 },
7156 expectedPeerSignatureAlgorithm: alg.id,
7157 })
7158
7159 testCases = append(testCases, testCase{
7160 testType: serverTest,
7161 name: "ServerAuth-Sign-Negotiate" + suffix,
7162 config: Config{
7163 MaxVersion: ver.version,
7164 CipherSuites: signingCiphers,
7165 VerifySignatureAlgorithms: allAlgorithms,
7166 },
7167 flags: []string{
7168 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7169 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7170 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007171 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007172 "-signing-prefs", strconv.Itoa(int(alg.id)),
7173 },
7174 expectedPeerSignatureAlgorithm: alg.id,
7175 })
7176 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007177 }
David Benjamin000800a2014-11-14 01:43:59 -05007178 }
7179
Nick Harper60edffd2016-06-21 15:19:24 -07007180 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007181 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007182 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007183 config: Config{
7184 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007185 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007186 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007187 signatureECDSAWithP521AndSHA512,
7188 signatureRSAPKCS1WithSHA384,
7189 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007190 },
7191 },
7192 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007193 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7194 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007195 },
Nick Harper60edffd2016-06-21 15:19:24 -07007196 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007197 })
7198
7199 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007200 name: "ClientAuth-SignatureType-TLS13",
7201 config: Config{
7202 ClientAuth: RequireAnyClientCert,
7203 MaxVersion: VersionTLS13,
7204 VerifySignatureAlgorithms: []signatureAlgorithm{
7205 signatureECDSAWithP521AndSHA512,
7206 signatureRSAPKCS1WithSHA384,
7207 signatureRSAPSSWithSHA384,
7208 signatureECDSAWithSHA1,
7209 },
7210 },
7211 flags: []string{
7212 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7213 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7214 },
7215 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7216 })
7217
7218 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007219 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007220 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007222 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007223 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007225 signatureECDSAWithP521AndSHA512,
7226 signatureRSAPKCS1WithSHA384,
7227 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007228 },
7229 },
Nick Harper60edffd2016-06-21 15:19:24 -07007230 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007231 })
7232
Steven Valdez143e8b32016-07-11 13:19:03 -04007233 testCases = append(testCases, testCase{
7234 testType: serverTest,
7235 name: "ServerAuth-SignatureType-TLS13",
7236 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007237 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007238 VerifySignatureAlgorithms: []signatureAlgorithm{
7239 signatureECDSAWithP521AndSHA512,
7240 signatureRSAPKCS1WithSHA384,
7241 signatureRSAPSSWithSHA384,
7242 signatureECDSAWithSHA1,
7243 },
7244 },
7245 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7246 })
7247
David Benjamina95e9f32016-07-08 16:28:04 -07007248 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007249 testCases = append(testCases, testCase{
7250 testType: serverTest,
7251 name: "Verify-ClientAuth-SignatureType",
7252 config: Config{
7253 MaxVersion: VersionTLS12,
7254 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007255 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007256 signatureRSAPKCS1WithSHA256,
7257 },
7258 Bugs: ProtocolBugs{
7259 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7260 },
7261 },
7262 flags: []string{
7263 "-require-any-client-certificate",
7264 },
7265 shouldFail: true,
7266 expectedError: ":WRONG_SIGNATURE_TYPE:",
7267 })
7268
7269 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007270 testType: serverTest,
7271 name: "Verify-ClientAuth-SignatureType-TLS13",
7272 config: Config{
7273 MaxVersion: VersionTLS13,
7274 Certificates: []Certificate{rsaCertificate},
7275 SignSignatureAlgorithms: []signatureAlgorithm{
7276 signatureRSAPSSWithSHA256,
7277 },
7278 Bugs: ProtocolBugs{
7279 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7280 },
7281 },
7282 flags: []string{
7283 "-require-any-client-certificate",
7284 },
7285 shouldFail: true,
7286 expectedError: ":WRONG_SIGNATURE_TYPE:",
7287 })
7288
7289 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007290 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007291 config: Config{
7292 MaxVersion: VersionTLS12,
7293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007294 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007295 signatureRSAPKCS1WithSHA256,
7296 },
7297 Bugs: ProtocolBugs{
7298 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7299 },
7300 },
7301 shouldFail: true,
7302 expectedError: ":WRONG_SIGNATURE_TYPE:",
7303 })
7304
Steven Valdez143e8b32016-07-11 13:19:03 -04007305 testCases = append(testCases, testCase{
7306 name: "Verify-ServerAuth-SignatureType-TLS13",
7307 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007308 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007309 SignSignatureAlgorithms: []signatureAlgorithm{
7310 signatureRSAPSSWithSHA256,
7311 },
7312 Bugs: ProtocolBugs{
7313 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7314 },
7315 },
7316 shouldFail: true,
7317 expectedError: ":WRONG_SIGNATURE_TYPE:",
7318 })
7319
David Benjamin51dd7d62016-07-08 16:07:01 -07007320 // Test that, if the list is missing, the peer falls back to SHA-1 in
7321 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007322 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007323 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007325 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007326 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007327 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007328 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007329 },
7330 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007331 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007332 },
7333 },
7334 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007335 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7336 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007337 },
7338 })
7339
7340 testCases = append(testCases, testCase{
7341 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007342 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007343 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007344 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007345 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007346 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007347 },
7348 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007349 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007350 },
7351 },
David Benjaminee32bea2016-08-17 13:36:44 -04007352 flags: []string{
7353 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7354 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7355 },
7356 })
7357
7358 testCases = append(testCases, testCase{
7359 name: "ClientAuth-SHA1-Fallback-ECDSA",
7360 config: Config{
7361 MaxVersion: VersionTLS12,
7362 ClientAuth: RequireAnyClientCert,
7363 VerifySignatureAlgorithms: []signatureAlgorithm{
7364 signatureECDSAWithSHA1,
7365 },
7366 Bugs: ProtocolBugs{
7367 NoSignatureAlgorithms: true,
7368 },
7369 },
7370 flags: []string{
7371 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7372 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7373 },
7374 })
7375
7376 testCases = append(testCases, testCase{
7377 testType: serverTest,
7378 name: "ServerAuth-SHA1-Fallback-ECDSA",
7379 config: Config{
7380 MaxVersion: VersionTLS12,
7381 VerifySignatureAlgorithms: []signatureAlgorithm{
7382 signatureECDSAWithSHA1,
7383 },
7384 Bugs: ProtocolBugs{
7385 NoSignatureAlgorithms: true,
7386 },
7387 },
7388 flags: []string{
7389 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7390 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7391 },
David Benjamin000800a2014-11-14 01:43:59 -05007392 })
David Benjamin72dc7832015-03-16 17:49:43 -04007393
David Benjamin51dd7d62016-07-08 16:07:01 -07007394 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007395 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007396 config: Config{
7397 MaxVersion: VersionTLS13,
7398 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007399 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007400 signatureRSAPKCS1WithSHA1,
7401 },
7402 Bugs: ProtocolBugs{
7403 NoSignatureAlgorithms: true,
7404 },
7405 },
7406 flags: []string{
7407 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7408 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7409 },
David Benjamin48901652016-08-01 12:12:47 -04007410 shouldFail: true,
7411 // An empty CertificateRequest signature algorithm list is a
7412 // syntax error in TLS 1.3.
7413 expectedError: ":DECODE_ERROR:",
7414 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007415 })
7416
7417 testCases = append(testCases, testCase{
7418 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007419 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007420 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007421 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007422 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007423 signatureRSAPKCS1WithSHA1,
7424 },
7425 Bugs: ProtocolBugs{
7426 NoSignatureAlgorithms: true,
7427 },
7428 },
7429 shouldFail: true,
7430 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7431 })
7432
David Benjaminb62d2872016-07-18 14:55:02 +02007433 // Test that hash preferences are enforced. BoringSSL does not implement
7434 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007435 testCases = append(testCases, testCase{
7436 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007437 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007439 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007440 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007441 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007442 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007443 },
7444 Bugs: ProtocolBugs{
7445 IgnorePeerSignatureAlgorithmPreferences: true,
7446 },
7447 },
7448 flags: []string{"-require-any-client-certificate"},
7449 shouldFail: true,
7450 expectedError: ":WRONG_SIGNATURE_TYPE:",
7451 })
7452
7453 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007454 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007456 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007458 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007459 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007460 },
7461 Bugs: ProtocolBugs{
7462 IgnorePeerSignatureAlgorithmPreferences: true,
7463 },
7464 },
7465 shouldFail: true,
7466 expectedError: ":WRONG_SIGNATURE_TYPE:",
7467 })
David Benjaminb62d2872016-07-18 14:55:02 +02007468 testCases = append(testCases, testCase{
7469 testType: serverTest,
7470 name: "ClientAuth-Enforced-TLS13",
7471 config: Config{
7472 MaxVersion: VersionTLS13,
7473 Certificates: []Certificate{rsaCertificate},
7474 SignSignatureAlgorithms: []signatureAlgorithm{
7475 signatureRSAPKCS1WithMD5,
7476 },
7477 Bugs: ProtocolBugs{
7478 IgnorePeerSignatureAlgorithmPreferences: true,
7479 IgnoreSignatureVersionChecks: true,
7480 },
7481 },
7482 flags: []string{"-require-any-client-certificate"},
7483 shouldFail: true,
7484 expectedError: ":WRONG_SIGNATURE_TYPE:",
7485 })
7486
7487 testCases = append(testCases, testCase{
7488 name: "ServerAuth-Enforced-TLS13",
7489 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007490 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007491 SignSignatureAlgorithms: []signatureAlgorithm{
7492 signatureRSAPKCS1WithMD5,
7493 },
7494 Bugs: ProtocolBugs{
7495 IgnorePeerSignatureAlgorithmPreferences: true,
7496 IgnoreSignatureVersionChecks: true,
7497 },
7498 },
7499 shouldFail: true,
7500 expectedError: ":WRONG_SIGNATURE_TYPE:",
7501 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007502
7503 // Test that the agreed upon digest respects the client preferences and
7504 // the server digests.
7505 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007506 name: "NoCommonAlgorithms-Digests",
7507 config: Config{
7508 MaxVersion: VersionTLS12,
7509 ClientAuth: RequireAnyClientCert,
7510 VerifySignatureAlgorithms: []signatureAlgorithm{
7511 signatureRSAPKCS1WithSHA512,
7512 signatureRSAPKCS1WithSHA1,
7513 },
7514 },
7515 flags: []string{
7516 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7517 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7518 "-digest-prefs", "SHA256",
7519 },
7520 shouldFail: true,
7521 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7522 })
7523 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007524 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007525 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007526 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007527 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007528 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007529 signatureRSAPKCS1WithSHA512,
7530 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007531 },
7532 },
7533 flags: []string{
7534 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7535 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007536 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007537 },
David Benjaminca3d5452016-07-14 12:51:01 -04007538 shouldFail: true,
7539 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7540 })
7541 testCases = append(testCases, testCase{
7542 name: "NoCommonAlgorithms-TLS13",
7543 config: Config{
7544 MaxVersion: VersionTLS13,
7545 ClientAuth: RequireAnyClientCert,
7546 VerifySignatureAlgorithms: []signatureAlgorithm{
7547 signatureRSAPSSWithSHA512,
7548 signatureRSAPSSWithSHA384,
7549 },
7550 },
7551 flags: []string{
7552 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7553 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7554 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7555 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007556 shouldFail: true,
7557 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007558 })
7559 testCases = append(testCases, testCase{
7560 name: "Agree-Digest-SHA256",
7561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007562 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007563 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007564 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007565 signatureRSAPKCS1WithSHA1,
7566 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007567 },
7568 },
7569 flags: []string{
7570 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7571 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007572 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007573 },
Nick Harper60edffd2016-06-21 15:19:24 -07007574 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007575 })
7576 testCases = append(testCases, testCase{
7577 name: "Agree-Digest-SHA1",
7578 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007579 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007580 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007581 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007582 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007583 },
7584 },
7585 flags: []string{
7586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007588 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007589 },
Nick Harper60edffd2016-06-21 15:19:24 -07007590 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007591 })
7592 testCases = append(testCases, testCase{
7593 name: "Agree-Digest-Default",
7594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007595 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007596 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007597 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007598 signatureRSAPKCS1WithSHA256,
7599 signatureECDSAWithP256AndSHA256,
7600 signatureRSAPKCS1WithSHA1,
7601 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007602 },
7603 },
7604 flags: []string{
7605 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7606 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7607 },
Nick Harper60edffd2016-06-21 15:19:24 -07007608 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007609 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007610
David Benjaminca3d5452016-07-14 12:51:01 -04007611 // Test that the signing preference list may include extra algorithms
7612 // without negotiation problems.
7613 testCases = append(testCases, testCase{
7614 testType: serverTest,
7615 name: "FilterExtraAlgorithms",
7616 config: Config{
7617 MaxVersion: VersionTLS12,
7618 VerifySignatureAlgorithms: []signatureAlgorithm{
7619 signatureRSAPKCS1WithSHA256,
7620 },
7621 },
7622 flags: []string{
7623 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7624 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7625 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7626 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7627 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7628 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7629 },
7630 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7631 })
7632
David Benjamin4c3ddf72016-06-29 18:13:53 -04007633 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7634 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007635 testCases = append(testCases, testCase{
7636 name: "CheckLeafCurve",
7637 config: Config{
7638 MaxVersion: VersionTLS12,
7639 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007640 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007641 },
7642 flags: []string{"-p384-only"},
7643 shouldFail: true,
7644 expectedError: ":BAD_ECC_CERT:",
7645 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007646
7647 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7648 testCases = append(testCases, testCase{
7649 name: "CheckLeafCurve-TLS13",
7650 config: Config{
7651 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007652 Certificates: []Certificate{ecdsaP256Certificate},
7653 },
7654 flags: []string{"-p384-only"},
7655 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007656
7657 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7658 testCases = append(testCases, testCase{
7659 name: "ECDSACurveMismatch-Verify-TLS12",
7660 config: Config{
7661 MaxVersion: VersionTLS12,
7662 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7663 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007664 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007665 signatureECDSAWithP384AndSHA384,
7666 },
7667 },
7668 })
7669
7670 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7671 testCases = append(testCases, testCase{
7672 name: "ECDSACurveMismatch-Verify-TLS13",
7673 config: Config{
7674 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007675 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007676 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007677 signatureECDSAWithP384AndSHA384,
7678 },
7679 Bugs: ProtocolBugs{
7680 SkipECDSACurveCheck: true,
7681 },
7682 },
7683 shouldFail: true,
7684 expectedError: ":WRONG_SIGNATURE_TYPE:",
7685 })
7686
7687 // Signature algorithm selection in TLS 1.3 should take the curve into
7688 // account.
7689 testCases = append(testCases, testCase{
7690 testType: serverTest,
7691 name: "ECDSACurveMismatch-Sign-TLS13",
7692 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007693 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007694 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007695 signatureECDSAWithP384AndSHA384,
7696 signatureECDSAWithP256AndSHA256,
7697 },
7698 },
7699 flags: []string{
7700 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7701 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7702 },
7703 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7704 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007705
7706 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7707 // server does not attempt to sign in that case.
7708 testCases = append(testCases, testCase{
7709 testType: serverTest,
7710 name: "RSA-PSS-Large",
7711 config: Config{
7712 MaxVersion: VersionTLS13,
7713 VerifySignatureAlgorithms: []signatureAlgorithm{
7714 signatureRSAPSSWithSHA512,
7715 },
7716 },
7717 flags: []string{
7718 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7719 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7720 },
7721 shouldFail: true,
7722 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7723 })
David Benjamin57e929f2016-08-30 00:30:38 -04007724
7725 // Test that RSA-PSS is enabled by default for TLS 1.2.
7726 testCases = append(testCases, testCase{
7727 testType: clientTest,
7728 name: "RSA-PSS-Default-Verify",
7729 config: Config{
7730 MaxVersion: VersionTLS12,
7731 SignSignatureAlgorithms: []signatureAlgorithm{
7732 signatureRSAPSSWithSHA256,
7733 },
7734 },
7735 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7736 })
7737
7738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "RSA-PSS-Default-Sign",
7741 config: Config{
7742 MaxVersion: VersionTLS12,
7743 VerifySignatureAlgorithms: []signatureAlgorithm{
7744 signatureRSAPSSWithSHA256,
7745 },
7746 },
7747 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7748 })
David Benjamin69522112017-03-28 15:38:29 -05007749
7750 // TLS 1.1 and below has no way to advertise support for or negotiate
7751 // Ed25519's signature algorithm.
7752 testCases = append(testCases, testCase{
7753 testType: clientTest,
7754 name: "NoEd25519-TLS11-ServerAuth-Verify",
7755 config: Config{
7756 MaxVersion: VersionTLS11,
7757 Certificates: []Certificate{ed25519Certificate},
7758 Bugs: ProtocolBugs{
7759 // Sign with Ed25519 even though it is TLS 1.1.
7760 UseLegacySigningAlgorithm: signatureEd25519,
7761 },
7762 },
7763 flags: []string{"-enable-ed25519"},
7764 shouldFail: true,
7765 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7766 })
7767 testCases = append(testCases, testCase{
7768 testType: serverTest,
7769 name: "NoEd25519-TLS11-ServerAuth-Sign",
7770 config: Config{
7771 MaxVersion: VersionTLS11,
7772 },
7773 flags: []string{
7774 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7775 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7776 },
7777 shouldFail: true,
7778 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7779 })
7780 testCases = append(testCases, testCase{
7781 testType: serverTest,
7782 name: "NoEd25519-TLS11-ClientAuth-Verify",
7783 config: Config{
7784 MaxVersion: VersionTLS11,
7785 Certificates: []Certificate{ed25519Certificate},
7786 Bugs: ProtocolBugs{
7787 // Sign with Ed25519 even though it is TLS 1.1.
7788 UseLegacySigningAlgorithm: signatureEd25519,
7789 },
7790 },
7791 flags: []string{
7792 "-enable-ed25519",
7793 "-require-any-client-certificate",
7794 },
7795 shouldFail: true,
7796 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7797 })
7798 testCases = append(testCases, testCase{
7799 testType: clientTest,
7800 name: "NoEd25519-TLS11-ClientAuth-Sign",
7801 config: Config{
7802 MaxVersion: VersionTLS11,
7803 ClientAuth: RequireAnyClientCert,
7804 },
7805 flags: []string{
7806 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7807 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7808 },
7809 shouldFail: true,
7810 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7811 })
7812
7813 // Test Ed25519 is not advertised by default.
7814 testCases = append(testCases, testCase{
7815 testType: clientTest,
7816 name: "Ed25519DefaultDisable-NoAdvertise",
7817 config: Config{
7818 Certificates: []Certificate{ed25519Certificate},
7819 },
7820 shouldFail: true,
7821 expectedLocalError: "tls: no common signature algorithms",
7822 })
7823
7824 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7825 // preferences.
7826 testCases = append(testCases, testCase{
7827 testType: clientTest,
7828 name: "Ed25519DefaultDisable-NoAccept",
7829 config: Config{
7830 Certificates: []Certificate{ed25519Certificate},
7831 Bugs: ProtocolBugs{
7832 IgnorePeerSignatureAlgorithmPreferences: true,
7833 },
7834 },
7835 shouldFail: true,
7836 expectedLocalError: "remote error: illegal parameter",
7837 expectedError: ":WRONG_SIGNATURE_TYPE:",
7838 })
David Benjamin71c21b42017-04-14 17:05:40 -04007839
7840 // Test that configuring verify preferences changes what the client
7841 // advertises.
7842 testCases = append(testCases, testCase{
7843 name: "VerifyPreferences-Advertised",
7844 config: Config{
7845 Certificates: []Certificate{rsaCertificate},
7846 SignSignatureAlgorithms: []signatureAlgorithm{
7847 signatureRSAPSSWithSHA256,
7848 signatureRSAPSSWithSHA384,
7849 signatureRSAPSSWithSHA512,
7850 },
7851 },
7852 flags: []string{
7853 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7854 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7855 },
7856 })
7857
7858 // Test that the client advertises a set which the runner can find
7859 // nothing in common with.
7860 testCases = append(testCases, testCase{
7861 name: "VerifyPreferences-NoCommonAlgorithms",
7862 config: Config{
7863 Certificates: []Certificate{rsaCertificate},
7864 SignSignatureAlgorithms: []signatureAlgorithm{
7865 signatureRSAPSSWithSHA256,
7866 signatureRSAPSSWithSHA512,
7867 },
7868 },
7869 flags: []string{
7870 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7871 },
7872 shouldFail: true,
7873 expectedLocalError: "tls: no common signature algorithms",
7874 })
7875
7876 // Test that the client enforces its preferences when configured.
7877 testCases = append(testCases, testCase{
7878 name: "VerifyPreferences-Enforced",
7879 config: Config{
7880 Certificates: []Certificate{rsaCertificate},
7881 SignSignatureAlgorithms: []signatureAlgorithm{
7882 signatureRSAPSSWithSHA256,
7883 signatureRSAPSSWithSHA512,
7884 },
7885 Bugs: ProtocolBugs{
7886 IgnorePeerSignatureAlgorithmPreferences: true,
7887 },
7888 },
7889 flags: []string{
7890 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7891 },
7892 shouldFail: true,
7893 expectedLocalError: "remote error: illegal parameter",
7894 expectedError: ":WRONG_SIGNATURE_TYPE:",
7895 })
7896
7897 // Test that explicitly configuring Ed25519 is as good as changing the
7898 // boolean toggle.
7899 testCases = append(testCases, testCase{
7900 name: "VerifyPreferences-Ed25519",
7901 config: Config{
7902 Certificates: []Certificate{ed25519Certificate},
7903 },
7904 flags: []string{
7905 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
7906 },
7907 })
David Benjamin000800a2014-11-14 01:43:59 -05007908}
7909
David Benjamin83f90402015-01-27 01:09:43 -05007910// timeouts is the retransmit schedule for BoringSSL. It doubles and
7911// caps at 60 seconds. On the 13th timeout, it gives up.
7912var timeouts = []time.Duration{
7913 1 * time.Second,
7914 2 * time.Second,
7915 4 * time.Second,
7916 8 * time.Second,
7917 16 * time.Second,
7918 32 * time.Second,
7919 60 * time.Second,
7920 60 * time.Second,
7921 60 * time.Second,
7922 60 * time.Second,
7923 60 * time.Second,
7924 60 * time.Second,
7925 60 * time.Second,
7926}
7927
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007928// shortTimeouts is an alternate set of timeouts which would occur if the
7929// initial timeout duration was set to 250ms.
7930var shortTimeouts = []time.Duration{
7931 250 * time.Millisecond,
7932 500 * time.Millisecond,
7933 1 * time.Second,
7934 2 * time.Second,
7935 4 * time.Second,
7936 8 * time.Second,
7937 16 * time.Second,
7938 32 * time.Second,
7939 60 * time.Second,
7940 60 * time.Second,
7941 60 * time.Second,
7942 60 * time.Second,
7943 60 * time.Second,
7944}
7945
David Benjamin83f90402015-01-27 01:09:43 -05007946func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007947 // These tests work by coordinating some behavior on both the shim and
7948 // the runner.
7949 //
7950 // TimeoutSchedule configures the runner to send a series of timeout
7951 // opcodes to the shim (see packetAdaptor) immediately before reading
7952 // each peer handshake flight N. The timeout opcode both simulates a
7953 // timeout in the shim and acts as a synchronization point to help the
7954 // runner bracket each handshake flight.
7955 //
7956 // We assume the shim does not read from the channel eagerly. It must
7957 // first wait until it has sent flight N and is ready to receive
7958 // handshake flight N+1. At this point, it will process the timeout
7959 // opcode. It must then immediately respond with a timeout ACK and act
7960 // as if the shim was idle for the specified amount of time.
7961 //
7962 // The runner then drops all packets received before the ACK and
7963 // continues waiting for flight N. This ordering results in one attempt
7964 // at sending flight N to be dropped. For the test to complete, the
7965 // shim must send flight N again, testing that the shim implements DTLS
7966 // retransmit on a timeout.
7967
Steven Valdez143e8b32016-07-11 13:19:03 -04007968 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007969 // likely be more epochs to cross and the final message's retransmit may
7970 // be more complex.
7971
David Benjamin11c82892017-02-23 20:40:31 -05007972 // Test that this is indeed the timeout schedule. Stress all
7973 // four patterns of handshake.
7974 for i := 1; i < len(timeouts); i++ {
7975 number := strconv.Itoa(i)
7976 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007977 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05007978 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007980 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007981 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007982 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007983 },
7984 },
7985 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007986 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007987 })
David Benjamin11c82892017-02-23 20:40:31 -05007988 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007989 protocol: dtls,
7990 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05007991 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007993 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007994 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007995 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007996 },
7997 },
7998 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007999 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008000 })
8001 }
David Benjamin11c82892017-02-23 20:40:31 -05008002
8003 // Test that exceeding the timeout schedule hits a read
8004 // timeout.
8005 testCases = append(testCases, testCase{
8006 protocol: dtls,
8007 name: "DTLS-Retransmit-Timeout",
8008 config: Config{
8009 MaxVersion: VersionTLS12,
8010 Bugs: ProtocolBugs{
8011 TimeoutSchedule: timeouts,
8012 },
8013 },
8014 resumeSession: true,
8015 flags: []string{"-async"},
8016 shouldFail: true,
8017 expectedError: ":READ_TIMEOUT_EXPIRED:",
8018 })
8019
8020 // Test that timeout handling has a fudge factor, due to API
8021 // problems.
8022 testCases = append(testCases, testCase{
8023 protocol: dtls,
8024 name: "DTLS-Retransmit-Fudge",
8025 config: Config{
8026 MaxVersion: VersionTLS12,
8027 Bugs: ProtocolBugs{
8028 TimeoutSchedule: []time.Duration{
8029 timeouts[0] - 10*time.Millisecond,
8030 },
8031 },
8032 },
8033 resumeSession: true,
8034 flags: []string{"-async"},
8035 })
8036
8037 // Test that the final Finished retransmitting isn't
8038 // duplicated if the peer badly fragments everything.
8039 testCases = append(testCases, testCase{
8040 testType: serverTest,
8041 protocol: dtls,
8042 name: "DTLS-Retransmit-Fragmented",
8043 config: Config{
8044 MaxVersion: VersionTLS12,
8045 Bugs: ProtocolBugs{
8046 TimeoutSchedule: []time.Duration{timeouts[0]},
8047 MaxHandshakeRecordLength: 2,
8048 },
8049 },
8050 flags: []string{"-async"},
8051 })
8052
8053 // Test the timeout schedule when a shorter initial timeout duration is set.
8054 testCases = append(testCases, testCase{
8055 protocol: dtls,
8056 name: "DTLS-Retransmit-Short-Client",
8057 config: Config{
8058 MaxVersion: VersionTLS12,
8059 Bugs: ProtocolBugs{
8060 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8061 },
8062 },
8063 resumeSession: true,
8064 flags: []string{
8065 "-async",
8066 "-initial-timeout-duration-ms", "250",
8067 },
8068 })
8069 testCases = append(testCases, testCase{
8070 protocol: dtls,
8071 testType: serverTest,
8072 name: "DTLS-Retransmit-Short-Server",
8073 config: Config{
8074 MaxVersion: VersionTLS12,
8075 Bugs: ProtocolBugs{
8076 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8077 },
8078 },
8079 resumeSession: true,
8080 flags: []string{
8081 "-async",
8082 "-initial-timeout-duration-ms", "250",
8083 },
8084 })
David Benjamin83f90402015-01-27 01:09:43 -05008085}
8086
David Benjaminc565ebb2015-04-03 04:06:36 -04008087func addExportKeyingMaterialTests() {
8088 for _, vers := range tlsVersions {
8089 if vers.version == VersionSSL30 {
8090 continue
8091 }
8092 testCases = append(testCases, testCase{
8093 name: "ExportKeyingMaterial-" + vers.name,
8094 config: Config{
8095 MaxVersion: vers.version,
8096 },
8097 exportKeyingMaterial: 1024,
8098 exportLabel: "label",
8099 exportContext: "context",
8100 useExportContext: true,
8101 })
8102 testCases = append(testCases, testCase{
8103 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8104 config: Config{
8105 MaxVersion: vers.version,
8106 },
8107 exportKeyingMaterial: 1024,
8108 })
8109 testCases = append(testCases, testCase{
8110 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8111 config: Config{
8112 MaxVersion: vers.version,
8113 },
8114 exportKeyingMaterial: 1024,
8115 useExportContext: true,
8116 })
8117 testCases = append(testCases, testCase{
8118 name: "ExportKeyingMaterial-Small-" + vers.name,
8119 config: Config{
8120 MaxVersion: vers.version,
8121 },
8122 exportKeyingMaterial: 1,
8123 exportLabel: "label",
8124 exportContext: "context",
8125 useExportContext: true,
8126 })
8127 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008128
David Benjaminc565ebb2015-04-03 04:06:36 -04008129 testCases = append(testCases, testCase{
8130 name: "ExportKeyingMaterial-SSL3",
8131 config: Config{
8132 MaxVersion: VersionSSL30,
8133 },
8134 exportKeyingMaterial: 1024,
8135 exportLabel: "label",
8136 exportContext: "context",
8137 useExportContext: true,
8138 shouldFail: true,
8139 expectedError: "failed to export keying material",
8140 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008141
8142 // Exporters work during a False Start.
8143 testCases = append(testCases, testCase{
8144 name: "ExportKeyingMaterial-FalseStart",
8145 config: Config{
8146 MaxVersion: VersionTLS12,
8147 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8148 NextProtos: []string{"foo"},
8149 Bugs: ProtocolBugs{
8150 ExpectFalseStart: true,
8151 },
8152 },
8153 flags: []string{
8154 "-false-start",
8155 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008156 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008157 },
8158 shimWritesFirst: true,
8159 exportKeyingMaterial: 1024,
8160 exportLabel: "label",
8161 exportContext: "context",
8162 useExportContext: true,
8163 })
8164
8165 // Exporters do not work in the middle of a renegotiation. Test this by
8166 // triggering the exporter after every SSL_read call and configuring the
8167 // shim to run asynchronously.
8168 testCases = append(testCases, testCase{
8169 name: "ExportKeyingMaterial-Renegotiate",
8170 config: Config{
8171 MaxVersion: VersionTLS12,
8172 },
8173 renegotiate: 1,
8174 flags: []string{
8175 "-async",
8176 "-use-exporter-between-reads",
8177 "-renegotiate-freely",
8178 "-expect-total-renegotiations", "1",
8179 },
8180 shouldFail: true,
8181 expectedError: "failed to export keying material",
8182 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008183}
8184
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008185func addTLSUniqueTests() {
8186 for _, isClient := range []bool{false, true} {
8187 for _, isResumption := range []bool{false, true} {
8188 for _, hasEMS := range []bool{false, true} {
8189 var suffix string
8190 if isResumption {
8191 suffix = "Resume-"
8192 } else {
8193 suffix = "Full-"
8194 }
8195
8196 if hasEMS {
8197 suffix += "EMS-"
8198 } else {
8199 suffix += "NoEMS-"
8200 }
8201
8202 if isClient {
8203 suffix += "Client"
8204 } else {
8205 suffix += "Server"
8206 }
8207
8208 test := testCase{
8209 name: "TLSUnique-" + suffix,
8210 testTLSUnique: true,
8211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008212 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008213 Bugs: ProtocolBugs{
8214 NoExtendedMasterSecret: !hasEMS,
8215 },
8216 },
8217 }
8218
8219 if isResumption {
8220 test.resumeSession = true
8221 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008222 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008223 Bugs: ProtocolBugs{
8224 NoExtendedMasterSecret: !hasEMS,
8225 },
8226 }
8227 }
8228
8229 if isResumption && !hasEMS {
8230 test.shouldFail = true
8231 test.expectedError = "failed to get tls-unique"
8232 }
8233
8234 testCases = append(testCases, test)
8235 }
8236 }
8237 }
8238}
8239
Adam Langley09505632015-07-30 18:10:13 -07008240func addCustomExtensionTests() {
8241 expectedContents := "custom extension"
8242 emptyString := ""
8243
8244 for _, isClient := range []bool{false, true} {
8245 suffix := "Server"
8246 flag := "-enable-server-custom-extension"
8247 testType := serverTest
8248 if isClient {
8249 suffix = "Client"
8250 flag = "-enable-client-custom-extension"
8251 testType = clientTest
8252 }
8253
8254 testCases = append(testCases, testCase{
8255 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008256 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008257 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008258 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008259 Bugs: ProtocolBugs{
8260 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008261 ExpectedCustomExtension: &expectedContents,
8262 },
8263 },
8264 flags: []string{flag},
8265 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008266 testCases = append(testCases, testCase{
8267 testType: testType,
8268 name: "CustomExtensions-" + suffix + "-TLS13",
8269 config: Config{
8270 MaxVersion: VersionTLS13,
8271 Bugs: ProtocolBugs{
8272 CustomExtension: expectedContents,
8273 ExpectedCustomExtension: &expectedContents,
8274 },
8275 },
8276 flags: []string{flag},
8277 })
Adam Langley09505632015-07-30 18:10:13 -07008278
Steven Valdez2a070722017-03-25 20:54:16 -05008279 // 0-RTT is not currently supported with Custom Extensions.
8280 testCases = append(testCases, testCase{
8281 testType: testType,
8282 name: "CustomExtensions-" + suffix + "-EarlyData",
8283 config: Config{
8284 MaxVersion: VersionTLS13,
8285 Bugs: ProtocolBugs{
8286 CustomExtension: expectedContents,
8287 ExpectedCustomExtension: &expectedContents,
8288 },
8289 },
8290 shouldFail: true,
8291 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8292 flags: []string{flag, "-enable-early-data"},
8293 })
8294
Adam Langley09505632015-07-30 18:10:13 -07008295 // If the parse callback fails, the handshake should also fail.
8296 testCases = append(testCases, testCase{
8297 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008298 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008299 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008300 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008301 Bugs: ProtocolBugs{
8302 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008303 ExpectedCustomExtension: &expectedContents,
8304 },
8305 },
David Benjamin399e7c92015-07-30 23:01:27 -04008306 flags: []string{flag},
8307 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008308 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8309 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008310 testCases = append(testCases, testCase{
8311 testType: testType,
8312 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8313 config: Config{
8314 MaxVersion: VersionTLS13,
8315 Bugs: ProtocolBugs{
8316 CustomExtension: expectedContents + "foo",
8317 ExpectedCustomExtension: &expectedContents,
8318 },
8319 },
8320 flags: []string{flag},
8321 shouldFail: true,
8322 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8323 })
Adam Langley09505632015-07-30 18:10:13 -07008324
8325 // If the add callback fails, the handshake should also fail.
8326 testCases = append(testCases, testCase{
8327 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008328 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008330 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008331 Bugs: ProtocolBugs{
8332 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008333 ExpectedCustomExtension: &expectedContents,
8334 },
8335 },
David Benjamin399e7c92015-07-30 23:01:27 -04008336 flags: []string{flag, "-custom-extension-fail-add"},
8337 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008338 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8339 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008340 testCases = append(testCases, testCase{
8341 testType: testType,
8342 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8343 config: Config{
8344 MaxVersion: VersionTLS13,
8345 Bugs: ProtocolBugs{
8346 CustomExtension: expectedContents,
8347 ExpectedCustomExtension: &expectedContents,
8348 },
8349 },
8350 flags: []string{flag, "-custom-extension-fail-add"},
8351 shouldFail: true,
8352 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8353 })
Adam Langley09505632015-07-30 18:10:13 -07008354
8355 // If the add callback returns zero, no extension should be
8356 // added.
8357 skipCustomExtension := expectedContents
8358 if isClient {
8359 // For the case where the client skips sending the
8360 // custom extension, the server must not “echo” it.
8361 skipCustomExtension = ""
8362 }
8363 testCases = append(testCases, testCase{
8364 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008365 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008367 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008368 Bugs: ProtocolBugs{
8369 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008370 ExpectedCustomExtension: &emptyString,
8371 },
8372 },
8373 flags: []string{flag, "-custom-extension-skip"},
8374 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008375 testCases = append(testCases, testCase{
8376 testType: testType,
8377 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8378 config: Config{
8379 MaxVersion: VersionTLS13,
8380 Bugs: ProtocolBugs{
8381 CustomExtension: skipCustomExtension,
8382 ExpectedCustomExtension: &emptyString,
8383 },
8384 },
8385 flags: []string{flag, "-custom-extension-skip"},
8386 })
Adam Langley09505632015-07-30 18:10:13 -07008387 }
8388
8389 // The custom extension add callback should not be called if the client
8390 // doesn't send the extension.
8391 testCases = append(testCases, testCase{
8392 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008393 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008395 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008396 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008397 ExpectedCustomExtension: &emptyString,
8398 },
8399 },
8400 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8401 })
Adam Langley2deb9842015-08-07 11:15:37 -07008402
Steven Valdez143e8b32016-07-11 13:19:03 -04008403 testCases = append(testCases, testCase{
8404 testType: serverTest,
8405 name: "CustomExtensions-NotCalled-Server-TLS13",
8406 config: Config{
8407 MaxVersion: VersionTLS13,
8408 Bugs: ProtocolBugs{
8409 ExpectedCustomExtension: &emptyString,
8410 },
8411 },
8412 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8413 })
8414
Adam Langley2deb9842015-08-07 11:15:37 -07008415 // Test an unknown extension from the server.
8416 testCases = append(testCases, testCase{
8417 testType: clientTest,
8418 name: "UnknownExtension-Client",
8419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008420 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008421 Bugs: ProtocolBugs{
8422 CustomExtension: expectedContents,
8423 },
8424 },
David Benjamin0c40a962016-08-01 12:05:50 -04008425 shouldFail: true,
8426 expectedError: ":UNEXPECTED_EXTENSION:",
8427 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008428 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008429 testCases = append(testCases, testCase{
8430 testType: clientTest,
8431 name: "UnknownExtension-Client-TLS13",
8432 config: Config{
8433 MaxVersion: VersionTLS13,
8434 Bugs: ProtocolBugs{
8435 CustomExtension: expectedContents,
8436 },
8437 },
David Benjamin0c40a962016-08-01 12:05:50 -04008438 shouldFail: true,
8439 expectedError: ":UNEXPECTED_EXTENSION:",
8440 expectedLocalError: "remote error: unsupported extension",
8441 })
David Benjamin490469f2016-10-05 22:44:38 -04008442 testCases = append(testCases, testCase{
8443 testType: clientTest,
8444 name: "UnknownUnencryptedExtension-Client-TLS13",
8445 config: Config{
8446 MaxVersion: VersionTLS13,
8447 Bugs: ProtocolBugs{
8448 CustomUnencryptedExtension: expectedContents,
8449 },
8450 },
8451 shouldFail: true,
8452 expectedError: ":UNEXPECTED_EXTENSION:",
8453 // The shim must send an alert, but alerts at this point do not
8454 // get successfully decrypted by the runner.
8455 expectedLocalError: "local error: bad record MAC",
8456 })
8457 testCases = append(testCases, testCase{
8458 testType: clientTest,
8459 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
8462 Bugs: ProtocolBugs{
8463 SendUnencryptedALPN: "foo",
8464 },
8465 },
8466 flags: []string{
8467 "-advertise-alpn", "\x03foo\x03bar",
8468 },
8469 shouldFail: true,
8470 expectedError: ":UNEXPECTED_EXTENSION:",
8471 // The shim must send an alert, but alerts at this point do not
8472 // get successfully decrypted by the runner.
8473 expectedLocalError: "local error: bad record MAC",
8474 })
David Benjamin0c40a962016-08-01 12:05:50 -04008475
8476 // Test a known but unoffered extension from the server.
8477 testCases = append(testCases, testCase{
8478 testType: clientTest,
8479 name: "UnofferedExtension-Client",
8480 config: Config{
8481 MaxVersion: VersionTLS12,
8482 Bugs: ProtocolBugs{
8483 SendALPN: "alpn",
8484 },
8485 },
8486 shouldFail: true,
8487 expectedError: ":UNEXPECTED_EXTENSION:",
8488 expectedLocalError: "remote error: unsupported extension",
8489 })
8490 testCases = append(testCases, testCase{
8491 testType: clientTest,
8492 name: "UnofferedExtension-Client-TLS13",
8493 config: Config{
8494 MaxVersion: VersionTLS13,
8495 Bugs: ProtocolBugs{
8496 SendALPN: "alpn",
8497 },
8498 },
8499 shouldFail: true,
8500 expectedError: ":UNEXPECTED_EXTENSION:",
8501 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008502 })
Adam Langley09505632015-07-30 18:10:13 -07008503}
8504
David Benjaminb36a3952015-12-01 18:53:13 -05008505func addRSAClientKeyExchangeTests() {
8506 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8507 testCases = append(testCases, testCase{
8508 testType: serverTest,
8509 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8510 config: Config{
8511 // Ensure the ClientHello version and final
8512 // version are different, to detect if the
8513 // server uses the wrong one.
8514 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008515 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008516 Bugs: ProtocolBugs{
8517 BadRSAClientKeyExchange: bad,
8518 },
8519 },
8520 shouldFail: true,
8521 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8522 })
8523 }
David Benjamine63d9d72016-09-19 18:27:34 -04008524
8525 // The server must compare whatever was in ClientHello.version for the
8526 // RSA premaster.
8527 testCases = append(testCases, testCase{
8528 testType: serverTest,
8529 name: "SendClientVersion-RSA",
8530 config: Config{
8531 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8532 Bugs: ProtocolBugs{
8533 SendClientVersion: 0x1234,
8534 },
8535 },
8536 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8537 })
David Benjaminb36a3952015-12-01 18:53:13 -05008538}
8539
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008540var testCurves = []struct {
8541 name string
8542 id CurveID
8543}{
Adam Langley764ab982017-03-10 18:01:30 -08008544 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008545 {"P-256", CurveP256},
8546 {"P-384", CurveP384},
8547 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008548 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008549}
8550
Steven Valdez5440fe02016-07-18 12:40:30 -04008551const bogusCurve = 0x1234
8552
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008553func addCurveTests() {
8554 for _, curve := range testCurves {
8555 testCases = append(testCases, testCase{
8556 name: "CurveTest-Client-" + curve.name,
8557 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008558 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008559 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8560 CurvePreferences: []CurveID{curve.id},
8561 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008562 flags: []string{
8563 "-enable-all-curves",
8564 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8565 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008566 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008567 })
8568 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008569 name: "CurveTest-Client-" + curve.name + "-TLS13",
8570 config: Config{
8571 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008572 CurvePreferences: []CurveID{curve.id},
8573 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008574 flags: []string{
8575 "-enable-all-curves",
8576 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8577 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008578 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008579 })
8580 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008581 testType: serverTest,
8582 name: "CurveTest-Server-" + curve.name,
8583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008584 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008585 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8586 CurvePreferences: []CurveID{curve.id},
8587 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008588 flags: []string{
8589 "-enable-all-curves",
8590 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8591 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008592 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008593 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008594 testCases = append(testCases, testCase{
8595 testType: serverTest,
8596 name: "CurveTest-Server-" + curve.name + "-TLS13",
8597 config: Config{
8598 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008599 CurvePreferences: []CurveID{curve.id},
8600 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008601 flags: []string{
8602 "-enable-all-curves",
8603 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8604 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008605 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008606 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008607 }
David Benjamin241ae832016-01-15 03:04:54 -05008608
8609 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008610 testCases = append(testCases, testCase{
8611 testType: serverTest,
8612 name: "UnknownCurve",
8613 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008614 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008615 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8616 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8617 },
8618 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008619
Steven Valdez803c77a2016-09-06 14:13:43 -04008620 // The server must be tolerant to bogus curves.
8621 testCases = append(testCases, testCase{
8622 testType: serverTest,
8623 name: "UnknownCurve-TLS13",
8624 config: Config{
8625 MaxVersion: VersionTLS13,
8626 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8627 },
8628 })
8629
David Benjamin4c3ddf72016-06-29 18:13:53 -04008630 // The server must not consider ECDHE ciphers when there are no
8631 // supported curves.
8632 testCases = append(testCases, testCase{
8633 testType: serverTest,
8634 name: "NoSupportedCurves",
8635 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008636 MaxVersion: VersionTLS12,
8637 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8638 Bugs: ProtocolBugs{
8639 NoSupportedCurves: true,
8640 },
8641 },
8642 shouldFail: true,
8643 expectedError: ":NO_SHARED_CIPHER:",
8644 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008645 testCases = append(testCases, testCase{
8646 testType: serverTest,
8647 name: "NoSupportedCurves-TLS13",
8648 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008649 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008650 Bugs: ProtocolBugs{
8651 NoSupportedCurves: true,
8652 },
8653 },
8654 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008655 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008656 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008657
8658 // The server must fall back to another cipher when there are no
8659 // supported curves.
8660 testCases = append(testCases, testCase{
8661 testType: serverTest,
8662 name: "NoCommonCurves",
8663 config: Config{
8664 MaxVersion: VersionTLS12,
8665 CipherSuites: []uint16{
8666 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008667 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008668 },
8669 CurvePreferences: []CurveID{CurveP224},
8670 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008671 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008672 })
8673
8674 // The client must reject bogus curves and disabled curves.
8675 testCases = append(testCases, testCase{
8676 name: "BadECDHECurve",
8677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008678 MaxVersion: VersionTLS12,
8679 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8680 Bugs: ProtocolBugs{
8681 SendCurve: bogusCurve,
8682 },
8683 },
8684 shouldFail: true,
8685 expectedError: ":WRONG_CURVE:",
8686 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008687 testCases = append(testCases, testCase{
8688 name: "BadECDHECurve-TLS13",
8689 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008690 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008691 Bugs: ProtocolBugs{
8692 SendCurve: bogusCurve,
8693 },
8694 },
8695 shouldFail: true,
8696 expectedError: ":WRONG_CURVE:",
8697 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008698
8699 testCases = append(testCases, testCase{
8700 name: "UnsupportedCurve",
8701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008702 MaxVersion: VersionTLS12,
8703 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8704 CurvePreferences: []CurveID{CurveP256},
8705 Bugs: ProtocolBugs{
8706 IgnorePeerCurvePreferences: true,
8707 },
8708 },
8709 flags: []string{"-p384-only"},
8710 shouldFail: true,
8711 expectedError: ":WRONG_CURVE:",
8712 })
8713
David Benjamin4f921572016-07-17 14:20:10 +02008714 testCases = append(testCases, testCase{
8715 // TODO(davidben): Add a TLS 1.3 version where
8716 // HelloRetryRequest requests an unsupported curve.
8717 name: "UnsupportedCurve-ServerHello-TLS13",
8718 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008719 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008720 CurvePreferences: []CurveID{CurveP384},
8721 Bugs: ProtocolBugs{
8722 SendCurve: CurveP256,
8723 },
8724 },
8725 flags: []string{"-p384-only"},
8726 shouldFail: true,
8727 expectedError: ":WRONG_CURVE:",
8728 })
8729
David Benjamin4c3ddf72016-06-29 18:13:53 -04008730 // Test invalid curve points.
8731 testCases = append(testCases, testCase{
8732 name: "InvalidECDHPoint-Client",
8733 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008734 MaxVersion: VersionTLS12,
8735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8736 CurvePreferences: []CurveID{CurveP256},
8737 Bugs: ProtocolBugs{
8738 InvalidECDHPoint: true,
8739 },
8740 },
8741 shouldFail: true,
8742 expectedError: ":INVALID_ENCODING:",
8743 })
8744 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008745 name: "InvalidECDHPoint-Client-TLS13",
8746 config: Config{
8747 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008748 CurvePreferences: []CurveID{CurveP256},
8749 Bugs: ProtocolBugs{
8750 InvalidECDHPoint: true,
8751 },
8752 },
8753 shouldFail: true,
8754 expectedError: ":INVALID_ENCODING:",
8755 })
8756 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008757 testType: serverTest,
8758 name: "InvalidECDHPoint-Server",
8759 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008760 MaxVersion: VersionTLS12,
8761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8762 CurvePreferences: []CurveID{CurveP256},
8763 Bugs: ProtocolBugs{
8764 InvalidECDHPoint: true,
8765 },
8766 },
8767 shouldFail: true,
8768 expectedError: ":INVALID_ENCODING:",
8769 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008770 testCases = append(testCases, testCase{
8771 testType: serverTest,
8772 name: "InvalidECDHPoint-Server-TLS13",
8773 config: Config{
8774 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008775 CurvePreferences: []CurveID{CurveP256},
8776 Bugs: ProtocolBugs{
8777 InvalidECDHPoint: true,
8778 },
8779 },
8780 shouldFail: true,
8781 expectedError: ":INVALID_ENCODING:",
8782 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008783
8784 // The previous curve ID should be reported on TLS 1.2 resumption.
8785 testCases = append(testCases, testCase{
8786 name: "CurveID-Resume-Client",
8787 config: Config{
8788 MaxVersion: VersionTLS12,
8789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8790 CurvePreferences: []CurveID{CurveX25519},
8791 },
8792 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8793 resumeSession: true,
8794 })
8795 testCases = append(testCases, testCase{
8796 testType: serverTest,
8797 name: "CurveID-Resume-Server",
8798 config: Config{
8799 MaxVersion: VersionTLS12,
8800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8801 CurvePreferences: []CurveID{CurveX25519},
8802 },
8803 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8804 resumeSession: true,
8805 })
8806
8807 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8808 // one should be reported.
8809 testCases = append(testCases, testCase{
8810 name: "CurveID-Resume-Client-TLS13",
8811 config: Config{
8812 MaxVersion: VersionTLS13,
8813 CurvePreferences: []CurveID{CurveX25519},
8814 },
8815 resumeConfig: &Config{
8816 MaxVersion: VersionTLS13,
8817 CurvePreferences: []CurveID{CurveP256},
8818 },
8819 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008820 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8821 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008822 },
8823 resumeSession: true,
8824 })
8825 testCases = append(testCases, testCase{
8826 testType: serverTest,
8827 name: "CurveID-Resume-Server-TLS13",
8828 config: Config{
8829 MaxVersion: VersionTLS13,
8830 CurvePreferences: []CurveID{CurveX25519},
8831 },
8832 resumeConfig: &Config{
8833 MaxVersion: VersionTLS13,
8834 CurvePreferences: []CurveID{CurveP256},
8835 },
8836 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008837 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8838 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008839 },
8840 resumeSession: true,
8841 })
David Benjamina81967b2016-12-22 09:16:57 -05008842
8843 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8844 testCases = append(testCases, testCase{
8845 name: "PointFormat-ServerHello-TLS12",
8846 config: Config{
8847 MaxVersion: VersionTLS12,
8848 Bugs: ProtocolBugs{
8849 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8850 },
8851 },
8852 })
8853 testCases = append(testCases, testCase{
8854 name: "PointFormat-EncryptedExtensions-TLS13",
8855 config: Config{
8856 MaxVersion: VersionTLS13,
8857 Bugs: ProtocolBugs{
8858 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8859 },
8860 },
8861 shouldFail: true,
8862 expectedError: ":ERROR_PARSING_EXTENSION:",
8863 })
8864
8865 // Test that we tolerate unknown point formats, as long as
8866 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8867 // check they are still functional.
8868 testCases = append(testCases, testCase{
8869 name: "PointFormat-Client-Tolerance",
8870 config: Config{
8871 MaxVersion: VersionTLS12,
8872 Bugs: ProtocolBugs{
8873 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8874 },
8875 },
8876 })
8877 testCases = append(testCases, testCase{
8878 testType: serverTest,
8879 name: "PointFormat-Server-Tolerance",
8880 config: Config{
8881 MaxVersion: VersionTLS12,
8882 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8883 Bugs: ProtocolBugs{
8884 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8885 },
8886 },
8887 })
8888
8889 // Test TLS 1.2 does not require the point format extension to be
8890 // present.
8891 testCases = append(testCases, testCase{
8892 name: "PointFormat-Client-Missing",
8893 config: Config{
8894 MaxVersion: VersionTLS12,
8895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8896 Bugs: ProtocolBugs{
8897 SendSupportedPointFormats: []byte{},
8898 },
8899 },
8900 })
8901 testCases = append(testCases, testCase{
8902 testType: serverTest,
8903 name: "PointFormat-Server-Missing",
8904 config: Config{
8905 MaxVersion: VersionTLS12,
8906 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8907 Bugs: ProtocolBugs{
8908 SendSupportedPointFormats: []byte{},
8909 },
8910 },
8911 })
8912
8913 // If the point format extension is present, uncompressed points must be
8914 // offered. BoringSSL requires this whether or not ECDHE is used.
8915 testCases = append(testCases, testCase{
8916 name: "PointFormat-Client-MissingUncompressed",
8917 config: Config{
8918 MaxVersion: VersionTLS12,
8919 Bugs: ProtocolBugs{
8920 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8921 },
8922 },
8923 shouldFail: true,
8924 expectedError: ":ERROR_PARSING_EXTENSION:",
8925 })
8926 testCases = append(testCases, testCase{
8927 testType: serverTest,
8928 name: "PointFormat-Server-MissingUncompressed",
8929 config: Config{
8930 MaxVersion: VersionTLS12,
8931 Bugs: ProtocolBugs{
8932 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8933 },
8934 },
8935 shouldFail: true,
8936 expectedError: ":ERROR_PARSING_EXTENSION:",
8937 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008938}
8939
David Benjaminc9ae27c2016-06-24 22:56:37 -04008940func addTLS13RecordTests() {
8941 testCases = append(testCases, testCase{
8942 name: "TLS13-RecordPadding",
8943 config: Config{
8944 MaxVersion: VersionTLS13,
8945 MinVersion: VersionTLS13,
8946 Bugs: ProtocolBugs{
8947 RecordPadding: 10,
8948 },
8949 },
8950 })
8951
8952 testCases = append(testCases, testCase{
8953 name: "TLS13-EmptyRecords",
8954 config: Config{
8955 MaxVersion: VersionTLS13,
8956 MinVersion: VersionTLS13,
8957 Bugs: ProtocolBugs{
8958 OmitRecordContents: true,
8959 },
8960 },
8961 shouldFail: true,
8962 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8963 })
8964
8965 testCases = append(testCases, testCase{
8966 name: "TLS13-OnlyPadding",
8967 config: Config{
8968 MaxVersion: VersionTLS13,
8969 MinVersion: VersionTLS13,
8970 Bugs: ProtocolBugs{
8971 OmitRecordContents: true,
8972 RecordPadding: 10,
8973 },
8974 },
8975 shouldFail: true,
8976 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8977 })
8978
8979 testCases = append(testCases, testCase{
8980 name: "TLS13-WrongOuterRecord",
8981 config: Config{
8982 MaxVersion: VersionTLS13,
8983 MinVersion: VersionTLS13,
8984 Bugs: ProtocolBugs{
8985 OuterRecordType: recordTypeHandshake,
8986 },
8987 },
8988 shouldFail: true,
8989 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8990 })
8991}
8992
Steven Valdez5b986082016-09-01 12:29:49 -04008993func addSessionTicketTests() {
8994 testCases = append(testCases, testCase{
8995 // In TLS 1.2 and below, empty NewSessionTicket messages
8996 // mean the server changed its mind on sending a ticket.
8997 name: "SendEmptySessionTicket",
8998 config: Config{
8999 MaxVersion: VersionTLS12,
9000 Bugs: ProtocolBugs{
9001 SendEmptySessionTicket: true,
9002 },
9003 },
9004 flags: []string{"-expect-no-session"},
9005 })
9006
9007 // Test that the server ignores unknown PSK modes.
9008 testCases = append(testCases, testCase{
9009 testType: serverTest,
9010 name: "TLS13-SendUnknownModeSessionTicket-Server",
9011 config: Config{
9012 MaxVersion: VersionTLS13,
9013 Bugs: ProtocolBugs{
9014 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009015 },
9016 },
9017 resumeSession: true,
9018 expectedResumeVersion: VersionTLS13,
9019 })
9020
Steven Valdeza833c352016-11-01 13:39:36 -04009021 // Test that the server does not send session tickets with no matching key exchange mode.
9022 testCases = append(testCases, testCase{
9023 testType: serverTest,
9024 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9025 config: Config{
9026 MaxVersion: VersionTLS13,
9027 Bugs: ProtocolBugs{
9028 SendPSKKeyExchangeModes: []byte{0x1a},
9029 ExpectNoNewSessionTicket: true,
9030 },
9031 },
9032 })
9033
9034 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009035 testCases = append(testCases, testCase{
9036 testType: serverTest,
9037 name: "TLS13-SendBadKEModeSessionTicket-Server",
9038 config: Config{
9039 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009040 },
9041 resumeConfig: &Config{
9042 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009043 Bugs: ProtocolBugs{
9044 SendPSKKeyExchangeModes: []byte{0x1a},
9045 },
9046 },
9047 resumeSession: true,
9048 expectResumeRejected: true,
9049 })
9050
Steven Valdeza833c352016-11-01 13:39:36 -04009051 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009052 testCases = append(testCases, testCase{
9053 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009054 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009055 config: Config{
9056 MaxVersion: VersionTLS13,
9057 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009058 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009059 },
9060 },
Steven Valdeza833c352016-11-01 13:39:36 -04009061 resumeSession: true,
9062 flags: []string{
9063 "-resumption-delay", "10",
9064 },
Steven Valdez5b986082016-09-01 12:29:49 -04009065 })
9066
Steven Valdeza833c352016-11-01 13:39:36 -04009067 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009068 testCases = append(testCases, testCase{
9069 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009070 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009071 config: Config{
9072 MaxVersion: VersionTLS13,
9073 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009074 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009075 },
9076 },
Steven Valdeza833c352016-11-01 13:39:36 -04009077 resumeSession: true,
9078 shouldFail: true,
9079 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009080 })
9081
David Benjamin35ac5b72017-03-03 15:05:56 -05009082 // Test that the server's ticket age skew reporting works.
9083 testCases = append(testCases, testCase{
9084 testType: serverTest,
9085 name: "TLS13-TicketAgeSkew-Forward",
9086 config: Config{
9087 MaxVersion: VersionTLS13,
9088 Bugs: ProtocolBugs{
9089 SendTicketAge: 15 * time.Second,
9090 },
9091 },
David Benjamin065d7332017-03-26 10:51:43 -05009092 resumeSession: true,
9093 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009094 flags: []string{
9095 "-resumption-delay", "10",
9096 "-expect-ticket-age-skew", "5",
9097 },
9098 })
9099 testCases = append(testCases, testCase{
9100 testType: serverTest,
9101 name: "TLS13-TicketAgeSkew-Backward",
9102 config: Config{
9103 MaxVersion: VersionTLS13,
9104 Bugs: ProtocolBugs{
9105 SendTicketAge: 5 * time.Second,
9106 },
9107 },
David Benjamin065d7332017-03-26 10:51:43 -05009108 resumeSession: true,
9109 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009110 flags: []string{
9111 "-resumption-delay", "10",
9112 "-expect-ticket-age-skew", "-5",
9113 },
9114 })
9115
Steven Valdez08b65f42016-12-07 15:29:45 -05009116 testCases = append(testCases, testCase{
9117 testType: clientTest,
9118 name: "TLS13-SendTicketEarlyDataInfo",
9119 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009120 MaxVersion: VersionTLS13,
9121 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009122 },
9123 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009124 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009125 "-expect-early-data-info",
9126 },
9127 })
9128
David Benjamin9b160662017-01-25 19:53:43 -05009129 // Test that 0-RTT tickets are ignored in clients unless opted in.
9130 testCases = append(testCases, testCase{
9131 testType: clientTest,
9132 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9133 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009134 MaxVersion: VersionTLS13,
9135 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009136 },
9137 })
9138
Steven Valdez08b65f42016-12-07 15:29:45 -05009139 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009140 testType: clientTest,
9141 name: "TLS13-DuplicateTicketEarlyDataInfo",
9142 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009143 MaxVersion: VersionTLS13,
9144 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009145 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009146 DuplicateTicketEarlyDataInfo: true,
9147 },
9148 },
9149 shouldFail: true,
9150 expectedError: ":DUPLICATE_EXTENSION:",
9151 expectedLocalError: "remote error: illegal parameter",
9152 })
9153
9154 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009155 testType: serverTest,
9156 name: "TLS13-ExpectTicketEarlyDataInfo",
9157 config: Config{
9158 MaxVersion: VersionTLS13,
9159 Bugs: ProtocolBugs{
9160 ExpectTicketEarlyDataInfo: true,
9161 },
9162 },
9163 flags: []string{
9164 "-enable-early-data",
9165 },
9166 })
David Benjamin17b30832017-01-28 14:00:32 -05009167
9168 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9169 // is honored.
9170 testCases = append(testCases, testCase{
9171 testType: clientTest,
9172 name: "TLS13-HonorServerSessionTicketLifetime",
9173 config: Config{
9174 MaxVersion: VersionTLS13,
9175 Bugs: ProtocolBugs{
9176 SendTicketLifetime: 20 * time.Second,
9177 },
9178 },
9179 flags: []string{
9180 "-resumption-delay", "19",
9181 },
9182 resumeSession: true,
9183 })
9184 testCases = append(testCases, testCase{
9185 testType: clientTest,
9186 name: "TLS13-HonorServerSessionTicketLifetime-2",
9187 config: Config{
9188 MaxVersion: VersionTLS13,
9189 Bugs: ProtocolBugs{
9190 SendTicketLifetime: 20 * time.Second,
9191 // The client should not offer the expired session.
9192 ExpectNoTLS13PSK: true,
9193 },
9194 },
9195 flags: []string{
9196 "-resumption-delay", "21",
9197 },
David Benjamin023d4192017-02-06 13:49:07 -05009198 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009199 expectResumeRejected: true,
9200 })
Steven Valdez5b986082016-09-01 12:29:49 -04009201}
9202
David Benjamin82261be2016-07-07 14:32:50 -07009203func addChangeCipherSpecTests() {
9204 // Test missing ChangeCipherSpecs.
9205 testCases = append(testCases, testCase{
9206 name: "SkipChangeCipherSpec-Client",
9207 config: Config{
9208 MaxVersion: VersionTLS12,
9209 Bugs: ProtocolBugs{
9210 SkipChangeCipherSpec: true,
9211 },
9212 },
9213 shouldFail: true,
9214 expectedError: ":UNEXPECTED_RECORD:",
9215 })
9216 testCases = append(testCases, testCase{
9217 testType: serverTest,
9218 name: "SkipChangeCipherSpec-Server",
9219 config: Config{
9220 MaxVersion: VersionTLS12,
9221 Bugs: ProtocolBugs{
9222 SkipChangeCipherSpec: true,
9223 },
9224 },
9225 shouldFail: true,
9226 expectedError: ":UNEXPECTED_RECORD:",
9227 })
9228 testCases = append(testCases, testCase{
9229 testType: serverTest,
9230 name: "SkipChangeCipherSpec-Server-NPN",
9231 config: Config{
9232 MaxVersion: VersionTLS12,
9233 NextProtos: []string{"bar"},
9234 Bugs: ProtocolBugs{
9235 SkipChangeCipherSpec: true,
9236 },
9237 },
9238 flags: []string{
9239 "-advertise-npn", "\x03foo\x03bar\x03baz",
9240 },
9241 shouldFail: true,
9242 expectedError: ":UNEXPECTED_RECORD:",
9243 })
9244
9245 // Test synchronization between the handshake and ChangeCipherSpec.
9246 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9247 // rejected. Test both with and without handshake packing to handle both
9248 // when the partial post-CCS message is in its own record and when it is
9249 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009250 for _, packed := range []bool{false, true} {
9251 var suffix string
9252 if packed {
9253 suffix = "-Packed"
9254 }
9255
9256 testCases = append(testCases, testCase{
9257 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9258 config: Config{
9259 MaxVersion: VersionTLS12,
9260 Bugs: ProtocolBugs{
9261 FragmentAcrossChangeCipherSpec: true,
9262 PackHandshakeFlight: packed,
9263 },
9264 },
9265 shouldFail: true,
9266 expectedError: ":UNEXPECTED_RECORD:",
9267 })
9268 testCases = append(testCases, testCase{
9269 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9270 config: Config{
9271 MaxVersion: VersionTLS12,
9272 },
9273 resumeSession: true,
9274 resumeConfig: &Config{
9275 MaxVersion: VersionTLS12,
9276 Bugs: ProtocolBugs{
9277 FragmentAcrossChangeCipherSpec: true,
9278 PackHandshakeFlight: packed,
9279 },
9280 },
9281 shouldFail: true,
9282 expectedError: ":UNEXPECTED_RECORD:",
9283 })
9284 testCases = append(testCases, testCase{
9285 testType: serverTest,
9286 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9287 config: Config{
9288 MaxVersion: VersionTLS12,
9289 Bugs: ProtocolBugs{
9290 FragmentAcrossChangeCipherSpec: true,
9291 PackHandshakeFlight: packed,
9292 },
9293 },
9294 shouldFail: true,
9295 expectedError: ":UNEXPECTED_RECORD:",
9296 })
9297 testCases = append(testCases, testCase{
9298 testType: serverTest,
9299 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9300 config: Config{
9301 MaxVersion: VersionTLS12,
9302 },
9303 resumeSession: true,
9304 resumeConfig: &Config{
9305 MaxVersion: VersionTLS12,
9306 Bugs: ProtocolBugs{
9307 FragmentAcrossChangeCipherSpec: true,
9308 PackHandshakeFlight: packed,
9309 },
9310 },
9311 shouldFail: true,
9312 expectedError: ":UNEXPECTED_RECORD:",
9313 })
9314 testCases = append(testCases, testCase{
9315 testType: serverTest,
9316 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9317 config: Config{
9318 MaxVersion: VersionTLS12,
9319 NextProtos: []string{"bar"},
9320 Bugs: ProtocolBugs{
9321 FragmentAcrossChangeCipherSpec: true,
9322 PackHandshakeFlight: packed,
9323 },
9324 },
9325 flags: []string{
9326 "-advertise-npn", "\x03foo\x03bar\x03baz",
9327 },
9328 shouldFail: true,
9329 expectedError: ":UNEXPECTED_RECORD:",
9330 })
9331 }
9332
David Benjamin61672812016-07-14 23:10:43 -04009333 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9334 // messages in the handshake queue. Do this by testing the server
9335 // reading the client Finished, reversing the flight so Finished comes
9336 // first.
9337 testCases = append(testCases, testCase{
9338 protocol: dtls,
9339 testType: serverTest,
9340 name: "SendUnencryptedFinished-DTLS",
9341 config: Config{
9342 MaxVersion: VersionTLS12,
9343 Bugs: ProtocolBugs{
9344 SendUnencryptedFinished: true,
9345 ReverseHandshakeFragments: true,
9346 },
9347 },
9348 shouldFail: true,
9349 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9350 })
9351
Steven Valdez143e8b32016-07-11 13:19:03 -04009352 // Test synchronization between encryption changes and the handshake in
9353 // TLS 1.3, where ChangeCipherSpec is implicit.
9354 testCases = append(testCases, testCase{
9355 name: "PartialEncryptedExtensionsWithServerHello",
9356 config: Config{
9357 MaxVersion: VersionTLS13,
9358 Bugs: ProtocolBugs{
9359 PartialEncryptedExtensionsWithServerHello: true,
9360 },
9361 },
9362 shouldFail: true,
9363 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9364 })
9365 testCases = append(testCases, testCase{
9366 testType: serverTest,
9367 name: "PartialClientFinishedWithClientHello",
9368 config: Config{
9369 MaxVersion: VersionTLS13,
9370 Bugs: ProtocolBugs{
9371 PartialClientFinishedWithClientHello: true,
9372 },
9373 },
9374 shouldFail: true,
9375 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9376 })
9377
David Benjamin82261be2016-07-07 14:32:50 -07009378 // Test that early ChangeCipherSpecs are handled correctly.
9379 testCases = append(testCases, testCase{
9380 testType: serverTest,
9381 name: "EarlyChangeCipherSpec-server-1",
9382 config: Config{
9383 MaxVersion: VersionTLS12,
9384 Bugs: ProtocolBugs{
9385 EarlyChangeCipherSpec: 1,
9386 },
9387 },
9388 shouldFail: true,
9389 expectedError: ":UNEXPECTED_RECORD:",
9390 })
9391 testCases = append(testCases, testCase{
9392 testType: serverTest,
9393 name: "EarlyChangeCipherSpec-server-2",
9394 config: Config{
9395 MaxVersion: VersionTLS12,
9396 Bugs: ProtocolBugs{
9397 EarlyChangeCipherSpec: 2,
9398 },
9399 },
9400 shouldFail: true,
9401 expectedError: ":UNEXPECTED_RECORD:",
9402 })
9403 testCases = append(testCases, testCase{
9404 protocol: dtls,
9405 name: "StrayChangeCipherSpec",
9406 config: Config{
9407 // TODO(davidben): Once DTLS 1.3 exists, test
9408 // that stray ChangeCipherSpec messages are
9409 // rejected.
9410 MaxVersion: VersionTLS12,
9411 Bugs: ProtocolBugs{
9412 StrayChangeCipherSpec: true,
9413 },
9414 },
9415 })
9416
9417 // Test that the contents of ChangeCipherSpec are checked.
9418 testCases = append(testCases, testCase{
9419 name: "BadChangeCipherSpec-1",
9420 config: Config{
9421 MaxVersion: VersionTLS12,
9422 Bugs: ProtocolBugs{
9423 BadChangeCipherSpec: []byte{2},
9424 },
9425 },
9426 shouldFail: true,
9427 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9428 })
9429 testCases = append(testCases, testCase{
9430 name: "BadChangeCipherSpec-2",
9431 config: Config{
9432 MaxVersion: VersionTLS12,
9433 Bugs: ProtocolBugs{
9434 BadChangeCipherSpec: []byte{1, 1},
9435 },
9436 },
9437 shouldFail: true,
9438 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9439 })
9440 testCases = append(testCases, testCase{
9441 protocol: dtls,
9442 name: "BadChangeCipherSpec-DTLS-1",
9443 config: Config{
9444 MaxVersion: VersionTLS12,
9445 Bugs: ProtocolBugs{
9446 BadChangeCipherSpec: []byte{2},
9447 },
9448 },
9449 shouldFail: true,
9450 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9451 })
9452 testCases = append(testCases, testCase{
9453 protocol: dtls,
9454 name: "BadChangeCipherSpec-DTLS-2",
9455 config: Config{
9456 MaxVersion: VersionTLS12,
9457 Bugs: ProtocolBugs{
9458 BadChangeCipherSpec: []byte{1, 1},
9459 },
9460 },
9461 shouldFail: true,
9462 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9463 })
9464}
9465
David Benjamincd2c8062016-09-09 11:28:16 -04009466type perMessageTest struct {
9467 messageType uint8
9468 test testCase
9469}
9470
9471// makePerMessageTests returns a series of test templates which cover each
9472// message in the TLS handshake. These may be used with bugs like
9473// WrongMessageType to fully test a per-message bug.
9474func makePerMessageTests() []perMessageTest {
9475 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009476 for _, protocol := range []protocol{tls, dtls} {
9477 var suffix string
9478 if protocol == dtls {
9479 suffix = "-DTLS"
9480 }
9481
David Benjamincd2c8062016-09-09 11:28:16 -04009482 ret = append(ret, perMessageTest{
9483 messageType: typeClientHello,
9484 test: testCase{
9485 protocol: protocol,
9486 testType: serverTest,
9487 name: "ClientHello" + suffix,
9488 config: Config{
9489 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009490 },
9491 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009492 })
9493
9494 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009495 ret = append(ret, perMessageTest{
9496 messageType: typeHelloVerifyRequest,
9497 test: testCase{
9498 protocol: protocol,
9499 name: "HelloVerifyRequest" + suffix,
9500 config: Config{
9501 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009502 },
9503 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009504 })
9505 }
9506
David Benjamincd2c8062016-09-09 11:28:16 -04009507 ret = append(ret, perMessageTest{
9508 messageType: typeServerHello,
9509 test: testCase{
9510 protocol: protocol,
9511 name: "ServerHello" + suffix,
9512 config: Config{
9513 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009514 },
9515 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009516 })
9517
David Benjamincd2c8062016-09-09 11:28:16 -04009518 ret = append(ret, perMessageTest{
9519 messageType: typeCertificate,
9520 test: testCase{
9521 protocol: protocol,
9522 name: "ServerCertificate" + suffix,
9523 config: Config{
9524 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009525 },
9526 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009527 })
9528
David Benjamincd2c8062016-09-09 11:28:16 -04009529 ret = append(ret, perMessageTest{
9530 messageType: typeCertificateStatus,
9531 test: testCase{
9532 protocol: protocol,
9533 name: "CertificateStatus" + suffix,
9534 config: Config{
9535 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009536 },
David Benjamincd2c8062016-09-09 11:28:16 -04009537 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009538 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009539 })
9540
David Benjamincd2c8062016-09-09 11:28:16 -04009541 ret = append(ret, perMessageTest{
9542 messageType: typeServerKeyExchange,
9543 test: testCase{
9544 protocol: protocol,
9545 name: "ServerKeyExchange" + suffix,
9546 config: Config{
9547 MaxVersion: VersionTLS12,
9548 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009549 },
9550 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009551 })
9552
David Benjamincd2c8062016-09-09 11:28:16 -04009553 ret = append(ret, perMessageTest{
9554 messageType: typeCertificateRequest,
9555 test: testCase{
9556 protocol: protocol,
9557 name: "CertificateRequest" + suffix,
9558 config: Config{
9559 MaxVersion: VersionTLS12,
9560 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009561 },
9562 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009563 })
9564
David Benjamincd2c8062016-09-09 11:28:16 -04009565 ret = append(ret, perMessageTest{
9566 messageType: typeServerHelloDone,
9567 test: testCase{
9568 protocol: protocol,
9569 name: "ServerHelloDone" + suffix,
9570 config: Config{
9571 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009572 },
9573 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009574 })
9575
David Benjamincd2c8062016-09-09 11:28:16 -04009576 ret = append(ret, perMessageTest{
9577 messageType: typeCertificate,
9578 test: testCase{
9579 testType: serverTest,
9580 protocol: protocol,
9581 name: "ClientCertificate" + suffix,
9582 config: Config{
9583 Certificates: []Certificate{rsaCertificate},
9584 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009585 },
David Benjamincd2c8062016-09-09 11:28:16 -04009586 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009587 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009588 })
9589
David Benjamincd2c8062016-09-09 11:28:16 -04009590 ret = append(ret, perMessageTest{
9591 messageType: typeCertificateVerify,
9592 test: testCase{
9593 testType: serverTest,
9594 protocol: protocol,
9595 name: "CertificateVerify" + suffix,
9596 config: Config{
9597 Certificates: []Certificate{rsaCertificate},
9598 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009599 },
David Benjamincd2c8062016-09-09 11:28:16 -04009600 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009601 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009602 })
9603
David Benjamincd2c8062016-09-09 11:28:16 -04009604 ret = append(ret, perMessageTest{
9605 messageType: typeClientKeyExchange,
9606 test: testCase{
9607 testType: serverTest,
9608 protocol: protocol,
9609 name: "ClientKeyExchange" + suffix,
9610 config: Config{
9611 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009612 },
9613 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009614 })
9615
9616 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009617 ret = append(ret, perMessageTest{
9618 messageType: typeNextProtocol,
9619 test: testCase{
9620 testType: serverTest,
9621 protocol: protocol,
9622 name: "NextProtocol" + suffix,
9623 config: Config{
9624 MaxVersion: VersionTLS12,
9625 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009626 },
David Benjamincd2c8062016-09-09 11:28:16 -04009627 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009628 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009629 })
9630
David Benjamincd2c8062016-09-09 11:28:16 -04009631 ret = append(ret, perMessageTest{
9632 messageType: typeChannelID,
9633 test: testCase{
9634 testType: serverTest,
9635 protocol: protocol,
9636 name: "ChannelID" + suffix,
9637 config: Config{
9638 MaxVersion: VersionTLS12,
9639 ChannelID: channelIDKey,
9640 },
9641 flags: []string{
9642 "-expect-channel-id",
9643 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009644 },
9645 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009646 })
9647 }
9648
David Benjamincd2c8062016-09-09 11:28:16 -04009649 ret = append(ret, perMessageTest{
9650 messageType: typeFinished,
9651 test: testCase{
9652 testType: serverTest,
9653 protocol: protocol,
9654 name: "ClientFinished" + suffix,
9655 config: Config{
9656 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009657 },
9658 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009659 })
9660
David Benjamincd2c8062016-09-09 11:28:16 -04009661 ret = append(ret, perMessageTest{
9662 messageType: typeNewSessionTicket,
9663 test: testCase{
9664 protocol: protocol,
9665 name: "NewSessionTicket" + suffix,
9666 config: Config{
9667 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009668 },
9669 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009670 })
9671
David Benjamincd2c8062016-09-09 11:28:16 -04009672 ret = append(ret, perMessageTest{
9673 messageType: typeFinished,
9674 test: testCase{
9675 protocol: protocol,
9676 name: "ServerFinished" + suffix,
9677 config: Config{
9678 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009679 },
9680 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009681 })
9682
9683 }
David Benjamincd2c8062016-09-09 11:28:16 -04009684
9685 ret = append(ret, perMessageTest{
9686 messageType: typeClientHello,
9687 test: testCase{
9688 testType: serverTest,
9689 name: "TLS13-ClientHello",
9690 config: Config{
9691 MaxVersion: VersionTLS13,
9692 },
9693 },
9694 })
9695
9696 ret = append(ret, perMessageTest{
9697 messageType: typeServerHello,
9698 test: testCase{
9699 name: "TLS13-ServerHello",
9700 config: Config{
9701 MaxVersion: VersionTLS13,
9702 },
9703 },
9704 })
9705
9706 ret = append(ret, perMessageTest{
9707 messageType: typeEncryptedExtensions,
9708 test: testCase{
9709 name: "TLS13-EncryptedExtensions",
9710 config: Config{
9711 MaxVersion: VersionTLS13,
9712 },
9713 },
9714 })
9715
9716 ret = append(ret, perMessageTest{
9717 messageType: typeCertificateRequest,
9718 test: testCase{
9719 name: "TLS13-CertificateRequest",
9720 config: Config{
9721 MaxVersion: VersionTLS13,
9722 ClientAuth: RequireAnyClientCert,
9723 },
9724 },
9725 })
9726
9727 ret = append(ret, perMessageTest{
9728 messageType: typeCertificate,
9729 test: testCase{
9730 name: "TLS13-ServerCertificate",
9731 config: Config{
9732 MaxVersion: VersionTLS13,
9733 },
9734 },
9735 })
9736
9737 ret = append(ret, perMessageTest{
9738 messageType: typeCertificateVerify,
9739 test: testCase{
9740 name: "TLS13-ServerCertificateVerify",
9741 config: Config{
9742 MaxVersion: VersionTLS13,
9743 },
9744 },
9745 })
9746
9747 ret = append(ret, perMessageTest{
9748 messageType: typeFinished,
9749 test: testCase{
9750 name: "TLS13-ServerFinished",
9751 config: Config{
9752 MaxVersion: VersionTLS13,
9753 },
9754 },
9755 })
9756
9757 ret = append(ret, perMessageTest{
9758 messageType: typeCertificate,
9759 test: testCase{
9760 testType: serverTest,
9761 name: "TLS13-ClientCertificate",
9762 config: Config{
9763 Certificates: []Certificate{rsaCertificate},
9764 MaxVersion: VersionTLS13,
9765 },
9766 flags: []string{"-require-any-client-certificate"},
9767 },
9768 })
9769
9770 ret = append(ret, perMessageTest{
9771 messageType: typeCertificateVerify,
9772 test: testCase{
9773 testType: serverTest,
9774 name: "TLS13-ClientCertificateVerify",
9775 config: Config{
9776 Certificates: []Certificate{rsaCertificate},
9777 MaxVersion: VersionTLS13,
9778 },
9779 flags: []string{"-require-any-client-certificate"},
9780 },
9781 })
9782
9783 ret = append(ret, perMessageTest{
9784 messageType: typeFinished,
9785 test: testCase{
9786 testType: serverTest,
9787 name: "TLS13-ClientFinished",
9788 config: Config{
9789 MaxVersion: VersionTLS13,
9790 },
9791 },
9792 })
9793
9794 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009795}
9796
David Benjamincd2c8062016-09-09 11:28:16 -04009797func addWrongMessageTypeTests() {
9798 for _, t := range makePerMessageTests() {
9799 t.test.name = "WrongMessageType-" + t.test.name
9800 t.test.config.Bugs.SendWrongMessageType = t.messageType
9801 t.test.shouldFail = true
9802 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9803 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009804
David Benjamincd2c8062016-09-09 11:28:16 -04009805 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9806 // In TLS 1.3, a bad ServerHello means the client sends
9807 // an unencrypted alert while the server expects
9808 // encryption, so the alert is not readable by runner.
9809 t.test.expectedLocalError = "local error: bad record MAC"
9810 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009811
David Benjamincd2c8062016-09-09 11:28:16 -04009812 testCases = append(testCases, t.test)
9813 }
David Benjaminebacdee2017-04-08 11:00:45 -04009814
9815 // The processing order for TLS 1.3 version negotiation is such that one
9816 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9817 // TLS 1.2. Test that we do not do this.
9818 testCases = append(testCases, testCase{
9819 name: "SendServerHelloAsHelloRetryRequest",
9820 config: Config{
9821 MaxVersion: VersionTLS12,
9822 Bugs: ProtocolBugs{
9823 SendServerHelloAsHelloRetryRequest: true,
9824 },
9825 },
9826 shouldFail: true,
9827 expectedError: ":UNEXPECTED_MESSAGE:",
9828 expectedLocalError: "remote error: unexpected message",
9829 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009830}
9831
David Benjamin639846e2016-09-09 11:41:18 -04009832func addTrailingMessageDataTests() {
9833 for _, t := range makePerMessageTests() {
9834 t.test.name = "TrailingMessageData-" + t.test.name
9835 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9836 t.test.shouldFail = true
9837 t.test.expectedError = ":DECODE_ERROR:"
9838 t.test.expectedLocalError = "remote error: error decoding message"
9839
9840 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9841 // In TLS 1.3, a bad ServerHello means the client sends
9842 // an unencrypted alert while the server expects
9843 // encryption, so the alert is not readable by runner.
9844 t.test.expectedLocalError = "local error: bad record MAC"
9845 }
9846
9847 if t.messageType == typeFinished {
9848 // Bad Finished messages read as the verify data having
9849 // the wrong length.
9850 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9851 t.test.expectedLocalError = "remote error: error decrypting message"
9852 }
9853
9854 testCases = append(testCases, t.test)
9855 }
9856}
9857
Steven Valdez143e8b32016-07-11 13:19:03 -04009858func addTLS13HandshakeTests() {
9859 testCases = append(testCases, testCase{
9860 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009861 name: "NegotiatePSKResumption-TLS13",
9862 config: Config{
9863 MaxVersion: VersionTLS13,
9864 Bugs: ProtocolBugs{
9865 NegotiatePSKResumption: true,
9866 },
9867 },
9868 resumeSession: true,
9869 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009870 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009871 })
9872
9873 testCases = append(testCases, testCase{
9874 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009875 name: "MissingKeyShare-Client",
9876 config: Config{
9877 MaxVersion: VersionTLS13,
9878 Bugs: ProtocolBugs{
9879 MissingKeyShare: true,
9880 },
9881 },
9882 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009883 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009884 })
9885
9886 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009887 testType: serverTest,
9888 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009889 config: Config{
9890 MaxVersion: VersionTLS13,
9891 Bugs: ProtocolBugs{
9892 MissingKeyShare: true,
9893 },
9894 },
9895 shouldFail: true,
9896 expectedError: ":MISSING_KEY_SHARE:",
9897 })
9898
9899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009900 testType: serverTest,
9901 name: "DuplicateKeyShares",
9902 config: Config{
9903 MaxVersion: VersionTLS13,
9904 Bugs: ProtocolBugs{
9905 DuplicateKeyShares: true,
9906 },
9907 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009908 shouldFail: true,
9909 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009910 })
9911
9912 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009913 testType: serverTest,
9914 name: "SkipEarlyData",
9915 config: Config{
9916 MaxVersion: VersionTLS13,
9917 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009918 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009919 },
9920 },
9921 })
9922
9923 testCases = append(testCases, testCase{
9924 testType: serverTest,
9925 name: "SkipEarlyData-OmitEarlyDataExtension",
9926 config: Config{
9927 MaxVersion: VersionTLS13,
9928 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009929 SendFakeEarlyDataLength: 4,
9930 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009931 },
9932 },
9933 shouldFail: true,
9934 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9935 })
9936
9937 testCases = append(testCases, testCase{
9938 testType: serverTest,
9939 name: "SkipEarlyData-TooMuchData",
9940 config: Config{
9941 MaxVersion: VersionTLS13,
9942 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009943 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009944 },
9945 },
9946 shouldFail: true,
9947 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9948 })
9949
9950 testCases = append(testCases, testCase{
9951 testType: serverTest,
9952 name: "SkipEarlyData-Interleaved",
9953 config: Config{
9954 MaxVersion: VersionTLS13,
9955 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009956 SendFakeEarlyDataLength: 4,
9957 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009958 },
9959 },
9960 shouldFail: true,
9961 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9962 })
9963
9964 testCases = append(testCases, testCase{
9965 testType: serverTest,
9966 name: "SkipEarlyData-EarlyDataInTLS12",
9967 config: Config{
9968 MaxVersion: VersionTLS13,
9969 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009970 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009971 },
9972 },
9973 shouldFail: true,
9974 expectedError: ":UNEXPECTED_RECORD:",
9975 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9976 })
9977
9978 testCases = append(testCases, testCase{
9979 testType: serverTest,
9980 name: "SkipEarlyData-HRR",
9981 config: Config{
9982 MaxVersion: VersionTLS13,
9983 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009984 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009985 },
9986 DefaultCurves: []CurveID{},
9987 },
9988 })
9989
9990 testCases = append(testCases, testCase{
9991 testType: serverTest,
9992 name: "SkipEarlyData-HRR-Interleaved",
9993 config: Config{
9994 MaxVersion: VersionTLS13,
9995 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009996 SendFakeEarlyDataLength: 4,
9997 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009998 },
9999 DefaultCurves: []CurveID{},
10000 },
10001 shouldFail: true,
10002 expectedError: ":UNEXPECTED_RECORD:",
10003 })
10004
10005 testCases = append(testCases, testCase{
10006 testType: serverTest,
10007 name: "SkipEarlyData-HRR-TooMuchData",
10008 config: Config{
10009 MaxVersion: VersionTLS13,
10010 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010011 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010012 },
10013 DefaultCurves: []CurveID{},
10014 },
10015 shouldFail: true,
10016 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10017 })
10018
10019 // Test that skipping early data looking for cleartext correctly
10020 // processes an alert record.
10021 testCases = append(testCases, testCase{
10022 testType: serverTest,
10023 name: "SkipEarlyData-HRR-FatalAlert",
10024 config: Config{
10025 MaxVersion: VersionTLS13,
10026 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010027 SendEarlyAlert: true,
10028 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010029 },
10030 DefaultCurves: []CurveID{},
10031 },
10032 shouldFail: true,
10033 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10034 })
10035
10036 testCases = append(testCases, testCase{
10037 testType: serverTest,
10038 name: "SkipEarlyData-SecondClientHelloEarlyData",
10039 config: Config{
10040 MaxVersion: VersionTLS13,
10041 Bugs: ProtocolBugs{
10042 SendEarlyDataOnSecondClientHello: true,
10043 },
10044 DefaultCurves: []CurveID{},
10045 },
10046 shouldFail: true,
10047 expectedLocalError: "remote error: bad record MAC",
10048 })
10049
10050 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010051 testType: clientTest,
10052 name: "EmptyEncryptedExtensions",
10053 config: Config{
10054 MaxVersion: VersionTLS13,
10055 Bugs: ProtocolBugs{
10056 EmptyEncryptedExtensions: true,
10057 },
10058 },
10059 shouldFail: true,
10060 expectedLocalError: "remote error: error decoding message",
10061 })
10062
10063 testCases = append(testCases, testCase{
10064 testType: clientTest,
10065 name: "EncryptedExtensionsWithKeyShare",
10066 config: Config{
10067 MaxVersion: VersionTLS13,
10068 Bugs: ProtocolBugs{
10069 EncryptedExtensionsWithKeyShare: true,
10070 },
10071 },
10072 shouldFail: true,
10073 expectedLocalError: "remote error: unsupported extension",
10074 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010075
10076 testCases = append(testCases, testCase{
10077 testType: serverTest,
10078 name: "SendHelloRetryRequest",
10079 config: Config{
10080 MaxVersion: VersionTLS13,
10081 // Require a HelloRetryRequest for every curve.
10082 DefaultCurves: []CurveID{},
10083 },
10084 expectedCurveID: CurveX25519,
10085 })
10086
10087 testCases = append(testCases, testCase{
10088 testType: serverTest,
10089 name: "SendHelloRetryRequest-2",
10090 config: Config{
10091 MaxVersion: VersionTLS13,
10092 DefaultCurves: []CurveID{CurveP384},
10093 },
10094 // Although the ClientHello did not predict our preferred curve,
10095 // we always select it whether it is predicted or not.
10096 expectedCurveID: CurveX25519,
10097 })
10098
10099 testCases = append(testCases, testCase{
10100 name: "UnknownCurve-HelloRetryRequest",
10101 config: Config{
10102 MaxVersion: VersionTLS13,
10103 // P-384 requires HelloRetryRequest in BoringSSL.
10104 CurvePreferences: []CurveID{CurveP384},
10105 Bugs: ProtocolBugs{
10106 SendHelloRetryRequestCurve: bogusCurve,
10107 },
10108 },
10109 shouldFail: true,
10110 expectedError: ":WRONG_CURVE:",
10111 })
10112
10113 testCases = append(testCases, testCase{
10114 name: "DisabledCurve-HelloRetryRequest",
10115 config: Config{
10116 MaxVersion: VersionTLS13,
10117 CurvePreferences: []CurveID{CurveP256},
10118 Bugs: ProtocolBugs{
10119 IgnorePeerCurvePreferences: true,
10120 },
10121 },
10122 flags: []string{"-p384-only"},
10123 shouldFail: true,
10124 expectedError: ":WRONG_CURVE:",
10125 })
10126
10127 testCases = append(testCases, testCase{
10128 name: "UnnecessaryHelloRetryRequest",
10129 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010130 MaxVersion: VersionTLS13,
10131 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010132 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010133 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010134 },
10135 },
10136 shouldFail: true,
10137 expectedError: ":WRONG_CURVE:",
10138 })
10139
10140 testCases = append(testCases, testCase{
10141 name: "SecondHelloRetryRequest",
10142 config: Config{
10143 MaxVersion: VersionTLS13,
10144 // P-384 requires HelloRetryRequest in BoringSSL.
10145 CurvePreferences: []CurveID{CurveP384},
10146 Bugs: ProtocolBugs{
10147 SecondHelloRetryRequest: true,
10148 },
10149 },
10150 shouldFail: true,
10151 expectedError: ":UNEXPECTED_MESSAGE:",
10152 })
10153
10154 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010155 name: "HelloRetryRequest-Empty",
10156 config: Config{
10157 MaxVersion: VersionTLS13,
10158 Bugs: ProtocolBugs{
10159 AlwaysSendHelloRetryRequest: true,
10160 },
10161 },
10162 shouldFail: true,
10163 expectedError: ":DECODE_ERROR:",
10164 })
10165
10166 testCases = append(testCases, testCase{
10167 name: "HelloRetryRequest-DuplicateCurve",
10168 config: Config{
10169 MaxVersion: VersionTLS13,
10170 // P-384 requires a HelloRetryRequest against BoringSSL's default
10171 // configuration. Assert this ExpectMissingKeyShare.
10172 CurvePreferences: []CurveID{CurveP384},
10173 Bugs: ProtocolBugs{
10174 ExpectMissingKeyShare: true,
10175 DuplicateHelloRetryRequestExtensions: true,
10176 },
10177 },
10178 shouldFail: true,
10179 expectedError: ":DUPLICATE_EXTENSION:",
10180 expectedLocalError: "remote error: illegal parameter",
10181 })
10182
10183 testCases = append(testCases, testCase{
10184 name: "HelloRetryRequest-Cookie",
10185 config: Config{
10186 MaxVersion: VersionTLS13,
10187 Bugs: ProtocolBugs{
10188 SendHelloRetryRequestCookie: []byte("cookie"),
10189 },
10190 },
10191 })
10192
10193 testCases = append(testCases, testCase{
10194 name: "HelloRetryRequest-DuplicateCookie",
10195 config: Config{
10196 MaxVersion: VersionTLS13,
10197 Bugs: ProtocolBugs{
10198 SendHelloRetryRequestCookie: []byte("cookie"),
10199 DuplicateHelloRetryRequestExtensions: true,
10200 },
10201 },
10202 shouldFail: true,
10203 expectedError: ":DUPLICATE_EXTENSION:",
10204 expectedLocalError: "remote error: illegal parameter",
10205 })
10206
10207 testCases = append(testCases, testCase{
10208 name: "HelloRetryRequest-EmptyCookie",
10209 config: Config{
10210 MaxVersion: VersionTLS13,
10211 Bugs: ProtocolBugs{
10212 SendHelloRetryRequestCookie: []byte{},
10213 },
10214 },
10215 shouldFail: true,
10216 expectedError: ":DECODE_ERROR:",
10217 })
10218
10219 testCases = append(testCases, testCase{
10220 name: "HelloRetryRequest-Cookie-Curve",
10221 config: Config{
10222 MaxVersion: VersionTLS13,
10223 // P-384 requires HelloRetryRequest in BoringSSL.
10224 CurvePreferences: []CurveID{CurveP384},
10225 Bugs: ProtocolBugs{
10226 SendHelloRetryRequestCookie: []byte("cookie"),
10227 ExpectMissingKeyShare: true,
10228 },
10229 },
10230 })
10231
10232 testCases = append(testCases, testCase{
10233 name: "HelloRetryRequest-Unknown",
10234 config: Config{
10235 MaxVersion: VersionTLS13,
10236 Bugs: ProtocolBugs{
10237 CustomHelloRetryRequestExtension: "extension",
10238 },
10239 },
10240 shouldFail: true,
10241 expectedError: ":UNEXPECTED_EXTENSION:",
10242 expectedLocalError: "remote error: unsupported extension",
10243 })
10244
10245 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010246 testType: serverTest,
10247 name: "SecondClientHelloMissingKeyShare",
10248 config: Config{
10249 MaxVersion: VersionTLS13,
10250 DefaultCurves: []CurveID{},
10251 Bugs: ProtocolBugs{
10252 SecondClientHelloMissingKeyShare: true,
10253 },
10254 },
10255 shouldFail: true,
10256 expectedError: ":MISSING_KEY_SHARE:",
10257 })
10258
10259 testCases = append(testCases, testCase{
10260 testType: serverTest,
10261 name: "SecondClientHelloWrongCurve",
10262 config: Config{
10263 MaxVersion: VersionTLS13,
10264 DefaultCurves: []CurveID{},
10265 Bugs: ProtocolBugs{
10266 MisinterpretHelloRetryRequestCurve: CurveP521,
10267 },
10268 },
10269 shouldFail: true,
10270 expectedError: ":WRONG_CURVE:",
10271 })
10272
10273 testCases = append(testCases, testCase{
10274 name: "HelloRetryRequestVersionMismatch",
10275 config: Config{
10276 MaxVersion: VersionTLS13,
10277 // P-384 requires HelloRetryRequest in BoringSSL.
10278 CurvePreferences: []CurveID{CurveP384},
10279 Bugs: ProtocolBugs{
10280 SendServerHelloVersion: 0x0305,
10281 },
10282 },
10283 shouldFail: true,
10284 expectedError: ":WRONG_VERSION_NUMBER:",
10285 })
10286
10287 testCases = append(testCases, testCase{
10288 name: "HelloRetryRequestCurveMismatch",
10289 config: Config{
10290 MaxVersion: VersionTLS13,
10291 // P-384 requires HelloRetryRequest in BoringSSL.
10292 CurvePreferences: []CurveID{CurveP384},
10293 Bugs: ProtocolBugs{
10294 // Send P-384 (correct) in the HelloRetryRequest.
10295 SendHelloRetryRequestCurve: CurveP384,
10296 // But send P-256 in the ServerHello.
10297 SendCurve: CurveP256,
10298 },
10299 },
10300 shouldFail: true,
10301 expectedError: ":WRONG_CURVE:",
10302 })
10303
10304 // Test the server selecting a curve that requires a HelloRetryRequest
10305 // without sending it.
10306 testCases = append(testCases, testCase{
10307 name: "SkipHelloRetryRequest",
10308 config: Config{
10309 MaxVersion: VersionTLS13,
10310 // P-384 requires HelloRetryRequest in BoringSSL.
10311 CurvePreferences: []CurveID{CurveP384},
10312 Bugs: ProtocolBugs{
10313 SkipHelloRetryRequest: true,
10314 },
10315 },
10316 shouldFail: true,
10317 expectedError: ":WRONG_CURVE:",
10318 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010319
10320 testCases = append(testCases, testCase{
10321 name: "TLS13-RequestContextInHandshake",
10322 config: Config{
10323 MaxVersion: VersionTLS13,
10324 MinVersion: VersionTLS13,
10325 ClientAuth: RequireAnyClientCert,
10326 Bugs: ProtocolBugs{
10327 SendRequestContext: []byte("request context"),
10328 },
10329 },
10330 flags: []string{
10331 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10332 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10333 },
10334 shouldFail: true,
10335 expectedError: ":DECODE_ERROR:",
10336 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010337
10338 testCases = append(testCases, testCase{
10339 testType: serverTest,
10340 name: "TLS13-TrailingKeyShareData",
10341 config: Config{
10342 MaxVersion: VersionTLS13,
10343 Bugs: ProtocolBugs{
10344 TrailingKeyShareData: true,
10345 },
10346 },
10347 shouldFail: true,
10348 expectedError: ":DECODE_ERROR:",
10349 })
David Benjamin7f78df42016-10-05 22:33:19 -040010350
10351 testCases = append(testCases, testCase{
10352 name: "TLS13-AlwaysSelectPSKIdentity",
10353 config: Config{
10354 MaxVersion: VersionTLS13,
10355 Bugs: ProtocolBugs{
10356 AlwaysSelectPSKIdentity: true,
10357 },
10358 },
10359 shouldFail: true,
10360 expectedError: ":UNEXPECTED_EXTENSION:",
10361 })
10362
10363 testCases = append(testCases, testCase{
10364 name: "TLS13-InvalidPSKIdentity",
10365 config: Config{
10366 MaxVersion: VersionTLS13,
10367 Bugs: ProtocolBugs{
10368 SelectPSKIdentityOnResume: 1,
10369 },
10370 },
10371 resumeSession: true,
10372 shouldFail: true,
10373 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10374 })
David Benjamin1286bee2016-10-07 15:25:06 -040010375
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010376 testCases = append(testCases, testCase{
10377 testType: serverTest,
10378 name: "TLS13-ExtraPSKIdentity",
10379 config: Config{
10380 MaxVersion: VersionTLS13,
10381 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010382 ExtraPSKIdentity: true,
10383 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010384 },
10385 },
10386 resumeSession: true,
10387 })
10388
David Benjamin1286bee2016-10-07 15:25:06 -040010389 // Test that unknown NewSessionTicket extensions are tolerated.
10390 testCases = append(testCases, testCase{
10391 name: "TLS13-CustomTicketExtension",
10392 config: Config{
10393 MaxVersion: VersionTLS13,
10394 Bugs: ProtocolBugs{
10395 CustomTicketExtension: "1234",
10396 },
10397 },
10398 })
Steven Valdez2d850622017-01-11 11:34:52 -050010399
Steven Valdez2d850622017-01-11 11:34:52 -050010400 testCases = append(testCases, testCase{
10401 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010402 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010403 config: Config{
10404 MaxVersion: VersionTLS13,
10405 MaxEarlyDataSize: 16384,
10406 },
10407 resumeConfig: &Config{
10408 MaxVersion: VersionTLS13,
10409 MaxEarlyDataSize: 16384,
10410 Bugs: ProtocolBugs{
10411 AlwaysRejectEarlyData: true,
10412 },
10413 },
10414 resumeSession: true,
10415 flags: []string{
10416 "-enable-early-data",
10417 "-expect-early-data-info",
10418 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010419 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010420 },
10421 })
10422
10423 testCases = append(testCases, testCase{
10424 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010425 name: "TLS13-EarlyData-RejectTicket-Client",
10426 config: Config{
10427 MaxVersion: VersionTLS13,
10428 MaxEarlyDataSize: 16384,
10429 Certificates: []Certificate{rsaCertificate},
10430 },
10431 resumeConfig: &Config{
10432 MaxVersion: VersionTLS13,
10433 MaxEarlyDataSize: 16384,
10434 Certificates: []Certificate{ecdsaP256Certificate},
10435 SessionTicketsDisabled: true,
10436 },
10437 resumeSession: true,
10438 expectResumeRejected: true,
10439 flags: []string{
10440 "-enable-early-data",
10441 "-expect-early-data-info",
10442 "-expect-reject-early-data",
10443 "-on-resume-shim-writes-first",
10444 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10445 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10446 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10447 // Session tickets are disabled, so the runner will not send a ticket.
10448 "-on-retry-expect-no-session",
10449 },
10450 })
10451
10452 testCases = append(testCases, testCase{
10453 testType: clientTest,
10454 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010455 config: Config{
10456 MaxVersion: VersionTLS13,
10457 MaxEarlyDataSize: 16384,
10458 },
10459 resumeConfig: &Config{
10460 MaxVersion: VersionTLS13,
10461 MaxEarlyDataSize: 16384,
10462 Bugs: ProtocolBugs{
10463 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10464 },
10465 },
10466 resumeSession: true,
10467 flags: []string{
10468 "-enable-early-data",
10469 "-expect-early-data-info",
10470 "-expect-reject-early-data",
10471 },
10472 })
10473
10474 // The client must check the server does not send the early_data
10475 // extension while rejecting the session.
10476 testCases = append(testCases, testCase{
10477 testType: clientTest,
10478 name: "TLS13-EarlyDataWithoutResume-Client",
10479 config: Config{
10480 MaxVersion: VersionTLS13,
10481 MaxEarlyDataSize: 16384,
10482 },
10483 resumeConfig: &Config{
10484 MaxVersion: VersionTLS13,
10485 SessionTicketsDisabled: true,
10486 Bugs: ProtocolBugs{
10487 SendEarlyDataExtension: true,
10488 },
10489 },
10490 resumeSession: true,
10491 flags: []string{
10492 "-enable-early-data",
10493 "-expect-early-data-info",
10494 },
10495 shouldFail: true,
10496 expectedError: ":UNEXPECTED_EXTENSION:",
10497 })
10498
10499 // The client must fail with a dedicated error code if the server
10500 // responds with TLS 1.2 when offering 0-RTT.
10501 testCases = append(testCases, testCase{
10502 testType: clientTest,
10503 name: "TLS13-EarlyDataVersionDowngrade-Client",
10504 config: Config{
10505 MaxVersion: VersionTLS13,
10506 MaxEarlyDataSize: 16384,
10507 },
10508 resumeConfig: &Config{
10509 MaxVersion: VersionTLS12,
10510 },
10511 resumeSession: true,
10512 flags: []string{
10513 "-enable-early-data",
10514 "-expect-early-data-info",
10515 },
10516 shouldFail: true,
10517 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10518 })
10519
10520 // Test that the client rejects an (unsolicited) early_data extension if
10521 // the server sent an HRR.
10522 testCases = append(testCases, testCase{
10523 testType: clientTest,
10524 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10525 config: Config{
10526 MaxVersion: VersionTLS13,
10527 MaxEarlyDataSize: 16384,
10528 },
10529 resumeConfig: &Config{
10530 MaxVersion: VersionTLS13,
10531 MaxEarlyDataSize: 16384,
10532 Bugs: ProtocolBugs{
10533 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10534 SendEarlyDataExtension: true,
10535 },
10536 },
10537 resumeSession: true,
10538 flags: []string{
10539 "-enable-early-data",
10540 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010541 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010542 },
10543 shouldFail: true,
10544 expectedError: ":UNEXPECTED_EXTENSION:",
10545 })
10546
10547 fooString := "foo"
10548 barString := "bar"
10549
10550 // Test that the client reports the correct ALPN after a 0-RTT reject
10551 // that changed it.
10552 testCases = append(testCases, testCase{
10553 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010554 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010555 config: Config{
10556 MaxVersion: VersionTLS13,
10557 MaxEarlyDataSize: 16384,
10558 Bugs: ProtocolBugs{
10559 ALPNProtocol: &fooString,
10560 },
10561 },
10562 resumeConfig: &Config{
10563 MaxVersion: VersionTLS13,
10564 MaxEarlyDataSize: 16384,
10565 Bugs: ProtocolBugs{
10566 ALPNProtocol: &barString,
10567 },
10568 },
10569 resumeSession: true,
10570 flags: []string{
10571 "-advertise-alpn", "\x03foo\x03bar",
10572 "-enable-early-data",
10573 "-expect-early-data-info",
10574 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010575 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010576 "-on-resume-expect-alpn", "foo",
10577 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010578 },
10579 })
10580
10581 // Test that the client reports the correct ALPN after a 0-RTT reject if
10582 // ALPN was omitted from the first connection.
10583 testCases = append(testCases, testCase{
10584 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010585 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010586 config: Config{
10587 MaxVersion: VersionTLS13,
10588 MaxEarlyDataSize: 16384,
10589 },
10590 resumeConfig: &Config{
10591 MaxVersion: VersionTLS13,
10592 MaxEarlyDataSize: 16384,
10593 NextProtos: []string{"foo"},
10594 },
10595 resumeSession: true,
10596 flags: []string{
10597 "-advertise-alpn", "\x03foo\x03bar",
10598 "-enable-early-data",
10599 "-expect-early-data-info",
10600 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010601 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010602 "-on-resume-expect-alpn", "",
10603 "-on-retry-expect-alpn", "foo",
10604 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010605 },
10606 })
10607
10608 // Test that the client reports the correct ALPN after a 0-RTT reject if
10609 // ALPN was omitted from the second connection.
10610 testCases = append(testCases, testCase{
10611 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010612 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010613 config: Config{
10614 MaxVersion: VersionTLS13,
10615 MaxEarlyDataSize: 16384,
10616 NextProtos: []string{"foo"},
10617 },
10618 resumeConfig: &Config{
10619 MaxVersion: VersionTLS13,
10620 MaxEarlyDataSize: 16384,
10621 },
10622 resumeSession: true,
10623 flags: []string{
10624 "-advertise-alpn", "\x03foo\x03bar",
10625 "-enable-early-data",
10626 "-expect-early-data-info",
10627 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010628 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010629 "-on-resume-expect-alpn", "foo",
10630 "-on-retry-expect-alpn", "",
10631 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010632 },
10633 })
10634
10635 // Test that the client enforces ALPN match on 0-RTT accept.
10636 testCases = append(testCases, testCase{
10637 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010638 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010639 config: Config{
10640 MaxVersion: VersionTLS13,
10641 MaxEarlyDataSize: 16384,
10642 Bugs: ProtocolBugs{
10643 ALPNProtocol: &fooString,
10644 },
10645 },
10646 resumeConfig: &Config{
10647 MaxVersion: VersionTLS13,
10648 MaxEarlyDataSize: 16384,
10649 Bugs: ProtocolBugs{
10650 AlwaysAcceptEarlyData: true,
10651 ALPNProtocol: &barString,
10652 },
10653 },
10654 resumeSession: true,
10655 flags: []string{
10656 "-advertise-alpn", "\x03foo\x03bar",
10657 "-enable-early-data",
10658 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010659 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010660 "-on-resume-expect-alpn", "foo",
10661 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010662 },
10663 shouldFail: true,
10664 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10665 })
10666
10667 // Test that the server correctly rejects 0-RTT when the previous
10668 // session did not allow early data on resumption.
10669 testCases = append(testCases, testCase{
10670 testType: serverTest,
10671 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10672 config: Config{
10673 MaxVersion: VersionTLS13,
10674 },
10675 resumeConfig: &Config{
10676 MaxVersion: VersionTLS13,
10677 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010678 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010679 ExpectEarlyDataAccepted: false,
10680 },
10681 },
10682 resumeSession: true,
10683 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010684 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010685 "-expect-reject-early-data",
10686 },
10687 })
10688
10689 // Test that we reject early data where ALPN is omitted from the first
10690 // connection.
10691 testCases = append(testCases, testCase{
10692 testType: serverTest,
10693 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10694 config: Config{
10695 MaxVersion: VersionTLS13,
10696 NextProtos: []string{},
10697 },
10698 resumeConfig: &Config{
10699 MaxVersion: VersionTLS13,
10700 NextProtos: []string{"foo"},
10701 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010702 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010703 ExpectEarlyDataAccepted: false,
10704 },
10705 },
10706 resumeSession: true,
10707 flags: []string{
10708 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010709 "-on-initial-select-alpn", "",
10710 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010711 },
10712 })
10713
10714 // Test that we reject early data where ALPN is omitted from the second
10715 // connection.
10716 testCases = append(testCases, testCase{
10717 testType: serverTest,
10718 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10719 config: Config{
10720 MaxVersion: VersionTLS13,
10721 NextProtos: []string{"foo"},
10722 },
10723 resumeConfig: &Config{
10724 MaxVersion: VersionTLS13,
10725 NextProtos: []string{},
10726 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010727 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010728 ExpectEarlyDataAccepted: false,
10729 },
10730 },
10731 resumeSession: true,
10732 flags: []string{
10733 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010734 "-on-initial-select-alpn", "foo",
10735 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010736 },
10737 })
10738
10739 // Test that we reject early data with mismatched ALPN.
10740 testCases = append(testCases, testCase{
10741 testType: serverTest,
10742 name: "TLS13-EarlyData-ALPNMismatch-Server",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 NextProtos: []string{"foo"},
10746 },
10747 resumeConfig: &Config{
10748 MaxVersion: VersionTLS13,
10749 NextProtos: []string{"bar"},
10750 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010751 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010752 ExpectEarlyDataAccepted: false,
10753 },
10754 },
10755 resumeSession: true,
10756 flags: []string{
10757 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010758 "-on-initial-select-alpn", "foo",
10759 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010760 },
10761 })
10762
David Benjamin6bb507b2017-03-29 16:35:57 -050010763 // Test that the client offering 0-RTT and Channel ID forbids the server
10764 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010765 testCases = append(testCases, testCase{
10766 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010767 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010768 config: Config{
10769 MaxVersion: VersionTLS13,
10770 MaxEarlyDataSize: 16384,
10771 RequestChannelID: true,
10772 },
10773 resumeSession: true,
10774 expectChannelID: true,
10775 shouldFail: true,
10776 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10777 flags: []string{
10778 "-enable-early-data",
10779 "-expect-early-data-info",
10780 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10781 },
10782 })
10783
David Benjamin6bb507b2017-03-29 16:35:57 -050010784 // Test that the client offering Channel ID and 0-RTT allows the server
10785 // to decline 0-RTT.
10786 testCases = append(testCases, testCase{
10787 testType: clientTest,
10788 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10789 config: Config{
10790 MaxVersion: VersionTLS13,
10791 MaxEarlyDataSize: 16384,
10792 RequestChannelID: true,
10793 Bugs: ProtocolBugs{
10794 AlwaysRejectEarlyData: true,
10795 },
10796 },
10797 resumeSession: true,
10798 expectChannelID: true,
10799 flags: []string{
10800 "-enable-early-data",
10801 "-expect-early-data-info",
10802 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10803 "-expect-reject-early-data",
10804 },
10805 })
10806
10807 // Test that the client offering Channel ID and 0-RTT allows the server
10808 // to decline Channel ID.
10809 testCases = append(testCases, testCase{
10810 testType: clientTest,
10811 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10812 config: Config{
10813 MaxVersion: VersionTLS13,
10814 MaxEarlyDataSize: 16384,
10815 },
10816 resumeSession: true,
10817 flags: []string{
10818 "-enable-early-data",
10819 "-expect-early-data-info",
10820 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10821 "-expect-accept-early-data",
10822 },
10823 })
10824
10825 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10826 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010827 testCases = append(testCases, testCase{
10828 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010829 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010830 config: Config{
10831 MaxVersion: VersionTLS13,
10832 ChannelID: channelIDKey,
10833 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010834 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010835 ExpectEarlyDataAccepted: false,
10836 },
10837 },
10838 resumeSession: true,
10839 expectChannelID: true,
10840 flags: []string{
10841 "-enable-early-data",
10842 "-expect-reject-early-data",
10843 "-expect-channel-id",
10844 base64.StdEncoding.EncodeToString(channelIDBytes),
10845 },
10846 })
10847
David Benjamin6bb507b2017-03-29 16:35:57 -050010848 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10849 // if not offered Channel ID.
10850 testCases = append(testCases, testCase{
10851 testType: serverTest,
10852 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10853 config: Config{
10854 MaxVersion: VersionTLS13,
10855 Bugs: ProtocolBugs{
10856 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10857 ExpectEarlyDataAccepted: true,
10858 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10859 },
10860 },
10861 resumeSession: true,
10862 expectChannelID: false,
10863 flags: []string{
10864 "-enable-early-data",
10865 "-expect-accept-early-data",
10866 "-enable-channel-id",
10867 },
10868 })
10869
David Benjamin32c89272017-03-26 13:54:21 -050010870 // Test that the server rejects 0-RTT streams without end_of_early_data.
10871 // The subsequent records should fail to decrypt.
10872 testCases = append(testCases, testCase{
10873 testType: serverTest,
10874 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10875 config: Config{
10876 MaxVersion: VersionTLS13,
10877 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010878 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010879 ExpectEarlyDataAccepted: true,
10880 SkipEndOfEarlyData: true,
10881 },
10882 },
10883 resumeSession: true,
10884 flags: []string{"-enable-early-data"},
10885 shouldFail: true,
10886 expectedLocalError: "remote error: bad record MAC",
10887 expectedError: ":BAD_DECRYPT:",
10888 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010889
10890 testCases = append(testCases, testCase{
10891 testType: serverTest,
10892 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10893 config: Config{
10894 MaxVersion: VersionTLS13,
10895 },
10896 resumeConfig: &Config{
10897 MaxVersion: VersionTLS13,
10898 Bugs: ProtocolBugs{
10899 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10900 SendStrayEarlyHandshake: true,
10901 ExpectEarlyDataAccepted: true},
10902 },
10903 resumeSession: true,
10904 shouldFail: true,
10905 expectedError: ":UNEXPECTED_RECORD:",
10906 expectedLocalError: "remote error: unexpected message",
10907 flags: []string{
10908 "-enable-early-data",
10909 },
10910 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010911}
10912
David Benjaminabbbee12016-10-31 19:20:42 -040010913func addTLS13CipherPreferenceTests() {
10914 // Test that client preference is honored if the shim has AES hardware
10915 // and ChaCha20-Poly1305 is preferred otherwise.
10916 testCases = append(testCases, testCase{
10917 testType: serverTest,
10918 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10919 config: Config{
10920 MaxVersion: VersionTLS13,
10921 CipherSuites: []uint16{
10922 TLS_CHACHA20_POLY1305_SHA256,
10923 TLS_AES_128_GCM_SHA256,
10924 },
10925 },
10926 flags: []string{
10927 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10928 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10929 },
10930 })
10931
10932 testCases = append(testCases, testCase{
10933 testType: serverTest,
10934 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10935 config: Config{
10936 MaxVersion: VersionTLS13,
10937 CipherSuites: []uint16{
10938 TLS_AES_128_GCM_SHA256,
10939 TLS_CHACHA20_POLY1305_SHA256,
10940 },
10941 },
10942 flags: []string{
10943 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10944 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10945 },
10946 })
10947
10948 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
10949 // whether it has AES hardware.
10950 testCases = append(testCases, testCase{
10951 name: "TLS13-CipherPreference-Client",
10952 config: Config{
10953 MaxVersion: VersionTLS13,
10954 // Use the client cipher order. (This is the default but
10955 // is listed to be explicit.)
10956 PreferServerCipherSuites: false,
10957 },
10958 flags: []string{
10959 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10960 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10961 },
10962 })
10963}
10964
David Benjaminf3fbade2016-09-19 13:08:16 -040010965func addPeekTests() {
10966 // Test SSL_peek works, including on empty records.
10967 testCases = append(testCases, testCase{
10968 name: "Peek-Basic",
10969 sendEmptyRecords: 1,
10970 flags: []string{"-peek-then-read"},
10971 })
10972
10973 // Test SSL_peek can drive the initial handshake.
10974 testCases = append(testCases, testCase{
10975 name: "Peek-ImplicitHandshake",
10976 flags: []string{
10977 "-peek-then-read",
10978 "-implicit-handshake",
10979 },
10980 })
10981
10982 // Test SSL_peek can discover and drive a renegotiation.
10983 testCases = append(testCases, testCase{
10984 name: "Peek-Renegotiate",
10985 config: Config{
10986 MaxVersion: VersionTLS12,
10987 },
10988 renegotiate: 1,
10989 flags: []string{
10990 "-peek-then-read",
10991 "-renegotiate-freely",
10992 "-expect-total-renegotiations", "1",
10993 },
10994 })
10995
10996 // Test SSL_peek can discover a close_notify.
10997 testCases = append(testCases, testCase{
10998 name: "Peek-Shutdown",
10999 config: Config{
11000 Bugs: ProtocolBugs{
11001 ExpectCloseNotify: true,
11002 },
11003 },
11004 flags: []string{
11005 "-peek-then-read",
11006 "-check-close-notify",
11007 },
11008 })
11009
11010 // Test SSL_peek can discover an alert.
11011 testCases = append(testCases, testCase{
11012 name: "Peek-Alert",
11013 config: Config{
11014 Bugs: ProtocolBugs{
11015 SendSpuriousAlert: alertRecordOverflow,
11016 },
11017 },
11018 flags: []string{"-peek-then-read"},
11019 shouldFail: true,
11020 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11021 })
11022
11023 // Test SSL_peek can handle KeyUpdate.
11024 testCases = append(testCases, testCase{
11025 name: "Peek-KeyUpdate",
11026 config: Config{
11027 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011028 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011029 sendKeyUpdates: 1,
11030 keyUpdateRequest: keyUpdateNotRequested,
11031 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011032 })
11033}
11034
David Benjamine6f22212016-11-08 14:28:24 -050011035func addRecordVersionTests() {
11036 for _, ver := range tlsVersions {
11037 // Test that the record version is enforced.
11038 testCases = append(testCases, testCase{
11039 name: "CheckRecordVersion-" + ver.name,
11040 config: Config{
11041 MinVersion: ver.version,
11042 MaxVersion: ver.version,
11043 Bugs: ProtocolBugs{
11044 SendRecordVersion: 0x03ff,
11045 },
11046 },
11047 shouldFail: true,
11048 expectedError: ":WRONG_VERSION_NUMBER:",
11049 })
11050
11051 // Test that the ClientHello may use any record version, for
11052 // compatibility reasons.
11053 testCases = append(testCases, testCase{
11054 testType: serverTest,
11055 name: "LooseInitialRecordVersion-" + ver.name,
11056 config: Config{
11057 MinVersion: ver.version,
11058 MaxVersion: ver.version,
11059 Bugs: ProtocolBugs{
11060 SendInitialRecordVersion: 0x03ff,
11061 },
11062 },
11063 })
11064
11065 // Test that garbage ClientHello record versions are rejected.
11066 testCases = append(testCases, testCase{
11067 testType: serverTest,
11068 name: "GarbageInitialRecordVersion-" + ver.name,
11069 config: Config{
11070 MinVersion: ver.version,
11071 MaxVersion: ver.version,
11072 Bugs: ProtocolBugs{
11073 SendInitialRecordVersion: 0xffff,
11074 },
11075 },
11076 shouldFail: true,
11077 expectedError: ":WRONG_VERSION_NUMBER:",
11078 })
11079 }
11080}
11081
David Benjamin2c516452016-11-15 10:16:54 +090011082func addCertificateTests() {
11083 // Test that a certificate chain with intermediate may be sent and
11084 // received as both client and server.
11085 for _, ver := range tlsVersions {
11086 testCases = append(testCases, testCase{
11087 testType: clientTest,
11088 name: "SendReceiveIntermediate-Client-" + ver.name,
11089 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011090 MinVersion: ver.version,
11091 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011092 Certificates: []Certificate{rsaChainCertificate},
11093 ClientAuth: RequireAnyClientCert,
11094 },
11095 expectPeerCertificate: &rsaChainCertificate,
11096 flags: []string{
11097 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11098 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11099 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11100 },
11101 })
11102
11103 testCases = append(testCases, testCase{
11104 testType: serverTest,
11105 name: "SendReceiveIntermediate-Server-" + ver.name,
11106 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011107 MinVersion: ver.version,
11108 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011109 Certificates: []Certificate{rsaChainCertificate},
11110 },
11111 expectPeerCertificate: &rsaChainCertificate,
11112 flags: []string{
11113 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11114 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11115 "-require-any-client-certificate",
11116 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11117 },
11118 })
11119 }
11120}
11121
David Benjaminbbaf3672016-11-17 10:53:09 +090011122func addRetainOnlySHA256ClientCertTests() {
11123 for _, ver := range tlsVersions {
11124 // Test that enabling
11125 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11126 // actually requesting a client certificate is a no-op.
11127 testCases = append(testCases, testCase{
11128 testType: serverTest,
11129 name: "RetainOnlySHA256-NoCert-" + ver.name,
11130 config: Config{
11131 MinVersion: ver.version,
11132 MaxVersion: ver.version,
11133 },
11134 flags: []string{
11135 "-retain-only-sha256-client-cert-initial",
11136 "-retain-only-sha256-client-cert-resume",
11137 },
11138 resumeSession: true,
11139 })
11140
11141 // Test that when retaining only a SHA-256 certificate is
11142 // enabled, the hash appears as expected.
11143 testCases = append(testCases, testCase{
11144 testType: serverTest,
11145 name: "RetainOnlySHA256-Cert-" + ver.name,
11146 config: Config{
11147 MinVersion: ver.version,
11148 MaxVersion: ver.version,
11149 Certificates: []Certificate{rsaCertificate},
11150 },
11151 flags: []string{
11152 "-verify-peer",
11153 "-retain-only-sha256-client-cert-initial",
11154 "-retain-only-sha256-client-cert-resume",
11155 "-expect-sha256-client-cert-initial",
11156 "-expect-sha256-client-cert-resume",
11157 },
11158 resumeSession: true,
11159 })
11160
11161 // Test that when the config changes from on to off, a
11162 // resumption is rejected because the server now wants the full
11163 // certificate chain.
11164 testCases = append(testCases, testCase{
11165 testType: serverTest,
11166 name: "RetainOnlySHA256-OnOff-" + ver.name,
11167 config: Config{
11168 MinVersion: ver.version,
11169 MaxVersion: ver.version,
11170 Certificates: []Certificate{rsaCertificate},
11171 },
11172 flags: []string{
11173 "-verify-peer",
11174 "-retain-only-sha256-client-cert-initial",
11175 "-expect-sha256-client-cert-initial",
11176 },
11177 resumeSession: true,
11178 expectResumeRejected: true,
11179 })
11180
11181 // Test that when the config changes from off to on, a
11182 // resumption is rejected because the server now wants just the
11183 // hash.
11184 testCases = append(testCases, testCase{
11185 testType: serverTest,
11186 name: "RetainOnlySHA256-OffOn-" + ver.name,
11187 config: Config{
11188 MinVersion: ver.version,
11189 MaxVersion: ver.version,
11190 Certificates: []Certificate{rsaCertificate},
11191 },
11192 flags: []string{
11193 "-verify-peer",
11194 "-retain-only-sha256-client-cert-resume",
11195 "-expect-sha256-client-cert-resume",
11196 },
11197 resumeSession: true,
11198 expectResumeRejected: true,
11199 })
11200 }
11201}
11202
Adam Langleya4b91982016-12-12 12:05:53 -080011203func addECDSAKeyUsageTests() {
11204 p256 := elliptic.P256()
11205 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11206 if err != nil {
11207 panic(err)
11208 }
11209
11210 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11211 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11212 if err != nil {
11213 panic(err)
11214 }
11215
11216 template := x509.Certificate{
11217 SerialNumber: serialNumber,
11218 Subject: pkix.Name{
11219 Organization: []string{"Acme Co"},
11220 },
11221 NotBefore: time.Now(),
11222 NotAfter: time.Now(),
11223
11224 // An ECC certificate with only the keyAgreement key usgae may
11225 // be used with ECDH, but not ECDSA.
11226 KeyUsage: x509.KeyUsageKeyAgreement,
11227 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11228 BasicConstraintsValid: true,
11229 }
11230
11231 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11232 if err != nil {
11233 panic(err)
11234 }
11235
11236 cert := Certificate{
11237 Certificate: [][]byte{derBytes},
11238 PrivateKey: priv,
11239 }
11240
11241 for _, ver := range tlsVersions {
11242 if ver.version < VersionTLS12 {
11243 continue
11244 }
11245
11246 testCases = append(testCases, testCase{
11247 testType: clientTest,
11248 name: "ECDSAKeyUsage-" + ver.name,
11249 config: Config{
11250 MinVersion: ver.version,
11251 MaxVersion: ver.version,
11252 Certificates: []Certificate{cert},
11253 },
11254 shouldFail: true,
11255 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11256 })
11257 }
11258}
11259
David Benjamin8c26d752017-03-26 15:13:51 -050011260func addExtraHandshakeTests() {
11261 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11262 // to ensure there is no transport I/O.
11263 testCases = append(testCases, testCase{
11264 testType: clientTest,
11265 name: "ExtraHandshake-Client-TLS12",
11266 config: Config{
11267 MinVersion: VersionTLS12,
11268 MaxVersion: VersionTLS12,
11269 },
11270 flags: []string{
11271 "-async",
11272 "-no-op-extra-handshake",
11273 },
11274 })
11275 testCases = append(testCases, testCase{
11276 testType: serverTest,
11277 name: "ExtraHandshake-Server-TLS12",
11278 config: Config{
11279 MinVersion: VersionTLS12,
11280 MaxVersion: VersionTLS12,
11281 },
11282 flags: []string{
11283 "-async",
11284 "-no-op-extra-handshake",
11285 },
11286 })
11287 testCases = append(testCases, testCase{
11288 testType: clientTest,
11289 name: "ExtraHandshake-Client-TLS13",
11290 config: Config{
11291 MinVersion: VersionTLS13,
11292 MaxVersion: VersionTLS13,
11293 },
11294 flags: []string{
11295 "-async",
11296 "-no-op-extra-handshake",
11297 },
11298 })
11299 testCases = append(testCases, testCase{
11300 testType: serverTest,
11301 name: "ExtraHandshake-Server-TLS13",
11302 config: Config{
11303 MinVersion: VersionTLS13,
11304 MaxVersion: VersionTLS13,
11305 },
11306 flags: []string{
11307 "-async",
11308 "-no-op-extra-handshake",
11309 },
11310 })
11311
11312 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11313 testCases = append(testCases, testCase{
11314 testType: serverTest,
11315 name: "ExtraHandshake-Server-EarlyData-TLS13",
11316 config: Config{
11317 MaxVersion: VersionTLS13,
11318 MinVersion: VersionTLS13,
11319 Bugs: ProtocolBugs{
11320 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11321 ExpectEarlyDataAccepted: true,
11322 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11323 },
11324 },
11325 messageCount: 2,
11326 resumeSession: true,
11327 flags: []string{
11328 "-async",
11329 "-enable-early-data",
11330 "-expect-accept-early-data",
11331 "-no-op-extra-handshake",
11332 },
11333 })
11334
11335 // An extra SSL_do_handshake drives the handshake to completion in False
11336 // Start. We test this by handshaking twice and asserting the False
11337 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11338 // how the test works.
11339 testCases = append(testCases, testCase{
11340 testType: clientTest,
11341 name: "ExtraHandshake-FalseStart",
11342 config: Config{
11343 MaxVersion: VersionTLS12,
11344 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11345 NextProtos: []string{"foo"},
11346 Bugs: ProtocolBugs{
11347 ExpectFalseStart: true,
11348 AlertBeforeFalseStartTest: alertAccessDenied,
11349 },
11350 },
11351 flags: []string{
11352 "-handshake-twice",
11353 "-false-start",
11354 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011355 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011356 },
11357 shimWritesFirst: true,
11358 shouldFail: true,
11359 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11360 expectedLocalError: "tls: peer did not false start: EOF",
11361 })
11362}
11363
Adam Langley7c803a62015-06-15 15:35:05 -070011364func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011365 defer wg.Done()
11366
11367 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011368 var err error
11369
David Benjaminba28dfc2016-11-15 17:47:21 +090011370 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011371 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11372 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011373 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011374 if err != nil {
11375 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11376 }
11377 break
11378 }
11379 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011380 } else if *repeatUntilFailure {
11381 for err == nil {
11382 statusChan <- statusMsg{test: test, started: true}
11383 err = runTest(test, shimPath, -1)
11384 }
11385 } else {
11386 statusChan <- statusMsg{test: test, started: true}
11387 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011388 }
Adam Langley95c29f32014-06-20 12:00:00 -070011389 statusChan <- statusMsg{test: test, err: err}
11390 }
11391}
11392
11393type statusMsg struct {
11394 test *testCase
11395 started bool
11396 err error
11397}
11398
David Benjamin5f237bc2015-02-11 17:14:15 -050011399func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011400 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011401
David Benjamin5f237bc2015-02-11 17:14:15 -050011402 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011403 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011404 if !*pipe {
11405 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011406 var erase string
11407 for i := 0; i < lineLen; i++ {
11408 erase += "\b \b"
11409 }
11410 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011411 }
11412
Adam Langley95c29f32014-06-20 12:00:00 -070011413 if msg.started {
11414 started++
11415 } else {
11416 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011417
11418 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011419 if msg.err == errUnimplemented {
11420 if *pipe {
11421 // Print each test instead of a status line.
11422 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11423 }
11424 unimplemented++
11425 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11426 } else {
11427 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11428 failed++
11429 testOutput.addResult(msg.test.name, "FAIL")
11430 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011431 } else {
11432 if *pipe {
11433 // Print each test instead of a status line.
11434 fmt.Printf("PASSED (%s)\n", msg.test.name)
11435 }
11436 testOutput.addResult(msg.test.name, "PASS")
11437 }
Adam Langley95c29f32014-06-20 12:00:00 -070011438 }
11439
David Benjamin5f237bc2015-02-11 17:14:15 -050011440 if !*pipe {
11441 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011442 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011443 lineLen = len(line)
11444 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011445 }
Adam Langley95c29f32014-06-20 12:00:00 -070011446 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011447
11448 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011449}
11450
11451func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011452 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011453 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011454 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011455
Adam Langley7c803a62015-06-15 15:35:05 -070011456 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011457 addCipherSuiteTests()
11458 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011459 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011460 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011461 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011462 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011463 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011464 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011465 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011466 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011467 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011468 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011469 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011470 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011471 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011472 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011473 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011474 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011475 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011476 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011477 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011478 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011479 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011480 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011481 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011482 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011483 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011484 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011485 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011486 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011487 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011488 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011489 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011490 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011491
11492 var wg sync.WaitGroup
11493
Adam Langley7c803a62015-06-15 15:35:05 -070011494 statusChan := make(chan statusMsg, *numWorkers)
11495 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011496 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011497
EKRf71d7ed2016-08-06 13:25:12 -070011498 if len(*shimConfigFile) != 0 {
11499 encoded, err := ioutil.ReadFile(*shimConfigFile)
11500 if err != nil {
11501 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11502 os.Exit(1)
11503 }
11504
11505 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11506 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11507 os.Exit(1)
11508 }
11509 }
11510
David Benjamin025b3d32014-07-01 19:53:04 -040011511 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011512
Adam Langley7c803a62015-06-15 15:35:05 -070011513 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011514 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011515 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011516 }
11517
David Benjamin270f0a72016-03-17 14:41:36 -040011518 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011519 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011520 matched := true
11521 if len(*testToRun) != 0 {
11522 var err error
11523 matched, err = filepath.Match(*testToRun, testCases[i].name)
11524 if err != nil {
11525 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11526 os.Exit(1)
11527 }
11528 }
11529
EKRf71d7ed2016-08-06 13:25:12 -070011530 if !*includeDisabled {
11531 for pattern := range shimConfig.DisabledTests {
11532 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11533 if err != nil {
11534 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11535 os.Exit(1)
11536 }
11537
11538 if isDisabled {
11539 matched = false
11540 break
11541 }
11542 }
11543 }
11544
David Benjamin17e12922016-07-28 18:04:43 -040011545 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011546 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011547 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011548
11549 // Only run one test if repeating until failure.
11550 if *repeatUntilFailure {
11551 break
11552 }
Adam Langley95c29f32014-06-20 12:00:00 -070011553 }
11554 }
David Benjamin17e12922016-07-28 18:04:43 -040011555
David Benjamin270f0a72016-03-17 14:41:36 -040011556 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011557 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011558 os.Exit(1)
11559 }
Adam Langley95c29f32014-06-20 12:00:00 -070011560
11561 close(testChan)
11562 wg.Wait()
11563 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011564 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011565
11566 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011567
11568 if *jsonOutput != "" {
11569 if err := testOutput.writeTo(*jsonOutput); err != nil {
11570 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11571 }
11572 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011573
EKR842ae6c2016-07-27 09:22:05 +020011574 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11575 os.Exit(1)
11576 }
11577
11578 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011579 os.Exit(1)
11580 }
Adam Langley95c29f32014-06-20 12:00:00 -070011581}