blob: 683f07cb4a27ac2ad94a0233623a4ca20486acbb [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
David Benjamin87c8a642015-02-21 01:54:29 -0500838 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
839 if err != nil {
840 panic(err)
841 }
842 defer func() {
843 if listener != nil {
844 listener.Close()
845 }
846 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700847
David Benjamin87c8a642015-02-21 01:54:29 -0500848 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400849 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400850 flags = append(flags, "-server")
851
David Benjamin025b3d32014-07-01 19:53:04 -0400852 flags = append(flags, "-key-file")
853 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700854 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400855 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700856 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400857 }
858
859 flags = append(flags, "-cert-file")
860 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700861 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400862 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700863 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400864 }
865 }
David Benjamin5a593af2014-08-11 19:51:50 -0400866
David Benjamin6fd297b2014-08-11 18:43:38 -0400867 if test.protocol == dtls {
868 flags = append(flags, "-dtls")
869 }
870
David Benjamin46662482016-08-17 00:51:00 -0400871 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400872 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400873 resumeCount++
874 if test.resumeRenewedSession {
875 resumeCount++
876 }
877 }
878
879 if resumeCount > 0 {
880 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400881 }
882
David Benjamine58c4f52014-08-24 03:47:07 -0400883 if test.shimWritesFirst {
884 flags = append(flags, "-shim-writes-first")
885 }
886
David Benjamin30789da2015-08-29 22:56:45 -0400887 if test.shimShutsDown {
888 flags = append(flags, "-shim-shuts-down")
889 }
890
David Benjaminc565ebb2015-04-03 04:06:36 -0400891 if test.exportKeyingMaterial > 0 {
892 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
893 flags = append(flags, "-export-label", test.exportLabel)
894 flags = append(flags, "-export-context", test.exportContext)
895 if test.useExportContext {
896 flags = append(flags, "-use-export-context")
897 }
898 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700899 if test.expectResumeRejected {
900 flags = append(flags, "-expect-session-miss")
901 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400902
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700903 if test.testTLSUnique {
904 flags = append(flags, "-tls-unique")
905 }
906
David Benjamin025b3d32014-07-01 19:53:04 -0400907 flags = append(flags, test.flags...)
908
909 var shim *exec.Cmd
910 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700911 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700912 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700913 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500914 } else if *useLLDB {
915 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400916 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700917 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400918 }
David Benjamin025b3d32014-07-01 19:53:04 -0400919 shim.Stdin = os.Stdin
920 var stdoutBuf, stderrBuf bytes.Buffer
921 shim.Stdout = &stdoutBuf
922 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800923 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500924 shim.Env = os.Environ()
925 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800926 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400927 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800928 }
929 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
930 }
David Benjamin025b3d32014-07-01 19:53:04 -0400931
932 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700933 panic(err)
934 }
David Benjamin87c8a642015-02-21 01:54:29 -0500935 waitChan := make(chan error, 1)
936 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700937
938 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700939
David Benjamin7a4aaa42016-09-20 17:58:14 -0400940 if *deterministic {
941 config.Rand = &deterministicRand{}
942 }
943
David Benjamin87c8a642015-02-21 01:54:29 -0500944 conn, err := acceptOrWait(listener, waitChan)
945 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400946 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500947 conn.Close()
948 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500949
David Benjamin46662482016-08-17 00:51:00 -0400950 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400951 var resumeConfig Config
952 if test.resumeConfig != nil {
953 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400954 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500955 resumeConfig.SessionTicketKey = config.SessionTicketKey
956 resumeConfig.ClientSessionCache = config.ClientSessionCache
957 resumeConfig.ServerSessionCache = config.ServerSessionCache
958 }
David Benjamin2e045a92016-06-08 13:09:56 -0400959 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400960 } else {
961 resumeConfig = config
962 }
David Benjamin87c8a642015-02-21 01:54:29 -0500963 var connResume net.Conn
964 connResume, err = acceptOrWait(listener, waitChan)
965 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400966 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500967 connResume.Close()
968 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400969 }
970
David Benjamin87c8a642015-02-21 01:54:29 -0500971 // Close the listener now. This is to avoid hangs should the shim try to
972 // open more connections than expected.
973 listener.Close()
974 listener = nil
975
976 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400977 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800978 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200979 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
980 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800981 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200982 case 89:
983 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400984 case 99:
985 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800986 }
987 }
Adam Langley95c29f32014-06-20 12:00:00 -0700988
David Benjamin9bea3492016-03-02 10:59:16 -0500989 // Account for Windows line endings.
990 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
991 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500992
993 // Separate the errors from the shim and those from tools like
994 // AddressSanitizer.
995 var extraStderr string
996 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
997 stderr = stderrParts[0]
998 extraStderr = stderrParts[1]
999 }
1000
Adam Langley95c29f32014-06-20 12:00:00 -07001001 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001002 expectedError := translateExpectedError(test.expectedError)
1003 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001004
Adam Langleyac61fa32014-06-23 12:03:11 -07001005 localError := "none"
1006 if err != nil {
1007 localError = err.Error()
1008 }
1009 if len(test.expectedLocalError) != 0 {
1010 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1011 }
Adam Langley95c29f32014-06-20 12:00:00 -07001012
1013 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001014 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001015 if childErr != nil {
1016 childError = childErr.Error()
1017 }
1018
1019 var msg string
1020 switch {
1021 case failed && !test.shouldFail:
1022 msg = "unexpected failure"
1023 case !failed && test.shouldFail:
1024 msg = "unexpected success"
1025 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001026 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001027 default:
1028 panic("internal error")
1029 }
1030
David Benjamin9aafb642016-09-20 19:36:53 -04001031 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 -07001032 }
1033
David Benjamind2ba8892016-09-20 19:41:04 -04001034 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001035 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001036 }
1037
David Benjamind2ba8892016-09-20 19:41:04 -04001038 if *useValgrind && isValgrindError {
1039 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1040 }
1041
Adam Langley95c29f32014-06-20 12:00:00 -07001042 return nil
1043}
1044
1045var tlsVersions = []struct {
1046 name string
1047 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001048 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001049 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001050}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001051 {"SSL3", VersionSSL30, "-no-ssl3", false},
1052 {"TLS1", VersionTLS10, "-no-tls1", true},
1053 {"TLS11", VersionTLS11, "-no-tls11", false},
1054 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001055 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001056}
1057
1058var testCipherSuites = []struct {
1059 name string
1060 id uint16
1061}{
1062 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001063 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001064 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001065 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001066 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001067 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001068 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001069 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1070 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001071 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001072 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1073 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001074 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001075 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1076 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001077 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1078 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001079 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001080 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001081 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001082 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001083 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001084 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001085 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001086 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001087 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001088 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001089 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001090 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001091 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1092 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1093 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1094 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001095 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1096 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001097 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1098 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001099 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001100 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1101 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1102 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001103 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001104}
1105
David Benjamin8b8c0062014-11-23 02:47:52 -05001106func hasComponent(suiteName, component string) bool {
1107 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1108}
1109
David Benjaminf7768e42014-08-31 02:06:47 -04001110func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001111 return hasComponent(suiteName, "GCM") ||
1112 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001113 hasComponent(suiteName, "SHA384") ||
1114 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001115}
1116
Nick Harper1fd39d82016-06-14 18:14:35 -07001117func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001118 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001119}
1120
David Benjamin8b8c0062014-11-23 02:47:52 -05001121func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001122 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001123}
1124
Adam Langleya7997f12015-05-14 17:38:50 -07001125func bigFromHex(hex string) *big.Int {
1126 ret, ok := new(big.Int).SetString(hex, 16)
1127 if !ok {
1128 panic("failed to parse hex number 0x" + hex)
1129 }
1130 return ret
1131}
1132
Adam Langley7c803a62015-06-15 15:35:05 -07001133func addBasicTests() {
1134 basicTests := []testCase{
1135 {
Adam Langley7c803a62015-06-15 15:35:05 -07001136 name: "NoFallbackSCSV",
1137 config: Config{
1138 Bugs: ProtocolBugs{
1139 FailIfNotFallbackSCSV: true,
1140 },
1141 },
1142 shouldFail: true,
1143 expectedLocalError: "no fallback SCSV found",
1144 },
1145 {
1146 name: "SendFallbackSCSV",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 FailIfNotFallbackSCSV: true,
1150 },
1151 },
1152 flags: []string{"-fallback-scsv"},
1153 },
1154 {
1155 name: "ClientCertificateTypes",
1156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001157 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001158 ClientAuth: RequestClientCert,
1159 ClientCertificateTypes: []byte{
1160 CertTypeDSSSign,
1161 CertTypeRSASign,
1162 CertTypeECDSASign,
1163 },
1164 },
1165 flags: []string{
1166 "-expect-certificate-types",
1167 base64.StdEncoding.EncodeToString([]byte{
1168 CertTypeDSSSign,
1169 CertTypeRSASign,
1170 CertTypeECDSASign,
1171 }),
1172 },
1173 },
1174 {
Adam Langley7c803a62015-06-15 15:35:05 -07001175 name: "UnauthenticatedECDH",
1176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1179 Bugs: ProtocolBugs{
1180 UnauthenticatedECDH: true,
1181 },
1182 },
1183 shouldFail: true,
1184 expectedError: ":UNEXPECTED_MESSAGE:",
1185 },
1186 {
1187 name: "SkipCertificateStatus",
1188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1191 Bugs: ProtocolBugs{
1192 SkipCertificateStatus: true,
1193 },
1194 },
1195 flags: []string{
1196 "-enable-ocsp-stapling",
1197 },
1198 },
1199 {
1200 name: "SkipServerKeyExchange",
1201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001202 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001203 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1204 Bugs: ProtocolBugs{
1205 SkipServerKeyExchange: true,
1206 },
1207 },
1208 shouldFail: true,
1209 expectedError: ":UNEXPECTED_MESSAGE:",
1210 },
1211 {
Adam Langley7c803a62015-06-15 15:35:05 -07001212 testType: serverTest,
1213 name: "Alert",
1214 config: Config{
1215 Bugs: ProtocolBugs{
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "Alert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1233 },
1234 {
1235 testType: serverTest,
1236 name: "FragmentAlert",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 FragmentAlert: true,
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":BAD_ALERT:",
1245 },
1246 {
1247 protocol: dtls,
1248 testType: serverTest,
1249 name: "FragmentAlert-DTLS",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 FragmentAlert: true,
1253 SendSpuriousAlert: alertRecordOverflow,
1254 },
1255 },
1256 shouldFail: true,
1257 expectedError: ":BAD_ALERT:",
1258 },
1259 {
1260 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001261 name: "DoubleAlert",
1262 config: Config{
1263 Bugs: ProtocolBugs{
1264 DoubleAlert: true,
1265 SendSpuriousAlert: alertRecordOverflow,
1266 },
1267 },
1268 shouldFail: true,
1269 expectedError: ":BAD_ALERT:",
1270 },
1271 {
1272 protocol: dtls,
1273 testType: serverTest,
1274 name: "DoubleAlert-DTLS",
1275 config: Config{
1276 Bugs: ProtocolBugs{
1277 DoubleAlert: true,
1278 SendSpuriousAlert: alertRecordOverflow,
1279 },
1280 },
1281 shouldFail: true,
1282 expectedError: ":BAD_ALERT:",
1283 },
1284 {
Adam Langley7c803a62015-06-15 15:35:05 -07001285 name: "SkipNewSessionTicket",
1286 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001287 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001288 Bugs: ProtocolBugs{
1289 SkipNewSessionTicket: true,
1290 },
1291 },
1292 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001293 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001294 },
1295 {
1296 testType: serverTest,
1297 name: "FallbackSCSV",
1298 config: Config{
1299 MaxVersion: VersionTLS11,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 shouldFail: true,
1305 expectedError: ":INAPPROPRIATE_FALLBACK:",
1306 },
1307 {
1308 testType: serverTest,
1309 name: "FallbackSCSV-VersionMatch",
1310 config: Config{
1311 Bugs: ProtocolBugs{
1312 SendFallbackSCSV: true,
1313 },
1314 },
1315 },
1316 {
1317 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001318 name: "FallbackSCSV-VersionMatch-TLS12",
1319 config: Config{
1320 MaxVersion: VersionTLS12,
1321 Bugs: ProtocolBugs{
1322 SendFallbackSCSV: true,
1323 },
1324 },
1325 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1326 },
1327 {
1328 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001329 name: "FragmentedClientVersion",
1330 config: Config{
1331 Bugs: ProtocolBugs{
1332 MaxHandshakeRecordLength: 1,
1333 FragmentClientVersion: true,
1334 },
1335 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001336 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001337 },
1338 {
Adam Langley7c803a62015-06-15 15:35:05 -07001339 testType: serverTest,
1340 name: "HttpGET",
1341 sendPrefix: "GET / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpPOST",
1348 sendPrefix: "POST / HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTP_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "HttpHEAD",
1355 sendPrefix: "HEAD / HTTP/1.0\n",
1356 shouldFail: true,
1357 expectedError: ":HTTP_REQUEST:",
1358 },
1359 {
1360 testType: serverTest,
1361 name: "HttpPUT",
1362 sendPrefix: "PUT / HTTP/1.0\n",
1363 shouldFail: true,
1364 expectedError: ":HTTP_REQUEST:",
1365 },
1366 {
1367 testType: serverTest,
1368 name: "HttpCONNECT",
1369 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1370 shouldFail: true,
1371 expectedError: ":HTTPS_PROXY_REQUEST:",
1372 },
1373 {
1374 testType: serverTest,
1375 name: "Garbage",
1376 sendPrefix: "blah",
1377 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001378 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001379 },
1380 {
Adam Langley7c803a62015-06-15 15:35:05 -07001381 name: "RSAEphemeralKey",
1382 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001383 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001384 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1385 Bugs: ProtocolBugs{
1386 RSAEphemeralKey: true,
1387 },
1388 },
1389 shouldFail: true,
1390 expectedError: ":UNEXPECTED_MESSAGE:",
1391 },
1392 {
1393 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001394 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001395 shouldFail: true,
1396 expectedError: ":WRONG_SSL_VERSION:",
1397 },
1398 {
1399 protocol: dtls,
1400 name: "DisableEverything-DTLS",
1401 flags: []string{"-no-tls12", "-no-tls1"},
1402 shouldFail: true,
1403 expectedError: ":WRONG_SSL_VERSION:",
1404 },
1405 {
Adam Langley7c803a62015-06-15 15:35:05 -07001406 protocol: dtls,
1407 testType: serverTest,
1408 name: "MTU",
1409 config: Config{
1410 Bugs: ProtocolBugs{
1411 MaxPacketLength: 256,
1412 },
1413 },
1414 flags: []string{"-mtu", "256"},
1415 },
1416 {
1417 protocol: dtls,
1418 testType: serverTest,
1419 name: "MTUExceeded",
1420 config: Config{
1421 Bugs: ProtocolBugs{
1422 MaxPacketLength: 255,
1423 },
1424 },
1425 flags: []string{"-mtu", "256"},
1426 shouldFail: true,
1427 expectedLocalError: "dtls: exceeded maximum packet length",
1428 },
1429 {
1430 name: "CertMismatchRSA",
1431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001432 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001433 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001434 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001435 Bugs: ProtocolBugs{
1436 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1441 },
1442 {
1443 name: "CertMismatchECDSA",
1444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001445 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001446 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001447 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001448 Bugs: ProtocolBugs{
1449 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1450 },
1451 },
1452 shouldFail: true,
1453 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1454 },
1455 {
1456 name: "EmptyCertificateList",
1457 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001458 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001459 Bugs: ProtocolBugs{
1460 EmptyCertificateList: true,
1461 },
1462 },
1463 shouldFail: true,
1464 expectedError: ":DECODE_ERROR:",
1465 },
1466 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001467 name: "EmptyCertificateList-TLS13",
1468 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001469 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 Bugs: ProtocolBugs{
1471 EmptyCertificateList: true,
1472 },
1473 },
1474 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001476 },
1477 {
Adam Langley7c803a62015-06-15 15:35:05 -07001478 name: "TLSFatalBadPackets",
1479 damageFirstWrite: true,
1480 shouldFail: true,
1481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets",
1486 damageFirstWrite: true,
1487 },
1488 {
1489 protocol: dtls,
1490 name: "DTLSIgnoreBadPackets-Async",
1491 damageFirstWrite: true,
1492 flags: []string{"-async"},
1493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataBeforeHandshake",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
1505 name: "AppDataBeforeHandshake-Empty",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 AppDataBeforeHandshake: []byte{},
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AppDataBeforeHandshake-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 protocol: dtls,
1527 name: "AppDataBeforeHandshake-DTLS-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
Adam Langley7c803a62015-06-15 15:35:05 -07001537 name: "AppDataAfterChangeCipherSpec",
1538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001539 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001540 Bugs: ProtocolBugs{
1541 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001545 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001546 },
1547 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 name: "AppDataAfterChangeCipherSpec-Empty",
1549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001550 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001551 Bugs: ProtocolBugs{
1552 AppDataAfterChangeCipherSpec: []byte{},
1553 },
1554 },
1555 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001556 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 name: "AppDataAfterChangeCipherSpec-DTLS",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1565 },
1566 },
1567 // BoringSSL's DTLS implementation will drop the out-of-order
1568 // application data.
1569 },
1570 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte{},
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "AlertAfterChangeCipherSpec",
1584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 AlertAfterChangeCipherSpec: alertRecordOverflow,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1592 },
1593 {
1594 protocol: dtls,
1595 name: "AlertAfterChangeCipherSpec-DTLS",
1596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 Bugs: ProtocolBugs{
1599 AlertAfterChangeCipherSpec: alertRecordOverflow,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "ReorderHandshakeFragments-Small-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 ReorderHandshakeFragments: true,
1611 // Small enough that every handshake message is
1612 // fragmented.
1613 MaxHandshakeRecordLength: 2,
1614 },
1615 },
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Large-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Large enough that no handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2048,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "MixCompleteMessageWithFragments-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 MixCompleteMessageWithFragments: true,
1636 MaxHandshakeRecordLength: 2,
1637 },
1638 },
1639 },
1640 {
1641 name: "SendInvalidRecordType",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "SendInvalidRecordType-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 SendInvalidRecordType: true,
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
1662 name: "FalseStart-SkipServerSecondLeg",
1663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 SkipNewSessionTicket: true,
1669 SkipChangeCipherSpec: true,
1670 SkipFinished: true,
1671 ExpectFalseStart: true,
1672 },
1673 },
1674 flags: []string{
1675 "-false-start",
1676 "-handshake-never-done",
1677 "-advertise-alpn", "\x03foo",
1678 },
1679 shimWritesFirst: true,
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg-Implicit",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 },
1694 },
1695 flags: []string{
1696 "-implicit-handshake",
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shouldFail: true,
1702 expectedError: ":UNEXPECTED_RECORD:",
1703 },
1704 {
1705 testType: serverTest,
1706 name: "FailEarlyCallback",
1707 flags: []string{"-fail-early-callback"},
1708 shouldFail: true,
1709 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001710 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001711 },
1712 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001713 name: "FailCertCallback-Client-TLS12",
1714 config: Config{
1715 MaxVersion: VersionTLS12,
1716 ClientAuth: RequestClientCert,
1717 },
1718 flags: []string{"-fail-cert-callback"},
1719 shouldFail: true,
1720 expectedError: ":CERT_CB_ERROR:",
1721 expectedLocalError: "remote error: internal error",
1722 },
1723 {
1724 testType: serverTest,
1725 name: "FailCertCallback-Server-TLS12",
1726 config: Config{
1727 MaxVersion: VersionTLS12,
1728 },
1729 flags: []string{"-fail-cert-callback"},
1730 shouldFail: true,
1731 expectedError: ":CERT_CB_ERROR:",
1732 expectedLocalError: "remote error: internal error",
1733 },
1734 {
1735 name: "FailCertCallback-Client-TLS13",
1736 config: Config{
1737 MaxVersion: VersionTLS13,
1738 ClientAuth: RequestClientCert,
1739 },
1740 flags: []string{"-fail-cert-callback"},
1741 shouldFail: true,
1742 expectedError: ":CERT_CB_ERROR:",
1743 expectedLocalError: "remote error: internal error",
1744 },
1745 {
1746 testType: serverTest,
1747 name: "FailCertCallback-Server-TLS13",
1748 config: Config{
1749 MaxVersion: VersionTLS13,
1750 },
1751 flags: []string{"-fail-cert-callback"},
1752 shouldFail: true,
1753 expectedError: ":CERT_CB_ERROR:",
1754 expectedLocalError: "remote error: internal error",
1755 },
1756 {
Adam Langley7c803a62015-06-15 15:35:05 -07001757 protocol: dtls,
1758 name: "FragmentMessageTypeMismatch-DTLS",
1759 config: Config{
1760 Bugs: ProtocolBugs{
1761 MaxHandshakeRecordLength: 2,
1762 FragmentMessageTypeMismatch: true,
1763 },
1764 },
1765 shouldFail: true,
1766 expectedError: ":FRAGMENT_MISMATCH:",
1767 },
1768 {
1769 protocol: dtls,
1770 name: "FragmentMessageLengthMismatch-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 MaxHandshakeRecordLength: 2,
1774 FragmentMessageLengthMismatch: true,
1775 },
1776 },
1777 shouldFail: true,
1778 expectedError: ":FRAGMENT_MISMATCH:",
1779 },
1780 {
1781 protocol: dtls,
1782 name: "SplitFragments-Header-DTLS",
1783 config: Config{
1784 Bugs: ProtocolBugs{
1785 SplitFragments: 2,
1786 },
1787 },
1788 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001789 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001790 },
1791 {
1792 protocol: dtls,
1793 name: "SplitFragments-Boundary-DTLS",
1794 config: Config{
1795 Bugs: ProtocolBugs{
1796 SplitFragments: dtlsRecordHeaderLen,
1797 },
1798 },
1799 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001800 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001801 },
1802 {
1803 protocol: dtls,
1804 name: "SplitFragments-Body-DTLS",
1805 config: Config{
1806 Bugs: ProtocolBugs{
1807 SplitFragments: dtlsRecordHeaderLen + 1,
1808 },
1809 },
1810 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001811 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001812 },
1813 {
1814 protocol: dtls,
1815 name: "SendEmptyFragments-DTLS",
1816 config: Config{
1817 Bugs: ProtocolBugs{
1818 SendEmptyFragments: true,
1819 },
1820 },
1821 },
1822 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001823 name: "BadFinished-Client",
1824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001825 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001826 Bugs: ProtocolBugs{
1827 BadFinished: true,
1828 },
1829 },
1830 shouldFail: true,
1831 expectedError: ":DIGEST_CHECK_FAILED:",
1832 },
1833 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001834 name: "BadFinished-Client-TLS13",
1835 config: Config{
1836 MaxVersion: VersionTLS13,
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 },
1840 },
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001845 testType: serverTest,
1846 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001848 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001849 Bugs: ProtocolBugs{
1850 BadFinished: true,
1851 },
1852 },
1853 shouldFail: true,
1854 expectedError: ":DIGEST_CHECK_FAILED:",
1855 },
1856 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001857 testType: serverTest,
1858 name: "BadFinished-Server-TLS13",
1859 config: Config{
1860 MaxVersion: VersionTLS13,
1861 Bugs: ProtocolBugs{
1862 BadFinished: true,
1863 },
1864 },
1865 shouldFail: true,
1866 expectedError: ":DIGEST_CHECK_FAILED:",
1867 },
1868 {
Adam Langley7c803a62015-06-15 15:35:05 -07001869 name: "FalseStart-BadFinished",
1870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1873 NextProtos: []string{"foo"},
1874 Bugs: ProtocolBugs{
1875 BadFinished: true,
1876 ExpectFalseStart: true,
1877 },
1878 },
1879 flags: []string{
1880 "-false-start",
1881 "-handshake-never-done",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":DIGEST_CHECK_FAILED:",
1887 },
1888 {
1889 name: "NoFalseStart-NoALPN",
1890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001891 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1893 Bugs: ProtocolBugs{
1894 ExpectFalseStart: true,
1895 AlertBeforeFalseStartTest: alertAccessDenied,
1896 },
1897 },
1898 flags: []string{
1899 "-false-start",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-NoAEAD",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
1927 name: "NoFalseStart-RSA",
1928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001929 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001930 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1931 NextProtos: []string{"foo"},
1932 Bugs: ProtocolBugs{
1933 ExpectFalseStart: true,
1934 AlertBeforeFalseStartTest: alertAccessDenied,
1935 },
1936 },
1937 flags: []string{
1938 "-false-start",
1939 "-advertise-alpn", "\x03foo",
1940 },
1941 shimWritesFirst: true,
1942 shouldFail: true,
1943 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1944 expectedLocalError: "tls: peer did not false start: EOF",
1945 },
1946 {
1947 name: "NoFalseStart-DHE_RSA",
1948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001949 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001950 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1951 NextProtos: []string{"foo"},
1952 Bugs: ProtocolBugs{
1953 ExpectFalseStart: true,
1954 AlertBeforeFalseStartTest: alertAccessDenied,
1955 },
1956 },
1957 flags: []string{
1958 "-false-start",
1959 "-advertise-alpn", "\x03foo",
1960 },
1961 shimWritesFirst: true,
1962 shouldFail: true,
1963 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1964 expectedLocalError: "tls: peer did not false start: EOF",
1965 },
1966 {
Adam Langley7c803a62015-06-15 15:35:05 -07001967 protocol: dtls,
1968 name: "SendSplitAlert-Sync",
1969 config: Config{
1970 Bugs: ProtocolBugs{
1971 SendSplitAlert: true,
1972 },
1973 },
1974 },
1975 {
1976 protocol: dtls,
1977 name: "SendSplitAlert-Async",
1978 config: Config{
1979 Bugs: ProtocolBugs{
1980 SendSplitAlert: true,
1981 },
1982 },
1983 flags: []string{"-async"},
1984 },
1985 {
1986 protocol: dtls,
1987 name: "PackDTLSHandshake",
1988 config: Config{
1989 Bugs: ProtocolBugs{
1990 MaxHandshakeRecordLength: 2,
1991 PackHandshakeFragments: 20,
1992 PackHandshakeRecords: 200,
1993 },
1994 },
1995 },
1996 {
Adam Langley7c803a62015-06-15 15:35:05 -07001997 name: "SendEmptyRecords-Pass",
1998 sendEmptyRecords: 32,
1999 },
2000 {
2001 name: "SendEmptyRecords",
2002 sendEmptyRecords: 33,
2003 shouldFail: true,
2004 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2005 },
2006 {
2007 name: "SendEmptyRecords-Async",
2008 sendEmptyRecords: 33,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2012 },
2013 {
David Benjamine8e84b92016-08-03 15:39:47 -04002014 name: "SendWarningAlerts-Pass",
2015 config: Config{
2016 MaxVersion: VersionTLS12,
2017 },
Adam Langley7c803a62015-06-15 15:35:05 -07002018 sendWarningAlerts: 4,
2019 },
2020 {
David Benjamine8e84b92016-08-03 15:39:47 -04002021 protocol: dtls,
2022 name: "SendWarningAlerts-DTLS-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 name: "SendWarningAlerts-TLS13",
2030 config: Config{
2031 MaxVersion: VersionTLS13,
2032 },
2033 sendWarningAlerts: 4,
2034 shouldFail: true,
2035 expectedError: ":BAD_ALERT:",
2036 expectedLocalError: "remote error: error decoding message",
2037 },
2038 {
2039 name: "SendWarningAlerts",
2040 config: Config{
2041 MaxVersion: VersionTLS12,
2042 },
Adam Langley7c803a62015-06-15 15:35:05 -07002043 sendWarningAlerts: 5,
2044 shouldFail: true,
2045 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2046 },
2047 {
David Benjamine8e84b92016-08-03 15:39:47 -04002048 name: "SendWarningAlerts-Async",
2049 config: Config{
2050 MaxVersion: VersionTLS12,
2051 },
Adam Langley7c803a62015-06-15 15:35:05 -07002052 sendWarningAlerts: 5,
2053 flags: []string{"-async"},
2054 shouldFail: true,
2055 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2056 },
David Benjaminba4594a2015-06-18 18:36:15 -04002057 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002058 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002059 config: Config{
2060 MaxVersion: VersionTLS13,
2061 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002062 sendKeyUpdates: 33,
2063 keyUpdateRequest: keyUpdateNotRequested,
2064 shouldFail: true,
2065 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002066 },
2067 {
David Benjaminba4594a2015-06-18 18:36:15 -04002068 name: "EmptySessionID",
2069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002070 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002071 SessionTicketsDisabled: true,
2072 },
2073 noSessionCache: true,
2074 flags: []string{"-expect-no-session"},
2075 },
David Benjamin30789da2015-08-29 22:56:45 -04002076 {
2077 name: "Unclean-Shutdown",
2078 config: Config{
2079 Bugs: ProtocolBugs{
2080 NoCloseNotify: true,
2081 ExpectCloseNotify: true,
2082 },
2083 },
2084 shimShutsDown: true,
2085 flags: []string{"-check-close-notify"},
2086 shouldFail: true,
2087 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2088 },
2089 {
2090 name: "Unclean-Shutdown-Ignored",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 NoCloseNotify: true,
2094 },
2095 },
2096 shimShutsDown: true,
2097 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002098 {
David Benjaminfa214e42016-05-10 17:03:10 -04002099 name: "Unclean-Shutdown-Alert",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SendAlertOnShutdown: alertDecompressionFailure,
2103 ExpectCloseNotify: true,
2104 },
2105 },
2106 shimShutsDown: true,
2107 flags: []string{"-check-close-notify"},
2108 shouldFail: true,
2109 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2110 },
2111 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002112 name: "LargePlaintext",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendLargeRecords: true,
2116 },
2117 },
2118 messageLen: maxPlaintext + 1,
2119 shouldFail: true,
2120 expectedError: ":DATA_LENGTH_TOO_LONG:",
2121 },
2122 {
2123 protocol: dtls,
2124 name: "LargePlaintext-DTLS",
2125 config: Config{
2126 Bugs: ProtocolBugs{
2127 SendLargeRecords: true,
2128 },
2129 },
2130 messageLen: maxPlaintext + 1,
2131 shouldFail: true,
2132 expectedError: ":DATA_LENGTH_TOO_LONG:",
2133 },
2134 {
2135 name: "LargeCiphertext",
2136 config: Config{
2137 Bugs: ProtocolBugs{
2138 SendLargeRecords: true,
2139 },
2140 },
2141 messageLen: maxPlaintext * 2,
2142 shouldFail: true,
2143 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2144 },
2145 {
2146 protocol: dtls,
2147 name: "LargeCiphertext-DTLS",
2148 config: Config{
2149 Bugs: ProtocolBugs{
2150 SendLargeRecords: true,
2151 },
2152 },
2153 messageLen: maxPlaintext * 2,
2154 // Unlike the other four cases, DTLS drops records which
2155 // are invalid before authentication, so the connection
2156 // does not fail.
2157 expectMessageDropped: true,
2158 },
David Benjamindd6fed92015-10-23 17:41:12 -04002159 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002160 name: "BadHelloRequest-1",
2161 renegotiate: 1,
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002164 Bugs: ProtocolBugs{
2165 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2166 },
2167 },
2168 flags: []string{
2169 "-renegotiate-freely",
2170 "-expect-total-renegotiations", "1",
2171 },
2172 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002173 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002174 },
2175 {
2176 name: "BadHelloRequest-2",
2177 renegotiate: 1,
2178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002179 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002180 Bugs: ProtocolBugs{
2181 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2182 },
2183 },
2184 flags: []string{
2185 "-renegotiate-freely",
2186 "-expect-total-renegotiations", "1",
2187 },
2188 shouldFail: true,
2189 expectedError: ":BAD_HELLO_REQUEST:",
2190 },
David Benjaminef1b0092015-11-21 14:05:44 -05002191 {
2192 testType: serverTest,
2193 name: "SupportTicketsWithSessionID",
2194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002195 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002196 SessionTicketsDisabled: true,
2197 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002198 resumeConfig: &Config{
2199 MaxVersion: VersionTLS12,
2200 },
David Benjaminef1b0092015-11-21 14:05:44 -05002201 resumeSession: true,
2202 },
David Benjamin02edcd02016-07-27 17:40:37 -04002203 {
2204 protocol: dtls,
2205 name: "DTLS-SendExtraFinished",
2206 config: Config{
2207 Bugs: ProtocolBugs{
2208 SendExtraFinished: true,
2209 },
2210 },
2211 shouldFail: true,
2212 expectedError: ":UNEXPECTED_RECORD:",
2213 },
2214 {
2215 protocol: dtls,
2216 name: "DTLS-SendExtraFinished-Reordered",
2217 config: Config{
2218 Bugs: ProtocolBugs{
2219 MaxHandshakeRecordLength: 2,
2220 ReorderHandshakeFragments: true,
2221 SendExtraFinished: true,
2222 },
2223 },
2224 shouldFail: true,
2225 expectedError: ":UNEXPECTED_RECORD:",
2226 },
David Benjamine97fb482016-07-29 09:23:07 -04002227 {
2228 testType: serverTest,
2229 name: "V2ClientHello-EmptyRecordPrefix",
2230 config: Config{
2231 // Choose a cipher suite that does not involve
2232 // elliptic curves, so no extensions are
2233 // involved.
2234 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002235 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002236 Bugs: ProtocolBugs{
2237 SendV2ClientHello: true,
2238 },
2239 },
2240 sendPrefix: string([]byte{
2241 byte(recordTypeHandshake),
2242 3, 1, // version
2243 0, 0, // length
2244 }),
2245 // A no-op empty record may not be sent before V2ClientHello.
2246 shouldFail: true,
2247 expectedError: ":WRONG_VERSION_NUMBER:",
2248 },
2249 {
2250 testType: serverTest,
2251 name: "V2ClientHello-WarningAlertPrefix",
2252 config: Config{
2253 // Choose a cipher suite that does not involve
2254 // elliptic curves, so no extensions are
2255 // involved.
2256 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002257 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002258 Bugs: ProtocolBugs{
2259 SendV2ClientHello: true,
2260 },
2261 },
2262 sendPrefix: string([]byte{
2263 byte(recordTypeAlert),
2264 3, 1, // version
2265 0, 2, // length
2266 alertLevelWarning, byte(alertDecompressionFailure),
2267 }),
2268 // A no-op warning alert may not be sent before V2ClientHello.
2269 shouldFail: true,
2270 expectedError: ":WRONG_VERSION_NUMBER:",
2271 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002272 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002273 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002274 config: Config{
2275 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002276 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002277 sendKeyUpdates: 1,
2278 keyUpdateRequest: keyUpdateNotRequested,
2279 },
2280 {
2281 name: "KeyUpdate-InvalidRequestMode",
2282 config: Config{
2283 MaxVersion: VersionTLS13,
2284 },
2285 sendKeyUpdates: 1,
2286 keyUpdateRequest: 42,
2287 shouldFail: true,
2288 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002289 },
David Benjaminabe94e32016-09-04 14:18:58 -04002290 {
2291 name: "SendSNIWarningAlert",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendSNIWarningAlert: true,
2296 },
2297 },
2298 },
David Benjaminc241d792016-09-09 10:34:20 -04002299 {
2300 testType: serverTest,
2301 name: "ExtraCompressionMethods-TLS12",
2302 config: Config{
2303 MaxVersion: VersionTLS12,
2304 Bugs: ProtocolBugs{
2305 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2306 },
2307 },
2308 },
2309 {
2310 testType: serverTest,
2311 name: "ExtraCompressionMethods-TLS13",
2312 config: Config{
2313 MaxVersion: VersionTLS13,
2314 Bugs: ProtocolBugs{
2315 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2316 },
2317 },
2318 shouldFail: true,
2319 expectedError: ":INVALID_COMPRESSION_LIST:",
2320 expectedLocalError: "remote error: illegal parameter",
2321 },
2322 {
2323 testType: serverTest,
2324 name: "NoNullCompression-TLS12",
2325 config: Config{
2326 MaxVersion: VersionTLS12,
2327 Bugs: ProtocolBugs{
2328 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2329 },
2330 },
2331 shouldFail: true,
2332 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2333 expectedLocalError: "remote error: illegal parameter",
2334 },
2335 {
2336 testType: serverTest,
2337 name: "NoNullCompression-TLS13",
2338 config: Config{
2339 MaxVersion: VersionTLS13,
2340 Bugs: ProtocolBugs{
2341 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2342 },
2343 },
2344 shouldFail: true,
2345 expectedError: ":INVALID_COMPRESSION_LIST:",
2346 expectedLocalError: "remote error: illegal parameter",
2347 },
David Benjamin65ac9972016-09-02 21:35:25 -04002348 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002349 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002350 config: Config{
2351 MaxVersion: VersionTLS12,
2352 Bugs: ProtocolBugs{
2353 ExpectGREASE: true,
2354 },
2355 },
2356 flags: []string{"-enable-grease"},
2357 },
2358 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002359 name: "GREASE-Client-TLS13",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 Bugs: ProtocolBugs{
2363 ExpectGREASE: true,
2364 },
2365 },
2366 flags: []string{"-enable-grease"},
2367 },
2368 {
2369 testType: serverTest,
2370 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002371 config: Config{
2372 MaxVersion: VersionTLS13,
2373 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002374 // TLS 1.3 servers are expected to
2375 // always enable GREASE. TLS 1.3 is new,
2376 // so there is no existing ecosystem to
2377 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002378 ExpectGREASE: true,
2379 },
2380 },
David Benjamin65ac9972016-09-02 21:35:25 -04002381 },
Adam Langley7c803a62015-06-15 15:35:05 -07002382 }
Adam Langley7c803a62015-06-15 15:35:05 -07002383 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002384
2385 // Test that very large messages can be received.
2386 cert := rsaCertificate
2387 for i := 0; i < 50; i++ {
2388 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2389 }
2390 testCases = append(testCases, testCase{
2391 name: "LargeMessage",
2392 config: Config{
2393 Certificates: []Certificate{cert},
2394 },
2395 })
2396 testCases = append(testCases, testCase{
2397 protocol: dtls,
2398 name: "LargeMessage-DTLS",
2399 config: Config{
2400 Certificates: []Certificate{cert},
2401 },
2402 })
2403
2404 // They are rejected if the maximum certificate chain length is capped.
2405 testCases = append(testCases, testCase{
2406 name: "LargeMessage-Reject",
2407 config: Config{
2408 Certificates: []Certificate{cert},
2409 },
2410 flags: []string{"-max-cert-list", "16384"},
2411 shouldFail: true,
2412 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2413 })
2414 testCases = append(testCases, testCase{
2415 protocol: dtls,
2416 name: "LargeMessage-Reject-DTLS",
2417 config: Config{
2418 Certificates: []Certificate{cert},
2419 },
2420 flags: []string{"-max-cert-list", "16384"},
2421 shouldFail: true,
2422 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2423 })
Adam Langley7c803a62015-06-15 15:35:05 -07002424}
2425
Adam Langley95c29f32014-06-20 12:00:00 -07002426func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002427 const bogusCipher = 0xfe00
2428
Adam Langley95c29f32014-06-20 12:00:00 -07002429 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002430 const psk = "12345"
2431 const pskIdentity = "luggage combo"
2432
Adam Langley95c29f32014-06-20 12:00:00 -07002433 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002434 var certFile string
2435 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002436 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002437 cert = ecdsaP256Certificate
2438 certFile = ecdsaP256CertificateFile
2439 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002440 } else {
David Benjamin33863262016-07-08 17:20:12 -07002441 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002442 certFile = rsaCertificateFile
2443 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002444 }
2445
David Benjamin48cae082014-10-27 01:06:24 -04002446 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002447 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002448 flags = append(flags,
2449 "-psk", psk,
2450 "-psk-identity", pskIdentity)
2451 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002452 if hasComponent(suite.name, "NULL") {
2453 // NULL ciphers must be explicitly enabled.
2454 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2455 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002456 if hasComponent(suite.name, "CECPQ1") {
2457 // CECPQ1 ciphers must be explicitly enabled.
2458 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2459 }
David Benjamin881f1962016-08-10 18:29:12 -04002460 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2461 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2462 // for now.
2463 flags = append(flags, "-cipher", suite.name)
2464 }
David Benjamin48cae082014-10-27 01:06:24 -04002465
Adam Langley95c29f32014-06-20 12:00:00 -07002466 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002467 for _, protocol := range []protocol{tls, dtls} {
2468 var prefix string
2469 if protocol == dtls {
2470 if !ver.hasDTLS {
2471 continue
2472 }
2473 prefix = "D"
2474 }
Adam Langley95c29f32014-06-20 12:00:00 -07002475
David Benjamin0407e762016-06-17 16:41:18 -04002476 var shouldServerFail, shouldClientFail bool
2477 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2478 // BoringSSL clients accept ECDHE on SSLv3, but
2479 // a BoringSSL server will never select it
2480 // because the extension is missing.
2481 shouldServerFail = true
2482 }
2483 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2484 shouldClientFail = true
2485 shouldServerFail = true
2486 }
David Benjamin54c217c2016-07-13 12:35:25 -04002487 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 shouldClientFail = true
2489 shouldServerFail = true
2490 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002491 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2492 shouldClientFail = true
2493 shouldServerFail = true
2494 }
David Benjamin0407e762016-06-17 16:41:18 -04002495 if !isDTLSCipher(suite.name) && protocol == dtls {
2496 shouldClientFail = true
2497 shouldServerFail = true
2498 }
David Benjamin4298d772015-12-19 00:18:25 -05002499
David Benjamin5ecb88b2016-10-04 17:51:35 -04002500 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002501 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002502 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002503 if shouldServerFail {
2504 expectedServerError = ":NO_SHARED_CIPHER:"
2505 }
2506 if shouldClientFail {
2507 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002508 // Configure the server to select ciphers as normal but
2509 // select an incompatible cipher in ServerHello.
2510 serverCipherSuites = nil
2511 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002512 }
David Benjamin025b3d32014-07-01 19:53:04 -04002513
David Benjamin6fd297b2014-08-11 18:43:38 -04002514 testCases = append(testCases, testCase{
2515 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002516 protocol: protocol,
2517
2518 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002519 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002520 MinVersion: ver.version,
2521 MaxVersion: ver.version,
2522 CipherSuites: []uint16{suite.id},
2523 Certificates: []Certificate{cert},
2524 PreSharedKey: []byte(psk),
2525 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002526 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002527 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002528 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002529 },
2530 certFile: certFile,
2531 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002532 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002533 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002534 shouldFail: shouldServerFail,
2535 expectedError: expectedServerError,
2536 })
2537
2538 testCases = append(testCases, testCase{
2539 testType: clientTest,
2540 protocol: protocol,
2541 name: prefix + ver.name + "-" + suite.name + "-client",
2542 config: Config{
2543 MinVersion: ver.version,
2544 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002545 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002546 Certificates: []Certificate{cert},
2547 PreSharedKey: []byte(psk),
2548 PreSharedKeyIdentity: pskIdentity,
2549 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002550 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002551 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002552 },
2553 },
2554 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002555 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002556 shouldFail: shouldClientFail,
2557 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002558 })
David Benjamin2c99d282015-09-01 10:23:00 -04002559
Nick Harper1fd39d82016-06-14 18:14:35 -07002560 if !shouldClientFail {
2561 // Ensure the maximum record size is accepted.
2562 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002563 protocol: protocol,
2564 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002565 config: Config{
2566 MinVersion: ver.version,
2567 MaxVersion: ver.version,
2568 CipherSuites: []uint16{suite.id},
2569 Certificates: []Certificate{cert},
2570 PreSharedKey: []byte(psk),
2571 PreSharedKeyIdentity: pskIdentity,
2572 },
2573 flags: flags,
2574 messageLen: maxPlaintext,
2575 })
David Benjamin231a4752016-11-10 10:46:00 -05002576
2577 // Test bad records for all ciphers. Bad records are fatal in TLS
2578 // and ignored in DTLS.
2579 var shouldFail bool
2580 var expectedError string
2581 if protocol == tls {
2582 shouldFail = true
2583 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2584 }
2585
2586 testCases = append(testCases, testCase{
2587 protocol: protocol,
2588 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2589 config: Config{
2590 MinVersion: ver.version,
2591 MaxVersion: ver.version,
2592 CipherSuites: []uint16{suite.id},
2593 Certificates: []Certificate{cert},
2594 PreSharedKey: []byte(psk),
2595 PreSharedKeyIdentity: pskIdentity,
2596 },
2597 flags: flags,
2598 damageFirstWrite: true,
2599 messageLen: maxPlaintext,
2600 shouldFail: shouldFail,
2601 expectedError: expectedError,
2602 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002603 }
2604 }
David Benjamin2c99d282015-09-01 10:23:00 -04002605 }
Adam Langley95c29f32014-06-20 12:00:00 -07002606 }
Adam Langleya7997f12015-05-14 17:38:50 -07002607
2608 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002609 name: "NoSharedCipher",
2610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002611 MaxVersion: VersionTLS12,
2612 CipherSuites: []uint16{},
2613 },
2614 shouldFail: true,
2615 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2616 })
2617
2618 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002619 name: "NoSharedCipher-TLS13",
2620 config: Config{
2621 MaxVersion: VersionTLS13,
2622 CipherSuites: []uint16{},
2623 },
2624 shouldFail: true,
2625 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2626 })
2627
2628 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002629 name: "UnsupportedCipherSuite",
2630 config: Config{
2631 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002632 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002633 Bugs: ProtocolBugs{
2634 IgnorePeerCipherPreferences: true,
2635 },
2636 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002637 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002638 shouldFail: true,
2639 expectedError: ":WRONG_CIPHER_RETURNED:",
2640 })
2641
2642 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002643 name: "ServerHelloBogusCipher",
2644 config: Config{
2645 MaxVersion: VersionTLS12,
2646 Bugs: ProtocolBugs{
2647 SendCipherSuite: bogusCipher,
2648 },
2649 },
2650 shouldFail: true,
2651 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2652 })
2653 testCases = append(testCases, testCase{
2654 name: "ServerHelloBogusCipher-TLS13",
2655 config: Config{
2656 MaxVersion: VersionTLS13,
2657 Bugs: ProtocolBugs{
2658 SendCipherSuite: bogusCipher,
2659 },
2660 },
2661 shouldFail: true,
2662 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2663 })
2664
2665 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002666 name: "WeakDH",
2667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002668 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002669 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2670 Bugs: ProtocolBugs{
2671 // This is a 1023-bit prime number, generated
2672 // with:
2673 // openssl gendh 1023 | openssl asn1parse -i
2674 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2675 },
2676 },
2677 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002678 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002679 })
Adam Langleycef75832015-09-03 14:51:12 -07002680
David Benjamincd24a392015-11-11 13:23:05 -08002681 testCases = append(testCases, testCase{
2682 name: "SillyDH",
2683 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002684 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002685 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2686 Bugs: ProtocolBugs{
2687 // This is a 4097-bit prime number, generated
2688 // with:
2689 // openssl gendh 4097 | openssl asn1parse -i
2690 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2691 },
2692 },
2693 shouldFail: true,
2694 expectedError: ":DH_P_TOO_LONG:",
2695 })
2696
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002697 // This test ensures that Diffie-Hellman public values are padded with
2698 // zeros so that they're the same length as the prime. This is to avoid
2699 // hitting a bug in yaSSL.
2700 testCases = append(testCases, testCase{
2701 testType: serverTest,
2702 name: "DHPublicValuePadded",
2703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002704 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002705 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2706 Bugs: ProtocolBugs{
2707 RequireDHPublicValueLen: (1025 + 7) / 8,
2708 },
2709 },
2710 flags: []string{"-use-sparse-dh-prime"},
2711 })
David Benjamincd24a392015-11-11 13:23:05 -08002712
David Benjamin241ae832016-01-15 03:04:54 -05002713 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002714 testCases = append(testCases, testCase{
2715 testType: serverTest,
2716 name: "UnknownCipher",
2717 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002718 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002719 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002720 Bugs: ProtocolBugs{
2721 AdvertiseAllConfiguredCiphers: true,
2722 },
2723 },
2724 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002725
2726 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002727 testCases = append(testCases, testCase{
2728 testType: serverTest,
2729 name: "UnknownCipher-TLS13",
2730 config: Config{
2731 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002732 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002733 Bugs: ProtocolBugs{
2734 AdvertiseAllConfiguredCiphers: true,
2735 },
David Benjamin241ae832016-01-15 03:04:54 -05002736 },
2737 })
2738
David Benjamin78679342016-09-16 19:42:05 -04002739 // Test empty ECDHE_PSK identity hints work as expected.
2740 testCases = append(testCases, testCase{
2741 name: "EmptyECDHEPSKHint",
2742 config: Config{
2743 MaxVersion: VersionTLS12,
2744 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2745 PreSharedKey: []byte("secret"),
2746 },
2747 flags: []string{"-psk", "secret"},
2748 })
2749
2750 // Test empty PSK identity hints work as expected, even if an explicit
2751 // ServerKeyExchange is sent.
2752 testCases = append(testCases, testCase{
2753 name: "ExplicitEmptyPSKHint",
2754 config: Config{
2755 MaxVersion: VersionTLS12,
2756 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2757 PreSharedKey: []byte("secret"),
2758 Bugs: ProtocolBugs{
2759 AlwaysSendPreSharedKeyIdentityHint: true,
2760 },
2761 },
2762 flags: []string{"-psk", "secret"},
2763 })
2764
Adam Langleycef75832015-09-03 14:51:12 -07002765 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2766 // 1.1 specific cipher suite settings. A server is setup with the given
2767 // cipher lists and then a connection is made for each member of
2768 // expectations. The cipher suite that the server selects must match
2769 // the specified one.
2770 var versionSpecificCiphersTest = []struct {
2771 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2772 // expectations is a map from TLS version to cipher suite id.
2773 expectations map[uint16]uint16
2774 }{
2775 {
2776 // Test that the null case (where no version-specific ciphers are set)
2777 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002778 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2779 "", // no ciphers specifically for TLS ≥ 1.0
2780 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002781 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002782 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2783 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2784 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2785 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002786 },
2787 },
2788 {
2789 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2790 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002791 "DES-CBC3-SHA:AES128-SHA", // default
2792 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2793 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002794 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002795 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002796 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2797 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2798 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2799 },
2800 },
2801 {
2802 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2803 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002804 "DES-CBC3-SHA:AES128-SHA", // default
2805 "", // no ciphers specifically for TLS ≥ 1.0
2806 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002807 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002808 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2809 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002810 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2811 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2812 },
2813 },
2814 {
2815 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2816 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002817 "DES-CBC3-SHA:AES128-SHA", // default
2818 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2819 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002820 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002821 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002822 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2823 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2824 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2825 },
2826 },
2827 }
2828
2829 for i, test := range versionSpecificCiphersTest {
2830 for version, expectedCipherSuite := range test.expectations {
2831 flags := []string{"-cipher", test.ciphersDefault}
2832 if len(test.ciphersTLS10) > 0 {
2833 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2834 }
2835 if len(test.ciphersTLS11) > 0 {
2836 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2837 }
2838
2839 testCases = append(testCases, testCase{
2840 testType: serverTest,
2841 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2842 config: Config{
2843 MaxVersion: version,
2844 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002845 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 -07002846 },
2847 flags: flags,
2848 expectedCipher: expectedCipherSuite,
2849 })
2850 }
2851 }
Adam Langley95c29f32014-06-20 12:00:00 -07002852}
2853
2854func addBadECDSASignatureTests() {
2855 for badR := BadValue(1); badR < NumBadValues; badR++ {
2856 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002857 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002858 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2859 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002860 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002861 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002862 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002863 Bugs: ProtocolBugs{
2864 BadECDSAR: badR,
2865 BadECDSAS: badS,
2866 },
2867 },
2868 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002869 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002870 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002871 testCases = append(testCases, testCase{
2872 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2873 config: Config{
2874 MaxVersion: VersionTLS13,
2875 Certificates: []Certificate{ecdsaP256Certificate},
2876 Bugs: ProtocolBugs{
2877 BadECDSAR: badR,
2878 BadECDSAS: badS,
2879 },
2880 },
2881 shouldFail: true,
2882 expectedError: ":BAD_SIGNATURE:",
2883 })
Adam Langley95c29f32014-06-20 12:00:00 -07002884 }
2885 }
2886}
2887
Adam Langley80842bd2014-06-20 12:00:00 -07002888func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002889 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002890 name: "MaxCBCPadding",
2891 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002892 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2894 Bugs: ProtocolBugs{
2895 MaxPadding: true,
2896 },
2897 },
2898 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2899 })
David Benjamin025b3d32014-07-01 19:53:04 -04002900 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002901 name: "BadCBCPadding",
2902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002903 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2905 Bugs: ProtocolBugs{
2906 PaddingFirstByteBad: true,
2907 },
2908 },
2909 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002910 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002911 })
2912 // OpenSSL previously had an issue where the first byte of padding in
2913 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002914 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002915 name: "BadCBCPadding255",
2916 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002917 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2919 Bugs: ProtocolBugs{
2920 MaxPadding: true,
2921 PaddingFirstByteBadIf255: true,
2922 },
2923 },
2924 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2925 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002926 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002927 })
2928}
2929
Kenny Root7fdeaf12014-08-05 15:23:37 -07002930func addCBCSplittingTests() {
2931 testCases = append(testCases, testCase{
2932 name: "CBCRecordSplitting",
2933 config: Config{
2934 MaxVersion: VersionTLS10,
2935 MinVersion: VersionTLS10,
2936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2937 },
David Benjaminac8302a2015-09-01 17:18:15 -04002938 messageLen: -1, // read until EOF
2939 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002940 flags: []string{
2941 "-async",
2942 "-write-different-record-sizes",
2943 "-cbc-record-splitting",
2944 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002945 })
2946 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002947 name: "CBCRecordSplittingPartialWrite",
2948 config: Config{
2949 MaxVersion: VersionTLS10,
2950 MinVersion: VersionTLS10,
2951 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2952 },
2953 messageLen: -1, // read until EOF
2954 flags: []string{
2955 "-async",
2956 "-write-different-record-sizes",
2957 "-cbc-record-splitting",
2958 "-partial-write",
2959 },
2960 })
2961}
2962
David Benjamin636293b2014-07-08 17:59:18 -04002963func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002964 // Add a dummy cert pool to stress certificate authority parsing.
2965 // TODO(davidben): Add tests that those values parse out correctly.
2966 certPool := x509.NewCertPool()
2967 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2968 if err != nil {
2969 panic(err)
2970 }
2971 certPool.AddCert(cert)
2972
David Benjamin636293b2014-07-08 17:59:18 -04002973 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002974 testCases = append(testCases, testCase{
2975 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002976 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002977 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002978 MinVersion: ver.version,
2979 MaxVersion: ver.version,
2980 ClientAuth: RequireAnyClientCert,
2981 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002982 },
2983 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002984 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2985 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002986 },
2987 })
2988 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002989 testType: serverTest,
2990 name: ver.name + "-Server-ClientAuth-RSA",
2991 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002992 MinVersion: ver.version,
2993 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002994 Certificates: []Certificate{rsaCertificate},
2995 },
2996 flags: []string{"-require-any-client-certificate"},
2997 })
David Benjamine098ec22014-08-27 23:13:20 -04002998 if ver.version != VersionSSL30 {
2999 testCases = append(testCases, testCase{
3000 testType: serverTest,
3001 name: ver.name + "-Server-ClientAuth-ECDSA",
3002 config: Config{
3003 MinVersion: ver.version,
3004 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003005 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003006 },
3007 flags: []string{"-require-any-client-certificate"},
3008 })
3009 testCases = append(testCases, testCase{
3010 testType: clientTest,
3011 name: ver.name + "-Client-ClientAuth-ECDSA",
3012 config: Config{
3013 MinVersion: ver.version,
3014 MaxVersion: ver.version,
3015 ClientAuth: RequireAnyClientCert,
3016 ClientCAs: certPool,
3017 },
3018 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003019 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3020 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003021 },
3022 })
3023 }
Adam Langley37646832016-08-01 16:16:46 -07003024
3025 testCases = append(testCases, testCase{
3026 name: "NoClientCertificate-" + ver.name,
3027 config: Config{
3028 MinVersion: ver.version,
3029 MaxVersion: ver.version,
3030 ClientAuth: RequireAnyClientCert,
3031 },
3032 shouldFail: true,
3033 expectedLocalError: "client didn't provide a certificate",
3034 })
3035
3036 testCases = append(testCases, testCase{
3037 // Even if not configured to expect a certificate, OpenSSL will
3038 // return X509_V_OK as the verify_result.
3039 testType: serverTest,
3040 name: "NoClientCertificateRequested-Server-" + ver.name,
3041 config: Config{
3042 MinVersion: ver.version,
3043 MaxVersion: ver.version,
3044 },
3045 flags: []string{
3046 "-expect-verify-result",
3047 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003048 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003049 })
3050
3051 testCases = append(testCases, testCase{
3052 // If a client certificate is not provided, OpenSSL will still
3053 // return X509_V_OK as the verify_result.
3054 testType: serverTest,
3055 name: "NoClientCertificate-Server-" + ver.name,
3056 config: Config{
3057 MinVersion: ver.version,
3058 MaxVersion: ver.version,
3059 },
3060 flags: []string{
3061 "-expect-verify-result",
3062 "-verify-peer",
3063 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003064 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003065 })
3066
David Benjamin1db9e1b2016-10-07 20:51:43 -04003067 certificateRequired := "remote error: certificate required"
3068 if ver.version < VersionTLS13 {
3069 // Prior to TLS 1.3, the generic handshake_failure alert
3070 // was used.
3071 certificateRequired = "remote error: handshake failure"
3072 }
Adam Langley37646832016-08-01 16:16:46 -07003073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "RequireAnyClientCertificate-" + ver.name,
3076 config: Config{
3077 MinVersion: ver.version,
3078 MaxVersion: ver.version,
3079 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003080 flags: []string{"-require-any-client-certificate"},
3081 shouldFail: true,
3082 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3083 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003084 })
3085
3086 if ver.version != VersionSSL30 {
3087 testCases = append(testCases, testCase{
3088 testType: serverTest,
3089 name: "SkipClientCertificate-" + ver.name,
3090 config: Config{
3091 MinVersion: ver.version,
3092 MaxVersion: ver.version,
3093 Bugs: ProtocolBugs{
3094 SkipClientCertificate: true,
3095 },
3096 },
3097 // Setting SSL_VERIFY_PEER allows anonymous clients.
3098 flags: []string{"-verify-peer"},
3099 shouldFail: true,
3100 expectedError: ":UNEXPECTED_MESSAGE:",
3101 })
3102 }
David Benjamin636293b2014-07-08 17:59:18 -04003103 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003104
David Benjaminc032dfa2016-05-12 14:54:57 -04003105 // Client auth is only legal in certificate-based ciphers.
3106 testCases = append(testCases, testCase{
3107 testType: clientTest,
3108 name: "ClientAuth-PSK",
3109 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003110 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003111 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3112 PreSharedKey: []byte("secret"),
3113 ClientAuth: RequireAnyClientCert,
3114 },
3115 flags: []string{
3116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3118 "-psk", "secret",
3119 },
3120 shouldFail: true,
3121 expectedError: ":UNEXPECTED_MESSAGE:",
3122 })
3123 testCases = append(testCases, testCase{
3124 testType: clientTest,
3125 name: "ClientAuth-ECDHE_PSK",
3126 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003127 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003128 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3129 PreSharedKey: []byte("secret"),
3130 ClientAuth: RequireAnyClientCert,
3131 },
3132 flags: []string{
3133 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3134 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3135 "-psk", "secret",
3136 },
3137 shouldFail: true,
3138 expectedError: ":UNEXPECTED_MESSAGE:",
3139 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003140
3141 // Regression test for a bug where the client CA list, if explicitly
3142 // set to NULL, was mis-encoded.
3143 testCases = append(testCases, testCase{
3144 testType: serverTest,
3145 name: "Null-Client-CA-List",
3146 config: Config{
3147 MaxVersion: VersionTLS12,
3148 Certificates: []Certificate{rsaCertificate},
3149 },
3150 flags: []string{
3151 "-require-any-client-certificate",
3152 "-use-null-client-ca-list",
3153 },
3154 })
David Benjamin636293b2014-07-08 17:59:18 -04003155}
3156
Adam Langley75712922014-10-10 16:23:43 -07003157func addExtendedMasterSecretTests() {
3158 const expectEMSFlag = "-expect-extended-master-secret"
3159
3160 for _, with := range []bool{false, true} {
3161 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003162 if with {
3163 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003164 }
3165
3166 for _, isClient := range []bool{false, true} {
3167 suffix := "-Server"
3168 testType := serverTest
3169 if isClient {
3170 suffix = "-Client"
3171 testType = clientTest
3172 }
3173
3174 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003175 // In TLS 1.3, the extension is irrelevant and
3176 // always reports as enabled.
3177 var flags []string
3178 if with || ver.version >= VersionTLS13 {
3179 flags = []string{expectEMSFlag}
3180 }
3181
Adam Langley75712922014-10-10 16:23:43 -07003182 test := testCase{
3183 testType: testType,
3184 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3185 config: Config{
3186 MinVersion: ver.version,
3187 MaxVersion: ver.version,
3188 Bugs: ProtocolBugs{
3189 NoExtendedMasterSecret: !with,
3190 RequireExtendedMasterSecret: with,
3191 },
3192 },
David Benjamin48cae082014-10-27 01:06:24 -04003193 flags: flags,
3194 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003195 }
3196 if test.shouldFail {
3197 test.expectedLocalError = "extended master secret required but not supported by peer"
3198 }
3199 testCases = append(testCases, test)
3200 }
3201 }
3202 }
3203
Adam Langleyba5934b2015-06-02 10:50:35 -07003204 for _, isClient := range []bool{false, true} {
3205 for _, supportedInFirstConnection := range []bool{false, true} {
3206 for _, supportedInResumeConnection := range []bool{false, true} {
3207 boolToWord := func(b bool) string {
3208 if b {
3209 return "Yes"
3210 }
3211 return "No"
3212 }
3213 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3214 if isClient {
3215 suffix += "Client"
3216 } else {
3217 suffix += "Server"
3218 }
3219
3220 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003221 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003222 Bugs: ProtocolBugs{
3223 RequireExtendedMasterSecret: true,
3224 },
3225 }
3226
3227 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003228 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003229 Bugs: ProtocolBugs{
3230 NoExtendedMasterSecret: true,
3231 },
3232 }
3233
3234 test := testCase{
3235 name: "ExtendedMasterSecret-" + suffix,
3236 resumeSession: true,
3237 }
3238
3239 if !isClient {
3240 test.testType = serverTest
3241 }
3242
3243 if supportedInFirstConnection {
3244 test.config = supportedConfig
3245 } else {
3246 test.config = noSupportConfig
3247 }
3248
3249 if supportedInResumeConnection {
3250 test.resumeConfig = &supportedConfig
3251 } else {
3252 test.resumeConfig = &noSupportConfig
3253 }
3254
3255 switch suffix {
3256 case "YesToYes-Client", "YesToYes-Server":
3257 // When a session is resumed, it should
3258 // still be aware that its master
3259 // secret was generated via EMS and
3260 // thus it's safe to use tls-unique.
3261 test.flags = []string{expectEMSFlag}
3262 case "NoToYes-Server":
3263 // If an original connection did not
3264 // contain EMS, but a resumption
3265 // handshake does, then a server should
3266 // not resume the session.
3267 test.expectResumeRejected = true
3268 case "YesToNo-Server":
3269 // Resuming an EMS session without the
3270 // EMS extension should cause the
3271 // server to abort the connection.
3272 test.shouldFail = true
3273 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3274 case "NoToYes-Client":
3275 // A client should abort a connection
3276 // where the server resumed a non-EMS
3277 // session but echoed the EMS
3278 // extension.
3279 test.shouldFail = true
3280 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3281 case "YesToNo-Client":
3282 // A client should abort a connection
3283 // where the server didn't echo EMS
3284 // when the session used it.
3285 test.shouldFail = true
3286 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3287 }
3288
3289 testCases = append(testCases, test)
3290 }
3291 }
3292 }
David Benjamin163c9562016-08-29 23:14:17 -04003293
3294 // Switching EMS on renegotiation is forbidden.
3295 testCases = append(testCases, testCase{
3296 name: "ExtendedMasterSecret-Renego-NoEMS",
3297 config: Config{
3298 MaxVersion: VersionTLS12,
3299 Bugs: ProtocolBugs{
3300 NoExtendedMasterSecret: true,
3301 NoExtendedMasterSecretOnRenegotiation: true,
3302 },
3303 },
3304 renegotiate: 1,
3305 flags: []string{
3306 "-renegotiate-freely",
3307 "-expect-total-renegotiations", "1",
3308 },
3309 })
3310
3311 testCases = append(testCases, testCase{
3312 name: "ExtendedMasterSecret-Renego-Upgrade",
3313 config: Config{
3314 MaxVersion: VersionTLS12,
3315 Bugs: ProtocolBugs{
3316 NoExtendedMasterSecret: true,
3317 },
3318 },
3319 renegotiate: 1,
3320 flags: []string{
3321 "-renegotiate-freely",
3322 "-expect-total-renegotiations", "1",
3323 },
3324 shouldFail: true,
3325 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3326 })
3327
3328 testCases = append(testCases, testCase{
3329 name: "ExtendedMasterSecret-Renego-Downgrade",
3330 config: Config{
3331 MaxVersion: VersionTLS12,
3332 Bugs: ProtocolBugs{
3333 NoExtendedMasterSecretOnRenegotiation: true,
3334 },
3335 },
3336 renegotiate: 1,
3337 flags: []string{
3338 "-renegotiate-freely",
3339 "-expect-total-renegotiations", "1",
3340 },
3341 shouldFail: true,
3342 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3343 })
Adam Langley75712922014-10-10 16:23:43 -07003344}
3345
David Benjamin582ba042016-07-07 12:33:25 -07003346type stateMachineTestConfig struct {
3347 protocol protocol
3348 async bool
3349 splitHandshake, packHandshakeFlight bool
3350}
3351
David Benjamin43ec06f2014-08-05 02:28:57 -04003352// Adds tests that try to cover the range of the handshake state machine, under
3353// various conditions. Some of these are redundant with other tests, but they
3354// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003355func addAllStateMachineCoverageTests() {
3356 for _, async := range []bool{false, true} {
3357 for _, protocol := range []protocol{tls, dtls} {
3358 addStateMachineCoverageTests(stateMachineTestConfig{
3359 protocol: protocol,
3360 async: async,
3361 })
3362 addStateMachineCoverageTests(stateMachineTestConfig{
3363 protocol: protocol,
3364 async: async,
3365 splitHandshake: true,
3366 })
3367 if protocol == tls {
3368 addStateMachineCoverageTests(stateMachineTestConfig{
3369 protocol: protocol,
3370 async: async,
3371 packHandshakeFlight: true,
3372 })
3373 }
3374 }
3375 }
3376}
3377
3378func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003379 var tests []testCase
3380
3381 // Basic handshake, with resumption. Client and server,
3382 // session ID and session ticket.
3383 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003384 name: "Basic-Client",
3385 config: Config{
3386 MaxVersion: VersionTLS12,
3387 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003389 // Ensure session tickets are used, not session IDs.
3390 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 })
3392 tests = append(tests, testCase{
3393 name: "Basic-Client-RenewTicket",
3394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003395 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003396 Bugs: ProtocolBugs{
3397 RenewTicketOnResume: true,
3398 },
3399 },
David Benjamin46662482016-08-17 00:51:00 -04003400 flags: []string{"-expect-ticket-renewal"},
3401 resumeSession: true,
3402 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003403 })
3404 tests = append(tests, testCase{
3405 name: "Basic-Client-NoTicket",
3406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003408 SessionTicketsDisabled: true,
3409 },
3410 resumeSession: true,
3411 })
3412 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003413 name: "Basic-Client-Implicit",
3414 config: Config{
3415 MaxVersion: VersionTLS12,
3416 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003417 flags: []string{"-implicit-handshake"},
3418 resumeSession: true,
3419 })
3420 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003421 testType: serverTest,
3422 name: "Basic-Server",
3423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003425 Bugs: ProtocolBugs{
3426 RequireSessionTickets: true,
3427 },
3428 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003429 resumeSession: true,
3430 })
3431 tests = append(tests, testCase{
3432 testType: serverTest,
3433 name: "Basic-Server-NoTickets",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003436 SessionTicketsDisabled: true,
3437 },
3438 resumeSession: true,
3439 })
3440 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003441 testType: serverTest,
3442 name: "Basic-Server-Implicit",
3443 config: Config{
3444 MaxVersion: VersionTLS12,
3445 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003446 flags: []string{"-implicit-handshake"},
3447 resumeSession: true,
3448 })
3449 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003450 testType: serverTest,
3451 name: "Basic-Server-EarlyCallback",
3452 config: Config{
3453 MaxVersion: VersionTLS12,
3454 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003455 flags: []string{"-use-early-callback"},
3456 resumeSession: true,
3457 })
3458
Steven Valdez143e8b32016-07-11 13:19:03 -04003459 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003460 if config.protocol == tls {
3461 tests = append(tests, testCase{
3462 name: "TLS13-1RTT-Client",
3463 config: Config{
3464 MaxVersion: VersionTLS13,
3465 MinVersion: VersionTLS13,
3466 },
David Benjamin46662482016-08-17 00:51:00 -04003467 resumeSession: true,
3468 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003469 })
3470
3471 tests = append(tests, testCase{
3472 testType: serverTest,
3473 name: "TLS13-1RTT-Server",
3474 config: Config{
3475 MaxVersion: VersionTLS13,
3476 MinVersion: VersionTLS13,
3477 },
David Benjamin46662482016-08-17 00:51:00 -04003478 resumeSession: true,
3479 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003480 })
3481
3482 tests = append(tests, testCase{
3483 name: "TLS13-HelloRetryRequest-Client",
3484 config: Config{
3485 MaxVersion: VersionTLS13,
3486 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003487 // P-384 requires a HelloRetryRequest against BoringSSL's default
3488 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003489 CurvePreferences: []CurveID{CurveP384},
3490 Bugs: ProtocolBugs{
3491 ExpectMissingKeyShare: true,
3492 },
3493 },
3494 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3495 resumeSession: true,
3496 })
3497
3498 tests = append(tests, testCase{
3499 testType: serverTest,
3500 name: "TLS13-HelloRetryRequest-Server",
3501 config: Config{
3502 MaxVersion: VersionTLS13,
3503 MinVersion: VersionTLS13,
3504 // Require a HelloRetryRequest for every curve.
3505 DefaultCurves: []CurveID{},
3506 },
3507 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3508 resumeSession: true,
3509 })
3510 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003511
David Benjamin760b1dd2015-05-15 23:33:48 -04003512 // TLS client auth.
3513 tests = append(tests, testCase{
3514 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003515 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003517 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003518 ClientAuth: RequestClientCert,
3519 },
3520 })
3521 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003522 testType: serverTest,
3523 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003524 config: Config{
3525 MaxVersion: VersionTLS12,
3526 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003527 // Setting SSL_VERIFY_PEER allows anonymous clients.
3528 flags: []string{"-verify-peer"},
3529 })
David Benjamin582ba042016-07-07 12:33:25 -07003530 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003531 tests = append(tests, testCase{
3532 testType: clientTest,
3533 name: "ClientAuth-NoCertificate-Client-SSL3",
3534 config: Config{
3535 MaxVersion: VersionSSL30,
3536 ClientAuth: RequestClientCert,
3537 },
3538 })
3539 tests = append(tests, testCase{
3540 testType: serverTest,
3541 name: "ClientAuth-NoCertificate-Server-SSL3",
3542 config: Config{
3543 MaxVersion: VersionSSL30,
3544 },
3545 // Setting SSL_VERIFY_PEER allows anonymous clients.
3546 flags: []string{"-verify-peer"},
3547 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003548 tests = append(tests, testCase{
3549 testType: clientTest,
3550 name: "ClientAuth-NoCertificate-Client-TLS13",
3551 config: Config{
3552 MaxVersion: VersionTLS13,
3553 ClientAuth: RequestClientCert,
3554 },
3555 })
3556 tests = append(tests, testCase{
3557 testType: serverTest,
3558 name: "ClientAuth-NoCertificate-Server-TLS13",
3559 config: Config{
3560 MaxVersion: VersionTLS13,
3561 },
3562 // Setting SSL_VERIFY_PEER allows anonymous clients.
3563 flags: []string{"-verify-peer"},
3564 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003565 }
3566 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003567 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003568 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003570 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003571 ClientAuth: RequireAnyClientCert,
3572 },
3573 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003574 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3575 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003576 },
3577 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003578 tests = append(tests, testCase{
3579 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003580 name: "ClientAuth-RSA-Client-TLS13",
3581 config: Config{
3582 MaxVersion: VersionTLS13,
3583 ClientAuth: RequireAnyClientCert,
3584 },
3585 flags: []string{
3586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3588 },
3589 })
3590 tests = append(tests, testCase{
3591 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003592 name: "ClientAuth-ECDSA-Client",
3593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003594 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003595 ClientAuth: RequireAnyClientCert,
3596 },
3597 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003598 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3599 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003600 },
3601 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003602 tests = append(tests, testCase{
3603 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003604 name: "ClientAuth-ECDSA-Client-TLS13",
3605 config: Config{
3606 MaxVersion: VersionTLS13,
3607 ClientAuth: RequireAnyClientCert,
3608 },
3609 flags: []string{
3610 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3611 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3612 },
3613 })
3614 tests = append(tests, testCase{
3615 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003616 name: "ClientAuth-NoCertificate-OldCallback",
3617 config: Config{
3618 MaxVersion: VersionTLS12,
3619 ClientAuth: RequestClientCert,
3620 },
3621 flags: []string{"-use-old-client-cert-callback"},
3622 })
3623 tests = append(tests, testCase{
3624 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003625 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 ClientAuth: RequestClientCert,
3629 },
3630 flags: []string{"-use-old-client-cert-callback"},
3631 })
3632 tests = append(tests, testCase{
3633 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003634 name: "ClientAuth-OldCallback",
3635 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003636 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003637 ClientAuth: RequireAnyClientCert,
3638 },
3639 flags: []string{
3640 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3641 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3642 "-use-old-client-cert-callback",
3643 },
3644 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003645 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003646 testType: clientTest,
3647 name: "ClientAuth-OldCallback-TLS13",
3648 config: Config{
3649 MaxVersion: VersionTLS13,
3650 ClientAuth: RequireAnyClientCert,
3651 },
3652 flags: []string{
3653 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3654 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3655 "-use-old-client-cert-callback",
3656 },
3657 })
3658 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003659 testType: serverTest,
3660 name: "ClientAuth-Server",
3661 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003662 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003663 Certificates: []Certificate{rsaCertificate},
3664 },
3665 flags: []string{"-require-any-client-certificate"},
3666 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003667 tests = append(tests, testCase{
3668 testType: serverTest,
3669 name: "ClientAuth-Server-TLS13",
3670 config: Config{
3671 MaxVersion: VersionTLS13,
3672 Certificates: []Certificate{rsaCertificate},
3673 },
3674 flags: []string{"-require-any-client-certificate"},
3675 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003676
David Benjamin4c3ddf72016-06-29 18:13:53 -04003677 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003678 tests = append(tests, testCase{
3679 testType: serverTest,
3680 name: "Basic-Server-RSA",
3681 config: Config{
3682 MaxVersion: VersionTLS12,
3683 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3684 },
3685 flags: []string{
3686 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3687 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3688 },
3689 })
3690 tests = append(tests, testCase{
3691 testType: serverTest,
3692 name: "Basic-Server-ECDHE-RSA",
3693 config: Config{
3694 MaxVersion: VersionTLS12,
3695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3696 },
3697 flags: []string{
3698 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3699 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3700 },
3701 })
3702 tests = append(tests, testCase{
3703 testType: serverTest,
3704 name: "Basic-Server-ECDHE-ECDSA",
3705 config: Config{
3706 MaxVersion: VersionTLS12,
3707 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3708 },
3709 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003710 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3711 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003712 },
3713 })
3714
David Benjamin760b1dd2015-05-15 23:33:48 -04003715 // No session ticket support; server doesn't send NewSessionTicket.
3716 tests = append(tests, testCase{
3717 name: "SessionTicketsDisabled-Client",
3718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003719 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003720 SessionTicketsDisabled: true,
3721 },
3722 })
3723 tests = append(tests, testCase{
3724 testType: serverTest,
3725 name: "SessionTicketsDisabled-Server",
3726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 SessionTicketsDisabled: true,
3729 },
3730 })
3731
3732 // Skip ServerKeyExchange in PSK key exchange if there's no
3733 // identity hint.
3734 tests = append(tests, testCase{
3735 name: "EmptyPSKHint-Client",
3736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003737 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003738 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3739 PreSharedKey: []byte("secret"),
3740 },
3741 flags: []string{"-psk", "secret"},
3742 })
3743 tests = append(tests, testCase{
3744 testType: serverTest,
3745 name: "EmptyPSKHint-Server",
3746 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003747 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003748 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3749 PreSharedKey: []byte("secret"),
3750 },
3751 flags: []string{"-psk", "secret"},
3752 })
3753
David Benjamin4c3ddf72016-06-29 18:13:53 -04003754 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003755 tests = append(tests, testCase{
3756 testType: clientTest,
3757 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 config: Config{
3759 MaxVersion: VersionTLS12,
3760 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003761 flags: []string{
3762 "-enable-ocsp-stapling",
3763 "-expect-ocsp-response",
3764 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003765 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003766 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003767 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003768 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003769 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003770 testType: serverTest,
3771 name: "OCSPStapling-Server",
3772 config: Config{
3773 MaxVersion: VersionTLS12,
3774 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003775 expectedOCSPResponse: testOCSPResponse,
3776 flags: []string{
3777 "-ocsp-response",
3778 base64.StdEncoding.EncodeToString(testOCSPResponse),
3779 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003780 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003781 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003782 tests = append(tests, testCase{
3783 testType: clientTest,
3784 name: "OCSPStapling-Client-TLS13",
3785 config: Config{
3786 MaxVersion: VersionTLS13,
3787 },
3788 flags: []string{
3789 "-enable-ocsp-stapling",
3790 "-expect-ocsp-response",
3791 base64.StdEncoding.EncodeToString(testOCSPResponse),
3792 "-verify-peer",
3793 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003794 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003795 })
3796 tests = append(tests, testCase{
3797 testType: serverTest,
3798 name: "OCSPStapling-Server-TLS13",
3799 config: Config{
3800 MaxVersion: VersionTLS13,
3801 },
3802 expectedOCSPResponse: testOCSPResponse,
3803 flags: []string{
3804 "-ocsp-response",
3805 base64.StdEncoding.EncodeToString(testOCSPResponse),
3806 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003807 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003808 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003809
David Benjamin4c3ddf72016-06-29 18:13:53 -04003810 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003811 for _, vers := range tlsVersions {
3812 if config.protocol == dtls && !vers.hasDTLS {
3813 continue
3814 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003815 for _, testType := range []testType{clientTest, serverTest} {
3816 suffix := "-Client"
3817 if testType == serverTest {
3818 suffix = "-Server"
3819 }
3820 suffix += "-" + vers.name
3821
3822 flag := "-verify-peer"
3823 if testType == serverTest {
3824 flag = "-require-any-client-certificate"
3825 }
3826
3827 tests = append(tests, testCase{
3828 testType: testType,
3829 name: "CertificateVerificationSucceed" + suffix,
3830 config: Config{
3831 MaxVersion: vers.version,
3832 Certificates: []Certificate{rsaCertificate},
3833 },
3834 flags: []string{
3835 flag,
3836 "-expect-verify-result",
3837 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003838 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003839 })
3840 tests = append(tests, testCase{
3841 testType: testType,
3842 name: "CertificateVerificationFail" + suffix,
3843 config: Config{
3844 MaxVersion: vers.version,
3845 Certificates: []Certificate{rsaCertificate},
3846 },
3847 flags: []string{
3848 flag,
3849 "-verify-fail",
3850 },
3851 shouldFail: true,
3852 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3853 })
3854 }
3855
3856 // By default, the client is in a soft fail mode where the peer
3857 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003858 tests = append(tests, testCase{
3859 testType: clientTest,
3860 name: "CertificateVerificationSoftFail-" + vers.name,
3861 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003862 MaxVersion: vers.version,
3863 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003864 },
3865 flags: []string{
3866 "-verify-fail",
3867 "-expect-verify-result",
3868 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003869 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003870 })
3871 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003872
David Benjamin1d4f4c02016-07-26 18:03:08 -04003873 tests = append(tests, testCase{
3874 name: "ShimSendAlert",
3875 flags: []string{"-send-alert"},
3876 shimWritesFirst: true,
3877 shouldFail: true,
3878 expectedLocalError: "remote error: decompression failure",
3879 })
3880
David Benjamin582ba042016-07-07 12:33:25 -07003881 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003882 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 name: "Renegotiate-Client",
3884 config: Config{
3885 MaxVersion: VersionTLS12,
3886 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003887 renegotiate: 1,
3888 flags: []string{
3889 "-renegotiate-freely",
3890 "-expect-total-renegotiations", "1",
3891 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003893
David Benjamin47921102016-07-28 11:29:18 -04003894 tests = append(tests, testCase{
3895 name: "SendHalfHelloRequest",
3896 config: Config{
3897 MaxVersion: VersionTLS12,
3898 Bugs: ProtocolBugs{
3899 PackHelloRequestWithFinished: config.packHandshakeFlight,
3900 },
3901 },
3902 sendHalfHelloRequest: true,
3903 flags: []string{"-renegotiate-ignore"},
3904 shouldFail: true,
3905 expectedError: ":UNEXPECTED_RECORD:",
3906 })
3907
David Benjamin760b1dd2015-05-15 23:33:48 -04003908 // NPN on client and server; results in post-handshake message.
3909 tests = append(tests, testCase{
3910 name: "NPN-Client",
3911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003912 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003913 NextProtos: []string{"foo"},
3914 },
3915 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003916 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 expectedNextProto: "foo",
3918 expectedNextProtoType: npn,
3919 })
3920 tests = append(tests, testCase{
3921 testType: serverTest,
3922 name: "NPN-Server",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 NextProtos: []string{"bar"},
3926 },
3927 flags: []string{
3928 "-advertise-npn", "\x03foo\x03bar\x03baz",
3929 "-expect-next-proto", "bar",
3930 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003931 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
3936 // TODO(davidben): Add tests for when False Start doesn't trigger.
3937
3938 // Client does False Start and negotiates NPN.
3939 tests = append(tests, testCase{
3940 name: "FalseStart",
3941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003942 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3944 NextProtos: []string{"foo"},
3945 Bugs: ProtocolBugs{
3946 ExpectFalseStart: true,
3947 },
3948 },
3949 flags: []string{
3950 "-false-start",
3951 "-select-next-proto", "foo",
3952 },
3953 shimWritesFirst: true,
3954 resumeSession: true,
3955 })
3956
3957 // Client does False Start and negotiates ALPN.
3958 tests = append(tests, testCase{
3959 name: "FalseStart-ALPN",
3960 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003961 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3963 NextProtos: []string{"foo"},
3964 Bugs: ProtocolBugs{
3965 ExpectFalseStart: true,
3966 },
3967 },
3968 flags: []string{
3969 "-false-start",
3970 "-advertise-alpn", "\x03foo",
3971 },
3972 shimWritesFirst: true,
3973 resumeSession: true,
3974 })
3975
3976 // Client does False Start but doesn't explicitly call
3977 // SSL_connect.
3978 tests = append(tests, testCase{
3979 name: "FalseStart-Implicit",
3980 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003981 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003982 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3983 NextProtos: []string{"foo"},
3984 },
3985 flags: []string{
3986 "-implicit-handshake",
3987 "-false-start",
3988 "-advertise-alpn", "\x03foo",
3989 },
3990 })
3991
3992 // False Start without session tickets.
3993 tests = append(tests, testCase{
3994 name: "FalseStart-SessionTicketsDisabled",
3995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003996 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3998 NextProtos: []string{"foo"},
3999 SessionTicketsDisabled: true,
4000 Bugs: ProtocolBugs{
4001 ExpectFalseStart: true,
4002 },
4003 },
4004 flags: []string{
4005 "-false-start",
4006 "-select-next-proto", "foo",
4007 },
4008 shimWritesFirst: true,
4009 })
4010
Adam Langleydf759b52016-07-11 15:24:37 -07004011 tests = append(tests, testCase{
4012 name: "FalseStart-CECPQ1",
4013 config: Config{
4014 MaxVersion: VersionTLS12,
4015 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
4016 NextProtos: []string{"foo"},
4017 Bugs: ProtocolBugs{
4018 ExpectFalseStart: true,
4019 },
4020 },
4021 flags: []string{
4022 "-false-start",
4023 "-cipher", "DEFAULT:kCECPQ1",
4024 "-select-next-proto", "foo",
4025 },
4026 shimWritesFirst: true,
4027 resumeSession: true,
4028 })
4029
David Benjamin760b1dd2015-05-15 23:33:48 -04004030 // Server parses a V2ClientHello.
4031 tests = append(tests, testCase{
4032 testType: serverTest,
4033 name: "SendV2ClientHello",
4034 config: Config{
4035 // Choose a cipher suite that does not involve
4036 // elliptic curves, so no extensions are
4037 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004038 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004039 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004040 Bugs: ProtocolBugs{
4041 SendV2ClientHello: true,
4042 },
4043 },
4044 })
4045
Nick Harper60a85cb2016-09-23 16:25:11 -07004046 // Test Channel ID
4047 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004048 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004049 continue
4050 }
4051 // Client sends a Channel ID.
4052 tests = append(tests, testCase{
4053 name: "ChannelID-Client-" + ver.name,
4054 config: Config{
4055 MaxVersion: ver.version,
4056 RequestChannelID: true,
4057 },
4058 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4059 resumeSession: true,
4060 expectChannelID: true,
4061 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004062
Nick Harper60a85cb2016-09-23 16:25:11 -07004063 // Server accepts a Channel ID.
4064 tests = append(tests, testCase{
4065 testType: serverTest,
4066 name: "ChannelID-Server-" + ver.name,
4067 config: Config{
4068 MaxVersion: ver.version,
4069 ChannelID: channelIDKey,
4070 },
4071 flags: []string{
4072 "-expect-channel-id",
4073 base64.StdEncoding.EncodeToString(channelIDBytes),
4074 },
4075 resumeSession: true,
4076 expectChannelID: true,
4077 })
4078
4079 tests = append(tests, testCase{
4080 testType: serverTest,
4081 name: "InvalidChannelIDSignature-" + ver.name,
4082 config: Config{
4083 MaxVersion: ver.version,
4084 ChannelID: channelIDKey,
4085 Bugs: ProtocolBugs{
4086 InvalidChannelIDSignature: true,
4087 },
4088 },
4089 flags: []string{"-enable-channel-id"},
4090 shouldFail: true,
4091 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4092 })
4093 }
David Benjamin30789da2015-08-29 22:56:45 -04004094
David Benjaminf8fcdf32016-06-08 15:56:13 -04004095 // Channel ID and NPN at the same time, to ensure their relative
4096 // ordering is correct.
4097 tests = append(tests, testCase{
4098 name: "ChannelID-NPN-Client",
4099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004100 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004101 RequestChannelID: true,
4102 NextProtos: []string{"foo"},
4103 },
4104 flags: []string{
4105 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4106 "-select-next-proto", "foo",
4107 },
4108 resumeSession: true,
4109 expectChannelID: true,
4110 expectedNextProto: "foo",
4111 expectedNextProtoType: npn,
4112 })
4113 tests = append(tests, testCase{
4114 testType: serverTest,
4115 name: "ChannelID-NPN-Server",
4116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004117 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004118 ChannelID: channelIDKey,
4119 NextProtos: []string{"bar"},
4120 },
4121 flags: []string{
4122 "-expect-channel-id",
4123 base64.StdEncoding.EncodeToString(channelIDBytes),
4124 "-advertise-npn", "\x03foo\x03bar\x03baz",
4125 "-expect-next-proto", "bar",
4126 },
4127 resumeSession: true,
4128 expectChannelID: true,
4129 expectedNextProto: "bar",
4130 expectedNextProtoType: npn,
4131 })
4132
David Benjamin30789da2015-08-29 22:56:45 -04004133 // Bidirectional shutdown with the runner initiating.
4134 tests = append(tests, testCase{
4135 name: "Shutdown-Runner",
4136 config: Config{
4137 Bugs: ProtocolBugs{
4138 ExpectCloseNotify: true,
4139 },
4140 },
4141 flags: []string{"-check-close-notify"},
4142 })
4143
4144 // Bidirectional shutdown with the shim initiating. The runner,
4145 // in the meantime, sends garbage before the close_notify which
4146 // the shim must ignore.
4147 tests = append(tests, testCase{
4148 name: "Shutdown-Shim",
4149 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004150 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004151 Bugs: ProtocolBugs{
4152 ExpectCloseNotify: true,
4153 },
4154 },
4155 shimShutsDown: true,
4156 sendEmptyRecords: 1,
4157 sendWarningAlerts: 1,
4158 flags: []string{"-check-close-notify"},
4159 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004160 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004161 // TODO(davidben): DTLS 1.3 will want a similar thing for
4162 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004163 tests = append(tests, testCase{
4164 name: "SkipHelloVerifyRequest",
4165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004166 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004167 Bugs: ProtocolBugs{
4168 SkipHelloVerifyRequest: true,
4169 },
4170 },
4171 })
4172 }
4173
David Benjamin760b1dd2015-05-15 23:33:48 -04004174 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004175 test.protocol = config.protocol
4176 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004177 test.name += "-DTLS"
4178 }
David Benjamin582ba042016-07-07 12:33:25 -07004179 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004180 test.name += "-Async"
4181 test.flags = append(test.flags, "-async")
4182 } else {
4183 test.name += "-Sync"
4184 }
David Benjamin582ba042016-07-07 12:33:25 -07004185 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004186 test.name += "-SplitHandshakeRecords"
4187 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004188 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004189 test.config.Bugs.MaxPacketLength = 256
4190 test.flags = append(test.flags, "-mtu", "256")
4191 }
4192 }
David Benjamin582ba042016-07-07 12:33:25 -07004193 if config.packHandshakeFlight {
4194 test.name += "-PackHandshakeFlight"
4195 test.config.Bugs.PackHandshakeFlight = true
4196 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004197 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004198 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004199}
4200
Adam Langley524e7172015-02-20 16:04:00 -08004201func addDDoSCallbackTests() {
4202 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004203 for _, resume := range []bool{false, true} {
4204 suffix := "Resume"
4205 if resume {
4206 suffix = "No" + suffix
4207 }
4208
4209 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004210 testType: serverTest,
4211 name: "Server-DDoS-OK-" + suffix,
4212 config: Config{
4213 MaxVersion: VersionTLS12,
4214 },
Adam Langley524e7172015-02-20 16:04:00 -08004215 flags: []string{"-install-ddos-callback"},
4216 resumeSession: resume,
4217 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004218 testCases = append(testCases, testCase{
4219 testType: serverTest,
4220 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4221 config: Config{
4222 MaxVersion: VersionTLS13,
4223 },
4224 flags: []string{"-install-ddos-callback"},
4225 resumeSession: resume,
4226 })
Adam Langley524e7172015-02-20 16:04:00 -08004227
4228 failFlag := "-fail-ddos-callback"
4229 if resume {
4230 failFlag = "-fail-second-ddos-callback"
4231 }
4232 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004233 testType: serverTest,
4234 name: "Server-DDoS-Reject-" + suffix,
4235 config: Config{
4236 MaxVersion: VersionTLS12,
4237 },
David Benjamin2c66e072016-09-16 15:58:00 -04004238 flags: []string{"-install-ddos-callback", failFlag},
4239 resumeSession: resume,
4240 shouldFail: true,
4241 expectedError: ":CONNECTION_REJECTED:",
4242 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004243 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004244 testCases = append(testCases, testCase{
4245 testType: serverTest,
4246 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4247 config: Config{
4248 MaxVersion: VersionTLS13,
4249 },
David Benjamin2c66e072016-09-16 15:58:00 -04004250 flags: []string{"-install-ddos-callback", failFlag},
4251 resumeSession: resume,
4252 shouldFail: true,
4253 expectedError: ":CONNECTION_REJECTED:",
4254 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004255 })
Adam Langley524e7172015-02-20 16:04:00 -08004256 }
4257}
4258
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004259func addVersionNegotiationTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all newer versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[i+1:] {
4264 flags = append(flags, vers.flag)
4265 }
4266
Steven Valdezfdd10992016-09-15 16:27:05 -04004267 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004268 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004269 protocols := []protocol{tls}
4270 if runnerVers.hasDTLS && shimVers.hasDTLS {
4271 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004272 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004273 for _, protocol := range protocols {
4274 expectedVersion := shimVers.version
4275 if runnerVers.version < shimVers.version {
4276 expectedVersion = runnerVers.version
4277 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004278
David Benjamin8b8c0062014-11-23 02:47:52 -05004279 suffix := shimVers.name + "-" + runnerVers.name
4280 if protocol == dtls {
4281 suffix += "-DTLS"
4282 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004283
David Benjamin1eb367c2014-12-12 18:17:51 -05004284 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4285
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004286 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004287 clientVers := shimVers.version
4288 if clientVers > VersionTLS10 {
4289 clientVers = VersionTLS10
4290 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004291 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004292 serverVers := expectedVersion
4293 if expectedVersion >= VersionTLS13 {
4294 serverVers = VersionTLS10
4295 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004296 serverVers = versionToWire(serverVers, protocol == dtls)
4297
David Benjamin8b8c0062014-11-23 02:47:52 -05004298 testCases = append(testCases, testCase{
4299 protocol: protocol,
4300 testType: clientTest,
4301 name: "VersionNegotiation-Client-" + suffix,
4302 config: Config{
4303 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004304 Bugs: ProtocolBugs{
4305 ExpectInitialRecordVersion: clientVers,
4306 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004307 },
4308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004311 testCases = append(testCases, testCase{
4312 protocol: protocol,
4313 testType: clientTest,
4314 name: "VersionNegotiation-Client2-" + suffix,
4315 config: Config{
4316 MaxVersion: runnerVers.version,
4317 Bugs: ProtocolBugs{
4318 ExpectInitialRecordVersion: clientVers,
4319 },
4320 },
4321 flags: []string{"-max-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004324
4325 testCases = append(testCases, testCase{
4326 protocol: protocol,
4327 testType: serverTest,
4328 name: "VersionNegotiation-Server-" + suffix,
4329 config: Config{
4330 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004331 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004332 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004333 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 },
4335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004338 testCases = append(testCases, testCase{
4339 protocol: protocol,
4340 testType: serverTest,
4341 name: "VersionNegotiation-Server2-" + suffix,
4342 config: Config{
4343 MaxVersion: runnerVers.version,
4344 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004345 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004346 },
4347 },
4348 flags: []string{"-max-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004351 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004352 }
4353 }
David Benjamin95c69562016-06-29 18:15:03 -04004354
Steven Valdezfdd10992016-09-15 16:27:05 -04004355 // Test the version extension at all versions.
4356 for _, vers := range tlsVersions {
4357 protocols := []protocol{tls}
4358 if vers.hasDTLS {
4359 protocols = append(protocols, dtls)
4360 }
4361 for _, protocol := range protocols {
4362 suffix := vers.name
4363 if protocol == dtls {
4364 suffix += "-DTLS"
4365 }
4366
4367 wireVersion := versionToWire(vers.version, protocol == dtls)
4368 testCases = append(testCases, testCase{
4369 protocol: protocol,
4370 testType: serverTest,
4371 name: "VersionNegotiationExtension-" + suffix,
4372 config: Config{
4373 Bugs: ProtocolBugs{
4374 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4375 },
4376 },
4377 expectedVersion: vers.version,
4378 })
4379 }
4380
4381 }
4382
4383 // If all versions are unknown, negotiation fails.
4384 testCases = append(testCases, testCase{
4385 testType: serverTest,
4386 name: "NoSupportedVersions",
4387 config: Config{
4388 Bugs: ProtocolBugs{
4389 SendSupportedVersions: []uint16{0x1111},
4390 },
4391 },
4392 shouldFail: true,
4393 expectedError: ":UNSUPPORTED_PROTOCOL:",
4394 })
4395 testCases = append(testCases, testCase{
4396 protocol: dtls,
4397 testType: serverTest,
4398 name: "NoSupportedVersions-DTLS",
4399 config: Config{
4400 Bugs: ProtocolBugs{
4401 SendSupportedVersions: []uint16{0x1111},
4402 },
4403 },
4404 shouldFail: true,
4405 expectedError: ":UNSUPPORTED_PROTOCOL:",
4406 })
4407
4408 testCases = append(testCases, testCase{
4409 testType: serverTest,
4410 name: "ClientHelloVersionTooHigh",
4411 config: Config{
4412 MaxVersion: VersionTLS13,
4413 Bugs: ProtocolBugs{
4414 SendClientVersion: 0x0304,
4415 OmitSupportedVersions: true,
4416 },
4417 },
4418 expectedVersion: VersionTLS12,
4419 })
4420
4421 testCases = append(testCases, testCase{
4422 testType: serverTest,
4423 name: "ConflictingVersionNegotiation",
4424 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004425 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004426 SendClientVersion: VersionTLS12,
4427 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004428 },
4429 },
David Benjaminad75a662016-09-30 15:42:59 -04004430 // The extension takes precedence over the ClientHello version.
4431 expectedVersion: VersionTLS11,
4432 })
4433
4434 testCases = append(testCases, testCase{
4435 testType: serverTest,
4436 name: "ConflictingVersionNegotiation-2",
4437 config: Config{
4438 Bugs: ProtocolBugs{
4439 SendClientVersion: VersionTLS11,
4440 SendSupportedVersions: []uint16{VersionTLS12},
4441 },
4442 },
4443 // The extension takes precedence over the ClientHello version.
4444 expectedVersion: VersionTLS12,
4445 })
4446
4447 testCases = append(testCases, testCase{
4448 testType: serverTest,
4449 name: "RejectFinalTLS13",
4450 config: Config{
4451 Bugs: ProtocolBugs{
4452 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4453 },
4454 },
4455 // We currently implement a draft TLS 1.3 version. Ensure that
4456 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004457 expectedVersion: VersionTLS12,
4458 })
4459
Brian Smithf85d3232016-10-28 10:34:06 -10004460 // Test that the maximum version is selected regardless of the
4461 // client-sent order.
4462 testCases = append(testCases, testCase{
4463 testType: serverTest,
4464 name: "IgnoreClientVersionOrder",
4465 config: Config{
4466 Bugs: ProtocolBugs{
4467 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4468 },
4469 },
4470 expectedVersion: VersionTLS13,
4471 })
4472
David Benjamin95c69562016-06-29 18:15:03 -04004473 // Test for version tolerance.
4474 testCases = append(testCases, testCase{
4475 testType: serverTest,
4476 name: "MinorVersionTolerance",
4477 config: Config{
4478 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004479 SendClientVersion: 0x03ff,
4480 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004481 },
4482 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004483 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004484 })
4485 testCases = append(testCases, testCase{
4486 testType: serverTest,
4487 name: "MajorVersionTolerance",
4488 config: Config{
4489 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004490 SendClientVersion: 0x0400,
4491 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004492 },
4493 },
David Benjaminad75a662016-09-30 15:42:59 -04004494 // TLS 1.3 must be negotiated with the supported_versions
4495 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004496 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004497 })
David Benjaminad75a662016-09-30 15:42:59 -04004498 testCases = append(testCases, testCase{
4499 testType: serverTest,
4500 name: "VersionTolerance-TLS13",
4501 config: Config{
4502 Bugs: ProtocolBugs{
4503 // Although TLS 1.3 does not use
4504 // ClientHello.version, it still tolerates high
4505 // values there.
4506 SendClientVersion: 0x0400,
4507 },
4508 },
4509 expectedVersion: VersionTLS13,
4510 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004511
David Benjamin95c69562016-06-29 18:15:03 -04004512 testCases = append(testCases, testCase{
4513 protocol: dtls,
4514 testType: serverTest,
4515 name: "MinorVersionTolerance-DTLS",
4516 config: Config{
4517 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004518 SendClientVersion: 0xfe00,
4519 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004520 },
4521 },
4522 expectedVersion: VersionTLS12,
4523 })
4524 testCases = append(testCases, testCase{
4525 protocol: dtls,
4526 testType: serverTest,
4527 name: "MajorVersionTolerance-DTLS",
4528 config: Config{
4529 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004530 SendClientVersion: 0xfdff,
4531 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004532 },
4533 },
4534 expectedVersion: VersionTLS12,
4535 })
4536
4537 // Test that versions below 3.0 are rejected.
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "VersionTooLow",
4541 config: Config{
4542 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004543 SendClientVersion: 0x0200,
4544 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004545 },
4546 },
4547 shouldFail: true,
4548 expectedError: ":UNSUPPORTED_PROTOCOL:",
4549 })
4550 testCases = append(testCases, testCase{
4551 protocol: dtls,
4552 testType: serverTest,
4553 name: "VersionTooLow-DTLS",
4554 config: Config{
4555 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004556 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004557 },
4558 },
4559 shouldFail: true,
4560 expectedError: ":UNSUPPORTED_PROTOCOL:",
4561 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004562
David Benjamin2dc02042016-09-19 19:57:37 -04004563 testCases = append(testCases, testCase{
4564 name: "ServerBogusVersion",
4565 config: Config{
4566 Bugs: ProtocolBugs{
4567 SendServerHelloVersion: 0x1234,
4568 },
4569 },
4570 shouldFail: true,
4571 expectedError: ":UNSUPPORTED_PROTOCOL:",
4572 })
4573
David Benjamin1f61f0d2016-07-10 12:20:35 -04004574 // Test TLS 1.3's downgrade signal.
4575 testCases = append(testCases, testCase{
4576 name: "Downgrade-TLS12-Client",
4577 config: Config{
4578 Bugs: ProtocolBugs{
4579 NegotiateVersion: VersionTLS12,
4580 },
4581 },
David Benjamin592b5322016-09-30 15:15:01 -04004582 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004583 // TODO(davidben): This test should fail once TLS 1.3 is final
4584 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004585 })
4586 testCases = append(testCases, testCase{
4587 testType: serverTest,
4588 name: "Downgrade-TLS12-Server",
4589 config: Config{
4590 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004591 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004592 },
4593 },
David Benjamin592b5322016-09-30 15:15:01 -04004594 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004595 // TODO(davidben): This test should fail once TLS 1.3 is final
4596 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004597 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004598}
4599
David Benjaminaccb4542014-12-12 23:44:33 -05004600func addMinimumVersionTests() {
4601 for i, shimVers := range tlsVersions {
4602 // Assemble flags to disable all older versions on the shim.
4603 var flags []string
4604 for _, vers := range tlsVersions[:i] {
4605 flags = append(flags, vers.flag)
4606 }
4607
4608 for _, runnerVers := range tlsVersions {
4609 protocols := []protocol{tls}
4610 if runnerVers.hasDTLS && shimVers.hasDTLS {
4611 protocols = append(protocols, dtls)
4612 }
4613 for _, protocol := range protocols {
4614 suffix := shimVers.name + "-" + runnerVers.name
4615 if protocol == dtls {
4616 suffix += "-DTLS"
4617 }
4618 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4619
David Benjaminaccb4542014-12-12 23:44:33 -05004620 var expectedVersion uint16
4621 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004622 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004623 if runnerVers.version >= shimVers.version {
4624 expectedVersion = runnerVers.version
4625 } else {
4626 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004627 expectedError = ":UNSUPPORTED_PROTOCOL:"
4628 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004629 }
4630
4631 testCases = append(testCases, testCase{
4632 protocol: protocol,
4633 testType: clientTest,
4634 name: "MinimumVersion-Client-" + suffix,
4635 config: Config{
4636 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004637 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004638 // Ensure the server does not decline to
4639 // select a version (versions extension) or
4640 // cipher (some ciphers depend on versions).
4641 NegotiateVersion: runnerVers.version,
4642 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004643 },
David Benjaminaccb4542014-12-12 23:44:33 -05004644 },
David Benjamin87909c02014-12-13 01:55:01 -05004645 flags: flags,
4646 expectedVersion: expectedVersion,
4647 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004648 expectedError: expectedError,
4649 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004650 })
4651 testCases = append(testCases, testCase{
4652 protocol: protocol,
4653 testType: clientTest,
4654 name: "MinimumVersion-Client2-" + suffix,
4655 config: Config{
4656 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004657 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004658 // Ensure the server does not decline to
4659 // select a version (versions extension) or
4660 // cipher (some ciphers depend on versions).
4661 NegotiateVersion: runnerVers.version,
4662 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004663 },
David Benjaminaccb4542014-12-12 23:44:33 -05004664 },
David Benjamin87909c02014-12-13 01:55:01 -05004665 flags: []string{"-min-version", shimVersFlag},
4666 expectedVersion: expectedVersion,
4667 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004668 expectedError: expectedError,
4669 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004670 })
4671
4672 testCases = append(testCases, testCase{
4673 protocol: protocol,
4674 testType: serverTest,
4675 name: "MinimumVersion-Server-" + suffix,
4676 config: Config{
4677 MaxVersion: runnerVers.version,
4678 },
David Benjamin87909c02014-12-13 01:55:01 -05004679 flags: flags,
4680 expectedVersion: expectedVersion,
4681 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004682 expectedError: expectedError,
4683 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004684 })
4685 testCases = append(testCases, testCase{
4686 protocol: protocol,
4687 testType: serverTest,
4688 name: "MinimumVersion-Server2-" + suffix,
4689 config: Config{
4690 MaxVersion: runnerVers.version,
4691 },
David Benjamin87909c02014-12-13 01:55:01 -05004692 flags: []string{"-min-version", shimVersFlag},
4693 expectedVersion: expectedVersion,
4694 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004695 expectedError: expectedError,
4696 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004697 })
4698 }
4699 }
4700 }
4701}
4702
David Benjamine78bfde2014-09-06 12:45:15 -04004703func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004704 // TODO(davidben): Extensions, where applicable, all move their server
4705 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4706 // tests for both. Also test interaction with 0-RTT when implemented.
4707
David Benjamin97d17d92016-07-14 16:12:00 -04004708 // Repeat extensions tests all versions except SSL 3.0.
4709 for _, ver := range tlsVersions {
4710 if ver.version == VersionSSL30 {
4711 continue
4712 }
4713
David Benjamin97d17d92016-07-14 16:12:00 -04004714 // Test that duplicate extensions are rejected.
4715 testCases = append(testCases, testCase{
4716 testType: clientTest,
4717 name: "DuplicateExtensionClient-" + ver.name,
4718 config: Config{
4719 MaxVersion: ver.version,
4720 Bugs: ProtocolBugs{
4721 DuplicateExtension: true,
4722 },
David Benjamine78bfde2014-09-06 12:45:15 -04004723 },
David Benjamin97d17d92016-07-14 16:12:00 -04004724 shouldFail: true,
4725 expectedLocalError: "remote error: error decoding message",
4726 })
4727 testCases = append(testCases, testCase{
4728 testType: serverTest,
4729 name: "DuplicateExtensionServer-" + ver.name,
4730 config: Config{
4731 MaxVersion: ver.version,
4732 Bugs: ProtocolBugs{
4733 DuplicateExtension: true,
4734 },
David Benjamine78bfde2014-09-06 12:45:15 -04004735 },
David Benjamin97d17d92016-07-14 16:12:00 -04004736 shouldFail: true,
4737 expectedLocalError: "remote error: error decoding message",
4738 })
4739
4740 // Test SNI.
4741 testCases = append(testCases, testCase{
4742 testType: clientTest,
4743 name: "ServerNameExtensionClient-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 ExpectServerName: "example.com",
4748 },
David Benjamine78bfde2014-09-06 12:45:15 -04004749 },
David Benjamin97d17d92016-07-14 16:12:00 -04004750 flags: []string{"-host-name", "example.com"},
4751 })
4752 testCases = append(testCases, testCase{
4753 testType: clientTest,
4754 name: "ServerNameExtensionClientMismatch-" + ver.name,
4755 config: Config{
4756 MaxVersion: ver.version,
4757 Bugs: ProtocolBugs{
4758 ExpectServerName: "mismatch.com",
4759 },
David Benjamine78bfde2014-09-06 12:45:15 -04004760 },
David Benjamin97d17d92016-07-14 16:12:00 -04004761 flags: []string{"-host-name", "example.com"},
4762 shouldFail: true,
4763 expectedLocalError: "tls: unexpected server name",
4764 })
4765 testCases = append(testCases, testCase{
4766 testType: clientTest,
4767 name: "ServerNameExtensionClientMissing-" + ver.name,
4768 config: Config{
4769 MaxVersion: ver.version,
4770 Bugs: ProtocolBugs{
4771 ExpectServerName: "missing.com",
4772 },
David Benjamine78bfde2014-09-06 12:45:15 -04004773 },
David Benjamin97d17d92016-07-14 16:12:00 -04004774 shouldFail: true,
4775 expectedLocalError: "tls: unexpected server name",
4776 })
4777 testCases = append(testCases, testCase{
4778 testType: serverTest,
4779 name: "ServerNameExtensionServer-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004783 },
David Benjamin97d17d92016-07-14 16:12:00 -04004784 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004785 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004786 })
4787
4788 // Test ALPN.
4789 testCases = append(testCases, testCase{
4790 testType: clientTest,
4791 name: "ALPNClient-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 NextProtos: []string{"foo"},
4795 },
4796 flags: []string{
4797 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4798 "-expect-alpn", "foo",
4799 },
4800 expectedNextProto: "foo",
4801 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004802 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004803 })
4804 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004805 testType: clientTest,
4806 name: "ALPNClient-Mismatch-" + ver.name,
4807 config: Config{
4808 MaxVersion: ver.version,
4809 Bugs: ProtocolBugs{
4810 SendALPN: "baz",
4811 },
4812 },
4813 flags: []string{
4814 "-advertise-alpn", "\x03foo\x03bar",
4815 },
4816 shouldFail: true,
4817 expectedError: ":INVALID_ALPN_PROTOCOL:",
4818 expectedLocalError: "remote error: illegal parameter",
4819 })
4820 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004821 testType: serverTest,
4822 name: "ALPNServer-" + ver.name,
4823 config: Config{
4824 MaxVersion: ver.version,
4825 NextProtos: []string{"foo", "bar", "baz"},
4826 },
4827 flags: []string{
4828 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4829 "-select-alpn", "foo",
4830 },
4831 expectedNextProto: "foo",
4832 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004833 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004834 })
4835 testCases = append(testCases, testCase{
4836 testType: serverTest,
4837 name: "ALPNServer-Decline-" + ver.name,
4838 config: Config{
4839 MaxVersion: ver.version,
4840 NextProtos: []string{"foo", "bar", "baz"},
4841 },
4842 flags: []string{"-decline-alpn"},
4843 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004844 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004845 })
4846
David Benjamin25fe85b2016-08-09 20:00:32 -04004847 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4848 // called once.
4849 testCases = append(testCases, testCase{
4850 testType: serverTest,
4851 name: "ALPNServer-Async-" + ver.name,
4852 config: Config{
4853 MaxVersion: ver.version,
4854 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004855 // Prior to TLS 1.3, exercise the asynchronous session callback.
4856 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004857 },
4858 flags: []string{
4859 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4860 "-select-alpn", "foo",
4861 "-async",
4862 },
4863 expectedNextProto: "foo",
4864 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004865 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004866 })
4867
David Benjamin97d17d92016-07-14 16:12:00 -04004868 var emptyString string
4869 testCases = append(testCases, testCase{
4870 testType: clientTest,
4871 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4872 config: Config{
4873 MaxVersion: ver.version,
4874 NextProtos: []string{""},
4875 Bugs: ProtocolBugs{
4876 // A server returning an empty ALPN protocol
4877 // should be rejected.
4878 ALPNProtocol: &emptyString,
4879 },
4880 },
4881 flags: []string{
4882 "-advertise-alpn", "\x03foo",
4883 },
4884 shouldFail: true,
4885 expectedError: ":PARSE_TLSEXT:",
4886 })
4887 testCases = append(testCases, testCase{
4888 testType: serverTest,
4889 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4890 config: Config{
4891 MaxVersion: ver.version,
4892 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004893 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004894 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004895 },
David Benjamin97d17d92016-07-14 16:12:00 -04004896 flags: []string{
4897 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004898 },
David Benjamin97d17d92016-07-14 16:12:00 -04004899 shouldFail: true,
4900 expectedError: ":PARSE_TLSEXT:",
4901 })
4902
4903 // Test NPN and the interaction with ALPN.
4904 if ver.version < VersionTLS13 {
4905 // Test that the server prefers ALPN over NPN.
4906 testCases = append(testCases, testCase{
4907 testType: serverTest,
4908 name: "ALPNServer-Preferred-" + ver.name,
4909 config: Config{
4910 MaxVersion: ver.version,
4911 NextProtos: []string{"foo", "bar", "baz"},
4912 },
4913 flags: []string{
4914 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4915 "-select-alpn", "foo",
4916 "-advertise-npn", "\x03foo\x03bar\x03baz",
4917 },
4918 expectedNextProto: "foo",
4919 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004920 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004921 })
4922 testCases = append(testCases, testCase{
4923 testType: serverTest,
4924 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4925 config: Config{
4926 MaxVersion: ver.version,
4927 NextProtos: []string{"foo", "bar", "baz"},
4928 Bugs: ProtocolBugs{
4929 SwapNPNAndALPN: true,
4930 },
4931 },
4932 flags: []string{
4933 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4934 "-select-alpn", "foo",
4935 "-advertise-npn", "\x03foo\x03bar\x03baz",
4936 },
4937 expectedNextProto: "foo",
4938 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004939 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004940 })
4941
4942 // Test that negotiating both NPN and ALPN is forbidden.
4943 testCases = append(testCases, testCase{
4944 name: "NegotiateALPNAndNPN-" + ver.name,
4945 config: Config{
4946 MaxVersion: ver.version,
4947 NextProtos: []string{"foo", "bar", "baz"},
4948 Bugs: ProtocolBugs{
4949 NegotiateALPNAndNPN: true,
4950 },
4951 },
4952 flags: []string{
4953 "-advertise-alpn", "\x03foo",
4954 "-select-next-proto", "foo",
4955 },
4956 shouldFail: true,
4957 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4958 })
4959 testCases = append(testCases, testCase{
4960 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4961 config: Config{
4962 MaxVersion: ver.version,
4963 NextProtos: []string{"foo", "bar", "baz"},
4964 Bugs: ProtocolBugs{
4965 NegotiateALPNAndNPN: true,
4966 SwapNPNAndALPN: true,
4967 },
4968 },
4969 flags: []string{
4970 "-advertise-alpn", "\x03foo",
4971 "-select-next-proto", "foo",
4972 },
4973 shouldFail: true,
4974 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4975 })
4976
4977 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4978 testCases = append(testCases, testCase{
4979 name: "DisableNPN-" + ver.name,
4980 config: Config{
4981 MaxVersion: ver.version,
4982 NextProtos: []string{"foo"},
4983 },
4984 flags: []string{
4985 "-select-next-proto", "foo",
4986 "-disable-npn",
4987 },
4988 expectNoNextProto: true,
4989 })
4990 }
4991
4992 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004993
4994 // Resume with a corrupt ticket.
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "CorruptTicket-" + ver.name,
4998 config: Config{
4999 MaxVersion: ver.version,
5000 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005001 FilterTicket: func(in []byte) ([]byte, error) {
5002 in[len(in)-1] ^= 1
5003 return in, nil
5004 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005005 },
5006 },
5007 resumeSession: true,
5008 expectResumeRejected: true,
5009 })
5010 // Test the ticket callback, with and without renewal.
5011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "TicketCallback-" + ver.name,
5014 config: Config{
5015 MaxVersion: ver.version,
5016 },
5017 resumeSession: true,
5018 flags: []string{"-use-ticket-callback"},
5019 })
5020 testCases = append(testCases, testCase{
5021 testType: serverTest,
5022 name: "TicketCallback-Renew-" + ver.name,
5023 config: Config{
5024 MaxVersion: ver.version,
5025 Bugs: ProtocolBugs{
5026 ExpectNewTicket: true,
5027 },
5028 },
5029 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5030 resumeSession: true,
5031 })
5032
5033 // Test that the ticket callback is only called once when everything before
5034 // it in the ClientHello is asynchronous. This corrupts the ticket so
5035 // certificate selection callbacks run.
5036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "TicketCallback-SingleCall-" + ver.name,
5039 config: Config{
5040 MaxVersion: ver.version,
5041 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005042 FilterTicket: func(in []byte) ([]byte, error) {
5043 in[len(in)-1] ^= 1
5044 return in, nil
5045 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005046 },
5047 },
5048 resumeSession: true,
5049 expectResumeRejected: true,
5050 flags: []string{
5051 "-use-ticket-callback",
5052 "-async",
5053 },
5054 })
5055
5056 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005057 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005058 testCases = append(testCases, testCase{
5059 testType: serverTest,
5060 name: "OversizedSessionId-" + ver.name,
5061 config: Config{
5062 MaxVersion: ver.version,
5063 Bugs: ProtocolBugs{
5064 OversizedSessionId: true,
5065 },
5066 },
5067 resumeSession: true,
5068 shouldFail: true,
5069 expectedError: ":DECODE_ERROR:",
5070 })
5071 }
5072
5073 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5074 // are ignored.
5075 if ver.hasDTLS {
5076 testCases = append(testCases, testCase{
5077 protocol: dtls,
5078 name: "SRTP-Client-" + ver.name,
5079 config: Config{
5080 MaxVersion: ver.version,
5081 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5082 },
5083 flags: []string{
5084 "-srtp-profiles",
5085 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5086 },
5087 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5088 })
5089 testCases = append(testCases, testCase{
5090 protocol: dtls,
5091 testType: serverTest,
5092 name: "SRTP-Server-" + ver.name,
5093 config: Config{
5094 MaxVersion: ver.version,
5095 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5096 },
5097 flags: []string{
5098 "-srtp-profiles",
5099 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5100 },
5101 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5102 })
5103 // Test that the MKI is ignored.
5104 testCases = append(testCases, testCase{
5105 protocol: dtls,
5106 testType: serverTest,
5107 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5108 config: Config{
5109 MaxVersion: ver.version,
5110 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5111 Bugs: ProtocolBugs{
5112 SRTPMasterKeyIdentifer: "bogus",
5113 },
5114 },
5115 flags: []string{
5116 "-srtp-profiles",
5117 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5118 },
5119 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5120 })
5121 // Test that SRTP isn't negotiated on the server if there were
5122 // no matching profiles.
5123 testCases = append(testCases, testCase{
5124 protocol: dtls,
5125 testType: serverTest,
5126 name: "SRTP-Server-NoMatch-" + ver.name,
5127 config: Config{
5128 MaxVersion: ver.version,
5129 SRTPProtectionProfiles: []uint16{100, 101, 102},
5130 },
5131 flags: []string{
5132 "-srtp-profiles",
5133 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5134 },
5135 expectedSRTPProtectionProfile: 0,
5136 })
5137 // Test that the server returning an invalid SRTP profile is
5138 // flagged as an error by the client.
5139 testCases = append(testCases, testCase{
5140 protocol: dtls,
5141 name: "SRTP-Client-NoMatch-" + ver.name,
5142 config: Config{
5143 MaxVersion: ver.version,
5144 Bugs: ProtocolBugs{
5145 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5146 },
5147 },
5148 flags: []string{
5149 "-srtp-profiles",
5150 "SRTP_AES128_CM_SHA1_80",
5151 },
5152 shouldFail: true,
5153 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5154 })
5155 }
5156
5157 // Test SCT list.
5158 testCases = append(testCases, testCase{
5159 name: "SignedCertificateTimestampList-Client-" + ver.name,
5160 testType: clientTest,
5161 config: Config{
5162 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005163 },
David Benjamin97d17d92016-07-14 16:12:00 -04005164 flags: []string{
5165 "-enable-signed-cert-timestamps",
5166 "-expect-signed-cert-timestamps",
5167 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005168 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005169 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005170 })
David Benjamindaa88502016-10-04 16:32:16 -04005171
Adam Langleycfa08c32016-11-17 13:21:27 -08005172 var differentSCTList []byte
5173 differentSCTList = append(differentSCTList, testSCTList...)
5174 differentSCTList[len(differentSCTList)-1] ^= 1
5175
David Benjamindaa88502016-10-04 16:32:16 -04005176 // The SCT extension did not specify that it must only be sent on resumption as it
5177 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005178 testCases = append(testCases, testCase{
5179 name: "SendSCTListOnResume-" + ver.name,
5180 config: Config{
5181 MaxVersion: ver.version,
5182 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005183 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005184 },
David Benjamind98452d2015-06-16 14:16:23 -04005185 },
David Benjamin97d17d92016-07-14 16:12:00 -04005186 flags: []string{
5187 "-enable-signed-cert-timestamps",
5188 "-expect-signed-cert-timestamps",
5189 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005190 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005191 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005192 })
David Benjamindaa88502016-10-04 16:32:16 -04005193
David Benjamin97d17d92016-07-14 16:12:00 -04005194 testCases = append(testCases, testCase{
5195 name: "SignedCertificateTimestampList-Server-" + ver.name,
5196 testType: serverTest,
5197 config: Config{
5198 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005199 },
David Benjamin97d17d92016-07-14 16:12:00 -04005200 flags: []string{
5201 "-signed-cert-timestamps",
5202 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005203 },
David Benjamin97d17d92016-07-14 16:12:00 -04005204 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005205 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005206 })
David Benjamin53210cb2016-11-16 09:01:48 +09005207
Adam Langleycfa08c32016-11-17 13:21:27 -08005208 emptySCTListCert := *testCerts[0].cert
5209 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5210
5211 // Test empty SCT list.
5212 testCases = append(testCases, testCase{
5213 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5214 testType: clientTest,
5215 config: Config{
5216 MaxVersion: ver.version,
5217 Certificates: []Certificate{emptySCTListCert},
5218 },
5219 flags: []string{
5220 "-enable-signed-cert-timestamps",
5221 },
5222 shouldFail: true,
5223 expectedError: ":ERROR_PARSING_EXTENSION:",
5224 })
5225
5226 emptySCTCert := *testCerts[0].cert
5227 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5228
5229 // Test empty SCT in non-empty list.
5230 testCases = append(testCases, testCase{
5231 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5232 testType: clientTest,
5233 config: Config{
5234 MaxVersion: ver.version,
5235 Certificates: []Certificate{emptySCTCert},
5236 },
5237 flags: []string{
5238 "-enable-signed-cert-timestamps",
5239 },
5240 shouldFail: true,
5241 expectedError: ":ERROR_PARSING_EXTENSION:",
5242 })
5243
David Benjamin53210cb2016-11-16 09:01:48 +09005244 // Test that certificate-related extensions are not sent unsolicited.
5245 testCases = append(testCases, testCase{
5246 testType: serverTest,
5247 name: "UnsolicitedCertificateExtensions-" + ver.name,
5248 config: Config{
5249 MaxVersion: ver.version,
5250 Bugs: ProtocolBugs{
5251 NoOCSPStapling: true,
5252 NoSignedCertificateTimestamps: true,
5253 },
5254 },
5255 flags: []string{
5256 "-ocsp-response",
5257 base64.StdEncoding.EncodeToString(testOCSPResponse),
5258 "-signed-cert-timestamps",
5259 base64.StdEncoding.EncodeToString(testSCTList),
5260 },
5261 })
David Benjamin97d17d92016-07-14 16:12:00 -04005262 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005263
Paul Lietar4fac72e2015-09-09 13:44:55 +01005264 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005265 testType: clientTest,
5266 name: "ClientHelloPadding",
5267 config: Config{
5268 Bugs: ProtocolBugs{
5269 RequireClientHelloSize: 512,
5270 },
5271 },
5272 // This hostname just needs to be long enough to push the
5273 // ClientHello into F5's danger zone between 256 and 511 bytes
5274 // long.
5275 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5276 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005277
5278 // Extensions should not function in SSL 3.0.
5279 testCases = append(testCases, testCase{
5280 testType: serverTest,
5281 name: "SSLv3Extensions-NoALPN",
5282 config: Config{
5283 MaxVersion: VersionSSL30,
5284 NextProtos: []string{"foo", "bar", "baz"},
5285 },
5286 flags: []string{
5287 "-select-alpn", "foo",
5288 },
5289 expectNoNextProto: true,
5290 })
5291
5292 // Test session tickets separately as they follow a different codepath.
5293 testCases = append(testCases, testCase{
5294 testType: serverTest,
5295 name: "SSLv3Extensions-NoTickets",
5296 config: Config{
5297 MaxVersion: VersionSSL30,
5298 Bugs: ProtocolBugs{
5299 // Historically, session tickets in SSL 3.0
5300 // failed in different ways depending on whether
5301 // the client supported renegotiation_info.
5302 NoRenegotiationInfo: true,
5303 },
5304 },
5305 resumeSession: true,
5306 })
5307 testCases = append(testCases, testCase{
5308 testType: serverTest,
5309 name: "SSLv3Extensions-NoTickets2",
5310 config: Config{
5311 MaxVersion: VersionSSL30,
5312 },
5313 resumeSession: true,
5314 })
5315
5316 // But SSL 3.0 does send and process renegotiation_info.
5317 testCases = append(testCases, testCase{
5318 testType: serverTest,
5319 name: "SSLv3Extensions-RenegotiationInfo",
5320 config: Config{
5321 MaxVersion: VersionSSL30,
5322 Bugs: ProtocolBugs{
5323 RequireRenegotiationInfo: true,
5324 },
5325 },
5326 })
5327 testCases = append(testCases, testCase{
5328 testType: serverTest,
5329 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5330 config: Config{
5331 MaxVersion: VersionSSL30,
5332 Bugs: ProtocolBugs{
5333 NoRenegotiationInfo: true,
5334 SendRenegotiationSCSV: true,
5335 RequireRenegotiationInfo: true,
5336 },
5337 },
5338 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005339
5340 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5341 // in ServerHello.
5342 testCases = append(testCases, testCase{
5343 name: "NPN-Forbidden-TLS13",
5344 config: Config{
5345 MaxVersion: VersionTLS13,
5346 NextProtos: []string{"foo"},
5347 Bugs: ProtocolBugs{
5348 NegotiateNPNAtAllVersions: true,
5349 },
5350 },
5351 flags: []string{"-select-next-proto", "foo"},
5352 shouldFail: true,
5353 expectedError: ":ERROR_PARSING_EXTENSION:",
5354 })
5355 testCases = append(testCases, testCase{
5356 name: "EMS-Forbidden-TLS13",
5357 config: Config{
5358 MaxVersion: VersionTLS13,
5359 Bugs: ProtocolBugs{
5360 NegotiateEMSAtAllVersions: true,
5361 },
5362 },
5363 shouldFail: true,
5364 expectedError: ":ERROR_PARSING_EXTENSION:",
5365 })
5366 testCases = append(testCases, testCase{
5367 name: "RenegotiationInfo-Forbidden-TLS13",
5368 config: Config{
5369 MaxVersion: VersionTLS13,
5370 Bugs: ProtocolBugs{
5371 NegotiateRenegotiationInfoAtAllVersions: true,
5372 },
5373 },
5374 shouldFail: true,
5375 expectedError: ":ERROR_PARSING_EXTENSION:",
5376 })
5377 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005378 name: "Ticket-Forbidden-TLS13",
5379 config: Config{
5380 MaxVersion: VersionTLS12,
5381 },
5382 resumeConfig: &Config{
5383 MaxVersion: VersionTLS13,
5384 Bugs: ProtocolBugs{
5385 AdvertiseTicketExtension: true,
5386 },
5387 },
5388 resumeSession: true,
5389 shouldFail: true,
5390 expectedError: ":ERROR_PARSING_EXTENSION:",
5391 })
5392
5393 // Test that illegal extensions in TLS 1.3 are declined by the server if
5394 // offered in ClientHello. The runner's server will fail if this occurs,
5395 // so we exercise the offering path. (EMS and Renegotiation Info are
5396 // implicit in every test.)
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005399 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005400 config: Config{
5401 MaxVersion: VersionTLS13,
5402 NextProtos: []string{"bar"},
5403 },
5404 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5405 })
David Benjamin196df5b2016-09-21 16:23:27 -04005406
David Benjamindaa88502016-10-04 16:32:16 -04005407 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5408 // tolerated.
5409 testCases = append(testCases, testCase{
5410 name: "SendOCSPResponseOnResume-TLS12",
5411 config: Config{
5412 MaxVersion: VersionTLS12,
5413 Bugs: ProtocolBugs{
5414 SendOCSPResponseOnResume: []byte("bogus"),
5415 },
5416 },
5417 flags: []string{
5418 "-enable-ocsp-stapling",
5419 "-expect-ocsp-response",
5420 base64.StdEncoding.EncodeToString(testOCSPResponse),
5421 },
5422 resumeSession: true,
5423 })
5424
David Benjamindaa88502016-10-04 16:32:16 -04005425 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005426 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005427 config: Config{
5428 MaxVersion: VersionTLS13,
5429 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005430 SendExtensionOnCertificate: testOCSPExtension,
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNEXPECTED_EXTENSION:",
5435 })
5436
5437 testCases = append(testCases, testCase{
5438 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5439 config: Config{
5440 MaxVersion: VersionTLS13,
5441 Bugs: ProtocolBugs{
5442 SendExtensionOnCertificate: testSCTExtension,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNEXPECTED_EXTENSION:",
5447 })
5448
5449 // Test that extensions on client certificates are never accepted.
5450 testCases = append(testCases, testCase{
5451 name: "SendExtensionOnClientCertificate-TLS13",
5452 testType: serverTest,
5453 config: Config{
5454 MaxVersion: VersionTLS13,
5455 Certificates: []Certificate{rsaCertificate},
5456 Bugs: ProtocolBugs{
5457 SendExtensionOnCertificate: testOCSPExtension,
5458 },
5459 },
5460 flags: []string{
5461 "-enable-ocsp-stapling",
5462 "-require-any-client-certificate",
5463 },
5464 shouldFail: true,
5465 expectedError: ":UNEXPECTED_EXTENSION:",
5466 })
5467
5468 testCases = append(testCases, testCase{
5469 name: "SendUnknownExtensionOnCertificate-TLS13",
5470 config: Config{
5471 MaxVersion: VersionTLS13,
5472 Bugs: ProtocolBugs{
5473 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5474 },
5475 },
5476 shouldFail: true,
5477 expectedError: ":UNEXPECTED_EXTENSION:",
5478 })
5479
Adam Langleycfa08c32016-11-17 13:21:27 -08005480 var differentSCTList []byte
5481 differentSCTList = append(differentSCTList, testSCTList...)
5482 differentSCTList[len(differentSCTList)-1] ^= 1
5483
Steven Valdeza833c352016-11-01 13:39:36 -04005484 // Test that extensions on intermediates are allowed but ignored.
5485 testCases = append(testCases, testCase{
5486 name: "IgnoreExtensionsOnIntermediates-TLS13",
5487 config: Config{
5488 MaxVersion: VersionTLS13,
5489 Certificates: []Certificate{rsaChainCertificate},
5490 Bugs: ProtocolBugs{
5491 // Send different values on the intermediate. This tests
5492 // the intermediate's extensions do not override the
5493 // leaf's.
5494 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005495 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005496 },
5497 },
5498 flags: []string{
5499 "-enable-ocsp-stapling",
5500 "-expect-ocsp-response",
5501 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005502 "-enable-signed-cert-timestamps",
5503 "-expect-signed-cert-timestamps",
5504 base64.StdEncoding.EncodeToString(testSCTList),
5505 },
5506 resumeSession: true,
5507 })
5508
5509 // Test that extensions are not sent on intermediates when configured
5510 // only for a leaf.
5511 testCases = append(testCases, testCase{
5512 testType: serverTest,
5513 name: "SendNoExtensionsOnIntermediate-TLS13",
5514 config: Config{
5515 MaxVersion: VersionTLS13,
5516 Bugs: ProtocolBugs{
5517 ExpectNoExtensionsOnIntermediate: true,
5518 },
5519 },
5520 flags: []string{
5521 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5522 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5523 "-ocsp-response",
5524 base64.StdEncoding.EncodeToString(testOCSPResponse),
5525 "-signed-cert-timestamps",
5526 base64.StdEncoding.EncodeToString(testSCTList),
5527 },
5528 })
5529
5530 // Test that extensions are not sent on client certificates.
5531 testCases = append(testCases, testCase{
5532 name: "SendNoClientCertificateExtensions-TLS13",
5533 config: Config{
5534 MaxVersion: VersionTLS13,
5535 ClientAuth: RequireAnyClientCert,
5536 },
5537 flags: []string{
5538 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5539 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5540 "-ocsp-response",
5541 base64.StdEncoding.EncodeToString(testOCSPResponse),
5542 "-signed-cert-timestamps",
5543 base64.StdEncoding.EncodeToString(testSCTList),
5544 },
5545 })
5546
5547 testCases = append(testCases, testCase{
5548 name: "SendDuplicateExtensionsOnCerts-TLS13",
5549 config: Config{
5550 MaxVersion: VersionTLS13,
5551 Bugs: ProtocolBugs{
5552 SendDuplicateCertExtensions: true,
5553 },
5554 },
5555 flags: []string{
5556 "-enable-ocsp-stapling",
5557 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005558 },
5559 resumeSession: true,
5560 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005561 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005562 })
Adam Langley9b885c52016-11-18 14:21:03 -08005563
5564 testCases = append(testCases, testCase{
5565 name: "SignedCertificateTimestampListInvalid-Server",
5566 testType: serverTest,
5567 flags: []string{
5568 "-signed-cert-timestamps",
5569 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5570 },
5571 shouldFail: true,
5572 expectedError: ":INVALID_SCT_LIST:",
5573 })
David Benjamine78bfde2014-09-06 12:45:15 -04005574}
5575
David Benjamin01fe8202014-09-24 15:21:44 -04005576func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005577 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005578 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005579 // SSL 3.0 does not have tickets and TLS 1.3 does not
5580 // have session IDs, so skip their cross-resumption
5581 // tests.
5582 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5583 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5584 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005585 }
5586
David Benjamin8b8c0062014-11-23 02:47:52 -05005587 protocols := []protocol{tls}
5588 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5589 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005590 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005591 for _, protocol := range protocols {
5592 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5593 if protocol == dtls {
5594 suffix += "-DTLS"
5595 }
5596
David Benjaminece3de92015-03-16 18:02:20 -04005597 if sessionVers.version == resumeVers.version {
5598 testCases = append(testCases, testCase{
5599 protocol: protocol,
5600 name: "Resume-Client" + suffix,
5601 resumeSession: true,
5602 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005603 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005604 Bugs: ProtocolBugs{
5605 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5606 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5607 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005608 },
David Benjaminece3de92015-03-16 18:02:20 -04005609 expectedVersion: sessionVers.version,
5610 expectedResumeVersion: resumeVers.version,
5611 })
5612 } else {
David Benjamin405da482016-08-08 17:25:07 -04005613 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5614
5615 // Offering a TLS 1.3 session sends an empty session ID, so
5616 // there is no way to convince a non-lookahead client the
5617 // session was resumed. It will appear to the client that a
5618 // stray ChangeCipherSpec was sent.
5619 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5620 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005621 }
5622
David Benjaminece3de92015-03-16 18:02:20 -04005623 testCases = append(testCases, testCase{
5624 protocol: protocol,
5625 name: "Resume-Client-Mismatch" + suffix,
5626 resumeSession: true,
5627 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005628 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005629 },
David Benjaminece3de92015-03-16 18:02:20 -04005630 expectedVersion: sessionVers.version,
5631 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005632 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005633 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005634 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005635 },
5636 },
5637 expectedResumeVersion: resumeVers.version,
5638 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005639 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005640 })
5641 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005642
5643 testCases = append(testCases, testCase{
5644 protocol: protocol,
5645 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005646 resumeSession: true,
5647 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005648 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005649 },
5650 expectedVersion: sessionVers.version,
5651 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005652 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005653 },
5654 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005655 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005656 expectedResumeVersion: resumeVers.version,
5657 })
5658
David Benjamin8b8c0062014-11-23 02:47:52 -05005659 testCases = append(testCases, testCase{
5660 protocol: protocol,
5661 testType: serverTest,
5662 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005663 resumeSession: true,
5664 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005665 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005666 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005667 expectedVersion: sessionVers.version,
5668 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005669 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005670 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005671 Bugs: ProtocolBugs{
5672 SendBothTickets: true,
5673 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005674 },
5675 expectedResumeVersion: resumeVers.version,
5676 })
5677 }
David Benjamin01fe8202014-09-24 15:21:44 -04005678 }
5679 }
David Benjaminece3de92015-03-16 18:02:20 -04005680
David Benjamin4199b0d2016-11-01 13:58:25 -04005681 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005682 testCases = append(testCases, testCase{
5683 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005684 name: "ShimTicketRewritable",
5685 resumeSession: true,
5686 config: Config{
5687 MaxVersion: VersionTLS12,
5688 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5689 Bugs: ProtocolBugs{
5690 FilterTicket: func(in []byte) ([]byte, error) {
5691 in, err := SetShimTicketVersion(in, VersionTLS12)
5692 if err != nil {
5693 return nil, err
5694 }
5695 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5696 },
5697 },
5698 },
5699 flags: []string{
5700 "-ticket-key",
5701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5702 },
5703 })
5704
5705 // Resumptions are declined if the version does not match.
5706 testCases = append(testCases, testCase{
5707 testType: serverTest,
5708 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005709 resumeSession: true,
5710 config: Config{
5711 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005712 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005713 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005714 FilterTicket: func(in []byte) ([]byte, error) {
5715 return SetShimTicketVersion(in, VersionTLS13)
5716 },
5717 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005718 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005719 flags: []string{
5720 "-ticket-key",
5721 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5722 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005723 expectResumeRejected: true,
5724 })
5725
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005728 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005729 resumeSession: true,
5730 config: Config{
5731 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005732 Bugs: ProtocolBugs{
5733 FilterTicket: func(in []byte) ([]byte, error) {
5734 return SetShimTicketVersion(in, VersionTLS12)
5735 },
5736 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005737 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005738 flags: []string{
5739 "-ticket-key",
5740 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5741 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005742 expectResumeRejected: true,
5743 })
5744
David Benjamin4199b0d2016-11-01 13:58:25 -04005745 // Resumptions are declined if the cipher is invalid or disabled.
5746 testCases = append(testCases, testCase{
5747 testType: serverTest,
5748 name: "Resume-Server-DeclineBadCipher",
5749 resumeSession: true,
5750 config: Config{
5751 MaxVersion: VersionTLS12,
5752 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005753 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005754 FilterTicket: func(in []byte) ([]byte, error) {
5755 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5756 },
5757 },
5758 },
5759 flags: []string{
5760 "-ticket-key",
5761 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5762 },
5763 expectResumeRejected: true,
5764 })
5765
5766 testCases = append(testCases, testCase{
5767 testType: serverTest,
5768 name: "Resume-Server-DeclineBadCipher-2",
5769 resumeSession: true,
5770 config: Config{
5771 MaxVersion: VersionTLS12,
5772 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005773 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005774 FilterTicket: func(in []byte) ([]byte, error) {
5775 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5776 },
5777 },
5778 },
5779 flags: []string{
5780 "-cipher", "AES128",
5781 "-ticket-key",
5782 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5783 },
5784 expectResumeRejected: true,
5785 })
5786
David Benjaminf01f42a2016-11-16 19:05:33 +09005787 // Sessions are not resumed if they do not use the preferred cipher.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "Resume-Server-CipherNotPreferred",
5791 resumeSession: true,
5792 config: Config{
5793 MaxVersion: VersionTLS12,
5794 Bugs: ProtocolBugs{
5795 ExpectNewTicket: true,
5796 FilterTicket: func(in []byte) ([]byte, error) {
5797 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5798 },
5799 },
5800 },
5801 flags: []string{
5802 "-ticket-key",
5803 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5804 },
5805 shouldFail: false,
5806 expectResumeRejected: true,
5807 })
5808
5809 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5810 // PRF hashes match, but BoringSSL will always decline such resumptions.
5811 testCases = append(testCases, testCase{
5812 testType: serverTest,
5813 name: "Resume-Server-CipherNotPreferred-TLS13",
5814 resumeSession: true,
5815 config: Config{
5816 MaxVersion: VersionTLS13,
5817 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5818 Bugs: ProtocolBugs{
5819 FilterTicket: func(in []byte) ([]byte, error) {
5820 // If the client (runner) offers ChaCha20-Poly1305 first, the
5821 // server (shim) always prefers it. Switch it to AES-GCM.
5822 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5823 },
5824 },
5825 },
5826 flags: []string{
5827 "-ticket-key",
5828 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5829 },
5830 shouldFail: false,
5831 expectResumeRejected: true,
5832 })
5833
5834 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005835 testCases = append(testCases, testCase{
5836 testType: serverTest,
5837 name: "Resume-Server-DeclineBadCipher-TLS13",
5838 resumeSession: true,
5839 config: Config{
5840 MaxVersion: VersionTLS13,
5841 Bugs: ProtocolBugs{
5842 FilterTicket: func(in []byte) ([]byte, error) {
5843 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5844 },
5845 },
5846 },
5847 flags: []string{
5848 "-ticket-key",
5849 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5850 },
5851 expectResumeRejected: true,
5852 })
5853
David Benjaminf01f42a2016-11-16 19:05:33 +09005854 // If the client does not offer the cipher from the session, decline to
5855 // resume. Clients are forbidden from doing this, but BoringSSL selects
5856 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "Resume-Server-UnofferedCipher",
5860 resumeSession: true,
5861 config: Config{
5862 MaxVersion: VersionTLS12,
5863 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5864 },
5865 resumeConfig: &Config{
5866 MaxVersion: VersionTLS12,
5867 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5868 Bugs: ProtocolBugs{
5869 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5870 },
5871 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005872 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005873 })
5874
David Benjaminf01f42a2016-11-16 19:05:33 +09005875 // In TLS 1.3, clients may advertise a cipher list which does not
5876 // include the selected cipher. Test that we tolerate this. Servers may
5877 // resume at another cipher if the PRF matches, but BoringSSL will
5878 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005879 testCases = append(testCases, testCase{
5880 testType: serverTest,
5881 name: "Resume-Server-UnofferedCipher-TLS13",
5882 resumeSession: true,
5883 config: Config{
5884 MaxVersion: VersionTLS13,
5885 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5886 },
5887 resumeConfig: &Config{
5888 MaxVersion: VersionTLS13,
5889 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5890 Bugs: ProtocolBugs{
5891 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5892 },
5893 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005894 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005895 })
5896
David Benjamin4199b0d2016-11-01 13:58:25 -04005897 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005898 testCases = append(testCases, testCase{
5899 name: "Resume-Client-CipherMismatch",
5900 resumeSession: true,
5901 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005902 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005903 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5904 },
5905 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005906 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005907 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5908 Bugs: ProtocolBugs{
5909 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5910 },
5911 },
5912 shouldFail: true,
5913 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5914 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915
David Benjamine1cc35e2016-11-16 16:25:58 +09005916 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5917 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005918 testCases = append(testCases, testCase{
5919 name: "Resume-Client-CipherMismatch-TLS13",
5920 resumeSession: true,
5921 config: Config{
5922 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005923 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005924 },
5925 resumeConfig: &Config{
5926 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005927 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5928 },
5929 })
5930
5931 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5932 testCases = append(testCases, testCase{
5933 name: "Resume-Client-PRFMismatch-TLS13",
5934 resumeSession: true,
5935 config: Config{
5936 MaxVersion: VersionTLS13,
5937 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5938 },
5939 resumeConfig: &Config{
5940 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005941 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005942 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005943 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005944 },
5945 },
5946 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005947 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005948 })
Steven Valdeza833c352016-11-01 13:39:36 -04005949
5950 testCases = append(testCases, testCase{
5951 testType: serverTest,
5952 name: "Resume-Server-BinderWrongLength",
5953 resumeSession: true,
5954 config: Config{
5955 MaxVersion: VersionTLS13,
5956 Bugs: ProtocolBugs{
5957 SendShortPSKBinder: true,
5958 },
5959 },
5960 shouldFail: true,
5961 expectedLocalError: "remote error: error decrypting message",
5962 expectedError: ":DIGEST_CHECK_FAILED:",
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 testType: serverTest,
5967 name: "Resume-Server-NoPSKBinder",
5968 resumeSession: true,
5969 config: Config{
5970 MaxVersion: VersionTLS13,
5971 Bugs: ProtocolBugs{
5972 SendNoPSKBinder: true,
5973 },
5974 },
5975 shouldFail: true,
5976 expectedLocalError: "remote error: error decoding message",
5977 expectedError: ":DECODE_ERROR:",
5978 })
5979
5980 testCases = append(testCases, testCase{
5981 testType: serverTest,
5982 name: "Resume-Server-InvalidPSKBinder",
5983 resumeSession: true,
5984 config: Config{
5985 MaxVersion: VersionTLS13,
5986 Bugs: ProtocolBugs{
5987 SendInvalidPSKBinder: true,
5988 },
5989 },
5990 shouldFail: true,
5991 expectedLocalError: "remote error: error decrypting message",
5992 expectedError: ":DIGEST_CHECK_FAILED:",
5993 })
5994
5995 testCases = append(testCases, testCase{
5996 testType: serverTest,
5997 name: "Resume-Server-PSKBinderFirstExtension",
5998 resumeSession: true,
5999 config: Config{
6000 MaxVersion: VersionTLS13,
6001 Bugs: ProtocolBugs{
6002 PSKBinderFirst: true,
6003 },
6004 },
6005 shouldFail: true,
6006 expectedLocalError: "remote error: illegal parameter",
6007 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6008 })
David Benjamin01fe8202014-09-24 15:21:44 -04006009}
6010
Adam Langley2ae77d22014-10-28 17:29:33 -07006011func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006012 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006013 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006014 testType: serverTest,
6015 name: "Renegotiate-Server-Forbidden",
6016 config: Config{
6017 MaxVersion: VersionTLS12,
6018 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006019 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006020 shouldFail: true,
6021 expectedError: ":NO_RENEGOTIATION:",
6022 expectedLocalError: "remote error: no renegotiation",
6023 })
Adam Langley5021b222015-06-12 18:27:58 -07006024 // The server shouldn't echo the renegotiation extension unless
6025 // requested by the client.
6026 testCases = append(testCases, testCase{
6027 testType: serverTest,
6028 name: "Renegotiate-Server-NoExt",
6029 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006030 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006031 Bugs: ProtocolBugs{
6032 NoRenegotiationInfo: true,
6033 RequireRenegotiationInfo: true,
6034 },
6035 },
6036 shouldFail: true,
6037 expectedLocalError: "renegotiation extension missing",
6038 })
6039 // The renegotiation SCSV should be sufficient for the server to echo
6040 // the extension.
6041 testCases = append(testCases, testCase{
6042 testType: serverTest,
6043 name: "Renegotiate-Server-NoExt-SCSV",
6044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006045 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006046 Bugs: ProtocolBugs{
6047 NoRenegotiationInfo: true,
6048 SendRenegotiationSCSV: true,
6049 RequireRenegotiationInfo: true,
6050 },
6051 },
6052 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006053 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006054 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006056 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006057 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006058 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006059 },
6060 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006061 renegotiate: 1,
6062 flags: []string{
6063 "-renegotiate-freely",
6064 "-expect-total-renegotiations", "1",
6065 },
David Benjamincdea40c2015-03-19 14:09:43 -04006066 })
6067 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006068 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006069 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006071 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006072 Bugs: ProtocolBugs{
6073 EmptyRenegotiationInfo: true,
6074 },
6075 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006076 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006077 shouldFail: true,
6078 expectedError: ":RENEGOTIATION_MISMATCH:",
6079 })
6080 testCases = append(testCases, testCase{
6081 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006082 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006084 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006085 Bugs: ProtocolBugs{
6086 BadRenegotiationInfo: true,
6087 },
6088 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006089 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006090 shouldFail: true,
6091 expectedError: ":RENEGOTIATION_MISMATCH:",
6092 })
6093 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006094 name: "Renegotiate-Client-Downgrade",
6095 renegotiate: 1,
6096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006097 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006098 Bugs: ProtocolBugs{
6099 NoRenegotiationInfoAfterInitial: true,
6100 },
6101 },
6102 flags: []string{"-renegotiate-freely"},
6103 shouldFail: true,
6104 expectedError: ":RENEGOTIATION_MISMATCH:",
6105 })
6106 testCases = append(testCases, testCase{
6107 name: "Renegotiate-Client-Upgrade",
6108 renegotiate: 1,
6109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006110 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006111 Bugs: ProtocolBugs{
6112 NoRenegotiationInfoInInitial: true,
6113 },
6114 },
6115 flags: []string{"-renegotiate-freely"},
6116 shouldFail: true,
6117 expectedError: ":RENEGOTIATION_MISMATCH:",
6118 })
6119 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006120 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006121 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006123 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006124 Bugs: ProtocolBugs{
6125 NoRenegotiationInfo: true,
6126 },
6127 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006128 flags: []string{
6129 "-renegotiate-freely",
6130 "-expect-total-renegotiations", "1",
6131 },
David Benjamincff0b902015-05-15 23:09:47 -04006132 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006133
6134 // Test that the server may switch ciphers on renegotiation without
6135 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006136 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006137 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006139 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006140 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006141 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006142 },
6143 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006144 flags: []string{
6145 "-renegotiate-freely",
6146 "-expect-total-renegotiations", "1",
6147 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006148 })
6149 testCases = append(testCases, testCase{
6150 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006151 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006152 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006153 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6155 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006156 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006157 flags: []string{
6158 "-renegotiate-freely",
6159 "-expect-total-renegotiations", "1",
6160 },
David Benjaminb16346b2015-04-08 19:16:58 -04006161 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006162
6163 // Test that the server may not switch versions on renegotiation.
6164 testCases = append(testCases, testCase{
6165 name: "Renegotiate-Client-SwitchVersion",
6166 config: Config{
6167 MaxVersion: VersionTLS12,
6168 // Pick a cipher which exists at both versions.
6169 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6170 Bugs: ProtocolBugs{
6171 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006172 // Avoid failing early at the record layer.
6173 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006174 },
6175 },
6176 renegotiate: 1,
6177 flags: []string{
6178 "-renegotiate-freely",
6179 "-expect-total-renegotiations", "1",
6180 },
6181 shouldFail: true,
6182 expectedError: ":WRONG_SSL_VERSION:",
6183 })
6184
David Benjaminb16346b2015-04-08 19:16:58 -04006185 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006186 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006187 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006188 config: Config{
6189 MaxVersion: VersionTLS10,
6190 Bugs: ProtocolBugs{
6191 RequireSameRenegoClientVersion: true,
6192 },
6193 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006194 flags: []string{
6195 "-renegotiate-freely",
6196 "-expect-total-renegotiations", "1",
6197 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006198 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006199 testCases = append(testCases, testCase{
6200 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006201 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006202 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006203 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006204 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6205 NextProtos: []string{"foo"},
6206 },
6207 flags: []string{
6208 "-false-start",
6209 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006210 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006211 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006212 },
6213 shimWritesFirst: true,
6214 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006215
6216 // Client-side renegotiation controls.
6217 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006218 name: "Renegotiate-Client-Forbidden-1",
6219 config: Config{
6220 MaxVersion: VersionTLS12,
6221 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006222 renegotiate: 1,
6223 shouldFail: true,
6224 expectedError: ":NO_RENEGOTIATION:",
6225 expectedLocalError: "remote error: no renegotiation",
6226 })
6227 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006228 name: "Renegotiate-Client-Once-1",
6229 config: Config{
6230 MaxVersion: VersionTLS12,
6231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006232 renegotiate: 1,
6233 flags: []string{
6234 "-renegotiate-once",
6235 "-expect-total-renegotiations", "1",
6236 },
6237 })
6238 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006239 name: "Renegotiate-Client-Freely-1",
6240 config: Config{
6241 MaxVersion: VersionTLS12,
6242 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006243 renegotiate: 1,
6244 flags: []string{
6245 "-renegotiate-freely",
6246 "-expect-total-renegotiations", "1",
6247 },
6248 })
6249 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006250 name: "Renegotiate-Client-Once-2",
6251 config: Config{
6252 MaxVersion: VersionTLS12,
6253 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006254 renegotiate: 2,
6255 flags: []string{"-renegotiate-once"},
6256 shouldFail: true,
6257 expectedError: ":NO_RENEGOTIATION:",
6258 expectedLocalError: "remote error: no renegotiation",
6259 })
6260 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006261 name: "Renegotiate-Client-Freely-2",
6262 config: Config{
6263 MaxVersion: VersionTLS12,
6264 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006265 renegotiate: 2,
6266 flags: []string{
6267 "-renegotiate-freely",
6268 "-expect-total-renegotiations", "2",
6269 },
6270 })
Adam Langley27a0d082015-11-03 13:34:10 -08006271 testCases = append(testCases, testCase{
6272 name: "Renegotiate-Client-NoIgnore",
6273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006274 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006275 Bugs: ProtocolBugs{
6276 SendHelloRequestBeforeEveryAppDataRecord: true,
6277 },
6278 },
6279 shouldFail: true,
6280 expectedError: ":NO_RENEGOTIATION:",
6281 })
6282 testCases = append(testCases, testCase{
6283 name: "Renegotiate-Client-Ignore",
6284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006285 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006286 Bugs: ProtocolBugs{
6287 SendHelloRequestBeforeEveryAppDataRecord: true,
6288 },
6289 },
6290 flags: []string{
6291 "-renegotiate-ignore",
6292 "-expect-total-renegotiations", "0",
6293 },
6294 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295
David Benjamin34941c02016-10-08 11:45:31 -04006296 // Renegotiation is not allowed at SSL 3.0.
6297 testCases = append(testCases, testCase{
6298 name: "Renegotiate-Client-SSL3",
6299 config: Config{
6300 MaxVersion: VersionSSL30,
6301 },
6302 renegotiate: 1,
6303 flags: []string{
6304 "-renegotiate-freely",
6305 "-expect-total-renegotiations", "1",
6306 },
6307 shouldFail: true,
6308 expectedError: ":NO_RENEGOTIATION:",
6309 expectedLocalError: "remote error: no renegotiation",
6310 })
6311
David Benjamin397c8e62016-07-08 14:14:36 -07006312 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006313 testCases = append(testCases, testCase{
6314 name: "StrayHelloRequest",
6315 config: Config{
6316 MaxVersion: VersionTLS12,
6317 Bugs: ProtocolBugs{
6318 SendHelloRequestBeforeEveryHandshakeMessage: true,
6319 },
6320 },
6321 })
6322 testCases = append(testCases, testCase{
6323 name: "StrayHelloRequest-Packed",
6324 config: Config{
6325 MaxVersion: VersionTLS12,
6326 Bugs: ProtocolBugs{
6327 PackHandshakeFlight: true,
6328 SendHelloRequestBeforeEveryHandshakeMessage: true,
6329 },
6330 },
6331 })
6332
David Benjamin12d2c482016-07-24 10:56:51 -04006333 // Test renegotiation works if HelloRequest and server Finished come in
6334 // the same record.
6335 testCases = append(testCases, testCase{
6336 name: "Renegotiate-Client-Packed",
6337 config: Config{
6338 MaxVersion: VersionTLS12,
6339 Bugs: ProtocolBugs{
6340 PackHandshakeFlight: true,
6341 PackHelloRequestWithFinished: true,
6342 },
6343 },
6344 renegotiate: 1,
6345 flags: []string{
6346 "-renegotiate-freely",
6347 "-expect-total-renegotiations", "1",
6348 },
6349 })
6350
David Benjamin397c8e62016-07-08 14:14:36 -07006351 // Renegotiation is forbidden in TLS 1.3.
6352 testCases = append(testCases, testCase{
6353 name: "Renegotiate-Client-TLS13",
6354 config: Config{
6355 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006356 Bugs: ProtocolBugs{
6357 SendHelloRequestBeforeEveryAppDataRecord: true,
6358 },
David Benjamin397c8e62016-07-08 14:14:36 -07006359 },
David Benjamin397c8e62016-07-08 14:14:36 -07006360 flags: []string{
6361 "-renegotiate-freely",
6362 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006363 shouldFail: true,
6364 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006365 })
6366
6367 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6368 testCases = append(testCases, testCase{
6369 name: "StrayHelloRequest-TLS13",
6370 config: Config{
6371 MaxVersion: VersionTLS13,
6372 Bugs: ProtocolBugs{
6373 SendHelloRequestBeforeEveryHandshakeMessage: true,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedError: ":UNEXPECTED_MESSAGE:",
6378 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006379}
6380
David Benjamin5e961c12014-11-07 01:48:35 -05006381func addDTLSReplayTests() {
6382 // Test that sequence number replays are detected.
6383 testCases = append(testCases, testCase{
6384 protocol: dtls,
6385 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006386 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006387 replayWrites: true,
6388 })
6389
David Benjamin8e6db492015-07-25 18:29:23 -04006390 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006391 // than the retransmit window.
6392 testCases = append(testCases, testCase{
6393 protocol: dtls,
6394 name: "DTLS-Replay-LargeGaps",
6395 config: Config{
6396 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006397 SequenceNumberMapping: func(in uint64) uint64 {
6398 return in * 127
6399 },
David Benjamin5e961c12014-11-07 01:48:35 -05006400 },
6401 },
David Benjamin8e6db492015-07-25 18:29:23 -04006402 messageCount: 200,
6403 replayWrites: true,
6404 })
6405
6406 // Test the incoming sequence number changing non-monotonically.
6407 testCases = append(testCases, testCase{
6408 protocol: dtls,
6409 name: "DTLS-Replay-NonMonotonic",
6410 config: Config{
6411 Bugs: ProtocolBugs{
6412 SequenceNumberMapping: func(in uint64) uint64 {
6413 return in ^ 31
6414 },
6415 },
6416 },
6417 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006418 replayWrites: true,
6419 })
6420}
6421
Nick Harper60edffd2016-06-21 15:19:24 -07006422var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006423 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006424 id signatureAlgorithm
6425 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006426}{
Nick Harper60edffd2016-06-21 15:19:24 -07006427 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6428 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6429 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6430 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006431 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006432 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6433 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6434 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006435 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6436 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6437 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006438 // Tests for key types prior to TLS 1.2.
6439 {"RSA", 0, testCertRSA},
6440 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006441}
6442
Nick Harper60edffd2016-06-21 15:19:24 -07006443const fakeSigAlg1 signatureAlgorithm = 0x2a01
6444const fakeSigAlg2 signatureAlgorithm = 0xff01
6445
6446func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006447 // Not all ciphers involve a signature. Advertise a list which gives all
6448 // versions a signing cipher.
6449 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006450 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006451 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6452 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6453 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6454 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6455 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6456 }
6457
David Benjaminca3d5452016-07-14 12:51:01 -04006458 var allAlgorithms []signatureAlgorithm
6459 for _, alg := range testSignatureAlgorithms {
6460 if alg.id != 0 {
6461 allAlgorithms = append(allAlgorithms, alg.id)
6462 }
6463 }
6464
Nick Harper60edffd2016-06-21 15:19:24 -07006465 // Make sure each signature algorithm works. Include some fake values in
6466 // the list and ensure they're ignored.
6467 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006468 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006469 if (ver.version < VersionTLS12) != (alg.id == 0) {
6470 continue
6471 }
6472
6473 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6474 // or remove it in C.
6475 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006476 continue
6477 }
Nick Harper60edffd2016-06-21 15:19:24 -07006478
David Benjamin3ef76972016-10-17 17:59:54 -04006479 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006480 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006481 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006482 shouldSignFail = true
6483 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006484 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006485 // RSA-PKCS1 does not exist in TLS 1.3.
6486 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006487 shouldSignFail = true
6488 shouldVerifyFail = true
6489 }
6490
6491 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6492 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6493 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006494 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006495
6496 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006497 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006498 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006499 }
6500 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006501 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006502 }
David Benjamin000800a2014-11-14 01:43:59 -05006503
David Benjamin1fb125c2016-07-08 18:52:12 -07006504 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006505
David Benjamin7a41d372016-07-09 11:21:54 -07006506 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006507 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006508 config: Config{
6509 MaxVersion: ver.version,
6510 ClientAuth: RequireAnyClientCert,
6511 VerifySignatureAlgorithms: []signatureAlgorithm{
6512 fakeSigAlg1,
6513 alg.id,
6514 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006515 },
David Benjamin7a41d372016-07-09 11:21:54 -07006516 },
6517 flags: []string{
6518 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6519 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6520 "-enable-all-curves",
6521 },
David Benjamin3ef76972016-10-17 17:59:54 -04006522 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006523 expectedError: signError,
6524 expectedPeerSignatureAlgorithm: alg.id,
6525 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006526
David Benjamin7a41d372016-07-09 11:21:54 -07006527 testCases = append(testCases, testCase{
6528 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006529 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006530 config: Config{
6531 MaxVersion: ver.version,
6532 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6533 SignSignatureAlgorithms: []signatureAlgorithm{
6534 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006535 },
David Benjamin7a41d372016-07-09 11:21:54 -07006536 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006537 SkipECDSACurveCheck: shouldVerifyFail,
6538 IgnoreSignatureVersionChecks: shouldVerifyFail,
6539 // Some signature algorithms may not be advertised.
6540 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006541 },
David Benjamin7a41d372016-07-09 11:21:54 -07006542 },
6543 flags: []string{
6544 "-require-any-client-certificate",
6545 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6546 "-enable-all-curves",
6547 },
David Benjamin3ef76972016-10-17 17:59:54 -04006548 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006549 expectedError: verifyError,
6550 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006551
6552 testCases = append(testCases, testCase{
6553 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006554 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006555 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006556 MaxVersion: ver.version,
6557 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006558 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006559 fakeSigAlg1,
6560 alg.id,
6561 fakeSigAlg2,
6562 },
6563 },
6564 flags: []string{
6565 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6566 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6567 "-enable-all-curves",
6568 },
David Benjamin3ef76972016-10-17 17:59:54 -04006569 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006570 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006571 expectedPeerSignatureAlgorithm: alg.id,
6572 })
6573
6574 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006575 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006576 config: Config{
6577 MaxVersion: ver.version,
6578 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006579 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006580 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006581 alg.id,
6582 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006583 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006584 SkipECDSACurveCheck: shouldVerifyFail,
6585 IgnoreSignatureVersionChecks: shouldVerifyFail,
6586 // Some signature algorithms may not be advertised.
6587 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006588 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006589 },
6590 flags: []string{
6591 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6592 "-enable-all-curves",
6593 },
David Benjamin3ef76972016-10-17 17:59:54 -04006594 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006595 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006596 })
David Benjamin5208fd42016-07-13 21:43:25 -04006597
David Benjamin3ef76972016-10-17 17:59:54 -04006598 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006599 testCases = append(testCases, testCase{
6600 testType: serverTest,
6601 name: "ClientAuth-InvalidSignature" + suffix,
6602 config: Config{
6603 MaxVersion: ver.version,
6604 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6605 SignSignatureAlgorithms: []signatureAlgorithm{
6606 alg.id,
6607 },
6608 Bugs: ProtocolBugs{
6609 InvalidSignature: true,
6610 },
6611 },
6612 flags: []string{
6613 "-require-any-client-certificate",
6614 "-enable-all-curves",
6615 },
6616 shouldFail: true,
6617 expectedError: ":BAD_SIGNATURE:",
6618 })
6619
6620 testCases = append(testCases, testCase{
6621 name: "ServerAuth-InvalidSignature" + suffix,
6622 config: Config{
6623 MaxVersion: ver.version,
6624 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6625 CipherSuites: signingCiphers,
6626 SignSignatureAlgorithms: []signatureAlgorithm{
6627 alg.id,
6628 },
6629 Bugs: ProtocolBugs{
6630 InvalidSignature: true,
6631 },
6632 },
6633 flags: []string{"-enable-all-curves"},
6634 shouldFail: true,
6635 expectedError: ":BAD_SIGNATURE:",
6636 })
6637 }
David Benjaminca3d5452016-07-14 12:51:01 -04006638
David Benjamin3ef76972016-10-17 17:59:54 -04006639 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006640 testCases = append(testCases, testCase{
6641 name: "ClientAuth-Sign-Negotiate" + suffix,
6642 config: Config{
6643 MaxVersion: ver.version,
6644 ClientAuth: RequireAnyClientCert,
6645 VerifySignatureAlgorithms: allAlgorithms,
6646 },
6647 flags: []string{
6648 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6649 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6650 "-enable-all-curves",
6651 "-signing-prefs", strconv.Itoa(int(alg.id)),
6652 },
6653 expectedPeerSignatureAlgorithm: alg.id,
6654 })
6655
6656 testCases = append(testCases, testCase{
6657 testType: serverTest,
6658 name: "ServerAuth-Sign-Negotiate" + suffix,
6659 config: Config{
6660 MaxVersion: ver.version,
6661 CipherSuites: signingCiphers,
6662 VerifySignatureAlgorithms: allAlgorithms,
6663 },
6664 flags: []string{
6665 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6666 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6667 "-enable-all-curves",
6668 "-signing-prefs", strconv.Itoa(int(alg.id)),
6669 },
6670 expectedPeerSignatureAlgorithm: alg.id,
6671 })
6672 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006673 }
David Benjamin000800a2014-11-14 01:43:59 -05006674 }
6675
Nick Harper60edffd2016-06-21 15:19:24 -07006676 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006677 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006678 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006679 config: Config{
6680 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006681 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006682 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006683 signatureECDSAWithP521AndSHA512,
6684 signatureRSAPKCS1WithSHA384,
6685 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006686 },
6687 },
6688 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006689 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6690 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006691 },
Nick Harper60edffd2016-06-21 15:19:24 -07006692 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006693 })
6694
6695 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006696 name: "ClientAuth-SignatureType-TLS13",
6697 config: Config{
6698 ClientAuth: RequireAnyClientCert,
6699 MaxVersion: VersionTLS13,
6700 VerifySignatureAlgorithms: []signatureAlgorithm{
6701 signatureECDSAWithP521AndSHA512,
6702 signatureRSAPKCS1WithSHA384,
6703 signatureRSAPSSWithSHA384,
6704 signatureECDSAWithSHA1,
6705 },
6706 },
6707 flags: []string{
6708 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6709 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6710 },
6711 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6712 })
6713
6714 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006715 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006716 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006718 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006719 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006720 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006721 signatureECDSAWithP521AndSHA512,
6722 signatureRSAPKCS1WithSHA384,
6723 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006724 },
6725 },
Nick Harper60edffd2016-06-21 15:19:24 -07006726 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006727 })
6728
Steven Valdez143e8b32016-07-11 13:19:03 -04006729 testCases = append(testCases, testCase{
6730 testType: serverTest,
6731 name: "ServerAuth-SignatureType-TLS13",
6732 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006733 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006734 VerifySignatureAlgorithms: []signatureAlgorithm{
6735 signatureECDSAWithP521AndSHA512,
6736 signatureRSAPKCS1WithSHA384,
6737 signatureRSAPSSWithSHA384,
6738 signatureECDSAWithSHA1,
6739 },
6740 },
6741 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6742 })
6743
David Benjamina95e9f32016-07-08 16:28:04 -07006744 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006745 testCases = append(testCases, testCase{
6746 testType: serverTest,
6747 name: "Verify-ClientAuth-SignatureType",
6748 config: Config{
6749 MaxVersion: VersionTLS12,
6750 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006751 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006752 signatureRSAPKCS1WithSHA256,
6753 },
6754 Bugs: ProtocolBugs{
6755 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6756 },
6757 },
6758 flags: []string{
6759 "-require-any-client-certificate",
6760 },
6761 shouldFail: true,
6762 expectedError: ":WRONG_SIGNATURE_TYPE:",
6763 })
6764
6765 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006766 testType: serverTest,
6767 name: "Verify-ClientAuth-SignatureType-TLS13",
6768 config: Config{
6769 MaxVersion: VersionTLS13,
6770 Certificates: []Certificate{rsaCertificate},
6771 SignSignatureAlgorithms: []signatureAlgorithm{
6772 signatureRSAPSSWithSHA256,
6773 },
6774 Bugs: ProtocolBugs{
6775 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6776 },
6777 },
6778 flags: []string{
6779 "-require-any-client-certificate",
6780 },
6781 shouldFail: true,
6782 expectedError: ":WRONG_SIGNATURE_TYPE:",
6783 })
6784
6785 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006786 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006787 config: Config{
6788 MaxVersion: VersionTLS12,
6789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006790 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006791 signatureRSAPKCS1WithSHA256,
6792 },
6793 Bugs: ProtocolBugs{
6794 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6795 },
6796 },
6797 shouldFail: true,
6798 expectedError: ":WRONG_SIGNATURE_TYPE:",
6799 })
6800
Steven Valdez143e8b32016-07-11 13:19:03 -04006801 testCases = append(testCases, testCase{
6802 name: "Verify-ServerAuth-SignatureType-TLS13",
6803 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006804 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006805 SignSignatureAlgorithms: []signatureAlgorithm{
6806 signatureRSAPSSWithSHA256,
6807 },
6808 Bugs: ProtocolBugs{
6809 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6810 },
6811 },
6812 shouldFail: true,
6813 expectedError: ":WRONG_SIGNATURE_TYPE:",
6814 })
6815
David Benjamin51dd7d62016-07-08 16:07:01 -07006816 // Test that, if the list is missing, the peer falls back to SHA-1 in
6817 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006818 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006819 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006821 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006822 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006823 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006824 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006825 },
6826 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006827 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006828 },
6829 },
6830 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006831 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6832 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006833 },
6834 })
6835
6836 testCases = append(testCases, testCase{
6837 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006838 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006839 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006840 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006841 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006842 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006843 },
6844 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006845 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006846 },
6847 },
David Benjaminee32bea2016-08-17 13:36:44 -04006848 flags: []string{
6849 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6850 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6851 },
6852 })
6853
6854 testCases = append(testCases, testCase{
6855 name: "ClientAuth-SHA1-Fallback-ECDSA",
6856 config: Config{
6857 MaxVersion: VersionTLS12,
6858 ClientAuth: RequireAnyClientCert,
6859 VerifySignatureAlgorithms: []signatureAlgorithm{
6860 signatureECDSAWithSHA1,
6861 },
6862 Bugs: ProtocolBugs{
6863 NoSignatureAlgorithms: true,
6864 },
6865 },
6866 flags: []string{
6867 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6868 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6869 },
6870 })
6871
6872 testCases = append(testCases, testCase{
6873 testType: serverTest,
6874 name: "ServerAuth-SHA1-Fallback-ECDSA",
6875 config: Config{
6876 MaxVersion: VersionTLS12,
6877 VerifySignatureAlgorithms: []signatureAlgorithm{
6878 signatureECDSAWithSHA1,
6879 },
6880 Bugs: ProtocolBugs{
6881 NoSignatureAlgorithms: true,
6882 },
6883 },
6884 flags: []string{
6885 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6886 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6887 },
David Benjamin000800a2014-11-14 01:43:59 -05006888 })
David Benjamin72dc7832015-03-16 17:49:43 -04006889
David Benjamin51dd7d62016-07-08 16:07:01 -07006890 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006891 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006892 config: Config{
6893 MaxVersion: VersionTLS13,
6894 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006895 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006896 signatureRSAPKCS1WithSHA1,
6897 },
6898 Bugs: ProtocolBugs{
6899 NoSignatureAlgorithms: true,
6900 },
6901 },
6902 flags: []string{
6903 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6904 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6905 },
David Benjamin48901652016-08-01 12:12:47 -04006906 shouldFail: true,
6907 // An empty CertificateRequest signature algorithm list is a
6908 // syntax error in TLS 1.3.
6909 expectedError: ":DECODE_ERROR:",
6910 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006911 })
6912
6913 testCases = append(testCases, testCase{
6914 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006915 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006916 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006917 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006918 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006919 signatureRSAPKCS1WithSHA1,
6920 },
6921 Bugs: ProtocolBugs{
6922 NoSignatureAlgorithms: true,
6923 },
6924 },
6925 shouldFail: true,
6926 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6927 })
6928
David Benjaminb62d2872016-07-18 14:55:02 +02006929 // Test that hash preferences are enforced. BoringSSL does not implement
6930 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006931 testCases = append(testCases, testCase{
6932 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006933 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006935 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006936 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006937 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006938 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006939 },
6940 Bugs: ProtocolBugs{
6941 IgnorePeerSignatureAlgorithmPreferences: true,
6942 },
6943 },
6944 flags: []string{"-require-any-client-certificate"},
6945 shouldFail: true,
6946 expectedError: ":WRONG_SIGNATURE_TYPE:",
6947 })
6948
6949 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006950 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006952 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006953 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006954 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006955 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006956 },
6957 Bugs: ProtocolBugs{
6958 IgnorePeerSignatureAlgorithmPreferences: true,
6959 },
6960 },
6961 shouldFail: true,
6962 expectedError: ":WRONG_SIGNATURE_TYPE:",
6963 })
David Benjaminb62d2872016-07-18 14:55:02 +02006964 testCases = append(testCases, testCase{
6965 testType: serverTest,
6966 name: "ClientAuth-Enforced-TLS13",
6967 config: Config{
6968 MaxVersion: VersionTLS13,
6969 Certificates: []Certificate{rsaCertificate},
6970 SignSignatureAlgorithms: []signatureAlgorithm{
6971 signatureRSAPKCS1WithMD5,
6972 },
6973 Bugs: ProtocolBugs{
6974 IgnorePeerSignatureAlgorithmPreferences: true,
6975 IgnoreSignatureVersionChecks: true,
6976 },
6977 },
6978 flags: []string{"-require-any-client-certificate"},
6979 shouldFail: true,
6980 expectedError: ":WRONG_SIGNATURE_TYPE:",
6981 })
6982
6983 testCases = append(testCases, testCase{
6984 name: "ServerAuth-Enforced-TLS13",
6985 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006986 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006987 SignSignatureAlgorithms: []signatureAlgorithm{
6988 signatureRSAPKCS1WithMD5,
6989 },
6990 Bugs: ProtocolBugs{
6991 IgnorePeerSignatureAlgorithmPreferences: true,
6992 IgnoreSignatureVersionChecks: true,
6993 },
6994 },
6995 shouldFail: true,
6996 expectedError: ":WRONG_SIGNATURE_TYPE:",
6997 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006998
6999 // Test that the agreed upon digest respects the client preferences and
7000 // the server digests.
7001 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007002 name: "NoCommonAlgorithms-Digests",
7003 config: Config{
7004 MaxVersion: VersionTLS12,
7005 ClientAuth: RequireAnyClientCert,
7006 VerifySignatureAlgorithms: []signatureAlgorithm{
7007 signatureRSAPKCS1WithSHA512,
7008 signatureRSAPKCS1WithSHA1,
7009 },
7010 },
7011 flags: []string{
7012 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7013 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7014 "-digest-prefs", "SHA256",
7015 },
7016 shouldFail: true,
7017 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7018 })
7019 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007020 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007022 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007023 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007024 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007025 signatureRSAPKCS1WithSHA512,
7026 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007027 },
7028 },
7029 flags: []string{
7030 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7031 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007032 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007033 },
David Benjaminca3d5452016-07-14 12:51:01 -04007034 shouldFail: true,
7035 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7036 })
7037 testCases = append(testCases, testCase{
7038 name: "NoCommonAlgorithms-TLS13",
7039 config: Config{
7040 MaxVersion: VersionTLS13,
7041 ClientAuth: RequireAnyClientCert,
7042 VerifySignatureAlgorithms: []signatureAlgorithm{
7043 signatureRSAPSSWithSHA512,
7044 signatureRSAPSSWithSHA384,
7045 },
7046 },
7047 flags: []string{
7048 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7049 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7050 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7051 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007052 shouldFail: true,
7053 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007054 })
7055 testCases = append(testCases, testCase{
7056 name: "Agree-Digest-SHA256",
7057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007058 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007059 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007060 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007061 signatureRSAPKCS1WithSHA1,
7062 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007063 },
7064 },
7065 flags: []string{
7066 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7067 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007068 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007069 },
Nick Harper60edffd2016-06-21 15:19:24 -07007070 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007071 })
7072 testCases = append(testCases, testCase{
7073 name: "Agree-Digest-SHA1",
7074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007075 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007076 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007077 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007078 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007079 },
7080 },
7081 flags: []string{
7082 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7083 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007084 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007085 },
Nick Harper60edffd2016-06-21 15:19:24 -07007086 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007087 })
7088 testCases = append(testCases, testCase{
7089 name: "Agree-Digest-Default",
7090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007091 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007092 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007093 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007094 signatureRSAPKCS1WithSHA256,
7095 signatureECDSAWithP256AndSHA256,
7096 signatureRSAPKCS1WithSHA1,
7097 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007098 },
7099 },
7100 flags: []string{
7101 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7102 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7103 },
Nick Harper60edffd2016-06-21 15:19:24 -07007104 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007105 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007106
David Benjaminca3d5452016-07-14 12:51:01 -04007107 // Test that the signing preference list may include extra algorithms
7108 // without negotiation problems.
7109 testCases = append(testCases, testCase{
7110 testType: serverTest,
7111 name: "FilterExtraAlgorithms",
7112 config: Config{
7113 MaxVersion: VersionTLS12,
7114 VerifySignatureAlgorithms: []signatureAlgorithm{
7115 signatureRSAPKCS1WithSHA256,
7116 },
7117 },
7118 flags: []string{
7119 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7120 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7121 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7122 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7123 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7124 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7125 },
7126 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7127 })
7128
David Benjamin4c3ddf72016-06-29 18:13:53 -04007129 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7130 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007131 testCases = append(testCases, testCase{
7132 name: "CheckLeafCurve",
7133 config: Config{
7134 MaxVersion: VersionTLS12,
7135 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007136 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007137 },
7138 flags: []string{"-p384-only"},
7139 shouldFail: true,
7140 expectedError: ":BAD_ECC_CERT:",
7141 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007142
7143 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7144 testCases = append(testCases, testCase{
7145 name: "CheckLeafCurve-TLS13",
7146 config: Config{
7147 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007148 Certificates: []Certificate{ecdsaP256Certificate},
7149 },
7150 flags: []string{"-p384-only"},
7151 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007152
7153 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7154 testCases = append(testCases, testCase{
7155 name: "ECDSACurveMismatch-Verify-TLS12",
7156 config: Config{
7157 MaxVersion: VersionTLS12,
7158 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7159 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007160 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007161 signatureECDSAWithP384AndSHA384,
7162 },
7163 },
7164 })
7165
7166 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7167 testCases = append(testCases, testCase{
7168 name: "ECDSACurveMismatch-Verify-TLS13",
7169 config: Config{
7170 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007171 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007172 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007173 signatureECDSAWithP384AndSHA384,
7174 },
7175 Bugs: ProtocolBugs{
7176 SkipECDSACurveCheck: true,
7177 },
7178 },
7179 shouldFail: true,
7180 expectedError: ":WRONG_SIGNATURE_TYPE:",
7181 })
7182
7183 // Signature algorithm selection in TLS 1.3 should take the curve into
7184 // account.
7185 testCases = append(testCases, testCase{
7186 testType: serverTest,
7187 name: "ECDSACurveMismatch-Sign-TLS13",
7188 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007189 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007190 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007191 signatureECDSAWithP384AndSHA384,
7192 signatureECDSAWithP256AndSHA256,
7193 },
7194 },
7195 flags: []string{
7196 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7197 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7198 },
7199 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7200 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007201
7202 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7203 // server does not attempt to sign in that case.
7204 testCases = append(testCases, testCase{
7205 testType: serverTest,
7206 name: "RSA-PSS-Large",
7207 config: Config{
7208 MaxVersion: VersionTLS13,
7209 VerifySignatureAlgorithms: []signatureAlgorithm{
7210 signatureRSAPSSWithSHA512,
7211 },
7212 },
7213 flags: []string{
7214 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7215 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7216 },
7217 shouldFail: true,
7218 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7219 })
David Benjamin57e929f2016-08-30 00:30:38 -04007220
7221 // Test that RSA-PSS is enabled by default for TLS 1.2.
7222 testCases = append(testCases, testCase{
7223 testType: clientTest,
7224 name: "RSA-PSS-Default-Verify",
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 SignSignatureAlgorithms: []signatureAlgorithm{
7228 signatureRSAPSSWithSHA256,
7229 },
7230 },
7231 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7232 })
7233
7234 testCases = append(testCases, testCase{
7235 testType: serverTest,
7236 name: "RSA-PSS-Default-Sign",
7237 config: Config{
7238 MaxVersion: VersionTLS12,
7239 VerifySignatureAlgorithms: []signatureAlgorithm{
7240 signatureRSAPSSWithSHA256,
7241 },
7242 },
7243 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7244 })
David Benjamin000800a2014-11-14 01:43:59 -05007245}
7246
David Benjamin83f90402015-01-27 01:09:43 -05007247// timeouts is the retransmit schedule for BoringSSL. It doubles and
7248// caps at 60 seconds. On the 13th timeout, it gives up.
7249var timeouts = []time.Duration{
7250 1 * time.Second,
7251 2 * time.Second,
7252 4 * time.Second,
7253 8 * time.Second,
7254 16 * time.Second,
7255 32 * time.Second,
7256 60 * 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}
7264
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007265// shortTimeouts is an alternate set of timeouts which would occur if the
7266// initial timeout duration was set to 250ms.
7267var shortTimeouts = []time.Duration{
7268 250 * time.Millisecond,
7269 500 * time.Millisecond,
7270 1 * time.Second,
7271 2 * time.Second,
7272 4 * time.Second,
7273 8 * time.Second,
7274 16 * time.Second,
7275 32 * time.Second,
7276 60 * time.Second,
7277 60 * time.Second,
7278 60 * time.Second,
7279 60 * time.Second,
7280 60 * time.Second,
7281}
7282
David Benjamin83f90402015-01-27 01:09:43 -05007283func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007284 // These tests work by coordinating some behavior on both the shim and
7285 // the runner.
7286 //
7287 // TimeoutSchedule configures the runner to send a series of timeout
7288 // opcodes to the shim (see packetAdaptor) immediately before reading
7289 // each peer handshake flight N. The timeout opcode both simulates a
7290 // timeout in the shim and acts as a synchronization point to help the
7291 // runner bracket each handshake flight.
7292 //
7293 // We assume the shim does not read from the channel eagerly. It must
7294 // first wait until it has sent flight N and is ready to receive
7295 // handshake flight N+1. At this point, it will process the timeout
7296 // opcode. It must then immediately respond with a timeout ACK and act
7297 // as if the shim was idle for the specified amount of time.
7298 //
7299 // The runner then drops all packets received before the ACK and
7300 // continues waiting for flight N. This ordering results in one attempt
7301 // at sending flight N to be dropped. For the test to complete, the
7302 // shim must send flight N again, testing that the shim implements DTLS
7303 // retransmit on a timeout.
7304
Steven Valdez143e8b32016-07-11 13:19:03 -04007305 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007306 // likely be more epochs to cross and the final message's retransmit may
7307 // be more complex.
7308
David Benjamin585d7a42016-06-02 14:58:00 -04007309 for _, async := range []bool{true, false} {
7310 var tests []testCase
7311
7312 // Test that this is indeed the timeout schedule. Stress all
7313 // four patterns of handshake.
7314 for i := 1; i < len(timeouts); i++ {
7315 number := strconv.Itoa(i)
7316 tests = append(tests, testCase{
7317 protocol: dtls,
7318 name: "DTLS-Retransmit-Client-" + number,
7319 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007320 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007321 Bugs: ProtocolBugs{
7322 TimeoutSchedule: timeouts[:i],
7323 },
7324 },
7325 resumeSession: true,
7326 })
7327 tests = append(tests, testCase{
7328 protocol: dtls,
7329 testType: serverTest,
7330 name: "DTLS-Retransmit-Server-" + number,
7331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007332 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007333 Bugs: ProtocolBugs{
7334 TimeoutSchedule: timeouts[:i],
7335 },
7336 },
7337 resumeSession: true,
7338 })
7339 }
7340
7341 // Test that exceeding the timeout schedule hits a read
7342 // timeout.
7343 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007344 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007345 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007346 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007347 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007348 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007349 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007350 },
7351 },
7352 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007353 shouldFail: true,
7354 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007355 })
David Benjamin585d7a42016-06-02 14:58:00 -04007356
7357 if async {
7358 // Test that timeout handling has a fudge factor, due to API
7359 // problems.
7360 tests = append(tests, testCase{
7361 protocol: dtls,
7362 name: "DTLS-Retransmit-Fudge",
7363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007364 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007365 Bugs: ProtocolBugs{
7366 TimeoutSchedule: []time.Duration{
7367 timeouts[0] - 10*time.Millisecond,
7368 },
7369 },
7370 },
7371 resumeSession: true,
7372 })
7373 }
7374
7375 // Test that the final Finished retransmitting isn't
7376 // duplicated if the peer badly fragments everything.
7377 tests = append(tests, testCase{
7378 testType: serverTest,
7379 protocol: dtls,
7380 name: "DTLS-Retransmit-Fragmented",
7381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007382 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007383 Bugs: ProtocolBugs{
7384 TimeoutSchedule: []time.Duration{timeouts[0]},
7385 MaxHandshakeRecordLength: 2,
7386 },
7387 },
7388 })
7389
7390 // Test the timeout schedule when a shorter initial timeout duration is set.
7391 tests = append(tests, testCase{
7392 protocol: dtls,
7393 name: "DTLS-Retransmit-Short-Client",
7394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007395 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007396 Bugs: ProtocolBugs{
7397 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7398 },
7399 },
7400 resumeSession: true,
7401 flags: []string{"-initial-timeout-duration-ms", "250"},
7402 })
7403 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007404 protocol: dtls,
7405 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007406 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007408 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007409 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007410 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007411 },
7412 },
7413 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007414 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007415 })
David Benjamin585d7a42016-06-02 14:58:00 -04007416
7417 for _, test := range tests {
7418 if async {
7419 test.name += "-Async"
7420 test.flags = append(test.flags, "-async")
7421 }
7422
7423 testCases = append(testCases, test)
7424 }
David Benjamin83f90402015-01-27 01:09:43 -05007425 }
David Benjamin83f90402015-01-27 01:09:43 -05007426}
7427
David Benjaminc565ebb2015-04-03 04:06:36 -04007428func addExportKeyingMaterialTests() {
7429 for _, vers := range tlsVersions {
7430 if vers.version == VersionSSL30 {
7431 continue
7432 }
7433 testCases = append(testCases, testCase{
7434 name: "ExportKeyingMaterial-" + vers.name,
7435 config: Config{
7436 MaxVersion: vers.version,
7437 },
7438 exportKeyingMaterial: 1024,
7439 exportLabel: "label",
7440 exportContext: "context",
7441 useExportContext: true,
7442 })
7443 testCases = append(testCases, testCase{
7444 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7445 config: Config{
7446 MaxVersion: vers.version,
7447 },
7448 exportKeyingMaterial: 1024,
7449 })
7450 testCases = append(testCases, testCase{
7451 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7452 config: Config{
7453 MaxVersion: vers.version,
7454 },
7455 exportKeyingMaterial: 1024,
7456 useExportContext: true,
7457 })
7458 testCases = append(testCases, testCase{
7459 name: "ExportKeyingMaterial-Small-" + vers.name,
7460 config: Config{
7461 MaxVersion: vers.version,
7462 },
7463 exportKeyingMaterial: 1,
7464 exportLabel: "label",
7465 exportContext: "context",
7466 useExportContext: true,
7467 })
7468 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007469
David Benjaminc565ebb2015-04-03 04:06:36 -04007470 testCases = append(testCases, testCase{
7471 name: "ExportKeyingMaterial-SSL3",
7472 config: Config{
7473 MaxVersion: VersionSSL30,
7474 },
7475 exportKeyingMaterial: 1024,
7476 exportLabel: "label",
7477 exportContext: "context",
7478 useExportContext: true,
7479 shouldFail: true,
7480 expectedError: "failed to export keying material",
7481 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007482
7483 // Exporters work during a False Start.
7484 testCases = append(testCases, testCase{
7485 name: "ExportKeyingMaterial-FalseStart",
7486 config: Config{
7487 MaxVersion: VersionTLS12,
7488 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7489 NextProtos: []string{"foo"},
7490 Bugs: ProtocolBugs{
7491 ExpectFalseStart: true,
7492 },
7493 },
7494 flags: []string{
7495 "-false-start",
7496 "-advertise-alpn", "\x03foo",
7497 },
7498 shimWritesFirst: true,
7499 exportKeyingMaterial: 1024,
7500 exportLabel: "label",
7501 exportContext: "context",
7502 useExportContext: true,
7503 })
7504
7505 // Exporters do not work in the middle of a renegotiation. Test this by
7506 // triggering the exporter after every SSL_read call and configuring the
7507 // shim to run asynchronously.
7508 testCases = append(testCases, testCase{
7509 name: "ExportKeyingMaterial-Renegotiate",
7510 config: Config{
7511 MaxVersion: VersionTLS12,
7512 },
7513 renegotiate: 1,
7514 flags: []string{
7515 "-async",
7516 "-use-exporter-between-reads",
7517 "-renegotiate-freely",
7518 "-expect-total-renegotiations", "1",
7519 },
7520 shouldFail: true,
7521 expectedError: "failed to export keying material",
7522 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007523}
7524
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007525func addTLSUniqueTests() {
7526 for _, isClient := range []bool{false, true} {
7527 for _, isResumption := range []bool{false, true} {
7528 for _, hasEMS := range []bool{false, true} {
7529 var suffix string
7530 if isResumption {
7531 suffix = "Resume-"
7532 } else {
7533 suffix = "Full-"
7534 }
7535
7536 if hasEMS {
7537 suffix += "EMS-"
7538 } else {
7539 suffix += "NoEMS-"
7540 }
7541
7542 if isClient {
7543 suffix += "Client"
7544 } else {
7545 suffix += "Server"
7546 }
7547
7548 test := testCase{
7549 name: "TLSUnique-" + suffix,
7550 testTLSUnique: true,
7551 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007552 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007553 Bugs: ProtocolBugs{
7554 NoExtendedMasterSecret: !hasEMS,
7555 },
7556 },
7557 }
7558
7559 if isResumption {
7560 test.resumeSession = true
7561 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007562 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007563 Bugs: ProtocolBugs{
7564 NoExtendedMasterSecret: !hasEMS,
7565 },
7566 }
7567 }
7568
7569 if isResumption && !hasEMS {
7570 test.shouldFail = true
7571 test.expectedError = "failed to get tls-unique"
7572 }
7573
7574 testCases = append(testCases, test)
7575 }
7576 }
7577 }
7578}
7579
Adam Langley09505632015-07-30 18:10:13 -07007580func addCustomExtensionTests() {
7581 expectedContents := "custom extension"
7582 emptyString := ""
7583
7584 for _, isClient := range []bool{false, true} {
7585 suffix := "Server"
7586 flag := "-enable-server-custom-extension"
7587 testType := serverTest
7588 if isClient {
7589 suffix = "Client"
7590 flag = "-enable-client-custom-extension"
7591 testType = clientTest
7592 }
7593
7594 testCases = append(testCases, testCase{
7595 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007596 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007598 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007599 Bugs: ProtocolBugs{
7600 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007601 ExpectedCustomExtension: &expectedContents,
7602 },
7603 },
7604 flags: []string{flag},
7605 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007606 testCases = append(testCases, testCase{
7607 testType: testType,
7608 name: "CustomExtensions-" + suffix + "-TLS13",
7609 config: Config{
7610 MaxVersion: VersionTLS13,
7611 Bugs: ProtocolBugs{
7612 CustomExtension: expectedContents,
7613 ExpectedCustomExtension: &expectedContents,
7614 },
7615 },
7616 flags: []string{flag},
7617 })
Adam Langley09505632015-07-30 18:10:13 -07007618
7619 // If the parse callback fails, the handshake should also fail.
7620 testCases = append(testCases, testCase{
7621 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007622 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007623 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007624 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007625 Bugs: ProtocolBugs{
7626 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007627 ExpectedCustomExtension: &expectedContents,
7628 },
7629 },
David Benjamin399e7c92015-07-30 23:01:27 -04007630 flags: []string{flag},
7631 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007632 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7633 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007634 testCases = append(testCases, testCase{
7635 testType: testType,
7636 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7637 config: Config{
7638 MaxVersion: VersionTLS13,
7639 Bugs: ProtocolBugs{
7640 CustomExtension: expectedContents + "foo",
7641 ExpectedCustomExtension: &expectedContents,
7642 },
7643 },
7644 flags: []string{flag},
7645 shouldFail: true,
7646 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7647 })
Adam Langley09505632015-07-30 18:10:13 -07007648
7649 // If the add callback fails, the handshake should also fail.
7650 testCases = append(testCases, testCase{
7651 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007652 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007653 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007654 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007655 Bugs: ProtocolBugs{
7656 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007657 ExpectedCustomExtension: &expectedContents,
7658 },
7659 },
David Benjamin399e7c92015-07-30 23:01:27 -04007660 flags: []string{flag, "-custom-extension-fail-add"},
7661 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007662 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7663 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007664 testCases = append(testCases, testCase{
7665 testType: testType,
7666 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7667 config: Config{
7668 MaxVersion: VersionTLS13,
7669 Bugs: ProtocolBugs{
7670 CustomExtension: expectedContents,
7671 ExpectedCustomExtension: &expectedContents,
7672 },
7673 },
7674 flags: []string{flag, "-custom-extension-fail-add"},
7675 shouldFail: true,
7676 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7677 })
Adam Langley09505632015-07-30 18:10:13 -07007678
7679 // If the add callback returns zero, no extension should be
7680 // added.
7681 skipCustomExtension := expectedContents
7682 if isClient {
7683 // For the case where the client skips sending the
7684 // custom extension, the server must not “echo” it.
7685 skipCustomExtension = ""
7686 }
7687 testCases = append(testCases, testCase{
7688 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007689 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007690 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007691 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007692 Bugs: ProtocolBugs{
7693 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007694 ExpectedCustomExtension: &emptyString,
7695 },
7696 },
7697 flags: []string{flag, "-custom-extension-skip"},
7698 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007699 testCases = append(testCases, testCase{
7700 testType: testType,
7701 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7702 config: Config{
7703 MaxVersion: VersionTLS13,
7704 Bugs: ProtocolBugs{
7705 CustomExtension: skipCustomExtension,
7706 ExpectedCustomExtension: &emptyString,
7707 },
7708 },
7709 flags: []string{flag, "-custom-extension-skip"},
7710 })
Adam Langley09505632015-07-30 18:10:13 -07007711 }
7712
7713 // The custom extension add callback should not be called if the client
7714 // doesn't send the extension.
7715 testCases = append(testCases, testCase{
7716 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007717 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007719 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007720 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007721 ExpectedCustomExtension: &emptyString,
7722 },
7723 },
7724 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7725 })
Adam Langley2deb9842015-08-07 11:15:37 -07007726
Steven Valdez143e8b32016-07-11 13:19:03 -04007727 testCases = append(testCases, testCase{
7728 testType: serverTest,
7729 name: "CustomExtensions-NotCalled-Server-TLS13",
7730 config: Config{
7731 MaxVersion: VersionTLS13,
7732 Bugs: ProtocolBugs{
7733 ExpectedCustomExtension: &emptyString,
7734 },
7735 },
7736 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7737 })
7738
Adam Langley2deb9842015-08-07 11:15:37 -07007739 // Test an unknown extension from the server.
7740 testCases = append(testCases, testCase{
7741 testType: clientTest,
7742 name: "UnknownExtension-Client",
7743 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007744 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007745 Bugs: ProtocolBugs{
7746 CustomExtension: expectedContents,
7747 },
7748 },
David Benjamin0c40a962016-08-01 12:05:50 -04007749 shouldFail: true,
7750 expectedError: ":UNEXPECTED_EXTENSION:",
7751 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007752 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007753 testCases = append(testCases, testCase{
7754 testType: clientTest,
7755 name: "UnknownExtension-Client-TLS13",
7756 config: Config{
7757 MaxVersion: VersionTLS13,
7758 Bugs: ProtocolBugs{
7759 CustomExtension: expectedContents,
7760 },
7761 },
David Benjamin0c40a962016-08-01 12:05:50 -04007762 shouldFail: true,
7763 expectedError: ":UNEXPECTED_EXTENSION:",
7764 expectedLocalError: "remote error: unsupported extension",
7765 })
David Benjamin490469f2016-10-05 22:44:38 -04007766 testCases = append(testCases, testCase{
7767 testType: clientTest,
7768 name: "UnknownUnencryptedExtension-Client-TLS13",
7769 config: Config{
7770 MaxVersion: VersionTLS13,
7771 Bugs: ProtocolBugs{
7772 CustomUnencryptedExtension: expectedContents,
7773 },
7774 },
7775 shouldFail: true,
7776 expectedError: ":UNEXPECTED_EXTENSION:",
7777 // The shim must send an alert, but alerts at this point do not
7778 // get successfully decrypted by the runner.
7779 expectedLocalError: "local error: bad record MAC",
7780 })
7781 testCases = append(testCases, testCase{
7782 testType: clientTest,
7783 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7784 config: Config{
7785 MaxVersion: VersionTLS13,
7786 Bugs: ProtocolBugs{
7787 SendUnencryptedALPN: "foo",
7788 },
7789 },
7790 flags: []string{
7791 "-advertise-alpn", "\x03foo\x03bar",
7792 },
7793 shouldFail: true,
7794 expectedError: ":UNEXPECTED_EXTENSION:",
7795 // The shim must send an alert, but alerts at this point do not
7796 // get successfully decrypted by the runner.
7797 expectedLocalError: "local error: bad record MAC",
7798 })
David Benjamin0c40a962016-08-01 12:05:50 -04007799
7800 // Test a known but unoffered extension from the server.
7801 testCases = append(testCases, testCase{
7802 testType: clientTest,
7803 name: "UnofferedExtension-Client",
7804 config: Config{
7805 MaxVersion: VersionTLS12,
7806 Bugs: ProtocolBugs{
7807 SendALPN: "alpn",
7808 },
7809 },
7810 shouldFail: true,
7811 expectedError: ":UNEXPECTED_EXTENSION:",
7812 expectedLocalError: "remote error: unsupported extension",
7813 })
7814 testCases = append(testCases, testCase{
7815 testType: clientTest,
7816 name: "UnofferedExtension-Client-TLS13",
7817 config: Config{
7818 MaxVersion: VersionTLS13,
7819 Bugs: ProtocolBugs{
7820 SendALPN: "alpn",
7821 },
7822 },
7823 shouldFail: true,
7824 expectedError: ":UNEXPECTED_EXTENSION:",
7825 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007826 })
Adam Langley09505632015-07-30 18:10:13 -07007827}
7828
David Benjaminb36a3952015-12-01 18:53:13 -05007829func addRSAClientKeyExchangeTests() {
7830 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7831 testCases = append(testCases, testCase{
7832 testType: serverTest,
7833 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7834 config: Config{
7835 // Ensure the ClientHello version and final
7836 // version are different, to detect if the
7837 // server uses the wrong one.
7838 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007839 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007840 Bugs: ProtocolBugs{
7841 BadRSAClientKeyExchange: bad,
7842 },
7843 },
7844 shouldFail: true,
7845 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7846 })
7847 }
David Benjamine63d9d72016-09-19 18:27:34 -04007848
7849 // The server must compare whatever was in ClientHello.version for the
7850 // RSA premaster.
7851 testCases = append(testCases, testCase{
7852 testType: serverTest,
7853 name: "SendClientVersion-RSA",
7854 config: Config{
7855 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7856 Bugs: ProtocolBugs{
7857 SendClientVersion: 0x1234,
7858 },
7859 },
7860 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7861 })
David Benjaminb36a3952015-12-01 18:53:13 -05007862}
7863
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007864var testCurves = []struct {
7865 name string
7866 id CurveID
7867}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007868 {"P-256", CurveP256},
7869 {"P-384", CurveP384},
7870 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007871 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007872}
7873
Steven Valdez5440fe02016-07-18 12:40:30 -04007874const bogusCurve = 0x1234
7875
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007876func addCurveTests() {
7877 for _, curve := range testCurves {
7878 testCases = append(testCases, testCase{
7879 name: "CurveTest-Client-" + curve.name,
7880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007881 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007882 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7883 CurvePreferences: []CurveID{curve.id},
7884 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007885 flags: []string{
7886 "-enable-all-curves",
7887 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7888 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007889 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007890 })
7891 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007892 name: "CurveTest-Client-" + curve.name + "-TLS13",
7893 config: Config{
7894 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007895 CurvePreferences: []CurveID{curve.id},
7896 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007897 flags: []string{
7898 "-enable-all-curves",
7899 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7900 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007901 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007902 })
7903 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007904 testType: serverTest,
7905 name: "CurveTest-Server-" + curve.name,
7906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007907 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7909 CurvePreferences: []CurveID{curve.id},
7910 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007911 flags: []string{
7912 "-enable-all-curves",
7913 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7914 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007915 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007916 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007917 testCases = append(testCases, testCase{
7918 testType: serverTest,
7919 name: "CurveTest-Server-" + curve.name + "-TLS13",
7920 config: Config{
7921 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007922 CurvePreferences: []CurveID{curve.id},
7923 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007924 flags: []string{
7925 "-enable-all-curves",
7926 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7927 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007928 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007929 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007930 }
David Benjamin241ae832016-01-15 03:04:54 -05007931
7932 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "UnknownCurve",
7936 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007937 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007938 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7939 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7940 },
7941 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007942
Steven Valdez803c77a2016-09-06 14:13:43 -04007943 // The server must be tolerant to bogus curves.
7944 testCases = append(testCases, testCase{
7945 testType: serverTest,
7946 name: "UnknownCurve-TLS13",
7947 config: Config{
7948 MaxVersion: VersionTLS13,
7949 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7950 },
7951 })
7952
David Benjamin4c3ddf72016-06-29 18:13:53 -04007953 // The server must not consider ECDHE ciphers when there are no
7954 // supported curves.
7955 testCases = append(testCases, testCase{
7956 testType: serverTest,
7957 name: "NoSupportedCurves",
7958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007959 MaxVersion: VersionTLS12,
7960 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7961 Bugs: ProtocolBugs{
7962 NoSupportedCurves: true,
7963 },
7964 },
7965 shouldFail: true,
7966 expectedError: ":NO_SHARED_CIPHER:",
7967 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007968 testCases = append(testCases, testCase{
7969 testType: serverTest,
7970 name: "NoSupportedCurves-TLS13",
7971 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007972 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007973 Bugs: ProtocolBugs{
7974 NoSupportedCurves: true,
7975 },
7976 },
7977 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007978 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007979 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007980
7981 // The server must fall back to another cipher when there are no
7982 // supported curves.
7983 testCases = append(testCases, testCase{
7984 testType: serverTest,
7985 name: "NoCommonCurves",
7986 config: Config{
7987 MaxVersion: VersionTLS12,
7988 CipherSuites: []uint16{
7989 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7990 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7991 },
7992 CurvePreferences: []CurveID{CurveP224},
7993 },
7994 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7995 })
7996
7997 // The client must reject bogus curves and disabled curves.
7998 testCases = append(testCases, testCase{
7999 name: "BadECDHECurve",
8000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008001 MaxVersion: VersionTLS12,
8002 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8003 Bugs: ProtocolBugs{
8004 SendCurve: bogusCurve,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedError: ":WRONG_CURVE:",
8009 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008010 testCases = append(testCases, testCase{
8011 name: "BadECDHECurve-TLS13",
8012 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008013 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008014 Bugs: ProtocolBugs{
8015 SendCurve: bogusCurve,
8016 },
8017 },
8018 shouldFail: true,
8019 expectedError: ":WRONG_CURVE:",
8020 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008021
8022 testCases = append(testCases, testCase{
8023 name: "UnsupportedCurve",
8024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008025 MaxVersion: VersionTLS12,
8026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8027 CurvePreferences: []CurveID{CurveP256},
8028 Bugs: ProtocolBugs{
8029 IgnorePeerCurvePreferences: true,
8030 },
8031 },
8032 flags: []string{"-p384-only"},
8033 shouldFail: true,
8034 expectedError: ":WRONG_CURVE:",
8035 })
8036
David Benjamin4f921572016-07-17 14:20:10 +02008037 testCases = append(testCases, testCase{
8038 // TODO(davidben): Add a TLS 1.3 version where
8039 // HelloRetryRequest requests an unsupported curve.
8040 name: "UnsupportedCurve-ServerHello-TLS13",
8041 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008042 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008043 CurvePreferences: []CurveID{CurveP384},
8044 Bugs: ProtocolBugs{
8045 SendCurve: CurveP256,
8046 },
8047 },
8048 flags: []string{"-p384-only"},
8049 shouldFail: true,
8050 expectedError: ":WRONG_CURVE:",
8051 })
8052
David Benjamin4c3ddf72016-06-29 18:13:53 -04008053 // Test invalid curve points.
8054 testCases = append(testCases, testCase{
8055 name: "InvalidECDHPoint-Client",
8056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008057 MaxVersion: VersionTLS12,
8058 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8059 CurvePreferences: []CurveID{CurveP256},
8060 Bugs: ProtocolBugs{
8061 InvalidECDHPoint: true,
8062 },
8063 },
8064 shouldFail: true,
8065 expectedError: ":INVALID_ENCODING:",
8066 })
8067 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008068 name: "InvalidECDHPoint-Client-TLS13",
8069 config: Config{
8070 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008071 CurvePreferences: []CurveID{CurveP256},
8072 Bugs: ProtocolBugs{
8073 InvalidECDHPoint: true,
8074 },
8075 },
8076 shouldFail: true,
8077 expectedError: ":INVALID_ENCODING:",
8078 })
8079 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008080 testType: serverTest,
8081 name: "InvalidECDHPoint-Server",
8082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008083 MaxVersion: VersionTLS12,
8084 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8085 CurvePreferences: []CurveID{CurveP256},
8086 Bugs: ProtocolBugs{
8087 InvalidECDHPoint: true,
8088 },
8089 },
8090 shouldFail: true,
8091 expectedError: ":INVALID_ENCODING:",
8092 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008093 testCases = append(testCases, testCase{
8094 testType: serverTest,
8095 name: "InvalidECDHPoint-Server-TLS13",
8096 config: Config{
8097 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008098 CurvePreferences: []CurveID{CurveP256},
8099 Bugs: ProtocolBugs{
8100 InvalidECDHPoint: true,
8101 },
8102 },
8103 shouldFail: true,
8104 expectedError: ":INVALID_ENCODING:",
8105 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008106}
8107
Matt Braithwaite54217e42016-06-13 13:03:47 -07008108func addCECPQ1Tests() {
8109 testCases = append(testCases, testCase{
8110 testType: clientTest,
8111 name: "CECPQ1-Client-BadX25519Part",
8112 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008113 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008114 MinVersion: VersionTLS12,
8115 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8116 Bugs: ProtocolBugs{
8117 CECPQ1BadX25519Part: true,
8118 },
8119 },
8120 flags: []string{"-cipher", "kCECPQ1"},
8121 shouldFail: true,
8122 expectedLocalError: "local error: bad record MAC",
8123 })
8124 testCases = append(testCases, testCase{
8125 testType: clientTest,
8126 name: "CECPQ1-Client-BadNewhopePart",
8127 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008128 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008129 MinVersion: VersionTLS12,
8130 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8131 Bugs: ProtocolBugs{
8132 CECPQ1BadNewhopePart: true,
8133 },
8134 },
8135 flags: []string{"-cipher", "kCECPQ1"},
8136 shouldFail: true,
8137 expectedLocalError: "local error: bad record MAC",
8138 })
8139 testCases = append(testCases, testCase{
8140 testType: serverTest,
8141 name: "CECPQ1-Server-BadX25519Part",
8142 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008143 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008144 MinVersion: VersionTLS12,
8145 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8146 Bugs: ProtocolBugs{
8147 CECPQ1BadX25519Part: true,
8148 },
8149 },
8150 flags: []string{"-cipher", "kCECPQ1"},
8151 shouldFail: true,
8152 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8153 })
8154 testCases = append(testCases, testCase{
8155 testType: serverTest,
8156 name: "CECPQ1-Server-BadNewhopePart",
8157 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008158 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008159 MinVersion: VersionTLS12,
8160 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8161 Bugs: ProtocolBugs{
8162 CECPQ1BadNewhopePart: true,
8163 },
8164 },
8165 flags: []string{"-cipher", "kCECPQ1"},
8166 shouldFail: true,
8167 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8168 })
8169}
8170
David Benjamin5c4e8572016-08-19 17:44:53 -04008171func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008172 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008173 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008174 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008175 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008176 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8177 Bugs: ProtocolBugs{
8178 // This is a 1234-bit prime number, generated
8179 // with:
8180 // openssl gendh 1234 | openssl asn1parse -i
8181 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8182 },
8183 },
David Benjamin9e68f192016-06-30 14:55:33 -04008184 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008185 })
8186 testCases = append(testCases, testCase{
8187 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008188 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008189 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008190 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008191 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8192 },
8193 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008194 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008195 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008196}
8197
David Benjaminc9ae27c2016-06-24 22:56:37 -04008198func addTLS13RecordTests() {
8199 testCases = append(testCases, testCase{
8200 name: "TLS13-RecordPadding",
8201 config: Config{
8202 MaxVersion: VersionTLS13,
8203 MinVersion: VersionTLS13,
8204 Bugs: ProtocolBugs{
8205 RecordPadding: 10,
8206 },
8207 },
8208 })
8209
8210 testCases = append(testCases, testCase{
8211 name: "TLS13-EmptyRecords",
8212 config: Config{
8213 MaxVersion: VersionTLS13,
8214 MinVersion: VersionTLS13,
8215 Bugs: ProtocolBugs{
8216 OmitRecordContents: true,
8217 },
8218 },
8219 shouldFail: true,
8220 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8221 })
8222
8223 testCases = append(testCases, testCase{
8224 name: "TLS13-OnlyPadding",
8225 config: Config{
8226 MaxVersion: VersionTLS13,
8227 MinVersion: VersionTLS13,
8228 Bugs: ProtocolBugs{
8229 OmitRecordContents: true,
8230 RecordPadding: 10,
8231 },
8232 },
8233 shouldFail: true,
8234 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8235 })
8236
8237 testCases = append(testCases, testCase{
8238 name: "TLS13-WrongOuterRecord",
8239 config: Config{
8240 MaxVersion: VersionTLS13,
8241 MinVersion: VersionTLS13,
8242 Bugs: ProtocolBugs{
8243 OuterRecordType: recordTypeHandshake,
8244 },
8245 },
8246 shouldFail: true,
8247 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8248 })
8249}
8250
Steven Valdez5b986082016-09-01 12:29:49 -04008251func addSessionTicketTests() {
8252 testCases = append(testCases, testCase{
8253 // In TLS 1.2 and below, empty NewSessionTicket messages
8254 // mean the server changed its mind on sending a ticket.
8255 name: "SendEmptySessionTicket",
8256 config: Config{
8257 MaxVersion: VersionTLS12,
8258 Bugs: ProtocolBugs{
8259 SendEmptySessionTicket: true,
8260 },
8261 },
8262 flags: []string{"-expect-no-session"},
8263 })
8264
8265 // Test that the server ignores unknown PSK modes.
8266 testCases = append(testCases, testCase{
8267 testType: serverTest,
8268 name: "TLS13-SendUnknownModeSessionTicket-Server",
8269 config: Config{
8270 MaxVersion: VersionTLS13,
8271 Bugs: ProtocolBugs{
8272 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008273 },
8274 },
8275 resumeSession: true,
8276 expectedResumeVersion: VersionTLS13,
8277 })
8278
Steven Valdeza833c352016-11-01 13:39:36 -04008279 // Test that the server does not send session tickets with no matching key exchange mode.
8280 testCases = append(testCases, testCase{
8281 testType: serverTest,
8282 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8283 config: Config{
8284 MaxVersion: VersionTLS13,
8285 Bugs: ProtocolBugs{
8286 SendPSKKeyExchangeModes: []byte{0x1a},
8287 ExpectNoNewSessionTicket: true,
8288 },
8289 },
8290 })
8291
8292 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008293 testCases = append(testCases, testCase{
8294 testType: serverTest,
8295 name: "TLS13-SendBadKEModeSessionTicket-Server",
8296 config: Config{
8297 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008298 },
8299 resumeConfig: &Config{
8300 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008301 Bugs: ProtocolBugs{
8302 SendPSKKeyExchangeModes: []byte{0x1a},
8303 },
8304 },
8305 resumeSession: true,
8306 expectResumeRejected: true,
8307 })
8308
Steven Valdeza833c352016-11-01 13:39:36 -04008309 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008310 testCases = append(testCases, testCase{
8311 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008312 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008313 config: Config{
8314 MaxVersion: VersionTLS13,
8315 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008316 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008317 },
8318 },
Steven Valdeza833c352016-11-01 13:39:36 -04008319 resumeSession: true,
8320 flags: []string{
8321 "-resumption-delay", "10",
8322 },
Steven Valdez5b986082016-09-01 12:29:49 -04008323 })
8324
Steven Valdeza833c352016-11-01 13:39:36 -04008325 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008326 testCases = append(testCases, testCase{
8327 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008328 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008329 config: Config{
8330 MaxVersion: VersionTLS13,
8331 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008332 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008333 },
8334 },
Steven Valdeza833c352016-11-01 13:39:36 -04008335 resumeSession: true,
8336 shouldFail: true,
8337 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008338 })
8339
Steven Valdez5b986082016-09-01 12:29:49 -04008340}
8341
David Benjamin82261be2016-07-07 14:32:50 -07008342func addChangeCipherSpecTests() {
8343 // Test missing ChangeCipherSpecs.
8344 testCases = append(testCases, testCase{
8345 name: "SkipChangeCipherSpec-Client",
8346 config: Config{
8347 MaxVersion: VersionTLS12,
8348 Bugs: ProtocolBugs{
8349 SkipChangeCipherSpec: true,
8350 },
8351 },
8352 shouldFail: true,
8353 expectedError: ":UNEXPECTED_RECORD:",
8354 })
8355 testCases = append(testCases, testCase{
8356 testType: serverTest,
8357 name: "SkipChangeCipherSpec-Server",
8358 config: Config{
8359 MaxVersion: VersionTLS12,
8360 Bugs: ProtocolBugs{
8361 SkipChangeCipherSpec: true,
8362 },
8363 },
8364 shouldFail: true,
8365 expectedError: ":UNEXPECTED_RECORD:",
8366 })
8367 testCases = append(testCases, testCase{
8368 testType: serverTest,
8369 name: "SkipChangeCipherSpec-Server-NPN",
8370 config: Config{
8371 MaxVersion: VersionTLS12,
8372 NextProtos: []string{"bar"},
8373 Bugs: ProtocolBugs{
8374 SkipChangeCipherSpec: true,
8375 },
8376 },
8377 flags: []string{
8378 "-advertise-npn", "\x03foo\x03bar\x03baz",
8379 },
8380 shouldFail: true,
8381 expectedError: ":UNEXPECTED_RECORD:",
8382 })
8383
8384 // Test synchronization between the handshake and ChangeCipherSpec.
8385 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8386 // rejected. Test both with and without handshake packing to handle both
8387 // when the partial post-CCS message is in its own record and when it is
8388 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008389 for _, packed := range []bool{false, true} {
8390 var suffix string
8391 if packed {
8392 suffix = "-Packed"
8393 }
8394
8395 testCases = append(testCases, testCase{
8396 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8397 config: Config{
8398 MaxVersion: VersionTLS12,
8399 Bugs: ProtocolBugs{
8400 FragmentAcrossChangeCipherSpec: true,
8401 PackHandshakeFlight: packed,
8402 },
8403 },
8404 shouldFail: true,
8405 expectedError: ":UNEXPECTED_RECORD:",
8406 })
8407 testCases = append(testCases, testCase{
8408 name: "FragmentAcrossChangeCipherSpec-Client-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" + suffix,
8426 config: Config{
8427 MaxVersion: VersionTLS12,
8428 Bugs: ProtocolBugs{
8429 FragmentAcrossChangeCipherSpec: true,
8430 PackHandshakeFlight: packed,
8431 },
8432 },
8433 shouldFail: true,
8434 expectedError: ":UNEXPECTED_RECORD:",
8435 })
8436 testCases = append(testCases, testCase{
8437 testType: serverTest,
8438 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8439 config: Config{
8440 MaxVersion: VersionTLS12,
8441 },
8442 resumeSession: true,
8443 resumeConfig: &Config{
8444 MaxVersion: VersionTLS12,
8445 Bugs: ProtocolBugs{
8446 FragmentAcrossChangeCipherSpec: true,
8447 PackHandshakeFlight: packed,
8448 },
8449 },
8450 shouldFail: true,
8451 expectedError: ":UNEXPECTED_RECORD:",
8452 })
8453 testCases = append(testCases, testCase{
8454 testType: serverTest,
8455 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8456 config: Config{
8457 MaxVersion: VersionTLS12,
8458 NextProtos: []string{"bar"},
8459 Bugs: ProtocolBugs{
8460 FragmentAcrossChangeCipherSpec: true,
8461 PackHandshakeFlight: packed,
8462 },
8463 },
8464 flags: []string{
8465 "-advertise-npn", "\x03foo\x03bar\x03baz",
8466 },
8467 shouldFail: true,
8468 expectedError: ":UNEXPECTED_RECORD:",
8469 })
8470 }
8471
David Benjamin61672812016-07-14 23:10:43 -04008472 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8473 // messages in the handshake queue. Do this by testing the server
8474 // reading the client Finished, reversing the flight so Finished comes
8475 // first.
8476 testCases = append(testCases, testCase{
8477 protocol: dtls,
8478 testType: serverTest,
8479 name: "SendUnencryptedFinished-DTLS",
8480 config: Config{
8481 MaxVersion: VersionTLS12,
8482 Bugs: ProtocolBugs{
8483 SendUnencryptedFinished: true,
8484 ReverseHandshakeFragments: true,
8485 },
8486 },
8487 shouldFail: true,
8488 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8489 })
8490
Steven Valdez143e8b32016-07-11 13:19:03 -04008491 // Test synchronization between encryption changes and the handshake in
8492 // TLS 1.3, where ChangeCipherSpec is implicit.
8493 testCases = append(testCases, testCase{
8494 name: "PartialEncryptedExtensionsWithServerHello",
8495 config: Config{
8496 MaxVersion: VersionTLS13,
8497 Bugs: ProtocolBugs{
8498 PartialEncryptedExtensionsWithServerHello: true,
8499 },
8500 },
8501 shouldFail: true,
8502 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8503 })
8504 testCases = append(testCases, testCase{
8505 testType: serverTest,
8506 name: "PartialClientFinishedWithClientHello",
8507 config: Config{
8508 MaxVersion: VersionTLS13,
8509 Bugs: ProtocolBugs{
8510 PartialClientFinishedWithClientHello: true,
8511 },
8512 },
8513 shouldFail: true,
8514 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8515 })
8516
David Benjamin82261be2016-07-07 14:32:50 -07008517 // Test that early ChangeCipherSpecs are handled correctly.
8518 testCases = append(testCases, testCase{
8519 testType: serverTest,
8520 name: "EarlyChangeCipherSpec-server-1",
8521 config: Config{
8522 MaxVersion: VersionTLS12,
8523 Bugs: ProtocolBugs{
8524 EarlyChangeCipherSpec: 1,
8525 },
8526 },
8527 shouldFail: true,
8528 expectedError: ":UNEXPECTED_RECORD:",
8529 })
8530 testCases = append(testCases, testCase{
8531 testType: serverTest,
8532 name: "EarlyChangeCipherSpec-server-2",
8533 config: Config{
8534 MaxVersion: VersionTLS12,
8535 Bugs: ProtocolBugs{
8536 EarlyChangeCipherSpec: 2,
8537 },
8538 },
8539 shouldFail: true,
8540 expectedError: ":UNEXPECTED_RECORD:",
8541 })
8542 testCases = append(testCases, testCase{
8543 protocol: dtls,
8544 name: "StrayChangeCipherSpec",
8545 config: Config{
8546 // TODO(davidben): Once DTLS 1.3 exists, test
8547 // that stray ChangeCipherSpec messages are
8548 // rejected.
8549 MaxVersion: VersionTLS12,
8550 Bugs: ProtocolBugs{
8551 StrayChangeCipherSpec: true,
8552 },
8553 },
8554 })
8555
8556 // Test that the contents of ChangeCipherSpec are checked.
8557 testCases = append(testCases, testCase{
8558 name: "BadChangeCipherSpec-1",
8559 config: Config{
8560 MaxVersion: VersionTLS12,
8561 Bugs: ProtocolBugs{
8562 BadChangeCipherSpec: []byte{2},
8563 },
8564 },
8565 shouldFail: true,
8566 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8567 })
8568 testCases = append(testCases, testCase{
8569 name: "BadChangeCipherSpec-2",
8570 config: Config{
8571 MaxVersion: VersionTLS12,
8572 Bugs: ProtocolBugs{
8573 BadChangeCipherSpec: []byte{1, 1},
8574 },
8575 },
8576 shouldFail: true,
8577 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8578 })
8579 testCases = append(testCases, testCase{
8580 protocol: dtls,
8581 name: "BadChangeCipherSpec-DTLS-1",
8582 config: Config{
8583 MaxVersion: VersionTLS12,
8584 Bugs: ProtocolBugs{
8585 BadChangeCipherSpec: []byte{2},
8586 },
8587 },
8588 shouldFail: true,
8589 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8590 })
8591 testCases = append(testCases, testCase{
8592 protocol: dtls,
8593 name: "BadChangeCipherSpec-DTLS-2",
8594 config: Config{
8595 MaxVersion: VersionTLS12,
8596 Bugs: ProtocolBugs{
8597 BadChangeCipherSpec: []byte{1, 1},
8598 },
8599 },
8600 shouldFail: true,
8601 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8602 })
8603}
8604
David Benjamincd2c8062016-09-09 11:28:16 -04008605type perMessageTest struct {
8606 messageType uint8
8607 test testCase
8608}
8609
8610// makePerMessageTests returns a series of test templates which cover each
8611// message in the TLS handshake. These may be used with bugs like
8612// WrongMessageType to fully test a per-message bug.
8613func makePerMessageTests() []perMessageTest {
8614 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008615 for _, protocol := range []protocol{tls, dtls} {
8616 var suffix string
8617 if protocol == dtls {
8618 suffix = "-DTLS"
8619 }
8620
David Benjamincd2c8062016-09-09 11:28:16 -04008621 ret = append(ret, perMessageTest{
8622 messageType: typeClientHello,
8623 test: testCase{
8624 protocol: protocol,
8625 testType: serverTest,
8626 name: "ClientHello" + suffix,
8627 config: Config{
8628 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008629 },
8630 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008631 })
8632
8633 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008634 ret = append(ret, perMessageTest{
8635 messageType: typeHelloVerifyRequest,
8636 test: testCase{
8637 protocol: protocol,
8638 name: "HelloVerifyRequest" + suffix,
8639 config: Config{
8640 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008641 },
8642 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008643 })
8644 }
8645
David Benjamincd2c8062016-09-09 11:28:16 -04008646 ret = append(ret, perMessageTest{
8647 messageType: typeServerHello,
8648 test: testCase{
8649 protocol: protocol,
8650 name: "ServerHello" + suffix,
8651 config: Config{
8652 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008653 },
8654 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008655 })
8656
David Benjamincd2c8062016-09-09 11:28:16 -04008657 ret = append(ret, perMessageTest{
8658 messageType: typeCertificate,
8659 test: testCase{
8660 protocol: protocol,
8661 name: "ServerCertificate" + suffix,
8662 config: Config{
8663 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008664 },
8665 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008666 })
8667
David Benjamincd2c8062016-09-09 11:28:16 -04008668 ret = append(ret, perMessageTest{
8669 messageType: typeCertificateStatus,
8670 test: testCase{
8671 protocol: protocol,
8672 name: "CertificateStatus" + suffix,
8673 config: Config{
8674 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008675 },
David Benjamincd2c8062016-09-09 11:28:16 -04008676 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008677 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008678 })
8679
David Benjamincd2c8062016-09-09 11:28:16 -04008680 ret = append(ret, perMessageTest{
8681 messageType: typeServerKeyExchange,
8682 test: testCase{
8683 protocol: protocol,
8684 name: "ServerKeyExchange" + suffix,
8685 config: Config{
8686 MaxVersion: VersionTLS12,
8687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008688 },
8689 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008690 })
8691
David Benjamincd2c8062016-09-09 11:28:16 -04008692 ret = append(ret, perMessageTest{
8693 messageType: typeCertificateRequest,
8694 test: testCase{
8695 protocol: protocol,
8696 name: "CertificateRequest" + suffix,
8697 config: Config{
8698 MaxVersion: VersionTLS12,
8699 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008700 },
8701 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008702 })
8703
David Benjamincd2c8062016-09-09 11:28:16 -04008704 ret = append(ret, perMessageTest{
8705 messageType: typeServerHelloDone,
8706 test: testCase{
8707 protocol: protocol,
8708 name: "ServerHelloDone" + suffix,
8709 config: Config{
8710 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008711 },
8712 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008713 })
8714
David Benjamincd2c8062016-09-09 11:28:16 -04008715 ret = append(ret, perMessageTest{
8716 messageType: typeCertificate,
8717 test: testCase{
8718 testType: serverTest,
8719 protocol: protocol,
8720 name: "ClientCertificate" + suffix,
8721 config: Config{
8722 Certificates: []Certificate{rsaCertificate},
8723 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008724 },
David Benjamincd2c8062016-09-09 11:28:16 -04008725 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008726 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008727 })
8728
David Benjamincd2c8062016-09-09 11:28:16 -04008729 ret = append(ret, perMessageTest{
8730 messageType: typeCertificateVerify,
8731 test: testCase{
8732 testType: serverTest,
8733 protocol: protocol,
8734 name: "CertificateVerify" + suffix,
8735 config: Config{
8736 Certificates: []Certificate{rsaCertificate},
8737 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008738 },
David Benjamincd2c8062016-09-09 11:28:16 -04008739 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008740 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008741 })
8742
David Benjamincd2c8062016-09-09 11:28:16 -04008743 ret = append(ret, perMessageTest{
8744 messageType: typeClientKeyExchange,
8745 test: testCase{
8746 testType: serverTest,
8747 protocol: protocol,
8748 name: "ClientKeyExchange" + suffix,
8749 config: Config{
8750 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008751 },
8752 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008753 })
8754
8755 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008756 ret = append(ret, perMessageTest{
8757 messageType: typeNextProtocol,
8758 test: testCase{
8759 testType: serverTest,
8760 protocol: protocol,
8761 name: "NextProtocol" + suffix,
8762 config: Config{
8763 MaxVersion: VersionTLS12,
8764 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008765 },
David Benjamincd2c8062016-09-09 11:28:16 -04008766 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008767 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 })
8769
David Benjamincd2c8062016-09-09 11:28:16 -04008770 ret = append(ret, perMessageTest{
8771 messageType: typeChannelID,
8772 test: testCase{
8773 testType: serverTest,
8774 protocol: protocol,
8775 name: "ChannelID" + suffix,
8776 config: Config{
8777 MaxVersion: VersionTLS12,
8778 ChannelID: channelIDKey,
8779 },
8780 flags: []string{
8781 "-expect-channel-id",
8782 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008783 },
8784 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008785 })
8786 }
8787
David Benjamincd2c8062016-09-09 11:28:16 -04008788 ret = append(ret, perMessageTest{
8789 messageType: typeFinished,
8790 test: testCase{
8791 testType: serverTest,
8792 protocol: protocol,
8793 name: "ClientFinished" + suffix,
8794 config: Config{
8795 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008796 },
8797 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008798 })
8799
David Benjamincd2c8062016-09-09 11:28:16 -04008800 ret = append(ret, perMessageTest{
8801 messageType: typeNewSessionTicket,
8802 test: testCase{
8803 protocol: protocol,
8804 name: "NewSessionTicket" + suffix,
8805 config: Config{
8806 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008807 },
8808 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008809 })
8810
David Benjamincd2c8062016-09-09 11:28:16 -04008811 ret = append(ret, perMessageTest{
8812 messageType: typeFinished,
8813 test: testCase{
8814 protocol: protocol,
8815 name: "ServerFinished" + suffix,
8816 config: Config{
8817 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008818 },
8819 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008820 })
8821
8822 }
David Benjamincd2c8062016-09-09 11:28:16 -04008823
8824 ret = append(ret, perMessageTest{
8825 messageType: typeClientHello,
8826 test: testCase{
8827 testType: serverTest,
8828 name: "TLS13-ClientHello",
8829 config: Config{
8830 MaxVersion: VersionTLS13,
8831 },
8832 },
8833 })
8834
8835 ret = append(ret, perMessageTest{
8836 messageType: typeServerHello,
8837 test: testCase{
8838 name: "TLS13-ServerHello",
8839 config: Config{
8840 MaxVersion: VersionTLS13,
8841 },
8842 },
8843 })
8844
8845 ret = append(ret, perMessageTest{
8846 messageType: typeEncryptedExtensions,
8847 test: testCase{
8848 name: "TLS13-EncryptedExtensions",
8849 config: Config{
8850 MaxVersion: VersionTLS13,
8851 },
8852 },
8853 })
8854
8855 ret = append(ret, perMessageTest{
8856 messageType: typeCertificateRequest,
8857 test: testCase{
8858 name: "TLS13-CertificateRequest",
8859 config: Config{
8860 MaxVersion: VersionTLS13,
8861 ClientAuth: RequireAnyClientCert,
8862 },
8863 },
8864 })
8865
8866 ret = append(ret, perMessageTest{
8867 messageType: typeCertificate,
8868 test: testCase{
8869 name: "TLS13-ServerCertificate",
8870 config: Config{
8871 MaxVersion: VersionTLS13,
8872 },
8873 },
8874 })
8875
8876 ret = append(ret, perMessageTest{
8877 messageType: typeCertificateVerify,
8878 test: testCase{
8879 name: "TLS13-ServerCertificateVerify",
8880 config: Config{
8881 MaxVersion: VersionTLS13,
8882 },
8883 },
8884 })
8885
8886 ret = append(ret, perMessageTest{
8887 messageType: typeFinished,
8888 test: testCase{
8889 name: "TLS13-ServerFinished",
8890 config: Config{
8891 MaxVersion: VersionTLS13,
8892 },
8893 },
8894 })
8895
8896 ret = append(ret, perMessageTest{
8897 messageType: typeCertificate,
8898 test: testCase{
8899 testType: serverTest,
8900 name: "TLS13-ClientCertificate",
8901 config: Config{
8902 Certificates: []Certificate{rsaCertificate},
8903 MaxVersion: VersionTLS13,
8904 },
8905 flags: []string{"-require-any-client-certificate"},
8906 },
8907 })
8908
8909 ret = append(ret, perMessageTest{
8910 messageType: typeCertificateVerify,
8911 test: testCase{
8912 testType: serverTest,
8913 name: "TLS13-ClientCertificateVerify",
8914 config: Config{
8915 Certificates: []Certificate{rsaCertificate},
8916 MaxVersion: VersionTLS13,
8917 },
8918 flags: []string{"-require-any-client-certificate"},
8919 },
8920 })
8921
8922 ret = append(ret, perMessageTest{
8923 messageType: typeFinished,
8924 test: testCase{
8925 testType: serverTest,
8926 name: "TLS13-ClientFinished",
8927 config: Config{
8928 MaxVersion: VersionTLS13,
8929 },
8930 },
8931 })
8932
8933 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008934}
8935
David Benjamincd2c8062016-09-09 11:28:16 -04008936func addWrongMessageTypeTests() {
8937 for _, t := range makePerMessageTests() {
8938 t.test.name = "WrongMessageType-" + t.test.name
8939 t.test.config.Bugs.SendWrongMessageType = t.messageType
8940 t.test.shouldFail = true
8941 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8942 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008943
David Benjamincd2c8062016-09-09 11:28:16 -04008944 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8945 // In TLS 1.3, a bad ServerHello means the client sends
8946 // an unencrypted alert while the server expects
8947 // encryption, so the alert is not readable by runner.
8948 t.test.expectedLocalError = "local error: bad record MAC"
8949 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008950
David Benjamincd2c8062016-09-09 11:28:16 -04008951 testCases = append(testCases, t.test)
8952 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008953}
8954
David Benjamin639846e2016-09-09 11:41:18 -04008955func addTrailingMessageDataTests() {
8956 for _, t := range makePerMessageTests() {
8957 t.test.name = "TrailingMessageData-" + t.test.name
8958 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8959 t.test.shouldFail = true
8960 t.test.expectedError = ":DECODE_ERROR:"
8961 t.test.expectedLocalError = "remote error: error decoding message"
8962
8963 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8964 // In TLS 1.3, a bad ServerHello means the client sends
8965 // an unencrypted alert while the server expects
8966 // encryption, so the alert is not readable by runner.
8967 t.test.expectedLocalError = "local error: bad record MAC"
8968 }
8969
8970 if t.messageType == typeFinished {
8971 // Bad Finished messages read as the verify data having
8972 // the wrong length.
8973 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8974 t.test.expectedLocalError = "remote error: error decrypting message"
8975 }
8976
8977 testCases = append(testCases, t.test)
8978 }
8979}
8980
Steven Valdez143e8b32016-07-11 13:19:03 -04008981func addTLS13HandshakeTests() {
8982 testCases = append(testCases, testCase{
8983 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008984 name: "NegotiatePSKResumption-TLS13",
8985 config: Config{
8986 MaxVersion: VersionTLS13,
8987 Bugs: ProtocolBugs{
8988 NegotiatePSKResumption: true,
8989 },
8990 },
8991 resumeSession: true,
8992 shouldFail: true,
8993 expectedError: ":UNEXPECTED_EXTENSION:",
8994 })
8995
8996 testCases = append(testCases, testCase{
8997 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008998 name: "MissingKeyShare-Client",
8999 config: Config{
9000 MaxVersion: VersionTLS13,
9001 Bugs: ProtocolBugs{
9002 MissingKeyShare: true,
9003 },
9004 },
9005 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009006 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009007 })
9008
9009 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009010 testType: serverTest,
9011 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009012 config: Config{
9013 MaxVersion: VersionTLS13,
9014 Bugs: ProtocolBugs{
9015 MissingKeyShare: true,
9016 },
9017 },
9018 shouldFail: true,
9019 expectedError: ":MISSING_KEY_SHARE:",
9020 })
9021
9022 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009023 testType: serverTest,
9024 name: "DuplicateKeyShares",
9025 config: Config{
9026 MaxVersion: VersionTLS13,
9027 Bugs: ProtocolBugs{
9028 DuplicateKeyShares: true,
9029 },
9030 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009031 shouldFail: true,
9032 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009033 })
9034
9035 testCases = append(testCases, testCase{
9036 testType: clientTest,
9037 name: "EmptyEncryptedExtensions",
9038 config: Config{
9039 MaxVersion: VersionTLS13,
9040 Bugs: ProtocolBugs{
9041 EmptyEncryptedExtensions: true,
9042 },
9043 },
9044 shouldFail: true,
9045 expectedLocalError: "remote error: error decoding message",
9046 })
9047
9048 testCases = append(testCases, testCase{
9049 testType: clientTest,
9050 name: "EncryptedExtensionsWithKeyShare",
9051 config: Config{
9052 MaxVersion: VersionTLS13,
9053 Bugs: ProtocolBugs{
9054 EncryptedExtensionsWithKeyShare: true,
9055 },
9056 },
9057 shouldFail: true,
9058 expectedLocalError: "remote error: unsupported extension",
9059 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009060
9061 testCases = append(testCases, testCase{
9062 testType: serverTest,
9063 name: "SendHelloRetryRequest",
9064 config: Config{
9065 MaxVersion: VersionTLS13,
9066 // Require a HelloRetryRequest for every curve.
9067 DefaultCurves: []CurveID{},
9068 },
9069 expectedCurveID: CurveX25519,
9070 })
9071
9072 testCases = append(testCases, testCase{
9073 testType: serverTest,
9074 name: "SendHelloRetryRequest-2",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 DefaultCurves: []CurveID{CurveP384},
9078 },
9079 // Although the ClientHello did not predict our preferred curve,
9080 // we always select it whether it is predicted or not.
9081 expectedCurveID: CurveX25519,
9082 })
9083
9084 testCases = append(testCases, testCase{
9085 name: "UnknownCurve-HelloRetryRequest",
9086 config: Config{
9087 MaxVersion: VersionTLS13,
9088 // P-384 requires HelloRetryRequest in BoringSSL.
9089 CurvePreferences: []CurveID{CurveP384},
9090 Bugs: ProtocolBugs{
9091 SendHelloRetryRequestCurve: bogusCurve,
9092 },
9093 },
9094 shouldFail: true,
9095 expectedError: ":WRONG_CURVE:",
9096 })
9097
9098 testCases = append(testCases, testCase{
9099 name: "DisabledCurve-HelloRetryRequest",
9100 config: Config{
9101 MaxVersion: VersionTLS13,
9102 CurvePreferences: []CurveID{CurveP256},
9103 Bugs: ProtocolBugs{
9104 IgnorePeerCurvePreferences: true,
9105 },
9106 },
9107 flags: []string{"-p384-only"},
9108 shouldFail: true,
9109 expectedError: ":WRONG_CURVE:",
9110 })
9111
9112 testCases = append(testCases, testCase{
9113 name: "UnnecessaryHelloRetryRequest",
9114 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009115 MaxVersion: VersionTLS13,
9116 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009117 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009118 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009119 },
9120 },
9121 shouldFail: true,
9122 expectedError: ":WRONG_CURVE:",
9123 })
9124
9125 testCases = append(testCases, testCase{
9126 name: "SecondHelloRetryRequest",
9127 config: Config{
9128 MaxVersion: VersionTLS13,
9129 // P-384 requires HelloRetryRequest in BoringSSL.
9130 CurvePreferences: []CurveID{CurveP384},
9131 Bugs: ProtocolBugs{
9132 SecondHelloRetryRequest: true,
9133 },
9134 },
9135 shouldFail: true,
9136 expectedError: ":UNEXPECTED_MESSAGE:",
9137 })
9138
9139 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009140 name: "HelloRetryRequest-Empty",
9141 config: Config{
9142 MaxVersion: VersionTLS13,
9143 Bugs: ProtocolBugs{
9144 AlwaysSendHelloRetryRequest: true,
9145 },
9146 },
9147 shouldFail: true,
9148 expectedError: ":DECODE_ERROR:",
9149 })
9150
9151 testCases = append(testCases, testCase{
9152 name: "HelloRetryRequest-DuplicateCurve",
9153 config: Config{
9154 MaxVersion: VersionTLS13,
9155 // P-384 requires a HelloRetryRequest against BoringSSL's default
9156 // configuration. Assert this ExpectMissingKeyShare.
9157 CurvePreferences: []CurveID{CurveP384},
9158 Bugs: ProtocolBugs{
9159 ExpectMissingKeyShare: true,
9160 DuplicateHelloRetryRequestExtensions: true,
9161 },
9162 },
9163 shouldFail: true,
9164 expectedError: ":DUPLICATE_EXTENSION:",
9165 expectedLocalError: "remote error: illegal parameter",
9166 })
9167
9168 testCases = append(testCases, testCase{
9169 name: "HelloRetryRequest-Cookie",
9170 config: Config{
9171 MaxVersion: VersionTLS13,
9172 Bugs: ProtocolBugs{
9173 SendHelloRetryRequestCookie: []byte("cookie"),
9174 },
9175 },
9176 })
9177
9178 testCases = append(testCases, testCase{
9179 name: "HelloRetryRequest-DuplicateCookie",
9180 config: Config{
9181 MaxVersion: VersionTLS13,
9182 Bugs: ProtocolBugs{
9183 SendHelloRetryRequestCookie: []byte("cookie"),
9184 DuplicateHelloRetryRequestExtensions: true,
9185 },
9186 },
9187 shouldFail: true,
9188 expectedError: ":DUPLICATE_EXTENSION:",
9189 expectedLocalError: "remote error: illegal parameter",
9190 })
9191
9192 testCases = append(testCases, testCase{
9193 name: "HelloRetryRequest-EmptyCookie",
9194 config: Config{
9195 MaxVersion: VersionTLS13,
9196 Bugs: ProtocolBugs{
9197 SendHelloRetryRequestCookie: []byte{},
9198 },
9199 },
9200 shouldFail: true,
9201 expectedError: ":DECODE_ERROR:",
9202 })
9203
9204 testCases = append(testCases, testCase{
9205 name: "HelloRetryRequest-Cookie-Curve",
9206 config: Config{
9207 MaxVersion: VersionTLS13,
9208 // P-384 requires HelloRetryRequest in BoringSSL.
9209 CurvePreferences: []CurveID{CurveP384},
9210 Bugs: ProtocolBugs{
9211 SendHelloRetryRequestCookie: []byte("cookie"),
9212 ExpectMissingKeyShare: true,
9213 },
9214 },
9215 })
9216
9217 testCases = append(testCases, testCase{
9218 name: "HelloRetryRequest-Unknown",
9219 config: Config{
9220 MaxVersion: VersionTLS13,
9221 Bugs: ProtocolBugs{
9222 CustomHelloRetryRequestExtension: "extension",
9223 },
9224 },
9225 shouldFail: true,
9226 expectedError: ":UNEXPECTED_EXTENSION:",
9227 expectedLocalError: "remote error: unsupported extension",
9228 })
9229
9230 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009231 testType: serverTest,
9232 name: "SecondClientHelloMissingKeyShare",
9233 config: Config{
9234 MaxVersion: VersionTLS13,
9235 DefaultCurves: []CurveID{},
9236 Bugs: ProtocolBugs{
9237 SecondClientHelloMissingKeyShare: true,
9238 },
9239 },
9240 shouldFail: true,
9241 expectedError: ":MISSING_KEY_SHARE:",
9242 })
9243
9244 testCases = append(testCases, testCase{
9245 testType: serverTest,
9246 name: "SecondClientHelloWrongCurve",
9247 config: Config{
9248 MaxVersion: VersionTLS13,
9249 DefaultCurves: []CurveID{},
9250 Bugs: ProtocolBugs{
9251 MisinterpretHelloRetryRequestCurve: CurveP521,
9252 },
9253 },
9254 shouldFail: true,
9255 expectedError: ":WRONG_CURVE:",
9256 })
9257
9258 testCases = append(testCases, testCase{
9259 name: "HelloRetryRequestVersionMismatch",
9260 config: Config{
9261 MaxVersion: VersionTLS13,
9262 // P-384 requires HelloRetryRequest in BoringSSL.
9263 CurvePreferences: []CurveID{CurveP384},
9264 Bugs: ProtocolBugs{
9265 SendServerHelloVersion: 0x0305,
9266 },
9267 },
9268 shouldFail: true,
9269 expectedError: ":WRONG_VERSION_NUMBER:",
9270 })
9271
9272 testCases = append(testCases, testCase{
9273 name: "HelloRetryRequestCurveMismatch",
9274 config: Config{
9275 MaxVersion: VersionTLS13,
9276 // P-384 requires HelloRetryRequest in BoringSSL.
9277 CurvePreferences: []CurveID{CurveP384},
9278 Bugs: ProtocolBugs{
9279 // Send P-384 (correct) in the HelloRetryRequest.
9280 SendHelloRetryRequestCurve: CurveP384,
9281 // But send P-256 in the ServerHello.
9282 SendCurve: CurveP256,
9283 },
9284 },
9285 shouldFail: true,
9286 expectedError: ":WRONG_CURVE:",
9287 })
9288
9289 // Test the server selecting a curve that requires a HelloRetryRequest
9290 // without sending it.
9291 testCases = append(testCases, testCase{
9292 name: "SkipHelloRetryRequest",
9293 config: Config{
9294 MaxVersion: VersionTLS13,
9295 // P-384 requires HelloRetryRequest in BoringSSL.
9296 CurvePreferences: []CurveID{CurveP384},
9297 Bugs: ProtocolBugs{
9298 SkipHelloRetryRequest: true,
9299 },
9300 },
9301 shouldFail: true,
9302 expectedError: ":WRONG_CURVE:",
9303 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009304
9305 testCases = append(testCases, testCase{
9306 name: "TLS13-RequestContextInHandshake",
9307 config: Config{
9308 MaxVersion: VersionTLS13,
9309 MinVersion: VersionTLS13,
9310 ClientAuth: RequireAnyClientCert,
9311 Bugs: ProtocolBugs{
9312 SendRequestContext: []byte("request context"),
9313 },
9314 },
9315 flags: []string{
9316 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9317 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9318 },
9319 shouldFail: true,
9320 expectedError: ":DECODE_ERROR:",
9321 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009322
9323 testCases = append(testCases, testCase{
9324 testType: serverTest,
9325 name: "TLS13-TrailingKeyShareData",
9326 config: Config{
9327 MaxVersion: VersionTLS13,
9328 Bugs: ProtocolBugs{
9329 TrailingKeyShareData: true,
9330 },
9331 },
9332 shouldFail: true,
9333 expectedError: ":DECODE_ERROR:",
9334 })
David Benjamin7f78df42016-10-05 22:33:19 -04009335
9336 testCases = append(testCases, testCase{
9337 name: "TLS13-AlwaysSelectPSKIdentity",
9338 config: Config{
9339 MaxVersion: VersionTLS13,
9340 Bugs: ProtocolBugs{
9341 AlwaysSelectPSKIdentity: true,
9342 },
9343 },
9344 shouldFail: true,
9345 expectedError: ":UNEXPECTED_EXTENSION:",
9346 })
9347
9348 testCases = append(testCases, testCase{
9349 name: "TLS13-InvalidPSKIdentity",
9350 config: Config{
9351 MaxVersion: VersionTLS13,
9352 Bugs: ProtocolBugs{
9353 SelectPSKIdentityOnResume: 1,
9354 },
9355 },
9356 resumeSession: true,
9357 shouldFail: true,
9358 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9359 })
David Benjamin1286bee2016-10-07 15:25:06 -04009360
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009361 testCases = append(testCases, testCase{
9362 testType: serverTest,
9363 name: "TLS13-ExtraPSKIdentity",
9364 config: Config{
9365 MaxVersion: VersionTLS13,
9366 Bugs: ProtocolBugs{
9367 ExtraPSKIdentity: true,
9368 },
9369 },
9370 resumeSession: true,
9371 })
9372
David Benjamin1286bee2016-10-07 15:25:06 -04009373 // Test that unknown NewSessionTicket extensions are tolerated.
9374 testCases = append(testCases, testCase{
9375 name: "TLS13-CustomTicketExtension",
9376 config: Config{
9377 MaxVersion: VersionTLS13,
9378 Bugs: ProtocolBugs{
9379 CustomTicketExtension: "1234",
9380 },
9381 },
9382 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009383}
9384
David Benjaminabbbee12016-10-31 19:20:42 -04009385func addTLS13CipherPreferenceTests() {
9386 // Test that client preference is honored if the shim has AES hardware
9387 // and ChaCha20-Poly1305 is preferred otherwise.
9388 testCases = append(testCases, testCase{
9389 testType: serverTest,
9390 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9391 config: Config{
9392 MaxVersion: VersionTLS13,
9393 CipherSuites: []uint16{
9394 TLS_CHACHA20_POLY1305_SHA256,
9395 TLS_AES_128_GCM_SHA256,
9396 },
9397 },
9398 flags: []string{
9399 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9400 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9401 },
9402 })
9403
9404 testCases = append(testCases, testCase{
9405 testType: serverTest,
9406 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9407 config: Config{
9408 MaxVersion: VersionTLS13,
9409 CipherSuites: []uint16{
9410 TLS_AES_128_GCM_SHA256,
9411 TLS_CHACHA20_POLY1305_SHA256,
9412 },
9413 },
9414 flags: []string{
9415 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9416 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9417 },
9418 })
9419
9420 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9421 // whether it has AES hardware.
9422 testCases = append(testCases, testCase{
9423 name: "TLS13-CipherPreference-Client",
9424 config: Config{
9425 MaxVersion: VersionTLS13,
9426 // Use the client cipher order. (This is the default but
9427 // is listed to be explicit.)
9428 PreferServerCipherSuites: false,
9429 },
9430 flags: []string{
9431 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9432 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9433 },
9434 })
9435}
9436
David Benjaminf3fbade2016-09-19 13:08:16 -04009437func addPeekTests() {
9438 // Test SSL_peek works, including on empty records.
9439 testCases = append(testCases, testCase{
9440 name: "Peek-Basic",
9441 sendEmptyRecords: 1,
9442 flags: []string{"-peek-then-read"},
9443 })
9444
9445 // Test SSL_peek can drive the initial handshake.
9446 testCases = append(testCases, testCase{
9447 name: "Peek-ImplicitHandshake",
9448 flags: []string{
9449 "-peek-then-read",
9450 "-implicit-handshake",
9451 },
9452 })
9453
9454 // Test SSL_peek can discover and drive a renegotiation.
9455 testCases = append(testCases, testCase{
9456 name: "Peek-Renegotiate",
9457 config: Config{
9458 MaxVersion: VersionTLS12,
9459 },
9460 renegotiate: 1,
9461 flags: []string{
9462 "-peek-then-read",
9463 "-renegotiate-freely",
9464 "-expect-total-renegotiations", "1",
9465 },
9466 })
9467
9468 // Test SSL_peek can discover a close_notify.
9469 testCases = append(testCases, testCase{
9470 name: "Peek-Shutdown",
9471 config: Config{
9472 Bugs: ProtocolBugs{
9473 ExpectCloseNotify: true,
9474 },
9475 },
9476 flags: []string{
9477 "-peek-then-read",
9478 "-check-close-notify",
9479 },
9480 })
9481
9482 // Test SSL_peek can discover an alert.
9483 testCases = append(testCases, testCase{
9484 name: "Peek-Alert",
9485 config: Config{
9486 Bugs: ProtocolBugs{
9487 SendSpuriousAlert: alertRecordOverflow,
9488 },
9489 },
9490 flags: []string{"-peek-then-read"},
9491 shouldFail: true,
9492 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9493 })
9494
9495 // Test SSL_peek can handle KeyUpdate.
9496 testCases = append(testCases, testCase{
9497 name: "Peek-KeyUpdate",
9498 config: Config{
9499 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009500 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009501 sendKeyUpdates: 1,
9502 keyUpdateRequest: keyUpdateNotRequested,
9503 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009504 })
9505}
9506
David Benjamine6f22212016-11-08 14:28:24 -05009507func addRecordVersionTests() {
9508 for _, ver := range tlsVersions {
9509 // Test that the record version is enforced.
9510 testCases = append(testCases, testCase{
9511 name: "CheckRecordVersion-" + ver.name,
9512 config: Config{
9513 MinVersion: ver.version,
9514 MaxVersion: ver.version,
9515 Bugs: ProtocolBugs{
9516 SendRecordVersion: 0x03ff,
9517 },
9518 },
9519 shouldFail: true,
9520 expectedError: ":WRONG_VERSION_NUMBER:",
9521 })
9522
9523 // Test that the ClientHello may use any record version, for
9524 // compatibility reasons.
9525 testCases = append(testCases, testCase{
9526 testType: serverTest,
9527 name: "LooseInitialRecordVersion-" + ver.name,
9528 config: Config{
9529 MinVersion: ver.version,
9530 MaxVersion: ver.version,
9531 Bugs: ProtocolBugs{
9532 SendInitialRecordVersion: 0x03ff,
9533 },
9534 },
9535 })
9536
9537 // Test that garbage ClientHello record versions are rejected.
9538 testCases = append(testCases, testCase{
9539 testType: serverTest,
9540 name: "GarbageInitialRecordVersion-" + ver.name,
9541 config: Config{
9542 MinVersion: ver.version,
9543 MaxVersion: ver.version,
9544 Bugs: ProtocolBugs{
9545 SendInitialRecordVersion: 0xffff,
9546 },
9547 },
9548 shouldFail: true,
9549 expectedError: ":WRONG_VERSION_NUMBER:",
9550 })
9551 }
9552}
9553
David Benjamin2c516452016-11-15 10:16:54 +09009554func addCertificateTests() {
9555 // Test that a certificate chain with intermediate may be sent and
9556 // received as both client and server.
9557 for _, ver := range tlsVersions {
9558 testCases = append(testCases, testCase{
9559 testType: clientTest,
9560 name: "SendReceiveIntermediate-Client-" + ver.name,
9561 config: Config{
9562 Certificates: []Certificate{rsaChainCertificate},
9563 ClientAuth: RequireAnyClientCert,
9564 },
9565 expectPeerCertificate: &rsaChainCertificate,
9566 flags: []string{
9567 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9568 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9569 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9570 },
9571 })
9572
9573 testCases = append(testCases, testCase{
9574 testType: serverTest,
9575 name: "SendReceiveIntermediate-Server-" + ver.name,
9576 config: Config{
9577 Certificates: []Certificate{rsaChainCertificate},
9578 },
9579 expectPeerCertificate: &rsaChainCertificate,
9580 flags: []string{
9581 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9582 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9583 "-require-any-client-certificate",
9584 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9585 },
9586 })
9587 }
9588}
9589
David Benjaminbbaf3672016-11-17 10:53:09 +09009590func addRetainOnlySHA256ClientCertTests() {
9591 for _, ver := range tlsVersions {
9592 // Test that enabling
9593 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9594 // actually requesting a client certificate is a no-op.
9595 testCases = append(testCases, testCase{
9596 testType: serverTest,
9597 name: "RetainOnlySHA256-NoCert-" + ver.name,
9598 config: Config{
9599 MinVersion: ver.version,
9600 MaxVersion: ver.version,
9601 },
9602 flags: []string{
9603 "-retain-only-sha256-client-cert-initial",
9604 "-retain-only-sha256-client-cert-resume",
9605 },
9606 resumeSession: true,
9607 })
9608
9609 // Test that when retaining only a SHA-256 certificate is
9610 // enabled, the hash appears as expected.
9611 testCases = append(testCases, testCase{
9612 testType: serverTest,
9613 name: "RetainOnlySHA256-Cert-" + ver.name,
9614 config: Config{
9615 MinVersion: ver.version,
9616 MaxVersion: ver.version,
9617 Certificates: []Certificate{rsaCertificate},
9618 },
9619 flags: []string{
9620 "-verify-peer",
9621 "-retain-only-sha256-client-cert-initial",
9622 "-retain-only-sha256-client-cert-resume",
9623 "-expect-sha256-client-cert-initial",
9624 "-expect-sha256-client-cert-resume",
9625 },
9626 resumeSession: true,
9627 })
9628
9629 // Test that when the config changes from on to off, a
9630 // resumption is rejected because the server now wants the full
9631 // certificate chain.
9632 testCases = append(testCases, testCase{
9633 testType: serverTest,
9634 name: "RetainOnlySHA256-OnOff-" + ver.name,
9635 config: Config{
9636 MinVersion: ver.version,
9637 MaxVersion: ver.version,
9638 Certificates: []Certificate{rsaCertificate},
9639 },
9640 flags: []string{
9641 "-verify-peer",
9642 "-retain-only-sha256-client-cert-initial",
9643 "-expect-sha256-client-cert-initial",
9644 },
9645 resumeSession: true,
9646 expectResumeRejected: true,
9647 })
9648
9649 // Test that when the config changes from off to on, a
9650 // resumption is rejected because the server now wants just the
9651 // hash.
9652 testCases = append(testCases, testCase{
9653 testType: serverTest,
9654 name: "RetainOnlySHA256-OffOn-" + ver.name,
9655 config: Config{
9656 MinVersion: ver.version,
9657 MaxVersion: ver.version,
9658 Certificates: []Certificate{rsaCertificate},
9659 },
9660 flags: []string{
9661 "-verify-peer",
9662 "-retain-only-sha256-client-cert-resume",
9663 "-expect-sha256-client-cert-resume",
9664 },
9665 resumeSession: true,
9666 expectResumeRejected: true,
9667 })
9668 }
9669}
9670
Adam Langley7c803a62015-06-15 15:35:05 -07009671func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009672 defer wg.Done()
9673
9674 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009675 var err error
9676
David Benjaminba28dfc2016-11-15 17:47:21 +09009677 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009678 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9679 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009680 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009681 if err != nil {
9682 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9683 }
9684 break
9685 }
9686 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009687 } else if *repeatUntilFailure {
9688 for err == nil {
9689 statusChan <- statusMsg{test: test, started: true}
9690 err = runTest(test, shimPath, -1)
9691 }
9692 } else {
9693 statusChan <- statusMsg{test: test, started: true}
9694 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009695 }
Adam Langley95c29f32014-06-20 12:00:00 -07009696 statusChan <- statusMsg{test: test, err: err}
9697 }
9698}
9699
9700type statusMsg struct {
9701 test *testCase
9702 started bool
9703 err error
9704}
9705
David Benjamin5f237bc2015-02-11 17:14:15 -05009706func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009707 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009708
David Benjamin5f237bc2015-02-11 17:14:15 -05009709 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009710 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009711 if !*pipe {
9712 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009713 var erase string
9714 for i := 0; i < lineLen; i++ {
9715 erase += "\b \b"
9716 }
9717 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009718 }
9719
Adam Langley95c29f32014-06-20 12:00:00 -07009720 if msg.started {
9721 started++
9722 } else {
9723 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009724
9725 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009726 if msg.err == errUnimplemented {
9727 if *pipe {
9728 // Print each test instead of a status line.
9729 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9730 }
9731 unimplemented++
9732 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9733 } else {
9734 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9735 failed++
9736 testOutput.addResult(msg.test.name, "FAIL")
9737 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009738 } else {
9739 if *pipe {
9740 // Print each test instead of a status line.
9741 fmt.Printf("PASSED (%s)\n", msg.test.name)
9742 }
9743 testOutput.addResult(msg.test.name, "PASS")
9744 }
Adam Langley95c29f32014-06-20 12:00:00 -07009745 }
9746
David Benjamin5f237bc2015-02-11 17:14:15 -05009747 if !*pipe {
9748 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009749 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009750 lineLen = len(line)
9751 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009752 }
Adam Langley95c29f32014-06-20 12:00:00 -07009753 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009754
9755 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009756}
9757
9758func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009759 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009760 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009761 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009762
Adam Langley7c803a62015-06-15 15:35:05 -07009763 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009764 addCipherSuiteTests()
9765 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009766 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009767 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009768 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009769 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009770 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009771 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009772 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009773 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009774 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009775 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009776 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009777 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009778 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009779 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009780 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009781 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009782 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009783 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009784 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009785 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009786 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009787 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009788 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009789 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009790 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009791 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009792 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009793 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009794 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009795 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009796 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009797 addRetainOnlySHA256ClientCertTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009798
9799 var wg sync.WaitGroup
9800
Adam Langley7c803a62015-06-15 15:35:05 -07009801 statusChan := make(chan statusMsg, *numWorkers)
9802 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009803 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009804
EKRf71d7ed2016-08-06 13:25:12 -07009805 if len(*shimConfigFile) != 0 {
9806 encoded, err := ioutil.ReadFile(*shimConfigFile)
9807 if err != nil {
9808 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9809 os.Exit(1)
9810 }
9811
9812 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9813 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9814 os.Exit(1)
9815 }
9816 }
9817
David Benjamin025b3d32014-07-01 19:53:04 -04009818 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009819
Adam Langley7c803a62015-06-15 15:35:05 -07009820 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009821 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009822 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009823 }
9824
David Benjamin270f0a72016-03-17 14:41:36 -04009825 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009826 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009827 matched := true
9828 if len(*testToRun) != 0 {
9829 var err error
9830 matched, err = filepath.Match(*testToRun, testCases[i].name)
9831 if err != nil {
9832 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9833 os.Exit(1)
9834 }
9835 }
9836
EKRf71d7ed2016-08-06 13:25:12 -07009837 if !*includeDisabled {
9838 for pattern := range shimConfig.DisabledTests {
9839 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9840 if err != nil {
9841 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9842 os.Exit(1)
9843 }
9844
9845 if isDisabled {
9846 matched = false
9847 break
9848 }
9849 }
9850 }
9851
David Benjamin17e12922016-07-28 18:04:43 -04009852 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009853 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009854 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +09009855
9856 // Only run one test if repeating until failure.
9857 if *repeatUntilFailure {
9858 break
9859 }
Adam Langley95c29f32014-06-20 12:00:00 -07009860 }
9861 }
David Benjamin17e12922016-07-28 18:04:43 -04009862
David Benjamin270f0a72016-03-17 14:41:36 -04009863 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009864 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009865 os.Exit(1)
9866 }
Adam Langley95c29f32014-06-20 12:00:00 -07009867
9868 close(testChan)
9869 wg.Wait()
9870 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009871 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009872
9873 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009874
9875 if *jsonOutput != "" {
9876 if err := testOutput.writeTo(*jsonOutput); err != nil {
9877 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9878 }
9879 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009880
EKR842ae6c2016-07-27 09:22:05 +02009881 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9882 os.Exit(1)
9883 }
9884
9885 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009886 os.Exit(1)
9887 }
Adam Langley95c29f32014-06-20 12:00:00 -07009888}