blob: a715ada0c0b977a9bb66cbd77b98ceb7f1bc5cff [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090065 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080066)
Adam Langley95c29f32014-06-20 12:00:00 -070067
EKRf71d7ed2016-08-06 13:25:12 -070068// ShimConfigurations is used with the “json” package and represents a shim
69// config file.
70type ShimConfiguration struct {
71 // DisabledTests maps from a glob-based pattern to a freeform string.
72 // The glob pattern is used to exclude tests from being run and the
73 // freeform string is unparsed but expected to explain why the test is
74 // disabled.
75 DisabledTests map[string]string
76
77 // ErrorMap maps from expected error strings to the correct error
78 // string for the shim in question. For example, it might map
79 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
80 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
81 ErrorMap map[string]string
82}
83
84var shimConfig ShimConfiguration
85
David Benjamin33863262016-07-08 17:20:12 -070086type testCert int
87
David Benjamin025b3d32014-07-01 19:53:04 -040088const (
David Benjamin33863262016-07-08 17:20:12 -070089 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040090 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090091 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070092 testCertECDSAP256
93 testCertECDSAP384
94 testCertECDSAP521
95)
96
97const (
98 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040099 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900100 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700101 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
102 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
103 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400104)
105
106const (
David Benjamina08e49d2014-08-24 01:46:07 -0400107 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400108 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900109 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700110 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
111 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
112 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400113 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400114)
115
David Benjamin7944a9f2016-07-12 22:27:01 -0400116var (
117 rsaCertificate Certificate
118 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900119 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400120 ecdsaP256Certificate Certificate
121 ecdsaP384Certificate Certificate
122 ecdsaP521Certificate Certificate
123)
David Benjamin33863262016-07-08 17:20:12 -0700124
125var testCerts = []struct {
126 id testCert
127 certFile, keyFile string
128 cert *Certificate
129}{
130 {
131 id: testCertRSA,
132 certFile: rsaCertificateFile,
133 keyFile: rsaKeyFile,
134 cert: &rsaCertificate,
135 },
136 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 id: testCertRSA1024,
138 certFile: rsa1024CertificateFile,
139 keyFile: rsa1024KeyFile,
140 cert: &rsa1024Certificate,
141 },
142 {
David Benjamin2c516452016-11-15 10:16:54 +0900143 id: testCertRSAChain,
144 certFile: rsaChainCertificateFile,
145 keyFile: rsaChainKeyFile,
146 cert: &rsaChainCertificate,
147 },
148 {
David Benjamin33863262016-07-08 17:20:12 -0700149 id: testCertECDSAP256,
150 certFile: ecdsaP256CertificateFile,
151 keyFile: ecdsaP256KeyFile,
152 cert: &ecdsaP256Certificate,
153 },
154 {
155 id: testCertECDSAP384,
156 certFile: ecdsaP384CertificateFile,
157 keyFile: ecdsaP384KeyFile,
158 cert: &ecdsaP384Certificate,
159 },
160 {
161 id: testCertECDSAP521,
162 certFile: ecdsaP521CertificateFile,
163 keyFile: ecdsaP521KeyFile,
164 cert: &ecdsaP521Certificate,
165 },
166}
167
David Benjamina08e49d2014-08-24 01:46:07 -0400168var channelIDKey *ecdsa.PrivateKey
169var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700170
David Benjamin61f95272014-11-25 01:55:35 -0500171var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800172var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500173
Steven Valdeza833c352016-11-01 13:39:36 -0400174var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800175var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400176
Adam Langley95c29f32014-06-20 12:00:00 -0700177func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700178 for i := range testCerts {
179 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
180 if err != nil {
181 panic(err)
182 }
183 cert.OCSPStaple = testOCSPResponse
184 cert.SignedCertificateTimestampList = testSCTList
185 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700186 }
David Benjamina08e49d2014-08-24 01:46:07 -0400187
Adam Langley7c803a62015-06-15 15:35:05 -0700188 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400189 if err != nil {
190 panic(err)
191 }
192 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
193 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
194 panic("bad key type")
195 }
196 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
197 if err != nil {
198 panic(err)
199 }
200 if channelIDKey.Curve != elliptic.P256() {
201 panic("bad curve")
202 }
203
204 channelIDBytes = make([]byte, 64)
205 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
206 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700207}
208
David Benjamin33863262016-07-08 17:20:12 -0700209func getRunnerCertificate(t testCert) Certificate {
210 for _, cert := range testCerts {
211 if cert.id == t {
212 return *cert.cert
213 }
214 }
215 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700216}
217
David Benjamin33863262016-07-08 17:20:12 -0700218func getShimCertificate(t testCert) string {
219 for _, cert := range testCerts {
220 if cert.id == t {
221 return cert.certFile
222 }
223 }
224 panic("Unknown test certificate")
225}
226
227func getShimKey(t testCert) string {
228 for _, cert := range testCerts {
229 if cert.id == t {
230 return cert.keyFile
231 }
232 }
233 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700234}
235
David Benjamin025b3d32014-07-01 19:53:04 -0400236type testType int
237
238const (
239 clientTest testType = iota
240 serverTest
241)
242
David Benjamin6fd297b2014-08-11 18:43:38 -0400243type protocol int
244
245const (
246 tls protocol = iota
247 dtls
248)
249
David Benjaminfc7b0862014-09-06 13:21:53 -0400250const (
251 alpn = 1
252 npn = 2
253)
254
Adam Langley95c29f32014-06-20 12:00:00 -0700255type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400256 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700258 name string
259 config Config
260 shouldFail bool
261 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700262 // expectedLocalError, if not empty, contains a substring that must be
263 // found in the local error.
264 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400265 // expectedVersion, if non-zero, specifies the TLS version that must be
266 // negotiated.
267 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400268 // expectedResumeVersion, if non-zero, specifies the TLS version that
269 // must be negotiated on resumption. If zero, expectedVersion is used.
270 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400271 // expectedCipher, if non-zero, specifies the TLS cipher suite that
272 // should be negotiated.
273 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400274 // expectChannelID controls whether the connection should have
275 // negotiated a Channel ID with channelIDKey.
276 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400277 // expectedNextProto controls whether the connection should
278 // negotiate a next protocol via NPN or ALPN.
279 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400280 // expectNoNextProto, if true, means that no next protocol should be
281 // negotiated.
282 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400283 // expectedNextProtoType, if non-zero, is the expected next
284 // protocol negotiation mechanism.
285 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500286 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
287 // should be negotiated. If zero, none should be negotiated.
288 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100289 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
290 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100291 // expectedSCTList, if not nil, is the expected SCT list to be received.
292 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700293 // expectedPeerSignatureAlgorithm, if not zero, is the signature
294 // algorithm that the peer should have used in the handshake.
295 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400296 // expectedCurveID, if not zero, is the curve that the handshake should
297 // have used.
298 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700299 // messageLen is the length, in bytes, of the test message that will be
300 // sent.
301 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400302 // messageCount is the number of test messages that will be sent.
303 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400304 // certFile is the path to the certificate to use for the server.
305 certFile string
306 // keyFile is the path to the private key to use for the server.
307 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400308 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400309 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400311 // resumeRenewedSession controls whether a third connection should be
312 // tested which attempts to resume the second connection's session.
313 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700314 // expectResumeRejected, if true, specifies that the attempted
315 // resumption must be rejected by the client. This is only valid for a
316 // serverTest.
317 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400318 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500319 // resumption. Unless newSessionsOnResume is set,
320 // SessionTicketKey, ServerSessionCache, and
321 // ClientSessionCache are copied from the initial connection's
322 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400323 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500324 // newSessionsOnResume, if true, will cause resumeConfig to
325 // use a different session resumption context.
326 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400327 // noSessionCache, if true, will cause the server to run without a
328 // session cache.
329 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400330 // sendPrefix sends a prefix on the socket before actually performing a
331 // handshake.
332 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400333 // shimWritesFirst controls whether the shim sends an initial "hello"
334 // message before doing a roundtrip with the runner.
335 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400336 // shimShutsDown, if true, runs a test where the shim shuts down the
337 // connection immediately after the handshake rather than echoing
338 // messages from the runner.
339 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400340 // renegotiate indicates the number of times the connection should be
341 // renegotiated during the exchange.
342 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400343 // sendHalfHelloRequest, if true, causes the server to send half a
344 // HelloRequest when the handshake completes.
345 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700346 // renegotiateCiphers is a list of ciphersuite ids that will be
347 // switched in just before renegotiation.
348 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500349 // replayWrites, if true, configures the underlying transport
350 // to replay every write it makes in DTLS tests.
351 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500352 // damageFirstWrite, if true, configures the underlying transport to
353 // damage the final byte of the first application data write.
354 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400355 // exportKeyingMaterial, if non-zero, configures the test to exchange
356 // keying material and verify they match.
357 exportKeyingMaterial int
358 exportLabel string
359 exportContext string
360 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400361 // flags, if not empty, contains a list of command-line flags that will
362 // be passed to the shim program.
363 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700364 // testTLSUnique, if true, causes the shim to send the tls-unique value
365 // which will be compared against the expected value.
366 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400367 // sendEmptyRecords is the number of consecutive empty records to send
368 // before and after the test message.
369 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400370 // sendWarningAlerts is the number of consecutive warning alerts to send
371 // before and after the test message.
372 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400373 // sendKeyUpdates is the number of consecutive key updates to send
374 // before and after the test message.
375 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400376 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
377 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400378 // expectMessageDropped, if true, means the test message is expected to
379 // be dropped by the client rather than echoed back.
380 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900381 // expectPeerCertificate, if not nil, is the certificate chain the peer
382 // is expected to send.
383 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700384}
385
Adam Langley7c803a62015-06-15 15:35:05 -0700386var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700387
David Benjaminc07afb72016-09-22 10:18:58 -0400388func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500389 if len(data) == 0 {
390 return
391 }
392
393 protocol := "tls"
394 if test.protocol == dtls {
395 protocol = "dtls"
396 }
397
398 side := "client"
399 if test.testType == serverTest {
400 side = "server"
401 }
402
403 dir := path.Join(*transcriptDir, protocol, side)
404 if err := os.MkdirAll(dir, 0755); err != nil {
405 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
406 return
407 }
408
David Benjaminc07afb72016-09-22 10:18:58 -0400409 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500410 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
411 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
412 }
413}
414
David Benjamin3ed59772016-03-08 12:50:21 -0500415// A timeoutConn implements an idle timeout on each Read and Write operation.
416type timeoutConn struct {
417 net.Conn
418 timeout time.Duration
419}
420
421func (t *timeoutConn) Read(b []byte) (int, error) {
422 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
423 return 0, err
424 }
425 return t.Conn.Read(b)
426}
427
428func (t *timeoutConn) Write(b []byte) (int, error) {
429 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
430 return 0, err
431 }
432 return t.Conn.Write(b)
433}
434
David Benjaminc07afb72016-09-22 10:18:58 -0400435func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400436 if !test.noSessionCache {
437 if config.ClientSessionCache == nil {
438 config.ClientSessionCache = NewLRUClientSessionCache(1)
439 }
440 if config.ServerSessionCache == nil {
441 config.ServerSessionCache = NewLRUServerSessionCache(1)
442 }
443 }
444 if test.testType == clientTest {
445 if len(config.Certificates) == 0 {
446 config.Certificates = []Certificate{rsaCertificate}
447 }
448 } else {
449 // Supply a ServerName to ensure a constant session cache key,
450 // rather than falling back to net.Conn.RemoteAddr.
451 if len(config.ServerName) == 0 {
452 config.ServerName = "test"
453 }
454 }
455 if *fuzzer {
456 config.Bugs.NullAllCiphers = true
457 }
David Benjamin01a90572016-09-22 00:11:43 -0400458 if *deterministic {
459 config.Time = func() time.Time { return time.Unix(1234, 1234) }
460 }
David Benjamine54af062016-08-08 19:21:18 -0400461
David Benjamin01784b42016-06-07 18:00:52 -0400462 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500463
David Benjamin6fd297b2014-08-11 18:43:38 -0400464 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500465 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
466 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500467 }
468
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500470 local, peer := "client", "server"
471 if test.testType == clientTest {
472 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500473 }
David Benjaminebda9b32015-11-02 15:33:18 -0500474 connDebug := &recordingConn{
475 Conn: conn,
476 isDatagram: test.protocol == dtls,
477 local: local,
478 peer: peer,
479 }
480 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 if *flagDebug {
482 defer connDebug.WriteTo(os.Stdout)
483 }
484 if len(*transcriptDir) != 0 {
485 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400486 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500487 }()
488 }
David Benjaminebda9b32015-11-02 15:33:18 -0500489
490 if config.Bugs.PacketAdaptor != nil {
491 config.Bugs.PacketAdaptor.debug = connDebug
492 }
493 }
494
495 if test.replayWrites {
496 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 }
498
David Benjamin3ed59772016-03-08 12:50:21 -0500499 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500500 if test.damageFirstWrite {
501 connDamage = newDamageAdaptor(conn)
502 conn = connDamage
503 }
504
David Benjamin6fd297b2014-08-11 18:43:38 -0400505 if test.sendPrefix != "" {
506 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
507 return err
508 }
David Benjamin98e882e2014-08-08 13:24:34 -0400509 }
510
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400512 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400513 if test.protocol == dtls {
514 tlsConn = DTLSServer(conn, config)
515 } else {
516 tlsConn = Server(conn, config)
517 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400518 } else {
519 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400520 if test.protocol == dtls {
521 tlsConn = DTLSClient(conn, config)
522 } else {
523 tlsConn = Client(conn, config)
524 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400525 }
David Benjamin30789da2015-08-29 22:56:45 -0400526 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400527
Adam Langley95c29f32014-06-20 12:00:00 -0700528 if err := tlsConn.Handshake(); err != nil {
529 return err
530 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700531
David Benjamin01fe8202014-09-24 15:21:44 -0400532 // TODO(davidben): move all per-connection expectations into a dedicated
533 // expectations struct that can be specified separately for the two
534 // legs.
535 expectedVersion := test.expectedVersion
536 if isResume && test.expectedResumeVersion != 0 {
537 expectedVersion = test.expectedResumeVersion
538 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 connState := tlsConn.ConnectionState()
540 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400541 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400542 }
543
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700544 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400545 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
546 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700547 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
548 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
549 }
David Benjamin90da8c82015-04-20 14:57:57 -0400550
David Benjamina08e49d2014-08-24 01:46:07 -0400551 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400553 if channelID == nil {
554 return fmt.Errorf("no channel ID negotiated")
555 }
556 if channelID.Curve != channelIDKey.Curve ||
557 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
558 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
559 return fmt.Errorf("incorrect channel ID")
560 }
561 }
562
David Benjaminae2888f2014-09-06 12:58:58 -0400563 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400565 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
566 }
567 }
568
David Benjaminc7ce9772015-10-09 19:32:41 -0400569 if test.expectNoNextProto {
570 if actual := connState.NegotiatedProtocol; actual != "" {
571 return fmt.Errorf("got unexpected next proto %s", actual)
572 }
573 }
574
David Benjaminfc7b0862014-09-06 13:21:53 -0400575 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700576 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400577 return fmt.Errorf("next proto type mismatch")
578 }
579 }
580
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700581 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500582 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
583 }
584
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100585 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300586 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100587 }
588
Paul Lietar4fac72e2015-09-09 13:44:55 +0100589 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
590 return fmt.Errorf("SCT list mismatch")
591 }
592
Nick Harper60edffd2016-06-21 15:19:24 -0700593 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
594 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400595 }
596
Steven Valdez5440fe02016-07-18 12:40:30 -0400597 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
598 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
599 }
600
David Benjamin2c516452016-11-15 10:16:54 +0900601 if test.expectPeerCertificate != nil {
602 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
603 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
604 }
605 for i, cert := range connState.PeerCertificates {
606 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
607 return fmt.Errorf("peer certificate %d did not match", i+1)
608 }
609 }
610 }
611
David Benjaminc565ebb2015-04-03 04:06:36 -0400612 if test.exportKeyingMaterial > 0 {
613 actual := make([]byte, test.exportKeyingMaterial)
614 if _, err := io.ReadFull(tlsConn, actual); err != nil {
615 return err
616 }
617 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
618 if err != nil {
619 return err
620 }
621 if !bytes.Equal(actual, expected) {
622 return fmt.Errorf("keying material mismatch")
623 }
624 }
625
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700626 if test.testTLSUnique {
627 var peersValue [12]byte
628 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
629 return err
630 }
631 expected := tlsConn.ConnectionState().TLSUnique
632 if !bytes.Equal(peersValue[:], expected) {
633 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
634 }
635 }
636
David Benjamine58c4f52014-08-24 03:47:07 -0400637 if test.shimWritesFirst {
638 var buf [5]byte
639 _, err := io.ReadFull(tlsConn, buf[:])
640 if err != nil {
641 return err
642 }
643 if string(buf[:]) != "hello" {
644 return fmt.Errorf("bad initial message")
645 }
646 }
647
Steven Valdez32635b82016-08-16 11:25:03 -0400648 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400649 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400650 return err
651 }
Steven Valdez32635b82016-08-16 11:25:03 -0400652 }
653
David Benjamina8ebe222015-06-06 03:04:39 -0400654 for i := 0; i < test.sendEmptyRecords; i++ {
655 tlsConn.Write(nil)
656 }
657
David Benjamin24f346d2015-06-06 03:28:08 -0400658 for i := 0; i < test.sendWarningAlerts; i++ {
659 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
660 }
661
David Benjamin47921102016-07-28 11:29:18 -0400662 if test.sendHalfHelloRequest {
663 tlsConn.SendHalfHelloRequest()
664 }
665
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400666 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700667 if test.renegotiateCiphers != nil {
668 config.CipherSuites = test.renegotiateCiphers
669 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400670 for i := 0; i < test.renegotiate; i++ {
671 if err := tlsConn.Renegotiate(); err != nil {
672 return err
673 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700674 }
675 } else if test.renegotiateCiphers != nil {
676 panic("renegotiateCiphers without renegotiate")
677 }
678
David Benjamin5fa3eba2015-01-22 16:35:40 -0500679 if test.damageFirstWrite {
680 connDamage.setDamage(true)
681 tlsConn.Write([]byte("DAMAGED WRITE"))
682 connDamage.setDamage(false)
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700686 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400687 if test.protocol == dtls {
688 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
689 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700690 // Read until EOF.
691 _, err := io.Copy(ioutil.Discard, tlsConn)
692 return err
693 }
David Benjamin4417d052015-04-05 04:17:25 -0400694 if messageLen == 0 {
695 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700696 }
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 messageCount := test.messageCount
699 if messageCount == 0 {
700 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400701 }
702
David Benjamin8e6db492015-07-25 18:29:23 -0400703 for j := 0; j < messageCount; j++ {
704 testMessage := make([]byte, messageLen)
705 for i := range testMessage {
706 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400707 }
David Benjamin8e6db492015-07-25 18:29:23 -0400708 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700709
Steven Valdez32635b82016-08-16 11:25:03 -0400710 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400711 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400712 }
713
David Benjamin8e6db492015-07-25 18:29:23 -0400714 for i := 0; i < test.sendEmptyRecords; i++ {
715 tlsConn.Write(nil)
716 }
717
718 for i := 0; i < test.sendWarningAlerts; i++ {
719 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
720 }
721
David Benjamin4f75aaf2015-09-01 16:53:10 -0400722 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400723 // The shim will not respond.
724 continue
725 }
726
David Benjamin8e6db492015-07-25 18:29:23 -0400727 buf := make([]byte, len(testMessage))
728 if test.protocol == dtls {
729 bufTmp := make([]byte, len(buf)+1)
730 n, err := tlsConn.Read(bufTmp)
731 if err != nil {
732 return err
733 }
734 if n != len(buf) {
735 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
736 }
737 copy(buf, bufTmp)
738 } else {
739 _, err := io.ReadFull(tlsConn, buf)
740 if err != nil {
741 return err
742 }
743 }
744
745 for i, v := range buf {
746 if v != testMessage[i]^0xff {
747 return fmt.Errorf("bad reply contents at byte %d", i)
748 }
Adam Langley95c29f32014-06-20 12:00:00 -0700749 }
750 }
751
752 return nil
753}
754
David Benjamin325b5c32014-07-01 19:40:31 -0400755func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400756 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700757 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400758 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700759 }
David Benjamin325b5c32014-07-01 19:40:31 -0400760 valgrindArgs = append(valgrindArgs, path)
761 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700762
David Benjamin325b5c32014-07-01 19:40:31 -0400763 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
David Benjamin325b5c32014-07-01 19:40:31 -0400766func gdbOf(path string, args ...string) *exec.Cmd {
767 xtermArgs := []string{"-e", "gdb", "--args"}
768 xtermArgs = append(xtermArgs, path)
769 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamind16bf342015-12-18 00:53:12 -0500774func lldbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "lldb", "--"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
778
779 return exec.Command("xterm", xtermArgs...)
780}
781
EKR842ae6c2016-07-27 09:22:05 +0200782var (
783 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
784 errUnimplemented = errors.New("child process does not implement needed flags")
785)
Adam Langley69a01602014-11-17 17:26:55 -0800786
David Benjamin87c8a642015-02-21 01:54:29 -0500787// accept accepts a connection from listener, unless waitChan signals a process
788// exit first.
789func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
790 type connOrError struct {
791 conn net.Conn
792 err error
793 }
794 connChan := make(chan connOrError, 1)
795 go func() {
796 conn, err := listener.Accept()
797 connChan <- connOrError{conn, err}
798 close(connChan)
799 }()
800 select {
801 case result := <-connChan:
802 return result.conn, result.err
803 case childErr := <-waitChan:
804 waitChan <- childErr
805 return nil, fmt.Errorf("child exited early: %s", childErr)
806 }
807}
808
EKRf71d7ed2016-08-06 13:25:12 -0700809func translateExpectedError(errorStr string) string {
810 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
811 return translated
812 }
813
814 if *looseErrors {
815 return ""
816 }
817
818 return errorStr
819}
820
Adam Langley7c803a62015-06-15 15:35:05 -0700821func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400822 // Help debugging panics on the Go side.
823 defer func() {
824 if r := recover(); r != nil {
825 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
826 panic(r)
827 }
828 }()
829
Adam Langley38311732014-10-16 19:04:35 -0700830 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
831 panic("Error expected without shouldFail in " + test.name)
832 }
833
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700834 if test.expectResumeRejected && !test.resumeSession {
835 panic("expectResumeRejected without resumeSession in " + test.name)
836 }
837
Adam Langley33b1d4f2016-12-07 15:03:45 -0800838 for _, ver := range tlsVersions {
839 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
840 continue
841 }
842
843 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
844 continue
845 }
846
847 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
848 }
849
David Benjamin87c8a642015-02-21 01:54:29 -0500850 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
851 if err != nil {
852 panic(err)
853 }
854 defer func() {
855 if listener != nil {
856 listener.Close()
857 }
858 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700859
David Benjamin87c8a642015-02-21 01:54:29 -0500860 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400861 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400862 flags = append(flags, "-server")
863
David Benjamin025b3d32014-07-01 19:53:04 -0400864 flags = append(flags, "-key-file")
865 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700866 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400867 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700868 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400869 }
870
871 flags = append(flags, "-cert-file")
872 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400874 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700875 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400876 }
877 }
David Benjamin5a593af2014-08-11 19:51:50 -0400878
David Benjamin6fd297b2014-08-11 18:43:38 -0400879 if test.protocol == dtls {
880 flags = append(flags, "-dtls")
881 }
882
David Benjamin46662482016-08-17 00:51:00 -0400883 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400884 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400885 resumeCount++
886 if test.resumeRenewedSession {
887 resumeCount++
888 }
889 }
890
891 if resumeCount > 0 {
892 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400893 }
894
David Benjamine58c4f52014-08-24 03:47:07 -0400895 if test.shimWritesFirst {
896 flags = append(flags, "-shim-writes-first")
897 }
898
David Benjamin30789da2015-08-29 22:56:45 -0400899 if test.shimShutsDown {
900 flags = append(flags, "-shim-shuts-down")
901 }
902
David Benjaminc565ebb2015-04-03 04:06:36 -0400903 if test.exportKeyingMaterial > 0 {
904 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
905 flags = append(flags, "-export-label", test.exportLabel)
906 flags = append(flags, "-export-context", test.exportContext)
907 if test.useExportContext {
908 flags = append(flags, "-use-export-context")
909 }
910 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700911 if test.expectResumeRejected {
912 flags = append(flags, "-expect-session-miss")
913 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400914
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700915 if test.testTLSUnique {
916 flags = append(flags, "-tls-unique")
917 }
918
David Benjamin025b3d32014-07-01 19:53:04 -0400919 flags = append(flags, test.flags...)
920
921 var shim *exec.Cmd
922 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700923 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700924 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700925 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500926 } else if *useLLDB {
927 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400928 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700929 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400930 }
David Benjamin025b3d32014-07-01 19:53:04 -0400931 shim.Stdin = os.Stdin
932 var stdoutBuf, stderrBuf bytes.Buffer
933 shim.Stdout = &stdoutBuf
934 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800935 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500936 shim.Env = os.Environ()
937 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800938 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400939 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800940 }
941 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
942 }
David Benjamin025b3d32014-07-01 19:53:04 -0400943
944 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700945 panic(err)
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 waitChan := make(chan error, 1)
948 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700949
950 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin7a4aaa42016-09-20 17:58:14 -0400952 if *deterministic {
953 config.Rand = &deterministicRand{}
954 }
955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 conn, err := acceptOrWait(listener, waitChan)
957 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400958 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500959 conn.Close()
960 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500961
David Benjamin46662482016-08-17 00:51:00 -0400962 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400963 var resumeConfig Config
964 if test.resumeConfig != nil {
965 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400966 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500967 resumeConfig.SessionTicketKey = config.SessionTicketKey
968 resumeConfig.ClientSessionCache = config.ClientSessionCache
969 resumeConfig.ServerSessionCache = config.ServerSessionCache
970 }
David Benjamin2e045a92016-06-08 13:09:56 -0400971 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400972 } else {
973 resumeConfig = config
974 }
David Benjamin87c8a642015-02-21 01:54:29 -0500975 var connResume net.Conn
976 connResume, err = acceptOrWait(listener, waitChan)
977 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400978 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500979 connResume.Close()
980 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400981 }
982
David Benjamin87c8a642015-02-21 01:54:29 -0500983 // Close the listener now. This is to avoid hangs should the shim try to
984 // open more connections than expected.
985 listener.Close()
986 listener = nil
987
988 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400989 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800990 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200991 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
992 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800993 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200994 case 89:
995 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400996 case 99:
997 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800998 }
999 }
Adam Langley95c29f32014-06-20 12:00:00 -07001000
David Benjamin9bea3492016-03-02 10:59:16 -05001001 // Account for Windows line endings.
1002 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1003 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001004
1005 // Separate the errors from the shim and those from tools like
1006 // AddressSanitizer.
1007 var extraStderr string
1008 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1009 stderr = stderrParts[0]
1010 extraStderr = stderrParts[1]
1011 }
1012
Adam Langley95c29f32014-06-20 12:00:00 -07001013 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001014 expectedError := translateExpectedError(test.expectedError)
1015 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001016
Adam Langleyac61fa32014-06-23 12:03:11 -07001017 localError := "none"
1018 if err != nil {
1019 localError = err.Error()
1020 }
1021 if len(test.expectedLocalError) != 0 {
1022 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1023 }
Adam Langley95c29f32014-06-20 12:00:00 -07001024
1025 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001026 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001027 if childErr != nil {
1028 childError = childErr.Error()
1029 }
1030
1031 var msg string
1032 switch {
1033 case failed && !test.shouldFail:
1034 msg = "unexpected failure"
1035 case !failed && test.shouldFail:
1036 msg = "unexpected success"
1037 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001038 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001039 default:
1040 panic("internal error")
1041 }
1042
David Benjamin9aafb642016-09-20 19:36:53 -04001043 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001044 }
1045
David Benjamind2ba8892016-09-20 19:41:04 -04001046 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001047 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001048 }
1049
David Benjamind2ba8892016-09-20 19:41:04 -04001050 if *useValgrind && isValgrindError {
1051 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1052 }
1053
Adam Langley95c29f32014-06-20 12:00:00 -07001054 return nil
1055}
1056
David Benjaminaa012042016-12-10 13:33:05 -05001057type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001058 name string
1059 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001060 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001061 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001062}
1063
1064var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001065 {"SSL3", VersionSSL30, "-no-ssl3", false},
1066 {"TLS1", VersionTLS10, "-no-tls1", true},
1067 {"TLS11", VersionTLS11, "-no-tls11", false},
1068 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001069 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001070}
1071
David Benjaminaa012042016-12-10 13:33:05 -05001072type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001073 name string
1074 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001075}
1076
1077var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001078 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001079 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001080 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001081 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001082 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001083 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001084 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001085 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1086 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001087 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001088 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1089 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001090 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001091 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1092 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001093 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1094 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001095 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001096 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001097 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001098 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001099 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001100 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001101 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001102 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001103 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001104 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001105 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001106 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
David Benjamin48cae082014-10-27 01:06:24 -04001107 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1108 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001109 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1110 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001111 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001112 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1113 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1114 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001115 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001116}
1117
David Benjamin8b8c0062014-11-23 02:47:52 -05001118func hasComponent(suiteName, component string) bool {
1119 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1120}
1121
David Benjaminf7768e42014-08-31 02:06:47 -04001122func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001123 return hasComponent(suiteName, "GCM") ||
1124 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001125 hasComponent(suiteName, "SHA384") ||
1126 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001127}
1128
Nick Harper1fd39d82016-06-14 18:14:35 -07001129func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001130 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001131}
1132
David Benjamin8b8c0062014-11-23 02:47:52 -05001133func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001134 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001135}
1136
Adam Langleya7997f12015-05-14 17:38:50 -07001137func bigFromHex(hex string) *big.Int {
1138 ret, ok := new(big.Int).SetString(hex, 16)
1139 if !ok {
1140 panic("failed to parse hex number 0x" + hex)
1141 }
1142 return ret
1143}
1144
Adam Langley7c803a62015-06-15 15:35:05 -07001145func addBasicTests() {
1146 basicTests := []testCase{
1147 {
Adam Langley7c803a62015-06-15 15:35:05 -07001148 name: "NoFallbackSCSV",
1149 config: Config{
1150 Bugs: ProtocolBugs{
1151 FailIfNotFallbackSCSV: true,
1152 },
1153 },
1154 shouldFail: true,
1155 expectedLocalError: "no fallback SCSV found",
1156 },
1157 {
1158 name: "SendFallbackSCSV",
1159 config: Config{
1160 Bugs: ProtocolBugs{
1161 FailIfNotFallbackSCSV: true,
1162 },
1163 },
1164 flags: []string{"-fallback-scsv"},
1165 },
1166 {
1167 name: "ClientCertificateTypes",
1168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001169 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001170 ClientAuth: RequestClientCert,
1171 ClientCertificateTypes: []byte{
1172 CertTypeDSSSign,
1173 CertTypeRSASign,
1174 CertTypeECDSASign,
1175 },
1176 },
1177 flags: []string{
1178 "-expect-certificate-types",
1179 base64.StdEncoding.EncodeToString([]byte{
1180 CertTypeDSSSign,
1181 CertTypeRSASign,
1182 CertTypeECDSASign,
1183 }),
1184 },
1185 },
1186 {
Adam Langley7c803a62015-06-15 15:35:05 -07001187 name: "UnauthenticatedECDH",
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 UnauthenticatedECDH: true,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":UNEXPECTED_MESSAGE:",
1197 },
1198 {
1199 name: "SkipCertificateStatus",
1200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001201 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001202 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1203 Bugs: ProtocolBugs{
1204 SkipCertificateStatus: true,
1205 },
1206 },
1207 flags: []string{
1208 "-enable-ocsp-stapling",
1209 },
1210 },
1211 {
1212 name: "SkipServerKeyExchange",
1213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001214 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001215 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1216 Bugs: ProtocolBugs{
1217 SkipServerKeyExchange: true,
1218 },
1219 },
1220 shouldFail: true,
1221 expectedError: ":UNEXPECTED_MESSAGE:",
1222 },
1223 {
Adam Langley7c803a62015-06-15 15:35:05 -07001224 testType: serverTest,
1225 name: "Alert",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1233 },
1234 {
1235 protocol: dtls,
1236 testType: serverTest,
1237 name: "Alert-DTLS",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1245 },
1246 {
1247 testType: serverTest,
1248 name: "FragmentAlert",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 FragmentAlert: true,
1252 SendSpuriousAlert: alertRecordOverflow,
1253 },
1254 },
1255 shouldFail: true,
1256 expectedError: ":BAD_ALERT:",
1257 },
1258 {
1259 protocol: dtls,
1260 testType: serverTest,
1261 name: "FragmentAlert-DTLS",
1262 config: Config{
1263 Bugs: ProtocolBugs{
1264 FragmentAlert: true,
1265 SendSpuriousAlert: alertRecordOverflow,
1266 },
1267 },
1268 shouldFail: true,
1269 expectedError: ":BAD_ALERT:",
1270 },
1271 {
1272 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001273 name: "DoubleAlert",
1274 config: Config{
1275 Bugs: ProtocolBugs{
1276 DoubleAlert: true,
1277 SendSpuriousAlert: alertRecordOverflow,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":BAD_ALERT:",
1282 },
1283 {
1284 protocol: dtls,
1285 testType: serverTest,
1286 name: "DoubleAlert-DTLS",
1287 config: Config{
1288 Bugs: ProtocolBugs{
1289 DoubleAlert: true,
1290 SendSpuriousAlert: alertRecordOverflow,
1291 },
1292 },
1293 shouldFail: true,
1294 expectedError: ":BAD_ALERT:",
1295 },
1296 {
Adam Langley7c803a62015-06-15 15:35:05 -07001297 name: "SkipNewSessionTicket",
1298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001299 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001300 Bugs: ProtocolBugs{
1301 SkipNewSessionTicket: true,
1302 },
1303 },
1304 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001305 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001306 },
1307 {
1308 testType: serverTest,
1309 name: "FallbackSCSV",
1310 config: Config{
1311 MaxVersion: VersionTLS11,
1312 Bugs: ProtocolBugs{
1313 SendFallbackSCSV: true,
1314 },
1315 },
1316 shouldFail: true,
1317 expectedError: ":INAPPROPRIATE_FALLBACK:",
1318 },
1319 {
1320 testType: serverTest,
1321 name: "FallbackSCSV-VersionMatch",
1322 config: Config{
1323 Bugs: ProtocolBugs{
1324 SendFallbackSCSV: true,
1325 },
1326 },
1327 },
1328 {
1329 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001330 name: "FallbackSCSV-VersionMatch-TLS12",
1331 config: Config{
1332 MaxVersion: VersionTLS12,
1333 Bugs: ProtocolBugs{
1334 SendFallbackSCSV: true,
1335 },
1336 },
1337 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1338 },
1339 {
1340 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001341 name: "FragmentedClientVersion",
1342 config: Config{
1343 Bugs: ProtocolBugs{
1344 MaxHandshakeRecordLength: 1,
1345 FragmentClientVersion: true,
1346 },
1347 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001348 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
Adam Langley7c803a62015-06-15 15:35:05 -07001351 testType: serverTest,
1352 name: "HttpGET",
1353 sendPrefix: "GET / HTTP/1.0\n",
1354 shouldFail: true,
1355 expectedError: ":HTTP_REQUEST:",
1356 },
1357 {
1358 testType: serverTest,
1359 name: "HttpPOST",
1360 sendPrefix: "POST / HTTP/1.0\n",
1361 shouldFail: true,
1362 expectedError: ":HTTP_REQUEST:",
1363 },
1364 {
1365 testType: serverTest,
1366 name: "HttpHEAD",
1367 sendPrefix: "HEAD / HTTP/1.0\n",
1368 shouldFail: true,
1369 expectedError: ":HTTP_REQUEST:",
1370 },
1371 {
1372 testType: serverTest,
1373 name: "HttpPUT",
1374 sendPrefix: "PUT / HTTP/1.0\n",
1375 shouldFail: true,
1376 expectedError: ":HTTP_REQUEST:",
1377 },
1378 {
1379 testType: serverTest,
1380 name: "HttpCONNECT",
1381 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1382 shouldFail: true,
1383 expectedError: ":HTTPS_PROXY_REQUEST:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "Garbage",
1388 sendPrefix: "blah",
1389 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001390 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001391 },
1392 {
Adam Langley7c803a62015-06-15 15:35:05 -07001393 name: "RSAEphemeralKey",
1394 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001395 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001396 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1397 Bugs: ProtocolBugs{
1398 RSAEphemeralKey: true,
1399 },
1400 },
1401 shouldFail: true,
1402 expectedError: ":UNEXPECTED_MESSAGE:",
1403 },
1404 {
1405 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001406 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 shouldFail: true,
1408 expectedError: ":WRONG_SSL_VERSION:",
1409 },
1410 {
1411 protocol: dtls,
1412 name: "DisableEverything-DTLS",
1413 flags: []string{"-no-tls12", "-no-tls1"},
1414 shouldFail: true,
1415 expectedError: ":WRONG_SSL_VERSION:",
1416 },
1417 {
Adam Langley7c803a62015-06-15 15:35:05 -07001418 protocol: dtls,
1419 testType: serverTest,
1420 name: "MTU",
1421 config: Config{
1422 Bugs: ProtocolBugs{
1423 MaxPacketLength: 256,
1424 },
1425 },
1426 flags: []string{"-mtu", "256"},
1427 },
1428 {
1429 protocol: dtls,
1430 testType: serverTest,
1431 name: "MTUExceeded",
1432 config: Config{
1433 Bugs: ProtocolBugs{
1434 MaxPacketLength: 255,
1435 },
1436 },
1437 flags: []string{"-mtu", "256"},
1438 shouldFail: true,
1439 expectedLocalError: "dtls: exceeded maximum packet length",
1440 },
1441 {
1442 name: "CertMismatchRSA",
1443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001444 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001445 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001446 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001447 Bugs: ProtocolBugs{
1448 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1449 },
1450 },
1451 shouldFail: true,
1452 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1453 },
1454 {
1455 name: "CertMismatchECDSA",
1456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001457 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001458 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001459 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001460 Bugs: ProtocolBugs{
1461 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1462 },
1463 },
1464 shouldFail: true,
1465 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1466 },
1467 {
1468 name: "EmptyCertificateList",
1469 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001470 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001471 Bugs: ProtocolBugs{
1472 EmptyCertificateList: true,
1473 },
1474 },
1475 shouldFail: true,
1476 expectedError: ":DECODE_ERROR:",
1477 },
1478 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001479 name: "EmptyCertificateList-TLS13",
1480 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001481 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001482 Bugs: ProtocolBugs{
1483 EmptyCertificateList: true,
1484 },
1485 },
1486 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001487 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001488 },
1489 {
Adam Langley7c803a62015-06-15 15:35:05 -07001490 name: "TLSFatalBadPackets",
1491 damageFirstWrite: true,
1492 shouldFail: true,
1493 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets",
1498 damageFirstWrite: true,
1499 },
1500 {
1501 protocol: dtls,
1502 name: "DTLSIgnoreBadPackets-Async",
1503 damageFirstWrite: true,
1504 flags: []string{"-async"},
1505 },
1506 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001507 name: "AppDataBeforeHandshake",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":UNEXPECTED_RECORD:",
1515 },
1516 {
1517 name: "AppDataBeforeHandshake-Empty",
1518 config: Config{
1519 Bugs: ProtocolBugs{
1520 AppDataBeforeHandshake: []byte{},
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":UNEXPECTED_RECORD:",
1525 },
1526 {
1527 protocol: dtls,
1528 name: "AppDataBeforeHandshake-DTLS",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1532 },
1533 },
1534 shouldFail: true,
1535 expectedError: ":UNEXPECTED_RECORD:",
1536 },
1537 {
1538 protocol: dtls,
1539 name: "AppDataBeforeHandshake-DTLS-Empty",
1540 config: Config{
1541 Bugs: ProtocolBugs{
1542 AppDataBeforeHandshake: []byte{},
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":UNEXPECTED_RECORD:",
1547 },
1548 {
Adam Langley7c803a62015-06-15 15:35:05 -07001549 name: "AppDataAfterChangeCipherSpec",
1550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001551 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001552 Bugs: ProtocolBugs{
1553 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1554 },
1555 },
1556 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001557 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001558 },
1559 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001560 name: "AppDataAfterChangeCipherSpec-Empty",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte{},
1565 },
1566 },
1567 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001568 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001569 },
1570 {
Adam Langley7c803a62015-06-15 15:35:05 -07001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001583 protocol: dtls,
1584 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001586 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001587 Bugs: ProtocolBugs{
1588 AppDataAfterChangeCipherSpec: []byte{},
1589 },
1590 },
1591 // BoringSSL's DTLS implementation will drop the out-of-order
1592 // application data.
1593 },
1594 {
Adam Langley7c803a62015-06-15 15:35:05 -07001595 name: "AlertAfterChangeCipherSpec",
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: "AlertAfterChangeCipherSpec-DTLS",
1608 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001609 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001610 Bugs: ProtocolBugs{
1611 AlertAfterChangeCipherSpec: alertRecordOverflow,
1612 },
1613 },
1614 shouldFail: true,
1615 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Small-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Small enough that every handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "ReorderHandshakeFragments-Large-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 // Large enough that no handshake message is
1636 // fragmented.
1637 MaxHandshakeRecordLength: 2048,
1638 },
1639 },
1640 },
1641 {
1642 protocol: dtls,
1643 name: "MixCompleteMessageWithFragments-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 ReorderHandshakeFragments: true,
1647 MixCompleteMessageWithFragments: true,
1648 MaxHandshakeRecordLength: 2,
1649 },
1650 },
1651 },
1652 {
1653 name: "SendInvalidRecordType",
1654 config: Config{
1655 Bugs: ProtocolBugs{
1656 SendInvalidRecordType: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":UNEXPECTED_RECORD:",
1661 },
1662 {
1663 protocol: dtls,
1664 name: "SendInvalidRecordType-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 SendInvalidRecordType: true,
1668 },
1669 },
1670 shouldFail: true,
1671 expectedError: ":UNEXPECTED_RECORD:",
1672 },
1673 {
1674 name: "FalseStart-SkipServerSecondLeg",
1675 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001676 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001677 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1678 NextProtos: []string{"foo"},
1679 Bugs: ProtocolBugs{
1680 SkipNewSessionTicket: true,
1681 SkipChangeCipherSpec: true,
1682 SkipFinished: true,
1683 ExpectFalseStart: true,
1684 },
1685 },
1686 flags: []string{
1687 "-false-start",
1688 "-handshake-never-done",
1689 "-advertise-alpn", "\x03foo",
1690 },
1691 shimWritesFirst: true,
1692 shouldFail: true,
1693 expectedError: ":UNEXPECTED_RECORD:",
1694 },
1695 {
1696 name: "FalseStart-SkipServerSecondLeg-Implicit",
1697 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001698 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1700 NextProtos: []string{"foo"},
1701 Bugs: ProtocolBugs{
1702 SkipNewSessionTicket: true,
1703 SkipChangeCipherSpec: true,
1704 SkipFinished: true,
1705 },
1706 },
1707 flags: []string{
1708 "-implicit-handshake",
1709 "-false-start",
1710 "-handshake-never-done",
1711 "-advertise-alpn", "\x03foo",
1712 },
1713 shouldFail: true,
1714 expectedError: ":UNEXPECTED_RECORD:",
1715 },
1716 {
1717 testType: serverTest,
1718 name: "FailEarlyCallback",
1719 flags: []string{"-fail-early-callback"},
1720 shouldFail: true,
1721 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001722 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001723 },
1724 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001725 name: "FailCertCallback-Client-TLS12",
1726 config: Config{
1727 MaxVersion: VersionTLS12,
1728 ClientAuth: RequestClientCert,
1729 },
1730 flags: []string{"-fail-cert-callback"},
1731 shouldFail: true,
1732 expectedError: ":CERT_CB_ERROR:",
1733 expectedLocalError: "remote error: internal error",
1734 },
1735 {
1736 testType: serverTest,
1737 name: "FailCertCallback-Server-TLS12",
1738 config: Config{
1739 MaxVersion: VersionTLS12,
1740 },
1741 flags: []string{"-fail-cert-callback"},
1742 shouldFail: true,
1743 expectedError: ":CERT_CB_ERROR:",
1744 expectedLocalError: "remote error: internal error",
1745 },
1746 {
1747 name: "FailCertCallback-Client-TLS13",
1748 config: Config{
1749 MaxVersion: VersionTLS13,
1750 ClientAuth: RequestClientCert,
1751 },
1752 flags: []string{"-fail-cert-callback"},
1753 shouldFail: true,
1754 expectedError: ":CERT_CB_ERROR:",
1755 expectedLocalError: "remote error: internal error",
1756 },
1757 {
1758 testType: serverTest,
1759 name: "FailCertCallback-Server-TLS13",
1760 config: Config{
1761 MaxVersion: VersionTLS13,
1762 },
1763 flags: []string{"-fail-cert-callback"},
1764 shouldFail: true,
1765 expectedError: ":CERT_CB_ERROR:",
1766 expectedLocalError: "remote error: internal error",
1767 },
1768 {
Adam Langley7c803a62015-06-15 15:35:05 -07001769 protocol: dtls,
1770 name: "FragmentMessageTypeMismatch-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 MaxHandshakeRecordLength: 2,
1774 FragmentMessageTypeMismatch: true,
1775 },
1776 },
1777 shouldFail: true,
1778 expectedError: ":FRAGMENT_MISMATCH:",
1779 },
1780 {
1781 protocol: dtls,
1782 name: "FragmentMessageLengthMismatch-DTLS",
1783 config: Config{
1784 Bugs: ProtocolBugs{
1785 MaxHandshakeRecordLength: 2,
1786 FragmentMessageLengthMismatch: true,
1787 },
1788 },
1789 shouldFail: true,
1790 expectedError: ":FRAGMENT_MISMATCH:",
1791 },
1792 {
1793 protocol: dtls,
1794 name: "SplitFragments-Header-DTLS",
1795 config: Config{
1796 Bugs: ProtocolBugs{
1797 SplitFragments: 2,
1798 },
1799 },
1800 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001801 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001802 },
1803 {
1804 protocol: dtls,
1805 name: "SplitFragments-Boundary-DTLS",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 SplitFragments: dtlsRecordHeaderLen,
1809 },
1810 },
1811 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001812 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001813 },
1814 {
1815 protocol: dtls,
1816 name: "SplitFragments-Body-DTLS",
1817 config: Config{
1818 Bugs: ProtocolBugs{
1819 SplitFragments: dtlsRecordHeaderLen + 1,
1820 },
1821 },
1822 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001823 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001824 },
1825 {
1826 protocol: dtls,
1827 name: "SendEmptyFragments-DTLS",
1828 config: Config{
1829 Bugs: ProtocolBugs{
1830 SendEmptyFragments: true,
1831 },
1832 },
1833 },
1834 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001835 name: "BadFinished-Client",
1836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001837 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001838 Bugs: ProtocolBugs{
1839 BadFinished: true,
1840 },
1841 },
1842 shouldFail: true,
1843 expectedError: ":DIGEST_CHECK_FAILED:",
1844 },
1845 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001846 name: "BadFinished-Client-TLS13",
1847 config: Config{
1848 MaxVersion: VersionTLS13,
1849 Bugs: ProtocolBugs{
1850 BadFinished: true,
1851 },
1852 },
1853 shouldFail: true,
1854 expectedError: ":DIGEST_CHECK_FAILED:",
1855 },
1856 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001857 testType: serverTest,
1858 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001860 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001861 Bugs: ProtocolBugs{
1862 BadFinished: true,
1863 },
1864 },
1865 shouldFail: true,
1866 expectedError: ":DIGEST_CHECK_FAILED:",
1867 },
1868 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001869 testType: serverTest,
1870 name: "BadFinished-Server-TLS13",
1871 config: Config{
1872 MaxVersion: VersionTLS13,
1873 Bugs: ProtocolBugs{
1874 BadFinished: true,
1875 },
1876 },
1877 shouldFail: true,
1878 expectedError: ":DIGEST_CHECK_FAILED:",
1879 },
1880 {
Adam Langley7c803a62015-06-15 15:35:05 -07001881 name: "FalseStart-BadFinished",
1882 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001883 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001884 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1885 NextProtos: []string{"foo"},
1886 Bugs: ProtocolBugs{
1887 BadFinished: true,
1888 ExpectFalseStart: true,
1889 },
1890 },
1891 flags: []string{
1892 "-false-start",
1893 "-handshake-never-done",
1894 "-advertise-alpn", "\x03foo",
1895 },
1896 shimWritesFirst: true,
1897 shouldFail: true,
1898 expectedError: ":DIGEST_CHECK_FAILED:",
1899 },
1900 {
1901 name: "NoFalseStart-NoALPN",
1902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001903 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1905 Bugs: ProtocolBugs{
1906 ExpectFalseStart: true,
1907 AlertBeforeFalseStartTest: alertAccessDenied,
1908 },
1909 },
1910 flags: []string{
1911 "-false-start",
1912 },
1913 shimWritesFirst: true,
1914 shouldFail: true,
1915 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1916 expectedLocalError: "tls: peer did not false start: EOF",
1917 },
1918 {
1919 name: "NoFalseStart-NoAEAD",
1920 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001921 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1923 NextProtos: []string{"foo"},
1924 Bugs: ProtocolBugs{
1925 ExpectFalseStart: true,
1926 AlertBeforeFalseStartTest: alertAccessDenied,
1927 },
1928 },
1929 flags: []string{
1930 "-false-start",
1931 "-advertise-alpn", "\x03foo",
1932 },
1933 shimWritesFirst: true,
1934 shouldFail: true,
1935 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1936 expectedLocalError: "tls: peer did not false start: EOF",
1937 },
1938 {
1939 name: "NoFalseStart-RSA",
1940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001941 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001942 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1943 NextProtos: []string{"foo"},
1944 Bugs: ProtocolBugs{
1945 ExpectFalseStart: true,
1946 AlertBeforeFalseStartTest: alertAccessDenied,
1947 },
1948 },
1949 flags: []string{
1950 "-false-start",
1951 "-advertise-alpn", "\x03foo",
1952 },
1953 shimWritesFirst: true,
1954 shouldFail: true,
1955 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1956 expectedLocalError: "tls: peer did not false start: EOF",
1957 },
1958 {
1959 name: "NoFalseStart-DHE_RSA",
1960 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001961 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001962 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1963 NextProtos: []string{"foo"},
1964 Bugs: ProtocolBugs{
1965 ExpectFalseStart: true,
1966 AlertBeforeFalseStartTest: alertAccessDenied,
1967 },
1968 },
1969 flags: []string{
1970 "-false-start",
1971 "-advertise-alpn", "\x03foo",
1972 },
1973 shimWritesFirst: true,
1974 shouldFail: true,
1975 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1976 expectedLocalError: "tls: peer did not false start: EOF",
1977 },
1978 {
Adam Langley7c803a62015-06-15 15:35:05 -07001979 protocol: dtls,
1980 name: "SendSplitAlert-Sync",
1981 config: Config{
1982 Bugs: ProtocolBugs{
1983 SendSplitAlert: true,
1984 },
1985 },
1986 },
1987 {
1988 protocol: dtls,
1989 name: "SendSplitAlert-Async",
1990 config: Config{
1991 Bugs: ProtocolBugs{
1992 SendSplitAlert: true,
1993 },
1994 },
1995 flags: []string{"-async"},
1996 },
1997 {
1998 protocol: dtls,
1999 name: "PackDTLSHandshake",
2000 config: Config{
2001 Bugs: ProtocolBugs{
2002 MaxHandshakeRecordLength: 2,
2003 PackHandshakeFragments: 20,
2004 PackHandshakeRecords: 200,
2005 },
2006 },
2007 },
2008 {
Adam Langley7c803a62015-06-15 15:35:05 -07002009 name: "SendEmptyRecords-Pass",
2010 sendEmptyRecords: 32,
2011 },
2012 {
2013 name: "SendEmptyRecords",
2014 sendEmptyRecords: 33,
2015 shouldFail: true,
2016 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2017 },
2018 {
2019 name: "SendEmptyRecords-Async",
2020 sendEmptyRecords: 33,
2021 flags: []string{"-async"},
2022 shouldFail: true,
2023 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2024 },
2025 {
David Benjamine8e84b92016-08-03 15:39:47 -04002026 name: "SendWarningAlerts-Pass",
2027 config: Config{
2028 MaxVersion: VersionTLS12,
2029 },
Adam Langley7c803a62015-06-15 15:35:05 -07002030 sendWarningAlerts: 4,
2031 },
2032 {
David Benjamine8e84b92016-08-03 15:39:47 -04002033 protocol: dtls,
2034 name: "SendWarningAlerts-DTLS-Pass",
2035 config: Config{
2036 MaxVersion: VersionTLS12,
2037 },
Adam Langley7c803a62015-06-15 15:35:05 -07002038 sendWarningAlerts: 4,
2039 },
2040 {
David Benjamine8e84b92016-08-03 15:39:47 -04002041 name: "SendWarningAlerts-TLS13",
2042 config: Config{
2043 MaxVersion: VersionTLS13,
2044 },
2045 sendWarningAlerts: 4,
2046 shouldFail: true,
2047 expectedError: ":BAD_ALERT:",
2048 expectedLocalError: "remote error: error decoding message",
2049 },
2050 {
2051 name: "SendWarningAlerts",
2052 config: Config{
2053 MaxVersion: VersionTLS12,
2054 },
Adam Langley7c803a62015-06-15 15:35:05 -07002055 sendWarningAlerts: 5,
2056 shouldFail: true,
2057 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2058 },
2059 {
David Benjamine8e84b92016-08-03 15:39:47 -04002060 name: "SendWarningAlerts-Async",
2061 config: Config{
2062 MaxVersion: VersionTLS12,
2063 },
Adam Langley7c803a62015-06-15 15:35:05 -07002064 sendWarningAlerts: 5,
2065 flags: []string{"-async"},
2066 shouldFail: true,
2067 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2068 },
David Benjaminba4594a2015-06-18 18:36:15 -04002069 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002070 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002071 config: Config{
2072 MaxVersion: VersionTLS13,
2073 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002074 sendKeyUpdates: 33,
2075 keyUpdateRequest: keyUpdateNotRequested,
2076 shouldFail: true,
2077 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002078 },
2079 {
David Benjaminba4594a2015-06-18 18:36:15 -04002080 name: "EmptySessionID",
2081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002082 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002083 SessionTicketsDisabled: true,
2084 },
2085 noSessionCache: true,
2086 flags: []string{"-expect-no-session"},
2087 },
David Benjamin30789da2015-08-29 22:56:45 -04002088 {
2089 name: "Unclean-Shutdown",
2090 config: Config{
2091 Bugs: ProtocolBugs{
2092 NoCloseNotify: true,
2093 ExpectCloseNotify: true,
2094 },
2095 },
2096 shimShutsDown: true,
2097 flags: []string{"-check-close-notify"},
2098 shouldFail: true,
2099 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2100 },
2101 {
2102 name: "Unclean-Shutdown-Ignored",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 NoCloseNotify: true,
2106 },
2107 },
2108 shimShutsDown: true,
2109 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002110 {
David Benjaminfa214e42016-05-10 17:03:10 -04002111 name: "Unclean-Shutdown-Alert",
2112 config: Config{
2113 Bugs: ProtocolBugs{
2114 SendAlertOnShutdown: alertDecompressionFailure,
2115 ExpectCloseNotify: true,
2116 },
2117 },
2118 shimShutsDown: true,
2119 flags: []string{"-check-close-notify"},
2120 shouldFail: true,
2121 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2122 },
2123 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002124 name: "LargePlaintext",
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 protocol: dtls,
2136 name: "LargePlaintext-DTLS",
2137 config: Config{
2138 Bugs: ProtocolBugs{
2139 SendLargeRecords: true,
2140 },
2141 },
2142 messageLen: maxPlaintext + 1,
2143 shouldFail: true,
2144 expectedError: ":DATA_LENGTH_TOO_LONG:",
2145 },
2146 {
2147 name: "LargeCiphertext",
2148 config: Config{
2149 Bugs: ProtocolBugs{
2150 SendLargeRecords: true,
2151 },
2152 },
2153 messageLen: maxPlaintext * 2,
2154 shouldFail: true,
2155 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2156 },
2157 {
2158 protocol: dtls,
2159 name: "LargeCiphertext-DTLS",
2160 config: Config{
2161 Bugs: ProtocolBugs{
2162 SendLargeRecords: true,
2163 },
2164 },
2165 messageLen: maxPlaintext * 2,
2166 // Unlike the other four cases, DTLS drops records which
2167 // are invalid before authentication, so the connection
2168 // does not fail.
2169 expectMessageDropped: true,
2170 },
David Benjamindd6fed92015-10-23 17:41:12 -04002171 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002172 name: "BadHelloRequest-1",
2173 renegotiate: 1,
2174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002175 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002176 Bugs: ProtocolBugs{
2177 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2178 },
2179 },
2180 flags: []string{
2181 "-renegotiate-freely",
2182 "-expect-total-renegotiations", "1",
2183 },
2184 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002185 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002186 },
2187 {
2188 name: "BadHelloRequest-2",
2189 renegotiate: 1,
2190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002191 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002192 Bugs: ProtocolBugs{
2193 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2194 },
2195 },
2196 flags: []string{
2197 "-renegotiate-freely",
2198 "-expect-total-renegotiations", "1",
2199 },
2200 shouldFail: true,
2201 expectedError: ":BAD_HELLO_REQUEST:",
2202 },
David Benjaminef1b0092015-11-21 14:05:44 -05002203 {
2204 testType: serverTest,
2205 name: "SupportTicketsWithSessionID",
2206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002207 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002208 SessionTicketsDisabled: true,
2209 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002210 resumeConfig: &Config{
2211 MaxVersion: VersionTLS12,
2212 },
David Benjaminef1b0092015-11-21 14:05:44 -05002213 resumeSession: true,
2214 },
David Benjamin02edcd02016-07-27 17:40:37 -04002215 {
2216 protocol: dtls,
2217 name: "DTLS-SendExtraFinished",
2218 config: Config{
2219 Bugs: ProtocolBugs{
2220 SendExtraFinished: true,
2221 },
2222 },
2223 shouldFail: true,
2224 expectedError: ":UNEXPECTED_RECORD:",
2225 },
2226 {
2227 protocol: dtls,
2228 name: "DTLS-SendExtraFinished-Reordered",
2229 config: Config{
2230 Bugs: ProtocolBugs{
2231 MaxHandshakeRecordLength: 2,
2232 ReorderHandshakeFragments: true,
2233 SendExtraFinished: true,
2234 },
2235 },
2236 shouldFail: true,
2237 expectedError: ":UNEXPECTED_RECORD:",
2238 },
David Benjamine97fb482016-07-29 09:23:07 -04002239 {
2240 testType: serverTest,
2241 name: "V2ClientHello-EmptyRecordPrefix",
2242 config: Config{
2243 // Choose a cipher suite that does not involve
2244 // elliptic curves, so no extensions are
2245 // involved.
2246 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002247 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002248 Bugs: ProtocolBugs{
2249 SendV2ClientHello: true,
2250 },
2251 },
2252 sendPrefix: string([]byte{
2253 byte(recordTypeHandshake),
2254 3, 1, // version
2255 0, 0, // length
2256 }),
2257 // A no-op empty record may not be sent before V2ClientHello.
2258 shouldFail: true,
2259 expectedError: ":WRONG_VERSION_NUMBER:",
2260 },
2261 {
2262 testType: serverTest,
2263 name: "V2ClientHello-WarningAlertPrefix",
2264 config: Config{
2265 // Choose a cipher suite that does not involve
2266 // elliptic curves, so no extensions are
2267 // involved.
2268 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002269 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002270 Bugs: ProtocolBugs{
2271 SendV2ClientHello: true,
2272 },
2273 },
2274 sendPrefix: string([]byte{
2275 byte(recordTypeAlert),
2276 3, 1, // version
2277 0, 2, // length
2278 alertLevelWarning, byte(alertDecompressionFailure),
2279 }),
2280 // A no-op warning alert may not be sent before V2ClientHello.
2281 shouldFail: true,
2282 expectedError: ":WRONG_VERSION_NUMBER:",
2283 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002284 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002285 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002286 config: Config{
2287 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002288 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002289 sendKeyUpdates: 1,
2290 keyUpdateRequest: keyUpdateNotRequested,
2291 },
2292 {
2293 name: "KeyUpdate-InvalidRequestMode",
2294 config: Config{
2295 MaxVersion: VersionTLS13,
2296 },
2297 sendKeyUpdates: 1,
2298 keyUpdateRequest: 42,
2299 shouldFail: true,
2300 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002301 },
David Benjaminabe94e32016-09-04 14:18:58 -04002302 {
2303 name: "SendSNIWarningAlert",
2304 config: Config{
2305 MaxVersion: VersionTLS12,
2306 Bugs: ProtocolBugs{
2307 SendSNIWarningAlert: true,
2308 },
2309 },
2310 },
David Benjaminc241d792016-09-09 10:34:20 -04002311 {
2312 testType: serverTest,
2313 name: "ExtraCompressionMethods-TLS12",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2318 },
2319 },
2320 },
2321 {
2322 testType: serverTest,
2323 name: "ExtraCompressionMethods-TLS13",
2324 config: Config{
2325 MaxVersion: VersionTLS13,
2326 Bugs: ProtocolBugs{
2327 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2328 },
2329 },
2330 shouldFail: true,
2331 expectedError: ":INVALID_COMPRESSION_LIST:",
2332 expectedLocalError: "remote error: illegal parameter",
2333 },
2334 {
2335 testType: serverTest,
2336 name: "NoNullCompression-TLS12",
2337 config: Config{
2338 MaxVersion: VersionTLS12,
2339 Bugs: ProtocolBugs{
2340 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2341 },
2342 },
2343 shouldFail: true,
2344 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2345 expectedLocalError: "remote error: illegal parameter",
2346 },
2347 {
2348 testType: serverTest,
2349 name: "NoNullCompression-TLS13",
2350 config: Config{
2351 MaxVersion: VersionTLS13,
2352 Bugs: ProtocolBugs{
2353 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2354 },
2355 },
2356 shouldFail: true,
2357 expectedError: ":INVALID_COMPRESSION_LIST:",
2358 expectedLocalError: "remote error: illegal parameter",
2359 },
David Benjamin65ac9972016-09-02 21:35:25 -04002360 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002361 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002362 config: Config{
2363 MaxVersion: VersionTLS12,
2364 Bugs: ProtocolBugs{
2365 ExpectGREASE: true,
2366 },
2367 },
2368 flags: []string{"-enable-grease"},
2369 },
2370 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002371 name: "GREASE-Client-TLS13",
2372 config: Config{
2373 MaxVersion: VersionTLS13,
2374 Bugs: ProtocolBugs{
2375 ExpectGREASE: true,
2376 },
2377 },
2378 flags: []string{"-enable-grease"},
2379 },
2380 {
2381 testType: serverTest,
2382 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002383 config: Config{
2384 MaxVersion: VersionTLS13,
2385 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002386 // TLS 1.3 servers are expected to
2387 // always enable GREASE. TLS 1.3 is new,
2388 // so there is no existing ecosystem to
2389 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002390 ExpectGREASE: true,
2391 },
2392 },
David Benjamin65ac9972016-09-02 21:35:25 -04002393 },
Adam Langley7c803a62015-06-15 15:35:05 -07002394 }
Adam Langley7c803a62015-06-15 15:35:05 -07002395 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002396
2397 // Test that very large messages can be received.
2398 cert := rsaCertificate
2399 for i := 0; i < 50; i++ {
2400 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2401 }
2402 testCases = append(testCases, testCase{
2403 name: "LargeMessage",
2404 config: Config{
2405 Certificates: []Certificate{cert},
2406 },
2407 })
2408 testCases = append(testCases, testCase{
2409 protocol: dtls,
2410 name: "LargeMessage-DTLS",
2411 config: Config{
2412 Certificates: []Certificate{cert},
2413 },
2414 })
2415
2416 // They are rejected if the maximum certificate chain length is capped.
2417 testCases = append(testCases, testCase{
2418 name: "LargeMessage-Reject",
2419 config: Config{
2420 Certificates: []Certificate{cert},
2421 },
2422 flags: []string{"-max-cert-list", "16384"},
2423 shouldFail: true,
2424 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2425 })
2426 testCases = append(testCases, testCase{
2427 protocol: dtls,
2428 name: "LargeMessage-Reject-DTLS",
2429 config: Config{
2430 Certificates: []Certificate{cert},
2431 },
2432 flags: []string{"-max-cert-list", "16384"},
2433 shouldFail: true,
2434 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2435 })
Adam Langley7c803a62015-06-15 15:35:05 -07002436}
2437
David Benjaminaa012042016-12-10 13:33:05 -05002438func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2439 const psk = "12345"
2440 const pskIdentity = "luggage combo"
2441
2442 var prefix string
2443 if protocol == dtls {
2444 if !ver.hasDTLS {
2445 return
2446 }
2447 prefix = "D"
2448 }
2449
2450 var cert Certificate
2451 var certFile string
2452 var keyFile string
2453 if hasComponent(suite.name, "ECDSA") {
2454 cert = ecdsaP256Certificate
2455 certFile = ecdsaP256CertificateFile
2456 keyFile = ecdsaP256KeyFile
2457 } else {
2458 cert = rsaCertificate
2459 certFile = rsaCertificateFile
2460 keyFile = rsaKeyFile
2461 }
2462
2463 var flags []string
2464 if hasComponent(suite.name, "PSK") {
2465 flags = append(flags,
2466 "-psk", psk,
2467 "-psk-identity", pskIdentity)
2468 }
2469 if hasComponent(suite.name, "NULL") {
2470 // NULL ciphers must be explicitly enabled.
2471 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2472 }
2473 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2474 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2475 // for now.
2476 flags = append(flags, "-cipher", suite.name)
2477 }
2478
2479 var shouldServerFail, shouldClientFail bool
2480 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2481 // BoringSSL clients accept ECDHE on SSLv3, but
2482 // a BoringSSL server will never select it
2483 // because the extension is missing.
2484 shouldServerFail = true
2485 }
2486 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2487 shouldClientFail = true
2488 shouldServerFail = true
2489 }
2490 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2491 shouldClientFail = true
2492 shouldServerFail = true
2493 }
2494 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2495 shouldClientFail = true
2496 shouldServerFail = true
2497 }
2498 if !isDTLSCipher(suite.name) && protocol == dtls {
2499 shouldClientFail = true
2500 shouldServerFail = true
2501 }
2502
2503 var sendCipherSuite uint16
2504 var expectedServerError, expectedClientError string
2505 serverCipherSuites := []uint16{suite.id}
2506 if shouldServerFail {
2507 expectedServerError = ":NO_SHARED_CIPHER:"
2508 }
2509 if shouldClientFail {
2510 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2511 // Configure the server to select ciphers as normal but
2512 // select an incompatible cipher in ServerHello.
2513 serverCipherSuites = nil
2514 sendCipherSuite = suite.id
2515 }
2516
2517 testCases = append(testCases, testCase{
2518 testType: serverTest,
2519 protocol: protocol,
2520 name: prefix + ver.name + "-" + suite.name + "-server",
2521 config: Config{
2522 MinVersion: ver.version,
2523 MaxVersion: ver.version,
2524 CipherSuites: []uint16{suite.id},
2525 Certificates: []Certificate{cert},
2526 PreSharedKey: []byte(psk),
2527 PreSharedKeyIdentity: pskIdentity,
2528 Bugs: ProtocolBugs{
2529 AdvertiseAllConfiguredCiphers: true,
2530 },
2531 },
2532 certFile: certFile,
2533 keyFile: keyFile,
2534 flags: flags,
2535 resumeSession: true,
2536 shouldFail: shouldServerFail,
2537 expectedError: expectedServerError,
2538 })
2539
2540 testCases = append(testCases, testCase{
2541 testType: clientTest,
2542 protocol: protocol,
2543 name: prefix + ver.name + "-" + suite.name + "-client",
2544 config: Config{
2545 MinVersion: ver.version,
2546 MaxVersion: ver.version,
2547 CipherSuites: serverCipherSuites,
2548 Certificates: []Certificate{cert},
2549 PreSharedKey: []byte(psk),
2550 PreSharedKeyIdentity: pskIdentity,
2551 Bugs: ProtocolBugs{
2552 IgnorePeerCipherPreferences: shouldClientFail,
2553 SendCipherSuite: sendCipherSuite,
2554 },
2555 },
2556 flags: flags,
2557 resumeSession: true,
2558 shouldFail: shouldClientFail,
2559 expectedError: expectedClientError,
2560 })
2561
2562 if !shouldClientFail {
2563 // Ensure the maximum record size is accepted.
2564 testCases = append(testCases, testCase{
2565 protocol: protocol,
2566 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2567 config: Config{
2568 MinVersion: ver.version,
2569 MaxVersion: ver.version,
2570 CipherSuites: []uint16{suite.id},
2571 Certificates: []Certificate{cert},
2572 PreSharedKey: []byte(psk),
2573 PreSharedKeyIdentity: pskIdentity,
2574 },
2575 flags: flags,
2576 messageLen: maxPlaintext,
2577 })
2578
2579 // Test bad records for all ciphers. Bad records are fatal in TLS
2580 // and ignored in DTLS.
2581 var shouldFail bool
2582 var expectedError string
2583 if protocol == tls {
2584 shouldFail = true
2585 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2586 }
2587
2588 testCases = append(testCases, testCase{
2589 protocol: protocol,
2590 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2591 config: Config{
2592 MinVersion: ver.version,
2593 MaxVersion: ver.version,
2594 CipherSuites: []uint16{suite.id},
2595 Certificates: []Certificate{cert},
2596 PreSharedKey: []byte(psk),
2597 PreSharedKeyIdentity: pskIdentity,
2598 },
2599 flags: flags,
2600 damageFirstWrite: true,
2601 messageLen: maxPlaintext,
2602 shouldFail: shouldFail,
2603 expectedError: expectedError,
2604 })
2605 }
2606}
2607
Adam Langley95c29f32014-06-20 12:00:00 -07002608func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002609 const bogusCipher = 0xfe00
2610
Adam Langley95c29f32014-06-20 12:00:00 -07002611 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002612 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002613 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002614 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002615 }
David Benjamin2c99d282015-09-01 10:23:00 -04002616 }
Adam Langley95c29f32014-06-20 12:00:00 -07002617 }
Adam Langleya7997f12015-05-14 17:38:50 -07002618
2619 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002620 name: "NoSharedCipher",
2621 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002622 MaxVersion: VersionTLS12,
2623 CipherSuites: []uint16{},
2624 },
2625 shouldFail: true,
2626 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2627 })
2628
2629 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002630 name: "NoSharedCipher-TLS13",
2631 config: Config{
2632 MaxVersion: VersionTLS13,
2633 CipherSuites: []uint16{},
2634 },
2635 shouldFail: true,
2636 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2637 })
2638
2639 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002640 name: "UnsupportedCipherSuite",
2641 config: Config{
2642 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002643 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002644 Bugs: ProtocolBugs{
2645 IgnorePeerCipherPreferences: true,
2646 },
2647 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002648 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002649 shouldFail: true,
2650 expectedError: ":WRONG_CIPHER_RETURNED:",
2651 })
2652
2653 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002654 name: "ServerHelloBogusCipher",
2655 config: Config{
2656 MaxVersion: VersionTLS12,
2657 Bugs: ProtocolBugs{
2658 SendCipherSuite: bogusCipher,
2659 },
2660 },
2661 shouldFail: true,
2662 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2663 })
2664 testCases = append(testCases, testCase{
2665 name: "ServerHelloBogusCipher-TLS13",
2666 config: Config{
2667 MaxVersion: VersionTLS13,
2668 Bugs: ProtocolBugs{
2669 SendCipherSuite: bogusCipher,
2670 },
2671 },
2672 shouldFail: true,
2673 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2674 })
2675
2676 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002677 name: "WeakDH",
2678 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002679 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002680 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2681 Bugs: ProtocolBugs{
2682 // This is a 1023-bit prime number, generated
2683 // with:
2684 // openssl gendh 1023 | openssl asn1parse -i
2685 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2686 },
2687 },
2688 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002689 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002690 })
Adam Langleycef75832015-09-03 14:51:12 -07002691
David Benjamincd24a392015-11-11 13:23:05 -08002692 testCases = append(testCases, testCase{
2693 name: "SillyDH",
2694 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002695 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002696 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2697 Bugs: ProtocolBugs{
2698 // This is a 4097-bit prime number, generated
2699 // with:
2700 // openssl gendh 4097 | openssl asn1parse -i
2701 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2702 },
2703 },
2704 shouldFail: true,
2705 expectedError: ":DH_P_TOO_LONG:",
2706 })
2707
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002708 // This test ensures that Diffie-Hellman public values are padded with
2709 // zeros so that they're the same length as the prime. This is to avoid
2710 // hitting a bug in yaSSL.
2711 testCases = append(testCases, testCase{
2712 testType: serverTest,
2713 name: "DHPublicValuePadded",
2714 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002715 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002716 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2717 Bugs: ProtocolBugs{
2718 RequireDHPublicValueLen: (1025 + 7) / 8,
2719 },
2720 },
2721 flags: []string{"-use-sparse-dh-prime"},
2722 })
David Benjamincd24a392015-11-11 13:23:05 -08002723
David Benjamin241ae832016-01-15 03:04:54 -05002724 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002725 testCases = append(testCases, testCase{
2726 testType: serverTest,
2727 name: "UnknownCipher",
2728 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002729 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002730 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002731 Bugs: ProtocolBugs{
2732 AdvertiseAllConfiguredCiphers: true,
2733 },
2734 },
2735 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002736
2737 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002738 testCases = append(testCases, testCase{
2739 testType: serverTest,
2740 name: "UnknownCipher-TLS13",
2741 config: Config{
2742 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002743 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002744 Bugs: ProtocolBugs{
2745 AdvertiseAllConfiguredCiphers: true,
2746 },
David Benjamin241ae832016-01-15 03:04:54 -05002747 },
2748 })
2749
David Benjamin78679342016-09-16 19:42:05 -04002750 // Test empty ECDHE_PSK identity hints work as expected.
2751 testCases = append(testCases, testCase{
2752 name: "EmptyECDHEPSKHint",
2753 config: Config{
2754 MaxVersion: VersionTLS12,
2755 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2756 PreSharedKey: []byte("secret"),
2757 },
2758 flags: []string{"-psk", "secret"},
2759 })
2760
2761 // Test empty PSK identity hints work as expected, even if an explicit
2762 // ServerKeyExchange is sent.
2763 testCases = append(testCases, testCase{
2764 name: "ExplicitEmptyPSKHint",
2765 config: Config{
2766 MaxVersion: VersionTLS12,
2767 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2768 PreSharedKey: []byte("secret"),
2769 Bugs: ProtocolBugs{
2770 AlwaysSendPreSharedKeyIdentityHint: true,
2771 },
2772 },
2773 flags: []string{"-psk", "secret"},
2774 })
2775
Adam Langleycef75832015-09-03 14:51:12 -07002776 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2777 // 1.1 specific cipher suite settings. A server is setup with the given
2778 // cipher lists and then a connection is made for each member of
2779 // expectations. The cipher suite that the server selects must match
2780 // the specified one.
2781 var versionSpecificCiphersTest = []struct {
2782 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2783 // expectations is a map from TLS version to cipher suite id.
2784 expectations map[uint16]uint16
2785 }{
2786 {
2787 // Test that the null case (where no version-specific ciphers are set)
2788 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002789 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2790 "", // no ciphers specifically for TLS ≥ 1.0
2791 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002792 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002793 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2794 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2795 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2796 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002797 },
2798 },
2799 {
2800 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2801 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002802 "DES-CBC3-SHA:AES128-SHA", // default
2803 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2804 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002805 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002806 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002807 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2808 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2809 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2810 },
2811 },
2812 {
2813 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2814 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002815 "DES-CBC3-SHA:AES128-SHA", // default
2816 "", // no ciphers specifically for TLS ≥ 1.0
2817 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002818 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002819 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2820 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002821 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2822 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2823 },
2824 },
2825 {
2826 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2827 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002828 "DES-CBC3-SHA:AES128-SHA", // default
2829 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2830 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002831 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002832 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002833 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2834 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2835 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2836 },
2837 },
2838 }
2839
2840 for i, test := range versionSpecificCiphersTest {
2841 for version, expectedCipherSuite := range test.expectations {
2842 flags := []string{"-cipher", test.ciphersDefault}
2843 if len(test.ciphersTLS10) > 0 {
2844 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2845 }
2846 if len(test.ciphersTLS11) > 0 {
2847 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2848 }
2849
2850 testCases = append(testCases, testCase{
2851 testType: serverTest,
2852 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2853 config: Config{
2854 MaxVersion: version,
2855 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002856 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 -07002857 },
2858 flags: flags,
2859 expectedCipher: expectedCipherSuite,
2860 })
2861 }
2862 }
Adam Langley95c29f32014-06-20 12:00:00 -07002863}
2864
2865func addBadECDSASignatureTests() {
2866 for badR := BadValue(1); badR < NumBadValues; badR++ {
2867 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002868 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002869 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2870 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002871 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002872 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002873 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002874 Bugs: ProtocolBugs{
2875 BadECDSAR: badR,
2876 BadECDSAS: badS,
2877 },
2878 },
2879 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002880 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002881 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002882 testCases = append(testCases, testCase{
2883 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2884 config: Config{
2885 MaxVersion: VersionTLS13,
2886 Certificates: []Certificate{ecdsaP256Certificate},
2887 Bugs: ProtocolBugs{
2888 BadECDSAR: badR,
2889 BadECDSAS: badS,
2890 },
2891 },
2892 shouldFail: true,
2893 expectedError: ":BAD_SIGNATURE:",
2894 })
Adam Langley95c29f32014-06-20 12:00:00 -07002895 }
2896 }
2897}
2898
Adam Langley80842bd2014-06-20 12:00:00 -07002899func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002900 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002901 name: "MaxCBCPadding",
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 MaxPadding: true,
2907 },
2908 },
2909 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2910 })
David Benjamin025b3d32014-07-01 19:53:04 -04002911 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002912 name: "BadCBCPadding",
2913 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002914 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2916 Bugs: ProtocolBugs{
2917 PaddingFirstByteBad: true,
2918 },
2919 },
2920 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002921 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002922 })
2923 // OpenSSL previously had an issue where the first byte of padding in
2924 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002925 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002926 name: "BadCBCPadding255",
2927 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002928 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002929 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2930 Bugs: ProtocolBugs{
2931 MaxPadding: true,
2932 PaddingFirstByteBadIf255: true,
2933 },
2934 },
2935 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2936 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002937 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002938 })
2939}
2940
Kenny Root7fdeaf12014-08-05 15:23:37 -07002941func addCBCSplittingTests() {
2942 testCases = append(testCases, testCase{
2943 name: "CBCRecordSplitting",
2944 config: Config{
2945 MaxVersion: VersionTLS10,
2946 MinVersion: VersionTLS10,
2947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2948 },
David Benjaminac8302a2015-09-01 17:18:15 -04002949 messageLen: -1, // read until EOF
2950 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002951 flags: []string{
2952 "-async",
2953 "-write-different-record-sizes",
2954 "-cbc-record-splitting",
2955 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002956 })
2957 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002958 name: "CBCRecordSplittingPartialWrite",
2959 config: Config{
2960 MaxVersion: VersionTLS10,
2961 MinVersion: VersionTLS10,
2962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2963 },
2964 messageLen: -1, // read until EOF
2965 flags: []string{
2966 "-async",
2967 "-write-different-record-sizes",
2968 "-cbc-record-splitting",
2969 "-partial-write",
2970 },
2971 })
2972}
2973
David Benjamin636293b2014-07-08 17:59:18 -04002974func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002975 // Add a dummy cert pool to stress certificate authority parsing.
2976 // TODO(davidben): Add tests that those values parse out correctly.
2977 certPool := x509.NewCertPool()
2978 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2979 if err != nil {
2980 panic(err)
2981 }
2982 certPool.AddCert(cert)
2983
David Benjamin636293b2014-07-08 17:59:18 -04002984 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002985 testCases = append(testCases, testCase{
2986 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002987 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002988 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002989 MinVersion: ver.version,
2990 MaxVersion: ver.version,
2991 ClientAuth: RequireAnyClientCert,
2992 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002993 },
2994 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002995 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2996 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002997 },
2998 })
2999 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003000 testType: serverTest,
3001 name: ver.name + "-Server-ClientAuth-RSA",
3002 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003003 MinVersion: ver.version,
3004 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003005 Certificates: []Certificate{rsaCertificate},
3006 },
3007 flags: []string{"-require-any-client-certificate"},
3008 })
David Benjamine098ec22014-08-27 23:13:20 -04003009 if ver.version != VersionSSL30 {
3010 testCases = append(testCases, testCase{
3011 testType: serverTest,
3012 name: ver.name + "-Server-ClientAuth-ECDSA",
3013 config: Config{
3014 MinVersion: ver.version,
3015 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003016 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003017 },
3018 flags: []string{"-require-any-client-certificate"},
3019 })
3020 testCases = append(testCases, testCase{
3021 testType: clientTest,
3022 name: ver.name + "-Client-ClientAuth-ECDSA",
3023 config: Config{
3024 MinVersion: ver.version,
3025 MaxVersion: ver.version,
3026 ClientAuth: RequireAnyClientCert,
3027 ClientCAs: certPool,
3028 },
3029 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003030 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3031 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003032 },
3033 })
3034 }
Adam Langley37646832016-08-01 16:16:46 -07003035
3036 testCases = append(testCases, testCase{
3037 name: "NoClientCertificate-" + ver.name,
3038 config: Config{
3039 MinVersion: ver.version,
3040 MaxVersion: ver.version,
3041 ClientAuth: RequireAnyClientCert,
3042 },
3043 shouldFail: true,
3044 expectedLocalError: "client didn't provide a certificate",
3045 })
3046
3047 testCases = append(testCases, testCase{
3048 // Even if not configured to expect a certificate, OpenSSL will
3049 // return X509_V_OK as the verify_result.
3050 testType: serverTest,
3051 name: "NoClientCertificateRequested-Server-" + ver.name,
3052 config: Config{
3053 MinVersion: ver.version,
3054 MaxVersion: ver.version,
3055 },
3056 flags: []string{
3057 "-expect-verify-result",
3058 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003059 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003060 })
3061
3062 testCases = append(testCases, testCase{
3063 // If a client certificate is not provided, OpenSSL will still
3064 // return X509_V_OK as the verify_result.
3065 testType: serverTest,
3066 name: "NoClientCertificate-Server-" + ver.name,
3067 config: Config{
3068 MinVersion: ver.version,
3069 MaxVersion: ver.version,
3070 },
3071 flags: []string{
3072 "-expect-verify-result",
3073 "-verify-peer",
3074 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003075 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003076 })
3077
David Benjamin1db9e1b2016-10-07 20:51:43 -04003078 certificateRequired := "remote error: certificate required"
3079 if ver.version < VersionTLS13 {
3080 // Prior to TLS 1.3, the generic handshake_failure alert
3081 // was used.
3082 certificateRequired = "remote error: handshake failure"
3083 }
Adam Langley37646832016-08-01 16:16:46 -07003084 testCases = append(testCases, testCase{
3085 testType: serverTest,
3086 name: "RequireAnyClientCertificate-" + ver.name,
3087 config: Config{
3088 MinVersion: ver.version,
3089 MaxVersion: ver.version,
3090 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003091 flags: []string{"-require-any-client-certificate"},
3092 shouldFail: true,
3093 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3094 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003095 })
3096
3097 if ver.version != VersionSSL30 {
3098 testCases = append(testCases, testCase{
3099 testType: serverTest,
3100 name: "SkipClientCertificate-" + ver.name,
3101 config: Config{
3102 MinVersion: ver.version,
3103 MaxVersion: ver.version,
3104 Bugs: ProtocolBugs{
3105 SkipClientCertificate: true,
3106 },
3107 },
3108 // Setting SSL_VERIFY_PEER allows anonymous clients.
3109 flags: []string{"-verify-peer"},
3110 shouldFail: true,
3111 expectedError: ":UNEXPECTED_MESSAGE:",
3112 })
3113 }
David Benjamin636293b2014-07-08 17:59:18 -04003114 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003115
David Benjaminc032dfa2016-05-12 14:54:57 -04003116 // Client auth is only legal in certificate-based ciphers.
3117 testCases = append(testCases, testCase{
3118 testType: clientTest,
3119 name: "ClientAuth-PSK",
3120 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003121 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003122 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3123 PreSharedKey: []byte("secret"),
3124 ClientAuth: RequireAnyClientCert,
3125 },
3126 flags: []string{
3127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3129 "-psk", "secret",
3130 },
3131 shouldFail: true,
3132 expectedError: ":UNEXPECTED_MESSAGE:",
3133 })
3134 testCases = append(testCases, testCase{
3135 testType: clientTest,
3136 name: "ClientAuth-ECDHE_PSK",
3137 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003138 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003139 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3140 PreSharedKey: []byte("secret"),
3141 ClientAuth: RequireAnyClientCert,
3142 },
3143 flags: []string{
3144 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3145 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3146 "-psk", "secret",
3147 },
3148 shouldFail: true,
3149 expectedError: ":UNEXPECTED_MESSAGE:",
3150 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003151
3152 // Regression test for a bug where the client CA list, if explicitly
3153 // set to NULL, was mis-encoded.
3154 testCases = append(testCases, testCase{
3155 testType: serverTest,
3156 name: "Null-Client-CA-List",
3157 config: Config{
3158 MaxVersion: VersionTLS12,
3159 Certificates: []Certificate{rsaCertificate},
3160 },
3161 flags: []string{
3162 "-require-any-client-certificate",
3163 "-use-null-client-ca-list",
3164 },
3165 })
David Benjamin636293b2014-07-08 17:59:18 -04003166}
3167
Adam Langley75712922014-10-10 16:23:43 -07003168func addExtendedMasterSecretTests() {
3169 const expectEMSFlag = "-expect-extended-master-secret"
3170
3171 for _, with := range []bool{false, true} {
3172 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003173 if with {
3174 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003175 }
3176
3177 for _, isClient := range []bool{false, true} {
3178 suffix := "-Server"
3179 testType := serverTest
3180 if isClient {
3181 suffix = "-Client"
3182 testType = clientTest
3183 }
3184
3185 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003186 // In TLS 1.3, the extension is irrelevant and
3187 // always reports as enabled.
3188 var flags []string
3189 if with || ver.version >= VersionTLS13 {
3190 flags = []string{expectEMSFlag}
3191 }
3192
Adam Langley75712922014-10-10 16:23:43 -07003193 test := testCase{
3194 testType: testType,
3195 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3196 config: Config{
3197 MinVersion: ver.version,
3198 MaxVersion: ver.version,
3199 Bugs: ProtocolBugs{
3200 NoExtendedMasterSecret: !with,
3201 RequireExtendedMasterSecret: with,
3202 },
3203 },
David Benjamin48cae082014-10-27 01:06:24 -04003204 flags: flags,
3205 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003206 }
3207 if test.shouldFail {
3208 test.expectedLocalError = "extended master secret required but not supported by peer"
3209 }
3210 testCases = append(testCases, test)
3211 }
3212 }
3213 }
3214
Adam Langleyba5934b2015-06-02 10:50:35 -07003215 for _, isClient := range []bool{false, true} {
3216 for _, supportedInFirstConnection := range []bool{false, true} {
3217 for _, supportedInResumeConnection := range []bool{false, true} {
3218 boolToWord := func(b bool) string {
3219 if b {
3220 return "Yes"
3221 }
3222 return "No"
3223 }
3224 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3225 if isClient {
3226 suffix += "Client"
3227 } else {
3228 suffix += "Server"
3229 }
3230
3231 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003232 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003233 Bugs: ProtocolBugs{
3234 RequireExtendedMasterSecret: true,
3235 },
3236 }
3237
3238 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003239 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003240 Bugs: ProtocolBugs{
3241 NoExtendedMasterSecret: true,
3242 },
3243 }
3244
3245 test := testCase{
3246 name: "ExtendedMasterSecret-" + suffix,
3247 resumeSession: true,
3248 }
3249
3250 if !isClient {
3251 test.testType = serverTest
3252 }
3253
3254 if supportedInFirstConnection {
3255 test.config = supportedConfig
3256 } else {
3257 test.config = noSupportConfig
3258 }
3259
3260 if supportedInResumeConnection {
3261 test.resumeConfig = &supportedConfig
3262 } else {
3263 test.resumeConfig = &noSupportConfig
3264 }
3265
3266 switch suffix {
3267 case "YesToYes-Client", "YesToYes-Server":
3268 // When a session is resumed, it should
3269 // still be aware that its master
3270 // secret was generated via EMS and
3271 // thus it's safe to use tls-unique.
3272 test.flags = []string{expectEMSFlag}
3273 case "NoToYes-Server":
3274 // If an original connection did not
3275 // contain EMS, but a resumption
3276 // handshake does, then a server should
3277 // not resume the session.
3278 test.expectResumeRejected = true
3279 case "YesToNo-Server":
3280 // Resuming an EMS session without the
3281 // EMS extension should cause the
3282 // server to abort the connection.
3283 test.shouldFail = true
3284 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3285 case "NoToYes-Client":
3286 // A client should abort a connection
3287 // where the server resumed a non-EMS
3288 // session but echoed the EMS
3289 // extension.
3290 test.shouldFail = true
3291 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3292 case "YesToNo-Client":
3293 // A client should abort a connection
3294 // where the server didn't echo EMS
3295 // when the session used it.
3296 test.shouldFail = true
3297 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3298 }
3299
3300 testCases = append(testCases, test)
3301 }
3302 }
3303 }
David Benjamin163c9562016-08-29 23:14:17 -04003304
3305 // Switching EMS on renegotiation is forbidden.
3306 testCases = append(testCases, testCase{
3307 name: "ExtendedMasterSecret-Renego-NoEMS",
3308 config: Config{
3309 MaxVersion: VersionTLS12,
3310 Bugs: ProtocolBugs{
3311 NoExtendedMasterSecret: true,
3312 NoExtendedMasterSecretOnRenegotiation: true,
3313 },
3314 },
3315 renegotiate: 1,
3316 flags: []string{
3317 "-renegotiate-freely",
3318 "-expect-total-renegotiations", "1",
3319 },
3320 })
3321
3322 testCases = append(testCases, testCase{
3323 name: "ExtendedMasterSecret-Renego-Upgrade",
3324 config: Config{
3325 MaxVersion: VersionTLS12,
3326 Bugs: ProtocolBugs{
3327 NoExtendedMasterSecret: true,
3328 },
3329 },
3330 renegotiate: 1,
3331 flags: []string{
3332 "-renegotiate-freely",
3333 "-expect-total-renegotiations", "1",
3334 },
3335 shouldFail: true,
3336 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3337 })
3338
3339 testCases = append(testCases, testCase{
3340 name: "ExtendedMasterSecret-Renego-Downgrade",
3341 config: Config{
3342 MaxVersion: VersionTLS12,
3343 Bugs: ProtocolBugs{
3344 NoExtendedMasterSecretOnRenegotiation: true,
3345 },
3346 },
3347 renegotiate: 1,
3348 flags: []string{
3349 "-renegotiate-freely",
3350 "-expect-total-renegotiations", "1",
3351 },
3352 shouldFail: true,
3353 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3354 })
Adam Langley75712922014-10-10 16:23:43 -07003355}
3356
David Benjamin582ba042016-07-07 12:33:25 -07003357type stateMachineTestConfig struct {
3358 protocol protocol
3359 async bool
3360 splitHandshake, packHandshakeFlight bool
3361}
3362
David Benjamin43ec06f2014-08-05 02:28:57 -04003363// Adds tests that try to cover the range of the handshake state machine, under
3364// various conditions. Some of these are redundant with other tests, but they
3365// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003366func addAllStateMachineCoverageTests() {
3367 for _, async := range []bool{false, true} {
3368 for _, protocol := range []protocol{tls, dtls} {
3369 addStateMachineCoverageTests(stateMachineTestConfig{
3370 protocol: protocol,
3371 async: async,
3372 })
3373 addStateMachineCoverageTests(stateMachineTestConfig{
3374 protocol: protocol,
3375 async: async,
3376 splitHandshake: true,
3377 })
3378 if protocol == tls {
3379 addStateMachineCoverageTests(stateMachineTestConfig{
3380 protocol: protocol,
3381 async: async,
3382 packHandshakeFlight: true,
3383 })
3384 }
3385 }
3386 }
3387}
3388
3389func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 var tests []testCase
3391
3392 // Basic handshake, with resumption. Client and server,
3393 // session ID and session ticket.
3394 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003395 name: "Basic-Client",
3396 config: Config{
3397 MaxVersion: VersionTLS12,
3398 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003399 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003400 // Ensure session tickets are used, not session IDs.
3401 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 })
3403 tests = append(tests, testCase{
3404 name: "Basic-Client-RenewTicket",
3405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003406 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 Bugs: ProtocolBugs{
3408 RenewTicketOnResume: true,
3409 },
3410 },
David Benjamin46662482016-08-17 00:51:00 -04003411 flags: []string{"-expect-ticket-renewal"},
3412 resumeSession: true,
3413 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003414 })
3415 tests = append(tests, testCase{
3416 name: "Basic-Client-NoTicket",
3417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003418 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003419 SessionTicketsDisabled: true,
3420 },
3421 resumeSession: true,
3422 })
3423 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 name: "Basic-Client-Implicit",
3425 config: Config{
3426 MaxVersion: VersionTLS12,
3427 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003428 flags: []string{"-implicit-handshake"},
3429 resumeSession: true,
3430 })
3431 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003432 testType: serverTest,
3433 name: "Basic-Server",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003436 Bugs: ProtocolBugs{
3437 RequireSessionTickets: true,
3438 },
3439 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003440 resumeSession: true,
3441 })
3442 tests = append(tests, testCase{
3443 testType: serverTest,
3444 name: "Basic-Server-NoTickets",
3445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003446 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003447 SessionTicketsDisabled: true,
3448 },
3449 resumeSession: true,
3450 })
3451 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003452 testType: serverTest,
3453 name: "Basic-Server-Implicit",
3454 config: Config{
3455 MaxVersion: VersionTLS12,
3456 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003457 flags: []string{"-implicit-handshake"},
3458 resumeSession: true,
3459 })
3460 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003461 testType: serverTest,
3462 name: "Basic-Server-EarlyCallback",
3463 config: Config{
3464 MaxVersion: VersionTLS12,
3465 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003466 flags: []string{"-use-early-callback"},
3467 resumeSession: true,
3468 })
3469
Steven Valdez143e8b32016-07-11 13:19:03 -04003470 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003471 if config.protocol == tls {
3472 tests = append(tests, testCase{
3473 name: "TLS13-1RTT-Client",
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 testType: serverTest,
3484 name: "TLS13-1RTT-Server",
3485 config: Config{
3486 MaxVersion: VersionTLS13,
3487 MinVersion: VersionTLS13,
3488 },
David Benjamin46662482016-08-17 00:51:00 -04003489 resumeSession: true,
3490 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003491 })
3492
3493 tests = append(tests, testCase{
3494 name: "TLS13-HelloRetryRequest-Client",
3495 config: Config{
3496 MaxVersion: VersionTLS13,
3497 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003498 // P-384 requires a HelloRetryRequest against BoringSSL's default
3499 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003500 CurvePreferences: []CurveID{CurveP384},
3501 Bugs: ProtocolBugs{
3502 ExpectMissingKeyShare: true,
3503 },
3504 },
3505 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3506 resumeSession: true,
3507 })
3508
3509 tests = append(tests, testCase{
3510 testType: serverTest,
3511 name: "TLS13-HelloRetryRequest-Server",
3512 config: Config{
3513 MaxVersion: VersionTLS13,
3514 MinVersion: VersionTLS13,
3515 // Require a HelloRetryRequest for every curve.
3516 DefaultCurves: []CurveID{},
3517 },
3518 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3519 resumeSession: true,
3520 })
3521 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003522
David Benjamin760b1dd2015-05-15 23:33:48 -04003523 // TLS client auth.
3524 tests = append(tests, testCase{
3525 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003526 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003527 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003528 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003529 ClientAuth: RequestClientCert,
3530 },
3531 })
3532 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003533 testType: serverTest,
3534 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003535 config: Config{
3536 MaxVersion: VersionTLS12,
3537 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003538 // Setting SSL_VERIFY_PEER allows anonymous clients.
3539 flags: []string{"-verify-peer"},
3540 })
David Benjamin582ba042016-07-07 12:33:25 -07003541 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003542 tests = append(tests, testCase{
3543 testType: clientTest,
3544 name: "ClientAuth-NoCertificate-Client-SSL3",
3545 config: Config{
3546 MaxVersion: VersionSSL30,
3547 ClientAuth: RequestClientCert,
3548 },
3549 })
3550 tests = append(tests, testCase{
3551 testType: serverTest,
3552 name: "ClientAuth-NoCertificate-Server-SSL3",
3553 config: Config{
3554 MaxVersion: VersionSSL30,
3555 },
3556 // Setting SSL_VERIFY_PEER allows anonymous clients.
3557 flags: []string{"-verify-peer"},
3558 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003559 tests = append(tests, testCase{
3560 testType: clientTest,
3561 name: "ClientAuth-NoCertificate-Client-TLS13",
3562 config: Config{
3563 MaxVersion: VersionTLS13,
3564 ClientAuth: RequestClientCert,
3565 },
3566 })
3567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "ClientAuth-NoCertificate-Server-TLS13",
3570 config: Config{
3571 MaxVersion: VersionTLS13,
3572 },
3573 // Setting SSL_VERIFY_PEER allows anonymous clients.
3574 flags: []string{"-verify-peer"},
3575 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003576 }
3577 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003578 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003579 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003581 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003582 ClientAuth: RequireAnyClientCert,
3583 },
3584 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003585 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3586 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 },
3588 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003589 tests = append(tests, testCase{
3590 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003591 name: "ClientAuth-RSA-Client-TLS13",
3592 config: Config{
3593 MaxVersion: VersionTLS13,
3594 ClientAuth: RequireAnyClientCert,
3595 },
3596 flags: []string{
3597 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3598 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3599 },
3600 })
3601 tests = append(tests, testCase{
3602 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003603 name: "ClientAuth-ECDSA-Client",
3604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003605 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003606 ClientAuth: RequireAnyClientCert,
3607 },
3608 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003609 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3610 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003611 },
3612 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003613 tests = append(tests, testCase{
3614 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003615 name: "ClientAuth-ECDSA-Client-TLS13",
3616 config: Config{
3617 MaxVersion: VersionTLS13,
3618 ClientAuth: RequireAnyClientCert,
3619 },
3620 flags: []string{
3621 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3622 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3623 },
3624 })
3625 tests = append(tests, testCase{
3626 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003627 name: "ClientAuth-NoCertificate-OldCallback",
3628 config: Config{
3629 MaxVersion: VersionTLS12,
3630 ClientAuth: RequestClientCert,
3631 },
3632 flags: []string{"-use-old-client-cert-callback"},
3633 })
3634 tests = append(tests, testCase{
3635 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003636 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3637 config: Config{
3638 MaxVersion: VersionTLS13,
3639 ClientAuth: RequestClientCert,
3640 },
3641 flags: []string{"-use-old-client-cert-callback"},
3642 })
3643 tests = append(tests, testCase{
3644 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003645 name: "ClientAuth-OldCallback",
3646 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003647 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003648 ClientAuth: RequireAnyClientCert,
3649 },
3650 flags: []string{
3651 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3652 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3653 "-use-old-client-cert-callback",
3654 },
3655 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003656 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003657 testType: clientTest,
3658 name: "ClientAuth-OldCallback-TLS13",
3659 config: Config{
3660 MaxVersion: VersionTLS13,
3661 ClientAuth: RequireAnyClientCert,
3662 },
3663 flags: []string{
3664 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3665 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3666 "-use-old-client-cert-callback",
3667 },
3668 })
3669 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003670 testType: serverTest,
3671 name: "ClientAuth-Server",
3672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003673 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003674 Certificates: []Certificate{rsaCertificate},
3675 },
3676 flags: []string{"-require-any-client-certificate"},
3677 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003678 tests = append(tests, testCase{
3679 testType: serverTest,
3680 name: "ClientAuth-Server-TLS13",
3681 config: Config{
3682 MaxVersion: VersionTLS13,
3683 Certificates: []Certificate{rsaCertificate},
3684 },
3685 flags: []string{"-require-any-client-certificate"},
3686 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003687
David Benjamin4c3ddf72016-06-29 18:13:53 -04003688 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003689 tests = append(tests, testCase{
3690 testType: serverTest,
3691 name: "Basic-Server-RSA",
3692 config: Config{
3693 MaxVersion: VersionTLS12,
3694 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3695 },
3696 flags: []string{
3697 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3698 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3699 },
3700 })
3701 tests = append(tests, testCase{
3702 testType: serverTest,
3703 name: "Basic-Server-ECDHE-RSA",
3704 config: Config{
3705 MaxVersion: VersionTLS12,
3706 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3707 },
3708 flags: []string{
3709 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3710 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3711 },
3712 })
3713 tests = append(tests, testCase{
3714 testType: serverTest,
3715 name: "Basic-Server-ECDHE-ECDSA",
3716 config: Config{
3717 MaxVersion: VersionTLS12,
3718 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3719 },
3720 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003721 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3722 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003723 },
3724 })
3725
David Benjamin760b1dd2015-05-15 23:33:48 -04003726 // No session ticket support; server doesn't send NewSessionTicket.
3727 tests = append(tests, testCase{
3728 name: "SessionTicketsDisabled-Client",
3729 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003730 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003731 SessionTicketsDisabled: true,
3732 },
3733 })
3734 tests = append(tests, testCase{
3735 testType: serverTest,
3736 name: "SessionTicketsDisabled-Server",
3737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003738 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003739 SessionTicketsDisabled: true,
3740 },
3741 })
3742
3743 // Skip ServerKeyExchange in PSK key exchange if there's no
3744 // identity hint.
3745 tests = append(tests, testCase{
3746 name: "EmptyPSKHint-Client",
3747 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003748 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3750 PreSharedKey: []byte("secret"),
3751 },
3752 flags: []string{"-psk", "secret"},
3753 })
3754 tests = append(tests, testCase{
3755 testType: serverTest,
3756 name: "EmptyPSKHint-Server",
3757 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003758 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003759 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3760 PreSharedKey: []byte("secret"),
3761 },
3762 flags: []string{"-psk", "secret"},
3763 })
3764
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003766 tests = append(tests, testCase{
3767 testType: clientTest,
3768 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003769 config: Config{
3770 MaxVersion: VersionTLS12,
3771 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003772 flags: []string{
3773 "-enable-ocsp-stapling",
3774 "-expect-ocsp-response",
3775 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003776 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003777 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003778 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003779 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003780 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003781 testType: serverTest,
3782 name: "OCSPStapling-Server",
3783 config: Config{
3784 MaxVersion: VersionTLS12,
3785 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003786 expectedOCSPResponse: testOCSPResponse,
3787 flags: []string{
3788 "-ocsp-response",
3789 base64.StdEncoding.EncodeToString(testOCSPResponse),
3790 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003791 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003792 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003793 tests = append(tests, testCase{
3794 testType: clientTest,
3795 name: "OCSPStapling-Client-TLS13",
3796 config: Config{
3797 MaxVersion: VersionTLS13,
3798 },
3799 flags: []string{
3800 "-enable-ocsp-stapling",
3801 "-expect-ocsp-response",
3802 base64.StdEncoding.EncodeToString(testOCSPResponse),
3803 "-verify-peer",
3804 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003805 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003806 })
3807 tests = append(tests, testCase{
3808 testType: serverTest,
3809 name: "OCSPStapling-Server-TLS13",
3810 config: Config{
3811 MaxVersion: VersionTLS13,
3812 },
3813 expectedOCSPResponse: testOCSPResponse,
3814 flags: []string{
3815 "-ocsp-response",
3816 base64.StdEncoding.EncodeToString(testOCSPResponse),
3817 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003818 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003819 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003820
David Benjamin4c3ddf72016-06-29 18:13:53 -04003821 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003822 for _, vers := range tlsVersions {
3823 if config.protocol == dtls && !vers.hasDTLS {
3824 continue
3825 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003826 for _, testType := range []testType{clientTest, serverTest} {
3827 suffix := "-Client"
3828 if testType == serverTest {
3829 suffix = "-Server"
3830 }
3831 suffix += "-" + vers.name
3832
3833 flag := "-verify-peer"
3834 if testType == serverTest {
3835 flag = "-require-any-client-certificate"
3836 }
3837
3838 tests = append(tests, testCase{
3839 testType: testType,
3840 name: "CertificateVerificationSucceed" + suffix,
3841 config: Config{
3842 MaxVersion: vers.version,
3843 Certificates: []Certificate{rsaCertificate},
3844 },
3845 flags: []string{
3846 flag,
3847 "-expect-verify-result",
3848 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003849 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003850 })
3851 tests = append(tests, testCase{
3852 testType: testType,
3853 name: "CertificateVerificationFail" + suffix,
3854 config: Config{
3855 MaxVersion: vers.version,
3856 Certificates: []Certificate{rsaCertificate},
3857 },
3858 flags: []string{
3859 flag,
3860 "-verify-fail",
3861 },
3862 shouldFail: true,
3863 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3864 })
3865 }
3866
3867 // By default, the client is in a soft fail mode where the peer
3868 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003869 tests = append(tests, testCase{
3870 testType: clientTest,
3871 name: "CertificateVerificationSoftFail-" + vers.name,
3872 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003873 MaxVersion: vers.version,
3874 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003875 },
3876 flags: []string{
3877 "-verify-fail",
3878 "-expect-verify-result",
3879 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003880 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003881 })
3882 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003883
David Benjamin1d4f4c02016-07-26 18:03:08 -04003884 tests = append(tests, testCase{
3885 name: "ShimSendAlert",
3886 flags: []string{"-send-alert"},
3887 shimWritesFirst: true,
3888 shouldFail: true,
3889 expectedLocalError: "remote error: decompression failure",
3890 })
3891
David Benjamin582ba042016-07-07 12:33:25 -07003892 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003893 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003894 name: "Renegotiate-Client",
3895 config: Config{
3896 MaxVersion: VersionTLS12,
3897 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003898 renegotiate: 1,
3899 flags: []string{
3900 "-renegotiate-freely",
3901 "-expect-total-renegotiations", "1",
3902 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003903 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904
David Benjamin47921102016-07-28 11:29:18 -04003905 tests = append(tests, testCase{
3906 name: "SendHalfHelloRequest",
3907 config: Config{
3908 MaxVersion: VersionTLS12,
3909 Bugs: ProtocolBugs{
3910 PackHelloRequestWithFinished: config.packHandshakeFlight,
3911 },
3912 },
3913 sendHalfHelloRequest: true,
3914 flags: []string{"-renegotiate-ignore"},
3915 shouldFail: true,
3916 expectedError: ":UNEXPECTED_RECORD:",
3917 })
3918
David Benjamin760b1dd2015-05-15 23:33:48 -04003919 // NPN on client and server; results in post-handshake message.
3920 tests = append(tests, testCase{
3921 name: "NPN-Client",
3922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003924 NextProtos: []string{"foo"},
3925 },
3926 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003927 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003928 expectedNextProto: "foo",
3929 expectedNextProtoType: npn,
3930 })
3931 tests = append(tests, testCase{
3932 testType: serverTest,
3933 name: "NPN-Server",
3934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003935 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003936 NextProtos: []string{"bar"},
3937 },
3938 flags: []string{
3939 "-advertise-npn", "\x03foo\x03bar\x03baz",
3940 "-expect-next-proto", "bar",
3941 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003942 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 expectedNextProto: "bar",
3944 expectedNextProtoType: npn,
3945 })
3946
3947 // TODO(davidben): Add tests for when False Start doesn't trigger.
3948
3949 // Client does False Start and negotiates NPN.
3950 tests = append(tests, testCase{
3951 name: "FalseStart",
3952 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003953 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3955 NextProtos: []string{"foo"},
3956 Bugs: ProtocolBugs{
3957 ExpectFalseStart: true,
3958 },
3959 },
3960 flags: []string{
3961 "-false-start",
3962 "-select-next-proto", "foo",
3963 },
3964 shimWritesFirst: true,
3965 resumeSession: true,
3966 })
3967
3968 // Client does False Start and negotiates ALPN.
3969 tests = append(tests, testCase{
3970 name: "FalseStart-ALPN",
3971 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003972 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3974 NextProtos: []string{"foo"},
3975 Bugs: ProtocolBugs{
3976 ExpectFalseStart: true,
3977 },
3978 },
3979 flags: []string{
3980 "-false-start",
3981 "-advertise-alpn", "\x03foo",
3982 },
3983 shimWritesFirst: true,
3984 resumeSession: true,
3985 })
3986
3987 // Client does False Start but doesn't explicitly call
3988 // SSL_connect.
3989 tests = append(tests, testCase{
3990 name: "FalseStart-Implicit",
3991 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003992 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3994 NextProtos: []string{"foo"},
3995 },
3996 flags: []string{
3997 "-implicit-handshake",
3998 "-false-start",
3999 "-advertise-alpn", "\x03foo",
4000 },
4001 })
4002
4003 // False Start without session tickets.
4004 tests = append(tests, testCase{
4005 name: "FalseStart-SessionTicketsDisabled",
4006 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004007 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4009 NextProtos: []string{"foo"},
4010 SessionTicketsDisabled: true,
4011 Bugs: ProtocolBugs{
4012 ExpectFalseStart: true,
4013 },
4014 },
4015 flags: []string{
4016 "-false-start",
4017 "-select-next-proto", "foo",
4018 },
4019 shimWritesFirst: true,
4020 })
4021
4022 // Server parses a V2ClientHello.
4023 tests = append(tests, testCase{
4024 testType: serverTest,
4025 name: "SendV2ClientHello",
4026 config: Config{
4027 // Choose a cipher suite that does not involve
4028 // elliptic curves, so no extensions are
4029 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004030 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004031 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004032 Bugs: ProtocolBugs{
4033 SendV2ClientHello: true,
4034 },
4035 },
4036 })
4037
Nick Harper60a85cb2016-09-23 16:25:11 -07004038 // Test Channel ID
4039 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004040 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004041 continue
4042 }
4043 // Client sends a Channel ID.
4044 tests = append(tests, testCase{
4045 name: "ChannelID-Client-" + ver.name,
4046 config: Config{
4047 MaxVersion: ver.version,
4048 RequestChannelID: true,
4049 },
4050 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4051 resumeSession: true,
4052 expectChannelID: true,
4053 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004054
Nick Harper60a85cb2016-09-23 16:25:11 -07004055 // Server accepts a Channel ID.
4056 tests = append(tests, testCase{
4057 testType: serverTest,
4058 name: "ChannelID-Server-" + ver.name,
4059 config: Config{
4060 MaxVersion: ver.version,
4061 ChannelID: channelIDKey,
4062 },
4063 flags: []string{
4064 "-expect-channel-id",
4065 base64.StdEncoding.EncodeToString(channelIDBytes),
4066 },
4067 resumeSession: true,
4068 expectChannelID: true,
4069 })
4070
4071 tests = append(tests, testCase{
4072 testType: serverTest,
4073 name: "InvalidChannelIDSignature-" + ver.name,
4074 config: Config{
4075 MaxVersion: ver.version,
4076 ChannelID: channelIDKey,
4077 Bugs: ProtocolBugs{
4078 InvalidChannelIDSignature: true,
4079 },
4080 },
4081 flags: []string{"-enable-channel-id"},
4082 shouldFail: true,
4083 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4084 })
4085 }
David Benjamin30789da2015-08-29 22:56:45 -04004086
David Benjaminf8fcdf32016-06-08 15:56:13 -04004087 // Channel ID and NPN at the same time, to ensure their relative
4088 // ordering is correct.
4089 tests = append(tests, testCase{
4090 name: "ChannelID-NPN-Client",
4091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004092 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004093 RequestChannelID: true,
4094 NextProtos: []string{"foo"},
4095 },
4096 flags: []string{
4097 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4098 "-select-next-proto", "foo",
4099 },
4100 resumeSession: true,
4101 expectChannelID: true,
4102 expectedNextProto: "foo",
4103 expectedNextProtoType: npn,
4104 })
4105 tests = append(tests, testCase{
4106 testType: serverTest,
4107 name: "ChannelID-NPN-Server",
4108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004109 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004110 ChannelID: channelIDKey,
4111 NextProtos: []string{"bar"},
4112 },
4113 flags: []string{
4114 "-expect-channel-id",
4115 base64.StdEncoding.EncodeToString(channelIDBytes),
4116 "-advertise-npn", "\x03foo\x03bar\x03baz",
4117 "-expect-next-proto", "bar",
4118 },
4119 resumeSession: true,
4120 expectChannelID: true,
4121 expectedNextProto: "bar",
4122 expectedNextProtoType: npn,
4123 })
4124
David Benjamin30789da2015-08-29 22:56:45 -04004125 // Bidirectional shutdown with the runner initiating.
4126 tests = append(tests, testCase{
4127 name: "Shutdown-Runner",
4128 config: Config{
4129 Bugs: ProtocolBugs{
4130 ExpectCloseNotify: true,
4131 },
4132 },
4133 flags: []string{"-check-close-notify"},
4134 })
4135
4136 // Bidirectional shutdown with the shim initiating. The runner,
4137 // in the meantime, sends garbage before the close_notify which
4138 // the shim must ignore.
4139 tests = append(tests, testCase{
4140 name: "Shutdown-Shim",
4141 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004142 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004143 Bugs: ProtocolBugs{
4144 ExpectCloseNotify: true,
4145 },
4146 },
4147 shimShutsDown: true,
4148 sendEmptyRecords: 1,
4149 sendWarningAlerts: 1,
4150 flags: []string{"-check-close-notify"},
4151 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004152 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004153 // TODO(davidben): DTLS 1.3 will want a similar thing for
4154 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004155 tests = append(tests, testCase{
4156 name: "SkipHelloVerifyRequest",
4157 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004158 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004159 Bugs: ProtocolBugs{
4160 SkipHelloVerifyRequest: true,
4161 },
4162 },
4163 })
4164 }
4165
David Benjamin760b1dd2015-05-15 23:33:48 -04004166 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004167 test.protocol = config.protocol
4168 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004169 test.name += "-DTLS"
4170 }
David Benjamin582ba042016-07-07 12:33:25 -07004171 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004172 test.name += "-Async"
4173 test.flags = append(test.flags, "-async")
4174 } else {
4175 test.name += "-Sync"
4176 }
David Benjamin582ba042016-07-07 12:33:25 -07004177 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004178 test.name += "-SplitHandshakeRecords"
4179 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004180 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004181 test.config.Bugs.MaxPacketLength = 256
4182 test.flags = append(test.flags, "-mtu", "256")
4183 }
4184 }
David Benjamin582ba042016-07-07 12:33:25 -07004185 if config.packHandshakeFlight {
4186 test.name += "-PackHandshakeFlight"
4187 test.config.Bugs.PackHandshakeFlight = true
4188 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004189 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004190 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004191}
4192
Adam Langley524e7172015-02-20 16:04:00 -08004193func addDDoSCallbackTests() {
4194 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004195 for _, resume := range []bool{false, true} {
4196 suffix := "Resume"
4197 if resume {
4198 suffix = "No" + suffix
4199 }
4200
4201 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004202 testType: serverTest,
4203 name: "Server-DDoS-OK-" + suffix,
4204 config: Config{
4205 MaxVersion: VersionTLS12,
4206 },
Adam Langley524e7172015-02-20 16:04:00 -08004207 flags: []string{"-install-ddos-callback"},
4208 resumeSession: resume,
4209 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004210 testCases = append(testCases, testCase{
4211 testType: serverTest,
4212 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4213 config: Config{
4214 MaxVersion: VersionTLS13,
4215 },
4216 flags: []string{"-install-ddos-callback"},
4217 resumeSession: resume,
4218 })
Adam Langley524e7172015-02-20 16:04:00 -08004219
4220 failFlag := "-fail-ddos-callback"
4221 if resume {
4222 failFlag = "-fail-second-ddos-callback"
4223 }
4224 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004225 testType: serverTest,
4226 name: "Server-DDoS-Reject-" + suffix,
4227 config: Config{
4228 MaxVersion: VersionTLS12,
4229 },
David Benjamin2c66e072016-09-16 15:58:00 -04004230 flags: []string{"-install-ddos-callback", failFlag},
4231 resumeSession: resume,
4232 shouldFail: true,
4233 expectedError: ":CONNECTION_REJECTED:",
4234 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004235 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004236 testCases = append(testCases, testCase{
4237 testType: serverTest,
4238 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4239 config: Config{
4240 MaxVersion: VersionTLS13,
4241 },
David Benjamin2c66e072016-09-16 15:58:00 -04004242 flags: []string{"-install-ddos-callback", failFlag},
4243 resumeSession: resume,
4244 shouldFail: true,
4245 expectedError: ":CONNECTION_REJECTED:",
4246 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004247 })
Adam Langley524e7172015-02-20 16:04:00 -08004248 }
4249}
4250
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004251func addVersionNegotiationTests() {
4252 for i, shimVers := range tlsVersions {
4253 // Assemble flags to disable all newer versions on the shim.
4254 var flags []string
4255 for _, vers := range tlsVersions[i+1:] {
4256 flags = append(flags, vers.flag)
4257 }
4258
Steven Valdezfdd10992016-09-15 16:27:05 -04004259 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004260 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004261 protocols := []protocol{tls}
4262 if runnerVers.hasDTLS && shimVers.hasDTLS {
4263 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004264 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004265 for _, protocol := range protocols {
4266 expectedVersion := shimVers.version
4267 if runnerVers.version < shimVers.version {
4268 expectedVersion = runnerVers.version
4269 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004270
David Benjamin8b8c0062014-11-23 02:47:52 -05004271 suffix := shimVers.name + "-" + runnerVers.name
4272 if protocol == dtls {
4273 suffix += "-DTLS"
4274 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004275
David Benjamin1eb367c2014-12-12 18:17:51 -05004276 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4277
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004278 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004279 clientVers := shimVers.version
4280 if clientVers > VersionTLS10 {
4281 clientVers = VersionTLS10
4282 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004283 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004284 serverVers := expectedVersion
4285 if expectedVersion >= VersionTLS13 {
4286 serverVers = VersionTLS10
4287 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004288 serverVers = versionToWire(serverVers, protocol == dtls)
4289
David Benjamin8b8c0062014-11-23 02:47:52 -05004290 testCases = append(testCases, testCase{
4291 protocol: protocol,
4292 testType: clientTest,
4293 name: "VersionNegotiation-Client-" + suffix,
4294 config: Config{
4295 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004296 Bugs: ProtocolBugs{
4297 ExpectInitialRecordVersion: clientVers,
4298 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004299 },
4300 flags: flags,
4301 expectedVersion: expectedVersion,
4302 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004303 testCases = append(testCases, testCase{
4304 protocol: protocol,
4305 testType: clientTest,
4306 name: "VersionNegotiation-Client2-" + suffix,
4307 config: Config{
4308 MaxVersion: runnerVers.version,
4309 Bugs: ProtocolBugs{
4310 ExpectInitialRecordVersion: clientVers,
4311 },
4312 },
4313 flags: []string{"-max-version", shimVersFlag},
4314 expectedVersion: expectedVersion,
4315 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004316
4317 testCases = append(testCases, testCase{
4318 protocol: protocol,
4319 testType: serverTest,
4320 name: "VersionNegotiation-Server-" + suffix,
4321 config: Config{
4322 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004323 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004324 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004325 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004326 },
4327 flags: flags,
4328 expectedVersion: expectedVersion,
4329 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004330 testCases = append(testCases, testCase{
4331 protocol: protocol,
4332 testType: serverTest,
4333 name: "VersionNegotiation-Server2-" + suffix,
4334 config: Config{
4335 MaxVersion: runnerVers.version,
4336 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004337 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004338 },
4339 },
4340 flags: []string{"-max-version", shimVersFlag},
4341 expectedVersion: expectedVersion,
4342 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004343 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004344 }
4345 }
David Benjamin95c69562016-06-29 18:15:03 -04004346
Steven Valdezfdd10992016-09-15 16:27:05 -04004347 // Test the version extension at all versions.
4348 for _, vers := range tlsVersions {
4349 protocols := []protocol{tls}
4350 if vers.hasDTLS {
4351 protocols = append(protocols, dtls)
4352 }
4353 for _, protocol := range protocols {
4354 suffix := vers.name
4355 if protocol == dtls {
4356 suffix += "-DTLS"
4357 }
4358
4359 wireVersion := versionToWire(vers.version, protocol == dtls)
4360 testCases = append(testCases, testCase{
4361 protocol: protocol,
4362 testType: serverTest,
4363 name: "VersionNegotiationExtension-" + suffix,
4364 config: Config{
4365 Bugs: ProtocolBugs{
4366 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4367 },
4368 },
4369 expectedVersion: vers.version,
4370 })
4371 }
4372
4373 }
4374
4375 // If all versions are unknown, negotiation fails.
4376 testCases = append(testCases, testCase{
4377 testType: serverTest,
4378 name: "NoSupportedVersions",
4379 config: Config{
4380 Bugs: ProtocolBugs{
4381 SendSupportedVersions: []uint16{0x1111},
4382 },
4383 },
4384 shouldFail: true,
4385 expectedError: ":UNSUPPORTED_PROTOCOL:",
4386 })
4387 testCases = append(testCases, testCase{
4388 protocol: dtls,
4389 testType: serverTest,
4390 name: "NoSupportedVersions-DTLS",
4391 config: Config{
4392 Bugs: ProtocolBugs{
4393 SendSupportedVersions: []uint16{0x1111},
4394 },
4395 },
4396 shouldFail: true,
4397 expectedError: ":UNSUPPORTED_PROTOCOL:",
4398 })
4399
4400 testCases = append(testCases, testCase{
4401 testType: serverTest,
4402 name: "ClientHelloVersionTooHigh",
4403 config: Config{
4404 MaxVersion: VersionTLS13,
4405 Bugs: ProtocolBugs{
4406 SendClientVersion: 0x0304,
4407 OmitSupportedVersions: true,
4408 },
4409 },
4410 expectedVersion: VersionTLS12,
4411 })
4412
4413 testCases = append(testCases, testCase{
4414 testType: serverTest,
4415 name: "ConflictingVersionNegotiation",
4416 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004417 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004418 SendClientVersion: VersionTLS12,
4419 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004420 },
4421 },
David Benjaminad75a662016-09-30 15:42:59 -04004422 // The extension takes precedence over the ClientHello version.
4423 expectedVersion: VersionTLS11,
4424 })
4425
4426 testCases = append(testCases, testCase{
4427 testType: serverTest,
4428 name: "ConflictingVersionNegotiation-2",
4429 config: Config{
4430 Bugs: ProtocolBugs{
4431 SendClientVersion: VersionTLS11,
4432 SendSupportedVersions: []uint16{VersionTLS12},
4433 },
4434 },
4435 // The extension takes precedence over the ClientHello version.
4436 expectedVersion: VersionTLS12,
4437 })
4438
4439 testCases = append(testCases, testCase{
4440 testType: serverTest,
4441 name: "RejectFinalTLS13",
4442 config: Config{
4443 Bugs: ProtocolBugs{
4444 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4445 },
4446 },
4447 // We currently implement a draft TLS 1.3 version. Ensure that
4448 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004449 expectedVersion: VersionTLS12,
4450 })
4451
Brian Smithf85d3232016-10-28 10:34:06 -10004452 // Test that the maximum version is selected regardless of the
4453 // client-sent order.
4454 testCases = append(testCases, testCase{
4455 testType: serverTest,
4456 name: "IgnoreClientVersionOrder",
4457 config: Config{
4458 Bugs: ProtocolBugs{
4459 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4460 },
4461 },
4462 expectedVersion: VersionTLS13,
4463 })
4464
David Benjamin95c69562016-06-29 18:15:03 -04004465 // Test for version tolerance.
4466 testCases = append(testCases, testCase{
4467 testType: serverTest,
4468 name: "MinorVersionTolerance",
4469 config: Config{
4470 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004471 SendClientVersion: 0x03ff,
4472 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004473 },
4474 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004475 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004476 })
4477 testCases = append(testCases, testCase{
4478 testType: serverTest,
4479 name: "MajorVersionTolerance",
4480 config: Config{
4481 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004482 SendClientVersion: 0x0400,
4483 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004484 },
4485 },
David Benjaminad75a662016-09-30 15:42:59 -04004486 // TLS 1.3 must be negotiated with the supported_versions
4487 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004488 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004489 })
David Benjaminad75a662016-09-30 15:42:59 -04004490 testCases = append(testCases, testCase{
4491 testType: serverTest,
4492 name: "VersionTolerance-TLS13",
4493 config: Config{
4494 Bugs: ProtocolBugs{
4495 // Although TLS 1.3 does not use
4496 // ClientHello.version, it still tolerates high
4497 // values there.
4498 SendClientVersion: 0x0400,
4499 },
4500 },
4501 expectedVersion: VersionTLS13,
4502 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004503
David Benjamin95c69562016-06-29 18:15:03 -04004504 testCases = append(testCases, testCase{
4505 protocol: dtls,
4506 testType: serverTest,
4507 name: "MinorVersionTolerance-DTLS",
4508 config: Config{
4509 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004510 SendClientVersion: 0xfe00,
4511 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004512 },
4513 },
4514 expectedVersion: VersionTLS12,
4515 })
4516 testCases = append(testCases, testCase{
4517 protocol: dtls,
4518 testType: serverTest,
4519 name: "MajorVersionTolerance-DTLS",
4520 config: Config{
4521 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004522 SendClientVersion: 0xfdff,
4523 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004524 },
4525 },
4526 expectedVersion: VersionTLS12,
4527 })
4528
4529 // Test that versions below 3.0 are rejected.
4530 testCases = append(testCases, testCase{
4531 testType: serverTest,
4532 name: "VersionTooLow",
4533 config: Config{
4534 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004535 SendClientVersion: 0x0200,
4536 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004537 },
4538 },
4539 shouldFail: true,
4540 expectedError: ":UNSUPPORTED_PROTOCOL:",
4541 })
4542 testCases = append(testCases, testCase{
4543 protocol: dtls,
4544 testType: serverTest,
4545 name: "VersionTooLow-DTLS",
4546 config: Config{
4547 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004548 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004549 },
4550 },
4551 shouldFail: true,
4552 expectedError: ":UNSUPPORTED_PROTOCOL:",
4553 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004554
David Benjamin2dc02042016-09-19 19:57:37 -04004555 testCases = append(testCases, testCase{
4556 name: "ServerBogusVersion",
4557 config: Config{
4558 Bugs: ProtocolBugs{
4559 SendServerHelloVersion: 0x1234,
4560 },
4561 },
4562 shouldFail: true,
4563 expectedError: ":UNSUPPORTED_PROTOCOL:",
4564 })
4565
David Benjamin1f61f0d2016-07-10 12:20:35 -04004566 // Test TLS 1.3's downgrade signal.
4567 testCases = append(testCases, testCase{
4568 name: "Downgrade-TLS12-Client",
4569 config: Config{
4570 Bugs: ProtocolBugs{
4571 NegotiateVersion: VersionTLS12,
4572 },
4573 },
David Benjamin592b5322016-09-30 15:15:01 -04004574 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004575 // TODO(davidben): This test should fail once TLS 1.3 is final
4576 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004577 })
4578 testCases = append(testCases, testCase{
4579 testType: serverTest,
4580 name: "Downgrade-TLS12-Server",
4581 config: Config{
4582 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004583 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004584 },
4585 },
David Benjamin592b5322016-09-30 15:15:01 -04004586 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004587 // TODO(davidben): This test should fail once TLS 1.3 is final
4588 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004589 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004590}
4591
David Benjaminaccb4542014-12-12 23:44:33 -05004592func addMinimumVersionTests() {
4593 for i, shimVers := range tlsVersions {
4594 // Assemble flags to disable all older versions on the shim.
4595 var flags []string
4596 for _, vers := range tlsVersions[:i] {
4597 flags = append(flags, vers.flag)
4598 }
4599
4600 for _, runnerVers := range tlsVersions {
4601 protocols := []protocol{tls}
4602 if runnerVers.hasDTLS && shimVers.hasDTLS {
4603 protocols = append(protocols, dtls)
4604 }
4605 for _, protocol := range protocols {
4606 suffix := shimVers.name + "-" + runnerVers.name
4607 if protocol == dtls {
4608 suffix += "-DTLS"
4609 }
4610 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4611
David Benjaminaccb4542014-12-12 23:44:33 -05004612 var expectedVersion uint16
4613 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004614 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004615 if runnerVers.version >= shimVers.version {
4616 expectedVersion = runnerVers.version
4617 } else {
4618 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004619 expectedError = ":UNSUPPORTED_PROTOCOL:"
4620 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004621 }
4622
4623 testCases = append(testCases, testCase{
4624 protocol: protocol,
4625 testType: clientTest,
4626 name: "MinimumVersion-Client-" + suffix,
4627 config: Config{
4628 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004629 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004630 // Ensure the server does not decline to
4631 // select a version (versions extension) or
4632 // cipher (some ciphers depend on versions).
4633 NegotiateVersion: runnerVers.version,
4634 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004635 },
David Benjaminaccb4542014-12-12 23:44:33 -05004636 },
David Benjamin87909c02014-12-13 01:55:01 -05004637 flags: flags,
4638 expectedVersion: expectedVersion,
4639 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004640 expectedError: expectedError,
4641 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004642 })
4643 testCases = append(testCases, testCase{
4644 protocol: protocol,
4645 testType: clientTest,
4646 name: "MinimumVersion-Client2-" + suffix,
4647 config: Config{
4648 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004649 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004650 // Ensure the server does not decline to
4651 // select a version (versions extension) or
4652 // cipher (some ciphers depend on versions).
4653 NegotiateVersion: runnerVers.version,
4654 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004655 },
David Benjaminaccb4542014-12-12 23:44:33 -05004656 },
David Benjamin87909c02014-12-13 01:55:01 -05004657 flags: []string{"-min-version", shimVersFlag},
4658 expectedVersion: expectedVersion,
4659 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004660 expectedError: expectedError,
4661 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004662 })
4663
4664 testCases = append(testCases, testCase{
4665 protocol: protocol,
4666 testType: serverTest,
4667 name: "MinimumVersion-Server-" + suffix,
4668 config: Config{
4669 MaxVersion: runnerVers.version,
4670 },
David Benjamin87909c02014-12-13 01:55:01 -05004671 flags: flags,
4672 expectedVersion: expectedVersion,
4673 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004674 expectedError: expectedError,
4675 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004676 })
4677 testCases = append(testCases, testCase{
4678 protocol: protocol,
4679 testType: serverTest,
4680 name: "MinimumVersion-Server2-" + suffix,
4681 config: Config{
4682 MaxVersion: runnerVers.version,
4683 },
David Benjamin87909c02014-12-13 01:55:01 -05004684 flags: []string{"-min-version", shimVersFlag},
4685 expectedVersion: expectedVersion,
4686 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004687 expectedError: expectedError,
4688 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004689 })
4690 }
4691 }
4692 }
4693}
4694
David Benjamine78bfde2014-09-06 12:45:15 -04004695func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004696 // TODO(davidben): Extensions, where applicable, all move their server
4697 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4698 // tests for both. Also test interaction with 0-RTT when implemented.
4699
David Benjamin97d17d92016-07-14 16:12:00 -04004700 // Repeat extensions tests all versions except SSL 3.0.
4701 for _, ver := range tlsVersions {
4702 if ver.version == VersionSSL30 {
4703 continue
4704 }
4705
David Benjamin97d17d92016-07-14 16:12:00 -04004706 // Test that duplicate extensions are rejected.
4707 testCases = append(testCases, testCase{
4708 testType: clientTest,
4709 name: "DuplicateExtensionClient-" + ver.name,
4710 config: Config{
4711 MaxVersion: ver.version,
4712 Bugs: ProtocolBugs{
4713 DuplicateExtension: true,
4714 },
David Benjamine78bfde2014-09-06 12:45:15 -04004715 },
David Benjamin97d17d92016-07-14 16:12:00 -04004716 shouldFail: true,
4717 expectedLocalError: "remote error: error decoding message",
4718 })
4719 testCases = append(testCases, testCase{
4720 testType: serverTest,
4721 name: "DuplicateExtensionServer-" + ver.name,
4722 config: Config{
4723 MaxVersion: ver.version,
4724 Bugs: ProtocolBugs{
4725 DuplicateExtension: true,
4726 },
David Benjamine78bfde2014-09-06 12:45:15 -04004727 },
David Benjamin97d17d92016-07-14 16:12:00 -04004728 shouldFail: true,
4729 expectedLocalError: "remote error: error decoding message",
4730 })
4731
4732 // Test SNI.
4733 testCases = append(testCases, testCase{
4734 testType: clientTest,
4735 name: "ServerNameExtensionClient-" + ver.name,
4736 config: Config{
4737 MaxVersion: ver.version,
4738 Bugs: ProtocolBugs{
4739 ExpectServerName: "example.com",
4740 },
David Benjamine78bfde2014-09-06 12:45:15 -04004741 },
David Benjamin97d17d92016-07-14 16:12:00 -04004742 flags: []string{"-host-name", "example.com"},
4743 })
4744 testCases = append(testCases, testCase{
4745 testType: clientTest,
4746 name: "ServerNameExtensionClientMismatch-" + ver.name,
4747 config: Config{
4748 MaxVersion: ver.version,
4749 Bugs: ProtocolBugs{
4750 ExpectServerName: "mismatch.com",
4751 },
David Benjamine78bfde2014-09-06 12:45:15 -04004752 },
David Benjamin97d17d92016-07-14 16:12:00 -04004753 flags: []string{"-host-name", "example.com"},
4754 shouldFail: true,
4755 expectedLocalError: "tls: unexpected server name",
4756 })
4757 testCases = append(testCases, testCase{
4758 testType: clientTest,
4759 name: "ServerNameExtensionClientMissing-" + ver.name,
4760 config: Config{
4761 MaxVersion: ver.version,
4762 Bugs: ProtocolBugs{
4763 ExpectServerName: "missing.com",
4764 },
David Benjamine78bfde2014-09-06 12:45:15 -04004765 },
David Benjamin97d17d92016-07-14 16:12:00 -04004766 shouldFail: true,
4767 expectedLocalError: "tls: unexpected server name",
4768 })
4769 testCases = append(testCases, testCase{
4770 testType: serverTest,
4771 name: "ServerNameExtensionServer-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004775 },
David Benjamin97d17d92016-07-14 16:12:00 -04004776 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004777 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004778 })
4779
4780 // Test ALPN.
4781 testCases = append(testCases, testCase{
4782 testType: clientTest,
4783 name: "ALPNClient-" + ver.name,
4784 config: Config{
4785 MaxVersion: ver.version,
4786 NextProtos: []string{"foo"},
4787 },
4788 flags: []string{
4789 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4790 "-expect-alpn", "foo",
4791 },
4792 expectedNextProto: "foo",
4793 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004794 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004795 })
4796 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004797 testType: clientTest,
4798 name: "ALPNClient-Mismatch-" + ver.name,
4799 config: Config{
4800 MaxVersion: ver.version,
4801 Bugs: ProtocolBugs{
4802 SendALPN: "baz",
4803 },
4804 },
4805 flags: []string{
4806 "-advertise-alpn", "\x03foo\x03bar",
4807 },
4808 shouldFail: true,
4809 expectedError: ":INVALID_ALPN_PROTOCOL:",
4810 expectedLocalError: "remote error: illegal parameter",
4811 })
4812 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004813 testType: serverTest,
4814 name: "ALPNServer-" + ver.name,
4815 config: Config{
4816 MaxVersion: ver.version,
4817 NextProtos: []string{"foo", "bar", "baz"},
4818 },
4819 flags: []string{
4820 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4821 "-select-alpn", "foo",
4822 },
4823 expectedNextProto: "foo",
4824 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004825 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004826 })
4827 testCases = append(testCases, testCase{
4828 testType: serverTest,
4829 name: "ALPNServer-Decline-" + ver.name,
4830 config: Config{
4831 MaxVersion: ver.version,
4832 NextProtos: []string{"foo", "bar", "baz"},
4833 },
4834 flags: []string{"-decline-alpn"},
4835 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004836 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004837 })
4838
David Benjamin25fe85b2016-08-09 20:00:32 -04004839 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4840 // called once.
4841 testCases = append(testCases, testCase{
4842 testType: serverTest,
4843 name: "ALPNServer-Async-" + ver.name,
4844 config: Config{
4845 MaxVersion: ver.version,
4846 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004847 // Prior to TLS 1.3, exercise the asynchronous session callback.
4848 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004849 },
4850 flags: []string{
4851 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4852 "-select-alpn", "foo",
4853 "-async",
4854 },
4855 expectedNextProto: "foo",
4856 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004857 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004858 })
4859
David Benjamin97d17d92016-07-14 16:12:00 -04004860 var emptyString string
4861 testCases = append(testCases, testCase{
4862 testType: clientTest,
4863 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 NextProtos: []string{""},
4867 Bugs: ProtocolBugs{
4868 // A server returning an empty ALPN protocol
4869 // should be rejected.
4870 ALPNProtocol: &emptyString,
4871 },
4872 },
4873 flags: []string{
4874 "-advertise-alpn", "\x03foo",
4875 },
4876 shouldFail: true,
4877 expectedError: ":PARSE_TLSEXT:",
4878 })
4879 testCases = append(testCases, testCase{
4880 testType: serverTest,
4881 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4882 config: Config{
4883 MaxVersion: ver.version,
4884 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004885 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004886 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004887 },
David Benjamin97d17d92016-07-14 16:12:00 -04004888 flags: []string{
4889 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004890 },
David Benjamin97d17d92016-07-14 16:12:00 -04004891 shouldFail: true,
4892 expectedError: ":PARSE_TLSEXT:",
4893 })
4894
4895 // Test NPN and the interaction with ALPN.
4896 if ver.version < VersionTLS13 {
4897 // Test that the server prefers ALPN over NPN.
4898 testCases = append(testCases, testCase{
4899 testType: serverTest,
4900 name: "ALPNServer-Preferred-" + ver.name,
4901 config: Config{
4902 MaxVersion: ver.version,
4903 NextProtos: []string{"foo", "bar", "baz"},
4904 },
4905 flags: []string{
4906 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4907 "-select-alpn", "foo",
4908 "-advertise-npn", "\x03foo\x03bar\x03baz",
4909 },
4910 expectedNextProto: "foo",
4911 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004912 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004913 })
4914 testCases = append(testCases, testCase{
4915 testType: serverTest,
4916 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4917 config: Config{
4918 MaxVersion: ver.version,
4919 NextProtos: []string{"foo", "bar", "baz"},
4920 Bugs: ProtocolBugs{
4921 SwapNPNAndALPN: true,
4922 },
4923 },
4924 flags: []string{
4925 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4926 "-select-alpn", "foo",
4927 "-advertise-npn", "\x03foo\x03bar\x03baz",
4928 },
4929 expectedNextProto: "foo",
4930 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004931 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004932 })
4933
4934 // Test that negotiating both NPN and ALPN is forbidden.
4935 testCases = append(testCases, testCase{
4936 name: "NegotiateALPNAndNPN-" + ver.name,
4937 config: Config{
4938 MaxVersion: ver.version,
4939 NextProtos: []string{"foo", "bar", "baz"},
4940 Bugs: ProtocolBugs{
4941 NegotiateALPNAndNPN: true,
4942 },
4943 },
4944 flags: []string{
4945 "-advertise-alpn", "\x03foo",
4946 "-select-next-proto", "foo",
4947 },
4948 shouldFail: true,
4949 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4953 config: Config{
4954 MaxVersion: ver.version,
4955 NextProtos: []string{"foo", "bar", "baz"},
4956 Bugs: ProtocolBugs{
4957 NegotiateALPNAndNPN: true,
4958 SwapNPNAndALPN: true,
4959 },
4960 },
4961 flags: []string{
4962 "-advertise-alpn", "\x03foo",
4963 "-select-next-proto", "foo",
4964 },
4965 shouldFail: true,
4966 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4967 })
David Benjamin97d17d92016-07-14 16:12:00 -04004968 }
4969
4970 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004971
4972 // Resume with a corrupt ticket.
4973 testCases = append(testCases, testCase{
4974 testType: serverTest,
4975 name: "CorruptTicket-" + ver.name,
4976 config: Config{
4977 MaxVersion: ver.version,
4978 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004979 FilterTicket: func(in []byte) ([]byte, error) {
4980 in[len(in)-1] ^= 1
4981 return in, nil
4982 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004983 },
4984 },
4985 resumeSession: true,
4986 expectResumeRejected: true,
4987 })
4988 // Test the ticket callback, with and without renewal.
4989 testCases = append(testCases, testCase{
4990 testType: serverTest,
4991 name: "TicketCallback-" + ver.name,
4992 config: Config{
4993 MaxVersion: ver.version,
4994 },
4995 resumeSession: true,
4996 flags: []string{"-use-ticket-callback"},
4997 })
4998 testCases = append(testCases, testCase{
4999 testType: serverTest,
5000 name: "TicketCallback-Renew-" + ver.name,
5001 config: Config{
5002 MaxVersion: ver.version,
5003 Bugs: ProtocolBugs{
5004 ExpectNewTicket: true,
5005 },
5006 },
5007 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5008 resumeSession: true,
5009 })
5010
5011 // Test that the ticket callback is only called once when everything before
5012 // it in the ClientHello is asynchronous. This corrupts the ticket so
5013 // certificate selection callbacks run.
5014 testCases = append(testCases, testCase{
5015 testType: serverTest,
5016 name: "TicketCallback-SingleCall-" + ver.name,
5017 config: Config{
5018 MaxVersion: ver.version,
5019 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005020 FilterTicket: func(in []byte) ([]byte, error) {
5021 in[len(in)-1] ^= 1
5022 return in, nil
5023 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005024 },
5025 },
5026 resumeSession: true,
5027 expectResumeRejected: true,
5028 flags: []string{
5029 "-use-ticket-callback",
5030 "-async",
5031 },
5032 })
5033
5034 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005035 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "OversizedSessionId-" + ver.name,
5039 config: Config{
5040 MaxVersion: ver.version,
5041 Bugs: ProtocolBugs{
5042 OversizedSessionId: true,
5043 },
5044 },
5045 resumeSession: true,
5046 shouldFail: true,
5047 expectedError: ":DECODE_ERROR:",
5048 })
5049 }
5050
5051 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5052 // are ignored.
5053 if ver.hasDTLS {
5054 testCases = append(testCases, testCase{
5055 protocol: dtls,
5056 name: "SRTP-Client-" + ver.name,
5057 config: Config{
5058 MaxVersion: ver.version,
5059 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5060 },
5061 flags: []string{
5062 "-srtp-profiles",
5063 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5064 },
5065 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5066 })
5067 testCases = append(testCases, testCase{
5068 protocol: dtls,
5069 testType: serverTest,
5070 name: "SRTP-Server-" + ver.name,
5071 config: Config{
5072 MaxVersion: ver.version,
5073 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5074 },
5075 flags: []string{
5076 "-srtp-profiles",
5077 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5078 },
5079 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5080 })
5081 // Test that the MKI is ignored.
5082 testCases = append(testCases, testCase{
5083 protocol: dtls,
5084 testType: serverTest,
5085 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5086 config: Config{
5087 MaxVersion: ver.version,
5088 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5089 Bugs: ProtocolBugs{
5090 SRTPMasterKeyIdentifer: "bogus",
5091 },
5092 },
5093 flags: []string{
5094 "-srtp-profiles",
5095 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5096 },
5097 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5098 })
5099 // Test that SRTP isn't negotiated on the server if there were
5100 // no matching profiles.
5101 testCases = append(testCases, testCase{
5102 protocol: dtls,
5103 testType: serverTest,
5104 name: "SRTP-Server-NoMatch-" + ver.name,
5105 config: Config{
5106 MaxVersion: ver.version,
5107 SRTPProtectionProfiles: []uint16{100, 101, 102},
5108 },
5109 flags: []string{
5110 "-srtp-profiles",
5111 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5112 },
5113 expectedSRTPProtectionProfile: 0,
5114 })
5115 // Test that the server returning an invalid SRTP profile is
5116 // flagged as an error by the client.
5117 testCases = append(testCases, testCase{
5118 protocol: dtls,
5119 name: "SRTP-Client-NoMatch-" + ver.name,
5120 config: Config{
5121 MaxVersion: ver.version,
5122 Bugs: ProtocolBugs{
5123 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5124 },
5125 },
5126 flags: []string{
5127 "-srtp-profiles",
5128 "SRTP_AES128_CM_SHA1_80",
5129 },
5130 shouldFail: true,
5131 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5132 })
5133 }
5134
5135 // Test SCT list.
5136 testCases = append(testCases, testCase{
5137 name: "SignedCertificateTimestampList-Client-" + ver.name,
5138 testType: clientTest,
5139 config: Config{
5140 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005141 },
David Benjamin97d17d92016-07-14 16:12:00 -04005142 flags: []string{
5143 "-enable-signed-cert-timestamps",
5144 "-expect-signed-cert-timestamps",
5145 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005146 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005147 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005148 })
David Benjamindaa88502016-10-04 16:32:16 -04005149
Adam Langleycfa08c32016-11-17 13:21:27 -08005150 var differentSCTList []byte
5151 differentSCTList = append(differentSCTList, testSCTList...)
5152 differentSCTList[len(differentSCTList)-1] ^= 1
5153
David Benjamindaa88502016-10-04 16:32:16 -04005154 // The SCT extension did not specify that it must only be sent on resumption as it
5155 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005156 testCases = append(testCases, testCase{
5157 name: "SendSCTListOnResume-" + ver.name,
5158 config: Config{
5159 MaxVersion: ver.version,
5160 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005161 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005162 },
David Benjamind98452d2015-06-16 14:16:23 -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
David Benjamin97d17d92016-07-14 16:12:00 -04005172 testCases = append(testCases, testCase{
5173 name: "SignedCertificateTimestampList-Server-" + ver.name,
5174 testType: serverTest,
5175 config: Config{
5176 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005177 },
David Benjamin97d17d92016-07-14 16:12:00 -04005178 flags: []string{
5179 "-signed-cert-timestamps",
5180 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005181 },
David Benjamin97d17d92016-07-14 16:12:00 -04005182 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005183 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005184 })
David Benjamin53210cb2016-11-16 09:01:48 +09005185
Adam Langleycfa08c32016-11-17 13:21:27 -08005186 emptySCTListCert := *testCerts[0].cert
5187 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5188
5189 // Test empty SCT list.
5190 testCases = append(testCases, testCase{
5191 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5192 testType: clientTest,
5193 config: Config{
5194 MaxVersion: ver.version,
5195 Certificates: []Certificate{emptySCTListCert},
5196 },
5197 flags: []string{
5198 "-enable-signed-cert-timestamps",
5199 },
5200 shouldFail: true,
5201 expectedError: ":ERROR_PARSING_EXTENSION:",
5202 })
5203
5204 emptySCTCert := *testCerts[0].cert
5205 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5206
5207 // Test empty SCT in non-empty list.
5208 testCases = append(testCases, testCase{
5209 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5210 testType: clientTest,
5211 config: Config{
5212 MaxVersion: ver.version,
5213 Certificates: []Certificate{emptySCTCert},
5214 },
5215 flags: []string{
5216 "-enable-signed-cert-timestamps",
5217 },
5218 shouldFail: true,
5219 expectedError: ":ERROR_PARSING_EXTENSION:",
5220 })
5221
David Benjamin53210cb2016-11-16 09:01:48 +09005222 // Test that certificate-related extensions are not sent unsolicited.
5223 testCases = append(testCases, testCase{
5224 testType: serverTest,
5225 name: "UnsolicitedCertificateExtensions-" + ver.name,
5226 config: Config{
5227 MaxVersion: ver.version,
5228 Bugs: ProtocolBugs{
5229 NoOCSPStapling: true,
5230 NoSignedCertificateTimestamps: true,
5231 },
5232 },
5233 flags: []string{
5234 "-ocsp-response",
5235 base64.StdEncoding.EncodeToString(testOCSPResponse),
5236 "-signed-cert-timestamps",
5237 base64.StdEncoding.EncodeToString(testSCTList),
5238 },
5239 })
David Benjamin97d17d92016-07-14 16:12:00 -04005240 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005241
Paul Lietar4fac72e2015-09-09 13:44:55 +01005242 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005243 testType: clientTest,
5244 name: "ClientHelloPadding",
5245 config: Config{
5246 Bugs: ProtocolBugs{
5247 RequireClientHelloSize: 512,
5248 },
5249 },
5250 // This hostname just needs to be long enough to push the
5251 // ClientHello into F5's danger zone between 256 and 511 bytes
5252 // long.
5253 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5254 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005255
5256 // Extensions should not function in SSL 3.0.
5257 testCases = append(testCases, testCase{
5258 testType: serverTest,
5259 name: "SSLv3Extensions-NoALPN",
5260 config: Config{
5261 MaxVersion: VersionSSL30,
5262 NextProtos: []string{"foo", "bar", "baz"},
5263 },
5264 flags: []string{
5265 "-select-alpn", "foo",
5266 },
5267 expectNoNextProto: true,
5268 })
5269
5270 // Test session tickets separately as they follow a different codepath.
5271 testCases = append(testCases, testCase{
5272 testType: serverTest,
5273 name: "SSLv3Extensions-NoTickets",
5274 config: Config{
5275 MaxVersion: VersionSSL30,
5276 Bugs: ProtocolBugs{
5277 // Historically, session tickets in SSL 3.0
5278 // failed in different ways depending on whether
5279 // the client supported renegotiation_info.
5280 NoRenegotiationInfo: true,
5281 },
5282 },
5283 resumeSession: true,
5284 })
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "SSLv3Extensions-NoTickets2",
5288 config: Config{
5289 MaxVersion: VersionSSL30,
5290 },
5291 resumeSession: true,
5292 })
5293
5294 // But SSL 3.0 does send and process renegotiation_info.
5295 testCases = append(testCases, testCase{
5296 testType: serverTest,
5297 name: "SSLv3Extensions-RenegotiationInfo",
5298 config: Config{
5299 MaxVersion: VersionSSL30,
5300 Bugs: ProtocolBugs{
5301 RequireRenegotiationInfo: true,
5302 },
5303 },
5304 })
5305 testCases = append(testCases, testCase{
5306 testType: serverTest,
5307 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5308 config: Config{
5309 MaxVersion: VersionSSL30,
5310 Bugs: ProtocolBugs{
5311 NoRenegotiationInfo: true,
5312 SendRenegotiationSCSV: true,
5313 RequireRenegotiationInfo: true,
5314 },
5315 },
5316 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005317
5318 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5319 // in ServerHello.
5320 testCases = append(testCases, testCase{
5321 name: "NPN-Forbidden-TLS13",
5322 config: Config{
5323 MaxVersion: VersionTLS13,
5324 NextProtos: []string{"foo"},
5325 Bugs: ProtocolBugs{
5326 NegotiateNPNAtAllVersions: true,
5327 },
5328 },
5329 flags: []string{"-select-next-proto", "foo"},
5330 shouldFail: true,
5331 expectedError: ":ERROR_PARSING_EXTENSION:",
5332 })
5333 testCases = append(testCases, testCase{
5334 name: "EMS-Forbidden-TLS13",
5335 config: Config{
5336 MaxVersion: VersionTLS13,
5337 Bugs: ProtocolBugs{
5338 NegotiateEMSAtAllVersions: true,
5339 },
5340 },
5341 shouldFail: true,
5342 expectedError: ":ERROR_PARSING_EXTENSION:",
5343 })
5344 testCases = append(testCases, testCase{
5345 name: "RenegotiationInfo-Forbidden-TLS13",
5346 config: Config{
5347 MaxVersion: VersionTLS13,
5348 Bugs: ProtocolBugs{
5349 NegotiateRenegotiationInfoAtAllVersions: true,
5350 },
5351 },
5352 shouldFail: true,
5353 expectedError: ":ERROR_PARSING_EXTENSION:",
5354 })
5355 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005356 name: "Ticket-Forbidden-TLS13",
5357 config: Config{
5358 MaxVersion: VersionTLS12,
5359 },
5360 resumeConfig: &Config{
5361 MaxVersion: VersionTLS13,
5362 Bugs: ProtocolBugs{
5363 AdvertiseTicketExtension: true,
5364 },
5365 },
5366 resumeSession: true,
5367 shouldFail: true,
5368 expectedError: ":ERROR_PARSING_EXTENSION:",
5369 })
5370
5371 // Test that illegal extensions in TLS 1.3 are declined by the server if
5372 // offered in ClientHello. The runner's server will fail if this occurs,
5373 // so we exercise the offering path. (EMS and Renegotiation Info are
5374 // implicit in every test.)
5375 testCases = append(testCases, testCase{
5376 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005377 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005378 config: Config{
5379 MaxVersion: VersionTLS13,
5380 NextProtos: []string{"bar"},
5381 },
5382 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5383 })
David Benjamin196df5b2016-09-21 16:23:27 -04005384
David Benjamindaa88502016-10-04 16:32:16 -04005385 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5386 // tolerated.
5387 testCases = append(testCases, testCase{
5388 name: "SendOCSPResponseOnResume-TLS12",
5389 config: Config{
5390 MaxVersion: VersionTLS12,
5391 Bugs: ProtocolBugs{
5392 SendOCSPResponseOnResume: []byte("bogus"),
5393 },
5394 },
5395 flags: []string{
5396 "-enable-ocsp-stapling",
5397 "-expect-ocsp-response",
5398 base64.StdEncoding.EncodeToString(testOCSPResponse),
5399 },
5400 resumeSession: true,
5401 })
5402
David Benjamindaa88502016-10-04 16:32:16 -04005403 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005404 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005405 config: Config{
5406 MaxVersion: VersionTLS13,
5407 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005408 SendExtensionOnCertificate: testOCSPExtension,
5409 },
5410 },
5411 shouldFail: true,
5412 expectedError: ":UNEXPECTED_EXTENSION:",
5413 })
5414
5415 testCases = append(testCases, testCase{
5416 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5417 config: Config{
5418 MaxVersion: VersionTLS13,
5419 Bugs: ProtocolBugs{
5420 SendExtensionOnCertificate: testSCTExtension,
5421 },
5422 },
5423 shouldFail: true,
5424 expectedError: ":UNEXPECTED_EXTENSION:",
5425 })
5426
5427 // Test that extensions on client certificates are never accepted.
5428 testCases = append(testCases, testCase{
5429 name: "SendExtensionOnClientCertificate-TLS13",
5430 testType: serverTest,
5431 config: Config{
5432 MaxVersion: VersionTLS13,
5433 Certificates: []Certificate{rsaCertificate},
5434 Bugs: ProtocolBugs{
5435 SendExtensionOnCertificate: testOCSPExtension,
5436 },
5437 },
5438 flags: []string{
5439 "-enable-ocsp-stapling",
5440 "-require-any-client-certificate",
5441 },
5442 shouldFail: true,
5443 expectedError: ":UNEXPECTED_EXTENSION:",
5444 })
5445
5446 testCases = append(testCases, testCase{
5447 name: "SendUnknownExtensionOnCertificate-TLS13",
5448 config: Config{
5449 MaxVersion: VersionTLS13,
5450 Bugs: ProtocolBugs{
5451 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5452 },
5453 },
5454 shouldFail: true,
5455 expectedError: ":UNEXPECTED_EXTENSION:",
5456 })
5457
Adam Langleycfa08c32016-11-17 13:21:27 -08005458 var differentSCTList []byte
5459 differentSCTList = append(differentSCTList, testSCTList...)
5460 differentSCTList[len(differentSCTList)-1] ^= 1
5461
Steven Valdeza833c352016-11-01 13:39:36 -04005462 // Test that extensions on intermediates are allowed but ignored.
5463 testCases = append(testCases, testCase{
5464 name: "IgnoreExtensionsOnIntermediates-TLS13",
5465 config: Config{
5466 MaxVersion: VersionTLS13,
5467 Certificates: []Certificate{rsaChainCertificate},
5468 Bugs: ProtocolBugs{
5469 // Send different values on the intermediate. This tests
5470 // the intermediate's extensions do not override the
5471 // leaf's.
5472 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005473 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005474 },
5475 },
5476 flags: []string{
5477 "-enable-ocsp-stapling",
5478 "-expect-ocsp-response",
5479 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005480 "-enable-signed-cert-timestamps",
5481 "-expect-signed-cert-timestamps",
5482 base64.StdEncoding.EncodeToString(testSCTList),
5483 },
5484 resumeSession: true,
5485 })
5486
5487 // Test that extensions are not sent on intermediates when configured
5488 // only for a leaf.
5489 testCases = append(testCases, testCase{
5490 testType: serverTest,
5491 name: "SendNoExtensionsOnIntermediate-TLS13",
5492 config: Config{
5493 MaxVersion: VersionTLS13,
5494 Bugs: ProtocolBugs{
5495 ExpectNoExtensionsOnIntermediate: true,
5496 },
5497 },
5498 flags: []string{
5499 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5500 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5501 "-ocsp-response",
5502 base64.StdEncoding.EncodeToString(testOCSPResponse),
5503 "-signed-cert-timestamps",
5504 base64.StdEncoding.EncodeToString(testSCTList),
5505 },
5506 })
5507
5508 // Test that extensions are not sent on client certificates.
5509 testCases = append(testCases, testCase{
5510 name: "SendNoClientCertificateExtensions-TLS13",
5511 config: Config{
5512 MaxVersion: VersionTLS13,
5513 ClientAuth: RequireAnyClientCert,
5514 },
5515 flags: []string{
5516 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5517 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5518 "-ocsp-response",
5519 base64.StdEncoding.EncodeToString(testOCSPResponse),
5520 "-signed-cert-timestamps",
5521 base64.StdEncoding.EncodeToString(testSCTList),
5522 },
5523 })
5524
5525 testCases = append(testCases, testCase{
5526 name: "SendDuplicateExtensionsOnCerts-TLS13",
5527 config: Config{
5528 MaxVersion: VersionTLS13,
5529 Bugs: ProtocolBugs{
5530 SendDuplicateCertExtensions: true,
5531 },
5532 },
5533 flags: []string{
5534 "-enable-ocsp-stapling",
5535 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005536 },
5537 resumeSession: true,
5538 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005539 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005540 })
Adam Langley9b885c52016-11-18 14:21:03 -08005541
5542 testCases = append(testCases, testCase{
5543 name: "SignedCertificateTimestampListInvalid-Server",
5544 testType: serverTest,
5545 flags: []string{
5546 "-signed-cert-timestamps",
5547 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5548 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005549 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005550 expectedError: ":INVALID_SCT_LIST:",
5551 })
David Benjamine78bfde2014-09-06 12:45:15 -04005552}
5553
David Benjamin01fe8202014-09-24 15:21:44 -04005554func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005555 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005556 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005557 // SSL 3.0 does not have tickets and TLS 1.3 does not
5558 // have session IDs, so skip their cross-resumption
5559 // tests.
5560 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5561 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5562 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005563 }
5564
David Benjamin8b8c0062014-11-23 02:47:52 -05005565 protocols := []protocol{tls}
5566 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5567 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005568 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005569 for _, protocol := range protocols {
5570 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5571 if protocol == dtls {
5572 suffix += "-DTLS"
5573 }
5574
David Benjaminece3de92015-03-16 18:02:20 -04005575 if sessionVers.version == resumeVers.version {
5576 testCases = append(testCases, testCase{
5577 protocol: protocol,
5578 name: "Resume-Client" + suffix,
5579 resumeSession: true,
5580 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005581 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005582 Bugs: ProtocolBugs{
5583 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5584 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5585 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005586 },
David Benjaminece3de92015-03-16 18:02:20 -04005587 expectedVersion: sessionVers.version,
5588 expectedResumeVersion: resumeVers.version,
5589 })
5590 } else {
David Benjamin405da482016-08-08 17:25:07 -04005591 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5592
5593 // Offering a TLS 1.3 session sends an empty session ID, so
5594 // there is no way to convince a non-lookahead client the
5595 // session was resumed. It will appear to the client that a
5596 // stray ChangeCipherSpec was sent.
5597 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5598 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005599 }
5600
David Benjaminece3de92015-03-16 18:02:20 -04005601 testCases = append(testCases, testCase{
5602 protocol: protocol,
5603 name: "Resume-Client-Mismatch" + suffix,
5604 resumeSession: true,
5605 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005606 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005607 },
David Benjaminece3de92015-03-16 18:02:20 -04005608 expectedVersion: sessionVers.version,
5609 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005610 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005611 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005612 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005613 },
5614 },
5615 expectedResumeVersion: resumeVers.version,
5616 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005617 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005618 })
5619 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005620
5621 testCases = append(testCases, testCase{
5622 protocol: protocol,
5623 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005624 resumeSession: true,
5625 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005626 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005627 },
5628 expectedVersion: sessionVers.version,
5629 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005630 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005631 },
5632 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005633 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005634 expectedResumeVersion: resumeVers.version,
5635 })
5636
David Benjamin8b8c0062014-11-23 02:47:52 -05005637 testCases = append(testCases, testCase{
5638 protocol: protocol,
5639 testType: serverTest,
5640 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005641 resumeSession: true,
5642 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005643 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005644 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005645 expectedVersion: sessionVers.version,
5646 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005647 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005648 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005649 Bugs: ProtocolBugs{
5650 SendBothTickets: true,
5651 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005652 },
5653 expectedResumeVersion: resumeVers.version,
5654 })
5655 }
David Benjamin01fe8202014-09-24 15:21:44 -04005656 }
5657 }
David Benjaminece3de92015-03-16 18:02:20 -04005658
David Benjamin4199b0d2016-11-01 13:58:25 -04005659 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005660 testCases = append(testCases, testCase{
5661 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005662 name: "ShimTicketRewritable",
5663 resumeSession: true,
5664 config: Config{
5665 MaxVersion: VersionTLS12,
5666 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5667 Bugs: ProtocolBugs{
5668 FilterTicket: func(in []byte) ([]byte, error) {
5669 in, err := SetShimTicketVersion(in, VersionTLS12)
5670 if err != nil {
5671 return nil, err
5672 }
5673 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5674 },
5675 },
5676 },
5677 flags: []string{
5678 "-ticket-key",
5679 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5680 },
5681 })
5682
5683 // Resumptions are declined if the version does not match.
5684 testCases = append(testCases, testCase{
5685 testType: serverTest,
5686 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005687 resumeSession: true,
5688 config: Config{
5689 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005690 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005691 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005692 FilterTicket: func(in []byte) ([]byte, error) {
5693 return SetShimTicketVersion(in, VersionTLS13)
5694 },
5695 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005696 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005697 flags: []string{
5698 "-ticket-key",
5699 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5700 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005701 expectResumeRejected: true,
5702 })
5703
5704 testCases = append(testCases, testCase{
5705 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005706 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005707 resumeSession: true,
5708 config: Config{
5709 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005710 Bugs: ProtocolBugs{
5711 FilterTicket: func(in []byte) ([]byte, error) {
5712 return SetShimTicketVersion(in, VersionTLS12)
5713 },
5714 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005715 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005716 flags: []string{
5717 "-ticket-key",
5718 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5719 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005720 expectResumeRejected: true,
5721 })
5722
David Benjamin4199b0d2016-11-01 13:58:25 -04005723 // Resumptions are declined if the cipher is invalid or disabled.
5724 testCases = append(testCases, testCase{
5725 testType: serverTest,
5726 name: "Resume-Server-DeclineBadCipher",
5727 resumeSession: true,
5728 config: Config{
5729 MaxVersion: VersionTLS12,
5730 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005731 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005732 FilterTicket: func(in []byte) ([]byte, error) {
5733 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5734 },
5735 },
5736 },
5737 flags: []string{
5738 "-ticket-key",
5739 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5740 },
5741 expectResumeRejected: true,
5742 })
5743
5744 testCases = append(testCases, testCase{
5745 testType: serverTest,
5746 name: "Resume-Server-DeclineBadCipher-2",
5747 resumeSession: true,
5748 config: Config{
5749 MaxVersion: VersionTLS12,
5750 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005751 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005752 FilterTicket: func(in []byte) ([]byte, error) {
5753 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5754 },
5755 },
5756 },
5757 flags: []string{
5758 "-cipher", "AES128",
5759 "-ticket-key",
5760 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5761 },
5762 expectResumeRejected: true,
5763 })
5764
David Benjaminf01f42a2016-11-16 19:05:33 +09005765 // Sessions are not resumed if they do not use the preferred cipher.
5766 testCases = append(testCases, testCase{
5767 testType: serverTest,
5768 name: "Resume-Server-CipherNotPreferred",
5769 resumeSession: true,
5770 config: Config{
5771 MaxVersion: VersionTLS12,
5772 Bugs: ProtocolBugs{
5773 ExpectNewTicket: true,
5774 FilterTicket: func(in []byte) ([]byte, error) {
5775 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5776 },
5777 },
5778 },
5779 flags: []string{
5780 "-ticket-key",
5781 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5782 },
5783 shouldFail: false,
5784 expectResumeRejected: true,
5785 })
5786
5787 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5788 // PRF hashes match, but BoringSSL will always decline such resumptions.
5789 testCases = append(testCases, testCase{
5790 testType: serverTest,
5791 name: "Resume-Server-CipherNotPreferred-TLS13",
5792 resumeSession: true,
5793 config: Config{
5794 MaxVersion: VersionTLS13,
5795 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5796 Bugs: ProtocolBugs{
5797 FilterTicket: func(in []byte) ([]byte, error) {
5798 // If the client (runner) offers ChaCha20-Poly1305 first, the
5799 // server (shim) always prefers it. Switch it to AES-GCM.
5800 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5801 },
5802 },
5803 },
5804 flags: []string{
5805 "-ticket-key",
5806 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5807 },
5808 shouldFail: false,
5809 expectResumeRejected: true,
5810 })
5811
5812 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005813 testCases = append(testCases, testCase{
5814 testType: serverTest,
5815 name: "Resume-Server-DeclineBadCipher-TLS13",
5816 resumeSession: true,
5817 config: Config{
5818 MaxVersion: VersionTLS13,
5819 Bugs: ProtocolBugs{
5820 FilterTicket: func(in []byte) ([]byte, error) {
5821 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5822 },
5823 },
5824 },
5825 flags: []string{
5826 "-ticket-key",
5827 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5828 },
5829 expectResumeRejected: true,
5830 })
5831
David Benjaminf01f42a2016-11-16 19:05:33 +09005832 // If the client does not offer the cipher from the session, decline to
5833 // resume. Clients are forbidden from doing this, but BoringSSL selects
5834 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005835 testCases = append(testCases, testCase{
5836 testType: serverTest,
5837 name: "Resume-Server-UnofferedCipher",
5838 resumeSession: true,
5839 config: Config{
5840 MaxVersion: VersionTLS12,
5841 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5842 },
5843 resumeConfig: &Config{
5844 MaxVersion: VersionTLS12,
5845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5846 Bugs: ProtocolBugs{
5847 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5848 },
5849 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005850 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005851 })
5852
David Benjaminf01f42a2016-11-16 19:05:33 +09005853 // In TLS 1.3, clients may advertise a cipher list which does not
5854 // include the selected cipher. Test that we tolerate this. Servers may
5855 // resume at another cipher if the PRF matches, but BoringSSL will
5856 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "Resume-Server-UnofferedCipher-TLS13",
5860 resumeSession: true,
5861 config: Config{
5862 MaxVersion: VersionTLS13,
5863 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5864 },
5865 resumeConfig: &Config{
5866 MaxVersion: VersionTLS13,
5867 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5868 Bugs: ProtocolBugs{
5869 SendCipherSuites: []uint16{TLS_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 Benjamin4199b0d2016-11-01 13:58:25 -04005875 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005876 testCases = append(testCases, testCase{
5877 name: "Resume-Client-CipherMismatch",
5878 resumeSession: true,
5879 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005880 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005881 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5882 },
5883 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005884 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005885 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5886 Bugs: ProtocolBugs{
5887 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5888 },
5889 },
5890 shouldFail: true,
5891 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5892 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005893
David Benjamine1cc35e2016-11-16 16:25:58 +09005894 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5895 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005896 testCases = append(testCases, testCase{
5897 name: "Resume-Client-CipherMismatch-TLS13",
5898 resumeSession: true,
5899 config: Config{
5900 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005901 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005902 },
5903 resumeConfig: &Config{
5904 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005905 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5906 },
5907 })
5908
5909 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5910 testCases = append(testCases, testCase{
5911 name: "Resume-Client-PRFMismatch-TLS13",
5912 resumeSession: true,
5913 config: Config{
5914 MaxVersion: VersionTLS13,
5915 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5916 },
5917 resumeConfig: &Config{
5918 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005919 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005920 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005921 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005922 },
5923 },
5924 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005925 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005926 })
Steven Valdeza833c352016-11-01 13:39:36 -04005927
5928 testCases = append(testCases, testCase{
5929 testType: serverTest,
5930 name: "Resume-Server-BinderWrongLength",
5931 resumeSession: true,
5932 config: Config{
5933 MaxVersion: VersionTLS13,
5934 Bugs: ProtocolBugs{
5935 SendShortPSKBinder: true,
5936 },
5937 },
5938 shouldFail: true,
5939 expectedLocalError: "remote error: error decrypting message",
5940 expectedError: ":DIGEST_CHECK_FAILED:",
5941 })
5942
5943 testCases = append(testCases, testCase{
5944 testType: serverTest,
5945 name: "Resume-Server-NoPSKBinder",
5946 resumeSession: true,
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 Bugs: ProtocolBugs{
5950 SendNoPSKBinder: true,
5951 },
5952 },
5953 shouldFail: true,
5954 expectedLocalError: "remote error: error decoding message",
5955 expectedError: ":DECODE_ERROR:",
5956 })
5957
5958 testCases = append(testCases, testCase{
5959 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005960 name: "Resume-Server-ExtraPSKBinder",
5961 resumeSession: true,
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 Bugs: ProtocolBugs{
5965 SendExtraPSKBinder: true,
5966 },
5967 },
5968 shouldFail: true,
5969 expectedLocalError: "remote error: illegal parameter",
5970 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5971 })
5972
5973 testCases = append(testCases, testCase{
5974 testType: serverTest,
5975 name: "Resume-Server-ExtraIdentityNoBinder",
5976 resumeSession: true,
5977 config: Config{
5978 MaxVersion: VersionTLS13,
5979 Bugs: ProtocolBugs{
5980 ExtraPSKIdentity: true,
5981 },
5982 },
5983 shouldFail: true,
5984 expectedLocalError: "remote error: illegal parameter",
5985 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5986 })
5987
5988 testCases = append(testCases, testCase{
5989 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04005990 name: "Resume-Server-InvalidPSKBinder",
5991 resumeSession: true,
5992 config: Config{
5993 MaxVersion: VersionTLS13,
5994 Bugs: ProtocolBugs{
5995 SendInvalidPSKBinder: true,
5996 },
5997 },
5998 shouldFail: true,
5999 expectedLocalError: "remote error: error decrypting message",
6000 expectedError: ":DIGEST_CHECK_FAILED:",
6001 })
6002
6003 testCases = append(testCases, testCase{
6004 testType: serverTest,
6005 name: "Resume-Server-PSKBinderFirstExtension",
6006 resumeSession: true,
6007 config: Config{
6008 MaxVersion: VersionTLS13,
6009 Bugs: ProtocolBugs{
6010 PSKBinderFirst: true,
6011 },
6012 },
6013 shouldFail: true,
6014 expectedLocalError: "remote error: illegal parameter",
6015 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6016 })
David Benjamin01fe8202014-09-24 15:21:44 -04006017}
6018
Adam Langley2ae77d22014-10-28 17:29:33 -07006019func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006020 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006021 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006022 testType: serverTest,
6023 name: "Renegotiate-Server-Forbidden",
6024 config: Config{
6025 MaxVersion: VersionTLS12,
6026 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006027 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006028 shouldFail: true,
6029 expectedError: ":NO_RENEGOTIATION:",
6030 expectedLocalError: "remote error: no renegotiation",
6031 })
Adam Langley5021b222015-06-12 18:27:58 -07006032 // The server shouldn't echo the renegotiation extension unless
6033 // requested by the client.
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "Renegotiate-Server-NoExt",
6037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006038 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006039 Bugs: ProtocolBugs{
6040 NoRenegotiationInfo: true,
6041 RequireRenegotiationInfo: true,
6042 },
6043 },
6044 shouldFail: true,
6045 expectedLocalError: "renegotiation extension missing",
6046 })
6047 // The renegotiation SCSV should be sufficient for the server to echo
6048 // the extension.
6049 testCases = append(testCases, testCase{
6050 testType: serverTest,
6051 name: "Renegotiate-Server-NoExt-SCSV",
6052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006053 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006054 Bugs: ProtocolBugs{
6055 NoRenegotiationInfo: true,
6056 SendRenegotiationSCSV: true,
6057 RequireRenegotiationInfo: true,
6058 },
6059 },
6060 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006061 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006062 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006064 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006065 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006066 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006067 },
6068 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006069 renegotiate: 1,
6070 flags: []string{
6071 "-renegotiate-freely",
6072 "-expect-total-renegotiations", "1",
6073 },
David Benjamincdea40c2015-03-19 14:09:43 -04006074 })
6075 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006076 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006077 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006079 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006080 Bugs: ProtocolBugs{
6081 EmptyRenegotiationInfo: true,
6082 },
6083 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006084 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006085 shouldFail: true,
6086 expectedError: ":RENEGOTIATION_MISMATCH:",
6087 })
6088 testCases = append(testCases, testCase{
6089 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006090 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006092 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006093 Bugs: ProtocolBugs{
6094 BadRenegotiationInfo: true,
6095 },
6096 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006097 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006098 shouldFail: true,
6099 expectedError: ":RENEGOTIATION_MISMATCH:",
6100 })
6101 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006102 name: "Renegotiate-Client-Downgrade",
6103 renegotiate: 1,
6104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006105 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006106 Bugs: ProtocolBugs{
6107 NoRenegotiationInfoAfterInitial: true,
6108 },
6109 },
6110 flags: []string{"-renegotiate-freely"},
6111 shouldFail: true,
6112 expectedError: ":RENEGOTIATION_MISMATCH:",
6113 })
6114 testCases = append(testCases, testCase{
6115 name: "Renegotiate-Client-Upgrade",
6116 renegotiate: 1,
6117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006118 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006119 Bugs: ProtocolBugs{
6120 NoRenegotiationInfoInInitial: true,
6121 },
6122 },
6123 flags: []string{"-renegotiate-freely"},
6124 shouldFail: true,
6125 expectedError: ":RENEGOTIATION_MISMATCH:",
6126 })
6127 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006128 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006129 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006131 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006132 Bugs: ProtocolBugs{
6133 NoRenegotiationInfo: true,
6134 },
6135 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006136 flags: []string{
6137 "-renegotiate-freely",
6138 "-expect-total-renegotiations", "1",
6139 },
David Benjamincff0b902015-05-15 23:09:47 -04006140 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006141
6142 // Test that the server may switch ciphers on renegotiation without
6143 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006144 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006145 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006146 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006147 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006148 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006149 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006150 },
6151 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006152 flags: []string{
6153 "-renegotiate-freely",
6154 "-expect-total-renegotiations", "1",
6155 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006156 })
6157 testCases = append(testCases, testCase{
6158 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006159 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006160 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006161 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6163 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006164 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006165 flags: []string{
6166 "-renegotiate-freely",
6167 "-expect-total-renegotiations", "1",
6168 },
David Benjaminb16346b2015-04-08 19:16:58 -04006169 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006170
6171 // Test that the server may not switch versions on renegotiation.
6172 testCases = append(testCases, testCase{
6173 name: "Renegotiate-Client-SwitchVersion",
6174 config: Config{
6175 MaxVersion: VersionTLS12,
6176 // Pick a cipher which exists at both versions.
6177 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6178 Bugs: ProtocolBugs{
6179 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006180 // Avoid failing early at the record layer.
6181 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006182 },
6183 },
6184 renegotiate: 1,
6185 flags: []string{
6186 "-renegotiate-freely",
6187 "-expect-total-renegotiations", "1",
6188 },
6189 shouldFail: true,
6190 expectedError: ":WRONG_SSL_VERSION:",
6191 })
6192
David Benjaminb16346b2015-04-08 19:16:58 -04006193 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006194 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006195 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006196 config: Config{
6197 MaxVersion: VersionTLS10,
6198 Bugs: ProtocolBugs{
6199 RequireSameRenegoClientVersion: true,
6200 },
6201 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006202 flags: []string{
6203 "-renegotiate-freely",
6204 "-expect-total-renegotiations", "1",
6205 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006206 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006207 testCases = append(testCases, testCase{
6208 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006209 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006210 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006211 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006212 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6213 NextProtos: []string{"foo"},
6214 },
6215 flags: []string{
6216 "-false-start",
6217 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006218 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006219 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006220 },
6221 shimWritesFirst: true,
6222 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006223
6224 // Client-side renegotiation controls.
6225 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006226 name: "Renegotiate-Client-Forbidden-1",
6227 config: Config{
6228 MaxVersion: VersionTLS12,
6229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006230 renegotiate: 1,
6231 shouldFail: true,
6232 expectedError: ":NO_RENEGOTIATION:",
6233 expectedLocalError: "remote error: no renegotiation",
6234 })
6235 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006236 name: "Renegotiate-Client-Once-1",
6237 config: Config{
6238 MaxVersion: VersionTLS12,
6239 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006240 renegotiate: 1,
6241 flags: []string{
6242 "-renegotiate-once",
6243 "-expect-total-renegotiations", "1",
6244 },
6245 })
6246 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006247 name: "Renegotiate-Client-Freely-1",
6248 config: Config{
6249 MaxVersion: VersionTLS12,
6250 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006251 renegotiate: 1,
6252 flags: []string{
6253 "-renegotiate-freely",
6254 "-expect-total-renegotiations", "1",
6255 },
6256 })
6257 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006258 name: "Renegotiate-Client-Once-2",
6259 config: Config{
6260 MaxVersion: VersionTLS12,
6261 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006262 renegotiate: 2,
6263 flags: []string{"-renegotiate-once"},
6264 shouldFail: true,
6265 expectedError: ":NO_RENEGOTIATION:",
6266 expectedLocalError: "remote error: no renegotiation",
6267 })
6268 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006269 name: "Renegotiate-Client-Freely-2",
6270 config: Config{
6271 MaxVersion: VersionTLS12,
6272 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006273 renegotiate: 2,
6274 flags: []string{
6275 "-renegotiate-freely",
6276 "-expect-total-renegotiations", "2",
6277 },
6278 })
Adam Langley27a0d082015-11-03 13:34:10 -08006279 testCases = append(testCases, testCase{
6280 name: "Renegotiate-Client-NoIgnore",
6281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006282 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006283 Bugs: ProtocolBugs{
6284 SendHelloRequestBeforeEveryAppDataRecord: true,
6285 },
6286 },
6287 shouldFail: true,
6288 expectedError: ":NO_RENEGOTIATION:",
6289 })
6290 testCases = append(testCases, testCase{
6291 name: "Renegotiate-Client-Ignore",
6292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006293 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006294 Bugs: ProtocolBugs{
6295 SendHelloRequestBeforeEveryAppDataRecord: true,
6296 },
6297 },
6298 flags: []string{
6299 "-renegotiate-ignore",
6300 "-expect-total-renegotiations", "0",
6301 },
6302 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006303
David Benjamin34941c02016-10-08 11:45:31 -04006304 // Renegotiation is not allowed at SSL 3.0.
6305 testCases = append(testCases, testCase{
6306 name: "Renegotiate-Client-SSL3",
6307 config: Config{
6308 MaxVersion: VersionSSL30,
6309 },
6310 renegotiate: 1,
6311 flags: []string{
6312 "-renegotiate-freely",
6313 "-expect-total-renegotiations", "1",
6314 },
6315 shouldFail: true,
6316 expectedError: ":NO_RENEGOTIATION:",
6317 expectedLocalError: "remote error: no renegotiation",
6318 })
6319
David Benjamin397c8e62016-07-08 14:14:36 -07006320 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006321 testCases = append(testCases, testCase{
6322 name: "StrayHelloRequest",
6323 config: Config{
6324 MaxVersion: VersionTLS12,
6325 Bugs: ProtocolBugs{
6326 SendHelloRequestBeforeEveryHandshakeMessage: true,
6327 },
6328 },
6329 })
6330 testCases = append(testCases, testCase{
6331 name: "StrayHelloRequest-Packed",
6332 config: Config{
6333 MaxVersion: VersionTLS12,
6334 Bugs: ProtocolBugs{
6335 PackHandshakeFlight: true,
6336 SendHelloRequestBeforeEveryHandshakeMessage: true,
6337 },
6338 },
6339 })
6340
David Benjamin12d2c482016-07-24 10:56:51 -04006341 // Test renegotiation works if HelloRequest and server Finished come in
6342 // the same record.
6343 testCases = append(testCases, testCase{
6344 name: "Renegotiate-Client-Packed",
6345 config: Config{
6346 MaxVersion: VersionTLS12,
6347 Bugs: ProtocolBugs{
6348 PackHandshakeFlight: true,
6349 PackHelloRequestWithFinished: true,
6350 },
6351 },
6352 renegotiate: 1,
6353 flags: []string{
6354 "-renegotiate-freely",
6355 "-expect-total-renegotiations", "1",
6356 },
6357 })
6358
David Benjamin397c8e62016-07-08 14:14:36 -07006359 // Renegotiation is forbidden in TLS 1.3.
6360 testCases = append(testCases, testCase{
6361 name: "Renegotiate-Client-TLS13",
6362 config: Config{
6363 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006364 Bugs: ProtocolBugs{
6365 SendHelloRequestBeforeEveryAppDataRecord: true,
6366 },
David Benjamin397c8e62016-07-08 14:14:36 -07006367 },
David Benjamin397c8e62016-07-08 14:14:36 -07006368 flags: []string{
6369 "-renegotiate-freely",
6370 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006371 shouldFail: true,
6372 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006373 })
6374
6375 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6376 testCases = append(testCases, testCase{
6377 name: "StrayHelloRequest-TLS13",
6378 config: Config{
6379 MaxVersion: VersionTLS13,
6380 Bugs: ProtocolBugs{
6381 SendHelloRequestBeforeEveryHandshakeMessage: true,
6382 },
6383 },
6384 shouldFail: true,
6385 expectedError: ":UNEXPECTED_MESSAGE:",
6386 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006387}
6388
David Benjamin5e961c12014-11-07 01:48:35 -05006389func addDTLSReplayTests() {
6390 // Test that sequence number replays are detected.
6391 testCases = append(testCases, testCase{
6392 protocol: dtls,
6393 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006394 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006395 replayWrites: true,
6396 })
6397
David Benjamin8e6db492015-07-25 18:29:23 -04006398 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006399 // than the retransmit window.
6400 testCases = append(testCases, testCase{
6401 protocol: dtls,
6402 name: "DTLS-Replay-LargeGaps",
6403 config: Config{
6404 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006405 SequenceNumberMapping: func(in uint64) uint64 {
6406 return in * 127
6407 },
David Benjamin5e961c12014-11-07 01:48:35 -05006408 },
6409 },
David Benjamin8e6db492015-07-25 18:29:23 -04006410 messageCount: 200,
6411 replayWrites: true,
6412 })
6413
6414 // Test the incoming sequence number changing non-monotonically.
6415 testCases = append(testCases, testCase{
6416 protocol: dtls,
6417 name: "DTLS-Replay-NonMonotonic",
6418 config: Config{
6419 Bugs: ProtocolBugs{
6420 SequenceNumberMapping: func(in uint64) uint64 {
6421 return in ^ 31
6422 },
6423 },
6424 },
6425 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006426 replayWrites: true,
6427 })
6428}
6429
Nick Harper60edffd2016-06-21 15:19:24 -07006430var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006431 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006432 id signatureAlgorithm
6433 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006434}{
Nick Harper60edffd2016-06-21 15:19:24 -07006435 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6436 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6437 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6438 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006439 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006440 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6441 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6442 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006443 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6444 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6445 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006446 // Tests for key types prior to TLS 1.2.
6447 {"RSA", 0, testCertRSA},
6448 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006449}
6450
Nick Harper60edffd2016-06-21 15:19:24 -07006451const fakeSigAlg1 signatureAlgorithm = 0x2a01
6452const fakeSigAlg2 signatureAlgorithm = 0xff01
6453
6454func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006455 // Not all ciphers involve a signature. Advertise a list which gives all
6456 // versions a signing cipher.
6457 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006458 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006459 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6460 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6461 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6462 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6463 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6464 }
6465
David Benjaminca3d5452016-07-14 12:51:01 -04006466 var allAlgorithms []signatureAlgorithm
6467 for _, alg := range testSignatureAlgorithms {
6468 if alg.id != 0 {
6469 allAlgorithms = append(allAlgorithms, alg.id)
6470 }
6471 }
6472
Nick Harper60edffd2016-06-21 15:19:24 -07006473 // Make sure each signature algorithm works. Include some fake values in
6474 // the list and ensure they're ignored.
6475 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006476 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006477 if (ver.version < VersionTLS12) != (alg.id == 0) {
6478 continue
6479 }
6480
6481 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6482 // or remove it in C.
6483 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006484 continue
6485 }
Nick Harper60edffd2016-06-21 15:19:24 -07006486
David Benjamin3ef76972016-10-17 17:59:54 -04006487 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006488 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006489 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006490 shouldSignFail = true
6491 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006492 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006493 // RSA-PKCS1 does not exist in TLS 1.3.
6494 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006495 shouldSignFail = true
6496 shouldVerifyFail = true
6497 }
6498
6499 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6500 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6501 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006502 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006503
6504 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006505 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006506 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006507 }
6508 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006509 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006510 }
David Benjamin000800a2014-11-14 01:43:59 -05006511
David Benjamin1fb125c2016-07-08 18:52:12 -07006512 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006513
David Benjamin7a41d372016-07-09 11:21:54 -07006514 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006515 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006516 config: Config{
6517 MaxVersion: ver.version,
6518 ClientAuth: RequireAnyClientCert,
6519 VerifySignatureAlgorithms: []signatureAlgorithm{
6520 fakeSigAlg1,
6521 alg.id,
6522 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006523 },
David Benjamin7a41d372016-07-09 11:21:54 -07006524 },
6525 flags: []string{
6526 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6527 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6528 "-enable-all-curves",
6529 },
David Benjamin3ef76972016-10-17 17:59:54 -04006530 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006531 expectedError: signError,
6532 expectedPeerSignatureAlgorithm: alg.id,
6533 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006534
David Benjamin7a41d372016-07-09 11:21:54 -07006535 testCases = append(testCases, testCase{
6536 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006537 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006538 config: Config{
6539 MaxVersion: ver.version,
6540 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6541 SignSignatureAlgorithms: []signatureAlgorithm{
6542 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006543 },
David Benjamin7a41d372016-07-09 11:21:54 -07006544 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006545 SkipECDSACurveCheck: shouldVerifyFail,
6546 IgnoreSignatureVersionChecks: shouldVerifyFail,
6547 // Some signature algorithms may not be advertised.
6548 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006549 },
David Benjamin7a41d372016-07-09 11:21:54 -07006550 },
6551 flags: []string{
6552 "-require-any-client-certificate",
6553 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6554 "-enable-all-curves",
6555 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006556 // Resume the session to assert the peer signature
6557 // algorithm is reported on both handshakes.
6558 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006559 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006560 expectedError: verifyError,
6561 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006562
6563 testCases = append(testCases, testCase{
6564 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006565 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006566 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006567 MaxVersion: ver.version,
6568 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006569 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006570 fakeSigAlg1,
6571 alg.id,
6572 fakeSigAlg2,
6573 },
6574 },
6575 flags: []string{
6576 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6577 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6578 "-enable-all-curves",
6579 },
David Benjamin3ef76972016-10-17 17:59:54 -04006580 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006581 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006582 expectedPeerSignatureAlgorithm: alg.id,
6583 })
6584
6585 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006586 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006587 config: Config{
6588 MaxVersion: ver.version,
6589 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006590 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006591 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006592 alg.id,
6593 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006594 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006595 SkipECDSACurveCheck: shouldVerifyFail,
6596 IgnoreSignatureVersionChecks: shouldVerifyFail,
6597 // Some signature algorithms may not be advertised.
6598 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006599 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006600 },
6601 flags: []string{
6602 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6603 "-enable-all-curves",
6604 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006605 // Resume the session to assert the peer signature
6606 // algorithm is reported on both handshakes.
6607 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006608 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006609 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006610 })
David Benjamin5208fd42016-07-13 21:43:25 -04006611
David Benjamin3ef76972016-10-17 17:59:54 -04006612 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006613 testCases = append(testCases, testCase{
6614 testType: serverTest,
6615 name: "ClientAuth-InvalidSignature" + suffix,
6616 config: Config{
6617 MaxVersion: ver.version,
6618 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6619 SignSignatureAlgorithms: []signatureAlgorithm{
6620 alg.id,
6621 },
6622 Bugs: ProtocolBugs{
6623 InvalidSignature: true,
6624 },
6625 },
6626 flags: []string{
6627 "-require-any-client-certificate",
6628 "-enable-all-curves",
6629 },
6630 shouldFail: true,
6631 expectedError: ":BAD_SIGNATURE:",
6632 })
6633
6634 testCases = append(testCases, testCase{
6635 name: "ServerAuth-InvalidSignature" + suffix,
6636 config: Config{
6637 MaxVersion: ver.version,
6638 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6639 CipherSuites: signingCiphers,
6640 SignSignatureAlgorithms: []signatureAlgorithm{
6641 alg.id,
6642 },
6643 Bugs: ProtocolBugs{
6644 InvalidSignature: true,
6645 },
6646 },
6647 flags: []string{"-enable-all-curves"},
6648 shouldFail: true,
6649 expectedError: ":BAD_SIGNATURE:",
6650 })
6651 }
David Benjaminca3d5452016-07-14 12:51:01 -04006652
David Benjamin3ef76972016-10-17 17:59:54 -04006653 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006654 testCases = append(testCases, testCase{
6655 name: "ClientAuth-Sign-Negotiate" + suffix,
6656 config: Config{
6657 MaxVersion: ver.version,
6658 ClientAuth: RequireAnyClientCert,
6659 VerifySignatureAlgorithms: allAlgorithms,
6660 },
6661 flags: []string{
6662 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6663 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6664 "-enable-all-curves",
6665 "-signing-prefs", strconv.Itoa(int(alg.id)),
6666 },
6667 expectedPeerSignatureAlgorithm: alg.id,
6668 })
6669
6670 testCases = append(testCases, testCase{
6671 testType: serverTest,
6672 name: "ServerAuth-Sign-Negotiate" + suffix,
6673 config: Config{
6674 MaxVersion: ver.version,
6675 CipherSuites: signingCiphers,
6676 VerifySignatureAlgorithms: allAlgorithms,
6677 },
6678 flags: []string{
6679 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6680 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6681 "-enable-all-curves",
6682 "-signing-prefs", strconv.Itoa(int(alg.id)),
6683 },
6684 expectedPeerSignatureAlgorithm: alg.id,
6685 })
6686 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006687 }
David Benjamin000800a2014-11-14 01:43:59 -05006688 }
6689
Nick Harper60edffd2016-06-21 15:19:24 -07006690 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006691 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006692 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006693 config: Config{
6694 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006695 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006696 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006697 signatureECDSAWithP521AndSHA512,
6698 signatureRSAPKCS1WithSHA384,
6699 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006700 },
6701 },
6702 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006703 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6704 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006705 },
Nick Harper60edffd2016-06-21 15:19:24 -07006706 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006707 })
6708
6709 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006710 name: "ClientAuth-SignatureType-TLS13",
6711 config: Config{
6712 ClientAuth: RequireAnyClientCert,
6713 MaxVersion: VersionTLS13,
6714 VerifySignatureAlgorithms: []signatureAlgorithm{
6715 signatureECDSAWithP521AndSHA512,
6716 signatureRSAPKCS1WithSHA384,
6717 signatureRSAPSSWithSHA384,
6718 signatureECDSAWithSHA1,
6719 },
6720 },
6721 flags: []string{
6722 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6723 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6724 },
6725 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6726 })
6727
6728 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006729 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006730 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006732 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006733 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006734 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006735 signatureECDSAWithP521AndSHA512,
6736 signatureRSAPKCS1WithSHA384,
6737 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006738 },
6739 },
Nick Harper60edffd2016-06-21 15:19:24 -07006740 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006741 })
6742
Steven Valdez143e8b32016-07-11 13:19:03 -04006743 testCases = append(testCases, testCase{
6744 testType: serverTest,
6745 name: "ServerAuth-SignatureType-TLS13",
6746 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006747 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006748 VerifySignatureAlgorithms: []signatureAlgorithm{
6749 signatureECDSAWithP521AndSHA512,
6750 signatureRSAPKCS1WithSHA384,
6751 signatureRSAPSSWithSHA384,
6752 signatureECDSAWithSHA1,
6753 },
6754 },
6755 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6756 })
6757
David Benjamina95e9f32016-07-08 16:28:04 -07006758 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: "Verify-ClientAuth-SignatureType",
6762 config: Config{
6763 MaxVersion: VersionTLS12,
6764 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006765 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006766 signatureRSAPKCS1WithSHA256,
6767 },
6768 Bugs: ProtocolBugs{
6769 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6770 },
6771 },
6772 flags: []string{
6773 "-require-any-client-certificate",
6774 },
6775 shouldFail: true,
6776 expectedError: ":WRONG_SIGNATURE_TYPE:",
6777 })
6778
6779 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006780 testType: serverTest,
6781 name: "Verify-ClientAuth-SignatureType-TLS13",
6782 config: Config{
6783 MaxVersion: VersionTLS13,
6784 Certificates: []Certificate{rsaCertificate},
6785 SignSignatureAlgorithms: []signatureAlgorithm{
6786 signatureRSAPSSWithSHA256,
6787 },
6788 Bugs: ProtocolBugs{
6789 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6790 },
6791 },
6792 flags: []string{
6793 "-require-any-client-certificate",
6794 },
6795 shouldFail: true,
6796 expectedError: ":WRONG_SIGNATURE_TYPE:",
6797 })
6798
6799 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006800 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006804 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006805 signatureRSAPKCS1WithSHA256,
6806 },
6807 Bugs: ProtocolBugs{
6808 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6809 },
6810 },
6811 shouldFail: true,
6812 expectedError: ":WRONG_SIGNATURE_TYPE:",
6813 })
6814
Steven Valdez143e8b32016-07-11 13:19:03 -04006815 testCases = append(testCases, testCase{
6816 name: "Verify-ServerAuth-SignatureType-TLS13",
6817 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006818 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006819 SignSignatureAlgorithms: []signatureAlgorithm{
6820 signatureRSAPSSWithSHA256,
6821 },
6822 Bugs: ProtocolBugs{
6823 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6824 },
6825 },
6826 shouldFail: true,
6827 expectedError: ":WRONG_SIGNATURE_TYPE:",
6828 })
6829
David Benjamin51dd7d62016-07-08 16:07:01 -07006830 // Test that, if the list is missing, the peer falls back to SHA-1 in
6831 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006832 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006833 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006835 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006836 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006837 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006838 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006839 },
6840 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006841 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006842 },
6843 },
6844 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006845 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6846 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006847 },
6848 })
6849
6850 testCases = append(testCases, testCase{
6851 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006852 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006853 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006854 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006855 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006856 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006857 },
6858 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006859 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006860 },
6861 },
David Benjaminee32bea2016-08-17 13:36:44 -04006862 flags: []string{
6863 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6864 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6865 },
6866 })
6867
6868 testCases = append(testCases, testCase{
6869 name: "ClientAuth-SHA1-Fallback-ECDSA",
6870 config: Config{
6871 MaxVersion: VersionTLS12,
6872 ClientAuth: RequireAnyClientCert,
6873 VerifySignatureAlgorithms: []signatureAlgorithm{
6874 signatureECDSAWithSHA1,
6875 },
6876 Bugs: ProtocolBugs{
6877 NoSignatureAlgorithms: true,
6878 },
6879 },
6880 flags: []string{
6881 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6882 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6883 },
6884 })
6885
6886 testCases = append(testCases, testCase{
6887 testType: serverTest,
6888 name: "ServerAuth-SHA1-Fallback-ECDSA",
6889 config: Config{
6890 MaxVersion: VersionTLS12,
6891 VerifySignatureAlgorithms: []signatureAlgorithm{
6892 signatureECDSAWithSHA1,
6893 },
6894 Bugs: ProtocolBugs{
6895 NoSignatureAlgorithms: true,
6896 },
6897 },
6898 flags: []string{
6899 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6900 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6901 },
David Benjamin000800a2014-11-14 01:43:59 -05006902 })
David Benjamin72dc7832015-03-16 17:49:43 -04006903
David Benjamin51dd7d62016-07-08 16:07:01 -07006904 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006905 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006906 config: Config{
6907 MaxVersion: VersionTLS13,
6908 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006909 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006910 signatureRSAPKCS1WithSHA1,
6911 },
6912 Bugs: ProtocolBugs{
6913 NoSignatureAlgorithms: true,
6914 },
6915 },
6916 flags: []string{
6917 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6918 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6919 },
David Benjamin48901652016-08-01 12:12:47 -04006920 shouldFail: true,
6921 // An empty CertificateRequest signature algorithm list is a
6922 // syntax error in TLS 1.3.
6923 expectedError: ":DECODE_ERROR:",
6924 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006925 })
6926
6927 testCases = append(testCases, testCase{
6928 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006929 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006930 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006931 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006932 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006933 signatureRSAPKCS1WithSHA1,
6934 },
6935 Bugs: ProtocolBugs{
6936 NoSignatureAlgorithms: true,
6937 },
6938 },
6939 shouldFail: true,
6940 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6941 })
6942
David Benjaminb62d2872016-07-18 14:55:02 +02006943 // Test that hash preferences are enforced. BoringSSL does not implement
6944 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006945 testCases = append(testCases, testCase{
6946 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006947 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006949 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006950 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006951 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006952 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006953 },
6954 Bugs: ProtocolBugs{
6955 IgnorePeerSignatureAlgorithmPreferences: true,
6956 },
6957 },
6958 flags: []string{"-require-any-client-certificate"},
6959 shouldFail: true,
6960 expectedError: ":WRONG_SIGNATURE_TYPE:",
6961 })
6962
6963 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006964 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006966 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006968 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006969 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006970 },
6971 Bugs: ProtocolBugs{
6972 IgnorePeerSignatureAlgorithmPreferences: true,
6973 },
6974 },
6975 shouldFail: true,
6976 expectedError: ":WRONG_SIGNATURE_TYPE:",
6977 })
David Benjaminb62d2872016-07-18 14:55:02 +02006978 testCases = append(testCases, testCase{
6979 testType: serverTest,
6980 name: "ClientAuth-Enforced-TLS13",
6981 config: Config{
6982 MaxVersion: VersionTLS13,
6983 Certificates: []Certificate{rsaCertificate},
6984 SignSignatureAlgorithms: []signatureAlgorithm{
6985 signatureRSAPKCS1WithMD5,
6986 },
6987 Bugs: ProtocolBugs{
6988 IgnorePeerSignatureAlgorithmPreferences: true,
6989 IgnoreSignatureVersionChecks: true,
6990 },
6991 },
6992 flags: []string{"-require-any-client-certificate"},
6993 shouldFail: true,
6994 expectedError: ":WRONG_SIGNATURE_TYPE:",
6995 })
6996
6997 testCases = append(testCases, testCase{
6998 name: "ServerAuth-Enforced-TLS13",
6999 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007000 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007001 SignSignatureAlgorithms: []signatureAlgorithm{
7002 signatureRSAPKCS1WithMD5,
7003 },
7004 Bugs: ProtocolBugs{
7005 IgnorePeerSignatureAlgorithmPreferences: true,
7006 IgnoreSignatureVersionChecks: true,
7007 },
7008 },
7009 shouldFail: true,
7010 expectedError: ":WRONG_SIGNATURE_TYPE:",
7011 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007012
7013 // Test that the agreed upon digest respects the client preferences and
7014 // the server digests.
7015 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007016 name: "NoCommonAlgorithms-Digests",
7017 config: Config{
7018 MaxVersion: VersionTLS12,
7019 ClientAuth: RequireAnyClientCert,
7020 VerifySignatureAlgorithms: []signatureAlgorithm{
7021 signatureRSAPKCS1WithSHA512,
7022 signatureRSAPKCS1WithSHA1,
7023 },
7024 },
7025 flags: []string{
7026 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7027 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7028 "-digest-prefs", "SHA256",
7029 },
7030 shouldFail: true,
7031 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7032 })
7033 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007034 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007036 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007037 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007038 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007039 signatureRSAPKCS1WithSHA512,
7040 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007041 },
7042 },
7043 flags: []string{
7044 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7045 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007046 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007047 },
David Benjaminca3d5452016-07-14 12:51:01 -04007048 shouldFail: true,
7049 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7050 })
7051 testCases = append(testCases, testCase{
7052 name: "NoCommonAlgorithms-TLS13",
7053 config: Config{
7054 MaxVersion: VersionTLS13,
7055 ClientAuth: RequireAnyClientCert,
7056 VerifySignatureAlgorithms: []signatureAlgorithm{
7057 signatureRSAPSSWithSHA512,
7058 signatureRSAPSSWithSHA384,
7059 },
7060 },
7061 flags: []string{
7062 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7063 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7064 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7065 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007066 shouldFail: true,
7067 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007068 })
7069 testCases = append(testCases, testCase{
7070 name: "Agree-Digest-SHA256",
7071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007072 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007073 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007074 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007075 signatureRSAPKCS1WithSHA1,
7076 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007077 },
7078 },
7079 flags: []string{
7080 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7081 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007082 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007083 },
Nick Harper60edffd2016-06-21 15:19:24 -07007084 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007085 })
7086 testCases = append(testCases, testCase{
7087 name: "Agree-Digest-SHA1",
7088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007089 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007090 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007091 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007092 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007093 },
7094 },
7095 flags: []string{
7096 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7097 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007098 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007099 },
Nick Harper60edffd2016-06-21 15:19:24 -07007100 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007101 })
7102 testCases = append(testCases, testCase{
7103 name: "Agree-Digest-Default",
7104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007105 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007106 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007107 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007108 signatureRSAPKCS1WithSHA256,
7109 signatureECDSAWithP256AndSHA256,
7110 signatureRSAPKCS1WithSHA1,
7111 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007112 },
7113 },
7114 flags: []string{
7115 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7116 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7117 },
Nick Harper60edffd2016-06-21 15:19:24 -07007118 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007119 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007120
David Benjaminca3d5452016-07-14 12:51:01 -04007121 // Test that the signing preference list may include extra algorithms
7122 // without negotiation problems.
7123 testCases = append(testCases, testCase{
7124 testType: serverTest,
7125 name: "FilterExtraAlgorithms",
7126 config: Config{
7127 MaxVersion: VersionTLS12,
7128 VerifySignatureAlgorithms: []signatureAlgorithm{
7129 signatureRSAPKCS1WithSHA256,
7130 },
7131 },
7132 flags: []string{
7133 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7134 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7135 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7136 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7137 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7138 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7139 },
7140 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7141 })
7142
David Benjamin4c3ddf72016-06-29 18:13:53 -04007143 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7144 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007145 testCases = append(testCases, testCase{
7146 name: "CheckLeafCurve",
7147 config: Config{
7148 MaxVersion: VersionTLS12,
7149 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007150 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007151 },
7152 flags: []string{"-p384-only"},
7153 shouldFail: true,
7154 expectedError: ":BAD_ECC_CERT:",
7155 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007156
7157 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7158 testCases = append(testCases, testCase{
7159 name: "CheckLeafCurve-TLS13",
7160 config: Config{
7161 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007162 Certificates: []Certificate{ecdsaP256Certificate},
7163 },
7164 flags: []string{"-p384-only"},
7165 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007166
7167 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7168 testCases = append(testCases, testCase{
7169 name: "ECDSACurveMismatch-Verify-TLS12",
7170 config: Config{
7171 MaxVersion: VersionTLS12,
7172 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7173 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007174 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007175 signatureECDSAWithP384AndSHA384,
7176 },
7177 },
7178 })
7179
7180 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7181 testCases = append(testCases, testCase{
7182 name: "ECDSACurveMismatch-Verify-TLS13",
7183 config: Config{
7184 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007185 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007186 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007187 signatureECDSAWithP384AndSHA384,
7188 },
7189 Bugs: ProtocolBugs{
7190 SkipECDSACurveCheck: true,
7191 },
7192 },
7193 shouldFail: true,
7194 expectedError: ":WRONG_SIGNATURE_TYPE:",
7195 })
7196
7197 // Signature algorithm selection in TLS 1.3 should take the curve into
7198 // account.
7199 testCases = append(testCases, testCase{
7200 testType: serverTest,
7201 name: "ECDSACurveMismatch-Sign-TLS13",
7202 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007203 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007204 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007205 signatureECDSAWithP384AndSHA384,
7206 signatureECDSAWithP256AndSHA256,
7207 },
7208 },
7209 flags: []string{
7210 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7211 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7212 },
7213 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7214 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007215
7216 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7217 // server does not attempt to sign in that case.
7218 testCases = append(testCases, testCase{
7219 testType: serverTest,
7220 name: "RSA-PSS-Large",
7221 config: Config{
7222 MaxVersion: VersionTLS13,
7223 VerifySignatureAlgorithms: []signatureAlgorithm{
7224 signatureRSAPSSWithSHA512,
7225 },
7226 },
7227 flags: []string{
7228 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7229 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7230 },
7231 shouldFail: true,
7232 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7233 })
David Benjamin57e929f2016-08-30 00:30:38 -04007234
7235 // Test that RSA-PSS is enabled by default for TLS 1.2.
7236 testCases = append(testCases, testCase{
7237 testType: clientTest,
7238 name: "RSA-PSS-Default-Verify",
7239 config: Config{
7240 MaxVersion: VersionTLS12,
7241 SignSignatureAlgorithms: []signatureAlgorithm{
7242 signatureRSAPSSWithSHA256,
7243 },
7244 },
7245 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7246 })
7247
7248 testCases = append(testCases, testCase{
7249 testType: serverTest,
7250 name: "RSA-PSS-Default-Sign",
7251 config: Config{
7252 MaxVersion: VersionTLS12,
7253 VerifySignatureAlgorithms: []signatureAlgorithm{
7254 signatureRSAPSSWithSHA256,
7255 },
7256 },
7257 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7258 })
David Benjamin000800a2014-11-14 01:43:59 -05007259}
7260
David Benjamin83f90402015-01-27 01:09:43 -05007261// timeouts is the retransmit schedule for BoringSSL. It doubles and
7262// caps at 60 seconds. On the 13th timeout, it gives up.
7263var timeouts = []time.Duration{
7264 1 * time.Second,
7265 2 * time.Second,
7266 4 * time.Second,
7267 8 * time.Second,
7268 16 * time.Second,
7269 32 * time.Second,
7270 60 * time.Second,
7271 60 * time.Second,
7272 60 * time.Second,
7273 60 * time.Second,
7274 60 * time.Second,
7275 60 * time.Second,
7276 60 * time.Second,
7277}
7278
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007279// shortTimeouts is an alternate set of timeouts which would occur if the
7280// initial timeout duration was set to 250ms.
7281var shortTimeouts = []time.Duration{
7282 250 * time.Millisecond,
7283 500 * time.Millisecond,
7284 1 * time.Second,
7285 2 * time.Second,
7286 4 * time.Second,
7287 8 * time.Second,
7288 16 * time.Second,
7289 32 * time.Second,
7290 60 * time.Second,
7291 60 * time.Second,
7292 60 * time.Second,
7293 60 * time.Second,
7294 60 * time.Second,
7295}
7296
David Benjamin83f90402015-01-27 01:09:43 -05007297func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007298 // These tests work by coordinating some behavior on both the shim and
7299 // the runner.
7300 //
7301 // TimeoutSchedule configures the runner to send a series of timeout
7302 // opcodes to the shim (see packetAdaptor) immediately before reading
7303 // each peer handshake flight N. The timeout opcode both simulates a
7304 // timeout in the shim and acts as a synchronization point to help the
7305 // runner bracket each handshake flight.
7306 //
7307 // We assume the shim does not read from the channel eagerly. It must
7308 // first wait until it has sent flight N and is ready to receive
7309 // handshake flight N+1. At this point, it will process the timeout
7310 // opcode. It must then immediately respond with a timeout ACK and act
7311 // as if the shim was idle for the specified amount of time.
7312 //
7313 // The runner then drops all packets received before the ACK and
7314 // continues waiting for flight N. This ordering results in one attempt
7315 // at sending flight N to be dropped. For the test to complete, the
7316 // shim must send flight N again, testing that the shim implements DTLS
7317 // retransmit on a timeout.
7318
Steven Valdez143e8b32016-07-11 13:19:03 -04007319 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007320 // likely be more epochs to cross and the final message's retransmit may
7321 // be more complex.
7322
David Benjamin585d7a42016-06-02 14:58:00 -04007323 for _, async := range []bool{true, false} {
7324 var tests []testCase
7325
7326 // Test that this is indeed the timeout schedule. Stress all
7327 // four patterns of handshake.
7328 for i := 1; i < len(timeouts); i++ {
7329 number := strconv.Itoa(i)
7330 tests = append(tests, testCase{
7331 protocol: dtls,
7332 name: "DTLS-Retransmit-Client-" + number,
7333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007334 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007335 Bugs: ProtocolBugs{
7336 TimeoutSchedule: timeouts[:i],
7337 },
7338 },
7339 resumeSession: true,
7340 })
7341 tests = append(tests, testCase{
7342 protocol: dtls,
7343 testType: serverTest,
7344 name: "DTLS-Retransmit-Server-" + number,
7345 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007346 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007347 Bugs: ProtocolBugs{
7348 TimeoutSchedule: timeouts[:i],
7349 },
7350 },
7351 resumeSession: true,
7352 })
7353 }
7354
7355 // Test that exceeding the timeout schedule hits a read
7356 // timeout.
7357 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007358 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007359 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007360 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007361 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007362 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007363 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007364 },
7365 },
7366 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007367 shouldFail: true,
7368 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007369 })
David Benjamin585d7a42016-06-02 14:58:00 -04007370
7371 if async {
7372 // Test that timeout handling has a fudge factor, due to API
7373 // problems.
7374 tests = append(tests, testCase{
7375 protocol: dtls,
7376 name: "DTLS-Retransmit-Fudge",
7377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007378 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007379 Bugs: ProtocolBugs{
7380 TimeoutSchedule: []time.Duration{
7381 timeouts[0] - 10*time.Millisecond,
7382 },
7383 },
7384 },
7385 resumeSession: true,
7386 })
7387 }
7388
7389 // Test that the final Finished retransmitting isn't
7390 // duplicated if the peer badly fragments everything.
7391 tests = append(tests, testCase{
7392 testType: serverTest,
7393 protocol: dtls,
7394 name: "DTLS-Retransmit-Fragmented",
7395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007396 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007397 Bugs: ProtocolBugs{
7398 TimeoutSchedule: []time.Duration{timeouts[0]},
7399 MaxHandshakeRecordLength: 2,
7400 },
7401 },
7402 })
7403
7404 // Test the timeout schedule when a shorter initial timeout duration is set.
7405 tests = append(tests, testCase{
7406 protocol: dtls,
7407 name: "DTLS-Retransmit-Short-Client",
7408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007409 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007410 Bugs: ProtocolBugs{
7411 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7412 },
7413 },
7414 resumeSession: true,
7415 flags: []string{"-initial-timeout-duration-ms", "250"},
7416 })
7417 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007418 protocol: dtls,
7419 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007420 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007422 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007423 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007424 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007425 },
7426 },
7427 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007428 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007429 })
David Benjamin585d7a42016-06-02 14:58:00 -04007430
7431 for _, test := range tests {
7432 if async {
7433 test.name += "-Async"
7434 test.flags = append(test.flags, "-async")
7435 }
7436
7437 testCases = append(testCases, test)
7438 }
David Benjamin83f90402015-01-27 01:09:43 -05007439 }
David Benjamin83f90402015-01-27 01:09:43 -05007440}
7441
David Benjaminc565ebb2015-04-03 04:06:36 -04007442func addExportKeyingMaterialTests() {
7443 for _, vers := range tlsVersions {
7444 if vers.version == VersionSSL30 {
7445 continue
7446 }
7447 testCases = append(testCases, testCase{
7448 name: "ExportKeyingMaterial-" + vers.name,
7449 config: Config{
7450 MaxVersion: vers.version,
7451 },
7452 exportKeyingMaterial: 1024,
7453 exportLabel: "label",
7454 exportContext: "context",
7455 useExportContext: true,
7456 })
7457 testCases = append(testCases, testCase{
7458 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7459 config: Config{
7460 MaxVersion: vers.version,
7461 },
7462 exportKeyingMaterial: 1024,
7463 })
7464 testCases = append(testCases, testCase{
7465 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7466 config: Config{
7467 MaxVersion: vers.version,
7468 },
7469 exportKeyingMaterial: 1024,
7470 useExportContext: true,
7471 })
7472 testCases = append(testCases, testCase{
7473 name: "ExportKeyingMaterial-Small-" + vers.name,
7474 config: Config{
7475 MaxVersion: vers.version,
7476 },
7477 exportKeyingMaterial: 1,
7478 exportLabel: "label",
7479 exportContext: "context",
7480 useExportContext: true,
7481 })
7482 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007483
David Benjaminc565ebb2015-04-03 04:06:36 -04007484 testCases = append(testCases, testCase{
7485 name: "ExportKeyingMaterial-SSL3",
7486 config: Config{
7487 MaxVersion: VersionSSL30,
7488 },
7489 exportKeyingMaterial: 1024,
7490 exportLabel: "label",
7491 exportContext: "context",
7492 useExportContext: true,
7493 shouldFail: true,
7494 expectedError: "failed to export keying material",
7495 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007496
7497 // Exporters work during a False Start.
7498 testCases = append(testCases, testCase{
7499 name: "ExportKeyingMaterial-FalseStart",
7500 config: Config{
7501 MaxVersion: VersionTLS12,
7502 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7503 NextProtos: []string{"foo"},
7504 Bugs: ProtocolBugs{
7505 ExpectFalseStart: true,
7506 },
7507 },
7508 flags: []string{
7509 "-false-start",
7510 "-advertise-alpn", "\x03foo",
7511 },
7512 shimWritesFirst: true,
7513 exportKeyingMaterial: 1024,
7514 exportLabel: "label",
7515 exportContext: "context",
7516 useExportContext: true,
7517 })
7518
7519 // Exporters do not work in the middle of a renegotiation. Test this by
7520 // triggering the exporter after every SSL_read call and configuring the
7521 // shim to run asynchronously.
7522 testCases = append(testCases, testCase{
7523 name: "ExportKeyingMaterial-Renegotiate",
7524 config: Config{
7525 MaxVersion: VersionTLS12,
7526 },
7527 renegotiate: 1,
7528 flags: []string{
7529 "-async",
7530 "-use-exporter-between-reads",
7531 "-renegotiate-freely",
7532 "-expect-total-renegotiations", "1",
7533 },
7534 shouldFail: true,
7535 expectedError: "failed to export keying material",
7536 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007537}
7538
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007539func addTLSUniqueTests() {
7540 for _, isClient := range []bool{false, true} {
7541 for _, isResumption := range []bool{false, true} {
7542 for _, hasEMS := range []bool{false, true} {
7543 var suffix string
7544 if isResumption {
7545 suffix = "Resume-"
7546 } else {
7547 suffix = "Full-"
7548 }
7549
7550 if hasEMS {
7551 suffix += "EMS-"
7552 } else {
7553 suffix += "NoEMS-"
7554 }
7555
7556 if isClient {
7557 suffix += "Client"
7558 } else {
7559 suffix += "Server"
7560 }
7561
7562 test := testCase{
7563 name: "TLSUnique-" + suffix,
7564 testTLSUnique: true,
7565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007566 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007567 Bugs: ProtocolBugs{
7568 NoExtendedMasterSecret: !hasEMS,
7569 },
7570 },
7571 }
7572
7573 if isResumption {
7574 test.resumeSession = true
7575 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007576 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007577 Bugs: ProtocolBugs{
7578 NoExtendedMasterSecret: !hasEMS,
7579 },
7580 }
7581 }
7582
7583 if isResumption && !hasEMS {
7584 test.shouldFail = true
7585 test.expectedError = "failed to get tls-unique"
7586 }
7587
7588 testCases = append(testCases, test)
7589 }
7590 }
7591 }
7592}
7593
Adam Langley09505632015-07-30 18:10:13 -07007594func addCustomExtensionTests() {
7595 expectedContents := "custom extension"
7596 emptyString := ""
7597
7598 for _, isClient := range []bool{false, true} {
7599 suffix := "Server"
7600 flag := "-enable-server-custom-extension"
7601 testType := serverTest
7602 if isClient {
7603 suffix = "Client"
7604 flag = "-enable-client-custom-extension"
7605 testType = clientTest
7606 }
7607
7608 testCases = append(testCases, testCase{
7609 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007610 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007611 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007612 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007613 Bugs: ProtocolBugs{
7614 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007615 ExpectedCustomExtension: &expectedContents,
7616 },
7617 },
7618 flags: []string{flag},
7619 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007620 testCases = append(testCases, testCase{
7621 testType: testType,
7622 name: "CustomExtensions-" + suffix + "-TLS13",
7623 config: Config{
7624 MaxVersion: VersionTLS13,
7625 Bugs: ProtocolBugs{
7626 CustomExtension: expectedContents,
7627 ExpectedCustomExtension: &expectedContents,
7628 },
7629 },
7630 flags: []string{flag},
7631 })
Adam Langley09505632015-07-30 18:10:13 -07007632
7633 // If the parse callback fails, the handshake should also fail.
7634 testCases = append(testCases, testCase{
7635 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007636 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007637 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007638 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007639 Bugs: ProtocolBugs{
7640 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007641 ExpectedCustomExtension: &expectedContents,
7642 },
7643 },
David Benjamin399e7c92015-07-30 23:01:27 -04007644 flags: []string{flag},
7645 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007646 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7647 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007648 testCases = append(testCases, testCase{
7649 testType: testType,
7650 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7651 config: Config{
7652 MaxVersion: VersionTLS13,
7653 Bugs: ProtocolBugs{
7654 CustomExtension: expectedContents + "foo",
7655 ExpectedCustomExtension: &expectedContents,
7656 },
7657 },
7658 flags: []string{flag},
7659 shouldFail: true,
7660 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7661 })
Adam Langley09505632015-07-30 18:10:13 -07007662
7663 // If the add callback fails, the handshake should also fail.
7664 testCases = append(testCases, testCase{
7665 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007666 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007667 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007668 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007669 Bugs: ProtocolBugs{
7670 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007671 ExpectedCustomExtension: &expectedContents,
7672 },
7673 },
David Benjamin399e7c92015-07-30 23:01:27 -04007674 flags: []string{flag, "-custom-extension-fail-add"},
7675 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007676 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7677 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007678 testCases = append(testCases, testCase{
7679 testType: testType,
7680 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7681 config: Config{
7682 MaxVersion: VersionTLS13,
7683 Bugs: ProtocolBugs{
7684 CustomExtension: expectedContents,
7685 ExpectedCustomExtension: &expectedContents,
7686 },
7687 },
7688 flags: []string{flag, "-custom-extension-fail-add"},
7689 shouldFail: true,
7690 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7691 })
Adam Langley09505632015-07-30 18:10:13 -07007692
7693 // If the add callback returns zero, no extension should be
7694 // added.
7695 skipCustomExtension := expectedContents
7696 if isClient {
7697 // For the case where the client skips sending the
7698 // custom extension, the server must not “echo” it.
7699 skipCustomExtension = ""
7700 }
7701 testCases = append(testCases, testCase{
7702 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007703 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007704 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007705 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007706 Bugs: ProtocolBugs{
7707 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007708 ExpectedCustomExtension: &emptyString,
7709 },
7710 },
7711 flags: []string{flag, "-custom-extension-skip"},
7712 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007713 testCases = append(testCases, testCase{
7714 testType: testType,
7715 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7716 config: Config{
7717 MaxVersion: VersionTLS13,
7718 Bugs: ProtocolBugs{
7719 CustomExtension: skipCustomExtension,
7720 ExpectedCustomExtension: &emptyString,
7721 },
7722 },
7723 flags: []string{flag, "-custom-extension-skip"},
7724 })
Adam Langley09505632015-07-30 18:10:13 -07007725 }
7726
7727 // The custom extension add callback should not be called if the client
7728 // doesn't send the extension.
7729 testCases = append(testCases, testCase{
7730 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007731 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007733 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007734 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007735 ExpectedCustomExtension: &emptyString,
7736 },
7737 },
7738 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7739 })
Adam Langley2deb9842015-08-07 11:15:37 -07007740
Steven Valdez143e8b32016-07-11 13:19:03 -04007741 testCases = append(testCases, testCase{
7742 testType: serverTest,
7743 name: "CustomExtensions-NotCalled-Server-TLS13",
7744 config: Config{
7745 MaxVersion: VersionTLS13,
7746 Bugs: ProtocolBugs{
7747 ExpectedCustomExtension: &emptyString,
7748 },
7749 },
7750 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7751 })
7752
Adam Langley2deb9842015-08-07 11:15:37 -07007753 // Test an unknown extension from the server.
7754 testCases = append(testCases, testCase{
7755 testType: clientTest,
7756 name: "UnknownExtension-Client",
7757 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007758 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007759 Bugs: ProtocolBugs{
7760 CustomExtension: expectedContents,
7761 },
7762 },
David Benjamin0c40a962016-08-01 12:05:50 -04007763 shouldFail: true,
7764 expectedError: ":UNEXPECTED_EXTENSION:",
7765 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007766 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007767 testCases = append(testCases, testCase{
7768 testType: clientTest,
7769 name: "UnknownExtension-Client-TLS13",
7770 config: Config{
7771 MaxVersion: VersionTLS13,
7772 Bugs: ProtocolBugs{
7773 CustomExtension: expectedContents,
7774 },
7775 },
David Benjamin0c40a962016-08-01 12:05:50 -04007776 shouldFail: true,
7777 expectedError: ":UNEXPECTED_EXTENSION:",
7778 expectedLocalError: "remote error: unsupported extension",
7779 })
David Benjamin490469f2016-10-05 22:44:38 -04007780 testCases = append(testCases, testCase{
7781 testType: clientTest,
7782 name: "UnknownUnencryptedExtension-Client-TLS13",
7783 config: Config{
7784 MaxVersion: VersionTLS13,
7785 Bugs: ProtocolBugs{
7786 CustomUnencryptedExtension: expectedContents,
7787 },
7788 },
7789 shouldFail: true,
7790 expectedError: ":UNEXPECTED_EXTENSION:",
7791 // The shim must send an alert, but alerts at this point do not
7792 // get successfully decrypted by the runner.
7793 expectedLocalError: "local error: bad record MAC",
7794 })
7795 testCases = append(testCases, testCase{
7796 testType: clientTest,
7797 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7798 config: Config{
7799 MaxVersion: VersionTLS13,
7800 Bugs: ProtocolBugs{
7801 SendUnencryptedALPN: "foo",
7802 },
7803 },
7804 flags: []string{
7805 "-advertise-alpn", "\x03foo\x03bar",
7806 },
7807 shouldFail: true,
7808 expectedError: ":UNEXPECTED_EXTENSION:",
7809 // The shim must send an alert, but alerts at this point do not
7810 // get successfully decrypted by the runner.
7811 expectedLocalError: "local error: bad record MAC",
7812 })
David Benjamin0c40a962016-08-01 12:05:50 -04007813
7814 // Test a known but unoffered extension from the server.
7815 testCases = append(testCases, testCase{
7816 testType: clientTest,
7817 name: "UnofferedExtension-Client",
7818 config: Config{
7819 MaxVersion: VersionTLS12,
7820 Bugs: ProtocolBugs{
7821 SendALPN: "alpn",
7822 },
7823 },
7824 shouldFail: true,
7825 expectedError: ":UNEXPECTED_EXTENSION:",
7826 expectedLocalError: "remote error: unsupported extension",
7827 })
7828 testCases = append(testCases, testCase{
7829 testType: clientTest,
7830 name: "UnofferedExtension-Client-TLS13",
7831 config: Config{
7832 MaxVersion: VersionTLS13,
7833 Bugs: ProtocolBugs{
7834 SendALPN: "alpn",
7835 },
7836 },
7837 shouldFail: true,
7838 expectedError: ":UNEXPECTED_EXTENSION:",
7839 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007840 })
Adam Langley09505632015-07-30 18:10:13 -07007841}
7842
David Benjaminb36a3952015-12-01 18:53:13 -05007843func addRSAClientKeyExchangeTests() {
7844 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7845 testCases = append(testCases, testCase{
7846 testType: serverTest,
7847 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7848 config: Config{
7849 // Ensure the ClientHello version and final
7850 // version are different, to detect if the
7851 // server uses the wrong one.
7852 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007853 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007854 Bugs: ProtocolBugs{
7855 BadRSAClientKeyExchange: bad,
7856 },
7857 },
7858 shouldFail: true,
7859 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7860 })
7861 }
David Benjamine63d9d72016-09-19 18:27:34 -04007862
7863 // The server must compare whatever was in ClientHello.version for the
7864 // RSA premaster.
7865 testCases = append(testCases, testCase{
7866 testType: serverTest,
7867 name: "SendClientVersion-RSA",
7868 config: Config{
7869 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7870 Bugs: ProtocolBugs{
7871 SendClientVersion: 0x1234,
7872 },
7873 },
7874 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7875 })
David Benjaminb36a3952015-12-01 18:53:13 -05007876}
7877
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007878var testCurves = []struct {
7879 name string
7880 id CurveID
7881}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007882 {"P-256", CurveP256},
7883 {"P-384", CurveP384},
7884 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007885 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007886}
7887
Steven Valdez5440fe02016-07-18 12:40:30 -04007888const bogusCurve = 0x1234
7889
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007890func addCurveTests() {
7891 for _, curve := range testCurves {
7892 testCases = append(testCases, testCase{
7893 name: "CurveTest-Client-" + curve.name,
7894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007895 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7897 CurvePreferences: []CurveID{curve.id},
7898 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007899 flags: []string{
7900 "-enable-all-curves",
7901 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7902 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007903 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007904 })
7905 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007906 name: "CurveTest-Client-" + curve.name + "-TLS13",
7907 config: Config{
7908 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007909 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,
Steven Valdez143e8b32016-07-11 13:19:03 -04007916 })
7917 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007918 testType: serverTest,
7919 name: "CurveTest-Server-" + curve.name,
7920 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007921 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7923 CurvePreferences: []CurveID{curve.id},
7924 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007925 flags: []string{
7926 "-enable-all-curves",
7927 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7928 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007929 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007930 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007931 testCases = append(testCases, testCase{
7932 testType: serverTest,
7933 name: "CurveTest-Server-" + curve.name + "-TLS13",
7934 config: Config{
7935 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007936 CurvePreferences: []CurveID{curve.id},
7937 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007938 flags: []string{
7939 "-enable-all-curves",
7940 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7941 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007942 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007943 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007944 }
David Benjamin241ae832016-01-15 03:04:54 -05007945
7946 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007947 testCases = append(testCases, testCase{
7948 testType: serverTest,
7949 name: "UnknownCurve",
7950 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007951 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007952 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7953 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7954 },
7955 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007956
Steven Valdez803c77a2016-09-06 14:13:43 -04007957 // The server must be tolerant to bogus curves.
7958 testCases = append(testCases, testCase{
7959 testType: serverTest,
7960 name: "UnknownCurve-TLS13",
7961 config: Config{
7962 MaxVersion: VersionTLS13,
7963 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7964 },
7965 })
7966
David Benjamin4c3ddf72016-06-29 18:13:53 -04007967 // The server must not consider ECDHE ciphers when there are no
7968 // supported curves.
7969 testCases = append(testCases, testCase{
7970 testType: serverTest,
7971 name: "NoSupportedCurves",
7972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007973 MaxVersion: VersionTLS12,
7974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7975 Bugs: ProtocolBugs{
7976 NoSupportedCurves: true,
7977 },
7978 },
7979 shouldFail: true,
7980 expectedError: ":NO_SHARED_CIPHER:",
7981 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007982 testCases = append(testCases, testCase{
7983 testType: serverTest,
7984 name: "NoSupportedCurves-TLS13",
7985 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007986 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007987 Bugs: ProtocolBugs{
7988 NoSupportedCurves: true,
7989 },
7990 },
7991 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007992 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007993 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007994
7995 // The server must fall back to another cipher when there are no
7996 // supported curves.
7997 testCases = append(testCases, testCase{
7998 testType: serverTest,
7999 name: "NoCommonCurves",
8000 config: Config{
8001 MaxVersion: VersionTLS12,
8002 CipherSuites: []uint16{
8003 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8004 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8005 },
8006 CurvePreferences: []CurveID{CurveP224},
8007 },
8008 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8009 })
8010
8011 // The client must reject bogus curves and disabled curves.
8012 testCases = append(testCases, testCase{
8013 name: "BadECDHECurve",
8014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008015 MaxVersion: VersionTLS12,
8016 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8017 Bugs: ProtocolBugs{
8018 SendCurve: bogusCurve,
8019 },
8020 },
8021 shouldFail: true,
8022 expectedError: ":WRONG_CURVE:",
8023 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008024 testCases = append(testCases, testCase{
8025 name: "BadECDHECurve-TLS13",
8026 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008027 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008028 Bugs: ProtocolBugs{
8029 SendCurve: bogusCurve,
8030 },
8031 },
8032 shouldFail: true,
8033 expectedError: ":WRONG_CURVE:",
8034 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008035
8036 testCases = append(testCases, testCase{
8037 name: "UnsupportedCurve",
8038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008039 MaxVersion: VersionTLS12,
8040 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8041 CurvePreferences: []CurveID{CurveP256},
8042 Bugs: ProtocolBugs{
8043 IgnorePeerCurvePreferences: true,
8044 },
8045 },
8046 flags: []string{"-p384-only"},
8047 shouldFail: true,
8048 expectedError: ":WRONG_CURVE:",
8049 })
8050
David Benjamin4f921572016-07-17 14:20:10 +02008051 testCases = append(testCases, testCase{
8052 // TODO(davidben): Add a TLS 1.3 version where
8053 // HelloRetryRequest requests an unsupported curve.
8054 name: "UnsupportedCurve-ServerHello-TLS13",
8055 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008056 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008057 CurvePreferences: []CurveID{CurveP384},
8058 Bugs: ProtocolBugs{
8059 SendCurve: CurveP256,
8060 },
8061 },
8062 flags: []string{"-p384-only"},
8063 shouldFail: true,
8064 expectedError: ":WRONG_CURVE:",
8065 })
8066
David Benjamin4c3ddf72016-06-29 18:13:53 -04008067 // Test invalid curve points.
8068 testCases = append(testCases, testCase{
8069 name: "InvalidECDHPoint-Client",
8070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008071 MaxVersion: VersionTLS12,
8072 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8073 CurvePreferences: []CurveID{CurveP256},
8074 Bugs: ProtocolBugs{
8075 InvalidECDHPoint: true,
8076 },
8077 },
8078 shouldFail: true,
8079 expectedError: ":INVALID_ENCODING:",
8080 })
8081 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008082 name: "InvalidECDHPoint-Client-TLS13",
8083 config: Config{
8084 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008085 CurvePreferences: []CurveID{CurveP256},
8086 Bugs: ProtocolBugs{
8087 InvalidECDHPoint: true,
8088 },
8089 },
8090 shouldFail: true,
8091 expectedError: ":INVALID_ENCODING:",
8092 })
8093 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008094 testType: serverTest,
8095 name: "InvalidECDHPoint-Server",
8096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008097 MaxVersion: VersionTLS12,
8098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8099 CurvePreferences: []CurveID{CurveP256},
8100 Bugs: ProtocolBugs{
8101 InvalidECDHPoint: true,
8102 },
8103 },
8104 shouldFail: true,
8105 expectedError: ":INVALID_ENCODING:",
8106 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008107 testCases = append(testCases, testCase{
8108 testType: serverTest,
8109 name: "InvalidECDHPoint-Server-TLS13",
8110 config: Config{
8111 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008112 CurvePreferences: []CurveID{CurveP256},
8113 Bugs: ProtocolBugs{
8114 InvalidECDHPoint: true,
8115 },
8116 },
8117 shouldFail: true,
8118 expectedError: ":INVALID_ENCODING:",
8119 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008120
8121 // The previous curve ID should be reported on TLS 1.2 resumption.
8122 testCases = append(testCases, testCase{
8123 name: "CurveID-Resume-Client",
8124 config: Config{
8125 MaxVersion: VersionTLS12,
8126 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8127 CurvePreferences: []CurveID{CurveX25519},
8128 },
8129 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8130 resumeSession: true,
8131 })
8132 testCases = append(testCases, testCase{
8133 testType: serverTest,
8134 name: "CurveID-Resume-Server",
8135 config: Config{
8136 MaxVersion: VersionTLS12,
8137 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8138 CurvePreferences: []CurveID{CurveX25519},
8139 },
8140 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8141 resumeSession: true,
8142 })
8143
8144 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8145 // one should be reported.
8146 testCases = append(testCases, testCase{
8147 name: "CurveID-Resume-Client-TLS13",
8148 config: Config{
8149 MaxVersion: VersionTLS13,
8150 CurvePreferences: []CurveID{CurveX25519},
8151 },
8152 resumeConfig: &Config{
8153 MaxVersion: VersionTLS13,
8154 CurvePreferences: []CurveID{CurveP256},
8155 },
8156 flags: []string{
8157 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8158 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8159 },
8160 resumeSession: true,
8161 })
8162 testCases = append(testCases, testCase{
8163 testType: serverTest,
8164 name: "CurveID-Resume-Server-TLS13",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 CurvePreferences: []CurveID{CurveX25519},
8168 },
8169 resumeConfig: &Config{
8170 MaxVersion: VersionTLS13,
8171 CurvePreferences: []CurveID{CurveP256},
8172 },
8173 flags: []string{
8174 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8175 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8176 },
8177 resumeSession: true,
8178 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008179}
8180
David Benjaminc9ae27c2016-06-24 22:56:37 -04008181func addTLS13RecordTests() {
8182 testCases = append(testCases, testCase{
8183 name: "TLS13-RecordPadding",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 MinVersion: VersionTLS13,
8187 Bugs: ProtocolBugs{
8188 RecordPadding: 10,
8189 },
8190 },
8191 })
8192
8193 testCases = append(testCases, testCase{
8194 name: "TLS13-EmptyRecords",
8195 config: Config{
8196 MaxVersion: VersionTLS13,
8197 MinVersion: VersionTLS13,
8198 Bugs: ProtocolBugs{
8199 OmitRecordContents: true,
8200 },
8201 },
8202 shouldFail: true,
8203 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8204 })
8205
8206 testCases = append(testCases, testCase{
8207 name: "TLS13-OnlyPadding",
8208 config: Config{
8209 MaxVersion: VersionTLS13,
8210 MinVersion: VersionTLS13,
8211 Bugs: ProtocolBugs{
8212 OmitRecordContents: true,
8213 RecordPadding: 10,
8214 },
8215 },
8216 shouldFail: true,
8217 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8218 })
8219
8220 testCases = append(testCases, testCase{
8221 name: "TLS13-WrongOuterRecord",
8222 config: Config{
8223 MaxVersion: VersionTLS13,
8224 MinVersion: VersionTLS13,
8225 Bugs: ProtocolBugs{
8226 OuterRecordType: recordTypeHandshake,
8227 },
8228 },
8229 shouldFail: true,
8230 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8231 })
8232}
8233
Steven Valdez5b986082016-09-01 12:29:49 -04008234func addSessionTicketTests() {
8235 testCases = append(testCases, testCase{
8236 // In TLS 1.2 and below, empty NewSessionTicket messages
8237 // mean the server changed its mind on sending a ticket.
8238 name: "SendEmptySessionTicket",
8239 config: Config{
8240 MaxVersion: VersionTLS12,
8241 Bugs: ProtocolBugs{
8242 SendEmptySessionTicket: true,
8243 },
8244 },
8245 flags: []string{"-expect-no-session"},
8246 })
8247
8248 // Test that the server ignores unknown PSK modes.
8249 testCases = append(testCases, testCase{
8250 testType: serverTest,
8251 name: "TLS13-SendUnknownModeSessionTicket-Server",
8252 config: Config{
8253 MaxVersion: VersionTLS13,
8254 Bugs: ProtocolBugs{
8255 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008256 },
8257 },
8258 resumeSession: true,
8259 expectedResumeVersion: VersionTLS13,
8260 })
8261
Steven Valdeza833c352016-11-01 13:39:36 -04008262 // Test that the server does not send session tickets with no matching key exchange mode.
8263 testCases = append(testCases, testCase{
8264 testType: serverTest,
8265 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8266 config: Config{
8267 MaxVersion: VersionTLS13,
8268 Bugs: ProtocolBugs{
8269 SendPSKKeyExchangeModes: []byte{0x1a},
8270 ExpectNoNewSessionTicket: true,
8271 },
8272 },
8273 })
8274
8275 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008276 testCases = append(testCases, testCase{
8277 testType: serverTest,
8278 name: "TLS13-SendBadKEModeSessionTicket-Server",
8279 config: Config{
8280 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008281 },
8282 resumeConfig: &Config{
8283 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008284 Bugs: ProtocolBugs{
8285 SendPSKKeyExchangeModes: []byte{0x1a},
8286 },
8287 },
8288 resumeSession: true,
8289 expectResumeRejected: true,
8290 })
8291
Steven Valdeza833c352016-11-01 13:39:36 -04008292 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008293 testCases = append(testCases, testCase{
8294 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008295 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008296 config: Config{
8297 MaxVersion: VersionTLS13,
8298 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008299 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008300 },
8301 },
Steven Valdeza833c352016-11-01 13:39:36 -04008302 resumeSession: true,
8303 flags: []string{
8304 "-resumption-delay", "10",
8305 },
Steven Valdez5b986082016-09-01 12:29:49 -04008306 })
8307
Steven Valdeza833c352016-11-01 13:39:36 -04008308 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008309 testCases = append(testCases, testCase{
8310 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008311 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008312 config: Config{
8313 MaxVersion: VersionTLS13,
8314 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008315 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008316 },
8317 },
Steven Valdeza833c352016-11-01 13:39:36 -04008318 resumeSession: true,
8319 shouldFail: true,
8320 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008321 })
8322
Steven Valdez5b986082016-09-01 12:29:49 -04008323}
8324
David Benjamin82261be2016-07-07 14:32:50 -07008325func addChangeCipherSpecTests() {
8326 // Test missing ChangeCipherSpecs.
8327 testCases = append(testCases, testCase{
8328 name: "SkipChangeCipherSpec-Client",
8329 config: Config{
8330 MaxVersion: VersionTLS12,
8331 Bugs: ProtocolBugs{
8332 SkipChangeCipherSpec: true,
8333 },
8334 },
8335 shouldFail: true,
8336 expectedError: ":UNEXPECTED_RECORD:",
8337 })
8338 testCases = append(testCases, testCase{
8339 testType: serverTest,
8340 name: "SkipChangeCipherSpec-Server",
8341 config: Config{
8342 MaxVersion: VersionTLS12,
8343 Bugs: ProtocolBugs{
8344 SkipChangeCipherSpec: true,
8345 },
8346 },
8347 shouldFail: true,
8348 expectedError: ":UNEXPECTED_RECORD:",
8349 })
8350 testCases = append(testCases, testCase{
8351 testType: serverTest,
8352 name: "SkipChangeCipherSpec-Server-NPN",
8353 config: Config{
8354 MaxVersion: VersionTLS12,
8355 NextProtos: []string{"bar"},
8356 Bugs: ProtocolBugs{
8357 SkipChangeCipherSpec: true,
8358 },
8359 },
8360 flags: []string{
8361 "-advertise-npn", "\x03foo\x03bar\x03baz",
8362 },
8363 shouldFail: true,
8364 expectedError: ":UNEXPECTED_RECORD:",
8365 })
8366
8367 // Test synchronization between the handshake and ChangeCipherSpec.
8368 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8369 // rejected. Test both with and without handshake packing to handle both
8370 // when the partial post-CCS message is in its own record and when it is
8371 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008372 for _, packed := range []bool{false, true} {
8373 var suffix string
8374 if packed {
8375 suffix = "-Packed"
8376 }
8377
8378 testCases = append(testCases, testCase{
8379 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8380 config: Config{
8381 MaxVersion: VersionTLS12,
8382 Bugs: ProtocolBugs{
8383 FragmentAcrossChangeCipherSpec: true,
8384 PackHandshakeFlight: packed,
8385 },
8386 },
8387 shouldFail: true,
8388 expectedError: ":UNEXPECTED_RECORD:",
8389 })
8390 testCases = append(testCases, testCase{
8391 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8392 config: Config{
8393 MaxVersion: VersionTLS12,
8394 },
8395 resumeSession: true,
8396 resumeConfig: &Config{
8397 MaxVersion: VersionTLS12,
8398 Bugs: ProtocolBugs{
8399 FragmentAcrossChangeCipherSpec: true,
8400 PackHandshakeFlight: packed,
8401 },
8402 },
8403 shouldFail: true,
8404 expectedError: ":UNEXPECTED_RECORD:",
8405 })
8406 testCases = append(testCases, testCase{
8407 testType: serverTest,
8408 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8409 config: Config{
8410 MaxVersion: VersionTLS12,
8411 Bugs: ProtocolBugs{
8412 FragmentAcrossChangeCipherSpec: true,
8413 PackHandshakeFlight: packed,
8414 },
8415 },
8416 shouldFail: true,
8417 expectedError: ":UNEXPECTED_RECORD:",
8418 })
8419 testCases = append(testCases, testCase{
8420 testType: serverTest,
8421 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8422 config: Config{
8423 MaxVersion: VersionTLS12,
8424 },
8425 resumeSession: true,
8426 resumeConfig: &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-NPN" + suffix,
8439 config: Config{
8440 MaxVersion: VersionTLS12,
8441 NextProtos: []string{"bar"},
8442 Bugs: ProtocolBugs{
8443 FragmentAcrossChangeCipherSpec: true,
8444 PackHandshakeFlight: packed,
8445 },
8446 },
8447 flags: []string{
8448 "-advertise-npn", "\x03foo\x03bar\x03baz",
8449 },
8450 shouldFail: true,
8451 expectedError: ":UNEXPECTED_RECORD:",
8452 })
8453 }
8454
David Benjamin61672812016-07-14 23:10:43 -04008455 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8456 // messages in the handshake queue. Do this by testing the server
8457 // reading the client Finished, reversing the flight so Finished comes
8458 // first.
8459 testCases = append(testCases, testCase{
8460 protocol: dtls,
8461 testType: serverTest,
8462 name: "SendUnencryptedFinished-DTLS",
8463 config: Config{
8464 MaxVersion: VersionTLS12,
8465 Bugs: ProtocolBugs{
8466 SendUnencryptedFinished: true,
8467 ReverseHandshakeFragments: true,
8468 },
8469 },
8470 shouldFail: true,
8471 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8472 })
8473
Steven Valdez143e8b32016-07-11 13:19:03 -04008474 // Test synchronization between encryption changes and the handshake in
8475 // TLS 1.3, where ChangeCipherSpec is implicit.
8476 testCases = append(testCases, testCase{
8477 name: "PartialEncryptedExtensionsWithServerHello",
8478 config: Config{
8479 MaxVersion: VersionTLS13,
8480 Bugs: ProtocolBugs{
8481 PartialEncryptedExtensionsWithServerHello: true,
8482 },
8483 },
8484 shouldFail: true,
8485 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8486 })
8487 testCases = append(testCases, testCase{
8488 testType: serverTest,
8489 name: "PartialClientFinishedWithClientHello",
8490 config: Config{
8491 MaxVersion: VersionTLS13,
8492 Bugs: ProtocolBugs{
8493 PartialClientFinishedWithClientHello: true,
8494 },
8495 },
8496 shouldFail: true,
8497 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8498 })
8499
David Benjamin82261be2016-07-07 14:32:50 -07008500 // Test that early ChangeCipherSpecs are handled correctly.
8501 testCases = append(testCases, testCase{
8502 testType: serverTest,
8503 name: "EarlyChangeCipherSpec-server-1",
8504 config: Config{
8505 MaxVersion: VersionTLS12,
8506 Bugs: ProtocolBugs{
8507 EarlyChangeCipherSpec: 1,
8508 },
8509 },
8510 shouldFail: true,
8511 expectedError: ":UNEXPECTED_RECORD:",
8512 })
8513 testCases = append(testCases, testCase{
8514 testType: serverTest,
8515 name: "EarlyChangeCipherSpec-server-2",
8516 config: Config{
8517 MaxVersion: VersionTLS12,
8518 Bugs: ProtocolBugs{
8519 EarlyChangeCipherSpec: 2,
8520 },
8521 },
8522 shouldFail: true,
8523 expectedError: ":UNEXPECTED_RECORD:",
8524 })
8525 testCases = append(testCases, testCase{
8526 protocol: dtls,
8527 name: "StrayChangeCipherSpec",
8528 config: Config{
8529 // TODO(davidben): Once DTLS 1.3 exists, test
8530 // that stray ChangeCipherSpec messages are
8531 // rejected.
8532 MaxVersion: VersionTLS12,
8533 Bugs: ProtocolBugs{
8534 StrayChangeCipherSpec: true,
8535 },
8536 },
8537 })
8538
8539 // Test that the contents of ChangeCipherSpec are checked.
8540 testCases = append(testCases, testCase{
8541 name: "BadChangeCipherSpec-1",
8542 config: Config{
8543 MaxVersion: VersionTLS12,
8544 Bugs: ProtocolBugs{
8545 BadChangeCipherSpec: []byte{2},
8546 },
8547 },
8548 shouldFail: true,
8549 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8550 })
8551 testCases = append(testCases, testCase{
8552 name: "BadChangeCipherSpec-2",
8553 config: Config{
8554 MaxVersion: VersionTLS12,
8555 Bugs: ProtocolBugs{
8556 BadChangeCipherSpec: []byte{1, 1},
8557 },
8558 },
8559 shouldFail: true,
8560 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8561 })
8562 testCases = append(testCases, testCase{
8563 protocol: dtls,
8564 name: "BadChangeCipherSpec-DTLS-1",
8565 config: Config{
8566 MaxVersion: VersionTLS12,
8567 Bugs: ProtocolBugs{
8568 BadChangeCipherSpec: []byte{2},
8569 },
8570 },
8571 shouldFail: true,
8572 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8573 })
8574 testCases = append(testCases, testCase{
8575 protocol: dtls,
8576 name: "BadChangeCipherSpec-DTLS-2",
8577 config: Config{
8578 MaxVersion: VersionTLS12,
8579 Bugs: ProtocolBugs{
8580 BadChangeCipherSpec: []byte{1, 1},
8581 },
8582 },
8583 shouldFail: true,
8584 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8585 })
8586}
8587
David Benjamincd2c8062016-09-09 11:28:16 -04008588type perMessageTest struct {
8589 messageType uint8
8590 test testCase
8591}
8592
8593// makePerMessageTests returns a series of test templates which cover each
8594// message in the TLS handshake. These may be used with bugs like
8595// WrongMessageType to fully test a per-message bug.
8596func makePerMessageTests() []perMessageTest {
8597 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008598 for _, protocol := range []protocol{tls, dtls} {
8599 var suffix string
8600 if protocol == dtls {
8601 suffix = "-DTLS"
8602 }
8603
David Benjamincd2c8062016-09-09 11:28:16 -04008604 ret = append(ret, perMessageTest{
8605 messageType: typeClientHello,
8606 test: testCase{
8607 protocol: protocol,
8608 testType: serverTest,
8609 name: "ClientHello" + suffix,
8610 config: Config{
8611 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008612 },
8613 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008614 })
8615
8616 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008617 ret = append(ret, perMessageTest{
8618 messageType: typeHelloVerifyRequest,
8619 test: testCase{
8620 protocol: protocol,
8621 name: "HelloVerifyRequest" + suffix,
8622 config: Config{
8623 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008624 },
8625 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008626 })
8627 }
8628
David Benjamincd2c8062016-09-09 11:28:16 -04008629 ret = append(ret, perMessageTest{
8630 messageType: typeServerHello,
8631 test: testCase{
8632 protocol: protocol,
8633 name: "ServerHello" + suffix,
8634 config: Config{
8635 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008636 },
8637 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008638 })
8639
David Benjamincd2c8062016-09-09 11:28:16 -04008640 ret = append(ret, perMessageTest{
8641 messageType: typeCertificate,
8642 test: testCase{
8643 protocol: protocol,
8644 name: "ServerCertificate" + suffix,
8645 config: Config{
8646 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008647 },
8648 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008649 })
8650
David Benjamincd2c8062016-09-09 11:28:16 -04008651 ret = append(ret, perMessageTest{
8652 messageType: typeCertificateStatus,
8653 test: testCase{
8654 protocol: protocol,
8655 name: "CertificateStatus" + suffix,
8656 config: Config{
8657 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008658 },
David Benjamincd2c8062016-09-09 11:28:16 -04008659 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008660 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008661 })
8662
David Benjamincd2c8062016-09-09 11:28:16 -04008663 ret = append(ret, perMessageTest{
8664 messageType: typeServerKeyExchange,
8665 test: testCase{
8666 protocol: protocol,
8667 name: "ServerKeyExchange" + suffix,
8668 config: Config{
8669 MaxVersion: VersionTLS12,
8670 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008671 },
8672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008673 })
8674
David Benjamincd2c8062016-09-09 11:28:16 -04008675 ret = append(ret, perMessageTest{
8676 messageType: typeCertificateRequest,
8677 test: testCase{
8678 protocol: protocol,
8679 name: "CertificateRequest" + suffix,
8680 config: Config{
8681 MaxVersion: VersionTLS12,
8682 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008683 },
8684 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008685 })
8686
David Benjamincd2c8062016-09-09 11:28:16 -04008687 ret = append(ret, perMessageTest{
8688 messageType: typeServerHelloDone,
8689 test: testCase{
8690 protocol: protocol,
8691 name: "ServerHelloDone" + suffix,
8692 config: Config{
8693 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008694 },
8695 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008696 })
8697
David Benjamincd2c8062016-09-09 11:28:16 -04008698 ret = append(ret, perMessageTest{
8699 messageType: typeCertificate,
8700 test: testCase{
8701 testType: serverTest,
8702 protocol: protocol,
8703 name: "ClientCertificate" + suffix,
8704 config: Config{
8705 Certificates: []Certificate{rsaCertificate},
8706 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008707 },
David Benjamincd2c8062016-09-09 11:28:16 -04008708 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008709 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008710 })
8711
David Benjamincd2c8062016-09-09 11:28:16 -04008712 ret = append(ret, perMessageTest{
8713 messageType: typeCertificateVerify,
8714 test: testCase{
8715 testType: serverTest,
8716 protocol: protocol,
8717 name: "CertificateVerify" + suffix,
8718 config: Config{
8719 Certificates: []Certificate{rsaCertificate},
8720 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008721 },
David Benjamincd2c8062016-09-09 11:28:16 -04008722 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008723 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008724 })
8725
David Benjamincd2c8062016-09-09 11:28:16 -04008726 ret = append(ret, perMessageTest{
8727 messageType: typeClientKeyExchange,
8728 test: testCase{
8729 testType: serverTest,
8730 protocol: protocol,
8731 name: "ClientKeyExchange" + suffix,
8732 config: Config{
8733 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008734 },
8735 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008736 })
8737
8738 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008739 ret = append(ret, perMessageTest{
8740 messageType: typeNextProtocol,
8741 test: testCase{
8742 testType: serverTest,
8743 protocol: protocol,
8744 name: "NextProtocol" + suffix,
8745 config: Config{
8746 MaxVersion: VersionTLS12,
8747 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008748 },
David Benjamincd2c8062016-09-09 11:28:16 -04008749 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008750 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008751 })
8752
David Benjamincd2c8062016-09-09 11:28:16 -04008753 ret = append(ret, perMessageTest{
8754 messageType: typeChannelID,
8755 test: testCase{
8756 testType: serverTest,
8757 protocol: protocol,
8758 name: "ChannelID" + suffix,
8759 config: Config{
8760 MaxVersion: VersionTLS12,
8761 ChannelID: channelIDKey,
8762 },
8763 flags: []string{
8764 "-expect-channel-id",
8765 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008766 },
8767 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 })
8769 }
8770
David Benjamincd2c8062016-09-09 11:28:16 -04008771 ret = append(ret, perMessageTest{
8772 messageType: typeFinished,
8773 test: testCase{
8774 testType: serverTest,
8775 protocol: protocol,
8776 name: "ClientFinished" + suffix,
8777 config: Config{
8778 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008779 },
8780 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008781 })
8782
David Benjamincd2c8062016-09-09 11:28:16 -04008783 ret = append(ret, perMessageTest{
8784 messageType: typeNewSessionTicket,
8785 test: testCase{
8786 protocol: protocol,
8787 name: "NewSessionTicket" + suffix,
8788 config: Config{
8789 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008790 },
8791 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008792 })
8793
David Benjamincd2c8062016-09-09 11:28:16 -04008794 ret = append(ret, perMessageTest{
8795 messageType: typeFinished,
8796 test: testCase{
8797 protocol: protocol,
8798 name: "ServerFinished" + suffix,
8799 config: Config{
8800 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008801 },
8802 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008803 })
8804
8805 }
David Benjamincd2c8062016-09-09 11:28:16 -04008806
8807 ret = append(ret, perMessageTest{
8808 messageType: typeClientHello,
8809 test: testCase{
8810 testType: serverTest,
8811 name: "TLS13-ClientHello",
8812 config: Config{
8813 MaxVersion: VersionTLS13,
8814 },
8815 },
8816 })
8817
8818 ret = append(ret, perMessageTest{
8819 messageType: typeServerHello,
8820 test: testCase{
8821 name: "TLS13-ServerHello",
8822 config: Config{
8823 MaxVersion: VersionTLS13,
8824 },
8825 },
8826 })
8827
8828 ret = append(ret, perMessageTest{
8829 messageType: typeEncryptedExtensions,
8830 test: testCase{
8831 name: "TLS13-EncryptedExtensions",
8832 config: Config{
8833 MaxVersion: VersionTLS13,
8834 },
8835 },
8836 })
8837
8838 ret = append(ret, perMessageTest{
8839 messageType: typeCertificateRequest,
8840 test: testCase{
8841 name: "TLS13-CertificateRequest",
8842 config: Config{
8843 MaxVersion: VersionTLS13,
8844 ClientAuth: RequireAnyClientCert,
8845 },
8846 },
8847 })
8848
8849 ret = append(ret, perMessageTest{
8850 messageType: typeCertificate,
8851 test: testCase{
8852 name: "TLS13-ServerCertificate",
8853 config: Config{
8854 MaxVersion: VersionTLS13,
8855 },
8856 },
8857 })
8858
8859 ret = append(ret, perMessageTest{
8860 messageType: typeCertificateVerify,
8861 test: testCase{
8862 name: "TLS13-ServerCertificateVerify",
8863 config: Config{
8864 MaxVersion: VersionTLS13,
8865 },
8866 },
8867 })
8868
8869 ret = append(ret, perMessageTest{
8870 messageType: typeFinished,
8871 test: testCase{
8872 name: "TLS13-ServerFinished",
8873 config: Config{
8874 MaxVersion: VersionTLS13,
8875 },
8876 },
8877 })
8878
8879 ret = append(ret, perMessageTest{
8880 messageType: typeCertificate,
8881 test: testCase{
8882 testType: serverTest,
8883 name: "TLS13-ClientCertificate",
8884 config: Config{
8885 Certificates: []Certificate{rsaCertificate},
8886 MaxVersion: VersionTLS13,
8887 },
8888 flags: []string{"-require-any-client-certificate"},
8889 },
8890 })
8891
8892 ret = append(ret, perMessageTest{
8893 messageType: typeCertificateVerify,
8894 test: testCase{
8895 testType: serverTest,
8896 name: "TLS13-ClientCertificateVerify",
8897 config: Config{
8898 Certificates: []Certificate{rsaCertificate},
8899 MaxVersion: VersionTLS13,
8900 },
8901 flags: []string{"-require-any-client-certificate"},
8902 },
8903 })
8904
8905 ret = append(ret, perMessageTest{
8906 messageType: typeFinished,
8907 test: testCase{
8908 testType: serverTest,
8909 name: "TLS13-ClientFinished",
8910 config: Config{
8911 MaxVersion: VersionTLS13,
8912 },
8913 },
8914 })
8915
8916 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008917}
8918
David Benjamincd2c8062016-09-09 11:28:16 -04008919func addWrongMessageTypeTests() {
8920 for _, t := range makePerMessageTests() {
8921 t.test.name = "WrongMessageType-" + t.test.name
8922 t.test.config.Bugs.SendWrongMessageType = t.messageType
8923 t.test.shouldFail = true
8924 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8925 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008926
David Benjamincd2c8062016-09-09 11:28:16 -04008927 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8928 // In TLS 1.3, a bad ServerHello means the client sends
8929 // an unencrypted alert while the server expects
8930 // encryption, so the alert is not readable by runner.
8931 t.test.expectedLocalError = "local error: bad record MAC"
8932 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008933
David Benjamincd2c8062016-09-09 11:28:16 -04008934 testCases = append(testCases, t.test)
8935 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008936}
8937
David Benjamin639846e2016-09-09 11:41:18 -04008938func addTrailingMessageDataTests() {
8939 for _, t := range makePerMessageTests() {
8940 t.test.name = "TrailingMessageData-" + t.test.name
8941 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8942 t.test.shouldFail = true
8943 t.test.expectedError = ":DECODE_ERROR:"
8944 t.test.expectedLocalError = "remote error: error decoding message"
8945
8946 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8947 // In TLS 1.3, a bad ServerHello means the client sends
8948 // an unencrypted alert while the server expects
8949 // encryption, so the alert is not readable by runner.
8950 t.test.expectedLocalError = "local error: bad record MAC"
8951 }
8952
8953 if t.messageType == typeFinished {
8954 // Bad Finished messages read as the verify data having
8955 // the wrong length.
8956 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8957 t.test.expectedLocalError = "remote error: error decrypting message"
8958 }
8959
8960 testCases = append(testCases, t.test)
8961 }
8962}
8963
Steven Valdez143e8b32016-07-11 13:19:03 -04008964func addTLS13HandshakeTests() {
8965 testCases = append(testCases, testCase{
8966 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008967 name: "NegotiatePSKResumption-TLS13",
8968 config: Config{
8969 MaxVersion: VersionTLS13,
8970 Bugs: ProtocolBugs{
8971 NegotiatePSKResumption: true,
8972 },
8973 },
8974 resumeSession: true,
8975 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008976 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04008977 })
8978
8979 testCases = append(testCases, testCase{
8980 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008981 name: "MissingKeyShare-Client",
8982 config: Config{
8983 MaxVersion: VersionTLS13,
8984 Bugs: ProtocolBugs{
8985 MissingKeyShare: true,
8986 },
8987 },
8988 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008989 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008990 })
8991
8992 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008993 testType: serverTest,
8994 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008995 config: Config{
8996 MaxVersion: VersionTLS13,
8997 Bugs: ProtocolBugs{
8998 MissingKeyShare: true,
8999 },
9000 },
9001 shouldFail: true,
9002 expectedError: ":MISSING_KEY_SHARE:",
9003 })
9004
9005 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009006 testType: serverTest,
9007 name: "DuplicateKeyShares",
9008 config: Config{
9009 MaxVersion: VersionTLS13,
9010 Bugs: ProtocolBugs{
9011 DuplicateKeyShares: true,
9012 },
9013 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009014 shouldFail: true,
9015 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009016 })
9017
9018 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009019 testType: serverTest,
9020 name: "SkipEarlyData",
9021 config: Config{
9022 MaxVersion: VersionTLS13,
9023 Bugs: ProtocolBugs{
9024 SendEarlyDataLength: 4,
9025 },
9026 },
9027 })
9028
9029 testCases = append(testCases, testCase{
9030 testType: serverTest,
9031 name: "SkipEarlyData-OmitEarlyDataExtension",
9032 config: Config{
9033 MaxVersion: VersionTLS13,
9034 Bugs: ProtocolBugs{
9035 SendEarlyDataLength: 4,
9036 OmitEarlyDataExtension: true,
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9041 })
9042
9043 testCases = append(testCases, testCase{
9044 testType: serverTest,
9045 name: "SkipEarlyData-TooMuchData",
9046 config: Config{
9047 MaxVersion: VersionTLS13,
9048 Bugs: ProtocolBugs{
9049 SendEarlyDataLength: 16384 + 1,
9050 },
9051 },
9052 shouldFail: true,
9053 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9054 })
9055
9056 testCases = append(testCases, testCase{
9057 testType: serverTest,
9058 name: "SkipEarlyData-Interleaved",
9059 config: Config{
9060 MaxVersion: VersionTLS13,
9061 Bugs: ProtocolBugs{
9062 SendEarlyDataLength: 4,
9063 InterleaveEarlyData: true,
9064 },
9065 },
9066 shouldFail: true,
9067 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9068 })
9069
9070 testCases = append(testCases, testCase{
9071 testType: serverTest,
9072 name: "SkipEarlyData-EarlyDataInTLS12",
9073 config: Config{
9074 MaxVersion: VersionTLS13,
9075 Bugs: ProtocolBugs{
9076 SendEarlyDataLength: 4,
9077 },
9078 },
9079 shouldFail: true,
9080 expectedError: ":UNEXPECTED_RECORD:",
9081 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9082 })
9083
9084 testCases = append(testCases, testCase{
9085 testType: serverTest,
9086 name: "SkipEarlyData-HRR",
9087 config: Config{
9088 MaxVersion: VersionTLS13,
9089 Bugs: ProtocolBugs{
9090 SendEarlyDataLength: 4,
9091 },
9092 DefaultCurves: []CurveID{},
9093 },
9094 })
9095
9096 testCases = append(testCases, testCase{
9097 testType: serverTest,
9098 name: "SkipEarlyData-HRR-Interleaved",
9099 config: Config{
9100 MaxVersion: VersionTLS13,
9101 Bugs: ProtocolBugs{
9102 SendEarlyDataLength: 4,
9103 InterleaveEarlyData: true,
9104 },
9105 DefaultCurves: []CurveID{},
9106 },
9107 shouldFail: true,
9108 expectedError: ":UNEXPECTED_RECORD:",
9109 })
9110
9111 testCases = append(testCases, testCase{
9112 testType: serverTest,
9113 name: "SkipEarlyData-HRR-TooMuchData",
9114 config: Config{
9115 MaxVersion: VersionTLS13,
9116 Bugs: ProtocolBugs{
9117 SendEarlyDataLength: 16384 + 1,
9118 },
9119 DefaultCurves: []CurveID{},
9120 },
9121 shouldFail: true,
9122 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9123 })
9124
9125 // Test that skipping early data looking for cleartext correctly
9126 // processes an alert record.
9127 testCases = append(testCases, testCase{
9128 testType: serverTest,
9129 name: "SkipEarlyData-HRR-FatalAlert",
9130 config: Config{
9131 MaxVersion: VersionTLS13,
9132 Bugs: ProtocolBugs{
9133 SendEarlyAlert: true,
9134 SendEarlyDataLength: 4,
9135 },
9136 DefaultCurves: []CurveID{},
9137 },
9138 shouldFail: true,
9139 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9140 })
9141
9142 testCases = append(testCases, testCase{
9143 testType: serverTest,
9144 name: "SkipEarlyData-SecondClientHelloEarlyData",
9145 config: Config{
9146 MaxVersion: VersionTLS13,
9147 Bugs: ProtocolBugs{
9148 SendEarlyDataOnSecondClientHello: true,
9149 },
9150 DefaultCurves: []CurveID{},
9151 },
9152 shouldFail: true,
9153 expectedLocalError: "remote error: bad record MAC",
9154 })
9155
9156 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009157 testType: clientTest,
9158 name: "EmptyEncryptedExtensions",
9159 config: Config{
9160 MaxVersion: VersionTLS13,
9161 Bugs: ProtocolBugs{
9162 EmptyEncryptedExtensions: true,
9163 },
9164 },
9165 shouldFail: true,
9166 expectedLocalError: "remote error: error decoding message",
9167 })
9168
9169 testCases = append(testCases, testCase{
9170 testType: clientTest,
9171 name: "EncryptedExtensionsWithKeyShare",
9172 config: Config{
9173 MaxVersion: VersionTLS13,
9174 Bugs: ProtocolBugs{
9175 EncryptedExtensionsWithKeyShare: true,
9176 },
9177 },
9178 shouldFail: true,
9179 expectedLocalError: "remote error: unsupported extension",
9180 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009181
9182 testCases = append(testCases, testCase{
9183 testType: serverTest,
9184 name: "SendHelloRetryRequest",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 // Require a HelloRetryRequest for every curve.
9188 DefaultCurves: []CurveID{},
9189 },
9190 expectedCurveID: CurveX25519,
9191 })
9192
9193 testCases = append(testCases, testCase{
9194 testType: serverTest,
9195 name: "SendHelloRetryRequest-2",
9196 config: Config{
9197 MaxVersion: VersionTLS13,
9198 DefaultCurves: []CurveID{CurveP384},
9199 },
9200 // Although the ClientHello did not predict our preferred curve,
9201 // we always select it whether it is predicted or not.
9202 expectedCurveID: CurveX25519,
9203 })
9204
9205 testCases = append(testCases, testCase{
9206 name: "UnknownCurve-HelloRetryRequest",
9207 config: Config{
9208 MaxVersion: VersionTLS13,
9209 // P-384 requires HelloRetryRequest in BoringSSL.
9210 CurvePreferences: []CurveID{CurveP384},
9211 Bugs: ProtocolBugs{
9212 SendHelloRetryRequestCurve: bogusCurve,
9213 },
9214 },
9215 shouldFail: true,
9216 expectedError: ":WRONG_CURVE:",
9217 })
9218
9219 testCases = append(testCases, testCase{
9220 name: "DisabledCurve-HelloRetryRequest",
9221 config: Config{
9222 MaxVersion: VersionTLS13,
9223 CurvePreferences: []CurveID{CurveP256},
9224 Bugs: ProtocolBugs{
9225 IgnorePeerCurvePreferences: true,
9226 },
9227 },
9228 flags: []string{"-p384-only"},
9229 shouldFail: true,
9230 expectedError: ":WRONG_CURVE:",
9231 })
9232
9233 testCases = append(testCases, testCase{
9234 name: "UnnecessaryHelloRetryRequest",
9235 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009236 MaxVersion: VersionTLS13,
9237 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009238 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009239 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009240 },
9241 },
9242 shouldFail: true,
9243 expectedError: ":WRONG_CURVE:",
9244 })
9245
9246 testCases = append(testCases, testCase{
9247 name: "SecondHelloRetryRequest",
9248 config: Config{
9249 MaxVersion: VersionTLS13,
9250 // P-384 requires HelloRetryRequest in BoringSSL.
9251 CurvePreferences: []CurveID{CurveP384},
9252 Bugs: ProtocolBugs{
9253 SecondHelloRetryRequest: true,
9254 },
9255 },
9256 shouldFail: true,
9257 expectedError: ":UNEXPECTED_MESSAGE:",
9258 })
9259
9260 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009261 name: "HelloRetryRequest-Empty",
9262 config: Config{
9263 MaxVersion: VersionTLS13,
9264 Bugs: ProtocolBugs{
9265 AlwaysSendHelloRetryRequest: true,
9266 },
9267 },
9268 shouldFail: true,
9269 expectedError: ":DECODE_ERROR:",
9270 })
9271
9272 testCases = append(testCases, testCase{
9273 name: "HelloRetryRequest-DuplicateCurve",
9274 config: Config{
9275 MaxVersion: VersionTLS13,
9276 // P-384 requires a HelloRetryRequest against BoringSSL's default
9277 // configuration. Assert this ExpectMissingKeyShare.
9278 CurvePreferences: []CurveID{CurveP384},
9279 Bugs: ProtocolBugs{
9280 ExpectMissingKeyShare: true,
9281 DuplicateHelloRetryRequestExtensions: true,
9282 },
9283 },
9284 shouldFail: true,
9285 expectedError: ":DUPLICATE_EXTENSION:",
9286 expectedLocalError: "remote error: illegal parameter",
9287 })
9288
9289 testCases = append(testCases, testCase{
9290 name: "HelloRetryRequest-Cookie",
9291 config: Config{
9292 MaxVersion: VersionTLS13,
9293 Bugs: ProtocolBugs{
9294 SendHelloRetryRequestCookie: []byte("cookie"),
9295 },
9296 },
9297 })
9298
9299 testCases = append(testCases, testCase{
9300 name: "HelloRetryRequest-DuplicateCookie",
9301 config: Config{
9302 MaxVersion: VersionTLS13,
9303 Bugs: ProtocolBugs{
9304 SendHelloRetryRequestCookie: []byte("cookie"),
9305 DuplicateHelloRetryRequestExtensions: true,
9306 },
9307 },
9308 shouldFail: true,
9309 expectedError: ":DUPLICATE_EXTENSION:",
9310 expectedLocalError: "remote error: illegal parameter",
9311 })
9312
9313 testCases = append(testCases, testCase{
9314 name: "HelloRetryRequest-EmptyCookie",
9315 config: Config{
9316 MaxVersion: VersionTLS13,
9317 Bugs: ProtocolBugs{
9318 SendHelloRetryRequestCookie: []byte{},
9319 },
9320 },
9321 shouldFail: true,
9322 expectedError: ":DECODE_ERROR:",
9323 })
9324
9325 testCases = append(testCases, testCase{
9326 name: "HelloRetryRequest-Cookie-Curve",
9327 config: Config{
9328 MaxVersion: VersionTLS13,
9329 // P-384 requires HelloRetryRequest in BoringSSL.
9330 CurvePreferences: []CurveID{CurveP384},
9331 Bugs: ProtocolBugs{
9332 SendHelloRetryRequestCookie: []byte("cookie"),
9333 ExpectMissingKeyShare: true,
9334 },
9335 },
9336 })
9337
9338 testCases = append(testCases, testCase{
9339 name: "HelloRetryRequest-Unknown",
9340 config: Config{
9341 MaxVersion: VersionTLS13,
9342 Bugs: ProtocolBugs{
9343 CustomHelloRetryRequestExtension: "extension",
9344 },
9345 },
9346 shouldFail: true,
9347 expectedError: ":UNEXPECTED_EXTENSION:",
9348 expectedLocalError: "remote error: unsupported extension",
9349 })
9350
9351 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009352 testType: serverTest,
9353 name: "SecondClientHelloMissingKeyShare",
9354 config: Config{
9355 MaxVersion: VersionTLS13,
9356 DefaultCurves: []CurveID{},
9357 Bugs: ProtocolBugs{
9358 SecondClientHelloMissingKeyShare: true,
9359 },
9360 },
9361 shouldFail: true,
9362 expectedError: ":MISSING_KEY_SHARE:",
9363 })
9364
9365 testCases = append(testCases, testCase{
9366 testType: serverTest,
9367 name: "SecondClientHelloWrongCurve",
9368 config: Config{
9369 MaxVersion: VersionTLS13,
9370 DefaultCurves: []CurveID{},
9371 Bugs: ProtocolBugs{
9372 MisinterpretHelloRetryRequestCurve: CurveP521,
9373 },
9374 },
9375 shouldFail: true,
9376 expectedError: ":WRONG_CURVE:",
9377 })
9378
9379 testCases = append(testCases, testCase{
9380 name: "HelloRetryRequestVersionMismatch",
9381 config: Config{
9382 MaxVersion: VersionTLS13,
9383 // P-384 requires HelloRetryRequest in BoringSSL.
9384 CurvePreferences: []CurveID{CurveP384},
9385 Bugs: ProtocolBugs{
9386 SendServerHelloVersion: 0x0305,
9387 },
9388 },
9389 shouldFail: true,
9390 expectedError: ":WRONG_VERSION_NUMBER:",
9391 })
9392
9393 testCases = append(testCases, testCase{
9394 name: "HelloRetryRequestCurveMismatch",
9395 config: Config{
9396 MaxVersion: VersionTLS13,
9397 // P-384 requires HelloRetryRequest in BoringSSL.
9398 CurvePreferences: []CurveID{CurveP384},
9399 Bugs: ProtocolBugs{
9400 // Send P-384 (correct) in the HelloRetryRequest.
9401 SendHelloRetryRequestCurve: CurveP384,
9402 // But send P-256 in the ServerHello.
9403 SendCurve: CurveP256,
9404 },
9405 },
9406 shouldFail: true,
9407 expectedError: ":WRONG_CURVE:",
9408 })
9409
9410 // Test the server selecting a curve that requires a HelloRetryRequest
9411 // without sending it.
9412 testCases = append(testCases, testCase{
9413 name: "SkipHelloRetryRequest",
9414 config: Config{
9415 MaxVersion: VersionTLS13,
9416 // P-384 requires HelloRetryRequest in BoringSSL.
9417 CurvePreferences: []CurveID{CurveP384},
9418 Bugs: ProtocolBugs{
9419 SkipHelloRetryRequest: true,
9420 },
9421 },
9422 shouldFail: true,
9423 expectedError: ":WRONG_CURVE:",
9424 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009425
9426 testCases = append(testCases, testCase{
9427 name: "TLS13-RequestContextInHandshake",
9428 config: Config{
9429 MaxVersion: VersionTLS13,
9430 MinVersion: VersionTLS13,
9431 ClientAuth: RequireAnyClientCert,
9432 Bugs: ProtocolBugs{
9433 SendRequestContext: []byte("request context"),
9434 },
9435 },
9436 flags: []string{
9437 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9438 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9439 },
9440 shouldFail: true,
9441 expectedError: ":DECODE_ERROR:",
9442 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009443
9444 testCases = append(testCases, testCase{
9445 testType: serverTest,
9446 name: "TLS13-TrailingKeyShareData",
9447 config: Config{
9448 MaxVersion: VersionTLS13,
9449 Bugs: ProtocolBugs{
9450 TrailingKeyShareData: true,
9451 },
9452 },
9453 shouldFail: true,
9454 expectedError: ":DECODE_ERROR:",
9455 })
David Benjamin7f78df42016-10-05 22:33:19 -04009456
9457 testCases = append(testCases, testCase{
9458 name: "TLS13-AlwaysSelectPSKIdentity",
9459 config: Config{
9460 MaxVersion: VersionTLS13,
9461 Bugs: ProtocolBugs{
9462 AlwaysSelectPSKIdentity: true,
9463 },
9464 },
9465 shouldFail: true,
9466 expectedError: ":UNEXPECTED_EXTENSION:",
9467 })
9468
9469 testCases = append(testCases, testCase{
9470 name: "TLS13-InvalidPSKIdentity",
9471 config: Config{
9472 MaxVersion: VersionTLS13,
9473 Bugs: ProtocolBugs{
9474 SelectPSKIdentityOnResume: 1,
9475 },
9476 },
9477 resumeSession: true,
9478 shouldFail: true,
9479 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9480 })
David Benjamin1286bee2016-10-07 15:25:06 -04009481
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009482 testCases = append(testCases, testCase{
9483 testType: serverTest,
9484 name: "TLS13-ExtraPSKIdentity",
9485 config: Config{
9486 MaxVersion: VersionTLS13,
9487 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009488 ExtraPSKIdentity: true,
9489 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009490 },
9491 },
9492 resumeSession: true,
9493 })
9494
David Benjamin1286bee2016-10-07 15:25:06 -04009495 // Test that unknown NewSessionTicket extensions are tolerated.
9496 testCases = append(testCases, testCase{
9497 name: "TLS13-CustomTicketExtension",
9498 config: Config{
9499 MaxVersion: VersionTLS13,
9500 Bugs: ProtocolBugs{
9501 CustomTicketExtension: "1234",
9502 },
9503 },
9504 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009505}
9506
David Benjaminabbbee12016-10-31 19:20:42 -04009507func addTLS13CipherPreferenceTests() {
9508 // Test that client preference is honored if the shim has AES hardware
9509 // and ChaCha20-Poly1305 is preferred otherwise.
9510 testCases = append(testCases, testCase{
9511 testType: serverTest,
9512 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9513 config: Config{
9514 MaxVersion: VersionTLS13,
9515 CipherSuites: []uint16{
9516 TLS_CHACHA20_POLY1305_SHA256,
9517 TLS_AES_128_GCM_SHA256,
9518 },
9519 },
9520 flags: []string{
9521 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9522 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9523 },
9524 })
9525
9526 testCases = append(testCases, testCase{
9527 testType: serverTest,
9528 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9529 config: Config{
9530 MaxVersion: VersionTLS13,
9531 CipherSuites: []uint16{
9532 TLS_AES_128_GCM_SHA256,
9533 TLS_CHACHA20_POLY1305_SHA256,
9534 },
9535 },
9536 flags: []string{
9537 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9538 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9539 },
9540 })
9541
9542 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9543 // whether it has AES hardware.
9544 testCases = append(testCases, testCase{
9545 name: "TLS13-CipherPreference-Client",
9546 config: Config{
9547 MaxVersion: VersionTLS13,
9548 // Use the client cipher order. (This is the default but
9549 // is listed to be explicit.)
9550 PreferServerCipherSuites: false,
9551 },
9552 flags: []string{
9553 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9554 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9555 },
9556 })
9557}
9558
David Benjaminf3fbade2016-09-19 13:08:16 -04009559func addPeekTests() {
9560 // Test SSL_peek works, including on empty records.
9561 testCases = append(testCases, testCase{
9562 name: "Peek-Basic",
9563 sendEmptyRecords: 1,
9564 flags: []string{"-peek-then-read"},
9565 })
9566
9567 // Test SSL_peek can drive the initial handshake.
9568 testCases = append(testCases, testCase{
9569 name: "Peek-ImplicitHandshake",
9570 flags: []string{
9571 "-peek-then-read",
9572 "-implicit-handshake",
9573 },
9574 })
9575
9576 // Test SSL_peek can discover and drive a renegotiation.
9577 testCases = append(testCases, testCase{
9578 name: "Peek-Renegotiate",
9579 config: Config{
9580 MaxVersion: VersionTLS12,
9581 },
9582 renegotiate: 1,
9583 flags: []string{
9584 "-peek-then-read",
9585 "-renegotiate-freely",
9586 "-expect-total-renegotiations", "1",
9587 },
9588 })
9589
9590 // Test SSL_peek can discover a close_notify.
9591 testCases = append(testCases, testCase{
9592 name: "Peek-Shutdown",
9593 config: Config{
9594 Bugs: ProtocolBugs{
9595 ExpectCloseNotify: true,
9596 },
9597 },
9598 flags: []string{
9599 "-peek-then-read",
9600 "-check-close-notify",
9601 },
9602 })
9603
9604 // Test SSL_peek can discover an alert.
9605 testCases = append(testCases, testCase{
9606 name: "Peek-Alert",
9607 config: Config{
9608 Bugs: ProtocolBugs{
9609 SendSpuriousAlert: alertRecordOverflow,
9610 },
9611 },
9612 flags: []string{"-peek-then-read"},
9613 shouldFail: true,
9614 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9615 })
9616
9617 // Test SSL_peek can handle KeyUpdate.
9618 testCases = append(testCases, testCase{
9619 name: "Peek-KeyUpdate",
9620 config: Config{
9621 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009622 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009623 sendKeyUpdates: 1,
9624 keyUpdateRequest: keyUpdateNotRequested,
9625 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009626 })
9627}
9628
David Benjamine6f22212016-11-08 14:28:24 -05009629func addRecordVersionTests() {
9630 for _, ver := range tlsVersions {
9631 // Test that the record version is enforced.
9632 testCases = append(testCases, testCase{
9633 name: "CheckRecordVersion-" + ver.name,
9634 config: Config{
9635 MinVersion: ver.version,
9636 MaxVersion: ver.version,
9637 Bugs: ProtocolBugs{
9638 SendRecordVersion: 0x03ff,
9639 },
9640 },
9641 shouldFail: true,
9642 expectedError: ":WRONG_VERSION_NUMBER:",
9643 })
9644
9645 // Test that the ClientHello may use any record version, for
9646 // compatibility reasons.
9647 testCases = append(testCases, testCase{
9648 testType: serverTest,
9649 name: "LooseInitialRecordVersion-" + ver.name,
9650 config: Config{
9651 MinVersion: ver.version,
9652 MaxVersion: ver.version,
9653 Bugs: ProtocolBugs{
9654 SendInitialRecordVersion: 0x03ff,
9655 },
9656 },
9657 })
9658
9659 // Test that garbage ClientHello record versions are rejected.
9660 testCases = append(testCases, testCase{
9661 testType: serverTest,
9662 name: "GarbageInitialRecordVersion-" + ver.name,
9663 config: Config{
9664 MinVersion: ver.version,
9665 MaxVersion: ver.version,
9666 Bugs: ProtocolBugs{
9667 SendInitialRecordVersion: 0xffff,
9668 },
9669 },
9670 shouldFail: true,
9671 expectedError: ":WRONG_VERSION_NUMBER:",
9672 })
9673 }
9674}
9675
David Benjamin2c516452016-11-15 10:16:54 +09009676func addCertificateTests() {
9677 // Test that a certificate chain with intermediate may be sent and
9678 // received as both client and server.
9679 for _, ver := range tlsVersions {
9680 testCases = append(testCases, testCase{
9681 testType: clientTest,
9682 name: "SendReceiveIntermediate-Client-" + ver.name,
9683 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009684 MinVersion: ver.version,
9685 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009686 Certificates: []Certificate{rsaChainCertificate},
9687 ClientAuth: RequireAnyClientCert,
9688 },
9689 expectPeerCertificate: &rsaChainCertificate,
9690 flags: []string{
9691 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9692 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9693 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9694 },
9695 })
9696
9697 testCases = append(testCases, testCase{
9698 testType: serverTest,
9699 name: "SendReceiveIntermediate-Server-" + ver.name,
9700 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009701 MinVersion: ver.version,
9702 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009703 Certificates: []Certificate{rsaChainCertificate},
9704 },
9705 expectPeerCertificate: &rsaChainCertificate,
9706 flags: []string{
9707 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9708 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9709 "-require-any-client-certificate",
9710 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9711 },
9712 })
9713 }
9714}
9715
David Benjaminbbaf3672016-11-17 10:53:09 +09009716func addRetainOnlySHA256ClientCertTests() {
9717 for _, ver := range tlsVersions {
9718 // Test that enabling
9719 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9720 // actually requesting a client certificate is a no-op.
9721 testCases = append(testCases, testCase{
9722 testType: serverTest,
9723 name: "RetainOnlySHA256-NoCert-" + ver.name,
9724 config: Config{
9725 MinVersion: ver.version,
9726 MaxVersion: ver.version,
9727 },
9728 flags: []string{
9729 "-retain-only-sha256-client-cert-initial",
9730 "-retain-only-sha256-client-cert-resume",
9731 },
9732 resumeSession: true,
9733 })
9734
9735 // Test that when retaining only a SHA-256 certificate is
9736 // enabled, the hash appears as expected.
9737 testCases = append(testCases, testCase{
9738 testType: serverTest,
9739 name: "RetainOnlySHA256-Cert-" + ver.name,
9740 config: Config{
9741 MinVersion: ver.version,
9742 MaxVersion: ver.version,
9743 Certificates: []Certificate{rsaCertificate},
9744 },
9745 flags: []string{
9746 "-verify-peer",
9747 "-retain-only-sha256-client-cert-initial",
9748 "-retain-only-sha256-client-cert-resume",
9749 "-expect-sha256-client-cert-initial",
9750 "-expect-sha256-client-cert-resume",
9751 },
9752 resumeSession: true,
9753 })
9754
9755 // Test that when the config changes from on to off, a
9756 // resumption is rejected because the server now wants the full
9757 // certificate chain.
9758 testCases = append(testCases, testCase{
9759 testType: serverTest,
9760 name: "RetainOnlySHA256-OnOff-" + ver.name,
9761 config: Config{
9762 MinVersion: ver.version,
9763 MaxVersion: ver.version,
9764 Certificates: []Certificate{rsaCertificate},
9765 },
9766 flags: []string{
9767 "-verify-peer",
9768 "-retain-only-sha256-client-cert-initial",
9769 "-expect-sha256-client-cert-initial",
9770 },
9771 resumeSession: true,
9772 expectResumeRejected: true,
9773 })
9774
9775 // Test that when the config changes from off to on, a
9776 // resumption is rejected because the server now wants just the
9777 // hash.
9778 testCases = append(testCases, testCase{
9779 testType: serverTest,
9780 name: "RetainOnlySHA256-OffOn-" + ver.name,
9781 config: Config{
9782 MinVersion: ver.version,
9783 MaxVersion: ver.version,
9784 Certificates: []Certificate{rsaCertificate},
9785 },
9786 flags: []string{
9787 "-verify-peer",
9788 "-retain-only-sha256-client-cert-resume",
9789 "-expect-sha256-client-cert-resume",
9790 },
9791 resumeSession: true,
9792 expectResumeRejected: true,
9793 })
9794 }
9795}
9796
Adam Langley7c803a62015-06-15 15:35:05 -07009797func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009798 defer wg.Done()
9799
9800 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009801 var err error
9802
David Benjaminba28dfc2016-11-15 17:47:21 +09009803 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009804 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9805 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009806 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009807 if err != nil {
9808 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9809 }
9810 break
9811 }
9812 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009813 } else if *repeatUntilFailure {
9814 for err == nil {
9815 statusChan <- statusMsg{test: test, started: true}
9816 err = runTest(test, shimPath, -1)
9817 }
9818 } else {
9819 statusChan <- statusMsg{test: test, started: true}
9820 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009821 }
Adam Langley95c29f32014-06-20 12:00:00 -07009822 statusChan <- statusMsg{test: test, err: err}
9823 }
9824}
9825
9826type statusMsg struct {
9827 test *testCase
9828 started bool
9829 err error
9830}
9831
David Benjamin5f237bc2015-02-11 17:14:15 -05009832func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009833 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009834
David Benjamin5f237bc2015-02-11 17:14:15 -05009835 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009836 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009837 if !*pipe {
9838 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009839 var erase string
9840 for i := 0; i < lineLen; i++ {
9841 erase += "\b \b"
9842 }
9843 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009844 }
9845
Adam Langley95c29f32014-06-20 12:00:00 -07009846 if msg.started {
9847 started++
9848 } else {
9849 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009850
9851 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009852 if msg.err == errUnimplemented {
9853 if *pipe {
9854 // Print each test instead of a status line.
9855 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9856 }
9857 unimplemented++
9858 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9859 } else {
9860 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9861 failed++
9862 testOutput.addResult(msg.test.name, "FAIL")
9863 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009864 } else {
9865 if *pipe {
9866 // Print each test instead of a status line.
9867 fmt.Printf("PASSED (%s)\n", msg.test.name)
9868 }
9869 testOutput.addResult(msg.test.name, "PASS")
9870 }
Adam Langley95c29f32014-06-20 12:00:00 -07009871 }
9872
David Benjamin5f237bc2015-02-11 17:14:15 -05009873 if !*pipe {
9874 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009875 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009876 lineLen = len(line)
9877 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009878 }
Adam Langley95c29f32014-06-20 12:00:00 -07009879 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009880
9881 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009882}
9883
9884func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009885 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009886 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009887 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009888
Adam Langley7c803a62015-06-15 15:35:05 -07009889 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009890 addCipherSuiteTests()
9891 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009892 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009893 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009894 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009895 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009896 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009897 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009898 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009899 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009900 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009901 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009902 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009903 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009904 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009905 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009906 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009907 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009908 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009909 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009910 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009911 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009912 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009913 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009914 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009915 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009916 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009917 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009918 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009919 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009920 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009921 addRetainOnlySHA256ClientCertTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009922
9923 var wg sync.WaitGroup
9924
Adam Langley7c803a62015-06-15 15:35:05 -07009925 statusChan := make(chan statusMsg, *numWorkers)
9926 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009927 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009928
EKRf71d7ed2016-08-06 13:25:12 -07009929 if len(*shimConfigFile) != 0 {
9930 encoded, err := ioutil.ReadFile(*shimConfigFile)
9931 if err != nil {
9932 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9933 os.Exit(1)
9934 }
9935
9936 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9937 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9938 os.Exit(1)
9939 }
9940 }
9941
David Benjamin025b3d32014-07-01 19:53:04 -04009942 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009943
Adam Langley7c803a62015-06-15 15:35:05 -07009944 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009945 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009946 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009947 }
9948
David Benjamin270f0a72016-03-17 14:41:36 -04009949 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009950 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009951 matched := true
9952 if len(*testToRun) != 0 {
9953 var err error
9954 matched, err = filepath.Match(*testToRun, testCases[i].name)
9955 if err != nil {
9956 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9957 os.Exit(1)
9958 }
9959 }
9960
EKRf71d7ed2016-08-06 13:25:12 -07009961 if !*includeDisabled {
9962 for pattern := range shimConfig.DisabledTests {
9963 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9964 if err != nil {
9965 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9966 os.Exit(1)
9967 }
9968
9969 if isDisabled {
9970 matched = false
9971 break
9972 }
9973 }
9974 }
9975
David Benjamin17e12922016-07-28 18:04:43 -04009976 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009977 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009978 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +09009979
9980 // Only run one test if repeating until failure.
9981 if *repeatUntilFailure {
9982 break
9983 }
Adam Langley95c29f32014-06-20 12:00:00 -07009984 }
9985 }
David Benjamin17e12922016-07-28 18:04:43 -04009986
David Benjamin270f0a72016-03-17 14:41:36 -04009987 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009988 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009989 os.Exit(1)
9990 }
Adam Langley95c29f32014-06-20 12:00:00 -07009991
9992 close(testChan)
9993 wg.Wait()
9994 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009995 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009996
9997 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009998
9999 if *jsonOutput != "" {
10000 if err := testOutput.writeTo(*jsonOutput); err != nil {
10001 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10002 }
10003 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010004
EKR842ae6c2016-07-27 09:22:05 +020010005 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10006 os.Exit(1)
10007 }
10008
10009 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010010 os.Exit(1)
10011 }
Adam Langley95c29f32014-06-20 12:00:00 -070010012}