blob: 8444c21934b0f59b12e4ddb53a21825f0ae99611 [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.")
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -070068 includeDHE = flag.Bool("include-dhe", false, "If true, test DHE ciphersuites.")
David Benjaminba28dfc2016-11-15 17:47:21 +090069 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 -080070)
Adam Langley95c29f32014-06-20 12:00:00 -070071
EKRf71d7ed2016-08-06 13:25:12 -070072// ShimConfigurations is used with the “json” package and represents a shim
73// config file.
74type ShimConfiguration struct {
75 // DisabledTests maps from a glob-based pattern to a freeform string.
76 // The glob pattern is used to exclude tests from being run and the
77 // freeform string is unparsed but expected to explain why the test is
78 // disabled.
79 DisabledTests map[string]string
80
81 // ErrorMap maps from expected error strings to the correct error
82 // string for the shim in question. For example, it might map
83 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
84 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
85 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050086
87 // HalfRTTTickets is the number of half-RTT tickets the client should
88 // expect before half-RTT data when testing 0-RTT.
89 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070090}
91
David Benjamin794cc592017-03-25 22:24:23 -050092// Setup shimConfig defaults aligning with BoringSSL.
93var shimConfig ShimConfiguration = ShimConfiguration{
94 HalfRTTTickets: 2,
95}
EKRf71d7ed2016-08-06 13:25:12 -070096
David Benjamin33863262016-07-08 17:20:12 -070097type testCert int
98
David Benjamin025b3d32014-07-01 19:53:04 -040099const (
David Benjamin33863262016-07-08 17:20:12 -0700100 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400101 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900102 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800103 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700104 testCertECDSAP256
105 testCertECDSAP384
106 testCertECDSAP521
107)
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 Benjamin025b3d32014-07-01 19:53:04 -0400117)
118
119const (
David Benjamina08e49d2014-08-24 01:46:07 -0400120 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400121 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900122 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800123 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700124 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
125 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
126 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400127 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400128)
129
David Benjamin7944a9f2016-07-12 22:27:01 -0400130var (
131 rsaCertificate Certificate
132 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900133 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800134 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400135 ecdsaP256Certificate Certificate
136 ecdsaP384Certificate Certificate
137 ecdsaP521Certificate Certificate
138)
David Benjamin33863262016-07-08 17:20:12 -0700139
140var testCerts = []struct {
141 id testCert
142 certFile, keyFile string
143 cert *Certificate
144}{
145 {
146 id: testCertRSA,
147 certFile: rsaCertificateFile,
148 keyFile: rsaKeyFile,
149 cert: &rsaCertificate,
150 },
151 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400152 id: testCertRSA1024,
153 certFile: rsa1024CertificateFile,
154 keyFile: rsa1024KeyFile,
155 cert: &rsa1024Certificate,
156 },
157 {
David Benjamin2c516452016-11-15 10:16:54 +0900158 id: testCertRSAChain,
159 certFile: rsaChainCertificateFile,
160 keyFile: rsaChainKeyFile,
161 cert: &rsaChainCertificate,
162 },
163 {
Adam Langley898be922017-02-27 12:37:59 -0800164 id: testCertECDSAP224,
165 certFile: ecdsaP224CertificateFile,
166 keyFile: ecdsaP224KeyFile,
167 cert: &ecdsaP224Certificate,
168 },
169 {
David Benjamin33863262016-07-08 17:20:12 -0700170 id: testCertECDSAP256,
171 certFile: ecdsaP256CertificateFile,
172 keyFile: ecdsaP256KeyFile,
173 cert: &ecdsaP256Certificate,
174 },
175 {
176 id: testCertECDSAP384,
177 certFile: ecdsaP384CertificateFile,
178 keyFile: ecdsaP384KeyFile,
179 cert: &ecdsaP384Certificate,
180 },
181 {
182 id: testCertECDSAP521,
183 certFile: ecdsaP521CertificateFile,
184 keyFile: ecdsaP521KeyFile,
185 cert: &ecdsaP521Certificate,
186 },
187}
188
David Benjamina08e49d2014-08-24 01:46:07 -0400189var channelIDKey *ecdsa.PrivateKey
190var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700191
David Benjamin61f95272014-11-25 01:55:35 -0500192var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800193var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500194
Steven Valdeza833c352016-11-01 13:39:36 -0400195var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800196var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400197
Adam Langley95c29f32014-06-20 12:00:00 -0700198func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700199 for i := range testCerts {
200 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
201 if err != nil {
202 panic(err)
203 }
204 cert.OCSPStaple = testOCSPResponse
205 cert.SignedCertificateTimestampList = testSCTList
206 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700207 }
David Benjamina08e49d2014-08-24 01:46:07 -0400208
Adam Langley7c803a62015-06-15 15:35:05 -0700209 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400210 if err != nil {
211 panic(err)
212 }
213 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
214 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
215 panic("bad key type")
216 }
217 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
218 if err != nil {
219 panic(err)
220 }
221 if channelIDKey.Curve != elliptic.P256() {
222 panic("bad curve")
223 }
224
225 channelIDBytes = make([]byte, 64)
226 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
227 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700228}
229
David Benjamin33863262016-07-08 17:20:12 -0700230func getRunnerCertificate(t testCert) Certificate {
231 for _, cert := range testCerts {
232 if cert.id == t {
233 return *cert.cert
234 }
235 }
236 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getShimCertificate(t testCert) string {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return cert.certFile
243 }
244 }
245 panic("Unknown test certificate")
246}
247
248func getShimKey(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.keyFile
252 }
253 }
254 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700255}
256
Adam Langley2ff79332017-02-28 13:45:39 -0800257// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
258func encodeDERValues(values [][]byte) string {
259 var ret string
260 for i, v := range values {
261 if i > 0 {
262 ret += ","
263 }
264 ret += hex.EncodeToString(v)
265 }
266
267 return ret
268}
269
David Benjamin025b3d32014-07-01 19:53:04 -0400270type testType int
271
272const (
273 clientTest testType = iota
274 serverTest
275)
276
David Benjamin6fd297b2014-08-11 18:43:38 -0400277type protocol int
278
279const (
280 tls protocol = iota
281 dtls
282)
283
David Benjaminfc7b0862014-09-06 13:21:53 -0400284const (
285 alpn = 1
286 npn = 2
287)
288
Adam Langley95c29f32014-06-20 12:00:00 -0700289type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400290 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400291 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700292 name string
293 config Config
294 shouldFail bool
295 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700296 // expectedLocalError, if not empty, contains a substring that must be
297 // found in the local error.
298 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400299 // expectedVersion, if non-zero, specifies the TLS version that must be
300 // negotiated.
301 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400302 // expectedResumeVersion, if non-zero, specifies the TLS version that
303 // must be negotiated on resumption. If zero, expectedVersion is used.
304 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400305 // expectedCipher, if non-zero, specifies the TLS cipher suite that
306 // should be negotiated.
307 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400308 // expectChannelID controls whether the connection should have
309 // negotiated a Channel ID with channelIDKey.
310 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400311 // expectedNextProto controls whether the connection should
312 // negotiate a next protocol via NPN or ALPN.
313 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400314 // expectNoNextProto, if true, means that no next protocol should be
315 // negotiated.
316 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400317 // expectedNextProtoType, if non-zero, is the expected next
318 // protocol negotiation mechanism.
319 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500320 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
321 // should be negotiated. If zero, none should be negotiated.
322 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100323 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
324 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100325 // expectedSCTList, if not nil, is the expected SCT list to be received.
326 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700327 // expectedPeerSignatureAlgorithm, if not zero, is the signature
328 // algorithm that the peer should have used in the handshake.
329 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400330 // expectedCurveID, if not zero, is the curve that the handshake should
331 // have used.
332 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700333 // messageLen is the length, in bytes, of the test message that will be
334 // sent.
335 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400336 // messageCount is the number of test messages that will be sent.
337 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400338 // certFile is the path to the certificate to use for the server.
339 certFile string
340 // keyFile is the path to the private key to use for the server.
341 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400342 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400343 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400344 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400345 // resumeRenewedSession controls whether a third connection should be
346 // tested which attempts to resume the second connection's session.
347 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700348 // expectResumeRejected, if true, specifies that the attempted
349 // resumption must be rejected by the client. This is only valid for a
350 // serverTest.
351 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400352 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500353 // resumption. Unless newSessionsOnResume is set,
354 // SessionTicketKey, ServerSessionCache, and
355 // ClientSessionCache are copied from the initial connection's
356 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400357 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500358 // newSessionsOnResume, if true, will cause resumeConfig to
359 // use a different session resumption context.
360 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400361 // noSessionCache, if true, will cause the server to run without a
362 // session cache.
363 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400364 // sendPrefix sends a prefix on the socket before actually performing a
365 // handshake.
366 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400367 // shimWritesFirst controls whether the shim sends an initial "hello"
368 // message before doing a roundtrip with the runner.
369 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400370 // shimShutsDown, if true, runs a test where the shim shuts down the
371 // connection immediately after the handshake rather than echoing
372 // messages from the runner.
373 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400374 // renegotiate indicates the number of times the connection should be
375 // renegotiated during the exchange.
376 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400377 // sendHalfHelloRequest, if true, causes the server to send half a
378 // HelloRequest when the handshake completes.
379 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700380 // renegotiateCiphers is a list of ciphersuite ids that will be
381 // switched in just before renegotiation.
382 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500383 // replayWrites, if true, configures the underlying transport
384 // to replay every write it makes in DTLS tests.
385 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500386 // damageFirstWrite, if true, configures the underlying transport to
387 // damage the final byte of the first application data write.
388 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400389 // exportKeyingMaterial, if non-zero, configures the test to exchange
390 // keying material and verify they match.
391 exportKeyingMaterial int
392 exportLabel string
393 exportContext string
394 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400395 // flags, if not empty, contains a list of command-line flags that will
396 // be passed to the shim program.
397 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700398 // testTLSUnique, if true, causes the shim to send the tls-unique value
399 // which will be compared against the expected value.
400 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400401 // sendEmptyRecords is the number of consecutive empty records to send
402 // before and after the test message.
403 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400404 // sendWarningAlerts is the number of consecutive warning alerts to send
405 // before and after the test message.
406 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400407 // sendKeyUpdates is the number of consecutive key updates to send
408 // before and after the test message.
409 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400410 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
411 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400412 // expectMessageDropped, if true, means the test message is expected to
413 // be dropped by the client rather than echoed back.
414 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900415 // expectPeerCertificate, if not nil, is the certificate chain the peer
416 // is expected to send.
417 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700418}
419
Adam Langley7c803a62015-06-15 15:35:05 -0700420var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700421
David Benjaminc07afb72016-09-22 10:18:58 -0400422func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500423 if len(data) == 0 {
424 return
425 }
426
427 protocol := "tls"
428 if test.protocol == dtls {
429 protocol = "dtls"
430 }
431
432 side := "client"
433 if test.testType == serverTest {
434 side = "server"
435 }
436
437 dir := path.Join(*transcriptDir, protocol, side)
438 if err := os.MkdirAll(dir, 0755); err != nil {
439 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
440 return
441 }
442
David Benjaminc07afb72016-09-22 10:18:58 -0400443 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500444 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
445 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
446 }
447}
448
David Benjamin3ed59772016-03-08 12:50:21 -0500449// A timeoutConn implements an idle timeout on each Read and Write operation.
450type timeoutConn struct {
451 net.Conn
452 timeout time.Duration
453}
454
455func (t *timeoutConn) Read(b []byte) (int, error) {
456 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
457 return 0, err
458 }
459 return t.Conn.Read(b)
460}
461
462func (t *timeoutConn) Write(b []byte) (int, error) {
463 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
464 return 0, err
465 }
466 return t.Conn.Write(b)
467}
468
David Benjaminc07afb72016-09-22 10:18:58 -0400469func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400470 if !test.noSessionCache {
471 if config.ClientSessionCache == nil {
472 config.ClientSessionCache = NewLRUClientSessionCache(1)
473 }
474 if config.ServerSessionCache == nil {
475 config.ServerSessionCache = NewLRUServerSessionCache(1)
476 }
477 }
478 if test.testType == clientTest {
479 if len(config.Certificates) == 0 {
480 config.Certificates = []Certificate{rsaCertificate}
481 }
482 } else {
483 // Supply a ServerName to ensure a constant session cache key,
484 // rather than falling back to net.Conn.RemoteAddr.
485 if len(config.ServerName) == 0 {
486 config.ServerName = "test"
487 }
488 }
489 if *fuzzer {
490 config.Bugs.NullAllCiphers = true
491 }
David Benjamin01a90572016-09-22 00:11:43 -0400492 if *deterministic {
493 config.Time = func() time.Time { return time.Unix(1234, 1234) }
494 }
David Benjamine54af062016-08-08 19:21:18 -0400495
David Benjamin01784b42016-06-07 18:00:52 -0400496 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500497
David Benjamin6fd297b2014-08-11 18:43:38 -0400498 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500499 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
500 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500501 }
502
David Benjamin9867b7d2016-03-01 23:25:48 -0500503 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500504 local, peer := "client", "server"
505 if test.testType == clientTest {
506 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500507 }
David Benjaminebda9b32015-11-02 15:33:18 -0500508 connDebug := &recordingConn{
509 Conn: conn,
510 isDatagram: test.protocol == dtls,
511 local: local,
512 peer: peer,
513 }
514 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500515 if *flagDebug {
516 defer connDebug.WriteTo(os.Stdout)
517 }
518 if len(*transcriptDir) != 0 {
519 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400520 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500521 }()
522 }
David Benjaminebda9b32015-11-02 15:33:18 -0500523
524 if config.Bugs.PacketAdaptor != nil {
525 config.Bugs.PacketAdaptor.debug = connDebug
526 }
527 }
528
529 if test.replayWrites {
530 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400531 }
532
David Benjamin3ed59772016-03-08 12:50:21 -0500533 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500534 if test.damageFirstWrite {
535 connDamage = newDamageAdaptor(conn)
536 conn = connDamage
537 }
538
David Benjamin6fd297b2014-08-11 18:43:38 -0400539 if test.sendPrefix != "" {
540 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
541 return err
542 }
David Benjamin98e882e2014-08-08 13:24:34 -0400543 }
544
David Benjamin1d5c83e2014-07-22 19:20:02 -0400545 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400546 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400547 if test.protocol == dtls {
548 tlsConn = DTLSServer(conn, config)
549 } else {
550 tlsConn = Server(conn, config)
551 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400552 } else {
553 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400554 if test.protocol == dtls {
555 tlsConn = DTLSClient(conn, config)
556 } else {
557 tlsConn = Client(conn, config)
558 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400559 }
David Benjamin30789da2015-08-29 22:56:45 -0400560 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400561
Adam Langley95c29f32014-06-20 12:00:00 -0700562 if err := tlsConn.Handshake(); err != nil {
563 return err
564 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700565
David Benjamin01fe8202014-09-24 15:21:44 -0400566 // TODO(davidben): move all per-connection expectations into a dedicated
567 // expectations struct that can be specified separately for the two
568 // legs.
569 expectedVersion := test.expectedVersion
570 if isResume && test.expectedResumeVersion != 0 {
571 expectedVersion = test.expectedResumeVersion
572 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700573 connState := tlsConn.ConnectionState()
574 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400575 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400576 }
577
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700578 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400579 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
580 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700581 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
582 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
583 }
David Benjamin90da8c82015-04-20 14:57:57 -0400584
David Benjamina08e49d2014-08-24 01:46:07 -0400585 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700586 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400587 if channelID == nil {
588 return fmt.Errorf("no channel ID negotiated")
589 }
590 if channelID.Curve != channelIDKey.Curve ||
591 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
592 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
593 return fmt.Errorf("incorrect channel ID")
594 }
595 }
596
David Benjaminae2888f2014-09-06 12:58:58 -0400597 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700598 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400599 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
600 }
601 }
602
David Benjaminc7ce9772015-10-09 19:32:41 -0400603 if test.expectNoNextProto {
604 if actual := connState.NegotiatedProtocol; actual != "" {
605 return fmt.Errorf("got unexpected next proto %s", actual)
606 }
607 }
608
David Benjaminfc7b0862014-09-06 13:21:53 -0400609 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400611 return fmt.Errorf("next proto type mismatch")
612 }
613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500616 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
617 }
618
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100619 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300620 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100621 }
622
Paul Lietar4fac72e2015-09-09 13:44:55 +0100623 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
624 return fmt.Errorf("SCT list mismatch")
625 }
626
Nick Harper60edffd2016-06-21 15:19:24 -0700627 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
628 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400629 }
630
Steven Valdez5440fe02016-07-18 12:40:30 -0400631 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
632 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
633 }
634
David Benjamin2c516452016-11-15 10:16:54 +0900635 if test.expectPeerCertificate != nil {
636 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
637 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
638 }
639 for i, cert := range connState.PeerCertificates {
640 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
641 return fmt.Errorf("peer certificate %d did not match", i+1)
642 }
643 }
644 }
645
David Benjaminc565ebb2015-04-03 04:06:36 -0400646 if test.exportKeyingMaterial > 0 {
647 actual := make([]byte, test.exportKeyingMaterial)
648 if _, err := io.ReadFull(tlsConn, actual); err != nil {
649 return err
650 }
651 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
652 if err != nil {
653 return err
654 }
655 if !bytes.Equal(actual, expected) {
656 return fmt.Errorf("keying material mismatch")
657 }
658 }
659
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700660 if test.testTLSUnique {
661 var peersValue [12]byte
662 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
663 return err
664 }
665 expected := tlsConn.ConnectionState().TLSUnique
666 if !bytes.Equal(peersValue[:], expected) {
667 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
668 }
669 }
670
David Benjamine58c4f52014-08-24 03:47:07 -0400671 if test.shimWritesFirst {
672 var buf [5]byte
673 _, err := io.ReadFull(tlsConn, buf[:])
674 if err != nil {
675 return err
676 }
677 if string(buf[:]) != "hello" {
678 return fmt.Errorf("bad initial message")
679 }
680 }
681
Steven Valdez32635b82016-08-16 11:25:03 -0400682 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400683 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400684 return err
685 }
Steven Valdez32635b82016-08-16 11:25:03 -0400686 }
687
David Benjamina8ebe222015-06-06 03:04:39 -0400688 for i := 0; i < test.sendEmptyRecords; i++ {
689 tlsConn.Write(nil)
690 }
691
David Benjamin24f346d2015-06-06 03:28:08 -0400692 for i := 0; i < test.sendWarningAlerts; i++ {
693 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
694 }
695
David Benjamin47921102016-07-28 11:29:18 -0400696 if test.sendHalfHelloRequest {
697 tlsConn.SendHalfHelloRequest()
698 }
699
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400700 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700701 if test.renegotiateCiphers != nil {
702 config.CipherSuites = test.renegotiateCiphers
703 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400704 for i := 0; i < test.renegotiate; i++ {
705 if err := tlsConn.Renegotiate(); err != nil {
706 return err
707 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700708 }
709 } else if test.renegotiateCiphers != nil {
710 panic("renegotiateCiphers without renegotiate")
711 }
712
David Benjamin5fa3eba2015-01-22 16:35:40 -0500713 if test.damageFirstWrite {
714 connDamage.setDamage(true)
715 tlsConn.Write([]byte("DAMAGED WRITE"))
716 connDamage.setDamage(false)
717 }
718
David Benjamin8e6db492015-07-25 18:29:23 -0400719 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700720 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400721 if test.protocol == dtls {
722 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
723 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700724 // Read until EOF.
725 _, err := io.Copy(ioutil.Discard, tlsConn)
726 return err
727 }
David Benjamin4417d052015-04-05 04:17:25 -0400728 if messageLen == 0 {
729 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700730 }
Adam Langley95c29f32014-06-20 12:00:00 -0700731
David Benjamin8e6db492015-07-25 18:29:23 -0400732 messageCount := test.messageCount
733 if messageCount == 0 {
734 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400735 }
736
David Benjamin8e6db492015-07-25 18:29:23 -0400737 for j := 0; j < messageCount; j++ {
738 testMessage := make([]byte, messageLen)
739 for i := range testMessage {
740 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400741 }
David Benjamin8e6db492015-07-25 18:29:23 -0400742 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700743
Steven Valdez32635b82016-08-16 11:25:03 -0400744 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400745 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400746 }
747
David Benjamin8e6db492015-07-25 18:29:23 -0400748 for i := 0; i < test.sendEmptyRecords; i++ {
749 tlsConn.Write(nil)
750 }
751
752 for i := 0; i < test.sendWarningAlerts; i++ {
753 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
754 }
755
David Benjamin4f75aaf2015-09-01 16:53:10 -0400756 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400757 // The shim will not respond.
758 continue
759 }
760
David Benjamin8e6db492015-07-25 18:29:23 -0400761 buf := make([]byte, len(testMessage))
762 if test.protocol == dtls {
763 bufTmp := make([]byte, len(buf)+1)
764 n, err := tlsConn.Read(bufTmp)
765 if err != nil {
766 return err
767 }
768 if n != len(buf) {
769 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
770 }
771 copy(buf, bufTmp)
772 } else {
773 _, err := io.ReadFull(tlsConn, buf)
774 if err != nil {
775 return err
776 }
777 }
778
779 for i, v := range buf {
780 if v != testMessage[i]^0xff {
781 return fmt.Errorf("bad reply contents at byte %d", i)
782 }
Adam Langley95c29f32014-06-20 12:00:00 -0700783 }
784 }
785
786 return nil
787}
788
David Benjamin325b5c32014-07-01 19:40:31 -0400789func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400790 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700791 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400792 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700793 }
David Benjamin325b5c32014-07-01 19:40:31 -0400794 valgrindArgs = append(valgrindArgs, path)
795 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700796
David Benjamin325b5c32014-07-01 19:40:31 -0400797 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700798}
799
David Benjamin325b5c32014-07-01 19:40:31 -0400800func gdbOf(path string, args ...string) *exec.Cmd {
801 xtermArgs := []string{"-e", "gdb", "--args"}
802 xtermArgs = append(xtermArgs, path)
803 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700804
David Benjamin325b5c32014-07-01 19:40:31 -0400805 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700806}
807
David Benjamind16bf342015-12-18 00:53:12 -0500808func lldbOf(path string, args ...string) *exec.Cmd {
809 xtermArgs := []string{"-e", "lldb", "--"}
810 xtermArgs = append(xtermArgs, path)
811 xtermArgs = append(xtermArgs, args...)
812
813 return exec.Command("xterm", xtermArgs...)
814}
815
EKR842ae6c2016-07-27 09:22:05 +0200816var (
817 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
818 errUnimplemented = errors.New("child process does not implement needed flags")
819)
Adam Langley69a01602014-11-17 17:26:55 -0800820
David Benjamin87c8a642015-02-21 01:54:29 -0500821// accept accepts a connection from listener, unless waitChan signals a process
822// exit first.
823func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
824 type connOrError struct {
825 conn net.Conn
826 err error
827 }
828 connChan := make(chan connOrError, 1)
829 go func() {
830 conn, err := listener.Accept()
831 connChan <- connOrError{conn, err}
832 close(connChan)
833 }()
834 select {
835 case result := <-connChan:
836 return result.conn, result.err
837 case childErr := <-waitChan:
838 waitChan <- childErr
839 return nil, fmt.Errorf("child exited early: %s", childErr)
840 }
841}
842
EKRf71d7ed2016-08-06 13:25:12 -0700843func translateExpectedError(errorStr string) string {
844 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
845 return translated
846 }
847
848 if *looseErrors {
849 return ""
850 }
851
852 return errorStr
853}
854
Adam Langley7c803a62015-06-15 15:35:05 -0700855func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400856 // Help debugging panics on the Go side.
857 defer func() {
858 if r := recover(); r != nil {
859 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
860 panic(r)
861 }
862 }()
863
Adam Langley38311732014-10-16 19:04:35 -0700864 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
865 panic("Error expected without shouldFail in " + test.name)
866 }
867
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700868 if test.expectResumeRejected && !test.resumeSession {
869 panic("expectResumeRejected without resumeSession in " + test.name)
870 }
871
Adam Langley33b1d4f2016-12-07 15:03:45 -0800872 for _, ver := range tlsVersions {
873 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
874 continue
875 }
876
877 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
878 continue
879 }
880
881 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))
882 }
883
David Benjamin87c8a642015-02-21 01:54:29 -0500884 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
885 if err != nil {
886 panic(err)
887 }
888 defer func() {
889 if listener != nil {
890 listener.Close()
891 }
892 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700893
David Benjamin87c8a642015-02-21 01:54:29 -0500894 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400895 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400896 flags = append(flags, "-server")
897
David Benjamin025b3d32014-07-01 19:53:04 -0400898 flags = append(flags, "-key-file")
899 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700900 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400901 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700902 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400903 }
904
905 flags = append(flags, "-cert-file")
906 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700907 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400908 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700909 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400910 }
911 }
David Benjamin5a593af2014-08-11 19:51:50 -0400912
David Benjamin6fd297b2014-08-11 18:43:38 -0400913 if test.protocol == dtls {
914 flags = append(flags, "-dtls")
915 }
916
David Benjamin46662482016-08-17 00:51:00 -0400917 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400918 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400919 resumeCount++
920 if test.resumeRenewedSession {
921 resumeCount++
922 }
923 }
924
925 if resumeCount > 0 {
926 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400927 }
928
David Benjamine58c4f52014-08-24 03:47:07 -0400929 if test.shimWritesFirst {
930 flags = append(flags, "-shim-writes-first")
931 }
932
David Benjamin30789da2015-08-29 22:56:45 -0400933 if test.shimShutsDown {
934 flags = append(flags, "-shim-shuts-down")
935 }
936
David Benjaminc565ebb2015-04-03 04:06:36 -0400937 if test.exportKeyingMaterial > 0 {
938 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
939 flags = append(flags, "-export-label", test.exportLabel)
940 flags = append(flags, "-export-context", test.exportContext)
941 if test.useExportContext {
942 flags = append(flags, "-use-export-context")
943 }
944 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700945 if test.expectResumeRejected {
946 flags = append(flags, "-expect-session-miss")
947 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400948
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700949 if test.testTLSUnique {
950 flags = append(flags, "-tls-unique")
951 }
952
David Benjamin025b3d32014-07-01 19:53:04 -0400953 flags = append(flags, test.flags...)
954
955 var shim *exec.Cmd
956 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700957 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700958 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700959 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500960 } else if *useLLDB {
961 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400962 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700963 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400964 }
David Benjamin025b3d32014-07-01 19:53:04 -0400965 shim.Stdin = os.Stdin
966 var stdoutBuf, stderrBuf bytes.Buffer
967 shim.Stdout = &stdoutBuf
968 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800969 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500970 shim.Env = os.Environ()
971 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800972 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400973 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800974 }
975 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
976 }
David Benjamin025b3d32014-07-01 19:53:04 -0400977
978 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700979 panic(err)
980 }
David Benjamin87c8a642015-02-21 01:54:29 -0500981 waitChan := make(chan error, 1)
982 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700983
984 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700985
David Benjamin7a4aaa42016-09-20 17:58:14 -0400986 if *deterministic {
987 config.Rand = &deterministicRand{}
988 }
989
David Benjamin87c8a642015-02-21 01:54:29 -0500990 conn, err := acceptOrWait(listener, waitChan)
991 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400992 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500993 conn.Close()
994 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500995
David Benjamin46662482016-08-17 00:51:00 -0400996 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400997 var resumeConfig Config
998 if test.resumeConfig != nil {
999 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001000 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001001 resumeConfig.SessionTicketKey = config.SessionTicketKey
1002 resumeConfig.ClientSessionCache = config.ClientSessionCache
1003 resumeConfig.ServerSessionCache = config.ServerSessionCache
1004 }
David Benjamin2e045a92016-06-08 13:09:56 -04001005 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001006 } else {
1007 resumeConfig = config
1008 }
David Benjamin87c8a642015-02-21 01:54:29 -05001009 var connResume net.Conn
1010 connResume, err = acceptOrWait(listener, waitChan)
1011 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001012 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001013 connResume.Close()
1014 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001015 }
1016
David Benjamin87c8a642015-02-21 01:54:29 -05001017 // Close the listener now. This is to avoid hangs should the shim try to
1018 // open more connections than expected.
1019 listener.Close()
1020 listener = nil
1021
1022 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -04001023 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001024 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001025 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1026 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001027 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001028 case 89:
1029 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001030 case 99:
1031 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001032 }
1033 }
Adam Langley95c29f32014-06-20 12:00:00 -07001034
David Benjamin9bea3492016-03-02 10:59:16 -05001035 // Account for Windows line endings.
1036 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1037 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001038
1039 // Separate the errors from the shim and those from tools like
1040 // AddressSanitizer.
1041 var extraStderr string
1042 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1043 stderr = stderrParts[0]
1044 extraStderr = stderrParts[1]
1045 }
1046
Adam Langley95c29f32014-06-20 12:00:00 -07001047 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001048 expectedError := translateExpectedError(test.expectedError)
1049 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001050
Adam Langleyac61fa32014-06-23 12:03:11 -07001051 localError := "none"
1052 if err != nil {
1053 localError = err.Error()
1054 }
1055 if len(test.expectedLocalError) != 0 {
1056 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1057 }
Adam Langley95c29f32014-06-20 12:00:00 -07001058
1059 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001060 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001061 if childErr != nil {
1062 childError = childErr.Error()
1063 }
1064
1065 var msg string
1066 switch {
1067 case failed && !test.shouldFail:
1068 msg = "unexpected failure"
1069 case !failed && test.shouldFail:
1070 msg = "unexpected success"
1071 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001072 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001073 default:
1074 panic("internal error")
1075 }
1076
David Benjamin9aafb642016-09-20 19:36:53 -04001077 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 -07001078 }
1079
David Benjamind2ba8892016-09-20 19:41:04 -04001080 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001081 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001082 }
1083
David Benjamind2ba8892016-09-20 19:41:04 -04001084 if *useValgrind && isValgrindError {
1085 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1086 }
1087
Adam Langley95c29f32014-06-20 12:00:00 -07001088 return nil
1089}
1090
David Benjaminaa012042016-12-10 13:33:05 -05001091type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001092 name string
1093 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001094 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001095 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001096}
1097
1098var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001099 {"SSL3", VersionSSL30, "-no-ssl3", false},
1100 {"TLS1", VersionTLS10, "-no-tls1", true},
1101 {"TLS11", VersionTLS11, "-no-tls11", false},
1102 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001103 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001104}
1105
David Benjaminaa012042016-12-10 13:33:05 -05001106type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001107 name string
1108 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001109}
1110
1111var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001112 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001113 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001114 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001115 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001116 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001117 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001118 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001119 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1120 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001121 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1122 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001123 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001124 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001125 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001126 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001127 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001128 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001129 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001130 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001131 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001132 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001133 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1134 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001135 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1136 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001137 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001138 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1139 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1140 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001141 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001142}
1143
David Benjamin8b8c0062014-11-23 02:47:52 -05001144func hasComponent(suiteName, component string) bool {
1145 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1146}
1147
David Benjaminf7768e42014-08-31 02:06:47 -04001148func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001149 return hasComponent(suiteName, "GCM") ||
1150 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001151 hasComponent(suiteName, "SHA384") ||
1152 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001153}
1154
Nick Harper1fd39d82016-06-14 18:14:35 -07001155func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001156 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001157}
1158
David Benjamin8b8c0062014-11-23 02:47:52 -05001159func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001160 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001161}
1162
Adam Langleya7997f12015-05-14 17:38:50 -07001163func bigFromHex(hex string) *big.Int {
1164 ret, ok := new(big.Int).SetString(hex, 16)
1165 if !ok {
1166 panic("failed to parse hex number 0x" + hex)
1167 }
1168 return ret
1169}
1170
Adam Langley7c803a62015-06-15 15:35:05 -07001171func addBasicTests() {
1172 basicTests := []testCase{
1173 {
Adam Langley7c803a62015-06-15 15:35:05 -07001174 name: "NoFallbackSCSV",
1175 config: Config{
1176 Bugs: ProtocolBugs{
1177 FailIfNotFallbackSCSV: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedLocalError: "no fallback SCSV found",
1182 },
1183 {
1184 name: "SendFallbackSCSV",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 FailIfNotFallbackSCSV: true,
1188 },
1189 },
1190 flags: []string{"-fallback-scsv"},
1191 },
1192 {
1193 name: "ClientCertificateTypes",
1194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001195 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001196 ClientAuth: RequestClientCert,
1197 ClientCertificateTypes: []byte{
1198 CertTypeDSSSign,
1199 CertTypeRSASign,
1200 CertTypeECDSASign,
1201 },
1202 },
1203 flags: []string{
1204 "-expect-certificate-types",
1205 base64.StdEncoding.EncodeToString([]byte{
1206 CertTypeDSSSign,
1207 CertTypeRSASign,
1208 CertTypeECDSASign,
1209 }),
1210 },
1211 },
1212 {
Adam Langley7c803a62015-06-15 15:35:05 -07001213 name: "UnauthenticatedECDH",
1214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001215 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1217 Bugs: ProtocolBugs{
1218 UnauthenticatedECDH: true,
1219 },
1220 },
1221 shouldFail: true,
1222 expectedError: ":UNEXPECTED_MESSAGE:",
1223 },
1224 {
1225 name: "SkipCertificateStatus",
1226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001227 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1229 Bugs: ProtocolBugs{
1230 SkipCertificateStatus: true,
1231 },
1232 },
1233 flags: []string{
1234 "-enable-ocsp-stapling",
1235 },
1236 },
1237 {
1238 name: "SkipServerKeyExchange",
1239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001240 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001241 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1242 Bugs: ProtocolBugs{
1243 SkipServerKeyExchange: true,
1244 },
1245 },
1246 shouldFail: true,
1247 expectedError: ":UNEXPECTED_MESSAGE:",
1248 },
1249 {
Adam Langley7c803a62015-06-15 15:35:05 -07001250 testType: serverTest,
1251 name: "Alert",
1252 config: Config{
1253 Bugs: ProtocolBugs{
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1259 },
1260 {
1261 protocol: dtls,
1262 testType: serverTest,
1263 name: "Alert-DTLS",
1264 config: Config{
1265 Bugs: ProtocolBugs{
1266 SendSpuriousAlert: alertRecordOverflow,
1267 },
1268 },
1269 shouldFail: true,
1270 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1271 },
1272 {
1273 testType: serverTest,
1274 name: "FragmentAlert",
1275 config: Config{
1276 Bugs: ProtocolBugs{
1277 FragmentAlert: true,
1278 SendSpuriousAlert: alertRecordOverflow,
1279 },
1280 },
1281 shouldFail: true,
1282 expectedError: ":BAD_ALERT:",
1283 },
1284 {
1285 protocol: dtls,
1286 testType: serverTest,
1287 name: "FragmentAlert-DTLS",
1288 config: Config{
1289 Bugs: ProtocolBugs{
1290 FragmentAlert: true,
1291 SendSpuriousAlert: alertRecordOverflow,
1292 },
1293 },
1294 shouldFail: true,
1295 expectedError: ":BAD_ALERT:",
1296 },
1297 {
1298 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001299 name: "DoubleAlert",
1300 config: Config{
1301 Bugs: ProtocolBugs{
1302 DoubleAlert: true,
1303 SendSpuriousAlert: alertRecordOverflow,
1304 },
1305 },
1306 shouldFail: true,
1307 expectedError: ":BAD_ALERT:",
1308 },
1309 {
1310 protocol: dtls,
1311 testType: serverTest,
1312 name: "DoubleAlert-DTLS",
1313 config: Config{
1314 Bugs: ProtocolBugs{
1315 DoubleAlert: true,
1316 SendSpuriousAlert: alertRecordOverflow,
1317 },
1318 },
1319 shouldFail: true,
1320 expectedError: ":BAD_ALERT:",
1321 },
1322 {
Adam Langley7c803a62015-06-15 15:35:05 -07001323 name: "SkipNewSessionTicket",
1324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001325 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001326 Bugs: ProtocolBugs{
1327 SkipNewSessionTicket: true,
1328 },
1329 },
1330 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001331 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001332 },
1333 {
1334 testType: serverTest,
1335 name: "FallbackSCSV",
1336 config: Config{
1337 MaxVersion: VersionTLS11,
1338 Bugs: ProtocolBugs{
1339 SendFallbackSCSV: true,
1340 },
1341 },
David Benjamin56cadc32016-12-16 19:54:11 -05001342 shouldFail: true,
1343 expectedError: ":INAPPROPRIATE_FALLBACK:",
1344 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001345 },
1346 {
1347 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001348 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001349 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001350 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001351 Bugs: ProtocolBugs{
1352 SendFallbackSCSV: true,
1353 },
1354 },
1355 },
1356 {
1357 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001358 name: "FallbackSCSV-VersionMatch-TLS12",
1359 config: Config{
1360 MaxVersion: VersionTLS12,
1361 Bugs: ProtocolBugs{
1362 SendFallbackSCSV: true,
1363 },
1364 },
1365 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1366 },
1367 {
1368 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001369 name: "FragmentedClientVersion",
1370 config: Config{
1371 Bugs: ProtocolBugs{
1372 MaxHandshakeRecordLength: 1,
1373 FragmentClientVersion: true,
1374 },
1375 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001376 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001377 },
1378 {
Adam Langley7c803a62015-06-15 15:35:05 -07001379 testType: serverTest,
1380 name: "HttpGET",
1381 sendPrefix: "GET / HTTP/1.0\n",
1382 shouldFail: true,
1383 expectedError: ":HTTP_REQUEST:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "HttpPOST",
1388 sendPrefix: "POST / HTTP/1.0\n",
1389 shouldFail: true,
1390 expectedError: ":HTTP_REQUEST:",
1391 },
1392 {
1393 testType: serverTest,
1394 name: "HttpHEAD",
1395 sendPrefix: "HEAD / HTTP/1.0\n",
1396 shouldFail: true,
1397 expectedError: ":HTTP_REQUEST:",
1398 },
1399 {
1400 testType: serverTest,
1401 name: "HttpPUT",
1402 sendPrefix: "PUT / HTTP/1.0\n",
1403 shouldFail: true,
1404 expectedError: ":HTTP_REQUEST:",
1405 },
1406 {
1407 testType: serverTest,
1408 name: "HttpCONNECT",
1409 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1410 shouldFail: true,
1411 expectedError: ":HTTPS_PROXY_REQUEST:",
1412 },
1413 {
1414 testType: serverTest,
1415 name: "Garbage",
1416 sendPrefix: "blah",
1417 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001418 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001419 },
1420 {
Adam Langley7c803a62015-06-15 15:35:05 -07001421 name: "RSAEphemeralKey",
1422 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001423 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001424 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1425 Bugs: ProtocolBugs{
1426 RSAEphemeralKey: true,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":UNEXPECTED_MESSAGE:",
1431 },
1432 {
1433 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001434 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001435 shouldFail: true,
1436 expectedError: ":WRONG_SSL_VERSION:",
1437 },
1438 {
1439 protocol: dtls,
1440 name: "DisableEverything-DTLS",
1441 flags: []string{"-no-tls12", "-no-tls1"},
1442 shouldFail: true,
1443 expectedError: ":WRONG_SSL_VERSION:",
1444 },
1445 {
Adam Langley7c803a62015-06-15 15:35:05 -07001446 protocol: dtls,
1447 testType: serverTest,
1448 name: "MTU",
1449 config: Config{
1450 Bugs: ProtocolBugs{
1451 MaxPacketLength: 256,
1452 },
1453 },
1454 flags: []string{"-mtu", "256"},
1455 },
1456 {
1457 protocol: dtls,
1458 testType: serverTest,
1459 name: "MTUExceeded",
1460 config: Config{
1461 Bugs: ProtocolBugs{
1462 MaxPacketLength: 255,
1463 },
1464 },
1465 flags: []string{"-mtu", "256"},
1466 shouldFail: true,
1467 expectedLocalError: "dtls: exceeded maximum packet length",
1468 },
1469 {
1470 name: "CertMismatchRSA",
1471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001472 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001473 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001474 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001475 Bugs: ProtocolBugs{
1476 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1477 },
1478 },
1479 shouldFail: true,
1480 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1481 },
1482 {
1483 name: "CertMismatchECDSA",
1484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001485 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001486 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001487 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001488 Bugs: ProtocolBugs{
1489 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1490 },
1491 },
1492 shouldFail: true,
1493 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1494 },
1495 {
1496 name: "EmptyCertificateList",
1497 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001498 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 Bugs: ProtocolBugs{
1500 EmptyCertificateList: true,
1501 },
1502 },
1503 shouldFail: true,
1504 expectedError: ":DECODE_ERROR:",
1505 },
1506 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001507 name: "EmptyCertificateList-TLS13",
1508 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001509 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001510 Bugs: ProtocolBugs{
1511 EmptyCertificateList: true,
1512 },
1513 },
1514 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001515 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001516 },
1517 {
Adam Langley7c803a62015-06-15 15:35:05 -07001518 name: "TLSFatalBadPackets",
1519 damageFirstWrite: true,
1520 shouldFail: true,
1521 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1522 },
1523 {
1524 protocol: dtls,
1525 name: "DTLSIgnoreBadPackets",
1526 damageFirstWrite: true,
1527 },
1528 {
1529 protocol: dtls,
1530 name: "DTLSIgnoreBadPackets-Async",
1531 damageFirstWrite: true,
1532 flags: []string{"-async"},
1533 },
1534 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001535 name: "AppDataBeforeHandshake",
1536 config: Config{
1537 Bugs: ProtocolBugs{
1538 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1539 },
1540 },
1541 shouldFail: true,
1542 expectedError: ":UNEXPECTED_RECORD:",
1543 },
1544 {
1545 name: "AppDataBeforeHandshake-Empty",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 AppDataBeforeHandshake: []byte{},
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: ":UNEXPECTED_RECORD:",
1553 },
1554 {
1555 protocol: dtls,
1556 name: "AppDataBeforeHandshake-DTLS",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1560 },
1561 },
1562 shouldFail: true,
1563 expectedError: ":UNEXPECTED_RECORD:",
1564 },
1565 {
1566 protocol: dtls,
1567 name: "AppDataBeforeHandshake-DTLS-Empty",
1568 config: Config{
1569 Bugs: ProtocolBugs{
1570 AppDataBeforeHandshake: []byte{},
1571 },
1572 },
1573 shouldFail: true,
1574 expectedError: ":UNEXPECTED_RECORD:",
1575 },
1576 {
Adam Langley7c803a62015-06-15 15:35:05 -07001577 name: "AppDataAfterChangeCipherSpec",
1578 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001579 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001580 Bugs: ProtocolBugs{
1581 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1582 },
1583 },
1584 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001585 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001586 },
1587 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001588 name: "AppDataAfterChangeCipherSpec-Empty",
1589 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001590 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001591 Bugs: ProtocolBugs{
1592 AppDataAfterChangeCipherSpec: []byte{},
1593 },
1594 },
1595 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001596 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001597 },
1598 {
Adam Langley7c803a62015-06-15 15:35:05 -07001599 protocol: dtls,
1600 name: "AppDataAfterChangeCipherSpec-DTLS",
1601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001602 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001603 Bugs: ProtocolBugs{
1604 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1605 },
1606 },
1607 // BoringSSL's DTLS implementation will drop the out-of-order
1608 // application data.
1609 },
1610 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001611 protocol: dtls,
1612 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001614 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001615 Bugs: ProtocolBugs{
1616 AppDataAfterChangeCipherSpec: []byte{},
1617 },
1618 },
1619 // BoringSSL's DTLS implementation will drop the out-of-order
1620 // application data.
1621 },
1622 {
Adam Langley7c803a62015-06-15 15:35:05 -07001623 name: "AlertAfterChangeCipherSpec",
1624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001625 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001626 Bugs: ProtocolBugs{
1627 AlertAfterChangeCipherSpec: alertRecordOverflow,
1628 },
1629 },
1630 shouldFail: true,
1631 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1632 },
1633 {
1634 protocol: dtls,
1635 name: "AlertAfterChangeCipherSpec-DTLS",
1636 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001637 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001638 Bugs: ProtocolBugs{
1639 AlertAfterChangeCipherSpec: alertRecordOverflow,
1640 },
1641 },
1642 shouldFail: true,
1643 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1644 },
1645 {
1646 protocol: dtls,
1647 name: "ReorderHandshakeFragments-Small-DTLS",
1648 config: Config{
1649 Bugs: ProtocolBugs{
1650 ReorderHandshakeFragments: true,
1651 // Small enough that every handshake message is
1652 // fragmented.
1653 MaxHandshakeRecordLength: 2,
1654 },
1655 },
1656 },
1657 {
1658 protocol: dtls,
1659 name: "ReorderHandshakeFragments-Large-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 ReorderHandshakeFragments: true,
1663 // Large enough that no handshake message is
1664 // fragmented.
1665 MaxHandshakeRecordLength: 2048,
1666 },
1667 },
1668 },
1669 {
1670 protocol: dtls,
1671 name: "MixCompleteMessageWithFragments-DTLS",
1672 config: Config{
1673 Bugs: ProtocolBugs{
1674 ReorderHandshakeFragments: true,
1675 MixCompleteMessageWithFragments: true,
1676 MaxHandshakeRecordLength: 2,
1677 },
1678 },
1679 },
1680 {
1681 name: "SendInvalidRecordType",
1682 config: Config{
1683 Bugs: ProtocolBugs{
1684 SendInvalidRecordType: true,
1685 },
1686 },
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_RECORD:",
1689 },
1690 {
1691 protocol: dtls,
1692 name: "SendInvalidRecordType-DTLS",
1693 config: Config{
1694 Bugs: ProtocolBugs{
1695 SendInvalidRecordType: true,
1696 },
1697 },
1698 shouldFail: true,
1699 expectedError: ":UNEXPECTED_RECORD:",
1700 },
1701 {
1702 name: "FalseStart-SkipServerSecondLeg",
1703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001704 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001705 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1706 NextProtos: []string{"foo"},
1707 Bugs: ProtocolBugs{
1708 SkipNewSessionTicket: true,
1709 SkipChangeCipherSpec: true,
1710 SkipFinished: true,
1711 ExpectFalseStart: true,
1712 },
1713 },
1714 flags: []string{
1715 "-false-start",
1716 "-handshake-never-done",
1717 "-advertise-alpn", "\x03foo",
1718 },
1719 shimWritesFirst: true,
1720 shouldFail: true,
1721 expectedError: ":UNEXPECTED_RECORD:",
1722 },
1723 {
1724 name: "FalseStart-SkipServerSecondLeg-Implicit",
1725 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001726 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001727 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1728 NextProtos: []string{"foo"},
1729 Bugs: ProtocolBugs{
1730 SkipNewSessionTicket: true,
1731 SkipChangeCipherSpec: true,
1732 SkipFinished: true,
1733 },
1734 },
1735 flags: []string{
1736 "-implicit-handshake",
1737 "-false-start",
1738 "-handshake-never-done",
1739 "-advertise-alpn", "\x03foo",
1740 },
1741 shouldFail: true,
1742 expectedError: ":UNEXPECTED_RECORD:",
1743 },
1744 {
1745 testType: serverTest,
1746 name: "FailEarlyCallback",
1747 flags: []string{"-fail-early-callback"},
1748 shouldFail: true,
1749 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001750 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001751 },
1752 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001753 name: "FailCertCallback-Client-TLS12",
1754 config: Config{
1755 MaxVersion: VersionTLS12,
1756 ClientAuth: RequestClientCert,
1757 },
1758 flags: []string{"-fail-cert-callback"},
1759 shouldFail: true,
1760 expectedError: ":CERT_CB_ERROR:",
1761 expectedLocalError: "remote error: internal error",
1762 },
1763 {
1764 testType: serverTest,
1765 name: "FailCertCallback-Server-TLS12",
1766 config: Config{
1767 MaxVersion: VersionTLS12,
1768 },
1769 flags: []string{"-fail-cert-callback"},
1770 shouldFail: true,
1771 expectedError: ":CERT_CB_ERROR:",
1772 expectedLocalError: "remote error: internal error",
1773 },
1774 {
1775 name: "FailCertCallback-Client-TLS13",
1776 config: Config{
1777 MaxVersion: VersionTLS13,
1778 ClientAuth: RequestClientCert,
1779 },
1780 flags: []string{"-fail-cert-callback"},
1781 shouldFail: true,
1782 expectedError: ":CERT_CB_ERROR:",
1783 expectedLocalError: "remote error: internal error",
1784 },
1785 {
1786 testType: serverTest,
1787 name: "FailCertCallback-Server-TLS13",
1788 config: Config{
1789 MaxVersion: VersionTLS13,
1790 },
1791 flags: []string{"-fail-cert-callback"},
1792 shouldFail: true,
1793 expectedError: ":CERT_CB_ERROR:",
1794 expectedLocalError: "remote error: internal error",
1795 },
1796 {
Adam Langley7c803a62015-06-15 15:35:05 -07001797 protocol: dtls,
1798 name: "FragmentMessageTypeMismatch-DTLS",
1799 config: Config{
1800 Bugs: ProtocolBugs{
1801 MaxHandshakeRecordLength: 2,
1802 FragmentMessageTypeMismatch: true,
1803 },
1804 },
1805 shouldFail: true,
1806 expectedError: ":FRAGMENT_MISMATCH:",
1807 },
1808 {
1809 protocol: dtls,
1810 name: "FragmentMessageLengthMismatch-DTLS",
1811 config: Config{
1812 Bugs: ProtocolBugs{
1813 MaxHandshakeRecordLength: 2,
1814 FragmentMessageLengthMismatch: true,
1815 },
1816 },
1817 shouldFail: true,
1818 expectedError: ":FRAGMENT_MISMATCH:",
1819 },
1820 {
1821 protocol: dtls,
1822 name: "SplitFragments-Header-DTLS",
1823 config: Config{
1824 Bugs: ProtocolBugs{
1825 SplitFragments: 2,
1826 },
1827 },
1828 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001829 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001830 },
1831 {
1832 protocol: dtls,
1833 name: "SplitFragments-Boundary-DTLS",
1834 config: Config{
1835 Bugs: ProtocolBugs{
1836 SplitFragments: dtlsRecordHeaderLen,
1837 },
1838 },
1839 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001840 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001841 },
1842 {
1843 protocol: dtls,
1844 name: "SplitFragments-Body-DTLS",
1845 config: Config{
1846 Bugs: ProtocolBugs{
1847 SplitFragments: dtlsRecordHeaderLen + 1,
1848 },
1849 },
1850 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001851 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001852 },
1853 {
1854 protocol: dtls,
1855 name: "SendEmptyFragments-DTLS",
1856 config: Config{
1857 Bugs: ProtocolBugs{
1858 SendEmptyFragments: true,
1859 },
1860 },
1861 },
1862 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001863 name: "BadFinished-Client",
1864 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001865 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001866 Bugs: ProtocolBugs{
1867 BadFinished: true,
1868 },
1869 },
1870 shouldFail: true,
1871 expectedError: ":DIGEST_CHECK_FAILED:",
1872 },
1873 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001874 name: "BadFinished-Client-TLS13",
1875 config: Config{
1876 MaxVersion: VersionTLS13,
1877 Bugs: ProtocolBugs{
1878 BadFinished: true,
1879 },
1880 },
1881 shouldFail: true,
1882 expectedError: ":DIGEST_CHECK_FAILED:",
1883 },
1884 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001885 testType: serverTest,
1886 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001887 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001888 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001889 Bugs: ProtocolBugs{
1890 BadFinished: true,
1891 },
1892 },
1893 shouldFail: true,
1894 expectedError: ":DIGEST_CHECK_FAILED:",
1895 },
1896 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001897 testType: serverTest,
1898 name: "BadFinished-Server-TLS13",
1899 config: Config{
1900 MaxVersion: VersionTLS13,
1901 Bugs: ProtocolBugs{
1902 BadFinished: true,
1903 },
1904 },
1905 shouldFail: true,
1906 expectedError: ":DIGEST_CHECK_FAILED:",
1907 },
1908 {
Adam Langley7c803a62015-06-15 15:35:05 -07001909 name: "FalseStart-BadFinished",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1913 NextProtos: []string{"foo"},
1914 Bugs: ProtocolBugs{
1915 BadFinished: true,
1916 ExpectFalseStart: true,
1917 },
1918 },
1919 flags: []string{
1920 "-false-start",
1921 "-handshake-never-done",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shimWritesFirst: true,
1925 shouldFail: true,
1926 expectedError: ":DIGEST_CHECK_FAILED:",
1927 },
1928 {
1929 name: "NoFalseStart-NoALPN",
1930 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001931 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001932 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1933 Bugs: ProtocolBugs{
1934 ExpectFalseStart: true,
1935 AlertBeforeFalseStartTest: alertAccessDenied,
1936 },
1937 },
1938 flags: []string{
1939 "-false-start",
1940 },
1941 shimWritesFirst: true,
1942 shouldFail: true,
1943 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1944 expectedLocalError: "tls: peer did not false start: EOF",
1945 },
1946 {
1947 name: "NoFalseStart-NoAEAD",
1948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001949 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1951 NextProtos: []string{"foo"},
1952 Bugs: ProtocolBugs{
1953 ExpectFalseStart: true,
1954 AlertBeforeFalseStartTest: alertAccessDenied,
1955 },
1956 },
1957 flags: []string{
1958 "-false-start",
1959 "-advertise-alpn", "\x03foo",
1960 },
1961 shimWritesFirst: true,
1962 shouldFail: true,
1963 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1964 expectedLocalError: "tls: peer did not false start: EOF",
1965 },
1966 {
1967 name: "NoFalseStart-RSA",
1968 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001969 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001970 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1971 NextProtos: []string{"foo"},
1972 Bugs: ProtocolBugs{
1973 ExpectFalseStart: true,
1974 AlertBeforeFalseStartTest: alertAccessDenied,
1975 },
1976 },
1977 flags: []string{
1978 "-false-start",
1979 "-advertise-alpn", "\x03foo",
1980 },
1981 shimWritesFirst: true,
1982 shouldFail: true,
1983 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1984 expectedLocalError: "tls: peer did not false start: EOF",
1985 },
1986 {
Adam Langley7c803a62015-06-15 15:35:05 -07001987 protocol: dtls,
1988 name: "SendSplitAlert-Sync",
1989 config: Config{
1990 Bugs: ProtocolBugs{
1991 SendSplitAlert: true,
1992 },
1993 },
1994 },
1995 {
1996 protocol: dtls,
1997 name: "SendSplitAlert-Async",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendSplitAlert: true,
2001 },
2002 },
2003 flags: []string{"-async"},
2004 },
2005 {
2006 protocol: dtls,
2007 name: "PackDTLSHandshake",
2008 config: Config{
2009 Bugs: ProtocolBugs{
2010 MaxHandshakeRecordLength: 2,
2011 PackHandshakeFragments: 20,
2012 PackHandshakeRecords: 200,
2013 },
2014 },
2015 },
2016 {
Adam Langley7c803a62015-06-15 15:35:05 -07002017 name: "SendEmptyRecords-Pass",
2018 sendEmptyRecords: 32,
2019 },
2020 {
2021 name: "SendEmptyRecords",
2022 sendEmptyRecords: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2025 },
2026 {
2027 name: "SendEmptyRecords-Async",
2028 sendEmptyRecords: 33,
2029 flags: []string{"-async"},
2030 shouldFail: true,
2031 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2032 },
2033 {
David Benjamine8e84b92016-08-03 15:39:47 -04002034 name: "SendWarningAlerts-Pass",
2035 config: Config{
2036 MaxVersion: VersionTLS12,
2037 },
Adam Langley7c803a62015-06-15 15:35:05 -07002038 sendWarningAlerts: 4,
2039 },
2040 {
David Benjamine8e84b92016-08-03 15:39:47 -04002041 protocol: dtls,
2042 name: "SendWarningAlerts-DTLS-Pass",
2043 config: Config{
2044 MaxVersion: VersionTLS12,
2045 },
Adam Langley7c803a62015-06-15 15:35:05 -07002046 sendWarningAlerts: 4,
2047 },
2048 {
David Benjamine8e84b92016-08-03 15:39:47 -04002049 name: "SendWarningAlerts-TLS13",
2050 config: Config{
2051 MaxVersion: VersionTLS13,
2052 },
2053 sendWarningAlerts: 4,
2054 shouldFail: true,
2055 expectedError: ":BAD_ALERT:",
2056 expectedLocalError: "remote error: error decoding message",
2057 },
2058 {
2059 name: "SendWarningAlerts",
2060 config: Config{
2061 MaxVersion: VersionTLS12,
2062 },
Adam Langley7c803a62015-06-15 15:35:05 -07002063 sendWarningAlerts: 5,
2064 shouldFail: true,
2065 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2066 },
2067 {
David Benjamine8e84b92016-08-03 15:39:47 -04002068 name: "SendWarningAlerts-Async",
2069 config: Config{
2070 MaxVersion: VersionTLS12,
2071 },
Adam Langley7c803a62015-06-15 15:35:05 -07002072 sendWarningAlerts: 5,
2073 flags: []string{"-async"},
2074 shouldFail: true,
2075 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2076 },
David Benjaminba4594a2015-06-18 18:36:15 -04002077 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002078 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002079 config: Config{
2080 MaxVersion: VersionTLS13,
2081 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002082 sendKeyUpdates: 33,
2083 keyUpdateRequest: keyUpdateNotRequested,
2084 shouldFail: true,
2085 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002086 },
2087 {
David Benjaminba4594a2015-06-18 18:36:15 -04002088 name: "EmptySessionID",
2089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002090 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002091 SessionTicketsDisabled: true,
2092 },
2093 noSessionCache: true,
2094 flags: []string{"-expect-no-session"},
2095 },
David Benjamin30789da2015-08-29 22:56:45 -04002096 {
2097 name: "Unclean-Shutdown",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 NoCloseNotify: true,
2101 ExpectCloseNotify: true,
2102 },
2103 },
2104 shimShutsDown: true,
2105 flags: []string{"-check-close-notify"},
2106 shouldFail: true,
2107 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2108 },
2109 {
2110 name: "Unclean-Shutdown-Ignored",
2111 config: Config{
2112 Bugs: ProtocolBugs{
2113 NoCloseNotify: true,
2114 },
2115 },
2116 shimShutsDown: true,
2117 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002118 {
David Benjaminfa214e42016-05-10 17:03:10 -04002119 name: "Unclean-Shutdown-Alert",
2120 config: Config{
2121 Bugs: ProtocolBugs{
2122 SendAlertOnShutdown: alertDecompressionFailure,
2123 ExpectCloseNotify: true,
2124 },
2125 },
2126 shimShutsDown: true,
2127 flags: []string{"-check-close-notify"},
2128 shouldFail: true,
2129 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2130 },
2131 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002132 name: "LargePlaintext",
2133 config: Config{
2134 Bugs: ProtocolBugs{
2135 SendLargeRecords: true,
2136 },
2137 },
2138 messageLen: maxPlaintext + 1,
2139 shouldFail: true,
2140 expectedError: ":DATA_LENGTH_TOO_LONG:",
2141 },
2142 {
2143 protocol: dtls,
2144 name: "LargePlaintext-DTLS",
2145 config: Config{
2146 Bugs: ProtocolBugs{
2147 SendLargeRecords: true,
2148 },
2149 },
2150 messageLen: maxPlaintext + 1,
2151 shouldFail: true,
2152 expectedError: ":DATA_LENGTH_TOO_LONG:",
2153 },
2154 {
2155 name: "LargeCiphertext",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 SendLargeRecords: true,
2159 },
2160 },
2161 messageLen: maxPlaintext * 2,
2162 shouldFail: true,
2163 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2164 },
2165 {
2166 protocol: dtls,
2167 name: "LargeCiphertext-DTLS",
2168 config: Config{
2169 Bugs: ProtocolBugs{
2170 SendLargeRecords: true,
2171 },
2172 },
2173 messageLen: maxPlaintext * 2,
2174 // Unlike the other four cases, DTLS drops records which
2175 // are invalid before authentication, so the connection
2176 // does not fail.
2177 expectMessageDropped: true,
2178 },
David Benjamindd6fed92015-10-23 17:41:12 -04002179 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002180 name: "BadHelloRequest-1",
2181 renegotiate: 1,
2182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002183 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002184 Bugs: ProtocolBugs{
2185 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2186 },
2187 },
2188 flags: []string{
2189 "-renegotiate-freely",
2190 "-expect-total-renegotiations", "1",
2191 },
2192 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002193 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002194 },
2195 {
2196 name: "BadHelloRequest-2",
2197 renegotiate: 1,
2198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002199 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002200 Bugs: ProtocolBugs{
2201 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2202 },
2203 },
2204 flags: []string{
2205 "-renegotiate-freely",
2206 "-expect-total-renegotiations", "1",
2207 },
2208 shouldFail: true,
2209 expectedError: ":BAD_HELLO_REQUEST:",
2210 },
David Benjaminef1b0092015-11-21 14:05:44 -05002211 {
2212 testType: serverTest,
2213 name: "SupportTicketsWithSessionID",
2214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002215 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002216 SessionTicketsDisabled: true,
2217 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002218 resumeConfig: &Config{
2219 MaxVersion: VersionTLS12,
2220 },
David Benjaminef1b0092015-11-21 14:05:44 -05002221 resumeSession: true,
2222 },
David Benjamin02edcd02016-07-27 17:40:37 -04002223 {
2224 protocol: dtls,
2225 name: "DTLS-SendExtraFinished",
2226 config: Config{
2227 Bugs: ProtocolBugs{
2228 SendExtraFinished: true,
2229 },
2230 },
2231 shouldFail: true,
2232 expectedError: ":UNEXPECTED_RECORD:",
2233 },
2234 {
2235 protocol: dtls,
2236 name: "DTLS-SendExtraFinished-Reordered",
2237 config: Config{
2238 Bugs: ProtocolBugs{
2239 MaxHandshakeRecordLength: 2,
2240 ReorderHandshakeFragments: true,
2241 SendExtraFinished: true,
2242 },
2243 },
2244 shouldFail: true,
2245 expectedError: ":UNEXPECTED_RECORD:",
2246 },
David Benjamine97fb482016-07-29 09:23:07 -04002247 {
2248 testType: serverTest,
2249 name: "V2ClientHello-EmptyRecordPrefix",
2250 config: Config{
2251 // Choose a cipher suite that does not involve
2252 // elliptic curves, so no extensions are
2253 // involved.
2254 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002255 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002256 Bugs: ProtocolBugs{
2257 SendV2ClientHello: true,
2258 },
2259 },
2260 sendPrefix: string([]byte{
2261 byte(recordTypeHandshake),
2262 3, 1, // version
2263 0, 0, // length
2264 }),
2265 // A no-op empty record may not be sent before V2ClientHello.
2266 shouldFail: true,
2267 expectedError: ":WRONG_VERSION_NUMBER:",
2268 },
2269 {
2270 testType: serverTest,
2271 name: "V2ClientHello-WarningAlertPrefix",
2272 config: Config{
2273 // Choose a cipher suite that does not involve
2274 // elliptic curves, so no extensions are
2275 // involved.
2276 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002277 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002278 Bugs: ProtocolBugs{
2279 SendV2ClientHello: true,
2280 },
2281 },
2282 sendPrefix: string([]byte{
2283 byte(recordTypeAlert),
2284 3, 1, // version
2285 0, 2, // length
2286 alertLevelWarning, byte(alertDecompressionFailure),
2287 }),
2288 // A no-op warning alert may not be sent before V2ClientHello.
2289 shouldFail: true,
2290 expectedError: ":WRONG_VERSION_NUMBER:",
2291 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002292 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002293 name: "KeyUpdate-Client",
2294 config: Config{
2295 MaxVersion: VersionTLS13,
2296 },
2297 sendKeyUpdates: 1,
2298 keyUpdateRequest: keyUpdateNotRequested,
2299 },
2300 {
2301 testType: serverTest,
2302 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002303 config: Config{
2304 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002305 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002306 sendKeyUpdates: 1,
2307 keyUpdateRequest: keyUpdateNotRequested,
2308 },
2309 {
2310 name: "KeyUpdate-InvalidRequestMode",
2311 config: Config{
2312 MaxVersion: VersionTLS13,
2313 },
2314 sendKeyUpdates: 1,
2315 keyUpdateRequest: 42,
2316 shouldFail: true,
2317 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002318 },
David Benjaminabe94e32016-09-04 14:18:58 -04002319 {
2320 name: "SendSNIWarningAlert",
2321 config: Config{
2322 MaxVersion: VersionTLS12,
2323 Bugs: ProtocolBugs{
2324 SendSNIWarningAlert: true,
2325 },
2326 },
2327 },
David Benjaminc241d792016-09-09 10:34:20 -04002328 {
2329 testType: serverTest,
2330 name: "ExtraCompressionMethods-TLS12",
2331 config: Config{
2332 MaxVersion: VersionTLS12,
2333 Bugs: ProtocolBugs{
2334 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2335 },
2336 },
2337 },
2338 {
2339 testType: serverTest,
2340 name: "ExtraCompressionMethods-TLS13",
2341 config: Config{
2342 MaxVersion: VersionTLS13,
2343 Bugs: ProtocolBugs{
2344 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2345 },
2346 },
2347 shouldFail: true,
2348 expectedError: ":INVALID_COMPRESSION_LIST:",
2349 expectedLocalError: "remote error: illegal parameter",
2350 },
2351 {
2352 testType: serverTest,
2353 name: "NoNullCompression-TLS12",
2354 config: Config{
2355 MaxVersion: VersionTLS12,
2356 Bugs: ProtocolBugs{
2357 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2358 },
2359 },
2360 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002361 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002362 expectedLocalError: "remote error: illegal parameter",
2363 },
2364 {
2365 testType: serverTest,
2366 name: "NoNullCompression-TLS13",
2367 config: Config{
2368 MaxVersion: VersionTLS13,
2369 Bugs: ProtocolBugs{
2370 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2371 },
2372 },
2373 shouldFail: true,
2374 expectedError: ":INVALID_COMPRESSION_LIST:",
2375 expectedLocalError: "remote error: illegal parameter",
2376 },
David Benjamin65ac9972016-09-02 21:35:25 -04002377 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002378 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002379 config: Config{
2380 MaxVersion: VersionTLS12,
2381 Bugs: ProtocolBugs{
2382 ExpectGREASE: true,
2383 },
2384 },
2385 flags: []string{"-enable-grease"},
2386 },
2387 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002388 name: "GREASE-Client-TLS13",
2389 config: Config{
2390 MaxVersion: VersionTLS13,
2391 Bugs: ProtocolBugs{
2392 ExpectGREASE: true,
2393 },
2394 },
2395 flags: []string{"-enable-grease"},
2396 },
2397 {
2398 testType: serverTest,
2399 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002400 config: Config{
2401 MaxVersion: VersionTLS13,
2402 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002403 // TLS 1.3 servers are expected to
2404 // always enable GREASE. TLS 1.3 is new,
2405 // so there is no existing ecosystem to
2406 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002407 ExpectGREASE: true,
2408 },
2409 },
David Benjamin65ac9972016-09-02 21:35:25 -04002410 },
David Benjamine3fbb362017-01-06 16:19:28 -05002411 {
2412 // Test the server so there is a large certificate as
2413 // well as application data.
2414 testType: serverTest,
2415 name: "MaxSendFragment",
2416 config: Config{
2417 Bugs: ProtocolBugs{
2418 MaxReceivePlaintext: 512,
2419 },
2420 },
2421 messageLen: 1024,
2422 flags: []string{
2423 "-max-send-fragment", "512",
2424 "-read-size", "1024",
2425 },
2426 },
2427 {
2428 // Test the server so there is a large certificate as
2429 // well as application data.
2430 testType: serverTest,
2431 name: "MaxSendFragment-TooLarge",
2432 config: Config{
2433 Bugs: ProtocolBugs{
2434 // Ensure that some of the records are
2435 // 512.
2436 MaxReceivePlaintext: 511,
2437 },
2438 },
2439 messageLen: 1024,
2440 flags: []string{
2441 "-max-send-fragment", "512",
2442 "-read-size", "1024",
2443 },
2444 shouldFail: true,
2445 expectedLocalError: "local error: record overflow",
2446 },
Adam Langley7c803a62015-06-15 15:35:05 -07002447 }
Adam Langley7c803a62015-06-15 15:35:05 -07002448 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002449
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002450 if *includeDHE {
2451 testCases = append(testCases, testCase{
2452 name: "NoFalseStart-DHE_RSA",
2453 config: Config{
2454 MaxVersion: VersionTLS12,
2455 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2456 NextProtos: []string{"foo"},
2457 Bugs: ProtocolBugs{
2458 ExpectFalseStart: true,
2459 AlertBeforeFalseStartTest: alertAccessDenied,
2460 },
2461 },
2462 flags: []string{
2463 "-false-start",
2464 "-advertise-alpn", "\x03foo",
2465 },
2466 shimWritesFirst: true,
2467 shouldFail: true,
2468 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2469 expectedLocalError: "tls: peer did not false start: EOF",
2470 })
2471 }
2472
David Benjamina252b342016-09-26 19:57:53 -04002473 // Test that very large messages can be received.
2474 cert := rsaCertificate
2475 for i := 0; i < 50; i++ {
2476 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2477 }
2478 testCases = append(testCases, testCase{
2479 name: "LargeMessage",
2480 config: Config{
2481 Certificates: []Certificate{cert},
2482 },
2483 })
2484 testCases = append(testCases, testCase{
2485 protocol: dtls,
2486 name: "LargeMessage-DTLS",
2487 config: Config{
2488 Certificates: []Certificate{cert},
2489 },
2490 })
2491
2492 // They are rejected if the maximum certificate chain length is capped.
2493 testCases = append(testCases, testCase{
2494 name: "LargeMessage-Reject",
2495 config: Config{
2496 Certificates: []Certificate{cert},
2497 },
2498 flags: []string{"-max-cert-list", "16384"},
2499 shouldFail: true,
2500 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2501 })
2502 testCases = append(testCases, testCase{
2503 protocol: dtls,
2504 name: "LargeMessage-Reject-DTLS",
2505 config: Config{
2506 Certificates: []Certificate{cert},
2507 },
2508 flags: []string{"-max-cert-list", "16384"},
2509 shouldFail: true,
2510 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2511 })
Adam Langley7c803a62015-06-15 15:35:05 -07002512}
2513
David Benjaminaa012042016-12-10 13:33:05 -05002514func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2515 const psk = "12345"
2516 const pskIdentity = "luggage combo"
2517
2518 var prefix string
2519 if protocol == dtls {
2520 if !ver.hasDTLS {
2521 return
2522 }
2523 prefix = "D"
2524 }
2525
2526 var cert Certificate
2527 var certFile string
2528 var keyFile string
2529 if hasComponent(suite.name, "ECDSA") {
2530 cert = ecdsaP256Certificate
2531 certFile = ecdsaP256CertificateFile
2532 keyFile = ecdsaP256KeyFile
2533 } else {
2534 cert = rsaCertificate
2535 certFile = rsaCertificateFile
2536 keyFile = rsaKeyFile
2537 }
2538
2539 var flags []string
2540 if hasComponent(suite.name, "PSK") {
2541 flags = append(flags,
2542 "-psk", psk,
2543 "-psk-identity", pskIdentity)
2544 }
2545 if hasComponent(suite.name, "NULL") {
2546 // NULL ciphers must be explicitly enabled.
2547 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2548 }
David Benjaminaa012042016-12-10 13:33:05 -05002549
2550 var shouldServerFail, shouldClientFail bool
2551 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2552 // BoringSSL clients accept ECDHE on SSLv3, but
2553 // a BoringSSL server will never select it
2554 // because the extension is missing.
2555 shouldServerFail = true
2556 }
2557 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2558 shouldClientFail = true
2559 shouldServerFail = true
2560 }
2561 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2562 shouldClientFail = true
2563 shouldServerFail = true
2564 }
2565 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2566 shouldClientFail = true
2567 shouldServerFail = true
2568 }
2569 if !isDTLSCipher(suite.name) && protocol == dtls {
2570 shouldClientFail = true
2571 shouldServerFail = true
2572 }
2573
2574 var sendCipherSuite uint16
2575 var expectedServerError, expectedClientError string
2576 serverCipherSuites := []uint16{suite.id}
2577 if shouldServerFail {
2578 expectedServerError = ":NO_SHARED_CIPHER:"
2579 }
2580 if shouldClientFail {
2581 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2582 // Configure the server to select ciphers as normal but
2583 // select an incompatible cipher in ServerHello.
2584 serverCipherSuites = nil
2585 sendCipherSuite = suite.id
2586 }
2587
David Benjamincdb6fe92017-02-07 16:06:48 -05002588 // For cipher suites and versions where exporters are defined, verify
2589 // that they interoperate.
2590 var exportKeyingMaterial int
2591 if ver.version > VersionSSL30 {
2592 exportKeyingMaterial = 1024
2593 }
2594
David Benjaminaa012042016-12-10 13:33:05 -05002595 testCases = append(testCases, testCase{
2596 testType: serverTest,
2597 protocol: protocol,
2598 name: prefix + ver.name + "-" + suite.name + "-server",
2599 config: Config{
2600 MinVersion: ver.version,
2601 MaxVersion: ver.version,
2602 CipherSuites: []uint16{suite.id},
2603 Certificates: []Certificate{cert},
2604 PreSharedKey: []byte(psk),
2605 PreSharedKeyIdentity: pskIdentity,
2606 Bugs: ProtocolBugs{
2607 AdvertiseAllConfiguredCiphers: true,
2608 },
2609 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002610 certFile: certFile,
2611 keyFile: keyFile,
2612 flags: flags,
2613 resumeSession: true,
2614 shouldFail: shouldServerFail,
2615 expectedError: expectedServerError,
2616 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002617 })
2618
2619 testCases = append(testCases, testCase{
2620 testType: clientTest,
2621 protocol: protocol,
2622 name: prefix + ver.name + "-" + suite.name + "-client",
2623 config: Config{
2624 MinVersion: ver.version,
2625 MaxVersion: ver.version,
2626 CipherSuites: serverCipherSuites,
2627 Certificates: []Certificate{cert},
2628 PreSharedKey: []byte(psk),
2629 PreSharedKeyIdentity: pskIdentity,
2630 Bugs: ProtocolBugs{
2631 IgnorePeerCipherPreferences: shouldClientFail,
2632 SendCipherSuite: sendCipherSuite,
2633 },
2634 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002635 flags: flags,
2636 resumeSession: true,
2637 shouldFail: shouldClientFail,
2638 expectedError: expectedClientError,
2639 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002640 })
2641
David Benjamin6f600d62016-12-21 16:06:54 -05002642 if shouldClientFail {
2643 return
2644 }
2645
2646 // Ensure the maximum record size is accepted.
2647 testCases = append(testCases, testCase{
2648 protocol: protocol,
2649 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2650 config: Config{
2651 MinVersion: ver.version,
2652 MaxVersion: ver.version,
2653 CipherSuites: []uint16{suite.id},
2654 Certificates: []Certificate{cert},
2655 PreSharedKey: []byte(psk),
2656 PreSharedKeyIdentity: pskIdentity,
2657 },
2658 flags: flags,
2659 messageLen: maxPlaintext,
2660 })
2661
2662 // Test bad records for all ciphers. Bad records are fatal in TLS
2663 // and ignored in DTLS.
2664 var shouldFail bool
2665 var expectedError string
2666 if protocol == tls {
2667 shouldFail = true
2668 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2669 }
2670
2671 testCases = append(testCases, testCase{
2672 protocol: protocol,
2673 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
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 },
2682 flags: flags,
2683 damageFirstWrite: true,
2684 messageLen: maxPlaintext,
2685 shouldFail: shouldFail,
2686 expectedError: expectedError,
2687 })
David Benjaminaa012042016-12-10 13:33:05 -05002688}
2689
Adam Langley95c29f32014-06-20 12:00:00 -07002690func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002691 const bogusCipher = 0xfe00
2692
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002693 if *includeDHE {
2694 testCipherSuites = append(testCipherSuites, []testCipherSuite{
2695 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2696 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
2697 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
2698 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
2699 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
2700 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
2701 }...)
2702 }
2703
Adam Langley95c29f32014-06-20 12:00:00 -07002704 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002705 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002706 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002707 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002708 }
David Benjamin2c99d282015-09-01 10:23:00 -04002709 }
Adam Langley95c29f32014-06-20 12:00:00 -07002710 }
Adam Langleya7997f12015-05-14 17:38:50 -07002711
2712 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002713 name: "NoSharedCipher",
2714 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002715 MaxVersion: VersionTLS12,
2716 CipherSuites: []uint16{},
2717 },
2718 shouldFail: true,
2719 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2720 })
2721
2722 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002723 name: "NoSharedCipher-TLS13",
2724 config: Config{
2725 MaxVersion: VersionTLS13,
2726 CipherSuites: []uint16{},
2727 },
2728 shouldFail: true,
2729 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2730 })
2731
2732 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002733 name: "UnsupportedCipherSuite",
2734 config: Config{
2735 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002736 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002737 Bugs: ProtocolBugs{
2738 IgnorePeerCipherPreferences: true,
2739 },
2740 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002741 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002742 shouldFail: true,
2743 expectedError: ":WRONG_CIPHER_RETURNED:",
2744 })
2745
2746 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002747 name: "ServerHelloBogusCipher",
2748 config: Config{
2749 MaxVersion: VersionTLS12,
2750 Bugs: ProtocolBugs{
2751 SendCipherSuite: bogusCipher,
2752 },
2753 },
2754 shouldFail: true,
2755 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2756 })
2757 testCases = append(testCases, testCase{
2758 name: "ServerHelloBogusCipher-TLS13",
2759 config: Config{
2760 MaxVersion: VersionTLS13,
2761 Bugs: ProtocolBugs{
2762 SendCipherSuite: bogusCipher,
2763 },
2764 },
2765 shouldFail: true,
2766 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2767 })
2768
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002769 if *includeDHE {
2770 testCases = append(testCases, testCase{
2771 name: "WeakDH",
2772 config: Config{
2773 MaxVersion: VersionTLS12,
2774 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2775 Bugs: ProtocolBugs{
2776 // This is a 1023-bit prime number, generated
2777 // with:
2778 // openssl gendh 1023 | openssl asn1parse -i
2779 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2780 },
Adam Langleya7997f12015-05-14 17:38:50 -07002781 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002782 shouldFail: true,
2783 expectedError: ":BAD_DH_P_LENGTH:",
2784 })
Adam Langleycef75832015-09-03 14:51:12 -07002785
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002786 testCases = append(testCases, testCase{
2787 name: "SillyDH",
2788 config: Config{
2789 MaxVersion: VersionTLS12,
2790 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2791 Bugs: ProtocolBugs{
2792 // This is a 4097-bit prime number, generated
2793 // with:
2794 // openssl gendh 4097 | openssl asn1parse -i
2795 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2796 },
David Benjamincd24a392015-11-11 13:23:05 -08002797 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002798 shouldFail: true,
2799 expectedError: ":DH_P_TOO_LONG:",
2800 })
David Benjamincd24a392015-11-11 13:23:05 -08002801
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002802 // This test ensures that Diffie-Hellman public values are padded with
2803 // zeros so that they're the same length as the prime. This is to avoid
2804 // hitting a bug in yaSSL.
2805 testCases = append(testCases, testCase{
2806 testType: serverTest,
2807 name: "DHPublicValuePadded",
2808 config: Config{
2809 MaxVersion: VersionTLS12,
2810 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2811 Bugs: ProtocolBugs{
2812 RequireDHPublicValueLen: (1025 + 7) / 8,
2813 },
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002814 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002815 flags: []string{"-use-sparse-dh-prime"},
2816 })
2817 }
David Benjamincd24a392015-11-11 13:23:05 -08002818
David Benjamin241ae832016-01-15 03:04:54 -05002819 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002820 testCases = append(testCases, testCase{
2821 testType: serverTest,
2822 name: "UnknownCipher",
2823 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002824 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002825 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002826 Bugs: ProtocolBugs{
2827 AdvertiseAllConfiguredCiphers: true,
2828 },
2829 },
2830 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002831
2832 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002833 testCases = append(testCases, testCase{
2834 testType: serverTest,
2835 name: "UnknownCipher-TLS13",
2836 config: Config{
2837 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002838 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002839 Bugs: ProtocolBugs{
2840 AdvertiseAllConfiguredCiphers: true,
2841 },
David Benjamin241ae832016-01-15 03:04:54 -05002842 },
2843 })
2844
David Benjamin78679342016-09-16 19:42:05 -04002845 // Test empty ECDHE_PSK identity hints work as expected.
2846 testCases = append(testCases, testCase{
2847 name: "EmptyECDHEPSKHint",
2848 config: Config{
2849 MaxVersion: VersionTLS12,
2850 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2851 PreSharedKey: []byte("secret"),
2852 },
2853 flags: []string{"-psk", "secret"},
2854 })
2855
2856 // Test empty PSK identity hints work as expected, even if an explicit
2857 // ServerKeyExchange is sent.
2858 testCases = append(testCases, testCase{
2859 name: "ExplicitEmptyPSKHint",
2860 config: Config{
2861 MaxVersion: VersionTLS12,
2862 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2863 PreSharedKey: []byte("secret"),
2864 Bugs: ProtocolBugs{
2865 AlwaysSendPreSharedKeyIdentityHint: true,
2866 },
2867 },
2868 flags: []string{"-psk", "secret"},
2869 })
Adam Langley95c29f32014-06-20 12:00:00 -07002870}
2871
2872func addBadECDSASignatureTests() {
2873 for badR := BadValue(1); badR < NumBadValues; badR++ {
2874 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002875 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002876 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2877 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002878 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002879 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002880 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002881 Bugs: ProtocolBugs{
2882 BadECDSAR: badR,
2883 BadECDSAS: badS,
2884 },
2885 },
2886 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002887 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002888 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002889 testCases = append(testCases, testCase{
2890 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2891 config: Config{
2892 MaxVersion: VersionTLS13,
2893 Certificates: []Certificate{ecdsaP256Certificate},
2894 Bugs: ProtocolBugs{
2895 BadECDSAR: badR,
2896 BadECDSAS: badS,
2897 },
2898 },
2899 shouldFail: true,
2900 expectedError: ":BAD_SIGNATURE:",
2901 })
Adam Langley95c29f32014-06-20 12:00:00 -07002902 }
2903 }
2904}
2905
Adam Langley80842bd2014-06-20 12:00:00 -07002906func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002907 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002908 name: "MaxCBCPadding",
2909 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002910 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002911 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2912 Bugs: ProtocolBugs{
2913 MaxPadding: true,
2914 },
2915 },
2916 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2917 })
David Benjamin025b3d32014-07-01 19:53:04 -04002918 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002919 name: "BadCBCPadding",
2920 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002921 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2923 Bugs: ProtocolBugs{
2924 PaddingFirstByteBad: true,
2925 },
2926 },
2927 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002928 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002929 })
2930 // OpenSSL previously had an issue where the first byte of padding in
2931 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002932 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002933 name: "BadCBCPadding255",
2934 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002935 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2937 Bugs: ProtocolBugs{
2938 MaxPadding: true,
2939 PaddingFirstByteBadIf255: true,
2940 },
2941 },
2942 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2943 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002944 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002945 })
2946}
2947
Kenny Root7fdeaf12014-08-05 15:23:37 -07002948func addCBCSplittingTests() {
2949 testCases = append(testCases, testCase{
2950 name: "CBCRecordSplitting",
2951 config: Config{
2952 MaxVersion: VersionTLS10,
2953 MinVersion: VersionTLS10,
2954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2955 },
David Benjaminac8302a2015-09-01 17:18:15 -04002956 messageLen: -1, // read until EOF
2957 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002958 flags: []string{
2959 "-async",
2960 "-write-different-record-sizes",
2961 "-cbc-record-splitting",
2962 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002963 })
2964 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002965 name: "CBCRecordSplittingPartialWrite",
2966 config: Config{
2967 MaxVersion: VersionTLS10,
2968 MinVersion: VersionTLS10,
2969 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2970 },
2971 messageLen: -1, // read until EOF
2972 flags: []string{
2973 "-async",
2974 "-write-different-record-sizes",
2975 "-cbc-record-splitting",
2976 "-partial-write",
2977 },
2978 })
2979}
2980
David Benjamin636293b2014-07-08 17:59:18 -04002981func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002982 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04002983 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08002984 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
2985 cert, err := x509.ParseCertificate(cert.Certificate[0])
2986 if err != nil {
2987 panic(err)
2988 }
2989 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04002990 }
Adam Langley2ff79332017-02-28 13:45:39 -08002991 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04002992
David Benjamin636293b2014-07-08 17:59:18 -04002993 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002994 testCases = append(testCases, testCase{
2995 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002996 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002997 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002998 MinVersion: ver.version,
2999 MaxVersion: ver.version,
3000 ClientAuth: RequireAnyClientCert,
3001 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003002 },
3003 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003004 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3005 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003006 },
3007 })
3008 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003009 testType: serverTest,
3010 name: ver.name + "-Server-ClientAuth-RSA",
3011 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003012 MinVersion: ver.version,
3013 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003014 Certificates: []Certificate{rsaCertificate},
3015 },
3016 flags: []string{"-require-any-client-certificate"},
3017 })
David Benjamine098ec22014-08-27 23:13:20 -04003018 if ver.version != VersionSSL30 {
3019 testCases = append(testCases, testCase{
3020 testType: serverTest,
3021 name: ver.name + "-Server-ClientAuth-ECDSA",
3022 config: Config{
3023 MinVersion: ver.version,
3024 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003025 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003026 },
3027 flags: []string{"-require-any-client-certificate"},
3028 })
3029 testCases = append(testCases, testCase{
3030 testType: clientTest,
3031 name: ver.name + "-Client-ClientAuth-ECDSA",
3032 config: Config{
3033 MinVersion: ver.version,
3034 MaxVersion: ver.version,
3035 ClientAuth: RequireAnyClientCert,
3036 ClientCAs: certPool,
3037 },
3038 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003039 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3040 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003041 },
3042 })
3043 }
Adam Langley37646832016-08-01 16:16:46 -07003044
3045 testCases = append(testCases, testCase{
3046 name: "NoClientCertificate-" + ver.name,
3047 config: Config{
3048 MinVersion: ver.version,
3049 MaxVersion: ver.version,
3050 ClientAuth: RequireAnyClientCert,
3051 },
3052 shouldFail: true,
3053 expectedLocalError: "client didn't provide a certificate",
3054 })
3055
3056 testCases = append(testCases, testCase{
3057 // Even if not configured to expect a certificate, OpenSSL will
3058 // return X509_V_OK as the verify_result.
3059 testType: serverTest,
3060 name: "NoClientCertificateRequested-Server-" + ver.name,
3061 config: Config{
3062 MinVersion: ver.version,
3063 MaxVersion: ver.version,
3064 },
3065 flags: []string{
3066 "-expect-verify-result",
3067 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003068 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003069 })
3070
3071 testCases = append(testCases, testCase{
3072 // If a client certificate is not provided, OpenSSL will still
3073 // return X509_V_OK as the verify_result.
3074 testType: serverTest,
3075 name: "NoClientCertificate-Server-" + ver.name,
3076 config: Config{
3077 MinVersion: ver.version,
3078 MaxVersion: ver.version,
3079 },
3080 flags: []string{
3081 "-expect-verify-result",
3082 "-verify-peer",
3083 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003084 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003085 })
3086
David Benjamin1db9e1b2016-10-07 20:51:43 -04003087 certificateRequired := "remote error: certificate required"
3088 if ver.version < VersionTLS13 {
3089 // Prior to TLS 1.3, the generic handshake_failure alert
3090 // was used.
3091 certificateRequired = "remote error: handshake failure"
3092 }
Adam Langley37646832016-08-01 16:16:46 -07003093 testCases = append(testCases, testCase{
3094 testType: serverTest,
3095 name: "RequireAnyClientCertificate-" + ver.name,
3096 config: Config{
3097 MinVersion: ver.version,
3098 MaxVersion: ver.version,
3099 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003100 flags: []string{"-require-any-client-certificate"},
3101 shouldFail: true,
3102 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3103 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003104 })
3105
3106 if ver.version != VersionSSL30 {
3107 testCases = append(testCases, testCase{
3108 testType: serverTest,
3109 name: "SkipClientCertificate-" + ver.name,
3110 config: Config{
3111 MinVersion: ver.version,
3112 MaxVersion: ver.version,
3113 Bugs: ProtocolBugs{
3114 SkipClientCertificate: true,
3115 },
3116 },
3117 // Setting SSL_VERIFY_PEER allows anonymous clients.
3118 flags: []string{"-verify-peer"},
3119 shouldFail: true,
3120 expectedError: ":UNEXPECTED_MESSAGE:",
3121 })
3122 }
Adam Langley2ff79332017-02-28 13:45:39 -08003123
3124 testCases = append(testCases, testCase{
3125 testType: serverTest,
3126 name: ver.name + "-Server-CertReq-CA-List",
3127 config: Config{
3128 MinVersion: ver.version,
3129 MaxVersion: ver.version,
3130 Certificates: []Certificate{rsaCertificate},
3131 Bugs: ProtocolBugs{
3132 ExpectCertificateReqNames: caNames,
3133 },
3134 },
3135 flags: []string{
3136 "-require-any-client-certificate",
3137 "-use-client-ca-list", encodeDERValues(caNames),
3138 },
3139 })
3140
3141 testCases = append(testCases, testCase{
3142 testType: clientTest,
3143 name: ver.name + "-Client-CertReq-CA-List",
3144 config: Config{
3145 MinVersion: ver.version,
3146 MaxVersion: ver.version,
3147 Certificates: []Certificate{rsaCertificate},
3148 ClientAuth: RequireAnyClientCert,
3149 ClientCAs: certPool,
3150 },
3151 flags: []string{
3152 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3153 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3154 "-expect-client-ca-list", encodeDERValues(caNames),
3155 },
3156 })
David Benjamin636293b2014-07-08 17:59:18 -04003157 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003158
David Benjaminc032dfa2016-05-12 14:54:57 -04003159 // Client auth is only legal in certificate-based ciphers.
3160 testCases = append(testCases, testCase{
3161 testType: clientTest,
3162 name: "ClientAuth-PSK",
3163 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003164 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003165 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3166 PreSharedKey: []byte("secret"),
3167 ClientAuth: RequireAnyClientCert,
3168 },
3169 flags: []string{
3170 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3171 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3172 "-psk", "secret",
3173 },
3174 shouldFail: true,
3175 expectedError: ":UNEXPECTED_MESSAGE:",
3176 })
3177 testCases = append(testCases, testCase{
3178 testType: clientTest,
3179 name: "ClientAuth-ECDHE_PSK",
3180 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003181 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003182 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3183 PreSharedKey: []byte("secret"),
3184 ClientAuth: RequireAnyClientCert,
3185 },
3186 flags: []string{
3187 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3188 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3189 "-psk", "secret",
3190 },
3191 shouldFail: true,
3192 expectedError: ":UNEXPECTED_MESSAGE:",
3193 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003194
3195 // Regression test for a bug where the client CA list, if explicitly
3196 // set to NULL, was mis-encoded.
3197 testCases = append(testCases, testCase{
3198 testType: serverTest,
3199 name: "Null-Client-CA-List",
3200 config: Config{
3201 MaxVersion: VersionTLS12,
3202 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003203 Bugs: ProtocolBugs{
3204 ExpectCertificateReqNames: [][]byte{},
3205 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003206 },
3207 flags: []string{
3208 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003209 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003210 },
3211 })
David Benjamin636293b2014-07-08 17:59:18 -04003212}
3213
Adam Langley75712922014-10-10 16:23:43 -07003214func addExtendedMasterSecretTests() {
3215 const expectEMSFlag = "-expect-extended-master-secret"
3216
3217 for _, with := range []bool{false, true} {
3218 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003219 if with {
3220 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003221 }
3222
3223 for _, isClient := range []bool{false, true} {
3224 suffix := "-Server"
3225 testType := serverTest
3226 if isClient {
3227 suffix = "-Client"
3228 testType = clientTest
3229 }
3230
3231 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003232 // In TLS 1.3, the extension is irrelevant and
3233 // always reports as enabled.
3234 var flags []string
3235 if with || ver.version >= VersionTLS13 {
3236 flags = []string{expectEMSFlag}
3237 }
3238
Adam Langley75712922014-10-10 16:23:43 -07003239 test := testCase{
3240 testType: testType,
3241 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3242 config: Config{
3243 MinVersion: ver.version,
3244 MaxVersion: ver.version,
3245 Bugs: ProtocolBugs{
3246 NoExtendedMasterSecret: !with,
3247 RequireExtendedMasterSecret: with,
3248 },
3249 },
David Benjamin48cae082014-10-27 01:06:24 -04003250 flags: flags,
3251 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003252 }
3253 if test.shouldFail {
3254 test.expectedLocalError = "extended master secret required but not supported by peer"
3255 }
3256 testCases = append(testCases, test)
3257 }
3258 }
3259 }
3260
Adam Langleyba5934b2015-06-02 10:50:35 -07003261 for _, isClient := range []bool{false, true} {
3262 for _, supportedInFirstConnection := range []bool{false, true} {
3263 for _, supportedInResumeConnection := range []bool{false, true} {
3264 boolToWord := func(b bool) string {
3265 if b {
3266 return "Yes"
3267 }
3268 return "No"
3269 }
3270 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3271 if isClient {
3272 suffix += "Client"
3273 } else {
3274 suffix += "Server"
3275 }
3276
3277 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003278 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003279 Bugs: ProtocolBugs{
3280 RequireExtendedMasterSecret: true,
3281 },
3282 }
3283
3284 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003285 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003286 Bugs: ProtocolBugs{
3287 NoExtendedMasterSecret: true,
3288 },
3289 }
3290
3291 test := testCase{
3292 name: "ExtendedMasterSecret-" + suffix,
3293 resumeSession: true,
3294 }
3295
3296 if !isClient {
3297 test.testType = serverTest
3298 }
3299
3300 if supportedInFirstConnection {
3301 test.config = supportedConfig
3302 } else {
3303 test.config = noSupportConfig
3304 }
3305
3306 if supportedInResumeConnection {
3307 test.resumeConfig = &supportedConfig
3308 } else {
3309 test.resumeConfig = &noSupportConfig
3310 }
3311
3312 switch suffix {
3313 case "YesToYes-Client", "YesToYes-Server":
3314 // When a session is resumed, it should
3315 // still be aware that its master
3316 // secret was generated via EMS and
3317 // thus it's safe to use tls-unique.
3318 test.flags = []string{expectEMSFlag}
3319 case "NoToYes-Server":
3320 // If an original connection did not
3321 // contain EMS, but a resumption
3322 // handshake does, then a server should
3323 // not resume the session.
3324 test.expectResumeRejected = true
3325 case "YesToNo-Server":
3326 // Resuming an EMS session without the
3327 // EMS extension should cause the
3328 // server to abort the connection.
3329 test.shouldFail = true
3330 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3331 case "NoToYes-Client":
3332 // A client should abort a connection
3333 // where the server resumed a non-EMS
3334 // session but echoed the EMS
3335 // extension.
3336 test.shouldFail = true
3337 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3338 case "YesToNo-Client":
3339 // A client should abort a connection
3340 // where the server didn't echo EMS
3341 // when the session used it.
3342 test.shouldFail = true
3343 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3344 }
3345
3346 testCases = append(testCases, test)
3347 }
3348 }
3349 }
David Benjamin163c9562016-08-29 23:14:17 -04003350
3351 // Switching EMS on renegotiation is forbidden.
3352 testCases = append(testCases, testCase{
3353 name: "ExtendedMasterSecret-Renego-NoEMS",
3354 config: Config{
3355 MaxVersion: VersionTLS12,
3356 Bugs: ProtocolBugs{
3357 NoExtendedMasterSecret: true,
3358 NoExtendedMasterSecretOnRenegotiation: true,
3359 },
3360 },
3361 renegotiate: 1,
3362 flags: []string{
3363 "-renegotiate-freely",
3364 "-expect-total-renegotiations", "1",
3365 },
3366 })
3367
3368 testCases = append(testCases, testCase{
3369 name: "ExtendedMasterSecret-Renego-Upgrade",
3370 config: Config{
3371 MaxVersion: VersionTLS12,
3372 Bugs: ProtocolBugs{
3373 NoExtendedMasterSecret: true,
3374 },
3375 },
3376 renegotiate: 1,
3377 flags: []string{
3378 "-renegotiate-freely",
3379 "-expect-total-renegotiations", "1",
3380 },
3381 shouldFail: true,
3382 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3383 })
3384
3385 testCases = append(testCases, testCase{
3386 name: "ExtendedMasterSecret-Renego-Downgrade",
3387 config: Config{
3388 MaxVersion: VersionTLS12,
3389 Bugs: ProtocolBugs{
3390 NoExtendedMasterSecretOnRenegotiation: true,
3391 },
3392 },
3393 renegotiate: 1,
3394 flags: []string{
3395 "-renegotiate-freely",
3396 "-expect-total-renegotiations", "1",
3397 },
3398 shouldFail: true,
3399 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3400 })
Adam Langley75712922014-10-10 16:23:43 -07003401}
3402
David Benjamin582ba042016-07-07 12:33:25 -07003403type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003404 protocol protocol
3405 async bool
3406 splitHandshake bool
3407 packHandshakeFlight bool
3408 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003409}
3410
David Benjamin43ec06f2014-08-05 02:28:57 -04003411// Adds tests that try to cover the range of the handshake state machine, under
3412// various conditions. Some of these are redundant with other tests, but they
3413// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003414func addAllStateMachineCoverageTests() {
3415 for _, async := range []bool{false, true} {
3416 for _, protocol := range []protocol{tls, dtls} {
3417 addStateMachineCoverageTests(stateMachineTestConfig{
3418 protocol: protocol,
3419 async: async,
3420 })
3421 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003422 protocol: protocol,
3423 async: async,
3424 implicitHandshake: true,
3425 })
3426 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003427 protocol: protocol,
3428 async: async,
3429 splitHandshake: true,
3430 })
3431 if protocol == tls {
3432 addStateMachineCoverageTests(stateMachineTestConfig{
3433 protocol: protocol,
3434 async: async,
3435 packHandshakeFlight: true,
3436 })
3437 }
3438 }
3439 }
3440}
3441
3442func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003443 var tests []testCase
3444
3445 // Basic handshake, with resumption. Client and server,
3446 // session ID and session ticket.
3447 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003448 name: "Basic-Client",
3449 config: Config{
3450 MaxVersion: VersionTLS12,
3451 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003452 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003453 // Ensure session tickets are used, not session IDs.
3454 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003455 })
3456 tests = append(tests, testCase{
3457 name: "Basic-Client-RenewTicket",
3458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003459 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003460 Bugs: ProtocolBugs{
3461 RenewTicketOnResume: true,
3462 },
3463 },
David Benjamin46662482016-08-17 00:51:00 -04003464 flags: []string{"-expect-ticket-renewal"},
3465 resumeSession: true,
3466 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003467 })
3468 tests = append(tests, testCase{
3469 name: "Basic-Client-NoTicket",
3470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003471 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003472 SessionTicketsDisabled: true,
3473 },
3474 resumeSession: true,
3475 })
3476 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003477 testType: serverTest,
3478 name: "Basic-Server",
3479 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003480 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003481 Bugs: ProtocolBugs{
3482 RequireSessionTickets: true,
3483 },
3484 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003485 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003486 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 })
3488 tests = append(tests, testCase{
3489 testType: serverTest,
3490 name: "Basic-Server-NoTickets",
3491 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003492 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003493 SessionTicketsDisabled: true,
3494 },
3495 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003496 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003497 })
3498 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003499 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003500 name: "Basic-Server-EarlyCallback",
3501 config: Config{
3502 MaxVersion: VersionTLS12,
3503 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 flags: []string{"-use-early-callback"},
3505 resumeSession: true,
3506 })
3507
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003509 if config.protocol == tls {
3510 tests = append(tests, testCase{
3511 name: "TLS13-1RTT-Client",
3512 config: Config{
3513 MaxVersion: VersionTLS13,
3514 MinVersion: VersionTLS13,
3515 },
David Benjamin46662482016-08-17 00:51:00 -04003516 resumeSession: true,
3517 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003518 })
3519
3520 tests = append(tests, testCase{
3521 testType: serverTest,
3522 name: "TLS13-1RTT-Server",
3523 config: Config{
3524 MaxVersion: VersionTLS13,
3525 MinVersion: VersionTLS13,
3526 },
David Benjamin46662482016-08-17 00:51:00 -04003527 resumeSession: true,
3528 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003529 // TLS 1.3 uses tickets, so the session should not be
3530 // cached statefully.
3531 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003532 })
3533
3534 tests = append(tests, testCase{
3535 name: "TLS13-HelloRetryRequest-Client",
3536 config: Config{
3537 MaxVersion: VersionTLS13,
3538 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003539 // P-384 requires a HelloRetryRequest against BoringSSL's default
3540 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003541 CurvePreferences: []CurveID{CurveP384},
3542 Bugs: ProtocolBugs{
3543 ExpectMissingKeyShare: true,
3544 },
3545 },
3546 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3547 resumeSession: true,
3548 })
3549
3550 tests = append(tests, testCase{
3551 testType: serverTest,
3552 name: "TLS13-HelloRetryRequest-Server",
3553 config: Config{
3554 MaxVersion: VersionTLS13,
3555 MinVersion: VersionTLS13,
3556 // Require a HelloRetryRequest for every curve.
3557 DefaultCurves: []CurveID{},
3558 },
3559 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3560 resumeSession: true,
3561 })
Steven Valdez2d850622017-01-11 11:34:52 -05003562
3563 // TODO(svaldez): Send data on early data once implemented.
3564 tests = append(tests, testCase{
3565 testType: clientTest,
3566 name: "TLS13-EarlyData-Client",
3567 config: Config{
3568 MaxVersion: VersionTLS13,
3569 MinVersion: VersionTLS13,
3570 MaxEarlyDataSize: 16384,
3571 },
3572 resumeSession: true,
3573 flags: []string{
3574 "-enable-early-data",
3575 "-expect-early-data-info",
3576 "-expect-accept-early-data",
3577 },
3578 })
3579
3580 tests = append(tests, testCase{
3581 testType: serverTest,
3582 name: "TLS13-EarlyData-Server",
3583 config: Config{
3584 MaxVersion: VersionTLS13,
3585 MinVersion: VersionTLS13,
3586 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003587 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003588 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003589 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003590 },
3591 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003592 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003593 resumeSession: true,
3594 flags: []string{
3595 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003596 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003597 },
3598 })
David Benjamine73c7f42016-08-17 00:29:33 -04003599 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003600
David Benjamin760b1dd2015-05-15 23:33:48 -04003601 // TLS client auth.
3602 tests = append(tests, testCase{
3603 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003604 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003605 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003606 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003607 ClientAuth: RequestClientCert,
3608 },
3609 })
3610 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003611 testType: serverTest,
3612 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003613 config: Config{
3614 MaxVersion: VersionTLS12,
3615 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003616 // Setting SSL_VERIFY_PEER allows anonymous clients.
3617 flags: []string{"-verify-peer"},
3618 })
David Benjamin582ba042016-07-07 12:33:25 -07003619 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003620 tests = append(tests, testCase{
3621 testType: clientTest,
3622 name: "ClientAuth-NoCertificate-Client-SSL3",
3623 config: Config{
3624 MaxVersion: VersionSSL30,
3625 ClientAuth: RequestClientCert,
3626 },
3627 })
3628 tests = append(tests, testCase{
3629 testType: serverTest,
3630 name: "ClientAuth-NoCertificate-Server-SSL3",
3631 config: Config{
3632 MaxVersion: VersionSSL30,
3633 },
3634 // Setting SSL_VERIFY_PEER allows anonymous clients.
3635 flags: []string{"-verify-peer"},
3636 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003637 tests = append(tests, testCase{
3638 testType: clientTest,
3639 name: "ClientAuth-NoCertificate-Client-TLS13",
3640 config: Config{
3641 MaxVersion: VersionTLS13,
3642 ClientAuth: RequestClientCert,
3643 },
3644 })
3645 tests = append(tests, testCase{
3646 testType: serverTest,
3647 name: "ClientAuth-NoCertificate-Server-TLS13",
3648 config: Config{
3649 MaxVersion: VersionTLS13,
3650 },
3651 // Setting SSL_VERIFY_PEER allows anonymous clients.
3652 flags: []string{"-verify-peer"},
3653 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003654 }
3655 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003656 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003657 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003659 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003660 ClientAuth: RequireAnyClientCert,
3661 },
3662 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003663 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3664 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003665 },
3666 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003667 tests = append(tests, testCase{
3668 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003669 name: "ClientAuth-RSA-Client-TLS13",
3670 config: Config{
3671 MaxVersion: VersionTLS13,
3672 ClientAuth: RequireAnyClientCert,
3673 },
3674 flags: []string{
3675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3677 },
3678 })
3679 tests = append(tests, testCase{
3680 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003681 name: "ClientAuth-ECDSA-Client",
3682 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003683 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003684 ClientAuth: RequireAnyClientCert,
3685 },
3686 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003687 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3688 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003689 },
3690 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003691 tests = append(tests, testCase{
3692 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003693 name: "ClientAuth-ECDSA-Client-TLS13",
3694 config: Config{
3695 MaxVersion: VersionTLS13,
3696 ClientAuth: RequireAnyClientCert,
3697 },
3698 flags: []string{
3699 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3700 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3701 },
3702 })
3703 tests = append(tests, testCase{
3704 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003705 name: "ClientAuth-NoCertificate-OldCallback",
3706 config: Config{
3707 MaxVersion: VersionTLS12,
3708 ClientAuth: RequestClientCert,
3709 },
3710 flags: []string{"-use-old-client-cert-callback"},
3711 })
3712 tests = append(tests, testCase{
3713 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003714 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3715 config: Config{
3716 MaxVersion: VersionTLS13,
3717 ClientAuth: RequestClientCert,
3718 },
3719 flags: []string{"-use-old-client-cert-callback"},
3720 })
3721 tests = append(tests, testCase{
3722 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003723 name: "ClientAuth-OldCallback",
3724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003725 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003726 ClientAuth: RequireAnyClientCert,
3727 },
3728 flags: []string{
3729 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3730 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3731 "-use-old-client-cert-callback",
3732 },
3733 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003735 testType: clientTest,
3736 name: "ClientAuth-OldCallback-TLS13",
3737 config: Config{
3738 MaxVersion: VersionTLS13,
3739 ClientAuth: RequireAnyClientCert,
3740 },
3741 flags: []string{
3742 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3743 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3744 "-use-old-client-cert-callback",
3745 },
3746 })
3747 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003748 testType: serverTest,
3749 name: "ClientAuth-Server",
3750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003751 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003752 Certificates: []Certificate{rsaCertificate},
3753 },
3754 flags: []string{"-require-any-client-certificate"},
3755 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003756 tests = append(tests, testCase{
3757 testType: serverTest,
3758 name: "ClientAuth-Server-TLS13",
3759 config: Config{
3760 MaxVersion: VersionTLS13,
3761 Certificates: []Certificate{rsaCertificate},
3762 },
3763 flags: []string{"-require-any-client-certificate"},
3764 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003765
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003767 tests = append(tests, testCase{
3768 testType: serverTest,
3769 name: "Basic-Server-RSA",
3770 config: Config{
3771 MaxVersion: VersionTLS12,
3772 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3773 },
3774 flags: []string{
3775 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3776 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3777 },
3778 })
3779 tests = append(tests, testCase{
3780 testType: serverTest,
3781 name: "Basic-Server-ECDHE-RSA",
3782 config: Config{
3783 MaxVersion: VersionTLS12,
3784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3785 },
3786 flags: []string{
3787 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3788 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3789 },
3790 })
3791 tests = append(tests, testCase{
3792 testType: serverTest,
3793 name: "Basic-Server-ECDHE-ECDSA",
3794 config: Config{
3795 MaxVersion: VersionTLS12,
3796 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3797 },
3798 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003799 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3800 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003801 },
3802 })
3803
David Benjamin760b1dd2015-05-15 23:33:48 -04003804 // No session ticket support; server doesn't send NewSessionTicket.
3805 tests = append(tests, testCase{
3806 name: "SessionTicketsDisabled-Client",
3807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003808 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003809 SessionTicketsDisabled: true,
3810 },
3811 })
3812 tests = append(tests, testCase{
3813 testType: serverTest,
3814 name: "SessionTicketsDisabled-Server",
3815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003816 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003817 SessionTicketsDisabled: true,
3818 },
3819 })
3820
3821 // Skip ServerKeyExchange in PSK key exchange if there's no
3822 // identity hint.
3823 tests = append(tests, testCase{
3824 name: "EmptyPSKHint-Client",
3825 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003826 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003827 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3828 PreSharedKey: []byte("secret"),
3829 },
3830 flags: []string{"-psk", "secret"},
3831 })
3832 tests = append(tests, testCase{
3833 testType: serverTest,
3834 name: "EmptyPSKHint-Server",
3835 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003836 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003837 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3838 PreSharedKey: []byte("secret"),
3839 },
3840 flags: []string{"-psk", "secret"},
3841 })
3842
David Benjamin4c3ddf72016-06-29 18:13:53 -04003843 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003844 tests = append(tests, testCase{
3845 testType: clientTest,
3846 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003847 config: Config{
3848 MaxVersion: VersionTLS12,
3849 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003850 flags: []string{
3851 "-enable-ocsp-stapling",
3852 "-expect-ocsp-response",
3853 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003854 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003855 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003856 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003857 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003858 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003859 testType: serverTest,
3860 name: "OCSPStapling-Server",
3861 config: Config{
3862 MaxVersion: VersionTLS12,
3863 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003864 expectedOCSPResponse: testOCSPResponse,
3865 flags: []string{
3866 "-ocsp-response",
3867 base64.StdEncoding.EncodeToString(testOCSPResponse),
3868 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003869 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003870 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003871 tests = append(tests, testCase{
3872 testType: clientTest,
3873 name: "OCSPStapling-Client-TLS13",
3874 config: Config{
3875 MaxVersion: VersionTLS13,
3876 },
3877 flags: []string{
3878 "-enable-ocsp-stapling",
3879 "-expect-ocsp-response",
3880 base64.StdEncoding.EncodeToString(testOCSPResponse),
3881 "-verify-peer",
3882 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003883 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003884 })
3885 tests = append(tests, testCase{
3886 testType: serverTest,
3887 name: "OCSPStapling-Server-TLS13",
3888 config: Config{
3889 MaxVersion: VersionTLS13,
3890 },
3891 expectedOCSPResponse: testOCSPResponse,
3892 flags: []string{
3893 "-ocsp-response",
3894 base64.StdEncoding.EncodeToString(testOCSPResponse),
3895 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003896 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003897 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003898
David Benjamin4c3ddf72016-06-29 18:13:53 -04003899 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003900 for _, vers := range tlsVersions {
3901 if config.protocol == dtls && !vers.hasDTLS {
3902 continue
3903 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003904 for _, testType := range []testType{clientTest, serverTest} {
3905 suffix := "-Client"
3906 if testType == serverTest {
3907 suffix = "-Server"
3908 }
3909 suffix += "-" + vers.name
3910
3911 flag := "-verify-peer"
3912 if testType == serverTest {
3913 flag = "-require-any-client-certificate"
3914 }
3915
3916 tests = append(tests, testCase{
3917 testType: testType,
3918 name: "CertificateVerificationSucceed" + suffix,
3919 config: Config{
3920 MaxVersion: vers.version,
3921 Certificates: []Certificate{rsaCertificate},
3922 },
3923 flags: []string{
3924 flag,
3925 "-expect-verify-result",
3926 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003927 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003928 })
3929 tests = append(tests, testCase{
3930 testType: testType,
3931 name: "CertificateVerificationFail" + suffix,
3932 config: Config{
3933 MaxVersion: vers.version,
3934 Certificates: []Certificate{rsaCertificate},
3935 },
3936 flags: []string{
3937 flag,
3938 "-verify-fail",
3939 },
3940 shouldFail: true,
3941 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3942 })
3943 }
3944
3945 // By default, the client is in a soft fail mode where the peer
3946 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003947 tests = append(tests, testCase{
3948 testType: clientTest,
3949 name: "CertificateVerificationSoftFail-" + vers.name,
3950 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003951 MaxVersion: vers.version,
3952 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003953 },
3954 flags: []string{
3955 "-verify-fail",
3956 "-expect-verify-result",
3957 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003958 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003959 })
3960 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003961
David Benjamin1d4f4c02016-07-26 18:03:08 -04003962 tests = append(tests, testCase{
3963 name: "ShimSendAlert",
3964 flags: []string{"-send-alert"},
3965 shimWritesFirst: true,
3966 shouldFail: true,
3967 expectedLocalError: "remote error: decompression failure",
3968 })
3969
David Benjamin582ba042016-07-07 12:33:25 -07003970 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003971 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 name: "Renegotiate-Client",
3973 config: Config{
3974 MaxVersion: VersionTLS12,
3975 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003976 renegotiate: 1,
3977 flags: []string{
3978 "-renegotiate-freely",
3979 "-expect-total-renegotiations", "1",
3980 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003981 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003982
David Benjamin47921102016-07-28 11:29:18 -04003983 tests = append(tests, testCase{
3984 name: "SendHalfHelloRequest",
3985 config: Config{
3986 MaxVersion: VersionTLS12,
3987 Bugs: ProtocolBugs{
3988 PackHelloRequestWithFinished: config.packHandshakeFlight,
3989 },
3990 },
3991 sendHalfHelloRequest: true,
3992 flags: []string{"-renegotiate-ignore"},
3993 shouldFail: true,
3994 expectedError: ":UNEXPECTED_RECORD:",
3995 })
3996
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 // NPN on client and server; results in post-handshake message.
3998 tests = append(tests, testCase{
3999 name: "NPN-Client",
4000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004001 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 NextProtos: []string{"foo"},
4003 },
4004 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004005 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004006 expectedNextProto: "foo",
4007 expectedNextProtoType: npn,
4008 })
4009 tests = append(tests, testCase{
4010 testType: serverTest,
4011 name: "NPN-Server",
4012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004014 NextProtos: []string{"bar"},
4015 },
4016 flags: []string{
4017 "-advertise-npn", "\x03foo\x03bar\x03baz",
4018 "-expect-next-proto", "bar",
4019 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004020 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004021 expectedNextProto: "bar",
4022 expectedNextProtoType: npn,
4023 })
4024
4025 // TODO(davidben): Add tests for when False Start doesn't trigger.
4026
4027 // Client does False Start and negotiates NPN.
4028 tests = append(tests, testCase{
4029 name: "FalseStart",
4030 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004031 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004032 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4033 NextProtos: []string{"foo"},
4034 Bugs: ProtocolBugs{
4035 ExpectFalseStart: true,
4036 },
4037 },
4038 flags: []string{
4039 "-false-start",
4040 "-select-next-proto", "foo",
4041 },
4042 shimWritesFirst: true,
4043 resumeSession: true,
4044 })
4045
4046 // Client does False Start and negotiates ALPN.
4047 tests = append(tests, testCase{
4048 name: "FalseStart-ALPN",
4049 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004050 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4052 NextProtos: []string{"foo"},
4053 Bugs: ProtocolBugs{
4054 ExpectFalseStart: true,
4055 },
4056 },
4057 flags: []string{
4058 "-false-start",
4059 "-advertise-alpn", "\x03foo",
4060 },
4061 shimWritesFirst: true,
4062 resumeSession: true,
4063 })
4064
David Benjamin760b1dd2015-05-15 23:33:48 -04004065 // False Start without session tickets.
4066 tests = append(tests, testCase{
4067 name: "FalseStart-SessionTicketsDisabled",
4068 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004069 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004070 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4071 NextProtos: []string{"foo"},
4072 SessionTicketsDisabled: true,
4073 Bugs: ProtocolBugs{
4074 ExpectFalseStart: true,
4075 },
4076 },
4077 flags: []string{
4078 "-false-start",
4079 "-select-next-proto", "foo",
4080 },
4081 shimWritesFirst: true,
4082 })
4083
4084 // Server parses a V2ClientHello.
4085 tests = append(tests, testCase{
4086 testType: serverTest,
4087 name: "SendV2ClientHello",
4088 config: Config{
4089 // Choose a cipher suite that does not involve
4090 // elliptic curves, so no extensions are
4091 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004092 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004093 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004094 Bugs: ProtocolBugs{
4095 SendV2ClientHello: true,
4096 },
4097 },
4098 })
4099
Nick Harper60a85cb2016-09-23 16:25:11 -07004100 // Test Channel ID
4101 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004102 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004103 continue
4104 }
4105 // Client sends a Channel ID.
4106 tests = append(tests, testCase{
4107 name: "ChannelID-Client-" + ver.name,
4108 config: Config{
4109 MaxVersion: ver.version,
4110 RequestChannelID: true,
4111 },
4112 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4113 resumeSession: true,
4114 expectChannelID: true,
4115 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004116
Nick Harper60a85cb2016-09-23 16:25:11 -07004117 // Server accepts a Channel ID.
4118 tests = append(tests, testCase{
4119 testType: serverTest,
4120 name: "ChannelID-Server-" + ver.name,
4121 config: Config{
4122 MaxVersion: ver.version,
4123 ChannelID: channelIDKey,
4124 },
4125 flags: []string{
4126 "-expect-channel-id",
4127 base64.StdEncoding.EncodeToString(channelIDBytes),
4128 },
4129 resumeSession: true,
4130 expectChannelID: true,
4131 })
4132
4133 tests = append(tests, testCase{
4134 testType: serverTest,
4135 name: "InvalidChannelIDSignature-" + ver.name,
4136 config: Config{
4137 MaxVersion: ver.version,
4138 ChannelID: channelIDKey,
4139 Bugs: ProtocolBugs{
4140 InvalidChannelIDSignature: true,
4141 },
4142 },
4143 flags: []string{"-enable-channel-id"},
4144 shouldFail: true,
4145 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4146 })
4147 }
David Benjamin30789da2015-08-29 22:56:45 -04004148
David Benjaminf8fcdf32016-06-08 15:56:13 -04004149 // Channel ID and NPN at the same time, to ensure their relative
4150 // ordering is correct.
4151 tests = append(tests, testCase{
4152 name: "ChannelID-NPN-Client",
4153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004154 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004155 RequestChannelID: true,
4156 NextProtos: []string{"foo"},
4157 },
4158 flags: []string{
4159 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4160 "-select-next-proto", "foo",
4161 },
4162 resumeSession: true,
4163 expectChannelID: true,
4164 expectedNextProto: "foo",
4165 expectedNextProtoType: npn,
4166 })
4167 tests = append(tests, testCase{
4168 testType: serverTest,
4169 name: "ChannelID-NPN-Server",
4170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004171 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004172 ChannelID: channelIDKey,
4173 NextProtos: []string{"bar"},
4174 },
4175 flags: []string{
4176 "-expect-channel-id",
4177 base64.StdEncoding.EncodeToString(channelIDBytes),
4178 "-advertise-npn", "\x03foo\x03bar\x03baz",
4179 "-expect-next-proto", "bar",
4180 },
4181 resumeSession: true,
4182 expectChannelID: true,
4183 expectedNextProto: "bar",
4184 expectedNextProtoType: npn,
4185 })
4186
David Benjamin30789da2015-08-29 22:56:45 -04004187 // Bidirectional shutdown with the runner initiating.
4188 tests = append(tests, testCase{
4189 name: "Shutdown-Runner",
4190 config: Config{
4191 Bugs: ProtocolBugs{
4192 ExpectCloseNotify: true,
4193 },
4194 },
4195 flags: []string{"-check-close-notify"},
4196 })
4197
David Benjamine3843d42017-03-25 18:00:56 -05004198 if !config.implicitHandshake {
4199 // Bidirectional shutdown with the shim initiating. The runner,
4200 // in the meantime, sends garbage before the close_notify which
4201 // the shim must ignore. This test is disabled under implicit
4202 // handshake tests because the shim never reads or writes.
4203 tests = append(tests, testCase{
4204 name: "Shutdown-Shim",
4205 config: Config{
4206 MaxVersion: VersionTLS12,
4207 Bugs: ProtocolBugs{
4208 ExpectCloseNotify: true,
4209 },
David Benjamin30789da2015-08-29 22:56:45 -04004210 },
David Benjamine3843d42017-03-25 18:00:56 -05004211 shimShutsDown: true,
4212 sendEmptyRecords: 1,
4213 sendWarningAlerts: 1,
4214 flags: []string{"-check-close-notify"},
4215 })
4216 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004217 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004218 // TODO(davidben): DTLS 1.3 will want a similar thing for
4219 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004220 tests = append(tests, testCase{
4221 name: "SkipHelloVerifyRequest",
4222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004223 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004224 Bugs: ProtocolBugs{
4225 SkipHelloVerifyRequest: true,
4226 },
4227 },
4228 })
4229 }
4230
David Benjamin760b1dd2015-05-15 23:33:48 -04004231 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004232 test.protocol = config.protocol
4233 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004234 test.name += "-DTLS"
4235 }
David Benjamin582ba042016-07-07 12:33:25 -07004236 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004237 test.name += "-Async"
4238 test.flags = append(test.flags, "-async")
4239 } else {
4240 test.name += "-Sync"
4241 }
David Benjamin582ba042016-07-07 12:33:25 -07004242 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004243 test.name += "-SplitHandshakeRecords"
4244 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004245 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004246 test.config.Bugs.MaxPacketLength = 256
4247 test.flags = append(test.flags, "-mtu", "256")
4248 }
4249 }
David Benjamin582ba042016-07-07 12:33:25 -07004250 if config.packHandshakeFlight {
4251 test.name += "-PackHandshakeFlight"
4252 test.config.Bugs.PackHandshakeFlight = true
4253 }
David Benjamine3843d42017-03-25 18:00:56 -05004254 if config.implicitHandshake {
4255 test.name += "-ImplicitHandshake"
4256 test.flags = append(test.flags, "-implicit-handshake")
4257 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004258 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004259 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004260}
4261
Adam Langley524e7172015-02-20 16:04:00 -08004262func addDDoSCallbackTests() {
4263 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004264 for _, resume := range []bool{false, true} {
4265 suffix := "Resume"
4266 if resume {
4267 suffix = "No" + suffix
4268 }
4269
4270 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004271 testType: serverTest,
4272 name: "Server-DDoS-OK-" + suffix,
4273 config: Config{
4274 MaxVersion: VersionTLS12,
4275 },
Adam Langley524e7172015-02-20 16:04:00 -08004276 flags: []string{"-install-ddos-callback"},
4277 resumeSession: resume,
4278 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004279 testCases = append(testCases, testCase{
4280 testType: serverTest,
4281 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4282 config: Config{
4283 MaxVersion: VersionTLS13,
4284 },
4285 flags: []string{"-install-ddos-callback"},
4286 resumeSession: resume,
4287 })
Adam Langley524e7172015-02-20 16:04:00 -08004288
4289 failFlag := "-fail-ddos-callback"
4290 if resume {
4291 failFlag = "-fail-second-ddos-callback"
4292 }
4293 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004294 testType: serverTest,
4295 name: "Server-DDoS-Reject-" + suffix,
4296 config: Config{
4297 MaxVersion: VersionTLS12,
4298 },
David Benjamin2c66e072016-09-16 15:58:00 -04004299 flags: []string{"-install-ddos-callback", failFlag},
4300 resumeSession: resume,
4301 shouldFail: true,
4302 expectedError: ":CONNECTION_REJECTED:",
4303 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004304 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004305 testCases = append(testCases, testCase{
4306 testType: serverTest,
4307 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4308 config: Config{
4309 MaxVersion: VersionTLS13,
4310 },
David Benjamin2c66e072016-09-16 15:58:00 -04004311 flags: []string{"-install-ddos-callback", failFlag},
4312 resumeSession: resume,
4313 shouldFail: true,
4314 expectedError: ":CONNECTION_REJECTED:",
4315 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004316 })
Adam Langley524e7172015-02-20 16:04:00 -08004317 }
4318}
4319
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004320func addVersionNegotiationTests() {
4321 for i, shimVers := range tlsVersions {
4322 // Assemble flags to disable all newer versions on the shim.
4323 var flags []string
4324 for _, vers := range tlsVersions[i+1:] {
4325 flags = append(flags, vers.flag)
4326 }
4327
Steven Valdezfdd10992016-09-15 16:27:05 -04004328 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004329 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004330 protocols := []protocol{tls}
4331 if runnerVers.hasDTLS && shimVers.hasDTLS {
4332 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004333 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 for _, protocol := range protocols {
4335 expectedVersion := shimVers.version
4336 if runnerVers.version < shimVers.version {
4337 expectedVersion = runnerVers.version
4338 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004339
David Benjamin8b8c0062014-11-23 02:47:52 -05004340 suffix := shimVers.name + "-" + runnerVers.name
4341 if protocol == dtls {
4342 suffix += "-DTLS"
4343 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004344
David Benjamin1eb367c2014-12-12 18:17:51 -05004345 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4346
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004347 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004348 clientVers := shimVers.version
4349 if clientVers > VersionTLS10 {
4350 clientVers = VersionTLS10
4351 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004352 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004353 serverVers := expectedVersion
4354 if expectedVersion >= VersionTLS13 {
4355 serverVers = VersionTLS10
4356 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004357 serverVers = versionToWire(serverVers, protocol == dtls)
4358
David Benjamin8b8c0062014-11-23 02:47:52 -05004359 testCases = append(testCases, testCase{
4360 protocol: protocol,
4361 testType: clientTest,
4362 name: "VersionNegotiation-Client-" + suffix,
4363 config: Config{
4364 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004365 Bugs: ProtocolBugs{
4366 ExpectInitialRecordVersion: clientVers,
4367 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004368 },
4369 flags: flags,
4370 expectedVersion: expectedVersion,
4371 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004372 testCases = append(testCases, testCase{
4373 protocol: protocol,
4374 testType: clientTest,
4375 name: "VersionNegotiation-Client2-" + suffix,
4376 config: Config{
4377 MaxVersion: runnerVers.version,
4378 Bugs: ProtocolBugs{
4379 ExpectInitialRecordVersion: clientVers,
4380 },
4381 },
4382 flags: []string{"-max-version", shimVersFlag},
4383 expectedVersion: expectedVersion,
4384 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004385
4386 testCases = append(testCases, testCase{
4387 protocol: protocol,
4388 testType: serverTest,
4389 name: "VersionNegotiation-Server-" + suffix,
4390 config: Config{
4391 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004392 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004393 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004394 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004395 },
4396 flags: flags,
4397 expectedVersion: expectedVersion,
4398 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004399 testCases = append(testCases, testCase{
4400 protocol: protocol,
4401 testType: serverTest,
4402 name: "VersionNegotiation-Server2-" + suffix,
4403 config: Config{
4404 MaxVersion: runnerVers.version,
4405 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004406 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004407 },
4408 },
4409 flags: []string{"-max-version", shimVersFlag},
4410 expectedVersion: expectedVersion,
4411 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004412 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004413 }
4414 }
David Benjamin95c69562016-06-29 18:15:03 -04004415
Steven Valdezfdd10992016-09-15 16:27:05 -04004416 // Test the version extension at all versions.
4417 for _, vers := range tlsVersions {
4418 protocols := []protocol{tls}
4419 if vers.hasDTLS {
4420 protocols = append(protocols, dtls)
4421 }
4422 for _, protocol := range protocols {
4423 suffix := vers.name
4424 if protocol == dtls {
4425 suffix += "-DTLS"
4426 }
4427
4428 wireVersion := versionToWire(vers.version, protocol == dtls)
4429 testCases = append(testCases, testCase{
4430 protocol: protocol,
4431 testType: serverTest,
4432 name: "VersionNegotiationExtension-" + suffix,
4433 config: Config{
4434 Bugs: ProtocolBugs{
4435 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4436 },
4437 },
4438 expectedVersion: vers.version,
4439 })
4440 }
4441
4442 }
4443
4444 // If all versions are unknown, negotiation fails.
4445 testCases = append(testCases, testCase{
4446 testType: serverTest,
4447 name: "NoSupportedVersions",
4448 config: Config{
4449 Bugs: ProtocolBugs{
4450 SendSupportedVersions: []uint16{0x1111},
4451 },
4452 },
4453 shouldFail: true,
4454 expectedError: ":UNSUPPORTED_PROTOCOL:",
4455 })
4456 testCases = append(testCases, testCase{
4457 protocol: dtls,
4458 testType: serverTest,
4459 name: "NoSupportedVersions-DTLS",
4460 config: Config{
4461 Bugs: ProtocolBugs{
4462 SendSupportedVersions: []uint16{0x1111},
4463 },
4464 },
4465 shouldFail: true,
4466 expectedError: ":UNSUPPORTED_PROTOCOL:",
4467 })
4468
4469 testCases = append(testCases, testCase{
4470 testType: serverTest,
4471 name: "ClientHelloVersionTooHigh",
4472 config: Config{
4473 MaxVersion: VersionTLS13,
4474 Bugs: ProtocolBugs{
4475 SendClientVersion: 0x0304,
4476 OmitSupportedVersions: true,
4477 },
4478 },
4479 expectedVersion: VersionTLS12,
4480 })
4481
4482 testCases = append(testCases, testCase{
4483 testType: serverTest,
4484 name: "ConflictingVersionNegotiation",
4485 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004486 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004487 SendClientVersion: VersionTLS12,
4488 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004489 },
4490 },
David Benjaminad75a662016-09-30 15:42:59 -04004491 // The extension takes precedence over the ClientHello version.
4492 expectedVersion: VersionTLS11,
4493 })
4494
4495 testCases = append(testCases, testCase{
4496 testType: serverTest,
4497 name: "ConflictingVersionNegotiation-2",
4498 config: Config{
4499 Bugs: ProtocolBugs{
4500 SendClientVersion: VersionTLS11,
4501 SendSupportedVersions: []uint16{VersionTLS12},
4502 },
4503 },
4504 // The extension takes precedence over the ClientHello version.
4505 expectedVersion: VersionTLS12,
4506 })
4507
4508 testCases = append(testCases, testCase{
4509 testType: serverTest,
4510 name: "RejectFinalTLS13",
4511 config: Config{
4512 Bugs: ProtocolBugs{
4513 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4514 },
4515 },
4516 // We currently implement a draft TLS 1.3 version. Ensure that
4517 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004518 expectedVersion: VersionTLS12,
4519 })
4520
Brian Smithf85d3232016-10-28 10:34:06 -10004521 // Test that the maximum version is selected regardless of the
4522 // client-sent order.
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "IgnoreClientVersionOrder",
4526 config: Config{
4527 Bugs: ProtocolBugs{
4528 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4529 },
4530 },
4531 expectedVersion: VersionTLS13,
4532 })
4533
David Benjamin95c69562016-06-29 18:15:03 -04004534 // Test for version tolerance.
4535 testCases = append(testCases, testCase{
4536 testType: serverTest,
4537 name: "MinorVersionTolerance",
4538 config: Config{
4539 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004540 SendClientVersion: 0x03ff,
4541 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004542 },
4543 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004544 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004545 })
4546 testCases = append(testCases, testCase{
4547 testType: serverTest,
4548 name: "MajorVersionTolerance",
4549 config: Config{
4550 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004551 SendClientVersion: 0x0400,
4552 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004553 },
4554 },
David Benjaminad75a662016-09-30 15:42:59 -04004555 // TLS 1.3 must be negotiated with the supported_versions
4556 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004557 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004558 })
David Benjaminad75a662016-09-30 15:42:59 -04004559 testCases = append(testCases, testCase{
4560 testType: serverTest,
4561 name: "VersionTolerance-TLS13",
4562 config: Config{
4563 Bugs: ProtocolBugs{
4564 // Although TLS 1.3 does not use
4565 // ClientHello.version, it still tolerates high
4566 // values there.
4567 SendClientVersion: 0x0400,
4568 },
4569 },
4570 expectedVersion: VersionTLS13,
4571 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004572
David Benjamin95c69562016-06-29 18:15:03 -04004573 testCases = append(testCases, testCase{
4574 protocol: dtls,
4575 testType: serverTest,
4576 name: "MinorVersionTolerance-DTLS",
4577 config: Config{
4578 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004579 SendClientVersion: 0xfe00,
4580 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004581 },
4582 },
4583 expectedVersion: VersionTLS12,
4584 })
4585 testCases = append(testCases, testCase{
4586 protocol: dtls,
4587 testType: serverTest,
4588 name: "MajorVersionTolerance-DTLS",
4589 config: Config{
4590 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004591 SendClientVersion: 0xfdff,
4592 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004593 },
4594 },
4595 expectedVersion: VersionTLS12,
4596 })
4597
4598 // Test that versions below 3.0 are rejected.
4599 testCases = append(testCases, testCase{
4600 testType: serverTest,
4601 name: "VersionTooLow",
4602 config: Config{
4603 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004604 SendClientVersion: 0x0200,
4605 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004606 },
4607 },
4608 shouldFail: true,
4609 expectedError: ":UNSUPPORTED_PROTOCOL:",
4610 })
4611 testCases = append(testCases, testCase{
4612 protocol: dtls,
4613 testType: serverTest,
4614 name: "VersionTooLow-DTLS",
4615 config: Config{
4616 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004617 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004618 },
4619 },
4620 shouldFail: true,
4621 expectedError: ":UNSUPPORTED_PROTOCOL:",
4622 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004623
David Benjamin2dc02042016-09-19 19:57:37 -04004624 testCases = append(testCases, testCase{
4625 name: "ServerBogusVersion",
4626 config: Config{
4627 Bugs: ProtocolBugs{
4628 SendServerHelloVersion: 0x1234,
4629 },
4630 },
4631 shouldFail: true,
4632 expectedError: ":UNSUPPORTED_PROTOCOL:",
4633 })
4634
David Benjamin1f61f0d2016-07-10 12:20:35 -04004635 // Test TLS 1.3's downgrade signal.
4636 testCases = append(testCases, testCase{
4637 name: "Downgrade-TLS12-Client",
4638 config: Config{
4639 Bugs: ProtocolBugs{
4640 NegotiateVersion: VersionTLS12,
4641 },
4642 },
David Benjamin592b5322016-09-30 15:15:01 -04004643 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004644 // TODO(davidben): This test should fail once TLS 1.3 is final
4645 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004646 })
4647 testCases = append(testCases, testCase{
4648 testType: serverTest,
4649 name: "Downgrade-TLS12-Server",
4650 config: Config{
4651 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004652 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004653 },
4654 },
David Benjamin592b5322016-09-30 15:15:01 -04004655 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004656 // TODO(davidben): This test should fail once TLS 1.3 is final
4657 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004658 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004659}
4660
David Benjaminaccb4542014-12-12 23:44:33 -05004661func addMinimumVersionTests() {
4662 for i, shimVers := range tlsVersions {
4663 // Assemble flags to disable all older versions on the shim.
4664 var flags []string
4665 for _, vers := range tlsVersions[:i] {
4666 flags = append(flags, vers.flag)
4667 }
4668
4669 for _, runnerVers := range tlsVersions {
4670 protocols := []protocol{tls}
4671 if runnerVers.hasDTLS && shimVers.hasDTLS {
4672 protocols = append(protocols, dtls)
4673 }
4674 for _, protocol := range protocols {
4675 suffix := shimVers.name + "-" + runnerVers.name
4676 if protocol == dtls {
4677 suffix += "-DTLS"
4678 }
4679 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4680
David Benjaminaccb4542014-12-12 23:44:33 -05004681 var expectedVersion uint16
4682 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004683 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004684 if runnerVers.version >= shimVers.version {
4685 expectedVersion = runnerVers.version
4686 } else {
4687 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004688 expectedError = ":UNSUPPORTED_PROTOCOL:"
4689 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004690 }
4691
4692 testCases = append(testCases, testCase{
4693 protocol: protocol,
4694 testType: clientTest,
4695 name: "MinimumVersion-Client-" + suffix,
4696 config: Config{
4697 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004698 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004699 // Ensure the server does not decline to
4700 // select a version (versions extension) or
4701 // cipher (some ciphers depend on versions).
4702 NegotiateVersion: runnerVers.version,
4703 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004704 },
David Benjaminaccb4542014-12-12 23:44:33 -05004705 },
David Benjamin87909c02014-12-13 01:55:01 -05004706 flags: flags,
4707 expectedVersion: expectedVersion,
4708 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004709 expectedError: expectedError,
4710 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004711 })
4712 testCases = append(testCases, testCase{
4713 protocol: protocol,
4714 testType: clientTest,
4715 name: "MinimumVersion-Client2-" + suffix,
4716 config: Config{
4717 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004718 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004719 // Ensure the server does not decline to
4720 // select a version (versions extension) or
4721 // cipher (some ciphers depend on versions).
4722 NegotiateVersion: runnerVers.version,
4723 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004724 },
David Benjaminaccb4542014-12-12 23:44:33 -05004725 },
David Benjamin87909c02014-12-13 01:55:01 -05004726 flags: []string{"-min-version", shimVersFlag},
4727 expectedVersion: expectedVersion,
4728 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004729 expectedError: expectedError,
4730 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004731 })
4732
4733 testCases = append(testCases, testCase{
4734 protocol: protocol,
4735 testType: serverTest,
4736 name: "MinimumVersion-Server-" + suffix,
4737 config: Config{
4738 MaxVersion: runnerVers.version,
4739 },
David Benjamin87909c02014-12-13 01:55:01 -05004740 flags: flags,
4741 expectedVersion: expectedVersion,
4742 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004743 expectedError: expectedError,
4744 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004745 })
4746 testCases = append(testCases, testCase{
4747 protocol: protocol,
4748 testType: serverTest,
4749 name: "MinimumVersion-Server2-" + suffix,
4750 config: Config{
4751 MaxVersion: runnerVers.version,
4752 },
David Benjamin87909c02014-12-13 01:55:01 -05004753 flags: []string{"-min-version", shimVersFlag},
4754 expectedVersion: expectedVersion,
4755 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004756 expectedError: expectedError,
4757 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004758 })
4759 }
4760 }
4761 }
4762}
4763
David Benjamine78bfde2014-09-06 12:45:15 -04004764func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004765 // TODO(davidben): Extensions, where applicable, all move their server
4766 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4767 // tests for both. Also test interaction with 0-RTT when implemented.
4768
David Benjamin97d17d92016-07-14 16:12:00 -04004769 // Repeat extensions tests all versions except SSL 3.0.
4770 for _, ver := range tlsVersions {
4771 if ver.version == VersionSSL30 {
4772 continue
4773 }
4774
David Benjamin97d17d92016-07-14 16:12:00 -04004775 // Test that duplicate extensions are rejected.
4776 testCases = append(testCases, testCase{
4777 testType: clientTest,
4778 name: "DuplicateExtensionClient-" + ver.name,
4779 config: Config{
4780 MaxVersion: ver.version,
4781 Bugs: ProtocolBugs{
4782 DuplicateExtension: true,
4783 },
David Benjamine78bfde2014-09-06 12:45:15 -04004784 },
David Benjamin97d17d92016-07-14 16:12:00 -04004785 shouldFail: true,
4786 expectedLocalError: "remote error: error decoding message",
4787 })
4788 testCases = append(testCases, testCase{
4789 testType: serverTest,
4790 name: "DuplicateExtensionServer-" + ver.name,
4791 config: Config{
4792 MaxVersion: ver.version,
4793 Bugs: ProtocolBugs{
4794 DuplicateExtension: true,
4795 },
David Benjamine78bfde2014-09-06 12:45:15 -04004796 },
David Benjamin97d17d92016-07-14 16:12:00 -04004797 shouldFail: true,
4798 expectedLocalError: "remote error: error decoding message",
4799 })
4800
4801 // Test SNI.
4802 testCases = append(testCases, testCase{
4803 testType: clientTest,
4804 name: "ServerNameExtensionClient-" + ver.name,
4805 config: Config{
4806 MaxVersion: ver.version,
4807 Bugs: ProtocolBugs{
4808 ExpectServerName: "example.com",
4809 },
David Benjamine78bfde2014-09-06 12:45:15 -04004810 },
David Benjamin97d17d92016-07-14 16:12:00 -04004811 flags: []string{"-host-name", "example.com"},
4812 })
4813 testCases = append(testCases, testCase{
4814 testType: clientTest,
4815 name: "ServerNameExtensionClientMismatch-" + ver.name,
4816 config: Config{
4817 MaxVersion: ver.version,
4818 Bugs: ProtocolBugs{
4819 ExpectServerName: "mismatch.com",
4820 },
David Benjamine78bfde2014-09-06 12:45:15 -04004821 },
David Benjamin97d17d92016-07-14 16:12:00 -04004822 flags: []string{"-host-name", "example.com"},
4823 shouldFail: true,
4824 expectedLocalError: "tls: unexpected server name",
4825 })
4826 testCases = append(testCases, testCase{
4827 testType: clientTest,
4828 name: "ServerNameExtensionClientMissing-" + ver.name,
4829 config: Config{
4830 MaxVersion: ver.version,
4831 Bugs: ProtocolBugs{
4832 ExpectServerName: "missing.com",
4833 },
David Benjamine78bfde2014-09-06 12:45:15 -04004834 },
David Benjamin97d17d92016-07-14 16:12:00 -04004835 shouldFail: true,
4836 expectedLocalError: "tls: unexpected server name",
4837 })
4838 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004839 testType: clientTest,
4840 name: "TolerateServerNameAck-" + ver.name,
4841 config: Config{
4842 MaxVersion: ver.version,
4843 Bugs: ProtocolBugs{
4844 SendServerNameAck: true,
4845 },
4846 },
4847 flags: []string{"-host-name", "example.com"},
4848 resumeSession: true,
4849 })
4850 testCases = append(testCases, testCase{
4851 testType: clientTest,
4852 name: "UnsolicitedServerNameAck-" + ver.name,
4853 config: Config{
4854 MaxVersion: ver.version,
4855 Bugs: ProtocolBugs{
4856 SendServerNameAck: true,
4857 },
4858 },
4859 shouldFail: true,
4860 expectedError: ":UNEXPECTED_EXTENSION:",
4861 expectedLocalError: "remote error: unsupported extension",
4862 })
4863 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004864 testType: serverTest,
4865 name: "ServerNameExtensionServer-" + ver.name,
4866 config: Config{
4867 MaxVersion: ver.version,
4868 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004869 },
David Benjamin97d17d92016-07-14 16:12:00 -04004870 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004871 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004872 })
4873
4874 // Test ALPN.
4875 testCases = append(testCases, testCase{
4876 testType: clientTest,
4877 name: "ALPNClient-" + ver.name,
4878 config: Config{
4879 MaxVersion: ver.version,
4880 NextProtos: []string{"foo"},
4881 },
4882 flags: []string{
4883 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4884 "-expect-alpn", "foo",
4885 },
4886 expectedNextProto: "foo",
4887 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004888 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004889 })
4890 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004891 testType: clientTest,
4892 name: "ALPNClient-Mismatch-" + ver.name,
4893 config: Config{
4894 MaxVersion: ver.version,
4895 Bugs: ProtocolBugs{
4896 SendALPN: "baz",
4897 },
4898 },
4899 flags: []string{
4900 "-advertise-alpn", "\x03foo\x03bar",
4901 },
4902 shouldFail: true,
4903 expectedError: ":INVALID_ALPN_PROTOCOL:",
4904 expectedLocalError: "remote error: illegal parameter",
4905 })
4906 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004907 testType: serverTest,
4908 name: "ALPNServer-" + ver.name,
4909 config: Config{
4910 MaxVersion: ver.version,
4911 NextProtos: []string{"foo", "bar", "baz"},
4912 },
4913 flags: []string{
4914 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4915 "-select-alpn", "foo",
4916 },
4917 expectedNextProto: "foo",
4918 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004919 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004920 })
4921 testCases = append(testCases, testCase{
4922 testType: serverTest,
4923 name: "ALPNServer-Decline-" + ver.name,
4924 config: Config{
4925 MaxVersion: ver.version,
4926 NextProtos: []string{"foo", "bar", "baz"},
4927 },
4928 flags: []string{"-decline-alpn"},
4929 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004930 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004931 })
4932
David Benjamin25fe85b2016-08-09 20:00:32 -04004933 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4934 // called once.
4935 testCases = append(testCases, testCase{
4936 testType: serverTest,
4937 name: "ALPNServer-Async-" + ver.name,
4938 config: Config{
4939 MaxVersion: ver.version,
4940 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004941 // Prior to TLS 1.3, exercise the asynchronous session callback.
4942 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004943 },
4944 flags: []string{
4945 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4946 "-select-alpn", "foo",
4947 "-async",
4948 },
4949 expectedNextProto: "foo",
4950 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004951 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004952 })
4953
David Benjamin97d17d92016-07-14 16:12:00 -04004954 var emptyString string
4955 testCases = append(testCases, testCase{
4956 testType: clientTest,
4957 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4958 config: Config{
4959 MaxVersion: ver.version,
4960 NextProtos: []string{""},
4961 Bugs: ProtocolBugs{
4962 // A server returning an empty ALPN protocol
4963 // should be rejected.
4964 ALPNProtocol: &emptyString,
4965 },
4966 },
4967 flags: []string{
4968 "-advertise-alpn", "\x03foo",
4969 },
4970 shouldFail: true,
4971 expectedError: ":PARSE_TLSEXT:",
4972 })
4973 testCases = append(testCases, testCase{
4974 testType: serverTest,
4975 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4976 config: Config{
4977 MaxVersion: ver.version,
4978 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004979 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004980 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004981 },
David Benjamin97d17d92016-07-14 16:12:00 -04004982 flags: []string{
4983 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004984 },
David Benjamin97d17d92016-07-14 16:12:00 -04004985 shouldFail: true,
4986 expectedError: ":PARSE_TLSEXT:",
4987 })
4988
4989 // Test NPN and the interaction with ALPN.
4990 if ver.version < VersionTLS13 {
4991 // Test that the server prefers ALPN over NPN.
4992 testCases = append(testCases, testCase{
4993 testType: serverTest,
4994 name: "ALPNServer-Preferred-" + ver.name,
4995 config: Config{
4996 MaxVersion: ver.version,
4997 NextProtos: []string{"foo", "bar", "baz"},
4998 },
4999 flags: []string{
5000 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5001 "-select-alpn", "foo",
5002 "-advertise-npn", "\x03foo\x03bar\x03baz",
5003 },
5004 expectedNextProto: "foo",
5005 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005006 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005007 })
5008 testCases = append(testCases, testCase{
5009 testType: serverTest,
5010 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5011 config: Config{
5012 MaxVersion: ver.version,
5013 NextProtos: []string{"foo", "bar", "baz"},
5014 Bugs: ProtocolBugs{
5015 SwapNPNAndALPN: true,
5016 },
5017 },
5018 flags: []string{
5019 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5020 "-select-alpn", "foo",
5021 "-advertise-npn", "\x03foo\x03bar\x03baz",
5022 },
5023 expectedNextProto: "foo",
5024 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005025 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005026 })
5027
5028 // Test that negotiating both NPN and ALPN is forbidden.
5029 testCases = append(testCases, testCase{
5030 name: "NegotiateALPNAndNPN-" + ver.name,
5031 config: Config{
5032 MaxVersion: ver.version,
5033 NextProtos: []string{"foo", "bar", "baz"},
5034 Bugs: ProtocolBugs{
5035 NegotiateALPNAndNPN: true,
5036 },
5037 },
5038 flags: []string{
5039 "-advertise-alpn", "\x03foo",
5040 "-select-next-proto", "foo",
5041 },
5042 shouldFail: true,
5043 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5044 })
5045 testCases = append(testCases, testCase{
5046 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5047 config: Config{
5048 MaxVersion: ver.version,
5049 NextProtos: []string{"foo", "bar", "baz"},
5050 Bugs: ProtocolBugs{
5051 NegotiateALPNAndNPN: true,
5052 SwapNPNAndALPN: true,
5053 },
5054 },
5055 flags: []string{
5056 "-advertise-alpn", "\x03foo",
5057 "-select-next-proto", "foo",
5058 },
5059 shouldFail: true,
5060 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5061 })
David Benjamin97d17d92016-07-14 16:12:00 -04005062 }
5063
5064 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005065
5066 // Resume with a corrupt ticket.
5067 testCases = append(testCases, testCase{
5068 testType: serverTest,
5069 name: "CorruptTicket-" + ver.name,
5070 config: Config{
5071 MaxVersion: ver.version,
5072 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005073 FilterTicket: func(in []byte) ([]byte, error) {
5074 in[len(in)-1] ^= 1
5075 return in, nil
5076 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005077 },
5078 },
5079 resumeSession: true,
5080 expectResumeRejected: true,
5081 })
5082 // Test the ticket callback, with and without renewal.
5083 testCases = append(testCases, testCase{
5084 testType: serverTest,
5085 name: "TicketCallback-" + ver.name,
5086 config: Config{
5087 MaxVersion: ver.version,
5088 },
5089 resumeSession: true,
5090 flags: []string{"-use-ticket-callback"},
5091 })
5092 testCases = append(testCases, testCase{
5093 testType: serverTest,
5094 name: "TicketCallback-Renew-" + ver.name,
5095 config: Config{
5096 MaxVersion: ver.version,
5097 Bugs: ProtocolBugs{
5098 ExpectNewTicket: true,
5099 },
5100 },
5101 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5102 resumeSession: true,
5103 })
5104
5105 // Test that the ticket callback is only called once when everything before
5106 // it in the ClientHello is asynchronous. This corrupts the ticket so
5107 // certificate selection callbacks run.
5108 testCases = append(testCases, testCase{
5109 testType: serverTest,
5110 name: "TicketCallback-SingleCall-" + ver.name,
5111 config: Config{
5112 MaxVersion: ver.version,
5113 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005114 FilterTicket: func(in []byte) ([]byte, error) {
5115 in[len(in)-1] ^= 1
5116 return in, nil
5117 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005118 },
5119 },
5120 resumeSession: true,
5121 expectResumeRejected: true,
5122 flags: []string{
5123 "-use-ticket-callback",
5124 "-async",
5125 },
5126 })
5127
David Benjamind4c349b2017-02-09 14:07:17 -05005128 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005129 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005130 testCases = append(testCases, testCase{
5131 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005132 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005133 config: Config{
5134 MaxVersion: ver.version,
5135 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005136 EmptyTicketSessionID: true,
5137 },
5138 },
5139 resumeSession: true,
5140 })
5141 testCases = append(testCases, testCase{
5142 testType: serverTest,
5143 name: "TicketSessionIDLength-16-" + ver.name,
5144 config: Config{
5145 MaxVersion: ver.version,
5146 Bugs: ProtocolBugs{
5147 TicketSessionIDLength: 16,
5148 },
5149 },
5150 resumeSession: true,
5151 })
5152 testCases = append(testCases, testCase{
5153 testType: serverTest,
5154 name: "TicketSessionIDLength-32-" + ver.name,
5155 config: Config{
5156 MaxVersion: ver.version,
5157 Bugs: ProtocolBugs{
5158 TicketSessionIDLength: 32,
5159 },
5160 },
5161 resumeSession: true,
5162 })
5163 testCases = append(testCases, testCase{
5164 testType: serverTest,
5165 name: "TicketSessionIDLength-33-" + ver.name,
5166 config: Config{
5167 MaxVersion: ver.version,
5168 Bugs: ProtocolBugs{
5169 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005170 },
5171 },
5172 resumeSession: true,
5173 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005174 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005175 expectedError: ":DECODE_ERROR:",
5176 })
5177 }
5178
5179 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5180 // are ignored.
5181 if ver.hasDTLS {
5182 testCases = append(testCases, testCase{
5183 protocol: dtls,
5184 name: "SRTP-Client-" + ver.name,
5185 config: Config{
5186 MaxVersion: ver.version,
5187 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5188 },
5189 flags: []string{
5190 "-srtp-profiles",
5191 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5192 },
5193 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5194 })
5195 testCases = append(testCases, testCase{
5196 protocol: dtls,
5197 testType: serverTest,
5198 name: "SRTP-Server-" + ver.name,
5199 config: Config{
5200 MaxVersion: ver.version,
5201 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5202 },
5203 flags: []string{
5204 "-srtp-profiles",
5205 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5206 },
5207 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5208 })
5209 // Test that the MKI is ignored.
5210 testCases = append(testCases, testCase{
5211 protocol: dtls,
5212 testType: serverTest,
5213 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5214 config: Config{
5215 MaxVersion: ver.version,
5216 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5217 Bugs: ProtocolBugs{
5218 SRTPMasterKeyIdentifer: "bogus",
5219 },
5220 },
5221 flags: []string{
5222 "-srtp-profiles",
5223 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5224 },
5225 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5226 })
5227 // Test that SRTP isn't negotiated on the server if there were
5228 // no matching profiles.
5229 testCases = append(testCases, testCase{
5230 protocol: dtls,
5231 testType: serverTest,
5232 name: "SRTP-Server-NoMatch-" + ver.name,
5233 config: Config{
5234 MaxVersion: ver.version,
5235 SRTPProtectionProfiles: []uint16{100, 101, 102},
5236 },
5237 flags: []string{
5238 "-srtp-profiles",
5239 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5240 },
5241 expectedSRTPProtectionProfile: 0,
5242 })
5243 // Test that the server returning an invalid SRTP profile is
5244 // flagged as an error by the client.
5245 testCases = append(testCases, testCase{
5246 protocol: dtls,
5247 name: "SRTP-Client-NoMatch-" + ver.name,
5248 config: Config{
5249 MaxVersion: ver.version,
5250 Bugs: ProtocolBugs{
5251 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5252 },
5253 },
5254 flags: []string{
5255 "-srtp-profiles",
5256 "SRTP_AES128_CM_SHA1_80",
5257 },
5258 shouldFail: true,
5259 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5260 })
5261 }
5262
5263 // Test SCT list.
5264 testCases = append(testCases, testCase{
5265 name: "SignedCertificateTimestampList-Client-" + ver.name,
5266 testType: clientTest,
5267 config: Config{
5268 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005269 },
David Benjamin97d17d92016-07-14 16:12:00 -04005270 flags: []string{
5271 "-enable-signed-cert-timestamps",
5272 "-expect-signed-cert-timestamps",
5273 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005274 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005275 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005276 })
David Benjamindaa88502016-10-04 16:32:16 -04005277
Adam Langleycfa08c32016-11-17 13:21:27 -08005278 var differentSCTList []byte
5279 differentSCTList = append(differentSCTList, testSCTList...)
5280 differentSCTList[len(differentSCTList)-1] ^= 1
5281
David Benjamindaa88502016-10-04 16:32:16 -04005282 // The SCT extension did not specify that it must only be sent on resumption as it
5283 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005284 testCases = append(testCases, testCase{
5285 name: "SendSCTListOnResume-" + ver.name,
5286 config: Config{
5287 MaxVersion: ver.version,
5288 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005289 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005290 },
David Benjamind98452d2015-06-16 14:16:23 -04005291 },
David Benjamin97d17d92016-07-14 16:12:00 -04005292 flags: []string{
5293 "-enable-signed-cert-timestamps",
5294 "-expect-signed-cert-timestamps",
5295 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005296 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005297 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005298 })
David Benjamindaa88502016-10-04 16:32:16 -04005299
David Benjamin97d17d92016-07-14 16:12:00 -04005300 testCases = append(testCases, testCase{
5301 name: "SignedCertificateTimestampList-Server-" + ver.name,
5302 testType: serverTest,
5303 config: Config{
5304 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005305 },
David Benjamin97d17d92016-07-14 16:12:00 -04005306 flags: []string{
5307 "-signed-cert-timestamps",
5308 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005309 },
David Benjamin97d17d92016-07-14 16:12:00 -04005310 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005311 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005312 })
David Benjamin53210cb2016-11-16 09:01:48 +09005313
Adam Langleycfa08c32016-11-17 13:21:27 -08005314 emptySCTListCert := *testCerts[0].cert
5315 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5316
5317 // Test empty SCT list.
5318 testCases = append(testCases, testCase{
5319 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5320 testType: clientTest,
5321 config: Config{
5322 MaxVersion: ver.version,
5323 Certificates: []Certificate{emptySCTListCert},
5324 },
5325 flags: []string{
5326 "-enable-signed-cert-timestamps",
5327 },
5328 shouldFail: true,
5329 expectedError: ":ERROR_PARSING_EXTENSION:",
5330 })
5331
5332 emptySCTCert := *testCerts[0].cert
5333 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5334
5335 // Test empty SCT in non-empty list.
5336 testCases = append(testCases, testCase{
5337 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5338 testType: clientTest,
5339 config: Config{
5340 MaxVersion: ver.version,
5341 Certificates: []Certificate{emptySCTCert},
5342 },
5343 flags: []string{
5344 "-enable-signed-cert-timestamps",
5345 },
5346 shouldFail: true,
5347 expectedError: ":ERROR_PARSING_EXTENSION:",
5348 })
5349
David Benjamin53210cb2016-11-16 09:01:48 +09005350 // Test that certificate-related extensions are not sent unsolicited.
5351 testCases = append(testCases, testCase{
5352 testType: serverTest,
5353 name: "UnsolicitedCertificateExtensions-" + ver.name,
5354 config: Config{
5355 MaxVersion: ver.version,
5356 Bugs: ProtocolBugs{
5357 NoOCSPStapling: true,
5358 NoSignedCertificateTimestamps: true,
5359 },
5360 },
5361 flags: []string{
5362 "-ocsp-response",
5363 base64.StdEncoding.EncodeToString(testOCSPResponse),
5364 "-signed-cert-timestamps",
5365 base64.StdEncoding.EncodeToString(testSCTList),
5366 },
5367 })
David Benjamin97d17d92016-07-14 16:12:00 -04005368 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005369
Paul Lietar4fac72e2015-09-09 13:44:55 +01005370 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005371 testType: clientTest,
5372 name: "ClientHelloPadding",
5373 config: Config{
5374 Bugs: ProtocolBugs{
5375 RequireClientHelloSize: 512,
5376 },
5377 },
5378 // This hostname just needs to be long enough to push the
5379 // ClientHello into F5's danger zone between 256 and 511 bytes
5380 // long.
5381 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5382 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005383
5384 // Extensions should not function in SSL 3.0.
5385 testCases = append(testCases, testCase{
5386 testType: serverTest,
5387 name: "SSLv3Extensions-NoALPN",
5388 config: Config{
5389 MaxVersion: VersionSSL30,
5390 NextProtos: []string{"foo", "bar", "baz"},
5391 },
5392 flags: []string{
5393 "-select-alpn", "foo",
5394 },
5395 expectNoNextProto: true,
5396 })
5397
5398 // Test session tickets separately as they follow a different codepath.
5399 testCases = append(testCases, testCase{
5400 testType: serverTest,
5401 name: "SSLv3Extensions-NoTickets",
5402 config: Config{
5403 MaxVersion: VersionSSL30,
5404 Bugs: ProtocolBugs{
5405 // Historically, session tickets in SSL 3.0
5406 // failed in different ways depending on whether
5407 // the client supported renegotiation_info.
5408 NoRenegotiationInfo: true,
5409 },
5410 },
5411 resumeSession: true,
5412 })
5413 testCases = append(testCases, testCase{
5414 testType: serverTest,
5415 name: "SSLv3Extensions-NoTickets2",
5416 config: Config{
5417 MaxVersion: VersionSSL30,
5418 },
5419 resumeSession: true,
5420 })
5421
5422 // But SSL 3.0 does send and process renegotiation_info.
5423 testCases = append(testCases, testCase{
5424 testType: serverTest,
5425 name: "SSLv3Extensions-RenegotiationInfo",
5426 config: Config{
5427 MaxVersion: VersionSSL30,
5428 Bugs: ProtocolBugs{
5429 RequireRenegotiationInfo: true,
5430 },
5431 },
David Benjamind2610042017-01-03 10:49:28 -05005432 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005433 })
5434 testCases = append(testCases, testCase{
5435 testType: serverTest,
5436 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5437 config: Config{
5438 MaxVersion: VersionSSL30,
5439 Bugs: ProtocolBugs{
5440 NoRenegotiationInfo: true,
5441 SendRenegotiationSCSV: true,
5442 RequireRenegotiationInfo: true,
5443 },
5444 },
David Benjamind2610042017-01-03 10:49:28 -05005445 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005446 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005447
5448 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5449 // in ServerHello.
5450 testCases = append(testCases, testCase{
5451 name: "NPN-Forbidden-TLS13",
5452 config: Config{
5453 MaxVersion: VersionTLS13,
5454 NextProtos: []string{"foo"},
5455 Bugs: ProtocolBugs{
5456 NegotiateNPNAtAllVersions: true,
5457 },
5458 },
5459 flags: []string{"-select-next-proto", "foo"},
5460 shouldFail: true,
5461 expectedError: ":ERROR_PARSING_EXTENSION:",
5462 })
5463 testCases = append(testCases, testCase{
5464 name: "EMS-Forbidden-TLS13",
5465 config: Config{
5466 MaxVersion: VersionTLS13,
5467 Bugs: ProtocolBugs{
5468 NegotiateEMSAtAllVersions: true,
5469 },
5470 },
5471 shouldFail: true,
5472 expectedError: ":ERROR_PARSING_EXTENSION:",
5473 })
5474 testCases = append(testCases, testCase{
5475 name: "RenegotiationInfo-Forbidden-TLS13",
5476 config: Config{
5477 MaxVersion: VersionTLS13,
5478 Bugs: ProtocolBugs{
5479 NegotiateRenegotiationInfoAtAllVersions: true,
5480 },
5481 },
5482 shouldFail: true,
5483 expectedError: ":ERROR_PARSING_EXTENSION:",
5484 })
5485 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005486 name: "Ticket-Forbidden-TLS13",
5487 config: Config{
5488 MaxVersion: VersionTLS12,
5489 },
5490 resumeConfig: &Config{
5491 MaxVersion: VersionTLS13,
5492 Bugs: ProtocolBugs{
5493 AdvertiseTicketExtension: true,
5494 },
5495 },
5496 resumeSession: true,
5497 shouldFail: true,
5498 expectedError: ":ERROR_PARSING_EXTENSION:",
5499 })
5500
5501 // Test that illegal extensions in TLS 1.3 are declined by the server if
5502 // offered in ClientHello. The runner's server will fail if this occurs,
5503 // so we exercise the offering path. (EMS and Renegotiation Info are
5504 // implicit in every test.)
5505 testCases = append(testCases, testCase{
5506 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005507 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005508 config: Config{
5509 MaxVersion: VersionTLS13,
5510 NextProtos: []string{"bar"},
5511 },
5512 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5513 })
David Benjamin196df5b2016-09-21 16:23:27 -04005514
David Benjamindaa88502016-10-04 16:32:16 -04005515 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5516 // tolerated.
5517 testCases = append(testCases, testCase{
5518 name: "SendOCSPResponseOnResume-TLS12",
5519 config: Config{
5520 MaxVersion: VersionTLS12,
5521 Bugs: ProtocolBugs{
5522 SendOCSPResponseOnResume: []byte("bogus"),
5523 },
5524 },
5525 flags: []string{
5526 "-enable-ocsp-stapling",
5527 "-expect-ocsp-response",
5528 base64.StdEncoding.EncodeToString(testOCSPResponse),
5529 },
5530 resumeSession: true,
5531 })
5532
David Benjamindaa88502016-10-04 16:32:16 -04005533 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005534 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005535 config: Config{
5536 MaxVersion: VersionTLS13,
5537 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005538 SendExtensionOnCertificate: testOCSPExtension,
5539 },
5540 },
5541 shouldFail: true,
5542 expectedError: ":UNEXPECTED_EXTENSION:",
5543 })
5544
5545 testCases = append(testCases, testCase{
5546 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5547 config: Config{
5548 MaxVersion: VersionTLS13,
5549 Bugs: ProtocolBugs{
5550 SendExtensionOnCertificate: testSCTExtension,
5551 },
5552 },
5553 shouldFail: true,
5554 expectedError: ":UNEXPECTED_EXTENSION:",
5555 })
5556
5557 // Test that extensions on client certificates are never accepted.
5558 testCases = append(testCases, testCase{
5559 name: "SendExtensionOnClientCertificate-TLS13",
5560 testType: serverTest,
5561 config: Config{
5562 MaxVersion: VersionTLS13,
5563 Certificates: []Certificate{rsaCertificate},
5564 Bugs: ProtocolBugs{
5565 SendExtensionOnCertificate: testOCSPExtension,
5566 },
5567 },
5568 flags: []string{
5569 "-enable-ocsp-stapling",
5570 "-require-any-client-certificate",
5571 },
5572 shouldFail: true,
5573 expectedError: ":UNEXPECTED_EXTENSION:",
5574 })
5575
5576 testCases = append(testCases, testCase{
5577 name: "SendUnknownExtensionOnCertificate-TLS13",
5578 config: Config{
5579 MaxVersion: VersionTLS13,
5580 Bugs: ProtocolBugs{
5581 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5582 },
5583 },
5584 shouldFail: true,
5585 expectedError: ":UNEXPECTED_EXTENSION:",
5586 })
5587
Adam Langleycfa08c32016-11-17 13:21:27 -08005588 var differentSCTList []byte
5589 differentSCTList = append(differentSCTList, testSCTList...)
5590 differentSCTList[len(differentSCTList)-1] ^= 1
5591
Steven Valdeza833c352016-11-01 13:39:36 -04005592 // Test that extensions on intermediates are allowed but ignored.
5593 testCases = append(testCases, testCase{
5594 name: "IgnoreExtensionsOnIntermediates-TLS13",
5595 config: Config{
5596 MaxVersion: VersionTLS13,
5597 Certificates: []Certificate{rsaChainCertificate},
5598 Bugs: ProtocolBugs{
5599 // Send different values on the intermediate. This tests
5600 // the intermediate's extensions do not override the
5601 // leaf's.
5602 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005603 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005604 },
5605 },
5606 flags: []string{
5607 "-enable-ocsp-stapling",
5608 "-expect-ocsp-response",
5609 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005610 "-enable-signed-cert-timestamps",
5611 "-expect-signed-cert-timestamps",
5612 base64.StdEncoding.EncodeToString(testSCTList),
5613 },
5614 resumeSession: true,
5615 })
5616
5617 // Test that extensions are not sent on intermediates when configured
5618 // only for a leaf.
5619 testCases = append(testCases, testCase{
5620 testType: serverTest,
5621 name: "SendNoExtensionsOnIntermediate-TLS13",
5622 config: Config{
5623 MaxVersion: VersionTLS13,
5624 Bugs: ProtocolBugs{
5625 ExpectNoExtensionsOnIntermediate: true,
5626 },
5627 },
5628 flags: []string{
5629 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5630 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5631 "-ocsp-response",
5632 base64.StdEncoding.EncodeToString(testOCSPResponse),
5633 "-signed-cert-timestamps",
5634 base64.StdEncoding.EncodeToString(testSCTList),
5635 },
5636 })
5637
5638 // Test that extensions are not sent on client certificates.
5639 testCases = append(testCases, testCase{
5640 name: "SendNoClientCertificateExtensions-TLS13",
5641 config: Config{
5642 MaxVersion: VersionTLS13,
5643 ClientAuth: RequireAnyClientCert,
5644 },
5645 flags: []string{
5646 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5647 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5648 "-ocsp-response",
5649 base64.StdEncoding.EncodeToString(testOCSPResponse),
5650 "-signed-cert-timestamps",
5651 base64.StdEncoding.EncodeToString(testSCTList),
5652 },
5653 })
5654
5655 testCases = append(testCases, testCase{
5656 name: "SendDuplicateExtensionsOnCerts-TLS13",
5657 config: Config{
5658 MaxVersion: VersionTLS13,
5659 Bugs: ProtocolBugs{
5660 SendDuplicateCertExtensions: true,
5661 },
5662 },
5663 flags: []string{
5664 "-enable-ocsp-stapling",
5665 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005666 },
5667 resumeSession: true,
5668 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005669 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005670 })
Adam Langley9b885c52016-11-18 14:21:03 -08005671
5672 testCases = append(testCases, testCase{
5673 name: "SignedCertificateTimestampListInvalid-Server",
5674 testType: serverTest,
5675 flags: []string{
5676 "-signed-cert-timestamps",
5677 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5678 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005679 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005680 expectedError: ":INVALID_SCT_LIST:",
5681 })
David Benjamine78bfde2014-09-06 12:45:15 -04005682}
5683
David Benjamin01fe8202014-09-24 15:21:44 -04005684func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005685 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005686 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005687 // SSL 3.0 does not have tickets and TLS 1.3 does not
5688 // have session IDs, so skip their cross-resumption
5689 // tests.
5690 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5691 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5692 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005693 }
5694
David Benjamin8b8c0062014-11-23 02:47:52 -05005695 protocols := []protocol{tls}
5696 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5697 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005698 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005699 for _, protocol := range protocols {
5700 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5701 if protocol == dtls {
5702 suffix += "-DTLS"
5703 }
5704
David Benjaminece3de92015-03-16 18:02:20 -04005705 if sessionVers.version == resumeVers.version {
5706 testCases = append(testCases, testCase{
5707 protocol: protocol,
5708 name: "Resume-Client" + suffix,
5709 resumeSession: true,
5710 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005711 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005712 Bugs: ProtocolBugs{
5713 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5714 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5715 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005716 },
David Benjaminece3de92015-03-16 18:02:20 -04005717 expectedVersion: sessionVers.version,
5718 expectedResumeVersion: resumeVers.version,
5719 })
5720 } else {
David Benjamin405da482016-08-08 17:25:07 -04005721 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5722
5723 // Offering a TLS 1.3 session sends an empty session ID, so
5724 // there is no way to convince a non-lookahead client the
5725 // session was resumed. It will appear to the client that a
5726 // stray ChangeCipherSpec was sent.
5727 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5728 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005729 }
5730
David Benjaminece3de92015-03-16 18:02:20 -04005731 testCases = append(testCases, testCase{
5732 protocol: protocol,
5733 name: "Resume-Client-Mismatch" + suffix,
5734 resumeSession: true,
5735 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005736 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005737 },
David Benjaminece3de92015-03-16 18:02:20 -04005738 expectedVersion: sessionVers.version,
5739 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005740 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005741 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005742 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005743 },
5744 },
5745 expectedResumeVersion: resumeVers.version,
5746 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005747 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005748 })
5749 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005750
5751 testCases = append(testCases, testCase{
5752 protocol: protocol,
5753 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005754 resumeSession: true,
5755 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005756 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005757 },
5758 expectedVersion: sessionVers.version,
5759 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005760 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005761 },
5762 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005763 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005764 expectedResumeVersion: resumeVers.version,
5765 })
5766
David Benjamin8b8c0062014-11-23 02:47:52 -05005767 testCases = append(testCases, testCase{
5768 protocol: protocol,
5769 testType: serverTest,
5770 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005771 resumeSession: true,
5772 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005773 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005774 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005775 expectedVersion: sessionVers.version,
5776 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005777 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005778 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005779 Bugs: ProtocolBugs{
5780 SendBothTickets: true,
5781 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005782 },
5783 expectedResumeVersion: resumeVers.version,
5784 })
5785 }
David Benjamin01fe8202014-09-24 15:21:44 -04005786 }
5787 }
David Benjaminece3de92015-03-16 18:02:20 -04005788
David Benjamin4199b0d2016-11-01 13:58:25 -04005789 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005790 testCases = append(testCases, testCase{
5791 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005792 name: "ShimTicketRewritable",
5793 resumeSession: true,
5794 config: Config{
5795 MaxVersion: VersionTLS12,
5796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5797 Bugs: ProtocolBugs{
5798 FilterTicket: func(in []byte) ([]byte, error) {
5799 in, err := SetShimTicketVersion(in, VersionTLS12)
5800 if err != nil {
5801 return nil, err
5802 }
5803 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5804 },
5805 },
5806 },
5807 flags: []string{
5808 "-ticket-key",
5809 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5810 },
5811 })
5812
5813 // Resumptions are declined if the version does not match.
5814 testCases = append(testCases, testCase{
5815 testType: serverTest,
5816 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005817 resumeSession: true,
5818 config: Config{
5819 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005820 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005821 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005822 FilterTicket: func(in []byte) ([]byte, error) {
5823 return SetShimTicketVersion(in, VersionTLS13)
5824 },
5825 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005826 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005827 flags: []string{
5828 "-ticket-key",
5829 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5830 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005831 expectResumeRejected: true,
5832 })
5833
5834 testCases = append(testCases, testCase{
5835 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005836 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005837 resumeSession: true,
5838 config: Config{
5839 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005840 Bugs: ProtocolBugs{
5841 FilterTicket: func(in []byte) ([]byte, error) {
5842 return SetShimTicketVersion(in, VersionTLS12)
5843 },
5844 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005845 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005846 flags: []string{
5847 "-ticket-key",
5848 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5849 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005850 expectResumeRejected: true,
5851 })
5852
David Benjamin4199b0d2016-11-01 13:58:25 -04005853 // Resumptions are declined if the cipher is invalid or disabled.
5854 testCases = append(testCases, testCase{
5855 testType: serverTest,
5856 name: "Resume-Server-DeclineBadCipher",
5857 resumeSession: true,
5858 config: Config{
5859 MaxVersion: VersionTLS12,
5860 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005861 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005862 FilterTicket: func(in []byte) ([]byte, error) {
5863 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5864 },
5865 },
5866 },
5867 flags: []string{
5868 "-ticket-key",
5869 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5870 },
5871 expectResumeRejected: true,
5872 })
5873
5874 testCases = append(testCases, testCase{
5875 testType: serverTest,
5876 name: "Resume-Server-DeclineBadCipher-2",
5877 resumeSession: true,
5878 config: Config{
5879 MaxVersion: VersionTLS12,
5880 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005881 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005882 FilterTicket: func(in []byte) ([]byte, error) {
5883 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5884 },
5885 },
5886 },
5887 flags: []string{
5888 "-cipher", "AES128",
5889 "-ticket-key",
5890 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5891 },
5892 expectResumeRejected: true,
5893 })
5894
David Benjaminf01f42a2016-11-16 19:05:33 +09005895 // Sessions are not resumed if they do not use the preferred cipher.
5896 testCases = append(testCases, testCase{
5897 testType: serverTest,
5898 name: "Resume-Server-CipherNotPreferred",
5899 resumeSession: true,
5900 config: Config{
5901 MaxVersion: VersionTLS12,
5902 Bugs: ProtocolBugs{
5903 ExpectNewTicket: true,
5904 FilterTicket: func(in []byte) ([]byte, error) {
5905 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5906 },
5907 },
5908 },
5909 flags: []string{
5910 "-ticket-key",
5911 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5912 },
5913 shouldFail: false,
5914 expectResumeRejected: true,
5915 })
5916
5917 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5918 // PRF hashes match, but BoringSSL will always decline such resumptions.
5919 testCases = append(testCases, testCase{
5920 testType: serverTest,
5921 name: "Resume-Server-CipherNotPreferred-TLS13",
5922 resumeSession: true,
5923 config: Config{
5924 MaxVersion: VersionTLS13,
5925 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5926 Bugs: ProtocolBugs{
5927 FilterTicket: func(in []byte) ([]byte, error) {
5928 // If the client (runner) offers ChaCha20-Poly1305 first, the
5929 // server (shim) always prefers it. Switch it to AES-GCM.
5930 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5931 },
5932 },
5933 },
5934 flags: []string{
5935 "-ticket-key",
5936 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5937 },
5938 shouldFail: false,
5939 expectResumeRejected: true,
5940 })
5941
5942 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005943 testCases = append(testCases, testCase{
5944 testType: serverTest,
5945 name: "Resume-Server-DeclineBadCipher-TLS13",
5946 resumeSession: true,
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 Bugs: ProtocolBugs{
5950 FilterTicket: func(in []byte) ([]byte, error) {
5951 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5952 },
5953 },
5954 },
5955 flags: []string{
5956 "-ticket-key",
5957 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5958 },
5959 expectResumeRejected: true,
5960 })
5961
David Benjaminf01f42a2016-11-16 19:05:33 +09005962 // If the client does not offer the cipher from the session, decline to
5963 // resume. Clients are forbidden from doing this, but BoringSSL selects
5964 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005965 testCases = append(testCases, testCase{
5966 testType: serverTest,
5967 name: "Resume-Server-UnofferedCipher",
5968 resumeSession: true,
5969 config: Config{
5970 MaxVersion: VersionTLS12,
5971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5972 },
5973 resumeConfig: &Config{
5974 MaxVersion: VersionTLS12,
5975 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5976 Bugs: ProtocolBugs{
5977 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5978 },
5979 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005980 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005981 })
5982
David Benjaminf01f42a2016-11-16 19:05:33 +09005983 // In TLS 1.3, clients may advertise a cipher list which does not
5984 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05005985 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
5986 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005987 testCases = append(testCases, testCase{
5988 testType: serverTest,
5989 name: "Resume-Server-UnofferedCipher-TLS13",
5990 resumeSession: true,
5991 config: Config{
5992 MaxVersion: VersionTLS13,
5993 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5994 },
5995 resumeConfig: &Config{
5996 MaxVersion: VersionTLS13,
5997 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5998 Bugs: ProtocolBugs{
5999 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6000 },
6001 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006002 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006003 })
6004
David Benjamin4199b0d2016-11-01 13:58:25 -04006005 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006006 testCases = append(testCases, testCase{
6007 name: "Resume-Client-CipherMismatch",
6008 resumeSession: true,
6009 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006010 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006011 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6012 },
6013 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006014 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006015 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6016 Bugs: ProtocolBugs{
6017 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6018 },
6019 },
6020 shouldFail: true,
6021 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6022 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006023
David Benjamine1cc35e2016-11-16 16:25:58 +09006024 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6025 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006026 testCases = append(testCases, testCase{
6027 name: "Resume-Client-CipherMismatch-TLS13",
6028 resumeSession: true,
6029 config: Config{
6030 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006031 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006032 },
6033 resumeConfig: &Config{
6034 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006035 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6036 },
6037 })
6038
6039 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6040 testCases = append(testCases, testCase{
6041 name: "Resume-Client-PRFMismatch-TLS13",
6042 resumeSession: true,
6043 config: Config{
6044 MaxVersion: VersionTLS13,
6045 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6046 },
6047 resumeConfig: &Config{
6048 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006049 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006050 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006051 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006052 },
6053 },
6054 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006055 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006056 })
Steven Valdeza833c352016-11-01 13:39:36 -04006057
6058 testCases = append(testCases, testCase{
6059 testType: serverTest,
6060 name: "Resume-Server-BinderWrongLength",
6061 resumeSession: true,
6062 config: Config{
6063 MaxVersion: VersionTLS13,
6064 Bugs: ProtocolBugs{
6065 SendShortPSKBinder: true,
6066 },
6067 },
6068 shouldFail: true,
6069 expectedLocalError: "remote error: error decrypting message",
6070 expectedError: ":DIGEST_CHECK_FAILED:",
6071 })
6072
6073 testCases = append(testCases, testCase{
6074 testType: serverTest,
6075 name: "Resume-Server-NoPSKBinder",
6076 resumeSession: true,
6077 config: Config{
6078 MaxVersion: VersionTLS13,
6079 Bugs: ProtocolBugs{
6080 SendNoPSKBinder: true,
6081 },
6082 },
6083 shouldFail: true,
6084 expectedLocalError: "remote error: error decoding message",
6085 expectedError: ":DECODE_ERROR:",
6086 })
6087
6088 testCases = append(testCases, testCase{
6089 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006090 name: "Resume-Server-ExtraPSKBinder",
6091 resumeSession: true,
6092 config: Config{
6093 MaxVersion: VersionTLS13,
6094 Bugs: ProtocolBugs{
6095 SendExtraPSKBinder: true,
6096 },
6097 },
6098 shouldFail: true,
6099 expectedLocalError: "remote error: illegal parameter",
6100 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6101 })
6102
6103 testCases = append(testCases, testCase{
6104 testType: serverTest,
6105 name: "Resume-Server-ExtraIdentityNoBinder",
6106 resumeSession: true,
6107 config: Config{
6108 MaxVersion: VersionTLS13,
6109 Bugs: ProtocolBugs{
6110 ExtraPSKIdentity: true,
6111 },
6112 },
6113 shouldFail: true,
6114 expectedLocalError: "remote error: illegal parameter",
6115 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6116 })
6117
6118 testCases = append(testCases, testCase{
6119 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006120 name: "Resume-Server-InvalidPSKBinder",
6121 resumeSession: true,
6122 config: Config{
6123 MaxVersion: VersionTLS13,
6124 Bugs: ProtocolBugs{
6125 SendInvalidPSKBinder: true,
6126 },
6127 },
6128 shouldFail: true,
6129 expectedLocalError: "remote error: error decrypting message",
6130 expectedError: ":DIGEST_CHECK_FAILED:",
6131 })
6132
6133 testCases = append(testCases, testCase{
6134 testType: serverTest,
6135 name: "Resume-Server-PSKBinderFirstExtension",
6136 resumeSession: true,
6137 config: Config{
6138 MaxVersion: VersionTLS13,
6139 Bugs: ProtocolBugs{
6140 PSKBinderFirst: true,
6141 },
6142 },
6143 shouldFail: true,
6144 expectedLocalError: "remote error: illegal parameter",
6145 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6146 })
David Benjamin01fe8202014-09-24 15:21:44 -04006147}
6148
Adam Langley2ae77d22014-10-28 17:29:33 -07006149func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006150 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006151 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006152 testType: serverTest,
6153 name: "Renegotiate-Server-Forbidden",
6154 config: Config{
6155 MaxVersion: VersionTLS12,
6156 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006157 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006158 shouldFail: true,
6159 expectedError: ":NO_RENEGOTIATION:",
6160 expectedLocalError: "remote error: no renegotiation",
6161 })
Adam Langley5021b222015-06-12 18:27:58 -07006162 // The server shouldn't echo the renegotiation extension unless
6163 // requested by the client.
6164 testCases = append(testCases, testCase{
6165 testType: serverTest,
6166 name: "Renegotiate-Server-NoExt",
6167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006168 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006169 Bugs: ProtocolBugs{
6170 NoRenegotiationInfo: true,
6171 RequireRenegotiationInfo: true,
6172 },
6173 },
6174 shouldFail: true,
6175 expectedLocalError: "renegotiation extension missing",
6176 })
6177 // The renegotiation SCSV should be sufficient for the server to echo
6178 // the extension.
6179 testCases = append(testCases, testCase{
6180 testType: serverTest,
6181 name: "Renegotiate-Server-NoExt-SCSV",
6182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006183 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006184 Bugs: ProtocolBugs{
6185 NoRenegotiationInfo: true,
6186 SendRenegotiationSCSV: true,
6187 RequireRenegotiationInfo: true,
6188 },
6189 },
6190 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006191 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006192 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006194 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006195 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006196 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006197 },
6198 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006199 renegotiate: 1,
6200 flags: []string{
6201 "-renegotiate-freely",
6202 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006203 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006204 },
David Benjamincdea40c2015-03-19 14:09:43 -04006205 })
6206 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006207 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006208 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006210 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006211 Bugs: ProtocolBugs{
6212 EmptyRenegotiationInfo: true,
6213 },
6214 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006215 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006216 shouldFail: true,
6217 expectedError: ":RENEGOTIATION_MISMATCH:",
6218 })
6219 testCases = append(testCases, testCase{
6220 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006221 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006223 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006224 Bugs: ProtocolBugs{
6225 BadRenegotiationInfo: true,
6226 },
6227 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006228 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006229 shouldFail: true,
6230 expectedError: ":RENEGOTIATION_MISMATCH:",
6231 })
6232 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006233 name: "Renegotiate-Client-Downgrade",
6234 renegotiate: 1,
6235 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006236 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006237 Bugs: ProtocolBugs{
6238 NoRenegotiationInfoAfterInitial: true,
6239 },
6240 },
6241 flags: []string{"-renegotiate-freely"},
6242 shouldFail: true,
6243 expectedError: ":RENEGOTIATION_MISMATCH:",
6244 })
6245 testCases = append(testCases, testCase{
6246 name: "Renegotiate-Client-Upgrade",
6247 renegotiate: 1,
6248 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006249 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006250 Bugs: ProtocolBugs{
6251 NoRenegotiationInfoInInitial: true,
6252 },
6253 },
6254 flags: []string{"-renegotiate-freely"},
6255 shouldFail: true,
6256 expectedError: ":RENEGOTIATION_MISMATCH:",
6257 })
6258 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006259 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006260 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006262 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006263 Bugs: ProtocolBugs{
6264 NoRenegotiationInfo: true,
6265 },
6266 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006267 flags: []string{
6268 "-renegotiate-freely",
6269 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006270 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006271 },
David Benjamincff0b902015-05-15 23:09:47 -04006272 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006273
6274 // Test that the server may switch ciphers on renegotiation without
6275 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006276 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006277 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006278 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006279 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006280 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006281 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006282 },
6283 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006284 flags: []string{
6285 "-renegotiate-freely",
6286 "-expect-total-renegotiations", "1",
6287 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006288 })
6289 testCases = append(testCases, testCase{
6290 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006291 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006292 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006293 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006294 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6295 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006296 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006297 flags: []string{
6298 "-renegotiate-freely",
6299 "-expect-total-renegotiations", "1",
6300 },
David Benjaminb16346b2015-04-08 19:16:58 -04006301 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006302
6303 // Test that the server may not switch versions on renegotiation.
6304 testCases = append(testCases, testCase{
6305 name: "Renegotiate-Client-SwitchVersion",
6306 config: Config{
6307 MaxVersion: VersionTLS12,
6308 // Pick a cipher which exists at both versions.
6309 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6310 Bugs: ProtocolBugs{
6311 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006312 // Avoid failing early at the record layer.
6313 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006314 },
6315 },
6316 renegotiate: 1,
6317 flags: []string{
6318 "-renegotiate-freely",
6319 "-expect-total-renegotiations", "1",
6320 },
6321 shouldFail: true,
6322 expectedError: ":WRONG_SSL_VERSION:",
6323 })
6324
David Benjaminb16346b2015-04-08 19:16:58 -04006325 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006326 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006327 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006328 config: Config{
6329 MaxVersion: VersionTLS10,
6330 Bugs: ProtocolBugs{
6331 RequireSameRenegoClientVersion: true,
6332 },
6333 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006334 flags: []string{
6335 "-renegotiate-freely",
6336 "-expect-total-renegotiations", "1",
6337 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006338 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006339 testCases = append(testCases, testCase{
6340 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006341 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006342 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006343 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006344 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6345 NextProtos: []string{"foo"},
6346 },
6347 flags: []string{
6348 "-false-start",
6349 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006350 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006351 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006352 },
6353 shimWritesFirst: true,
6354 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006355
6356 // Client-side renegotiation controls.
6357 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006358 name: "Renegotiate-Client-Forbidden-1",
6359 config: Config{
6360 MaxVersion: VersionTLS12,
6361 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006362 renegotiate: 1,
6363 shouldFail: true,
6364 expectedError: ":NO_RENEGOTIATION:",
6365 expectedLocalError: "remote error: no renegotiation",
6366 })
6367 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006368 name: "Renegotiate-Client-Once-1",
6369 config: Config{
6370 MaxVersion: VersionTLS12,
6371 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006372 renegotiate: 1,
6373 flags: []string{
6374 "-renegotiate-once",
6375 "-expect-total-renegotiations", "1",
6376 },
6377 })
6378 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006379 name: "Renegotiate-Client-Freely-1",
6380 config: Config{
6381 MaxVersion: VersionTLS12,
6382 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006383 renegotiate: 1,
6384 flags: []string{
6385 "-renegotiate-freely",
6386 "-expect-total-renegotiations", "1",
6387 },
6388 })
6389 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006390 name: "Renegotiate-Client-Once-2",
6391 config: Config{
6392 MaxVersion: VersionTLS12,
6393 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006394 renegotiate: 2,
6395 flags: []string{"-renegotiate-once"},
6396 shouldFail: true,
6397 expectedError: ":NO_RENEGOTIATION:",
6398 expectedLocalError: "remote error: no renegotiation",
6399 })
6400 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006401 name: "Renegotiate-Client-Freely-2",
6402 config: Config{
6403 MaxVersion: VersionTLS12,
6404 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006405 renegotiate: 2,
6406 flags: []string{
6407 "-renegotiate-freely",
6408 "-expect-total-renegotiations", "2",
6409 },
6410 })
Adam Langley27a0d082015-11-03 13:34:10 -08006411 testCases = append(testCases, testCase{
6412 name: "Renegotiate-Client-NoIgnore",
6413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006414 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006415 Bugs: ProtocolBugs{
6416 SendHelloRequestBeforeEveryAppDataRecord: true,
6417 },
6418 },
6419 shouldFail: true,
6420 expectedError: ":NO_RENEGOTIATION:",
6421 })
6422 testCases = append(testCases, testCase{
6423 name: "Renegotiate-Client-Ignore",
6424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006425 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006426 Bugs: ProtocolBugs{
6427 SendHelloRequestBeforeEveryAppDataRecord: true,
6428 },
6429 },
6430 flags: []string{
6431 "-renegotiate-ignore",
6432 "-expect-total-renegotiations", "0",
6433 },
6434 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006435
David Benjamin34941c02016-10-08 11:45:31 -04006436 // Renegotiation is not allowed at SSL 3.0.
6437 testCases = append(testCases, testCase{
6438 name: "Renegotiate-Client-SSL3",
6439 config: Config{
6440 MaxVersion: VersionSSL30,
6441 },
6442 renegotiate: 1,
6443 flags: []string{
6444 "-renegotiate-freely",
6445 "-expect-total-renegotiations", "1",
6446 },
6447 shouldFail: true,
6448 expectedError: ":NO_RENEGOTIATION:",
6449 expectedLocalError: "remote error: no renegotiation",
6450 })
6451
David Benjamina1eaba12017-01-01 23:19:22 -05006452 // Renegotiation is not allowed when there is an unfinished write.
6453 testCases = append(testCases, testCase{
6454 name: "Renegotiate-Client-UnfinishedWrite",
6455 config: Config{
6456 MaxVersion: VersionTLS12,
6457 },
6458 renegotiate: 1,
6459 flags: []string{
6460 "-async",
6461 "-renegotiate-freely",
6462 "-read-with-unfinished-write",
6463 },
6464 shouldFail: true,
6465 expectedError: ":NO_RENEGOTIATION:",
6466 // We do not successfully send the no_renegotiation alert in
6467 // this case. https://crbug.com/boringssl/130
6468 })
6469
David Benjamin07ab5d42017-02-09 20:11:41 -05006470 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006471 testCases = append(testCases, testCase{
6472 name: "StrayHelloRequest",
6473 config: Config{
6474 MaxVersion: VersionTLS12,
6475 Bugs: ProtocolBugs{
6476 SendHelloRequestBeforeEveryHandshakeMessage: true,
6477 },
6478 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006479 shouldFail: true,
6480 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006481 })
6482 testCases = append(testCases, testCase{
6483 name: "StrayHelloRequest-Packed",
6484 config: Config{
6485 MaxVersion: VersionTLS12,
6486 Bugs: ProtocolBugs{
6487 PackHandshakeFlight: true,
6488 SendHelloRequestBeforeEveryHandshakeMessage: true,
6489 },
6490 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006491 shouldFail: true,
6492 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006493 })
6494
David Benjamin12d2c482016-07-24 10:56:51 -04006495 // Test renegotiation works if HelloRequest and server Finished come in
6496 // the same record.
6497 testCases = append(testCases, testCase{
6498 name: "Renegotiate-Client-Packed",
6499 config: Config{
6500 MaxVersion: VersionTLS12,
6501 Bugs: ProtocolBugs{
6502 PackHandshakeFlight: true,
6503 PackHelloRequestWithFinished: true,
6504 },
6505 },
6506 renegotiate: 1,
6507 flags: []string{
6508 "-renegotiate-freely",
6509 "-expect-total-renegotiations", "1",
6510 },
6511 })
6512
David Benjamin397c8e62016-07-08 14:14:36 -07006513 // Renegotiation is forbidden in TLS 1.3.
6514 testCases = append(testCases, testCase{
6515 name: "Renegotiate-Client-TLS13",
6516 config: Config{
6517 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006518 Bugs: ProtocolBugs{
6519 SendHelloRequestBeforeEveryAppDataRecord: true,
6520 },
David Benjamin397c8e62016-07-08 14:14:36 -07006521 },
David Benjamin397c8e62016-07-08 14:14:36 -07006522 flags: []string{
6523 "-renegotiate-freely",
6524 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006525 shouldFail: true,
6526 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006527 })
6528
6529 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6530 testCases = append(testCases, testCase{
6531 name: "StrayHelloRequest-TLS13",
6532 config: Config{
6533 MaxVersion: VersionTLS13,
6534 Bugs: ProtocolBugs{
6535 SendHelloRequestBeforeEveryHandshakeMessage: true,
6536 },
6537 },
6538 shouldFail: true,
6539 expectedError: ":UNEXPECTED_MESSAGE:",
6540 })
David Benjamind2610042017-01-03 10:49:28 -05006541
6542 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6543 // always reads as supporting it, regardless of whether it was
6544 // negotiated.
6545 testCases = append(testCases, testCase{
6546 name: "AlwaysReportRenegotiationInfo-TLS13",
6547 config: Config{
6548 MaxVersion: VersionTLS13,
6549 Bugs: ProtocolBugs{
6550 NoRenegotiationInfo: true,
6551 },
6552 },
6553 flags: []string{
6554 "-expect-secure-renegotiation",
6555 },
6556 })
David Benjamina58baaf2017-02-28 20:54:28 -05006557
6558 // Certificates may not change on renegotiation.
6559 testCases = append(testCases, testCase{
6560 name: "Renegotiation-CertificateChange",
6561 config: Config{
6562 MaxVersion: VersionTLS12,
6563 Certificates: []Certificate{rsaCertificate},
6564 Bugs: ProtocolBugs{
6565 RenegotiationCertificate: &rsaChainCertificate,
6566 },
6567 },
6568 renegotiate: 1,
6569 flags: []string{"-renegotiate-freely"},
6570 shouldFail: true,
6571 expectedError: ":SERVER_CERT_CHANGED:",
6572 })
6573 testCases = append(testCases, testCase{
6574 name: "Renegotiation-CertificateChange-2",
6575 config: Config{
6576 MaxVersion: VersionTLS12,
6577 Certificates: []Certificate{rsaCertificate},
6578 Bugs: ProtocolBugs{
6579 RenegotiationCertificate: &rsa1024Certificate,
6580 },
6581 },
6582 renegotiate: 1,
6583 flags: []string{"-renegotiate-freely"},
6584 shouldFail: true,
6585 expectedError: ":SERVER_CERT_CHANGED:",
6586 })
David Benjaminbbf42462017-03-14 21:27:10 -04006587
6588 // We do not negotiate ALPN after the initial handshake. This is
6589 // error-prone and only risks bugs in consumers.
6590 testCases = append(testCases, testCase{
6591 testType: clientTest,
6592 name: "Renegotiation-ForbidALPN",
6593 config: Config{
6594 MaxVersion: VersionTLS12,
6595 Bugs: ProtocolBugs{
6596 // Forcibly negotiate ALPN on both initial and
6597 // renegotiation handshakes. The test stack will
6598 // internally check the client does not offer
6599 // it.
6600 SendALPN: "foo",
6601 },
6602 },
6603 flags: []string{
6604 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6605 "-expect-alpn", "foo",
6606 "-renegotiate-freely",
6607 },
6608 renegotiate: 1,
6609 shouldFail: true,
6610 expectedError: ":UNEXPECTED_EXTENSION:",
6611 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006612}
6613
David Benjamin5e961c12014-11-07 01:48:35 -05006614func addDTLSReplayTests() {
6615 // Test that sequence number replays are detected.
6616 testCases = append(testCases, testCase{
6617 protocol: dtls,
6618 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006619 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006620 replayWrites: true,
6621 })
6622
David Benjamin8e6db492015-07-25 18:29:23 -04006623 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006624 // than the retransmit window.
6625 testCases = append(testCases, testCase{
6626 protocol: dtls,
6627 name: "DTLS-Replay-LargeGaps",
6628 config: Config{
6629 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006630 SequenceNumberMapping: func(in uint64) uint64 {
6631 return in * 127
6632 },
David Benjamin5e961c12014-11-07 01:48:35 -05006633 },
6634 },
David Benjamin8e6db492015-07-25 18:29:23 -04006635 messageCount: 200,
6636 replayWrites: true,
6637 })
6638
6639 // Test the incoming sequence number changing non-monotonically.
6640 testCases = append(testCases, testCase{
6641 protocol: dtls,
6642 name: "DTLS-Replay-NonMonotonic",
6643 config: Config{
6644 Bugs: ProtocolBugs{
6645 SequenceNumberMapping: func(in uint64) uint64 {
6646 return in ^ 31
6647 },
6648 },
6649 },
6650 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006651 replayWrites: true,
6652 })
6653}
6654
Nick Harper60edffd2016-06-21 15:19:24 -07006655var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006656 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006657 id signatureAlgorithm
6658 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006659}{
Nick Harper60edffd2016-06-21 15:19:24 -07006660 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6661 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6662 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6663 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006664 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006665 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6666 // hash function doesn't have to match the curve and so the same
6667 // signature algorithm works with P-224.
6668 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006669 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6670 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6671 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006672 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6673 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6674 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006675 // Tests for key types prior to TLS 1.2.
6676 {"RSA", 0, testCertRSA},
6677 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006678}
6679
Nick Harper60edffd2016-06-21 15:19:24 -07006680const fakeSigAlg1 signatureAlgorithm = 0x2a01
6681const fakeSigAlg2 signatureAlgorithm = 0xff01
6682
6683func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006684 // Not all ciphers involve a signature. Advertise a list which gives all
6685 // versions a signing cipher.
6686 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006687 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006688 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6689 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6690 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6691 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006692 }
6693 if *includeDHE {
6694 signingCiphers = append(signingCiphers, TLS_DHE_RSA_WITH_AES_128_CBC_SHA)
David Benjamin5208fd42016-07-13 21:43:25 -04006695 }
6696
David Benjaminca3d5452016-07-14 12:51:01 -04006697 var allAlgorithms []signatureAlgorithm
6698 for _, alg := range testSignatureAlgorithms {
6699 if alg.id != 0 {
6700 allAlgorithms = append(allAlgorithms, alg.id)
6701 }
6702 }
6703
Nick Harper60edffd2016-06-21 15:19:24 -07006704 // Make sure each signature algorithm works. Include some fake values in
6705 // the list and ensure they're ignored.
6706 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006707 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006708 if (ver.version < VersionTLS12) != (alg.id == 0) {
6709 continue
6710 }
6711
6712 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6713 // or remove it in C.
6714 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006715 continue
6716 }
Nick Harper60edffd2016-06-21 15:19:24 -07006717
David Benjamin3ef76972016-10-17 17:59:54 -04006718 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006719 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006720 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006721 shouldSignFail = true
6722 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006723 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006724 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08006725 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
6726 shouldSignFail = true
6727 shouldVerifyFail = true
6728 }
6729 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
6730 // the curve has to match the hash size.
6731 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04006732 shouldSignFail = true
6733 shouldVerifyFail = true
6734 }
6735
6736 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6737 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6738 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006739 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006740
6741 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006742 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006743 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006744 }
6745 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006746 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006747 }
David Benjamin000800a2014-11-14 01:43:59 -05006748
David Benjamin1fb125c2016-07-08 18:52:12 -07006749 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006750
David Benjamin7a41d372016-07-09 11:21:54 -07006751 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006752 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006753 config: Config{
6754 MaxVersion: ver.version,
6755 ClientAuth: RequireAnyClientCert,
6756 VerifySignatureAlgorithms: []signatureAlgorithm{
6757 fakeSigAlg1,
6758 alg.id,
6759 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006760 },
David Benjamin7a41d372016-07-09 11:21:54 -07006761 },
6762 flags: []string{
6763 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6764 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6765 "-enable-all-curves",
6766 },
David Benjamin3ef76972016-10-17 17:59:54 -04006767 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006768 expectedError: signError,
6769 expectedPeerSignatureAlgorithm: alg.id,
6770 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006771
David Benjamin7a41d372016-07-09 11:21:54 -07006772 testCases = append(testCases, testCase{
6773 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006774 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006775 config: Config{
6776 MaxVersion: ver.version,
6777 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6778 SignSignatureAlgorithms: []signatureAlgorithm{
6779 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006780 },
David Benjamin7a41d372016-07-09 11:21:54 -07006781 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006782 SkipECDSACurveCheck: shouldVerifyFail,
6783 IgnoreSignatureVersionChecks: shouldVerifyFail,
6784 // Some signature algorithms may not be advertised.
6785 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006786 },
David Benjamin7a41d372016-07-09 11:21:54 -07006787 },
6788 flags: []string{
6789 "-require-any-client-certificate",
6790 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6791 "-enable-all-curves",
6792 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006793 // Resume the session to assert the peer signature
6794 // algorithm is reported on both handshakes.
6795 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006796 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006797 expectedError: verifyError,
6798 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006799
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006800 // No signing cipher for SSL 3.0.
6801 if *includeDHE || ver.version > VersionSSL30 {
6802 testCases = append(testCases, testCase{
6803 testType: serverTest,
6804 name: "ServerAuth-Sign" + suffix,
6805 config: Config{
6806 MaxVersion: ver.version,
6807 CipherSuites: signingCiphers,
6808 VerifySignatureAlgorithms: []signatureAlgorithm{
6809 fakeSigAlg1,
6810 alg.id,
6811 fakeSigAlg2,
6812 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006813 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006814 flags: []string{
6815 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6816 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6817 "-enable-all-curves",
6818 },
6819 shouldFail: shouldSignFail,
6820 expectedError: signError,
6821 expectedPeerSignatureAlgorithm: alg.id,
6822 })
6823 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006824
6825 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006826 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006827 config: Config{
6828 MaxVersion: ver.version,
6829 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006830 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006831 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006832 alg.id,
6833 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006834 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006835 SkipECDSACurveCheck: shouldVerifyFail,
6836 IgnoreSignatureVersionChecks: shouldVerifyFail,
6837 // Some signature algorithms may not be advertised.
6838 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006839 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006840 },
6841 flags: []string{
6842 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6843 "-enable-all-curves",
6844 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006845 // Resume the session to assert the peer signature
6846 // algorithm is reported on both handshakes.
6847 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006848 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006849 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006850 })
David Benjamin5208fd42016-07-13 21:43:25 -04006851
David Benjamin3ef76972016-10-17 17:59:54 -04006852 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006853 testCases = append(testCases, testCase{
6854 testType: serverTest,
6855 name: "ClientAuth-InvalidSignature" + suffix,
6856 config: Config{
6857 MaxVersion: ver.version,
6858 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6859 SignSignatureAlgorithms: []signatureAlgorithm{
6860 alg.id,
6861 },
6862 Bugs: ProtocolBugs{
6863 InvalidSignature: true,
6864 },
6865 },
6866 flags: []string{
6867 "-require-any-client-certificate",
6868 "-enable-all-curves",
6869 },
6870 shouldFail: true,
6871 expectedError: ":BAD_SIGNATURE:",
6872 })
6873
6874 testCases = append(testCases, testCase{
6875 name: "ServerAuth-InvalidSignature" + suffix,
6876 config: Config{
6877 MaxVersion: ver.version,
6878 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6879 CipherSuites: signingCiphers,
6880 SignSignatureAlgorithms: []signatureAlgorithm{
6881 alg.id,
6882 },
6883 Bugs: ProtocolBugs{
6884 InvalidSignature: true,
6885 },
6886 },
6887 flags: []string{"-enable-all-curves"},
6888 shouldFail: true,
6889 expectedError: ":BAD_SIGNATURE:",
6890 })
6891 }
David Benjaminca3d5452016-07-14 12:51:01 -04006892
David Benjamin3ef76972016-10-17 17:59:54 -04006893 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006894 testCases = append(testCases, testCase{
6895 name: "ClientAuth-Sign-Negotiate" + suffix,
6896 config: Config{
6897 MaxVersion: ver.version,
6898 ClientAuth: RequireAnyClientCert,
6899 VerifySignatureAlgorithms: allAlgorithms,
6900 },
6901 flags: []string{
6902 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6903 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6904 "-enable-all-curves",
6905 "-signing-prefs", strconv.Itoa(int(alg.id)),
6906 },
6907 expectedPeerSignatureAlgorithm: alg.id,
6908 })
6909
6910 testCases = append(testCases, testCase{
6911 testType: serverTest,
6912 name: "ServerAuth-Sign-Negotiate" + suffix,
6913 config: Config{
6914 MaxVersion: ver.version,
6915 CipherSuites: signingCiphers,
6916 VerifySignatureAlgorithms: allAlgorithms,
6917 },
6918 flags: []string{
6919 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6920 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6921 "-enable-all-curves",
6922 "-signing-prefs", strconv.Itoa(int(alg.id)),
6923 },
6924 expectedPeerSignatureAlgorithm: alg.id,
6925 })
6926 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006927 }
David Benjamin000800a2014-11-14 01:43:59 -05006928 }
6929
Nick Harper60edffd2016-06-21 15:19:24 -07006930 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006931 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006932 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006933 config: Config{
6934 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006935 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006936 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006937 signatureECDSAWithP521AndSHA512,
6938 signatureRSAPKCS1WithSHA384,
6939 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006940 },
6941 },
6942 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006943 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6944 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006945 },
Nick Harper60edffd2016-06-21 15:19:24 -07006946 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006947 })
6948
6949 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006950 name: "ClientAuth-SignatureType-TLS13",
6951 config: Config{
6952 ClientAuth: RequireAnyClientCert,
6953 MaxVersion: VersionTLS13,
6954 VerifySignatureAlgorithms: []signatureAlgorithm{
6955 signatureECDSAWithP521AndSHA512,
6956 signatureRSAPKCS1WithSHA384,
6957 signatureRSAPSSWithSHA384,
6958 signatureECDSAWithSHA1,
6959 },
6960 },
6961 flags: []string{
6962 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6963 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6964 },
6965 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6966 })
6967
6968 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006969 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006970 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006972 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006974 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006975 signatureECDSAWithP521AndSHA512,
6976 signatureRSAPKCS1WithSHA384,
6977 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006978 },
6979 },
Nick Harper60edffd2016-06-21 15:19:24 -07006980 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006981 })
6982
Steven Valdez143e8b32016-07-11 13:19:03 -04006983 testCases = append(testCases, testCase{
6984 testType: serverTest,
6985 name: "ServerAuth-SignatureType-TLS13",
6986 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006987 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006988 VerifySignatureAlgorithms: []signatureAlgorithm{
6989 signatureECDSAWithP521AndSHA512,
6990 signatureRSAPKCS1WithSHA384,
6991 signatureRSAPSSWithSHA384,
6992 signatureECDSAWithSHA1,
6993 },
6994 },
6995 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6996 })
6997
David Benjamina95e9f32016-07-08 16:28:04 -07006998 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006999 testCases = append(testCases, testCase{
7000 testType: serverTest,
7001 name: "Verify-ClientAuth-SignatureType",
7002 config: Config{
7003 MaxVersion: VersionTLS12,
7004 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007005 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007006 signatureRSAPKCS1WithSHA256,
7007 },
7008 Bugs: ProtocolBugs{
7009 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7010 },
7011 },
7012 flags: []string{
7013 "-require-any-client-certificate",
7014 },
7015 shouldFail: true,
7016 expectedError: ":WRONG_SIGNATURE_TYPE:",
7017 })
7018
7019 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007020 testType: serverTest,
7021 name: "Verify-ClientAuth-SignatureType-TLS13",
7022 config: Config{
7023 MaxVersion: VersionTLS13,
7024 Certificates: []Certificate{rsaCertificate},
7025 SignSignatureAlgorithms: []signatureAlgorithm{
7026 signatureRSAPSSWithSHA256,
7027 },
7028 Bugs: ProtocolBugs{
7029 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7030 },
7031 },
7032 flags: []string{
7033 "-require-any-client-certificate",
7034 },
7035 shouldFail: true,
7036 expectedError: ":WRONG_SIGNATURE_TYPE:",
7037 })
7038
7039 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007040 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007041 config: Config{
7042 MaxVersion: VersionTLS12,
7043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007044 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007045 signatureRSAPKCS1WithSHA256,
7046 },
7047 Bugs: ProtocolBugs{
7048 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7049 },
7050 },
7051 shouldFail: true,
7052 expectedError: ":WRONG_SIGNATURE_TYPE:",
7053 })
7054
Steven Valdez143e8b32016-07-11 13:19:03 -04007055 testCases = append(testCases, testCase{
7056 name: "Verify-ServerAuth-SignatureType-TLS13",
7057 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007058 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007059 SignSignatureAlgorithms: []signatureAlgorithm{
7060 signatureRSAPSSWithSHA256,
7061 },
7062 Bugs: ProtocolBugs{
7063 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7064 },
7065 },
7066 shouldFail: true,
7067 expectedError: ":WRONG_SIGNATURE_TYPE:",
7068 })
7069
David Benjamin51dd7d62016-07-08 16:07:01 -07007070 // Test that, if the list is missing, the peer falls back to SHA-1 in
7071 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007072 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007073 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007075 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007076 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007077 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007078 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007079 },
7080 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007081 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007082 },
7083 },
7084 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007085 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7086 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007087 },
7088 })
7089
7090 testCases = append(testCases, testCase{
7091 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007092 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007093 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007094 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007095 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007096 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007097 },
7098 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007099 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007100 },
7101 },
David Benjaminee32bea2016-08-17 13:36:44 -04007102 flags: []string{
7103 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7104 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7105 },
7106 })
7107
7108 testCases = append(testCases, testCase{
7109 name: "ClientAuth-SHA1-Fallback-ECDSA",
7110 config: Config{
7111 MaxVersion: VersionTLS12,
7112 ClientAuth: RequireAnyClientCert,
7113 VerifySignatureAlgorithms: []signatureAlgorithm{
7114 signatureECDSAWithSHA1,
7115 },
7116 Bugs: ProtocolBugs{
7117 NoSignatureAlgorithms: true,
7118 },
7119 },
7120 flags: []string{
7121 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7122 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7123 },
7124 })
7125
7126 testCases = append(testCases, testCase{
7127 testType: serverTest,
7128 name: "ServerAuth-SHA1-Fallback-ECDSA",
7129 config: Config{
7130 MaxVersion: VersionTLS12,
7131 VerifySignatureAlgorithms: []signatureAlgorithm{
7132 signatureECDSAWithSHA1,
7133 },
7134 Bugs: ProtocolBugs{
7135 NoSignatureAlgorithms: true,
7136 },
7137 },
7138 flags: []string{
7139 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7140 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7141 },
David Benjamin000800a2014-11-14 01:43:59 -05007142 })
David Benjamin72dc7832015-03-16 17:49:43 -04007143
David Benjamin51dd7d62016-07-08 16:07:01 -07007144 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007145 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007146 config: Config{
7147 MaxVersion: VersionTLS13,
7148 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007149 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007150 signatureRSAPKCS1WithSHA1,
7151 },
7152 Bugs: ProtocolBugs{
7153 NoSignatureAlgorithms: true,
7154 },
7155 },
7156 flags: []string{
7157 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7158 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7159 },
David Benjamin48901652016-08-01 12:12:47 -04007160 shouldFail: true,
7161 // An empty CertificateRequest signature algorithm list is a
7162 // syntax error in TLS 1.3.
7163 expectedError: ":DECODE_ERROR:",
7164 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007165 })
7166
7167 testCases = append(testCases, testCase{
7168 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007169 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007170 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007171 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007172 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007173 signatureRSAPKCS1WithSHA1,
7174 },
7175 Bugs: ProtocolBugs{
7176 NoSignatureAlgorithms: true,
7177 },
7178 },
7179 shouldFail: true,
7180 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7181 })
7182
David Benjaminb62d2872016-07-18 14:55:02 +02007183 // Test that hash preferences are enforced. BoringSSL does not implement
7184 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007185 testCases = append(testCases, testCase{
7186 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007187 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007189 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007190 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007191 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007192 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007193 },
7194 Bugs: ProtocolBugs{
7195 IgnorePeerSignatureAlgorithmPreferences: true,
7196 },
7197 },
7198 flags: []string{"-require-any-client-certificate"},
7199 shouldFail: true,
7200 expectedError: ":WRONG_SIGNATURE_TYPE:",
7201 })
7202
7203 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007204 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007206 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007207 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007208 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007209 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007210 },
7211 Bugs: ProtocolBugs{
7212 IgnorePeerSignatureAlgorithmPreferences: true,
7213 },
7214 },
7215 shouldFail: true,
7216 expectedError: ":WRONG_SIGNATURE_TYPE:",
7217 })
David Benjaminb62d2872016-07-18 14:55:02 +02007218 testCases = append(testCases, testCase{
7219 testType: serverTest,
7220 name: "ClientAuth-Enforced-TLS13",
7221 config: Config{
7222 MaxVersion: VersionTLS13,
7223 Certificates: []Certificate{rsaCertificate},
7224 SignSignatureAlgorithms: []signatureAlgorithm{
7225 signatureRSAPKCS1WithMD5,
7226 },
7227 Bugs: ProtocolBugs{
7228 IgnorePeerSignatureAlgorithmPreferences: true,
7229 IgnoreSignatureVersionChecks: true,
7230 },
7231 },
7232 flags: []string{"-require-any-client-certificate"},
7233 shouldFail: true,
7234 expectedError: ":WRONG_SIGNATURE_TYPE:",
7235 })
7236
7237 testCases = append(testCases, testCase{
7238 name: "ServerAuth-Enforced-TLS13",
7239 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007240 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007241 SignSignatureAlgorithms: []signatureAlgorithm{
7242 signatureRSAPKCS1WithMD5,
7243 },
7244 Bugs: ProtocolBugs{
7245 IgnorePeerSignatureAlgorithmPreferences: true,
7246 IgnoreSignatureVersionChecks: true,
7247 },
7248 },
7249 shouldFail: true,
7250 expectedError: ":WRONG_SIGNATURE_TYPE:",
7251 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007252
7253 // Test that the agreed upon digest respects the client preferences and
7254 // the server digests.
7255 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007256 name: "NoCommonAlgorithms-Digests",
7257 config: Config{
7258 MaxVersion: VersionTLS12,
7259 ClientAuth: RequireAnyClientCert,
7260 VerifySignatureAlgorithms: []signatureAlgorithm{
7261 signatureRSAPKCS1WithSHA512,
7262 signatureRSAPKCS1WithSHA1,
7263 },
7264 },
7265 flags: []string{
7266 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7267 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7268 "-digest-prefs", "SHA256",
7269 },
7270 shouldFail: true,
7271 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7272 })
7273 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007274 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007275 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007276 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007277 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007278 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007279 signatureRSAPKCS1WithSHA512,
7280 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007281 },
7282 },
7283 flags: []string{
7284 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7285 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007286 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007287 },
David Benjaminca3d5452016-07-14 12:51:01 -04007288 shouldFail: true,
7289 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7290 })
7291 testCases = append(testCases, testCase{
7292 name: "NoCommonAlgorithms-TLS13",
7293 config: Config{
7294 MaxVersion: VersionTLS13,
7295 ClientAuth: RequireAnyClientCert,
7296 VerifySignatureAlgorithms: []signatureAlgorithm{
7297 signatureRSAPSSWithSHA512,
7298 signatureRSAPSSWithSHA384,
7299 },
7300 },
7301 flags: []string{
7302 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7303 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7304 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7305 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007306 shouldFail: true,
7307 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007308 })
7309 testCases = append(testCases, testCase{
7310 name: "Agree-Digest-SHA256",
7311 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007312 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007313 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007314 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007315 signatureRSAPKCS1WithSHA1,
7316 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007317 },
7318 },
7319 flags: []string{
7320 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7321 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007322 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007323 },
Nick Harper60edffd2016-06-21 15:19:24 -07007324 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007325 })
7326 testCases = append(testCases, testCase{
7327 name: "Agree-Digest-SHA1",
7328 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007329 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007330 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007331 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007332 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007333 },
7334 },
7335 flags: []string{
7336 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7337 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007338 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007339 },
Nick Harper60edffd2016-06-21 15:19:24 -07007340 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007341 })
7342 testCases = append(testCases, testCase{
7343 name: "Agree-Digest-Default",
7344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007345 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007346 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007347 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007348 signatureRSAPKCS1WithSHA256,
7349 signatureECDSAWithP256AndSHA256,
7350 signatureRSAPKCS1WithSHA1,
7351 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007352 },
7353 },
7354 flags: []string{
7355 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7356 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7357 },
Nick Harper60edffd2016-06-21 15:19:24 -07007358 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007359 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007360
David Benjaminca3d5452016-07-14 12:51:01 -04007361 // Test that the signing preference list may include extra algorithms
7362 // without negotiation problems.
7363 testCases = append(testCases, testCase{
7364 testType: serverTest,
7365 name: "FilterExtraAlgorithms",
7366 config: Config{
7367 MaxVersion: VersionTLS12,
7368 VerifySignatureAlgorithms: []signatureAlgorithm{
7369 signatureRSAPKCS1WithSHA256,
7370 },
7371 },
7372 flags: []string{
7373 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7374 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7375 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7376 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7377 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7378 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7379 },
7380 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7381 })
7382
David Benjamin4c3ddf72016-06-29 18:13:53 -04007383 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7384 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007385 testCases = append(testCases, testCase{
7386 name: "CheckLeafCurve",
7387 config: Config{
7388 MaxVersion: VersionTLS12,
7389 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007390 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007391 },
7392 flags: []string{"-p384-only"},
7393 shouldFail: true,
7394 expectedError: ":BAD_ECC_CERT:",
7395 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007396
7397 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7398 testCases = append(testCases, testCase{
7399 name: "CheckLeafCurve-TLS13",
7400 config: Config{
7401 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007402 Certificates: []Certificate{ecdsaP256Certificate},
7403 },
7404 flags: []string{"-p384-only"},
7405 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007406
7407 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7408 testCases = append(testCases, testCase{
7409 name: "ECDSACurveMismatch-Verify-TLS12",
7410 config: Config{
7411 MaxVersion: VersionTLS12,
7412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7413 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007414 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007415 signatureECDSAWithP384AndSHA384,
7416 },
7417 },
7418 })
7419
7420 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7421 testCases = append(testCases, testCase{
7422 name: "ECDSACurveMismatch-Verify-TLS13",
7423 config: Config{
7424 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007425 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007426 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007427 signatureECDSAWithP384AndSHA384,
7428 },
7429 Bugs: ProtocolBugs{
7430 SkipECDSACurveCheck: true,
7431 },
7432 },
7433 shouldFail: true,
7434 expectedError: ":WRONG_SIGNATURE_TYPE:",
7435 })
7436
7437 // Signature algorithm selection in TLS 1.3 should take the curve into
7438 // account.
7439 testCases = append(testCases, testCase{
7440 testType: serverTest,
7441 name: "ECDSACurveMismatch-Sign-TLS13",
7442 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007443 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007444 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007445 signatureECDSAWithP384AndSHA384,
7446 signatureECDSAWithP256AndSHA256,
7447 },
7448 },
7449 flags: []string{
7450 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7451 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7452 },
7453 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7454 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007455
7456 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7457 // server does not attempt to sign in that case.
7458 testCases = append(testCases, testCase{
7459 testType: serverTest,
7460 name: "RSA-PSS-Large",
7461 config: Config{
7462 MaxVersion: VersionTLS13,
7463 VerifySignatureAlgorithms: []signatureAlgorithm{
7464 signatureRSAPSSWithSHA512,
7465 },
7466 },
7467 flags: []string{
7468 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7469 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7470 },
7471 shouldFail: true,
7472 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7473 })
David Benjamin57e929f2016-08-30 00:30:38 -04007474
7475 // Test that RSA-PSS is enabled by default for TLS 1.2.
7476 testCases = append(testCases, testCase{
7477 testType: clientTest,
7478 name: "RSA-PSS-Default-Verify",
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 SignSignatureAlgorithms: []signatureAlgorithm{
7482 signatureRSAPSSWithSHA256,
7483 },
7484 },
7485 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7486 })
7487
7488 testCases = append(testCases, testCase{
7489 testType: serverTest,
7490 name: "RSA-PSS-Default-Sign",
7491 config: Config{
7492 MaxVersion: VersionTLS12,
7493 VerifySignatureAlgorithms: []signatureAlgorithm{
7494 signatureRSAPSSWithSHA256,
7495 },
7496 },
7497 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7498 })
David Benjamin000800a2014-11-14 01:43:59 -05007499}
7500
David Benjamin83f90402015-01-27 01:09:43 -05007501// timeouts is the retransmit schedule for BoringSSL. It doubles and
7502// caps at 60 seconds. On the 13th timeout, it gives up.
7503var timeouts = []time.Duration{
7504 1 * time.Second,
7505 2 * time.Second,
7506 4 * time.Second,
7507 8 * time.Second,
7508 16 * time.Second,
7509 32 * time.Second,
7510 60 * time.Second,
7511 60 * time.Second,
7512 60 * time.Second,
7513 60 * time.Second,
7514 60 * time.Second,
7515 60 * time.Second,
7516 60 * time.Second,
7517}
7518
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007519// shortTimeouts is an alternate set of timeouts which would occur if the
7520// initial timeout duration was set to 250ms.
7521var shortTimeouts = []time.Duration{
7522 250 * time.Millisecond,
7523 500 * time.Millisecond,
7524 1 * time.Second,
7525 2 * time.Second,
7526 4 * time.Second,
7527 8 * time.Second,
7528 16 * time.Second,
7529 32 * time.Second,
7530 60 * time.Second,
7531 60 * time.Second,
7532 60 * time.Second,
7533 60 * time.Second,
7534 60 * time.Second,
7535}
7536
David Benjamin83f90402015-01-27 01:09:43 -05007537func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007538 // These tests work by coordinating some behavior on both the shim and
7539 // the runner.
7540 //
7541 // TimeoutSchedule configures the runner to send a series of timeout
7542 // opcodes to the shim (see packetAdaptor) immediately before reading
7543 // each peer handshake flight N. The timeout opcode both simulates a
7544 // timeout in the shim and acts as a synchronization point to help the
7545 // runner bracket each handshake flight.
7546 //
7547 // We assume the shim does not read from the channel eagerly. It must
7548 // first wait until it has sent flight N and is ready to receive
7549 // handshake flight N+1. At this point, it will process the timeout
7550 // opcode. It must then immediately respond with a timeout ACK and act
7551 // as if the shim was idle for the specified amount of time.
7552 //
7553 // The runner then drops all packets received before the ACK and
7554 // continues waiting for flight N. This ordering results in one attempt
7555 // at sending flight N to be dropped. For the test to complete, the
7556 // shim must send flight N again, testing that the shim implements DTLS
7557 // retransmit on a timeout.
7558
Steven Valdez143e8b32016-07-11 13:19:03 -04007559 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007560 // likely be more epochs to cross and the final message's retransmit may
7561 // be more complex.
7562
David Benjamin11c82892017-02-23 20:40:31 -05007563 // Test that this is indeed the timeout schedule. Stress all
7564 // four patterns of handshake.
7565 for i := 1; i < len(timeouts); i++ {
7566 number := strconv.Itoa(i)
7567 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007568 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05007569 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007570 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007571 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007572 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007573 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007574 },
7575 },
7576 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007577 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007578 })
David Benjamin11c82892017-02-23 20:40:31 -05007579 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007580 protocol: dtls,
7581 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05007582 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007584 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007585 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007586 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007587 },
7588 },
7589 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007590 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007591 })
7592 }
David Benjamin11c82892017-02-23 20:40:31 -05007593
7594 // Test that exceeding the timeout schedule hits a read
7595 // timeout.
7596 testCases = append(testCases, testCase{
7597 protocol: dtls,
7598 name: "DTLS-Retransmit-Timeout",
7599 config: Config{
7600 MaxVersion: VersionTLS12,
7601 Bugs: ProtocolBugs{
7602 TimeoutSchedule: timeouts,
7603 },
7604 },
7605 resumeSession: true,
7606 flags: []string{"-async"},
7607 shouldFail: true,
7608 expectedError: ":READ_TIMEOUT_EXPIRED:",
7609 })
7610
7611 // Test that timeout handling has a fudge factor, due to API
7612 // problems.
7613 testCases = append(testCases, testCase{
7614 protocol: dtls,
7615 name: "DTLS-Retransmit-Fudge",
7616 config: Config{
7617 MaxVersion: VersionTLS12,
7618 Bugs: ProtocolBugs{
7619 TimeoutSchedule: []time.Duration{
7620 timeouts[0] - 10*time.Millisecond,
7621 },
7622 },
7623 },
7624 resumeSession: true,
7625 flags: []string{"-async"},
7626 })
7627
7628 // Test that the final Finished retransmitting isn't
7629 // duplicated if the peer badly fragments everything.
7630 testCases = append(testCases, testCase{
7631 testType: serverTest,
7632 protocol: dtls,
7633 name: "DTLS-Retransmit-Fragmented",
7634 config: Config{
7635 MaxVersion: VersionTLS12,
7636 Bugs: ProtocolBugs{
7637 TimeoutSchedule: []time.Duration{timeouts[0]},
7638 MaxHandshakeRecordLength: 2,
7639 },
7640 },
7641 flags: []string{"-async"},
7642 })
7643
7644 // Test the timeout schedule when a shorter initial timeout duration is set.
7645 testCases = append(testCases, testCase{
7646 protocol: dtls,
7647 name: "DTLS-Retransmit-Short-Client",
7648 config: Config{
7649 MaxVersion: VersionTLS12,
7650 Bugs: ProtocolBugs{
7651 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7652 },
7653 },
7654 resumeSession: true,
7655 flags: []string{
7656 "-async",
7657 "-initial-timeout-duration-ms", "250",
7658 },
7659 })
7660 testCases = append(testCases, testCase{
7661 protocol: dtls,
7662 testType: serverTest,
7663 name: "DTLS-Retransmit-Short-Server",
7664 config: Config{
7665 MaxVersion: VersionTLS12,
7666 Bugs: ProtocolBugs{
7667 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7668 },
7669 },
7670 resumeSession: true,
7671 flags: []string{
7672 "-async",
7673 "-initial-timeout-duration-ms", "250",
7674 },
7675 })
David Benjamin83f90402015-01-27 01:09:43 -05007676}
7677
David Benjaminc565ebb2015-04-03 04:06:36 -04007678func addExportKeyingMaterialTests() {
7679 for _, vers := range tlsVersions {
7680 if vers.version == VersionSSL30 {
7681 continue
7682 }
7683 testCases = append(testCases, testCase{
7684 name: "ExportKeyingMaterial-" + vers.name,
7685 config: Config{
7686 MaxVersion: vers.version,
7687 },
7688 exportKeyingMaterial: 1024,
7689 exportLabel: "label",
7690 exportContext: "context",
7691 useExportContext: true,
7692 })
7693 testCases = append(testCases, testCase{
7694 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7695 config: Config{
7696 MaxVersion: vers.version,
7697 },
7698 exportKeyingMaterial: 1024,
7699 })
7700 testCases = append(testCases, testCase{
7701 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7702 config: Config{
7703 MaxVersion: vers.version,
7704 },
7705 exportKeyingMaterial: 1024,
7706 useExportContext: true,
7707 })
7708 testCases = append(testCases, testCase{
7709 name: "ExportKeyingMaterial-Small-" + vers.name,
7710 config: Config{
7711 MaxVersion: vers.version,
7712 },
7713 exportKeyingMaterial: 1,
7714 exportLabel: "label",
7715 exportContext: "context",
7716 useExportContext: true,
7717 })
7718 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007719
David Benjaminc565ebb2015-04-03 04:06:36 -04007720 testCases = append(testCases, testCase{
7721 name: "ExportKeyingMaterial-SSL3",
7722 config: Config{
7723 MaxVersion: VersionSSL30,
7724 },
7725 exportKeyingMaterial: 1024,
7726 exportLabel: "label",
7727 exportContext: "context",
7728 useExportContext: true,
7729 shouldFail: true,
7730 expectedError: "failed to export keying material",
7731 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007732
7733 // Exporters work during a False Start.
7734 testCases = append(testCases, testCase{
7735 name: "ExportKeyingMaterial-FalseStart",
7736 config: Config{
7737 MaxVersion: VersionTLS12,
7738 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7739 NextProtos: []string{"foo"},
7740 Bugs: ProtocolBugs{
7741 ExpectFalseStart: true,
7742 },
7743 },
7744 flags: []string{
7745 "-false-start",
7746 "-advertise-alpn", "\x03foo",
7747 },
7748 shimWritesFirst: true,
7749 exportKeyingMaterial: 1024,
7750 exportLabel: "label",
7751 exportContext: "context",
7752 useExportContext: true,
7753 })
7754
7755 // Exporters do not work in the middle of a renegotiation. Test this by
7756 // triggering the exporter after every SSL_read call and configuring the
7757 // shim to run asynchronously.
7758 testCases = append(testCases, testCase{
7759 name: "ExportKeyingMaterial-Renegotiate",
7760 config: Config{
7761 MaxVersion: VersionTLS12,
7762 },
7763 renegotiate: 1,
7764 flags: []string{
7765 "-async",
7766 "-use-exporter-between-reads",
7767 "-renegotiate-freely",
7768 "-expect-total-renegotiations", "1",
7769 },
7770 shouldFail: true,
7771 expectedError: "failed to export keying material",
7772 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007773}
7774
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007775func addTLSUniqueTests() {
7776 for _, isClient := range []bool{false, true} {
7777 for _, isResumption := range []bool{false, true} {
7778 for _, hasEMS := range []bool{false, true} {
7779 var suffix string
7780 if isResumption {
7781 suffix = "Resume-"
7782 } else {
7783 suffix = "Full-"
7784 }
7785
7786 if hasEMS {
7787 suffix += "EMS-"
7788 } else {
7789 suffix += "NoEMS-"
7790 }
7791
7792 if isClient {
7793 suffix += "Client"
7794 } else {
7795 suffix += "Server"
7796 }
7797
7798 test := testCase{
7799 name: "TLSUnique-" + suffix,
7800 testTLSUnique: true,
7801 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007802 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007803 Bugs: ProtocolBugs{
7804 NoExtendedMasterSecret: !hasEMS,
7805 },
7806 },
7807 }
7808
7809 if isResumption {
7810 test.resumeSession = true
7811 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007812 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007813 Bugs: ProtocolBugs{
7814 NoExtendedMasterSecret: !hasEMS,
7815 },
7816 }
7817 }
7818
7819 if isResumption && !hasEMS {
7820 test.shouldFail = true
7821 test.expectedError = "failed to get tls-unique"
7822 }
7823
7824 testCases = append(testCases, test)
7825 }
7826 }
7827 }
7828}
7829
Adam Langley09505632015-07-30 18:10:13 -07007830func addCustomExtensionTests() {
7831 expectedContents := "custom extension"
7832 emptyString := ""
7833
7834 for _, isClient := range []bool{false, true} {
7835 suffix := "Server"
7836 flag := "-enable-server-custom-extension"
7837 testType := serverTest
7838 if isClient {
7839 suffix = "Client"
7840 flag = "-enable-client-custom-extension"
7841 testType = clientTest
7842 }
7843
7844 testCases = append(testCases, testCase{
7845 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007846 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007848 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007849 Bugs: ProtocolBugs{
7850 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007851 ExpectedCustomExtension: &expectedContents,
7852 },
7853 },
7854 flags: []string{flag},
7855 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007856 testCases = append(testCases, testCase{
7857 testType: testType,
7858 name: "CustomExtensions-" + suffix + "-TLS13",
7859 config: Config{
7860 MaxVersion: VersionTLS13,
7861 Bugs: ProtocolBugs{
7862 CustomExtension: expectedContents,
7863 ExpectedCustomExtension: &expectedContents,
7864 },
7865 },
7866 flags: []string{flag},
7867 })
Adam Langley09505632015-07-30 18:10:13 -07007868
Steven Valdez2a070722017-03-25 20:54:16 -05007869 // 0-RTT is not currently supported with Custom Extensions.
7870 testCases = append(testCases, testCase{
7871 testType: testType,
7872 name: "CustomExtensions-" + suffix + "-EarlyData",
7873 config: Config{
7874 MaxVersion: VersionTLS13,
7875 Bugs: ProtocolBugs{
7876 CustomExtension: expectedContents,
7877 ExpectedCustomExtension: &expectedContents,
7878 },
7879 },
7880 shouldFail: true,
7881 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7882 flags: []string{flag, "-enable-early-data"},
7883 })
7884
Adam Langley09505632015-07-30 18:10:13 -07007885 // If the parse callback fails, the handshake should also fail.
7886 testCases = append(testCases, testCase{
7887 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007888 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007889 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007890 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007891 Bugs: ProtocolBugs{
7892 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007893 ExpectedCustomExtension: &expectedContents,
7894 },
7895 },
David Benjamin399e7c92015-07-30 23:01:27 -04007896 flags: []string{flag},
7897 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007898 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7899 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007900 testCases = append(testCases, testCase{
7901 testType: testType,
7902 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7903 config: Config{
7904 MaxVersion: VersionTLS13,
7905 Bugs: ProtocolBugs{
7906 CustomExtension: expectedContents + "foo",
7907 ExpectedCustomExtension: &expectedContents,
7908 },
7909 },
7910 flags: []string{flag},
7911 shouldFail: true,
7912 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7913 })
Adam Langley09505632015-07-30 18:10:13 -07007914
7915 // If the add callback fails, the handshake should also fail.
7916 testCases = append(testCases, testCase{
7917 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007918 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007920 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007921 Bugs: ProtocolBugs{
7922 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007923 ExpectedCustomExtension: &expectedContents,
7924 },
7925 },
David Benjamin399e7c92015-07-30 23:01:27 -04007926 flags: []string{flag, "-custom-extension-fail-add"},
7927 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007928 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7929 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007930 testCases = append(testCases, testCase{
7931 testType: testType,
7932 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7933 config: Config{
7934 MaxVersion: VersionTLS13,
7935 Bugs: ProtocolBugs{
7936 CustomExtension: expectedContents,
7937 ExpectedCustomExtension: &expectedContents,
7938 },
7939 },
7940 flags: []string{flag, "-custom-extension-fail-add"},
7941 shouldFail: true,
7942 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7943 })
Adam Langley09505632015-07-30 18:10:13 -07007944
7945 // If the add callback returns zero, no extension should be
7946 // added.
7947 skipCustomExtension := expectedContents
7948 if isClient {
7949 // For the case where the client skips sending the
7950 // custom extension, the server must not “echo” it.
7951 skipCustomExtension = ""
7952 }
7953 testCases = append(testCases, testCase{
7954 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007955 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007957 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007958 Bugs: ProtocolBugs{
7959 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007960 ExpectedCustomExtension: &emptyString,
7961 },
7962 },
7963 flags: []string{flag, "-custom-extension-skip"},
7964 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007965 testCases = append(testCases, testCase{
7966 testType: testType,
7967 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7968 config: Config{
7969 MaxVersion: VersionTLS13,
7970 Bugs: ProtocolBugs{
7971 CustomExtension: skipCustomExtension,
7972 ExpectedCustomExtension: &emptyString,
7973 },
7974 },
7975 flags: []string{flag, "-custom-extension-skip"},
7976 })
Adam Langley09505632015-07-30 18:10:13 -07007977 }
7978
7979 // The custom extension add callback should not be called if the client
7980 // doesn't send the extension.
7981 testCases = append(testCases, testCase{
7982 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007983 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007985 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007986 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007987 ExpectedCustomExtension: &emptyString,
7988 },
7989 },
7990 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7991 })
Adam Langley2deb9842015-08-07 11:15:37 -07007992
Steven Valdez143e8b32016-07-11 13:19:03 -04007993 testCases = append(testCases, testCase{
7994 testType: serverTest,
7995 name: "CustomExtensions-NotCalled-Server-TLS13",
7996 config: Config{
7997 MaxVersion: VersionTLS13,
7998 Bugs: ProtocolBugs{
7999 ExpectedCustomExtension: &emptyString,
8000 },
8001 },
8002 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8003 })
8004
Adam Langley2deb9842015-08-07 11:15:37 -07008005 // Test an unknown extension from the server.
8006 testCases = append(testCases, testCase{
8007 testType: clientTest,
8008 name: "UnknownExtension-Client",
8009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008010 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008011 Bugs: ProtocolBugs{
8012 CustomExtension: expectedContents,
8013 },
8014 },
David Benjamin0c40a962016-08-01 12:05:50 -04008015 shouldFail: true,
8016 expectedError: ":UNEXPECTED_EXTENSION:",
8017 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008018 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008019 testCases = append(testCases, testCase{
8020 testType: clientTest,
8021 name: "UnknownExtension-Client-TLS13",
8022 config: Config{
8023 MaxVersion: VersionTLS13,
8024 Bugs: ProtocolBugs{
8025 CustomExtension: expectedContents,
8026 },
8027 },
David Benjamin0c40a962016-08-01 12:05:50 -04008028 shouldFail: true,
8029 expectedError: ":UNEXPECTED_EXTENSION:",
8030 expectedLocalError: "remote error: unsupported extension",
8031 })
David Benjamin490469f2016-10-05 22:44:38 -04008032 testCases = append(testCases, testCase{
8033 testType: clientTest,
8034 name: "UnknownUnencryptedExtension-Client-TLS13",
8035 config: Config{
8036 MaxVersion: VersionTLS13,
8037 Bugs: ProtocolBugs{
8038 CustomUnencryptedExtension: expectedContents,
8039 },
8040 },
8041 shouldFail: true,
8042 expectedError: ":UNEXPECTED_EXTENSION:",
8043 // The shim must send an alert, but alerts at this point do not
8044 // get successfully decrypted by the runner.
8045 expectedLocalError: "local error: bad record MAC",
8046 })
8047 testCases = append(testCases, testCase{
8048 testType: clientTest,
8049 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8050 config: Config{
8051 MaxVersion: VersionTLS13,
8052 Bugs: ProtocolBugs{
8053 SendUnencryptedALPN: "foo",
8054 },
8055 },
8056 flags: []string{
8057 "-advertise-alpn", "\x03foo\x03bar",
8058 },
8059 shouldFail: true,
8060 expectedError: ":UNEXPECTED_EXTENSION:",
8061 // The shim must send an alert, but alerts at this point do not
8062 // get successfully decrypted by the runner.
8063 expectedLocalError: "local error: bad record MAC",
8064 })
David Benjamin0c40a962016-08-01 12:05:50 -04008065
8066 // Test a known but unoffered extension from the server.
8067 testCases = append(testCases, testCase{
8068 testType: clientTest,
8069 name: "UnofferedExtension-Client",
8070 config: Config{
8071 MaxVersion: VersionTLS12,
8072 Bugs: ProtocolBugs{
8073 SendALPN: "alpn",
8074 },
8075 },
8076 shouldFail: true,
8077 expectedError: ":UNEXPECTED_EXTENSION:",
8078 expectedLocalError: "remote error: unsupported extension",
8079 })
8080 testCases = append(testCases, testCase{
8081 testType: clientTest,
8082 name: "UnofferedExtension-Client-TLS13",
8083 config: Config{
8084 MaxVersion: VersionTLS13,
8085 Bugs: ProtocolBugs{
8086 SendALPN: "alpn",
8087 },
8088 },
8089 shouldFail: true,
8090 expectedError: ":UNEXPECTED_EXTENSION:",
8091 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008092 })
Adam Langley09505632015-07-30 18:10:13 -07008093}
8094
David Benjaminb36a3952015-12-01 18:53:13 -05008095func addRSAClientKeyExchangeTests() {
8096 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8097 testCases = append(testCases, testCase{
8098 testType: serverTest,
8099 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8100 config: Config{
8101 // Ensure the ClientHello version and final
8102 // version are different, to detect if the
8103 // server uses the wrong one.
8104 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008105 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008106 Bugs: ProtocolBugs{
8107 BadRSAClientKeyExchange: bad,
8108 },
8109 },
8110 shouldFail: true,
8111 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8112 })
8113 }
David Benjamine63d9d72016-09-19 18:27:34 -04008114
8115 // The server must compare whatever was in ClientHello.version for the
8116 // RSA premaster.
8117 testCases = append(testCases, testCase{
8118 testType: serverTest,
8119 name: "SendClientVersion-RSA",
8120 config: Config{
8121 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8122 Bugs: ProtocolBugs{
8123 SendClientVersion: 0x1234,
8124 },
8125 },
8126 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8127 })
David Benjaminb36a3952015-12-01 18:53:13 -05008128}
8129
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008130var testCurves = []struct {
8131 name string
8132 id CurveID
8133}{
Adam Langley764ab982017-03-10 18:01:30 -08008134 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008135 {"P-256", CurveP256},
8136 {"P-384", CurveP384},
8137 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008138 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008139}
8140
Steven Valdez5440fe02016-07-18 12:40:30 -04008141const bogusCurve = 0x1234
8142
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008143func addCurveTests() {
8144 for _, curve := range testCurves {
8145 testCases = append(testCases, testCase{
8146 name: "CurveTest-Client-" + curve.name,
8147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008148 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008149 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8150 CurvePreferences: []CurveID{curve.id},
8151 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008152 flags: []string{
8153 "-enable-all-curves",
8154 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8155 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008156 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008157 })
8158 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008159 name: "CurveTest-Client-" + curve.name + "-TLS13",
8160 config: Config{
8161 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008162 CurvePreferences: []CurveID{curve.id},
8163 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008164 flags: []string{
8165 "-enable-all-curves",
8166 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8167 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008168 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008169 })
8170 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008171 testType: serverTest,
8172 name: "CurveTest-Server-" + curve.name,
8173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008174 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8176 CurvePreferences: []CurveID{curve.id},
8177 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008178 flags: []string{
8179 "-enable-all-curves",
8180 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8181 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008182 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008183 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008184 testCases = append(testCases, testCase{
8185 testType: serverTest,
8186 name: "CurveTest-Server-" + curve.name + "-TLS13",
8187 config: Config{
8188 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008189 CurvePreferences: []CurveID{curve.id},
8190 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008191 flags: []string{
8192 "-enable-all-curves",
8193 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8194 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008195 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008196 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008197 }
David Benjamin241ae832016-01-15 03:04:54 -05008198
8199 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008200 testCases = append(testCases, testCase{
8201 testType: serverTest,
8202 name: "UnknownCurve",
8203 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008204 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8206 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8207 },
8208 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008209
Steven Valdez803c77a2016-09-06 14:13:43 -04008210 // The server must be tolerant to bogus curves.
8211 testCases = append(testCases, testCase{
8212 testType: serverTest,
8213 name: "UnknownCurve-TLS13",
8214 config: Config{
8215 MaxVersion: VersionTLS13,
8216 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8217 },
8218 })
8219
David Benjamin4c3ddf72016-06-29 18:13:53 -04008220 // The server must not consider ECDHE ciphers when there are no
8221 // supported curves.
8222 testCases = append(testCases, testCase{
8223 testType: serverTest,
8224 name: "NoSupportedCurves",
8225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008226 MaxVersion: VersionTLS12,
8227 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8228 Bugs: ProtocolBugs{
8229 NoSupportedCurves: true,
8230 },
8231 },
8232 shouldFail: true,
8233 expectedError: ":NO_SHARED_CIPHER:",
8234 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008235 testCases = append(testCases, testCase{
8236 testType: serverTest,
8237 name: "NoSupportedCurves-TLS13",
8238 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008239 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008240 Bugs: ProtocolBugs{
8241 NoSupportedCurves: true,
8242 },
8243 },
8244 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008245 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008246 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008247
8248 // The server must fall back to another cipher when there are no
8249 // supported curves.
8250 testCases = append(testCases, testCase{
8251 testType: serverTest,
8252 name: "NoCommonCurves",
8253 config: Config{
8254 MaxVersion: VersionTLS12,
8255 CipherSuites: []uint16{
8256 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008257 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008258 },
8259 CurvePreferences: []CurveID{CurveP224},
8260 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008261 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008262 })
8263
8264 // The client must reject bogus curves and disabled curves.
8265 testCases = append(testCases, testCase{
8266 name: "BadECDHECurve",
8267 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008268 MaxVersion: VersionTLS12,
8269 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8270 Bugs: ProtocolBugs{
8271 SendCurve: bogusCurve,
8272 },
8273 },
8274 shouldFail: true,
8275 expectedError: ":WRONG_CURVE:",
8276 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008277 testCases = append(testCases, testCase{
8278 name: "BadECDHECurve-TLS13",
8279 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008280 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008281 Bugs: ProtocolBugs{
8282 SendCurve: bogusCurve,
8283 },
8284 },
8285 shouldFail: true,
8286 expectedError: ":WRONG_CURVE:",
8287 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008288
8289 testCases = append(testCases, testCase{
8290 name: "UnsupportedCurve",
8291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008292 MaxVersion: VersionTLS12,
8293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8294 CurvePreferences: []CurveID{CurveP256},
8295 Bugs: ProtocolBugs{
8296 IgnorePeerCurvePreferences: true,
8297 },
8298 },
8299 flags: []string{"-p384-only"},
8300 shouldFail: true,
8301 expectedError: ":WRONG_CURVE:",
8302 })
8303
David Benjamin4f921572016-07-17 14:20:10 +02008304 testCases = append(testCases, testCase{
8305 // TODO(davidben): Add a TLS 1.3 version where
8306 // HelloRetryRequest requests an unsupported curve.
8307 name: "UnsupportedCurve-ServerHello-TLS13",
8308 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008309 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008310 CurvePreferences: []CurveID{CurveP384},
8311 Bugs: ProtocolBugs{
8312 SendCurve: CurveP256,
8313 },
8314 },
8315 flags: []string{"-p384-only"},
8316 shouldFail: true,
8317 expectedError: ":WRONG_CURVE:",
8318 })
8319
David Benjamin4c3ddf72016-06-29 18:13:53 -04008320 // Test invalid curve points.
8321 testCases = append(testCases, testCase{
8322 name: "InvalidECDHPoint-Client",
8323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008324 MaxVersion: VersionTLS12,
8325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8326 CurvePreferences: []CurveID{CurveP256},
8327 Bugs: ProtocolBugs{
8328 InvalidECDHPoint: true,
8329 },
8330 },
8331 shouldFail: true,
8332 expectedError: ":INVALID_ENCODING:",
8333 })
8334 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008335 name: "InvalidECDHPoint-Client-TLS13",
8336 config: Config{
8337 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008338 CurvePreferences: []CurveID{CurveP256},
8339 Bugs: ProtocolBugs{
8340 InvalidECDHPoint: true,
8341 },
8342 },
8343 shouldFail: true,
8344 expectedError: ":INVALID_ENCODING:",
8345 })
8346 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008347 testType: serverTest,
8348 name: "InvalidECDHPoint-Server",
8349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008350 MaxVersion: VersionTLS12,
8351 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8352 CurvePreferences: []CurveID{CurveP256},
8353 Bugs: ProtocolBugs{
8354 InvalidECDHPoint: true,
8355 },
8356 },
8357 shouldFail: true,
8358 expectedError: ":INVALID_ENCODING:",
8359 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008360 testCases = append(testCases, testCase{
8361 testType: serverTest,
8362 name: "InvalidECDHPoint-Server-TLS13",
8363 config: Config{
8364 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008365 CurvePreferences: []CurveID{CurveP256},
8366 Bugs: ProtocolBugs{
8367 InvalidECDHPoint: true,
8368 },
8369 },
8370 shouldFail: true,
8371 expectedError: ":INVALID_ENCODING:",
8372 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008373
8374 // The previous curve ID should be reported on TLS 1.2 resumption.
8375 testCases = append(testCases, testCase{
8376 name: "CurveID-Resume-Client",
8377 config: Config{
8378 MaxVersion: VersionTLS12,
8379 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8380 CurvePreferences: []CurveID{CurveX25519},
8381 },
8382 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8383 resumeSession: true,
8384 })
8385 testCases = append(testCases, testCase{
8386 testType: serverTest,
8387 name: "CurveID-Resume-Server",
8388 config: Config{
8389 MaxVersion: VersionTLS12,
8390 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8391 CurvePreferences: []CurveID{CurveX25519},
8392 },
8393 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8394 resumeSession: true,
8395 })
8396
8397 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8398 // one should be reported.
8399 testCases = append(testCases, testCase{
8400 name: "CurveID-Resume-Client-TLS13",
8401 config: Config{
8402 MaxVersion: VersionTLS13,
8403 CurvePreferences: []CurveID{CurveX25519},
8404 },
8405 resumeConfig: &Config{
8406 MaxVersion: VersionTLS13,
8407 CurvePreferences: []CurveID{CurveP256},
8408 },
8409 flags: []string{
8410 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8411 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8412 },
8413 resumeSession: true,
8414 })
8415 testCases = append(testCases, testCase{
8416 testType: serverTest,
8417 name: "CurveID-Resume-Server-TLS13",
8418 config: Config{
8419 MaxVersion: VersionTLS13,
8420 CurvePreferences: []CurveID{CurveX25519},
8421 },
8422 resumeConfig: &Config{
8423 MaxVersion: VersionTLS13,
8424 CurvePreferences: []CurveID{CurveP256},
8425 },
8426 flags: []string{
8427 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8428 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8429 },
8430 resumeSession: true,
8431 })
David Benjamina81967b2016-12-22 09:16:57 -05008432
8433 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8434 testCases = append(testCases, testCase{
8435 name: "PointFormat-ServerHello-TLS12",
8436 config: Config{
8437 MaxVersion: VersionTLS12,
8438 Bugs: ProtocolBugs{
8439 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8440 },
8441 },
8442 })
8443 testCases = append(testCases, testCase{
8444 name: "PointFormat-EncryptedExtensions-TLS13",
8445 config: Config{
8446 MaxVersion: VersionTLS13,
8447 Bugs: ProtocolBugs{
8448 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8449 },
8450 },
8451 shouldFail: true,
8452 expectedError: ":ERROR_PARSING_EXTENSION:",
8453 })
8454
8455 // Test that we tolerate unknown point formats, as long as
8456 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8457 // check they are still functional.
8458 testCases = append(testCases, testCase{
8459 name: "PointFormat-Client-Tolerance",
8460 config: Config{
8461 MaxVersion: VersionTLS12,
8462 Bugs: ProtocolBugs{
8463 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8464 },
8465 },
8466 })
8467 testCases = append(testCases, testCase{
8468 testType: serverTest,
8469 name: "PointFormat-Server-Tolerance",
8470 config: Config{
8471 MaxVersion: VersionTLS12,
8472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8473 Bugs: ProtocolBugs{
8474 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8475 },
8476 },
8477 })
8478
8479 // Test TLS 1.2 does not require the point format extension to be
8480 // present.
8481 testCases = append(testCases, testCase{
8482 name: "PointFormat-Client-Missing",
8483 config: Config{
8484 MaxVersion: VersionTLS12,
8485 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8486 Bugs: ProtocolBugs{
8487 SendSupportedPointFormats: []byte{},
8488 },
8489 },
8490 })
8491 testCases = append(testCases, testCase{
8492 testType: serverTest,
8493 name: "PointFormat-Server-Missing",
8494 config: Config{
8495 MaxVersion: VersionTLS12,
8496 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8497 Bugs: ProtocolBugs{
8498 SendSupportedPointFormats: []byte{},
8499 },
8500 },
8501 })
8502
8503 // If the point format extension is present, uncompressed points must be
8504 // offered. BoringSSL requires this whether or not ECDHE is used.
8505 testCases = append(testCases, testCase{
8506 name: "PointFormat-Client-MissingUncompressed",
8507 config: Config{
8508 MaxVersion: VersionTLS12,
8509 Bugs: ProtocolBugs{
8510 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8511 },
8512 },
8513 shouldFail: true,
8514 expectedError: ":ERROR_PARSING_EXTENSION:",
8515 })
8516 testCases = append(testCases, testCase{
8517 testType: serverTest,
8518 name: "PointFormat-Server-MissingUncompressed",
8519 config: Config{
8520 MaxVersion: VersionTLS12,
8521 Bugs: ProtocolBugs{
8522 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8523 },
8524 },
8525 shouldFail: true,
8526 expectedError: ":ERROR_PARSING_EXTENSION:",
8527 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008528}
8529
David Benjaminc9ae27c2016-06-24 22:56:37 -04008530func addTLS13RecordTests() {
8531 testCases = append(testCases, testCase{
8532 name: "TLS13-RecordPadding",
8533 config: Config{
8534 MaxVersion: VersionTLS13,
8535 MinVersion: VersionTLS13,
8536 Bugs: ProtocolBugs{
8537 RecordPadding: 10,
8538 },
8539 },
8540 })
8541
8542 testCases = append(testCases, testCase{
8543 name: "TLS13-EmptyRecords",
8544 config: Config{
8545 MaxVersion: VersionTLS13,
8546 MinVersion: VersionTLS13,
8547 Bugs: ProtocolBugs{
8548 OmitRecordContents: true,
8549 },
8550 },
8551 shouldFail: true,
8552 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8553 })
8554
8555 testCases = append(testCases, testCase{
8556 name: "TLS13-OnlyPadding",
8557 config: Config{
8558 MaxVersion: VersionTLS13,
8559 MinVersion: VersionTLS13,
8560 Bugs: ProtocolBugs{
8561 OmitRecordContents: true,
8562 RecordPadding: 10,
8563 },
8564 },
8565 shouldFail: true,
8566 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8567 })
8568
8569 testCases = append(testCases, testCase{
8570 name: "TLS13-WrongOuterRecord",
8571 config: Config{
8572 MaxVersion: VersionTLS13,
8573 MinVersion: VersionTLS13,
8574 Bugs: ProtocolBugs{
8575 OuterRecordType: recordTypeHandshake,
8576 },
8577 },
8578 shouldFail: true,
8579 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8580 })
8581}
8582
Steven Valdez5b986082016-09-01 12:29:49 -04008583func addSessionTicketTests() {
8584 testCases = append(testCases, testCase{
8585 // In TLS 1.2 and below, empty NewSessionTicket messages
8586 // mean the server changed its mind on sending a ticket.
8587 name: "SendEmptySessionTicket",
8588 config: Config{
8589 MaxVersion: VersionTLS12,
8590 Bugs: ProtocolBugs{
8591 SendEmptySessionTicket: true,
8592 },
8593 },
8594 flags: []string{"-expect-no-session"},
8595 })
8596
8597 // Test that the server ignores unknown PSK modes.
8598 testCases = append(testCases, testCase{
8599 testType: serverTest,
8600 name: "TLS13-SendUnknownModeSessionTicket-Server",
8601 config: Config{
8602 MaxVersion: VersionTLS13,
8603 Bugs: ProtocolBugs{
8604 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008605 },
8606 },
8607 resumeSession: true,
8608 expectedResumeVersion: VersionTLS13,
8609 })
8610
Steven Valdeza833c352016-11-01 13:39:36 -04008611 // Test that the server does not send session tickets with no matching key exchange mode.
8612 testCases = append(testCases, testCase{
8613 testType: serverTest,
8614 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8615 config: Config{
8616 MaxVersion: VersionTLS13,
8617 Bugs: ProtocolBugs{
8618 SendPSKKeyExchangeModes: []byte{0x1a},
8619 ExpectNoNewSessionTicket: true,
8620 },
8621 },
8622 })
8623
8624 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008625 testCases = append(testCases, testCase{
8626 testType: serverTest,
8627 name: "TLS13-SendBadKEModeSessionTicket-Server",
8628 config: Config{
8629 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008630 },
8631 resumeConfig: &Config{
8632 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008633 Bugs: ProtocolBugs{
8634 SendPSKKeyExchangeModes: []byte{0x1a},
8635 },
8636 },
8637 resumeSession: true,
8638 expectResumeRejected: true,
8639 })
8640
Steven Valdeza833c352016-11-01 13:39:36 -04008641 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008642 testCases = append(testCases, testCase{
8643 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008644 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008645 config: Config{
8646 MaxVersion: VersionTLS13,
8647 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008648 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008649 },
8650 },
Steven Valdeza833c352016-11-01 13:39:36 -04008651 resumeSession: true,
8652 flags: []string{
8653 "-resumption-delay", "10",
8654 },
Steven Valdez5b986082016-09-01 12:29:49 -04008655 })
8656
Steven Valdeza833c352016-11-01 13:39:36 -04008657 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008658 testCases = append(testCases, testCase{
8659 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008660 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008661 config: Config{
8662 MaxVersion: VersionTLS13,
8663 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008664 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008665 },
8666 },
Steven Valdeza833c352016-11-01 13:39:36 -04008667 resumeSession: true,
8668 shouldFail: true,
8669 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008670 })
8671
David Benjamin35ac5b72017-03-03 15:05:56 -05008672 // Test that the server's ticket age skew reporting works.
8673 testCases = append(testCases, testCase{
8674 testType: serverTest,
8675 name: "TLS13-TicketAgeSkew-Forward",
8676 config: Config{
8677 MaxVersion: VersionTLS13,
8678 Bugs: ProtocolBugs{
8679 SendTicketAge: 15 * time.Second,
8680 },
8681 },
David Benjamin065d7332017-03-26 10:51:43 -05008682 resumeSession: true,
8683 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05008684 flags: []string{
8685 "-resumption-delay", "10",
8686 "-expect-ticket-age-skew", "5",
8687 },
8688 })
8689 testCases = append(testCases, testCase{
8690 testType: serverTest,
8691 name: "TLS13-TicketAgeSkew-Backward",
8692 config: Config{
8693 MaxVersion: VersionTLS13,
8694 Bugs: ProtocolBugs{
8695 SendTicketAge: 5 * time.Second,
8696 },
8697 },
David Benjamin065d7332017-03-26 10:51:43 -05008698 resumeSession: true,
8699 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05008700 flags: []string{
8701 "-resumption-delay", "10",
8702 "-expect-ticket-age-skew", "-5",
8703 },
8704 })
8705
Steven Valdez08b65f42016-12-07 15:29:45 -05008706 testCases = append(testCases, testCase{
8707 testType: clientTest,
8708 name: "TLS13-SendTicketEarlyDataInfo",
8709 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008710 MaxVersion: VersionTLS13,
8711 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008712 },
8713 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008714 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008715 "-expect-early-data-info",
8716 },
8717 })
8718
David Benjamin9b160662017-01-25 19:53:43 -05008719 // Test that 0-RTT tickets are ignored in clients unless opted in.
8720 testCases = append(testCases, testCase{
8721 testType: clientTest,
8722 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8723 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008724 MaxVersion: VersionTLS13,
8725 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008726 },
8727 })
8728
Steven Valdez08b65f42016-12-07 15:29:45 -05008729 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008730 testType: clientTest,
8731 name: "TLS13-DuplicateTicketEarlyDataInfo",
8732 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008733 MaxVersion: VersionTLS13,
8734 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008735 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008736 DuplicateTicketEarlyDataInfo: true,
8737 },
8738 },
8739 shouldFail: true,
8740 expectedError: ":DUPLICATE_EXTENSION:",
8741 expectedLocalError: "remote error: illegal parameter",
8742 })
8743
8744 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008745 testType: serverTest,
8746 name: "TLS13-ExpectTicketEarlyDataInfo",
8747 config: Config{
8748 MaxVersion: VersionTLS13,
8749 Bugs: ProtocolBugs{
8750 ExpectTicketEarlyDataInfo: true,
8751 },
8752 },
8753 flags: []string{
8754 "-enable-early-data",
8755 },
8756 })
David Benjamin17b30832017-01-28 14:00:32 -05008757
8758 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8759 // is honored.
8760 testCases = append(testCases, testCase{
8761 testType: clientTest,
8762 name: "TLS13-HonorServerSessionTicketLifetime",
8763 config: Config{
8764 MaxVersion: VersionTLS13,
8765 Bugs: ProtocolBugs{
8766 SendTicketLifetime: 20 * time.Second,
8767 },
8768 },
8769 flags: []string{
8770 "-resumption-delay", "19",
8771 },
8772 resumeSession: true,
8773 })
8774 testCases = append(testCases, testCase{
8775 testType: clientTest,
8776 name: "TLS13-HonorServerSessionTicketLifetime-2",
8777 config: Config{
8778 MaxVersion: VersionTLS13,
8779 Bugs: ProtocolBugs{
8780 SendTicketLifetime: 20 * time.Second,
8781 // The client should not offer the expired session.
8782 ExpectNoTLS13PSK: true,
8783 },
8784 },
8785 flags: []string{
8786 "-resumption-delay", "21",
8787 },
David Benjamin023d4192017-02-06 13:49:07 -05008788 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008789 expectResumeRejected: true,
8790 })
Steven Valdez5b986082016-09-01 12:29:49 -04008791}
8792
David Benjamin82261be2016-07-07 14:32:50 -07008793func addChangeCipherSpecTests() {
8794 // Test missing ChangeCipherSpecs.
8795 testCases = append(testCases, testCase{
8796 name: "SkipChangeCipherSpec-Client",
8797 config: Config{
8798 MaxVersion: VersionTLS12,
8799 Bugs: ProtocolBugs{
8800 SkipChangeCipherSpec: true,
8801 },
8802 },
8803 shouldFail: true,
8804 expectedError: ":UNEXPECTED_RECORD:",
8805 })
8806 testCases = append(testCases, testCase{
8807 testType: serverTest,
8808 name: "SkipChangeCipherSpec-Server",
8809 config: Config{
8810 MaxVersion: VersionTLS12,
8811 Bugs: ProtocolBugs{
8812 SkipChangeCipherSpec: true,
8813 },
8814 },
8815 shouldFail: true,
8816 expectedError: ":UNEXPECTED_RECORD:",
8817 })
8818 testCases = append(testCases, testCase{
8819 testType: serverTest,
8820 name: "SkipChangeCipherSpec-Server-NPN",
8821 config: Config{
8822 MaxVersion: VersionTLS12,
8823 NextProtos: []string{"bar"},
8824 Bugs: ProtocolBugs{
8825 SkipChangeCipherSpec: true,
8826 },
8827 },
8828 flags: []string{
8829 "-advertise-npn", "\x03foo\x03bar\x03baz",
8830 },
8831 shouldFail: true,
8832 expectedError: ":UNEXPECTED_RECORD:",
8833 })
8834
8835 // Test synchronization between the handshake and ChangeCipherSpec.
8836 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8837 // rejected. Test both with and without handshake packing to handle both
8838 // when the partial post-CCS message is in its own record and when it is
8839 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008840 for _, packed := range []bool{false, true} {
8841 var suffix string
8842 if packed {
8843 suffix = "-Packed"
8844 }
8845
8846 testCases = append(testCases, testCase{
8847 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8848 config: Config{
8849 MaxVersion: VersionTLS12,
8850 Bugs: ProtocolBugs{
8851 FragmentAcrossChangeCipherSpec: true,
8852 PackHandshakeFlight: packed,
8853 },
8854 },
8855 shouldFail: true,
8856 expectedError: ":UNEXPECTED_RECORD:",
8857 })
8858 testCases = append(testCases, testCase{
8859 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8860 config: Config{
8861 MaxVersion: VersionTLS12,
8862 },
8863 resumeSession: true,
8864 resumeConfig: &Config{
8865 MaxVersion: VersionTLS12,
8866 Bugs: ProtocolBugs{
8867 FragmentAcrossChangeCipherSpec: true,
8868 PackHandshakeFlight: packed,
8869 },
8870 },
8871 shouldFail: true,
8872 expectedError: ":UNEXPECTED_RECORD:",
8873 })
8874 testCases = append(testCases, testCase{
8875 testType: serverTest,
8876 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8877 config: Config{
8878 MaxVersion: VersionTLS12,
8879 Bugs: ProtocolBugs{
8880 FragmentAcrossChangeCipherSpec: true,
8881 PackHandshakeFlight: packed,
8882 },
8883 },
8884 shouldFail: true,
8885 expectedError: ":UNEXPECTED_RECORD:",
8886 })
8887 testCases = append(testCases, testCase{
8888 testType: serverTest,
8889 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8890 config: Config{
8891 MaxVersion: VersionTLS12,
8892 },
8893 resumeSession: true,
8894 resumeConfig: &Config{
8895 MaxVersion: VersionTLS12,
8896 Bugs: ProtocolBugs{
8897 FragmentAcrossChangeCipherSpec: true,
8898 PackHandshakeFlight: packed,
8899 },
8900 },
8901 shouldFail: true,
8902 expectedError: ":UNEXPECTED_RECORD:",
8903 })
8904 testCases = append(testCases, testCase{
8905 testType: serverTest,
8906 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8907 config: Config{
8908 MaxVersion: VersionTLS12,
8909 NextProtos: []string{"bar"},
8910 Bugs: ProtocolBugs{
8911 FragmentAcrossChangeCipherSpec: true,
8912 PackHandshakeFlight: packed,
8913 },
8914 },
8915 flags: []string{
8916 "-advertise-npn", "\x03foo\x03bar\x03baz",
8917 },
8918 shouldFail: true,
8919 expectedError: ":UNEXPECTED_RECORD:",
8920 })
8921 }
8922
David Benjamin61672812016-07-14 23:10:43 -04008923 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8924 // messages in the handshake queue. Do this by testing the server
8925 // reading the client Finished, reversing the flight so Finished comes
8926 // first.
8927 testCases = append(testCases, testCase{
8928 protocol: dtls,
8929 testType: serverTest,
8930 name: "SendUnencryptedFinished-DTLS",
8931 config: Config{
8932 MaxVersion: VersionTLS12,
8933 Bugs: ProtocolBugs{
8934 SendUnencryptedFinished: true,
8935 ReverseHandshakeFragments: true,
8936 },
8937 },
8938 shouldFail: true,
8939 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8940 })
8941
Steven Valdez143e8b32016-07-11 13:19:03 -04008942 // Test synchronization between encryption changes and the handshake in
8943 // TLS 1.3, where ChangeCipherSpec is implicit.
8944 testCases = append(testCases, testCase{
8945 name: "PartialEncryptedExtensionsWithServerHello",
8946 config: Config{
8947 MaxVersion: VersionTLS13,
8948 Bugs: ProtocolBugs{
8949 PartialEncryptedExtensionsWithServerHello: true,
8950 },
8951 },
8952 shouldFail: true,
8953 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8954 })
8955 testCases = append(testCases, testCase{
8956 testType: serverTest,
8957 name: "PartialClientFinishedWithClientHello",
8958 config: Config{
8959 MaxVersion: VersionTLS13,
8960 Bugs: ProtocolBugs{
8961 PartialClientFinishedWithClientHello: true,
8962 },
8963 },
8964 shouldFail: true,
8965 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8966 })
8967
David Benjamin82261be2016-07-07 14:32:50 -07008968 // Test that early ChangeCipherSpecs are handled correctly.
8969 testCases = append(testCases, testCase{
8970 testType: serverTest,
8971 name: "EarlyChangeCipherSpec-server-1",
8972 config: Config{
8973 MaxVersion: VersionTLS12,
8974 Bugs: ProtocolBugs{
8975 EarlyChangeCipherSpec: 1,
8976 },
8977 },
8978 shouldFail: true,
8979 expectedError: ":UNEXPECTED_RECORD:",
8980 })
8981 testCases = append(testCases, testCase{
8982 testType: serverTest,
8983 name: "EarlyChangeCipherSpec-server-2",
8984 config: Config{
8985 MaxVersion: VersionTLS12,
8986 Bugs: ProtocolBugs{
8987 EarlyChangeCipherSpec: 2,
8988 },
8989 },
8990 shouldFail: true,
8991 expectedError: ":UNEXPECTED_RECORD:",
8992 })
8993 testCases = append(testCases, testCase{
8994 protocol: dtls,
8995 name: "StrayChangeCipherSpec",
8996 config: Config{
8997 // TODO(davidben): Once DTLS 1.3 exists, test
8998 // that stray ChangeCipherSpec messages are
8999 // rejected.
9000 MaxVersion: VersionTLS12,
9001 Bugs: ProtocolBugs{
9002 StrayChangeCipherSpec: true,
9003 },
9004 },
9005 })
9006
9007 // Test that the contents of ChangeCipherSpec are checked.
9008 testCases = append(testCases, testCase{
9009 name: "BadChangeCipherSpec-1",
9010 config: Config{
9011 MaxVersion: VersionTLS12,
9012 Bugs: ProtocolBugs{
9013 BadChangeCipherSpec: []byte{2},
9014 },
9015 },
9016 shouldFail: true,
9017 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9018 })
9019 testCases = append(testCases, testCase{
9020 name: "BadChangeCipherSpec-2",
9021 config: Config{
9022 MaxVersion: VersionTLS12,
9023 Bugs: ProtocolBugs{
9024 BadChangeCipherSpec: []byte{1, 1},
9025 },
9026 },
9027 shouldFail: true,
9028 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9029 })
9030 testCases = append(testCases, testCase{
9031 protocol: dtls,
9032 name: "BadChangeCipherSpec-DTLS-1",
9033 config: Config{
9034 MaxVersion: VersionTLS12,
9035 Bugs: ProtocolBugs{
9036 BadChangeCipherSpec: []byte{2},
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9041 })
9042 testCases = append(testCases, testCase{
9043 protocol: dtls,
9044 name: "BadChangeCipherSpec-DTLS-2",
9045 config: Config{
9046 MaxVersion: VersionTLS12,
9047 Bugs: ProtocolBugs{
9048 BadChangeCipherSpec: []byte{1, 1},
9049 },
9050 },
9051 shouldFail: true,
9052 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9053 })
9054}
9055
David Benjamincd2c8062016-09-09 11:28:16 -04009056type perMessageTest struct {
9057 messageType uint8
9058 test testCase
9059}
9060
9061// makePerMessageTests returns a series of test templates which cover each
9062// message in the TLS handshake. These may be used with bugs like
9063// WrongMessageType to fully test a per-message bug.
9064func makePerMessageTests() []perMessageTest {
9065 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009066 for _, protocol := range []protocol{tls, dtls} {
9067 var suffix string
9068 if protocol == dtls {
9069 suffix = "-DTLS"
9070 }
9071
David Benjamincd2c8062016-09-09 11:28:16 -04009072 ret = append(ret, perMessageTest{
9073 messageType: typeClientHello,
9074 test: testCase{
9075 protocol: protocol,
9076 testType: serverTest,
9077 name: "ClientHello" + suffix,
9078 config: Config{
9079 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009080 },
9081 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009082 })
9083
9084 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009085 ret = append(ret, perMessageTest{
9086 messageType: typeHelloVerifyRequest,
9087 test: testCase{
9088 protocol: protocol,
9089 name: "HelloVerifyRequest" + suffix,
9090 config: Config{
9091 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009092 },
9093 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009094 })
9095 }
9096
David Benjamincd2c8062016-09-09 11:28:16 -04009097 ret = append(ret, perMessageTest{
9098 messageType: typeServerHello,
9099 test: testCase{
9100 protocol: protocol,
9101 name: "ServerHello" + suffix,
9102 config: Config{
9103 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009104 },
9105 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009106 })
9107
David Benjamincd2c8062016-09-09 11:28:16 -04009108 ret = append(ret, perMessageTest{
9109 messageType: typeCertificate,
9110 test: testCase{
9111 protocol: protocol,
9112 name: "ServerCertificate" + suffix,
9113 config: Config{
9114 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009115 },
9116 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009117 })
9118
David Benjamincd2c8062016-09-09 11:28:16 -04009119 ret = append(ret, perMessageTest{
9120 messageType: typeCertificateStatus,
9121 test: testCase{
9122 protocol: protocol,
9123 name: "CertificateStatus" + suffix,
9124 config: Config{
9125 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009126 },
David Benjamincd2c8062016-09-09 11:28:16 -04009127 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009128 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009129 })
9130
David Benjamincd2c8062016-09-09 11:28:16 -04009131 ret = append(ret, perMessageTest{
9132 messageType: typeServerKeyExchange,
9133 test: testCase{
9134 protocol: protocol,
9135 name: "ServerKeyExchange" + suffix,
9136 config: Config{
9137 MaxVersion: VersionTLS12,
9138 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009139 },
9140 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009141 })
9142
David Benjamincd2c8062016-09-09 11:28:16 -04009143 ret = append(ret, perMessageTest{
9144 messageType: typeCertificateRequest,
9145 test: testCase{
9146 protocol: protocol,
9147 name: "CertificateRequest" + suffix,
9148 config: Config{
9149 MaxVersion: VersionTLS12,
9150 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009151 },
9152 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009153 })
9154
David Benjamincd2c8062016-09-09 11:28:16 -04009155 ret = append(ret, perMessageTest{
9156 messageType: typeServerHelloDone,
9157 test: testCase{
9158 protocol: protocol,
9159 name: "ServerHelloDone" + suffix,
9160 config: Config{
9161 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009162 },
9163 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009164 })
9165
David Benjamincd2c8062016-09-09 11:28:16 -04009166 ret = append(ret, perMessageTest{
9167 messageType: typeCertificate,
9168 test: testCase{
9169 testType: serverTest,
9170 protocol: protocol,
9171 name: "ClientCertificate" + suffix,
9172 config: Config{
9173 Certificates: []Certificate{rsaCertificate},
9174 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009175 },
David Benjamincd2c8062016-09-09 11:28:16 -04009176 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009177 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009178 })
9179
David Benjamincd2c8062016-09-09 11:28:16 -04009180 ret = append(ret, perMessageTest{
9181 messageType: typeCertificateVerify,
9182 test: testCase{
9183 testType: serverTest,
9184 protocol: protocol,
9185 name: "CertificateVerify" + suffix,
9186 config: Config{
9187 Certificates: []Certificate{rsaCertificate},
9188 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009189 },
David Benjamincd2c8062016-09-09 11:28:16 -04009190 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009191 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009192 })
9193
David Benjamincd2c8062016-09-09 11:28:16 -04009194 ret = append(ret, perMessageTest{
9195 messageType: typeClientKeyExchange,
9196 test: testCase{
9197 testType: serverTest,
9198 protocol: protocol,
9199 name: "ClientKeyExchange" + suffix,
9200 config: Config{
9201 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009202 },
9203 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009204 })
9205
9206 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009207 ret = append(ret, perMessageTest{
9208 messageType: typeNextProtocol,
9209 test: testCase{
9210 testType: serverTest,
9211 protocol: protocol,
9212 name: "NextProtocol" + suffix,
9213 config: Config{
9214 MaxVersion: VersionTLS12,
9215 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009216 },
David Benjamincd2c8062016-09-09 11:28:16 -04009217 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009218 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009219 })
9220
David Benjamincd2c8062016-09-09 11:28:16 -04009221 ret = append(ret, perMessageTest{
9222 messageType: typeChannelID,
9223 test: testCase{
9224 testType: serverTest,
9225 protocol: protocol,
9226 name: "ChannelID" + suffix,
9227 config: Config{
9228 MaxVersion: VersionTLS12,
9229 ChannelID: channelIDKey,
9230 },
9231 flags: []string{
9232 "-expect-channel-id",
9233 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009234 },
9235 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009236 })
9237 }
9238
David Benjamincd2c8062016-09-09 11:28:16 -04009239 ret = append(ret, perMessageTest{
9240 messageType: typeFinished,
9241 test: testCase{
9242 testType: serverTest,
9243 protocol: protocol,
9244 name: "ClientFinished" + suffix,
9245 config: Config{
9246 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009247 },
9248 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009249 })
9250
David Benjamincd2c8062016-09-09 11:28:16 -04009251 ret = append(ret, perMessageTest{
9252 messageType: typeNewSessionTicket,
9253 test: testCase{
9254 protocol: protocol,
9255 name: "NewSessionTicket" + suffix,
9256 config: Config{
9257 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009258 },
9259 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009260 })
9261
David Benjamincd2c8062016-09-09 11:28:16 -04009262 ret = append(ret, perMessageTest{
9263 messageType: typeFinished,
9264 test: testCase{
9265 protocol: protocol,
9266 name: "ServerFinished" + suffix,
9267 config: Config{
9268 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009269 },
9270 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009271 })
9272
9273 }
David Benjamincd2c8062016-09-09 11:28:16 -04009274
9275 ret = append(ret, perMessageTest{
9276 messageType: typeClientHello,
9277 test: testCase{
9278 testType: serverTest,
9279 name: "TLS13-ClientHello",
9280 config: Config{
9281 MaxVersion: VersionTLS13,
9282 },
9283 },
9284 })
9285
9286 ret = append(ret, perMessageTest{
9287 messageType: typeServerHello,
9288 test: testCase{
9289 name: "TLS13-ServerHello",
9290 config: Config{
9291 MaxVersion: VersionTLS13,
9292 },
9293 },
9294 })
9295
9296 ret = append(ret, perMessageTest{
9297 messageType: typeEncryptedExtensions,
9298 test: testCase{
9299 name: "TLS13-EncryptedExtensions",
9300 config: Config{
9301 MaxVersion: VersionTLS13,
9302 },
9303 },
9304 })
9305
9306 ret = append(ret, perMessageTest{
9307 messageType: typeCertificateRequest,
9308 test: testCase{
9309 name: "TLS13-CertificateRequest",
9310 config: Config{
9311 MaxVersion: VersionTLS13,
9312 ClientAuth: RequireAnyClientCert,
9313 },
9314 },
9315 })
9316
9317 ret = append(ret, perMessageTest{
9318 messageType: typeCertificate,
9319 test: testCase{
9320 name: "TLS13-ServerCertificate",
9321 config: Config{
9322 MaxVersion: VersionTLS13,
9323 },
9324 },
9325 })
9326
9327 ret = append(ret, perMessageTest{
9328 messageType: typeCertificateVerify,
9329 test: testCase{
9330 name: "TLS13-ServerCertificateVerify",
9331 config: Config{
9332 MaxVersion: VersionTLS13,
9333 },
9334 },
9335 })
9336
9337 ret = append(ret, perMessageTest{
9338 messageType: typeFinished,
9339 test: testCase{
9340 name: "TLS13-ServerFinished",
9341 config: Config{
9342 MaxVersion: VersionTLS13,
9343 },
9344 },
9345 })
9346
9347 ret = append(ret, perMessageTest{
9348 messageType: typeCertificate,
9349 test: testCase{
9350 testType: serverTest,
9351 name: "TLS13-ClientCertificate",
9352 config: Config{
9353 Certificates: []Certificate{rsaCertificate},
9354 MaxVersion: VersionTLS13,
9355 },
9356 flags: []string{"-require-any-client-certificate"},
9357 },
9358 })
9359
9360 ret = append(ret, perMessageTest{
9361 messageType: typeCertificateVerify,
9362 test: testCase{
9363 testType: serverTest,
9364 name: "TLS13-ClientCertificateVerify",
9365 config: Config{
9366 Certificates: []Certificate{rsaCertificate},
9367 MaxVersion: VersionTLS13,
9368 },
9369 flags: []string{"-require-any-client-certificate"},
9370 },
9371 })
9372
9373 ret = append(ret, perMessageTest{
9374 messageType: typeFinished,
9375 test: testCase{
9376 testType: serverTest,
9377 name: "TLS13-ClientFinished",
9378 config: Config{
9379 MaxVersion: VersionTLS13,
9380 },
9381 },
9382 })
9383
9384 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009385}
9386
David Benjamincd2c8062016-09-09 11:28:16 -04009387func addWrongMessageTypeTests() {
9388 for _, t := range makePerMessageTests() {
9389 t.test.name = "WrongMessageType-" + t.test.name
9390 t.test.config.Bugs.SendWrongMessageType = t.messageType
9391 t.test.shouldFail = true
9392 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9393 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009394
David Benjamincd2c8062016-09-09 11:28:16 -04009395 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9396 // In TLS 1.3, a bad ServerHello means the client sends
9397 // an unencrypted alert while the server expects
9398 // encryption, so the alert is not readable by runner.
9399 t.test.expectedLocalError = "local error: bad record MAC"
9400 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009401
David Benjamincd2c8062016-09-09 11:28:16 -04009402 testCases = append(testCases, t.test)
9403 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009404}
9405
David Benjamin639846e2016-09-09 11:41:18 -04009406func addTrailingMessageDataTests() {
9407 for _, t := range makePerMessageTests() {
9408 t.test.name = "TrailingMessageData-" + t.test.name
9409 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9410 t.test.shouldFail = true
9411 t.test.expectedError = ":DECODE_ERROR:"
9412 t.test.expectedLocalError = "remote error: error decoding message"
9413
9414 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9415 // In TLS 1.3, a bad ServerHello means the client sends
9416 // an unencrypted alert while the server expects
9417 // encryption, so the alert is not readable by runner.
9418 t.test.expectedLocalError = "local error: bad record MAC"
9419 }
9420
9421 if t.messageType == typeFinished {
9422 // Bad Finished messages read as the verify data having
9423 // the wrong length.
9424 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9425 t.test.expectedLocalError = "remote error: error decrypting message"
9426 }
9427
9428 testCases = append(testCases, t.test)
9429 }
9430}
9431
Steven Valdez143e8b32016-07-11 13:19:03 -04009432func addTLS13HandshakeTests() {
9433 testCases = append(testCases, testCase{
9434 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009435 name: "NegotiatePSKResumption-TLS13",
9436 config: Config{
9437 MaxVersion: VersionTLS13,
9438 Bugs: ProtocolBugs{
9439 NegotiatePSKResumption: true,
9440 },
9441 },
9442 resumeSession: true,
9443 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009444 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009445 })
9446
9447 testCases = append(testCases, testCase{
9448 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009449 name: "MissingKeyShare-Client",
9450 config: Config{
9451 MaxVersion: VersionTLS13,
9452 Bugs: ProtocolBugs{
9453 MissingKeyShare: true,
9454 },
9455 },
9456 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009457 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009458 })
9459
9460 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009461 testType: serverTest,
9462 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009463 config: Config{
9464 MaxVersion: VersionTLS13,
9465 Bugs: ProtocolBugs{
9466 MissingKeyShare: true,
9467 },
9468 },
9469 shouldFail: true,
9470 expectedError: ":MISSING_KEY_SHARE:",
9471 })
9472
9473 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009474 testType: serverTest,
9475 name: "DuplicateKeyShares",
9476 config: Config{
9477 MaxVersion: VersionTLS13,
9478 Bugs: ProtocolBugs{
9479 DuplicateKeyShares: true,
9480 },
9481 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009482 shouldFail: true,
9483 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009484 })
9485
9486 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009487 testType: serverTest,
9488 name: "SkipEarlyData",
9489 config: Config{
9490 MaxVersion: VersionTLS13,
9491 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009492 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009493 },
9494 },
9495 })
9496
9497 testCases = append(testCases, testCase{
9498 testType: serverTest,
9499 name: "SkipEarlyData-OmitEarlyDataExtension",
9500 config: Config{
9501 MaxVersion: VersionTLS13,
9502 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009503 SendFakeEarlyDataLength: 4,
9504 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009505 },
9506 },
9507 shouldFail: true,
9508 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9509 })
9510
9511 testCases = append(testCases, testCase{
9512 testType: serverTest,
9513 name: "SkipEarlyData-TooMuchData",
9514 config: Config{
9515 MaxVersion: VersionTLS13,
9516 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009517 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009518 },
9519 },
9520 shouldFail: true,
9521 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9522 })
9523
9524 testCases = append(testCases, testCase{
9525 testType: serverTest,
9526 name: "SkipEarlyData-Interleaved",
9527 config: Config{
9528 MaxVersion: VersionTLS13,
9529 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009530 SendFakeEarlyDataLength: 4,
9531 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009532 },
9533 },
9534 shouldFail: true,
9535 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9536 })
9537
9538 testCases = append(testCases, testCase{
9539 testType: serverTest,
9540 name: "SkipEarlyData-EarlyDataInTLS12",
9541 config: Config{
9542 MaxVersion: VersionTLS13,
9543 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009544 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009545 },
9546 },
9547 shouldFail: true,
9548 expectedError: ":UNEXPECTED_RECORD:",
9549 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9550 })
9551
9552 testCases = append(testCases, testCase{
9553 testType: serverTest,
9554 name: "SkipEarlyData-HRR",
9555 config: Config{
9556 MaxVersion: VersionTLS13,
9557 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009558 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009559 },
9560 DefaultCurves: []CurveID{},
9561 },
9562 })
9563
9564 testCases = append(testCases, testCase{
9565 testType: serverTest,
9566 name: "SkipEarlyData-HRR-Interleaved",
9567 config: Config{
9568 MaxVersion: VersionTLS13,
9569 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009570 SendFakeEarlyDataLength: 4,
9571 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009572 },
9573 DefaultCurves: []CurveID{},
9574 },
9575 shouldFail: true,
9576 expectedError: ":UNEXPECTED_RECORD:",
9577 })
9578
9579 testCases = append(testCases, testCase{
9580 testType: serverTest,
9581 name: "SkipEarlyData-HRR-TooMuchData",
9582 config: Config{
9583 MaxVersion: VersionTLS13,
9584 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009585 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009586 },
9587 DefaultCurves: []CurveID{},
9588 },
9589 shouldFail: true,
9590 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9591 })
9592
9593 // Test that skipping early data looking for cleartext correctly
9594 // processes an alert record.
9595 testCases = append(testCases, testCase{
9596 testType: serverTest,
9597 name: "SkipEarlyData-HRR-FatalAlert",
9598 config: Config{
9599 MaxVersion: VersionTLS13,
9600 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009601 SendEarlyAlert: true,
9602 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009603 },
9604 DefaultCurves: []CurveID{},
9605 },
9606 shouldFail: true,
9607 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9608 })
9609
9610 testCases = append(testCases, testCase{
9611 testType: serverTest,
9612 name: "SkipEarlyData-SecondClientHelloEarlyData",
9613 config: Config{
9614 MaxVersion: VersionTLS13,
9615 Bugs: ProtocolBugs{
9616 SendEarlyDataOnSecondClientHello: true,
9617 },
9618 DefaultCurves: []CurveID{},
9619 },
9620 shouldFail: true,
9621 expectedLocalError: "remote error: bad record MAC",
9622 })
9623
9624 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009625 testType: clientTest,
9626 name: "EmptyEncryptedExtensions",
9627 config: Config{
9628 MaxVersion: VersionTLS13,
9629 Bugs: ProtocolBugs{
9630 EmptyEncryptedExtensions: true,
9631 },
9632 },
9633 shouldFail: true,
9634 expectedLocalError: "remote error: error decoding message",
9635 })
9636
9637 testCases = append(testCases, testCase{
9638 testType: clientTest,
9639 name: "EncryptedExtensionsWithKeyShare",
9640 config: Config{
9641 MaxVersion: VersionTLS13,
9642 Bugs: ProtocolBugs{
9643 EncryptedExtensionsWithKeyShare: true,
9644 },
9645 },
9646 shouldFail: true,
9647 expectedLocalError: "remote error: unsupported extension",
9648 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009649
9650 testCases = append(testCases, testCase{
9651 testType: serverTest,
9652 name: "SendHelloRetryRequest",
9653 config: Config{
9654 MaxVersion: VersionTLS13,
9655 // Require a HelloRetryRequest for every curve.
9656 DefaultCurves: []CurveID{},
9657 },
9658 expectedCurveID: CurveX25519,
9659 })
9660
9661 testCases = append(testCases, testCase{
9662 testType: serverTest,
9663 name: "SendHelloRetryRequest-2",
9664 config: Config{
9665 MaxVersion: VersionTLS13,
9666 DefaultCurves: []CurveID{CurveP384},
9667 },
9668 // Although the ClientHello did not predict our preferred curve,
9669 // we always select it whether it is predicted or not.
9670 expectedCurveID: CurveX25519,
9671 })
9672
9673 testCases = append(testCases, testCase{
9674 name: "UnknownCurve-HelloRetryRequest",
9675 config: Config{
9676 MaxVersion: VersionTLS13,
9677 // P-384 requires HelloRetryRequest in BoringSSL.
9678 CurvePreferences: []CurveID{CurveP384},
9679 Bugs: ProtocolBugs{
9680 SendHelloRetryRequestCurve: bogusCurve,
9681 },
9682 },
9683 shouldFail: true,
9684 expectedError: ":WRONG_CURVE:",
9685 })
9686
9687 testCases = append(testCases, testCase{
9688 name: "DisabledCurve-HelloRetryRequest",
9689 config: Config{
9690 MaxVersion: VersionTLS13,
9691 CurvePreferences: []CurveID{CurveP256},
9692 Bugs: ProtocolBugs{
9693 IgnorePeerCurvePreferences: true,
9694 },
9695 },
9696 flags: []string{"-p384-only"},
9697 shouldFail: true,
9698 expectedError: ":WRONG_CURVE:",
9699 })
9700
9701 testCases = append(testCases, testCase{
9702 name: "UnnecessaryHelloRetryRequest",
9703 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009704 MaxVersion: VersionTLS13,
9705 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009706 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009707 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009708 },
9709 },
9710 shouldFail: true,
9711 expectedError: ":WRONG_CURVE:",
9712 })
9713
9714 testCases = append(testCases, testCase{
9715 name: "SecondHelloRetryRequest",
9716 config: Config{
9717 MaxVersion: VersionTLS13,
9718 // P-384 requires HelloRetryRequest in BoringSSL.
9719 CurvePreferences: []CurveID{CurveP384},
9720 Bugs: ProtocolBugs{
9721 SecondHelloRetryRequest: true,
9722 },
9723 },
9724 shouldFail: true,
9725 expectedError: ":UNEXPECTED_MESSAGE:",
9726 })
9727
9728 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009729 name: "HelloRetryRequest-Empty",
9730 config: Config{
9731 MaxVersion: VersionTLS13,
9732 Bugs: ProtocolBugs{
9733 AlwaysSendHelloRetryRequest: true,
9734 },
9735 },
9736 shouldFail: true,
9737 expectedError: ":DECODE_ERROR:",
9738 })
9739
9740 testCases = append(testCases, testCase{
9741 name: "HelloRetryRequest-DuplicateCurve",
9742 config: Config{
9743 MaxVersion: VersionTLS13,
9744 // P-384 requires a HelloRetryRequest against BoringSSL's default
9745 // configuration. Assert this ExpectMissingKeyShare.
9746 CurvePreferences: []CurveID{CurveP384},
9747 Bugs: ProtocolBugs{
9748 ExpectMissingKeyShare: true,
9749 DuplicateHelloRetryRequestExtensions: true,
9750 },
9751 },
9752 shouldFail: true,
9753 expectedError: ":DUPLICATE_EXTENSION:",
9754 expectedLocalError: "remote error: illegal parameter",
9755 })
9756
9757 testCases = append(testCases, testCase{
9758 name: "HelloRetryRequest-Cookie",
9759 config: Config{
9760 MaxVersion: VersionTLS13,
9761 Bugs: ProtocolBugs{
9762 SendHelloRetryRequestCookie: []byte("cookie"),
9763 },
9764 },
9765 })
9766
9767 testCases = append(testCases, testCase{
9768 name: "HelloRetryRequest-DuplicateCookie",
9769 config: Config{
9770 MaxVersion: VersionTLS13,
9771 Bugs: ProtocolBugs{
9772 SendHelloRetryRequestCookie: []byte("cookie"),
9773 DuplicateHelloRetryRequestExtensions: true,
9774 },
9775 },
9776 shouldFail: true,
9777 expectedError: ":DUPLICATE_EXTENSION:",
9778 expectedLocalError: "remote error: illegal parameter",
9779 })
9780
9781 testCases = append(testCases, testCase{
9782 name: "HelloRetryRequest-EmptyCookie",
9783 config: Config{
9784 MaxVersion: VersionTLS13,
9785 Bugs: ProtocolBugs{
9786 SendHelloRetryRequestCookie: []byte{},
9787 },
9788 },
9789 shouldFail: true,
9790 expectedError: ":DECODE_ERROR:",
9791 })
9792
9793 testCases = append(testCases, testCase{
9794 name: "HelloRetryRequest-Cookie-Curve",
9795 config: Config{
9796 MaxVersion: VersionTLS13,
9797 // P-384 requires HelloRetryRequest in BoringSSL.
9798 CurvePreferences: []CurveID{CurveP384},
9799 Bugs: ProtocolBugs{
9800 SendHelloRetryRequestCookie: []byte("cookie"),
9801 ExpectMissingKeyShare: true,
9802 },
9803 },
9804 })
9805
9806 testCases = append(testCases, testCase{
9807 name: "HelloRetryRequest-Unknown",
9808 config: Config{
9809 MaxVersion: VersionTLS13,
9810 Bugs: ProtocolBugs{
9811 CustomHelloRetryRequestExtension: "extension",
9812 },
9813 },
9814 shouldFail: true,
9815 expectedError: ":UNEXPECTED_EXTENSION:",
9816 expectedLocalError: "remote error: unsupported extension",
9817 })
9818
9819 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009820 testType: serverTest,
9821 name: "SecondClientHelloMissingKeyShare",
9822 config: Config{
9823 MaxVersion: VersionTLS13,
9824 DefaultCurves: []CurveID{},
9825 Bugs: ProtocolBugs{
9826 SecondClientHelloMissingKeyShare: true,
9827 },
9828 },
9829 shouldFail: true,
9830 expectedError: ":MISSING_KEY_SHARE:",
9831 })
9832
9833 testCases = append(testCases, testCase{
9834 testType: serverTest,
9835 name: "SecondClientHelloWrongCurve",
9836 config: Config{
9837 MaxVersion: VersionTLS13,
9838 DefaultCurves: []CurveID{},
9839 Bugs: ProtocolBugs{
9840 MisinterpretHelloRetryRequestCurve: CurveP521,
9841 },
9842 },
9843 shouldFail: true,
9844 expectedError: ":WRONG_CURVE:",
9845 })
9846
9847 testCases = append(testCases, testCase{
9848 name: "HelloRetryRequestVersionMismatch",
9849 config: Config{
9850 MaxVersion: VersionTLS13,
9851 // P-384 requires HelloRetryRequest in BoringSSL.
9852 CurvePreferences: []CurveID{CurveP384},
9853 Bugs: ProtocolBugs{
9854 SendServerHelloVersion: 0x0305,
9855 },
9856 },
9857 shouldFail: true,
9858 expectedError: ":WRONG_VERSION_NUMBER:",
9859 })
9860
9861 testCases = append(testCases, testCase{
9862 name: "HelloRetryRequestCurveMismatch",
9863 config: Config{
9864 MaxVersion: VersionTLS13,
9865 // P-384 requires HelloRetryRequest in BoringSSL.
9866 CurvePreferences: []CurveID{CurveP384},
9867 Bugs: ProtocolBugs{
9868 // Send P-384 (correct) in the HelloRetryRequest.
9869 SendHelloRetryRequestCurve: CurveP384,
9870 // But send P-256 in the ServerHello.
9871 SendCurve: CurveP256,
9872 },
9873 },
9874 shouldFail: true,
9875 expectedError: ":WRONG_CURVE:",
9876 })
9877
9878 // Test the server selecting a curve that requires a HelloRetryRequest
9879 // without sending it.
9880 testCases = append(testCases, testCase{
9881 name: "SkipHelloRetryRequest",
9882 config: Config{
9883 MaxVersion: VersionTLS13,
9884 // P-384 requires HelloRetryRequest in BoringSSL.
9885 CurvePreferences: []CurveID{CurveP384},
9886 Bugs: ProtocolBugs{
9887 SkipHelloRetryRequest: true,
9888 },
9889 },
9890 shouldFail: true,
9891 expectedError: ":WRONG_CURVE:",
9892 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009893
9894 testCases = append(testCases, testCase{
9895 name: "TLS13-RequestContextInHandshake",
9896 config: Config{
9897 MaxVersion: VersionTLS13,
9898 MinVersion: VersionTLS13,
9899 ClientAuth: RequireAnyClientCert,
9900 Bugs: ProtocolBugs{
9901 SendRequestContext: []byte("request context"),
9902 },
9903 },
9904 flags: []string{
9905 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9906 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9907 },
9908 shouldFail: true,
9909 expectedError: ":DECODE_ERROR:",
9910 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009911
9912 testCases = append(testCases, testCase{
9913 testType: serverTest,
9914 name: "TLS13-TrailingKeyShareData",
9915 config: Config{
9916 MaxVersion: VersionTLS13,
9917 Bugs: ProtocolBugs{
9918 TrailingKeyShareData: true,
9919 },
9920 },
9921 shouldFail: true,
9922 expectedError: ":DECODE_ERROR:",
9923 })
David Benjamin7f78df42016-10-05 22:33:19 -04009924
9925 testCases = append(testCases, testCase{
9926 name: "TLS13-AlwaysSelectPSKIdentity",
9927 config: Config{
9928 MaxVersion: VersionTLS13,
9929 Bugs: ProtocolBugs{
9930 AlwaysSelectPSKIdentity: true,
9931 },
9932 },
9933 shouldFail: true,
9934 expectedError: ":UNEXPECTED_EXTENSION:",
9935 })
9936
9937 testCases = append(testCases, testCase{
9938 name: "TLS13-InvalidPSKIdentity",
9939 config: Config{
9940 MaxVersion: VersionTLS13,
9941 Bugs: ProtocolBugs{
9942 SelectPSKIdentityOnResume: 1,
9943 },
9944 },
9945 resumeSession: true,
9946 shouldFail: true,
9947 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9948 })
David Benjamin1286bee2016-10-07 15:25:06 -04009949
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009950 testCases = append(testCases, testCase{
9951 testType: serverTest,
9952 name: "TLS13-ExtraPSKIdentity",
9953 config: Config{
9954 MaxVersion: VersionTLS13,
9955 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009956 ExtraPSKIdentity: true,
9957 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009958 },
9959 },
9960 resumeSession: true,
9961 })
9962
David Benjamin1286bee2016-10-07 15:25:06 -04009963 // Test that unknown NewSessionTicket extensions are tolerated.
9964 testCases = append(testCases, testCase{
9965 name: "TLS13-CustomTicketExtension",
9966 config: Config{
9967 MaxVersion: VersionTLS13,
9968 Bugs: ProtocolBugs{
9969 CustomTicketExtension: "1234",
9970 },
9971 },
9972 })
Steven Valdez2d850622017-01-11 11:34:52 -05009973
Steven Valdez2d850622017-01-11 11:34:52 -05009974 testCases = append(testCases, testCase{
9975 testType: clientTest,
9976 name: "TLS13-DataLessEarlyData-Reject-Client",
9977 config: Config{
9978 MaxVersion: VersionTLS13,
9979 MaxEarlyDataSize: 16384,
9980 },
9981 resumeConfig: &Config{
9982 MaxVersion: VersionTLS13,
9983 MaxEarlyDataSize: 16384,
9984 Bugs: ProtocolBugs{
9985 AlwaysRejectEarlyData: true,
9986 },
9987 },
9988 resumeSession: true,
9989 flags: []string{
9990 "-enable-early-data",
9991 "-expect-early-data-info",
9992 "-expect-reject-early-data",
9993 },
9994 })
9995
9996 testCases = append(testCases, testCase{
9997 testType: clientTest,
9998 name: "TLS13-DataLessEarlyData-HRR-Client",
9999 config: Config{
10000 MaxVersion: VersionTLS13,
10001 MaxEarlyDataSize: 16384,
10002 },
10003 resumeConfig: &Config{
10004 MaxVersion: VersionTLS13,
10005 MaxEarlyDataSize: 16384,
10006 Bugs: ProtocolBugs{
10007 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10008 },
10009 },
10010 resumeSession: true,
10011 flags: []string{
10012 "-enable-early-data",
10013 "-expect-early-data-info",
10014 "-expect-reject-early-data",
10015 },
10016 })
10017
10018 // The client must check the server does not send the early_data
10019 // extension while rejecting the session.
10020 testCases = append(testCases, testCase{
10021 testType: clientTest,
10022 name: "TLS13-EarlyDataWithoutResume-Client",
10023 config: Config{
10024 MaxVersion: VersionTLS13,
10025 MaxEarlyDataSize: 16384,
10026 },
10027 resumeConfig: &Config{
10028 MaxVersion: VersionTLS13,
10029 SessionTicketsDisabled: true,
10030 Bugs: ProtocolBugs{
10031 SendEarlyDataExtension: true,
10032 },
10033 },
10034 resumeSession: true,
10035 flags: []string{
10036 "-enable-early-data",
10037 "-expect-early-data-info",
10038 },
10039 shouldFail: true,
10040 expectedError: ":UNEXPECTED_EXTENSION:",
10041 })
10042
10043 // The client must fail with a dedicated error code if the server
10044 // responds with TLS 1.2 when offering 0-RTT.
10045 testCases = append(testCases, testCase{
10046 testType: clientTest,
10047 name: "TLS13-EarlyDataVersionDowngrade-Client",
10048 config: Config{
10049 MaxVersion: VersionTLS13,
10050 MaxEarlyDataSize: 16384,
10051 },
10052 resumeConfig: &Config{
10053 MaxVersion: VersionTLS12,
10054 },
10055 resumeSession: true,
10056 flags: []string{
10057 "-enable-early-data",
10058 "-expect-early-data-info",
10059 },
10060 shouldFail: true,
10061 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10062 })
10063
10064 // Test that the client rejects an (unsolicited) early_data extension if
10065 // the server sent an HRR.
10066 testCases = append(testCases, testCase{
10067 testType: clientTest,
10068 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10069 config: Config{
10070 MaxVersion: VersionTLS13,
10071 MaxEarlyDataSize: 16384,
10072 },
10073 resumeConfig: &Config{
10074 MaxVersion: VersionTLS13,
10075 MaxEarlyDataSize: 16384,
10076 Bugs: ProtocolBugs{
10077 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10078 SendEarlyDataExtension: true,
10079 },
10080 },
10081 resumeSession: true,
10082 flags: []string{
10083 "-enable-early-data",
10084 "-expect-early-data-info",
10085 },
10086 shouldFail: true,
10087 expectedError: ":UNEXPECTED_EXTENSION:",
10088 })
10089
10090 fooString := "foo"
10091 barString := "bar"
10092
10093 // Test that the client reports the correct ALPN after a 0-RTT reject
10094 // that changed it.
10095 testCases = append(testCases, testCase{
10096 testType: clientTest,
10097 name: "TLS13-DataLessEarlyData-ALPNMismatch-Client",
10098 config: Config{
10099 MaxVersion: VersionTLS13,
10100 MaxEarlyDataSize: 16384,
10101 Bugs: ProtocolBugs{
10102 ALPNProtocol: &fooString,
10103 },
10104 },
10105 resumeConfig: &Config{
10106 MaxVersion: VersionTLS13,
10107 MaxEarlyDataSize: 16384,
10108 Bugs: ProtocolBugs{
10109 ALPNProtocol: &barString,
10110 },
10111 },
10112 resumeSession: true,
10113 flags: []string{
10114 "-advertise-alpn", "\x03foo\x03bar",
10115 "-enable-early-data",
10116 "-expect-early-data-info",
10117 "-expect-reject-early-data",
10118 "-expect-alpn", "foo",
10119 "-expect-resume-alpn", "bar",
10120 },
10121 })
10122
10123 // Test that the client reports the correct ALPN after a 0-RTT reject if
10124 // ALPN was omitted from the first connection.
10125 testCases = append(testCases, testCase{
10126 testType: clientTest,
10127 name: "TLS13-DataLessEarlyData-ALPNOmitted1-Client",
10128 config: Config{
10129 MaxVersion: VersionTLS13,
10130 MaxEarlyDataSize: 16384,
10131 },
10132 resumeConfig: &Config{
10133 MaxVersion: VersionTLS13,
10134 MaxEarlyDataSize: 16384,
10135 NextProtos: []string{"foo"},
10136 },
10137 resumeSession: true,
10138 flags: []string{
10139 "-advertise-alpn", "\x03foo\x03bar",
10140 "-enable-early-data",
10141 "-expect-early-data-info",
10142 "-expect-reject-early-data",
10143 "-expect-no-alpn",
10144 "-expect-resume-alpn", "foo",
10145 },
10146 })
10147
10148 // Test that the client reports the correct ALPN after a 0-RTT reject if
10149 // ALPN was omitted from the second connection.
10150 testCases = append(testCases, testCase{
10151 testType: clientTest,
10152 name: "TLS13-DataLessEarlyData-ALPNOmitted2-Client",
10153 config: Config{
10154 MaxVersion: VersionTLS13,
10155 MaxEarlyDataSize: 16384,
10156 NextProtos: []string{"foo"},
10157 },
10158 resumeConfig: &Config{
10159 MaxVersion: VersionTLS13,
10160 MaxEarlyDataSize: 16384,
10161 },
10162 resumeSession: true,
10163 flags: []string{
10164 "-advertise-alpn", "\x03foo\x03bar",
10165 "-enable-early-data",
10166 "-expect-early-data-info",
10167 "-expect-reject-early-data",
10168 "-expect-alpn", "foo",
10169 "-expect-no-resume-alpn",
10170 },
10171 })
10172
10173 // Test that the client enforces ALPN match on 0-RTT accept.
10174 testCases = append(testCases, testCase{
10175 testType: clientTest,
10176 name: "TLS13-DataLessEarlyData-BadALPNMismatch-Client",
10177 config: Config{
10178 MaxVersion: VersionTLS13,
10179 MaxEarlyDataSize: 16384,
10180 Bugs: ProtocolBugs{
10181 ALPNProtocol: &fooString,
10182 },
10183 },
10184 resumeConfig: &Config{
10185 MaxVersion: VersionTLS13,
10186 MaxEarlyDataSize: 16384,
10187 Bugs: ProtocolBugs{
10188 AlwaysAcceptEarlyData: true,
10189 ALPNProtocol: &barString,
10190 },
10191 },
10192 resumeSession: true,
10193 flags: []string{
10194 "-advertise-alpn", "\x03foo\x03bar",
10195 "-enable-early-data",
10196 "-expect-early-data-info",
10197 },
10198 shouldFail: true,
10199 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10200 })
10201
10202 // Test that the server correctly rejects 0-RTT when the previous
10203 // session did not allow early data on resumption.
10204 testCases = append(testCases, testCase{
10205 testType: serverTest,
10206 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10207 config: Config{
10208 MaxVersion: VersionTLS13,
10209 },
10210 resumeConfig: &Config{
10211 MaxVersion: VersionTLS13,
10212 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010213 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010214 ExpectEarlyDataAccepted: false,
10215 },
10216 },
10217 resumeSession: true,
10218 flags: []string{
10219 "-enable-resume-early-data",
10220 "-expect-reject-early-data",
10221 },
10222 })
10223
10224 // Test that we reject early data where ALPN is omitted from the first
10225 // connection.
10226 testCases = append(testCases, testCase{
10227 testType: serverTest,
10228 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10229 config: Config{
10230 MaxVersion: VersionTLS13,
10231 NextProtos: []string{},
10232 },
10233 resumeConfig: &Config{
10234 MaxVersion: VersionTLS13,
10235 NextProtos: []string{"foo"},
10236 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010237 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010238 ExpectEarlyDataAccepted: false,
10239 },
10240 },
10241 resumeSession: true,
10242 flags: []string{
10243 "-enable-early-data",
10244 "-select-alpn", "",
10245 "-select-resume-alpn", "foo",
10246 },
10247 })
10248
10249 // Test that we reject early data where ALPN is omitted from the second
10250 // connection.
10251 testCases = append(testCases, testCase{
10252 testType: serverTest,
10253 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10254 config: Config{
10255 MaxVersion: VersionTLS13,
10256 NextProtos: []string{"foo"},
10257 },
10258 resumeConfig: &Config{
10259 MaxVersion: VersionTLS13,
10260 NextProtos: []string{},
10261 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010262 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010263 ExpectEarlyDataAccepted: false,
10264 },
10265 },
10266 resumeSession: true,
10267 flags: []string{
10268 "-enable-early-data",
10269 "-select-alpn", "foo",
10270 "-select-resume-alpn", "",
10271 },
10272 })
10273
10274 // Test that we reject early data with mismatched ALPN.
10275 testCases = append(testCases, testCase{
10276 testType: serverTest,
10277 name: "TLS13-EarlyData-ALPNMismatch-Server",
10278 config: Config{
10279 MaxVersion: VersionTLS13,
10280 NextProtos: []string{"foo"},
10281 },
10282 resumeConfig: &Config{
10283 MaxVersion: VersionTLS13,
10284 NextProtos: []string{"bar"},
10285 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010286 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010287 ExpectEarlyDataAccepted: false,
10288 },
10289 },
10290 resumeSession: true,
10291 flags: []string{
10292 "-enable-early-data",
10293 "-select-alpn", "foo",
10294 "-select-resume-alpn", "bar",
10295 },
10296 })
10297
David Benjamin6bb507b2017-03-29 16:35:57 -050010298 // Test that the client offering 0-RTT and Channel ID forbids the server
10299 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010300 testCases = append(testCases, testCase{
10301 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010302 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010303 config: Config{
10304 MaxVersion: VersionTLS13,
10305 MaxEarlyDataSize: 16384,
10306 RequestChannelID: true,
10307 },
10308 resumeSession: true,
10309 expectChannelID: true,
10310 shouldFail: true,
10311 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10312 flags: []string{
10313 "-enable-early-data",
10314 "-expect-early-data-info",
10315 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10316 },
10317 })
10318
David Benjamin6bb507b2017-03-29 16:35:57 -050010319 // Test that the client offering Channel ID and 0-RTT allows the server
10320 // to decline 0-RTT.
10321 testCases = append(testCases, testCase{
10322 testType: clientTest,
10323 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10324 config: Config{
10325 MaxVersion: VersionTLS13,
10326 MaxEarlyDataSize: 16384,
10327 RequestChannelID: true,
10328 Bugs: ProtocolBugs{
10329 AlwaysRejectEarlyData: true,
10330 },
10331 },
10332 resumeSession: true,
10333 expectChannelID: true,
10334 flags: []string{
10335 "-enable-early-data",
10336 "-expect-early-data-info",
10337 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10338 "-expect-reject-early-data",
10339 },
10340 })
10341
10342 // Test that the client offering Channel ID and 0-RTT allows the server
10343 // to decline Channel ID.
10344 testCases = append(testCases, testCase{
10345 testType: clientTest,
10346 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10347 config: Config{
10348 MaxVersion: VersionTLS13,
10349 MaxEarlyDataSize: 16384,
10350 },
10351 resumeSession: true,
10352 flags: []string{
10353 "-enable-early-data",
10354 "-expect-early-data-info",
10355 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10356 "-expect-accept-early-data",
10357 },
10358 })
10359
10360 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10361 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010362 testCases = append(testCases, testCase{
10363 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010364 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010365 config: Config{
10366 MaxVersion: VersionTLS13,
10367 ChannelID: channelIDKey,
10368 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010369 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010370 ExpectEarlyDataAccepted: false,
10371 },
10372 },
10373 resumeSession: true,
10374 expectChannelID: true,
10375 flags: []string{
10376 "-enable-early-data",
10377 "-expect-reject-early-data",
10378 "-expect-channel-id",
10379 base64.StdEncoding.EncodeToString(channelIDBytes),
10380 },
10381 })
10382
David Benjamin6bb507b2017-03-29 16:35:57 -050010383 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10384 // if not offered Channel ID.
10385 testCases = append(testCases, testCase{
10386 testType: serverTest,
10387 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10388 config: Config{
10389 MaxVersion: VersionTLS13,
10390 Bugs: ProtocolBugs{
10391 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10392 ExpectEarlyDataAccepted: true,
10393 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10394 },
10395 },
10396 resumeSession: true,
10397 expectChannelID: false,
10398 flags: []string{
10399 "-enable-early-data",
10400 "-expect-accept-early-data",
10401 "-enable-channel-id",
10402 },
10403 })
10404
David Benjamin32c89272017-03-26 13:54:21 -050010405 // Test that the server rejects 0-RTT streams without end_of_early_data.
10406 // The subsequent records should fail to decrypt.
10407 testCases = append(testCases, testCase{
10408 testType: serverTest,
10409 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10410 config: Config{
10411 MaxVersion: VersionTLS13,
10412 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010413 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010414 ExpectEarlyDataAccepted: true,
10415 SkipEndOfEarlyData: true,
10416 },
10417 },
10418 resumeSession: true,
10419 flags: []string{"-enable-early-data"},
10420 shouldFail: true,
10421 expectedLocalError: "remote error: bad record MAC",
10422 expectedError: ":BAD_DECRYPT:",
10423 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010424
10425 testCases = append(testCases, testCase{
10426 testType: serverTest,
10427 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10428 config: Config{
10429 MaxVersion: VersionTLS13,
10430 },
10431 resumeConfig: &Config{
10432 MaxVersion: VersionTLS13,
10433 Bugs: ProtocolBugs{
10434 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10435 SendStrayEarlyHandshake: true,
10436 ExpectEarlyDataAccepted: true},
10437 },
10438 resumeSession: true,
10439 shouldFail: true,
10440 expectedError: ":UNEXPECTED_RECORD:",
10441 expectedLocalError: "remote error: unexpected message",
10442 flags: []string{
10443 "-enable-early-data",
10444 },
10445 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010446}
10447
David Benjaminabbbee12016-10-31 19:20:42 -040010448func addTLS13CipherPreferenceTests() {
10449 // Test that client preference is honored if the shim has AES hardware
10450 // and ChaCha20-Poly1305 is preferred otherwise.
10451 testCases = append(testCases, testCase{
10452 testType: serverTest,
10453 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10454 config: Config{
10455 MaxVersion: VersionTLS13,
10456 CipherSuites: []uint16{
10457 TLS_CHACHA20_POLY1305_SHA256,
10458 TLS_AES_128_GCM_SHA256,
10459 },
10460 },
10461 flags: []string{
10462 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10463 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10464 },
10465 })
10466
10467 testCases = append(testCases, testCase{
10468 testType: serverTest,
10469 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10470 config: Config{
10471 MaxVersion: VersionTLS13,
10472 CipherSuites: []uint16{
10473 TLS_AES_128_GCM_SHA256,
10474 TLS_CHACHA20_POLY1305_SHA256,
10475 },
10476 },
10477 flags: []string{
10478 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10479 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10480 },
10481 })
10482
10483 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
10484 // whether it has AES hardware.
10485 testCases = append(testCases, testCase{
10486 name: "TLS13-CipherPreference-Client",
10487 config: Config{
10488 MaxVersion: VersionTLS13,
10489 // Use the client cipher order. (This is the default but
10490 // is listed to be explicit.)
10491 PreferServerCipherSuites: false,
10492 },
10493 flags: []string{
10494 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10495 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10496 },
10497 })
10498}
10499
David Benjaminf3fbade2016-09-19 13:08:16 -040010500func addPeekTests() {
10501 // Test SSL_peek works, including on empty records.
10502 testCases = append(testCases, testCase{
10503 name: "Peek-Basic",
10504 sendEmptyRecords: 1,
10505 flags: []string{"-peek-then-read"},
10506 })
10507
10508 // Test SSL_peek can drive the initial handshake.
10509 testCases = append(testCases, testCase{
10510 name: "Peek-ImplicitHandshake",
10511 flags: []string{
10512 "-peek-then-read",
10513 "-implicit-handshake",
10514 },
10515 })
10516
10517 // Test SSL_peek can discover and drive a renegotiation.
10518 testCases = append(testCases, testCase{
10519 name: "Peek-Renegotiate",
10520 config: Config{
10521 MaxVersion: VersionTLS12,
10522 },
10523 renegotiate: 1,
10524 flags: []string{
10525 "-peek-then-read",
10526 "-renegotiate-freely",
10527 "-expect-total-renegotiations", "1",
10528 },
10529 })
10530
10531 // Test SSL_peek can discover a close_notify.
10532 testCases = append(testCases, testCase{
10533 name: "Peek-Shutdown",
10534 config: Config{
10535 Bugs: ProtocolBugs{
10536 ExpectCloseNotify: true,
10537 },
10538 },
10539 flags: []string{
10540 "-peek-then-read",
10541 "-check-close-notify",
10542 },
10543 })
10544
10545 // Test SSL_peek can discover an alert.
10546 testCases = append(testCases, testCase{
10547 name: "Peek-Alert",
10548 config: Config{
10549 Bugs: ProtocolBugs{
10550 SendSpuriousAlert: alertRecordOverflow,
10551 },
10552 },
10553 flags: []string{"-peek-then-read"},
10554 shouldFail: true,
10555 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
10556 })
10557
10558 // Test SSL_peek can handle KeyUpdate.
10559 testCases = append(testCases, testCase{
10560 name: "Peek-KeyUpdate",
10561 config: Config{
10562 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040010563 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040010564 sendKeyUpdates: 1,
10565 keyUpdateRequest: keyUpdateNotRequested,
10566 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040010567 })
10568}
10569
David Benjamine6f22212016-11-08 14:28:24 -050010570func addRecordVersionTests() {
10571 for _, ver := range tlsVersions {
10572 // Test that the record version is enforced.
10573 testCases = append(testCases, testCase{
10574 name: "CheckRecordVersion-" + ver.name,
10575 config: Config{
10576 MinVersion: ver.version,
10577 MaxVersion: ver.version,
10578 Bugs: ProtocolBugs{
10579 SendRecordVersion: 0x03ff,
10580 },
10581 },
10582 shouldFail: true,
10583 expectedError: ":WRONG_VERSION_NUMBER:",
10584 })
10585
10586 // Test that the ClientHello may use any record version, for
10587 // compatibility reasons.
10588 testCases = append(testCases, testCase{
10589 testType: serverTest,
10590 name: "LooseInitialRecordVersion-" + ver.name,
10591 config: Config{
10592 MinVersion: ver.version,
10593 MaxVersion: ver.version,
10594 Bugs: ProtocolBugs{
10595 SendInitialRecordVersion: 0x03ff,
10596 },
10597 },
10598 })
10599
10600 // Test that garbage ClientHello record versions are rejected.
10601 testCases = append(testCases, testCase{
10602 testType: serverTest,
10603 name: "GarbageInitialRecordVersion-" + ver.name,
10604 config: Config{
10605 MinVersion: ver.version,
10606 MaxVersion: ver.version,
10607 Bugs: ProtocolBugs{
10608 SendInitialRecordVersion: 0xffff,
10609 },
10610 },
10611 shouldFail: true,
10612 expectedError: ":WRONG_VERSION_NUMBER:",
10613 })
10614 }
10615}
10616
David Benjamin2c516452016-11-15 10:16:54 +090010617func addCertificateTests() {
10618 // Test that a certificate chain with intermediate may be sent and
10619 // received as both client and server.
10620 for _, ver := range tlsVersions {
10621 testCases = append(testCases, testCase{
10622 testType: clientTest,
10623 name: "SendReceiveIntermediate-Client-" + ver.name,
10624 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010625 MinVersion: ver.version,
10626 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010627 Certificates: []Certificate{rsaChainCertificate},
10628 ClientAuth: RequireAnyClientCert,
10629 },
10630 expectPeerCertificate: &rsaChainCertificate,
10631 flags: []string{
10632 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10633 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10634 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10635 },
10636 })
10637
10638 testCases = append(testCases, testCase{
10639 testType: serverTest,
10640 name: "SendReceiveIntermediate-Server-" + ver.name,
10641 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010642 MinVersion: ver.version,
10643 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010644 Certificates: []Certificate{rsaChainCertificate},
10645 },
10646 expectPeerCertificate: &rsaChainCertificate,
10647 flags: []string{
10648 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10649 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10650 "-require-any-client-certificate",
10651 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10652 },
10653 })
10654 }
10655}
10656
David Benjaminbbaf3672016-11-17 10:53:09 +090010657func addRetainOnlySHA256ClientCertTests() {
10658 for _, ver := range tlsVersions {
10659 // Test that enabling
10660 // SSL_CTX_set_retain_only_sha256_of_client_certs without
10661 // actually requesting a client certificate is a no-op.
10662 testCases = append(testCases, testCase{
10663 testType: serverTest,
10664 name: "RetainOnlySHA256-NoCert-" + ver.name,
10665 config: Config{
10666 MinVersion: ver.version,
10667 MaxVersion: ver.version,
10668 },
10669 flags: []string{
10670 "-retain-only-sha256-client-cert-initial",
10671 "-retain-only-sha256-client-cert-resume",
10672 },
10673 resumeSession: true,
10674 })
10675
10676 // Test that when retaining only a SHA-256 certificate is
10677 // enabled, the hash appears as expected.
10678 testCases = append(testCases, testCase{
10679 testType: serverTest,
10680 name: "RetainOnlySHA256-Cert-" + ver.name,
10681 config: Config{
10682 MinVersion: ver.version,
10683 MaxVersion: ver.version,
10684 Certificates: []Certificate{rsaCertificate},
10685 },
10686 flags: []string{
10687 "-verify-peer",
10688 "-retain-only-sha256-client-cert-initial",
10689 "-retain-only-sha256-client-cert-resume",
10690 "-expect-sha256-client-cert-initial",
10691 "-expect-sha256-client-cert-resume",
10692 },
10693 resumeSession: true,
10694 })
10695
10696 // Test that when the config changes from on to off, a
10697 // resumption is rejected because the server now wants the full
10698 // certificate chain.
10699 testCases = append(testCases, testCase{
10700 testType: serverTest,
10701 name: "RetainOnlySHA256-OnOff-" + ver.name,
10702 config: Config{
10703 MinVersion: ver.version,
10704 MaxVersion: ver.version,
10705 Certificates: []Certificate{rsaCertificate},
10706 },
10707 flags: []string{
10708 "-verify-peer",
10709 "-retain-only-sha256-client-cert-initial",
10710 "-expect-sha256-client-cert-initial",
10711 },
10712 resumeSession: true,
10713 expectResumeRejected: true,
10714 })
10715
10716 // Test that when the config changes from off to on, a
10717 // resumption is rejected because the server now wants just the
10718 // hash.
10719 testCases = append(testCases, testCase{
10720 testType: serverTest,
10721 name: "RetainOnlySHA256-OffOn-" + ver.name,
10722 config: Config{
10723 MinVersion: ver.version,
10724 MaxVersion: ver.version,
10725 Certificates: []Certificate{rsaCertificate},
10726 },
10727 flags: []string{
10728 "-verify-peer",
10729 "-retain-only-sha256-client-cert-resume",
10730 "-expect-sha256-client-cert-resume",
10731 },
10732 resumeSession: true,
10733 expectResumeRejected: true,
10734 })
10735 }
10736}
10737
Adam Langleya4b91982016-12-12 12:05:53 -080010738func addECDSAKeyUsageTests() {
10739 p256 := elliptic.P256()
10740 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10741 if err != nil {
10742 panic(err)
10743 }
10744
10745 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10746 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10747 if err != nil {
10748 panic(err)
10749 }
10750
10751 template := x509.Certificate{
10752 SerialNumber: serialNumber,
10753 Subject: pkix.Name{
10754 Organization: []string{"Acme Co"},
10755 },
10756 NotBefore: time.Now(),
10757 NotAfter: time.Now(),
10758
10759 // An ECC certificate with only the keyAgreement key usgae may
10760 // be used with ECDH, but not ECDSA.
10761 KeyUsage: x509.KeyUsageKeyAgreement,
10762 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10763 BasicConstraintsValid: true,
10764 }
10765
10766 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10767 if err != nil {
10768 panic(err)
10769 }
10770
10771 cert := Certificate{
10772 Certificate: [][]byte{derBytes},
10773 PrivateKey: priv,
10774 }
10775
10776 for _, ver := range tlsVersions {
10777 if ver.version < VersionTLS12 {
10778 continue
10779 }
10780
10781 testCases = append(testCases, testCase{
10782 testType: clientTest,
10783 name: "ECDSAKeyUsage-" + ver.name,
10784 config: Config{
10785 MinVersion: ver.version,
10786 MaxVersion: ver.version,
10787 Certificates: []Certificate{cert},
10788 },
10789 shouldFail: true,
10790 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10791 })
10792 }
10793}
10794
David Benjamin8c26d752017-03-26 15:13:51 -050010795func addExtraHandshakeTests() {
10796 // An extra SSL_do_handshake is normally a no-op. These tests use -async
10797 // to ensure there is no transport I/O.
10798 testCases = append(testCases, testCase{
10799 testType: clientTest,
10800 name: "ExtraHandshake-Client-TLS12",
10801 config: Config{
10802 MinVersion: VersionTLS12,
10803 MaxVersion: VersionTLS12,
10804 },
10805 flags: []string{
10806 "-async",
10807 "-no-op-extra-handshake",
10808 },
10809 })
10810 testCases = append(testCases, testCase{
10811 testType: serverTest,
10812 name: "ExtraHandshake-Server-TLS12",
10813 config: Config{
10814 MinVersion: VersionTLS12,
10815 MaxVersion: VersionTLS12,
10816 },
10817 flags: []string{
10818 "-async",
10819 "-no-op-extra-handshake",
10820 },
10821 })
10822 testCases = append(testCases, testCase{
10823 testType: clientTest,
10824 name: "ExtraHandshake-Client-TLS13",
10825 config: Config{
10826 MinVersion: VersionTLS13,
10827 MaxVersion: VersionTLS13,
10828 },
10829 flags: []string{
10830 "-async",
10831 "-no-op-extra-handshake",
10832 },
10833 })
10834 testCases = append(testCases, testCase{
10835 testType: serverTest,
10836 name: "ExtraHandshake-Server-TLS13",
10837 config: Config{
10838 MinVersion: VersionTLS13,
10839 MaxVersion: VersionTLS13,
10840 },
10841 flags: []string{
10842 "-async",
10843 "-no-op-extra-handshake",
10844 },
10845 })
10846
10847 // An extra SSL_do_handshake is a no-op in server 0-RTT.
10848 testCases = append(testCases, testCase{
10849 testType: serverTest,
10850 name: "ExtraHandshake-Server-EarlyData-TLS13",
10851 config: Config{
10852 MaxVersion: VersionTLS13,
10853 MinVersion: VersionTLS13,
10854 Bugs: ProtocolBugs{
10855 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10856 ExpectEarlyDataAccepted: true,
10857 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10858 },
10859 },
10860 messageCount: 2,
10861 resumeSession: true,
10862 flags: []string{
10863 "-async",
10864 "-enable-early-data",
10865 "-expect-accept-early-data",
10866 "-no-op-extra-handshake",
10867 },
10868 })
10869
10870 // An extra SSL_do_handshake drives the handshake to completion in False
10871 // Start. We test this by handshaking twice and asserting the False
10872 // Start does not appear to happen. See AlertBeforeFalseStartTest for
10873 // how the test works.
10874 testCases = append(testCases, testCase{
10875 testType: clientTest,
10876 name: "ExtraHandshake-FalseStart",
10877 config: Config{
10878 MaxVersion: VersionTLS12,
10879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
10880 NextProtos: []string{"foo"},
10881 Bugs: ProtocolBugs{
10882 ExpectFalseStart: true,
10883 AlertBeforeFalseStartTest: alertAccessDenied,
10884 },
10885 },
10886 flags: []string{
10887 "-handshake-twice",
10888 "-false-start",
10889 "-advertise-alpn", "\x03foo",
10890 },
10891 shimWritesFirst: true,
10892 shouldFail: true,
10893 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
10894 expectedLocalError: "tls: peer did not false start: EOF",
10895 })
10896}
10897
Adam Langley7c803a62015-06-15 15:35:05 -070010898func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010899 defer wg.Done()
10900
10901 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010902 var err error
10903
David Benjaminba28dfc2016-11-15 17:47:21 +090010904 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010905 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10906 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010907 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010908 if err != nil {
10909 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10910 }
10911 break
10912 }
10913 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010914 } else if *repeatUntilFailure {
10915 for err == nil {
10916 statusChan <- statusMsg{test: test, started: true}
10917 err = runTest(test, shimPath, -1)
10918 }
10919 } else {
10920 statusChan <- statusMsg{test: test, started: true}
10921 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010922 }
Adam Langley95c29f32014-06-20 12:00:00 -070010923 statusChan <- statusMsg{test: test, err: err}
10924 }
10925}
10926
10927type statusMsg struct {
10928 test *testCase
10929 started bool
10930 err error
10931}
10932
David Benjamin5f237bc2015-02-11 17:14:15 -050010933func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010934 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010935
David Benjamin5f237bc2015-02-11 17:14:15 -050010936 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010937 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010938 if !*pipe {
10939 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010940 var erase string
10941 for i := 0; i < lineLen; i++ {
10942 erase += "\b \b"
10943 }
10944 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010945 }
10946
Adam Langley95c29f32014-06-20 12:00:00 -070010947 if msg.started {
10948 started++
10949 } else {
10950 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010951
10952 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010953 if msg.err == errUnimplemented {
10954 if *pipe {
10955 // Print each test instead of a status line.
10956 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10957 }
10958 unimplemented++
10959 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10960 } else {
10961 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10962 failed++
10963 testOutput.addResult(msg.test.name, "FAIL")
10964 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010965 } else {
10966 if *pipe {
10967 // Print each test instead of a status line.
10968 fmt.Printf("PASSED (%s)\n", msg.test.name)
10969 }
10970 testOutput.addResult(msg.test.name, "PASS")
10971 }
Adam Langley95c29f32014-06-20 12:00:00 -070010972 }
10973
David Benjamin5f237bc2015-02-11 17:14:15 -050010974 if !*pipe {
10975 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010976 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010977 lineLen = len(line)
10978 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010979 }
Adam Langley95c29f32014-06-20 12:00:00 -070010980 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010981
10982 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010983}
10984
10985func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010986 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010987 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010988 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010989
Adam Langley7c803a62015-06-15 15:35:05 -070010990 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010991 addCipherSuiteTests()
10992 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010993 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010994 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010995 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010996 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010997 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010998 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010999 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011000 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011001 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011002 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011003 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011004 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011005 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011006 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011007 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011008 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011009 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011010 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011011 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011012 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011013 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011014 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011015 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011016 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011017 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011018 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011019 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011020 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011021 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011022 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011023 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011024 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011025
11026 var wg sync.WaitGroup
11027
Adam Langley7c803a62015-06-15 15:35:05 -070011028 statusChan := make(chan statusMsg, *numWorkers)
11029 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011030 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011031
EKRf71d7ed2016-08-06 13:25:12 -070011032 if len(*shimConfigFile) != 0 {
11033 encoded, err := ioutil.ReadFile(*shimConfigFile)
11034 if err != nil {
11035 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11036 os.Exit(1)
11037 }
11038
11039 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11040 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11041 os.Exit(1)
11042 }
11043 }
11044
David Benjamin025b3d32014-07-01 19:53:04 -040011045 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011046
Adam Langley7c803a62015-06-15 15:35:05 -070011047 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011048 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011049 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011050 }
11051
David Benjamin270f0a72016-03-17 14:41:36 -040011052 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011053 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011054 matched := true
11055 if len(*testToRun) != 0 {
11056 var err error
11057 matched, err = filepath.Match(*testToRun, testCases[i].name)
11058 if err != nil {
11059 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11060 os.Exit(1)
11061 }
11062 }
11063
EKRf71d7ed2016-08-06 13:25:12 -070011064 if !*includeDisabled {
11065 for pattern := range shimConfig.DisabledTests {
11066 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11067 if err != nil {
11068 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11069 os.Exit(1)
11070 }
11071
11072 if isDisabled {
11073 matched = false
11074 break
11075 }
11076 }
11077 }
11078
David Benjamin17e12922016-07-28 18:04:43 -040011079 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011080 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011081 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011082
11083 // Only run one test if repeating until failure.
11084 if *repeatUntilFailure {
11085 break
11086 }
Adam Langley95c29f32014-06-20 12:00:00 -070011087 }
11088 }
David Benjamin17e12922016-07-28 18:04:43 -040011089
David Benjamin270f0a72016-03-17 14:41:36 -040011090 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011091 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011092 os.Exit(1)
11093 }
Adam Langley95c29f32014-06-20 12:00:00 -070011094
11095 close(testChan)
11096 wg.Wait()
11097 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011098 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011099
11100 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011101
11102 if *jsonOutput != "" {
11103 if err := testOutput.writeTo(*jsonOutput); err != nil {
11104 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11105 }
11106 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011107
EKR842ae6c2016-07-27 09:22:05 +020011108 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11109 os.Exit(1)
11110 }
11111
11112 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011113 os.Exit(1)
11114 }
Adam Langley95c29f32014-06-20 12:00:00 -070011115}