blob: 87a79a33357c39d0fac306b0caa776330a6453aa [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"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 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.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090065 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 -080066)
Adam Langley95c29f32014-06-20 12:00:00 -070067
EKRf71d7ed2016-08-06 13:25:12 -070068// ShimConfigurations is used with the “json” package and represents a shim
69// config file.
70type ShimConfiguration struct {
71 // DisabledTests maps from a glob-based pattern to a freeform string.
72 // The glob pattern is used to exclude tests from being run and the
73 // freeform string is unparsed but expected to explain why the test is
74 // disabled.
75 DisabledTests map[string]string
76
77 // ErrorMap maps from expected error strings to the correct error
78 // string for the shim in question. For example, it might map
79 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
80 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
81 ErrorMap map[string]string
82}
83
84var shimConfig ShimConfiguration
85
David Benjamin33863262016-07-08 17:20:12 -070086type testCert int
87
David Benjamin025b3d32014-07-01 19:53:04 -040088const (
David Benjamin33863262016-07-08 17:20:12 -070089 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040090 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090091 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070092 testCertECDSAP256
93 testCertECDSAP384
94 testCertECDSAP521
95)
96
97const (
98 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040099 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900100 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700101 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
102 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
103 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400104)
105
106const (
David Benjamina08e49d2014-08-24 01:46:07 -0400107 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400108 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900109 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700110 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
111 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
112 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400113 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400114)
115
David Benjamin7944a9f2016-07-12 22:27:01 -0400116var (
117 rsaCertificate Certificate
118 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900119 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400120 ecdsaP256Certificate Certificate
121 ecdsaP384Certificate Certificate
122 ecdsaP521Certificate Certificate
123)
David Benjamin33863262016-07-08 17:20:12 -0700124
125var testCerts = []struct {
126 id testCert
127 certFile, keyFile string
128 cert *Certificate
129}{
130 {
131 id: testCertRSA,
132 certFile: rsaCertificateFile,
133 keyFile: rsaKeyFile,
134 cert: &rsaCertificate,
135 },
136 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 id: testCertRSA1024,
138 certFile: rsa1024CertificateFile,
139 keyFile: rsa1024KeyFile,
140 cert: &rsa1024Certificate,
141 },
142 {
David Benjamin2c516452016-11-15 10:16:54 +0900143 id: testCertRSAChain,
144 certFile: rsaChainCertificateFile,
145 keyFile: rsaChainKeyFile,
146 cert: &rsaChainCertificate,
147 },
148 {
David Benjamin33863262016-07-08 17:20:12 -0700149 id: testCertECDSAP256,
150 certFile: ecdsaP256CertificateFile,
151 keyFile: ecdsaP256KeyFile,
152 cert: &ecdsaP256Certificate,
153 },
154 {
155 id: testCertECDSAP384,
156 certFile: ecdsaP384CertificateFile,
157 keyFile: ecdsaP384KeyFile,
158 cert: &ecdsaP384Certificate,
159 },
160 {
161 id: testCertECDSAP521,
162 certFile: ecdsaP521CertificateFile,
163 keyFile: ecdsaP521KeyFile,
164 cert: &ecdsaP521Certificate,
165 },
166}
167
David Benjamina08e49d2014-08-24 01:46:07 -0400168var channelIDKey *ecdsa.PrivateKey
169var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700170
David Benjamin61f95272014-11-25 01:55:35 -0500171var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800172var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500173
Steven Valdeza833c352016-11-01 13:39:36 -0400174var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800175var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400176
Adam Langley95c29f32014-06-20 12:00:00 -0700177func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700178 for i := range testCerts {
179 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
180 if err != nil {
181 panic(err)
182 }
183 cert.OCSPStaple = testOCSPResponse
184 cert.SignedCertificateTimestampList = testSCTList
185 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700186 }
David Benjamina08e49d2014-08-24 01:46:07 -0400187
Adam Langley7c803a62015-06-15 15:35:05 -0700188 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400189 if err != nil {
190 panic(err)
191 }
192 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
193 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
194 panic("bad key type")
195 }
196 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
197 if err != nil {
198 panic(err)
199 }
200 if channelIDKey.Curve != elliptic.P256() {
201 panic("bad curve")
202 }
203
204 channelIDBytes = make([]byte, 64)
205 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
206 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700207}
208
David Benjamin33863262016-07-08 17:20:12 -0700209func getRunnerCertificate(t testCert) Certificate {
210 for _, cert := range testCerts {
211 if cert.id == t {
212 return *cert.cert
213 }
214 }
215 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700216}
217
David Benjamin33863262016-07-08 17:20:12 -0700218func getShimCertificate(t testCert) string {
219 for _, cert := range testCerts {
220 if cert.id == t {
221 return cert.certFile
222 }
223 }
224 panic("Unknown test certificate")
225}
226
227func getShimKey(t testCert) string {
228 for _, cert := range testCerts {
229 if cert.id == t {
230 return cert.keyFile
231 }
232 }
233 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700234}
235
David Benjamin025b3d32014-07-01 19:53:04 -0400236type testType int
237
238const (
239 clientTest testType = iota
240 serverTest
241)
242
David Benjamin6fd297b2014-08-11 18:43:38 -0400243type protocol int
244
245const (
246 tls protocol = iota
247 dtls
248)
249
David Benjaminfc7b0862014-09-06 13:21:53 -0400250const (
251 alpn = 1
252 npn = 2
253)
254
Adam Langley95c29f32014-06-20 12:00:00 -0700255type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400256 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700258 name string
259 config Config
260 shouldFail bool
261 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700262 // expectedLocalError, if not empty, contains a substring that must be
263 // found in the local error.
264 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400265 // expectedVersion, if non-zero, specifies the TLS version that must be
266 // negotiated.
267 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400268 // expectedResumeVersion, if non-zero, specifies the TLS version that
269 // must be negotiated on resumption. If zero, expectedVersion is used.
270 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400271 // expectedCipher, if non-zero, specifies the TLS cipher suite that
272 // should be negotiated.
273 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400274 // expectChannelID controls whether the connection should have
275 // negotiated a Channel ID with channelIDKey.
276 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400277 // expectedNextProto controls whether the connection should
278 // negotiate a next protocol via NPN or ALPN.
279 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400280 // expectNoNextProto, if true, means that no next protocol should be
281 // negotiated.
282 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400283 // expectedNextProtoType, if non-zero, is the expected next
284 // protocol negotiation mechanism.
285 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500286 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
287 // should be negotiated. If zero, none should be negotiated.
288 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100289 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
290 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100291 // expectedSCTList, if not nil, is the expected SCT list to be received.
292 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700293 // expectedPeerSignatureAlgorithm, if not zero, is the signature
294 // algorithm that the peer should have used in the handshake.
295 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400296 // expectedCurveID, if not zero, is the curve that the handshake should
297 // have used.
298 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700299 // messageLen is the length, in bytes, of the test message that will be
300 // sent.
301 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400302 // messageCount is the number of test messages that will be sent.
303 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400304 // certFile is the path to the certificate to use for the server.
305 certFile string
306 // keyFile is the path to the private key to use for the server.
307 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400308 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400309 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400311 // resumeRenewedSession controls whether a third connection should be
312 // tested which attempts to resume the second connection's session.
313 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700314 // expectResumeRejected, if true, specifies that the attempted
315 // resumption must be rejected by the client. This is only valid for a
316 // serverTest.
317 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400318 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500319 // resumption. Unless newSessionsOnResume is set,
320 // SessionTicketKey, ServerSessionCache, and
321 // ClientSessionCache are copied from the initial connection's
322 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400323 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500324 // newSessionsOnResume, if true, will cause resumeConfig to
325 // use a different session resumption context.
326 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400327 // noSessionCache, if true, will cause the server to run without a
328 // session cache.
329 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400330 // sendPrefix sends a prefix on the socket before actually performing a
331 // handshake.
332 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400333 // shimWritesFirst controls whether the shim sends an initial "hello"
334 // message before doing a roundtrip with the runner.
335 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400336 // shimShutsDown, if true, runs a test where the shim shuts down the
337 // connection immediately after the handshake rather than echoing
338 // messages from the runner.
339 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400340 // renegotiate indicates the number of times the connection should be
341 // renegotiated during the exchange.
342 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400343 // sendHalfHelloRequest, if true, causes the server to send half a
344 // HelloRequest when the handshake completes.
345 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700346 // renegotiateCiphers is a list of ciphersuite ids that will be
347 // switched in just before renegotiation.
348 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500349 // replayWrites, if true, configures the underlying transport
350 // to replay every write it makes in DTLS tests.
351 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500352 // damageFirstWrite, if true, configures the underlying transport to
353 // damage the final byte of the first application data write.
354 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400355 // exportKeyingMaterial, if non-zero, configures the test to exchange
356 // keying material and verify they match.
357 exportKeyingMaterial int
358 exportLabel string
359 exportContext string
360 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400361 // flags, if not empty, contains a list of command-line flags that will
362 // be passed to the shim program.
363 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700364 // testTLSUnique, if true, causes the shim to send the tls-unique value
365 // which will be compared against the expected value.
366 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400367 // sendEmptyRecords is the number of consecutive empty records to send
368 // before and after the test message.
369 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400370 // sendWarningAlerts is the number of consecutive warning alerts to send
371 // before and after the test message.
372 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400373 // sendKeyUpdates is the number of consecutive key updates to send
374 // before and after the test message.
375 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400376 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
377 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400378 // expectMessageDropped, if true, means the test message is expected to
379 // be dropped by the client rather than echoed back.
380 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900381 // expectPeerCertificate, if not nil, is the certificate chain the peer
382 // is expected to send.
383 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700384}
385
Adam Langley7c803a62015-06-15 15:35:05 -0700386var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700387
David Benjaminc07afb72016-09-22 10:18:58 -0400388func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500389 if len(data) == 0 {
390 return
391 }
392
393 protocol := "tls"
394 if test.protocol == dtls {
395 protocol = "dtls"
396 }
397
398 side := "client"
399 if test.testType == serverTest {
400 side = "server"
401 }
402
403 dir := path.Join(*transcriptDir, protocol, side)
404 if err := os.MkdirAll(dir, 0755); err != nil {
405 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
406 return
407 }
408
David Benjaminc07afb72016-09-22 10:18:58 -0400409 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500410 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
411 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
412 }
413}
414
David Benjamin3ed59772016-03-08 12:50:21 -0500415// A timeoutConn implements an idle timeout on each Read and Write operation.
416type timeoutConn struct {
417 net.Conn
418 timeout time.Duration
419}
420
421func (t *timeoutConn) Read(b []byte) (int, error) {
422 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
423 return 0, err
424 }
425 return t.Conn.Read(b)
426}
427
428func (t *timeoutConn) Write(b []byte) (int, error) {
429 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
430 return 0, err
431 }
432 return t.Conn.Write(b)
433}
434
David Benjaminc07afb72016-09-22 10:18:58 -0400435func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400436 if !test.noSessionCache {
437 if config.ClientSessionCache == nil {
438 config.ClientSessionCache = NewLRUClientSessionCache(1)
439 }
440 if config.ServerSessionCache == nil {
441 config.ServerSessionCache = NewLRUServerSessionCache(1)
442 }
443 }
444 if test.testType == clientTest {
445 if len(config.Certificates) == 0 {
446 config.Certificates = []Certificate{rsaCertificate}
447 }
448 } else {
449 // Supply a ServerName to ensure a constant session cache key,
450 // rather than falling back to net.Conn.RemoteAddr.
451 if len(config.ServerName) == 0 {
452 config.ServerName = "test"
453 }
454 }
455 if *fuzzer {
456 config.Bugs.NullAllCiphers = true
457 }
David Benjamin01a90572016-09-22 00:11:43 -0400458 if *deterministic {
459 config.Time = func() time.Time { return time.Unix(1234, 1234) }
460 }
David Benjamine54af062016-08-08 19:21:18 -0400461
David Benjamin01784b42016-06-07 18:00:52 -0400462 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500463
David Benjamin6fd297b2014-08-11 18:43:38 -0400464 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500465 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
466 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500467 }
468
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500470 local, peer := "client", "server"
471 if test.testType == clientTest {
472 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500473 }
David Benjaminebda9b32015-11-02 15:33:18 -0500474 connDebug := &recordingConn{
475 Conn: conn,
476 isDatagram: test.protocol == dtls,
477 local: local,
478 peer: peer,
479 }
480 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 if *flagDebug {
482 defer connDebug.WriteTo(os.Stdout)
483 }
484 if len(*transcriptDir) != 0 {
485 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400486 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500487 }()
488 }
David Benjaminebda9b32015-11-02 15:33:18 -0500489
490 if config.Bugs.PacketAdaptor != nil {
491 config.Bugs.PacketAdaptor.debug = connDebug
492 }
493 }
494
495 if test.replayWrites {
496 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 }
498
David Benjamin3ed59772016-03-08 12:50:21 -0500499 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500500 if test.damageFirstWrite {
501 connDamage = newDamageAdaptor(conn)
502 conn = connDamage
503 }
504
David Benjamin6fd297b2014-08-11 18:43:38 -0400505 if test.sendPrefix != "" {
506 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
507 return err
508 }
David Benjamin98e882e2014-08-08 13:24:34 -0400509 }
510
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400512 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400513 if test.protocol == dtls {
514 tlsConn = DTLSServer(conn, config)
515 } else {
516 tlsConn = Server(conn, config)
517 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400518 } else {
519 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400520 if test.protocol == dtls {
521 tlsConn = DTLSClient(conn, config)
522 } else {
523 tlsConn = Client(conn, config)
524 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400525 }
David Benjamin30789da2015-08-29 22:56:45 -0400526 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400527
Adam Langley95c29f32014-06-20 12:00:00 -0700528 if err := tlsConn.Handshake(); err != nil {
529 return err
530 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700531
David Benjamin01fe8202014-09-24 15:21:44 -0400532 // TODO(davidben): move all per-connection expectations into a dedicated
533 // expectations struct that can be specified separately for the two
534 // legs.
535 expectedVersion := test.expectedVersion
536 if isResume && test.expectedResumeVersion != 0 {
537 expectedVersion = test.expectedResumeVersion
538 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 connState := tlsConn.ConnectionState()
540 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400541 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400542 }
543
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700544 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400545 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
546 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700547 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
548 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
549 }
David Benjamin90da8c82015-04-20 14:57:57 -0400550
David Benjamina08e49d2014-08-24 01:46:07 -0400551 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400553 if channelID == nil {
554 return fmt.Errorf("no channel ID negotiated")
555 }
556 if channelID.Curve != channelIDKey.Curve ||
557 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
558 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
559 return fmt.Errorf("incorrect channel ID")
560 }
561 }
562
David Benjaminae2888f2014-09-06 12:58:58 -0400563 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400565 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
566 }
567 }
568
David Benjaminc7ce9772015-10-09 19:32:41 -0400569 if test.expectNoNextProto {
570 if actual := connState.NegotiatedProtocol; actual != "" {
571 return fmt.Errorf("got unexpected next proto %s", actual)
572 }
573 }
574
David Benjaminfc7b0862014-09-06 13:21:53 -0400575 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700576 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400577 return fmt.Errorf("next proto type mismatch")
578 }
579 }
580
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700581 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500582 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
583 }
584
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100585 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300586 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100587 }
588
Paul Lietar4fac72e2015-09-09 13:44:55 +0100589 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
590 return fmt.Errorf("SCT list mismatch")
591 }
592
Nick Harper60edffd2016-06-21 15:19:24 -0700593 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
594 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400595 }
596
Steven Valdez5440fe02016-07-18 12:40:30 -0400597 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
598 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
599 }
600
David Benjamin2c516452016-11-15 10:16:54 +0900601 if test.expectPeerCertificate != nil {
602 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
603 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
604 }
605 for i, cert := range connState.PeerCertificates {
606 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
607 return fmt.Errorf("peer certificate %d did not match", i+1)
608 }
609 }
610 }
611
David Benjaminc565ebb2015-04-03 04:06:36 -0400612 if test.exportKeyingMaterial > 0 {
613 actual := make([]byte, test.exportKeyingMaterial)
614 if _, err := io.ReadFull(tlsConn, actual); err != nil {
615 return err
616 }
617 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
618 if err != nil {
619 return err
620 }
621 if !bytes.Equal(actual, expected) {
622 return fmt.Errorf("keying material mismatch")
623 }
624 }
625
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700626 if test.testTLSUnique {
627 var peersValue [12]byte
628 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
629 return err
630 }
631 expected := tlsConn.ConnectionState().TLSUnique
632 if !bytes.Equal(peersValue[:], expected) {
633 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
634 }
635 }
636
David Benjamine58c4f52014-08-24 03:47:07 -0400637 if test.shimWritesFirst {
638 var buf [5]byte
639 _, err := io.ReadFull(tlsConn, buf[:])
640 if err != nil {
641 return err
642 }
643 if string(buf[:]) != "hello" {
644 return fmt.Errorf("bad initial message")
645 }
646 }
647
Steven Valdez32635b82016-08-16 11:25:03 -0400648 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400649 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400650 return err
651 }
Steven Valdez32635b82016-08-16 11:25:03 -0400652 }
653
David Benjamina8ebe222015-06-06 03:04:39 -0400654 for i := 0; i < test.sendEmptyRecords; i++ {
655 tlsConn.Write(nil)
656 }
657
David Benjamin24f346d2015-06-06 03:28:08 -0400658 for i := 0; i < test.sendWarningAlerts; i++ {
659 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
660 }
661
David Benjamin47921102016-07-28 11:29:18 -0400662 if test.sendHalfHelloRequest {
663 tlsConn.SendHalfHelloRequest()
664 }
665
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400666 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700667 if test.renegotiateCiphers != nil {
668 config.CipherSuites = test.renegotiateCiphers
669 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400670 for i := 0; i < test.renegotiate; i++ {
671 if err := tlsConn.Renegotiate(); err != nil {
672 return err
673 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700674 }
675 } else if test.renegotiateCiphers != nil {
676 panic("renegotiateCiphers without renegotiate")
677 }
678
David Benjamin5fa3eba2015-01-22 16:35:40 -0500679 if test.damageFirstWrite {
680 connDamage.setDamage(true)
681 tlsConn.Write([]byte("DAMAGED WRITE"))
682 connDamage.setDamage(false)
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700686 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400687 if test.protocol == dtls {
688 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
689 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700690 // Read until EOF.
691 _, err := io.Copy(ioutil.Discard, tlsConn)
692 return err
693 }
David Benjamin4417d052015-04-05 04:17:25 -0400694 if messageLen == 0 {
695 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700696 }
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 messageCount := test.messageCount
699 if messageCount == 0 {
700 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400701 }
702
David Benjamin8e6db492015-07-25 18:29:23 -0400703 for j := 0; j < messageCount; j++ {
704 testMessage := make([]byte, messageLen)
705 for i := range testMessage {
706 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400707 }
David Benjamin8e6db492015-07-25 18:29:23 -0400708 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700709
Steven Valdez32635b82016-08-16 11:25:03 -0400710 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400711 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400712 }
713
David Benjamin8e6db492015-07-25 18:29:23 -0400714 for i := 0; i < test.sendEmptyRecords; i++ {
715 tlsConn.Write(nil)
716 }
717
718 for i := 0; i < test.sendWarningAlerts; i++ {
719 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
720 }
721
David Benjamin4f75aaf2015-09-01 16:53:10 -0400722 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400723 // The shim will not respond.
724 continue
725 }
726
David Benjamin8e6db492015-07-25 18:29:23 -0400727 buf := make([]byte, len(testMessage))
728 if test.protocol == dtls {
729 bufTmp := make([]byte, len(buf)+1)
730 n, err := tlsConn.Read(bufTmp)
731 if err != nil {
732 return err
733 }
734 if n != len(buf) {
735 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
736 }
737 copy(buf, bufTmp)
738 } else {
739 _, err := io.ReadFull(tlsConn, buf)
740 if err != nil {
741 return err
742 }
743 }
744
745 for i, v := range buf {
746 if v != testMessage[i]^0xff {
747 return fmt.Errorf("bad reply contents at byte %d", i)
748 }
Adam Langley95c29f32014-06-20 12:00:00 -0700749 }
750 }
751
752 return nil
753}
754
David Benjamin325b5c32014-07-01 19:40:31 -0400755func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400756 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700757 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400758 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700759 }
David Benjamin325b5c32014-07-01 19:40:31 -0400760 valgrindArgs = append(valgrindArgs, path)
761 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700762
David Benjamin325b5c32014-07-01 19:40:31 -0400763 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
David Benjamin325b5c32014-07-01 19:40:31 -0400766func gdbOf(path string, args ...string) *exec.Cmd {
767 xtermArgs := []string{"-e", "gdb", "--args"}
768 xtermArgs = append(xtermArgs, path)
769 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamind16bf342015-12-18 00:53:12 -0500774func lldbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "lldb", "--"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
778
779 return exec.Command("xterm", xtermArgs...)
780}
781
EKR842ae6c2016-07-27 09:22:05 +0200782var (
783 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
784 errUnimplemented = errors.New("child process does not implement needed flags")
785)
Adam Langley69a01602014-11-17 17:26:55 -0800786
David Benjamin87c8a642015-02-21 01:54:29 -0500787// accept accepts a connection from listener, unless waitChan signals a process
788// exit first.
789func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
790 type connOrError struct {
791 conn net.Conn
792 err error
793 }
794 connChan := make(chan connOrError, 1)
795 go func() {
796 conn, err := listener.Accept()
797 connChan <- connOrError{conn, err}
798 close(connChan)
799 }()
800 select {
801 case result := <-connChan:
802 return result.conn, result.err
803 case childErr := <-waitChan:
804 waitChan <- childErr
805 return nil, fmt.Errorf("child exited early: %s", childErr)
806 }
807}
808
EKRf71d7ed2016-08-06 13:25:12 -0700809func translateExpectedError(errorStr string) string {
810 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
811 return translated
812 }
813
814 if *looseErrors {
815 return ""
816 }
817
818 return errorStr
819}
820
Adam Langley7c803a62015-06-15 15:35:05 -0700821func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400822 // Help debugging panics on the Go side.
823 defer func() {
824 if r := recover(); r != nil {
825 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
826 panic(r)
827 }
828 }()
829
Adam Langley38311732014-10-16 19:04:35 -0700830 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
831 panic("Error expected without shouldFail in " + test.name)
832 }
833
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700834 if test.expectResumeRejected && !test.resumeSession {
835 panic("expectResumeRejected without resumeSession in " + test.name)
836 }
837
Adam Langley33b1d4f2016-12-07 15:03:45 -0800838 for _, ver := range tlsVersions {
839 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
840 continue
841 }
842
843 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
844 continue
845 }
846
847 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))
848 }
849
David Benjamin87c8a642015-02-21 01:54:29 -0500850 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
851 if err != nil {
852 panic(err)
853 }
854 defer func() {
855 if listener != nil {
856 listener.Close()
857 }
858 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700859
David Benjamin87c8a642015-02-21 01:54:29 -0500860 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400861 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400862 flags = append(flags, "-server")
863
David Benjamin025b3d32014-07-01 19:53:04 -0400864 flags = append(flags, "-key-file")
865 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700866 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400867 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700868 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400869 }
870
871 flags = append(flags, "-cert-file")
872 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400874 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700875 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400876 }
877 }
David Benjamin5a593af2014-08-11 19:51:50 -0400878
David Benjamin6fd297b2014-08-11 18:43:38 -0400879 if test.protocol == dtls {
880 flags = append(flags, "-dtls")
881 }
882
David Benjamin46662482016-08-17 00:51:00 -0400883 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400884 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400885 resumeCount++
886 if test.resumeRenewedSession {
887 resumeCount++
888 }
889 }
890
891 if resumeCount > 0 {
892 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400893 }
894
David Benjamine58c4f52014-08-24 03:47:07 -0400895 if test.shimWritesFirst {
896 flags = append(flags, "-shim-writes-first")
897 }
898
David Benjamin30789da2015-08-29 22:56:45 -0400899 if test.shimShutsDown {
900 flags = append(flags, "-shim-shuts-down")
901 }
902
David Benjaminc565ebb2015-04-03 04:06:36 -0400903 if test.exportKeyingMaterial > 0 {
904 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
905 flags = append(flags, "-export-label", test.exportLabel)
906 flags = append(flags, "-export-context", test.exportContext)
907 if test.useExportContext {
908 flags = append(flags, "-use-export-context")
909 }
910 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700911 if test.expectResumeRejected {
912 flags = append(flags, "-expect-session-miss")
913 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400914
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700915 if test.testTLSUnique {
916 flags = append(flags, "-tls-unique")
917 }
918
David Benjamin025b3d32014-07-01 19:53:04 -0400919 flags = append(flags, test.flags...)
920
921 var shim *exec.Cmd
922 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700923 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700924 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700925 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500926 } else if *useLLDB {
927 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400928 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700929 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400930 }
David Benjamin025b3d32014-07-01 19:53:04 -0400931 shim.Stdin = os.Stdin
932 var stdoutBuf, stderrBuf bytes.Buffer
933 shim.Stdout = &stdoutBuf
934 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800935 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500936 shim.Env = os.Environ()
937 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800938 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400939 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800940 }
941 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
942 }
David Benjamin025b3d32014-07-01 19:53:04 -0400943
944 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700945 panic(err)
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 waitChan := make(chan error, 1)
948 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700949
950 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin7a4aaa42016-09-20 17:58:14 -0400952 if *deterministic {
953 config.Rand = &deterministicRand{}
954 }
955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 conn, err := acceptOrWait(listener, waitChan)
957 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400958 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500959 conn.Close()
960 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500961
David Benjamin46662482016-08-17 00:51:00 -0400962 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400963 var resumeConfig Config
964 if test.resumeConfig != nil {
965 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400966 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500967 resumeConfig.SessionTicketKey = config.SessionTicketKey
968 resumeConfig.ClientSessionCache = config.ClientSessionCache
969 resumeConfig.ServerSessionCache = config.ServerSessionCache
970 }
David Benjamin2e045a92016-06-08 13:09:56 -0400971 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400972 } else {
973 resumeConfig = config
974 }
David Benjamin87c8a642015-02-21 01:54:29 -0500975 var connResume net.Conn
976 connResume, err = acceptOrWait(listener, waitChan)
977 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400978 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500979 connResume.Close()
980 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400981 }
982
David Benjamin87c8a642015-02-21 01:54:29 -0500983 // Close the listener now. This is to avoid hangs should the shim try to
984 // open more connections than expected.
985 listener.Close()
986 listener = nil
987
988 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400989 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800990 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200991 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
992 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800993 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200994 case 89:
995 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400996 case 99:
997 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800998 }
999 }
Adam Langley95c29f32014-06-20 12:00:00 -07001000
David Benjamin9bea3492016-03-02 10:59:16 -05001001 // Account for Windows line endings.
1002 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1003 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001004
1005 // Separate the errors from the shim and those from tools like
1006 // AddressSanitizer.
1007 var extraStderr string
1008 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1009 stderr = stderrParts[0]
1010 extraStderr = stderrParts[1]
1011 }
1012
Adam Langley95c29f32014-06-20 12:00:00 -07001013 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001014 expectedError := translateExpectedError(test.expectedError)
1015 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001016
Adam Langleyac61fa32014-06-23 12:03:11 -07001017 localError := "none"
1018 if err != nil {
1019 localError = err.Error()
1020 }
1021 if len(test.expectedLocalError) != 0 {
1022 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1023 }
Adam Langley95c29f32014-06-20 12:00:00 -07001024
1025 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001026 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001027 if childErr != nil {
1028 childError = childErr.Error()
1029 }
1030
1031 var msg string
1032 switch {
1033 case failed && !test.shouldFail:
1034 msg = "unexpected failure"
1035 case !failed && test.shouldFail:
1036 msg = "unexpected success"
1037 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001038 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001039 default:
1040 panic("internal error")
1041 }
1042
David Benjamin9aafb642016-09-20 19:36:53 -04001043 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 -07001044 }
1045
David Benjamind2ba8892016-09-20 19:41:04 -04001046 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001047 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001048 }
1049
David Benjamind2ba8892016-09-20 19:41:04 -04001050 if *useValgrind && isValgrindError {
1051 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1052 }
1053
Adam Langley95c29f32014-06-20 12:00:00 -07001054 return nil
1055}
1056
1057var tlsVersions = []struct {
1058 name string
1059 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001060 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001061 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001062}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001063 {"SSL3", VersionSSL30, "-no-ssl3", false},
1064 {"TLS1", VersionTLS10, "-no-tls1", true},
1065 {"TLS11", VersionTLS11, "-no-tls11", false},
1066 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001067 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001068}
1069
1070var testCipherSuites = []struct {
1071 name string
1072 id uint16
1073}{
1074 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001075 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001076 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001077 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001078 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001079 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001080 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001081 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1082 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001083 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001084 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1085 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001086 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001087 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1088 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001089 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1090 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001091 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001092 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001093 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001094 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001095 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001096 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001097 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001098 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001099 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001100 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001101 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001102 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
David Benjamin48cae082014-10-27 01:06:24 -04001103 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1104 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001105 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1106 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001107 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001108 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1109 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1110 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001111 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001112}
1113
David Benjamin8b8c0062014-11-23 02:47:52 -05001114func hasComponent(suiteName, component string) bool {
1115 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1116}
1117
David Benjaminf7768e42014-08-31 02:06:47 -04001118func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001119 return hasComponent(suiteName, "GCM") ||
1120 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001121 hasComponent(suiteName, "SHA384") ||
1122 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001123}
1124
Nick Harper1fd39d82016-06-14 18:14:35 -07001125func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001126 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001127}
1128
David Benjamin8b8c0062014-11-23 02:47:52 -05001129func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001130 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001131}
1132
Adam Langleya7997f12015-05-14 17:38:50 -07001133func bigFromHex(hex string) *big.Int {
1134 ret, ok := new(big.Int).SetString(hex, 16)
1135 if !ok {
1136 panic("failed to parse hex number 0x" + hex)
1137 }
1138 return ret
1139}
1140
Adam Langley7c803a62015-06-15 15:35:05 -07001141func addBasicTests() {
1142 basicTests := []testCase{
1143 {
Adam Langley7c803a62015-06-15 15:35:05 -07001144 name: "NoFallbackSCSV",
1145 config: Config{
1146 Bugs: ProtocolBugs{
1147 FailIfNotFallbackSCSV: true,
1148 },
1149 },
1150 shouldFail: true,
1151 expectedLocalError: "no fallback SCSV found",
1152 },
1153 {
1154 name: "SendFallbackSCSV",
1155 config: Config{
1156 Bugs: ProtocolBugs{
1157 FailIfNotFallbackSCSV: true,
1158 },
1159 },
1160 flags: []string{"-fallback-scsv"},
1161 },
1162 {
1163 name: "ClientCertificateTypes",
1164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001165 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001166 ClientAuth: RequestClientCert,
1167 ClientCertificateTypes: []byte{
1168 CertTypeDSSSign,
1169 CertTypeRSASign,
1170 CertTypeECDSASign,
1171 },
1172 },
1173 flags: []string{
1174 "-expect-certificate-types",
1175 base64.StdEncoding.EncodeToString([]byte{
1176 CertTypeDSSSign,
1177 CertTypeRSASign,
1178 CertTypeECDSASign,
1179 }),
1180 },
1181 },
1182 {
Adam Langley7c803a62015-06-15 15:35:05 -07001183 name: "UnauthenticatedECDH",
1184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001185 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1187 Bugs: ProtocolBugs{
1188 UnauthenticatedECDH: true,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":UNEXPECTED_MESSAGE:",
1193 },
1194 {
1195 name: "SkipCertificateStatus",
1196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001197 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1199 Bugs: ProtocolBugs{
1200 SkipCertificateStatus: true,
1201 },
1202 },
1203 flags: []string{
1204 "-enable-ocsp-stapling",
1205 },
1206 },
1207 {
1208 name: "SkipServerKeyExchange",
1209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001210 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1212 Bugs: ProtocolBugs{
1213 SkipServerKeyExchange: true,
1214 },
1215 },
1216 shouldFail: true,
1217 expectedError: ":UNEXPECTED_MESSAGE:",
1218 },
1219 {
Adam Langley7c803a62015-06-15 15:35:05 -07001220 testType: serverTest,
1221 name: "Alert",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 SendSpuriousAlert: alertRecordOverflow,
1225 },
1226 },
1227 shouldFail: true,
1228 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1229 },
1230 {
1231 protocol: dtls,
1232 testType: serverTest,
1233 name: "Alert-DTLS",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 SendSpuriousAlert: alertRecordOverflow,
1237 },
1238 },
1239 shouldFail: true,
1240 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1241 },
1242 {
1243 testType: serverTest,
1244 name: "FragmentAlert",
1245 config: Config{
1246 Bugs: ProtocolBugs{
1247 FragmentAlert: true,
1248 SendSpuriousAlert: alertRecordOverflow,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":BAD_ALERT:",
1253 },
1254 {
1255 protocol: dtls,
1256 testType: serverTest,
1257 name: "FragmentAlert-DTLS",
1258 config: Config{
1259 Bugs: ProtocolBugs{
1260 FragmentAlert: true,
1261 SendSpuriousAlert: alertRecordOverflow,
1262 },
1263 },
1264 shouldFail: true,
1265 expectedError: ":BAD_ALERT:",
1266 },
1267 {
1268 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001269 name: "DoubleAlert",
1270 config: Config{
1271 Bugs: ProtocolBugs{
1272 DoubleAlert: true,
1273 SendSpuriousAlert: alertRecordOverflow,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":BAD_ALERT:",
1278 },
1279 {
1280 protocol: dtls,
1281 testType: serverTest,
1282 name: "DoubleAlert-DTLS",
1283 config: Config{
1284 Bugs: ProtocolBugs{
1285 DoubleAlert: true,
1286 SendSpuriousAlert: alertRecordOverflow,
1287 },
1288 },
1289 shouldFail: true,
1290 expectedError: ":BAD_ALERT:",
1291 },
1292 {
Adam Langley7c803a62015-06-15 15:35:05 -07001293 name: "SkipNewSessionTicket",
1294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001295 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001296 Bugs: ProtocolBugs{
1297 SkipNewSessionTicket: true,
1298 },
1299 },
1300 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001301 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001302 },
1303 {
1304 testType: serverTest,
1305 name: "FallbackSCSV",
1306 config: Config{
1307 MaxVersion: VersionTLS11,
1308 Bugs: ProtocolBugs{
1309 SendFallbackSCSV: true,
1310 },
1311 },
1312 shouldFail: true,
1313 expectedError: ":INAPPROPRIATE_FALLBACK:",
1314 },
1315 {
1316 testType: serverTest,
1317 name: "FallbackSCSV-VersionMatch",
1318 config: Config{
1319 Bugs: ProtocolBugs{
1320 SendFallbackSCSV: true,
1321 },
1322 },
1323 },
1324 {
1325 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001326 name: "FallbackSCSV-VersionMatch-TLS12",
1327 config: Config{
1328 MaxVersion: VersionTLS12,
1329 Bugs: ProtocolBugs{
1330 SendFallbackSCSV: true,
1331 },
1332 },
1333 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1334 },
1335 {
1336 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001337 name: "FragmentedClientVersion",
1338 config: Config{
1339 Bugs: ProtocolBugs{
1340 MaxHandshakeRecordLength: 1,
1341 FragmentClientVersion: true,
1342 },
1343 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001344 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001345 },
1346 {
Adam Langley7c803a62015-06-15 15:35:05 -07001347 testType: serverTest,
1348 name: "HttpGET",
1349 sendPrefix: "GET / HTTP/1.0\n",
1350 shouldFail: true,
1351 expectedError: ":HTTP_REQUEST:",
1352 },
1353 {
1354 testType: serverTest,
1355 name: "HttpPOST",
1356 sendPrefix: "POST / HTTP/1.0\n",
1357 shouldFail: true,
1358 expectedError: ":HTTP_REQUEST:",
1359 },
1360 {
1361 testType: serverTest,
1362 name: "HttpHEAD",
1363 sendPrefix: "HEAD / HTTP/1.0\n",
1364 shouldFail: true,
1365 expectedError: ":HTTP_REQUEST:",
1366 },
1367 {
1368 testType: serverTest,
1369 name: "HttpPUT",
1370 sendPrefix: "PUT / HTTP/1.0\n",
1371 shouldFail: true,
1372 expectedError: ":HTTP_REQUEST:",
1373 },
1374 {
1375 testType: serverTest,
1376 name: "HttpCONNECT",
1377 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1378 shouldFail: true,
1379 expectedError: ":HTTPS_PROXY_REQUEST:",
1380 },
1381 {
1382 testType: serverTest,
1383 name: "Garbage",
1384 sendPrefix: "blah",
1385 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001386 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001387 },
1388 {
Adam Langley7c803a62015-06-15 15:35:05 -07001389 name: "RSAEphemeralKey",
1390 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001391 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001392 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1393 Bugs: ProtocolBugs{
1394 RSAEphemeralKey: true,
1395 },
1396 },
1397 shouldFail: true,
1398 expectedError: ":UNEXPECTED_MESSAGE:",
1399 },
1400 {
1401 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001402 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001403 shouldFail: true,
1404 expectedError: ":WRONG_SSL_VERSION:",
1405 },
1406 {
1407 protocol: dtls,
1408 name: "DisableEverything-DTLS",
1409 flags: []string{"-no-tls12", "-no-tls1"},
1410 shouldFail: true,
1411 expectedError: ":WRONG_SSL_VERSION:",
1412 },
1413 {
Adam Langley7c803a62015-06-15 15:35:05 -07001414 protocol: dtls,
1415 testType: serverTest,
1416 name: "MTU",
1417 config: Config{
1418 Bugs: ProtocolBugs{
1419 MaxPacketLength: 256,
1420 },
1421 },
1422 flags: []string{"-mtu", "256"},
1423 },
1424 {
1425 protocol: dtls,
1426 testType: serverTest,
1427 name: "MTUExceeded",
1428 config: Config{
1429 Bugs: ProtocolBugs{
1430 MaxPacketLength: 255,
1431 },
1432 },
1433 flags: []string{"-mtu", "256"},
1434 shouldFail: true,
1435 expectedLocalError: "dtls: exceeded maximum packet length",
1436 },
1437 {
1438 name: "CertMismatchRSA",
1439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001440 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001441 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001442 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001443 Bugs: ProtocolBugs{
1444 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1445 },
1446 },
1447 shouldFail: true,
1448 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1449 },
1450 {
1451 name: "CertMismatchECDSA",
1452 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001453 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001454 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001455 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001456 Bugs: ProtocolBugs{
1457 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1458 },
1459 },
1460 shouldFail: true,
1461 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1462 },
1463 {
1464 name: "EmptyCertificateList",
1465 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001466 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001467 Bugs: ProtocolBugs{
1468 EmptyCertificateList: true,
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":DECODE_ERROR:",
1473 },
1474 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001475 name: "EmptyCertificateList-TLS13",
1476 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001477 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001478 Bugs: ProtocolBugs{
1479 EmptyCertificateList: true,
1480 },
1481 },
1482 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001483 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001484 },
1485 {
Adam Langley7c803a62015-06-15 15:35:05 -07001486 name: "TLSFatalBadPackets",
1487 damageFirstWrite: true,
1488 shouldFail: true,
1489 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1490 },
1491 {
1492 protocol: dtls,
1493 name: "DTLSIgnoreBadPackets",
1494 damageFirstWrite: true,
1495 },
1496 {
1497 protocol: dtls,
1498 name: "DTLSIgnoreBadPackets-Async",
1499 damageFirstWrite: true,
1500 flags: []string{"-async"},
1501 },
1502 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001503 name: "AppDataBeforeHandshake",
1504 config: Config{
1505 Bugs: ProtocolBugs{
1506 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1507 },
1508 },
1509 shouldFail: true,
1510 expectedError: ":UNEXPECTED_RECORD:",
1511 },
1512 {
1513 name: "AppDataBeforeHandshake-Empty",
1514 config: Config{
1515 Bugs: ProtocolBugs{
1516 AppDataBeforeHandshake: []byte{},
1517 },
1518 },
1519 shouldFail: true,
1520 expectedError: ":UNEXPECTED_RECORD:",
1521 },
1522 {
1523 protocol: dtls,
1524 name: "AppDataBeforeHandshake-DTLS",
1525 config: Config{
1526 Bugs: ProtocolBugs{
1527 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1528 },
1529 },
1530 shouldFail: true,
1531 expectedError: ":UNEXPECTED_RECORD:",
1532 },
1533 {
1534 protocol: dtls,
1535 name: "AppDataBeforeHandshake-DTLS-Empty",
1536 config: Config{
1537 Bugs: ProtocolBugs{
1538 AppDataBeforeHandshake: []byte{},
1539 },
1540 },
1541 shouldFail: true,
1542 expectedError: ":UNEXPECTED_RECORD:",
1543 },
1544 {
Adam Langley7c803a62015-06-15 15:35:05 -07001545 name: "AppDataAfterChangeCipherSpec",
1546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001547 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001548 Bugs: ProtocolBugs{
1549 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1550 },
1551 },
1552 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001553 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001554 },
1555 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001556 name: "AppDataAfterChangeCipherSpec-Empty",
1557 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001558 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001559 Bugs: ProtocolBugs{
1560 AppDataAfterChangeCipherSpec: []byte{},
1561 },
1562 },
1563 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001564 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001565 },
1566 {
Adam Langley7c803a62015-06-15 15:35:05 -07001567 protocol: dtls,
1568 name: "AppDataAfterChangeCipherSpec-DTLS",
1569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001570 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001571 Bugs: ProtocolBugs{
1572 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1573 },
1574 },
1575 // BoringSSL's DTLS implementation will drop the out-of-order
1576 // application data.
1577 },
1578 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 protocol: dtls,
1580 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001582 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001583 Bugs: ProtocolBugs{
1584 AppDataAfterChangeCipherSpec: []byte{},
1585 },
1586 },
1587 // BoringSSL's DTLS implementation will drop the out-of-order
1588 // application data.
1589 },
1590 {
Adam Langley7c803a62015-06-15 15:35:05 -07001591 name: "AlertAfterChangeCipherSpec",
1592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001593 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001594 Bugs: ProtocolBugs{
1595 AlertAfterChangeCipherSpec: alertRecordOverflow,
1596 },
1597 },
1598 shouldFail: true,
1599 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1600 },
1601 {
1602 protocol: dtls,
1603 name: "AlertAfterChangeCipherSpec-DTLS",
1604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001605 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001606 Bugs: ProtocolBugs{
1607 AlertAfterChangeCipherSpec: alertRecordOverflow,
1608 },
1609 },
1610 shouldFail: true,
1611 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1612 },
1613 {
1614 protocol: dtls,
1615 name: "ReorderHandshakeFragments-Small-DTLS",
1616 config: Config{
1617 Bugs: ProtocolBugs{
1618 ReorderHandshakeFragments: true,
1619 // Small enough that every handshake message is
1620 // fragmented.
1621 MaxHandshakeRecordLength: 2,
1622 },
1623 },
1624 },
1625 {
1626 protocol: dtls,
1627 name: "ReorderHandshakeFragments-Large-DTLS",
1628 config: Config{
1629 Bugs: ProtocolBugs{
1630 ReorderHandshakeFragments: true,
1631 // Large enough that no handshake message is
1632 // fragmented.
1633 MaxHandshakeRecordLength: 2048,
1634 },
1635 },
1636 },
1637 {
1638 protocol: dtls,
1639 name: "MixCompleteMessageWithFragments-DTLS",
1640 config: Config{
1641 Bugs: ProtocolBugs{
1642 ReorderHandshakeFragments: true,
1643 MixCompleteMessageWithFragments: true,
1644 MaxHandshakeRecordLength: 2,
1645 },
1646 },
1647 },
1648 {
1649 name: "SendInvalidRecordType",
1650 config: Config{
1651 Bugs: ProtocolBugs{
1652 SendInvalidRecordType: true,
1653 },
1654 },
1655 shouldFail: true,
1656 expectedError: ":UNEXPECTED_RECORD:",
1657 },
1658 {
1659 protocol: dtls,
1660 name: "SendInvalidRecordType-DTLS",
1661 config: Config{
1662 Bugs: ProtocolBugs{
1663 SendInvalidRecordType: true,
1664 },
1665 },
1666 shouldFail: true,
1667 expectedError: ":UNEXPECTED_RECORD:",
1668 },
1669 {
1670 name: "FalseStart-SkipServerSecondLeg",
1671 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001672 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001673 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1674 NextProtos: []string{"foo"},
1675 Bugs: ProtocolBugs{
1676 SkipNewSessionTicket: true,
1677 SkipChangeCipherSpec: true,
1678 SkipFinished: true,
1679 ExpectFalseStart: true,
1680 },
1681 },
1682 flags: []string{
1683 "-false-start",
1684 "-handshake-never-done",
1685 "-advertise-alpn", "\x03foo",
1686 },
1687 shimWritesFirst: true,
1688 shouldFail: true,
1689 expectedError: ":UNEXPECTED_RECORD:",
1690 },
1691 {
1692 name: "FalseStart-SkipServerSecondLeg-Implicit",
1693 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001694 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1696 NextProtos: []string{"foo"},
1697 Bugs: ProtocolBugs{
1698 SkipNewSessionTicket: true,
1699 SkipChangeCipherSpec: true,
1700 SkipFinished: true,
1701 },
1702 },
1703 flags: []string{
1704 "-implicit-handshake",
1705 "-false-start",
1706 "-handshake-never-done",
1707 "-advertise-alpn", "\x03foo",
1708 },
1709 shouldFail: true,
1710 expectedError: ":UNEXPECTED_RECORD:",
1711 },
1712 {
1713 testType: serverTest,
1714 name: "FailEarlyCallback",
1715 flags: []string{"-fail-early-callback"},
1716 shouldFail: true,
1717 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001718 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001719 },
1720 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001721 name: "FailCertCallback-Client-TLS12",
1722 config: Config{
1723 MaxVersion: VersionTLS12,
1724 ClientAuth: RequestClientCert,
1725 },
1726 flags: []string{"-fail-cert-callback"},
1727 shouldFail: true,
1728 expectedError: ":CERT_CB_ERROR:",
1729 expectedLocalError: "remote error: internal error",
1730 },
1731 {
1732 testType: serverTest,
1733 name: "FailCertCallback-Server-TLS12",
1734 config: Config{
1735 MaxVersion: VersionTLS12,
1736 },
1737 flags: []string{"-fail-cert-callback"},
1738 shouldFail: true,
1739 expectedError: ":CERT_CB_ERROR:",
1740 expectedLocalError: "remote error: internal error",
1741 },
1742 {
1743 name: "FailCertCallback-Client-TLS13",
1744 config: Config{
1745 MaxVersion: VersionTLS13,
1746 ClientAuth: RequestClientCert,
1747 },
1748 flags: []string{"-fail-cert-callback"},
1749 shouldFail: true,
1750 expectedError: ":CERT_CB_ERROR:",
1751 expectedLocalError: "remote error: internal error",
1752 },
1753 {
1754 testType: serverTest,
1755 name: "FailCertCallback-Server-TLS13",
1756 config: Config{
1757 MaxVersion: VersionTLS13,
1758 },
1759 flags: []string{"-fail-cert-callback"},
1760 shouldFail: true,
1761 expectedError: ":CERT_CB_ERROR:",
1762 expectedLocalError: "remote error: internal error",
1763 },
1764 {
Adam Langley7c803a62015-06-15 15:35:05 -07001765 protocol: dtls,
1766 name: "FragmentMessageTypeMismatch-DTLS",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 MaxHandshakeRecordLength: 2,
1770 FragmentMessageTypeMismatch: true,
1771 },
1772 },
1773 shouldFail: true,
1774 expectedError: ":FRAGMENT_MISMATCH:",
1775 },
1776 {
1777 protocol: dtls,
1778 name: "FragmentMessageLengthMismatch-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 MaxHandshakeRecordLength: 2,
1782 FragmentMessageLengthMismatch: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":FRAGMENT_MISMATCH:",
1787 },
1788 {
1789 protocol: dtls,
1790 name: "SplitFragments-Header-DTLS",
1791 config: Config{
1792 Bugs: ProtocolBugs{
1793 SplitFragments: 2,
1794 },
1795 },
1796 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001797 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001798 },
1799 {
1800 protocol: dtls,
1801 name: "SplitFragments-Boundary-DTLS",
1802 config: Config{
1803 Bugs: ProtocolBugs{
1804 SplitFragments: dtlsRecordHeaderLen,
1805 },
1806 },
1807 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001808 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001809 },
1810 {
1811 protocol: dtls,
1812 name: "SplitFragments-Body-DTLS",
1813 config: Config{
1814 Bugs: ProtocolBugs{
1815 SplitFragments: dtlsRecordHeaderLen + 1,
1816 },
1817 },
1818 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001819 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001820 },
1821 {
1822 protocol: dtls,
1823 name: "SendEmptyFragments-DTLS",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 SendEmptyFragments: true,
1827 },
1828 },
1829 },
1830 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001831 name: "BadFinished-Client",
1832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001833 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 },
1837 },
1838 shouldFail: true,
1839 expectedError: ":DIGEST_CHECK_FAILED:",
1840 },
1841 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001842 name: "BadFinished-Client-TLS13",
1843 config: Config{
1844 MaxVersion: VersionTLS13,
1845 Bugs: ProtocolBugs{
1846 BadFinished: true,
1847 },
1848 },
1849 shouldFail: true,
1850 expectedError: ":DIGEST_CHECK_FAILED:",
1851 },
1852 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001853 testType: serverTest,
1854 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001856 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001857 Bugs: ProtocolBugs{
1858 BadFinished: true,
1859 },
1860 },
1861 shouldFail: true,
1862 expectedError: ":DIGEST_CHECK_FAILED:",
1863 },
1864 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001865 testType: serverTest,
1866 name: "BadFinished-Server-TLS13",
1867 config: Config{
1868 MaxVersion: VersionTLS13,
1869 Bugs: ProtocolBugs{
1870 BadFinished: true,
1871 },
1872 },
1873 shouldFail: true,
1874 expectedError: ":DIGEST_CHECK_FAILED:",
1875 },
1876 {
Adam Langley7c803a62015-06-15 15:35:05 -07001877 name: "FalseStart-BadFinished",
1878 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001879 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1881 NextProtos: []string{"foo"},
1882 Bugs: ProtocolBugs{
1883 BadFinished: true,
1884 ExpectFalseStart: true,
1885 },
1886 },
1887 flags: []string{
1888 "-false-start",
1889 "-handshake-never-done",
1890 "-advertise-alpn", "\x03foo",
1891 },
1892 shimWritesFirst: true,
1893 shouldFail: true,
1894 expectedError: ":DIGEST_CHECK_FAILED:",
1895 },
1896 {
1897 name: "NoFalseStart-NoALPN",
1898 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001899 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001900 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1901 Bugs: ProtocolBugs{
1902 ExpectFalseStart: true,
1903 AlertBeforeFalseStartTest: alertAccessDenied,
1904 },
1905 },
1906 flags: []string{
1907 "-false-start",
1908 },
1909 shimWritesFirst: true,
1910 shouldFail: true,
1911 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1912 expectedLocalError: "tls: peer did not false start: EOF",
1913 },
1914 {
1915 name: "NoFalseStart-NoAEAD",
1916 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001917 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1919 NextProtos: []string{"foo"},
1920 Bugs: ProtocolBugs{
1921 ExpectFalseStart: true,
1922 AlertBeforeFalseStartTest: alertAccessDenied,
1923 },
1924 },
1925 flags: []string{
1926 "-false-start",
1927 "-advertise-alpn", "\x03foo",
1928 },
1929 shimWritesFirst: true,
1930 shouldFail: true,
1931 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1932 expectedLocalError: "tls: peer did not false start: EOF",
1933 },
1934 {
1935 name: "NoFalseStart-RSA",
1936 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001937 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001938 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1939 NextProtos: []string{"foo"},
1940 Bugs: ProtocolBugs{
1941 ExpectFalseStart: true,
1942 AlertBeforeFalseStartTest: alertAccessDenied,
1943 },
1944 },
1945 flags: []string{
1946 "-false-start",
1947 "-advertise-alpn", "\x03foo",
1948 },
1949 shimWritesFirst: true,
1950 shouldFail: true,
1951 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1952 expectedLocalError: "tls: peer did not false start: EOF",
1953 },
1954 {
1955 name: "NoFalseStart-DHE_RSA",
1956 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001957 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001958 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1959 NextProtos: []string{"foo"},
1960 Bugs: ProtocolBugs{
1961 ExpectFalseStart: true,
1962 AlertBeforeFalseStartTest: alertAccessDenied,
1963 },
1964 },
1965 flags: []string{
1966 "-false-start",
1967 "-advertise-alpn", "\x03foo",
1968 },
1969 shimWritesFirst: true,
1970 shouldFail: true,
1971 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1972 expectedLocalError: "tls: peer did not false start: EOF",
1973 },
1974 {
Adam Langley7c803a62015-06-15 15:35:05 -07001975 protocol: dtls,
1976 name: "SendSplitAlert-Sync",
1977 config: Config{
1978 Bugs: ProtocolBugs{
1979 SendSplitAlert: true,
1980 },
1981 },
1982 },
1983 {
1984 protocol: dtls,
1985 name: "SendSplitAlert-Async",
1986 config: Config{
1987 Bugs: ProtocolBugs{
1988 SendSplitAlert: true,
1989 },
1990 },
1991 flags: []string{"-async"},
1992 },
1993 {
1994 protocol: dtls,
1995 name: "PackDTLSHandshake",
1996 config: Config{
1997 Bugs: ProtocolBugs{
1998 MaxHandshakeRecordLength: 2,
1999 PackHandshakeFragments: 20,
2000 PackHandshakeRecords: 200,
2001 },
2002 },
2003 },
2004 {
Adam Langley7c803a62015-06-15 15:35:05 -07002005 name: "SendEmptyRecords-Pass",
2006 sendEmptyRecords: 32,
2007 },
2008 {
2009 name: "SendEmptyRecords",
2010 sendEmptyRecords: 33,
2011 shouldFail: true,
2012 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2013 },
2014 {
2015 name: "SendEmptyRecords-Async",
2016 sendEmptyRecords: 33,
2017 flags: []string{"-async"},
2018 shouldFail: true,
2019 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2020 },
2021 {
David Benjamine8e84b92016-08-03 15:39:47 -04002022 name: "SendWarningAlerts-Pass",
2023 config: Config{
2024 MaxVersion: VersionTLS12,
2025 },
Adam Langley7c803a62015-06-15 15:35:05 -07002026 sendWarningAlerts: 4,
2027 },
2028 {
David Benjamine8e84b92016-08-03 15:39:47 -04002029 protocol: dtls,
2030 name: "SendWarningAlerts-DTLS-Pass",
2031 config: Config{
2032 MaxVersion: VersionTLS12,
2033 },
Adam Langley7c803a62015-06-15 15:35:05 -07002034 sendWarningAlerts: 4,
2035 },
2036 {
David Benjamine8e84b92016-08-03 15:39:47 -04002037 name: "SendWarningAlerts-TLS13",
2038 config: Config{
2039 MaxVersion: VersionTLS13,
2040 },
2041 sendWarningAlerts: 4,
2042 shouldFail: true,
2043 expectedError: ":BAD_ALERT:",
2044 expectedLocalError: "remote error: error decoding message",
2045 },
2046 {
2047 name: "SendWarningAlerts",
2048 config: Config{
2049 MaxVersion: VersionTLS12,
2050 },
Adam Langley7c803a62015-06-15 15:35:05 -07002051 sendWarningAlerts: 5,
2052 shouldFail: true,
2053 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2054 },
2055 {
David Benjamine8e84b92016-08-03 15:39:47 -04002056 name: "SendWarningAlerts-Async",
2057 config: Config{
2058 MaxVersion: VersionTLS12,
2059 },
Adam Langley7c803a62015-06-15 15:35:05 -07002060 sendWarningAlerts: 5,
2061 flags: []string{"-async"},
2062 shouldFail: true,
2063 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2064 },
David Benjaminba4594a2015-06-18 18:36:15 -04002065 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002066 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002067 config: Config{
2068 MaxVersion: VersionTLS13,
2069 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002070 sendKeyUpdates: 33,
2071 keyUpdateRequest: keyUpdateNotRequested,
2072 shouldFail: true,
2073 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002074 },
2075 {
David Benjaminba4594a2015-06-18 18:36:15 -04002076 name: "EmptySessionID",
2077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002078 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002079 SessionTicketsDisabled: true,
2080 },
2081 noSessionCache: true,
2082 flags: []string{"-expect-no-session"},
2083 },
David Benjamin30789da2015-08-29 22:56:45 -04002084 {
2085 name: "Unclean-Shutdown",
2086 config: Config{
2087 Bugs: ProtocolBugs{
2088 NoCloseNotify: true,
2089 ExpectCloseNotify: true,
2090 },
2091 },
2092 shimShutsDown: true,
2093 flags: []string{"-check-close-notify"},
2094 shouldFail: true,
2095 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2096 },
2097 {
2098 name: "Unclean-Shutdown-Ignored",
2099 config: Config{
2100 Bugs: ProtocolBugs{
2101 NoCloseNotify: true,
2102 },
2103 },
2104 shimShutsDown: true,
2105 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002106 {
David Benjaminfa214e42016-05-10 17:03:10 -04002107 name: "Unclean-Shutdown-Alert",
2108 config: Config{
2109 Bugs: ProtocolBugs{
2110 SendAlertOnShutdown: alertDecompressionFailure,
2111 ExpectCloseNotify: true,
2112 },
2113 },
2114 shimShutsDown: true,
2115 flags: []string{"-check-close-notify"},
2116 shouldFail: true,
2117 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2118 },
2119 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002120 name: "LargePlaintext",
2121 config: Config{
2122 Bugs: ProtocolBugs{
2123 SendLargeRecords: true,
2124 },
2125 },
2126 messageLen: maxPlaintext + 1,
2127 shouldFail: true,
2128 expectedError: ":DATA_LENGTH_TOO_LONG:",
2129 },
2130 {
2131 protocol: dtls,
2132 name: "LargePlaintext-DTLS",
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 name: "LargeCiphertext",
2144 config: Config{
2145 Bugs: ProtocolBugs{
2146 SendLargeRecords: true,
2147 },
2148 },
2149 messageLen: maxPlaintext * 2,
2150 shouldFail: true,
2151 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2152 },
2153 {
2154 protocol: dtls,
2155 name: "LargeCiphertext-DTLS",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 SendLargeRecords: true,
2159 },
2160 },
2161 messageLen: maxPlaintext * 2,
2162 // Unlike the other four cases, DTLS drops records which
2163 // are invalid before authentication, so the connection
2164 // does not fail.
2165 expectMessageDropped: true,
2166 },
David Benjamindd6fed92015-10-23 17:41:12 -04002167 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002168 name: "BadHelloRequest-1",
2169 renegotiate: 1,
2170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002171 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002172 Bugs: ProtocolBugs{
2173 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2174 },
2175 },
2176 flags: []string{
2177 "-renegotiate-freely",
2178 "-expect-total-renegotiations", "1",
2179 },
2180 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002181 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002182 },
2183 {
2184 name: "BadHelloRequest-2",
2185 renegotiate: 1,
2186 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002187 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002188 Bugs: ProtocolBugs{
2189 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2190 },
2191 },
2192 flags: []string{
2193 "-renegotiate-freely",
2194 "-expect-total-renegotiations", "1",
2195 },
2196 shouldFail: true,
2197 expectedError: ":BAD_HELLO_REQUEST:",
2198 },
David Benjaminef1b0092015-11-21 14:05:44 -05002199 {
2200 testType: serverTest,
2201 name: "SupportTicketsWithSessionID",
2202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002203 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002204 SessionTicketsDisabled: true,
2205 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002206 resumeConfig: &Config{
2207 MaxVersion: VersionTLS12,
2208 },
David Benjaminef1b0092015-11-21 14:05:44 -05002209 resumeSession: true,
2210 },
David Benjamin02edcd02016-07-27 17:40:37 -04002211 {
2212 protocol: dtls,
2213 name: "DTLS-SendExtraFinished",
2214 config: Config{
2215 Bugs: ProtocolBugs{
2216 SendExtraFinished: true,
2217 },
2218 },
2219 shouldFail: true,
2220 expectedError: ":UNEXPECTED_RECORD:",
2221 },
2222 {
2223 protocol: dtls,
2224 name: "DTLS-SendExtraFinished-Reordered",
2225 config: Config{
2226 Bugs: ProtocolBugs{
2227 MaxHandshakeRecordLength: 2,
2228 ReorderHandshakeFragments: true,
2229 SendExtraFinished: true,
2230 },
2231 },
2232 shouldFail: true,
2233 expectedError: ":UNEXPECTED_RECORD:",
2234 },
David Benjamine97fb482016-07-29 09:23:07 -04002235 {
2236 testType: serverTest,
2237 name: "V2ClientHello-EmptyRecordPrefix",
2238 config: Config{
2239 // Choose a cipher suite that does not involve
2240 // elliptic curves, so no extensions are
2241 // involved.
2242 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002243 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002244 Bugs: ProtocolBugs{
2245 SendV2ClientHello: true,
2246 },
2247 },
2248 sendPrefix: string([]byte{
2249 byte(recordTypeHandshake),
2250 3, 1, // version
2251 0, 0, // length
2252 }),
2253 // A no-op empty record may not be sent before V2ClientHello.
2254 shouldFail: true,
2255 expectedError: ":WRONG_VERSION_NUMBER:",
2256 },
2257 {
2258 testType: serverTest,
2259 name: "V2ClientHello-WarningAlertPrefix",
2260 config: Config{
2261 // Choose a cipher suite that does not involve
2262 // elliptic curves, so no extensions are
2263 // involved.
2264 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002265 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002266 Bugs: ProtocolBugs{
2267 SendV2ClientHello: true,
2268 },
2269 },
2270 sendPrefix: string([]byte{
2271 byte(recordTypeAlert),
2272 3, 1, // version
2273 0, 2, // length
2274 alertLevelWarning, byte(alertDecompressionFailure),
2275 }),
2276 // A no-op warning alert may not be sent before V2ClientHello.
2277 shouldFail: true,
2278 expectedError: ":WRONG_VERSION_NUMBER:",
2279 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002280 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002281 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002282 config: Config{
2283 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002284 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002285 sendKeyUpdates: 1,
2286 keyUpdateRequest: keyUpdateNotRequested,
2287 },
2288 {
2289 name: "KeyUpdate-InvalidRequestMode",
2290 config: Config{
2291 MaxVersion: VersionTLS13,
2292 },
2293 sendKeyUpdates: 1,
2294 keyUpdateRequest: 42,
2295 shouldFail: true,
2296 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002297 },
David Benjaminabe94e32016-09-04 14:18:58 -04002298 {
2299 name: "SendSNIWarningAlert",
2300 config: Config{
2301 MaxVersion: VersionTLS12,
2302 Bugs: ProtocolBugs{
2303 SendSNIWarningAlert: true,
2304 },
2305 },
2306 },
David Benjaminc241d792016-09-09 10:34:20 -04002307 {
2308 testType: serverTest,
2309 name: "ExtraCompressionMethods-TLS12",
2310 config: Config{
2311 MaxVersion: VersionTLS12,
2312 Bugs: ProtocolBugs{
2313 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2314 },
2315 },
2316 },
2317 {
2318 testType: serverTest,
2319 name: "ExtraCompressionMethods-TLS13",
2320 config: Config{
2321 MaxVersion: VersionTLS13,
2322 Bugs: ProtocolBugs{
2323 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2324 },
2325 },
2326 shouldFail: true,
2327 expectedError: ":INVALID_COMPRESSION_LIST:",
2328 expectedLocalError: "remote error: illegal parameter",
2329 },
2330 {
2331 testType: serverTest,
2332 name: "NoNullCompression-TLS12",
2333 config: Config{
2334 MaxVersion: VersionTLS12,
2335 Bugs: ProtocolBugs{
2336 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2337 },
2338 },
2339 shouldFail: true,
2340 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2341 expectedLocalError: "remote error: illegal parameter",
2342 },
2343 {
2344 testType: serverTest,
2345 name: "NoNullCompression-TLS13",
2346 config: Config{
2347 MaxVersion: VersionTLS13,
2348 Bugs: ProtocolBugs{
2349 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2350 },
2351 },
2352 shouldFail: true,
2353 expectedError: ":INVALID_COMPRESSION_LIST:",
2354 expectedLocalError: "remote error: illegal parameter",
2355 },
David Benjamin65ac9972016-09-02 21:35:25 -04002356 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002357 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002358 config: Config{
2359 MaxVersion: VersionTLS12,
2360 Bugs: ProtocolBugs{
2361 ExpectGREASE: true,
2362 },
2363 },
2364 flags: []string{"-enable-grease"},
2365 },
2366 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002367 name: "GREASE-Client-TLS13",
2368 config: Config{
2369 MaxVersion: VersionTLS13,
2370 Bugs: ProtocolBugs{
2371 ExpectGREASE: true,
2372 },
2373 },
2374 flags: []string{"-enable-grease"},
2375 },
2376 {
2377 testType: serverTest,
2378 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002379 config: Config{
2380 MaxVersion: VersionTLS13,
2381 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002382 // TLS 1.3 servers are expected to
2383 // always enable GREASE. TLS 1.3 is new,
2384 // so there is no existing ecosystem to
2385 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002386 ExpectGREASE: true,
2387 },
2388 },
David Benjamin65ac9972016-09-02 21:35:25 -04002389 },
Adam Langley7c803a62015-06-15 15:35:05 -07002390 }
Adam Langley7c803a62015-06-15 15:35:05 -07002391 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002392
2393 // Test that very large messages can be received.
2394 cert := rsaCertificate
2395 for i := 0; i < 50; i++ {
2396 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2397 }
2398 testCases = append(testCases, testCase{
2399 name: "LargeMessage",
2400 config: Config{
2401 Certificates: []Certificate{cert},
2402 },
2403 })
2404 testCases = append(testCases, testCase{
2405 protocol: dtls,
2406 name: "LargeMessage-DTLS",
2407 config: Config{
2408 Certificates: []Certificate{cert},
2409 },
2410 })
2411
2412 // They are rejected if the maximum certificate chain length is capped.
2413 testCases = append(testCases, testCase{
2414 name: "LargeMessage-Reject",
2415 config: Config{
2416 Certificates: []Certificate{cert},
2417 },
2418 flags: []string{"-max-cert-list", "16384"},
2419 shouldFail: true,
2420 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2421 })
2422 testCases = append(testCases, testCase{
2423 protocol: dtls,
2424 name: "LargeMessage-Reject-DTLS",
2425 config: Config{
2426 Certificates: []Certificate{cert},
2427 },
2428 flags: []string{"-max-cert-list", "16384"},
2429 shouldFail: true,
2430 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2431 })
Adam Langley7c803a62015-06-15 15:35:05 -07002432}
2433
Adam Langley95c29f32014-06-20 12:00:00 -07002434func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002435 const bogusCipher = 0xfe00
2436
Adam Langley95c29f32014-06-20 12:00:00 -07002437 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002438 const psk = "12345"
2439 const pskIdentity = "luggage combo"
2440
Adam Langley95c29f32014-06-20 12:00:00 -07002441 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002442 var certFile string
2443 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002444 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002445 cert = ecdsaP256Certificate
2446 certFile = ecdsaP256CertificateFile
2447 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002448 } else {
David Benjamin33863262016-07-08 17:20:12 -07002449 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002450 certFile = rsaCertificateFile
2451 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002452 }
2453
David Benjamin48cae082014-10-27 01:06:24 -04002454 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002455 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002456 flags = append(flags,
2457 "-psk", psk,
2458 "-psk-identity", pskIdentity)
2459 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002460 if hasComponent(suite.name, "NULL") {
2461 // NULL ciphers must be explicitly enabled.
2462 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2463 }
David Benjamin881f1962016-08-10 18:29:12 -04002464 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2465 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2466 // for now.
2467 flags = append(flags, "-cipher", suite.name)
2468 }
David Benjamin48cae082014-10-27 01:06:24 -04002469
Adam Langley95c29f32014-06-20 12:00:00 -07002470 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002471 for _, protocol := range []protocol{tls, dtls} {
2472 var prefix string
2473 if protocol == dtls {
2474 if !ver.hasDTLS {
2475 continue
2476 }
2477 prefix = "D"
2478 }
Adam Langley95c29f32014-06-20 12:00:00 -07002479
David Benjamin0407e762016-06-17 16:41:18 -04002480 var shouldServerFail, shouldClientFail bool
2481 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2482 // BoringSSL clients accept ECDHE on SSLv3, but
2483 // a BoringSSL server will never select it
2484 // because the extension is missing.
2485 shouldServerFail = true
2486 }
2487 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2488 shouldClientFail = true
2489 shouldServerFail = true
2490 }
David Benjamin54c217c2016-07-13 12:35:25 -04002491 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002492 shouldClientFail = true
2493 shouldServerFail = true
2494 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002495 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2496 shouldClientFail = true
2497 shouldServerFail = true
2498 }
David Benjamin0407e762016-06-17 16:41:18 -04002499 if !isDTLSCipher(suite.name) && protocol == dtls {
2500 shouldClientFail = true
2501 shouldServerFail = true
2502 }
David Benjamin4298d772015-12-19 00:18:25 -05002503
David Benjamin5ecb88b2016-10-04 17:51:35 -04002504 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002505 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002506 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002507 if shouldServerFail {
2508 expectedServerError = ":NO_SHARED_CIPHER:"
2509 }
2510 if shouldClientFail {
2511 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002512 // Configure the server to select ciphers as normal but
2513 // select an incompatible cipher in ServerHello.
2514 serverCipherSuites = nil
2515 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002516 }
David Benjamin025b3d32014-07-01 19:53:04 -04002517
David Benjamin6fd297b2014-08-11 18:43:38 -04002518 testCases = append(testCases, testCase{
2519 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002520 protocol: protocol,
2521
2522 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002523 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002524 MinVersion: ver.version,
2525 MaxVersion: ver.version,
2526 CipherSuites: []uint16{suite.id},
2527 Certificates: []Certificate{cert},
2528 PreSharedKey: []byte(psk),
2529 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002530 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002531 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002532 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002533 },
2534 certFile: certFile,
2535 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002536 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002537 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002538 shouldFail: shouldServerFail,
2539 expectedError: expectedServerError,
2540 })
2541
2542 testCases = append(testCases, testCase{
2543 testType: clientTest,
2544 protocol: protocol,
2545 name: prefix + ver.name + "-" + suite.name + "-client",
2546 config: Config{
2547 MinVersion: ver.version,
2548 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002549 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002550 Certificates: []Certificate{cert},
2551 PreSharedKey: []byte(psk),
2552 PreSharedKeyIdentity: pskIdentity,
2553 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002554 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002555 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002556 },
2557 },
2558 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002559 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002560 shouldFail: shouldClientFail,
2561 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002562 })
David Benjamin2c99d282015-09-01 10:23:00 -04002563
Nick Harper1fd39d82016-06-14 18:14:35 -07002564 if !shouldClientFail {
2565 // Ensure the maximum record size is accepted.
2566 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002567 protocol: protocol,
2568 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002569 config: Config{
2570 MinVersion: ver.version,
2571 MaxVersion: ver.version,
2572 CipherSuites: []uint16{suite.id},
2573 Certificates: []Certificate{cert},
2574 PreSharedKey: []byte(psk),
2575 PreSharedKeyIdentity: pskIdentity,
2576 },
2577 flags: flags,
2578 messageLen: maxPlaintext,
2579 })
David Benjamin231a4752016-11-10 10:46:00 -05002580
2581 // Test bad records for all ciphers. Bad records are fatal in TLS
2582 // and ignored in DTLS.
2583 var shouldFail bool
2584 var expectedError string
2585 if protocol == tls {
2586 shouldFail = true
2587 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2588 }
2589
2590 testCases = append(testCases, testCase{
2591 protocol: protocol,
2592 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2593 config: Config{
2594 MinVersion: ver.version,
2595 MaxVersion: ver.version,
2596 CipherSuites: []uint16{suite.id},
2597 Certificates: []Certificate{cert},
2598 PreSharedKey: []byte(psk),
2599 PreSharedKeyIdentity: pskIdentity,
2600 },
2601 flags: flags,
2602 damageFirstWrite: true,
2603 messageLen: maxPlaintext,
2604 shouldFail: shouldFail,
2605 expectedError: expectedError,
2606 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002607 }
2608 }
David Benjamin2c99d282015-09-01 10:23:00 -04002609 }
Adam Langley95c29f32014-06-20 12:00:00 -07002610 }
Adam Langleya7997f12015-05-14 17:38:50 -07002611
2612 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002613 name: "NoSharedCipher",
2614 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002615 MaxVersion: VersionTLS12,
2616 CipherSuites: []uint16{},
2617 },
2618 shouldFail: true,
2619 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2620 })
2621
2622 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002623 name: "NoSharedCipher-TLS13",
2624 config: Config{
2625 MaxVersion: VersionTLS13,
2626 CipherSuites: []uint16{},
2627 },
2628 shouldFail: true,
2629 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2630 })
2631
2632 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002633 name: "UnsupportedCipherSuite",
2634 config: Config{
2635 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002636 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002637 Bugs: ProtocolBugs{
2638 IgnorePeerCipherPreferences: true,
2639 },
2640 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002641 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002642 shouldFail: true,
2643 expectedError: ":WRONG_CIPHER_RETURNED:",
2644 })
2645
2646 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002647 name: "ServerHelloBogusCipher",
2648 config: Config{
2649 MaxVersion: VersionTLS12,
2650 Bugs: ProtocolBugs{
2651 SendCipherSuite: bogusCipher,
2652 },
2653 },
2654 shouldFail: true,
2655 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2656 })
2657 testCases = append(testCases, testCase{
2658 name: "ServerHelloBogusCipher-TLS13",
2659 config: Config{
2660 MaxVersion: VersionTLS13,
2661 Bugs: ProtocolBugs{
2662 SendCipherSuite: bogusCipher,
2663 },
2664 },
2665 shouldFail: true,
2666 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2667 })
2668
2669 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002670 name: "WeakDH",
2671 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002672 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002673 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2674 Bugs: ProtocolBugs{
2675 // This is a 1023-bit prime number, generated
2676 // with:
2677 // openssl gendh 1023 | openssl asn1parse -i
2678 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2679 },
2680 },
2681 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002682 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002683 })
Adam Langleycef75832015-09-03 14:51:12 -07002684
David Benjamincd24a392015-11-11 13:23:05 -08002685 testCases = append(testCases, testCase{
2686 name: "SillyDH",
2687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002688 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002689 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2690 Bugs: ProtocolBugs{
2691 // This is a 4097-bit prime number, generated
2692 // with:
2693 // openssl gendh 4097 | openssl asn1parse -i
2694 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2695 },
2696 },
2697 shouldFail: true,
2698 expectedError: ":DH_P_TOO_LONG:",
2699 })
2700
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002701 // This test ensures that Diffie-Hellman public values are padded with
2702 // zeros so that they're the same length as the prime. This is to avoid
2703 // hitting a bug in yaSSL.
2704 testCases = append(testCases, testCase{
2705 testType: serverTest,
2706 name: "DHPublicValuePadded",
2707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002708 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002709 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2710 Bugs: ProtocolBugs{
2711 RequireDHPublicValueLen: (1025 + 7) / 8,
2712 },
2713 },
2714 flags: []string{"-use-sparse-dh-prime"},
2715 })
David Benjamincd24a392015-11-11 13:23:05 -08002716
David Benjamin241ae832016-01-15 03:04:54 -05002717 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002718 testCases = append(testCases, testCase{
2719 testType: serverTest,
2720 name: "UnknownCipher",
2721 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002722 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002723 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002724 Bugs: ProtocolBugs{
2725 AdvertiseAllConfiguredCiphers: true,
2726 },
2727 },
2728 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002729
2730 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002731 testCases = append(testCases, testCase{
2732 testType: serverTest,
2733 name: "UnknownCipher-TLS13",
2734 config: Config{
2735 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002736 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002737 Bugs: ProtocolBugs{
2738 AdvertiseAllConfiguredCiphers: true,
2739 },
David Benjamin241ae832016-01-15 03:04:54 -05002740 },
2741 })
2742
David Benjamin78679342016-09-16 19:42:05 -04002743 // Test empty ECDHE_PSK identity hints work as expected.
2744 testCases = append(testCases, testCase{
2745 name: "EmptyECDHEPSKHint",
2746 config: Config{
2747 MaxVersion: VersionTLS12,
2748 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2749 PreSharedKey: []byte("secret"),
2750 },
2751 flags: []string{"-psk", "secret"},
2752 })
2753
2754 // Test empty PSK identity hints work as expected, even if an explicit
2755 // ServerKeyExchange is sent.
2756 testCases = append(testCases, testCase{
2757 name: "ExplicitEmptyPSKHint",
2758 config: Config{
2759 MaxVersion: VersionTLS12,
2760 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2761 PreSharedKey: []byte("secret"),
2762 Bugs: ProtocolBugs{
2763 AlwaysSendPreSharedKeyIdentityHint: true,
2764 },
2765 },
2766 flags: []string{"-psk", "secret"},
2767 })
2768
Adam Langleycef75832015-09-03 14:51:12 -07002769 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2770 // 1.1 specific cipher suite settings. A server is setup with the given
2771 // cipher lists and then a connection is made for each member of
2772 // expectations. The cipher suite that the server selects must match
2773 // the specified one.
2774 var versionSpecificCiphersTest = []struct {
2775 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2776 // expectations is a map from TLS version to cipher suite id.
2777 expectations map[uint16]uint16
2778 }{
2779 {
2780 // Test that the null case (where no version-specific ciphers are set)
2781 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002782 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2783 "", // no ciphers specifically for TLS ≥ 1.0
2784 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002785 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002786 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2787 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2788 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2789 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002790 },
2791 },
2792 {
2793 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2794 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002795 "DES-CBC3-SHA:AES128-SHA", // default
2796 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2797 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002798 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002799 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002800 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2801 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2802 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2803 },
2804 },
2805 {
2806 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2807 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002808 "DES-CBC3-SHA:AES128-SHA", // default
2809 "", // no ciphers specifically for TLS ≥ 1.0
2810 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002811 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002812 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2813 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002814 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2815 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2816 },
2817 },
2818 {
2819 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2820 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002821 "DES-CBC3-SHA:AES128-SHA", // default
2822 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2823 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002824 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002825 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002826 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2827 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2828 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2829 },
2830 },
2831 }
2832
2833 for i, test := range versionSpecificCiphersTest {
2834 for version, expectedCipherSuite := range test.expectations {
2835 flags := []string{"-cipher", test.ciphersDefault}
2836 if len(test.ciphersTLS10) > 0 {
2837 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2838 }
2839 if len(test.ciphersTLS11) > 0 {
2840 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2841 }
2842
2843 testCases = append(testCases, testCase{
2844 testType: serverTest,
2845 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2846 config: Config{
2847 MaxVersion: version,
2848 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002849 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002850 },
2851 flags: flags,
2852 expectedCipher: expectedCipherSuite,
2853 })
2854 }
2855 }
Adam Langley95c29f32014-06-20 12:00:00 -07002856}
2857
2858func addBadECDSASignatureTests() {
2859 for badR := BadValue(1); badR < NumBadValues; badR++ {
2860 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002861 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002862 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2863 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002864 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002865 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002866 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002867 Bugs: ProtocolBugs{
2868 BadECDSAR: badR,
2869 BadECDSAS: badS,
2870 },
2871 },
2872 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002873 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002874 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002875 testCases = append(testCases, testCase{
2876 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2877 config: Config{
2878 MaxVersion: VersionTLS13,
2879 Certificates: []Certificate{ecdsaP256Certificate},
2880 Bugs: ProtocolBugs{
2881 BadECDSAR: badR,
2882 BadECDSAS: badS,
2883 },
2884 },
2885 shouldFail: true,
2886 expectedError: ":BAD_SIGNATURE:",
2887 })
Adam Langley95c29f32014-06-20 12:00:00 -07002888 }
2889 }
2890}
2891
Adam Langley80842bd2014-06-20 12:00:00 -07002892func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002893 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002894 name: "MaxCBCPadding",
2895 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002896 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2898 Bugs: ProtocolBugs{
2899 MaxPadding: true,
2900 },
2901 },
2902 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2903 })
David Benjamin025b3d32014-07-01 19:53:04 -04002904 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002905 name: "BadCBCPadding",
2906 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002907 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2909 Bugs: ProtocolBugs{
2910 PaddingFirstByteBad: true,
2911 },
2912 },
2913 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002914 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002915 })
2916 // OpenSSL previously had an issue where the first byte of padding in
2917 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002918 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002919 name: "BadCBCPadding255",
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 MaxPadding: true,
2925 PaddingFirstByteBadIf255: true,
2926 },
2927 },
2928 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2929 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002930 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002931 })
2932}
2933
Kenny Root7fdeaf12014-08-05 15:23:37 -07002934func addCBCSplittingTests() {
2935 testCases = append(testCases, testCase{
2936 name: "CBCRecordSplitting",
2937 config: Config{
2938 MaxVersion: VersionTLS10,
2939 MinVersion: VersionTLS10,
2940 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2941 },
David Benjaminac8302a2015-09-01 17:18:15 -04002942 messageLen: -1, // read until EOF
2943 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002944 flags: []string{
2945 "-async",
2946 "-write-different-record-sizes",
2947 "-cbc-record-splitting",
2948 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002949 })
2950 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002951 name: "CBCRecordSplittingPartialWrite",
2952 config: Config{
2953 MaxVersion: VersionTLS10,
2954 MinVersion: VersionTLS10,
2955 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2956 },
2957 messageLen: -1, // read until EOF
2958 flags: []string{
2959 "-async",
2960 "-write-different-record-sizes",
2961 "-cbc-record-splitting",
2962 "-partial-write",
2963 },
2964 })
2965}
2966
David Benjamin636293b2014-07-08 17:59:18 -04002967func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002968 // Add a dummy cert pool to stress certificate authority parsing.
2969 // TODO(davidben): Add tests that those values parse out correctly.
2970 certPool := x509.NewCertPool()
2971 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2972 if err != nil {
2973 panic(err)
2974 }
2975 certPool.AddCert(cert)
2976
David Benjamin636293b2014-07-08 17:59:18 -04002977 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002978 testCases = append(testCases, testCase{
2979 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002980 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002981 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002982 MinVersion: ver.version,
2983 MaxVersion: ver.version,
2984 ClientAuth: RequireAnyClientCert,
2985 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002986 },
2987 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002988 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2989 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002990 },
2991 })
2992 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002993 testType: serverTest,
2994 name: ver.name + "-Server-ClientAuth-RSA",
2995 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002996 MinVersion: ver.version,
2997 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002998 Certificates: []Certificate{rsaCertificate},
2999 },
3000 flags: []string{"-require-any-client-certificate"},
3001 })
David Benjamine098ec22014-08-27 23:13:20 -04003002 if ver.version != VersionSSL30 {
3003 testCases = append(testCases, testCase{
3004 testType: serverTest,
3005 name: ver.name + "-Server-ClientAuth-ECDSA",
3006 config: Config{
3007 MinVersion: ver.version,
3008 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003009 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003010 },
3011 flags: []string{"-require-any-client-certificate"},
3012 })
3013 testCases = append(testCases, testCase{
3014 testType: clientTest,
3015 name: ver.name + "-Client-ClientAuth-ECDSA",
3016 config: Config{
3017 MinVersion: ver.version,
3018 MaxVersion: ver.version,
3019 ClientAuth: RequireAnyClientCert,
3020 ClientCAs: certPool,
3021 },
3022 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003023 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3024 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003025 },
3026 })
3027 }
Adam Langley37646832016-08-01 16:16:46 -07003028
3029 testCases = append(testCases, testCase{
3030 name: "NoClientCertificate-" + ver.name,
3031 config: Config{
3032 MinVersion: ver.version,
3033 MaxVersion: ver.version,
3034 ClientAuth: RequireAnyClientCert,
3035 },
3036 shouldFail: true,
3037 expectedLocalError: "client didn't provide a certificate",
3038 })
3039
3040 testCases = append(testCases, testCase{
3041 // Even if not configured to expect a certificate, OpenSSL will
3042 // return X509_V_OK as the verify_result.
3043 testType: serverTest,
3044 name: "NoClientCertificateRequested-Server-" + ver.name,
3045 config: Config{
3046 MinVersion: ver.version,
3047 MaxVersion: ver.version,
3048 },
3049 flags: []string{
3050 "-expect-verify-result",
3051 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003052 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003053 })
3054
3055 testCases = append(testCases, testCase{
3056 // If a client certificate is not provided, OpenSSL will still
3057 // return X509_V_OK as the verify_result.
3058 testType: serverTest,
3059 name: "NoClientCertificate-Server-" + ver.name,
3060 config: Config{
3061 MinVersion: ver.version,
3062 MaxVersion: ver.version,
3063 },
3064 flags: []string{
3065 "-expect-verify-result",
3066 "-verify-peer",
3067 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003068 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003069 })
3070
David Benjamin1db9e1b2016-10-07 20:51:43 -04003071 certificateRequired := "remote error: certificate required"
3072 if ver.version < VersionTLS13 {
3073 // Prior to TLS 1.3, the generic handshake_failure alert
3074 // was used.
3075 certificateRequired = "remote error: handshake failure"
3076 }
Adam Langley37646832016-08-01 16:16:46 -07003077 testCases = append(testCases, testCase{
3078 testType: serverTest,
3079 name: "RequireAnyClientCertificate-" + ver.name,
3080 config: Config{
3081 MinVersion: ver.version,
3082 MaxVersion: ver.version,
3083 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003084 flags: []string{"-require-any-client-certificate"},
3085 shouldFail: true,
3086 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3087 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003088 })
3089
3090 if ver.version != VersionSSL30 {
3091 testCases = append(testCases, testCase{
3092 testType: serverTest,
3093 name: "SkipClientCertificate-" + ver.name,
3094 config: Config{
3095 MinVersion: ver.version,
3096 MaxVersion: ver.version,
3097 Bugs: ProtocolBugs{
3098 SkipClientCertificate: true,
3099 },
3100 },
3101 // Setting SSL_VERIFY_PEER allows anonymous clients.
3102 flags: []string{"-verify-peer"},
3103 shouldFail: true,
3104 expectedError: ":UNEXPECTED_MESSAGE:",
3105 })
3106 }
David Benjamin636293b2014-07-08 17:59:18 -04003107 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003108
David Benjaminc032dfa2016-05-12 14:54:57 -04003109 // Client auth is only legal in certificate-based ciphers.
3110 testCases = append(testCases, testCase{
3111 testType: clientTest,
3112 name: "ClientAuth-PSK",
3113 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003114 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003115 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3116 PreSharedKey: []byte("secret"),
3117 ClientAuth: RequireAnyClientCert,
3118 },
3119 flags: []string{
3120 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3121 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3122 "-psk", "secret",
3123 },
3124 shouldFail: true,
3125 expectedError: ":UNEXPECTED_MESSAGE:",
3126 })
3127 testCases = append(testCases, testCase{
3128 testType: clientTest,
3129 name: "ClientAuth-ECDHE_PSK",
3130 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003131 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003132 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3133 PreSharedKey: []byte("secret"),
3134 ClientAuth: RequireAnyClientCert,
3135 },
3136 flags: []string{
3137 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3138 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3139 "-psk", "secret",
3140 },
3141 shouldFail: true,
3142 expectedError: ":UNEXPECTED_MESSAGE:",
3143 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003144
3145 // Regression test for a bug where the client CA list, if explicitly
3146 // set to NULL, was mis-encoded.
3147 testCases = append(testCases, testCase{
3148 testType: serverTest,
3149 name: "Null-Client-CA-List",
3150 config: Config{
3151 MaxVersion: VersionTLS12,
3152 Certificates: []Certificate{rsaCertificate},
3153 },
3154 flags: []string{
3155 "-require-any-client-certificate",
3156 "-use-null-client-ca-list",
3157 },
3158 })
David Benjamin636293b2014-07-08 17:59:18 -04003159}
3160
Adam Langley75712922014-10-10 16:23:43 -07003161func addExtendedMasterSecretTests() {
3162 const expectEMSFlag = "-expect-extended-master-secret"
3163
3164 for _, with := range []bool{false, true} {
3165 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003166 if with {
3167 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003168 }
3169
3170 for _, isClient := range []bool{false, true} {
3171 suffix := "-Server"
3172 testType := serverTest
3173 if isClient {
3174 suffix = "-Client"
3175 testType = clientTest
3176 }
3177
3178 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003179 // In TLS 1.3, the extension is irrelevant and
3180 // always reports as enabled.
3181 var flags []string
3182 if with || ver.version >= VersionTLS13 {
3183 flags = []string{expectEMSFlag}
3184 }
3185
Adam Langley75712922014-10-10 16:23:43 -07003186 test := testCase{
3187 testType: testType,
3188 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3189 config: Config{
3190 MinVersion: ver.version,
3191 MaxVersion: ver.version,
3192 Bugs: ProtocolBugs{
3193 NoExtendedMasterSecret: !with,
3194 RequireExtendedMasterSecret: with,
3195 },
3196 },
David Benjamin48cae082014-10-27 01:06:24 -04003197 flags: flags,
3198 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003199 }
3200 if test.shouldFail {
3201 test.expectedLocalError = "extended master secret required but not supported by peer"
3202 }
3203 testCases = append(testCases, test)
3204 }
3205 }
3206 }
3207
Adam Langleyba5934b2015-06-02 10:50:35 -07003208 for _, isClient := range []bool{false, true} {
3209 for _, supportedInFirstConnection := range []bool{false, true} {
3210 for _, supportedInResumeConnection := range []bool{false, true} {
3211 boolToWord := func(b bool) string {
3212 if b {
3213 return "Yes"
3214 }
3215 return "No"
3216 }
3217 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3218 if isClient {
3219 suffix += "Client"
3220 } else {
3221 suffix += "Server"
3222 }
3223
3224 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003225 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003226 Bugs: ProtocolBugs{
3227 RequireExtendedMasterSecret: true,
3228 },
3229 }
3230
3231 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003232 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003233 Bugs: ProtocolBugs{
3234 NoExtendedMasterSecret: true,
3235 },
3236 }
3237
3238 test := testCase{
3239 name: "ExtendedMasterSecret-" + suffix,
3240 resumeSession: true,
3241 }
3242
3243 if !isClient {
3244 test.testType = serverTest
3245 }
3246
3247 if supportedInFirstConnection {
3248 test.config = supportedConfig
3249 } else {
3250 test.config = noSupportConfig
3251 }
3252
3253 if supportedInResumeConnection {
3254 test.resumeConfig = &supportedConfig
3255 } else {
3256 test.resumeConfig = &noSupportConfig
3257 }
3258
3259 switch suffix {
3260 case "YesToYes-Client", "YesToYes-Server":
3261 // When a session is resumed, it should
3262 // still be aware that its master
3263 // secret was generated via EMS and
3264 // thus it's safe to use tls-unique.
3265 test.flags = []string{expectEMSFlag}
3266 case "NoToYes-Server":
3267 // If an original connection did not
3268 // contain EMS, but a resumption
3269 // handshake does, then a server should
3270 // not resume the session.
3271 test.expectResumeRejected = true
3272 case "YesToNo-Server":
3273 // Resuming an EMS session without the
3274 // EMS extension should cause the
3275 // server to abort the connection.
3276 test.shouldFail = true
3277 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3278 case "NoToYes-Client":
3279 // A client should abort a connection
3280 // where the server resumed a non-EMS
3281 // session but echoed the EMS
3282 // extension.
3283 test.shouldFail = true
3284 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3285 case "YesToNo-Client":
3286 // A client should abort a connection
3287 // where the server didn't echo EMS
3288 // when the session used it.
3289 test.shouldFail = true
3290 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3291 }
3292
3293 testCases = append(testCases, test)
3294 }
3295 }
3296 }
David Benjamin163c9562016-08-29 23:14:17 -04003297
3298 // Switching EMS on renegotiation is forbidden.
3299 testCases = append(testCases, testCase{
3300 name: "ExtendedMasterSecret-Renego-NoEMS",
3301 config: Config{
3302 MaxVersion: VersionTLS12,
3303 Bugs: ProtocolBugs{
3304 NoExtendedMasterSecret: true,
3305 NoExtendedMasterSecretOnRenegotiation: true,
3306 },
3307 },
3308 renegotiate: 1,
3309 flags: []string{
3310 "-renegotiate-freely",
3311 "-expect-total-renegotiations", "1",
3312 },
3313 })
3314
3315 testCases = append(testCases, testCase{
3316 name: "ExtendedMasterSecret-Renego-Upgrade",
3317 config: Config{
3318 MaxVersion: VersionTLS12,
3319 Bugs: ProtocolBugs{
3320 NoExtendedMasterSecret: true,
3321 },
3322 },
3323 renegotiate: 1,
3324 flags: []string{
3325 "-renegotiate-freely",
3326 "-expect-total-renegotiations", "1",
3327 },
3328 shouldFail: true,
3329 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3330 })
3331
3332 testCases = append(testCases, testCase{
3333 name: "ExtendedMasterSecret-Renego-Downgrade",
3334 config: Config{
3335 MaxVersion: VersionTLS12,
3336 Bugs: ProtocolBugs{
3337 NoExtendedMasterSecretOnRenegotiation: true,
3338 },
3339 },
3340 renegotiate: 1,
3341 flags: []string{
3342 "-renegotiate-freely",
3343 "-expect-total-renegotiations", "1",
3344 },
3345 shouldFail: true,
3346 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3347 })
Adam Langley75712922014-10-10 16:23:43 -07003348}
3349
David Benjamin582ba042016-07-07 12:33:25 -07003350type stateMachineTestConfig struct {
3351 protocol protocol
3352 async bool
3353 splitHandshake, packHandshakeFlight bool
3354}
3355
David Benjamin43ec06f2014-08-05 02:28:57 -04003356// Adds tests that try to cover the range of the handshake state machine, under
3357// various conditions. Some of these are redundant with other tests, but they
3358// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003359func addAllStateMachineCoverageTests() {
3360 for _, async := range []bool{false, true} {
3361 for _, protocol := range []protocol{tls, dtls} {
3362 addStateMachineCoverageTests(stateMachineTestConfig{
3363 protocol: protocol,
3364 async: async,
3365 })
3366 addStateMachineCoverageTests(stateMachineTestConfig{
3367 protocol: protocol,
3368 async: async,
3369 splitHandshake: true,
3370 })
3371 if protocol == tls {
3372 addStateMachineCoverageTests(stateMachineTestConfig{
3373 protocol: protocol,
3374 async: async,
3375 packHandshakeFlight: true,
3376 })
3377 }
3378 }
3379 }
3380}
3381
3382func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003383 var tests []testCase
3384
3385 // Basic handshake, with resumption. Client and server,
3386 // session ID and session ticket.
3387 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003388 name: "Basic-Client",
3389 config: Config{
3390 MaxVersion: VersionTLS12,
3391 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003392 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003393 // Ensure session tickets are used, not session IDs.
3394 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 })
3396 tests = append(tests, testCase{
3397 name: "Basic-Client-RenewTicket",
3398 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003399 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 Bugs: ProtocolBugs{
3401 RenewTicketOnResume: true,
3402 },
3403 },
David Benjamin46662482016-08-17 00:51:00 -04003404 flags: []string{"-expect-ticket-renewal"},
3405 resumeSession: true,
3406 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 })
3408 tests = append(tests, testCase{
3409 name: "Basic-Client-NoTicket",
3410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 SessionTicketsDisabled: true,
3413 },
3414 resumeSession: true,
3415 })
3416 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003417 name: "Basic-Client-Implicit",
3418 config: Config{
3419 MaxVersion: VersionTLS12,
3420 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003421 flags: []string{"-implicit-handshake"},
3422 resumeSession: true,
3423 })
3424 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003425 testType: serverTest,
3426 name: "Basic-Server",
3427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003428 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003429 Bugs: ProtocolBugs{
3430 RequireSessionTickets: true,
3431 },
3432 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003433 resumeSession: true,
3434 })
3435 tests = append(tests, testCase{
3436 testType: serverTest,
3437 name: "Basic-Server-NoTickets",
3438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003439 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003440 SessionTicketsDisabled: true,
3441 },
3442 resumeSession: true,
3443 })
3444 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003445 testType: serverTest,
3446 name: "Basic-Server-Implicit",
3447 config: Config{
3448 MaxVersion: VersionTLS12,
3449 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003450 flags: []string{"-implicit-handshake"},
3451 resumeSession: true,
3452 })
3453 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003454 testType: serverTest,
3455 name: "Basic-Server-EarlyCallback",
3456 config: Config{
3457 MaxVersion: VersionTLS12,
3458 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003459 flags: []string{"-use-early-callback"},
3460 resumeSession: true,
3461 })
3462
Steven Valdez143e8b32016-07-11 13:19:03 -04003463 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003464 if config.protocol == tls {
3465 tests = append(tests, testCase{
3466 name: "TLS13-1RTT-Client",
3467 config: Config{
3468 MaxVersion: VersionTLS13,
3469 MinVersion: VersionTLS13,
3470 },
David Benjamin46662482016-08-17 00:51:00 -04003471 resumeSession: true,
3472 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003473 })
3474
3475 tests = append(tests, testCase{
3476 testType: serverTest,
3477 name: "TLS13-1RTT-Server",
3478 config: Config{
3479 MaxVersion: VersionTLS13,
3480 MinVersion: VersionTLS13,
3481 },
David Benjamin46662482016-08-17 00:51:00 -04003482 resumeSession: true,
3483 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003484 })
3485
3486 tests = append(tests, testCase{
3487 name: "TLS13-HelloRetryRequest-Client",
3488 config: Config{
3489 MaxVersion: VersionTLS13,
3490 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003491 // P-384 requires a HelloRetryRequest against BoringSSL's default
3492 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003493 CurvePreferences: []CurveID{CurveP384},
3494 Bugs: ProtocolBugs{
3495 ExpectMissingKeyShare: true,
3496 },
3497 },
3498 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3499 resumeSession: true,
3500 })
3501
3502 tests = append(tests, testCase{
3503 testType: serverTest,
3504 name: "TLS13-HelloRetryRequest-Server",
3505 config: Config{
3506 MaxVersion: VersionTLS13,
3507 MinVersion: VersionTLS13,
3508 // Require a HelloRetryRequest for every curve.
3509 DefaultCurves: []CurveID{},
3510 },
3511 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3512 resumeSession: true,
3513 })
3514 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003515
David Benjamin760b1dd2015-05-15 23:33:48 -04003516 // TLS client auth.
3517 tests = append(tests, testCase{
3518 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003519 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003521 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003522 ClientAuth: RequestClientCert,
3523 },
3524 })
3525 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003526 testType: serverTest,
3527 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003528 config: Config{
3529 MaxVersion: VersionTLS12,
3530 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003531 // Setting SSL_VERIFY_PEER allows anonymous clients.
3532 flags: []string{"-verify-peer"},
3533 })
David Benjamin582ba042016-07-07 12:33:25 -07003534 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003535 tests = append(tests, testCase{
3536 testType: clientTest,
3537 name: "ClientAuth-NoCertificate-Client-SSL3",
3538 config: Config{
3539 MaxVersion: VersionSSL30,
3540 ClientAuth: RequestClientCert,
3541 },
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "ClientAuth-NoCertificate-Server-SSL3",
3546 config: Config{
3547 MaxVersion: VersionSSL30,
3548 },
3549 // Setting SSL_VERIFY_PEER allows anonymous clients.
3550 flags: []string{"-verify-peer"},
3551 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003552 tests = append(tests, testCase{
3553 testType: clientTest,
3554 name: "ClientAuth-NoCertificate-Client-TLS13",
3555 config: Config{
3556 MaxVersion: VersionTLS13,
3557 ClientAuth: RequestClientCert,
3558 },
3559 })
3560 tests = append(tests, testCase{
3561 testType: serverTest,
3562 name: "ClientAuth-NoCertificate-Server-TLS13",
3563 config: Config{
3564 MaxVersion: VersionTLS13,
3565 },
3566 // Setting SSL_VERIFY_PEER allows anonymous clients.
3567 flags: []string{"-verify-peer"},
3568 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003569 }
3570 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003571 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003572 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003574 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003575 ClientAuth: RequireAnyClientCert,
3576 },
3577 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003578 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3579 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003580 },
3581 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003582 tests = append(tests, testCase{
3583 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003584 name: "ClientAuth-RSA-Client-TLS13",
3585 config: Config{
3586 MaxVersion: VersionTLS13,
3587 ClientAuth: RequireAnyClientCert,
3588 },
3589 flags: []string{
3590 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3591 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3592 },
3593 })
3594 tests = append(tests, testCase{
3595 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003596 name: "ClientAuth-ECDSA-Client",
3597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003598 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003599 ClientAuth: RequireAnyClientCert,
3600 },
3601 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003602 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3603 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003604 },
3605 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003606 tests = append(tests, testCase{
3607 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003608 name: "ClientAuth-ECDSA-Client-TLS13",
3609 config: Config{
3610 MaxVersion: VersionTLS13,
3611 ClientAuth: RequireAnyClientCert,
3612 },
3613 flags: []string{
3614 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3615 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3616 },
3617 })
3618 tests = append(tests, testCase{
3619 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003620 name: "ClientAuth-NoCertificate-OldCallback",
3621 config: Config{
3622 MaxVersion: VersionTLS12,
3623 ClientAuth: RequestClientCert,
3624 },
3625 flags: []string{"-use-old-client-cert-callback"},
3626 })
3627 tests = append(tests, testCase{
3628 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003629 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3630 config: Config{
3631 MaxVersion: VersionTLS13,
3632 ClientAuth: RequestClientCert,
3633 },
3634 flags: []string{"-use-old-client-cert-callback"},
3635 })
3636 tests = append(tests, testCase{
3637 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003638 name: "ClientAuth-OldCallback",
3639 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003640 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003641 ClientAuth: RequireAnyClientCert,
3642 },
3643 flags: []string{
3644 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3645 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3646 "-use-old-client-cert-callback",
3647 },
3648 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003649 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003650 testType: clientTest,
3651 name: "ClientAuth-OldCallback-TLS13",
3652 config: Config{
3653 MaxVersion: VersionTLS13,
3654 ClientAuth: RequireAnyClientCert,
3655 },
3656 flags: []string{
3657 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3658 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3659 "-use-old-client-cert-callback",
3660 },
3661 })
3662 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003663 testType: serverTest,
3664 name: "ClientAuth-Server",
3665 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003666 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003667 Certificates: []Certificate{rsaCertificate},
3668 },
3669 flags: []string{"-require-any-client-certificate"},
3670 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003671 tests = append(tests, testCase{
3672 testType: serverTest,
3673 name: "ClientAuth-Server-TLS13",
3674 config: Config{
3675 MaxVersion: VersionTLS13,
3676 Certificates: []Certificate{rsaCertificate},
3677 },
3678 flags: []string{"-require-any-client-certificate"},
3679 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003680
David Benjamin4c3ddf72016-06-29 18:13:53 -04003681 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003682 tests = append(tests, testCase{
3683 testType: serverTest,
3684 name: "Basic-Server-RSA",
3685 config: Config{
3686 MaxVersion: VersionTLS12,
3687 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3688 },
3689 flags: []string{
3690 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3691 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3692 },
3693 })
3694 tests = append(tests, testCase{
3695 testType: serverTest,
3696 name: "Basic-Server-ECDHE-RSA",
3697 config: Config{
3698 MaxVersion: VersionTLS12,
3699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3700 },
3701 flags: []string{
3702 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3703 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3704 },
3705 })
3706 tests = append(tests, testCase{
3707 testType: serverTest,
3708 name: "Basic-Server-ECDHE-ECDSA",
3709 config: Config{
3710 MaxVersion: VersionTLS12,
3711 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3712 },
3713 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003714 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3715 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003716 },
3717 })
3718
David Benjamin760b1dd2015-05-15 23:33:48 -04003719 // No session ticket support; server doesn't send NewSessionTicket.
3720 tests = append(tests, testCase{
3721 name: "SessionTicketsDisabled-Client",
3722 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003723 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003724 SessionTicketsDisabled: true,
3725 },
3726 })
3727 tests = append(tests, testCase{
3728 testType: serverTest,
3729 name: "SessionTicketsDisabled-Server",
3730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003731 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003732 SessionTicketsDisabled: true,
3733 },
3734 })
3735
3736 // Skip ServerKeyExchange in PSK key exchange if there's no
3737 // identity hint.
3738 tests = append(tests, testCase{
3739 name: "EmptyPSKHint-Client",
3740 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003741 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003742 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3743 PreSharedKey: []byte("secret"),
3744 },
3745 flags: []string{"-psk", "secret"},
3746 })
3747 tests = append(tests, testCase{
3748 testType: serverTest,
3749 name: "EmptyPSKHint-Server",
3750 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003751 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003752 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3753 PreSharedKey: []byte("secret"),
3754 },
3755 flags: []string{"-psk", "secret"},
3756 })
3757
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003759 tests = append(tests, testCase{
3760 testType: clientTest,
3761 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003762 config: Config{
3763 MaxVersion: VersionTLS12,
3764 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003765 flags: []string{
3766 "-enable-ocsp-stapling",
3767 "-expect-ocsp-response",
3768 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003769 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003770 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003771 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003772 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003773 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003774 testType: serverTest,
3775 name: "OCSPStapling-Server",
3776 config: Config{
3777 MaxVersion: VersionTLS12,
3778 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003779 expectedOCSPResponse: testOCSPResponse,
3780 flags: []string{
3781 "-ocsp-response",
3782 base64.StdEncoding.EncodeToString(testOCSPResponse),
3783 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003784 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003785 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003786 tests = append(tests, testCase{
3787 testType: clientTest,
3788 name: "OCSPStapling-Client-TLS13",
3789 config: Config{
3790 MaxVersion: VersionTLS13,
3791 },
3792 flags: []string{
3793 "-enable-ocsp-stapling",
3794 "-expect-ocsp-response",
3795 base64.StdEncoding.EncodeToString(testOCSPResponse),
3796 "-verify-peer",
3797 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003798 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003799 })
3800 tests = append(tests, testCase{
3801 testType: serverTest,
3802 name: "OCSPStapling-Server-TLS13",
3803 config: Config{
3804 MaxVersion: VersionTLS13,
3805 },
3806 expectedOCSPResponse: testOCSPResponse,
3807 flags: []string{
3808 "-ocsp-response",
3809 base64.StdEncoding.EncodeToString(testOCSPResponse),
3810 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003811 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003812 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003813
David Benjamin4c3ddf72016-06-29 18:13:53 -04003814 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003815 for _, vers := range tlsVersions {
3816 if config.protocol == dtls && !vers.hasDTLS {
3817 continue
3818 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003819 for _, testType := range []testType{clientTest, serverTest} {
3820 suffix := "-Client"
3821 if testType == serverTest {
3822 suffix = "-Server"
3823 }
3824 suffix += "-" + vers.name
3825
3826 flag := "-verify-peer"
3827 if testType == serverTest {
3828 flag = "-require-any-client-certificate"
3829 }
3830
3831 tests = append(tests, testCase{
3832 testType: testType,
3833 name: "CertificateVerificationSucceed" + suffix,
3834 config: Config{
3835 MaxVersion: vers.version,
3836 Certificates: []Certificate{rsaCertificate},
3837 },
3838 flags: []string{
3839 flag,
3840 "-expect-verify-result",
3841 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003842 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003843 })
3844 tests = append(tests, testCase{
3845 testType: testType,
3846 name: "CertificateVerificationFail" + suffix,
3847 config: Config{
3848 MaxVersion: vers.version,
3849 Certificates: []Certificate{rsaCertificate},
3850 },
3851 flags: []string{
3852 flag,
3853 "-verify-fail",
3854 },
3855 shouldFail: true,
3856 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3857 })
3858 }
3859
3860 // By default, the client is in a soft fail mode where the peer
3861 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003862 tests = append(tests, testCase{
3863 testType: clientTest,
3864 name: "CertificateVerificationSoftFail-" + vers.name,
3865 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003866 MaxVersion: vers.version,
3867 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003868 },
3869 flags: []string{
3870 "-verify-fail",
3871 "-expect-verify-result",
3872 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003873 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003874 })
3875 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003876
David Benjamin1d4f4c02016-07-26 18:03:08 -04003877 tests = append(tests, testCase{
3878 name: "ShimSendAlert",
3879 flags: []string{"-send-alert"},
3880 shimWritesFirst: true,
3881 shouldFail: true,
3882 expectedLocalError: "remote error: decompression failure",
3883 })
3884
David Benjamin582ba042016-07-07 12:33:25 -07003885 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003886 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003887 name: "Renegotiate-Client",
3888 config: Config{
3889 MaxVersion: VersionTLS12,
3890 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-freely",
3894 "-expect-total-renegotiations", "1",
3895 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003896 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003897
David Benjamin47921102016-07-28 11:29:18 -04003898 tests = append(tests, testCase{
3899 name: "SendHalfHelloRequest",
3900 config: Config{
3901 MaxVersion: VersionTLS12,
3902 Bugs: ProtocolBugs{
3903 PackHelloRequestWithFinished: config.packHandshakeFlight,
3904 },
3905 },
3906 sendHalfHelloRequest: true,
3907 flags: []string{"-renegotiate-ignore"},
3908 shouldFail: true,
3909 expectedError: ":UNEXPECTED_RECORD:",
3910 })
3911
David Benjamin760b1dd2015-05-15 23:33:48 -04003912 // NPN on client and server; results in post-handshake message.
3913 tests = append(tests, testCase{
3914 name: "NPN-Client",
3915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003916 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 NextProtos: []string{"foo"},
3918 },
3919 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003920 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003921 expectedNextProto: "foo",
3922 expectedNextProtoType: npn,
3923 })
3924 tests = append(tests, testCase{
3925 testType: serverTest,
3926 name: "NPN-Server",
3927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003928 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 NextProtos: []string{"bar"},
3930 },
3931 flags: []string{
3932 "-advertise-npn", "\x03foo\x03bar\x03baz",
3933 "-expect-next-proto", "bar",
3934 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003935 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003936 expectedNextProto: "bar",
3937 expectedNextProtoType: npn,
3938 })
3939
3940 // TODO(davidben): Add tests for when False Start doesn't trigger.
3941
3942 // Client does False Start and negotiates NPN.
3943 tests = append(tests, testCase{
3944 name: "FalseStart",
3945 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003946 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3948 NextProtos: []string{"foo"},
3949 Bugs: ProtocolBugs{
3950 ExpectFalseStart: true,
3951 },
3952 },
3953 flags: []string{
3954 "-false-start",
3955 "-select-next-proto", "foo",
3956 },
3957 shimWritesFirst: true,
3958 resumeSession: true,
3959 })
3960
3961 // Client does False Start and negotiates ALPN.
3962 tests = append(tests, testCase{
3963 name: "FalseStart-ALPN",
3964 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003965 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3967 NextProtos: []string{"foo"},
3968 Bugs: ProtocolBugs{
3969 ExpectFalseStart: true,
3970 },
3971 },
3972 flags: []string{
3973 "-false-start",
3974 "-advertise-alpn", "\x03foo",
3975 },
3976 shimWritesFirst: true,
3977 resumeSession: true,
3978 })
3979
3980 // Client does False Start but doesn't explicitly call
3981 // SSL_connect.
3982 tests = append(tests, testCase{
3983 name: "FalseStart-Implicit",
3984 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003985 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003986 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3987 NextProtos: []string{"foo"},
3988 },
3989 flags: []string{
3990 "-implicit-handshake",
3991 "-false-start",
3992 "-advertise-alpn", "\x03foo",
3993 },
3994 })
3995
3996 // False Start without session tickets.
3997 tests = append(tests, testCase{
3998 name: "FalseStart-SessionTicketsDisabled",
3999 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004000 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4002 NextProtos: []string{"foo"},
4003 SessionTicketsDisabled: true,
4004 Bugs: ProtocolBugs{
4005 ExpectFalseStart: true,
4006 },
4007 },
4008 flags: []string{
4009 "-false-start",
4010 "-select-next-proto", "foo",
4011 },
4012 shimWritesFirst: true,
4013 })
4014
4015 // Server parses a V2ClientHello.
4016 tests = append(tests, testCase{
4017 testType: serverTest,
4018 name: "SendV2ClientHello",
4019 config: Config{
4020 // Choose a cipher suite that does not involve
4021 // elliptic curves, so no extensions are
4022 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004023 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004024 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004025 Bugs: ProtocolBugs{
4026 SendV2ClientHello: true,
4027 },
4028 },
4029 })
4030
Nick Harper60a85cb2016-09-23 16:25:11 -07004031 // Test Channel ID
4032 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004033 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004034 continue
4035 }
4036 // Client sends a Channel ID.
4037 tests = append(tests, testCase{
4038 name: "ChannelID-Client-" + ver.name,
4039 config: Config{
4040 MaxVersion: ver.version,
4041 RequestChannelID: true,
4042 },
4043 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4044 resumeSession: true,
4045 expectChannelID: true,
4046 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004047
Nick Harper60a85cb2016-09-23 16:25:11 -07004048 // Server accepts a Channel ID.
4049 tests = append(tests, testCase{
4050 testType: serverTest,
4051 name: "ChannelID-Server-" + ver.name,
4052 config: Config{
4053 MaxVersion: ver.version,
4054 ChannelID: channelIDKey,
4055 },
4056 flags: []string{
4057 "-expect-channel-id",
4058 base64.StdEncoding.EncodeToString(channelIDBytes),
4059 },
4060 resumeSession: true,
4061 expectChannelID: true,
4062 })
4063
4064 tests = append(tests, testCase{
4065 testType: serverTest,
4066 name: "InvalidChannelIDSignature-" + ver.name,
4067 config: Config{
4068 MaxVersion: ver.version,
4069 ChannelID: channelIDKey,
4070 Bugs: ProtocolBugs{
4071 InvalidChannelIDSignature: true,
4072 },
4073 },
4074 flags: []string{"-enable-channel-id"},
4075 shouldFail: true,
4076 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4077 })
4078 }
David Benjamin30789da2015-08-29 22:56:45 -04004079
David Benjaminf8fcdf32016-06-08 15:56:13 -04004080 // Channel ID and NPN at the same time, to ensure their relative
4081 // ordering is correct.
4082 tests = append(tests, testCase{
4083 name: "ChannelID-NPN-Client",
4084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004085 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004086 RequestChannelID: true,
4087 NextProtos: []string{"foo"},
4088 },
4089 flags: []string{
4090 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4091 "-select-next-proto", "foo",
4092 },
4093 resumeSession: true,
4094 expectChannelID: true,
4095 expectedNextProto: "foo",
4096 expectedNextProtoType: npn,
4097 })
4098 tests = append(tests, testCase{
4099 testType: serverTest,
4100 name: "ChannelID-NPN-Server",
4101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004102 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004103 ChannelID: channelIDKey,
4104 NextProtos: []string{"bar"},
4105 },
4106 flags: []string{
4107 "-expect-channel-id",
4108 base64.StdEncoding.EncodeToString(channelIDBytes),
4109 "-advertise-npn", "\x03foo\x03bar\x03baz",
4110 "-expect-next-proto", "bar",
4111 },
4112 resumeSession: true,
4113 expectChannelID: true,
4114 expectedNextProto: "bar",
4115 expectedNextProtoType: npn,
4116 })
4117
David Benjamin30789da2015-08-29 22:56:45 -04004118 // Bidirectional shutdown with the runner initiating.
4119 tests = append(tests, testCase{
4120 name: "Shutdown-Runner",
4121 config: Config{
4122 Bugs: ProtocolBugs{
4123 ExpectCloseNotify: true,
4124 },
4125 },
4126 flags: []string{"-check-close-notify"},
4127 })
4128
4129 // Bidirectional shutdown with the shim initiating. The runner,
4130 // in the meantime, sends garbage before the close_notify which
4131 // the shim must ignore.
4132 tests = append(tests, testCase{
4133 name: "Shutdown-Shim",
4134 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004135 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004136 Bugs: ProtocolBugs{
4137 ExpectCloseNotify: true,
4138 },
4139 },
4140 shimShutsDown: true,
4141 sendEmptyRecords: 1,
4142 sendWarningAlerts: 1,
4143 flags: []string{"-check-close-notify"},
4144 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004145 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004146 // TODO(davidben): DTLS 1.3 will want a similar thing for
4147 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004148 tests = append(tests, testCase{
4149 name: "SkipHelloVerifyRequest",
4150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004151 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004152 Bugs: ProtocolBugs{
4153 SkipHelloVerifyRequest: true,
4154 },
4155 },
4156 })
4157 }
4158
David Benjamin760b1dd2015-05-15 23:33:48 -04004159 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004160 test.protocol = config.protocol
4161 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004162 test.name += "-DTLS"
4163 }
David Benjamin582ba042016-07-07 12:33:25 -07004164 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004165 test.name += "-Async"
4166 test.flags = append(test.flags, "-async")
4167 } else {
4168 test.name += "-Sync"
4169 }
David Benjamin582ba042016-07-07 12:33:25 -07004170 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004171 test.name += "-SplitHandshakeRecords"
4172 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004173 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004174 test.config.Bugs.MaxPacketLength = 256
4175 test.flags = append(test.flags, "-mtu", "256")
4176 }
4177 }
David Benjamin582ba042016-07-07 12:33:25 -07004178 if config.packHandshakeFlight {
4179 test.name += "-PackHandshakeFlight"
4180 test.config.Bugs.PackHandshakeFlight = true
4181 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004182 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004183 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004184}
4185
Adam Langley524e7172015-02-20 16:04:00 -08004186func addDDoSCallbackTests() {
4187 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004188 for _, resume := range []bool{false, true} {
4189 suffix := "Resume"
4190 if resume {
4191 suffix = "No" + suffix
4192 }
4193
4194 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004195 testType: serverTest,
4196 name: "Server-DDoS-OK-" + suffix,
4197 config: Config{
4198 MaxVersion: VersionTLS12,
4199 },
Adam Langley524e7172015-02-20 16:04:00 -08004200 flags: []string{"-install-ddos-callback"},
4201 resumeSession: resume,
4202 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004203 testCases = append(testCases, testCase{
4204 testType: serverTest,
4205 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4206 config: Config{
4207 MaxVersion: VersionTLS13,
4208 },
4209 flags: []string{"-install-ddos-callback"},
4210 resumeSession: resume,
4211 })
Adam Langley524e7172015-02-20 16:04:00 -08004212
4213 failFlag := "-fail-ddos-callback"
4214 if resume {
4215 failFlag = "-fail-second-ddos-callback"
4216 }
4217 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004218 testType: serverTest,
4219 name: "Server-DDoS-Reject-" + suffix,
4220 config: Config{
4221 MaxVersion: VersionTLS12,
4222 },
David Benjamin2c66e072016-09-16 15:58:00 -04004223 flags: []string{"-install-ddos-callback", failFlag},
4224 resumeSession: resume,
4225 shouldFail: true,
4226 expectedError: ":CONNECTION_REJECTED:",
4227 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004228 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004229 testCases = append(testCases, testCase{
4230 testType: serverTest,
4231 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4232 config: Config{
4233 MaxVersion: VersionTLS13,
4234 },
David Benjamin2c66e072016-09-16 15:58:00 -04004235 flags: []string{"-install-ddos-callback", failFlag},
4236 resumeSession: resume,
4237 shouldFail: true,
4238 expectedError: ":CONNECTION_REJECTED:",
4239 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004240 })
Adam Langley524e7172015-02-20 16:04:00 -08004241 }
4242}
4243
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004244func addVersionNegotiationTests() {
4245 for i, shimVers := range tlsVersions {
4246 // Assemble flags to disable all newer versions on the shim.
4247 var flags []string
4248 for _, vers := range tlsVersions[i+1:] {
4249 flags = append(flags, vers.flag)
4250 }
4251
Steven Valdezfdd10992016-09-15 16:27:05 -04004252 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004253 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004254 protocols := []protocol{tls}
4255 if runnerVers.hasDTLS && shimVers.hasDTLS {
4256 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004257 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004258 for _, protocol := range protocols {
4259 expectedVersion := shimVers.version
4260 if runnerVers.version < shimVers.version {
4261 expectedVersion = runnerVers.version
4262 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004263
David Benjamin8b8c0062014-11-23 02:47:52 -05004264 suffix := shimVers.name + "-" + runnerVers.name
4265 if protocol == dtls {
4266 suffix += "-DTLS"
4267 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004268
David Benjamin1eb367c2014-12-12 18:17:51 -05004269 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4270
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004271 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004272 clientVers := shimVers.version
4273 if clientVers > VersionTLS10 {
4274 clientVers = VersionTLS10
4275 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004276 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004277 serverVers := expectedVersion
4278 if expectedVersion >= VersionTLS13 {
4279 serverVers = VersionTLS10
4280 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004281 serverVers = versionToWire(serverVers, protocol == dtls)
4282
David Benjamin8b8c0062014-11-23 02:47:52 -05004283 testCases = append(testCases, testCase{
4284 protocol: protocol,
4285 testType: clientTest,
4286 name: "VersionNegotiation-Client-" + suffix,
4287 config: Config{
4288 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004289 Bugs: ProtocolBugs{
4290 ExpectInitialRecordVersion: clientVers,
4291 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004292 },
4293 flags: flags,
4294 expectedVersion: expectedVersion,
4295 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004296 testCases = append(testCases, testCase{
4297 protocol: protocol,
4298 testType: clientTest,
4299 name: "VersionNegotiation-Client2-" + suffix,
4300 config: Config{
4301 MaxVersion: runnerVers.version,
4302 Bugs: ProtocolBugs{
4303 ExpectInitialRecordVersion: clientVers,
4304 },
4305 },
4306 flags: []string{"-max-version", shimVersFlag},
4307 expectedVersion: expectedVersion,
4308 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004309
4310 testCases = append(testCases, testCase{
4311 protocol: protocol,
4312 testType: serverTest,
4313 name: "VersionNegotiation-Server-" + suffix,
4314 config: Config{
4315 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004316 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004317 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004318 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004319 },
4320 flags: flags,
4321 expectedVersion: expectedVersion,
4322 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004323 testCases = append(testCases, testCase{
4324 protocol: protocol,
4325 testType: serverTest,
4326 name: "VersionNegotiation-Server2-" + suffix,
4327 config: Config{
4328 MaxVersion: runnerVers.version,
4329 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004330 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004331 },
4332 },
4333 flags: []string{"-max-version", shimVersFlag},
4334 expectedVersion: expectedVersion,
4335 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004336 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004337 }
4338 }
David Benjamin95c69562016-06-29 18:15:03 -04004339
Steven Valdezfdd10992016-09-15 16:27:05 -04004340 // Test the version extension at all versions.
4341 for _, vers := range tlsVersions {
4342 protocols := []protocol{tls}
4343 if vers.hasDTLS {
4344 protocols = append(protocols, dtls)
4345 }
4346 for _, protocol := range protocols {
4347 suffix := vers.name
4348 if protocol == dtls {
4349 suffix += "-DTLS"
4350 }
4351
4352 wireVersion := versionToWire(vers.version, protocol == dtls)
4353 testCases = append(testCases, testCase{
4354 protocol: protocol,
4355 testType: serverTest,
4356 name: "VersionNegotiationExtension-" + suffix,
4357 config: Config{
4358 Bugs: ProtocolBugs{
4359 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4360 },
4361 },
4362 expectedVersion: vers.version,
4363 })
4364 }
4365
4366 }
4367
4368 // If all versions are unknown, negotiation fails.
4369 testCases = append(testCases, testCase{
4370 testType: serverTest,
4371 name: "NoSupportedVersions",
4372 config: Config{
4373 Bugs: ProtocolBugs{
4374 SendSupportedVersions: []uint16{0x1111},
4375 },
4376 },
4377 shouldFail: true,
4378 expectedError: ":UNSUPPORTED_PROTOCOL:",
4379 })
4380 testCases = append(testCases, testCase{
4381 protocol: dtls,
4382 testType: serverTest,
4383 name: "NoSupportedVersions-DTLS",
4384 config: Config{
4385 Bugs: ProtocolBugs{
4386 SendSupportedVersions: []uint16{0x1111},
4387 },
4388 },
4389 shouldFail: true,
4390 expectedError: ":UNSUPPORTED_PROTOCOL:",
4391 })
4392
4393 testCases = append(testCases, testCase{
4394 testType: serverTest,
4395 name: "ClientHelloVersionTooHigh",
4396 config: Config{
4397 MaxVersion: VersionTLS13,
4398 Bugs: ProtocolBugs{
4399 SendClientVersion: 0x0304,
4400 OmitSupportedVersions: true,
4401 },
4402 },
4403 expectedVersion: VersionTLS12,
4404 })
4405
4406 testCases = append(testCases, testCase{
4407 testType: serverTest,
4408 name: "ConflictingVersionNegotiation",
4409 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004410 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004411 SendClientVersion: VersionTLS12,
4412 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004413 },
4414 },
David Benjaminad75a662016-09-30 15:42:59 -04004415 // The extension takes precedence over the ClientHello version.
4416 expectedVersion: VersionTLS11,
4417 })
4418
4419 testCases = append(testCases, testCase{
4420 testType: serverTest,
4421 name: "ConflictingVersionNegotiation-2",
4422 config: Config{
4423 Bugs: ProtocolBugs{
4424 SendClientVersion: VersionTLS11,
4425 SendSupportedVersions: []uint16{VersionTLS12},
4426 },
4427 },
4428 // The extension takes precedence over the ClientHello version.
4429 expectedVersion: VersionTLS12,
4430 })
4431
4432 testCases = append(testCases, testCase{
4433 testType: serverTest,
4434 name: "RejectFinalTLS13",
4435 config: Config{
4436 Bugs: ProtocolBugs{
4437 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4438 },
4439 },
4440 // We currently implement a draft TLS 1.3 version. Ensure that
4441 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004442 expectedVersion: VersionTLS12,
4443 })
4444
Brian Smithf85d3232016-10-28 10:34:06 -10004445 // Test that the maximum version is selected regardless of the
4446 // client-sent order.
4447 testCases = append(testCases, testCase{
4448 testType: serverTest,
4449 name: "IgnoreClientVersionOrder",
4450 config: Config{
4451 Bugs: ProtocolBugs{
4452 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4453 },
4454 },
4455 expectedVersion: VersionTLS13,
4456 })
4457
David Benjamin95c69562016-06-29 18:15:03 -04004458 // Test for version tolerance.
4459 testCases = append(testCases, testCase{
4460 testType: serverTest,
4461 name: "MinorVersionTolerance",
4462 config: Config{
4463 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004464 SendClientVersion: 0x03ff,
4465 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004466 },
4467 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004468 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004469 })
4470 testCases = append(testCases, testCase{
4471 testType: serverTest,
4472 name: "MajorVersionTolerance",
4473 config: Config{
4474 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004475 SendClientVersion: 0x0400,
4476 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004477 },
4478 },
David Benjaminad75a662016-09-30 15:42:59 -04004479 // TLS 1.3 must be negotiated with the supported_versions
4480 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004481 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004482 })
David Benjaminad75a662016-09-30 15:42:59 -04004483 testCases = append(testCases, testCase{
4484 testType: serverTest,
4485 name: "VersionTolerance-TLS13",
4486 config: Config{
4487 Bugs: ProtocolBugs{
4488 // Although TLS 1.3 does not use
4489 // ClientHello.version, it still tolerates high
4490 // values there.
4491 SendClientVersion: 0x0400,
4492 },
4493 },
4494 expectedVersion: VersionTLS13,
4495 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004496
David Benjamin95c69562016-06-29 18:15:03 -04004497 testCases = append(testCases, testCase{
4498 protocol: dtls,
4499 testType: serverTest,
4500 name: "MinorVersionTolerance-DTLS",
4501 config: Config{
4502 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004503 SendClientVersion: 0xfe00,
4504 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004505 },
4506 },
4507 expectedVersion: VersionTLS12,
4508 })
4509 testCases = append(testCases, testCase{
4510 protocol: dtls,
4511 testType: serverTest,
4512 name: "MajorVersionTolerance-DTLS",
4513 config: Config{
4514 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004515 SendClientVersion: 0xfdff,
4516 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004517 },
4518 },
4519 expectedVersion: VersionTLS12,
4520 })
4521
4522 // Test that versions below 3.0 are rejected.
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "VersionTooLow",
4526 config: Config{
4527 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004528 SendClientVersion: 0x0200,
4529 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004530 },
4531 },
4532 shouldFail: true,
4533 expectedError: ":UNSUPPORTED_PROTOCOL:",
4534 })
4535 testCases = append(testCases, testCase{
4536 protocol: dtls,
4537 testType: serverTest,
4538 name: "VersionTooLow-DTLS",
4539 config: Config{
4540 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004541 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004542 },
4543 },
4544 shouldFail: true,
4545 expectedError: ":UNSUPPORTED_PROTOCOL:",
4546 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004547
David Benjamin2dc02042016-09-19 19:57:37 -04004548 testCases = append(testCases, testCase{
4549 name: "ServerBogusVersion",
4550 config: Config{
4551 Bugs: ProtocolBugs{
4552 SendServerHelloVersion: 0x1234,
4553 },
4554 },
4555 shouldFail: true,
4556 expectedError: ":UNSUPPORTED_PROTOCOL:",
4557 })
4558
David Benjamin1f61f0d2016-07-10 12:20:35 -04004559 // Test TLS 1.3's downgrade signal.
4560 testCases = append(testCases, testCase{
4561 name: "Downgrade-TLS12-Client",
4562 config: Config{
4563 Bugs: ProtocolBugs{
4564 NegotiateVersion: VersionTLS12,
4565 },
4566 },
David Benjamin592b5322016-09-30 15:15:01 -04004567 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004568 // TODO(davidben): This test should fail once TLS 1.3 is final
4569 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004570 })
4571 testCases = append(testCases, testCase{
4572 testType: serverTest,
4573 name: "Downgrade-TLS12-Server",
4574 config: Config{
4575 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004576 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004577 },
4578 },
David Benjamin592b5322016-09-30 15:15:01 -04004579 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004580 // TODO(davidben): This test should fail once TLS 1.3 is final
4581 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004582 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004583}
4584
David Benjaminaccb4542014-12-12 23:44:33 -05004585func addMinimumVersionTests() {
4586 for i, shimVers := range tlsVersions {
4587 // Assemble flags to disable all older versions on the shim.
4588 var flags []string
4589 for _, vers := range tlsVersions[:i] {
4590 flags = append(flags, vers.flag)
4591 }
4592
4593 for _, runnerVers := range tlsVersions {
4594 protocols := []protocol{tls}
4595 if runnerVers.hasDTLS && shimVers.hasDTLS {
4596 protocols = append(protocols, dtls)
4597 }
4598 for _, protocol := range protocols {
4599 suffix := shimVers.name + "-" + runnerVers.name
4600 if protocol == dtls {
4601 suffix += "-DTLS"
4602 }
4603 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4604
David Benjaminaccb4542014-12-12 23:44:33 -05004605 var expectedVersion uint16
4606 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004607 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004608 if runnerVers.version >= shimVers.version {
4609 expectedVersion = runnerVers.version
4610 } else {
4611 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004612 expectedError = ":UNSUPPORTED_PROTOCOL:"
4613 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004614 }
4615
4616 testCases = append(testCases, testCase{
4617 protocol: protocol,
4618 testType: clientTest,
4619 name: "MinimumVersion-Client-" + suffix,
4620 config: Config{
4621 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004622 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004623 // Ensure the server does not decline to
4624 // select a version (versions extension) or
4625 // cipher (some ciphers depend on versions).
4626 NegotiateVersion: runnerVers.version,
4627 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004628 },
David Benjaminaccb4542014-12-12 23:44:33 -05004629 },
David Benjamin87909c02014-12-13 01:55:01 -05004630 flags: flags,
4631 expectedVersion: expectedVersion,
4632 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004633 expectedError: expectedError,
4634 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004635 })
4636 testCases = append(testCases, testCase{
4637 protocol: protocol,
4638 testType: clientTest,
4639 name: "MinimumVersion-Client2-" + suffix,
4640 config: Config{
4641 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004642 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004643 // Ensure the server does not decline to
4644 // select a version (versions extension) or
4645 // cipher (some ciphers depend on versions).
4646 NegotiateVersion: runnerVers.version,
4647 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004648 },
David Benjaminaccb4542014-12-12 23:44:33 -05004649 },
David Benjamin87909c02014-12-13 01:55:01 -05004650 flags: []string{"-min-version", shimVersFlag},
4651 expectedVersion: expectedVersion,
4652 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004653 expectedError: expectedError,
4654 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004655 })
4656
4657 testCases = append(testCases, testCase{
4658 protocol: protocol,
4659 testType: serverTest,
4660 name: "MinimumVersion-Server-" + suffix,
4661 config: Config{
4662 MaxVersion: runnerVers.version,
4663 },
David Benjamin87909c02014-12-13 01:55:01 -05004664 flags: flags,
4665 expectedVersion: expectedVersion,
4666 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004667 expectedError: expectedError,
4668 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004669 })
4670 testCases = append(testCases, testCase{
4671 protocol: protocol,
4672 testType: serverTest,
4673 name: "MinimumVersion-Server2-" + suffix,
4674 config: Config{
4675 MaxVersion: runnerVers.version,
4676 },
David Benjamin87909c02014-12-13 01:55:01 -05004677 flags: []string{"-min-version", shimVersFlag},
4678 expectedVersion: expectedVersion,
4679 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004680 expectedError: expectedError,
4681 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004682 })
4683 }
4684 }
4685 }
4686}
4687
David Benjamine78bfde2014-09-06 12:45:15 -04004688func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004689 // TODO(davidben): Extensions, where applicable, all move their server
4690 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4691 // tests for both. Also test interaction with 0-RTT when implemented.
4692
David Benjamin97d17d92016-07-14 16:12:00 -04004693 // Repeat extensions tests all versions except SSL 3.0.
4694 for _, ver := range tlsVersions {
4695 if ver.version == VersionSSL30 {
4696 continue
4697 }
4698
David Benjamin97d17d92016-07-14 16:12:00 -04004699 // Test that duplicate extensions are rejected.
4700 testCases = append(testCases, testCase{
4701 testType: clientTest,
4702 name: "DuplicateExtensionClient-" + ver.name,
4703 config: Config{
4704 MaxVersion: ver.version,
4705 Bugs: ProtocolBugs{
4706 DuplicateExtension: true,
4707 },
David Benjamine78bfde2014-09-06 12:45:15 -04004708 },
David Benjamin97d17d92016-07-14 16:12:00 -04004709 shouldFail: true,
4710 expectedLocalError: "remote error: error decoding message",
4711 })
4712 testCases = append(testCases, testCase{
4713 testType: serverTest,
4714 name: "DuplicateExtensionServer-" + ver.name,
4715 config: Config{
4716 MaxVersion: ver.version,
4717 Bugs: ProtocolBugs{
4718 DuplicateExtension: true,
4719 },
David Benjamine78bfde2014-09-06 12:45:15 -04004720 },
David Benjamin97d17d92016-07-14 16:12:00 -04004721 shouldFail: true,
4722 expectedLocalError: "remote error: error decoding message",
4723 })
4724
4725 // Test SNI.
4726 testCases = append(testCases, testCase{
4727 testType: clientTest,
4728 name: "ServerNameExtensionClient-" + ver.name,
4729 config: Config{
4730 MaxVersion: ver.version,
4731 Bugs: ProtocolBugs{
4732 ExpectServerName: "example.com",
4733 },
David Benjamine78bfde2014-09-06 12:45:15 -04004734 },
David Benjamin97d17d92016-07-14 16:12:00 -04004735 flags: []string{"-host-name", "example.com"},
4736 })
4737 testCases = append(testCases, testCase{
4738 testType: clientTest,
4739 name: "ServerNameExtensionClientMismatch-" + ver.name,
4740 config: Config{
4741 MaxVersion: ver.version,
4742 Bugs: ProtocolBugs{
4743 ExpectServerName: "mismatch.com",
4744 },
David Benjamine78bfde2014-09-06 12:45:15 -04004745 },
David Benjamin97d17d92016-07-14 16:12:00 -04004746 flags: []string{"-host-name", "example.com"},
4747 shouldFail: true,
4748 expectedLocalError: "tls: unexpected server name",
4749 })
4750 testCases = append(testCases, testCase{
4751 testType: clientTest,
4752 name: "ServerNameExtensionClientMissing-" + ver.name,
4753 config: Config{
4754 MaxVersion: ver.version,
4755 Bugs: ProtocolBugs{
4756 ExpectServerName: "missing.com",
4757 },
David Benjamine78bfde2014-09-06 12:45:15 -04004758 },
David Benjamin97d17d92016-07-14 16:12:00 -04004759 shouldFail: true,
4760 expectedLocalError: "tls: unexpected server name",
4761 })
4762 testCases = append(testCases, testCase{
4763 testType: serverTest,
4764 name: "ServerNameExtensionServer-" + ver.name,
4765 config: Config{
4766 MaxVersion: ver.version,
4767 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004768 },
David Benjamin97d17d92016-07-14 16:12:00 -04004769 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004770 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004771 })
4772
4773 // Test ALPN.
4774 testCases = append(testCases, testCase{
4775 testType: clientTest,
4776 name: "ALPNClient-" + ver.name,
4777 config: Config{
4778 MaxVersion: ver.version,
4779 NextProtos: []string{"foo"},
4780 },
4781 flags: []string{
4782 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4783 "-expect-alpn", "foo",
4784 },
4785 expectedNextProto: "foo",
4786 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004787 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004788 })
4789 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004790 testType: clientTest,
4791 name: "ALPNClient-Mismatch-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 Bugs: ProtocolBugs{
4795 SendALPN: "baz",
4796 },
4797 },
4798 flags: []string{
4799 "-advertise-alpn", "\x03foo\x03bar",
4800 },
4801 shouldFail: true,
4802 expectedError: ":INVALID_ALPN_PROTOCOL:",
4803 expectedLocalError: "remote error: illegal parameter",
4804 })
4805 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004806 testType: serverTest,
4807 name: "ALPNServer-" + ver.name,
4808 config: Config{
4809 MaxVersion: ver.version,
4810 NextProtos: []string{"foo", "bar", "baz"},
4811 },
4812 flags: []string{
4813 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4814 "-select-alpn", "foo",
4815 },
4816 expectedNextProto: "foo",
4817 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004818 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004819 })
4820 testCases = append(testCases, testCase{
4821 testType: serverTest,
4822 name: "ALPNServer-Decline-" + ver.name,
4823 config: Config{
4824 MaxVersion: ver.version,
4825 NextProtos: []string{"foo", "bar", "baz"},
4826 },
4827 flags: []string{"-decline-alpn"},
4828 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004829 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004830 })
4831
David Benjamin25fe85b2016-08-09 20:00:32 -04004832 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4833 // called once.
4834 testCases = append(testCases, testCase{
4835 testType: serverTest,
4836 name: "ALPNServer-Async-" + ver.name,
4837 config: Config{
4838 MaxVersion: ver.version,
4839 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004840 // Prior to TLS 1.3, exercise the asynchronous session callback.
4841 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004842 },
4843 flags: []string{
4844 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4845 "-select-alpn", "foo",
4846 "-async",
4847 },
4848 expectedNextProto: "foo",
4849 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004850 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004851 })
4852
David Benjamin97d17d92016-07-14 16:12:00 -04004853 var emptyString string
4854 testCases = append(testCases, testCase{
4855 testType: clientTest,
4856 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4857 config: Config{
4858 MaxVersion: ver.version,
4859 NextProtos: []string{""},
4860 Bugs: ProtocolBugs{
4861 // A server returning an empty ALPN protocol
4862 // should be rejected.
4863 ALPNProtocol: &emptyString,
4864 },
4865 },
4866 flags: []string{
4867 "-advertise-alpn", "\x03foo",
4868 },
4869 shouldFail: true,
4870 expectedError: ":PARSE_TLSEXT:",
4871 })
4872 testCases = append(testCases, testCase{
4873 testType: serverTest,
4874 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4875 config: Config{
4876 MaxVersion: ver.version,
4877 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004878 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004879 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004880 },
David Benjamin97d17d92016-07-14 16:12:00 -04004881 flags: []string{
4882 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004883 },
David Benjamin97d17d92016-07-14 16:12:00 -04004884 shouldFail: true,
4885 expectedError: ":PARSE_TLSEXT:",
4886 })
4887
4888 // Test NPN and the interaction with ALPN.
4889 if ver.version < VersionTLS13 {
4890 // Test that the server prefers ALPN over NPN.
4891 testCases = append(testCases, testCase{
4892 testType: serverTest,
4893 name: "ALPNServer-Preferred-" + ver.name,
4894 config: Config{
4895 MaxVersion: ver.version,
4896 NextProtos: []string{"foo", "bar", "baz"},
4897 },
4898 flags: []string{
4899 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4900 "-select-alpn", "foo",
4901 "-advertise-npn", "\x03foo\x03bar\x03baz",
4902 },
4903 expectedNextProto: "foo",
4904 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004905 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004906 })
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4910 config: Config{
4911 MaxVersion: ver.version,
4912 NextProtos: []string{"foo", "bar", "baz"},
4913 Bugs: ProtocolBugs{
4914 SwapNPNAndALPN: true,
4915 },
4916 },
4917 flags: []string{
4918 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4919 "-select-alpn", "foo",
4920 "-advertise-npn", "\x03foo\x03bar\x03baz",
4921 },
4922 expectedNextProto: "foo",
4923 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004924 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004925 })
4926
4927 // Test that negotiating both NPN and ALPN is forbidden.
4928 testCases = append(testCases, testCase{
4929 name: "NegotiateALPNAndNPN-" + ver.name,
4930 config: Config{
4931 MaxVersion: ver.version,
4932 NextProtos: []string{"foo", "bar", "baz"},
4933 Bugs: ProtocolBugs{
4934 NegotiateALPNAndNPN: true,
4935 },
4936 },
4937 flags: []string{
4938 "-advertise-alpn", "\x03foo",
4939 "-select-next-proto", "foo",
4940 },
4941 shouldFail: true,
4942 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4943 })
4944 testCases = append(testCases, testCase{
4945 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4946 config: Config{
4947 MaxVersion: ver.version,
4948 NextProtos: []string{"foo", "bar", "baz"},
4949 Bugs: ProtocolBugs{
4950 NegotiateALPNAndNPN: true,
4951 SwapNPNAndALPN: true,
4952 },
4953 },
4954 flags: []string{
4955 "-advertise-alpn", "\x03foo",
4956 "-select-next-proto", "foo",
4957 },
4958 shouldFail: true,
4959 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4960 })
David Benjamin97d17d92016-07-14 16:12:00 -04004961 }
4962
4963 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004964
4965 // Resume with a corrupt ticket.
4966 testCases = append(testCases, testCase{
4967 testType: serverTest,
4968 name: "CorruptTicket-" + ver.name,
4969 config: Config{
4970 MaxVersion: ver.version,
4971 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004972 FilterTicket: func(in []byte) ([]byte, error) {
4973 in[len(in)-1] ^= 1
4974 return in, nil
4975 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004976 },
4977 },
4978 resumeSession: true,
4979 expectResumeRejected: true,
4980 })
4981 // Test the ticket callback, with and without renewal.
4982 testCases = append(testCases, testCase{
4983 testType: serverTest,
4984 name: "TicketCallback-" + ver.name,
4985 config: Config{
4986 MaxVersion: ver.version,
4987 },
4988 resumeSession: true,
4989 flags: []string{"-use-ticket-callback"},
4990 })
4991 testCases = append(testCases, testCase{
4992 testType: serverTest,
4993 name: "TicketCallback-Renew-" + ver.name,
4994 config: Config{
4995 MaxVersion: ver.version,
4996 Bugs: ProtocolBugs{
4997 ExpectNewTicket: true,
4998 },
4999 },
5000 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5001 resumeSession: true,
5002 })
5003
5004 // Test that the ticket callback is only called once when everything before
5005 // it in the ClientHello is asynchronous. This corrupts the ticket so
5006 // certificate selection callbacks run.
5007 testCases = append(testCases, testCase{
5008 testType: serverTest,
5009 name: "TicketCallback-SingleCall-" + ver.name,
5010 config: Config{
5011 MaxVersion: ver.version,
5012 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005013 FilterTicket: func(in []byte) ([]byte, error) {
5014 in[len(in)-1] ^= 1
5015 return in, nil
5016 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005017 },
5018 },
5019 resumeSession: true,
5020 expectResumeRejected: true,
5021 flags: []string{
5022 "-use-ticket-callback",
5023 "-async",
5024 },
5025 })
5026
5027 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005028 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005029 testCases = append(testCases, testCase{
5030 testType: serverTest,
5031 name: "OversizedSessionId-" + ver.name,
5032 config: Config{
5033 MaxVersion: ver.version,
5034 Bugs: ProtocolBugs{
5035 OversizedSessionId: true,
5036 },
5037 },
5038 resumeSession: true,
5039 shouldFail: true,
5040 expectedError: ":DECODE_ERROR:",
5041 })
5042 }
5043
5044 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5045 // are ignored.
5046 if ver.hasDTLS {
5047 testCases = append(testCases, testCase{
5048 protocol: dtls,
5049 name: "SRTP-Client-" + ver.name,
5050 config: Config{
5051 MaxVersion: ver.version,
5052 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5053 },
5054 flags: []string{
5055 "-srtp-profiles",
5056 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5057 },
5058 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5059 })
5060 testCases = append(testCases, testCase{
5061 protocol: dtls,
5062 testType: serverTest,
5063 name: "SRTP-Server-" + ver.name,
5064 config: Config{
5065 MaxVersion: ver.version,
5066 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5067 },
5068 flags: []string{
5069 "-srtp-profiles",
5070 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5071 },
5072 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5073 })
5074 // Test that the MKI is ignored.
5075 testCases = append(testCases, testCase{
5076 protocol: dtls,
5077 testType: serverTest,
5078 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5079 config: Config{
5080 MaxVersion: ver.version,
5081 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5082 Bugs: ProtocolBugs{
5083 SRTPMasterKeyIdentifer: "bogus",
5084 },
5085 },
5086 flags: []string{
5087 "-srtp-profiles",
5088 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5089 },
5090 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5091 })
5092 // Test that SRTP isn't negotiated on the server if there were
5093 // no matching profiles.
5094 testCases = append(testCases, testCase{
5095 protocol: dtls,
5096 testType: serverTest,
5097 name: "SRTP-Server-NoMatch-" + ver.name,
5098 config: Config{
5099 MaxVersion: ver.version,
5100 SRTPProtectionProfiles: []uint16{100, 101, 102},
5101 },
5102 flags: []string{
5103 "-srtp-profiles",
5104 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5105 },
5106 expectedSRTPProtectionProfile: 0,
5107 })
5108 // Test that the server returning an invalid SRTP profile is
5109 // flagged as an error by the client.
5110 testCases = append(testCases, testCase{
5111 protocol: dtls,
5112 name: "SRTP-Client-NoMatch-" + ver.name,
5113 config: Config{
5114 MaxVersion: ver.version,
5115 Bugs: ProtocolBugs{
5116 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5117 },
5118 },
5119 flags: []string{
5120 "-srtp-profiles",
5121 "SRTP_AES128_CM_SHA1_80",
5122 },
5123 shouldFail: true,
5124 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5125 })
5126 }
5127
5128 // Test SCT list.
5129 testCases = append(testCases, testCase{
5130 name: "SignedCertificateTimestampList-Client-" + ver.name,
5131 testType: clientTest,
5132 config: Config{
5133 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005134 },
David Benjamin97d17d92016-07-14 16:12:00 -04005135 flags: []string{
5136 "-enable-signed-cert-timestamps",
5137 "-expect-signed-cert-timestamps",
5138 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005139 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005140 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005141 })
David Benjamindaa88502016-10-04 16:32:16 -04005142
Adam Langleycfa08c32016-11-17 13:21:27 -08005143 var differentSCTList []byte
5144 differentSCTList = append(differentSCTList, testSCTList...)
5145 differentSCTList[len(differentSCTList)-1] ^= 1
5146
David Benjamindaa88502016-10-04 16:32:16 -04005147 // The SCT extension did not specify that it must only be sent on resumption as it
5148 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005149 testCases = append(testCases, testCase{
5150 name: "SendSCTListOnResume-" + ver.name,
5151 config: Config{
5152 MaxVersion: ver.version,
5153 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005154 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005155 },
David Benjamind98452d2015-06-16 14:16:23 -04005156 },
David Benjamin97d17d92016-07-14 16:12:00 -04005157 flags: []string{
5158 "-enable-signed-cert-timestamps",
5159 "-expect-signed-cert-timestamps",
5160 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005161 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005162 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005163 })
David Benjamindaa88502016-10-04 16:32:16 -04005164
David Benjamin97d17d92016-07-14 16:12:00 -04005165 testCases = append(testCases, testCase{
5166 name: "SignedCertificateTimestampList-Server-" + ver.name,
5167 testType: serverTest,
5168 config: Config{
5169 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005170 },
David Benjamin97d17d92016-07-14 16:12:00 -04005171 flags: []string{
5172 "-signed-cert-timestamps",
5173 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005174 },
David Benjamin97d17d92016-07-14 16:12:00 -04005175 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005176 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005177 })
David Benjamin53210cb2016-11-16 09:01:48 +09005178
Adam Langleycfa08c32016-11-17 13:21:27 -08005179 emptySCTListCert := *testCerts[0].cert
5180 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5181
5182 // Test empty SCT list.
5183 testCases = append(testCases, testCase{
5184 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5185 testType: clientTest,
5186 config: Config{
5187 MaxVersion: ver.version,
5188 Certificates: []Certificate{emptySCTListCert},
5189 },
5190 flags: []string{
5191 "-enable-signed-cert-timestamps",
5192 },
5193 shouldFail: true,
5194 expectedError: ":ERROR_PARSING_EXTENSION:",
5195 })
5196
5197 emptySCTCert := *testCerts[0].cert
5198 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5199
5200 // Test empty SCT in non-empty list.
5201 testCases = append(testCases, testCase{
5202 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5203 testType: clientTest,
5204 config: Config{
5205 MaxVersion: ver.version,
5206 Certificates: []Certificate{emptySCTCert},
5207 },
5208 flags: []string{
5209 "-enable-signed-cert-timestamps",
5210 },
5211 shouldFail: true,
5212 expectedError: ":ERROR_PARSING_EXTENSION:",
5213 })
5214
David Benjamin53210cb2016-11-16 09:01:48 +09005215 // Test that certificate-related extensions are not sent unsolicited.
5216 testCases = append(testCases, testCase{
5217 testType: serverTest,
5218 name: "UnsolicitedCertificateExtensions-" + ver.name,
5219 config: Config{
5220 MaxVersion: ver.version,
5221 Bugs: ProtocolBugs{
5222 NoOCSPStapling: true,
5223 NoSignedCertificateTimestamps: true,
5224 },
5225 },
5226 flags: []string{
5227 "-ocsp-response",
5228 base64.StdEncoding.EncodeToString(testOCSPResponse),
5229 "-signed-cert-timestamps",
5230 base64.StdEncoding.EncodeToString(testSCTList),
5231 },
5232 })
David Benjamin97d17d92016-07-14 16:12:00 -04005233 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005234
Paul Lietar4fac72e2015-09-09 13:44:55 +01005235 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005236 testType: clientTest,
5237 name: "ClientHelloPadding",
5238 config: Config{
5239 Bugs: ProtocolBugs{
5240 RequireClientHelloSize: 512,
5241 },
5242 },
5243 // This hostname just needs to be long enough to push the
5244 // ClientHello into F5's danger zone between 256 and 511 bytes
5245 // long.
5246 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5247 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005248
5249 // Extensions should not function in SSL 3.0.
5250 testCases = append(testCases, testCase{
5251 testType: serverTest,
5252 name: "SSLv3Extensions-NoALPN",
5253 config: Config{
5254 MaxVersion: VersionSSL30,
5255 NextProtos: []string{"foo", "bar", "baz"},
5256 },
5257 flags: []string{
5258 "-select-alpn", "foo",
5259 },
5260 expectNoNextProto: true,
5261 })
5262
5263 // Test session tickets separately as they follow a different codepath.
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "SSLv3Extensions-NoTickets",
5267 config: Config{
5268 MaxVersion: VersionSSL30,
5269 Bugs: ProtocolBugs{
5270 // Historically, session tickets in SSL 3.0
5271 // failed in different ways depending on whether
5272 // the client supported renegotiation_info.
5273 NoRenegotiationInfo: true,
5274 },
5275 },
5276 resumeSession: true,
5277 })
5278 testCases = append(testCases, testCase{
5279 testType: serverTest,
5280 name: "SSLv3Extensions-NoTickets2",
5281 config: Config{
5282 MaxVersion: VersionSSL30,
5283 },
5284 resumeSession: true,
5285 })
5286
5287 // But SSL 3.0 does send and process renegotiation_info.
5288 testCases = append(testCases, testCase{
5289 testType: serverTest,
5290 name: "SSLv3Extensions-RenegotiationInfo",
5291 config: Config{
5292 MaxVersion: VersionSSL30,
5293 Bugs: ProtocolBugs{
5294 RequireRenegotiationInfo: true,
5295 },
5296 },
5297 })
5298 testCases = append(testCases, testCase{
5299 testType: serverTest,
5300 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5301 config: Config{
5302 MaxVersion: VersionSSL30,
5303 Bugs: ProtocolBugs{
5304 NoRenegotiationInfo: true,
5305 SendRenegotiationSCSV: true,
5306 RequireRenegotiationInfo: true,
5307 },
5308 },
5309 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005310
5311 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5312 // in ServerHello.
5313 testCases = append(testCases, testCase{
5314 name: "NPN-Forbidden-TLS13",
5315 config: Config{
5316 MaxVersion: VersionTLS13,
5317 NextProtos: []string{"foo"},
5318 Bugs: ProtocolBugs{
5319 NegotiateNPNAtAllVersions: true,
5320 },
5321 },
5322 flags: []string{"-select-next-proto", "foo"},
5323 shouldFail: true,
5324 expectedError: ":ERROR_PARSING_EXTENSION:",
5325 })
5326 testCases = append(testCases, testCase{
5327 name: "EMS-Forbidden-TLS13",
5328 config: Config{
5329 MaxVersion: VersionTLS13,
5330 Bugs: ProtocolBugs{
5331 NegotiateEMSAtAllVersions: true,
5332 },
5333 },
5334 shouldFail: true,
5335 expectedError: ":ERROR_PARSING_EXTENSION:",
5336 })
5337 testCases = append(testCases, testCase{
5338 name: "RenegotiationInfo-Forbidden-TLS13",
5339 config: Config{
5340 MaxVersion: VersionTLS13,
5341 Bugs: ProtocolBugs{
5342 NegotiateRenegotiationInfoAtAllVersions: true,
5343 },
5344 },
5345 shouldFail: true,
5346 expectedError: ":ERROR_PARSING_EXTENSION:",
5347 })
5348 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005349 name: "Ticket-Forbidden-TLS13",
5350 config: Config{
5351 MaxVersion: VersionTLS12,
5352 },
5353 resumeConfig: &Config{
5354 MaxVersion: VersionTLS13,
5355 Bugs: ProtocolBugs{
5356 AdvertiseTicketExtension: true,
5357 },
5358 },
5359 resumeSession: true,
5360 shouldFail: true,
5361 expectedError: ":ERROR_PARSING_EXTENSION:",
5362 })
5363
5364 // Test that illegal extensions in TLS 1.3 are declined by the server if
5365 // offered in ClientHello. The runner's server will fail if this occurs,
5366 // so we exercise the offering path. (EMS and Renegotiation Info are
5367 // implicit in every test.)
5368 testCases = append(testCases, testCase{
5369 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005370 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005371 config: Config{
5372 MaxVersion: VersionTLS13,
5373 NextProtos: []string{"bar"},
5374 },
5375 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5376 })
David Benjamin196df5b2016-09-21 16:23:27 -04005377
David Benjamindaa88502016-10-04 16:32:16 -04005378 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5379 // tolerated.
5380 testCases = append(testCases, testCase{
5381 name: "SendOCSPResponseOnResume-TLS12",
5382 config: Config{
5383 MaxVersion: VersionTLS12,
5384 Bugs: ProtocolBugs{
5385 SendOCSPResponseOnResume: []byte("bogus"),
5386 },
5387 },
5388 flags: []string{
5389 "-enable-ocsp-stapling",
5390 "-expect-ocsp-response",
5391 base64.StdEncoding.EncodeToString(testOCSPResponse),
5392 },
5393 resumeSession: true,
5394 })
5395
David Benjamindaa88502016-10-04 16:32:16 -04005396 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005397 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005398 config: Config{
5399 MaxVersion: VersionTLS13,
5400 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005401 SendExtensionOnCertificate: testOCSPExtension,
5402 },
5403 },
5404 shouldFail: true,
5405 expectedError: ":UNEXPECTED_EXTENSION:",
5406 })
5407
5408 testCases = append(testCases, testCase{
5409 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5410 config: Config{
5411 MaxVersion: VersionTLS13,
5412 Bugs: ProtocolBugs{
5413 SendExtensionOnCertificate: testSCTExtension,
5414 },
5415 },
5416 shouldFail: true,
5417 expectedError: ":UNEXPECTED_EXTENSION:",
5418 })
5419
5420 // Test that extensions on client certificates are never accepted.
5421 testCases = append(testCases, testCase{
5422 name: "SendExtensionOnClientCertificate-TLS13",
5423 testType: serverTest,
5424 config: Config{
5425 MaxVersion: VersionTLS13,
5426 Certificates: []Certificate{rsaCertificate},
5427 Bugs: ProtocolBugs{
5428 SendExtensionOnCertificate: testOCSPExtension,
5429 },
5430 },
5431 flags: []string{
5432 "-enable-ocsp-stapling",
5433 "-require-any-client-certificate",
5434 },
5435 shouldFail: true,
5436 expectedError: ":UNEXPECTED_EXTENSION:",
5437 })
5438
5439 testCases = append(testCases, testCase{
5440 name: "SendUnknownExtensionOnCertificate-TLS13",
5441 config: Config{
5442 MaxVersion: VersionTLS13,
5443 Bugs: ProtocolBugs{
5444 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5445 },
5446 },
5447 shouldFail: true,
5448 expectedError: ":UNEXPECTED_EXTENSION:",
5449 })
5450
Adam Langleycfa08c32016-11-17 13:21:27 -08005451 var differentSCTList []byte
5452 differentSCTList = append(differentSCTList, testSCTList...)
5453 differentSCTList[len(differentSCTList)-1] ^= 1
5454
Steven Valdeza833c352016-11-01 13:39:36 -04005455 // Test that extensions on intermediates are allowed but ignored.
5456 testCases = append(testCases, testCase{
5457 name: "IgnoreExtensionsOnIntermediates-TLS13",
5458 config: Config{
5459 MaxVersion: VersionTLS13,
5460 Certificates: []Certificate{rsaChainCertificate},
5461 Bugs: ProtocolBugs{
5462 // Send different values on the intermediate. This tests
5463 // the intermediate's extensions do not override the
5464 // leaf's.
5465 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005466 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005467 },
5468 },
5469 flags: []string{
5470 "-enable-ocsp-stapling",
5471 "-expect-ocsp-response",
5472 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005473 "-enable-signed-cert-timestamps",
5474 "-expect-signed-cert-timestamps",
5475 base64.StdEncoding.EncodeToString(testSCTList),
5476 },
5477 resumeSession: true,
5478 })
5479
5480 // Test that extensions are not sent on intermediates when configured
5481 // only for a leaf.
5482 testCases = append(testCases, testCase{
5483 testType: serverTest,
5484 name: "SendNoExtensionsOnIntermediate-TLS13",
5485 config: Config{
5486 MaxVersion: VersionTLS13,
5487 Bugs: ProtocolBugs{
5488 ExpectNoExtensionsOnIntermediate: true,
5489 },
5490 },
5491 flags: []string{
5492 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5493 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5494 "-ocsp-response",
5495 base64.StdEncoding.EncodeToString(testOCSPResponse),
5496 "-signed-cert-timestamps",
5497 base64.StdEncoding.EncodeToString(testSCTList),
5498 },
5499 })
5500
5501 // Test that extensions are not sent on client certificates.
5502 testCases = append(testCases, testCase{
5503 name: "SendNoClientCertificateExtensions-TLS13",
5504 config: Config{
5505 MaxVersion: VersionTLS13,
5506 ClientAuth: RequireAnyClientCert,
5507 },
5508 flags: []string{
5509 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5510 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5511 "-ocsp-response",
5512 base64.StdEncoding.EncodeToString(testOCSPResponse),
5513 "-signed-cert-timestamps",
5514 base64.StdEncoding.EncodeToString(testSCTList),
5515 },
5516 })
5517
5518 testCases = append(testCases, testCase{
5519 name: "SendDuplicateExtensionsOnCerts-TLS13",
5520 config: Config{
5521 MaxVersion: VersionTLS13,
5522 Bugs: ProtocolBugs{
5523 SendDuplicateCertExtensions: true,
5524 },
5525 },
5526 flags: []string{
5527 "-enable-ocsp-stapling",
5528 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005529 },
5530 resumeSession: true,
5531 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005532 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005533 })
Adam Langley9b885c52016-11-18 14:21:03 -08005534
5535 testCases = append(testCases, testCase{
5536 name: "SignedCertificateTimestampListInvalid-Server",
5537 testType: serverTest,
5538 flags: []string{
5539 "-signed-cert-timestamps",
5540 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5541 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005542 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005543 expectedError: ":INVALID_SCT_LIST:",
5544 })
David Benjamine78bfde2014-09-06 12:45:15 -04005545}
5546
David Benjamin01fe8202014-09-24 15:21:44 -04005547func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005548 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005549 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005550 // SSL 3.0 does not have tickets and TLS 1.3 does not
5551 // have session IDs, so skip their cross-resumption
5552 // tests.
5553 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5554 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5555 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005556 }
5557
David Benjamin8b8c0062014-11-23 02:47:52 -05005558 protocols := []protocol{tls}
5559 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5560 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005561 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005562 for _, protocol := range protocols {
5563 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5564 if protocol == dtls {
5565 suffix += "-DTLS"
5566 }
5567
David Benjaminece3de92015-03-16 18:02:20 -04005568 if sessionVers.version == resumeVers.version {
5569 testCases = append(testCases, testCase{
5570 protocol: protocol,
5571 name: "Resume-Client" + suffix,
5572 resumeSession: true,
5573 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005574 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005575 Bugs: ProtocolBugs{
5576 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5577 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5578 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005579 },
David Benjaminece3de92015-03-16 18:02:20 -04005580 expectedVersion: sessionVers.version,
5581 expectedResumeVersion: resumeVers.version,
5582 })
5583 } else {
David Benjamin405da482016-08-08 17:25:07 -04005584 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5585
5586 // Offering a TLS 1.3 session sends an empty session ID, so
5587 // there is no way to convince a non-lookahead client the
5588 // session was resumed. It will appear to the client that a
5589 // stray ChangeCipherSpec was sent.
5590 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5591 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005592 }
5593
David Benjaminece3de92015-03-16 18:02:20 -04005594 testCases = append(testCases, testCase{
5595 protocol: protocol,
5596 name: "Resume-Client-Mismatch" + suffix,
5597 resumeSession: true,
5598 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005599 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005600 },
David Benjaminece3de92015-03-16 18:02:20 -04005601 expectedVersion: sessionVers.version,
5602 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005603 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005604 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005605 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005606 },
5607 },
5608 expectedResumeVersion: resumeVers.version,
5609 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005610 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005611 })
5612 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005613
5614 testCases = append(testCases, testCase{
5615 protocol: protocol,
5616 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005617 resumeSession: true,
5618 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005619 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005620 },
5621 expectedVersion: sessionVers.version,
5622 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005623 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005624 },
5625 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005626 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005627 expectedResumeVersion: resumeVers.version,
5628 })
5629
David Benjamin8b8c0062014-11-23 02:47:52 -05005630 testCases = append(testCases, testCase{
5631 protocol: protocol,
5632 testType: serverTest,
5633 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005634 resumeSession: true,
5635 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005636 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005637 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005638 expectedVersion: sessionVers.version,
5639 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005640 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005641 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005642 Bugs: ProtocolBugs{
5643 SendBothTickets: true,
5644 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005645 },
5646 expectedResumeVersion: resumeVers.version,
5647 })
5648 }
David Benjamin01fe8202014-09-24 15:21:44 -04005649 }
5650 }
David Benjaminece3de92015-03-16 18:02:20 -04005651
David Benjamin4199b0d2016-11-01 13:58:25 -04005652 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005653 testCases = append(testCases, testCase{
5654 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005655 name: "ShimTicketRewritable",
5656 resumeSession: true,
5657 config: Config{
5658 MaxVersion: VersionTLS12,
5659 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5660 Bugs: ProtocolBugs{
5661 FilterTicket: func(in []byte) ([]byte, error) {
5662 in, err := SetShimTicketVersion(in, VersionTLS12)
5663 if err != nil {
5664 return nil, err
5665 }
5666 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5667 },
5668 },
5669 },
5670 flags: []string{
5671 "-ticket-key",
5672 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5673 },
5674 })
5675
5676 // Resumptions are declined if the version does not match.
5677 testCases = append(testCases, testCase{
5678 testType: serverTest,
5679 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005680 resumeSession: true,
5681 config: Config{
5682 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005683 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005684 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005685 FilterTicket: func(in []byte) ([]byte, error) {
5686 return SetShimTicketVersion(in, VersionTLS13)
5687 },
5688 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005689 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005690 flags: []string{
5691 "-ticket-key",
5692 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5693 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005694 expectResumeRejected: true,
5695 })
5696
5697 testCases = append(testCases, testCase{
5698 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005699 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005700 resumeSession: true,
5701 config: Config{
5702 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005703 Bugs: ProtocolBugs{
5704 FilterTicket: func(in []byte) ([]byte, error) {
5705 return SetShimTicketVersion(in, VersionTLS12)
5706 },
5707 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005708 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005709 flags: []string{
5710 "-ticket-key",
5711 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5712 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005713 expectResumeRejected: true,
5714 })
5715
David Benjamin4199b0d2016-11-01 13:58:25 -04005716 // Resumptions are declined if the cipher is invalid or disabled.
5717 testCases = append(testCases, testCase{
5718 testType: serverTest,
5719 name: "Resume-Server-DeclineBadCipher",
5720 resumeSession: true,
5721 config: Config{
5722 MaxVersion: VersionTLS12,
5723 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005724 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005725 FilterTicket: func(in []byte) ([]byte, error) {
5726 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5727 },
5728 },
5729 },
5730 flags: []string{
5731 "-ticket-key",
5732 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5733 },
5734 expectResumeRejected: true,
5735 })
5736
5737 testCases = append(testCases, testCase{
5738 testType: serverTest,
5739 name: "Resume-Server-DeclineBadCipher-2",
5740 resumeSession: true,
5741 config: Config{
5742 MaxVersion: VersionTLS12,
5743 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005744 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005745 FilterTicket: func(in []byte) ([]byte, error) {
5746 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5747 },
5748 },
5749 },
5750 flags: []string{
5751 "-cipher", "AES128",
5752 "-ticket-key",
5753 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5754 },
5755 expectResumeRejected: true,
5756 })
5757
David Benjaminf01f42a2016-11-16 19:05:33 +09005758 // Sessions are not resumed if they do not use the preferred cipher.
5759 testCases = append(testCases, testCase{
5760 testType: serverTest,
5761 name: "Resume-Server-CipherNotPreferred",
5762 resumeSession: true,
5763 config: Config{
5764 MaxVersion: VersionTLS12,
5765 Bugs: ProtocolBugs{
5766 ExpectNewTicket: true,
5767 FilterTicket: func(in []byte) ([]byte, error) {
5768 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5769 },
5770 },
5771 },
5772 flags: []string{
5773 "-ticket-key",
5774 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5775 },
5776 shouldFail: false,
5777 expectResumeRejected: true,
5778 })
5779
5780 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5781 // PRF hashes match, but BoringSSL will always decline such resumptions.
5782 testCases = append(testCases, testCase{
5783 testType: serverTest,
5784 name: "Resume-Server-CipherNotPreferred-TLS13",
5785 resumeSession: true,
5786 config: Config{
5787 MaxVersion: VersionTLS13,
5788 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5789 Bugs: ProtocolBugs{
5790 FilterTicket: func(in []byte) ([]byte, error) {
5791 // If the client (runner) offers ChaCha20-Poly1305 first, the
5792 // server (shim) always prefers it. Switch it to AES-GCM.
5793 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5794 },
5795 },
5796 },
5797 flags: []string{
5798 "-ticket-key",
5799 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5800 },
5801 shouldFail: false,
5802 expectResumeRejected: true,
5803 })
5804
5805 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005806 testCases = append(testCases, testCase{
5807 testType: serverTest,
5808 name: "Resume-Server-DeclineBadCipher-TLS13",
5809 resumeSession: true,
5810 config: Config{
5811 MaxVersion: VersionTLS13,
5812 Bugs: ProtocolBugs{
5813 FilterTicket: func(in []byte) ([]byte, error) {
5814 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5815 },
5816 },
5817 },
5818 flags: []string{
5819 "-ticket-key",
5820 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5821 },
5822 expectResumeRejected: true,
5823 })
5824
David Benjaminf01f42a2016-11-16 19:05:33 +09005825 // If the client does not offer the cipher from the session, decline to
5826 // resume. Clients are forbidden from doing this, but BoringSSL selects
5827 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005828 testCases = append(testCases, testCase{
5829 testType: serverTest,
5830 name: "Resume-Server-UnofferedCipher",
5831 resumeSession: true,
5832 config: Config{
5833 MaxVersion: VersionTLS12,
5834 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5835 },
5836 resumeConfig: &Config{
5837 MaxVersion: VersionTLS12,
5838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5839 Bugs: ProtocolBugs{
5840 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5841 },
5842 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005843 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005844 })
5845
David Benjaminf01f42a2016-11-16 19:05:33 +09005846 // In TLS 1.3, clients may advertise a cipher list which does not
5847 // include the selected cipher. Test that we tolerate this. Servers may
5848 // resume at another cipher if the PRF matches, but BoringSSL will
5849 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005850 testCases = append(testCases, testCase{
5851 testType: serverTest,
5852 name: "Resume-Server-UnofferedCipher-TLS13",
5853 resumeSession: true,
5854 config: Config{
5855 MaxVersion: VersionTLS13,
5856 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5857 },
5858 resumeConfig: &Config{
5859 MaxVersion: VersionTLS13,
5860 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5861 Bugs: ProtocolBugs{
5862 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5863 },
5864 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005865 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005866 })
5867
David Benjamin4199b0d2016-11-01 13:58:25 -04005868 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005869 testCases = append(testCases, testCase{
5870 name: "Resume-Client-CipherMismatch",
5871 resumeSession: true,
5872 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005873 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005874 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5875 },
5876 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005877 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005878 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5879 Bugs: ProtocolBugs{
5880 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5881 },
5882 },
5883 shouldFail: true,
5884 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5885 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005886
David Benjamine1cc35e2016-11-16 16:25:58 +09005887 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5888 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005889 testCases = append(testCases, testCase{
5890 name: "Resume-Client-CipherMismatch-TLS13",
5891 resumeSession: true,
5892 config: Config{
5893 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005894 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005895 },
5896 resumeConfig: &Config{
5897 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005898 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5899 },
5900 })
5901
5902 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5903 testCases = append(testCases, testCase{
5904 name: "Resume-Client-PRFMismatch-TLS13",
5905 resumeSession: true,
5906 config: Config{
5907 MaxVersion: VersionTLS13,
5908 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5909 },
5910 resumeConfig: &Config{
5911 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005912 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005913 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005914 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915 },
5916 },
5917 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005918 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005919 })
Steven Valdeza833c352016-11-01 13:39:36 -04005920
5921 testCases = append(testCases, testCase{
5922 testType: serverTest,
5923 name: "Resume-Server-BinderWrongLength",
5924 resumeSession: true,
5925 config: Config{
5926 MaxVersion: VersionTLS13,
5927 Bugs: ProtocolBugs{
5928 SendShortPSKBinder: true,
5929 },
5930 },
5931 shouldFail: true,
5932 expectedLocalError: "remote error: error decrypting message",
5933 expectedError: ":DIGEST_CHECK_FAILED:",
5934 })
5935
5936 testCases = append(testCases, testCase{
5937 testType: serverTest,
5938 name: "Resume-Server-NoPSKBinder",
5939 resumeSession: true,
5940 config: Config{
5941 MaxVersion: VersionTLS13,
5942 Bugs: ProtocolBugs{
5943 SendNoPSKBinder: true,
5944 },
5945 },
5946 shouldFail: true,
5947 expectedLocalError: "remote error: error decoding message",
5948 expectedError: ":DECODE_ERROR:",
5949 })
5950
5951 testCases = append(testCases, testCase{
5952 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005953 name: "Resume-Server-ExtraPSKBinder",
5954 resumeSession: true,
5955 config: Config{
5956 MaxVersion: VersionTLS13,
5957 Bugs: ProtocolBugs{
5958 SendExtraPSKBinder: true,
5959 },
5960 },
5961 shouldFail: true,
5962 expectedLocalError: "remote error: illegal parameter",
5963 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5964 })
5965
5966 testCases = append(testCases, testCase{
5967 testType: serverTest,
5968 name: "Resume-Server-ExtraIdentityNoBinder",
5969 resumeSession: true,
5970 config: Config{
5971 MaxVersion: VersionTLS13,
5972 Bugs: ProtocolBugs{
5973 ExtraPSKIdentity: true,
5974 },
5975 },
5976 shouldFail: true,
5977 expectedLocalError: "remote error: illegal parameter",
5978 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5979 })
5980
5981 testCases = append(testCases, testCase{
5982 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04005983 name: "Resume-Server-InvalidPSKBinder",
5984 resumeSession: true,
5985 config: Config{
5986 MaxVersion: VersionTLS13,
5987 Bugs: ProtocolBugs{
5988 SendInvalidPSKBinder: true,
5989 },
5990 },
5991 shouldFail: true,
5992 expectedLocalError: "remote error: error decrypting message",
5993 expectedError: ":DIGEST_CHECK_FAILED:",
5994 })
5995
5996 testCases = append(testCases, testCase{
5997 testType: serverTest,
5998 name: "Resume-Server-PSKBinderFirstExtension",
5999 resumeSession: true,
6000 config: Config{
6001 MaxVersion: VersionTLS13,
6002 Bugs: ProtocolBugs{
6003 PSKBinderFirst: true,
6004 },
6005 },
6006 shouldFail: true,
6007 expectedLocalError: "remote error: illegal parameter",
6008 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6009 })
David Benjamin01fe8202014-09-24 15:21:44 -04006010}
6011
Adam Langley2ae77d22014-10-28 17:29:33 -07006012func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006013 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006014 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006015 testType: serverTest,
6016 name: "Renegotiate-Server-Forbidden",
6017 config: Config{
6018 MaxVersion: VersionTLS12,
6019 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006020 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006021 shouldFail: true,
6022 expectedError: ":NO_RENEGOTIATION:",
6023 expectedLocalError: "remote error: no renegotiation",
6024 })
Adam Langley5021b222015-06-12 18:27:58 -07006025 // The server shouldn't echo the renegotiation extension unless
6026 // requested by the client.
6027 testCases = append(testCases, testCase{
6028 testType: serverTest,
6029 name: "Renegotiate-Server-NoExt",
6030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006031 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006032 Bugs: ProtocolBugs{
6033 NoRenegotiationInfo: true,
6034 RequireRenegotiationInfo: true,
6035 },
6036 },
6037 shouldFail: true,
6038 expectedLocalError: "renegotiation extension missing",
6039 })
6040 // The renegotiation SCSV should be sufficient for the server to echo
6041 // the extension.
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
6044 name: "Renegotiate-Server-NoExt-SCSV",
6045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006046 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006047 Bugs: ProtocolBugs{
6048 NoRenegotiationInfo: true,
6049 SendRenegotiationSCSV: true,
6050 RequireRenegotiationInfo: true,
6051 },
6052 },
6053 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006054 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006055 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006057 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006058 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006059 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006060 },
6061 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006062 renegotiate: 1,
6063 flags: []string{
6064 "-renegotiate-freely",
6065 "-expect-total-renegotiations", "1",
6066 },
David Benjamincdea40c2015-03-19 14:09:43 -04006067 })
6068 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006069 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006070 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006072 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006073 Bugs: ProtocolBugs{
6074 EmptyRenegotiationInfo: true,
6075 },
6076 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006077 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006078 shouldFail: true,
6079 expectedError: ":RENEGOTIATION_MISMATCH:",
6080 })
6081 testCases = append(testCases, testCase{
6082 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006083 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006085 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006086 Bugs: ProtocolBugs{
6087 BadRenegotiationInfo: true,
6088 },
6089 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006090 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006091 shouldFail: true,
6092 expectedError: ":RENEGOTIATION_MISMATCH:",
6093 })
6094 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006095 name: "Renegotiate-Client-Downgrade",
6096 renegotiate: 1,
6097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006099 Bugs: ProtocolBugs{
6100 NoRenegotiationInfoAfterInitial: true,
6101 },
6102 },
6103 flags: []string{"-renegotiate-freely"},
6104 shouldFail: true,
6105 expectedError: ":RENEGOTIATION_MISMATCH:",
6106 })
6107 testCases = append(testCases, testCase{
6108 name: "Renegotiate-Client-Upgrade",
6109 renegotiate: 1,
6110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006111 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006112 Bugs: ProtocolBugs{
6113 NoRenegotiationInfoInInitial: true,
6114 },
6115 },
6116 flags: []string{"-renegotiate-freely"},
6117 shouldFail: true,
6118 expectedError: ":RENEGOTIATION_MISMATCH:",
6119 })
6120 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006121 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006122 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006124 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006125 Bugs: ProtocolBugs{
6126 NoRenegotiationInfo: true,
6127 },
6128 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006129 flags: []string{
6130 "-renegotiate-freely",
6131 "-expect-total-renegotiations", "1",
6132 },
David Benjamincff0b902015-05-15 23:09:47 -04006133 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006134
6135 // Test that the server may switch ciphers on renegotiation without
6136 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006137 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006138 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006139 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006140 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006141 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006142 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006143 },
6144 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006145 flags: []string{
6146 "-renegotiate-freely",
6147 "-expect-total-renegotiations", "1",
6148 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006149 })
6150 testCases = append(testCases, testCase{
6151 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006152 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006153 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006154 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006155 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6156 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006157 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006158 flags: []string{
6159 "-renegotiate-freely",
6160 "-expect-total-renegotiations", "1",
6161 },
David Benjaminb16346b2015-04-08 19:16:58 -04006162 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006163
6164 // Test that the server may not switch versions on renegotiation.
6165 testCases = append(testCases, testCase{
6166 name: "Renegotiate-Client-SwitchVersion",
6167 config: Config{
6168 MaxVersion: VersionTLS12,
6169 // Pick a cipher which exists at both versions.
6170 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6171 Bugs: ProtocolBugs{
6172 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006173 // Avoid failing early at the record layer.
6174 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006175 },
6176 },
6177 renegotiate: 1,
6178 flags: []string{
6179 "-renegotiate-freely",
6180 "-expect-total-renegotiations", "1",
6181 },
6182 shouldFail: true,
6183 expectedError: ":WRONG_SSL_VERSION:",
6184 })
6185
David Benjaminb16346b2015-04-08 19:16:58 -04006186 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006187 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006188 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006189 config: Config{
6190 MaxVersion: VersionTLS10,
6191 Bugs: ProtocolBugs{
6192 RequireSameRenegoClientVersion: true,
6193 },
6194 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006195 flags: []string{
6196 "-renegotiate-freely",
6197 "-expect-total-renegotiations", "1",
6198 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006199 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006200 testCases = append(testCases, testCase{
6201 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006202 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006203 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006204 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6206 NextProtos: []string{"foo"},
6207 },
6208 flags: []string{
6209 "-false-start",
6210 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006211 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006212 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006213 },
6214 shimWritesFirst: true,
6215 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006216
6217 // Client-side renegotiation controls.
6218 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006219 name: "Renegotiate-Client-Forbidden-1",
6220 config: Config{
6221 MaxVersion: VersionTLS12,
6222 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006223 renegotiate: 1,
6224 shouldFail: true,
6225 expectedError: ":NO_RENEGOTIATION:",
6226 expectedLocalError: "remote error: no renegotiation",
6227 })
6228 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006229 name: "Renegotiate-Client-Once-1",
6230 config: Config{
6231 MaxVersion: VersionTLS12,
6232 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006233 renegotiate: 1,
6234 flags: []string{
6235 "-renegotiate-once",
6236 "-expect-total-renegotiations", "1",
6237 },
6238 })
6239 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006240 name: "Renegotiate-Client-Freely-1",
6241 config: Config{
6242 MaxVersion: VersionTLS12,
6243 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006244 renegotiate: 1,
6245 flags: []string{
6246 "-renegotiate-freely",
6247 "-expect-total-renegotiations", "1",
6248 },
6249 })
6250 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006251 name: "Renegotiate-Client-Once-2",
6252 config: Config{
6253 MaxVersion: VersionTLS12,
6254 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006255 renegotiate: 2,
6256 flags: []string{"-renegotiate-once"},
6257 shouldFail: true,
6258 expectedError: ":NO_RENEGOTIATION:",
6259 expectedLocalError: "remote error: no renegotiation",
6260 })
6261 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006262 name: "Renegotiate-Client-Freely-2",
6263 config: Config{
6264 MaxVersion: VersionTLS12,
6265 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006266 renegotiate: 2,
6267 flags: []string{
6268 "-renegotiate-freely",
6269 "-expect-total-renegotiations", "2",
6270 },
6271 })
Adam Langley27a0d082015-11-03 13:34:10 -08006272 testCases = append(testCases, testCase{
6273 name: "Renegotiate-Client-NoIgnore",
6274 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006275 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006276 Bugs: ProtocolBugs{
6277 SendHelloRequestBeforeEveryAppDataRecord: true,
6278 },
6279 },
6280 shouldFail: true,
6281 expectedError: ":NO_RENEGOTIATION:",
6282 })
6283 testCases = append(testCases, testCase{
6284 name: "Renegotiate-Client-Ignore",
6285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006286 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006287 Bugs: ProtocolBugs{
6288 SendHelloRequestBeforeEveryAppDataRecord: true,
6289 },
6290 },
6291 flags: []string{
6292 "-renegotiate-ignore",
6293 "-expect-total-renegotiations", "0",
6294 },
6295 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006296
David Benjamin34941c02016-10-08 11:45:31 -04006297 // Renegotiation is not allowed at SSL 3.0.
6298 testCases = append(testCases, testCase{
6299 name: "Renegotiate-Client-SSL3",
6300 config: Config{
6301 MaxVersion: VersionSSL30,
6302 },
6303 renegotiate: 1,
6304 flags: []string{
6305 "-renegotiate-freely",
6306 "-expect-total-renegotiations", "1",
6307 },
6308 shouldFail: true,
6309 expectedError: ":NO_RENEGOTIATION:",
6310 expectedLocalError: "remote error: no renegotiation",
6311 })
6312
David Benjamin397c8e62016-07-08 14:14:36 -07006313 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006314 testCases = append(testCases, testCase{
6315 name: "StrayHelloRequest",
6316 config: Config{
6317 MaxVersion: VersionTLS12,
6318 Bugs: ProtocolBugs{
6319 SendHelloRequestBeforeEveryHandshakeMessage: true,
6320 },
6321 },
6322 })
6323 testCases = append(testCases, testCase{
6324 name: "StrayHelloRequest-Packed",
6325 config: Config{
6326 MaxVersion: VersionTLS12,
6327 Bugs: ProtocolBugs{
6328 PackHandshakeFlight: true,
6329 SendHelloRequestBeforeEveryHandshakeMessage: true,
6330 },
6331 },
6332 })
6333
David Benjamin12d2c482016-07-24 10:56:51 -04006334 // Test renegotiation works if HelloRequest and server Finished come in
6335 // the same record.
6336 testCases = append(testCases, testCase{
6337 name: "Renegotiate-Client-Packed",
6338 config: Config{
6339 MaxVersion: VersionTLS12,
6340 Bugs: ProtocolBugs{
6341 PackHandshakeFlight: true,
6342 PackHelloRequestWithFinished: true,
6343 },
6344 },
6345 renegotiate: 1,
6346 flags: []string{
6347 "-renegotiate-freely",
6348 "-expect-total-renegotiations", "1",
6349 },
6350 })
6351
David Benjamin397c8e62016-07-08 14:14:36 -07006352 // Renegotiation is forbidden in TLS 1.3.
6353 testCases = append(testCases, testCase{
6354 name: "Renegotiate-Client-TLS13",
6355 config: Config{
6356 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006357 Bugs: ProtocolBugs{
6358 SendHelloRequestBeforeEveryAppDataRecord: true,
6359 },
David Benjamin397c8e62016-07-08 14:14:36 -07006360 },
David Benjamin397c8e62016-07-08 14:14:36 -07006361 flags: []string{
6362 "-renegotiate-freely",
6363 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006364 shouldFail: true,
6365 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006366 })
6367
6368 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6369 testCases = append(testCases, testCase{
6370 name: "StrayHelloRequest-TLS13",
6371 config: Config{
6372 MaxVersion: VersionTLS13,
6373 Bugs: ProtocolBugs{
6374 SendHelloRequestBeforeEveryHandshakeMessage: true,
6375 },
6376 },
6377 shouldFail: true,
6378 expectedError: ":UNEXPECTED_MESSAGE:",
6379 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006380}
6381
David Benjamin5e961c12014-11-07 01:48:35 -05006382func addDTLSReplayTests() {
6383 // Test that sequence number replays are detected.
6384 testCases = append(testCases, testCase{
6385 protocol: dtls,
6386 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006387 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006388 replayWrites: true,
6389 })
6390
David Benjamin8e6db492015-07-25 18:29:23 -04006391 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006392 // than the retransmit window.
6393 testCases = append(testCases, testCase{
6394 protocol: dtls,
6395 name: "DTLS-Replay-LargeGaps",
6396 config: Config{
6397 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006398 SequenceNumberMapping: func(in uint64) uint64 {
6399 return in * 127
6400 },
David Benjamin5e961c12014-11-07 01:48:35 -05006401 },
6402 },
David Benjamin8e6db492015-07-25 18:29:23 -04006403 messageCount: 200,
6404 replayWrites: true,
6405 })
6406
6407 // Test the incoming sequence number changing non-monotonically.
6408 testCases = append(testCases, testCase{
6409 protocol: dtls,
6410 name: "DTLS-Replay-NonMonotonic",
6411 config: Config{
6412 Bugs: ProtocolBugs{
6413 SequenceNumberMapping: func(in uint64) uint64 {
6414 return in ^ 31
6415 },
6416 },
6417 },
6418 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006419 replayWrites: true,
6420 })
6421}
6422
Nick Harper60edffd2016-06-21 15:19:24 -07006423var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006424 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006425 id signatureAlgorithm
6426 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006427}{
Nick Harper60edffd2016-06-21 15:19:24 -07006428 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6429 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6430 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6431 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006432 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006433 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6434 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6435 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006436 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6437 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6438 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006439 // Tests for key types prior to TLS 1.2.
6440 {"RSA", 0, testCertRSA},
6441 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006442}
6443
Nick Harper60edffd2016-06-21 15:19:24 -07006444const fakeSigAlg1 signatureAlgorithm = 0x2a01
6445const fakeSigAlg2 signatureAlgorithm = 0xff01
6446
6447func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006448 // Not all ciphers involve a signature. Advertise a list which gives all
6449 // versions a signing cipher.
6450 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006451 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006452 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6453 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6454 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6455 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6456 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6457 }
6458
David Benjaminca3d5452016-07-14 12:51:01 -04006459 var allAlgorithms []signatureAlgorithm
6460 for _, alg := range testSignatureAlgorithms {
6461 if alg.id != 0 {
6462 allAlgorithms = append(allAlgorithms, alg.id)
6463 }
6464 }
6465
Nick Harper60edffd2016-06-21 15:19:24 -07006466 // Make sure each signature algorithm works. Include some fake values in
6467 // the list and ensure they're ignored.
6468 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006469 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006470 if (ver.version < VersionTLS12) != (alg.id == 0) {
6471 continue
6472 }
6473
6474 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6475 // or remove it in C.
6476 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006477 continue
6478 }
Nick Harper60edffd2016-06-21 15:19:24 -07006479
David Benjamin3ef76972016-10-17 17:59:54 -04006480 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006481 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006482 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006483 shouldSignFail = true
6484 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006485 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006486 // RSA-PKCS1 does not exist in TLS 1.3.
6487 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006488 shouldSignFail = true
6489 shouldVerifyFail = true
6490 }
6491
6492 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6493 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6494 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006495 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006496
6497 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006498 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006499 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006500 }
6501 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006502 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006503 }
David Benjamin000800a2014-11-14 01:43:59 -05006504
David Benjamin1fb125c2016-07-08 18:52:12 -07006505 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006506
David Benjamin7a41d372016-07-09 11:21:54 -07006507 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006508 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006509 config: Config{
6510 MaxVersion: ver.version,
6511 ClientAuth: RequireAnyClientCert,
6512 VerifySignatureAlgorithms: []signatureAlgorithm{
6513 fakeSigAlg1,
6514 alg.id,
6515 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006516 },
David Benjamin7a41d372016-07-09 11:21:54 -07006517 },
6518 flags: []string{
6519 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6520 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6521 "-enable-all-curves",
6522 },
David Benjamin3ef76972016-10-17 17:59:54 -04006523 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006524 expectedError: signError,
6525 expectedPeerSignatureAlgorithm: alg.id,
6526 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006527
David Benjamin7a41d372016-07-09 11:21:54 -07006528 testCases = append(testCases, testCase{
6529 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006530 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006531 config: Config{
6532 MaxVersion: ver.version,
6533 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6534 SignSignatureAlgorithms: []signatureAlgorithm{
6535 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006536 },
David Benjamin7a41d372016-07-09 11:21:54 -07006537 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006538 SkipECDSACurveCheck: shouldVerifyFail,
6539 IgnoreSignatureVersionChecks: shouldVerifyFail,
6540 // Some signature algorithms may not be advertised.
6541 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006542 },
David Benjamin7a41d372016-07-09 11:21:54 -07006543 },
6544 flags: []string{
6545 "-require-any-client-certificate",
6546 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6547 "-enable-all-curves",
6548 },
David Benjamin3ef76972016-10-17 17:59:54 -04006549 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006550 expectedError: verifyError,
6551 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006552
6553 testCases = append(testCases, testCase{
6554 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006555 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006556 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006557 MaxVersion: ver.version,
6558 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006559 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006560 fakeSigAlg1,
6561 alg.id,
6562 fakeSigAlg2,
6563 },
6564 },
6565 flags: []string{
6566 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6567 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6568 "-enable-all-curves",
6569 },
David Benjamin3ef76972016-10-17 17:59:54 -04006570 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006571 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006572 expectedPeerSignatureAlgorithm: alg.id,
6573 })
6574
6575 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006576 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006577 config: Config{
6578 MaxVersion: ver.version,
6579 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006580 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006581 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006582 alg.id,
6583 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006584 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006585 SkipECDSACurveCheck: shouldVerifyFail,
6586 IgnoreSignatureVersionChecks: shouldVerifyFail,
6587 // Some signature algorithms may not be advertised.
6588 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006589 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006590 },
6591 flags: []string{
6592 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6593 "-enable-all-curves",
6594 },
David Benjamin3ef76972016-10-17 17:59:54 -04006595 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006596 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006597 })
David Benjamin5208fd42016-07-13 21:43:25 -04006598
David Benjamin3ef76972016-10-17 17:59:54 -04006599 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006600 testCases = append(testCases, testCase{
6601 testType: serverTest,
6602 name: "ClientAuth-InvalidSignature" + suffix,
6603 config: Config{
6604 MaxVersion: ver.version,
6605 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6606 SignSignatureAlgorithms: []signatureAlgorithm{
6607 alg.id,
6608 },
6609 Bugs: ProtocolBugs{
6610 InvalidSignature: true,
6611 },
6612 },
6613 flags: []string{
6614 "-require-any-client-certificate",
6615 "-enable-all-curves",
6616 },
6617 shouldFail: true,
6618 expectedError: ":BAD_SIGNATURE:",
6619 })
6620
6621 testCases = append(testCases, testCase{
6622 name: "ServerAuth-InvalidSignature" + suffix,
6623 config: Config{
6624 MaxVersion: ver.version,
6625 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6626 CipherSuites: signingCiphers,
6627 SignSignatureAlgorithms: []signatureAlgorithm{
6628 alg.id,
6629 },
6630 Bugs: ProtocolBugs{
6631 InvalidSignature: true,
6632 },
6633 },
6634 flags: []string{"-enable-all-curves"},
6635 shouldFail: true,
6636 expectedError: ":BAD_SIGNATURE:",
6637 })
6638 }
David Benjaminca3d5452016-07-14 12:51:01 -04006639
David Benjamin3ef76972016-10-17 17:59:54 -04006640 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006641 testCases = append(testCases, testCase{
6642 name: "ClientAuth-Sign-Negotiate" + suffix,
6643 config: Config{
6644 MaxVersion: ver.version,
6645 ClientAuth: RequireAnyClientCert,
6646 VerifySignatureAlgorithms: allAlgorithms,
6647 },
6648 flags: []string{
6649 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6650 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6651 "-enable-all-curves",
6652 "-signing-prefs", strconv.Itoa(int(alg.id)),
6653 },
6654 expectedPeerSignatureAlgorithm: alg.id,
6655 })
6656
6657 testCases = append(testCases, testCase{
6658 testType: serverTest,
6659 name: "ServerAuth-Sign-Negotiate" + suffix,
6660 config: Config{
6661 MaxVersion: ver.version,
6662 CipherSuites: signingCiphers,
6663 VerifySignatureAlgorithms: allAlgorithms,
6664 },
6665 flags: []string{
6666 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6667 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6668 "-enable-all-curves",
6669 "-signing-prefs", strconv.Itoa(int(alg.id)),
6670 },
6671 expectedPeerSignatureAlgorithm: alg.id,
6672 })
6673 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006674 }
David Benjamin000800a2014-11-14 01:43:59 -05006675 }
6676
Nick Harper60edffd2016-06-21 15:19:24 -07006677 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006678 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006679 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006680 config: Config{
6681 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006682 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006683 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006684 signatureECDSAWithP521AndSHA512,
6685 signatureRSAPKCS1WithSHA384,
6686 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006687 },
6688 },
6689 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006690 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6691 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006692 },
Nick Harper60edffd2016-06-21 15:19:24 -07006693 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006694 })
6695
6696 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006697 name: "ClientAuth-SignatureType-TLS13",
6698 config: Config{
6699 ClientAuth: RequireAnyClientCert,
6700 MaxVersion: VersionTLS13,
6701 VerifySignatureAlgorithms: []signatureAlgorithm{
6702 signatureECDSAWithP521AndSHA512,
6703 signatureRSAPKCS1WithSHA384,
6704 signatureRSAPSSWithSHA384,
6705 signatureECDSAWithSHA1,
6706 },
6707 },
6708 flags: []string{
6709 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6710 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6711 },
6712 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6713 })
6714
6715 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006716 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006717 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006719 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006720 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006721 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006722 signatureECDSAWithP521AndSHA512,
6723 signatureRSAPKCS1WithSHA384,
6724 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006725 },
6726 },
Nick Harper60edffd2016-06-21 15:19:24 -07006727 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006728 })
6729
Steven Valdez143e8b32016-07-11 13:19:03 -04006730 testCases = append(testCases, testCase{
6731 testType: serverTest,
6732 name: "ServerAuth-SignatureType-TLS13",
6733 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006734 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006735 VerifySignatureAlgorithms: []signatureAlgorithm{
6736 signatureECDSAWithP521AndSHA512,
6737 signatureRSAPKCS1WithSHA384,
6738 signatureRSAPSSWithSHA384,
6739 signatureECDSAWithSHA1,
6740 },
6741 },
6742 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6743 })
6744
David Benjamina95e9f32016-07-08 16:28:04 -07006745 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006746 testCases = append(testCases, testCase{
6747 testType: serverTest,
6748 name: "Verify-ClientAuth-SignatureType",
6749 config: Config{
6750 MaxVersion: VersionTLS12,
6751 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006752 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006753 signatureRSAPKCS1WithSHA256,
6754 },
6755 Bugs: ProtocolBugs{
6756 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6757 },
6758 },
6759 flags: []string{
6760 "-require-any-client-certificate",
6761 },
6762 shouldFail: true,
6763 expectedError: ":WRONG_SIGNATURE_TYPE:",
6764 })
6765
6766 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006767 testType: serverTest,
6768 name: "Verify-ClientAuth-SignatureType-TLS13",
6769 config: Config{
6770 MaxVersion: VersionTLS13,
6771 Certificates: []Certificate{rsaCertificate},
6772 SignSignatureAlgorithms: []signatureAlgorithm{
6773 signatureRSAPSSWithSHA256,
6774 },
6775 Bugs: ProtocolBugs{
6776 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6777 },
6778 },
6779 flags: []string{
6780 "-require-any-client-certificate",
6781 },
6782 shouldFail: true,
6783 expectedError: ":WRONG_SIGNATURE_TYPE:",
6784 })
6785
6786 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006787 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006788 config: Config{
6789 MaxVersion: VersionTLS12,
6790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006791 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006792 signatureRSAPKCS1WithSHA256,
6793 },
6794 Bugs: ProtocolBugs{
6795 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6796 },
6797 },
6798 shouldFail: true,
6799 expectedError: ":WRONG_SIGNATURE_TYPE:",
6800 })
6801
Steven Valdez143e8b32016-07-11 13:19:03 -04006802 testCases = append(testCases, testCase{
6803 name: "Verify-ServerAuth-SignatureType-TLS13",
6804 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006805 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006806 SignSignatureAlgorithms: []signatureAlgorithm{
6807 signatureRSAPSSWithSHA256,
6808 },
6809 Bugs: ProtocolBugs{
6810 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6811 },
6812 },
6813 shouldFail: true,
6814 expectedError: ":WRONG_SIGNATURE_TYPE:",
6815 })
6816
David Benjamin51dd7d62016-07-08 16:07:01 -07006817 // Test that, if the list is missing, the peer falls back to SHA-1 in
6818 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006819 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006820 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006822 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006823 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006824 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006825 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006826 },
6827 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006828 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006829 },
6830 },
6831 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006832 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6833 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006834 },
6835 })
6836
6837 testCases = append(testCases, testCase{
6838 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006839 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006840 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006841 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006842 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006843 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006844 },
6845 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006846 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006847 },
6848 },
David Benjaminee32bea2016-08-17 13:36:44 -04006849 flags: []string{
6850 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6851 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6852 },
6853 })
6854
6855 testCases = append(testCases, testCase{
6856 name: "ClientAuth-SHA1-Fallback-ECDSA",
6857 config: Config{
6858 MaxVersion: VersionTLS12,
6859 ClientAuth: RequireAnyClientCert,
6860 VerifySignatureAlgorithms: []signatureAlgorithm{
6861 signatureECDSAWithSHA1,
6862 },
6863 Bugs: ProtocolBugs{
6864 NoSignatureAlgorithms: true,
6865 },
6866 },
6867 flags: []string{
6868 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6869 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6870 },
6871 })
6872
6873 testCases = append(testCases, testCase{
6874 testType: serverTest,
6875 name: "ServerAuth-SHA1-Fallback-ECDSA",
6876 config: Config{
6877 MaxVersion: VersionTLS12,
6878 VerifySignatureAlgorithms: []signatureAlgorithm{
6879 signatureECDSAWithSHA1,
6880 },
6881 Bugs: ProtocolBugs{
6882 NoSignatureAlgorithms: true,
6883 },
6884 },
6885 flags: []string{
6886 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6887 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6888 },
David Benjamin000800a2014-11-14 01:43:59 -05006889 })
David Benjamin72dc7832015-03-16 17:49:43 -04006890
David Benjamin51dd7d62016-07-08 16:07:01 -07006891 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006892 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006893 config: Config{
6894 MaxVersion: VersionTLS13,
6895 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006896 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006897 signatureRSAPKCS1WithSHA1,
6898 },
6899 Bugs: ProtocolBugs{
6900 NoSignatureAlgorithms: true,
6901 },
6902 },
6903 flags: []string{
6904 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6905 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6906 },
David Benjamin48901652016-08-01 12:12:47 -04006907 shouldFail: true,
6908 // An empty CertificateRequest signature algorithm list is a
6909 // syntax error in TLS 1.3.
6910 expectedError: ":DECODE_ERROR:",
6911 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006912 })
6913
6914 testCases = append(testCases, testCase{
6915 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006916 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006917 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006918 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006919 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006920 signatureRSAPKCS1WithSHA1,
6921 },
6922 Bugs: ProtocolBugs{
6923 NoSignatureAlgorithms: true,
6924 },
6925 },
6926 shouldFail: true,
6927 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6928 })
6929
David Benjaminb62d2872016-07-18 14:55:02 +02006930 // Test that hash preferences are enforced. BoringSSL does not implement
6931 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006932 testCases = append(testCases, testCase{
6933 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006934 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006936 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006937 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006938 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006939 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006940 },
6941 Bugs: ProtocolBugs{
6942 IgnorePeerSignatureAlgorithmPreferences: true,
6943 },
6944 },
6945 flags: []string{"-require-any-client-certificate"},
6946 shouldFail: true,
6947 expectedError: ":WRONG_SIGNATURE_TYPE:",
6948 })
6949
6950 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006951 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006953 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006955 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006956 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006957 },
6958 Bugs: ProtocolBugs{
6959 IgnorePeerSignatureAlgorithmPreferences: true,
6960 },
6961 },
6962 shouldFail: true,
6963 expectedError: ":WRONG_SIGNATURE_TYPE:",
6964 })
David Benjaminb62d2872016-07-18 14:55:02 +02006965 testCases = append(testCases, testCase{
6966 testType: serverTest,
6967 name: "ClientAuth-Enforced-TLS13",
6968 config: Config{
6969 MaxVersion: VersionTLS13,
6970 Certificates: []Certificate{rsaCertificate},
6971 SignSignatureAlgorithms: []signatureAlgorithm{
6972 signatureRSAPKCS1WithMD5,
6973 },
6974 Bugs: ProtocolBugs{
6975 IgnorePeerSignatureAlgorithmPreferences: true,
6976 IgnoreSignatureVersionChecks: true,
6977 },
6978 },
6979 flags: []string{"-require-any-client-certificate"},
6980 shouldFail: true,
6981 expectedError: ":WRONG_SIGNATURE_TYPE:",
6982 })
6983
6984 testCases = append(testCases, testCase{
6985 name: "ServerAuth-Enforced-TLS13",
6986 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006987 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006988 SignSignatureAlgorithms: []signatureAlgorithm{
6989 signatureRSAPKCS1WithMD5,
6990 },
6991 Bugs: ProtocolBugs{
6992 IgnorePeerSignatureAlgorithmPreferences: true,
6993 IgnoreSignatureVersionChecks: true,
6994 },
6995 },
6996 shouldFail: true,
6997 expectedError: ":WRONG_SIGNATURE_TYPE:",
6998 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006999
7000 // Test that the agreed upon digest respects the client preferences and
7001 // the server digests.
7002 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007003 name: "NoCommonAlgorithms-Digests",
7004 config: Config{
7005 MaxVersion: VersionTLS12,
7006 ClientAuth: RequireAnyClientCert,
7007 VerifySignatureAlgorithms: []signatureAlgorithm{
7008 signatureRSAPKCS1WithSHA512,
7009 signatureRSAPKCS1WithSHA1,
7010 },
7011 },
7012 flags: []string{
7013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7015 "-digest-prefs", "SHA256",
7016 },
7017 shouldFail: true,
7018 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7019 })
7020 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007021 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007022 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007023 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007024 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007025 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007026 signatureRSAPKCS1WithSHA512,
7027 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007028 },
7029 },
7030 flags: []string{
7031 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7032 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007033 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007034 },
David Benjaminca3d5452016-07-14 12:51:01 -04007035 shouldFail: true,
7036 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7037 })
7038 testCases = append(testCases, testCase{
7039 name: "NoCommonAlgorithms-TLS13",
7040 config: Config{
7041 MaxVersion: VersionTLS13,
7042 ClientAuth: RequireAnyClientCert,
7043 VerifySignatureAlgorithms: []signatureAlgorithm{
7044 signatureRSAPSSWithSHA512,
7045 signatureRSAPSSWithSHA384,
7046 },
7047 },
7048 flags: []string{
7049 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7050 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7051 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7052 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007053 shouldFail: true,
7054 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007055 })
7056 testCases = append(testCases, testCase{
7057 name: "Agree-Digest-SHA256",
7058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007059 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007060 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007061 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007062 signatureRSAPKCS1WithSHA1,
7063 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007064 },
7065 },
7066 flags: []string{
7067 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7068 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007069 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007070 },
Nick Harper60edffd2016-06-21 15:19:24 -07007071 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007072 })
7073 testCases = append(testCases, testCase{
7074 name: "Agree-Digest-SHA1",
7075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007076 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007077 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007078 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007079 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007080 },
7081 },
7082 flags: []string{
7083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007085 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007086 },
Nick Harper60edffd2016-06-21 15:19:24 -07007087 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007088 })
7089 testCases = append(testCases, testCase{
7090 name: "Agree-Digest-Default",
7091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007093 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007094 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007095 signatureRSAPKCS1WithSHA256,
7096 signatureECDSAWithP256AndSHA256,
7097 signatureRSAPKCS1WithSHA1,
7098 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007099 },
7100 },
7101 flags: []string{
7102 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7103 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7104 },
Nick Harper60edffd2016-06-21 15:19:24 -07007105 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007106 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007107
David Benjaminca3d5452016-07-14 12:51:01 -04007108 // Test that the signing preference list may include extra algorithms
7109 // without negotiation problems.
7110 testCases = append(testCases, testCase{
7111 testType: serverTest,
7112 name: "FilterExtraAlgorithms",
7113 config: Config{
7114 MaxVersion: VersionTLS12,
7115 VerifySignatureAlgorithms: []signatureAlgorithm{
7116 signatureRSAPKCS1WithSHA256,
7117 },
7118 },
7119 flags: []string{
7120 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7121 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7122 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7123 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7124 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7125 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7126 },
7127 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7128 })
7129
David Benjamin4c3ddf72016-06-29 18:13:53 -04007130 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7131 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007132 testCases = append(testCases, testCase{
7133 name: "CheckLeafCurve",
7134 config: Config{
7135 MaxVersion: VersionTLS12,
7136 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007137 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007138 },
7139 flags: []string{"-p384-only"},
7140 shouldFail: true,
7141 expectedError: ":BAD_ECC_CERT:",
7142 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007143
7144 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7145 testCases = append(testCases, testCase{
7146 name: "CheckLeafCurve-TLS13",
7147 config: Config{
7148 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007149 Certificates: []Certificate{ecdsaP256Certificate},
7150 },
7151 flags: []string{"-p384-only"},
7152 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007153
7154 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7155 testCases = append(testCases, testCase{
7156 name: "ECDSACurveMismatch-Verify-TLS12",
7157 config: Config{
7158 MaxVersion: VersionTLS12,
7159 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7160 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007161 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007162 signatureECDSAWithP384AndSHA384,
7163 },
7164 },
7165 })
7166
7167 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7168 testCases = append(testCases, testCase{
7169 name: "ECDSACurveMismatch-Verify-TLS13",
7170 config: Config{
7171 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007172 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007173 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007174 signatureECDSAWithP384AndSHA384,
7175 },
7176 Bugs: ProtocolBugs{
7177 SkipECDSACurveCheck: true,
7178 },
7179 },
7180 shouldFail: true,
7181 expectedError: ":WRONG_SIGNATURE_TYPE:",
7182 })
7183
7184 // Signature algorithm selection in TLS 1.3 should take the curve into
7185 // account.
7186 testCases = append(testCases, testCase{
7187 testType: serverTest,
7188 name: "ECDSACurveMismatch-Sign-TLS13",
7189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007190 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007191 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007192 signatureECDSAWithP384AndSHA384,
7193 signatureECDSAWithP256AndSHA256,
7194 },
7195 },
7196 flags: []string{
7197 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7198 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7199 },
7200 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7201 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007202
7203 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7204 // server does not attempt to sign in that case.
7205 testCases = append(testCases, testCase{
7206 testType: serverTest,
7207 name: "RSA-PSS-Large",
7208 config: Config{
7209 MaxVersion: VersionTLS13,
7210 VerifySignatureAlgorithms: []signatureAlgorithm{
7211 signatureRSAPSSWithSHA512,
7212 },
7213 },
7214 flags: []string{
7215 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7216 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7217 },
7218 shouldFail: true,
7219 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7220 })
David Benjamin57e929f2016-08-30 00:30:38 -04007221
7222 // Test that RSA-PSS is enabled by default for TLS 1.2.
7223 testCases = append(testCases, testCase{
7224 testType: clientTest,
7225 name: "RSA-PSS-Default-Verify",
7226 config: Config{
7227 MaxVersion: VersionTLS12,
7228 SignSignatureAlgorithms: []signatureAlgorithm{
7229 signatureRSAPSSWithSHA256,
7230 },
7231 },
7232 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7233 })
7234
7235 testCases = append(testCases, testCase{
7236 testType: serverTest,
7237 name: "RSA-PSS-Default-Sign",
7238 config: Config{
7239 MaxVersion: VersionTLS12,
7240 VerifySignatureAlgorithms: []signatureAlgorithm{
7241 signatureRSAPSSWithSHA256,
7242 },
7243 },
7244 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7245 })
David Benjamin000800a2014-11-14 01:43:59 -05007246}
7247
David Benjamin83f90402015-01-27 01:09:43 -05007248// timeouts is the retransmit schedule for BoringSSL. It doubles and
7249// caps at 60 seconds. On the 13th timeout, it gives up.
7250var timeouts = []time.Duration{
7251 1 * time.Second,
7252 2 * time.Second,
7253 4 * time.Second,
7254 8 * time.Second,
7255 16 * time.Second,
7256 32 * time.Second,
7257 60 * time.Second,
7258 60 * time.Second,
7259 60 * time.Second,
7260 60 * time.Second,
7261 60 * time.Second,
7262 60 * time.Second,
7263 60 * time.Second,
7264}
7265
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007266// shortTimeouts is an alternate set of timeouts which would occur if the
7267// initial timeout duration was set to 250ms.
7268var shortTimeouts = []time.Duration{
7269 250 * time.Millisecond,
7270 500 * time.Millisecond,
7271 1 * time.Second,
7272 2 * time.Second,
7273 4 * time.Second,
7274 8 * time.Second,
7275 16 * time.Second,
7276 32 * time.Second,
7277 60 * time.Second,
7278 60 * time.Second,
7279 60 * time.Second,
7280 60 * time.Second,
7281 60 * time.Second,
7282}
7283
David Benjamin83f90402015-01-27 01:09:43 -05007284func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007285 // These tests work by coordinating some behavior on both the shim and
7286 // the runner.
7287 //
7288 // TimeoutSchedule configures the runner to send a series of timeout
7289 // opcodes to the shim (see packetAdaptor) immediately before reading
7290 // each peer handshake flight N. The timeout opcode both simulates a
7291 // timeout in the shim and acts as a synchronization point to help the
7292 // runner bracket each handshake flight.
7293 //
7294 // We assume the shim does not read from the channel eagerly. It must
7295 // first wait until it has sent flight N and is ready to receive
7296 // handshake flight N+1. At this point, it will process the timeout
7297 // opcode. It must then immediately respond with a timeout ACK and act
7298 // as if the shim was idle for the specified amount of time.
7299 //
7300 // The runner then drops all packets received before the ACK and
7301 // continues waiting for flight N. This ordering results in one attempt
7302 // at sending flight N to be dropped. For the test to complete, the
7303 // shim must send flight N again, testing that the shim implements DTLS
7304 // retransmit on a timeout.
7305
Steven Valdez143e8b32016-07-11 13:19:03 -04007306 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007307 // likely be more epochs to cross and the final message's retransmit may
7308 // be more complex.
7309
David Benjamin585d7a42016-06-02 14:58:00 -04007310 for _, async := range []bool{true, false} {
7311 var tests []testCase
7312
7313 // Test that this is indeed the timeout schedule. Stress all
7314 // four patterns of handshake.
7315 for i := 1; i < len(timeouts); i++ {
7316 number := strconv.Itoa(i)
7317 tests = append(tests, testCase{
7318 protocol: dtls,
7319 name: "DTLS-Retransmit-Client-" + number,
7320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007321 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007322 Bugs: ProtocolBugs{
7323 TimeoutSchedule: timeouts[:i],
7324 },
7325 },
7326 resumeSession: true,
7327 })
7328 tests = append(tests, testCase{
7329 protocol: dtls,
7330 testType: serverTest,
7331 name: "DTLS-Retransmit-Server-" + number,
7332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007333 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007334 Bugs: ProtocolBugs{
7335 TimeoutSchedule: timeouts[:i],
7336 },
7337 },
7338 resumeSession: true,
7339 })
7340 }
7341
7342 // Test that exceeding the timeout schedule hits a read
7343 // timeout.
7344 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007345 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007346 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007349 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007350 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007351 },
7352 },
7353 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007354 shouldFail: true,
7355 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007356 })
David Benjamin585d7a42016-06-02 14:58:00 -04007357
7358 if async {
7359 // Test that timeout handling has a fudge factor, due to API
7360 // problems.
7361 tests = append(tests, testCase{
7362 protocol: dtls,
7363 name: "DTLS-Retransmit-Fudge",
7364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007365 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007366 Bugs: ProtocolBugs{
7367 TimeoutSchedule: []time.Duration{
7368 timeouts[0] - 10*time.Millisecond,
7369 },
7370 },
7371 },
7372 resumeSession: true,
7373 })
7374 }
7375
7376 // Test that the final Finished retransmitting isn't
7377 // duplicated if the peer badly fragments everything.
7378 tests = append(tests, testCase{
7379 testType: serverTest,
7380 protocol: dtls,
7381 name: "DTLS-Retransmit-Fragmented",
7382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007383 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007384 Bugs: ProtocolBugs{
7385 TimeoutSchedule: []time.Duration{timeouts[0]},
7386 MaxHandshakeRecordLength: 2,
7387 },
7388 },
7389 })
7390
7391 // Test the timeout schedule when a shorter initial timeout duration is set.
7392 tests = append(tests, testCase{
7393 protocol: dtls,
7394 name: "DTLS-Retransmit-Short-Client",
7395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007396 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007397 Bugs: ProtocolBugs{
7398 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7399 },
7400 },
7401 resumeSession: true,
7402 flags: []string{"-initial-timeout-duration-ms", "250"},
7403 })
7404 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007405 protocol: dtls,
7406 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007407 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007409 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007410 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007411 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007412 },
7413 },
7414 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007415 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007416 })
David Benjamin585d7a42016-06-02 14:58:00 -04007417
7418 for _, test := range tests {
7419 if async {
7420 test.name += "-Async"
7421 test.flags = append(test.flags, "-async")
7422 }
7423
7424 testCases = append(testCases, test)
7425 }
David Benjamin83f90402015-01-27 01:09:43 -05007426 }
David Benjamin83f90402015-01-27 01:09:43 -05007427}
7428
David Benjaminc565ebb2015-04-03 04:06:36 -04007429func addExportKeyingMaterialTests() {
7430 for _, vers := range tlsVersions {
7431 if vers.version == VersionSSL30 {
7432 continue
7433 }
7434 testCases = append(testCases, testCase{
7435 name: "ExportKeyingMaterial-" + vers.name,
7436 config: Config{
7437 MaxVersion: vers.version,
7438 },
7439 exportKeyingMaterial: 1024,
7440 exportLabel: "label",
7441 exportContext: "context",
7442 useExportContext: true,
7443 })
7444 testCases = append(testCases, testCase{
7445 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7446 config: Config{
7447 MaxVersion: vers.version,
7448 },
7449 exportKeyingMaterial: 1024,
7450 })
7451 testCases = append(testCases, testCase{
7452 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7453 config: Config{
7454 MaxVersion: vers.version,
7455 },
7456 exportKeyingMaterial: 1024,
7457 useExportContext: true,
7458 })
7459 testCases = append(testCases, testCase{
7460 name: "ExportKeyingMaterial-Small-" + vers.name,
7461 config: Config{
7462 MaxVersion: vers.version,
7463 },
7464 exportKeyingMaterial: 1,
7465 exportLabel: "label",
7466 exportContext: "context",
7467 useExportContext: true,
7468 })
7469 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007470
David Benjaminc565ebb2015-04-03 04:06:36 -04007471 testCases = append(testCases, testCase{
7472 name: "ExportKeyingMaterial-SSL3",
7473 config: Config{
7474 MaxVersion: VersionSSL30,
7475 },
7476 exportKeyingMaterial: 1024,
7477 exportLabel: "label",
7478 exportContext: "context",
7479 useExportContext: true,
7480 shouldFail: true,
7481 expectedError: "failed to export keying material",
7482 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007483
7484 // Exporters work during a False Start.
7485 testCases = append(testCases, testCase{
7486 name: "ExportKeyingMaterial-FalseStart",
7487 config: Config{
7488 MaxVersion: VersionTLS12,
7489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7490 NextProtos: []string{"foo"},
7491 Bugs: ProtocolBugs{
7492 ExpectFalseStart: true,
7493 },
7494 },
7495 flags: []string{
7496 "-false-start",
7497 "-advertise-alpn", "\x03foo",
7498 },
7499 shimWritesFirst: true,
7500 exportKeyingMaterial: 1024,
7501 exportLabel: "label",
7502 exportContext: "context",
7503 useExportContext: true,
7504 })
7505
7506 // Exporters do not work in the middle of a renegotiation. Test this by
7507 // triggering the exporter after every SSL_read call and configuring the
7508 // shim to run asynchronously.
7509 testCases = append(testCases, testCase{
7510 name: "ExportKeyingMaterial-Renegotiate",
7511 config: Config{
7512 MaxVersion: VersionTLS12,
7513 },
7514 renegotiate: 1,
7515 flags: []string{
7516 "-async",
7517 "-use-exporter-between-reads",
7518 "-renegotiate-freely",
7519 "-expect-total-renegotiations", "1",
7520 },
7521 shouldFail: true,
7522 expectedError: "failed to export keying material",
7523 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007524}
7525
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007526func addTLSUniqueTests() {
7527 for _, isClient := range []bool{false, true} {
7528 for _, isResumption := range []bool{false, true} {
7529 for _, hasEMS := range []bool{false, true} {
7530 var suffix string
7531 if isResumption {
7532 suffix = "Resume-"
7533 } else {
7534 suffix = "Full-"
7535 }
7536
7537 if hasEMS {
7538 suffix += "EMS-"
7539 } else {
7540 suffix += "NoEMS-"
7541 }
7542
7543 if isClient {
7544 suffix += "Client"
7545 } else {
7546 suffix += "Server"
7547 }
7548
7549 test := testCase{
7550 name: "TLSUnique-" + suffix,
7551 testTLSUnique: true,
7552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007553 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007554 Bugs: ProtocolBugs{
7555 NoExtendedMasterSecret: !hasEMS,
7556 },
7557 },
7558 }
7559
7560 if isResumption {
7561 test.resumeSession = true
7562 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007563 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007564 Bugs: ProtocolBugs{
7565 NoExtendedMasterSecret: !hasEMS,
7566 },
7567 }
7568 }
7569
7570 if isResumption && !hasEMS {
7571 test.shouldFail = true
7572 test.expectedError = "failed to get tls-unique"
7573 }
7574
7575 testCases = append(testCases, test)
7576 }
7577 }
7578 }
7579}
7580
Adam Langley09505632015-07-30 18:10:13 -07007581func addCustomExtensionTests() {
7582 expectedContents := "custom extension"
7583 emptyString := ""
7584
7585 for _, isClient := range []bool{false, true} {
7586 suffix := "Server"
7587 flag := "-enable-server-custom-extension"
7588 testType := serverTest
7589 if isClient {
7590 suffix = "Client"
7591 flag = "-enable-client-custom-extension"
7592 testType = clientTest
7593 }
7594
7595 testCases = append(testCases, testCase{
7596 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007597 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007598 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007599 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007600 Bugs: ProtocolBugs{
7601 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007602 ExpectedCustomExtension: &expectedContents,
7603 },
7604 },
7605 flags: []string{flag},
7606 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007607 testCases = append(testCases, testCase{
7608 testType: testType,
7609 name: "CustomExtensions-" + suffix + "-TLS13",
7610 config: Config{
7611 MaxVersion: VersionTLS13,
7612 Bugs: ProtocolBugs{
7613 CustomExtension: expectedContents,
7614 ExpectedCustomExtension: &expectedContents,
7615 },
7616 },
7617 flags: []string{flag},
7618 })
Adam Langley09505632015-07-30 18:10:13 -07007619
7620 // If the parse callback fails, the handshake should also fail.
7621 testCases = append(testCases, testCase{
7622 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007623 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007625 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007626 Bugs: ProtocolBugs{
7627 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007628 ExpectedCustomExtension: &expectedContents,
7629 },
7630 },
David Benjamin399e7c92015-07-30 23:01:27 -04007631 flags: []string{flag},
7632 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007633 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7634 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007635 testCases = append(testCases, testCase{
7636 testType: testType,
7637 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7638 config: Config{
7639 MaxVersion: VersionTLS13,
7640 Bugs: ProtocolBugs{
7641 CustomExtension: expectedContents + "foo",
7642 ExpectedCustomExtension: &expectedContents,
7643 },
7644 },
7645 flags: []string{flag},
7646 shouldFail: true,
7647 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7648 })
Adam Langley09505632015-07-30 18:10:13 -07007649
7650 // If the add callback fails, the handshake should also fail.
7651 testCases = append(testCases, testCase{
7652 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007653 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007654 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007655 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007656 Bugs: ProtocolBugs{
7657 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007658 ExpectedCustomExtension: &expectedContents,
7659 },
7660 },
David Benjamin399e7c92015-07-30 23:01:27 -04007661 flags: []string{flag, "-custom-extension-fail-add"},
7662 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007663 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7664 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007665 testCases = append(testCases, testCase{
7666 testType: testType,
7667 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7668 config: Config{
7669 MaxVersion: VersionTLS13,
7670 Bugs: ProtocolBugs{
7671 CustomExtension: expectedContents,
7672 ExpectedCustomExtension: &expectedContents,
7673 },
7674 },
7675 flags: []string{flag, "-custom-extension-fail-add"},
7676 shouldFail: true,
7677 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7678 })
Adam Langley09505632015-07-30 18:10:13 -07007679
7680 // If the add callback returns zero, no extension should be
7681 // added.
7682 skipCustomExtension := expectedContents
7683 if isClient {
7684 // For the case where the client skips sending the
7685 // custom extension, the server must not “echo” it.
7686 skipCustomExtension = ""
7687 }
7688 testCases = append(testCases, testCase{
7689 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007690 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007691 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007692 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007693 Bugs: ProtocolBugs{
7694 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007695 ExpectedCustomExtension: &emptyString,
7696 },
7697 },
7698 flags: []string{flag, "-custom-extension-skip"},
7699 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007700 testCases = append(testCases, testCase{
7701 testType: testType,
7702 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7703 config: Config{
7704 MaxVersion: VersionTLS13,
7705 Bugs: ProtocolBugs{
7706 CustomExtension: skipCustomExtension,
7707 ExpectedCustomExtension: &emptyString,
7708 },
7709 },
7710 flags: []string{flag, "-custom-extension-skip"},
7711 })
Adam Langley09505632015-07-30 18:10:13 -07007712 }
7713
7714 // The custom extension add callback should not be called if the client
7715 // doesn't send the extension.
7716 testCases = append(testCases, testCase{
7717 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007718 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007720 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007721 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007722 ExpectedCustomExtension: &emptyString,
7723 },
7724 },
7725 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7726 })
Adam Langley2deb9842015-08-07 11:15:37 -07007727
Steven Valdez143e8b32016-07-11 13:19:03 -04007728 testCases = append(testCases, testCase{
7729 testType: serverTest,
7730 name: "CustomExtensions-NotCalled-Server-TLS13",
7731 config: Config{
7732 MaxVersion: VersionTLS13,
7733 Bugs: ProtocolBugs{
7734 ExpectedCustomExtension: &emptyString,
7735 },
7736 },
7737 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7738 })
7739
Adam Langley2deb9842015-08-07 11:15:37 -07007740 // Test an unknown extension from the server.
7741 testCases = append(testCases, testCase{
7742 testType: clientTest,
7743 name: "UnknownExtension-Client",
7744 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007745 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007746 Bugs: ProtocolBugs{
7747 CustomExtension: expectedContents,
7748 },
7749 },
David Benjamin0c40a962016-08-01 12:05:50 -04007750 shouldFail: true,
7751 expectedError: ":UNEXPECTED_EXTENSION:",
7752 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007753 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007754 testCases = append(testCases, testCase{
7755 testType: clientTest,
7756 name: "UnknownExtension-Client-TLS13",
7757 config: Config{
7758 MaxVersion: VersionTLS13,
7759 Bugs: ProtocolBugs{
7760 CustomExtension: expectedContents,
7761 },
7762 },
David Benjamin0c40a962016-08-01 12:05:50 -04007763 shouldFail: true,
7764 expectedError: ":UNEXPECTED_EXTENSION:",
7765 expectedLocalError: "remote error: unsupported extension",
7766 })
David Benjamin490469f2016-10-05 22:44:38 -04007767 testCases = append(testCases, testCase{
7768 testType: clientTest,
7769 name: "UnknownUnencryptedExtension-Client-TLS13",
7770 config: Config{
7771 MaxVersion: VersionTLS13,
7772 Bugs: ProtocolBugs{
7773 CustomUnencryptedExtension: expectedContents,
7774 },
7775 },
7776 shouldFail: true,
7777 expectedError: ":UNEXPECTED_EXTENSION:",
7778 // The shim must send an alert, but alerts at this point do not
7779 // get successfully decrypted by the runner.
7780 expectedLocalError: "local error: bad record MAC",
7781 })
7782 testCases = append(testCases, testCase{
7783 testType: clientTest,
7784 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7785 config: Config{
7786 MaxVersion: VersionTLS13,
7787 Bugs: ProtocolBugs{
7788 SendUnencryptedALPN: "foo",
7789 },
7790 },
7791 flags: []string{
7792 "-advertise-alpn", "\x03foo\x03bar",
7793 },
7794 shouldFail: true,
7795 expectedError: ":UNEXPECTED_EXTENSION:",
7796 // The shim must send an alert, but alerts at this point do not
7797 // get successfully decrypted by the runner.
7798 expectedLocalError: "local error: bad record MAC",
7799 })
David Benjamin0c40a962016-08-01 12:05:50 -04007800
7801 // Test a known but unoffered extension from the server.
7802 testCases = append(testCases, testCase{
7803 testType: clientTest,
7804 name: "UnofferedExtension-Client",
7805 config: Config{
7806 MaxVersion: VersionTLS12,
7807 Bugs: ProtocolBugs{
7808 SendALPN: "alpn",
7809 },
7810 },
7811 shouldFail: true,
7812 expectedError: ":UNEXPECTED_EXTENSION:",
7813 expectedLocalError: "remote error: unsupported extension",
7814 })
7815 testCases = append(testCases, testCase{
7816 testType: clientTest,
7817 name: "UnofferedExtension-Client-TLS13",
7818 config: Config{
7819 MaxVersion: VersionTLS13,
7820 Bugs: ProtocolBugs{
7821 SendALPN: "alpn",
7822 },
7823 },
7824 shouldFail: true,
7825 expectedError: ":UNEXPECTED_EXTENSION:",
7826 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007827 })
Adam Langley09505632015-07-30 18:10:13 -07007828}
7829
David Benjaminb36a3952015-12-01 18:53:13 -05007830func addRSAClientKeyExchangeTests() {
7831 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7832 testCases = append(testCases, testCase{
7833 testType: serverTest,
7834 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7835 config: Config{
7836 // Ensure the ClientHello version and final
7837 // version are different, to detect if the
7838 // server uses the wrong one.
7839 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007840 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007841 Bugs: ProtocolBugs{
7842 BadRSAClientKeyExchange: bad,
7843 },
7844 },
7845 shouldFail: true,
7846 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7847 })
7848 }
David Benjamine63d9d72016-09-19 18:27:34 -04007849
7850 // The server must compare whatever was in ClientHello.version for the
7851 // RSA premaster.
7852 testCases = append(testCases, testCase{
7853 testType: serverTest,
7854 name: "SendClientVersion-RSA",
7855 config: Config{
7856 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7857 Bugs: ProtocolBugs{
7858 SendClientVersion: 0x1234,
7859 },
7860 },
7861 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7862 })
David Benjaminb36a3952015-12-01 18:53:13 -05007863}
7864
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007865var testCurves = []struct {
7866 name string
7867 id CurveID
7868}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007869 {"P-256", CurveP256},
7870 {"P-384", CurveP384},
7871 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007872 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007873}
7874
Steven Valdez5440fe02016-07-18 12:40:30 -04007875const bogusCurve = 0x1234
7876
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007877func addCurveTests() {
7878 for _, curve := range testCurves {
7879 testCases = append(testCases, testCase{
7880 name: "CurveTest-Client-" + curve.name,
7881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007882 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007883 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7884 CurvePreferences: []CurveID{curve.id},
7885 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007886 flags: []string{
7887 "-enable-all-curves",
7888 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7889 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007890 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007891 })
7892 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007893 name: "CurveTest-Client-" + curve.name + "-TLS13",
7894 config: Config{
7895 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007896 CurvePreferences: []CurveID{curve.id},
7897 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007898 flags: []string{
7899 "-enable-all-curves",
7900 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7901 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007902 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007903 })
7904 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007905 testType: serverTest,
7906 name: "CurveTest-Server-" + curve.name,
7907 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007908 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7910 CurvePreferences: []CurveID{curve.id},
7911 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007912 flags: []string{
7913 "-enable-all-curves",
7914 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7915 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007916 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007917 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007918 testCases = append(testCases, testCase{
7919 testType: serverTest,
7920 name: "CurveTest-Server-" + curve.name + "-TLS13",
7921 config: Config{
7922 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007923 CurvePreferences: []CurveID{curve.id},
7924 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007925 flags: []string{
7926 "-enable-all-curves",
7927 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7928 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007929 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007930 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007931 }
David Benjamin241ae832016-01-15 03:04:54 -05007932
7933 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007934 testCases = append(testCases, testCase{
7935 testType: serverTest,
7936 name: "UnknownCurve",
7937 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007938 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7940 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7941 },
7942 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007943
Steven Valdez803c77a2016-09-06 14:13:43 -04007944 // The server must be tolerant to bogus curves.
7945 testCases = append(testCases, testCase{
7946 testType: serverTest,
7947 name: "UnknownCurve-TLS13",
7948 config: Config{
7949 MaxVersion: VersionTLS13,
7950 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7951 },
7952 })
7953
David Benjamin4c3ddf72016-06-29 18:13:53 -04007954 // The server must not consider ECDHE ciphers when there are no
7955 // supported curves.
7956 testCases = append(testCases, testCase{
7957 testType: serverTest,
7958 name: "NoSupportedCurves",
7959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007960 MaxVersion: VersionTLS12,
7961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7962 Bugs: ProtocolBugs{
7963 NoSupportedCurves: true,
7964 },
7965 },
7966 shouldFail: true,
7967 expectedError: ":NO_SHARED_CIPHER:",
7968 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007969 testCases = append(testCases, testCase{
7970 testType: serverTest,
7971 name: "NoSupportedCurves-TLS13",
7972 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007973 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007974 Bugs: ProtocolBugs{
7975 NoSupportedCurves: true,
7976 },
7977 },
7978 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007979 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007980 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007981
7982 // The server must fall back to another cipher when there are no
7983 // supported curves.
7984 testCases = append(testCases, testCase{
7985 testType: serverTest,
7986 name: "NoCommonCurves",
7987 config: Config{
7988 MaxVersion: VersionTLS12,
7989 CipherSuites: []uint16{
7990 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7991 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7992 },
7993 CurvePreferences: []CurveID{CurveP224},
7994 },
7995 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7996 })
7997
7998 // The client must reject bogus curves and disabled curves.
7999 testCases = append(testCases, testCase{
8000 name: "BadECDHECurve",
8001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008002 MaxVersion: VersionTLS12,
8003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8004 Bugs: ProtocolBugs{
8005 SendCurve: bogusCurve,
8006 },
8007 },
8008 shouldFail: true,
8009 expectedError: ":WRONG_CURVE:",
8010 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008011 testCases = append(testCases, testCase{
8012 name: "BadECDHECurve-TLS13",
8013 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008014 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008015 Bugs: ProtocolBugs{
8016 SendCurve: bogusCurve,
8017 },
8018 },
8019 shouldFail: true,
8020 expectedError: ":WRONG_CURVE:",
8021 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008022
8023 testCases = append(testCases, testCase{
8024 name: "UnsupportedCurve",
8025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008026 MaxVersion: VersionTLS12,
8027 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8028 CurvePreferences: []CurveID{CurveP256},
8029 Bugs: ProtocolBugs{
8030 IgnorePeerCurvePreferences: true,
8031 },
8032 },
8033 flags: []string{"-p384-only"},
8034 shouldFail: true,
8035 expectedError: ":WRONG_CURVE:",
8036 })
8037
David Benjamin4f921572016-07-17 14:20:10 +02008038 testCases = append(testCases, testCase{
8039 // TODO(davidben): Add a TLS 1.3 version where
8040 // HelloRetryRequest requests an unsupported curve.
8041 name: "UnsupportedCurve-ServerHello-TLS13",
8042 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008043 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008044 CurvePreferences: []CurveID{CurveP384},
8045 Bugs: ProtocolBugs{
8046 SendCurve: CurveP256,
8047 },
8048 },
8049 flags: []string{"-p384-only"},
8050 shouldFail: true,
8051 expectedError: ":WRONG_CURVE:",
8052 })
8053
David Benjamin4c3ddf72016-06-29 18:13:53 -04008054 // Test invalid curve points.
8055 testCases = append(testCases, testCase{
8056 name: "InvalidECDHPoint-Client",
8057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008058 MaxVersion: VersionTLS12,
8059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8060 CurvePreferences: []CurveID{CurveP256},
8061 Bugs: ProtocolBugs{
8062 InvalidECDHPoint: true,
8063 },
8064 },
8065 shouldFail: true,
8066 expectedError: ":INVALID_ENCODING:",
8067 })
8068 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008069 name: "InvalidECDHPoint-Client-TLS13",
8070 config: Config{
8071 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008072 CurvePreferences: []CurveID{CurveP256},
8073 Bugs: ProtocolBugs{
8074 InvalidECDHPoint: true,
8075 },
8076 },
8077 shouldFail: true,
8078 expectedError: ":INVALID_ENCODING:",
8079 })
8080 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008081 testType: serverTest,
8082 name: "InvalidECDHPoint-Server",
8083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008084 MaxVersion: VersionTLS12,
8085 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8086 CurvePreferences: []CurveID{CurveP256},
8087 Bugs: ProtocolBugs{
8088 InvalidECDHPoint: true,
8089 },
8090 },
8091 shouldFail: true,
8092 expectedError: ":INVALID_ENCODING:",
8093 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008094 testCases = append(testCases, testCase{
8095 testType: serverTest,
8096 name: "InvalidECDHPoint-Server-TLS13",
8097 config: Config{
8098 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008099 CurvePreferences: []CurveID{CurveP256},
8100 Bugs: ProtocolBugs{
8101 InvalidECDHPoint: true,
8102 },
8103 },
8104 shouldFail: true,
8105 expectedError: ":INVALID_ENCODING:",
8106 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008107
8108 // The previous curve ID should be reported on TLS 1.2 resumption.
8109 testCases = append(testCases, testCase{
8110 name: "CurveID-Resume-Client",
8111 config: Config{
8112 MaxVersion: VersionTLS12,
8113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8114 CurvePreferences: []CurveID{CurveX25519},
8115 },
8116 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8117 resumeSession: true,
8118 })
8119 testCases = append(testCases, testCase{
8120 testType: serverTest,
8121 name: "CurveID-Resume-Server",
8122 config: Config{
8123 MaxVersion: VersionTLS12,
8124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8125 CurvePreferences: []CurveID{CurveX25519},
8126 },
8127 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8128 resumeSession: true,
8129 })
8130
8131 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8132 // one should be reported.
8133 testCases = append(testCases, testCase{
8134 name: "CurveID-Resume-Client-TLS13",
8135 config: Config{
8136 MaxVersion: VersionTLS13,
8137 CurvePreferences: []CurveID{CurveX25519},
8138 },
8139 resumeConfig: &Config{
8140 MaxVersion: VersionTLS13,
8141 CurvePreferences: []CurveID{CurveP256},
8142 },
8143 flags: []string{
8144 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8145 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8146 },
8147 resumeSession: true,
8148 })
8149 testCases = append(testCases, testCase{
8150 testType: serverTest,
8151 name: "CurveID-Resume-Server-TLS13",
8152 config: Config{
8153 MaxVersion: VersionTLS13,
8154 CurvePreferences: []CurveID{CurveX25519},
8155 },
8156 resumeConfig: &Config{
8157 MaxVersion: VersionTLS13,
8158 CurvePreferences: []CurveID{CurveP256},
8159 },
8160 flags: []string{
8161 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8162 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8163 },
8164 resumeSession: true,
8165 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008166}
8167
David Benjaminc9ae27c2016-06-24 22:56:37 -04008168func addTLS13RecordTests() {
8169 testCases = append(testCases, testCase{
8170 name: "TLS13-RecordPadding",
8171 config: Config{
8172 MaxVersion: VersionTLS13,
8173 MinVersion: VersionTLS13,
8174 Bugs: ProtocolBugs{
8175 RecordPadding: 10,
8176 },
8177 },
8178 })
8179
8180 testCases = append(testCases, testCase{
8181 name: "TLS13-EmptyRecords",
8182 config: Config{
8183 MaxVersion: VersionTLS13,
8184 MinVersion: VersionTLS13,
8185 Bugs: ProtocolBugs{
8186 OmitRecordContents: true,
8187 },
8188 },
8189 shouldFail: true,
8190 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8191 })
8192
8193 testCases = append(testCases, testCase{
8194 name: "TLS13-OnlyPadding",
8195 config: Config{
8196 MaxVersion: VersionTLS13,
8197 MinVersion: VersionTLS13,
8198 Bugs: ProtocolBugs{
8199 OmitRecordContents: true,
8200 RecordPadding: 10,
8201 },
8202 },
8203 shouldFail: true,
8204 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8205 })
8206
8207 testCases = append(testCases, testCase{
8208 name: "TLS13-WrongOuterRecord",
8209 config: Config{
8210 MaxVersion: VersionTLS13,
8211 MinVersion: VersionTLS13,
8212 Bugs: ProtocolBugs{
8213 OuterRecordType: recordTypeHandshake,
8214 },
8215 },
8216 shouldFail: true,
8217 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8218 })
8219}
8220
Steven Valdez5b986082016-09-01 12:29:49 -04008221func addSessionTicketTests() {
8222 testCases = append(testCases, testCase{
8223 // In TLS 1.2 and below, empty NewSessionTicket messages
8224 // mean the server changed its mind on sending a ticket.
8225 name: "SendEmptySessionTicket",
8226 config: Config{
8227 MaxVersion: VersionTLS12,
8228 Bugs: ProtocolBugs{
8229 SendEmptySessionTicket: true,
8230 },
8231 },
8232 flags: []string{"-expect-no-session"},
8233 })
8234
8235 // Test that the server ignores unknown PSK modes.
8236 testCases = append(testCases, testCase{
8237 testType: serverTest,
8238 name: "TLS13-SendUnknownModeSessionTicket-Server",
8239 config: Config{
8240 MaxVersion: VersionTLS13,
8241 Bugs: ProtocolBugs{
8242 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008243 },
8244 },
8245 resumeSession: true,
8246 expectedResumeVersion: VersionTLS13,
8247 })
8248
Steven Valdeza833c352016-11-01 13:39:36 -04008249 // Test that the server does not send session tickets with no matching key exchange mode.
8250 testCases = append(testCases, testCase{
8251 testType: serverTest,
8252 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8253 config: Config{
8254 MaxVersion: VersionTLS13,
8255 Bugs: ProtocolBugs{
8256 SendPSKKeyExchangeModes: []byte{0x1a},
8257 ExpectNoNewSessionTicket: true,
8258 },
8259 },
8260 })
8261
8262 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008263 testCases = append(testCases, testCase{
8264 testType: serverTest,
8265 name: "TLS13-SendBadKEModeSessionTicket-Server",
8266 config: Config{
8267 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008268 },
8269 resumeConfig: &Config{
8270 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008271 Bugs: ProtocolBugs{
8272 SendPSKKeyExchangeModes: []byte{0x1a},
8273 },
8274 },
8275 resumeSession: true,
8276 expectResumeRejected: true,
8277 })
8278
Steven Valdeza833c352016-11-01 13:39:36 -04008279 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008280 testCases = append(testCases, testCase{
8281 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008282 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008283 config: Config{
8284 MaxVersion: VersionTLS13,
8285 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008286 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008287 },
8288 },
Steven Valdeza833c352016-11-01 13:39:36 -04008289 resumeSession: true,
8290 flags: []string{
8291 "-resumption-delay", "10",
8292 },
Steven Valdez5b986082016-09-01 12:29:49 -04008293 })
8294
Steven Valdeza833c352016-11-01 13:39:36 -04008295 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008296 testCases = append(testCases, testCase{
8297 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008298 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008299 config: Config{
8300 MaxVersion: VersionTLS13,
8301 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008302 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008303 },
8304 },
Steven Valdeza833c352016-11-01 13:39:36 -04008305 resumeSession: true,
8306 shouldFail: true,
8307 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008308 })
8309
Steven Valdez5b986082016-09-01 12:29:49 -04008310}
8311
David Benjamin82261be2016-07-07 14:32:50 -07008312func addChangeCipherSpecTests() {
8313 // Test missing ChangeCipherSpecs.
8314 testCases = append(testCases, testCase{
8315 name: "SkipChangeCipherSpec-Client",
8316 config: Config{
8317 MaxVersion: VersionTLS12,
8318 Bugs: ProtocolBugs{
8319 SkipChangeCipherSpec: true,
8320 },
8321 },
8322 shouldFail: true,
8323 expectedError: ":UNEXPECTED_RECORD:",
8324 })
8325 testCases = append(testCases, testCase{
8326 testType: serverTest,
8327 name: "SkipChangeCipherSpec-Server",
8328 config: Config{
8329 MaxVersion: VersionTLS12,
8330 Bugs: ProtocolBugs{
8331 SkipChangeCipherSpec: true,
8332 },
8333 },
8334 shouldFail: true,
8335 expectedError: ":UNEXPECTED_RECORD:",
8336 })
8337 testCases = append(testCases, testCase{
8338 testType: serverTest,
8339 name: "SkipChangeCipherSpec-Server-NPN",
8340 config: Config{
8341 MaxVersion: VersionTLS12,
8342 NextProtos: []string{"bar"},
8343 Bugs: ProtocolBugs{
8344 SkipChangeCipherSpec: true,
8345 },
8346 },
8347 flags: []string{
8348 "-advertise-npn", "\x03foo\x03bar\x03baz",
8349 },
8350 shouldFail: true,
8351 expectedError: ":UNEXPECTED_RECORD:",
8352 })
8353
8354 // Test synchronization between the handshake and ChangeCipherSpec.
8355 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8356 // rejected. Test both with and without handshake packing to handle both
8357 // when the partial post-CCS message is in its own record and when it is
8358 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008359 for _, packed := range []bool{false, true} {
8360 var suffix string
8361 if packed {
8362 suffix = "-Packed"
8363 }
8364
8365 testCases = append(testCases, testCase{
8366 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8367 config: Config{
8368 MaxVersion: VersionTLS12,
8369 Bugs: ProtocolBugs{
8370 FragmentAcrossChangeCipherSpec: true,
8371 PackHandshakeFlight: packed,
8372 },
8373 },
8374 shouldFail: true,
8375 expectedError: ":UNEXPECTED_RECORD:",
8376 })
8377 testCases = append(testCases, testCase{
8378 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8379 config: Config{
8380 MaxVersion: VersionTLS12,
8381 },
8382 resumeSession: true,
8383 resumeConfig: &Config{
8384 MaxVersion: VersionTLS12,
8385 Bugs: ProtocolBugs{
8386 FragmentAcrossChangeCipherSpec: true,
8387 PackHandshakeFlight: packed,
8388 },
8389 },
8390 shouldFail: true,
8391 expectedError: ":UNEXPECTED_RECORD:",
8392 })
8393 testCases = append(testCases, testCase{
8394 testType: serverTest,
8395 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8396 config: Config{
8397 MaxVersion: VersionTLS12,
8398 Bugs: ProtocolBugs{
8399 FragmentAcrossChangeCipherSpec: true,
8400 PackHandshakeFlight: packed,
8401 },
8402 },
8403 shouldFail: true,
8404 expectedError: ":UNEXPECTED_RECORD:",
8405 })
8406 testCases = append(testCases, testCase{
8407 testType: serverTest,
8408 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8409 config: Config{
8410 MaxVersion: VersionTLS12,
8411 },
8412 resumeSession: true,
8413 resumeConfig: &Config{
8414 MaxVersion: VersionTLS12,
8415 Bugs: ProtocolBugs{
8416 FragmentAcrossChangeCipherSpec: true,
8417 PackHandshakeFlight: packed,
8418 },
8419 },
8420 shouldFail: true,
8421 expectedError: ":UNEXPECTED_RECORD:",
8422 })
8423 testCases = append(testCases, testCase{
8424 testType: serverTest,
8425 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8426 config: Config{
8427 MaxVersion: VersionTLS12,
8428 NextProtos: []string{"bar"},
8429 Bugs: ProtocolBugs{
8430 FragmentAcrossChangeCipherSpec: true,
8431 PackHandshakeFlight: packed,
8432 },
8433 },
8434 flags: []string{
8435 "-advertise-npn", "\x03foo\x03bar\x03baz",
8436 },
8437 shouldFail: true,
8438 expectedError: ":UNEXPECTED_RECORD:",
8439 })
8440 }
8441
David Benjamin61672812016-07-14 23:10:43 -04008442 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8443 // messages in the handshake queue. Do this by testing the server
8444 // reading the client Finished, reversing the flight so Finished comes
8445 // first.
8446 testCases = append(testCases, testCase{
8447 protocol: dtls,
8448 testType: serverTest,
8449 name: "SendUnencryptedFinished-DTLS",
8450 config: Config{
8451 MaxVersion: VersionTLS12,
8452 Bugs: ProtocolBugs{
8453 SendUnencryptedFinished: true,
8454 ReverseHandshakeFragments: true,
8455 },
8456 },
8457 shouldFail: true,
8458 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8459 })
8460
Steven Valdez143e8b32016-07-11 13:19:03 -04008461 // Test synchronization between encryption changes and the handshake in
8462 // TLS 1.3, where ChangeCipherSpec is implicit.
8463 testCases = append(testCases, testCase{
8464 name: "PartialEncryptedExtensionsWithServerHello",
8465 config: Config{
8466 MaxVersion: VersionTLS13,
8467 Bugs: ProtocolBugs{
8468 PartialEncryptedExtensionsWithServerHello: true,
8469 },
8470 },
8471 shouldFail: true,
8472 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8473 })
8474 testCases = append(testCases, testCase{
8475 testType: serverTest,
8476 name: "PartialClientFinishedWithClientHello",
8477 config: Config{
8478 MaxVersion: VersionTLS13,
8479 Bugs: ProtocolBugs{
8480 PartialClientFinishedWithClientHello: true,
8481 },
8482 },
8483 shouldFail: true,
8484 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8485 })
8486
David Benjamin82261be2016-07-07 14:32:50 -07008487 // Test that early ChangeCipherSpecs are handled correctly.
8488 testCases = append(testCases, testCase{
8489 testType: serverTest,
8490 name: "EarlyChangeCipherSpec-server-1",
8491 config: Config{
8492 MaxVersion: VersionTLS12,
8493 Bugs: ProtocolBugs{
8494 EarlyChangeCipherSpec: 1,
8495 },
8496 },
8497 shouldFail: true,
8498 expectedError: ":UNEXPECTED_RECORD:",
8499 })
8500 testCases = append(testCases, testCase{
8501 testType: serverTest,
8502 name: "EarlyChangeCipherSpec-server-2",
8503 config: Config{
8504 MaxVersion: VersionTLS12,
8505 Bugs: ProtocolBugs{
8506 EarlyChangeCipherSpec: 2,
8507 },
8508 },
8509 shouldFail: true,
8510 expectedError: ":UNEXPECTED_RECORD:",
8511 })
8512 testCases = append(testCases, testCase{
8513 protocol: dtls,
8514 name: "StrayChangeCipherSpec",
8515 config: Config{
8516 // TODO(davidben): Once DTLS 1.3 exists, test
8517 // that stray ChangeCipherSpec messages are
8518 // rejected.
8519 MaxVersion: VersionTLS12,
8520 Bugs: ProtocolBugs{
8521 StrayChangeCipherSpec: true,
8522 },
8523 },
8524 })
8525
8526 // Test that the contents of ChangeCipherSpec are checked.
8527 testCases = append(testCases, testCase{
8528 name: "BadChangeCipherSpec-1",
8529 config: Config{
8530 MaxVersion: VersionTLS12,
8531 Bugs: ProtocolBugs{
8532 BadChangeCipherSpec: []byte{2},
8533 },
8534 },
8535 shouldFail: true,
8536 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8537 })
8538 testCases = append(testCases, testCase{
8539 name: "BadChangeCipherSpec-2",
8540 config: Config{
8541 MaxVersion: VersionTLS12,
8542 Bugs: ProtocolBugs{
8543 BadChangeCipherSpec: []byte{1, 1},
8544 },
8545 },
8546 shouldFail: true,
8547 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8548 })
8549 testCases = append(testCases, testCase{
8550 protocol: dtls,
8551 name: "BadChangeCipherSpec-DTLS-1",
8552 config: Config{
8553 MaxVersion: VersionTLS12,
8554 Bugs: ProtocolBugs{
8555 BadChangeCipherSpec: []byte{2},
8556 },
8557 },
8558 shouldFail: true,
8559 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8560 })
8561 testCases = append(testCases, testCase{
8562 protocol: dtls,
8563 name: "BadChangeCipherSpec-DTLS-2",
8564 config: Config{
8565 MaxVersion: VersionTLS12,
8566 Bugs: ProtocolBugs{
8567 BadChangeCipherSpec: []byte{1, 1},
8568 },
8569 },
8570 shouldFail: true,
8571 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8572 })
8573}
8574
David Benjamincd2c8062016-09-09 11:28:16 -04008575type perMessageTest struct {
8576 messageType uint8
8577 test testCase
8578}
8579
8580// makePerMessageTests returns a series of test templates which cover each
8581// message in the TLS handshake. These may be used with bugs like
8582// WrongMessageType to fully test a per-message bug.
8583func makePerMessageTests() []perMessageTest {
8584 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008585 for _, protocol := range []protocol{tls, dtls} {
8586 var suffix string
8587 if protocol == dtls {
8588 suffix = "-DTLS"
8589 }
8590
David Benjamincd2c8062016-09-09 11:28:16 -04008591 ret = append(ret, perMessageTest{
8592 messageType: typeClientHello,
8593 test: testCase{
8594 protocol: protocol,
8595 testType: serverTest,
8596 name: "ClientHello" + suffix,
8597 config: Config{
8598 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008599 },
8600 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008601 })
8602
8603 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008604 ret = append(ret, perMessageTest{
8605 messageType: typeHelloVerifyRequest,
8606 test: testCase{
8607 protocol: protocol,
8608 name: "HelloVerifyRequest" + suffix,
8609 config: Config{
8610 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008611 },
8612 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008613 })
8614 }
8615
David Benjamincd2c8062016-09-09 11:28:16 -04008616 ret = append(ret, perMessageTest{
8617 messageType: typeServerHello,
8618 test: testCase{
8619 protocol: protocol,
8620 name: "ServerHello" + suffix,
8621 config: Config{
8622 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008623 },
8624 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008625 })
8626
David Benjamincd2c8062016-09-09 11:28:16 -04008627 ret = append(ret, perMessageTest{
8628 messageType: typeCertificate,
8629 test: testCase{
8630 protocol: protocol,
8631 name: "ServerCertificate" + suffix,
8632 config: Config{
8633 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008634 },
8635 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008636 })
8637
David Benjamincd2c8062016-09-09 11:28:16 -04008638 ret = append(ret, perMessageTest{
8639 messageType: typeCertificateStatus,
8640 test: testCase{
8641 protocol: protocol,
8642 name: "CertificateStatus" + suffix,
8643 config: Config{
8644 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008645 },
David Benjamincd2c8062016-09-09 11:28:16 -04008646 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008647 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008648 })
8649
David Benjamincd2c8062016-09-09 11:28:16 -04008650 ret = append(ret, perMessageTest{
8651 messageType: typeServerKeyExchange,
8652 test: testCase{
8653 protocol: protocol,
8654 name: "ServerKeyExchange" + suffix,
8655 config: Config{
8656 MaxVersion: VersionTLS12,
8657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008658 },
8659 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008660 })
8661
David Benjamincd2c8062016-09-09 11:28:16 -04008662 ret = append(ret, perMessageTest{
8663 messageType: typeCertificateRequest,
8664 test: testCase{
8665 protocol: protocol,
8666 name: "CertificateRequest" + suffix,
8667 config: Config{
8668 MaxVersion: VersionTLS12,
8669 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008670 },
8671 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008672 })
8673
David Benjamincd2c8062016-09-09 11:28:16 -04008674 ret = append(ret, perMessageTest{
8675 messageType: typeServerHelloDone,
8676 test: testCase{
8677 protocol: protocol,
8678 name: "ServerHelloDone" + suffix,
8679 config: Config{
8680 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008681 },
8682 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008683 })
8684
David Benjamincd2c8062016-09-09 11:28:16 -04008685 ret = append(ret, perMessageTest{
8686 messageType: typeCertificate,
8687 test: testCase{
8688 testType: serverTest,
8689 protocol: protocol,
8690 name: "ClientCertificate" + suffix,
8691 config: Config{
8692 Certificates: []Certificate{rsaCertificate},
8693 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008694 },
David Benjamincd2c8062016-09-09 11:28:16 -04008695 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008696 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008697 })
8698
David Benjamincd2c8062016-09-09 11:28:16 -04008699 ret = append(ret, perMessageTest{
8700 messageType: typeCertificateVerify,
8701 test: testCase{
8702 testType: serverTest,
8703 protocol: protocol,
8704 name: "CertificateVerify" + suffix,
8705 config: Config{
8706 Certificates: []Certificate{rsaCertificate},
8707 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008708 },
David Benjamincd2c8062016-09-09 11:28:16 -04008709 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008710 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008711 })
8712
David Benjamincd2c8062016-09-09 11:28:16 -04008713 ret = append(ret, perMessageTest{
8714 messageType: typeClientKeyExchange,
8715 test: testCase{
8716 testType: serverTest,
8717 protocol: protocol,
8718 name: "ClientKeyExchange" + suffix,
8719 config: Config{
8720 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008721 },
8722 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008723 })
8724
8725 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008726 ret = append(ret, perMessageTest{
8727 messageType: typeNextProtocol,
8728 test: testCase{
8729 testType: serverTest,
8730 protocol: protocol,
8731 name: "NextProtocol" + suffix,
8732 config: Config{
8733 MaxVersion: VersionTLS12,
8734 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008735 },
David Benjamincd2c8062016-09-09 11:28:16 -04008736 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008737 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008738 })
8739
David Benjamincd2c8062016-09-09 11:28:16 -04008740 ret = append(ret, perMessageTest{
8741 messageType: typeChannelID,
8742 test: testCase{
8743 testType: serverTest,
8744 protocol: protocol,
8745 name: "ChannelID" + suffix,
8746 config: Config{
8747 MaxVersion: VersionTLS12,
8748 ChannelID: channelIDKey,
8749 },
8750 flags: []string{
8751 "-expect-channel-id",
8752 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008753 },
8754 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008755 })
8756 }
8757
David Benjamincd2c8062016-09-09 11:28:16 -04008758 ret = append(ret, perMessageTest{
8759 messageType: typeFinished,
8760 test: testCase{
8761 testType: serverTest,
8762 protocol: protocol,
8763 name: "ClientFinished" + suffix,
8764 config: Config{
8765 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008766 },
8767 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 })
8769
David Benjamincd2c8062016-09-09 11:28:16 -04008770 ret = append(ret, perMessageTest{
8771 messageType: typeNewSessionTicket,
8772 test: testCase{
8773 protocol: protocol,
8774 name: "NewSessionTicket" + suffix,
8775 config: Config{
8776 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008777 },
8778 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008779 })
8780
David Benjamincd2c8062016-09-09 11:28:16 -04008781 ret = append(ret, perMessageTest{
8782 messageType: typeFinished,
8783 test: testCase{
8784 protocol: protocol,
8785 name: "ServerFinished" + suffix,
8786 config: Config{
8787 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008788 },
8789 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008790 })
8791
8792 }
David Benjamincd2c8062016-09-09 11:28:16 -04008793
8794 ret = append(ret, perMessageTest{
8795 messageType: typeClientHello,
8796 test: testCase{
8797 testType: serverTest,
8798 name: "TLS13-ClientHello",
8799 config: Config{
8800 MaxVersion: VersionTLS13,
8801 },
8802 },
8803 })
8804
8805 ret = append(ret, perMessageTest{
8806 messageType: typeServerHello,
8807 test: testCase{
8808 name: "TLS13-ServerHello",
8809 config: Config{
8810 MaxVersion: VersionTLS13,
8811 },
8812 },
8813 })
8814
8815 ret = append(ret, perMessageTest{
8816 messageType: typeEncryptedExtensions,
8817 test: testCase{
8818 name: "TLS13-EncryptedExtensions",
8819 config: Config{
8820 MaxVersion: VersionTLS13,
8821 },
8822 },
8823 })
8824
8825 ret = append(ret, perMessageTest{
8826 messageType: typeCertificateRequest,
8827 test: testCase{
8828 name: "TLS13-CertificateRequest",
8829 config: Config{
8830 MaxVersion: VersionTLS13,
8831 ClientAuth: RequireAnyClientCert,
8832 },
8833 },
8834 })
8835
8836 ret = append(ret, perMessageTest{
8837 messageType: typeCertificate,
8838 test: testCase{
8839 name: "TLS13-ServerCertificate",
8840 config: Config{
8841 MaxVersion: VersionTLS13,
8842 },
8843 },
8844 })
8845
8846 ret = append(ret, perMessageTest{
8847 messageType: typeCertificateVerify,
8848 test: testCase{
8849 name: "TLS13-ServerCertificateVerify",
8850 config: Config{
8851 MaxVersion: VersionTLS13,
8852 },
8853 },
8854 })
8855
8856 ret = append(ret, perMessageTest{
8857 messageType: typeFinished,
8858 test: testCase{
8859 name: "TLS13-ServerFinished",
8860 config: Config{
8861 MaxVersion: VersionTLS13,
8862 },
8863 },
8864 })
8865
8866 ret = append(ret, perMessageTest{
8867 messageType: typeCertificate,
8868 test: testCase{
8869 testType: serverTest,
8870 name: "TLS13-ClientCertificate",
8871 config: Config{
8872 Certificates: []Certificate{rsaCertificate},
8873 MaxVersion: VersionTLS13,
8874 },
8875 flags: []string{"-require-any-client-certificate"},
8876 },
8877 })
8878
8879 ret = append(ret, perMessageTest{
8880 messageType: typeCertificateVerify,
8881 test: testCase{
8882 testType: serverTest,
8883 name: "TLS13-ClientCertificateVerify",
8884 config: Config{
8885 Certificates: []Certificate{rsaCertificate},
8886 MaxVersion: VersionTLS13,
8887 },
8888 flags: []string{"-require-any-client-certificate"},
8889 },
8890 })
8891
8892 ret = append(ret, perMessageTest{
8893 messageType: typeFinished,
8894 test: testCase{
8895 testType: serverTest,
8896 name: "TLS13-ClientFinished",
8897 config: Config{
8898 MaxVersion: VersionTLS13,
8899 },
8900 },
8901 })
8902
8903 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008904}
8905
David Benjamincd2c8062016-09-09 11:28:16 -04008906func addWrongMessageTypeTests() {
8907 for _, t := range makePerMessageTests() {
8908 t.test.name = "WrongMessageType-" + t.test.name
8909 t.test.config.Bugs.SendWrongMessageType = t.messageType
8910 t.test.shouldFail = true
8911 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8912 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008913
David Benjamincd2c8062016-09-09 11:28:16 -04008914 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8915 // In TLS 1.3, a bad ServerHello means the client sends
8916 // an unencrypted alert while the server expects
8917 // encryption, so the alert is not readable by runner.
8918 t.test.expectedLocalError = "local error: bad record MAC"
8919 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008920
David Benjamincd2c8062016-09-09 11:28:16 -04008921 testCases = append(testCases, t.test)
8922 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008923}
8924
David Benjamin639846e2016-09-09 11:41:18 -04008925func addTrailingMessageDataTests() {
8926 for _, t := range makePerMessageTests() {
8927 t.test.name = "TrailingMessageData-" + t.test.name
8928 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8929 t.test.shouldFail = true
8930 t.test.expectedError = ":DECODE_ERROR:"
8931 t.test.expectedLocalError = "remote error: error decoding message"
8932
8933 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8934 // In TLS 1.3, a bad ServerHello means the client sends
8935 // an unencrypted alert while the server expects
8936 // encryption, so the alert is not readable by runner.
8937 t.test.expectedLocalError = "local error: bad record MAC"
8938 }
8939
8940 if t.messageType == typeFinished {
8941 // Bad Finished messages read as the verify data having
8942 // the wrong length.
8943 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8944 t.test.expectedLocalError = "remote error: error decrypting message"
8945 }
8946
8947 testCases = append(testCases, t.test)
8948 }
8949}
8950
Steven Valdez143e8b32016-07-11 13:19:03 -04008951func addTLS13HandshakeTests() {
8952 testCases = append(testCases, testCase{
8953 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008954 name: "NegotiatePSKResumption-TLS13",
8955 config: Config{
8956 MaxVersion: VersionTLS13,
8957 Bugs: ProtocolBugs{
8958 NegotiatePSKResumption: true,
8959 },
8960 },
8961 resumeSession: true,
8962 shouldFail: true,
8963 expectedError: ":UNEXPECTED_EXTENSION:",
8964 })
8965
8966 testCases = append(testCases, testCase{
8967 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008968 name: "MissingKeyShare-Client",
8969 config: Config{
8970 MaxVersion: VersionTLS13,
8971 Bugs: ProtocolBugs{
8972 MissingKeyShare: true,
8973 },
8974 },
8975 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008976 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008977 })
8978
8979 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008980 testType: serverTest,
8981 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008982 config: Config{
8983 MaxVersion: VersionTLS13,
8984 Bugs: ProtocolBugs{
8985 MissingKeyShare: true,
8986 },
8987 },
8988 shouldFail: true,
8989 expectedError: ":MISSING_KEY_SHARE:",
8990 })
8991
8992 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008993 testType: serverTest,
8994 name: "DuplicateKeyShares",
8995 config: Config{
8996 MaxVersion: VersionTLS13,
8997 Bugs: ProtocolBugs{
8998 DuplicateKeyShares: true,
8999 },
9000 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009001 shouldFail: true,
9002 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009003 })
9004
9005 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009006 testType: serverTest,
9007 name: "SkipEarlyData",
9008 config: Config{
9009 MaxVersion: VersionTLS13,
9010 Bugs: ProtocolBugs{
9011 SendEarlyDataLength: 4,
9012 },
9013 },
9014 })
9015
9016 testCases = append(testCases, testCase{
9017 testType: serverTest,
9018 name: "SkipEarlyData-OmitEarlyDataExtension",
9019 config: Config{
9020 MaxVersion: VersionTLS13,
9021 Bugs: ProtocolBugs{
9022 SendEarlyDataLength: 4,
9023 OmitEarlyDataExtension: true,
9024 },
9025 },
9026 shouldFail: true,
9027 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9028 })
9029
9030 testCases = append(testCases, testCase{
9031 testType: serverTest,
9032 name: "SkipEarlyData-TooMuchData",
9033 config: Config{
9034 MaxVersion: VersionTLS13,
9035 Bugs: ProtocolBugs{
9036 SendEarlyDataLength: 16384 + 1,
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9041 })
9042
9043 testCases = append(testCases, testCase{
9044 testType: serverTest,
9045 name: "SkipEarlyData-Interleaved",
9046 config: Config{
9047 MaxVersion: VersionTLS13,
9048 Bugs: ProtocolBugs{
9049 SendEarlyDataLength: 4,
9050 InterleaveEarlyData: true,
9051 },
9052 },
9053 shouldFail: true,
9054 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9055 })
9056
9057 testCases = append(testCases, testCase{
9058 testType: serverTest,
9059 name: "SkipEarlyData-EarlyDataInTLS12",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 Bugs: ProtocolBugs{
9063 SendEarlyDataLength: 4,
9064 },
9065 },
9066 shouldFail: true,
9067 expectedError: ":UNEXPECTED_RECORD:",
9068 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9069 })
9070
9071 testCases = append(testCases, testCase{
9072 testType: serverTest,
9073 name: "SkipEarlyData-HRR",
9074 config: Config{
9075 MaxVersion: VersionTLS13,
9076 Bugs: ProtocolBugs{
9077 SendEarlyDataLength: 4,
9078 },
9079 DefaultCurves: []CurveID{},
9080 },
9081 })
9082
9083 testCases = append(testCases, testCase{
9084 testType: serverTest,
9085 name: "SkipEarlyData-HRR-Interleaved",
9086 config: Config{
9087 MaxVersion: VersionTLS13,
9088 Bugs: ProtocolBugs{
9089 SendEarlyDataLength: 4,
9090 InterleaveEarlyData: true,
9091 },
9092 DefaultCurves: []CurveID{},
9093 },
9094 shouldFail: true,
9095 expectedError: ":UNEXPECTED_RECORD:",
9096 })
9097
9098 testCases = append(testCases, testCase{
9099 testType: serverTest,
9100 name: "SkipEarlyData-HRR-TooMuchData",
9101 config: Config{
9102 MaxVersion: VersionTLS13,
9103 Bugs: ProtocolBugs{
9104 SendEarlyDataLength: 16384 + 1,
9105 },
9106 DefaultCurves: []CurveID{},
9107 },
9108 shouldFail: true,
9109 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9110 })
9111
9112 // Test that skipping early data looking for cleartext correctly
9113 // processes an alert record.
9114 testCases = append(testCases, testCase{
9115 testType: serverTest,
9116 name: "SkipEarlyData-HRR-FatalAlert",
9117 config: Config{
9118 MaxVersion: VersionTLS13,
9119 Bugs: ProtocolBugs{
9120 SendEarlyAlert: true,
9121 SendEarlyDataLength: 4,
9122 },
9123 DefaultCurves: []CurveID{},
9124 },
9125 shouldFail: true,
9126 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9127 })
9128
9129 testCases = append(testCases, testCase{
9130 testType: serverTest,
9131 name: "SkipEarlyData-SecondClientHelloEarlyData",
9132 config: Config{
9133 MaxVersion: VersionTLS13,
9134 Bugs: ProtocolBugs{
9135 SendEarlyDataOnSecondClientHello: true,
9136 },
9137 DefaultCurves: []CurveID{},
9138 },
9139 shouldFail: true,
9140 expectedLocalError: "remote error: bad record MAC",
9141 })
9142
9143 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009144 testType: clientTest,
9145 name: "EmptyEncryptedExtensions",
9146 config: Config{
9147 MaxVersion: VersionTLS13,
9148 Bugs: ProtocolBugs{
9149 EmptyEncryptedExtensions: true,
9150 },
9151 },
9152 shouldFail: true,
9153 expectedLocalError: "remote error: error decoding message",
9154 })
9155
9156 testCases = append(testCases, testCase{
9157 testType: clientTest,
9158 name: "EncryptedExtensionsWithKeyShare",
9159 config: Config{
9160 MaxVersion: VersionTLS13,
9161 Bugs: ProtocolBugs{
9162 EncryptedExtensionsWithKeyShare: true,
9163 },
9164 },
9165 shouldFail: true,
9166 expectedLocalError: "remote error: unsupported extension",
9167 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009168
9169 testCases = append(testCases, testCase{
9170 testType: serverTest,
9171 name: "SendHelloRetryRequest",
9172 config: Config{
9173 MaxVersion: VersionTLS13,
9174 // Require a HelloRetryRequest for every curve.
9175 DefaultCurves: []CurveID{},
9176 },
9177 expectedCurveID: CurveX25519,
9178 })
9179
9180 testCases = append(testCases, testCase{
9181 testType: serverTest,
9182 name: "SendHelloRetryRequest-2",
9183 config: Config{
9184 MaxVersion: VersionTLS13,
9185 DefaultCurves: []CurveID{CurveP384},
9186 },
9187 // Although the ClientHello did not predict our preferred curve,
9188 // we always select it whether it is predicted or not.
9189 expectedCurveID: CurveX25519,
9190 })
9191
9192 testCases = append(testCases, testCase{
9193 name: "UnknownCurve-HelloRetryRequest",
9194 config: Config{
9195 MaxVersion: VersionTLS13,
9196 // P-384 requires HelloRetryRequest in BoringSSL.
9197 CurvePreferences: []CurveID{CurveP384},
9198 Bugs: ProtocolBugs{
9199 SendHelloRetryRequestCurve: bogusCurve,
9200 },
9201 },
9202 shouldFail: true,
9203 expectedError: ":WRONG_CURVE:",
9204 })
9205
9206 testCases = append(testCases, testCase{
9207 name: "DisabledCurve-HelloRetryRequest",
9208 config: Config{
9209 MaxVersion: VersionTLS13,
9210 CurvePreferences: []CurveID{CurveP256},
9211 Bugs: ProtocolBugs{
9212 IgnorePeerCurvePreferences: true,
9213 },
9214 },
9215 flags: []string{"-p384-only"},
9216 shouldFail: true,
9217 expectedError: ":WRONG_CURVE:",
9218 })
9219
9220 testCases = append(testCases, testCase{
9221 name: "UnnecessaryHelloRetryRequest",
9222 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009223 MaxVersion: VersionTLS13,
9224 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009225 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009226 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009227 },
9228 },
9229 shouldFail: true,
9230 expectedError: ":WRONG_CURVE:",
9231 })
9232
9233 testCases = append(testCases, testCase{
9234 name: "SecondHelloRetryRequest",
9235 config: Config{
9236 MaxVersion: VersionTLS13,
9237 // P-384 requires HelloRetryRequest in BoringSSL.
9238 CurvePreferences: []CurveID{CurveP384},
9239 Bugs: ProtocolBugs{
9240 SecondHelloRetryRequest: true,
9241 },
9242 },
9243 shouldFail: true,
9244 expectedError: ":UNEXPECTED_MESSAGE:",
9245 })
9246
9247 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009248 name: "HelloRetryRequest-Empty",
9249 config: Config{
9250 MaxVersion: VersionTLS13,
9251 Bugs: ProtocolBugs{
9252 AlwaysSendHelloRetryRequest: true,
9253 },
9254 },
9255 shouldFail: true,
9256 expectedError: ":DECODE_ERROR:",
9257 })
9258
9259 testCases = append(testCases, testCase{
9260 name: "HelloRetryRequest-DuplicateCurve",
9261 config: Config{
9262 MaxVersion: VersionTLS13,
9263 // P-384 requires a HelloRetryRequest against BoringSSL's default
9264 // configuration. Assert this ExpectMissingKeyShare.
9265 CurvePreferences: []CurveID{CurveP384},
9266 Bugs: ProtocolBugs{
9267 ExpectMissingKeyShare: true,
9268 DuplicateHelloRetryRequestExtensions: true,
9269 },
9270 },
9271 shouldFail: true,
9272 expectedError: ":DUPLICATE_EXTENSION:",
9273 expectedLocalError: "remote error: illegal parameter",
9274 })
9275
9276 testCases = append(testCases, testCase{
9277 name: "HelloRetryRequest-Cookie",
9278 config: Config{
9279 MaxVersion: VersionTLS13,
9280 Bugs: ProtocolBugs{
9281 SendHelloRetryRequestCookie: []byte("cookie"),
9282 },
9283 },
9284 })
9285
9286 testCases = append(testCases, testCase{
9287 name: "HelloRetryRequest-DuplicateCookie",
9288 config: Config{
9289 MaxVersion: VersionTLS13,
9290 Bugs: ProtocolBugs{
9291 SendHelloRetryRequestCookie: []byte("cookie"),
9292 DuplicateHelloRetryRequestExtensions: true,
9293 },
9294 },
9295 shouldFail: true,
9296 expectedError: ":DUPLICATE_EXTENSION:",
9297 expectedLocalError: "remote error: illegal parameter",
9298 })
9299
9300 testCases = append(testCases, testCase{
9301 name: "HelloRetryRequest-EmptyCookie",
9302 config: Config{
9303 MaxVersion: VersionTLS13,
9304 Bugs: ProtocolBugs{
9305 SendHelloRetryRequestCookie: []byte{},
9306 },
9307 },
9308 shouldFail: true,
9309 expectedError: ":DECODE_ERROR:",
9310 })
9311
9312 testCases = append(testCases, testCase{
9313 name: "HelloRetryRequest-Cookie-Curve",
9314 config: Config{
9315 MaxVersion: VersionTLS13,
9316 // P-384 requires HelloRetryRequest in BoringSSL.
9317 CurvePreferences: []CurveID{CurveP384},
9318 Bugs: ProtocolBugs{
9319 SendHelloRetryRequestCookie: []byte("cookie"),
9320 ExpectMissingKeyShare: true,
9321 },
9322 },
9323 })
9324
9325 testCases = append(testCases, testCase{
9326 name: "HelloRetryRequest-Unknown",
9327 config: Config{
9328 MaxVersion: VersionTLS13,
9329 Bugs: ProtocolBugs{
9330 CustomHelloRetryRequestExtension: "extension",
9331 },
9332 },
9333 shouldFail: true,
9334 expectedError: ":UNEXPECTED_EXTENSION:",
9335 expectedLocalError: "remote error: unsupported extension",
9336 })
9337
9338 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009339 testType: serverTest,
9340 name: "SecondClientHelloMissingKeyShare",
9341 config: Config{
9342 MaxVersion: VersionTLS13,
9343 DefaultCurves: []CurveID{},
9344 Bugs: ProtocolBugs{
9345 SecondClientHelloMissingKeyShare: true,
9346 },
9347 },
9348 shouldFail: true,
9349 expectedError: ":MISSING_KEY_SHARE:",
9350 })
9351
9352 testCases = append(testCases, testCase{
9353 testType: serverTest,
9354 name: "SecondClientHelloWrongCurve",
9355 config: Config{
9356 MaxVersion: VersionTLS13,
9357 DefaultCurves: []CurveID{},
9358 Bugs: ProtocolBugs{
9359 MisinterpretHelloRetryRequestCurve: CurveP521,
9360 },
9361 },
9362 shouldFail: true,
9363 expectedError: ":WRONG_CURVE:",
9364 })
9365
9366 testCases = append(testCases, testCase{
9367 name: "HelloRetryRequestVersionMismatch",
9368 config: Config{
9369 MaxVersion: VersionTLS13,
9370 // P-384 requires HelloRetryRequest in BoringSSL.
9371 CurvePreferences: []CurveID{CurveP384},
9372 Bugs: ProtocolBugs{
9373 SendServerHelloVersion: 0x0305,
9374 },
9375 },
9376 shouldFail: true,
9377 expectedError: ":WRONG_VERSION_NUMBER:",
9378 })
9379
9380 testCases = append(testCases, testCase{
9381 name: "HelloRetryRequestCurveMismatch",
9382 config: Config{
9383 MaxVersion: VersionTLS13,
9384 // P-384 requires HelloRetryRequest in BoringSSL.
9385 CurvePreferences: []CurveID{CurveP384},
9386 Bugs: ProtocolBugs{
9387 // Send P-384 (correct) in the HelloRetryRequest.
9388 SendHelloRetryRequestCurve: CurveP384,
9389 // But send P-256 in the ServerHello.
9390 SendCurve: CurveP256,
9391 },
9392 },
9393 shouldFail: true,
9394 expectedError: ":WRONG_CURVE:",
9395 })
9396
9397 // Test the server selecting a curve that requires a HelloRetryRequest
9398 // without sending it.
9399 testCases = append(testCases, testCase{
9400 name: "SkipHelloRetryRequest",
9401 config: Config{
9402 MaxVersion: VersionTLS13,
9403 // P-384 requires HelloRetryRequest in BoringSSL.
9404 CurvePreferences: []CurveID{CurveP384},
9405 Bugs: ProtocolBugs{
9406 SkipHelloRetryRequest: true,
9407 },
9408 },
9409 shouldFail: true,
9410 expectedError: ":WRONG_CURVE:",
9411 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009412
9413 testCases = append(testCases, testCase{
9414 name: "TLS13-RequestContextInHandshake",
9415 config: Config{
9416 MaxVersion: VersionTLS13,
9417 MinVersion: VersionTLS13,
9418 ClientAuth: RequireAnyClientCert,
9419 Bugs: ProtocolBugs{
9420 SendRequestContext: []byte("request context"),
9421 },
9422 },
9423 flags: []string{
9424 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9425 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9426 },
9427 shouldFail: true,
9428 expectedError: ":DECODE_ERROR:",
9429 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009430
9431 testCases = append(testCases, testCase{
9432 testType: serverTest,
9433 name: "TLS13-TrailingKeyShareData",
9434 config: Config{
9435 MaxVersion: VersionTLS13,
9436 Bugs: ProtocolBugs{
9437 TrailingKeyShareData: true,
9438 },
9439 },
9440 shouldFail: true,
9441 expectedError: ":DECODE_ERROR:",
9442 })
David Benjamin7f78df42016-10-05 22:33:19 -04009443
9444 testCases = append(testCases, testCase{
9445 name: "TLS13-AlwaysSelectPSKIdentity",
9446 config: Config{
9447 MaxVersion: VersionTLS13,
9448 Bugs: ProtocolBugs{
9449 AlwaysSelectPSKIdentity: true,
9450 },
9451 },
9452 shouldFail: true,
9453 expectedError: ":UNEXPECTED_EXTENSION:",
9454 })
9455
9456 testCases = append(testCases, testCase{
9457 name: "TLS13-InvalidPSKIdentity",
9458 config: Config{
9459 MaxVersion: VersionTLS13,
9460 Bugs: ProtocolBugs{
9461 SelectPSKIdentityOnResume: 1,
9462 },
9463 },
9464 resumeSession: true,
9465 shouldFail: true,
9466 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9467 })
David Benjamin1286bee2016-10-07 15:25:06 -04009468
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009469 testCases = append(testCases, testCase{
9470 testType: serverTest,
9471 name: "TLS13-ExtraPSKIdentity",
9472 config: Config{
9473 MaxVersion: VersionTLS13,
9474 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009475 ExtraPSKIdentity: true,
9476 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009477 },
9478 },
9479 resumeSession: true,
9480 })
9481
David Benjamin1286bee2016-10-07 15:25:06 -04009482 // Test that unknown NewSessionTicket extensions are tolerated.
9483 testCases = append(testCases, testCase{
9484 name: "TLS13-CustomTicketExtension",
9485 config: Config{
9486 MaxVersion: VersionTLS13,
9487 Bugs: ProtocolBugs{
9488 CustomTicketExtension: "1234",
9489 },
9490 },
9491 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009492}
9493
David Benjaminabbbee12016-10-31 19:20:42 -04009494func addTLS13CipherPreferenceTests() {
9495 // Test that client preference is honored if the shim has AES hardware
9496 // and ChaCha20-Poly1305 is preferred otherwise.
9497 testCases = append(testCases, testCase{
9498 testType: serverTest,
9499 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9500 config: Config{
9501 MaxVersion: VersionTLS13,
9502 CipherSuites: []uint16{
9503 TLS_CHACHA20_POLY1305_SHA256,
9504 TLS_AES_128_GCM_SHA256,
9505 },
9506 },
9507 flags: []string{
9508 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9509 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9510 },
9511 })
9512
9513 testCases = append(testCases, testCase{
9514 testType: serverTest,
9515 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9516 config: Config{
9517 MaxVersion: VersionTLS13,
9518 CipherSuites: []uint16{
9519 TLS_AES_128_GCM_SHA256,
9520 TLS_CHACHA20_POLY1305_SHA256,
9521 },
9522 },
9523 flags: []string{
9524 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9525 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9526 },
9527 })
9528
9529 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9530 // whether it has AES hardware.
9531 testCases = append(testCases, testCase{
9532 name: "TLS13-CipherPreference-Client",
9533 config: Config{
9534 MaxVersion: VersionTLS13,
9535 // Use the client cipher order. (This is the default but
9536 // is listed to be explicit.)
9537 PreferServerCipherSuites: false,
9538 },
9539 flags: []string{
9540 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9541 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9542 },
9543 })
9544}
9545
David Benjaminf3fbade2016-09-19 13:08:16 -04009546func addPeekTests() {
9547 // Test SSL_peek works, including on empty records.
9548 testCases = append(testCases, testCase{
9549 name: "Peek-Basic",
9550 sendEmptyRecords: 1,
9551 flags: []string{"-peek-then-read"},
9552 })
9553
9554 // Test SSL_peek can drive the initial handshake.
9555 testCases = append(testCases, testCase{
9556 name: "Peek-ImplicitHandshake",
9557 flags: []string{
9558 "-peek-then-read",
9559 "-implicit-handshake",
9560 },
9561 })
9562
9563 // Test SSL_peek can discover and drive a renegotiation.
9564 testCases = append(testCases, testCase{
9565 name: "Peek-Renegotiate",
9566 config: Config{
9567 MaxVersion: VersionTLS12,
9568 },
9569 renegotiate: 1,
9570 flags: []string{
9571 "-peek-then-read",
9572 "-renegotiate-freely",
9573 "-expect-total-renegotiations", "1",
9574 },
9575 })
9576
9577 // Test SSL_peek can discover a close_notify.
9578 testCases = append(testCases, testCase{
9579 name: "Peek-Shutdown",
9580 config: Config{
9581 Bugs: ProtocolBugs{
9582 ExpectCloseNotify: true,
9583 },
9584 },
9585 flags: []string{
9586 "-peek-then-read",
9587 "-check-close-notify",
9588 },
9589 })
9590
9591 // Test SSL_peek can discover an alert.
9592 testCases = append(testCases, testCase{
9593 name: "Peek-Alert",
9594 config: Config{
9595 Bugs: ProtocolBugs{
9596 SendSpuriousAlert: alertRecordOverflow,
9597 },
9598 },
9599 flags: []string{"-peek-then-read"},
9600 shouldFail: true,
9601 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9602 })
9603
9604 // Test SSL_peek can handle KeyUpdate.
9605 testCases = append(testCases, testCase{
9606 name: "Peek-KeyUpdate",
9607 config: Config{
9608 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009609 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009610 sendKeyUpdates: 1,
9611 keyUpdateRequest: keyUpdateNotRequested,
9612 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009613 })
9614}
9615
David Benjamine6f22212016-11-08 14:28:24 -05009616func addRecordVersionTests() {
9617 for _, ver := range tlsVersions {
9618 // Test that the record version is enforced.
9619 testCases = append(testCases, testCase{
9620 name: "CheckRecordVersion-" + ver.name,
9621 config: Config{
9622 MinVersion: ver.version,
9623 MaxVersion: ver.version,
9624 Bugs: ProtocolBugs{
9625 SendRecordVersion: 0x03ff,
9626 },
9627 },
9628 shouldFail: true,
9629 expectedError: ":WRONG_VERSION_NUMBER:",
9630 })
9631
9632 // Test that the ClientHello may use any record version, for
9633 // compatibility reasons.
9634 testCases = append(testCases, testCase{
9635 testType: serverTest,
9636 name: "LooseInitialRecordVersion-" + ver.name,
9637 config: Config{
9638 MinVersion: ver.version,
9639 MaxVersion: ver.version,
9640 Bugs: ProtocolBugs{
9641 SendInitialRecordVersion: 0x03ff,
9642 },
9643 },
9644 })
9645
9646 // Test that garbage ClientHello record versions are rejected.
9647 testCases = append(testCases, testCase{
9648 testType: serverTest,
9649 name: "GarbageInitialRecordVersion-" + ver.name,
9650 config: Config{
9651 MinVersion: ver.version,
9652 MaxVersion: ver.version,
9653 Bugs: ProtocolBugs{
9654 SendInitialRecordVersion: 0xffff,
9655 },
9656 },
9657 shouldFail: true,
9658 expectedError: ":WRONG_VERSION_NUMBER:",
9659 })
9660 }
9661}
9662
David Benjamin2c516452016-11-15 10:16:54 +09009663func addCertificateTests() {
9664 // Test that a certificate chain with intermediate may be sent and
9665 // received as both client and server.
9666 for _, ver := range tlsVersions {
9667 testCases = append(testCases, testCase{
9668 testType: clientTest,
9669 name: "SendReceiveIntermediate-Client-" + ver.name,
9670 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009671 MinVersion: ver.version,
9672 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009673 Certificates: []Certificate{rsaChainCertificate},
9674 ClientAuth: RequireAnyClientCert,
9675 },
9676 expectPeerCertificate: &rsaChainCertificate,
9677 flags: []string{
9678 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9679 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9680 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9681 },
9682 })
9683
9684 testCases = append(testCases, testCase{
9685 testType: serverTest,
9686 name: "SendReceiveIntermediate-Server-" + ver.name,
9687 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009688 MinVersion: ver.version,
9689 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009690 Certificates: []Certificate{rsaChainCertificate},
9691 },
9692 expectPeerCertificate: &rsaChainCertificate,
9693 flags: []string{
9694 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9695 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9696 "-require-any-client-certificate",
9697 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9698 },
9699 })
9700 }
9701}
9702
David Benjaminbbaf3672016-11-17 10:53:09 +09009703func addRetainOnlySHA256ClientCertTests() {
9704 for _, ver := range tlsVersions {
9705 // Test that enabling
9706 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9707 // actually requesting a client certificate is a no-op.
9708 testCases = append(testCases, testCase{
9709 testType: serverTest,
9710 name: "RetainOnlySHA256-NoCert-" + ver.name,
9711 config: Config{
9712 MinVersion: ver.version,
9713 MaxVersion: ver.version,
9714 },
9715 flags: []string{
9716 "-retain-only-sha256-client-cert-initial",
9717 "-retain-only-sha256-client-cert-resume",
9718 },
9719 resumeSession: true,
9720 })
9721
9722 // Test that when retaining only a SHA-256 certificate is
9723 // enabled, the hash appears as expected.
9724 testCases = append(testCases, testCase{
9725 testType: serverTest,
9726 name: "RetainOnlySHA256-Cert-" + ver.name,
9727 config: Config{
9728 MinVersion: ver.version,
9729 MaxVersion: ver.version,
9730 Certificates: []Certificate{rsaCertificate},
9731 },
9732 flags: []string{
9733 "-verify-peer",
9734 "-retain-only-sha256-client-cert-initial",
9735 "-retain-only-sha256-client-cert-resume",
9736 "-expect-sha256-client-cert-initial",
9737 "-expect-sha256-client-cert-resume",
9738 },
9739 resumeSession: true,
9740 })
9741
9742 // Test that when the config changes from on to off, a
9743 // resumption is rejected because the server now wants the full
9744 // certificate chain.
9745 testCases = append(testCases, testCase{
9746 testType: serverTest,
9747 name: "RetainOnlySHA256-OnOff-" + ver.name,
9748 config: Config{
9749 MinVersion: ver.version,
9750 MaxVersion: ver.version,
9751 Certificates: []Certificate{rsaCertificate},
9752 },
9753 flags: []string{
9754 "-verify-peer",
9755 "-retain-only-sha256-client-cert-initial",
9756 "-expect-sha256-client-cert-initial",
9757 },
9758 resumeSession: true,
9759 expectResumeRejected: true,
9760 })
9761
9762 // Test that when the config changes from off to on, a
9763 // resumption is rejected because the server now wants just the
9764 // hash.
9765 testCases = append(testCases, testCase{
9766 testType: serverTest,
9767 name: "RetainOnlySHA256-OffOn-" + ver.name,
9768 config: Config{
9769 MinVersion: ver.version,
9770 MaxVersion: ver.version,
9771 Certificates: []Certificate{rsaCertificate},
9772 },
9773 flags: []string{
9774 "-verify-peer",
9775 "-retain-only-sha256-client-cert-resume",
9776 "-expect-sha256-client-cert-resume",
9777 },
9778 resumeSession: true,
9779 expectResumeRejected: true,
9780 })
9781 }
9782}
9783
Adam Langley7c803a62015-06-15 15:35:05 -07009784func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009785 defer wg.Done()
9786
9787 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009788 var err error
9789
David Benjaminba28dfc2016-11-15 17:47:21 +09009790 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009791 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9792 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009793 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009794 if err != nil {
9795 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9796 }
9797 break
9798 }
9799 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009800 } else if *repeatUntilFailure {
9801 for err == nil {
9802 statusChan <- statusMsg{test: test, started: true}
9803 err = runTest(test, shimPath, -1)
9804 }
9805 } else {
9806 statusChan <- statusMsg{test: test, started: true}
9807 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009808 }
Adam Langley95c29f32014-06-20 12:00:00 -07009809 statusChan <- statusMsg{test: test, err: err}
9810 }
9811}
9812
9813type statusMsg struct {
9814 test *testCase
9815 started bool
9816 err error
9817}
9818
David Benjamin5f237bc2015-02-11 17:14:15 -05009819func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009820 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009821
David Benjamin5f237bc2015-02-11 17:14:15 -05009822 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009823 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009824 if !*pipe {
9825 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009826 var erase string
9827 for i := 0; i < lineLen; i++ {
9828 erase += "\b \b"
9829 }
9830 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009831 }
9832
Adam Langley95c29f32014-06-20 12:00:00 -07009833 if msg.started {
9834 started++
9835 } else {
9836 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009837
9838 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009839 if msg.err == errUnimplemented {
9840 if *pipe {
9841 // Print each test instead of a status line.
9842 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9843 }
9844 unimplemented++
9845 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9846 } else {
9847 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9848 failed++
9849 testOutput.addResult(msg.test.name, "FAIL")
9850 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009851 } else {
9852 if *pipe {
9853 // Print each test instead of a status line.
9854 fmt.Printf("PASSED (%s)\n", msg.test.name)
9855 }
9856 testOutput.addResult(msg.test.name, "PASS")
9857 }
Adam Langley95c29f32014-06-20 12:00:00 -07009858 }
9859
David Benjamin5f237bc2015-02-11 17:14:15 -05009860 if !*pipe {
9861 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009862 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009863 lineLen = len(line)
9864 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009865 }
Adam Langley95c29f32014-06-20 12:00:00 -07009866 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009867
9868 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009869}
9870
9871func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009872 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009873 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009874 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009875
Adam Langley7c803a62015-06-15 15:35:05 -07009876 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009877 addCipherSuiteTests()
9878 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009879 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009880 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009881 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009882 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009883 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009884 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009885 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009886 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009887 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009888 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009889 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009890 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009891 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009892 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009893 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009894 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009895 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009896 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009897 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009898 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009899 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009900 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009901 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009902 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009903 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009904 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009905 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009906 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009907 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009908 addRetainOnlySHA256ClientCertTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009909
9910 var wg sync.WaitGroup
9911
Adam Langley7c803a62015-06-15 15:35:05 -07009912 statusChan := make(chan statusMsg, *numWorkers)
9913 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009914 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009915
EKRf71d7ed2016-08-06 13:25:12 -07009916 if len(*shimConfigFile) != 0 {
9917 encoded, err := ioutil.ReadFile(*shimConfigFile)
9918 if err != nil {
9919 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9920 os.Exit(1)
9921 }
9922
9923 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9924 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9925 os.Exit(1)
9926 }
9927 }
9928
David Benjamin025b3d32014-07-01 19:53:04 -04009929 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009930
Adam Langley7c803a62015-06-15 15:35:05 -07009931 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009932 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009933 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009934 }
9935
David Benjamin270f0a72016-03-17 14:41:36 -04009936 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009937 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009938 matched := true
9939 if len(*testToRun) != 0 {
9940 var err error
9941 matched, err = filepath.Match(*testToRun, testCases[i].name)
9942 if err != nil {
9943 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9944 os.Exit(1)
9945 }
9946 }
9947
EKRf71d7ed2016-08-06 13:25:12 -07009948 if !*includeDisabled {
9949 for pattern := range shimConfig.DisabledTests {
9950 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9951 if err != nil {
9952 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9953 os.Exit(1)
9954 }
9955
9956 if isDisabled {
9957 matched = false
9958 break
9959 }
9960 }
9961 }
9962
David Benjamin17e12922016-07-28 18:04:43 -04009963 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009964 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009965 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +09009966
9967 // Only run one test if repeating until failure.
9968 if *repeatUntilFailure {
9969 break
9970 }
Adam Langley95c29f32014-06-20 12:00:00 -07009971 }
9972 }
David Benjamin17e12922016-07-28 18:04:43 -04009973
David Benjamin270f0a72016-03-17 14:41:36 -04009974 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009975 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009976 os.Exit(1)
9977 }
Adam Langley95c29f32014-06-20 12:00:00 -07009978
9979 close(testChan)
9980 wg.Wait()
9981 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009982 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009983
9984 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009985
9986 if *jsonOutput != "" {
9987 if err := testOutput.writeTo(*jsonOutput); err != nil {
9988 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9989 }
9990 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009991
EKR842ae6c2016-07-27 09:22:05 +02009992 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9993 os.Exit(1)
9994 }
9995
9996 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009997 os.Exit(1)
9998 }
Adam Langley95c29f32014-06-20 12:00:00 -07009999}