blob: d048b80b00c2a603a98a76ff13cabce7636957b1 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090065 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080066)
Adam Langley95c29f32014-06-20 12:00:00 -070067
EKRf71d7ed2016-08-06 13:25:12 -070068// ShimConfigurations is used with the “json” package and represents a shim
69// config file.
70type ShimConfiguration struct {
71 // DisabledTests maps from a glob-based pattern to a freeform string.
72 // The glob pattern is used to exclude tests from being run and the
73 // freeform string is unparsed but expected to explain why the test is
74 // disabled.
75 DisabledTests map[string]string
76
77 // ErrorMap maps from expected error strings to the correct error
78 // string for the shim in question. For example, it might map
79 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
80 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
81 ErrorMap map[string]string
82}
83
84var shimConfig ShimConfiguration
85
David Benjamin33863262016-07-08 17:20:12 -070086type testCert int
87
David Benjamin025b3d32014-07-01 19:53:04 -040088const (
David Benjamin33863262016-07-08 17:20:12 -070089 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040090 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090091 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070092 testCertECDSAP256
93 testCertECDSAP384
94 testCertECDSAP521
95)
96
97const (
98 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040099 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900100 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700101 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
102 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
103 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400104)
105
106const (
David Benjamina08e49d2014-08-24 01:46:07 -0400107 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400108 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900109 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700110 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
111 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
112 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400113 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400114)
115
David Benjamin7944a9f2016-07-12 22:27:01 -0400116var (
117 rsaCertificate Certificate
118 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900119 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400120 ecdsaP256Certificate Certificate
121 ecdsaP384Certificate Certificate
122 ecdsaP521Certificate Certificate
123)
David Benjamin33863262016-07-08 17:20:12 -0700124
125var testCerts = []struct {
126 id testCert
127 certFile, keyFile string
128 cert *Certificate
129}{
130 {
131 id: testCertRSA,
132 certFile: rsaCertificateFile,
133 keyFile: rsaKeyFile,
134 cert: &rsaCertificate,
135 },
136 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 id: testCertRSA1024,
138 certFile: rsa1024CertificateFile,
139 keyFile: rsa1024KeyFile,
140 cert: &rsa1024Certificate,
141 },
142 {
David Benjamin2c516452016-11-15 10:16:54 +0900143 id: testCertRSAChain,
144 certFile: rsaChainCertificateFile,
145 keyFile: rsaChainKeyFile,
146 cert: &rsaChainCertificate,
147 },
148 {
David Benjamin33863262016-07-08 17:20:12 -0700149 id: testCertECDSAP256,
150 certFile: ecdsaP256CertificateFile,
151 keyFile: ecdsaP256KeyFile,
152 cert: &ecdsaP256Certificate,
153 },
154 {
155 id: testCertECDSAP384,
156 certFile: ecdsaP384CertificateFile,
157 keyFile: ecdsaP384KeyFile,
158 cert: &ecdsaP384Certificate,
159 },
160 {
161 id: testCertECDSAP521,
162 certFile: ecdsaP521CertificateFile,
163 keyFile: ecdsaP521KeyFile,
164 cert: &ecdsaP521Certificate,
165 },
166}
167
David Benjamina08e49d2014-08-24 01:46:07 -0400168var channelIDKey *ecdsa.PrivateKey
169var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700170
David Benjamin61f95272014-11-25 01:55:35 -0500171var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800172var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500173
Steven Valdeza833c352016-11-01 13:39:36 -0400174var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800175var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400176
Adam Langley95c29f32014-06-20 12:00:00 -0700177func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700178 for i := range testCerts {
179 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
180 if err != nil {
181 panic(err)
182 }
183 cert.OCSPStaple = testOCSPResponse
184 cert.SignedCertificateTimestampList = testSCTList
185 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700186 }
David Benjamina08e49d2014-08-24 01:46:07 -0400187
Adam Langley7c803a62015-06-15 15:35:05 -0700188 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400189 if err != nil {
190 panic(err)
191 }
192 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
193 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
194 panic("bad key type")
195 }
196 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
197 if err != nil {
198 panic(err)
199 }
200 if channelIDKey.Curve != elliptic.P256() {
201 panic("bad curve")
202 }
203
204 channelIDBytes = make([]byte, 64)
205 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
206 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700207}
208
David Benjamin33863262016-07-08 17:20:12 -0700209func getRunnerCertificate(t testCert) Certificate {
210 for _, cert := range testCerts {
211 if cert.id == t {
212 return *cert.cert
213 }
214 }
215 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700216}
217
David Benjamin33863262016-07-08 17:20:12 -0700218func getShimCertificate(t testCert) string {
219 for _, cert := range testCerts {
220 if cert.id == t {
221 return cert.certFile
222 }
223 }
224 panic("Unknown test certificate")
225}
226
227func getShimKey(t testCert) string {
228 for _, cert := range testCerts {
229 if cert.id == t {
230 return cert.keyFile
231 }
232 }
233 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700234}
235
David Benjamin025b3d32014-07-01 19:53:04 -0400236type testType int
237
238const (
239 clientTest testType = iota
240 serverTest
241)
242
David Benjamin6fd297b2014-08-11 18:43:38 -0400243type protocol int
244
245const (
246 tls protocol = iota
247 dtls
248)
249
David Benjaminfc7b0862014-09-06 13:21:53 -0400250const (
251 alpn = 1
252 npn = 2
253)
254
Adam Langley95c29f32014-06-20 12:00:00 -0700255type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400256 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700258 name string
259 config Config
260 shouldFail bool
261 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700262 // expectedLocalError, if not empty, contains a substring that must be
263 // found in the local error.
264 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400265 // expectedVersion, if non-zero, specifies the TLS version that must be
266 // negotiated.
267 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400268 // expectedResumeVersion, if non-zero, specifies the TLS version that
269 // must be negotiated on resumption. If zero, expectedVersion is used.
270 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400271 // expectedCipher, if non-zero, specifies the TLS cipher suite that
272 // should be negotiated.
273 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400274 // expectChannelID controls whether the connection should have
275 // negotiated a Channel ID with channelIDKey.
276 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400277 // expectedNextProto controls whether the connection should
278 // negotiate a next protocol via NPN or ALPN.
279 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400280 // expectNoNextProto, if true, means that no next protocol should be
281 // negotiated.
282 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400283 // expectedNextProtoType, if non-zero, is the expected next
284 // protocol negotiation mechanism.
285 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500286 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
287 // should be negotiated. If zero, none should be negotiated.
288 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100289 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
290 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100291 // expectedSCTList, if not nil, is the expected SCT list to be received.
292 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700293 // expectedPeerSignatureAlgorithm, if not zero, is the signature
294 // algorithm that the peer should have used in the handshake.
295 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400296 // expectedCurveID, if not zero, is the curve that the handshake should
297 // have used.
298 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700299 // messageLen is the length, in bytes, of the test message that will be
300 // sent.
301 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400302 // messageCount is the number of test messages that will be sent.
303 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400304 // certFile is the path to the certificate to use for the server.
305 certFile string
306 // keyFile is the path to the private key to use for the server.
307 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400308 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400309 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400311 // resumeRenewedSession controls whether a third connection should be
312 // tested which attempts to resume the second connection's session.
313 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700314 // expectResumeRejected, if true, specifies that the attempted
315 // resumption must be rejected by the client. This is only valid for a
316 // serverTest.
317 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400318 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500319 // resumption. Unless newSessionsOnResume is set,
320 // SessionTicketKey, ServerSessionCache, and
321 // ClientSessionCache are copied from the initial connection's
322 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400323 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500324 // newSessionsOnResume, if true, will cause resumeConfig to
325 // use a different session resumption context.
326 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400327 // noSessionCache, if true, will cause the server to run without a
328 // session cache.
329 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400330 // sendPrefix sends a prefix on the socket before actually performing a
331 // handshake.
332 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400333 // shimWritesFirst controls whether the shim sends an initial "hello"
334 // message before doing a roundtrip with the runner.
335 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400336 // shimShutsDown, if true, runs a test where the shim shuts down the
337 // connection immediately after the handshake rather than echoing
338 // messages from the runner.
339 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400340 // renegotiate indicates the number of times the connection should be
341 // renegotiated during the exchange.
342 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400343 // sendHalfHelloRequest, if true, causes the server to send half a
344 // HelloRequest when the handshake completes.
345 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700346 // renegotiateCiphers is a list of ciphersuite ids that will be
347 // switched in just before renegotiation.
348 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500349 // replayWrites, if true, configures the underlying transport
350 // to replay every write it makes in DTLS tests.
351 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500352 // damageFirstWrite, if true, configures the underlying transport to
353 // damage the final byte of the first application data write.
354 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400355 // exportKeyingMaterial, if non-zero, configures the test to exchange
356 // keying material and verify they match.
357 exportKeyingMaterial int
358 exportLabel string
359 exportContext string
360 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400361 // flags, if not empty, contains a list of command-line flags that will
362 // be passed to the shim program.
363 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700364 // testTLSUnique, if true, causes the shim to send the tls-unique value
365 // which will be compared against the expected value.
366 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400367 // sendEmptyRecords is the number of consecutive empty records to send
368 // before and after the test message.
369 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400370 // sendWarningAlerts is the number of consecutive warning alerts to send
371 // before and after the test message.
372 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400373 // sendKeyUpdates is the number of consecutive key updates to send
374 // before and after the test message.
375 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400376 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
377 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400378 // expectMessageDropped, if true, means the test message is expected to
379 // be dropped by the client rather than echoed back.
380 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900381 // expectPeerCertificate, if not nil, is the certificate chain the peer
382 // is expected to send.
383 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700384}
385
Adam Langley7c803a62015-06-15 15:35:05 -0700386var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700387
David Benjaminc07afb72016-09-22 10:18:58 -0400388func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500389 if len(data) == 0 {
390 return
391 }
392
393 protocol := "tls"
394 if test.protocol == dtls {
395 protocol = "dtls"
396 }
397
398 side := "client"
399 if test.testType == serverTest {
400 side = "server"
401 }
402
403 dir := path.Join(*transcriptDir, protocol, side)
404 if err := os.MkdirAll(dir, 0755); err != nil {
405 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
406 return
407 }
408
David Benjaminc07afb72016-09-22 10:18:58 -0400409 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500410 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
411 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
412 }
413}
414
David Benjamin3ed59772016-03-08 12:50:21 -0500415// A timeoutConn implements an idle timeout on each Read and Write operation.
416type timeoutConn struct {
417 net.Conn
418 timeout time.Duration
419}
420
421func (t *timeoutConn) Read(b []byte) (int, error) {
422 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
423 return 0, err
424 }
425 return t.Conn.Read(b)
426}
427
428func (t *timeoutConn) Write(b []byte) (int, error) {
429 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
430 return 0, err
431 }
432 return t.Conn.Write(b)
433}
434
David Benjaminc07afb72016-09-22 10:18:58 -0400435func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400436 if !test.noSessionCache {
437 if config.ClientSessionCache == nil {
438 config.ClientSessionCache = NewLRUClientSessionCache(1)
439 }
440 if config.ServerSessionCache == nil {
441 config.ServerSessionCache = NewLRUServerSessionCache(1)
442 }
443 }
444 if test.testType == clientTest {
445 if len(config.Certificates) == 0 {
446 config.Certificates = []Certificate{rsaCertificate}
447 }
448 } else {
449 // Supply a ServerName to ensure a constant session cache key,
450 // rather than falling back to net.Conn.RemoteAddr.
451 if len(config.ServerName) == 0 {
452 config.ServerName = "test"
453 }
454 }
455 if *fuzzer {
456 config.Bugs.NullAllCiphers = true
457 }
David Benjamin01a90572016-09-22 00:11:43 -0400458 if *deterministic {
459 config.Time = func() time.Time { return time.Unix(1234, 1234) }
460 }
David Benjamine54af062016-08-08 19:21:18 -0400461
David Benjamin01784b42016-06-07 18:00:52 -0400462 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500463
David Benjamin6fd297b2014-08-11 18:43:38 -0400464 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500465 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
466 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500467 }
468
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500470 local, peer := "client", "server"
471 if test.testType == clientTest {
472 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500473 }
David Benjaminebda9b32015-11-02 15:33:18 -0500474 connDebug := &recordingConn{
475 Conn: conn,
476 isDatagram: test.protocol == dtls,
477 local: local,
478 peer: peer,
479 }
480 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 if *flagDebug {
482 defer connDebug.WriteTo(os.Stdout)
483 }
484 if len(*transcriptDir) != 0 {
485 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400486 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500487 }()
488 }
David Benjaminebda9b32015-11-02 15:33:18 -0500489
490 if config.Bugs.PacketAdaptor != nil {
491 config.Bugs.PacketAdaptor.debug = connDebug
492 }
493 }
494
495 if test.replayWrites {
496 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 }
498
David Benjamin3ed59772016-03-08 12:50:21 -0500499 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500500 if test.damageFirstWrite {
501 connDamage = newDamageAdaptor(conn)
502 conn = connDamage
503 }
504
David Benjamin6fd297b2014-08-11 18:43:38 -0400505 if test.sendPrefix != "" {
506 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
507 return err
508 }
David Benjamin98e882e2014-08-08 13:24:34 -0400509 }
510
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400512 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400513 if test.protocol == dtls {
514 tlsConn = DTLSServer(conn, config)
515 } else {
516 tlsConn = Server(conn, config)
517 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400518 } else {
519 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400520 if test.protocol == dtls {
521 tlsConn = DTLSClient(conn, config)
522 } else {
523 tlsConn = Client(conn, config)
524 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400525 }
David Benjamin30789da2015-08-29 22:56:45 -0400526 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400527
Adam Langley95c29f32014-06-20 12:00:00 -0700528 if err := tlsConn.Handshake(); err != nil {
529 return err
530 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700531
David Benjamin01fe8202014-09-24 15:21:44 -0400532 // TODO(davidben): move all per-connection expectations into a dedicated
533 // expectations struct that can be specified separately for the two
534 // legs.
535 expectedVersion := test.expectedVersion
536 if isResume && test.expectedResumeVersion != 0 {
537 expectedVersion = test.expectedResumeVersion
538 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 connState := tlsConn.ConnectionState()
540 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400541 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400542 }
543
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700544 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400545 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
546 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700547 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
548 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
549 }
David Benjamin90da8c82015-04-20 14:57:57 -0400550
David Benjamina08e49d2014-08-24 01:46:07 -0400551 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400553 if channelID == nil {
554 return fmt.Errorf("no channel ID negotiated")
555 }
556 if channelID.Curve != channelIDKey.Curve ||
557 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
558 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
559 return fmt.Errorf("incorrect channel ID")
560 }
561 }
562
David Benjaminae2888f2014-09-06 12:58:58 -0400563 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400565 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
566 }
567 }
568
David Benjaminc7ce9772015-10-09 19:32:41 -0400569 if test.expectNoNextProto {
570 if actual := connState.NegotiatedProtocol; actual != "" {
571 return fmt.Errorf("got unexpected next proto %s", actual)
572 }
573 }
574
David Benjaminfc7b0862014-09-06 13:21:53 -0400575 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700576 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400577 return fmt.Errorf("next proto type mismatch")
578 }
579 }
580
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700581 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500582 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
583 }
584
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100585 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300586 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100587 }
588
Paul Lietar4fac72e2015-09-09 13:44:55 +0100589 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
590 return fmt.Errorf("SCT list mismatch")
591 }
592
Nick Harper60edffd2016-06-21 15:19:24 -0700593 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
594 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400595 }
596
Steven Valdez5440fe02016-07-18 12:40:30 -0400597 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
598 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
599 }
600
David Benjamin2c516452016-11-15 10:16:54 +0900601 if test.expectPeerCertificate != nil {
602 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
603 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
604 }
605 for i, cert := range connState.PeerCertificates {
606 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
607 return fmt.Errorf("peer certificate %d did not match", i+1)
608 }
609 }
610 }
611
David Benjaminc565ebb2015-04-03 04:06:36 -0400612 if test.exportKeyingMaterial > 0 {
613 actual := make([]byte, test.exportKeyingMaterial)
614 if _, err := io.ReadFull(tlsConn, actual); err != nil {
615 return err
616 }
617 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
618 if err != nil {
619 return err
620 }
621 if !bytes.Equal(actual, expected) {
622 return fmt.Errorf("keying material mismatch")
623 }
624 }
625
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700626 if test.testTLSUnique {
627 var peersValue [12]byte
628 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
629 return err
630 }
631 expected := tlsConn.ConnectionState().TLSUnique
632 if !bytes.Equal(peersValue[:], expected) {
633 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
634 }
635 }
636
David Benjamine58c4f52014-08-24 03:47:07 -0400637 if test.shimWritesFirst {
638 var buf [5]byte
639 _, err := io.ReadFull(tlsConn, buf[:])
640 if err != nil {
641 return err
642 }
643 if string(buf[:]) != "hello" {
644 return fmt.Errorf("bad initial message")
645 }
646 }
647
Steven Valdez32635b82016-08-16 11:25:03 -0400648 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400649 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400650 return err
651 }
Steven Valdez32635b82016-08-16 11:25:03 -0400652 }
653
David Benjamina8ebe222015-06-06 03:04:39 -0400654 for i := 0; i < test.sendEmptyRecords; i++ {
655 tlsConn.Write(nil)
656 }
657
David Benjamin24f346d2015-06-06 03:28:08 -0400658 for i := 0; i < test.sendWarningAlerts; i++ {
659 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
660 }
661
David Benjamin47921102016-07-28 11:29:18 -0400662 if test.sendHalfHelloRequest {
663 tlsConn.SendHalfHelloRequest()
664 }
665
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400666 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700667 if test.renegotiateCiphers != nil {
668 config.CipherSuites = test.renegotiateCiphers
669 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400670 for i := 0; i < test.renegotiate; i++ {
671 if err := tlsConn.Renegotiate(); err != nil {
672 return err
673 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700674 }
675 } else if test.renegotiateCiphers != nil {
676 panic("renegotiateCiphers without renegotiate")
677 }
678
David Benjamin5fa3eba2015-01-22 16:35:40 -0500679 if test.damageFirstWrite {
680 connDamage.setDamage(true)
681 tlsConn.Write([]byte("DAMAGED WRITE"))
682 connDamage.setDamage(false)
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700686 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400687 if test.protocol == dtls {
688 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
689 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700690 // Read until EOF.
691 _, err := io.Copy(ioutil.Discard, tlsConn)
692 return err
693 }
David Benjamin4417d052015-04-05 04:17:25 -0400694 if messageLen == 0 {
695 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700696 }
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 messageCount := test.messageCount
699 if messageCount == 0 {
700 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400701 }
702
David Benjamin8e6db492015-07-25 18:29:23 -0400703 for j := 0; j < messageCount; j++ {
704 testMessage := make([]byte, messageLen)
705 for i := range testMessage {
706 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400707 }
David Benjamin8e6db492015-07-25 18:29:23 -0400708 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700709
Steven Valdez32635b82016-08-16 11:25:03 -0400710 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400711 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400712 }
713
David Benjamin8e6db492015-07-25 18:29:23 -0400714 for i := 0; i < test.sendEmptyRecords; i++ {
715 tlsConn.Write(nil)
716 }
717
718 for i := 0; i < test.sendWarningAlerts; i++ {
719 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
720 }
721
David Benjamin4f75aaf2015-09-01 16:53:10 -0400722 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400723 // The shim will not respond.
724 continue
725 }
726
David Benjamin8e6db492015-07-25 18:29:23 -0400727 buf := make([]byte, len(testMessage))
728 if test.protocol == dtls {
729 bufTmp := make([]byte, len(buf)+1)
730 n, err := tlsConn.Read(bufTmp)
731 if err != nil {
732 return err
733 }
734 if n != len(buf) {
735 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
736 }
737 copy(buf, bufTmp)
738 } else {
739 _, err := io.ReadFull(tlsConn, buf)
740 if err != nil {
741 return err
742 }
743 }
744
745 for i, v := range buf {
746 if v != testMessage[i]^0xff {
747 return fmt.Errorf("bad reply contents at byte %d", i)
748 }
Adam Langley95c29f32014-06-20 12:00:00 -0700749 }
750 }
751
752 return nil
753}
754
David Benjamin325b5c32014-07-01 19:40:31 -0400755func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400756 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700757 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400758 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700759 }
David Benjamin325b5c32014-07-01 19:40:31 -0400760 valgrindArgs = append(valgrindArgs, path)
761 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700762
David Benjamin325b5c32014-07-01 19:40:31 -0400763 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
David Benjamin325b5c32014-07-01 19:40:31 -0400766func gdbOf(path string, args ...string) *exec.Cmd {
767 xtermArgs := []string{"-e", "gdb", "--args"}
768 xtermArgs = append(xtermArgs, path)
769 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamind16bf342015-12-18 00:53:12 -0500774func lldbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "lldb", "--"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
778
779 return exec.Command("xterm", xtermArgs...)
780}
781
EKR842ae6c2016-07-27 09:22:05 +0200782var (
783 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
784 errUnimplemented = errors.New("child process does not implement needed flags")
785)
Adam Langley69a01602014-11-17 17:26:55 -0800786
David Benjamin87c8a642015-02-21 01:54:29 -0500787// accept accepts a connection from listener, unless waitChan signals a process
788// exit first.
789func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
790 type connOrError struct {
791 conn net.Conn
792 err error
793 }
794 connChan := make(chan connOrError, 1)
795 go func() {
796 conn, err := listener.Accept()
797 connChan <- connOrError{conn, err}
798 close(connChan)
799 }()
800 select {
801 case result := <-connChan:
802 return result.conn, result.err
803 case childErr := <-waitChan:
804 waitChan <- childErr
805 return nil, fmt.Errorf("child exited early: %s", childErr)
806 }
807}
808
EKRf71d7ed2016-08-06 13:25:12 -0700809func translateExpectedError(errorStr string) string {
810 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
811 return translated
812 }
813
814 if *looseErrors {
815 return ""
816 }
817
818 return errorStr
819}
820
Adam Langley7c803a62015-06-15 15:35:05 -0700821func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400822 // Help debugging panics on the Go side.
823 defer func() {
824 if r := recover(); r != nil {
825 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
826 panic(r)
827 }
828 }()
829
Adam Langley38311732014-10-16 19:04:35 -0700830 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
831 panic("Error expected without shouldFail in " + test.name)
832 }
833
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700834 if test.expectResumeRejected && !test.resumeSession {
835 panic("expectResumeRejected without resumeSession in " + test.name)
836 }
837
David Benjamin87c8a642015-02-21 01:54:29 -0500838 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
839 if err != nil {
840 panic(err)
841 }
842 defer func() {
843 if listener != nil {
844 listener.Close()
845 }
846 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700847
David Benjamin87c8a642015-02-21 01:54:29 -0500848 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400849 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400850 flags = append(flags, "-server")
851
David Benjamin025b3d32014-07-01 19:53:04 -0400852 flags = append(flags, "-key-file")
853 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700854 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400855 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700856 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400857 }
858
859 flags = append(flags, "-cert-file")
860 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700861 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400862 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700863 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400864 }
865 }
David Benjamin5a593af2014-08-11 19:51:50 -0400866
David Benjamin6fd297b2014-08-11 18:43:38 -0400867 if test.protocol == dtls {
868 flags = append(flags, "-dtls")
869 }
870
David Benjamin46662482016-08-17 00:51:00 -0400871 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400872 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400873 resumeCount++
874 if test.resumeRenewedSession {
875 resumeCount++
876 }
877 }
878
879 if resumeCount > 0 {
880 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400881 }
882
David Benjamine58c4f52014-08-24 03:47:07 -0400883 if test.shimWritesFirst {
884 flags = append(flags, "-shim-writes-first")
885 }
886
David Benjamin30789da2015-08-29 22:56:45 -0400887 if test.shimShutsDown {
888 flags = append(flags, "-shim-shuts-down")
889 }
890
David Benjaminc565ebb2015-04-03 04:06:36 -0400891 if test.exportKeyingMaterial > 0 {
892 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
893 flags = append(flags, "-export-label", test.exportLabel)
894 flags = append(flags, "-export-context", test.exportContext)
895 if test.useExportContext {
896 flags = append(flags, "-use-export-context")
897 }
898 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700899 if test.expectResumeRejected {
900 flags = append(flags, "-expect-session-miss")
901 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400902
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700903 if test.testTLSUnique {
904 flags = append(flags, "-tls-unique")
905 }
906
David Benjamin025b3d32014-07-01 19:53:04 -0400907 flags = append(flags, test.flags...)
908
909 var shim *exec.Cmd
910 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700911 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700912 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700913 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500914 } else if *useLLDB {
915 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400916 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700917 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400918 }
David Benjamin025b3d32014-07-01 19:53:04 -0400919 shim.Stdin = os.Stdin
920 var stdoutBuf, stderrBuf bytes.Buffer
921 shim.Stdout = &stdoutBuf
922 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800923 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500924 shim.Env = os.Environ()
925 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800926 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400927 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800928 }
929 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
930 }
David Benjamin025b3d32014-07-01 19:53:04 -0400931
932 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700933 panic(err)
934 }
David Benjamin87c8a642015-02-21 01:54:29 -0500935 waitChan := make(chan error, 1)
936 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700937
938 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700939
David Benjamin7a4aaa42016-09-20 17:58:14 -0400940 if *deterministic {
941 config.Rand = &deterministicRand{}
942 }
943
David Benjamin87c8a642015-02-21 01:54:29 -0500944 conn, err := acceptOrWait(listener, waitChan)
945 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400946 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500947 conn.Close()
948 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500949
David Benjamin46662482016-08-17 00:51:00 -0400950 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400951 var resumeConfig Config
952 if test.resumeConfig != nil {
953 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400954 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500955 resumeConfig.SessionTicketKey = config.SessionTicketKey
956 resumeConfig.ClientSessionCache = config.ClientSessionCache
957 resumeConfig.ServerSessionCache = config.ServerSessionCache
958 }
David Benjamin2e045a92016-06-08 13:09:56 -0400959 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400960 } else {
961 resumeConfig = config
962 }
David Benjamin87c8a642015-02-21 01:54:29 -0500963 var connResume net.Conn
964 connResume, err = acceptOrWait(listener, waitChan)
965 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400966 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500967 connResume.Close()
968 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400969 }
970
David Benjamin87c8a642015-02-21 01:54:29 -0500971 // Close the listener now. This is to avoid hangs should the shim try to
972 // open more connections than expected.
973 listener.Close()
974 listener = nil
975
976 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400977 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800978 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200979 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
980 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800981 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200982 case 89:
983 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400984 case 99:
985 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800986 }
987 }
Adam Langley95c29f32014-06-20 12:00:00 -0700988
David Benjamin9bea3492016-03-02 10:59:16 -0500989 // Account for Windows line endings.
990 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
991 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500992
993 // Separate the errors from the shim and those from tools like
994 // AddressSanitizer.
995 var extraStderr string
996 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
997 stderr = stderrParts[0]
998 extraStderr = stderrParts[1]
999 }
1000
Adam Langley95c29f32014-06-20 12:00:00 -07001001 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001002 expectedError := translateExpectedError(test.expectedError)
1003 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001004
Adam Langleyac61fa32014-06-23 12:03:11 -07001005 localError := "none"
1006 if err != nil {
1007 localError = err.Error()
1008 }
1009 if len(test.expectedLocalError) != 0 {
1010 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1011 }
Adam Langley95c29f32014-06-20 12:00:00 -07001012
1013 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001014 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001015 if childErr != nil {
1016 childError = childErr.Error()
1017 }
1018
1019 var msg string
1020 switch {
1021 case failed && !test.shouldFail:
1022 msg = "unexpected failure"
1023 case !failed && test.shouldFail:
1024 msg = "unexpected success"
1025 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001026 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001027 default:
1028 panic("internal error")
1029 }
1030
David Benjamin9aafb642016-09-20 19:36:53 -04001031 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001032 }
1033
David Benjamind2ba8892016-09-20 19:41:04 -04001034 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001035 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001036 }
1037
David Benjamind2ba8892016-09-20 19:41:04 -04001038 if *useValgrind && isValgrindError {
1039 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1040 }
1041
Adam Langley95c29f32014-06-20 12:00:00 -07001042 return nil
1043}
1044
1045var tlsVersions = []struct {
1046 name string
1047 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001048 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001049 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001050}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001051 {"SSL3", VersionSSL30, "-no-ssl3", false},
1052 {"TLS1", VersionTLS10, "-no-tls1", true},
1053 {"TLS11", VersionTLS11, "-no-tls11", false},
1054 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001055 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001056}
1057
1058var testCipherSuites = []struct {
1059 name string
1060 id uint16
1061}{
1062 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001063 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001064 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001065 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001066 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001067 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001068 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001069 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1070 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001071 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001072 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1073 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001074 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001075 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1076 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001077 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1078 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001079 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001080 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001081 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001082 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001083 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001084 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001085 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001086 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001087 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001088 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001089 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001090 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001091 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1092 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1093 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1094 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001095 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1096 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001097 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1098 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001099 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001100 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1101 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1102 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001103 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001104}
1105
David Benjamin8b8c0062014-11-23 02:47:52 -05001106func hasComponent(suiteName, component string) bool {
1107 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1108}
1109
David Benjaminf7768e42014-08-31 02:06:47 -04001110func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001111 return hasComponent(suiteName, "GCM") ||
1112 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001113 hasComponent(suiteName, "SHA384") ||
1114 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001115}
1116
Nick Harper1fd39d82016-06-14 18:14:35 -07001117func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001118 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001119}
1120
David Benjamin8b8c0062014-11-23 02:47:52 -05001121func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001122 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001123}
1124
Adam Langleya7997f12015-05-14 17:38:50 -07001125func bigFromHex(hex string) *big.Int {
1126 ret, ok := new(big.Int).SetString(hex, 16)
1127 if !ok {
1128 panic("failed to parse hex number 0x" + hex)
1129 }
1130 return ret
1131}
1132
Adam Langley7c803a62015-06-15 15:35:05 -07001133func addBasicTests() {
1134 basicTests := []testCase{
1135 {
Adam Langley7c803a62015-06-15 15:35:05 -07001136 name: "NoFallbackSCSV",
1137 config: Config{
1138 Bugs: ProtocolBugs{
1139 FailIfNotFallbackSCSV: true,
1140 },
1141 },
1142 shouldFail: true,
1143 expectedLocalError: "no fallback SCSV found",
1144 },
1145 {
1146 name: "SendFallbackSCSV",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 FailIfNotFallbackSCSV: true,
1150 },
1151 },
1152 flags: []string{"-fallback-scsv"},
1153 },
1154 {
1155 name: "ClientCertificateTypes",
1156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001157 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001158 ClientAuth: RequestClientCert,
1159 ClientCertificateTypes: []byte{
1160 CertTypeDSSSign,
1161 CertTypeRSASign,
1162 CertTypeECDSASign,
1163 },
1164 },
1165 flags: []string{
1166 "-expect-certificate-types",
1167 base64.StdEncoding.EncodeToString([]byte{
1168 CertTypeDSSSign,
1169 CertTypeRSASign,
1170 CertTypeECDSASign,
1171 }),
1172 },
1173 },
1174 {
Adam Langley7c803a62015-06-15 15:35:05 -07001175 name: "UnauthenticatedECDH",
1176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1179 Bugs: ProtocolBugs{
1180 UnauthenticatedECDH: true,
1181 },
1182 },
1183 shouldFail: true,
1184 expectedError: ":UNEXPECTED_MESSAGE:",
1185 },
1186 {
1187 name: "SkipCertificateStatus",
1188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1191 Bugs: ProtocolBugs{
1192 SkipCertificateStatus: true,
1193 },
1194 },
1195 flags: []string{
1196 "-enable-ocsp-stapling",
1197 },
1198 },
1199 {
1200 name: "SkipServerKeyExchange",
1201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001202 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001203 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1204 Bugs: ProtocolBugs{
1205 SkipServerKeyExchange: true,
1206 },
1207 },
1208 shouldFail: true,
1209 expectedError: ":UNEXPECTED_MESSAGE:",
1210 },
1211 {
Adam Langley7c803a62015-06-15 15:35:05 -07001212 testType: serverTest,
1213 name: "Alert",
1214 config: Config{
1215 Bugs: ProtocolBugs{
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "Alert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1233 },
1234 {
1235 testType: serverTest,
1236 name: "FragmentAlert",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 FragmentAlert: true,
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":BAD_ALERT:",
1245 },
1246 {
1247 protocol: dtls,
1248 testType: serverTest,
1249 name: "FragmentAlert-DTLS",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 FragmentAlert: true,
1253 SendSpuriousAlert: alertRecordOverflow,
1254 },
1255 },
1256 shouldFail: true,
1257 expectedError: ":BAD_ALERT:",
1258 },
1259 {
1260 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001261 name: "DoubleAlert",
1262 config: Config{
1263 Bugs: ProtocolBugs{
1264 DoubleAlert: true,
1265 SendSpuriousAlert: alertRecordOverflow,
1266 },
1267 },
1268 shouldFail: true,
1269 expectedError: ":BAD_ALERT:",
1270 },
1271 {
1272 protocol: dtls,
1273 testType: serverTest,
1274 name: "DoubleAlert-DTLS",
1275 config: Config{
1276 Bugs: ProtocolBugs{
1277 DoubleAlert: true,
1278 SendSpuriousAlert: alertRecordOverflow,
1279 },
1280 },
1281 shouldFail: true,
1282 expectedError: ":BAD_ALERT:",
1283 },
1284 {
Adam Langley7c803a62015-06-15 15:35:05 -07001285 name: "SkipNewSessionTicket",
1286 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001287 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001288 Bugs: ProtocolBugs{
1289 SkipNewSessionTicket: true,
1290 },
1291 },
1292 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001293 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001294 },
1295 {
1296 testType: serverTest,
1297 name: "FallbackSCSV",
1298 config: Config{
1299 MaxVersion: VersionTLS11,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 shouldFail: true,
1305 expectedError: ":INAPPROPRIATE_FALLBACK:",
1306 },
1307 {
1308 testType: serverTest,
1309 name: "FallbackSCSV-VersionMatch",
1310 config: Config{
1311 Bugs: ProtocolBugs{
1312 SendFallbackSCSV: true,
1313 },
1314 },
1315 },
1316 {
1317 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001318 name: "FallbackSCSV-VersionMatch-TLS12",
1319 config: Config{
1320 MaxVersion: VersionTLS12,
1321 Bugs: ProtocolBugs{
1322 SendFallbackSCSV: true,
1323 },
1324 },
1325 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1326 },
1327 {
1328 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001329 name: "FragmentedClientVersion",
1330 config: Config{
1331 Bugs: ProtocolBugs{
1332 MaxHandshakeRecordLength: 1,
1333 FragmentClientVersion: true,
1334 },
1335 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001336 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001337 },
1338 {
Adam Langley7c803a62015-06-15 15:35:05 -07001339 testType: serverTest,
1340 name: "HttpGET",
1341 sendPrefix: "GET / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpPOST",
1348 sendPrefix: "POST / HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTP_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "HttpHEAD",
1355 sendPrefix: "HEAD / HTTP/1.0\n",
1356 shouldFail: true,
1357 expectedError: ":HTTP_REQUEST:",
1358 },
1359 {
1360 testType: serverTest,
1361 name: "HttpPUT",
1362 sendPrefix: "PUT / HTTP/1.0\n",
1363 shouldFail: true,
1364 expectedError: ":HTTP_REQUEST:",
1365 },
1366 {
1367 testType: serverTest,
1368 name: "HttpCONNECT",
1369 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1370 shouldFail: true,
1371 expectedError: ":HTTPS_PROXY_REQUEST:",
1372 },
1373 {
1374 testType: serverTest,
1375 name: "Garbage",
1376 sendPrefix: "blah",
1377 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001378 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001379 },
1380 {
Adam Langley7c803a62015-06-15 15:35:05 -07001381 name: "RSAEphemeralKey",
1382 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001383 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001384 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1385 Bugs: ProtocolBugs{
1386 RSAEphemeralKey: true,
1387 },
1388 },
1389 shouldFail: true,
1390 expectedError: ":UNEXPECTED_MESSAGE:",
1391 },
1392 {
1393 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001394 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001395 shouldFail: true,
1396 expectedError: ":WRONG_SSL_VERSION:",
1397 },
1398 {
1399 protocol: dtls,
1400 name: "DisableEverything-DTLS",
1401 flags: []string{"-no-tls12", "-no-tls1"},
1402 shouldFail: true,
1403 expectedError: ":WRONG_SSL_VERSION:",
1404 },
1405 {
Adam Langley7c803a62015-06-15 15:35:05 -07001406 protocol: dtls,
1407 testType: serverTest,
1408 name: "MTU",
1409 config: Config{
1410 Bugs: ProtocolBugs{
1411 MaxPacketLength: 256,
1412 },
1413 },
1414 flags: []string{"-mtu", "256"},
1415 },
1416 {
1417 protocol: dtls,
1418 testType: serverTest,
1419 name: "MTUExceeded",
1420 config: Config{
1421 Bugs: ProtocolBugs{
1422 MaxPacketLength: 255,
1423 },
1424 },
1425 flags: []string{"-mtu", "256"},
1426 shouldFail: true,
1427 expectedLocalError: "dtls: exceeded maximum packet length",
1428 },
1429 {
1430 name: "CertMismatchRSA",
1431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001432 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001433 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001434 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001435 Bugs: ProtocolBugs{
1436 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1441 },
1442 {
1443 name: "CertMismatchECDSA",
1444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001445 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001446 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001447 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001448 Bugs: ProtocolBugs{
1449 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1450 },
1451 },
1452 shouldFail: true,
1453 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1454 },
1455 {
1456 name: "EmptyCertificateList",
1457 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001458 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001459 Bugs: ProtocolBugs{
1460 EmptyCertificateList: true,
1461 },
1462 },
1463 shouldFail: true,
1464 expectedError: ":DECODE_ERROR:",
1465 },
1466 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001467 name: "EmptyCertificateList-TLS13",
1468 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001469 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 Bugs: ProtocolBugs{
1471 EmptyCertificateList: true,
1472 },
1473 },
1474 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001476 },
1477 {
Adam Langley7c803a62015-06-15 15:35:05 -07001478 name: "TLSFatalBadPackets",
1479 damageFirstWrite: true,
1480 shouldFail: true,
1481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets",
1486 damageFirstWrite: true,
1487 },
1488 {
1489 protocol: dtls,
1490 name: "DTLSIgnoreBadPackets-Async",
1491 damageFirstWrite: true,
1492 flags: []string{"-async"},
1493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataBeforeHandshake",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
1505 name: "AppDataBeforeHandshake-Empty",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 AppDataBeforeHandshake: []byte{},
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AppDataBeforeHandshake-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 protocol: dtls,
1527 name: "AppDataBeforeHandshake-DTLS-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
Adam Langley7c803a62015-06-15 15:35:05 -07001537 name: "AppDataAfterChangeCipherSpec",
1538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001539 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001540 Bugs: ProtocolBugs{
1541 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001545 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001546 },
1547 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 name: "AppDataAfterChangeCipherSpec-Empty",
1549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001550 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001551 Bugs: ProtocolBugs{
1552 AppDataAfterChangeCipherSpec: []byte{},
1553 },
1554 },
1555 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001556 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 name: "AppDataAfterChangeCipherSpec-DTLS",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1565 },
1566 },
1567 // BoringSSL's DTLS implementation will drop the out-of-order
1568 // application data.
1569 },
1570 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte{},
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "AlertAfterChangeCipherSpec",
1584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 AlertAfterChangeCipherSpec: alertRecordOverflow,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1592 },
1593 {
1594 protocol: dtls,
1595 name: "AlertAfterChangeCipherSpec-DTLS",
1596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 Bugs: ProtocolBugs{
1599 AlertAfterChangeCipherSpec: alertRecordOverflow,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "ReorderHandshakeFragments-Small-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 ReorderHandshakeFragments: true,
1611 // Small enough that every handshake message is
1612 // fragmented.
1613 MaxHandshakeRecordLength: 2,
1614 },
1615 },
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Large-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Large enough that no handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2048,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "MixCompleteMessageWithFragments-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 MixCompleteMessageWithFragments: true,
1636 MaxHandshakeRecordLength: 2,
1637 },
1638 },
1639 },
1640 {
1641 name: "SendInvalidRecordType",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "SendInvalidRecordType-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 SendInvalidRecordType: true,
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
1662 name: "FalseStart-SkipServerSecondLeg",
1663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 SkipNewSessionTicket: true,
1669 SkipChangeCipherSpec: true,
1670 SkipFinished: true,
1671 ExpectFalseStart: true,
1672 },
1673 },
1674 flags: []string{
1675 "-false-start",
1676 "-handshake-never-done",
1677 "-advertise-alpn", "\x03foo",
1678 },
1679 shimWritesFirst: true,
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg-Implicit",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 },
1694 },
1695 flags: []string{
1696 "-implicit-handshake",
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shouldFail: true,
1702 expectedError: ":UNEXPECTED_RECORD:",
1703 },
1704 {
1705 testType: serverTest,
1706 name: "FailEarlyCallback",
1707 flags: []string{"-fail-early-callback"},
1708 shouldFail: true,
1709 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001710 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001711 },
1712 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001713 name: "FailCertCallback-Client-TLS12",
1714 config: Config{
1715 MaxVersion: VersionTLS12,
1716 ClientAuth: RequestClientCert,
1717 },
1718 flags: []string{"-fail-cert-callback"},
1719 shouldFail: true,
1720 expectedError: ":CERT_CB_ERROR:",
1721 expectedLocalError: "remote error: internal error",
1722 },
1723 {
1724 testType: serverTest,
1725 name: "FailCertCallback-Server-TLS12",
1726 config: Config{
1727 MaxVersion: VersionTLS12,
1728 },
1729 flags: []string{"-fail-cert-callback"},
1730 shouldFail: true,
1731 expectedError: ":CERT_CB_ERROR:",
1732 expectedLocalError: "remote error: internal error",
1733 },
1734 {
1735 name: "FailCertCallback-Client-TLS13",
1736 config: Config{
1737 MaxVersion: VersionTLS13,
1738 ClientAuth: RequestClientCert,
1739 },
1740 flags: []string{"-fail-cert-callback"},
1741 shouldFail: true,
1742 expectedError: ":CERT_CB_ERROR:",
1743 expectedLocalError: "remote error: internal error",
1744 },
1745 {
1746 testType: serverTest,
1747 name: "FailCertCallback-Server-TLS13",
1748 config: Config{
1749 MaxVersion: VersionTLS13,
1750 },
1751 flags: []string{"-fail-cert-callback"},
1752 shouldFail: true,
1753 expectedError: ":CERT_CB_ERROR:",
1754 expectedLocalError: "remote error: internal error",
1755 },
1756 {
Adam Langley7c803a62015-06-15 15:35:05 -07001757 protocol: dtls,
1758 name: "FragmentMessageTypeMismatch-DTLS",
1759 config: Config{
1760 Bugs: ProtocolBugs{
1761 MaxHandshakeRecordLength: 2,
1762 FragmentMessageTypeMismatch: true,
1763 },
1764 },
1765 shouldFail: true,
1766 expectedError: ":FRAGMENT_MISMATCH:",
1767 },
1768 {
1769 protocol: dtls,
1770 name: "FragmentMessageLengthMismatch-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 MaxHandshakeRecordLength: 2,
1774 FragmentMessageLengthMismatch: true,
1775 },
1776 },
1777 shouldFail: true,
1778 expectedError: ":FRAGMENT_MISMATCH:",
1779 },
1780 {
1781 protocol: dtls,
1782 name: "SplitFragments-Header-DTLS",
1783 config: Config{
1784 Bugs: ProtocolBugs{
1785 SplitFragments: 2,
1786 },
1787 },
1788 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001789 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001790 },
1791 {
1792 protocol: dtls,
1793 name: "SplitFragments-Boundary-DTLS",
1794 config: Config{
1795 Bugs: ProtocolBugs{
1796 SplitFragments: dtlsRecordHeaderLen,
1797 },
1798 },
1799 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001800 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001801 },
1802 {
1803 protocol: dtls,
1804 name: "SplitFragments-Body-DTLS",
1805 config: Config{
1806 Bugs: ProtocolBugs{
1807 SplitFragments: dtlsRecordHeaderLen + 1,
1808 },
1809 },
1810 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001811 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001812 },
1813 {
1814 protocol: dtls,
1815 name: "SendEmptyFragments-DTLS",
1816 config: Config{
1817 Bugs: ProtocolBugs{
1818 SendEmptyFragments: true,
1819 },
1820 },
1821 },
1822 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001823 name: "BadFinished-Client",
1824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001825 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001826 Bugs: ProtocolBugs{
1827 BadFinished: true,
1828 },
1829 },
1830 shouldFail: true,
1831 expectedError: ":DIGEST_CHECK_FAILED:",
1832 },
1833 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001834 name: "BadFinished-Client-TLS13",
1835 config: Config{
1836 MaxVersion: VersionTLS13,
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 },
1840 },
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001845 testType: serverTest,
1846 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001848 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001849 Bugs: ProtocolBugs{
1850 BadFinished: true,
1851 },
1852 },
1853 shouldFail: true,
1854 expectedError: ":DIGEST_CHECK_FAILED:",
1855 },
1856 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001857 testType: serverTest,
1858 name: "BadFinished-Server-TLS13",
1859 config: Config{
1860 MaxVersion: VersionTLS13,
1861 Bugs: ProtocolBugs{
1862 BadFinished: true,
1863 },
1864 },
1865 shouldFail: true,
1866 expectedError: ":DIGEST_CHECK_FAILED:",
1867 },
1868 {
Adam Langley7c803a62015-06-15 15:35:05 -07001869 name: "FalseStart-BadFinished",
1870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1873 NextProtos: []string{"foo"},
1874 Bugs: ProtocolBugs{
1875 BadFinished: true,
1876 ExpectFalseStart: true,
1877 },
1878 },
1879 flags: []string{
1880 "-false-start",
1881 "-handshake-never-done",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":DIGEST_CHECK_FAILED:",
1887 },
1888 {
1889 name: "NoFalseStart-NoALPN",
1890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001891 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1893 Bugs: ProtocolBugs{
1894 ExpectFalseStart: true,
1895 AlertBeforeFalseStartTest: alertAccessDenied,
1896 },
1897 },
1898 flags: []string{
1899 "-false-start",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-NoAEAD",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
1927 name: "NoFalseStart-RSA",
1928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001929 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001930 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1931 NextProtos: []string{"foo"},
1932 Bugs: ProtocolBugs{
1933 ExpectFalseStart: true,
1934 AlertBeforeFalseStartTest: alertAccessDenied,
1935 },
1936 },
1937 flags: []string{
1938 "-false-start",
1939 "-advertise-alpn", "\x03foo",
1940 },
1941 shimWritesFirst: true,
1942 shouldFail: true,
1943 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1944 expectedLocalError: "tls: peer did not false start: EOF",
1945 },
1946 {
1947 name: "NoFalseStart-DHE_RSA",
1948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001949 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001950 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1951 NextProtos: []string{"foo"},
1952 Bugs: ProtocolBugs{
1953 ExpectFalseStart: true,
1954 AlertBeforeFalseStartTest: alertAccessDenied,
1955 },
1956 },
1957 flags: []string{
1958 "-false-start",
1959 "-advertise-alpn", "\x03foo",
1960 },
1961 shimWritesFirst: true,
1962 shouldFail: true,
1963 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1964 expectedLocalError: "tls: peer did not false start: EOF",
1965 },
1966 {
Adam Langley7c803a62015-06-15 15:35:05 -07001967 protocol: dtls,
1968 name: "SendSplitAlert-Sync",
1969 config: Config{
1970 Bugs: ProtocolBugs{
1971 SendSplitAlert: true,
1972 },
1973 },
1974 },
1975 {
1976 protocol: dtls,
1977 name: "SendSplitAlert-Async",
1978 config: Config{
1979 Bugs: ProtocolBugs{
1980 SendSplitAlert: true,
1981 },
1982 },
1983 flags: []string{"-async"},
1984 },
1985 {
1986 protocol: dtls,
1987 name: "PackDTLSHandshake",
1988 config: Config{
1989 Bugs: ProtocolBugs{
1990 MaxHandshakeRecordLength: 2,
1991 PackHandshakeFragments: 20,
1992 PackHandshakeRecords: 200,
1993 },
1994 },
1995 },
1996 {
Adam Langley7c803a62015-06-15 15:35:05 -07001997 name: "SendEmptyRecords-Pass",
1998 sendEmptyRecords: 32,
1999 },
2000 {
2001 name: "SendEmptyRecords",
2002 sendEmptyRecords: 33,
2003 shouldFail: true,
2004 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2005 },
2006 {
2007 name: "SendEmptyRecords-Async",
2008 sendEmptyRecords: 33,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2012 },
2013 {
David Benjamine8e84b92016-08-03 15:39:47 -04002014 name: "SendWarningAlerts-Pass",
2015 config: Config{
2016 MaxVersion: VersionTLS12,
2017 },
Adam Langley7c803a62015-06-15 15:35:05 -07002018 sendWarningAlerts: 4,
2019 },
2020 {
David Benjamine8e84b92016-08-03 15:39:47 -04002021 protocol: dtls,
2022 name: "SendWarningAlerts-DTLS-Pass",
2023 config: Config{
2024 MaxVersion: VersionTLS12,
2025 },
Adam Langley7c803a62015-06-15 15:35:05 -07002026 sendWarningAlerts: 4,
2027 },
2028 {
David Benjamine8e84b92016-08-03 15:39:47 -04002029 name: "SendWarningAlerts-TLS13",
2030 config: Config{
2031 MaxVersion: VersionTLS13,
2032 },
2033 sendWarningAlerts: 4,
2034 shouldFail: true,
2035 expectedError: ":BAD_ALERT:",
2036 expectedLocalError: "remote error: error decoding message",
2037 },
2038 {
2039 name: "SendWarningAlerts",
2040 config: Config{
2041 MaxVersion: VersionTLS12,
2042 },
Adam Langley7c803a62015-06-15 15:35:05 -07002043 sendWarningAlerts: 5,
2044 shouldFail: true,
2045 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2046 },
2047 {
David Benjamine8e84b92016-08-03 15:39:47 -04002048 name: "SendWarningAlerts-Async",
2049 config: Config{
2050 MaxVersion: VersionTLS12,
2051 },
Adam Langley7c803a62015-06-15 15:35:05 -07002052 sendWarningAlerts: 5,
2053 flags: []string{"-async"},
2054 shouldFail: true,
2055 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2056 },
David Benjaminba4594a2015-06-18 18:36:15 -04002057 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002058 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002059 config: Config{
2060 MaxVersion: VersionTLS13,
2061 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002062 sendKeyUpdates: 33,
2063 keyUpdateRequest: keyUpdateNotRequested,
2064 shouldFail: true,
2065 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002066 },
2067 {
David Benjaminba4594a2015-06-18 18:36:15 -04002068 name: "EmptySessionID",
2069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002070 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002071 SessionTicketsDisabled: true,
2072 },
2073 noSessionCache: true,
2074 flags: []string{"-expect-no-session"},
2075 },
David Benjamin30789da2015-08-29 22:56:45 -04002076 {
2077 name: "Unclean-Shutdown",
2078 config: Config{
2079 Bugs: ProtocolBugs{
2080 NoCloseNotify: true,
2081 ExpectCloseNotify: true,
2082 },
2083 },
2084 shimShutsDown: true,
2085 flags: []string{"-check-close-notify"},
2086 shouldFail: true,
2087 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2088 },
2089 {
2090 name: "Unclean-Shutdown-Ignored",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 NoCloseNotify: true,
2094 },
2095 },
2096 shimShutsDown: true,
2097 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002098 {
David Benjaminfa214e42016-05-10 17:03:10 -04002099 name: "Unclean-Shutdown-Alert",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SendAlertOnShutdown: alertDecompressionFailure,
2103 ExpectCloseNotify: true,
2104 },
2105 },
2106 shimShutsDown: true,
2107 flags: []string{"-check-close-notify"},
2108 shouldFail: true,
2109 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2110 },
2111 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002112 name: "LargePlaintext",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendLargeRecords: true,
2116 },
2117 },
2118 messageLen: maxPlaintext + 1,
2119 shouldFail: true,
2120 expectedError: ":DATA_LENGTH_TOO_LONG:",
2121 },
2122 {
2123 protocol: dtls,
2124 name: "LargePlaintext-DTLS",
2125 config: Config{
2126 Bugs: ProtocolBugs{
2127 SendLargeRecords: true,
2128 },
2129 },
2130 messageLen: maxPlaintext + 1,
2131 shouldFail: true,
2132 expectedError: ":DATA_LENGTH_TOO_LONG:",
2133 },
2134 {
2135 name: "LargeCiphertext",
2136 config: Config{
2137 Bugs: ProtocolBugs{
2138 SendLargeRecords: true,
2139 },
2140 },
2141 messageLen: maxPlaintext * 2,
2142 shouldFail: true,
2143 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2144 },
2145 {
2146 protocol: dtls,
2147 name: "LargeCiphertext-DTLS",
2148 config: Config{
2149 Bugs: ProtocolBugs{
2150 SendLargeRecords: true,
2151 },
2152 },
2153 messageLen: maxPlaintext * 2,
2154 // Unlike the other four cases, DTLS drops records which
2155 // are invalid before authentication, so the connection
2156 // does not fail.
2157 expectMessageDropped: true,
2158 },
David Benjamindd6fed92015-10-23 17:41:12 -04002159 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002160 name: "BadHelloRequest-1",
2161 renegotiate: 1,
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002164 Bugs: ProtocolBugs{
2165 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2166 },
2167 },
2168 flags: []string{
2169 "-renegotiate-freely",
2170 "-expect-total-renegotiations", "1",
2171 },
2172 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002173 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002174 },
2175 {
2176 name: "BadHelloRequest-2",
2177 renegotiate: 1,
2178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002179 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002180 Bugs: ProtocolBugs{
2181 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2182 },
2183 },
2184 flags: []string{
2185 "-renegotiate-freely",
2186 "-expect-total-renegotiations", "1",
2187 },
2188 shouldFail: true,
2189 expectedError: ":BAD_HELLO_REQUEST:",
2190 },
David Benjaminef1b0092015-11-21 14:05:44 -05002191 {
2192 testType: serverTest,
2193 name: "SupportTicketsWithSessionID",
2194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002195 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002196 SessionTicketsDisabled: true,
2197 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002198 resumeConfig: &Config{
2199 MaxVersion: VersionTLS12,
2200 },
David Benjaminef1b0092015-11-21 14:05:44 -05002201 resumeSession: true,
2202 },
David Benjamin02edcd02016-07-27 17:40:37 -04002203 {
2204 protocol: dtls,
2205 name: "DTLS-SendExtraFinished",
2206 config: Config{
2207 Bugs: ProtocolBugs{
2208 SendExtraFinished: true,
2209 },
2210 },
2211 shouldFail: true,
2212 expectedError: ":UNEXPECTED_RECORD:",
2213 },
2214 {
2215 protocol: dtls,
2216 name: "DTLS-SendExtraFinished-Reordered",
2217 config: Config{
2218 Bugs: ProtocolBugs{
2219 MaxHandshakeRecordLength: 2,
2220 ReorderHandshakeFragments: true,
2221 SendExtraFinished: true,
2222 },
2223 },
2224 shouldFail: true,
2225 expectedError: ":UNEXPECTED_RECORD:",
2226 },
David Benjamine97fb482016-07-29 09:23:07 -04002227 {
2228 testType: serverTest,
2229 name: "V2ClientHello-EmptyRecordPrefix",
2230 config: Config{
2231 // Choose a cipher suite that does not involve
2232 // elliptic curves, so no extensions are
2233 // involved.
2234 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002235 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002236 Bugs: ProtocolBugs{
2237 SendV2ClientHello: true,
2238 },
2239 },
2240 sendPrefix: string([]byte{
2241 byte(recordTypeHandshake),
2242 3, 1, // version
2243 0, 0, // length
2244 }),
2245 // A no-op empty record may not be sent before V2ClientHello.
2246 shouldFail: true,
2247 expectedError: ":WRONG_VERSION_NUMBER:",
2248 },
2249 {
2250 testType: serverTest,
2251 name: "V2ClientHello-WarningAlertPrefix",
2252 config: Config{
2253 // Choose a cipher suite that does not involve
2254 // elliptic curves, so no extensions are
2255 // involved.
2256 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002257 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002258 Bugs: ProtocolBugs{
2259 SendV2ClientHello: true,
2260 },
2261 },
2262 sendPrefix: string([]byte{
2263 byte(recordTypeAlert),
2264 3, 1, // version
2265 0, 2, // length
2266 alertLevelWarning, byte(alertDecompressionFailure),
2267 }),
2268 // A no-op warning alert may not be sent before V2ClientHello.
2269 shouldFail: true,
2270 expectedError: ":WRONG_VERSION_NUMBER:",
2271 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002272 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002273 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002274 config: Config{
2275 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002276 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002277 sendKeyUpdates: 1,
2278 keyUpdateRequest: keyUpdateNotRequested,
2279 },
2280 {
2281 name: "KeyUpdate-InvalidRequestMode",
2282 config: Config{
2283 MaxVersion: VersionTLS13,
2284 },
2285 sendKeyUpdates: 1,
2286 keyUpdateRequest: 42,
2287 shouldFail: true,
2288 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002289 },
David Benjaminabe94e32016-09-04 14:18:58 -04002290 {
2291 name: "SendSNIWarningAlert",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendSNIWarningAlert: true,
2296 },
2297 },
2298 },
David Benjaminc241d792016-09-09 10:34:20 -04002299 {
2300 testType: serverTest,
2301 name: "ExtraCompressionMethods-TLS12",
2302 config: Config{
2303 MaxVersion: VersionTLS12,
2304 Bugs: ProtocolBugs{
2305 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2306 },
2307 },
2308 },
2309 {
2310 testType: serverTest,
2311 name: "ExtraCompressionMethods-TLS13",
2312 config: Config{
2313 MaxVersion: VersionTLS13,
2314 Bugs: ProtocolBugs{
2315 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2316 },
2317 },
2318 shouldFail: true,
2319 expectedError: ":INVALID_COMPRESSION_LIST:",
2320 expectedLocalError: "remote error: illegal parameter",
2321 },
2322 {
2323 testType: serverTest,
2324 name: "NoNullCompression-TLS12",
2325 config: Config{
2326 MaxVersion: VersionTLS12,
2327 Bugs: ProtocolBugs{
2328 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2329 },
2330 },
2331 shouldFail: true,
2332 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2333 expectedLocalError: "remote error: illegal parameter",
2334 },
2335 {
2336 testType: serverTest,
2337 name: "NoNullCompression-TLS13",
2338 config: Config{
2339 MaxVersion: VersionTLS13,
2340 Bugs: ProtocolBugs{
2341 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2342 },
2343 },
2344 shouldFail: true,
2345 expectedError: ":INVALID_COMPRESSION_LIST:",
2346 expectedLocalError: "remote error: illegal parameter",
2347 },
David Benjamin65ac9972016-09-02 21:35:25 -04002348 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002349 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002350 config: Config{
2351 MaxVersion: VersionTLS12,
2352 Bugs: ProtocolBugs{
2353 ExpectGREASE: true,
2354 },
2355 },
2356 flags: []string{"-enable-grease"},
2357 },
2358 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002359 name: "GREASE-Client-TLS13",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 Bugs: ProtocolBugs{
2363 ExpectGREASE: true,
2364 },
2365 },
2366 flags: []string{"-enable-grease"},
2367 },
2368 {
2369 testType: serverTest,
2370 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002371 config: Config{
2372 MaxVersion: VersionTLS13,
2373 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002374 // TLS 1.3 servers are expected to
2375 // always enable GREASE. TLS 1.3 is new,
2376 // so there is no existing ecosystem to
2377 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002378 ExpectGREASE: true,
2379 },
2380 },
David Benjamin65ac9972016-09-02 21:35:25 -04002381 },
Adam Langley7c803a62015-06-15 15:35:05 -07002382 }
Adam Langley7c803a62015-06-15 15:35:05 -07002383 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002384
2385 // Test that very large messages can be received.
2386 cert := rsaCertificate
2387 for i := 0; i < 50; i++ {
2388 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2389 }
2390 testCases = append(testCases, testCase{
2391 name: "LargeMessage",
2392 config: Config{
2393 Certificates: []Certificate{cert},
2394 },
2395 })
2396 testCases = append(testCases, testCase{
2397 protocol: dtls,
2398 name: "LargeMessage-DTLS",
2399 config: Config{
2400 Certificates: []Certificate{cert},
2401 },
2402 })
2403
2404 // They are rejected if the maximum certificate chain length is capped.
2405 testCases = append(testCases, testCase{
2406 name: "LargeMessage-Reject",
2407 config: Config{
2408 Certificates: []Certificate{cert},
2409 },
2410 flags: []string{"-max-cert-list", "16384"},
2411 shouldFail: true,
2412 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2413 })
2414 testCases = append(testCases, testCase{
2415 protocol: dtls,
2416 name: "LargeMessage-Reject-DTLS",
2417 config: Config{
2418 Certificates: []Certificate{cert},
2419 },
2420 flags: []string{"-max-cert-list", "16384"},
2421 shouldFail: true,
2422 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2423 })
Adam Langley7c803a62015-06-15 15:35:05 -07002424}
2425
Adam Langley95c29f32014-06-20 12:00:00 -07002426func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002427 const bogusCipher = 0xfe00
2428
Adam Langley95c29f32014-06-20 12:00:00 -07002429 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002430 const psk = "12345"
2431 const pskIdentity = "luggage combo"
2432
Adam Langley95c29f32014-06-20 12:00:00 -07002433 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002434 var certFile string
2435 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002436 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002437 cert = ecdsaP256Certificate
2438 certFile = ecdsaP256CertificateFile
2439 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002440 } else {
David Benjamin33863262016-07-08 17:20:12 -07002441 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002442 certFile = rsaCertificateFile
2443 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002444 }
2445
David Benjamin48cae082014-10-27 01:06:24 -04002446 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002447 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002448 flags = append(flags,
2449 "-psk", psk,
2450 "-psk-identity", pskIdentity)
2451 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002452 if hasComponent(suite.name, "NULL") {
2453 // NULL ciphers must be explicitly enabled.
2454 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2455 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002456 if hasComponent(suite.name, "CECPQ1") {
2457 // CECPQ1 ciphers must be explicitly enabled.
2458 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2459 }
David Benjamin881f1962016-08-10 18:29:12 -04002460 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2461 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2462 // for now.
2463 flags = append(flags, "-cipher", suite.name)
2464 }
David Benjamin48cae082014-10-27 01:06:24 -04002465
Adam Langley95c29f32014-06-20 12:00:00 -07002466 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002467 for _, protocol := range []protocol{tls, dtls} {
2468 var prefix string
2469 if protocol == dtls {
2470 if !ver.hasDTLS {
2471 continue
2472 }
2473 prefix = "D"
2474 }
Adam Langley95c29f32014-06-20 12:00:00 -07002475
David Benjamin0407e762016-06-17 16:41:18 -04002476 var shouldServerFail, shouldClientFail bool
2477 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2478 // BoringSSL clients accept ECDHE on SSLv3, but
2479 // a BoringSSL server will never select it
2480 // because the extension is missing.
2481 shouldServerFail = true
2482 }
2483 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2484 shouldClientFail = true
2485 shouldServerFail = true
2486 }
David Benjamin54c217c2016-07-13 12:35:25 -04002487 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 shouldClientFail = true
2489 shouldServerFail = true
2490 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002491 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2492 shouldClientFail = true
2493 shouldServerFail = true
2494 }
David Benjamin0407e762016-06-17 16:41:18 -04002495 if !isDTLSCipher(suite.name) && protocol == dtls {
2496 shouldClientFail = true
2497 shouldServerFail = true
2498 }
David Benjamin4298d772015-12-19 00:18:25 -05002499
David Benjamin5ecb88b2016-10-04 17:51:35 -04002500 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002501 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002502 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002503 if shouldServerFail {
2504 expectedServerError = ":NO_SHARED_CIPHER:"
2505 }
2506 if shouldClientFail {
2507 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002508 // Configure the server to select ciphers as normal but
2509 // select an incompatible cipher in ServerHello.
2510 serverCipherSuites = nil
2511 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002512 }
David Benjamin025b3d32014-07-01 19:53:04 -04002513
David Benjamin6fd297b2014-08-11 18:43:38 -04002514 testCases = append(testCases, testCase{
2515 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002516 protocol: protocol,
2517
2518 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002519 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002520 MinVersion: ver.version,
2521 MaxVersion: ver.version,
2522 CipherSuites: []uint16{suite.id},
2523 Certificates: []Certificate{cert},
2524 PreSharedKey: []byte(psk),
2525 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002526 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002527 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002528 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002529 },
2530 certFile: certFile,
2531 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002532 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002533 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002534 shouldFail: shouldServerFail,
2535 expectedError: expectedServerError,
2536 })
2537
2538 testCases = append(testCases, testCase{
2539 testType: clientTest,
2540 protocol: protocol,
2541 name: prefix + ver.name + "-" + suite.name + "-client",
2542 config: Config{
2543 MinVersion: ver.version,
2544 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002545 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002546 Certificates: []Certificate{cert},
2547 PreSharedKey: []byte(psk),
2548 PreSharedKeyIdentity: pskIdentity,
2549 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002550 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002551 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002552 },
2553 },
2554 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002555 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002556 shouldFail: shouldClientFail,
2557 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002558 })
David Benjamin2c99d282015-09-01 10:23:00 -04002559
Nick Harper1fd39d82016-06-14 18:14:35 -07002560 if !shouldClientFail {
2561 // Ensure the maximum record size is accepted.
2562 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002563 protocol: protocol,
2564 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002565 config: Config{
2566 MinVersion: ver.version,
2567 MaxVersion: ver.version,
2568 CipherSuites: []uint16{suite.id},
2569 Certificates: []Certificate{cert},
2570 PreSharedKey: []byte(psk),
2571 PreSharedKeyIdentity: pskIdentity,
2572 },
2573 flags: flags,
2574 messageLen: maxPlaintext,
2575 })
David Benjamin231a4752016-11-10 10:46:00 -05002576
2577 // Test bad records for all ciphers. Bad records are fatal in TLS
2578 // and ignored in DTLS.
2579 var shouldFail bool
2580 var expectedError string
2581 if protocol == tls {
2582 shouldFail = true
2583 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2584 }
2585
2586 testCases = append(testCases, testCase{
2587 protocol: protocol,
2588 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2589 config: Config{
2590 MinVersion: ver.version,
2591 MaxVersion: ver.version,
2592 CipherSuites: []uint16{suite.id},
2593 Certificates: []Certificate{cert},
2594 PreSharedKey: []byte(psk),
2595 PreSharedKeyIdentity: pskIdentity,
2596 },
2597 flags: flags,
2598 damageFirstWrite: true,
2599 messageLen: maxPlaintext,
2600 shouldFail: shouldFail,
2601 expectedError: expectedError,
2602 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002603 }
2604 }
David Benjamin2c99d282015-09-01 10:23:00 -04002605 }
Adam Langley95c29f32014-06-20 12:00:00 -07002606 }
Adam Langleya7997f12015-05-14 17:38:50 -07002607
2608 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002609 name: "NoSharedCipher",
2610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002611 MaxVersion: VersionTLS12,
2612 CipherSuites: []uint16{},
2613 },
2614 shouldFail: true,
2615 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2616 })
2617
2618 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002619 name: "NoSharedCipher-TLS13",
2620 config: Config{
2621 MaxVersion: VersionTLS13,
2622 CipherSuites: []uint16{},
2623 },
2624 shouldFail: true,
2625 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2626 })
2627
2628 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002629 name: "UnsupportedCipherSuite",
2630 config: Config{
2631 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002632 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002633 Bugs: ProtocolBugs{
2634 IgnorePeerCipherPreferences: true,
2635 },
2636 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002637 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002638 shouldFail: true,
2639 expectedError: ":WRONG_CIPHER_RETURNED:",
2640 })
2641
2642 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002643 name: "ServerHelloBogusCipher",
2644 config: Config{
2645 MaxVersion: VersionTLS12,
2646 Bugs: ProtocolBugs{
2647 SendCipherSuite: bogusCipher,
2648 },
2649 },
2650 shouldFail: true,
2651 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2652 })
2653 testCases = append(testCases, testCase{
2654 name: "ServerHelloBogusCipher-TLS13",
2655 config: Config{
2656 MaxVersion: VersionTLS13,
2657 Bugs: ProtocolBugs{
2658 SendCipherSuite: bogusCipher,
2659 },
2660 },
2661 shouldFail: true,
2662 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2663 })
2664
2665 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002666 name: "WeakDH",
2667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002668 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002669 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2670 Bugs: ProtocolBugs{
2671 // This is a 1023-bit prime number, generated
2672 // with:
2673 // openssl gendh 1023 | openssl asn1parse -i
2674 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2675 },
2676 },
2677 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002678 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002679 })
Adam Langleycef75832015-09-03 14:51:12 -07002680
David Benjamincd24a392015-11-11 13:23:05 -08002681 testCases = append(testCases, testCase{
2682 name: "SillyDH",
2683 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002684 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002685 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2686 Bugs: ProtocolBugs{
2687 // This is a 4097-bit prime number, generated
2688 // with:
2689 // openssl gendh 4097 | openssl asn1parse -i
2690 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2691 },
2692 },
2693 shouldFail: true,
2694 expectedError: ":DH_P_TOO_LONG:",
2695 })
2696
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002697 // This test ensures that Diffie-Hellman public values are padded with
2698 // zeros so that they're the same length as the prime. This is to avoid
2699 // hitting a bug in yaSSL.
2700 testCases = append(testCases, testCase{
2701 testType: serverTest,
2702 name: "DHPublicValuePadded",
2703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002704 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002705 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2706 Bugs: ProtocolBugs{
2707 RequireDHPublicValueLen: (1025 + 7) / 8,
2708 },
2709 },
2710 flags: []string{"-use-sparse-dh-prime"},
2711 })
David Benjamincd24a392015-11-11 13:23:05 -08002712
David Benjamin241ae832016-01-15 03:04:54 -05002713 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002714 testCases = append(testCases, testCase{
2715 testType: serverTest,
2716 name: "UnknownCipher",
2717 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002718 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002719 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002720 Bugs: ProtocolBugs{
2721 AdvertiseAllConfiguredCiphers: true,
2722 },
2723 },
2724 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002725
2726 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002727 testCases = append(testCases, testCase{
2728 testType: serverTest,
2729 name: "UnknownCipher-TLS13",
2730 config: Config{
2731 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002732 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002733 Bugs: ProtocolBugs{
2734 AdvertiseAllConfiguredCiphers: true,
2735 },
David Benjamin241ae832016-01-15 03:04:54 -05002736 },
2737 })
2738
David Benjamin78679342016-09-16 19:42:05 -04002739 // Test empty ECDHE_PSK identity hints work as expected.
2740 testCases = append(testCases, testCase{
2741 name: "EmptyECDHEPSKHint",
2742 config: Config{
2743 MaxVersion: VersionTLS12,
2744 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2745 PreSharedKey: []byte("secret"),
2746 },
2747 flags: []string{"-psk", "secret"},
2748 })
2749
2750 // Test empty PSK identity hints work as expected, even if an explicit
2751 // ServerKeyExchange is sent.
2752 testCases = append(testCases, testCase{
2753 name: "ExplicitEmptyPSKHint",
2754 config: Config{
2755 MaxVersion: VersionTLS12,
2756 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2757 PreSharedKey: []byte("secret"),
2758 Bugs: ProtocolBugs{
2759 AlwaysSendPreSharedKeyIdentityHint: true,
2760 },
2761 },
2762 flags: []string{"-psk", "secret"},
2763 })
2764
Adam Langleycef75832015-09-03 14:51:12 -07002765 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2766 // 1.1 specific cipher suite settings. A server is setup with the given
2767 // cipher lists and then a connection is made for each member of
2768 // expectations. The cipher suite that the server selects must match
2769 // the specified one.
2770 var versionSpecificCiphersTest = []struct {
2771 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2772 // expectations is a map from TLS version to cipher suite id.
2773 expectations map[uint16]uint16
2774 }{
2775 {
2776 // Test that the null case (where no version-specific ciphers are set)
2777 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002778 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2779 "", // no ciphers specifically for TLS ≥ 1.0
2780 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002781 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002782 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2783 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2784 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2785 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002786 },
2787 },
2788 {
2789 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2790 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002791 "DES-CBC3-SHA:AES128-SHA", // default
2792 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2793 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002794 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002795 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002796 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2797 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2798 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2799 },
2800 },
2801 {
2802 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2803 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002804 "DES-CBC3-SHA:AES128-SHA", // default
2805 "", // no ciphers specifically for TLS ≥ 1.0
2806 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002807 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002808 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2809 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002810 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2811 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2812 },
2813 },
2814 {
2815 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2816 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002817 "DES-CBC3-SHA:AES128-SHA", // default
2818 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2819 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002820 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002821 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002822 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2823 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2824 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2825 },
2826 },
2827 }
2828
2829 for i, test := range versionSpecificCiphersTest {
2830 for version, expectedCipherSuite := range test.expectations {
2831 flags := []string{"-cipher", test.ciphersDefault}
2832 if len(test.ciphersTLS10) > 0 {
2833 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2834 }
2835 if len(test.ciphersTLS11) > 0 {
2836 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2837 }
2838
2839 testCases = append(testCases, testCase{
2840 testType: serverTest,
2841 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2842 config: Config{
2843 MaxVersion: version,
2844 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002845 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002846 },
2847 flags: flags,
2848 expectedCipher: expectedCipherSuite,
2849 })
2850 }
2851 }
Adam Langley95c29f32014-06-20 12:00:00 -07002852}
2853
2854func addBadECDSASignatureTests() {
2855 for badR := BadValue(1); badR < NumBadValues; badR++ {
2856 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002857 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002858 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2859 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002860 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002861 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002862 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002863 Bugs: ProtocolBugs{
2864 BadECDSAR: badR,
2865 BadECDSAS: badS,
2866 },
2867 },
2868 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002869 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002870 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002871 testCases = append(testCases, testCase{
2872 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2873 config: Config{
2874 MaxVersion: VersionTLS13,
2875 Certificates: []Certificate{ecdsaP256Certificate},
2876 Bugs: ProtocolBugs{
2877 BadECDSAR: badR,
2878 BadECDSAS: badS,
2879 },
2880 },
2881 shouldFail: true,
2882 expectedError: ":BAD_SIGNATURE:",
2883 })
Adam Langley95c29f32014-06-20 12:00:00 -07002884 }
2885 }
2886}
2887
Adam Langley80842bd2014-06-20 12:00:00 -07002888func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002889 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002890 name: "MaxCBCPadding",
2891 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002892 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2894 Bugs: ProtocolBugs{
2895 MaxPadding: true,
2896 },
2897 },
2898 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2899 })
David Benjamin025b3d32014-07-01 19:53:04 -04002900 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002901 name: "BadCBCPadding",
2902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002903 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2905 Bugs: ProtocolBugs{
2906 PaddingFirstByteBad: true,
2907 },
2908 },
2909 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002910 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002911 })
2912 // OpenSSL previously had an issue where the first byte of padding in
2913 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002914 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002915 name: "BadCBCPadding255",
2916 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002917 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2919 Bugs: ProtocolBugs{
2920 MaxPadding: true,
2921 PaddingFirstByteBadIf255: true,
2922 },
2923 },
2924 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2925 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002926 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002927 })
2928}
2929
Kenny Root7fdeaf12014-08-05 15:23:37 -07002930func addCBCSplittingTests() {
2931 testCases = append(testCases, testCase{
2932 name: "CBCRecordSplitting",
2933 config: Config{
2934 MaxVersion: VersionTLS10,
2935 MinVersion: VersionTLS10,
2936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2937 },
David Benjaminac8302a2015-09-01 17:18:15 -04002938 messageLen: -1, // read until EOF
2939 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002940 flags: []string{
2941 "-async",
2942 "-write-different-record-sizes",
2943 "-cbc-record-splitting",
2944 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002945 })
2946 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002947 name: "CBCRecordSplittingPartialWrite",
2948 config: Config{
2949 MaxVersion: VersionTLS10,
2950 MinVersion: VersionTLS10,
2951 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2952 },
2953 messageLen: -1, // read until EOF
2954 flags: []string{
2955 "-async",
2956 "-write-different-record-sizes",
2957 "-cbc-record-splitting",
2958 "-partial-write",
2959 },
2960 })
2961}
2962
David Benjamin636293b2014-07-08 17:59:18 -04002963func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002964 // Add a dummy cert pool to stress certificate authority parsing.
2965 // TODO(davidben): Add tests that those values parse out correctly.
2966 certPool := x509.NewCertPool()
2967 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2968 if err != nil {
2969 panic(err)
2970 }
2971 certPool.AddCert(cert)
2972
David Benjamin636293b2014-07-08 17:59:18 -04002973 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002974 testCases = append(testCases, testCase{
2975 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002976 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002977 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002978 MinVersion: ver.version,
2979 MaxVersion: ver.version,
2980 ClientAuth: RequireAnyClientCert,
2981 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002982 },
2983 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002984 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2985 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002986 },
2987 })
2988 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002989 testType: serverTest,
2990 name: ver.name + "-Server-ClientAuth-RSA",
2991 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002992 MinVersion: ver.version,
2993 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002994 Certificates: []Certificate{rsaCertificate},
2995 },
2996 flags: []string{"-require-any-client-certificate"},
2997 })
David Benjamine098ec22014-08-27 23:13:20 -04002998 if ver.version != VersionSSL30 {
2999 testCases = append(testCases, testCase{
3000 testType: serverTest,
3001 name: ver.name + "-Server-ClientAuth-ECDSA",
3002 config: Config{
3003 MinVersion: ver.version,
3004 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003005 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003006 },
3007 flags: []string{"-require-any-client-certificate"},
3008 })
3009 testCases = append(testCases, testCase{
3010 testType: clientTest,
3011 name: ver.name + "-Client-ClientAuth-ECDSA",
3012 config: Config{
3013 MinVersion: ver.version,
3014 MaxVersion: ver.version,
3015 ClientAuth: RequireAnyClientCert,
3016 ClientCAs: certPool,
3017 },
3018 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003019 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3020 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003021 },
3022 })
3023 }
Adam Langley37646832016-08-01 16:16:46 -07003024
3025 testCases = append(testCases, testCase{
3026 name: "NoClientCertificate-" + ver.name,
3027 config: Config{
3028 MinVersion: ver.version,
3029 MaxVersion: ver.version,
3030 ClientAuth: RequireAnyClientCert,
3031 },
3032 shouldFail: true,
3033 expectedLocalError: "client didn't provide a certificate",
3034 })
3035
3036 testCases = append(testCases, testCase{
3037 // Even if not configured to expect a certificate, OpenSSL will
3038 // return X509_V_OK as the verify_result.
3039 testType: serverTest,
3040 name: "NoClientCertificateRequested-Server-" + ver.name,
3041 config: Config{
3042 MinVersion: ver.version,
3043 MaxVersion: ver.version,
3044 },
3045 flags: []string{
3046 "-expect-verify-result",
3047 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003048 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003049 })
3050
3051 testCases = append(testCases, testCase{
3052 // If a client certificate is not provided, OpenSSL will still
3053 // return X509_V_OK as the verify_result.
3054 testType: serverTest,
3055 name: "NoClientCertificate-Server-" + ver.name,
3056 config: Config{
3057 MinVersion: ver.version,
3058 MaxVersion: ver.version,
3059 },
3060 flags: []string{
3061 "-expect-verify-result",
3062 "-verify-peer",
3063 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003064 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003065 })
3066
David Benjamin1db9e1b2016-10-07 20:51:43 -04003067 certificateRequired := "remote error: certificate required"
3068 if ver.version < VersionTLS13 {
3069 // Prior to TLS 1.3, the generic handshake_failure alert
3070 // was used.
3071 certificateRequired = "remote error: handshake failure"
3072 }
Adam Langley37646832016-08-01 16:16:46 -07003073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "RequireAnyClientCertificate-" + ver.name,
3076 config: Config{
3077 MinVersion: ver.version,
3078 MaxVersion: ver.version,
3079 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003080 flags: []string{"-require-any-client-certificate"},
3081 shouldFail: true,
3082 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3083 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003084 })
3085
3086 if ver.version != VersionSSL30 {
3087 testCases = append(testCases, testCase{
3088 testType: serverTest,
3089 name: "SkipClientCertificate-" + ver.name,
3090 config: Config{
3091 MinVersion: ver.version,
3092 MaxVersion: ver.version,
3093 Bugs: ProtocolBugs{
3094 SkipClientCertificate: true,
3095 },
3096 },
3097 // Setting SSL_VERIFY_PEER allows anonymous clients.
3098 flags: []string{"-verify-peer"},
3099 shouldFail: true,
3100 expectedError: ":UNEXPECTED_MESSAGE:",
3101 })
3102 }
David Benjamin636293b2014-07-08 17:59:18 -04003103 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003104
David Benjaminc032dfa2016-05-12 14:54:57 -04003105 // Client auth is only legal in certificate-based ciphers.
3106 testCases = append(testCases, testCase{
3107 testType: clientTest,
3108 name: "ClientAuth-PSK",
3109 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003110 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003111 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3112 PreSharedKey: []byte("secret"),
3113 ClientAuth: RequireAnyClientCert,
3114 },
3115 flags: []string{
3116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3118 "-psk", "secret",
3119 },
3120 shouldFail: true,
3121 expectedError: ":UNEXPECTED_MESSAGE:",
3122 })
3123 testCases = append(testCases, testCase{
3124 testType: clientTest,
3125 name: "ClientAuth-ECDHE_PSK",
3126 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003127 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003128 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3129 PreSharedKey: []byte("secret"),
3130 ClientAuth: RequireAnyClientCert,
3131 },
3132 flags: []string{
3133 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3134 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3135 "-psk", "secret",
3136 },
3137 shouldFail: true,
3138 expectedError: ":UNEXPECTED_MESSAGE:",
3139 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003140
3141 // Regression test for a bug where the client CA list, if explicitly
3142 // set to NULL, was mis-encoded.
3143 testCases = append(testCases, testCase{
3144 testType: serverTest,
3145 name: "Null-Client-CA-List",
3146 config: Config{
3147 MaxVersion: VersionTLS12,
3148 Certificates: []Certificate{rsaCertificate},
3149 },
3150 flags: []string{
3151 "-require-any-client-certificate",
3152 "-use-null-client-ca-list",
3153 },
3154 })
David Benjamin636293b2014-07-08 17:59:18 -04003155}
3156
Adam Langley75712922014-10-10 16:23:43 -07003157func addExtendedMasterSecretTests() {
3158 const expectEMSFlag = "-expect-extended-master-secret"
3159
3160 for _, with := range []bool{false, true} {
3161 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003162 if with {
3163 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003164 }
3165
3166 for _, isClient := range []bool{false, true} {
3167 suffix := "-Server"
3168 testType := serverTest
3169 if isClient {
3170 suffix = "-Client"
3171 testType = clientTest
3172 }
3173
3174 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003175 // In TLS 1.3, the extension is irrelevant and
3176 // always reports as enabled.
3177 var flags []string
3178 if with || ver.version >= VersionTLS13 {
3179 flags = []string{expectEMSFlag}
3180 }
3181
Adam Langley75712922014-10-10 16:23:43 -07003182 test := testCase{
3183 testType: testType,
3184 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3185 config: Config{
3186 MinVersion: ver.version,
3187 MaxVersion: ver.version,
3188 Bugs: ProtocolBugs{
3189 NoExtendedMasterSecret: !with,
3190 RequireExtendedMasterSecret: with,
3191 },
3192 },
David Benjamin48cae082014-10-27 01:06:24 -04003193 flags: flags,
3194 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003195 }
3196 if test.shouldFail {
3197 test.expectedLocalError = "extended master secret required but not supported by peer"
3198 }
3199 testCases = append(testCases, test)
3200 }
3201 }
3202 }
3203
Adam Langleyba5934b2015-06-02 10:50:35 -07003204 for _, isClient := range []bool{false, true} {
3205 for _, supportedInFirstConnection := range []bool{false, true} {
3206 for _, supportedInResumeConnection := range []bool{false, true} {
3207 boolToWord := func(b bool) string {
3208 if b {
3209 return "Yes"
3210 }
3211 return "No"
3212 }
3213 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3214 if isClient {
3215 suffix += "Client"
3216 } else {
3217 suffix += "Server"
3218 }
3219
3220 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003221 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003222 Bugs: ProtocolBugs{
3223 RequireExtendedMasterSecret: true,
3224 },
3225 }
3226
3227 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003228 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003229 Bugs: ProtocolBugs{
3230 NoExtendedMasterSecret: true,
3231 },
3232 }
3233
3234 test := testCase{
3235 name: "ExtendedMasterSecret-" + suffix,
3236 resumeSession: true,
3237 }
3238
3239 if !isClient {
3240 test.testType = serverTest
3241 }
3242
3243 if supportedInFirstConnection {
3244 test.config = supportedConfig
3245 } else {
3246 test.config = noSupportConfig
3247 }
3248
3249 if supportedInResumeConnection {
3250 test.resumeConfig = &supportedConfig
3251 } else {
3252 test.resumeConfig = &noSupportConfig
3253 }
3254
3255 switch suffix {
3256 case "YesToYes-Client", "YesToYes-Server":
3257 // When a session is resumed, it should
3258 // still be aware that its master
3259 // secret was generated via EMS and
3260 // thus it's safe to use tls-unique.
3261 test.flags = []string{expectEMSFlag}
3262 case "NoToYes-Server":
3263 // If an original connection did not
3264 // contain EMS, but a resumption
3265 // handshake does, then a server should
3266 // not resume the session.
3267 test.expectResumeRejected = true
3268 case "YesToNo-Server":
3269 // Resuming an EMS session without the
3270 // EMS extension should cause the
3271 // server to abort the connection.
3272 test.shouldFail = true
3273 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3274 case "NoToYes-Client":
3275 // A client should abort a connection
3276 // where the server resumed a non-EMS
3277 // session but echoed the EMS
3278 // extension.
3279 test.shouldFail = true
3280 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3281 case "YesToNo-Client":
3282 // A client should abort a connection
3283 // where the server didn't echo EMS
3284 // when the session used it.
3285 test.shouldFail = true
3286 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3287 }
3288
3289 testCases = append(testCases, test)
3290 }
3291 }
3292 }
David Benjamin163c9562016-08-29 23:14:17 -04003293
3294 // Switching EMS on renegotiation is forbidden.
3295 testCases = append(testCases, testCase{
3296 name: "ExtendedMasterSecret-Renego-NoEMS",
3297 config: Config{
3298 MaxVersion: VersionTLS12,
3299 Bugs: ProtocolBugs{
3300 NoExtendedMasterSecret: true,
3301 NoExtendedMasterSecretOnRenegotiation: true,
3302 },
3303 },
3304 renegotiate: 1,
3305 flags: []string{
3306 "-renegotiate-freely",
3307 "-expect-total-renegotiations", "1",
3308 },
3309 })
3310
3311 testCases = append(testCases, testCase{
3312 name: "ExtendedMasterSecret-Renego-Upgrade",
3313 config: Config{
3314 MaxVersion: VersionTLS12,
3315 Bugs: ProtocolBugs{
3316 NoExtendedMasterSecret: true,
3317 },
3318 },
3319 renegotiate: 1,
3320 flags: []string{
3321 "-renegotiate-freely",
3322 "-expect-total-renegotiations", "1",
3323 },
3324 shouldFail: true,
3325 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3326 })
3327
3328 testCases = append(testCases, testCase{
3329 name: "ExtendedMasterSecret-Renego-Downgrade",
3330 config: Config{
3331 MaxVersion: VersionTLS12,
3332 Bugs: ProtocolBugs{
3333 NoExtendedMasterSecretOnRenegotiation: true,
3334 },
3335 },
3336 renegotiate: 1,
3337 flags: []string{
3338 "-renegotiate-freely",
3339 "-expect-total-renegotiations", "1",
3340 },
3341 shouldFail: true,
3342 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3343 })
Adam Langley75712922014-10-10 16:23:43 -07003344}
3345
David Benjamin582ba042016-07-07 12:33:25 -07003346type stateMachineTestConfig struct {
3347 protocol protocol
3348 async bool
3349 splitHandshake, packHandshakeFlight bool
3350}
3351
David Benjamin43ec06f2014-08-05 02:28:57 -04003352// Adds tests that try to cover the range of the handshake state machine, under
3353// various conditions. Some of these are redundant with other tests, but they
3354// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003355func addAllStateMachineCoverageTests() {
3356 for _, async := range []bool{false, true} {
3357 for _, protocol := range []protocol{tls, dtls} {
3358 addStateMachineCoverageTests(stateMachineTestConfig{
3359 protocol: protocol,
3360 async: async,
3361 })
3362 addStateMachineCoverageTests(stateMachineTestConfig{
3363 protocol: protocol,
3364 async: async,
3365 splitHandshake: true,
3366 })
3367 if protocol == tls {
3368 addStateMachineCoverageTests(stateMachineTestConfig{
3369 protocol: protocol,
3370 async: async,
3371 packHandshakeFlight: true,
3372 })
3373 }
3374 }
3375 }
3376}
3377
3378func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003379 var tests []testCase
3380
3381 // Basic handshake, with resumption. Client and server,
3382 // session ID and session ticket.
3383 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003384 name: "Basic-Client",
3385 config: Config{
3386 MaxVersion: VersionTLS12,
3387 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003389 // Ensure session tickets are used, not session IDs.
3390 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 })
3392 tests = append(tests, testCase{
3393 name: "Basic-Client-RenewTicket",
3394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003395 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003396 Bugs: ProtocolBugs{
3397 RenewTicketOnResume: true,
3398 },
3399 },
David Benjamin46662482016-08-17 00:51:00 -04003400 flags: []string{"-expect-ticket-renewal"},
3401 resumeSession: true,
3402 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003403 })
3404 tests = append(tests, testCase{
3405 name: "Basic-Client-NoTicket",
3406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003408 SessionTicketsDisabled: true,
3409 },
3410 resumeSession: true,
3411 })
3412 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003413 name: "Basic-Client-Implicit",
3414 config: Config{
3415 MaxVersion: VersionTLS12,
3416 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003417 flags: []string{"-implicit-handshake"},
3418 resumeSession: true,
3419 })
3420 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003421 testType: serverTest,
3422 name: "Basic-Server",
3423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003425 Bugs: ProtocolBugs{
3426 RequireSessionTickets: true,
3427 },
3428 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003429 resumeSession: true,
3430 })
3431 tests = append(tests, testCase{
3432 testType: serverTest,
3433 name: "Basic-Server-NoTickets",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003436 SessionTicketsDisabled: true,
3437 },
3438 resumeSession: true,
3439 })
3440 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003441 testType: serverTest,
3442 name: "Basic-Server-Implicit",
3443 config: Config{
3444 MaxVersion: VersionTLS12,
3445 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003446 flags: []string{"-implicit-handshake"},
3447 resumeSession: true,
3448 })
3449 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003450 testType: serverTest,
3451 name: "Basic-Server-EarlyCallback",
3452 config: Config{
3453 MaxVersion: VersionTLS12,
3454 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003455 flags: []string{"-use-early-callback"},
3456 resumeSession: true,
3457 })
3458
Steven Valdez143e8b32016-07-11 13:19:03 -04003459 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003460 if config.protocol == tls {
3461 tests = append(tests, testCase{
3462 name: "TLS13-1RTT-Client",
3463 config: Config{
3464 MaxVersion: VersionTLS13,
3465 MinVersion: VersionTLS13,
3466 },
David Benjamin46662482016-08-17 00:51:00 -04003467 resumeSession: true,
3468 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003469 })
3470
3471 tests = append(tests, testCase{
3472 testType: serverTest,
3473 name: "TLS13-1RTT-Server",
3474 config: Config{
3475 MaxVersion: VersionTLS13,
3476 MinVersion: VersionTLS13,
3477 },
David Benjamin46662482016-08-17 00:51:00 -04003478 resumeSession: true,
3479 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003480 })
3481
3482 tests = append(tests, testCase{
3483 name: "TLS13-HelloRetryRequest-Client",
3484 config: Config{
3485 MaxVersion: VersionTLS13,
3486 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003487 // P-384 requires a HelloRetryRequest against BoringSSL's default
3488 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003489 CurvePreferences: []CurveID{CurveP384},
3490 Bugs: ProtocolBugs{
3491 ExpectMissingKeyShare: true,
3492 },
3493 },
3494 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3495 resumeSession: true,
3496 })
3497
3498 tests = append(tests, testCase{
3499 testType: serverTest,
3500 name: "TLS13-HelloRetryRequest-Server",
3501 config: Config{
3502 MaxVersion: VersionTLS13,
3503 MinVersion: VersionTLS13,
3504 // Require a HelloRetryRequest for every curve.
3505 DefaultCurves: []CurveID{},
3506 },
3507 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3508 resumeSession: true,
3509 })
3510 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003511
David Benjamin760b1dd2015-05-15 23:33:48 -04003512 // TLS client auth.
3513 tests = append(tests, testCase{
3514 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003515 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003517 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003518 ClientAuth: RequestClientCert,
3519 },
3520 })
3521 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003522 testType: serverTest,
3523 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003524 config: Config{
3525 MaxVersion: VersionTLS12,
3526 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003527 // Setting SSL_VERIFY_PEER allows anonymous clients.
3528 flags: []string{"-verify-peer"},
3529 })
David Benjamin582ba042016-07-07 12:33:25 -07003530 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003531 tests = append(tests, testCase{
3532 testType: clientTest,
3533 name: "ClientAuth-NoCertificate-Client-SSL3",
3534 config: Config{
3535 MaxVersion: VersionSSL30,
3536 ClientAuth: RequestClientCert,
3537 },
3538 })
3539 tests = append(tests, testCase{
3540 testType: serverTest,
3541 name: "ClientAuth-NoCertificate-Server-SSL3",
3542 config: Config{
3543 MaxVersion: VersionSSL30,
3544 },
3545 // Setting SSL_VERIFY_PEER allows anonymous clients.
3546 flags: []string{"-verify-peer"},
3547 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003548 tests = append(tests, testCase{
3549 testType: clientTest,
3550 name: "ClientAuth-NoCertificate-Client-TLS13",
3551 config: Config{
3552 MaxVersion: VersionTLS13,
3553 ClientAuth: RequestClientCert,
3554 },
3555 })
3556 tests = append(tests, testCase{
3557 testType: serverTest,
3558 name: "ClientAuth-NoCertificate-Server-TLS13",
3559 config: Config{
3560 MaxVersion: VersionTLS13,
3561 },
3562 // Setting SSL_VERIFY_PEER allows anonymous clients.
3563 flags: []string{"-verify-peer"},
3564 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003565 }
3566 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003567 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003568 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003570 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003571 ClientAuth: RequireAnyClientCert,
3572 },
3573 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003574 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3575 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003576 },
3577 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003578 tests = append(tests, testCase{
3579 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003580 name: "ClientAuth-RSA-Client-TLS13",
3581 config: Config{
3582 MaxVersion: VersionTLS13,
3583 ClientAuth: RequireAnyClientCert,
3584 },
3585 flags: []string{
3586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3588 },
3589 })
3590 tests = append(tests, testCase{
3591 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003592 name: "ClientAuth-ECDSA-Client",
3593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003594 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003595 ClientAuth: RequireAnyClientCert,
3596 },
3597 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003598 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3599 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003600 },
3601 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003602 tests = append(tests, testCase{
3603 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003604 name: "ClientAuth-ECDSA-Client-TLS13",
3605 config: Config{
3606 MaxVersion: VersionTLS13,
3607 ClientAuth: RequireAnyClientCert,
3608 },
3609 flags: []string{
3610 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3611 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3612 },
3613 })
3614 tests = append(tests, testCase{
3615 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003616 name: "ClientAuth-NoCertificate-OldCallback",
3617 config: Config{
3618 MaxVersion: VersionTLS12,
3619 ClientAuth: RequestClientCert,
3620 },
3621 flags: []string{"-use-old-client-cert-callback"},
3622 })
3623 tests = append(tests, testCase{
3624 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003625 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 ClientAuth: RequestClientCert,
3629 },
3630 flags: []string{"-use-old-client-cert-callback"},
3631 })
3632 tests = append(tests, testCase{
3633 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003634 name: "ClientAuth-OldCallback",
3635 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003636 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003637 ClientAuth: RequireAnyClientCert,
3638 },
3639 flags: []string{
3640 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3641 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3642 "-use-old-client-cert-callback",
3643 },
3644 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003645 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003646 testType: clientTest,
3647 name: "ClientAuth-OldCallback-TLS13",
3648 config: Config{
3649 MaxVersion: VersionTLS13,
3650 ClientAuth: RequireAnyClientCert,
3651 },
3652 flags: []string{
3653 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3654 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3655 "-use-old-client-cert-callback",
3656 },
3657 })
3658 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003659 testType: serverTest,
3660 name: "ClientAuth-Server",
3661 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003662 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003663 Certificates: []Certificate{rsaCertificate},
3664 },
3665 flags: []string{"-require-any-client-certificate"},
3666 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003667 tests = append(tests, testCase{
3668 testType: serverTest,
3669 name: "ClientAuth-Server-TLS13",
3670 config: Config{
3671 MaxVersion: VersionTLS13,
3672 Certificates: []Certificate{rsaCertificate},
3673 },
3674 flags: []string{"-require-any-client-certificate"},
3675 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003676
David Benjamin4c3ddf72016-06-29 18:13:53 -04003677 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003678 tests = append(tests, testCase{
3679 testType: serverTest,
3680 name: "Basic-Server-RSA",
3681 config: Config{
3682 MaxVersion: VersionTLS12,
3683 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3684 },
3685 flags: []string{
3686 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3687 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3688 },
3689 })
3690 tests = append(tests, testCase{
3691 testType: serverTest,
3692 name: "Basic-Server-ECDHE-RSA",
3693 config: Config{
3694 MaxVersion: VersionTLS12,
3695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3696 },
3697 flags: []string{
3698 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3699 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3700 },
3701 })
3702 tests = append(tests, testCase{
3703 testType: serverTest,
3704 name: "Basic-Server-ECDHE-ECDSA",
3705 config: Config{
3706 MaxVersion: VersionTLS12,
3707 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3708 },
3709 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003710 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3711 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003712 },
3713 })
3714
David Benjamin760b1dd2015-05-15 23:33:48 -04003715 // No session ticket support; server doesn't send NewSessionTicket.
3716 tests = append(tests, testCase{
3717 name: "SessionTicketsDisabled-Client",
3718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003719 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003720 SessionTicketsDisabled: true,
3721 },
3722 })
3723 tests = append(tests, testCase{
3724 testType: serverTest,
3725 name: "SessionTicketsDisabled-Server",
3726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 SessionTicketsDisabled: true,
3729 },
3730 })
3731
3732 // Skip ServerKeyExchange in PSK key exchange if there's no
3733 // identity hint.
3734 tests = append(tests, testCase{
3735 name: "EmptyPSKHint-Client",
3736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003737 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003738 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3739 PreSharedKey: []byte("secret"),
3740 },
3741 flags: []string{"-psk", "secret"},
3742 })
3743 tests = append(tests, testCase{
3744 testType: serverTest,
3745 name: "EmptyPSKHint-Server",
3746 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003747 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003748 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3749 PreSharedKey: []byte("secret"),
3750 },
3751 flags: []string{"-psk", "secret"},
3752 })
3753
David Benjamin4c3ddf72016-06-29 18:13:53 -04003754 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003755 tests = append(tests, testCase{
3756 testType: clientTest,
3757 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 config: Config{
3759 MaxVersion: VersionTLS12,
3760 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003761 flags: []string{
3762 "-enable-ocsp-stapling",
3763 "-expect-ocsp-response",
3764 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003765 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003766 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003767 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003768 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003769 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003770 testType: serverTest,
3771 name: "OCSPStapling-Server",
3772 config: Config{
3773 MaxVersion: VersionTLS12,
3774 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003775 expectedOCSPResponse: testOCSPResponse,
3776 flags: []string{
3777 "-ocsp-response",
3778 base64.StdEncoding.EncodeToString(testOCSPResponse),
3779 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003780 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003781 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003782 tests = append(tests, testCase{
3783 testType: clientTest,
3784 name: "OCSPStapling-Client-TLS13",
3785 config: Config{
3786 MaxVersion: VersionTLS13,
3787 },
3788 flags: []string{
3789 "-enable-ocsp-stapling",
3790 "-expect-ocsp-response",
3791 base64.StdEncoding.EncodeToString(testOCSPResponse),
3792 "-verify-peer",
3793 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003794 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003795 })
3796 tests = append(tests, testCase{
3797 testType: serverTest,
3798 name: "OCSPStapling-Server-TLS13",
3799 config: Config{
3800 MaxVersion: VersionTLS13,
3801 },
3802 expectedOCSPResponse: testOCSPResponse,
3803 flags: []string{
3804 "-ocsp-response",
3805 base64.StdEncoding.EncodeToString(testOCSPResponse),
3806 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003807 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003808 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003809
David Benjamin4c3ddf72016-06-29 18:13:53 -04003810 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003811 for _, vers := range tlsVersions {
3812 if config.protocol == dtls && !vers.hasDTLS {
3813 continue
3814 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003815 for _, testType := range []testType{clientTest, serverTest} {
3816 suffix := "-Client"
3817 if testType == serverTest {
3818 suffix = "-Server"
3819 }
3820 suffix += "-" + vers.name
3821
3822 flag := "-verify-peer"
3823 if testType == serverTest {
3824 flag = "-require-any-client-certificate"
3825 }
3826
3827 tests = append(tests, testCase{
3828 testType: testType,
3829 name: "CertificateVerificationSucceed" + suffix,
3830 config: Config{
3831 MaxVersion: vers.version,
3832 Certificates: []Certificate{rsaCertificate},
3833 },
3834 flags: []string{
3835 flag,
3836 "-expect-verify-result",
3837 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003838 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003839 })
3840 tests = append(tests, testCase{
3841 testType: testType,
3842 name: "CertificateVerificationFail" + suffix,
3843 config: Config{
3844 MaxVersion: vers.version,
3845 Certificates: []Certificate{rsaCertificate},
3846 },
3847 flags: []string{
3848 flag,
3849 "-verify-fail",
3850 },
3851 shouldFail: true,
3852 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3853 })
3854 }
3855
3856 // By default, the client is in a soft fail mode where the peer
3857 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003858 tests = append(tests, testCase{
3859 testType: clientTest,
3860 name: "CertificateVerificationSoftFail-" + vers.name,
3861 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003862 MaxVersion: vers.version,
3863 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003864 },
3865 flags: []string{
3866 "-verify-fail",
3867 "-expect-verify-result",
3868 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003869 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003870 })
3871 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003872
David Benjamin1d4f4c02016-07-26 18:03:08 -04003873 tests = append(tests, testCase{
3874 name: "ShimSendAlert",
3875 flags: []string{"-send-alert"},
3876 shimWritesFirst: true,
3877 shouldFail: true,
3878 expectedLocalError: "remote error: decompression failure",
3879 })
3880
David Benjamin582ba042016-07-07 12:33:25 -07003881 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003882 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 name: "Renegotiate-Client",
3884 config: Config{
3885 MaxVersion: VersionTLS12,
3886 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003887 renegotiate: 1,
3888 flags: []string{
3889 "-renegotiate-freely",
3890 "-expect-total-renegotiations", "1",
3891 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003893
David Benjamin47921102016-07-28 11:29:18 -04003894 tests = append(tests, testCase{
3895 name: "SendHalfHelloRequest",
3896 config: Config{
3897 MaxVersion: VersionTLS12,
3898 Bugs: ProtocolBugs{
3899 PackHelloRequestWithFinished: config.packHandshakeFlight,
3900 },
3901 },
3902 sendHalfHelloRequest: true,
3903 flags: []string{"-renegotiate-ignore"},
3904 shouldFail: true,
3905 expectedError: ":UNEXPECTED_RECORD:",
3906 })
3907
David Benjamin760b1dd2015-05-15 23:33:48 -04003908 // NPN on client and server; results in post-handshake message.
3909 tests = append(tests, testCase{
3910 name: "NPN-Client",
3911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003912 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003913 NextProtos: []string{"foo"},
3914 },
3915 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003916 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 expectedNextProto: "foo",
3918 expectedNextProtoType: npn,
3919 })
3920 tests = append(tests, testCase{
3921 testType: serverTest,
3922 name: "NPN-Server",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 NextProtos: []string{"bar"},
3926 },
3927 flags: []string{
3928 "-advertise-npn", "\x03foo\x03bar\x03baz",
3929 "-expect-next-proto", "bar",
3930 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003931 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
3936 // TODO(davidben): Add tests for when False Start doesn't trigger.
3937
3938 // Client does False Start and negotiates NPN.
3939 tests = append(tests, testCase{
3940 name: "FalseStart",
3941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003942 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3944 NextProtos: []string{"foo"},
3945 Bugs: ProtocolBugs{
3946 ExpectFalseStart: true,
3947 },
3948 },
3949 flags: []string{
3950 "-false-start",
3951 "-select-next-proto", "foo",
3952 },
3953 shimWritesFirst: true,
3954 resumeSession: true,
3955 })
3956
3957 // Client does False Start and negotiates ALPN.
3958 tests = append(tests, testCase{
3959 name: "FalseStart-ALPN",
3960 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003961 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3963 NextProtos: []string{"foo"},
3964 Bugs: ProtocolBugs{
3965 ExpectFalseStart: true,
3966 },
3967 },
3968 flags: []string{
3969 "-false-start",
3970 "-advertise-alpn", "\x03foo",
3971 },
3972 shimWritesFirst: true,
3973 resumeSession: true,
3974 })
3975
3976 // Client does False Start but doesn't explicitly call
3977 // SSL_connect.
3978 tests = append(tests, testCase{
3979 name: "FalseStart-Implicit",
3980 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003981 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003982 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3983 NextProtos: []string{"foo"},
3984 },
3985 flags: []string{
3986 "-implicit-handshake",
3987 "-false-start",
3988 "-advertise-alpn", "\x03foo",
3989 },
3990 })
3991
3992 // False Start without session tickets.
3993 tests = append(tests, testCase{
3994 name: "FalseStart-SessionTicketsDisabled",
3995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003996 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3998 NextProtos: []string{"foo"},
3999 SessionTicketsDisabled: true,
4000 Bugs: ProtocolBugs{
4001 ExpectFalseStart: true,
4002 },
4003 },
4004 flags: []string{
4005 "-false-start",
4006 "-select-next-proto", "foo",
4007 },
4008 shimWritesFirst: true,
4009 })
4010
Adam Langleydf759b52016-07-11 15:24:37 -07004011 tests = append(tests, testCase{
4012 name: "FalseStart-CECPQ1",
4013 config: Config{
4014 MaxVersion: VersionTLS12,
4015 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
4016 NextProtos: []string{"foo"},
4017 Bugs: ProtocolBugs{
4018 ExpectFalseStart: true,
4019 },
4020 },
4021 flags: []string{
4022 "-false-start",
4023 "-cipher", "DEFAULT:kCECPQ1",
4024 "-select-next-proto", "foo",
4025 },
4026 shimWritesFirst: true,
4027 resumeSession: true,
4028 })
4029
David Benjamin760b1dd2015-05-15 23:33:48 -04004030 // Server parses a V2ClientHello.
4031 tests = append(tests, testCase{
4032 testType: serverTest,
4033 name: "SendV2ClientHello",
4034 config: Config{
4035 // Choose a cipher suite that does not involve
4036 // elliptic curves, so no extensions are
4037 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004038 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004039 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004040 Bugs: ProtocolBugs{
4041 SendV2ClientHello: true,
4042 },
4043 },
4044 })
4045
Nick Harper60a85cb2016-09-23 16:25:11 -07004046 // Test Channel ID
4047 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004048 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004049 continue
4050 }
4051 // Client sends a Channel ID.
4052 tests = append(tests, testCase{
4053 name: "ChannelID-Client-" + ver.name,
4054 config: Config{
4055 MaxVersion: ver.version,
4056 RequestChannelID: true,
4057 },
4058 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4059 resumeSession: true,
4060 expectChannelID: true,
4061 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004062
Nick Harper60a85cb2016-09-23 16:25:11 -07004063 // Server accepts a Channel ID.
4064 tests = append(tests, testCase{
4065 testType: serverTest,
4066 name: "ChannelID-Server-" + ver.name,
4067 config: Config{
4068 MaxVersion: ver.version,
4069 ChannelID: channelIDKey,
4070 },
4071 flags: []string{
4072 "-expect-channel-id",
4073 base64.StdEncoding.EncodeToString(channelIDBytes),
4074 },
4075 resumeSession: true,
4076 expectChannelID: true,
4077 })
4078
4079 tests = append(tests, testCase{
4080 testType: serverTest,
4081 name: "InvalidChannelIDSignature-" + ver.name,
4082 config: Config{
4083 MaxVersion: ver.version,
4084 ChannelID: channelIDKey,
4085 Bugs: ProtocolBugs{
4086 InvalidChannelIDSignature: true,
4087 },
4088 },
4089 flags: []string{"-enable-channel-id"},
4090 shouldFail: true,
4091 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4092 })
4093 }
David Benjamin30789da2015-08-29 22:56:45 -04004094
David Benjaminf8fcdf32016-06-08 15:56:13 -04004095 // Channel ID and NPN at the same time, to ensure their relative
4096 // ordering is correct.
4097 tests = append(tests, testCase{
4098 name: "ChannelID-NPN-Client",
4099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004100 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004101 RequestChannelID: true,
4102 NextProtos: []string{"foo"},
4103 },
4104 flags: []string{
4105 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4106 "-select-next-proto", "foo",
4107 },
4108 resumeSession: true,
4109 expectChannelID: true,
4110 expectedNextProto: "foo",
4111 expectedNextProtoType: npn,
4112 })
4113 tests = append(tests, testCase{
4114 testType: serverTest,
4115 name: "ChannelID-NPN-Server",
4116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004117 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004118 ChannelID: channelIDKey,
4119 NextProtos: []string{"bar"},
4120 },
4121 flags: []string{
4122 "-expect-channel-id",
4123 base64.StdEncoding.EncodeToString(channelIDBytes),
4124 "-advertise-npn", "\x03foo\x03bar\x03baz",
4125 "-expect-next-proto", "bar",
4126 },
4127 resumeSession: true,
4128 expectChannelID: true,
4129 expectedNextProto: "bar",
4130 expectedNextProtoType: npn,
4131 })
4132
David Benjamin30789da2015-08-29 22:56:45 -04004133 // Bidirectional shutdown with the runner initiating.
4134 tests = append(tests, testCase{
4135 name: "Shutdown-Runner",
4136 config: Config{
4137 Bugs: ProtocolBugs{
4138 ExpectCloseNotify: true,
4139 },
4140 },
4141 flags: []string{"-check-close-notify"},
4142 })
4143
4144 // Bidirectional shutdown with the shim initiating. The runner,
4145 // in the meantime, sends garbage before the close_notify which
4146 // the shim must ignore.
4147 tests = append(tests, testCase{
4148 name: "Shutdown-Shim",
4149 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004150 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004151 Bugs: ProtocolBugs{
4152 ExpectCloseNotify: true,
4153 },
4154 },
4155 shimShutsDown: true,
4156 sendEmptyRecords: 1,
4157 sendWarningAlerts: 1,
4158 flags: []string{"-check-close-notify"},
4159 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004160 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004161 // TODO(davidben): DTLS 1.3 will want a similar thing for
4162 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004163 tests = append(tests, testCase{
4164 name: "SkipHelloVerifyRequest",
4165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004166 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004167 Bugs: ProtocolBugs{
4168 SkipHelloVerifyRequest: true,
4169 },
4170 },
4171 })
4172 }
4173
David Benjamin760b1dd2015-05-15 23:33:48 -04004174 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004175 test.protocol = config.protocol
4176 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004177 test.name += "-DTLS"
4178 }
David Benjamin582ba042016-07-07 12:33:25 -07004179 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004180 test.name += "-Async"
4181 test.flags = append(test.flags, "-async")
4182 } else {
4183 test.name += "-Sync"
4184 }
David Benjamin582ba042016-07-07 12:33:25 -07004185 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004186 test.name += "-SplitHandshakeRecords"
4187 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004188 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004189 test.config.Bugs.MaxPacketLength = 256
4190 test.flags = append(test.flags, "-mtu", "256")
4191 }
4192 }
David Benjamin582ba042016-07-07 12:33:25 -07004193 if config.packHandshakeFlight {
4194 test.name += "-PackHandshakeFlight"
4195 test.config.Bugs.PackHandshakeFlight = true
4196 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004197 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004198 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004199}
4200
Adam Langley524e7172015-02-20 16:04:00 -08004201func addDDoSCallbackTests() {
4202 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004203 for _, resume := range []bool{false, true} {
4204 suffix := "Resume"
4205 if resume {
4206 suffix = "No" + suffix
4207 }
4208
4209 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004210 testType: serverTest,
4211 name: "Server-DDoS-OK-" + suffix,
4212 config: Config{
4213 MaxVersion: VersionTLS12,
4214 },
Adam Langley524e7172015-02-20 16:04:00 -08004215 flags: []string{"-install-ddos-callback"},
4216 resumeSession: resume,
4217 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004218 testCases = append(testCases, testCase{
4219 testType: serverTest,
4220 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4221 config: Config{
4222 MaxVersion: VersionTLS13,
4223 },
4224 flags: []string{"-install-ddos-callback"},
4225 resumeSession: resume,
4226 })
Adam Langley524e7172015-02-20 16:04:00 -08004227
4228 failFlag := "-fail-ddos-callback"
4229 if resume {
4230 failFlag = "-fail-second-ddos-callback"
4231 }
4232 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004233 testType: serverTest,
4234 name: "Server-DDoS-Reject-" + suffix,
4235 config: Config{
4236 MaxVersion: VersionTLS12,
4237 },
David Benjamin2c66e072016-09-16 15:58:00 -04004238 flags: []string{"-install-ddos-callback", failFlag},
4239 resumeSession: resume,
4240 shouldFail: true,
4241 expectedError: ":CONNECTION_REJECTED:",
4242 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004243 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004244 testCases = append(testCases, testCase{
4245 testType: serverTest,
4246 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4247 config: Config{
4248 MaxVersion: VersionTLS13,
4249 },
David Benjamin2c66e072016-09-16 15:58:00 -04004250 flags: []string{"-install-ddos-callback", failFlag},
4251 resumeSession: resume,
4252 shouldFail: true,
4253 expectedError: ":CONNECTION_REJECTED:",
4254 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004255 })
Adam Langley524e7172015-02-20 16:04:00 -08004256 }
4257}
4258
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004259func addVersionNegotiationTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all newer versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[i+1:] {
4264 flags = append(flags, vers.flag)
4265 }
4266
Steven Valdezfdd10992016-09-15 16:27:05 -04004267 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004268 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004269 protocols := []protocol{tls}
4270 if runnerVers.hasDTLS && shimVers.hasDTLS {
4271 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004272 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004273 for _, protocol := range protocols {
4274 expectedVersion := shimVers.version
4275 if runnerVers.version < shimVers.version {
4276 expectedVersion = runnerVers.version
4277 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004278
David Benjamin8b8c0062014-11-23 02:47:52 -05004279 suffix := shimVers.name + "-" + runnerVers.name
4280 if protocol == dtls {
4281 suffix += "-DTLS"
4282 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004283
David Benjamin1eb367c2014-12-12 18:17:51 -05004284 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4285
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004286 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004287 clientVers := shimVers.version
4288 if clientVers > VersionTLS10 {
4289 clientVers = VersionTLS10
4290 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004291 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004292 serverVers := expectedVersion
4293 if expectedVersion >= VersionTLS13 {
4294 serverVers = VersionTLS10
4295 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004296 serverVers = versionToWire(serverVers, protocol == dtls)
4297
David Benjamin8b8c0062014-11-23 02:47:52 -05004298 testCases = append(testCases, testCase{
4299 protocol: protocol,
4300 testType: clientTest,
4301 name: "VersionNegotiation-Client-" + suffix,
4302 config: Config{
4303 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004304 Bugs: ProtocolBugs{
4305 ExpectInitialRecordVersion: clientVers,
4306 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004307 },
4308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004311 testCases = append(testCases, testCase{
4312 protocol: protocol,
4313 testType: clientTest,
4314 name: "VersionNegotiation-Client2-" + suffix,
4315 config: Config{
4316 MaxVersion: runnerVers.version,
4317 Bugs: ProtocolBugs{
4318 ExpectInitialRecordVersion: clientVers,
4319 },
4320 },
4321 flags: []string{"-max-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004324
4325 testCases = append(testCases, testCase{
4326 protocol: protocol,
4327 testType: serverTest,
4328 name: "VersionNegotiation-Server-" + suffix,
4329 config: Config{
4330 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004331 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004332 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004333 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 },
4335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004338 testCases = append(testCases, testCase{
4339 protocol: protocol,
4340 testType: serverTest,
4341 name: "VersionNegotiation-Server2-" + suffix,
4342 config: Config{
4343 MaxVersion: runnerVers.version,
4344 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004345 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004346 },
4347 },
4348 flags: []string{"-max-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004351 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004352 }
4353 }
David Benjamin95c69562016-06-29 18:15:03 -04004354
Steven Valdezfdd10992016-09-15 16:27:05 -04004355 // Test the version extension at all versions.
4356 for _, vers := range tlsVersions {
4357 protocols := []protocol{tls}
4358 if vers.hasDTLS {
4359 protocols = append(protocols, dtls)
4360 }
4361 for _, protocol := range protocols {
4362 suffix := vers.name
4363 if protocol == dtls {
4364 suffix += "-DTLS"
4365 }
4366
4367 wireVersion := versionToWire(vers.version, protocol == dtls)
4368 testCases = append(testCases, testCase{
4369 protocol: protocol,
4370 testType: serverTest,
4371 name: "VersionNegotiationExtension-" + suffix,
4372 config: Config{
4373 Bugs: ProtocolBugs{
4374 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4375 },
4376 },
4377 expectedVersion: vers.version,
4378 })
4379 }
4380
4381 }
4382
4383 // If all versions are unknown, negotiation fails.
4384 testCases = append(testCases, testCase{
4385 testType: serverTest,
4386 name: "NoSupportedVersions",
4387 config: Config{
4388 Bugs: ProtocolBugs{
4389 SendSupportedVersions: []uint16{0x1111},
4390 },
4391 },
4392 shouldFail: true,
4393 expectedError: ":UNSUPPORTED_PROTOCOL:",
4394 })
4395 testCases = append(testCases, testCase{
4396 protocol: dtls,
4397 testType: serverTest,
4398 name: "NoSupportedVersions-DTLS",
4399 config: Config{
4400 Bugs: ProtocolBugs{
4401 SendSupportedVersions: []uint16{0x1111},
4402 },
4403 },
4404 shouldFail: true,
4405 expectedError: ":UNSUPPORTED_PROTOCOL:",
4406 })
4407
4408 testCases = append(testCases, testCase{
4409 testType: serverTest,
4410 name: "ClientHelloVersionTooHigh",
4411 config: Config{
4412 MaxVersion: VersionTLS13,
4413 Bugs: ProtocolBugs{
4414 SendClientVersion: 0x0304,
4415 OmitSupportedVersions: true,
4416 },
4417 },
4418 expectedVersion: VersionTLS12,
4419 })
4420
4421 testCases = append(testCases, testCase{
4422 testType: serverTest,
4423 name: "ConflictingVersionNegotiation",
4424 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004425 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004426 SendClientVersion: VersionTLS12,
4427 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004428 },
4429 },
David Benjaminad75a662016-09-30 15:42:59 -04004430 // The extension takes precedence over the ClientHello version.
4431 expectedVersion: VersionTLS11,
4432 })
4433
4434 testCases = append(testCases, testCase{
4435 testType: serverTest,
4436 name: "ConflictingVersionNegotiation-2",
4437 config: Config{
4438 Bugs: ProtocolBugs{
4439 SendClientVersion: VersionTLS11,
4440 SendSupportedVersions: []uint16{VersionTLS12},
4441 },
4442 },
4443 // The extension takes precedence over the ClientHello version.
4444 expectedVersion: VersionTLS12,
4445 })
4446
4447 testCases = append(testCases, testCase{
4448 testType: serverTest,
4449 name: "RejectFinalTLS13",
4450 config: Config{
4451 Bugs: ProtocolBugs{
4452 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4453 },
4454 },
4455 // We currently implement a draft TLS 1.3 version. Ensure that
4456 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004457 expectedVersion: VersionTLS12,
4458 })
4459
Brian Smithf85d3232016-10-28 10:34:06 -10004460 // Test that the maximum version is selected regardless of the
4461 // client-sent order.
4462 testCases = append(testCases, testCase{
4463 testType: serverTest,
4464 name: "IgnoreClientVersionOrder",
4465 config: Config{
4466 Bugs: ProtocolBugs{
4467 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4468 },
4469 },
4470 expectedVersion: VersionTLS13,
4471 })
4472
David Benjamin95c69562016-06-29 18:15:03 -04004473 // Test for version tolerance.
4474 testCases = append(testCases, testCase{
4475 testType: serverTest,
4476 name: "MinorVersionTolerance",
4477 config: Config{
4478 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004479 SendClientVersion: 0x03ff,
4480 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004481 },
4482 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004483 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004484 })
4485 testCases = append(testCases, testCase{
4486 testType: serverTest,
4487 name: "MajorVersionTolerance",
4488 config: Config{
4489 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004490 SendClientVersion: 0x0400,
4491 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004492 },
4493 },
David Benjaminad75a662016-09-30 15:42:59 -04004494 // TLS 1.3 must be negotiated with the supported_versions
4495 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004496 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004497 })
David Benjaminad75a662016-09-30 15:42:59 -04004498 testCases = append(testCases, testCase{
4499 testType: serverTest,
4500 name: "VersionTolerance-TLS13",
4501 config: Config{
4502 Bugs: ProtocolBugs{
4503 // Although TLS 1.3 does not use
4504 // ClientHello.version, it still tolerates high
4505 // values there.
4506 SendClientVersion: 0x0400,
4507 },
4508 },
4509 expectedVersion: VersionTLS13,
4510 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004511
David Benjamin95c69562016-06-29 18:15:03 -04004512 testCases = append(testCases, testCase{
4513 protocol: dtls,
4514 testType: serverTest,
4515 name: "MinorVersionTolerance-DTLS",
4516 config: Config{
4517 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004518 SendClientVersion: 0xfe00,
4519 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004520 },
4521 },
4522 expectedVersion: VersionTLS12,
4523 })
4524 testCases = append(testCases, testCase{
4525 protocol: dtls,
4526 testType: serverTest,
4527 name: "MajorVersionTolerance-DTLS",
4528 config: Config{
4529 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004530 SendClientVersion: 0xfdff,
4531 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004532 },
4533 },
4534 expectedVersion: VersionTLS12,
4535 })
4536
4537 // Test that versions below 3.0 are rejected.
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "VersionTooLow",
4541 config: Config{
4542 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004543 SendClientVersion: 0x0200,
4544 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004545 },
4546 },
4547 shouldFail: true,
4548 expectedError: ":UNSUPPORTED_PROTOCOL:",
4549 })
4550 testCases = append(testCases, testCase{
4551 protocol: dtls,
4552 testType: serverTest,
4553 name: "VersionTooLow-DTLS",
4554 config: Config{
4555 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004556 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004557 },
4558 },
4559 shouldFail: true,
4560 expectedError: ":UNSUPPORTED_PROTOCOL:",
4561 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004562
David Benjamin2dc02042016-09-19 19:57:37 -04004563 testCases = append(testCases, testCase{
4564 name: "ServerBogusVersion",
4565 config: Config{
4566 Bugs: ProtocolBugs{
4567 SendServerHelloVersion: 0x1234,
4568 },
4569 },
4570 shouldFail: true,
4571 expectedError: ":UNSUPPORTED_PROTOCOL:",
4572 })
4573
David Benjamin1f61f0d2016-07-10 12:20:35 -04004574 // Test TLS 1.3's downgrade signal.
4575 testCases = append(testCases, testCase{
4576 name: "Downgrade-TLS12-Client",
4577 config: Config{
4578 Bugs: ProtocolBugs{
4579 NegotiateVersion: VersionTLS12,
4580 },
4581 },
David Benjamin592b5322016-09-30 15:15:01 -04004582 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004583 // TODO(davidben): This test should fail once TLS 1.3 is final
4584 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004585 })
4586 testCases = append(testCases, testCase{
4587 testType: serverTest,
4588 name: "Downgrade-TLS12-Server",
4589 config: Config{
4590 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004591 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004592 },
4593 },
David Benjamin592b5322016-09-30 15:15:01 -04004594 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004595 // TODO(davidben): This test should fail once TLS 1.3 is final
4596 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004597 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004598}
4599
David Benjaminaccb4542014-12-12 23:44:33 -05004600func addMinimumVersionTests() {
4601 for i, shimVers := range tlsVersions {
4602 // Assemble flags to disable all older versions on the shim.
4603 var flags []string
4604 for _, vers := range tlsVersions[:i] {
4605 flags = append(flags, vers.flag)
4606 }
4607
4608 for _, runnerVers := range tlsVersions {
4609 protocols := []protocol{tls}
4610 if runnerVers.hasDTLS && shimVers.hasDTLS {
4611 protocols = append(protocols, dtls)
4612 }
4613 for _, protocol := range protocols {
4614 suffix := shimVers.name + "-" + runnerVers.name
4615 if protocol == dtls {
4616 suffix += "-DTLS"
4617 }
4618 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4619
David Benjaminaccb4542014-12-12 23:44:33 -05004620 var expectedVersion uint16
4621 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004622 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004623 if runnerVers.version >= shimVers.version {
4624 expectedVersion = runnerVers.version
4625 } else {
4626 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004627 expectedError = ":UNSUPPORTED_PROTOCOL:"
4628 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004629 }
4630
4631 testCases = append(testCases, testCase{
4632 protocol: protocol,
4633 testType: clientTest,
4634 name: "MinimumVersion-Client-" + suffix,
4635 config: Config{
4636 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004637 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004638 // Ensure the server does not decline to
4639 // select a version (versions extension) or
4640 // cipher (some ciphers depend on versions).
4641 NegotiateVersion: runnerVers.version,
4642 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004643 },
David Benjaminaccb4542014-12-12 23:44:33 -05004644 },
David Benjamin87909c02014-12-13 01:55:01 -05004645 flags: flags,
4646 expectedVersion: expectedVersion,
4647 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004648 expectedError: expectedError,
4649 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004650 })
4651 testCases = append(testCases, testCase{
4652 protocol: protocol,
4653 testType: clientTest,
4654 name: "MinimumVersion-Client2-" + suffix,
4655 config: Config{
4656 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004657 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004658 // Ensure the server does not decline to
4659 // select a version (versions extension) or
4660 // cipher (some ciphers depend on versions).
4661 NegotiateVersion: runnerVers.version,
4662 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004663 },
David Benjaminaccb4542014-12-12 23:44:33 -05004664 },
David Benjamin87909c02014-12-13 01:55:01 -05004665 flags: []string{"-min-version", shimVersFlag},
4666 expectedVersion: expectedVersion,
4667 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004668 expectedError: expectedError,
4669 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004670 })
4671
4672 testCases = append(testCases, testCase{
4673 protocol: protocol,
4674 testType: serverTest,
4675 name: "MinimumVersion-Server-" + suffix,
4676 config: Config{
4677 MaxVersion: runnerVers.version,
4678 },
David Benjamin87909c02014-12-13 01:55:01 -05004679 flags: flags,
4680 expectedVersion: expectedVersion,
4681 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004682 expectedError: expectedError,
4683 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004684 })
4685 testCases = append(testCases, testCase{
4686 protocol: protocol,
4687 testType: serverTest,
4688 name: "MinimumVersion-Server2-" + suffix,
4689 config: Config{
4690 MaxVersion: runnerVers.version,
4691 },
David Benjamin87909c02014-12-13 01:55:01 -05004692 flags: []string{"-min-version", shimVersFlag},
4693 expectedVersion: expectedVersion,
4694 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004695 expectedError: expectedError,
4696 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004697 })
4698 }
4699 }
4700 }
4701}
4702
David Benjamine78bfde2014-09-06 12:45:15 -04004703func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004704 // TODO(davidben): Extensions, where applicable, all move their server
4705 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4706 // tests for both. Also test interaction with 0-RTT when implemented.
4707
David Benjamin97d17d92016-07-14 16:12:00 -04004708 // Repeat extensions tests all versions except SSL 3.0.
4709 for _, ver := range tlsVersions {
4710 if ver.version == VersionSSL30 {
4711 continue
4712 }
4713
David Benjamin97d17d92016-07-14 16:12:00 -04004714 // Test that duplicate extensions are rejected.
4715 testCases = append(testCases, testCase{
4716 testType: clientTest,
4717 name: "DuplicateExtensionClient-" + ver.name,
4718 config: Config{
4719 MaxVersion: ver.version,
4720 Bugs: ProtocolBugs{
4721 DuplicateExtension: true,
4722 },
David Benjamine78bfde2014-09-06 12:45:15 -04004723 },
David Benjamin97d17d92016-07-14 16:12:00 -04004724 shouldFail: true,
4725 expectedLocalError: "remote error: error decoding message",
4726 })
4727 testCases = append(testCases, testCase{
4728 testType: serverTest,
4729 name: "DuplicateExtensionServer-" + ver.name,
4730 config: Config{
4731 MaxVersion: ver.version,
4732 Bugs: ProtocolBugs{
4733 DuplicateExtension: true,
4734 },
David Benjamine78bfde2014-09-06 12:45:15 -04004735 },
David Benjamin97d17d92016-07-14 16:12:00 -04004736 shouldFail: true,
4737 expectedLocalError: "remote error: error decoding message",
4738 })
4739
4740 // Test SNI.
4741 testCases = append(testCases, testCase{
4742 testType: clientTest,
4743 name: "ServerNameExtensionClient-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 ExpectServerName: "example.com",
4748 },
David Benjamine78bfde2014-09-06 12:45:15 -04004749 },
David Benjamin97d17d92016-07-14 16:12:00 -04004750 flags: []string{"-host-name", "example.com"},
4751 })
4752 testCases = append(testCases, testCase{
4753 testType: clientTest,
4754 name: "ServerNameExtensionClientMismatch-" + ver.name,
4755 config: Config{
4756 MaxVersion: ver.version,
4757 Bugs: ProtocolBugs{
4758 ExpectServerName: "mismatch.com",
4759 },
David Benjamine78bfde2014-09-06 12:45:15 -04004760 },
David Benjamin97d17d92016-07-14 16:12:00 -04004761 flags: []string{"-host-name", "example.com"},
4762 shouldFail: true,
4763 expectedLocalError: "tls: unexpected server name",
4764 })
4765 testCases = append(testCases, testCase{
4766 testType: clientTest,
4767 name: "ServerNameExtensionClientMissing-" + ver.name,
4768 config: Config{
4769 MaxVersion: ver.version,
4770 Bugs: ProtocolBugs{
4771 ExpectServerName: "missing.com",
4772 },
David Benjamine78bfde2014-09-06 12:45:15 -04004773 },
David Benjamin97d17d92016-07-14 16:12:00 -04004774 shouldFail: true,
4775 expectedLocalError: "tls: unexpected server name",
4776 })
4777 testCases = append(testCases, testCase{
4778 testType: serverTest,
4779 name: "ServerNameExtensionServer-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004783 },
David Benjamin97d17d92016-07-14 16:12:00 -04004784 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004785 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004786 })
4787
4788 // Test ALPN.
4789 testCases = append(testCases, testCase{
4790 testType: clientTest,
4791 name: "ALPNClient-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 NextProtos: []string{"foo"},
4795 },
4796 flags: []string{
4797 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4798 "-expect-alpn", "foo",
4799 },
4800 expectedNextProto: "foo",
4801 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004802 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004803 })
4804 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004805 testType: clientTest,
4806 name: "ALPNClient-Mismatch-" + ver.name,
4807 config: Config{
4808 MaxVersion: ver.version,
4809 Bugs: ProtocolBugs{
4810 SendALPN: "baz",
4811 },
4812 },
4813 flags: []string{
4814 "-advertise-alpn", "\x03foo\x03bar",
4815 },
4816 shouldFail: true,
4817 expectedError: ":INVALID_ALPN_PROTOCOL:",
4818 expectedLocalError: "remote error: illegal parameter",
4819 })
4820 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004821 testType: serverTest,
4822 name: "ALPNServer-" + ver.name,
4823 config: Config{
4824 MaxVersion: ver.version,
4825 NextProtos: []string{"foo", "bar", "baz"},
4826 },
4827 flags: []string{
4828 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4829 "-select-alpn", "foo",
4830 },
4831 expectedNextProto: "foo",
4832 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004833 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004834 })
4835 testCases = append(testCases, testCase{
4836 testType: serverTest,
4837 name: "ALPNServer-Decline-" + ver.name,
4838 config: Config{
4839 MaxVersion: ver.version,
4840 NextProtos: []string{"foo", "bar", "baz"},
4841 },
4842 flags: []string{"-decline-alpn"},
4843 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004844 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004845 })
4846
David Benjamin25fe85b2016-08-09 20:00:32 -04004847 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4848 // called once.
4849 testCases = append(testCases, testCase{
4850 testType: serverTest,
4851 name: "ALPNServer-Async-" + ver.name,
4852 config: Config{
4853 MaxVersion: ver.version,
4854 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004855 // Prior to TLS 1.3, exercise the asynchronous session callback.
4856 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004857 },
4858 flags: []string{
4859 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4860 "-select-alpn", "foo",
4861 "-async",
4862 },
4863 expectedNextProto: "foo",
4864 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004865 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004866 })
4867
David Benjamin97d17d92016-07-14 16:12:00 -04004868 var emptyString string
4869 testCases = append(testCases, testCase{
4870 testType: clientTest,
4871 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4872 config: Config{
4873 MaxVersion: ver.version,
4874 NextProtos: []string{""},
4875 Bugs: ProtocolBugs{
4876 // A server returning an empty ALPN protocol
4877 // should be rejected.
4878 ALPNProtocol: &emptyString,
4879 },
4880 },
4881 flags: []string{
4882 "-advertise-alpn", "\x03foo",
4883 },
4884 shouldFail: true,
4885 expectedError: ":PARSE_TLSEXT:",
4886 })
4887 testCases = append(testCases, testCase{
4888 testType: serverTest,
4889 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4890 config: Config{
4891 MaxVersion: ver.version,
4892 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004893 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004894 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004895 },
David Benjamin97d17d92016-07-14 16:12:00 -04004896 flags: []string{
4897 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004898 },
David Benjamin97d17d92016-07-14 16:12:00 -04004899 shouldFail: true,
4900 expectedError: ":PARSE_TLSEXT:",
4901 })
4902
4903 // Test NPN and the interaction with ALPN.
4904 if ver.version < VersionTLS13 {
4905 // Test that the server prefers ALPN over NPN.
4906 testCases = append(testCases, testCase{
4907 testType: serverTest,
4908 name: "ALPNServer-Preferred-" + ver.name,
4909 config: Config{
4910 MaxVersion: ver.version,
4911 NextProtos: []string{"foo", "bar", "baz"},
4912 },
4913 flags: []string{
4914 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4915 "-select-alpn", "foo",
4916 "-advertise-npn", "\x03foo\x03bar\x03baz",
4917 },
4918 expectedNextProto: "foo",
4919 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004920 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004921 })
4922 testCases = append(testCases, testCase{
4923 testType: serverTest,
4924 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4925 config: Config{
4926 MaxVersion: ver.version,
4927 NextProtos: []string{"foo", "bar", "baz"},
4928 Bugs: ProtocolBugs{
4929 SwapNPNAndALPN: true,
4930 },
4931 },
4932 flags: []string{
4933 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4934 "-select-alpn", "foo",
4935 "-advertise-npn", "\x03foo\x03bar\x03baz",
4936 },
4937 expectedNextProto: "foo",
4938 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004939 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004940 })
4941
4942 // Test that negotiating both NPN and ALPN is forbidden.
4943 testCases = append(testCases, testCase{
4944 name: "NegotiateALPNAndNPN-" + ver.name,
4945 config: Config{
4946 MaxVersion: ver.version,
4947 NextProtos: []string{"foo", "bar", "baz"},
4948 Bugs: ProtocolBugs{
4949 NegotiateALPNAndNPN: true,
4950 },
4951 },
4952 flags: []string{
4953 "-advertise-alpn", "\x03foo",
4954 "-select-next-proto", "foo",
4955 },
4956 shouldFail: true,
4957 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4958 })
4959 testCases = append(testCases, testCase{
4960 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4961 config: Config{
4962 MaxVersion: ver.version,
4963 NextProtos: []string{"foo", "bar", "baz"},
4964 Bugs: ProtocolBugs{
4965 NegotiateALPNAndNPN: true,
4966 SwapNPNAndALPN: true,
4967 },
4968 },
4969 flags: []string{
4970 "-advertise-alpn", "\x03foo",
4971 "-select-next-proto", "foo",
4972 },
4973 shouldFail: true,
4974 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4975 })
4976
4977 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4978 testCases = append(testCases, testCase{
4979 name: "DisableNPN-" + ver.name,
4980 config: Config{
4981 MaxVersion: ver.version,
4982 NextProtos: []string{"foo"},
4983 },
4984 flags: []string{
4985 "-select-next-proto", "foo",
4986 "-disable-npn",
4987 },
4988 expectNoNextProto: true,
4989 })
4990 }
4991
4992 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004993
4994 // Resume with a corrupt ticket.
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "CorruptTicket-" + ver.name,
4998 config: Config{
4999 MaxVersion: ver.version,
5000 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005001 FilterTicket: func(in []byte) ([]byte, error) {
5002 in[len(in)-1] ^= 1
5003 return in, nil
5004 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005005 },
5006 },
5007 resumeSession: true,
5008 expectResumeRejected: true,
5009 })
5010 // Test the ticket callback, with and without renewal.
5011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "TicketCallback-" + ver.name,
5014 config: Config{
5015 MaxVersion: ver.version,
5016 },
5017 resumeSession: true,
5018 flags: []string{"-use-ticket-callback"},
5019 })
5020 testCases = append(testCases, testCase{
5021 testType: serverTest,
5022 name: "TicketCallback-Renew-" + ver.name,
5023 config: Config{
5024 MaxVersion: ver.version,
5025 Bugs: ProtocolBugs{
5026 ExpectNewTicket: true,
5027 },
5028 },
5029 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5030 resumeSession: true,
5031 })
5032
5033 // Test that the ticket callback is only called once when everything before
5034 // it in the ClientHello is asynchronous. This corrupts the ticket so
5035 // certificate selection callbacks run.
5036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "TicketCallback-SingleCall-" + ver.name,
5039 config: Config{
5040 MaxVersion: ver.version,
5041 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005042 FilterTicket: func(in []byte) ([]byte, error) {
5043 in[len(in)-1] ^= 1
5044 return in, nil
5045 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005046 },
5047 },
5048 resumeSession: true,
5049 expectResumeRejected: true,
5050 flags: []string{
5051 "-use-ticket-callback",
5052 "-async",
5053 },
5054 })
5055
5056 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005057 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005058 testCases = append(testCases, testCase{
5059 testType: serverTest,
5060 name: "OversizedSessionId-" + ver.name,
5061 config: Config{
5062 MaxVersion: ver.version,
5063 Bugs: ProtocolBugs{
5064 OversizedSessionId: true,
5065 },
5066 },
5067 resumeSession: true,
5068 shouldFail: true,
5069 expectedError: ":DECODE_ERROR:",
5070 })
5071 }
5072
5073 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5074 // are ignored.
5075 if ver.hasDTLS {
5076 testCases = append(testCases, testCase{
5077 protocol: dtls,
5078 name: "SRTP-Client-" + ver.name,
5079 config: Config{
5080 MaxVersion: ver.version,
5081 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5082 },
5083 flags: []string{
5084 "-srtp-profiles",
5085 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5086 },
5087 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5088 })
5089 testCases = append(testCases, testCase{
5090 protocol: dtls,
5091 testType: serverTest,
5092 name: "SRTP-Server-" + ver.name,
5093 config: Config{
5094 MaxVersion: ver.version,
5095 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5096 },
5097 flags: []string{
5098 "-srtp-profiles",
5099 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5100 },
5101 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5102 })
5103 // Test that the MKI is ignored.
5104 testCases = append(testCases, testCase{
5105 protocol: dtls,
5106 testType: serverTest,
5107 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5108 config: Config{
5109 MaxVersion: ver.version,
5110 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5111 Bugs: ProtocolBugs{
5112 SRTPMasterKeyIdentifer: "bogus",
5113 },
5114 },
5115 flags: []string{
5116 "-srtp-profiles",
5117 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5118 },
5119 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5120 })
5121 // Test that SRTP isn't negotiated on the server if there were
5122 // no matching profiles.
5123 testCases = append(testCases, testCase{
5124 protocol: dtls,
5125 testType: serverTest,
5126 name: "SRTP-Server-NoMatch-" + ver.name,
5127 config: Config{
5128 MaxVersion: ver.version,
5129 SRTPProtectionProfiles: []uint16{100, 101, 102},
5130 },
5131 flags: []string{
5132 "-srtp-profiles",
5133 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5134 },
5135 expectedSRTPProtectionProfile: 0,
5136 })
5137 // Test that the server returning an invalid SRTP profile is
5138 // flagged as an error by the client.
5139 testCases = append(testCases, testCase{
5140 protocol: dtls,
5141 name: "SRTP-Client-NoMatch-" + ver.name,
5142 config: Config{
5143 MaxVersion: ver.version,
5144 Bugs: ProtocolBugs{
5145 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5146 },
5147 },
5148 flags: []string{
5149 "-srtp-profiles",
5150 "SRTP_AES128_CM_SHA1_80",
5151 },
5152 shouldFail: true,
5153 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5154 })
5155 }
5156
5157 // Test SCT list.
5158 testCases = append(testCases, testCase{
5159 name: "SignedCertificateTimestampList-Client-" + ver.name,
5160 testType: clientTest,
5161 config: Config{
5162 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005163 },
David Benjamin97d17d92016-07-14 16:12:00 -04005164 flags: []string{
5165 "-enable-signed-cert-timestamps",
5166 "-expect-signed-cert-timestamps",
5167 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005168 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005169 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005170 })
David Benjamindaa88502016-10-04 16:32:16 -04005171
Adam Langleycfa08c32016-11-17 13:21:27 -08005172 var differentSCTList []byte
5173 differentSCTList = append(differentSCTList, testSCTList...)
5174 differentSCTList[len(differentSCTList)-1] ^= 1
5175
David Benjamindaa88502016-10-04 16:32:16 -04005176 // The SCT extension did not specify that it must only be sent on resumption as it
5177 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005178 testCases = append(testCases, testCase{
5179 name: "SendSCTListOnResume-" + ver.name,
5180 config: Config{
5181 MaxVersion: ver.version,
5182 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005183 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005184 },
David Benjamind98452d2015-06-16 14:16:23 -04005185 },
David Benjamin97d17d92016-07-14 16:12:00 -04005186 flags: []string{
5187 "-enable-signed-cert-timestamps",
5188 "-expect-signed-cert-timestamps",
5189 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005190 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005191 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005192 })
David Benjamindaa88502016-10-04 16:32:16 -04005193
David Benjamin97d17d92016-07-14 16:12:00 -04005194 testCases = append(testCases, testCase{
5195 name: "SignedCertificateTimestampList-Server-" + ver.name,
5196 testType: serverTest,
5197 config: Config{
5198 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005199 },
David Benjamin97d17d92016-07-14 16:12:00 -04005200 flags: []string{
5201 "-signed-cert-timestamps",
5202 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005203 },
David Benjamin97d17d92016-07-14 16:12:00 -04005204 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005205 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005206 })
David Benjamin53210cb2016-11-16 09:01:48 +09005207
Adam Langleycfa08c32016-11-17 13:21:27 -08005208 emptySCTListCert := *testCerts[0].cert
5209 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5210
5211 // Test empty SCT list.
5212 testCases = append(testCases, testCase{
5213 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5214 testType: clientTest,
5215 config: Config{
5216 MaxVersion: ver.version,
5217 Certificates: []Certificate{emptySCTListCert},
5218 },
5219 flags: []string{
5220 "-enable-signed-cert-timestamps",
5221 },
5222 shouldFail: true,
5223 expectedError: ":ERROR_PARSING_EXTENSION:",
5224 })
5225
5226 emptySCTCert := *testCerts[0].cert
5227 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5228
5229 // Test empty SCT in non-empty list.
5230 testCases = append(testCases, testCase{
5231 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5232 testType: clientTest,
5233 config: Config{
5234 MaxVersion: ver.version,
5235 Certificates: []Certificate{emptySCTCert},
5236 },
5237 flags: []string{
5238 "-enable-signed-cert-timestamps",
5239 },
5240 shouldFail: true,
5241 expectedError: ":ERROR_PARSING_EXTENSION:",
5242 })
5243
David Benjamin53210cb2016-11-16 09:01:48 +09005244 // Test that certificate-related extensions are not sent unsolicited.
5245 testCases = append(testCases, testCase{
5246 testType: serverTest,
5247 name: "UnsolicitedCertificateExtensions-" + ver.name,
5248 config: Config{
5249 MaxVersion: ver.version,
5250 Bugs: ProtocolBugs{
5251 NoOCSPStapling: true,
5252 NoSignedCertificateTimestamps: true,
5253 },
5254 },
5255 flags: []string{
5256 "-ocsp-response",
5257 base64.StdEncoding.EncodeToString(testOCSPResponse),
5258 "-signed-cert-timestamps",
5259 base64.StdEncoding.EncodeToString(testSCTList),
5260 },
5261 })
David Benjamin97d17d92016-07-14 16:12:00 -04005262 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005263
Paul Lietar4fac72e2015-09-09 13:44:55 +01005264 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005265 testType: clientTest,
5266 name: "ClientHelloPadding",
5267 config: Config{
5268 Bugs: ProtocolBugs{
5269 RequireClientHelloSize: 512,
5270 },
5271 },
5272 // This hostname just needs to be long enough to push the
5273 // ClientHello into F5's danger zone between 256 and 511 bytes
5274 // long.
5275 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5276 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005277
5278 // Extensions should not function in SSL 3.0.
5279 testCases = append(testCases, testCase{
5280 testType: serverTest,
5281 name: "SSLv3Extensions-NoALPN",
5282 config: Config{
5283 MaxVersion: VersionSSL30,
5284 NextProtos: []string{"foo", "bar", "baz"},
5285 },
5286 flags: []string{
5287 "-select-alpn", "foo",
5288 },
5289 expectNoNextProto: true,
5290 })
5291
5292 // Test session tickets separately as they follow a different codepath.
5293 testCases = append(testCases, testCase{
5294 testType: serverTest,
5295 name: "SSLv3Extensions-NoTickets",
5296 config: Config{
5297 MaxVersion: VersionSSL30,
5298 Bugs: ProtocolBugs{
5299 // Historically, session tickets in SSL 3.0
5300 // failed in different ways depending on whether
5301 // the client supported renegotiation_info.
5302 NoRenegotiationInfo: true,
5303 },
5304 },
5305 resumeSession: true,
5306 })
5307 testCases = append(testCases, testCase{
5308 testType: serverTest,
5309 name: "SSLv3Extensions-NoTickets2",
5310 config: Config{
5311 MaxVersion: VersionSSL30,
5312 },
5313 resumeSession: true,
5314 })
5315
5316 // But SSL 3.0 does send and process renegotiation_info.
5317 testCases = append(testCases, testCase{
5318 testType: serverTest,
5319 name: "SSLv3Extensions-RenegotiationInfo",
5320 config: Config{
5321 MaxVersion: VersionSSL30,
5322 Bugs: ProtocolBugs{
5323 RequireRenegotiationInfo: true,
5324 },
5325 },
5326 })
5327 testCases = append(testCases, testCase{
5328 testType: serverTest,
5329 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5330 config: Config{
5331 MaxVersion: VersionSSL30,
5332 Bugs: ProtocolBugs{
5333 NoRenegotiationInfo: true,
5334 SendRenegotiationSCSV: true,
5335 RequireRenegotiationInfo: true,
5336 },
5337 },
5338 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005339
5340 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5341 // in ServerHello.
5342 testCases = append(testCases, testCase{
5343 name: "NPN-Forbidden-TLS13",
5344 config: Config{
5345 MaxVersion: VersionTLS13,
5346 NextProtos: []string{"foo"},
5347 Bugs: ProtocolBugs{
5348 NegotiateNPNAtAllVersions: true,
5349 },
5350 },
5351 flags: []string{"-select-next-proto", "foo"},
5352 shouldFail: true,
5353 expectedError: ":ERROR_PARSING_EXTENSION:",
5354 })
5355 testCases = append(testCases, testCase{
5356 name: "EMS-Forbidden-TLS13",
5357 config: Config{
5358 MaxVersion: VersionTLS13,
5359 Bugs: ProtocolBugs{
5360 NegotiateEMSAtAllVersions: true,
5361 },
5362 },
5363 shouldFail: true,
5364 expectedError: ":ERROR_PARSING_EXTENSION:",
5365 })
5366 testCases = append(testCases, testCase{
5367 name: "RenegotiationInfo-Forbidden-TLS13",
5368 config: Config{
5369 MaxVersion: VersionTLS13,
5370 Bugs: ProtocolBugs{
5371 NegotiateRenegotiationInfoAtAllVersions: true,
5372 },
5373 },
5374 shouldFail: true,
5375 expectedError: ":ERROR_PARSING_EXTENSION:",
5376 })
5377 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005378 name: "Ticket-Forbidden-TLS13",
5379 config: Config{
5380 MaxVersion: VersionTLS12,
5381 },
5382 resumeConfig: &Config{
5383 MaxVersion: VersionTLS13,
5384 Bugs: ProtocolBugs{
5385 AdvertiseTicketExtension: true,
5386 },
5387 },
5388 resumeSession: true,
5389 shouldFail: true,
5390 expectedError: ":ERROR_PARSING_EXTENSION:",
5391 })
5392
5393 // Test that illegal extensions in TLS 1.3 are declined by the server if
5394 // offered in ClientHello. The runner's server will fail if this occurs,
5395 // so we exercise the offering path. (EMS and Renegotiation Info are
5396 // implicit in every test.)
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005399 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005400 config: Config{
5401 MaxVersion: VersionTLS13,
5402 NextProtos: []string{"bar"},
5403 },
5404 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5405 })
David Benjamin196df5b2016-09-21 16:23:27 -04005406
David Benjamindaa88502016-10-04 16:32:16 -04005407 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5408 // tolerated.
5409 testCases = append(testCases, testCase{
5410 name: "SendOCSPResponseOnResume-TLS12",
5411 config: Config{
5412 MaxVersion: VersionTLS12,
5413 Bugs: ProtocolBugs{
5414 SendOCSPResponseOnResume: []byte("bogus"),
5415 },
5416 },
5417 flags: []string{
5418 "-enable-ocsp-stapling",
5419 "-expect-ocsp-response",
5420 base64.StdEncoding.EncodeToString(testOCSPResponse),
5421 },
5422 resumeSession: true,
5423 })
5424
David Benjamindaa88502016-10-04 16:32:16 -04005425 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005426 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005427 config: Config{
5428 MaxVersion: VersionTLS13,
5429 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005430 SendExtensionOnCertificate: testOCSPExtension,
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNEXPECTED_EXTENSION:",
5435 })
5436
5437 testCases = append(testCases, testCase{
5438 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5439 config: Config{
5440 MaxVersion: VersionTLS13,
5441 Bugs: ProtocolBugs{
5442 SendExtensionOnCertificate: testSCTExtension,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNEXPECTED_EXTENSION:",
5447 })
5448
5449 // Test that extensions on client certificates are never accepted.
5450 testCases = append(testCases, testCase{
5451 name: "SendExtensionOnClientCertificate-TLS13",
5452 testType: serverTest,
5453 config: Config{
5454 MaxVersion: VersionTLS13,
5455 Certificates: []Certificate{rsaCertificate},
5456 Bugs: ProtocolBugs{
5457 SendExtensionOnCertificate: testOCSPExtension,
5458 },
5459 },
5460 flags: []string{
5461 "-enable-ocsp-stapling",
5462 "-require-any-client-certificate",
5463 },
5464 shouldFail: true,
5465 expectedError: ":UNEXPECTED_EXTENSION:",
5466 })
5467
5468 testCases = append(testCases, testCase{
5469 name: "SendUnknownExtensionOnCertificate-TLS13",
5470 config: Config{
5471 MaxVersion: VersionTLS13,
5472 Bugs: ProtocolBugs{
5473 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5474 },
5475 },
5476 shouldFail: true,
5477 expectedError: ":UNEXPECTED_EXTENSION:",
5478 })
5479
Adam Langleycfa08c32016-11-17 13:21:27 -08005480 var differentSCTList []byte
5481 differentSCTList = append(differentSCTList, testSCTList...)
5482 differentSCTList[len(differentSCTList)-1] ^= 1
5483
Steven Valdeza833c352016-11-01 13:39:36 -04005484 // Test that extensions on intermediates are allowed but ignored.
5485 testCases = append(testCases, testCase{
5486 name: "IgnoreExtensionsOnIntermediates-TLS13",
5487 config: Config{
5488 MaxVersion: VersionTLS13,
5489 Certificates: []Certificate{rsaChainCertificate},
5490 Bugs: ProtocolBugs{
5491 // Send different values on the intermediate. This tests
5492 // the intermediate's extensions do not override the
5493 // leaf's.
5494 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005495 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005496 },
5497 },
5498 flags: []string{
5499 "-enable-ocsp-stapling",
5500 "-expect-ocsp-response",
5501 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005502 "-enable-signed-cert-timestamps",
5503 "-expect-signed-cert-timestamps",
5504 base64.StdEncoding.EncodeToString(testSCTList),
5505 },
5506 resumeSession: true,
5507 })
5508
5509 // Test that extensions are not sent on intermediates when configured
5510 // only for a leaf.
5511 testCases = append(testCases, testCase{
5512 testType: serverTest,
5513 name: "SendNoExtensionsOnIntermediate-TLS13",
5514 config: Config{
5515 MaxVersion: VersionTLS13,
5516 Bugs: ProtocolBugs{
5517 ExpectNoExtensionsOnIntermediate: true,
5518 },
5519 },
5520 flags: []string{
5521 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5522 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5523 "-ocsp-response",
5524 base64.StdEncoding.EncodeToString(testOCSPResponse),
5525 "-signed-cert-timestamps",
5526 base64.StdEncoding.EncodeToString(testSCTList),
5527 },
5528 })
5529
5530 // Test that extensions are not sent on client certificates.
5531 testCases = append(testCases, testCase{
5532 name: "SendNoClientCertificateExtensions-TLS13",
5533 config: Config{
5534 MaxVersion: VersionTLS13,
5535 ClientAuth: RequireAnyClientCert,
5536 },
5537 flags: []string{
5538 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5539 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5540 "-ocsp-response",
5541 base64.StdEncoding.EncodeToString(testOCSPResponse),
5542 "-signed-cert-timestamps",
5543 base64.StdEncoding.EncodeToString(testSCTList),
5544 },
5545 })
5546
5547 testCases = append(testCases, testCase{
5548 name: "SendDuplicateExtensionsOnCerts-TLS13",
5549 config: Config{
5550 MaxVersion: VersionTLS13,
5551 Bugs: ProtocolBugs{
5552 SendDuplicateCertExtensions: true,
5553 },
5554 },
5555 flags: []string{
5556 "-enable-ocsp-stapling",
5557 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005558 },
5559 resumeSession: true,
5560 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005561 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005562 })
Adam Langley9b885c52016-11-18 14:21:03 -08005563
5564 testCases = append(testCases, testCase{
5565 name: "SignedCertificateTimestampListInvalid-Server",
5566 testType: serverTest,
5567 flags: []string{
5568 "-signed-cert-timestamps",
5569 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5570 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005571 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005572 expectedError: ":INVALID_SCT_LIST:",
5573 })
David Benjamine78bfde2014-09-06 12:45:15 -04005574}
5575
David Benjamin01fe8202014-09-24 15:21:44 -04005576func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005577 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005578 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005579 // SSL 3.0 does not have tickets and TLS 1.3 does not
5580 // have session IDs, so skip their cross-resumption
5581 // tests.
5582 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5583 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5584 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005585 }
5586
David Benjamin8b8c0062014-11-23 02:47:52 -05005587 protocols := []protocol{tls}
5588 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5589 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005590 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005591 for _, protocol := range protocols {
5592 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5593 if protocol == dtls {
5594 suffix += "-DTLS"
5595 }
5596
David Benjaminece3de92015-03-16 18:02:20 -04005597 if sessionVers.version == resumeVers.version {
5598 testCases = append(testCases, testCase{
5599 protocol: protocol,
5600 name: "Resume-Client" + suffix,
5601 resumeSession: true,
5602 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005603 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005604 Bugs: ProtocolBugs{
5605 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5606 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5607 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005608 },
David Benjaminece3de92015-03-16 18:02:20 -04005609 expectedVersion: sessionVers.version,
5610 expectedResumeVersion: resumeVers.version,
5611 })
5612 } else {
David Benjamin405da482016-08-08 17:25:07 -04005613 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5614
5615 // Offering a TLS 1.3 session sends an empty session ID, so
5616 // there is no way to convince a non-lookahead client the
5617 // session was resumed. It will appear to the client that a
5618 // stray ChangeCipherSpec was sent.
5619 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5620 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005621 }
5622
David Benjaminece3de92015-03-16 18:02:20 -04005623 testCases = append(testCases, testCase{
5624 protocol: protocol,
5625 name: "Resume-Client-Mismatch" + suffix,
5626 resumeSession: true,
5627 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005628 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005629 },
David Benjaminece3de92015-03-16 18:02:20 -04005630 expectedVersion: sessionVers.version,
5631 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005632 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005633 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005634 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005635 },
5636 },
5637 expectedResumeVersion: resumeVers.version,
5638 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005639 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005640 })
5641 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005642
5643 testCases = append(testCases, testCase{
5644 protocol: protocol,
5645 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005646 resumeSession: true,
5647 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005648 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005649 },
5650 expectedVersion: sessionVers.version,
5651 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005652 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005653 },
5654 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005655 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005656 expectedResumeVersion: resumeVers.version,
5657 })
5658
David Benjamin8b8c0062014-11-23 02:47:52 -05005659 testCases = append(testCases, testCase{
5660 protocol: protocol,
5661 testType: serverTest,
5662 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005663 resumeSession: true,
5664 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005665 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005666 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005667 expectedVersion: sessionVers.version,
5668 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005669 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005670 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005671 Bugs: ProtocolBugs{
5672 SendBothTickets: true,
5673 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005674 },
5675 expectedResumeVersion: resumeVers.version,
5676 })
5677 }
David Benjamin01fe8202014-09-24 15:21:44 -04005678 }
5679 }
David Benjaminece3de92015-03-16 18:02:20 -04005680
David Benjamin4199b0d2016-11-01 13:58:25 -04005681 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005682 testCases = append(testCases, testCase{
5683 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005684 name: "ShimTicketRewritable",
5685 resumeSession: true,
5686 config: Config{
5687 MaxVersion: VersionTLS12,
5688 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5689 Bugs: ProtocolBugs{
5690 FilterTicket: func(in []byte) ([]byte, error) {
5691 in, err := SetShimTicketVersion(in, VersionTLS12)
5692 if err != nil {
5693 return nil, err
5694 }
5695 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5696 },
5697 },
5698 },
5699 flags: []string{
5700 "-ticket-key",
5701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5702 },
5703 })
5704
5705 // Resumptions are declined if the version does not match.
5706 testCases = append(testCases, testCase{
5707 testType: serverTest,
5708 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005709 resumeSession: true,
5710 config: Config{
5711 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005712 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005713 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005714 FilterTicket: func(in []byte) ([]byte, error) {
5715 return SetShimTicketVersion(in, VersionTLS13)
5716 },
5717 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005718 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005719 flags: []string{
5720 "-ticket-key",
5721 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5722 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005723 expectResumeRejected: true,
5724 })
5725
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005728 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005729 resumeSession: true,
5730 config: Config{
5731 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005732 Bugs: ProtocolBugs{
5733 FilterTicket: func(in []byte) ([]byte, error) {
5734 return SetShimTicketVersion(in, VersionTLS12)
5735 },
5736 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005737 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005738 flags: []string{
5739 "-ticket-key",
5740 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5741 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005742 expectResumeRejected: true,
5743 })
5744
David Benjamin4199b0d2016-11-01 13:58:25 -04005745 // Resumptions are declined if the cipher is invalid or disabled.
5746 testCases = append(testCases, testCase{
5747 testType: serverTest,
5748 name: "Resume-Server-DeclineBadCipher",
5749 resumeSession: true,
5750 config: Config{
5751 MaxVersion: VersionTLS12,
5752 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005753 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005754 FilterTicket: func(in []byte) ([]byte, error) {
5755 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5756 },
5757 },
5758 },
5759 flags: []string{
5760 "-ticket-key",
5761 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5762 },
5763 expectResumeRejected: true,
5764 })
5765
5766 testCases = append(testCases, testCase{
5767 testType: serverTest,
5768 name: "Resume-Server-DeclineBadCipher-2",
5769 resumeSession: true,
5770 config: Config{
5771 MaxVersion: VersionTLS12,
5772 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005773 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005774 FilterTicket: func(in []byte) ([]byte, error) {
5775 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5776 },
5777 },
5778 },
5779 flags: []string{
5780 "-cipher", "AES128",
5781 "-ticket-key",
5782 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5783 },
5784 expectResumeRejected: true,
5785 })
5786
David Benjaminf01f42a2016-11-16 19:05:33 +09005787 // Sessions are not resumed if they do not use the preferred cipher.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "Resume-Server-CipherNotPreferred",
5791 resumeSession: true,
5792 config: Config{
5793 MaxVersion: VersionTLS12,
5794 Bugs: ProtocolBugs{
5795 ExpectNewTicket: true,
5796 FilterTicket: func(in []byte) ([]byte, error) {
5797 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5798 },
5799 },
5800 },
5801 flags: []string{
5802 "-ticket-key",
5803 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5804 },
5805 shouldFail: false,
5806 expectResumeRejected: true,
5807 })
5808
5809 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5810 // PRF hashes match, but BoringSSL will always decline such resumptions.
5811 testCases = append(testCases, testCase{
5812 testType: serverTest,
5813 name: "Resume-Server-CipherNotPreferred-TLS13",
5814 resumeSession: true,
5815 config: Config{
5816 MaxVersion: VersionTLS13,
5817 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5818 Bugs: ProtocolBugs{
5819 FilterTicket: func(in []byte) ([]byte, error) {
5820 // If the client (runner) offers ChaCha20-Poly1305 first, the
5821 // server (shim) always prefers it. Switch it to AES-GCM.
5822 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5823 },
5824 },
5825 },
5826 flags: []string{
5827 "-ticket-key",
5828 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5829 },
5830 shouldFail: false,
5831 expectResumeRejected: true,
5832 })
5833
5834 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005835 testCases = append(testCases, testCase{
5836 testType: serverTest,
5837 name: "Resume-Server-DeclineBadCipher-TLS13",
5838 resumeSession: true,
5839 config: Config{
5840 MaxVersion: VersionTLS13,
5841 Bugs: ProtocolBugs{
5842 FilterTicket: func(in []byte) ([]byte, error) {
5843 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5844 },
5845 },
5846 },
5847 flags: []string{
5848 "-ticket-key",
5849 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5850 },
5851 expectResumeRejected: true,
5852 })
5853
David Benjaminf01f42a2016-11-16 19:05:33 +09005854 // If the client does not offer the cipher from the session, decline to
5855 // resume. Clients are forbidden from doing this, but BoringSSL selects
5856 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "Resume-Server-UnofferedCipher",
5860 resumeSession: true,
5861 config: Config{
5862 MaxVersion: VersionTLS12,
5863 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5864 },
5865 resumeConfig: &Config{
5866 MaxVersion: VersionTLS12,
5867 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5868 Bugs: ProtocolBugs{
5869 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5870 },
5871 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005872 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005873 })
5874
David Benjaminf01f42a2016-11-16 19:05:33 +09005875 // In TLS 1.3, clients may advertise a cipher list which does not
5876 // include the selected cipher. Test that we tolerate this. Servers may
5877 // resume at another cipher if the PRF matches, but BoringSSL will
5878 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005879 testCases = append(testCases, testCase{
5880 testType: serverTest,
5881 name: "Resume-Server-UnofferedCipher-TLS13",
5882 resumeSession: true,
5883 config: Config{
5884 MaxVersion: VersionTLS13,
5885 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5886 },
5887 resumeConfig: &Config{
5888 MaxVersion: VersionTLS13,
5889 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5890 Bugs: ProtocolBugs{
5891 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5892 },
5893 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005894 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005895 })
5896
David Benjamin4199b0d2016-11-01 13:58:25 -04005897 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005898 testCases = append(testCases, testCase{
5899 name: "Resume-Client-CipherMismatch",
5900 resumeSession: true,
5901 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005902 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005903 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5904 },
5905 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005906 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005907 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5908 Bugs: ProtocolBugs{
5909 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5910 },
5911 },
5912 shouldFail: true,
5913 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5914 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915
David Benjamine1cc35e2016-11-16 16:25:58 +09005916 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5917 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005918 testCases = append(testCases, testCase{
5919 name: "Resume-Client-CipherMismatch-TLS13",
5920 resumeSession: true,
5921 config: Config{
5922 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005923 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005924 },
5925 resumeConfig: &Config{
5926 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005927 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5928 },
5929 })
5930
5931 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5932 testCases = append(testCases, testCase{
5933 name: "Resume-Client-PRFMismatch-TLS13",
5934 resumeSession: true,
5935 config: Config{
5936 MaxVersion: VersionTLS13,
5937 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5938 },
5939 resumeConfig: &Config{
5940 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005941 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005942 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005943 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005944 },
5945 },
5946 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005947 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005948 })
Steven Valdeza833c352016-11-01 13:39:36 -04005949
5950 testCases = append(testCases, testCase{
5951 testType: serverTest,
5952 name: "Resume-Server-BinderWrongLength",
5953 resumeSession: true,
5954 config: Config{
5955 MaxVersion: VersionTLS13,
5956 Bugs: ProtocolBugs{
5957 SendShortPSKBinder: true,
5958 },
5959 },
5960 shouldFail: true,
5961 expectedLocalError: "remote error: error decrypting message",
5962 expectedError: ":DIGEST_CHECK_FAILED:",
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 testType: serverTest,
5967 name: "Resume-Server-NoPSKBinder",
5968 resumeSession: true,
5969 config: Config{
5970 MaxVersion: VersionTLS13,
5971 Bugs: ProtocolBugs{
5972 SendNoPSKBinder: true,
5973 },
5974 },
5975 shouldFail: true,
5976 expectedLocalError: "remote error: error decoding message",
5977 expectedError: ":DECODE_ERROR:",
5978 })
5979
5980 testCases = append(testCases, testCase{
5981 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005982 name: "Resume-Server-ExtraPSKBinder",
5983 resumeSession: true,
5984 config: Config{
5985 MaxVersion: VersionTLS13,
5986 Bugs: ProtocolBugs{
5987 SendExtraPSKBinder: true,
5988 },
5989 },
5990 shouldFail: true,
5991 expectedLocalError: "remote error: illegal parameter",
5992 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5993 })
5994
5995 testCases = append(testCases, testCase{
5996 testType: serverTest,
5997 name: "Resume-Server-ExtraIdentityNoBinder",
5998 resumeSession: true,
5999 config: Config{
6000 MaxVersion: VersionTLS13,
6001 Bugs: ProtocolBugs{
6002 ExtraPSKIdentity: true,
6003 },
6004 },
6005 shouldFail: true,
6006 expectedLocalError: "remote error: illegal parameter",
6007 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6008 })
6009
6010 testCases = append(testCases, testCase{
6011 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006012 name: "Resume-Server-InvalidPSKBinder",
6013 resumeSession: true,
6014 config: Config{
6015 MaxVersion: VersionTLS13,
6016 Bugs: ProtocolBugs{
6017 SendInvalidPSKBinder: true,
6018 },
6019 },
6020 shouldFail: true,
6021 expectedLocalError: "remote error: error decrypting message",
6022 expectedError: ":DIGEST_CHECK_FAILED:",
6023 })
6024
6025 testCases = append(testCases, testCase{
6026 testType: serverTest,
6027 name: "Resume-Server-PSKBinderFirstExtension",
6028 resumeSession: true,
6029 config: Config{
6030 MaxVersion: VersionTLS13,
6031 Bugs: ProtocolBugs{
6032 PSKBinderFirst: true,
6033 },
6034 },
6035 shouldFail: true,
6036 expectedLocalError: "remote error: illegal parameter",
6037 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6038 })
David Benjamin01fe8202014-09-24 15:21:44 -04006039}
6040
Adam Langley2ae77d22014-10-28 17:29:33 -07006041func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006042 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006043 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006044 testType: serverTest,
6045 name: "Renegotiate-Server-Forbidden",
6046 config: Config{
6047 MaxVersion: VersionTLS12,
6048 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006049 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006050 shouldFail: true,
6051 expectedError: ":NO_RENEGOTIATION:",
6052 expectedLocalError: "remote error: no renegotiation",
6053 })
Adam Langley5021b222015-06-12 18:27:58 -07006054 // The server shouldn't echo the renegotiation extension unless
6055 // requested by the client.
6056 testCases = append(testCases, testCase{
6057 testType: serverTest,
6058 name: "Renegotiate-Server-NoExt",
6059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006060 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006061 Bugs: ProtocolBugs{
6062 NoRenegotiationInfo: true,
6063 RequireRenegotiationInfo: true,
6064 },
6065 },
6066 shouldFail: true,
6067 expectedLocalError: "renegotiation extension missing",
6068 })
6069 // The renegotiation SCSV should be sufficient for the server to echo
6070 // the extension.
6071 testCases = append(testCases, testCase{
6072 testType: serverTest,
6073 name: "Renegotiate-Server-NoExt-SCSV",
6074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006075 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006076 Bugs: ProtocolBugs{
6077 NoRenegotiationInfo: true,
6078 SendRenegotiationSCSV: true,
6079 RequireRenegotiationInfo: true,
6080 },
6081 },
6082 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006083 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006084 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006086 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006087 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006088 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006089 },
6090 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006091 renegotiate: 1,
6092 flags: []string{
6093 "-renegotiate-freely",
6094 "-expect-total-renegotiations", "1",
6095 },
David Benjamincdea40c2015-03-19 14:09:43 -04006096 })
6097 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006098 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006099 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006101 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006102 Bugs: ProtocolBugs{
6103 EmptyRenegotiationInfo: true,
6104 },
6105 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006106 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006107 shouldFail: true,
6108 expectedError: ":RENEGOTIATION_MISMATCH:",
6109 })
6110 testCases = append(testCases, testCase{
6111 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006112 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006114 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006115 Bugs: ProtocolBugs{
6116 BadRenegotiationInfo: true,
6117 },
6118 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006119 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006120 shouldFail: true,
6121 expectedError: ":RENEGOTIATION_MISMATCH:",
6122 })
6123 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006124 name: "Renegotiate-Client-Downgrade",
6125 renegotiate: 1,
6126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006127 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006128 Bugs: ProtocolBugs{
6129 NoRenegotiationInfoAfterInitial: true,
6130 },
6131 },
6132 flags: []string{"-renegotiate-freely"},
6133 shouldFail: true,
6134 expectedError: ":RENEGOTIATION_MISMATCH:",
6135 })
6136 testCases = append(testCases, testCase{
6137 name: "Renegotiate-Client-Upgrade",
6138 renegotiate: 1,
6139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006140 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006141 Bugs: ProtocolBugs{
6142 NoRenegotiationInfoInInitial: true,
6143 },
6144 },
6145 flags: []string{"-renegotiate-freely"},
6146 shouldFail: true,
6147 expectedError: ":RENEGOTIATION_MISMATCH:",
6148 })
6149 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006150 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006151 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006153 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006154 Bugs: ProtocolBugs{
6155 NoRenegotiationInfo: true,
6156 },
6157 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006158 flags: []string{
6159 "-renegotiate-freely",
6160 "-expect-total-renegotiations", "1",
6161 },
David Benjamincff0b902015-05-15 23:09:47 -04006162 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006163
6164 // Test that the server may switch ciphers on renegotiation without
6165 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006166 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006167 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006168 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006169 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006170 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006171 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006172 },
6173 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006174 flags: []string{
6175 "-renegotiate-freely",
6176 "-expect-total-renegotiations", "1",
6177 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006178 })
6179 testCases = append(testCases, testCase{
6180 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006181 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006182 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006183 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6185 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006186 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006187 flags: []string{
6188 "-renegotiate-freely",
6189 "-expect-total-renegotiations", "1",
6190 },
David Benjaminb16346b2015-04-08 19:16:58 -04006191 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006192
6193 // Test that the server may not switch versions on renegotiation.
6194 testCases = append(testCases, testCase{
6195 name: "Renegotiate-Client-SwitchVersion",
6196 config: Config{
6197 MaxVersion: VersionTLS12,
6198 // Pick a cipher which exists at both versions.
6199 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6200 Bugs: ProtocolBugs{
6201 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006202 // Avoid failing early at the record layer.
6203 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006204 },
6205 },
6206 renegotiate: 1,
6207 flags: []string{
6208 "-renegotiate-freely",
6209 "-expect-total-renegotiations", "1",
6210 },
6211 shouldFail: true,
6212 expectedError: ":WRONG_SSL_VERSION:",
6213 })
6214
David Benjaminb16346b2015-04-08 19:16:58 -04006215 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006216 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006217 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006218 config: Config{
6219 MaxVersion: VersionTLS10,
6220 Bugs: ProtocolBugs{
6221 RequireSameRenegoClientVersion: true,
6222 },
6223 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006224 flags: []string{
6225 "-renegotiate-freely",
6226 "-expect-total-renegotiations", "1",
6227 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006228 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006229 testCases = append(testCases, testCase{
6230 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006231 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006233 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006234 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6235 NextProtos: []string{"foo"},
6236 },
6237 flags: []string{
6238 "-false-start",
6239 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006240 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006241 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006242 },
6243 shimWritesFirst: true,
6244 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006245
6246 // Client-side renegotiation controls.
6247 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006248 name: "Renegotiate-Client-Forbidden-1",
6249 config: Config{
6250 MaxVersion: VersionTLS12,
6251 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006252 renegotiate: 1,
6253 shouldFail: true,
6254 expectedError: ":NO_RENEGOTIATION:",
6255 expectedLocalError: "remote error: no renegotiation",
6256 })
6257 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006258 name: "Renegotiate-Client-Once-1",
6259 config: Config{
6260 MaxVersion: VersionTLS12,
6261 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006262 renegotiate: 1,
6263 flags: []string{
6264 "-renegotiate-once",
6265 "-expect-total-renegotiations", "1",
6266 },
6267 })
6268 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006269 name: "Renegotiate-Client-Freely-1",
6270 config: Config{
6271 MaxVersion: VersionTLS12,
6272 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006273 renegotiate: 1,
6274 flags: []string{
6275 "-renegotiate-freely",
6276 "-expect-total-renegotiations", "1",
6277 },
6278 })
6279 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006280 name: "Renegotiate-Client-Once-2",
6281 config: Config{
6282 MaxVersion: VersionTLS12,
6283 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006284 renegotiate: 2,
6285 flags: []string{"-renegotiate-once"},
6286 shouldFail: true,
6287 expectedError: ":NO_RENEGOTIATION:",
6288 expectedLocalError: "remote error: no renegotiation",
6289 })
6290 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006291 name: "Renegotiate-Client-Freely-2",
6292 config: Config{
6293 MaxVersion: VersionTLS12,
6294 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006295 renegotiate: 2,
6296 flags: []string{
6297 "-renegotiate-freely",
6298 "-expect-total-renegotiations", "2",
6299 },
6300 })
Adam Langley27a0d082015-11-03 13:34:10 -08006301 testCases = append(testCases, testCase{
6302 name: "Renegotiate-Client-NoIgnore",
6303 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006304 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006305 Bugs: ProtocolBugs{
6306 SendHelloRequestBeforeEveryAppDataRecord: true,
6307 },
6308 },
6309 shouldFail: true,
6310 expectedError: ":NO_RENEGOTIATION:",
6311 })
6312 testCases = append(testCases, testCase{
6313 name: "Renegotiate-Client-Ignore",
6314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006315 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006316 Bugs: ProtocolBugs{
6317 SendHelloRequestBeforeEveryAppDataRecord: true,
6318 },
6319 },
6320 flags: []string{
6321 "-renegotiate-ignore",
6322 "-expect-total-renegotiations", "0",
6323 },
6324 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006325
David Benjamin34941c02016-10-08 11:45:31 -04006326 // Renegotiation is not allowed at SSL 3.0.
6327 testCases = append(testCases, testCase{
6328 name: "Renegotiate-Client-SSL3",
6329 config: Config{
6330 MaxVersion: VersionSSL30,
6331 },
6332 renegotiate: 1,
6333 flags: []string{
6334 "-renegotiate-freely",
6335 "-expect-total-renegotiations", "1",
6336 },
6337 shouldFail: true,
6338 expectedError: ":NO_RENEGOTIATION:",
6339 expectedLocalError: "remote error: no renegotiation",
6340 })
6341
David Benjamin397c8e62016-07-08 14:14:36 -07006342 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006343 testCases = append(testCases, testCase{
6344 name: "StrayHelloRequest",
6345 config: Config{
6346 MaxVersion: VersionTLS12,
6347 Bugs: ProtocolBugs{
6348 SendHelloRequestBeforeEveryHandshakeMessage: true,
6349 },
6350 },
6351 })
6352 testCases = append(testCases, testCase{
6353 name: "StrayHelloRequest-Packed",
6354 config: Config{
6355 MaxVersion: VersionTLS12,
6356 Bugs: ProtocolBugs{
6357 PackHandshakeFlight: true,
6358 SendHelloRequestBeforeEveryHandshakeMessage: true,
6359 },
6360 },
6361 })
6362
David Benjamin12d2c482016-07-24 10:56:51 -04006363 // Test renegotiation works if HelloRequest and server Finished come in
6364 // the same record.
6365 testCases = append(testCases, testCase{
6366 name: "Renegotiate-Client-Packed",
6367 config: Config{
6368 MaxVersion: VersionTLS12,
6369 Bugs: ProtocolBugs{
6370 PackHandshakeFlight: true,
6371 PackHelloRequestWithFinished: true,
6372 },
6373 },
6374 renegotiate: 1,
6375 flags: []string{
6376 "-renegotiate-freely",
6377 "-expect-total-renegotiations", "1",
6378 },
6379 })
6380
David Benjamin397c8e62016-07-08 14:14:36 -07006381 // Renegotiation is forbidden in TLS 1.3.
6382 testCases = append(testCases, testCase{
6383 name: "Renegotiate-Client-TLS13",
6384 config: Config{
6385 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006386 Bugs: ProtocolBugs{
6387 SendHelloRequestBeforeEveryAppDataRecord: true,
6388 },
David Benjamin397c8e62016-07-08 14:14:36 -07006389 },
David Benjamin397c8e62016-07-08 14:14:36 -07006390 flags: []string{
6391 "-renegotiate-freely",
6392 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006393 shouldFail: true,
6394 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006395 })
6396
6397 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6398 testCases = append(testCases, testCase{
6399 name: "StrayHelloRequest-TLS13",
6400 config: Config{
6401 MaxVersion: VersionTLS13,
6402 Bugs: ProtocolBugs{
6403 SendHelloRequestBeforeEveryHandshakeMessage: true,
6404 },
6405 },
6406 shouldFail: true,
6407 expectedError: ":UNEXPECTED_MESSAGE:",
6408 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006409}
6410
David Benjamin5e961c12014-11-07 01:48:35 -05006411func addDTLSReplayTests() {
6412 // Test that sequence number replays are detected.
6413 testCases = append(testCases, testCase{
6414 protocol: dtls,
6415 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006416 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006417 replayWrites: true,
6418 })
6419
David Benjamin8e6db492015-07-25 18:29:23 -04006420 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006421 // than the retransmit window.
6422 testCases = append(testCases, testCase{
6423 protocol: dtls,
6424 name: "DTLS-Replay-LargeGaps",
6425 config: Config{
6426 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006427 SequenceNumberMapping: func(in uint64) uint64 {
6428 return in * 127
6429 },
David Benjamin5e961c12014-11-07 01:48:35 -05006430 },
6431 },
David Benjamin8e6db492015-07-25 18:29:23 -04006432 messageCount: 200,
6433 replayWrites: true,
6434 })
6435
6436 // Test the incoming sequence number changing non-monotonically.
6437 testCases = append(testCases, testCase{
6438 protocol: dtls,
6439 name: "DTLS-Replay-NonMonotonic",
6440 config: Config{
6441 Bugs: ProtocolBugs{
6442 SequenceNumberMapping: func(in uint64) uint64 {
6443 return in ^ 31
6444 },
6445 },
6446 },
6447 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006448 replayWrites: true,
6449 })
6450}
6451
Nick Harper60edffd2016-06-21 15:19:24 -07006452var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006453 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006454 id signatureAlgorithm
6455 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006456}{
Nick Harper60edffd2016-06-21 15:19:24 -07006457 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6458 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6459 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6460 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006461 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006462 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6463 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6464 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006465 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6466 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6467 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006468 // Tests for key types prior to TLS 1.2.
6469 {"RSA", 0, testCertRSA},
6470 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006471}
6472
Nick Harper60edffd2016-06-21 15:19:24 -07006473const fakeSigAlg1 signatureAlgorithm = 0x2a01
6474const fakeSigAlg2 signatureAlgorithm = 0xff01
6475
6476func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006477 // Not all ciphers involve a signature. Advertise a list which gives all
6478 // versions a signing cipher.
6479 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006480 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006481 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6482 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6483 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6484 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6485 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6486 }
6487
David Benjaminca3d5452016-07-14 12:51:01 -04006488 var allAlgorithms []signatureAlgorithm
6489 for _, alg := range testSignatureAlgorithms {
6490 if alg.id != 0 {
6491 allAlgorithms = append(allAlgorithms, alg.id)
6492 }
6493 }
6494
Nick Harper60edffd2016-06-21 15:19:24 -07006495 // Make sure each signature algorithm works. Include some fake values in
6496 // the list and ensure they're ignored.
6497 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006498 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006499 if (ver.version < VersionTLS12) != (alg.id == 0) {
6500 continue
6501 }
6502
6503 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6504 // or remove it in C.
6505 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006506 continue
6507 }
Nick Harper60edffd2016-06-21 15:19:24 -07006508
David Benjamin3ef76972016-10-17 17:59:54 -04006509 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006510 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006511 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006512 shouldSignFail = true
6513 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006514 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006515 // RSA-PKCS1 does not exist in TLS 1.3.
6516 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006517 shouldSignFail = true
6518 shouldVerifyFail = true
6519 }
6520
6521 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6522 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6523 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006524 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006525
6526 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006527 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006528 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006529 }
6530 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006531 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006532 }
David Benjamin000800a2014-11-14 01:43:59 -05006533
David Benjamin1fb125c2016-07-08 18:52:12 -07006534 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006535
David Benjamin7a41d372016-07-09 11:21:54 -07006536 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006537 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006538 config: Config{
6539 MaxVersion: ver.version,
6540 ClientAuth: RequireAnyClientCert,
6541 VerifySignatureAlgorithms: []signatureAlgorithm{
6542 fakeSigAlg1,
6543 alg.id,
6544 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006545 },
David Benjamin7a41d372016-07-09 11:21:54 -07006546 },
6547 flags: []string{
6548 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6549 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6550 "-enable-all-curves",
6551 },
David Benjamin3ef76972016-10-17 17:59:54 -04006552 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006553 expectedError: signError,
6554 expectedPeerSignatureAlgorithm: alg.id,
6555 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006556
David Benjamin7a41d372016-07-09 11:21:54 -07006557 testCases = append(testCases, testCase{
6558 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006559 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006560 config: Config{
6561 MaxVersion: ver.version,
6562 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6563 SignSignatureAlgorithms: []signatureAlgorithm{
6564 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006565 },
David Benjamin7a41d372016-07-09 11:21:54 -07006566 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006567 SkipECDSACurveCheck: shouldVerifyFail,
6568 IgnoreSignatureVersionChecks: shouldVerifyFail,
6569 // Some signature algorithms may not be advertised.
6570 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006571 },
David Benjamin7a41d372016-07-09 11:21:54 -07006572 },
6573 flags: []string{
6574 "-require-any-client-certificate",
6575 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6576 "-enable-all-curves",
6577 },
David Benjamin3ef76972016-10-17 17:59:54 -04006578 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006579 expectedError: verifyError,
6580 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006581
6582 testCases = append(testCases, testCase{
6583 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006584 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006585 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006586 MaxVersion: ver.version,
6587 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006588 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006589 fakeSigAlg1,
6590 alg.id,
6591 fakeSigAlg2,
6592 },
6593 },
6594 flags: []string{
6595 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6596 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6597 "-enable-all-curves",
6598 },
David Benjamin3ef76972016-10-17 17:59:54 -04006599 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006600 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006601 expectedPeerSignatureAlgorithm: alg.id,
6602 })
6603
6604 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006605 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006606 config: Config{
6607 MaxVersion: ver.version,
6608 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006609 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006610 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006611 alg.id,
6612 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006613 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006614 SkipECDSACurveCheck: shouldVerifyFail,
6615 IgnoreSignatureVersionChecks: shouldVerifyFail,
6616 // Some signature algorithms may not be advertised.
6617 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006618 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006619 },
6620 flags: []string{
6621 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6622 "-enable-all-curves",
6623 },
David Benjamin3ef76972016-10-17 17:59:54 -04006624 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006625 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006626 })
David Benjamin5208fd42016-07-13 21:43:25 -04006627
David Benjamin3ef76972016-10-17 17:59:54 -04006628 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006629 testCases = append(testCases, testCase{
6630 testType: serverTest,
6631 name: "ClientAuth-InvalidSignature" + suffix,
6632 config: Config{
6633 MaxVersion: ver.version,
6634 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6635 SignSignatureAlgorithms: []signatureAlgorithm{
6636 alg.id,
6637 },
6638 Bugs: ProtocolBugs{
6639 InvalidSignature: true,
6640 },
6641 },
6642 flags: []string{
6643 "-require-any-client-certificate",
6644 "-enable-all-curves",
6645 },
6646 shouldFail: true,
6647 expectedError: ":BAD_SIGNATURE:",
6648 })
6649
6650 testCases = append(testCases, testCase{
6651 name: "ServerAuth-InvalidSignature" + suffix,
6652 config: Config{
6653 MaxVersion: ver.version,
6654 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6655 CipherSuites: signingCiphers,
6656 SignSignatureAlgorithms: []signatureAlgorithm{
6657 alg.id,
6658 },
6659 Bugs: ProtocolBugs{
6660 InvalidSignature: true,
6661 },
6662 },
6663 flags: []string{"-enable-all-curves"},
6664 shouldFail: true,
6665 expectedError: ":BAD_SIGNATURE:",
6666 })
6667 }
David Benjaminca3d5452016-07-14 12:51:01 -04006668
David Benjamin3ef76972016-10-17 17:59:54 -04006669 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006670 testCases = append(testCases, testCase{
6671 name: "ClientAuth-Sign-Negotiate" + suffix,
6672 config: Config{
6673 MaxVersion: ver.version,
6674 ClientAuth: RequireAnyClientCert,
6675 VerifySignatureAlgorithms: allAlgorithms,
6676 },
6677 flags: []string{
6678 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6679 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6680 "-enable-all-curves",
6681 "-signing-prefs", strconv.Itoa(int(alg.id)),
6682 },
6683 expectedPeerSignatureAlgorithm: alg.id,
6684 })
6685
6686 testCases = append(testCases, testCase{
6687 testType: serverTest,
6688 name: "ServerAuth-Sign-Negotiate" + suffix,
6689 config: Config{
6690 MaxVersion: ver.version,
6691 CipherSuites: signingCiphers,
6692 VerifySignatureAlgorithms: allAlgorithms,
6693 },
6694 flags: []string{
6695 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6696 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6697 "-enable-all-curves",
6698 "-signing-prefs", strconv.Itoa(int(alg.id)),
6699 },
6700 expectedPeerSignatureAlgorithm: alg.id,
6701 })
6702 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006703 }
David Benjamin000800a2014-11-14 01:43:59 -05006704 }
6705
Nick Harper60edffd2016-06-21 15:19:24 -07006706 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006707 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006708 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006709 config: Config{
6710 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006711 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006712 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006713 signatureECDSAWithP521AndSHA512,
6714 signatureRSAPKCS1WithSHA384,
6715 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006716 },
6717 },
6718 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006719 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6720 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006721 },
Nick Harper60edffd2016-06-21 15:19:24 -07006722 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006723 })
6724
6725 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006726 name: "ClientAuth-SignatureType-TLS13",
6727 config: Config{
6728 ClientAuth: RequireAnyClientCert,
6729 MaxVersion: VersionTLS13,
6730 VerifySignatureAlgorithms: []signatureAlgorithm{
6731 signatureECDSAWithP521AndSHA512,
6732 signatureRSAPKCS1WithSHA384,
6733 signatureRSAPSSWithSHA384,
6734 signatureECDSAWithSHA1,
6735 },
6736 },
6737 flags: []string{
6738 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6739 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6740 },
6741 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6742 })
6743
6744 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006745 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006746 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006748 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006749 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006750 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006751 signatureECDSAWithP521AndSHA512,
6752 signatureRSAPKCS1WithSHA384,
6753 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006754 },
6755 },
Nick Harper60edffd2016-06-21 15:19:24 -07006756 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006757 })
6758
Steven Valdez143e8b32016-07-11 13:19:03 -04006759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: "ServerAuth-SignatureType-TLS13",
6762 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006763 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006764 VerifySignatureAlgorithms: []signatureAlgorithm{
6765 signatureECDSAWithP521AndSHA512,
6766 signatureRSAPKCS1WithSHA384,
6767 signatureRSAPSSWithSHA384,
6768 signatureECDSAWithSHA1,
6769 },
6770 },
6771 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6772 })
6773
David Benjamina95e9f32016-07-08 16:28:04 -07006774 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "Verify-ClientAuth-SignatureType",
6778 config: Config{
6779 MaxVersion: VersionTLS12,
6780 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006781 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006782 signatureRSAPKCS1WithSHA256,
6783 },
6784 Bugs: ProtocolBugs{
6785 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6786 },
6787 },
6788 flags: []string{
6789 "-require-any-client-certificate",
6790 },
6791 shouldFail: true,
6792 expectedError: ":WRONG_SIGNATURE_TYPE:",
6793 })
6794
6795 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006796 testType: serverTest,
6797 name: "Verify-ClientAuth-SignatureType-TLS13",
6798 config: Config{
6799 MaxVersion: VersionTLS13,
6800 Certificates: []Certificate{rsaCertificate},
6801 SignSignatureAlgorithms: []signatureAlgorithm{
6802 signatureRSAPSSWithSHA256,
6803 },
6804 Bugs: ProtocolBugs{
6805 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6806 },
6807 },
6808 flags: []string{
6809 "-require-any-client-certificate",
6810 },
6811 shouldFail: true,
6812 expectedError: ":WRONG_SIGNATURE_TYPE:",
6813 })
6814
6815 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006816 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006817 config: Config{
6818 MaxVersion: VersionTLS12,
6819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006820 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006821 signatureRSAPKCS1WithSHA256,
6822 },
6823 Bugs: ProtocolBugs{
6824 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6825 },
6826 },
6827 shouldFail: true,
6828 expectedError: ":WRONG_SIGNATURE_TYPE:",
6829 })
6830
Steven Valdez143e8b32016-07-11 13:19:03 -04006831 testCases = append(testCases, testCase{
6832 name: "Verify-ServerAuth-SignatureType-TLS13",
6833 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006834 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006835 SignSignatureAlgorithms: []signatureAlgorithm{
6836 signatureRSAPSSWithSHA256,
6837 },
6838 Bugs: ProtocolBugs{
6839 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6840 },
6841 },
6842 shouldFail: true,
6843 expectedError: ":WRONG_SIGNATURE_TYPE:",
6844 })
6845
David Benjamin51dd7d62016-07-08 16:07:01 -07006846 // Test that, if the list is missing, the peer falls back to SHA-1 in
6847 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006848 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006849 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006851 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006852 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006853 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006854 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006855 },
6856 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006857 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006858 },
6859 },
6860 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006861 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6862 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006863 },
6864 })
6865
6866 testCases = append(testCases, testCase{
6867 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006868 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006869 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006870 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006871 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006872 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006873 },
6874 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006875 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006876 },
6877 },
David Benjaminee32bea2016-08-17 13:36:44 -04006878 flags: []string{
6879 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6880 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6881 },
6882 })
6883
6884 testCases = append(testCases, testCase{
6885 name: "ClientAuth-SHA1-Fallback-ECDSA",
6886 config: Config{
6887 MaxVersion: VersionTLS12,
6888 ClientAuth: RequireAnyClientCert,
6889 VerifySignatureAlgorithms: []signatureAlgorithm{
6890 signatureECDSAWithSHA1,
6891 },
6892 Bugs: ProtocolBugs{
6893 NoSignatureAlgorithms: true,
6894 },
6895 },
6896 flags: []string{
6897 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6898 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6899 },
6900 })
6901
6902 testCases = append(testCases, testCase{
6903 testType: serverTest,
6904 name: "ServerAuth-SHA1-Fallback-ECDSA",
6905 config: Config{
6906 MaxVersion: VersionTLS12,
6907 VerifySignatureAlgorithms: []signatureAlgorithm{
6908 signatureECDSAWithSHA1,
6909 },
6910 Bugs: ProtocolBugs{
6911 NoSignatureAlgorithms: true,
6912 },
6913 },
6914 flags: []string{
6915 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6916 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6917 },
David Benjamin000800a2014-11-14 01:43:59 -05006918 })
David Benjamin72dc7832015-03-16 17:49:43 -04006919
David Benjamin51dd7d62016-07-08 16:07:01 -07006920 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006921 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006922 config: Config{
6923 MaxVersion: VersionTLS13,
6924 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006925 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006926 signatureRSAPKCS1WithSHA1,
6927 },
6928 Bugs: ProtocolBugs{
6929 NoSignatureAlgorithms: true,
6930 },
6931 },
6932 flags: []string{
6933 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6934 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6935 },
David Benjamin48901652016-08-01 12:12:47 -04006936 shouldFail: true,
6937 // An empty CertificateRequest signature algorithm list is a
6938 // syntax error in TLS 1.3.
6939 expectedError: ":DECODE_ERROR:",
6940 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006941 })
6942
6943 testCases = append(testCases, testCase{
6944 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006945 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006946 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006947 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006948 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006949 signatureRSAPKCS1WithSHA1,
6950 },
6951 Bugs: ProtocolBugs{
6952 NoSignatureAlgorithms: true,
6953 },
6954 },
6955 shouldFail: true,
6956 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6957 })
6958
David Benjaminb62d2872016-07-18 14:55:02 +02006959 // Test that hash preferences are enforced. BoringSSL does not implement
6960 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006961 testCases = append(testCases, testCase{
6962 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006963 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006965 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006966 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006967 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006968 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006969 },
6970 Bugs: ProtocolBugs{
6971 IgnorePeerSignatureAlgorithmPreferences: true,
6972 },
6973 },
6974 flags: []string{"-require-any-client-certificate"},
6975 shouldFail: true,
6976 expectedError: ":WRONG_SIGNATURE_TYPE:",
6977 })
6978
6979 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006980 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006982 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006983 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006984 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006985 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006986 },
6987 Bugs: ProtocolBugs{
6988 IgnorePeerSignatureAlgorithmPreferences: true,
6989 },
6990 },
6991 shouldFail: true,
6992 expectedError: ":WRONG_SIGNATURE_TYPE:",
6993 })
David Benjaminb62d2872016-07-18 14:55:02 +02006994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "ClientAuth-Enforced-TLS13",
6997 config: Config{
6998 MaxVersion: VersionTLS13,
6999 Certificates: []Certificate{rsaCertificate},
7000 SignSignatureAlgorithms: []signatureAlgorithm{
7001 signatureRSAPKCS1WithMD5,
7002 },
7003 Bugs: ProtocolBugs{
7004 IgnorePeerSignatureAlgorithmPreferences: true,
7005 IgnoreSignatureVersionChecks: true,
7006 },
7007 },
7008 flags: []string{"-require-any-client-certificate"},
7009 shouldFail: true,
7010 expectedError: ":WRONG_SIGNATURE_TYPE:",
7011 })
7012
7013 testCases = append(testCases, testCase{
7014 name: "ServerAuth-Enforced-TLS13",
7015 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007016 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007017 SignSignatureAlgorithms: []signatureAlgorithm{
7018 signatureRSAPKCS1WithMD5,
7019 },
7020 Bugs: ProtocolBugs{
7021 IgnorePeerSignatureAlgorithmPreferences: true,
7022 IgnoreSignatureVersionChecks: true,
7023 },
7024 },
7025 shouldFail: true,
7026 expectedError: ":WRONG_SIGNATURE_TYPE:",
7027 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007028
7029 // Test that the agreed upon digest respects the client preferences and
7030 // the server digests.
7031 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007032 name: "NoCommonAlgorithms-Digests",
7033 config: Config{
7034 MaxVersion: VersionTLS12,
7035 ClientAuth: RequireAnyClientCert,
7036 VerifySignatureAlgorithms: []signatureAlgorithm{
7037 signatureRSAPKCS1WithSHA512,
7038 signatureRSAPKCS1WithSHA1,
7039 },
7040 },
7041 flags: []string{
7042 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7043 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7044 "-digest-prefs", "SHA256",
7045 },
7046 shouldFail: true,
7047 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7048 })
7049 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007050 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007052 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007053 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007054 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007055 signatureRSAPKCS1WithSHA512,
7056 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007057 },
7058 },
7059 flags: []string{
7060 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7061 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007062 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007063 },
David Benjaminca3d5452016-07-14 12:51:01 -04007064 shouldFail: true,
7065 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7066 })
7067 testCases = append(testCases, testCase{
7068 name: "NoCommonAlgorithms-TLS13",
7069 config: Config{
7070 MaxVersion: VersionTLS13,
7071 ClientAuth: RequireAnyClientCert,
7072 VerifySignatureAlgorithms: []signatureAlgorithm{
7073 signatureRSAPSSWithSHA512,
7074 signatureRSAPSSWithSHA384,
7075 },
7076 },
7077 flags: []string{
7078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7080 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7081 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007082 shouldFail: true,
7083 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007084 })
7085 testCases = append(testCases, testCase{
7086 name: "Agree-Digest-SHA256",
7087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007088 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007089 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007090 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007091 signatureRSAPKCS1WithSHA1,
7092 signatureRSAPKCS1WithSHA256,
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", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007099 },
Nick Harper60edffd2016-06-21 15:19:24 -07007100 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007101 })
7102 testCases = append(testCases, testCase{
7103 name: "Agree-Digest-SHA1",
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 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007109 },
7110 },
7111 flags: []string{
7112 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7113 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007114 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007115 },
Nick Harper60edffd2016-06-21 15:19:24 -07007116 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007117 })
7118 testCases = append(testCases, testCase{
7119 name: "Agree-Digest-Default",
7120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007121 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007122 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007123 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007124 signatureRSAPKCS1WithSHA256,
7125 signatureECDSAWithP256AndSHA256,
7126 signatureRSAPKCS1WithSHA1,
7127 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007128 },
7129 },
7130 flags: []string{
7131 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7132 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7133 },
Nick Harper60edffd2016-06-21 15:19:24 -07007134 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007135 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007136
David Benjaminca3d5452016-07-14 12:51:01 -04007137 // Test that the signing preference list may include extra algorithms
7138 // without negotiation problems.
7139 testCases = append(testCases, testCase{
7140 testType: serverTest,
7141 name: "FilterExtraAlgorithms",
7142 config: Config{
7143 MaxVersion: VersionTLS12,
7144 VerifySignatureAlgorithms: []signatureAlgorithm{
7145 signatureRSAPKCS1WithSHA256,
7146 },
7147 },
7148 flags: []string{
7149 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7150 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7151 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7152 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7153 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7154 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7155 },
7156 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7157 })
7158
David Benjamin4c3ddf72016-06-29 18:13:53 -04007159 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7160 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007161 testCases = append(testCases, testCase{
7162 name: "CheckLeafCurve",
7163 config: Config{
7164 MaxVersion: VersionTLS12,
7165 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007166 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007167 },
7168 flags: []string{"-p384-only"},
7169 shouldFail: true,
7170 expectedError: ":BAD_ECC_CERT:",
7171 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007172
7173 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7174 testCases = append(testCases, testCase{
7175 name: "CheckLeafCurve-TLS13",
7176 config: Config{
7177 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007178 Certificates: []Certificate{ecdsaP256Certificate},
7179 },
7180 flags: []string{"-p384-only"},
7181 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007182
7183 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7184 testCases = append(testCases, testCase{
7185 name: "ECDSACurveMismatch-Verify-TLS12",
7186 config: Config{
7187 MaxVersion: VersionTLS12,
7188 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7189 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007190 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007191 signatureECDSAWithP384AndSHA384,
7192 },
7193 },
7194 })
7195
7196 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7197 testCases = append(testCases, testCase{
7198 name: "ECDSACurveMismatch-Verify-TLS13",
7199 config: Config{
7200 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007201 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007202 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007203 signatureECDSAWithP384AndSHA384,
7204 },
7205 Bugs: ProtocolBugs{
7206 SkipECDSACurveCheck: true,
7207 },
7208 },
7209 shouldFail: true,
7210 expectedError: ":WRONG_SIGNATURE_TYPE:",
7211 })
7212
7213 // Signature algorithm selection in TLS 1.3 should take the curve into
7214 // account.
7215 testCases = append(testCases, testCase{
7216 testType: serverTest,
7217 name: "ECDSACurveMismatch-Sign-TLS13",
7218 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007219 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007220 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007221 signatureECDSAWithP384AndSHA384,
7222 signatureECDSAWithP256AndSHA256,
7223 },
7224 },
7225 flags: []string{
7226 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7227 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7228 },
7229 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7230 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007231
7232 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7233 // server does not attempt to sign in that case.
7234 testCases = append(testCases, testCase{
7235 testType: serverTest,
7236 name: "RSA-PSS-Large",
7237 config: Config{
7238 MaxVersion: VersionTLS13,
7239 VerifySignatureAlgorithms: []signatureAlgorithm{
7240 signatureRSAPSSWithSHA512,
7241 },
7242 },
7243 flags: []string{
7244 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7245 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7246 },
7247 shouldFail: true,
7248 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7249 })
David Benjamin57e929f2016-08-30 00:30:38 -04007250
7251 // Test that RSA-PSS is enabled by default for TLS 1.2.
7252 testCases = append(testCases, testCase{
7253 testType: clientTest,
7254 name: "RSA-PSS-Default-Verify",
7255 config: Config{
7256 MaxVersion: VersionTLS12,
7257 SignSignatureAlgorithms: []signatureAlgorithm{
7258 signatureRSAPSSWithSHA256,
7259 },
7260 },
7261 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7262 })
7263
7264 testCases = append(testCases, testCase{
7265 testType: serverTest,
7266 name: "RSA-PSS-Default-Sign",
7267 config: Config{
7268 MaxVersion: VersionTLS12,
7269 VerifySignatureAlgorithms: []signatureAlgorithm{
7270 signatureRSAPSSWithSHA256,
7271 },
7272 },
7273 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7274 })
David Benjamin000800a2014-11-14 01:43:59 -05007275}
7276
David Benjamin83f90402015-01-27 01:09:43 -05007277// timeouts is the retransmit schedule for BoringSSL. It doubles and
7278// caps at 60 seconds. On the 13th timeout, it gives up.
7279var timeouts = []time.Duration{
7280 1 * time.Second,
7281 2 * time.Second,
7282 4 * time.Second,
7283 8 * time.Second,
7284 16 * time.Second,
7285 32 * time.Second,
7286 60 * time.Second,
7287 60 * time.Second,
7288 60 * time.Second,
7289 60 * time.Second,
7290 60 * time.Second,
7291 60 * time.Second,
7292 60 * time.Second,
7293}
7294
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007295// shortTimeouts is an alternate set of timeouts which would occur if the
7296// initial timeout duration was set to 250ms.
7297var shortTimeouts = []time.Duration{
7298 250 * time.Millisecond,
7299 500 * time.Millisecond,
7300 1 * time.Second,
7301 2 * time.Second,
7302 4 * time.Second,
7303 8 * time.Second,
7304 16 * time.Second,
7305 32 * time.Second,
7306 60 * time.Second,
7307 60 * time.Second,
7308 60 * time.Second,
7309 60 * time.Second,
7310 60 * time.Second,
7311}
7312
David Benjamin83f90402015-01-27 01:09:43 -05007313func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007314 // These tests work by coordinating some behavior on both the shim and
7315 // the runner.
7316 //
7317 // TimeoutSchedule configures the runner to send a series of timeout
7318 // opcodes to the shim (see packetAdaptor) immediately before reading
7319 // each peer handshake flight N. The timeout opcode both simulates a
7320 // timeout in the shim and acts as a synchronization point to help the
7321 // runner bracket each handshake flight.
7322 //
7323 // We assume the shim does not read from the channel eagerly. It must
7324 // first wait until it has sent flight N and is ready to receive
7325 // handshake flight N+1. At this point, it will process the timeout
7326 // opcode. It must then immediately respond with a timeout ACK and act
7327 // as if the shim was idle for the specified amount of time.
7328 //
7329 // The runner then drops all packets received before the ACK and
7330 // continues waiting for flight N. This ordering results in one attempt
7331 // at sending flight N to be dropped. For the test to complete, the
7332 // shim must send flight N again, testing that the shim implements DTLS
7333 // retransmit on a timeout.
7334
Steven Valdez143e8b32016-07-11 13:19:03 -04007335 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007336 // likely be more epochs to cross and the final message's retransmit may
7337 // be more complex.
7338
David Benjamin585d7a42016-06-02 14:58:00 -04007339 for _, async := range []bool{true, false} {
7340 var tests []testCase
7341
7342 // Test that this is indeed the timeout schedule. Stress all
7343 // four patterns of handshake.
7344 for i := 1; i < len(timeouts); i++ {
7345 number := strconv.Itoa(i)
7346 tests = append(tests, testCase{
7347 protocol: dtls,
7348 name: "DTLS-Retransmit-Client-" + number,
7349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007350 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007351 Bugs: ProtocolBugs{
7352 TimeoutSchedule: timeouts[:i],
7353 },
7354 },
7355 resumeSession: true,
7356 })
7357 tests = append(tests, testCase{
7358 protocol: dtls,
7359 testType: serverTest,
7360 name: "DTLS-Retransmit-Server-" + number,
7361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007362 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007363 Bugs: ProtocolBugs{
7364 TimeoutSchedule: timeouts[:i],
7365 },
7366 },
7367 resumeSession: true,
7368 })
7369 }
7370
7371 // Test that exceeding the timeout schedule hits a read
7372 // timeout.
7373 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007374 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007375 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007377 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007378 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007379 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007380 },
7381 },
7382 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007383 shouldFail: true,
7384 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007385 })
David Benjamin585d7a42016-06-02 14:58:00 -04007386
7387 if async {
7388 // Test that timeout handling has a fudge factor, due to API
7389 // problems.
7390 tests = append(tests, testCase{
7391 protocol: dtls,
7392 name: "DTLS-Retransmit-Fudge",
7393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007394 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007395 Bugs: ProtocolBugs{
7396 TimeoutSchedule: []time.Duration{
7397 timeouts[0] - 10*time.Millisecond,
7398 },
7399 },
7400 },
7401 resumeSession: true,
7402 })
7403 }
7404
7405 // Test that the final Finished retransmitting isn't
7406 // duplicated if the peer badly fragments everything.
7407 tests = append(tests, testCase{
7408 testType: serverTest,
7409 protocol: dtls,
7410 name: "DTLS-Retransmit-Fragmented",
7411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007412 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007413 Bugs: ProtocolBugs{
7414 TimeoutSchedule: []time.Duration{timeouts[0]},
7415 MaxHandshakeRecordLength: 2,
7416 },
7417 },
7418 })
7419
7420 // Test the timeout schedule when a shorter initial timeout duration is set.
7421 tests = append(tests, testCase{
7422 protocol: dtls,
7423 name: "DTLS-Retransmit-Short-Client",
7424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007425 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007426 Bugs: ProtocolBugs{
7427 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7428 },
7429 },
7430 resumeSession: true,
7431 flags: []string{"-initial-timeout-duration-ms", "250"},
7432 })
7433 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007434 protocol: dtls,
7435 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007436 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007438 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007439 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007440 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007441 },
7442 },
7443 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007444 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007445 })
David Benjamin585d7a42016-06-02 14:58:00 -04007446
7447 for _, test := range tests {
7448 if async {
7449 test.name += "-Async"
7450 test.flags = append(test.flags, "-async")
7451 }
7452
7453 testCases = append(testCases, test)
7454 }
David Benjamin83f90402015-01-27 01:09:43 -05007455 }
David Benjamin83f90402015-01-27 01:09:43 -05007456}
7457
David Benjaminc565ebb2015-04-03 04:06:36 -04007458func addExportKeyingMaterialTests() {
7459 for _, vers := range tlsVersions {
7460 if vers.version == VersionSSL30 {
7461 continue
7462 }
7463 testCases = append(testCases, testCase{
7464 name: "ExportKeyingMaterial-" + vers.name,
7465 config: Config{
7466 MaxVersion: vers.version,
7467 },
7468 exportKeyingMaterial: 1024,
7469 exportLabel: "label",
7470 exportContext: "context",
7471 useExportContext: true,
7472 })
7473 testCases = append(testCases, testCase{
7474 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7475 config: Config{
7476 MaxVersion: vers.version,
7477 },
7478 exportKeyingMaterial: 1024,
7479 })
7480 testCases = append(testCases, testCase{
7481 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7482 config: Config{
7483 MaxVersion: vers.version,
7484 },
7485 exportKeyingMaterial: 1024,
7486 useExportContext: true,
7487 })
7488 testCases = append(testCases, testCase{
7489 name: "ExportKeyingMaterial-Small-" + vers.name,
7490 config: Config{
7491 MaxVersion: vers.version,
7492 },
7493 exportKeyingMaterial: 1,
7494 exportLabel: "label",
7495 exportContext: "context",
7496 useExportContext: true,
7497 })
7498 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007499
David Benjaminc565ebb2015-04-03 04:06:36 -04007500 testCases = append(testCases, testCase{
7501 name: "ExportKeyingMaterial-SSL3",
7502 config: Config{
7503 MaxVersion: VersionSSL30,
7504 },
7505 exportKeyingMaterial: 1024,
7506 exportLabel: "label",
7507 exportContext: "context",
7508 useExportContext: true,
7509 shouldFail: true,
7510 expectedError: "failed to export keying material",
7511 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007512
7513 // Exporters work during a False Start.
7514 testCases = append(testCases, testCase{
7515 name: "ExportKeyingMaterial-FalseStart",
7516 config: Config{
7517 MaxVersion: VersionTLS12,
7518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7519 NextProtos: []string{"foo"},
7520 Bugs: ProtocolBugs{
7521 ExpectFalseStart: true,
7522 },
7523 },
7524 flags: []string{
7525 "-false-start",
7526 "-advertise-alpn", "\x03foo",
7527 },
7528 shimWritesFirst: true,
7529 exportKeyingMaterial: 1024,
7530 exportLabel: "label",
7531 exportContext: "context",
7532 useExportContext: true,
7533 })
7534
7535 // Exporters do not work in the middle of a renegotiation. Test this by
7536 // triggering the exporter after every SSL_read call and configuring the
7537 // shim to run asynchronously.
7538 testCases = append(testCases, testCase{
7539 name: "ExportKeyingMaterial-Renegotiate",
7540 config: Config{
7541 MaxVersion: VersionTLS12,
7542 },
7543 renegotiate: 1,
7544 flags: []string{
7545 "-async",
7546 "-use-exporter-between-reads",
7547 "-renegotiate-freely",
7548 "-expect-total-renegotiations", "1",
7549 },
7550 shouldFail: true,
7551 expectedError: "failed to export keying material",
7552 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007553}
7554
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007555func addTLSUniqueTests() {
7556 for _, isClient := range []bool{false, true} {
7557 for _, isResumption := range []bool{false, true} {
7558 for _, hasEMS := range []bool{false, true} {
7559 var suffix string
7560 if isResumption {
7561 suffix = "Resume-"
7562 } else {
7563 suffix = "Full-"
7564 }
7565
7566 if hasEMS {
7567 suffix += "EMS-"
7568 } else {
7569 suffix += "NoEMS-"
7570 }
7571
7572 if isClient {
7573 suffix += "Client"
7574 } else {
7575 suffix += "Server"
7576 }
7577
7578 test := testCase{
7579 name: "TLSUnique-" + suffix,
7580 testTLSUnique: true,
7581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007582 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007583 Bugs: ProtocolBugs{
7584 NoExtendedMasterSecret: !hasEMS,
7585 },
7586 },
7587 }
7588
7589 if isResumption {
7590 test.resumeSession = true
7591 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007592 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007593 Bugs: ProtocolBugs{
7594 NoExtendedMasterSecret: !hasEMS,
7595 },
7596 }
7597 }
7598
7599 if isResumption && !hasEMS {
7600 test.shouldFail = true
7601 test.expectedError = "failed to get tls-unique"
7602 }
7603
7604 testCases = append(testCases, test)
7605 }
7606 }
7607 }
7608}
7609
Adam Langley09505632015-07-30 18:10:13 -07007610func addCustomExtensionTests() {
7611 expectedContents := "custom extension"
7612 emptyString := ""
7613
7614 for _, isClient := range []bool{false, true} {
7615 suffix := "Server"
7616 flag := "-enable-server-custom-extension"
7617 testType := serverTest
7618 if isClient {
7619 suffix = "Client"
7620 flag = "-enable-client-custom-extension"
7621 testType = clientTest
7622 }
7623
7624 testCases = append(testCases, testCase{
7625 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007626 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007628 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007629 Bugs: ProtocolBugs{
7630 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007631 ExpectedCustomExtension: &expectedContents,
7632 },
7633 },
7634 flags: []string{flag},
7635 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007636 testCases = append(testCases, testCase{
7637 testType: testType,
7638 name: "CustomExtensions-" + suffix + "-TLS13",
7639 config: Config{
7640 MaxVersion: VersionTLS13,
7641 Bugs: ProtocolBugs{
7642 CustomExtension: expectedContents,
7643 ExpectedCustomExtension: &expectedContents,
7644 },
7645 },
7646 flags: []string{flag},
7647 })
Adam Langley09505632015-07-30 18:10:13 -07007648
7649 // If the parse callback fails, the handshake should also fail.
7650 testCases = append(testCases, testCase{
7651 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007652 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007653 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007654 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007655 Bugs: ProtocolBugs{
7656 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007657 ExpectedCustomExtension: &expectedContents,
7658 },
7659 },
David Benjamin399e7c92015-07-30 23:01:27 -04007660 flags: []string{flag},
7661 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007662 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7663 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007664 testCases = append(testCases, testCase{
7665 testType: testType,
7666 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7667 config: Config{
7668 MaxVersion: VersionTLS13,
7669 Bugs: ProtocolBugs{
7670 CustomExtension: expectedContents + "foo",
7671 ExpectedCustomExtension: &expectedContents,
7672 },
7673 },
7674 flags: []string{flag},
7675 shouldFail: true,
7676 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7677 })
Adam Langley09505632015-07-30 18:10:13 -07007678
7679 // If the add callback fails, the handshake should also fail.
7680 testCases = append(testCases, testCase{
7681 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007682 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007684 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007685 Bugs: ProtocolBugs{
7686 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007687 ExpectedCustomExtension: &expectedContents,
7688 },
7689 },
David Benjamin399e7c92015-07-30 23:01:27 -04007690 flags: []string{flag, "-custom-extension-fail-add"},
7691 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007692 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7693 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007694 testCases = append(testCases, testCase{
7695 testType: testType,
7696 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7697 config: Config{
7698 MaxVersion: VersionTLS13,
7699 Bugs: ProtocolBugs{
7700 CustomExtension: expectedContents,
7701 ExpectedCustomExtension: &expectedContents,
7702 },
7703 },
7704 flags: []string{flag, "-custom-extension-fail-add"},
7705 shouldFail: true,
7706 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7707 })
Adam Langley09505632015-07-30 18:10:13 -07007708
7709 // If the add callback returns zero, no extension should be
7710 // added.
7711 skipCustomExtension := expectedContents
7712 if isClient {
7713 // For the case where the client skips sending the
7714 // custom extension, the server must not “echo” it.
7715 skipCustomExtension = ""
7716 }
7717 testCases = append(testCases, testCase{
7718 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007719 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007721 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007722 Bugs: ProtocolBugs{
7723 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007724 ExpectedCustomExtension: &emptyString,
7725 },
7726 },
7727 flags: []string{flag, "-custom-extension-skip"},
7728 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007729 testCases = append(testCases, testCase{
7730 testType: testType,
7731 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7732 config: Config{
7733 MaxVersion: VersionTLS13,
7734 Bugs: ProtocolBugs{
7735 CustomExtension: skipCustomExtension,
7736 ExpectedCustomExtension: &emptyString,
7737 },
7738 },
7739 flags: []string{flag, "-custom-extension-skip"},
7740 })
Adam Langley09505632015-07-30 18:10:13 -07007741 }
7742
7743 // The custom extension add callback should not be called if the client
7744 // doesn't send the extension.
7745 testCases = append(testCases, testCase{
7746 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007747 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007749 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007750 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007751 ExpectedCustomExtension: &emptyString,
7752 },
7753 },
7754 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7755 })
Adam Langley2deb9842015-08-07 11:15:37 -07007756
Steven Valdez143e8b32016-07-11 13:19:03 -04007757 testCases = append(testCases, testCase{
7758 testType: serverTest,
7759 name: "CustomExtensions-NotCalled-Server-TLS13",
7760 config: Config{
7761 MaxVersion: VersionTLS13,
7762 Bugs: ProtocolBugs{
7763 ExpectedCustomExtension: &emptyString,
7764 },
7765 },
7766 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7767 })
7768
Adam Langley2deb9842015-08-07 11:15:37 -07007769 // Test an unknown extension from the server.
7770 testCases = append(testCases, testCase{
7771 testType: clientTest,
7772 name: "UnknownExtension-Client",
7773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007774 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007775 Bugs: ProtocolBugs{
7776 CustomExtension: expectedContents,
7777 },
7778 },
David Benjamin0c40a962016-08-01 12:05:50 -04007779 shouldFail: true,
7780 expectedError: ":UNEXPECTED_EXTENSION:",
7781 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007782 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007783 testCases = append(testCases, testCase{
7784 testType: clientTest,
7785 name: "UnknownExtension-Client-TLS13",
7786 config: Config{
7787 MaxVersion: VersionTLS13,
7788 Bugs: ProtocolBugs{
7789 CustomExtension: expectedContents,
7790 },
7791 },
David Benjamin0c40a962016-08-01 12:05:50 -04007792 shouldFail: true,
7793 expectedError: ":UNEXPECTED_EXTENSION:",
7794 expectedLocalError: "remote error: unsupported extension",
7795 })
David Benjamin490469f2016-10-05 22:44:38 -04007796 testCases = append(testCases, testCase{
7797 testType: clientTest,
7798 name: "UnknownUnencryptedExtension-Client-TLS13",
7799 config: Config{
7800 MaxVersion: VersionTLS13,
7801 Bugs: ProtocolBugs{
7802 CustomUnencryptedExtension: expectedContents,
7803 },
7804 },
7805 shouldFail: true,
7806 expectedError: ":UNEXPECTED_EXTENSION:",
7807 // The shim must send an alert, but alerts at this point do not
7808 // get successfully decrypted by the runner.
7809 expectedLocalError: "local error: bad record MAC",
7810 })
7811 testCases = append(testCases, testCase{
7812 testType: clientTest,
7813 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7814 config: Config{
7815 MaxVersion: VersionTLS13,
7816 Bugs: ProtocolBugs{
7817 SendUnencryptedALPN: "foo",
7818 },
7819 },
7820 flags: []string{
7821 "-advertise-alpn", "\x03foo\x03bar",
7822 },
7823 shouldFail: true,
7824 expectedError: ":UNEXPECTED_EXTENSION:",
7825 // The shim must send an alert, but alerts at this point do not
7826 // get successfully decrypted by the runner.
7827 expectedLocalError: "local error: bad record MAC",
7828 })
David Benjamin0c40a962016-08-01 12:05:50 -04007829
7830 // Test a known but unoffered extension from the server.
7831 testCases = append(testCases, testCase{
7832 testType: clientTest,
7833 name: "UnofferedExtension-Client",
7834 config: Config{
7835 MaxVersion: VersionTLS12,
7836 Bugs: ProtocolBugs{
7837 SendALPN: "alpn",
7838 },
7839 },
7840 shouldFail: true,
7841 expectedError: ":UNEXPECTED_EXTENSION:",
7842 expectedLocalError: "remote error: unsupported extension",
7843 })
7844 testCases = append(testCases, testCase{
7845 testType: clientTest,
7846 name: "UnofferedExtension-Client-TLS13",
7847 config: Config{
7848 MaxVersion: VersionTLS13,
7849 Bugs: ProtocolBugs{
7850 SendALPN: "alpn",
7851 },
7852 },
7853 shouldFail: true,
7854 expectedError: ":UNEXPECTED_EXTENSION:",
7855 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007856 })
Adam Langley09505632015-07-30 18:10:13 -07007857}
7858
David Benjaminb36a3952015-12-01 18:53:13 -05007859func addRSAClientKeyExchangeTests() {
7860 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7861 testCases = append(testCases, testCase{
7862 testType: serverTest,
7863 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7864 config: Config{
7865 // Ensure the ClientHello version and final
7866 // version are different, to detect if the
7867 // server uses the wrong one.
7868 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007869 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007870 Bugs: ProtocolBugs{
7871 BadRSAClientKeyExchange: bad,
7872 },
7873 },
7874 shouldFail: true,
7875 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7876 })
7877 }
David Benjamine63d9d72016-09-19 18:27:34 -04007878
7879 // The server must compare whatever was in ClientHello.version for the
7880 // RSA premaster.
7881 testCases = append(testCases, testCase{
7882 testType: serverTest,
7883 name: "SendClientVersion-RSA",
7884 config: Config{
7885 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7886 Bugs: ProtocolBugs{
7887 SendClientVersion: 0x1234,
7888 },
7889 },
7890 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7891 })
David Benjaminb36a3952015-12-01 18:53:13 -05007892}
7893
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007894var testCurves = []struct {
7895 name string
7896 id CurveID
7897}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007898 {"P-256", CurveP256},
7899 {"P-384", CurveP384},
7900 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007901 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007902}
7903
Steven Valdez5440fe02016-07-18 12:40:30 -04007904const bogusCurve = 0x1234
7905
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007906func addCurveTests() {
7907 for _, curve := range testCurves {
7908 testCases = append(testCases, testCase{
7909 name: "CurveTest-Client-" + curve.name,
7910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007911 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7913 CurvePreferences: []CurveID{curve.id},
7914 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007915 flags: []string{
7916 "-enable-all-curves",
7917 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7918 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007919 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007920 })
7921 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007922 name: "CurveTest-Client-" + curve.name + "-TLS13",
7923 config: Config{
7924 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007925 CurvePreferences: []CurveID{curve.id},
7926 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007927 flags: []string{
7928 "-enable-all-curves",
7929 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7930 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007931 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007932 })
7933 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007934 testType: serverTest,
7935 name: "CurveTest-Server-" + curve.name,
7936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007937 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007938 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7939 CurvePreferences: []CurveID{curve.id},
7940 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007941 flags: []string{
7942 "-enable-all-curves",
7943 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7944 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007945 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007946 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007947 testCases = append(testCases, testCase{
7948 testType: serverTest,
7949 name: "CurveTest-Server-" + curve.name + "-TLS13",
7950 config: Config{
7951 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007952 CurvePreferences: []CurveID{curve.id},
7953 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007954 flags: []string{
7955 "-enable-all-curves",
7956 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7957 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007958 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007959 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007960 }
David Benjamin241ae832016-01-15 03:04:54 -05007961
7962 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007963 testCases = append(testCases, testCase{
7964 testType: serverTest,
7965 name: "UnknownCurve",
7966 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007967 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7969 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7970 },
7971 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007972
Steven Valdez803c77a2016-09-06 14:13:43 -04007973 // The server must be tolerant to bogus curves.
7974 testCases = append(testCases, testCase{
7975 testType: serverTest,
7976 name: "UnknownCurve-TLS13",
7977 config: Config{
7978 MaxVersion: VersionTLS13,
7979 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7980 },
7981 })
7982
David Benjamin4c3ddf72016-06-29 18:13:53 -04007983 // The server must not consider ECDHE ciphers when there are no
7984 // supported curves.
7985 testCases = append(testCases, testCase{
7986 testType: serverTest,
7987 name: "NoSupportedCurves",
7988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007989 MaxVersion: VersionTLS12,
7990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7991 Bugs: ProtocolBugs{
7992 NoSupportedCurves: true,
7993 },
7994 },
7995 shouldFail: true,
7996 expectedError: ":NO_SHARED_CIPHER:",
7997 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007998 testCases = append(testCases, testCase{
7999 testType: serverTest,
8000 name: "NoSupportedCurves-TLS13",
8001 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008002 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008003 Bugs: ProtocolBugs{
8004 NoSupportedCurves: true,
8005 },
8006 },
8007 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008008 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008009 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008010
8011 // The server must fall back to another cipher when there are no
8012 // supported curves.
8013 testCases = append(testCases, testCase{
8014 testType: serverTest,
8015 name: "NoCommonCurves",
8016 config: Config{
8017 MaxVersion: VersionTLS12,
8018 CipherSuites: []uint16{
8019 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8020 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8021 },
8022 CurvePreferences: []CurveID{CurveP224},
8023 },
8024 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8025 })
8026
8027 // The client must reject bogus curves and disabled curves.
8028 testCases = append(testCases, testCase{
8029 name: "BadECDHECurve",
8030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008031 MaxVersion: VersionTLS12,
8032 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8033 Bugs: ProtocolBugs{
8034 SendCurve: bogusCurve,
8035 },
8036 },
8037 shouldFail: true,
8038 expectedError: ":WRONG_CURVE:",
8039 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008040 testCases = append(testCases, testCase{
8041 name: "BadECDHECurve-TLS13",
8042 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008043 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008044 Bugs: ProtocolBugs{
8045 SendCurve: bogusCurve,
8046 },
8047 },
8048 shouldFail: true,
8049 expectedError: ":WRONG_CURVE:",
8050 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008051
8052 testCases = append(testCases, testCase{
8053 name: "UnsupportedCurve",
8054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008055 MaxVersion: VersionTLS12,
8056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8057 CurvePreferences: []CurveID{CurveP256},
8058 Bugs: ProtocolBugs{
8059 IgnorePeerCurvePreferences: true,
8060 },
8061 },
8062 flags: []string{"-p384-only"},
8063 shouldFail: true,
8064 expectedError: ":WRONG_CURVE:",
8065 })
8066
David Benjamin4f921572016-07-17 14:20:10 +02008067 testCases = append(testCases, testCase{
8068 // TODO(davidben): Add a TLS 1.3 version where
8069 // HelloRetryRequest requests an unsupported curve.
8070 name: "UnsupportedCurve-ServerHello-TLS13",
8071 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008072 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008073 CurvePreferences: []CurveID{CurveP384},
8074 Bugs: ProtocolBugs{
8075 SendCurve: CurveP256,
8076 },
8077 },
8078 flags: []string{"-p384-only"},
8079 shouldFail: true,
8080 expectedError: ":WRONG_CURVE:",
8081 })
8082
David Benjamin4c3ddf72016-06-29 18:13:53 -04008083 // Test invalid curve points.
8084 testCases = append(testCases, testCase{
8085 name: "InvalidECDHPoint-Client",
8086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008087 MaxVersion: VersionTLS12,
8088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8089 CurvePreferences: []CurveID{CurveP256},
8090 Bugs: ProtocolBugs{
8091 InvalidECDHPoint: true,
8092 },
8093 },
8094 shouldFail: true,
8095 expectedError: ":INVALID_ENCODING:",
8096 })
8097 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008098 name: "InvalidECDHPoint-Client-TLS13",
8099 config: Config{
8100 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008101 CurvePreferences: []CurveID{CurveP256},
8102 Bugs: ProtocolBugs{
8103 InvalidECDHPoint: true,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":INVALID_ENCODING:",
8108 })
8109 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008110 testType: serverTest,
8111 name: "InvalidECDHPoint-Server",
8112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008113 MaxVersion: VersionTLS12,
8114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8115 CurvePreferences: []CurveID{CurveP256},
8116 Bugs: ProtocolBugs{
8117 InvalidECDHPoint: true,
8118 },
8119 },
8120 shouldFail: true,
8121 expectedError: ":INVALID_ENCODING:",
8122 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008123 testCases = append(testCases, testCase{
8124 testType: serverTest,
8125 name: "InvalidECDHPoint-Server-TLS13",
8126 config: Config{
8127 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008128 CurvePreferences: []CurveID{CurveP256},
8129 Bugs: ProtocolBugs{
8130 InvalidECDHPoint: true,
8131 },
8132 },
8133 shouldFail: true,
8134 expectedError: ":INVALID_ENCODING:",
8135 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008136}
8137
Matt Braithwaite54217e42016-06-13 13:03:47 -07008138func addCECPQ1Tests() {
8139 testCases = append(testCases, testCase{
8140 testType: clientTest,
8141 name: "CECPQ1-Client-BadX25519Part",
8142 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008143 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008144 MinVersion: VersionTLS12,
8145 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8146 Bugs: ProtocolBugs{
8147 CECPQ1BadX25519Part: true,
8148 },
8149 },
8150 flags: []string{"-cipher", "kCECPQ1"},
8151 shouldFail: true,
8152 expectedLocalError: "local error: bad record MAC",
8153 })
8154 testCases = append(testCases, testCase{
8155 testType: clientTest,
8156 name: "CECPQ1-Client-BadNewhopePart",
8157 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008158 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008159 MinVersion: VersionTLS12,
8160 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8161 Bugs: ProtocolBugs{
8162 CECPQ1BadNewhopePart: true,
8163 },
8164 },
8165 flags: []string{"-cipher", "kCECPQ1"},
8166 shouldFail: true,
8167 expectedLocalError: "local error: bad record MAC",
8168 })
8169 testCases = append(testCases, testCase{
8170 testType: serverTest,
8171 name: "CECPQ1-Server-BadX25519Part",
8172 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008173 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008174 MinVersion: VersionTLS12,
8175 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8176 Bugs: ProtocolBugs{
8177 CECPQ1BadX25519Part: true,
8178 },
8179 },
8180 flags: []string{"-cipher", "kCECPQ1"},
8181 shouldFail: true,
8182 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8183 })
8184 testCases = append(testCases, testCase{
8185 testType: serverTest,
8186 name: "CECPQ1-Server-BadNewhopePart",
8187 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008188 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008189 MinVersion: VersionTLS12,
8190 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8191 Bugs: ProtocolBugs{
8192 CECPQ1BadNewhopePart: true,
8193 },
8194 },
8195 flags: []string{"-cipher", "kCECPQ1"},
8196 shouldFail: true,
8197 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8198 })
8199}
8200
David Benjamin5c4e8572016-08-19 17:44:53 -04008201func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008202 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008203 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008204 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008205 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008206 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8207 Bugs: ProtocolBugs{
8208 // This is a 1234-bit prime number, generated
8209 // with:
8210 // openssl gendh 1234 | openssl asn1parse -i
8211 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8212 },
8213 },
David Benjamin9e68f192016-06-30 14:55:33 -04008214 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008215 })
8216 testCases = append(testCases, testCase{
8217 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008218 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008219 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008220 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008221 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8222 },
8223 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008224 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008225 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008226}
8227
David Benjaminc9ae27c2016-06-24 22:56:37 -04008228func addTLS13RecordTests() {
8229 testCases = append(testCases, testCase{
8230 name: "TLS13-RecordPadding",
8231 config: Config{
8232 MaxVersion: VersionTLS13,
8233 MinVersion: VersionTLS13,
8234 Bugs: ProtocolBugs{
8235 RecordPadding: 10,
8236 },
8237 },
8238 })
8239
8240 testCases = append(testCases, testCase{
8241 name: "TLS13-EmptyRecords",
8242 config: Config{
8243 MaxVersion: VersionTLS13,
8244 MinVersion: VersionTLS13,
8245 Bugs: ProtocolBugs{
8246 OmitRecordContents: true,
8247 },
8248 },
8249 shouldFail: true,
8250 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8251 })
8252
8253 testCases = append(testCases, testCase{
8254 name: "TLS13-OnlyPadding",
8255 config: Config{
8256 MaxVersion: VersionTLS13,
8257 MinVersion: VersionTLS13,
8258 Bugs: ProtocolBugs{
8259 OmitRecordContents: true,
8260 RecordPadding: 10,
8261 },
8262 },
8263 shouldFail: true,
8264 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8265 })
8266
8267 testCases = append(testCases, testCase{
8268 name: "TLS13-WrongOuterRecord",
8269 config: Config{
8270 MaxVersion: VersionTLS13,
8271 MinVersion: VersionTLS13,
8272 Bugs: ProtocolBugs{
8273 OuterRecordType: recordTypeHandshake,
8274 },
8275 },
8276 shouldFail: true,
8277 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8278 })
8279}
8280
Steven Valdez5b986082016-09-01 12:29:49 -04008281func addSessionTicketTests() {
8282 testCases = append(testCases, testCase{
8283 // In TLS 1.2 and below, empty NewSessionTicket messages
8284 // mean the server changed its mind on sending a ticket.
8285 name: "SendEmptySessionTicket",
8286 config: Config{
8287 MaxVersion: VersionTLS12,
8288 Bugs: ProtocolBugs{
8289 SendEmptySessionTicket: true,
8290 },
8291 },
8292 flags: []string{"-expect-no-session"},
8293 })
8294
8295 // Test that the server ignores unknown PSK modes.
8296 testCases = append(testCases, testCase{
8297 testType: serverTest,
8298 name: "TLS13-SendUnknownModeSessionTicket-Server",
8299 config: Config{
8300 MaxVersion: VersionTLS13,
8301 Bugs: ProtocolBugs{
8302 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008303 },
8304 },
8305 resumeSession: true,
8306 expectedResumeVersion: VersionTLS13,
8307 })
8308
Steven Valdeza833c352016-11-01 13:39:36 -04008309 // Test that the server does not send session tickets with no matching key exchange mode.
8310 testCases = append(testCases, testCase{
8311 testType: serverTest,
8312 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8313 config: Config{
8314 MaxVersion: VersionTLS13,
8315 Bugs: ProtocolBugs{
8316 SendPSKKeyExchangeModes: []byte{0x1a},
8317 ExpectNoNewSessionTicket: true,
8318 },
8319 },
8320 })
8321
8322 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008323 testCases = append(testCases, testCase{
8324 testType: serverTest,
8325 name: "TLS13-SendBadKEModeSessionTicket-Server",
8326 config: Config{
8327 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008328 },
8329 resumeConfig: &Config{
8330 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008331 Bugs: ProtocolBugs{
8332 SendPSKKeyExchangeModes: []byte{0x1a},
8333 },
8334 },
8335 resumeSession: true,
8336 expectResumeRejected: true,
8337 })
8338
Steven Valdeza833c352016-11-01 13:39:36 -04008339 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008340 testCases = append(testCases, testCase{
8341 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008342 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008343 config: Config{
8344 MaxVersion: VersionTLS13,
8345 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008346 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008347 },
8348 },
Steven Valdeza833c352016-11-01 13:39:36 -04008349 resumeSession: true,
8350 flags: []string{
8351 "-resumption-delay", "10",
8352 },
Steven Valdez5b986082016-09-01 12:29:49 -04008353 })
8354
Steven Valdeza833c352016-11-01 13:39:36 -04008355 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008356 testCases = append(testCases, testCase{
8357 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008358 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008359 config: Config{
8360 MaxVersion: VersionTLS13,
8361 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008362 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008363 },
8364 },
Steven Valdeza833c352016-11-01 13:39:36 -04008365 resumeSession: true,
8366 shouldFail: true,
8367 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008368 })
8369
Steven Valdez5b986082016-09-01 12:29:49 -04008370}
8371
David Benjamin82261be2016-07-07 14:32:50 -07008372func addChangeCipherSpecTests() {
8373 // Test missing ChangeCipherSpecs.
8374 testCases = append(testCases, testCase{
8375 name: "SkipChangeCipherSpec-Client",
8376 config: Config{
8377 MaxVersion: VersionTLS12,
8378 Bugs: ProtocolBugs{
8379 SkipChangeCipherSpec: true,
8380 },
8381 },
8382 shouldFail: true,
8383 expectedError: ":UNEXPECTED_RECORD:",
8384 })
8385 testCases = append(testCases, testCase{
8386 testType: serverTest,
8387 name: "SkipChangeCipherSpec-Server",
8388 config: Config{
8389 MaxVersion: VersionTLS12,
8390 Bugs: ProtocolBugs{
8391 SkipChangeCipherSpec: true,
8392 },
8393 },
8394 shouldFail: true,
8395 expectedError: ":UNEXPECTED_RECORD:",
8396 })
8397 testCases = append(testCases, testCase{
8398 testType: serverTest,
8399 name: "SkipChangeCipherSpec-Server-NPN",
8400 config: Config{
8401 MaxVersion: VersionTLS12,
8402 NextProtos: []string{"bar"},
8403 Bugs: ProtocolBugs{
8404 SkipChangeCipherSpec: true,
8405 },
8406 },
8407 flags: []string{
8408 "-advertise-npn", "\x03foo\x03bar\x03baz",
8409 },
8410 shouldFail: true,
8411 expectedError: ":UNEXPECTED_RECORD:",
8412 })
8413
8414 // Test synchronization between the handshake and ChangeCipherSpec.
8415 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8416 // rejected. Test both with and without handshake packing to handle both
8417 // when the partial post-CCS message is in its own record and when it is
8418 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008419 for _, packed := range []bool{false, true} {
8420 var suffix string
8421 if packed {
8422 suffix = "-Packed"
8423 }
8424
8425 testCases = append(testCases, testCase{
8426 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8427 config: Config{
8428 MaxVersion: VersionTLS12,
8429 Bugs: ProtocolBugs{
8430 FragmentAcrossChangeCipherSpec: true,
8431 PackHandshakeFlight: packed,
8432 },
8433 },
8434 shouldFail: true,
8435 expectedError: ":UNEXPECTED_RECORD:",
8436 })
8437 testCases = append(testCases, testCase{
8438 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8439 config: Config{
8440 MaxVersion: VersionTLS12,
8441 },
8442 resumeSession: true,
8443 resumeConfig: &Config{
8444 MaxVersion: VersionTLS12,
8445 Bugs: ProtocolBugs{
8446 FragmentAcrossChangeCipherSpec: true,
8447 PackHandshakeFlight: packed,
8448 },
8449 },
8450 shouldFail: true,
8451 expectedError: ":UNEXPECTED_RECORD:",
8452 })
8453 testCases = append(testCases, testCase{
8454 testType: serverTest,
8455 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8456 config: Config{
8457 MaxVersion: VersionTLS12,
8458 Bugs: ProtocolBugs{
8459 FragmentAcrossChangeCipherSpec: true,
8460 PackHandshakeFlight: packed,
8461 },
8462 },
8463 shouldFail: true,
8464 expectedError: ":UNEXPECTED_RECORD:",
8465 })
8466 testCases = append(testCases, testCase{
8467 testType: serverTest,
8468 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8469 config: Config{
8470 MaxVersion: VersionTLS12,
8471 },
8472 resumeSession: true,
8473 resumeConfig: &Config{
8474 MaxVersion: VersionTLS12,
8475 Bugs: ProtocolBugs{
8476 FragmentAcrossChangeCipherSpec: true,
8477 PackHandshakeFlight: packed,
8478 },
8479 },
8480 shouldFail: true,
8481 expectedError: ":UNEXPECTED_RECORD:",
8482 })
8483 testCases = append(testCases, testCase{
8484 testType: serverTest,
8485 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8486 config: Config{
8487 MaxVersion: VersionTLS12,
8488 NextProtos: []string{"bar"},
8489 Bugs: ProtocolBugs{
8490 FragmentAcrossChangeCipherSpec: true,
8491 PackHandshakeFlight: packed,
8492 },
8493 },
8494 flags: []string{
8495 "-advertise-npn", "\x03foo\x03bar\x03baz",
8496 },
8497 shouldFail: true,
8498 expectedError: ":UNEXPECTED_RECORD:",
8499 })
8500 }
8501
David Benjamin61672812016-07-14 23:10:43 -04008502 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8503 // messages in the handshake queue. Do this by testing the server
8504 // reading the client Finished, reversing the flight so Finished comes
8505 // first.
8506 testCases = append(testCases, testCase{
8507 protocol: dtls,
8508 testType: serverTest,
8509 name: "SendUnencryptedFinished-DTLS",
8510 config: Config{
8511 MaxVersion: VersionTLS12,
8512 Bugs: ProtocolBugs{
8513 SendUnencryptedFinished: true,
8514 ReverseHandshakeFragments: true,
8515 },
8516 },
8517 shouldFail: true,
8518 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8519 })
8520
Steven Valdez143e8b32016-07-11 13:19:03 -04008521 // Test synchronization between encryption changes and the handshake in
8522 // TLS 1.3, where ChangeCipherSpec is implicit.
8523 testCases = append(testCases, testCase{
8524 name: "PartialEncryptedExtensionsWithServerHello",
8525 config: Config{
8526 MaxVersion: VersionTLS13,
8527 Bugs: ProtocolBugs{
8528 PartialEncryptedExtensionsWithServerHello: true,
8529 },
8530 },
8531 shouldFail: true,
8532 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8533 })
8534 testCases = append(testCases, testCase{
8535 testType: serverTest,
8536 name: "PartialClientFinishedWithClientHello",
8537 config: Config{
8538 MaxVersion: VersionTLS13,
8539 Bugs: ProtocolBugs{
8540 PartialClientFinishedWithClientHello: true,
8541 },
8542 },
8543 shouldFail: true,
8544 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8545 })
8546
David Benjamin82261be2016-07-07 14:32:50 -07008547 // Test that early ChangeCipherSpecs are handled correctly.
8548 testCases = append(testCases, testCase{
8549 testType: serverTest,
8550 name: "EarlyChangeCipherSpec-server-1",
8551 config: Config{
8552 MaxVersion: VersionTLS12,
8553 Bugs: ProtocolBugs{
8554 EarlyChangeCipherSpec: 1,
8555 },
8556 },
8557 shouldFail: true,
8558 expectedError: ":UNEXPECTED_RECORD:",
8559 })
8560 testCases = append(testCases, testCase{
8561 testType: serverTest,
8562 name: "EarlyChangeCipherSpec-server-2",
8563 config: Config{
8564 MaxVersion: VersionTLS12,
8565 Bugs: ProtocolBugs{
8566 EarlyChangeCipherSpec: 2,
8567 },
8568 },
8569 shouldFail: true,
8570 expectedError: ":UNEXPECTED_RECORD:",
8571 })
8572 testCases = append(testCases, testCase{
8573 protocol: dtls,
8574 name: "StrayChangeCipherSpec",
8575 config: Config{
8576 // TODO(davidben): Once DTLS 1.3 exists, test
8577 // that stray ChangeCipherSpec messages are
8578 // rejected.
8579 MaxVersion: VersionTLS12,
8580 Bugs: ProtocolBugs{
8581 StrayChangeCipherSpec: true,
8582 },
8583 },
8584 })
8585
8586 // Test that the contents of ChangeCipherSpec are checked.
8587 testCases = append(testCases, testCase{
8588 name: "BadChangeCipherSpec-1",
8589 config: Config{
8590 MaxVersion: VersionTLS12,
8591 Bugs: ProtocolBugs{
8592 BadChangeCipherSpec: []byte{2},
8593 },
8594 },
8595 shouldFail: true,
8596 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8597 })
8598 testCases = append(testCases, testCase{
8599 name: "BadChangeCipherSpec-2",
8600 config: Config{
8601 MaxVersion: VersionTLS12,
8602 Bugs: ProtocolBugs{
8603 BadChangeCipherSpec: []byte{1, 1},
8604 },
8605 },
8606 shouldFail: true,
8607 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8608 })
8609 testCases = append(testCases, testCase{
8610 protocol: dtls,
8611 name: "BadChangeCipherSpec-DTLS-1",
8612 config: Config{
8613 MaxVersion: VersionTLS12,
8614 Bugs: ProtocolBugs{
8615 BadChangeCipherSpec: []byte{2},
8616 },
8617 },
8618 shouldFail: true,
8619 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8620 })
8621 testCases = append(testCases, testCase{
8622 protocol: dtls,
8623 name: "BadChangeCipherSpec-DTLS-2",
8624 config: Config{
8625 MaxVersion: VersionTLS12,
8626 Bugs: ProtocolBugs{
8627 BadChangeCipherSpec: []byte{1, 1},
8628 },
8629 },
8630 shouldFail: true,
8631 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8632 })
8633}
8634
David Benjamincd2c8062016-09-09 11:28:16 -04008635type perMessageTest struct {
8636 messageType uint8
8637 test testCase
8638}
8639
8640// makePerMessageTests returns a series of test templates which cover each
8641// message in the TLS handshake. These may be used with bugs like
8642// WrongMessageType to fully test a per-message bug.
8643func makePerMessageTests() []perMessageTest {
8644 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008645 for _, protocol := range []protocol{tls, dtls} {
8646 var suffix string
8647 if protocol == dtls {
8648 suffix = "-DTLS"
8649 }
8650
David Benjamincd2c8062016-09-09 11:28:16 -04008651 ret = append(ret, perMessageTest{
8652 messageType: typeClientHello,
8653 test: testCase{
8654 protocol: protocol,
8655 testType: serverTest,
8656 name: "ClientHello" + suffix,
8657 config: Config{
8658 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008659 },
8660 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008661 })
8662
8663 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008664 ret = append(ret, perMessageTest{
8665 messageType: typeHelloVerifyRequest,
8666 test: testCase{
8667 protocol: protocol,
8668 name: "HelloVerifyRequest" + suffix,
8669 config: Config{
8670 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008671 },
8672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008673 })
8674 }
8675
David Benjamincd2c8062016-09-09 11:28:16 -04008676 ret = append(ret, perMessageTest{
8677 messageType: typeServerHello,
8678 test: testCase{
8679 protocol: protocol,
8680 name: "ServerHello" + suffix,
8681 config: Config{
8682 MaxVersion: VersionTLS12,
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: typeCertificate,
8689 test: testCase{
8690 protocol: protocol,
8691 name: "ServerCertificate" + 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: typeCertificateStatus,
8700 test: testCase{
8701 protocol: protocol,
8702 name: "CertificateStatus" + suffix,
8703 config: Config{
8704 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008705 },
David Benjamincd2c8062016-09-09 11:28:16 -04008706 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008707 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008708 })
8709
David Benjamincd2c8062016-09-09 11:28:16 -04008710 ret = append(ret, perMessageTest{
8711 messageType: typeServerKeyExchange,
8712 test: testCase{
8713 protocol: protocol,
8714 name: "ServerKeyExchange" + suffix,
8715 config: Config{
8716 MaxVersion: VersionTLS12,
8717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008718 },
8719 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008720 })
8721
David Benjamincd2c8062016-09-09 11:28:16 -04008722 ret = append(ret, perMessageTest{
8723 messageType: typeCertificateRequest,
8724 test: testCase{
8725 protocol: protocol,
8726 name: "CertificateRequest" + suffix,
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008730 },
8731 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008732 })
8733
David Benjamincd2c8062016-09-09 11:28:16 -04008734 ret = append(ret, perMessageTest{
8735 messageType: typeServerHelloDone,
8736 test: testCase{
8737 protocol: protocol,
8738 name: "ServerHelloDone" + suffix,
8739 config: Config{
8740 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008741 },
8742 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008743 })
8744
David Benjamincd2c8062016-09-09 11:28:16 -04008745 ret = append(ret, perMessageTest{
8746 messageType: typeCertificate,
8747 test: testCase{
8748 testType: serverTest,
8749 protocol: protocol,
8750 name: "ClientCertificate" + suffix,
8751 config: Config{
8752 Certificates: []Certificate{rsaCertificate},
8753 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008754 },
David Benjamincd2c8062016-09-09 11:28:16 -04008755 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008756 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008757 })
8758
David Benjamincd2c8062016-09-09 11:28:16 -04008759 ret = append(ret, perMessageTest{
8760 messageType: typeCertificateVerify,
8761 test: testCase{
8762 testType: serverTest,
8763 protocol: protocol,
8764 name: "CertificateVerify" + suffix,
8765 config: Config{
8766 Certificates: []Certificate{rsaCertificate},
8767 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 },
David Benjamincd2c8062016-09-09 11:28:16 -04008769 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008770 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008771 })
8772
David Benjamincd2c8062016-09-09 11:28:16 -04008773 ret = append(ret, perMessageTest{
8774 messageType: typeClientKeyExchange,
8775 test: testCase{
8776 testType: serverTest,
8777 protocol: protocol,
8778 name: "ClientKeyExchange" + suffix,
8779 config: Config{
8780 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008781 },
8782 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008783 })
8784
8785 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008786 ret = append(ret, perMessageTest{
8787 messageType: typeNextProtocol,
8788 test: testCase{
8789 testType: serverTest,
8790 protocol: protocol,
8791 name: "NextProtocol" + suffix,
8792 config: Config{
8793 MaxVersion: VersionTLS12,
8794 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008795 },
David Benjamincd2c8062016-09-09 11:28:16 -04008796 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008797 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008798 })
8799
David Benjamincd2c8062016-09-09 11:28:16 -04008800 ret = append(ret, perMessageTest{
8801 messageType: typeChannelID,
8802 test: testCase{
8803 testType: serverTest,
8804 protocol: protocol,
8805 name: "ChannelID" + suffix,
8806 config: Config{
8807 MaxVersion: VersionTLS12,
8808 ChannelID: channelIDKey,
8809 },
8810 flags: []string{
8811 "-expect-channel-id",
8812 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008813 },
8814 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008815 })
8816 }
8817
David Benjamincd2c8062016-09-09 11:28:16 -04008818 ret = append(ret, perMessageTest{
8819 messageType: typeFinished,
8820 test: testCase{
8821 testType: serverTest,
8822 protocol: protocol,
8823 name: "ClientFinished" + suffix,
8824 config: Config{
8825 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008826 },
8827 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008828 })
8829
David Benjamincd2c8062016-09-09 11:28:16 -04008830 ret = append(ret, perMessageTest{
8831 messageType: typeNewSessionTicket,
8832 test: testCase{
8833 protocol: protocol,
8834 name: "NewSessionTicket" + suffix,
8835 config: Config{
8836 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008837 },
8838 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008839 })
8840
David Benjamincd2c8062016-09-09 11:28:16 -04008841 ret = append(ret, perMessageTest{
8842 messageType: typeFinished,
8843 test: testCase{
8844 protocol: protocol,
8845 name: "ServerFinished" + suffix,
8846 config: Config{
8847 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008848 },
8849 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008850 })
8851
8852 }
David Benjamincd2c8062016-09-09 11:28:16 -04008853
8854 ret = append(ret, perMessageTest{
8855 messageType: typeClientHello,
8856 test: testCase{
8857 testType: serverTest,
8858 name: "TLS13-ClientHello",
8859 config: Config{
8860 MaxVersion: VersionTLS13,
8861 },
8862 },
8863 })
8864
8865 ret = append(ret, perMessageTest{
8866 messageType: typeServerHello,
8867 test: testCase{
8868 name: "TLS13-ServerHello",
8869 config: Config{
8870 MaxVersion: VersionTLS13,
8871 },
8872 },
8873 })
8874
8875 ret = append(ret, perMessageTest{
8876 messageType: typeEncryptedExtensions,
8877 test: testCase{
8878 name: "TLS13-EncryptedExtensions",
8879 config: Config{
8880 MaxVersion: VersionTLS13,
8881 },
8882 },
8883 })
8884
8885 ret = append(ret, perMessageTest{
8886 messageType: typeCertificateRequest,
8887 test: testCase{
8888 name: "TLS13-CertificateRequest",
8889 config: Config{
8890 MaxVersion: VersionTLS13,
8891 ClientAuth: RequireAnyClientCert,
8892 },
8893 },
8894 })
8895
8896 ret = append(ret, perMessageTest{
8897 messageType: typeCertificate,
8898 test: testCase{
8899 name: "TLS13-ServerCertificate",
8900 config: Config{
8901 MaxVersion: VersionTLS13,
8902 },
8903 },
8904 })
8905
8906 ret = append(ret, perMessageTest{
8907 messageType: typeCertificateVerify,
8908 test: testCase{
8909 name: "TLS13-ServerCertificateVerify",
8910 config: Config{
8911 MaxVersion: VersionTLS13,
8912 },
8913 },
8914 })
8915
8916 ret = append(ret, perMessageTest{
8917 messageType: typeFinished,
8918 test: testCase{
8919 name: "TLS13-ServerFinished",
8920 config: Config{
8921 MaxVersion: VersionTLS13,
8922 },
8923 },
8924 })
8925
8926 ret = append(ret, perMessageTest{
8927 messageType: typeCertificate,
8928 test: testCase{
8929 testType: serverTest,
8930 name: "TLS13-ClientCertificate",
8931 config: Config{
8932 Certificates: []Certificate{rsaCertificate},
8933 MaxVersion: VersionTLS13,
8934 },
8935 flags: []string{"-require-any-client-certificate"},
8936 },
8937 })
8938
8939 ret = append(ret, perMessageTest{
8940 messageType: typeCertificateVerify,
8941 test: testCase{
8942 testType: serverTest,
8943 name: "TLS13-ClientCertificateVerify",
8944 config: Config{
8945 Certificates: []Certificate{rsaCertificate},
8946 MaxVersion: VersionTLS13,
8947 },
8948 flags: []string{"-require-any-client-certificate"},
8949 },
8950 })
8951
8952 ret = append(ret, perMessageTest{
8953 messageType: typeFinished,
8954 test: testCase{
8955 testType: serverTest,
8956 name: "TLS13-ClientFinished",
8957 config: Config{
8958 MaxVersion: VersionTLS13,
8959 },
8960 },
8961 })
8962
8963 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008964}
8965
David Benjamincd2c8062016-09-09 11:28:16 -04008966func addWrongMessageTypeTests() {
8967 for _, t := range makePerMessageTests() {
8968 t.test.name = "WrongMessageType-" + t.test.name
8969 t.test.config.Bugs.SendWrongMessageType = t.messageType
8970 t.test.shouldFail = true
8971 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8972 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008973
David Benjamincd2c8062016-09-09 11:28:16 -04008974 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8975 // In TLS 1.3, a bad ServerHello means the client sends
8976 // an unencrypted alert while the server expects
8977 // encryption, so the alert is not readable by runner.
8978 t.test.expectedLocalError = "local error: bad record MAC"
8979 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008980
David Benjamincd2c8062016-09-09 11:28:16 -04008981 testCases = append(testCases, t.test)
8982 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008983}
8984
David Benjamin639846e2016-09-09 11:41:18 -04008985func addTrailingMessageDataTests() {
8986 for _, t := range makePerMessageTests() {
8987 t.test.name = "TrailingMessageData-" + t.test.name
8988 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8989 t.test.shouldFail = true
8990 t.test.expectedError = ":DECODE_ERROR:"
8991 t.test.expectedLocalError = "remote error: error decoding message"
8992
8993 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8994 // In TLS 1.3, a bad ServerHello means the client sends
8995 // an unencrypted alert while the server expects
8996 // encryption, so the alert is not readable by runner.
8997 t.test.expectedLocalError = "local error: bad record MAC"
8998 }
8999
9000 if t.messageType == typeFinished {
9001 // Bad Finished messages read as the verify data having
9002 // the wrong length.
9003 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9004 t.test.expectedLocalError = "remote error: error decrypting message"
9005 }
9006
9007 testCases = append(testCases, t.test)
9008 }
9009}
9010
Steven Valdez143e8b32016-07-11 13:19:03 -04009011func addTLS13HandshakeTests() {
9012 testCases = append(testCases, testCase{
9013 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009014 name: "NegotiatePSKResumption-TLS13",
9015 config: Config{
9016 MaxVersion: VersionTLS13,
9017 Bugs: ProtocolBugs{
9018 NegotiatePSKResumption: true,
9019 },
9020 },
9021 resumeSession: true,
9022 shouldFail: true,
9023 expectedError: ":UNEXPECTED_EXTENSION:",
9024 })
9025
9026 testCases = append(testCases, testCase{
9027 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009028 name: "MissingKeyShare-Client",
9029 config: Config{
9030 MaxVersion: VersionTLS13,
9031 Bugs: ProtocolBugs{
9032 MissingKeyShare: true,
9033 },
9034 },
9035 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009036 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009037 })
9038
9039 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009040 testType: serverTest,
9041 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009042 config: Config{
9043 MaxVersion: VersionTLS13,
9044 Bugs: ProtocolBugs{
9045 MissingKeyShare: true,
9046 },
9047 },
9048 shouldFail: true,
9049 expectedError: ":MISSING_KEY_SHARE:",
9050 })
9051
9052 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009053 testType: serverTest,
9054 name: "DuplicateKeyShares",
9055 config: Config{
9056 MaxVersion: VersionTLS13,
9057 Bugs: ProtocolBugs{
9058 DuplicateKeyShares: true,
9059 },
9060 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009061 shouldFail: true,
9062 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009063 })
9064
9065 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009066 testType: serverTest,
9067 name: "SkipEarlyData",
9068 config: Config{
9069 MaxVersion: VersionTLS13,
9070 Bugs: ProtocolBugs{
9071 SendEarlyDataLength: 4,
9072 },
9073 },
9074 })
9075
9076 testCases = append(testCases, testCase{
9077 testType: serverTest,
9078 name: "SkipEarlyData-OmitEarlyDataExtension",
9079 config: Config{
9080 MaxVersion: VersionTLS13,
9081 Bugs: ProtocolBugs{
9082 SendEarlyDataLength: 4,
9083 OmitEarlyDataExtension: true,
9084 },
9085 },
9086 shouldFail: true,
9087 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9088 })
9089
9090 testCases = append(testCases, testCase{
9091 testType: serverTest,
9092 name: "SkipEarlyData-TooMuchData",
9093 config: Config{
9094 MaxVersion: VersionTLS13,
9095 Bugs: ProtocolBugs{
9096 SendEarlyDataLength: 16384 + 1,
9097 },
9098 },
9099 shouldFail: true,
9100 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9101 })
9102
9103 testCases = append(testCases, testCase{
9104 testType: serverTest,
9105 name: "SkipEarlyData-Interleaved",
9106 config: Config{
9107 MaxVersion: VersionTLS13,
9108 Bugs: ProtocolBugs{
9109 SendEarlyDataLength: 4,
9110 InterleaveEarlyData: true,
9111 },
9112 },
9113 shouldFail: true,
9114 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9115 })
9116
9117 testCases = append(testCases, testCase{
9118 testType: serverTest,
9119 name: "SkipEarlyData-EarlyDataInTLS12",
9120 config: Config{
9121 MaxVersion: VersionTLS13,
9122 Bugs: ProtocolBugs{
9123 SendEarlyDataLength: 4,
9124 },
9125 },
9126 shouldFail: true,
9127 expectedError: ":UNEXPECTED_RECORD:",
9128 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9129 })
9130
9131 testCases = append(testCases, testCase{
9132 testType: serverTest,
9133 name: "SkipEarlyData-HRR",
9134 config: Config{
9135 MaxVersion: VersionTLS13,
9136 Bugs: ProtocolBugs{
9137 SendEarlyDataLength: 4,
9138 },
9139 DefaultCurves: []CurveID{},
9140 },
9141 })
9142
9143 testCases = append(testCases, testCase{
9144 testType: serverTest,
9145 name: "SkipEarlyData-HRR-Interleaved",
9146 config: Config{
9147 MaxVersion: VersionTLS13,
9148 Bugs: ProtocolBugs{
9149 SendEarlyDataLength: 4,
9150 InterleaveEarlyData: true,
9151 },
9152 DefaultCurves: []CurveID{},
9153 },
9154 shouldFail: true,
9155 expectedError: ":UNEXPECTED_RECORD:",
9156 })
9157
9158 testCases = append(testCases, testCase{
9159 testType: serverTest,
9160 name: "SkipEarlyData-HRR-TooMuchData",
9161 config: Config{
9162 MaxVersion: VersionTLS13,
9163 Bugs: ProtocolBugs{
9164 SendEarlyDataLength: 16384 + 1,
9165 },
9166 DefaultCurves: []CurveID{},
9167 },
9168 shouldFail: true,
9169 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9170 })
9171
9172 // Test that skipping early data looking for cleartext correctly
9173 // processes an alert record.
9174 testCases = append(testCases, testCase{
9175 testType: serverTest,
9176 name: "SkipEarlyData-HRR-FatalAlert",
9177 config: Config{
9178 MaxVersion: VersionTLS13,
9179 Bugs: ProtocolBugs{
9180 SendEarlyAlert: true,
9181 SendEarlyDataLength: 4,
9182 },
9183 DefaultCurves: []CurveID{},
9184 },
9185 shouldFail: true,
9186 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9187 })
9188
9189 testCases = append(testCases, testCase{
9190 testType: serverTest,
9191 name: "SkipEarlyData-SecondClientHelloEarlyData",
9192 config: Config{
9193 MaxVersion: VersionTLS13,
9194 Bugs: ProtocolBugs{
9195 SendEarlyDataOnSecondClientHello: true,
9196 },
9197 DefaultCurves: []CurveID{},
9198 },
9199 shouldFail: true,
9200 expectedLocalError: "remote error: bad record MAC",
9201 })
9202
9203 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009204 testType: clientTest,
9205 name: "EmptyEncryptedExtensions",
9206 config: Config{
9207 MaxVersion: VersionTLS13,
9208 Bugs: ProtocolBugs{
9209 EmptyEncryptedExtensions: true,
9210 },
9211 },
9212 shouldFail: true,
9213 expectedLocalError: "remote error: error decoding message",
9214 })
9215
9216 testCases = append(testCases, testCase{
9217 testType: clientTest,
9218 name: "EncryptedExtensionsWithKeyShare",
9219 config: Config{
9220 MaxVersion: VersionTLS13,
9221 Bugs: ProtocolBugs{
9222 EncryptedExtensionsWithKeyShare: true,
9223 },
9224 },
9225 shouldFail: true,
9226 expectedLocalError: "remote error: unsupported extension",
9227 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009228
9229 testCases = append(testCases, testCase{
9230 testType: serverTest,
9231 name: "SendHelloRetryRequest",
9232 config: Config{
9233 MaxVersion: VersionTLS13,
9234 // Require a HelloRetryRequest for every curve.
9235 DefaultCurves: []CurveID{},
9236 },
9237 expectedCurveID: CurveX25519,
9238 })
9239
9240 testCases = append(testCases, testCase{
9241 testType: serverTest,
9242 name: "SendHelloRetryRequest-2",
9243 config: Config{
9244 MaxVersion: VersionTLS13,
9245 DefaultCurves: []CurveID{CurveP384},
9246 },
9247 // Although the ClientHello did not predict our preferred curve,
9248 // we always select it whether it is predicted or not.
9249 expectedCurveID: CurveX25519,
9250 })
9251
9252 testCases = append(testCases, testCase{
9253 name: "UnknownCurve-HelloRetryRequest",
9254 config: Config{
9255 MaxVersion: VersionTLS13,
9256 // P-384 requires HelloRetryRequest in BoringSSL.
9257 CurvePreferences: []CurveID{CurveP384},
9258 Bugs: ProtocolBugs{
9259 SendHelloRetryRequestCurve: bogusCurve,
9260 },
9261 },
9262 shouldFail: true,
9263 expectedError: ":WRONG_CURVE:",
9264 })
9265
9266 testCases = append(testCases, testCase{
9267 name: "DisabledCurve-HelloRetryRequest",
9268 config: Config{
9269 MaxVersion: VersionTLS13,
9270 CurvePreferences: []CurveID{CurveP256},
9271 Bugs: ProtocolBugs{
9272 IgnorePeerCurvePreferences: true,
9273 },
9274 },
9275 flags: []string{"-p384-only"},
9276 shouldFail: true,
9277 expectedError: ":WRONG_CURVE:",
9278 })
9279
9280 testCases = append(testCases, testCase{
9281 name: "UnnecessaryHelloRetryRequest",
9282 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009283 MaxVersion: VersionTLS13,
9284 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009285 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009286 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009287 },
9288 },
9289 shouldFail: true,
9290 expectedError: ":WRONG_CURVE:",
9291 })
9292
9293 testCases = append(testCases, testCase{
9294 name: "SecondHelloRetryRequest",
9295 config: Config{
9296 MaxVersion: VersionTLS13,
9297 // P-384 requires HelloRetryRequest in BoringSSL.
9298 CurvePreferences: []CurveID{CurveP384},
9299 Bugs: ProtocolBugs{
9300 SecondHelloRetryRequest: true,
9301 },
9302 },
9303 shouldFail: true,
9304 expectedError: ":UNEXPECTED_MESSAGE:",
9305 })
9306
9307 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009308 name: "HelloRetryRequest-Empty",
9309 config: Config{
9310 MaxVersion: VersionTLS13,
9311 Bugs: ProtocolBugs{
9312 AlwaysSendHelloRetryRequest: true,
9313 },
9314 },
9315 shouldFail: true,
9316 expectedError: ":DECODE_ERROR:",
9317 })
9318
9319 testCases = append(testCases, testCase{
9320 name: "HelloRetryRequest-DuplicateCurve",
9321 config: Config{
9322 MaxVersion: VersionTLS13,
9323 // P-384 requires a HelloRetryRequest against BoringSSL's default
9324 // configuration. Assert this ExpectMissingKeyShare.
9325 CurvePreferences: []CurveID{CurveP384},
9326 Bugs: ProtocolBugs{
9327 ExpectMissingKeyShare: true,
9328 DuplicateHelloRetryRequestExtensions: true,
9329 },
9330 },
9331 shouldFail: true,
9332 expectedError: ":DUPLICATE_EXTENSION:",
9333 expectedLocalError: "remote error: illegal parameter",
9334 })
9335
9336 testCases = append(testCases, testCase{
9337 name: "HelloRetryRequest-Cookie",
9338 config: Config{
9339 MaxVersion: VersionTLS13,
9340 Bugs: ProtocolBugs{
9341 SendHelloRetryRequestCookie: []byte("cookie"),
9342 },
9343 },
9344 })
9345
9346 testCases = append(testCases, testCase{
9347 name: "HelloRetryRequest-DuplicateCookie",
9348 config: Config{
9349 MaxVersion: VersionTLS13,
9350 Bugs: ProtocolBugs{
9351 SendHelloRetryRequestCookie: []byte("cookie"),
9352 DuplicateHelloRetryRequestExtensions: true,
9353 },
9354 },
9355 shouldFail: true,
9356 expectedError: ":DUPLICATE_EXTENSION:",
9357 expectedLocalError: "remote error: illegal parameter",
9358 })
9359
9360 testCases = append(testCases, testCase{
9361 name: "HelloRetryRequest-EmptyCookie",
9362 config: Config{
9363 MaxVersion: VersionTLS13,
9364 Bugs: ProtocolBugs{
9365 SendHelloRetryRequestCookie: []byte{},
9366 },
9367 },
9368 shouldFail: true,
9369 expectedError: ":DECODE_ERROR:",
9370 })
9371
9372 testCases = append(testCases, testCase{
9373 name: "HelloRetryRequest-Cookie-Curve",
9374 config: Config{
9375 MaxVersion: VersionTLS13,
9376 // P-384 requires HelloRetryRequest in BoringSSL.
9377 CurvePreferences: []CurveID{CurveP384},
9378 Bugs: ProtocolBugs{
9379 SendHelloRetryRequestCookie: []byte("cookie"),
9380 ExpectMissingKeyShare: true,
9381 },
9382 },
9383 })
9384
9385 testCases = append(testCases, testCase{
9386 name: "HelloRetryRequest-Unknown",
9387 config: Config{
9388 MaxVersion: VersionTLS13,
9389 Bugs: ProtocolBugs{
9390 CustomHelloRetryRequestExtension: "extension",
9391 },
9392 },
9393 shouldFail: true,
9394 expectedError: ":UNEXPECTED_EXTENSION:",
9395 expectedLocalError: "remote error: unsupported extension",
9396 })
9397
9398 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009399 testType: serverTest,
9400 name: "SecondClientHelloMissingKeyShare",
9401 config: Config{
9402 MaxVersion: VersionTLS13,
9403 DefaultCurves: []CurveID{},
9404 Bugs: ProtocolBugs{
9405 SecondClientHelloMissingKeyShare: true,
9406 },
9407 },
9408 shouldFail: true,
9409 expectedError: ":MISSING_KEY_SHARE:",
9410 })
9411
9412 testCases = append(testCases, testCase{
9413 testType: serverTest,
9414 name: "SecondClientHelloWrongCurve",
9415 config: Config{
9416 MaxVersion: VersionTLS13,
9417 DefaultCurves: []CurveID{},
9418 Bugs: ProtocolBugs{
9419 MisinterpretHelloRetryRequestCurve: CurveP521,
9420 },
9421 },
9422 shouldFail: true,
9423 expectedError: ":WRONG_CURVE:",
9424 })
9425
9426 testCases = append(testCases, testCase{
9427 name: "HelloRetryRequestVersionMismatch",
9428 config: Config{
9429 MaxVersion: VersionTLS13,
9430 // P-384 requires HelloRetryRequest in BoringSSL.
9431 CurvePreferences: []CurveID{CurveP384},
9432 Bugs: ProtocolBugs{
9433 SendServerHelloVersion: 0x0305,
9434 },
9435 },
9436 shouldFail: true,
9437 expectedError: ":WRONG_VERSION_NUMBER:",
9438 })
9439
9440 testCases = append(testCases, testCase{
9441 name: "HelloRetryRequestCurveMismatch",
9442 config: Config{
9443 MaxVersion: VersionTLS13,
9444 // P-384 requires HelloRetryRequest in BoringSSL.
9445 CurvePreferences: []CurveID{CurveP384},
9446 Bugs: ProtocolBugs{
9447 // Send P-384 (correct) in the HelloRetryRequest.
9448 SendHelloRetryRequestCurve: CurveP384,
9449 // But send P-256 in the ServerHello.
9450 SendCurve: CurveP256,
9451 },
9452 },
9453 shouldFail: true,
9454 expectedError: ":WRONG_CURVE:",
9455 })
9456
9457 // Test the server selecting a curve that requires a HelloRetryRequest
9458 // without sending it.
9459 testCases = append(testCases, testCase{
9460 name: "SkipHelloRetryRequest",
9461 config: Config{
9462 MaxVersion: VersionTLS13,
9463 // P-384 requires HelloRetryRequest in BoringSSL.
9464 CurvePreferences: []CurveID{CurveP384},
9465 Bugs: ProtocolBugs{
9466 SkipHelloRetryRequest: true,
9467 },
9468 },
9469 shouldFail: true,
9470 expectedError: ":WRONG_CURVE:",
9471 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009472
9473 testCases = append(testCases, testCase{
9474 name: "TLS13-RequestContextInHandshake",
9475 config: Config{
9476 MaxVersion: VersionTLS13,
9477 MinVersion: VersionTLS13,
9478 ClientAuth: RequireAnyClientCert,
9479 Bugs: ProtocolBugs{
9480 SendRequestContext: []byte("request context"),
9481 },
9482 },
9483 flags: []string{
9484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9486 },
9487 shouldFail: true,
9488 expectedError: ":DECODE_ERROR:",
9489 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009490
9491 testCases = append(testCases, testCase{
9492 testType: serverTest,
9493 name: "TLS13-TrailingKeyShareData",
9494 config: Config{
9495 MaxVersion: VersionTLS13,
9496 Bugs: ProtocolBugs{
9497 TrailingKeyShareData: true,
9498 },
9499 },
9500 shouldFail: true,
9501 expectedError: ":DECODE_ERROR:",
9502 })
David Benjamin7f78df42016-10-05 22:33:19 -04009503
9504 testCases = append(testCases, testCase{
9505 name: "TLS13-AlwaysSelectPSKIdentity",
9506 config: Config{
9507 MaxVersion: VersionTLS13,
9508 Bugs: ProtocolBugs{
9509 AlwaysSelectPSKIdentity: true,
9510 },
9511 },
9512 shouldFail: true,
9513 expectedError: ":UNEXPECTED_EXTENSION:",
9514 })
9515
9516 testCases = append(testCases, testCase{
9517 name: "TLS13-InvalidPSKIdentity",
9518 config: Config{
9519 MaxVersion: VersionTLS13,
9520 Bugs: ProtocolBugs{
9521 SelectPSKIdentityOnResume: 1,
9522 },
9523 },
9524 resumeSession: true,
9525 shouldFail: true,
9526 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9527 })
David Benjamin1286bee2016-10-07 15:25:06 -04009528
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009529 testCases = append(testCases, testCase{
9530 testType: serverTest,
9531 name: "TLS13-ExtraPSKIdentity",
9532 config: Config{
9533 MaxVersion: VersionTLS13,
9534 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009535 ExtraPSKIdentity: true,
9536 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009537 },
9538 },
9539 resumeSession: true,
9540 })
9541
David Benjamin1286bee2016-10-07 15:25:06 -04009542 // Test that unknown NewSessionTicket extensions are tolerated.
9543 testCases = append(testCases, testCase{
9544 name: "TLS13-CustomTicketExtension",
9545 config: Config{
9546 MaxVersion: VersionTLS13,
9547 Bugs: ProtocolBugs{
9548 CustomTicketExtension: "1234",
9549 },
9550 },
9551 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009552}
9553
David Benjaminabbbee12016-10-31 19:20:42 -04009554func addTLS13CipherPreferenceTests() {
9555 // Test that client preference is honored if the shim has AES hardware
9556 // and ChaCha20-Poly1305 is preferred otherwise.
9557 testCases = append(testCases, testCase{
9558 testType: serverTest,
9559 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9560 config: Config{
9561 MaxVersion: VersionTLS13,
9562 CipherSuites: []uint16{
9563 TLS_CHACHA20_POLY1305_SHA256,
9564 TLS_AES_128_GCM_SHA256,
9565 },
9566 },
9567 flags: []string{
9568 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9569 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9570 },
9571 })
9572
9573 testCases = append(testCases, testCase{
9574 testType: serverTest,
9575 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9576 config: Config{
9577 MaxVersion: VersionTLS13,
9578 CipherSuites: []uint16{
9579 TLS_AES_128_GCM_SHA256,
9580 TLS_CHACHA20_POLY1305_SHA256,
9581 },
9582 },
9583 flags: []string{
9584 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9585 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9586 },
9587 })
9588
9589 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9590 // whether it has AES hardware.
9591 testCases = append(testCases, testCase{
9592 name: "TLS13-CipherPreference-Client",
9593 config: Config{
9594 MaxVersion: VersionTLS13,
9595 // Use the client cipher order. (This is the default but
9596 // is listed to be explicit.)
9597 PreferServerCipherSuites: false,
9598 },
9599 flags: []string{
9600 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9601 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9602 },
9603 })
9604}
9605
David Benjaminf3fbade2016-09-19 13:08:16 -04009606func addPeekTests() {
9607 // Test SSL_peek works, including on empty records.
9608 testCases = append(testCases, testCase{
9609 name: "Peek-Basic",
9610 sendEmptyRecords: 1,
9611 flags: []string{"-peek-then-read"},
9612 })
9613
9614 // Test SSL_peek can drive the initial handshake.
9615 testCases = append(testCases, testCase{
9616 name: "Peek-ImplicitHandshake",
9617 flags: []string{
9618 "-peek-then-read",
9619 "-implicit-handshake",
9620 },
9621 })
9622
9623 // Test SSL_peek can discover and drive a renegotiation.
9624 testCases = append(testCases, testCase{
9625 name: "Peek-Renegotiate",
9626 config: Config{
9627 MaxVersion: VersionTLS12,
9628 },
9629 renegotiate: 1,
9630 flags: []string{
9631 "-peek-then-read",
9632 "-renegotiate-freely",
9633 "-expect-total-renegotiations", "1",
9634 },
9635 })
9636
9637 // Test SSL_peek can discover a close_notify.
9638 testCases = append(testCases, testCase{
9639 name: "Peek-Shutdown",
9640 config: Config{
9641 Bugs: ProtocolBugs{
9642 ExpectCloseNotify: true,
9643 },
9644 },
9645 flags: []string{
9646 "-peek-then-read",
9647 "-check-close-notify",
9648 },
9649 })
9650
9651 // Test SSL_peek can discover an alert.
9652 testCases = append(testCases, testCase{
9653 name: "Peek-Alert",
9654 config: Config{
9655 Bugs: ProtocolBugs{
9656 SendSpuriousAlert: alertRecordOverflow,
9657 },
9658 },
9659 flags: []string{"-peek-then-read"},
9660 shouldFail: true,
9661 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9662 })
9663
9664 // Test SSL_peek can handle KeyUpdate.
9665 testCases = append(testCases, testCase{
9666 name: "Peek-KeyUpdate",
9667 config: Config{
9668 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009669 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009670 sendKeyUpdates: 1,
9671 keyUpdateRequest: keyUpdateNotRequested,
9672 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009673 })
9674}
9675
David Benjamine6f22212016-11-08 14:28:24 -05009676func addRecordVersionTests() {
9677 for _, ver := range tlsVersions {
9678 // Test that the record version is enforced.
9679 testCases = append(testCases, testCase{
9680 name: "CheckRecordVersion-" + ver.name,
9681 config: Config{
9682 MinVersion: ver.version,
9683 MaxVersion: ver.version,
9684 Bugs: ProtocolBugs{
9685 SendRecordVersion: 0x03ff,
9686 },
9687 },
9688 shouldFail: true,
9689 expectedError: ":WRONG_VERSION_NUMBER:",
9690 })
9691
9692 // Test that the ClientHello may use any record version, for
9693 // compatibility reasons.
9694 testCases = append(testCases, testCase{
9695 testType: serverTest,
9696 name: "LooseInitialRecordVersion-" + ver.name,
9697 config: Config{
9698 MinVersion: ver.version,
9699 MaxVersion: ver.version,
9700 Bugs: ProtocolBugs{
9701 SendInitialRecordVersion: 0x03ff,
9702 },
9703 },
9704 })
9705
9706 // Test that garbage ClientHello record versions are rejected.
9707 testCases = append(testCases, testCase{
9708 testType: serverTest,
9709 name: "GarbageInitialRecordVersion-" + ver.name,
9710 config: Config{
9711 MinVersion: ver.version,
9712 MaxVersion: ver.version,
9713 Bugs: ProtocolBugs{
9714 SendInitialRecordVersion: 0xffff,
9715 },
9716 },
9717 shouldFail: true,
9718 expectedError: ":WRONG_VERSION_NUMBER:",
9719 })
9720 }
9721}
9722
David Benjamin2c516452016-11-15 10:16:54 +09009723func addCertificateTests() {
9724 // Test that a certificate chain with intermediate may be sent and
9725 // received as both client and server.
9726 for _, ver := range tlsVersions {
9727 testCases = append(testCases, testCase{
9728 testType: clientTest,
9729 name: "SendReceiveIntermediate-Client-" + ver.name,
9730 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009731 MinVersion: ver.version,
9732 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009733 Certificates: []Certificate{rsaChainCertificate},
9734 ClientAuth: RequireAnyClientCert,
9735 },
9736 expectPeerCertificate: &rsaChainCertificate,
9737 flags: []string{
9738 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9739 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9740 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9741 },
9742 })
9743
9744 testCases = append(testCases, testCase{
9745 testType: serverTest,
9746 name: "SendReceiveIntermediate-Server-" + ver.name,
9747 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009748 MinVersion: ver.version,
9749 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009750 Certificates: []Certificate{rsaChainCertificate},
9751 },
9752 expectPeerCertificate: &rsaChainCertificate,
9753 flags: []string{
9754 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9755 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9756 "-require-any-client-certificate",
9757 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9758 },
9759 })
9760 }
9761}
9762
David Benjaminbbaf3672016-11-17 10:53:09 +09009763func addRetainOnlySHA256ClientCertTests() {
9764 for _, ver := range tlsVersions {
9765 // Test that enabling
9766 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9767 // actually requesting a client certificate is a no-op.
9768 testCases = append(testCases, testCase{
9769 testType: serverTest,
9770 name: "RetainOnlySHA256-NoCert-" + ver.name,
9771 config: Config{
9772 MinVersion: ver.version,
9773 MaxVersion: ver.version,
9774 },
9775 flags: []string{
9776 "-retain-only-sha256-client-cert-initial",
9777 "-retain-only-sha256-client-cert-resume",
9778 },
9779 resumeSession: true,
9780 })
9781
9782 // Test that when retaining only a SHA-256 certificate is
9783 // enabled, the hash appears as expected.
9784 testCases = append(testCases, testCase{
9785 testType: serverTest,
9786 name: "RetainOnlySHA256-Cert-" + ver.name,
9787 config: Config{
9788 MinVersion: ver.version,
9789 MaxVersion: ver.version,
9790 Certificates: []Certificate{rsaCertificate},
9791 },
9792 flags: []string{
9793 "-verify-peer",
9794 "-retain-only-sha256-client-cert-initial",
9795 "-retain-only-sha256-client-cert-resume",
9796 "-expect-sha256-client-cert-initial",
9797 "-expect-sha256-client-cert-resume",
9798 },
9799 resumeSession: true,
9800 })
9801
9802 // Test that when the config changes from on to off, a
9803 // resumption is rejected because the server now wants the full
9804 // certificate chain.
9805 testCases = append(testCases, testCase{
9806 testType: serverTest,
9807 name: "RetainOnlySHA256-OnOff-" + ver.name,
9808 config: Config{
9809 MinVersion: ver.version,
9810 MaxVersion: ver.version,
9811 Certificates: []Certificate{rsaCertificate},
9812 },
9813 flags: []string{
9814 "-verify-peer",
9815 "-retain-only-sha256-client-cert-initial",
9816 "-expect-sha256-client-cert-initial",
9817 },
9818 resumeSession: true,
9819 expectResumeRejected: true,
9820 })
9821
9822 // Test that when the config changes from off to on, a
9823 // resumption is rejected because the server now wants just the
9824 // hash.
9825 testCases = append(testCases, testCase{
9826 testType: serverTest,
9827 name: "RetainOnlySHA256-OffOn-" + ver.name,
9828 config: Config{
9829 MinVersion: ver.version,
9830 MaxVersion: ver.version,
9831 Certificates: []Certificate{rsaCertificate},
9832 },
9833 flags: []string{
9834 "-verify-peer",
9835 "-retain-only-sha256-client-cert-resume",
9836 "-expect-sha256-client-cert-resume",
9837 },
9838 resumeSession: true,
9839 expectResumeRejected: true,
9840 })
9841 }
9842}
9843
Adam Langley7c803a62015-06-15 15:35:05 -07009844func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009845 defer wg.Done()
9846
9847 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009848 var err error
9849
David Benjaminba28dfc2016-11-15 17:47:21 +09009850 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009851 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9852 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009853 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009854 if err != nil {
9855 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9856 }
9857 break
9858 }
9859 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009860 } else if *repeatUntilFailure {
9861 for err == nil {
9862 statusChan <- statusMsg{test: test, started: true}
9863 err = runTest(test, shimPath, -1)
9864 }
9865 } else {
9866 statusChan <- statusMsg{test: test, started: true}
9867 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009868 }
Adam Langley95c29f32014-06-20 12:00:00 -07009869 statusChan <- statusMsg{test: test, err: err}
9870 }
9871}
9872
9873type statusMsg struct {
9874 test *testCase
9875 started bool
9876 err error
9877}
9878
David Benjamin5f237bc2015-02-11 17:14:15 -05009879func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009880 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009881
David Benjamin5f237bc2015-02-11 17:14:15 -05009882 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009883 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009884 if !*pipe {
9885 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009886 var erase string
9887 for i := 0; i < lineLen; i++ {
9888 erase += "\b \b"
9889 }
9890 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009891 }
9892
Adam Langley95c29f32014-06-20 12:00:00 -07009893 if msg.started {
9894 started++
9895 } else {
9896 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009897
9898 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009899 if msg.err == errUnimplemented {
9900 if *pipe {
9901 // Print each test instead of a status line.
9902 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9903 }
9904 unimplemented++
9905 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9906 } else {
9907 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9908 failed++
9909 testOutput.addResult(msg.test.name, "FAIL")
9910 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009911 } else {
9912 if *pipe {
9913 // Print each test instead of a status line.
9914 fmt.Printf("PASSED (%s)\n", msg.test.name)
9915 }
9916 testOutput.addResult(msg.test.name, "PASS")
9917 }
Adam Langley95c29f32014-06-20 12:00:00 -07009918 }
9919
David Benjamin5f237bc2015-02-11 17:14:15 -05009920 if !*pipe {
9921 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009922 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009923 lineLen = len(line)
9924 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009925 }
Adam Langley95c29f32014-06-20 12:00:00 -07009926 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009927
9928 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009929}
9930
9931func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009932 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009933 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009934 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009935
Adam Langley7c803a62015-06-15 15:35:05 -07009936 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009937 addCipherSuiteTests()
9938 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009939 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009940 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009941 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009942 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009943 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009944 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009945 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009946 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009947 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009948 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009949 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009950 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009951 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009952 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009953 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009954 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009955 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009956 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009957 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009958 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009959 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009960 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009961 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009962 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009963 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009964 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009965 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009966 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009967 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009968 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009969 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009970 addRetainOnlySHA256ClientCertTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009971
9972 var wg sync.WaitGroup
9973
Adam Langley7c803a62015-06-15 15:35:05 -07009974 statusChan := make(chan statusMsg, *numWorkers)
9975 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009976 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009977
EKRf71d7ed2016-08-06 13:25:12 -07009978 if len(*shimConfigFile) != 0 {
9979 encoded, err := ioutil.ReadFile(*shimConfigFile)
9980 if err != nil {
9981 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9982 os.Exit(1)
9983 }
9984
9985 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9986 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9987 os.Exit(1)
9988 }
9989 }
9990
David Benjamin025b3d32014-07-01 19:53:04 -04009991 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009992
Adam Langley7c803a62015-06-15 15:35:05 -07009993 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009994 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009995 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009996 }
9997
David Benjamin270f0a72016-03-17 14:41:36 -04009998 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009999 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010000 matched := true
10001 if len(*testToRun) != 0 {
10002 var err error
10003 matched, err = filepath.Match(*testToRun, testCases[i].name)
10004 if err != nil {
10005 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10006 os.Exit(1)
10007 }
10008 }
10009
EKRf71d7ed2016-08-06 13:25:12 -070010010 if !*includeDisabled {
10011 for pattern := range shimConfig.DisabledTests {
10012 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10013 if err != nil {
10014 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10015 os.Exit(1)
10016 }
10017
10018 if isDisabled {
10019 matched = false
10020 break
10021 }
10022 }
10023 }
10024
David Benjamin17e12922016-07-28 18:04:43 -040010025 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010026 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010027 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010028
10029 // Only run one test if repeating until failure.
10030 if *repeatUntilFailure {
10031 break
10032 }
Adam Langley95c29f32014-06-20 12:00:00 -070010033 }
10034 }
David Benjamin17e12922016-07-28 18:04:43 -040010035
David Benjamin270f0a72016-03-17 14:41:36 -040010036 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010037 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010038 os.Exit(1)
10039 }
Adam Langley95c29f32014-06-20 12:00:00 -070010040
10041 close(testChan)
10042 wg.Wait()
10043 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010044 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010045
10046 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010047
10048 if *jsonOutput != "" {
10049 if err := testOutput.writeTo(*jsonOutput); err != nil {
10050 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10051 }
10052 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010053
EKR842ae6c2016-07-27 09:22:05 +020010054 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10055 os.Exit(1)
10056 }
10057
10058 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010059 os.Exit(1)
10060 }
Adam Langley95c29f32014-06-20 12:00:00 -070010061}