blob: 8a18e8f03f3d5c836ce0ddcff43a28e93f42a487 [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}
172var testSCTList = []byte{5, 6, 7, 8}
173
Steven Valdeza833c352016-11-01 13:39:36 -0400174var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
175var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, 4}, testSCTList...)
176
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"},
4855 },
4856 flags: []string{
4857 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4858 "-select-alpn", "foo",
4859 "-async",
4860 },
4861 expectedNextProto: "foo",
4862 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004863 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004864 })
4865
David Benjamin97d17d92016-07-14 16:12:00 -04004866 var emptyString string
4867 testCases = append(testCases, testCase{
4868 testType: clientTest,
4869 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4870 config: Config{
4871 MaxVersion: ver.version,
4872 NextProtos: []string{""},
4873 Bugs: ProtocolBugs{
4874 // A server returning an empty ALPN protocol
4875 // should be rejected.
4876 ALPNProtocol: &emptyString,
4877 },
4878 },
4879 flags: []string{
4880 "-advertise-alpn", "\x03foo",
4881 },
4882 shouldFail: true,
4883 expectedError: ":PARSE_TLSEXT:",
4884 })
4885 testCases = append(testCases, testCase{
4886 testType: serverTest,
4887 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4888 config: Config{
4889 MaxVersion: ver.version,
4890 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004891 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004892 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004893 },
David Benjamin97d17d92016-07-14 16:12:00 -04004894 flags: []string{
4895 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004896 },
David Benjamin97d17d92016-07-14 16:12:00 -04004897 shouldFail: true,
4898 expectedError: ":PARSE_TLSEXT:",
4899 })
4900
4901 // Test NPN and the interaction with ALPN.
4902 if ver.version < VersionTLS13 {
4903 // Test that the server prefers ALPN over NPN.
4904 testCases = append(testCases, testCase{
4905 testType: serverTest,
4906 name: "ALPNServer-Preferred-" + ver.name,
4907 config: Config{
4908 MaxVersion: ver.version,
4909 NextProtos: []string{"foo", "bar", "baz"},
4910 },
4911 flags: []string{
4912 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4913 "-select-alpn", "foo",
4914 "-advertise-npn", "\x03foo\x03bar\x03baz",
4915 },
4916 expectedNextProto: "foo",
4917 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004918 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004919 })
4920 testCases = append(testCases, testCase{
4921 testType: serverTest,
4922 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4923 config: Config{
4924 MaxVersion: ver.version,
4925 NextProtos: []string{"foo", "bar", "baz"},
4926 Bugs: ProtocolBugs{
4927 SwapNPNAndALPN: true,
4928 },
4929 },
4930 flags: []string{
4931 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4932 "-select-alpn", "foo",
4933 "-advertise-npn", "\x03foo\x03bar\x03baz",
4934 },
4935 expectedNextProto: "foo",
4936 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004937 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004938 })
4939
4940 // Test that negotiating both NPN and ALPN is forbidden.
4941 testCases = append(testCases, testCase{
4942 name: "NegotiateALPNAndNPN-" + ver.name,
4943 config: Config{
4944 MaxVersion: ver.version,
4945 NextProtos: []string{"foo", "bar", "baz"},
4946 Bugs: ProtocolBugs{
4947 NegotiateALPNAndNPN: true,
4948 },
4949 },
4950 flags: []string{
4951 "-advertise-alpn", "\x03foo",
4952 "-select-next-proto", "foo",
4953 },
4954 shouldFail: true,
4955 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4956 })
4957 testCases = append(testCases, testCase{
4958 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4959 config: Config{
4960 MaxVersion: ver.version,
4961 NextProtos: []string{"foo", "bar", "baz"},
4962 Bugs: ProtocolBugs{
4963 NegotiateALPNAndNPN: true,
4964 SwapNPNAndALPN: true,
4965 },
4966 },
4967 flags: []string{
4968 "-advertise-alpn", "\x03foo",
4969 "-select-next-proto", "foo",
4970 },
4971 shouldFail: true,
4972 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4973 })
4974
4975 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4976 testCases = append(testCases, testCase{
4977 name: "DisableNPN-" + ver.name,
4978 config: Config{
4979 MaxVersion: ver.version,
4980 NextProtos: []string{"foo"},
4981 },
4982 flags: []string{
4983 "-select-next-proto", "foo",
4984 "-disable-npn",
4985 },
4986 expectNoNextProto: true,
4987 })
4988 }
4989
4990 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004991
4992 // Resume with a corrupt ticket.
4993 testCases = append(testCases, testCase{
4994 testType: serverTest,
4995 name: "CorruptTicket-" + ver.name,
4996 config: Config{
4997 MaxVersion: ver.version,
4998 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004999 FilterTicket: func(in []byte) ([]byte, error) {
5000 in[len(in)-1] ^= 1
5001 return in, nil
5002 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005003 },
5004 },
5005 resumeSession: true,
5006 expectResumeRejected: true,
5007 })
5008 // Test the ticket callback, with and without renewal.
5009 testCases = append(testCases, testCase{
5010 testType: serverTest,
5011 name: "TicketCallback-" + ver.name,
5012 config: Config{
5013 MaxVersion: ver.version,
5014 },
5015 resumeSession: true,
5016 flags: []string{"-use-ticket-callback"},
5017 })
5018 testCases = append(testCases, testCase{
5019 testType: serverTest,
5020 name: "TicketCallback-Renew-" + ver.name,
5021 config: Config{
5022 MaxVersion: ver.version,
5023 Bugs: ProtocolBugs{
5024 ExpectNewTicket: true,
5025 },
5026 },
5027 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5028 resumeSession: true,
5029 })
5030
5031 // Test that the ticket callback is only called once when everything before
5032 // it in the ClientHello is asynchronous. This corrupts the ticket so
5033 // certificate selection callbacks run.
5034 testCases = append(testCases, testCase{
5035 testType: serverTest,
5036 name: "TicketCallback-SingleCall-" + ver.name,
5037 config: Config{
5038 MaxVersion: ver.version,
5039 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005040 FilterTicket: func(in []byte) ([]byte, error) {
5041 in[len(in)-1] ^= 1
5042 return in, nil
5043 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005044 },
5045 },
5046 resumeSession: true,
5047 expectResumeRejected: true,
5048 flags: []string{
5049 "-use-ticket-callback",
5050 "-async",
5051 },
5052 })
5053
5054 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005055 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005056 testCases = append(testCases, testCase{
5057 testType: serverTest,
5058 name: "OversizedSessionId-" + ver.name,
5059 config: Config{
5060 MaxVersion: ver.version,
5061 Bugs: ProtocolBugs{
5062 OversizedSessionId: true,
5063 },
5064 },
5065 resumeSession: true,
5066 shouldFail: true,
5067 expectedError: ":DECODE_ERROR:",
5068 })
5069 }
5070
5071 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5072 // are ignored.
5073 if ver.hasDTLS {
5074 testCases = append(testCases, testCase{
5075 protocol: dtls,
5076 name: "SRTP-Client-" + ver.name,
5077 config: Config{
5078 MaxVersion: ver.version,
5079 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5080 },
5081 flags: []string{
5082 "-srtp-profiles",
5083 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5084 },
5085 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5086 })
5087 testCases = append(testCases, testCase{
5088 protocol: dtls,
5089 testType: serverTest,
5090 name: "SRTP-Server-" + ver.name,
5091 config: Config{
5092 MaxVersion: ver.version,
5093 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5094 },
5095 flags: []string{
5096 "-srtp-profiles",
5097 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5098 },
5099 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5100 })
5101 // Test that the MKI is ignored.
5102 testCases = append(testCases, testCase{
5103 protocol: dtls,
5104 testType: serverTest,
5105 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5106 config: Config{
5107 MaxVersion: ver.version,
5108 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5109 Bugs: ProtocolBugs{
5110 SRTPMasterKeyIdentifer: "bogus",
5111 },
5112 },
5113 flags: []string{
5114 "-srtp-profiles",
5115 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5116 },
5117 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5118 })
5119 // Test that SRTP isn't negotiated on the server if there were
5120 // no matching profiles.
5121 testCases = append(testCases, testCase{
5122 protocol: dtls,
5123 testType: serverTest,
5124 name: "SRTP-Server-NoMatch-" + ver.name,
5125 config: Config{
5126 MaxVersion: ver.version,
5127 SRTPProtectionProfiles: []uint16{100, 101, 102},
5128 },
5129 flags: []string{
5130 "-srtp-profiles",
5131 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5132 },
5133 expectedSRTPProtectionProfile: 0,
5134 })
5135 // Test that the server returning an invalid SRTP profile is
5136 // flagged as an error by the client.
5137 testCases = append(testCases, testCase{
5138 protocol: dtls,
5139 name: "SRTP-Client-NoMatch-" + ver.name,
5140 config: Config{
5141 MaxVersion: ver.version,
5142 Bugs: ProtocolBugs{
5143 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5144 },
5145 },
5146 flags: []string{
5147 "-srtp-profiles",
5148 "SRTP_AES128_CM_SHA1_80",
5149 },
5150 shouldFail: true,
5151 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5152 })
5153 }
5154
5155 // Test SCT list.
5156 testCases = append(testCases, testCase{
5157 name: "SignedCertificateTimestampList-Client-" + ver.name,
5158 testType: clientTest,
5159 config: Config{
5160 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005161 },
David Benjamin97d17d92016-07-14 16:12:00 -04005162 flags: []string{
5163 "-enable-signed-cert-timestamps",
5164 "-expect-signed-cert-timestamps",
5165 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005166 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005167 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005168 })
David Benjamindaa88502016-10-04 16:32:16 -04005169
5170 // The SCT extension did not specify that it must only be sent on resumption as it
5171 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005172 testCases = append(testCases, testCase{
5173 name: "SendSCTListOnResume-" + ver.name,
5174 config: Config{
5175 MaxVersion: ver.version,
5176 Bugs: ProtocolBugs{
5177 SendSCTListOnResume: []byte("bogus"),
5178 },
David Benjamind98452d2015-06-16 14:16:23 -04005179 },
David Benjamin97d17d92016-07-14 16:12:00 -04005180 flags: []string{
5181 "-enable-signed-cert-timestamps",
5182 "-expect-signed-cert-timestamps",
5183 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005184 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005185 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005186 })
David Benjamindaa88502016-10-04 16:32:16 -04005187
David Benjamin97d17d92016-07-14 16:12:00 -04005188 testCases = append(testCases, testCase{
5189 name: "SignedCertificateTimestampList-Server-" + ver.name,
5190 testType: serverTest,
5191 config: Config{
5192 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005193 },
David Benjamin97d17d92016-07-14 16:12:00 -04005194 flags: []string{
5195 "-signed-cert-timestamps",
5196 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005197 },
David Benjamin97d17d92016-07-14 16:12:00 -04005198 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005199 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005200 })
David Benjamin53210cb2016-11-16 09:01:48 +09005201
5202 // Test that certificate-related extensions are not sent unsolicited.
5203 testCases = append(testCases, testCase{
5204 testType: serverTest,
5205 name: "UnsolicitedCertificateExtensions-" + ver.name,
5206 config: Config{
5207 MaxVersion: ver.version,
5208 Bugs: ProtocolBugs{
5209 NoOCSPStapling: true,
5210 NoSignedCertificateTimestamps: true,
5211 },
5212 },
5213 flags: []string{
5214 "-ocsp-response",
5215 base64.StdEncoding.EncodeToString(testOCSPResponse),
5216 "-signed-cert-timestamps",
5217 base64.StdEncoding.EncodeToString(testSCTList),
5218 },
5219 })
David Benjamin97d17d92016-07-14 16:12:00 -04005220 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005221
Paul Lietar4fac72e2015-09-09 13:44:55 +01005222 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005223 testType: clientTest,
5224 name: "ClientHelloPadding",
5225 config: Config{
5226 Bugs: ProtocolBugs{
5227 RequireClientHelloSize: 512,
5228 },
5229 },
5230 // This hostname just needs to be long enough to push the
5231 // ClientHello into F5's danger zone between 256 and 511 bytes
5232 // long.
5233 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5234 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005235
5236 // Extensions should not function in SSL 3.0.
5237 testCases = append(testCases, testCase{
5238 testType: serverTest,
5239 name: "SSLv3Extensions-NoALPN",
5240 config: Config{
5241 MaxVersion: VersionSSL30,
5242 NextProtos: []string{"foo", "bar", "baz"},
5243 },
5244 flags: []string{
5245 "-select-alpn", "foo",
5246 },
5247 expectNoNextProto: true,
5248 })
5249
5250 // Test session tickets separately as they follow a different codepath.
5251 testCases = append(testCases, testCase{
5252 testType: serverTest,
5253 name: "SSLv3Extensions-NoTickets",
5254 config: Config{
5255 MaxVersion: VersionSSL30,
5256 Bugs: ProtocolBugs{
5257 // Historically, session tickets in SSL 3.0
5258 // failed in different ways depending on whether
5259 // the client supported renegotiation_info.
5260 NoRenegotiationInfo: true,
5261 },
5262 },
5263 resumeSession: true,
5264 })
5265 testCases = append(testCases, testCase{
5266 testType: serverTest,
5267 name: "SSLv3Extensions-NoTickets2",
5268 config: Config{
5269 MaxVersion: VersionSSL30,
5270 },
5271 resumeSession: true,
5272 })
5273
5274 // But SSL 3.0 does send and process renegotiation_info.
5275 testCases = append(testCases, testCase{
5276 testType: serverTest,
5277 name: "SSLv3Extensions-RenegotiationInfo",
5278 config: Config{
5279 MaxVersion: VersionSSL30,
5280 Bugs: ProtocolBugs{
5281 RequireRenegotiationInfo: true,
5282 },
5283 },
5284 })
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5288 config: Config{
5289 MaxVersion: VersionSSL30,
5290 Bugs: ProtocolBugs{
5291 NoRenegotiationInfo: true,
5292 SendRenegotiationSCSV: true,
5293 RequireRenegotiationInfo: true,
5294 },
5295 },
5296 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005297
5298 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5299 // in ServerHello.
5300 testCases = append(testCases, testCase{
5301 name: "NPN-Forbidden-TLS13",
5302 config: Config{
5303 MaxVersion: VersionTLS13,
5304 NextProtos: []string{"foo"},
5305 Bugs: ProtocolBugs{
5306 NegotiateNPNAtAllVersions: true,
5307 },
5308 },
5309 flags: []string{"-select-next-proto", "foo"},
5310 shouldFail: true,
5311 expectedError: ":ERROR_PARSING_EXTENSION:",
5312 })
5313 testCases = append(testCases, testCase{
5314 name: "EMS-Forbidden-TLS13",
5315 config: Config{
5316 MaxVersion: VersionTLS13,
5317 Bugs: ProtocolBugs{
5318 NegotiateEMSAtAllVersions: true,
5319 },
5320 },
5321 shouldFail: true,
5322 expectedError: ":ERROR_PARSING_EXTENSION:",
5323 })
5324 testCases = append(testCases, testCase{
5325 name: "RenegotiationInfo-Forbidden-TLS13",
5326 config: Config{
5327 MaxVersion: VersionTLS13,
5328 Bugs: ProtocolBugs{
5329 NegotiateRenegotiationInfoAtAllVersions: true,
5330 },
5331 },
5332 shouldFail: true,
5333 expectedError: ":ERROR_PARSING_EXTENSION:",
5334 })
5335 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005336 name: "Ticket-Forbidden-TLS13",
5337 config: Config{
5338 MaxVersion: VersionTLS12,
5339 },
5340 resumeConfig: &Config{
5341 MaxVersion: VersionTLS13,
5342 Bugs: ProtocolBugs{
5343 AdvertiseTicketExtension: true,
5344 },
5345 },
5346 resumeSession: true,
5347 shouldFail: true,
5348 expectedError: ":ERROR_PARSING_EXTENSION:",
5349 })
5350
5351 // Test that illegal extensions in TLS 1.3 are declined by the server if
5352 // offered in ClientHello. The runner's server will fail if this occurs,
5353 // so we exercise the offering path. (EMS and Renegotiation Info are
5354 // implicit in every test.)
5355 testCases = append(testCases, testCase{
5356 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005357 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005358 config: Config{
5359 MaxVersion: VersionTLS13,
5360 NextProtos: []string{"bar"},
5361 },
5362 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5363 })
David Benjamin196df5b2016-09-21 16:23:27 -04005364
David Benjamindaa88502016-10-04 16:32:16 -04005365 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5366 // tolerated.
5367 testCases = append(testCases, testCase{
5368 name: "SendOCSPResponseOnResume-TLS12",
5369 config: Config{
5370 MaxVersion: VersionTLS12,
5371 Bugs: ProtocolBugs{
5372 SendOCSPResponseOnResume: []byte("bogus"),
5373 },
5374 },
5375 flags: []string{
5376 "-enable-ocsp-stapling",
5377 "-expect-ocsp-response",
5378 base64.StdEncoding.EncodeToString(testOCSPResponse),
5379 },
5380 resumeSession: true,
5381 })
5382
David Benjamindaa88502016-10-04 16:32:16 -04005383 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005384 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005385 config: Config{
5386 MaxVersion: VersionTLS13,
5387 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005388 SendExtensionOnCertificate: testOCSPExtension,
5389 },
5390 },
5391 shouldFail: true,
5392 expectedError: ":UNEXPECTED_EXTENSION:",
5393 })
5394
5395 testCases = append(testCases, testCase{
5396 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5397 config: Config{
5398 MaxVersion: VersionTLS13,
5399 Bugs: ProtocolBugs{
5400 SendExtensionOnCertificate: testSCTExtension,
5401 },
5402 },
5403 shouldFail: true,
5404 expectedError: ":UNEXPECTED_EXTENSION:",
5405 })
5406
5407 // Test that extensions on client certificates are never accepted.
5408 testCases = append(testCases, testCase{
5409 name: "SendExtensionOnClientCertificate-TLS13",
5410 testType: serverTest,
5411 config: Config{
5412 MaxVersion: VersionTLS13,
5413 Certificates: []Certificate{rsaCertificate},
5414 Bugs: ProtocolBugs{
5415 SendExtensionOnCertificate: testOCSPExtension,
5416 },
5417 },
5418 flags: []string{
5419 "-enable-ocsp-stapling",
5420 "-require-any-client-certificate",
5421 },
5422 shouldFail: true,
5423 expectedError: ":UNEXPECTED_EXTENSION:",
5424 })
5425
5426 testCases = append(testCases, testCase{
5427 name: "SendUnknownExtensionOnCertificate-TLS13",
5428 config: Config{
5429 MaxVersion: VersionTLS13,
5430 Bugs: ProtocolBugs{
5431 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5432 },
5433 },
5434 shouldFail: true,
5435 expectedError: ":UNEXPECTED_EXTENSION:",
5436 })
5437
5438 // Test that extensions on intermediates are allowed but ignored.
5439 testCases = append(testCases, testCase{
5440 name: "IgnoreExtensionsOnIntermediates-TLS13",
5441 config: Config{
5442 MaxVersion: VersionTLS13,
5443 Certificates: []Certificate{rsaChainCertificate},
5444 Bugs: ProtocolBugs{
5445 // Send different values on the intermediate. This tests
5446 // the intermediate's extensions do not override the
5447 // leaf's.
5448 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
5449 SendSCTOnIntermediates: []byte{1, 3, 3, 7},
David Benjamindaa88502016-10-04 16:32:16 -04005450 },
5451 },
5452 flags: []string{
5453 "-enable-ocsp-stapling",
5454 "-expect-ocsp-response",
5455 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005456 "-enable-signed-cert-timestamps",
5457 "-expect-signed-cert-timestamps",
5458 base64.StdEncoding.EncodeToString(testSCTList),
5459 },
5460 resumeSession: true,
5461 })
5462
5463 // Test that extensions are not sent on intermediates when configured
5464 // only for a leaf.
5465 testCases = append(testCases, testCase{
5466 testType: serverTest,
5467 name: "SendNoExtensionsOnIntermediate-TLS13",
5468 config: Config{
5469 MaxVersion: VersionTLS13,
5470 Bugs: ProtocolBugs{
5471 ExpectNoExtensionsOnIntermediate: true,
5472 },
5473 },
5474 flags: []string{
5475 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5476 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5477 "-ocsp-response",
5478 base64.StdEncoding.EncodeToString(testOCSPResponse),
5479 "-signed-cert-timestamps",
5480 base64.StdEncoding.EncodeToString(testSCTList),
5481 },
5482 })
5483
5484 // Test that extensions are not sent on client certificates.
5485 testCases = append(testCases, testCase{
5486 name: "SendNoClientCertificateExtensions-TLS13",
5487 config: Config{
5488 MaxVersion: VersionTLS13,
5489 ClientAuth: RequireAnyClientCert,
5490 },
5491 flags: []string{
5492 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5493 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5494 "-ocsp-response",
5495 base64.StdEncoding.EncodeToString(testOCSPResponse),
5496 "-signed-cert-timestamps",
5497 base64.StdEncoding.EncodeToString(testSCTList),
5498 },
5499 })
5500
5501 testCases = append(testCases, testCase{
5502 name: "SendDuplicateExtensionsOnCerts-TLS13",
5503 config: Config{
5504 MaxVersion: VersionTLS13,
5505 Bugs: ProtocolBugs{
5506 SendDuplicateCertExtensions: true,
5507 },
5508 },
5509 flags: []string{
5510 "-enable-ocsp-stapling",
5511 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005512 },
5513 resumeSession: true,
5514 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005515 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005516 })
David Benjamine78bfde2014-09-06 12:45:15 -04005517}
5518
David Benjamin01fe8202014-09-24 15:21:44 -04005519func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005520 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005521 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005522 // SSL 3.0 does not have tickets and TLS 1.3 does not
5523 // have session IDs, so skip their cross-resumption
5524 // tests.
5525 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5526 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5527 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005528 }
5529
David Benjamin8b8c0062014-11-23 02:47:52 -05005530 protocols := []protocol{tls}
5531 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5532 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005533 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005534 for _, protocol := range protocols {
5535 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5536 if protocol == dtls {
5537 suffix += "-DTLS"
5538 }
5539
David Benjaminece3de92015-03-16 18:02:20 -04005540 if sessionVers.version == resumeVers.version {
5541 testCases = append(testCases, testCase{
5542 protocol: protocol,
5543 name: "Resume-Client" + suffix,
5544 resumeSession: true,
5545 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005546 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005547 Bugs: ProtocolBugs{
5548 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5549 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5550 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005551 },
David Benjaminece3de92015-03-16 18:02:20 -04005552 expectedVersion: sessionVers.version,
5553 expectedResumeVersion: resumeVers.version,
5554 })
5555 } else {
David Benjamin405da482016-08-08 17:25:07 -04005556 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5557
5558 // Offering a TLS 1.3 session sends an empty session ID, so
5559 // there is no way to convince a non-lookahead client the
5560 // session was resumed. It will appear to the client that a
5561 // stray ChangeCipherSpec was sent.
5562 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5563 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005564 }
5565
David Benjaminece3de92015-03-16 18:02:20 -04005566 testCases = append(testCases, testCase{
5567 protocol: protocol,
5568 name: "Resume-Client-Mismatch" + suffix,
5569 resumeSession: true,
5570 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005571 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005572 },
David Benjaminece3de92015-03-16 18:02:20 -04005573 expectedVersion: sessionVers.version,
5574 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005575 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005576 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005577 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005578 },
5579 },
5580 expectedResumeVersion: resumeVers.version,
5581 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005582 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005583 })
5584 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005585
5586 testCases = append(testCases, testCase{
5587 protocol: protocol,
5588 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005589 resumeSession: true,
5590 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005591 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005592 },
5593 expectedVersion: sessionVers.version,
5594 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005595 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005596 },
5597 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005598 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005599 expectedResumeVersion: resumeVers.version,
5600 })
5601
David Benjamin8b8c0062014-11-23 02:47:52 -05005602 testCases = append(testCases, testCase{
5603 protocol: protocol,
5604 testType: serverTest,
5605 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005606 resumeSession: true,
5607 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005608 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005609 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005610 expectedVersion: sessionVers.version,
5611 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005612 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005613 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005614 Bugs: ProtocolBugs{
5615 SendBothTickets: true,
5616 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005617 },
5618 expectedResumeVersion: resumeVers.version,
5619 })
5620 }
David Benjamin01fe8202014-09-24 15:21:44 -04005621 }
5622 }
David Benjaminece3de92015-03-16 18:02:20 -04005623
David Benjamin4199b0d2016-11-01 13:58:25 -04005624 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005625 testCases = append(testCases, testCase{
5626 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005627 name: "ShimTicketRewritable",
5628 resumeSession: true,
5629 config: Config{
5630 MaxVersion: VersionTLS12,
5631 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5632 Bugs: ProtocolBugs{
5633 FilterTicket: func(in []byte) ([]byte, error) {
5634 in, err := SetShimTicketVersion(in, VersionTLS12)
5635 if err != nil {
5636 return nil, err
5637 }
5638 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5639 },
5640 },
5641 },
5642 flags: []string{
5643 "-ticket-key",
5644 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5645 },
5646 })
5647
5648 // Resumptions are declined if the version does not match.
5649 testCases = append(testCases, testCase{
5650 testType: serverTest,
5651 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005652 resumeSession: true,
5653 config: Config{
5654 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005655 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005656 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005657 FilterTicket: func(in []byte) ([]byte, error) {
5658 return SetShimTicketVersion(in, VersionTLS13)
5659 },
5660 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005661 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005662 flags: []string{
5663 "-ticket-key",
5664 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5665 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005666 expectResumeRejected: true,
5667 })
5668
5669 testCases = append(testCases, testCase{
5670 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005671 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005672 resumeSession: true,
5673 config: Config{
5674 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005675 Bugs: ProtocolBugs{
5676 FilterTicket: func(in []byte) ([]byte, error) {
5677 return SetShimTicketVersion(in, VersionTLS12)
5678 },
5679 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005680 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005681 flags: []string{
5682 "-ticket-key",
5683 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5684 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005685 expectResumeRejected: true,
5686 })
5687
David Benjamin4199b0d2016-11-01 13:58:25 -04005688 // Resumptions are declined if the cipher is invalid or disabled.
5689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "Resume-Server-DeclineBadCipher",
5692 resumeSession: true,
5693 config: Config{
5694 MaxVersion: VersionTLS12,
5695 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005696 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005697 FilterTicket: func(in []byte) ([]byte, error) {
5698 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5699 },
5700 },
5701 },
5702 flags: []string{
5703 "-ticket-key",
5704 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5705 },
5706 expectResumeRejected: true,
5707 })
5708
5709 testCases = append(testCases, testCase{
5710 testType: serverTest,
5711 name: "Resume-Server-DeclineBadCipher-2",
5712 resumeSession: true,
5713 config: Config{
5714 MaxVersion: VersionTLS12,
5715 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005716 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005717 FilterTicket: func(in []byte) ([]byte, error) {
5718 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5719 },
5720 },
5721 },
5722 flags: []string{
5723 "-cipher", "AES128",
5724 "-ticket-key",
5725 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5726 },
5727 expectResumeRejected: true,
5728 })
5729
5730 testCases = append(testCases, testCase{
5731 testType: serverTest,
5732 name: "Resume-Server-DeclineBadCipher-TLS13",
5733 resumeSession: true,
5734 config: Config{
5735 MaxVersion: VersionTLS13,
5736 Bugs: ProtocolBugs{
5737 FilterTicket: func(in []byte) ([]byte, error) {
5738 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5739 },
5740 },
5741 },
5742 flags: []string{
5743 "-ticket-key",
5744 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5745 },
5746 expectResumeRejected: true,
5747 })
5748
David Benjamin75f99142016-11-12 12:36:06 +09005749 // Clients must not advertise a session without also advertising the
5750 // cipher.
5751 testCases = append(testCases, testCase{
5752 testType: serverTest,
5753 name: "Resume-Server-UnofferedCipher",
5754 resumeSession: true,
5755 config: Config{
5756 MaxVersion: VersionTLS12,
5757 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5758 },
5759 resumeConfig: &Config{
5760 MaxVersion: VersionTLS12,
5761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5762 Bugs: ProtocolBugs{
5763 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5764 },
5765 },
5766 shouldFail: true,
5767 expectedError: ":REQUIRED_CIPHER_MISSING:",
5768 })
5769
5770 testCases = append(testCases, testCase{
5771 testType: serverTest,
5772 name: "Resume-Server-UnofferedCipher-TLS13",
5773 resumeSession: true,
5774 config: Config{
5775 MaxVersion: VersionTLS13,
5776 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5777 },
5778 resumeConfig: &Config{
5779 MaxVersion: VersionTLS13,
5780 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5781 Bugs: ProtocolBugs{
5782 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5783 },
5784 },
5785 shouldFail: true,
5786 expectedError: ":REQUIRED_CIPHER_MISSING:",
5787 })
5788
David Benjamin4199b0d2016-11-01 13:58:25 -04005789 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005790 testCases = append(testCases, testCase{
5791 name: "Resume-Client-CipherMismatch",
5792 resumeSession: true,
5793 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005794 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005795 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5796 },
5797 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005798 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005799 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5800 Bugs: ProtocolBugs{
5801 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5802 },
5803 },
5804 shouldFail: true,
5805 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5806 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005807
5808 testCases = append(testCases, testCase{
5809 name: "Resume-Client-CipherMismatch-TLS13",
5810 resumeSession: true,
5811 config: Config{
5812 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005813 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005814 },
5815 resumeConfig: &Config{
5816 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005817 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005818 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005819 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005820 },
5821 },
5822 shouldFail: true,
5823 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5824 })
Steven Valdeza833c352016-11-01 13:39:36 -04005825
5826 testCases = append(testCases, testCase{
5827 testType: serverTest,
5828 name: "Resume-Server-BinderWrongLength",
5829 resumeSession: true,
5830 config: Config{
5831 MaxVersion: VersionTLS13,
5832 Bugs: ProtocolBugs{
5833 SendShortPSKBinder: true,
5834 },
5835 },
5836 shouldFail: true,
5837 expectedLocalError: "remote error: error decrypting message",
5838 expectedError: ":DIGEST_CHECK_FAILED:",
5839 })
5840
5841 testCases = append(testCases, testCase{
5842 testType: serverTest,
5843 name: "Resume-Server-NoPSKBinder",
5844 resumeSession: true,
5845 config: Config{
5846 MaxVersion: VersionTLS13,
5847 Bugs: ProtocolBugs{
5848 SendNoPSKBinder: true,
5849 },
5850 },
5851 shouldFail: true,
5852 expectedLocalError: "remote error: error decoding message",
5853 expectedError: ":DECODE_ERROR:",
5854 })
5855
5856 testCases = append(testCases, testCase{
5857 testType: serverTest,
5858 name: "Resume-Server-InvalidPSKBinder",
5859 resumeSession: true,
5860 config: Config{
5861 MaxVersion: VersionTLS13,
5862 Bugs: ProtocolBugs{
5863 SendInvalidPSKBinder: true,
5864 },
5865 },
5866 shouldFail: true,
5867 expectedLocalError: "remote error: error decrypting message",
5868 expectedError: ":DIGEST_CHECK_FAILED:",
5869 })
5870
5871 testCases = append(testCases, testCase{
5872 testType: serverTest,
5873 name: "Resume-Server-PSKBinderFirstExtension",
5874 resumeSession: true,
5875 config: Config{
5876 MaxVersion: VersionTLS13,
5877 Bugs: ProtocolBugs{
5878 PSKBinderFirst: true,
5879 },
5880 },
5881 shouldFail: true,
5882 expectedLocalError: "remote error: illegal parameter",
5883 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
5884 })
David Benjamin01fe8202014-09-24 15:21:44 -04005885}
5886
Adam Langley2ae77d22014-10-28 17:29:33 -07005887func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005888 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005889 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005890 testType: serverTest,
5891 name: "Renegotiate-Server-Forbidden",
5892 config: Config{
5893 MaxVersion: VersionTLS12,
5894 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005895 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005896 shouldFail: true,
5897 expectedError: ":NO_RENEGOTIATION:",
5898 expectedLocalError: "remote error: no renegotiation",
5899 })
Adam Langley5021b222015-06-12 18:27:58 -07005900 // The server shouldn't echo the renegotiation extension unless
5901 // requested by the client.
5902 testCases = append(testCases, testCase{
5903 testType: serverTest,
5904 name: "Renegotiate-Server-NoExt",
5905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005906 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005907 Bugs: ProtocolBugs{
5908 NoRenegotiationInfo: true,
5909 RequireRenegotiationInfo: true,
5910 },
5911 },
5912 shouldFail: true,
5913 expectedLocalError: "renegotiation extension missing",
5914 })
5915 // The renegotiation SCSV should be sufficient for the server to echo
5916 // the extension.
5917 testCases = append(testCases, testCase{
5918 testType: serverTest,
5919 name: "Renegotiate-Server-NoExt-SCSV",
5920 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005921 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005922 Bugs: ProtocolBugs{
5923 NoRenegotiationInfo: true,
5924 SendRenegotiationSCSV: true,
5925 RequireRenegotiationInfo: true,
5926 },
5927 },
5928 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005929 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005930 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005932 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005933 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005934 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005935 },
5936 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005937 renegotiate: 1,
5938 flags: []string{
5939 "-renegotiate-freely",
5940 "-expect-total-renegotiations", "1",
5941 },
David Benjamincdea40c2015-03-19 14:09:43 -04005942 })
5943 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005944 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005945 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005947 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005948 Bugs: ProtocolBugs{
5949 EmptyRenegotiationInfo: true,
5950 },
5951 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005952 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005953 shouldFail: true,
5954 expectedError: ":RENEGOTIATION_MISMATCH:",
5955 })
5956 testCases = append(testCases, testCase{
5957 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005958 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005960 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005961 Bugs: ProtocolBugs{
5962 BadRenegotiationInfo: true,
5963 },
5964 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005965 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005966 shouldFail: true,
5967 expectedError: ":RENEGOTIATION_MISMATCH:",
5968 })
5969 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005970 name: "Renegotiate-Client-Downgrade",
5971 renegotiate: 1,
5972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005973 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005974 Bugs: ProtocolBugs{
5975 NoRenegotiationInfoAfterInitial: true,
5976 },
5977 },
5978 flags: []string{"-renegotiate-freely"},
5979 shouldFail: true,
5980 expectedError: ":RENEGOTIATION_MISMATCH:",
5981 })
5982 testCases = append(testCases, testCase{
5983 name: "Renegotiate-Client-Upgrade",
5984 renegotiate: 1,
5985 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005986 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005987 Bugs: ProtocolBugs{
5988 NoRenegotiationInfoInInitial: true,
5989 },
5990 },
5991 flags: []string{"-renegotiate-freely"},
5992 shouldFail: true,
5993 expectedError: ":RENEGOTIATION_MISMATCH:",
5994 })
5995 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005996 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005997 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005998 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005999 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006000 Bugs: ProtocolBugs{
6001 NoRenegotiationInfo: true,
6002 },
6003 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006004 flags: []string{
6005 "-renegotiate-freely",
6006 "-expect-total-renegotiations", "1",
6007 },
David Benjamincff0b902015-05-15 23:09:47 -04006008 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006009
6010 // Test that the server may switch ciphers on renegotiation without
6011 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006012 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006013 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006014 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006015 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006016 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006017 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006018 },
6019 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006020 flags: []string{
6021 "-renegotiate-freely",
6022 "-expect-total-renegotiations", "1",
6023 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006024 })
6025 testCases = append(testCases, testCase{
6026 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006027 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006028 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006029 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006030 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6031 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006032 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006033 flags: []string{
6034 "-renegotiate-freely",
6035 "-expect-total-renegotiations", "1",
6036 },
David Benjaminb16346b2015-04-08 19:16:58 -04006037 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006038
6039 // Test that the server may not switch versions on renegotiation.
6040 testCases = append(testCases, testCase{
6041 name: "Renegotiate-Client-SwitchVersion",
6042 config: Config{
6043 MaxVersion: VersionTLS12,
6044 // Pick a cipher which exists at both versions.
6045 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6046 Bugs: ProtocolBugs{
6047 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006048 // Avoid failing early at the record layer.
6049 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006050 },
6051 },
6052 renegotiate: 1,
6053 flags: []string{
6054 "-renegotiate-freely",
6055 "-expect-total-renegotiations", "1",
6056 },
6057 shouldFail: true,
6058 expectedError: ":WRONG_SSL_VERSION:",
6059 })
6060
David Benjaminb16346b2015-04-08 19:16:58 -04006061 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006062 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006063 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006064 config: Config{
6065 MaxVersion: VersionTLS10,
6066 Bugs: ProtocolBugs{
6067 RequireSameRenegoClientVersion: true,
6068 },
6069 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006070 flags: []string{
6071 "-renegotiate-freely",
6072 "-expect-total-renegotiations", "1",
6073 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006074 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006075 testCases = append(testCases, testCase{
6076 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006077 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006078 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006079 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6081 NextProtos: []string{"foo"},
6082 },
6083 flags: []string{
6084 "-false-start",
6085 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006086 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006087 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006088 },
6089 shimWritesFirst: true,
6090 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006091
6092 // Client-side renegotiation controls.
6093 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006094 name: "Renegotiate-Client-Forbidden-1",
6095 config: Config{
6096 MaxVersion: VersionTLS12,
6097 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006098 renegotiate: 1,
6099 shouldFail: true,
6100 expectedError: ":NO_RENEGOTIATION:",
6101 expectedLocalError: "remote error: no renegotiation",
6102 })
6103 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006104 name: "Renegotiate-Client-Once-1",
6105 config: Config{
6106 MaxVersion: VersionTLS12,
6107 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006108 renegotiate: 1,
6109 flags: []string{
6110 "-renegotiate-once",
6111 "-expect-total-renegotiations", "1",
6112 },
6113 })
6114 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006115 name: "Renegotiate-Client-Freely-1",
6116 config: Config{
6117 MaxVersion: VersionTLS12,
6118 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006119 renegotiate: 1,
6120 flags: []string{
6121 "-renegotiate-freely",
6122 "-expect-total-renegotiations", "1",
6123 },
6124 })
6125 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006126 name: "Renegotiate-Client-Once-2",
6127 config: Config{
6128 MaxVersion: VersionTLS12,
6129 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006130 renegotiate: 2,
6131 flags: []string{"-renegotiate-once"},
6132 shouldFail: true,
6133 expectedError: ":NO_RENEGOTIATION:",
6134 expectedLocalError: "remote error: no renegotiation",
6135 })
6136 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006137 name: "Renegotiate-Client-Freely-2",
6138 config: Config{
6139 MaxVersion: VersionTLS12,
6140 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006141 renegotiate: 2,
6142 flags: []string{
6143 "-renegotiate-freely",
6144 "-expect-total-renegotiations", "2",
6145 },
6146 })
Adam Langley27a0d082015-11-03 13:34:10 -08006147 testCases = append(testCases, testCase{
6148 name: "Renegotiate-Client-NoIgnore",
6149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006150 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006151 Bugs: ProtocolBugs{
6152 SendHelloRequestBeforeEveryAppDataRecord: true,
6153 },
6154 },
6155 shouldFail: true,
6156 expectedError: ":NO_RENEGOTIATION:",
6157 })
6158 testCases = append(testCases, testCase{
6159 name: "Renegotiate-Client-Ignore",
6160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006161 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006162 Bugs: ProtocolBugs{
6163 SendHelloRequestBeforeEveryAppDataRecord: true,
6164 },
6165 },
6166 flags: []string{
6167 "-renegotiate-ignore",
6168 "-expect-total-renegotiations", "0",
6169 },
6170 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171
David Benjamin34941c02016-10-08 11:45:31 -04006172 // Renegotiation is not allowed at SSL 3.0.
6173 testCases = append(testCases, testCase{
6174 name: "Renegotiate-Client-SSL3",
6175 config: Config{
6176 MaxVersion: VersionSSL30,
6177 },
6178 renegotiate: 1,
6179 flags: []string{
6180 "-renegotiate-freely",
6181 "-expect-total-renegotiations", "1",
6182 },
6183 shouldFail: true,
6184 expectedError: ":NO_RENEGOTIATION:",
6185 expectedLocalError: "remote error: no renegotiation",
6186 })
6187
David Benjamin397c8e62016-07-08 14:14:36 -07006188 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006189 testCases = append(testCases, testCase{
6190 name: "StrayHelloRequest",
6191 config: Config{
6192 MaxVersion: VersionTLS12,
6193 Bugs: ProtocolBugs{
6194 SendHelloRequestBeforeEveryHandshakeMessage: true,
6195 },
6196 },
6197 })
6198 testCases = append(testCases, testCase{
6199 name: "StrayHelloRequest-Packed",
6200 config: Config{
6201 MaxVersion: VersionTLS12,
6202 Bugs: ProtocolBugs{
6203 PackHandshakeFlight: true,
6204 SendHelloRequestBeforeEveryHandshakeMessage: true,
6205 },
6206 },
6207 })
6208
David Benjamin12d2c482016-07-24 10:56:51 -04006209 // Test renegotiation works if HelloRequest and server Finished come in
6210 // the same record.
6211 testCases = append(testCases, testCase{
6212 name: "Renegotiate-Client-Packed",
6213 config: Config{
6214 MaxVersion: VersionTLS12,
6215 Bugs: ProtocolBugs{
6216 PackHandshakeFlight: true,
6217 PackHelloRequestWithFinished: true,
6218 },
6219 },
6220 renegotiate: 1,
6221 flags: []string{
6222 "-renegotiate-freely",
6223 "-expect-total-renegotiations", "1",
6224 },
6225 })
6226
David Benjamin397c8e62016-07-08 14:14:36 -07006227 // Renegotiation is forbidden in TLS 1.3.
6228 testCases = append(testCases, testCase{
6229 name: "Renegotiate-Client-TLS13",
6230 config: Config{
6231 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006232 Bugs: ProtocolBugs{
6233 SendHelloRequestBeforeEveryAppDataRecord: true,
6234 },
David Benjamin397c8e62016-07-08 14:14:36 -07006235 },
David Benjamin397c8e62016-07-08 14:14:36 -07006236 flags: []string{
6237 "-renegotiate-freely",
6238 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006239 shouldFail: true,
6240 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006241 })
6242
6243 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6244 testCases = append(testCases, testCase{
6245 name: "StrayHelloRequest-TLS13",
6246 config: Config{
6247 MaxVersion: VersionTLS13,
6248 Bugs: ProtocolBugs{
6249 SendHelloRequestBeforeEveryHandshakeMessage: true,
6250 },
6251 },
6252 shouldFail: true,
6253 expectedError: ":UNEXPECTED_MESSAGE:",
6254 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006255}
6256
David Benjamin5e961c12014-11-07 01:48:35 -05006257func addDTLSReplayTests() {
6258 // Test that sequence number replays are detected.
6259 testCases = append(testCases, testCase{
6260 protocol: dtls,
6261 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006262 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006263 replayWrites: true,
6264 })
6265
David Benjamin8e6db492015-07-25 18:29:23 -04006266 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006267 // than the retransmit window.
6268 testCases = append(testCases, testCase{
6269 protocol: dtls,
6270 name: "DTLS-Replay-LargeGaps",
6271 config: Config{
6272 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006273 SequenceNumberMapping: func(in uint64) uint64 {
6274 return in * 127
6275 },
David Benjamin5e961c12014-11-07 01:48:35 -05006276 },
6277 },
David Benjamin8e6db492015-07-25 18:29:23 -04006278 messageCount: 200,
6279 replayWrites: true,
6280 })
6281
6282 // Test the incoming sequence number changing non-monotonically.
6283 testCases = append(testCases, testCase{
6284 protocol: dtls,
6285 name: "DTLS-Replay-NonMonotonic",
6286 config: Config{
6287 Bugs: ProtocolBugs{
6288 SequenceNumberMapping: func(in uint64) uint64 {
6289 return in ^ 31
6290 },
6291 },
6292 },
6293 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006294 replayWrites: true,
6295 })
6296}
6297
Nick Harper60edffd2016-06-21 15:19:24 -07006298var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006299 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006300 id signatureAlgorithm
6301 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006302}{
Nick Harper60edffd2016-06-21 15:19:24 -07006303 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6304 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6305 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6306 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006307 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006308 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6309 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6310 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006311 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6312 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6313 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006314 // Tests for key types prior to TLS 1.2.
6315 {"RSA", 0, testCertRSA},
6316 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006317}
6318
Nick Harper60edffd2016-06-21 15:19:24 -07006319const fakeSigAlg1 signatureAlgorithm = 0x2a01
6320const fakeSigAlg2 signatureAlgorithm = 0xff01
6321
6322func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006323 // Not all ciphers involve a signature. Advertise a list which gives all
6324 // versions a signing cipher.
6325 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006326 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006327 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6328 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6329 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6330 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6331 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6332 }
6333
David Benjaminca3d5452016-07-14 12:51:01 -04006334 var allAlgorithms []signatureAlgorithm
6335 for _, alg := range testSignatureAlgorithms {
6336 if alg.id != 0 {
6337 allAlgorithms = append(allAlgorithms, alg.id)
6338 }
6339 }
6340
Nick Harper60edffd2016-06-21 15:19:24 -07006341 // Make sure each signature algorithm works. Include some fake values in
6342 // the list and ensure they're ignored.
6343 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006344 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006345 if (ver.version < VersionTLS12) != (alg.id == 0) {
6346 continue
6347 }
6348
6349 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6350 // or remove it in C.
6351 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006352 continue
6353 }
Nick Harper60edffd2016-06-21 15:19:24 -07006354
David Benjamin3ef76972016-10-17 17:59:54 -04006355 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006356 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006357 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006358 shouldSignFail = true
6359 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006360 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006361 // RSA-PKCS1 does not exist in TLS 1.3.
6362 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006363 shouldSignFail = true
6364 shouldVerifyFail = true
6365 }
6366
6367 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6368 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6369 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006370 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006371
6372 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006373 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006374 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006375 }
6376 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006377 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006378 }
David Benjamin000800a2014-11-14 01:43:59 -05006379
David Benjamin1fb125c2016-07-08 18:52:12 -07006380 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006381
David Benjamin7a41d372016-07-09 11:21:54 -07006382 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006383 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006384 config: Config{
6385 MaxVersion: ver.version,
6386 ClientAuth: RequireAnyClientCert,
6387 VerifySignatureAlgorithms: []signatureAlgorithm{
6388 fakeSigAlg1,
6389 alg.id,
6390 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006391 },
David Benjamin7a41d372016-07-09 11:21:54 -07006392 },
6393 flags: []string{
6394 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6395 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6396 "-enable-all-curves",
6397 },
David Benjamin3ef76972016-10-17 17:59:54 -04006398 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006399 expectedError: signError,
6400 expectedPeerSignatureAlgorithm: alg.id,
6401 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006402
David Benjamin7a41d372016-07-09 11:21:54 -07006403 testCases = append(testCases, testCase{
6404 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006405 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006406 config: Config{
6407 MaxVersion: ver.version,
6408 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6409 SignSignatureAlgorithms: []signatureAlgorithm{
6410 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006411 },
David Benjamin7a41d372016-07-09 11:21:54 -07006412 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006413 SkipECDSACurveCheck: shouldVerifyFail,
6414 IgnoreSignatureVersionChecks: shouldVerifyFail,
6415 // Some signature algorithms may not be advertised.
6416 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006417 },
David Benjamin7a41d372016-07-09 11:21:54 -07006418 },
6419 flags: []string{
6420 "-require-any-client-certificate",
6421 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6422 "-enable-all-curves",
6423 },
David Benjamin3ef76972016-10-17 17:59:54 -04006424 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006425 expectedError: verifyError,
6426 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006427
6428 testCases = append(testCases, testCase{
6429 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006430 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006431 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006432 MaxVersion: ver.version,
6433 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006434 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006435 fakeSigAlg1,
6436 alg.id,
6437 fakeSigAlg2,
6438 },
6439 },
6440 flags: []string{
6441 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6442 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6443 "-enable-all-curves",
6444 },
David Benjamin3ef76972016-10-17 17:59:54 -04006445 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006446 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006447 expectedPeerSignatureAlgorithm: alg.id,
6448 })
6449
6450 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006451 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006452 config: Config{
6453 MaxVersion: ver.version,
6454 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006455 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006456 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006457 alg.id,
6458 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006459 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006460 SkipECDSACurveCheck: shouldVerifyFail,
6461 IgnoreSignatureVersionChecks: shouldVerifyFail,
6462 // Some signature algorithms may not be advertised.
6463 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006464 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006465 },
6466 flags: []string{
6467 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6468 "-enable-all-curves",
6469 },
David Benjamin3ef76972016-10-17 17:59:54 -04006470 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006471 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006472 })
David Benjamin5208fd42016-07-13 21:43:25 -04006473
David Benjamin3ef76972016-10-17 17:59:54 -04006474 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006475 testCases = append(testCases, testCase{
6476 testType: serverTest,
6477 name: "ClientAuth-InvalidSignature" + suffix,
6478 config: Config{
6479 MaxVersion: ver.version,
6480 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6481 SignSignatureAlgorithms: []signatureAlgorithm{
6482 alg.id,
6483 },
6484 Bugs: ProtocolBugs{
6485 InvalidSignature: true,
6486 },
6487 },
6488 flags: []string{
6489 "-require-any-client-certificate",
6490 "-enable-all-curves",
6491 },
6492 shouldFail: true,
6493 expectedError: ":BAD_SIGNATURE:",
6494 })
6495
6496 testCases = append(testCases, testCase{
6497 name: "ServerAuth-InvalidSignature" + suffix,
6498 config: Config{
6499 MaxVersion: ver.version,
6500 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6501 CipherSuites: signingCiphers,
6502 SignSignatureAlgorithms: []signatureAlgorithm{
6503 alg.id,
6504 },
6505 Bugs: ProtocolBugs{
6506 InvalidSignature: true,
6507 },
6508 },
6509 flags: []string{"-enable-all-curves"},
6510 shouldFail: true,
6511 expectedError: ":BAD_SIGNATURE:",
6512 })
6513 }
David Benjaminca3d5452016-07-14 12:51:01 -04006514
David Benjamin3ef76972016-10-17 17:59:54 -04006515 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006516 testCases = append(testCases, testCase{
6517 name: "ClientAuth-Sign-Negotiate" + suffix,
6518 config: Config{
6519 MaxVersion: ver.version,
6520 ClientAuth: RequireAnyClientCert,
6521 VerifySignatureAlgorithms: allAlgorithms,
6522 },
6523 flags: []string{
6524 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6525 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6526 "-enable-all-curves",
6527 "-signing-prefs", strconv.Itoa(int(alg.id)),
6528 },
6529 expectedPeerSignatureAlgorithm: alg.id,
6530 })
6531
6532 testCases = append(testCases, testCase{
6533 testType: serverTest,
6534 name: "ServerAuth-Sign-Negotiate" + suffix,
6535 config: Config{
6536 MaxVersion: ver.version,
6537 CipherSuites: signingCiphers,
6538 VerifySignatureAlgorithms: allAlgorithms,
6539 },
6540 flags: []string{
6541 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6542 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6543 "-enable-all-curves",
6544 "-signing-prefs", strconv.Itoa(int(alg.id)),
6545 },
6546 expectedPeerSignatureAlgorithm: alg.id,
6547 })
6548 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006549 }
David Benjamin000800a2014-11-14 01:43:59 -05006550 }
6551
Nick Harper60edffd2016-06-21 15:19:24 -07006552 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006553 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006554 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006555 config: Config{
6556 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006557 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006558 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006559 signatureECDSAWithP521AndSHA512,
6560 signatureRSAPKCS1WithSHA384,
6561 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006562 },
6563 },
6564 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006565 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6566 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006567 },
Nick Harper60edffd2016-06-21 15:19:24 -07006568 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006569 })
6570
6571 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006572 name: "ClientAuth-SignatureType-TLS13",
6573 config: Config{
6574 ClientAuth: RequireAnyClientCert,
6575 MaxVersion: VersionTLS13,
6576 VerifySignatureAlgorithms: []signatureAlgorithm{
6577 signatureECDSAWithP521AndSHA512,
6578 signatureRSAPKCS1WithSHA384,
6579 signatureRSAPSSWithSHA384,
6580 signatureECDSAWithSHA1,
6581 },
6582 },
6583 flags: []string{
6584 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6585 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6586 },
6587 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6588 })
6589
6590 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006591 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006592 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006594 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006595 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006596 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006597 signatureECDSAWithP521AndSHA512,
6598 signatureRSAPKCS1WithSHA384,
6599 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006600 },
6601 },
Nick Harper60edffd2016-06-21 15:19:24 -07006602 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006603 })
6604
Steven Valdez143e8b32016-07-11 13:19:03 -04006605 testCases = append(testCases, testCase{
6606 testType: serverTest,
6607 name: "ServerAuth-SignatureType-TLS13",
6608 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006609 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006610 VerifySignatureAlgorithms: []signatureAlgorithm{
6611 signatureECDSAWithP521AndSHA512,
6612 signatureRSAPKCS1WithSHA384,
6613 signatureRSAPSSWithSHA384,
6614 signatureECDSAWithSHA1,
6615 },
6616 },
6617 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6618 })
6619
David Benjamina95e9f32016-07-08 16:28:04 -07006620 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006621 testCases = append(testCases, testCase{
6622 testType: serverTest,
6623 name: "Verify-ClientAuth-SignatureType",
6624 config: Config{
6625 MaxVersion: VersionTLS12,
6626 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006627 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006628 signatureRSAPKCS1WithSHA256,
6629 },
6630 Bugs: ProtocolBugs{
6631 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6632 },
6633 },
6634 flags: []string{
6635 "-require-any-client-certificate",
6636 },
6637 shouldFail: true,
6638 expectedError: ":WRONG_SIGNATURE_TYPE:",
6639 })
6640
6641 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006642 testType: serverTest,
6643 name: "Verify-ClientAuth-SignatureType-TLS13",
6644 config: Config{
6645 MaxVersion: VersionTLS13,
6646 Certificates: []Certificate{rsaCertificate},
6647 SignSignatureAlgorithms: []signatureAlgorithm{
6648 signatureRSAPSSWithSHA256,
6649 },
6650 Bugs: ProtocolBugs{
6651 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6652 },
6653 },
6654 flags: []string{
6655 "-require-any-client-certificate",
6656 },
6657 shouldFail: true,
6658 expectedError: ":WRONG_SIGNATURE_TYPE:",
6659 })
6660
6661 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006662 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006663 config: Config{
6664 MaxVersion: VersionTLS12,
6665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006666 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006667 signatureRSAPKCS1WithSHA256,
6668 },
6669 Bugs: ProtocolBugs{
6670 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6671 },
6672 },
6673 shouldFail: true,
6674 expectedError: ":WRONG_SIGNATURE_TYPE:",
6675 })
6676
Steven Valdez143e8b32016-07-11 13:19:03 -04006677 testCases = append(testCases, testCase{
6678 name: "Verify-ServerAuth-SignatureType-TLS13",
6679 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006680 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006681 SignSignatureAlgorithms: []signatureAlgorithm{
6682 signatureRSAPSSWithSHA256,
6683 },
6684 Bugs: ProtocolBugs{
6685 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6686 },
6687 },
6688 shouldFail: true,
6689 expectedError: ":WRONG_SIGNATURE_TYPE:",
6690 })
6691
David Benjamin51dd7d62016-07-08 16:07:01 -07006692 // Test that, if the list is missing, the peer falls back to SHA-1 in
6693 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006694 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006695 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006696 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006697 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006698 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006699 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006700 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006701 },
6702 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006703 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006704 },
6705 },
6706 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006707 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6708 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006709 },
6710 })
6711
6712 testCases = append(testCases, testCase{
6713 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006714 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006715 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006716 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006717 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006718 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006719 },
6720 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006721 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006722 },
6723 },
David Benjaminee32bea2016-08-17 13:36:44 -04006724 flags: []string{
6725 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6726 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6727 },
6728 })
6729
6730 testCases = append(testCases, testCase{
6731 name: "ClientAuth-SHA1-Fallback-ECDSA",
6732 config: Config{
6733 MaxVersion: VersionTLS12,
6734 ClientAuth: RequireAnyClientCert,
6735 VerifySignatureAlgorithms: []signatureAlgorithm{
6736 signatureECDSAWithSHA1,
6737 },
6738 Bugs: ProtocolBugs{
6739 NoSignatureAlgorithms: true,
6740 },
6741 },
6742 flags: []string{
6743 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6744 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6745 },
6746 })
6747
6748 testCases = append(testCases, testCase{
6749 testType: serverTest,
6750 name: "ServerAuth-SHA1-Fallback-ECDSA",
6751 config: Config{
6752 MaxVersion: VersionTLS12,
6753 VerifySignatureAlgorithms: []signatureAlgorithm{
6754 signatureECDSAWithSHA1,
6755 },
6756 Bugs: ProtocolBugs{
6757 NoSignatureAlgorithms: true,
6758 },
6759 },
6760 flags: []string{
6761 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6762 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6763 },
David Benjamin000800a2014-11-14 01:43:59 -05006764 })
David Benjamin72dc7832015-03-16 17:49:43 -04006765
David Benjamin51dd7d62016-07-08 16:07:01 -07006766 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006767 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006768 config: Config{
6769 MaxVersion: VersionTLS13,
6770 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006771 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006772 signatureRSAPKCS1WithSHA1,
6773 },
6774 Bugs: ProtocolBugs{
6775 NoSignatureAlgorithms: true,
6776 },
6777 },
6778 flags: []string{
6779 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6780 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6781 },
David Benjamin48901652016-08-01 12:12:47 -04006782 shouldFail: true,
6783 // An empty CertificateRequest signature algorithm list is a
6784 // syntax error in TLS 1.3.
6785 expectedError: ":DECODE_ERROR:",
6786 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006787 })
6788
6789 testCases = append(testCases, testCase{
6790 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006791 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006792 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006793 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006794 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006795 signatureRSAPKCS1WithSHA1,
6796 },
6797 Bugs: ProtocolBugs{
6798 NoSignatureAlgorithms: true,
6799 },
6800 },
6801 shouldFail: true,
6802 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6803 })
6804
David Benjaminb62d2872016-07-18 14:55:02 +02006805 // Test that hash preferences are enforced. BoringSSL does not implement
6806 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006807 testCases = append(testCases, testCase{
6808 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006809 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006811 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006812 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006813 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006814 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006815 },
6816 Bugs: ProtocolBugs{
6817 IgnorePeerSignatureAlgorithmPreferences: true,
6818 },
6819 },
6820 flags: []string{"-require-any-client-certificate"},
6821 shouldFail: true,
6822 expectedError: ":WRONG_SIGNATURE_TYPE:",
6823 })
6824
6825 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006826 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006827 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006828 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006830 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006831 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006832 },
6833 Bugs: ProtocolBugs{
6834 IgnorePeerSignatureAlgorithmPreferences: true,
6835 },
6836 },
6837 shouldFail: true,
6838 expectedError: ":WRONG_SIGNATURE_TYPE:",
6839 })
David Benjaminb62d2872016-07-18 14:55:02 +02006840 testCases = append(testCases, testCase{
6841 testType: serverTest,
6842 name: "ClientAuth-Enforced-TLS13",
6843 config: Config{
6844 MaxVersion: VersionTLS13,
6845 Certificates: []Certificate{rsaCertificate},
6846 SignSignatureAlgorithms: []signatureAlgorithm{
6847 signatureRSAPKCS1WithMD5,
6848 },
6849 Bugs: ProtocolBugs{
6850 IgnorePeerSignatureAlgorithmPreferences: true,
6851 IgnoreSignatureVersionChecks: true,
6852 },
6853 },
6854 flags: []string{"-require-any-client-certificate"},
6855 shouldFail: true,
6856 expectedError: ":WRONG_SIGNATURE_TYPE:",
6857 })
6858
6859 testCases = append(testCases, testCase{
6860 name: "ServerAuth-Enforced-TLS13",
6861 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006862 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006863 SignSignatureAlgorithms: []signatureAlgorithm{
6864 signatureRSAPKCS1WithMD5,
6865 },
6866 Bugs: ProtocolBugs{
6867 IgnorePeerSignatureAlgorithmPreferences: true,
6868 IgnoreSignatureVersionChecks: true,
6869 },
6870 },
6871 shouldFail: true,
6872 expectedError: ":WRONG_SIGNATURE_TYPE:",
6873 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006874
6875 // Test that the agreed upon digest respects the client preferences and
6876 // the server digests.
6877 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006878 name: "NoCommonAlgorithms-Digests",
6879 config: Config{
6880 MaxVersion: VersionTLS12,
6881 ClientAuth: RequireAnyClientCert,
6882 VerifySignatureAlgorithms: []signatureAlgorithm{
6883 signatureRSAPKCS1WithSHA512,
6884 signatureRSAPKCS1WithSHA1,
6885 },
6886 },
6887 flags: []string{
6888 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6889 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6890 "-digest-prefs", "SHA256",
6891 },
6892 shouldFail: true,
6893 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6894 })
6895 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006896 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006898 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006899 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006900 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006901 signatureRSAPKCS1WithSHA512,
6902 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006903 },
6904 },
6905 flags: []string{
6906 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6907 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006908 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006909 },
David Benjaminca3d5452016-07-14 12:51:01 -04006910 shouldFail: true,
6911 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6912 })
6913 testCases = append(testCases, testCase{
6914 name: "NoCommonAlgorithms-TLS13",
6915 config: Config{
6916 MaxVersion: VersionTLS13,
6917 ClientAuth: RequireAnyClientCert,
6918 VerifySignatureAlgorithms: []signatureAlgorithm{
6919 signatureRSAPSSWithSHA512,
6920 signatureRSAPSSWithSHA384,
6921 },
6922 },
6923 flags: []string{
6924 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6925 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6926 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6927 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006928 shouldFail: true,
6929 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006930 })
6931 testCases = append(testCases, testCase{
6932 name: "Agree-Digest-SHA256",
6933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006934 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006935 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006936 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006937 signatureRSAPKCS1WithSHA1,
6938 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006939 },
6940 },
6941 flags: []string{
6942 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6943 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006944 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006945 },
Nick Harper60edffd2016-06-21 15:19:24 -07006946 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006947 })
6948 testCases = append(testCases, testCase{
6949 name: "Agree-Digest-SHA1",
6950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006951 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006952 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006953 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006954 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006955 },
6956 },
6957 flags: []string{
6958 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6959 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006960 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006961 },
Nick Harper60edffd2016-06-21 15:19:24 -07006962 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006963 })
6964 testCases = append(testCases, testCase{
6965 name: "Agree-Digest-Default",
6966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006967 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006968 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006969 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006970 signatureRSAPKCS1WithSHA256,
6971 signatureECDSAWithP256AndSHA256,
6972 signatureRSAPKCS1WithSHA1,
6973 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006974 },
6975 },
6976 flags: []string{
6977 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6978 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6979 },
Nick Harper60edffd2016-06-21 15:19:24 -07006980 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006981 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006982
David Benjaminca3d5452016-07-14 12:51:01 -04006983 // Test that the signing preference list may include extra algorithms
6984 // without negotiation problems.
6985 testCases = append(testCases, testCase{
6986 testType: serverTest,
6987 name: "FilterExtraAlgorithms",
6988 config: Config{
6989 MaxVersion: VersionTLS12,
6990 VerifySignatureAlgorithms: []signatureAlgorithm{
6991 signatureRSAPKCS1WithSHA256,
6992 },
6993 },
6994 flags: []string{
6995 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6996 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6997 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6998 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6999 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7000 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7001 },
7002 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7003 })
7004
David Benjamin4c3ddf72016-06-29 18:13:53 -04007005 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7006 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007007 testCases = append(testCases, testCase{
7008 name: "CheckLeafCurve",
7009 config: Config{
7010 MaxVersion: VersionTLS12,
7011 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007012 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013 },
7014 flags: []string{"-p384-only"},
7015 shouldFail: true,
7016 expectedError: ":BAD_ECC_CERT:",
7017 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007018
7019 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7020 testCases = append(testCases, testCase{
7021 name: "CheckLeafCurve-TLS13",
7022 config: Config{
7023 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007024 Certificates: []Certificate{ecdsaP256Certificate},
7025 },
7026 flags: []string{"-p384-only"},
7027 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007028
7029 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7030 testCases = append(testCases, testCase{
7031 name: "ECDSACurveMismatch-Verify-TLS12",
7032 config: Config{
7033 MaxVersion: VersionTLS12,
7034 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7035 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007036 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007037 signatureECDSAWithP384AndSHA384,
7038 },
7039 },
7040 })
7041
7042 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7043 testCases = append(testCases, testCase{
7044 name: "ECDSACurveMismatch-Verify-TLS13",
7045 config: Config{
7046 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007047 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007048 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007049 signatureECDSAWithP384AndSHA384,
7050 },
7051 Bugs: ProtocolBugs{
7052 SkipECDSACurveCheck: true,
7053 },
7054 },
7055 shouldFail: true,
7056 expectedError: ":WRONG_SIGNATURE_TYPE:",
7057 })
7058
7059 // Signature algorithm selection in TLS 1.3 should take the curve into
7060 // account.
7061 testCases = append(testCases, testCase{
7062 testType: serverTest,
7063 name: "ECDSACurveMismatch-Sign-TLS13",
7064 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007065 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007066 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007067 signatureECDSAWithP384AndSHA384,
7068 signatureECDSAWithP256AndSHA256,
7069 },
7070 },
7071 flags: []string{
7072 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7073 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7074 },
7075 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7076 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007077
7078 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7079 // server does not attempt to sign in that case.
7080 testCases = append(testCases, testCase{
7081 testType: serverTest,
7082 name: "RSA-PSS-Large",
7083 config: Config{
7084 MaxVersion: VersionTLS13,
7085 VerifySignatureAlgorithms: []signatureAlgorithm{
7086 signatureRSAPSSWithSHA512,
7087 },
7088 },
7089 flags: []string{
7090 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7091 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7092 },
7093 shouldFail: true,
7094 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7095 })
David Benjamin57e929f2016-08-30 00:30:38 -04007096
7097 // Test that RSA-PSS is enabled by default for TLS 1.2.
7098 testCases = append(testCases, testCase{
7099 testType: clientTest,
7100 name: "RSA-PSS-Default-Verify",
7101 config: Config{
7102 MaxVersion: VersionTLS12,
7103 SignSignatureAlgorithms: []signatureAlgorithm{
7104 signatureRSAPSSWithSHA256,
7105 },
7106 },
7107 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7108 })
7109
7110 testCases = append(testCases, testCase{
7111 testType: serverTest,
7112 name: "RSA-PSS-Default-Sign",
7113 config: Config{
7114 MaxVersion: VersionTLS12,
7115 VerifySignatureAlgorithms: []signatureAlgorithm{
7116 signatureRSAPSSWithSHA256,
7117 },
7118 },
7119 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7120 })
David Benjamin000800a2014-11-14 01:43:59 -05007121}
7122
David Benjamin83f90402015-01-27 01:09:43 -05007123// timeouts is the retransmit schedule for BoringSSL. It doubles and
7124// caps at 60 seconds. On the 13th timeout, it gives up.
7125var timeouts = []time.Duration{
7126 1 * time.Second,
7127 2 * time.Second,
7128 4 * time.Second,
7129 8 * time.Second,
7130 16 * time.Second,
7131 32 * time.Second,
7132 60 * time.Second,
7133 60 * time.Second,
7134 60 * time.Second,
7135 60 * time.Second,
7136 60 * time.Second,
7137 60 * time.Second,
7138 60 * time.Second,
7139}
7140
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007141// shortTimeouts is an alternate set of timeouts which would occur if the
7142// initial timeout duration was set to 250ms.
7143var shortTimeouts = []time.Duration{
7144 250 * time.Millisecond,
7145 500 * time.Millisecond,
7146 1 * time.Second,
7147 2 * time.Second,
7148 4 * time.Second,
7149 8 * time.Second,
7150 16 * time.Second,
7151 32 * time.Second,
7152 60 * time.Second,
7153 60 * time.Second,
7154 60 * time.Second,
7155 60 * time.Second,
7156 60 * time.Second,
7157}
7158
David Benjamin83f90402015-01-27 01:09:43 -05007159func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007160 // These tests work by coordinating some behavior on both the shim and
7161 // the runner.
7162 //
7163 // TimeoutSchedule configures the runner to send a series of timeout
7164 // opcodes to the shim (see packetAdaptor) immediately before reading
7165 // each peer handshake flight N. The timeout opcode both simulates a
7166 // timeout in the shim and acts as a synchronization point to help the
7167 // runner bracket each handshake flight.
7168 //
7169 // We assume the shim does not read from the channel eagerly. It must
7170 // first wait until it has sent flight N and is ready to receive
7171 // handshake flight N+1. At this point, it will process the timeout
7172 // opcode. It must then immediately respond with a timeout ACK and act
7173 // as if the shim was idle for the specified amount of time.
7174 //
7175 // The runner then drops all packets received before the ACK and
7176 // continues waiting for flight N. This ordering results in one attempt
7177 // at sending flight N to be dropped. For the test to complete, the
7178 // shim must send flight N again, testing that the shim implements DTLS
7179 // retransmit on a timeout.
7180
Steven Valdez143e8b32016-07-11 13:19:03 -04007181 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007182 // likely be more epochs to cross and the final message's retransmit may
7183 // be more complex.
7184
David Benjamin585d7a42016-06-02 14:58:00 -04007185 for _, async := range []bool{true, false} {
7186 var tests []testCase
7187
7188 // Test that this is indeed the timeout schedule. Stress all
7189 // four patterns of handshake.
7190 for i := 1; i < len(timeouts); i++ {
7191 number := strconv.Itoa(i)
7192 tests = append(tests, testCase{
7193 protocol: dtls,
7194 name: "DTLS-Retransmit-Client-" + number,
7195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007197 Bugs: ProtocolBugs{
7198 TimeoutSchedule: timeouts[:i],
7199 },
7200 },
7201 resumeSession: true,
7202 })
7203 tests = append(tests, testCase{
7204 protocol: dtls,
7205 testType: serverTest,
7206 name: "DTLS-Retransmit-Server-" + number,
7207 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007208 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007209 Bugs: ProtocolBugs{
7210 TimeoutSchedule: timeouts[:i],
7211 },
7212 },
7213 resumeSession: true,
7214 })
7215 }
7216
7217 // Test that exceeding the timeout schedule hits a read
7218 // timeout.
7219 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007220 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007221 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007223 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007224 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007225 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007226 },
7227 },
7228 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007229 shouldFail: true,
7230 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007231 })
David Benjamin585d7a42016-06-02 14:58:00 -04007232
7233 if async {
7234 // Test that timeout handling has a fudge factor, due to API
7235 // problems.
7236 tests = append(tests, testCase{
7237 protocol: dtls,
7238 name: "DTLS-Retransmit-Fudge",
7239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007240 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007241 Bugs: ProtocolBugs{
7242 TimeoutSchedule: []time.Duration{
7243 timeouts[0] - 10*time.Millisecond,
7244 },
7245 },
7246 },
7247 resumeSession: true,
7248 })
7249 }
7250
7251 // Test that the final Finished retransmitting isn't
7252 // duplicated if the peer badly fragments everything.
7253 tests = append(tests, testCase{
7254 testType: serverTest,
7255 protocol: dtls,
7256 name: "DTLS-Retransmit-Fragmented",
7257 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007258 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007259 Bugs: ProtocolBugs{
7260 TimeoutSchedule: []time.Duration{timeouts[0]},
7261 MaxHandshakeRecordLength: 2,
7262 },
7263 },
7264 })
7265
7266 // Test the timeout schedule when a shorter initial timeout duration is set.
7267 tests = append(tests, testCase{
7268 protocol: dtls,
7269 name: "DTLS-Retransmit-Short-Client",
7270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007271 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007272 Bugs: ProtocolBugs{
7273 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7274 },
7275 },
7276 resumeSession: true,
7277 flags: []string{"-initial-timeout-duration-ms", "250"},
7278 })
7279 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007280 protocol: dtls,
7281 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007282 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007283 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007284 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007285 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007286 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007287 },
7288 },
7289 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007290 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007291 })
David Benjamin585d7a42016-06-02 14:58:00 -04007292
7293 for _, test := range tests {
7294 if async {
7295 test.name += "-Async"
7296 test.flags = append(test.flags, "-async")
7297 }
7298
7299 testCases = append(testCases, test)
7300 }
David Benjamin83f90402015-01-27 01:09:43 -05007301 }
David Benjamin83f90402015-01-27 01:09:43 -05007302}
7303
David Benjaminc565ebb2015-04-03 04:06:36 -04007304func addExportKeyingMaterialTests() {
7305 for _, vers := range tlsVersions {
7306 if vers.version == VersionSSL30 {
7307 continue
7308 }
7309 testCases = append(testCases, testCase{
7310 name: "ExportKeyingMaterial-" + vers.name,
7311 config: Config{
7312 MaxVersion: vers.version,
7313 },
7314 exportKeyingMaterial: 1024,
7315 exportLabel: "label",
7316 exportContext: "context",
7317 useExportContext: true,
7318 })
7319 testCases = append(testCases, testCase{
7320 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7321 config: Config{
7322 MaxVersion: vers.version,
7323 },
7324 exportKeyingMaterial: 1024,
7325 })
7326 testCases = append(testCases, testCase{
7327 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7328 config: Config{
7329 MaxVersion: vers.version,
7330 },
7331 exportKeyingMaterial: 1024,
7332 useExportContext: true,
7333 })
7334 testCases = append(testCases, testCase{
7335 name: "ExportKeyingMaterial-Small-" + vers.name,
7336 config: Config{
7337 MaxVersion: vers.version,
7338 },
7339 exportKeyingMaterial: 1,
7340 exportLabel: "label",
7341 exportContext: "context",
7342 useExportContext: true,
7343 })
7344 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007345
David Benjaminc565ebb2015-04-03 04:06:36 -04007346 testCases = append(testCases, testCase{
7347 name: "ExportKeyingMaterial-SSL3",
7348 config: Config{
7349 MaxVersion: VersionSSL30,
7350 },
7351 exportKeyingMaterial: 1024,
7352 exportLabel: "label",
7353 exportContext: "context",
7354 useExportContext: true,
7355 shouldFail: true,
7356 expectedError: "failed to export keying material",
7357 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007358
7359 // Exporters work during a False Start.
7360 testCases = append(testCases, testCase{
7361 name: "ExportKeyingMaterial-FalseStart",
7362 config: Config{
7363 MaxVersion: VersionTLS12,
7364 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7365 NextProtos: []string{"foo"},
7366 Bugs: ProtocolBugs{
7367 ExpectFalseStart: true,
7368 },
7369 },
7370 flags: []string{
7371 "-false-start",
7372 "-advertise-alpn", "\x03foo",
7373 },
7374 shimWritesFirst: true,
7375 exportKeyingMaterial: 1024,
7376 exportLabel: "label",
7377 exportContext: "context",
7378 useExportContext: true,
7379 })
7380
7381 // Exporters do not work in the middle of a renegotiation. Test this by
7382 // triggering the exporter after every SSL_read call and configuring the
7383 // shim to run asynchronously.
7384 testCases = append(testCases, testCase{
7385 name: "ExportKeyingMaterial-Renegotiate",
7386 config: Config{
7387 MaxVersion: VersionTLS12,
7388 },
7389 renegotiate: 1,
7390 flags: []string{
7391 "-async",
7392 "-use-exporter-between-reads",
7393 "-renegotiate-freely",
7394 "-expect-total-renegotiations", "1",
7395 },
7396 shouldFail: true,
7397 expectedError: "failed to export keying material",
7398 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007399}
7400
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007401func addTLSUniqueTests() {
7402 for _, isClient := range []bool{false, true} {
7403 for _, isResumption := range []bool{false, true} {
7404 for _, hasEMS := range []bool{false, true} {
7405 var suffix string
7406 if isResumption {
7407 suffix = "Resume-"
7408 } else {
7409 suffix = "Full-"
7410 }
7411
7412 if hasEMS {
7413 suffix += "EMS-"
7414 } else {
7415 suffix += "NoEMS-"
7416 }
7417
7418 if isClient {
7419 suffix += "Client"
7420 } else {
7421 suffix += "Server"
7422 }
7423
7424 test := testCase{
7425 name: "TLSUnique-" + suffix,
7426 testTLSUnique: true,
7427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007428 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007429 Bugs: ProtocolBugs{
7430 NoExtendedMasterSecret: !hasEMS,
7431 },
7432 },
7433 }
7434
7435 if isResumption {
7436 test.resumeSession = true
7437 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007438 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007439 Bugs: ProtocolBugs{
7440 NoExtendedMasterSecret: !hasEMS,
7441 },
7442 }
7443 }
7444
7445 if isResumption && !hasEMS {
7446 test.shouldFail = true
7447 test.expectedError = "failed to get tls-unique"
7448 }
7449
7450 testCases = append(testCases, test)
7451 }
7452 }
7453 }
7454}
7455
Adam Langley09505632015-07-30 18:10:13 -07007456func addCustomExtensionTests() {
7457 expectedContents := "custom extension"
7458 emptyString := ""
7459
7460 for _, isClient := range []bool{false, true} {
7461 suffix := "Server"
7462 flag := "-enable-server-custom-extension"
7463 testType := serverTest
7464 if isClient {
7465 suffix = "Client"
7466 flag = "-enable-client-custom-extension"
7467 testType = clientTest
7468 }
7469
7470 testCases = append(testCases, testCase{
7471 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007472 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007474 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007475 Bugs: ProtocolBugs{
7476 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007477 ExpectedCustomExtension: &expectedContents,
7478 },
7479 },
7480 flags: []string{flag},
7481 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007482 testCases = append(testCases, testCase{
7483 testType: testType,
7484 name: "CustomExtensions-" + suffix + "-TLS13",
7485 config: Config{
7486 MaxVersion: VersionTLS13,
7487 Bugs: ProtocolBugs{
7488 CustomExtension: expectedContents,
7489 ExpectedCustomExtension: &expectedContents,
7490 },
7491 },
7492 flags: []string{flag},
7493 })
Adam Langley09505632015-07-30 18:10:13 -07007494
7495 // If the parse callback fails, the handshake should also fail.
7496 testCases = append(testCases, testCase{
7497 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007498 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007500 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007501 Bugs: ProtocolBugs{
7502 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007503 ExpectedCustomExtension: &expectedContents,
7504 },
7505 },
David Benjamin399e7c92015-07-30 23:01:27 -04007506 flags: []string{flag},
7507 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007508 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7509 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007510 testCases = append(testCases, testCase{
7511 testType: testType,
7512 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7513 config: Config{
7514 MaxVersion: VersionTLS13,
7515 Bugs: ProtocolBugs{
7516 CustomExtension: expectedContents + "foo",
7517 ExpectedCustomExtension: &expectedContents,
7518 },
7519 },
7520 flags: []string{flag},
7521 shouldFail: true,
7522 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7523 })
Adam Langley09505632015-07-30 18:10:13 -07007524
7525 // If the add callback fails, the handshake should also fail.
7526 testCases = append(testCases, testCase{
7527 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007528 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007530 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007531 Bugs: ProtocolBugs{
7532 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007533 ExpectedCustomExtension: &expectedContents,
7534 },
7535 },
David Benjamin399e7c92015-07-30 23:01:27 -04007536 flags: []string{flag, "-custom-extension-fail-add"},
7537 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007538 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7539 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007540 testCases = append(testCases, testCase{
7541 testType: testType,
7542 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7543 config: Config{
7544 MaxVersion: VersionTLS13,
7545 Bugs: ProtocolBugs{
7546 CustomExtension: expectedContents,
7547 ExpectedCustomExtension: &expectedContents,
7548 },
7549 },
7550 flags: []string{flag, "-custom-extension-fail-add"},
7551 shouldFail: true,
7552 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7553 })
Adam Langley09505632015-07-30 18:10:13 -07007554
7555 // If the add callback returns zero, no extension should be
7556 // added.
7557 skipCustomExtension := expectedContents
7558 if isClient {
7559 // For the case where the client skips sending the
7560 // custom extension, the server must not “echo” it.
7561 skipCustomExtension = ""
7562 }
7563 testCases = append(testCases, testCase{
7564 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007565 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007567 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007568 Bugs: ProtocolBugs{
7569 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007570 ExpectedCustomExtension: &emptyString,
7571 },
7572 },
7573 flags: []string{flag, "-custom-extension-skip"},
7574 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007575 testCases = append(testCases, testCase{
7576 testType: testType,
7577 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7578 config: Config{
7579 MaxVersion: VersionTLS13,
7580 Bugs: ProtocolBugs{
7581 CustomExtension: skipCustomExtension,
7582 ExpectedCustomExtension: &emptyString,
7583 },
7584 },
7585 flags: []string{flag, "-custom-extension-skip"},
7586 })
Adam Langley09505632015-07-30 18:10:13 -07007587 }
7588
7589 // The custom extension add callback should not be called if the client
7590 // doesn't send the extension.
7591 testCases = append(testCases, testCase{
7592 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007593 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007595 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007596 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007597 ExpectedCustomExtension: &emptyString,
7598 },
7599 },
7600 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7601 })
Adam Langley2deb9842015-08-07 11:15:37 -07007602
Steven Valdez143e8b32016-07-11 13:19:03 -04007603 testCases = append(testCases, testCase{
7604 testType: serverTest,
7605 name: "CustomExtensions-NotCalled-Server-TLS13",
7606 config: Config{
7607 MaxVersion: VersionTLS13,
7608 Bugs: ProtocolBugs{
7609 ExpectedCustomExtension: &emptyString,
7610 },
7611 },
7612 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7613 })
7614
Adam Langley2deb9842015-08-07 11:15:37 -07007615 // Test an unknown extension from the server.
7616 testCases = append(testCases, testCase{
7617 testType: clientTest,
7618 name: "UnknownExtension-Client",
7619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007620 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007621 Bugs: ProtocolBugs{
7622 CustomExtension: expectedContents,
7623 },
7624 },
David Benjamin0c40a962016-08-01 12:05:50 -04007625 shouldFail: true,
7626 expectedError: ":UNEXPECTED_EXTENSION:",
7627 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007628 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007629 testCases = append(testCases, testCase{
7630 testType: clientTest,
7631 name: "UnknownExtension-Client-TLS13",
7632 config: Config{
7633 MaxVersion: VersionTLS13,
7634 Bugs: ProtocolBugs{
7635 CustomExtension: expectedContents,
7636 },
7637 },
David Benjamin0c40a962016-08-01 12:05:50 -04007638 shouldFail: true,
7639 expectedError: ":UNEXPECTED_EXTENSION:",
7640 expectedLocalError: "remote error: unsupported extension",
7641 })
David Benjamin490469f2016-10-05 22:44:38 -04007642 testCases = append(testCases, testCase{
7643 testType: clientTest,
7644 name: "UnknownUnencryptedExtension-Client-TLS13",
7645 config: Config{
7646 MaxVersion: VersionTLS13,
7647 Bugs: ProtocolBugs{
7648 CustomUnencryptedExtension: expectedContents,
7649 },
7650 },
7651 shouldFail: true,
7652 expectedError: ":UNEXPECTED_EXTENSION:",
7653 // The shim must send an alert, but alerts at this point do not
7654 // get successfully decrypted by the runner.
7655 expectedLocalError: "local error: bad record MAC",
7656 })
7657 testCases = append(testCases, testCase{
7658 testType: clientTest,
7659 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7660 config: Config{
7661 MaxVersion: VersionTLS13,
7662 Bugs: ProtocolBugs{
7663 SendUnencryptedALPN: "foo",
7664 },
7665 },
7666 flags: []string{
7667 "-advertise-alpn", "\x03foo\x03bar",
7668 },
7669 shouldFail: true,
7670 expectedError: ":UNEXPECTED_EXTENSION:",
7671 // The shim must send an alert, but alerts at this point do not
7672 // get successfully decrypted by the runner.
7673 expectedLocalError: "local error: bad record MAC",
7674 })
David Benjamin0c40a962016-08-01 12:05:50 -04007675
7676 // Test a known but unoffered extension from the server.
7677 testCases = append(testCases, testCase{
7678 testType: clientTest,
7679 name: "UnofferedExtension-Client",
7680 config: Config{
7681 MaxVersion: VersionTLS12,
7682 Bugs: ProtocolBugs{
7683 SendALPN: "alpn",
7684 },
7685 },
7686 shouldFail: true,
7687 expectedError: ":UNEXPECTED_EXTENSION:",
7688 expectedLocalError: "remote error: unsupported extension",
7689 })
7690 testCases = append(testCases, testCase{
7691 testType: clientTest,
7692 name: "UnofferedExtension-Client-TLS13",
7693 config: Config{
7694 MaxVersion: VersionTLS13,
7695 Bugs: ProtocolBugs{
7696 SendALPN: "alpn",
7697 },
7698 },
7699 shouldFail: true,
7700 expectedError: ":UNEXPECTED_EXTENSION:",
7701 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007702 })
Adam Langley09505632015-07-30 18:10:13 -07007703}
7704
David Benjaminb36a3952015-12-01 18:53:13 -05007705func addRSAClientKeyExchangeTests() {
7706 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7707 testCases = append(testCases, testCase{
7708 testType: serverTest,
7709 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7710 config: Config{
7711 // Ensure the ClientHello version and final
7712 // version are different, to detect if the
7713 // server uses the wrong one.
7714 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007715 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007716 Bugs: ProtocolBugs{
7717 BadRSAClientKeyExchange: bad,
7718 },
7719 },
7720 shouldFail: true,
7721 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7722 })
7723 }
David Benjamine63d9d72016-09-19 18:27:34 -04007724
7725 // The server must compare whatever was in ClientHello.version for the
7726 // RSA premaster.
7727 testCases = append(testCases, testCase{
7728 testType: serverTest,
7729 name: "SendClientVersion-RSA",
7730 config: Config{
7731 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7732 Bugs: ProtocolBugs{
7733 SendClientVersion: 0x1234,
7734 },
7735 },
7736 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7737 })
David Benjaminb36a3952015-12-01 18:53:13 -05007738}
7739
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007740var testCurves = []struct {
7741 name string
7742 id CurveID
7743}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007744 {"P-256", CurveP256},
7745 {"P-384", CurveP384},
7746 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007747 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007748}
7749
Steven Valdez5440fe02016-07-18 12:40:30 -04007750const bogusCurve = 0x1234
7751
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007752func addCurveTests() {
7753 for _, curve := range testCurves {
7754 testCases = append(testCases, testCase{
7755 name: "CurveTest-Client-" + curve.name,
7756 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007757 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007758 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7759 CurvePreferences: []CurveID{curve.id},
7760 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007761 flags: []string{
7762 "-enable-all-curves",
7763 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7764 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007765 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007766 })
7767 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007768 name: "CurveTest-Client-" + curve.name + "-TLS13",
7769 config: Config{
7770 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007771 CurvePreferences: []CurveID{curve.id},
7772 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007773 flags: []string{
7774 "-enable-all-curves",
7775 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7776 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007777 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007778 })
7779 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007780 testType: serverTest,
7781 name: "CurveTest-Server-" + curve.name,
7782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007783 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7785 CurvePreferences: []CurveID{curve.id},
7786 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007787 flags: []string{
7788 "-enable-all-curves",
7789 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7790 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007791 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007792 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007793 testCases = append(testCases, testCase{
7794 testType: serverTest,
7795 name: "CurveTest-Server-" + curve.name + "-TLS13",
7796 config: Config{
7797 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007798 CurvePreferences: []CurveID{curve.id},
7799 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007800 flags: []string{
7801 "-enable-all-curves",
7802 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7803 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007804 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007805 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007806 }
David Benjamin241ae832016-01-15 03:04:54 -05007807
7808 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007809 testCases = append(testCases, testCase{
7810 testType: serverTest,
7811 name: "UnknownCurve",
7812 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007813 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007814 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7815 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7816 },
7817 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007818
Steven Valdez803c77a2016-09-06 14:13:43 -04007819 // The server must be tolerant to bogus curves.
7820 testCases = append(testCases, testCase{
7821 testType: serverTest,
7822 name: "UnknownCurve-TLS13",
7823 config: Config{
7824 MaxVersion: VersionTLS13,
7825 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7826 },
7827 })
7828
David Benjamin4c3ddf72016-06-29 18:13:53 -04007829 // The server must not consider ECDHE ciphers when there are no
7830 // supported curves.
7831 testCases = append(testCases, testCase{
7832 testType: serverTest,
7833 name: "NoSupportedCurves",
7834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007835 MaxVersion: VersionTLS12,
7836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7837 Bugs: ProtocolBugs{
7838 NoSupportedCurves: true,
7839 },
7840 },
7841 shouldFail: true,
7842 expectedError: ":NO_SHARED_CIPHER:",
7843 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007844 testCases = append(testCases, testCase{
7845 testType: serverTest,
7846 name: "NoSupportedCurves-TLS13",
7847 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007848 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007849 Bugs: ProtocolBugs{
7850 NoSupportedCurves: true,
7851 },
7852 },
7853 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007854 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007855 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007856
7857 // The server must fall back to another cipher when there are no
7858 // supported curves.
7859 testCases = append(testCases, testCase{
7860 testType: serverTest,
7861 name: "NoCommonCurves",
7862 config: Config{
7863 MaxVersion: VersionTLS12,
7864 CipherSuites: []uint16{
7865 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7866 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7867 },
7868 CurvePreferences: []CurveID{CurveP224},
7869 },
7870 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7871 })
7872
7873 // The client must reject bogus curves and disabled curves.
7874 testCases = append(testCases, testCase{
7875 name: "BadECDHECurve",
7876 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007877 MaxVersion: VersionTLS12,
7878 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7879 Bugs: ProtocolBugs{
7880 SendCurve: bogusCurve,
7881 },
7882 },
7883 shouldFail: true,
7884 expectedError: ":WRONG_CURVE:",
7885 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007886 testCases = append(testCases, testCase{
7887 name: "BadECDHECurve-TLS13",
7888 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007889 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007890 Bugs: ProtocolBugs{
7891 SendCurve: bogusCurve,
7892 },
7893 },
7894 shouldFail: true,
7895 expectedError: ":WRONG_CURVE:",
7896 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007897
7898 testCases = append(testCases, testCase{
7899 name: "UnsupportedCurve",
7900 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007901 MaxVersion: VersionTLS12,
7902 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7903 CurvePreferences: []CurveID{CurveP256},
7904 Bugs: ProtocolBugs{
7905 IgnorePeerCurvePreferences: true,
7906 },
7907 },
7908 flags: []string{"-p384-only"},
7909 shouldFail: true,
7910 expectedError: ":WRONG_CURVE:",
7911 })
7912
David Benjamin4f921572016-07-17 14:20:10 +02007913 testCases = append(testCases, testCase{
7914 // TODO(davidben): Add a TLS 1.3 version where
7915 // HelloRetryRequest requests an unsupported curve.
7916 name: "UnsupportedCurve-ServerHello-TLS13",
7917 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007918 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007919 CurvePreferences: []CurveID{CurveP384},
7920 Bugs: ProtocolBugs{
7921 SendCurve: CurveP256,
7922 },
7923 },
7924 flags: []string{"-p384-only"},
7925 shouldFail: true,
7926 expectedError: ":WRONG_CURVE:",
7927 })
7928
David Benjamin4c3ddf72016-06-29 18:13:53 -04007929 // Test invalid curve points.
7930 testCases = append(testCases, testCase{
7931 name: "InvalidECDHPoint-Client",
7932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007933 MaxVersion: VersionTLS12,
7934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7935 CurvePreferences: []CurveID{CurveP256},
7936 Bugs: ProtocolBugs{
7937 InvalidECDHPoint: true,
7938 },
7939 },
7940 shouldFail: true,
7941 expectedError: ":INVALID_ENCODING:",
7942 })
7943 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007944 name: "InvalidECDHPoint-Client-TLS13",
7945 config: Config{
7946 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007947 CurvePreferences: []CurveID{CurveP256},
7948 Bugs: ProtocolBugs{
7949 InvalidECDHPoint: true,
7950 },
7951 },
7952 shouldFail: true,
7953 expectedError: ":INVALID_ENCODING:",
7954 })
7955 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007956 testType: serverTest,
7957 name: "InvalidECDHPoint-Server",
7958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007959 MaxVersion: VersionTLS12,
7960 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7961 CurvePreferences: []CurveID{CurveP256},
7962 Bugs: ProtocolBugs{
7963 InvalidECDHPoint: true,
7964 },
7965 },
7966 shouldFail: true,
7967 expectedError: ":INVALID_ENCODING:",
7968 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007969 testCases = append(testCases, testCase{
7970 testType: serverTest,
7971 name: "InvalidECDHPoint-Server-TLS13",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007974 CurvePreferences: []CurveID{CurveP256},
7975 Bugs: ProtocolBugs{
7976 InvalidECDHPoint: true,
7977 },
7978 },
7979 shouldFail: true,
7980 expectedError: ":INVALID_ENCODING:",
7981 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007982}
7983
Matt Braithwaite54217e42016-06-13 13:03:47 -07007984func addCECPQ1Tests() {
7985 testCases = append(testCases, testCase{
7986 testType: clientTest,
7987 name: "CECPQ1-Client-BadX25519Part",
7988 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007989 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007990 MinVersion: VersionTLS12,
7991 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7992 Bugs: ProtocolBugs{
7993 CECPQ1BadX25519Part: true,
7994 },
7995 },
7996 flags: []string{"-cipher", "kCECPQ1"},
7997 shouldFail: true,
7998 expectedLocalError: "local error: bad record MAC",
7999 })
8000 testCases = append(testCases, testCase{
8001 testType: clientTest,
8002 name: "CECPQ1-Client-BadNewhopePart",
8003 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008004 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008005 MinVersion: VersionTLS12,
8006 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8007 Bugs: ProtocolBugs{
8008 CECPQ1BadNewhopePart: true,
8009 },
8010 },
8011 flags: []string{"-cipher", "kCECPQ1"},
8012 shouldFail: true,
8013 expectedLocalError: "local error: bad record MAC",
8014 })
8015 testCases = append(testCases, testCase{
8016 testType: serverTest,
8017 name: "CECPQ1-Server-BadX25519Part",
8018 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008019 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008020 MinVersion: VersionTLS12,
8021 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8022 Bugs: ProtocolBugs{
8023 CECPQ1BadX25519Part: true,
8024 },
8025 },
8026 flags: []string{"-cipher", "kCECPQ1"},
8027 shouldFail: true,
8028 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8029 })
8030 testCases = append(testCases, testCase{
8031 testType: serverTest,
8032 name: "CECPQ1-Server-BadNewhopePart",
8033 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008034 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008035 MinVersion: VersionTLS12,
8036 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8037 Bugs: ProtocolBugs{
8038 CECPQ1BadNewhopePart: true,
8039 },
8040 },
8041 flags: []string{"-cipher", "kCECPQ1"},
8042 shouldFail: true,
8043 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8044 })
8045}
8046
David Benjamin5c4e8572016-08-19 17:44:53 -04008047func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008048 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008049 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008050 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008051 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008052 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8053 Bugs: ProtocolBugs{
8054 // This is a 1234-bit prime number, generated
8055 // with:
8056 // openssl gendh 1234 | openssl asn1parse -i
8057 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8058 },
8059 },
David Benjamin9e68f192016-06-30 14:55:33 -04008060 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008061 })
8062 testCases = append(testCases, testCase{
8063 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008064 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008065 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008066 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008067 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8068 },
8069 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008070 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008071 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008072}
8073
David Benjaminc9ae27c2016-06-24 22:56:37 -04008074func addTLS13RecordTests() {
8075 testCases = append(testCases, testCase{
8076 name: "TLS13-RecordPadding",
8077 config: Config{
8078 MaxVersion: VersionTLS13,
8079 MinVersion: VersionTLS13,
8080 Bugs: ProtocolBugs{
8081 RecordPadding: 10,
8082 },
8083 },
8084 })
8085
8086 testCases = append(testCases, testCase{
8087 name: "TLS13-EmptyRecords",
8088 config: Config{
8089 MaxVersion: VersionTLS13,
8090 MinVersion: VersionTLS13,
8091 Bugs: ProtocolBugs{
8092 OmitRecordContents: true,
8093 },
8094 },
8095 shouldFail: true,
8096 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8097 })
8098
8099 testCases = append(testCases, testCase{
8100 name: "TLS13-OnlyPadding",
8101 config: Config{
8102 MaxVersion: VersionTLS13,
8103 MinVersion: VersionTLS13,
8104 Bugs: ProtocolBugs{
8105 OmitRecordContents: true,
8106 RecordPadding: 10,
8107 },
8108 },
8109 shouldFail: true,
8110 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8111 })
8112
8113 testCases = append(testCases, testCase{
8114 name: "TLS13-WrongOuterRecord",
8115 config: Config{
8116 MaxVersion: VersionTLS13,
8117 MinVersion: VersionTLS13,
8118 Bugs: ProtocolBugs{
8119 OuterRecordType: recordTypeHandshake,
8120 },
8121 },
8122 shouldFail: true,
8123 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8124 })
8125}
8126
Steven Valdez5b986082016-09-01 12:29:49 -04008127func addSessionTicketTests() {
8128 testCases = append(testCases, testCase{
8129 // In TLS 1.2 and below, empty NewSessionTicket messages
8130 // mean the server changed its mind on sending a ticket.
8131 name: "SendEmptySessionTicket",
8132 config: Config{
8133 MaxVersion: VersionTLS12,
8134 Bugs: ProtocolBugs{
8135 SendEmptySessionTicket: true,
8136 },
8137 },
8138 flags: []string{"-expect-no-session"},
8139 })
8140
8141 // Test that the server ignores unknown PSK modes.
8142 testCases = append(testCases, testCase{
8143 testType: serverTest,
8144 name: "TLS13-SendUnknownModeSessionTicket-Server",
8145 config: Config{
8146 MaxVersion: VersionTLS13,
8147 Bugs: ProtocolBugs{
8148 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008149 },
8150 },
8151 resumeSession: true,
8152 expectedResumeVersion: VersionTLS13,
8153 })
8154
Steven Valdeza833c352016-11-01 13:39:36 -04008155 // Test that the server does not send session tickets with no matching key exchange mode.
8156 testCases = append(testCases, testCase{
8157 testType: serverTest,
8158 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8159 config: Config{
8160 MaxVersion: VersionTLS13,
8161 Bugs: ProtocolBugs{
8162 SendPSKKeyExchangeModes: []byte{0x1a},
8163 ExpectNoNewSessionTicket: true,
8164 },
8165 },
8166 })
8167
8168 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008169 testCases = append(testCases, testCase{
8170 testType: serverTest,
8171 name: "TLS13-SendBadKEModeSessionTicket-Server",
8172 config: Config{
8173 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008174 },
8175 resumeConfig: &Config{
8176 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008177 Bugs: ProtocolBugs{
8178 SendPSKKeyExchangeModes: []byte{0x1a},
8179 },
8180 },
8181 resumeSession: true,
8182 expectResumeRejected: true,
8183 })
8184
Steven Valdeza833c352016-11-01 13:39:36 -04008185 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008186 testCases = append(testCases, testCase{
8187 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008188 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008189 config: Config{
8190 MaxVersion: VersionTLS13,
8191 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008192 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008193 },
8194 },
Steven Valdeza833c352016-11-01 13:39:36 -04008195 resumeSession: true,
8196 flags: []string{
8197 "-resumption-delay", "10",
8198 },
Steven Valdez5b986082016-09-01 12:29:49 -04008199 })
8200
Steven Valdeza833c352016-11-01 13:39:36 -04008201 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008202 testCases = append(testCases, testCase{
8203 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008204 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008205 config: Config{
8206 MaxVersion: VersionTLS13,
8207 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008208 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008209 },
8210 },
Steven Valdeza833c352016-11-01 13:39:36 -04008211 resumeSession: true,
8212 shouldFail: true,
8213 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008214 })
8215
Steven Valdez5b986082016-09-01 12:29:49 -04008216}
8217
David Benjamin82261be2016-07-07 14:32:50 -07008218func addChangeCipherSpecTests() {
8219 // Test missing ChangeCipherSpecs.
8220 testCases = append(testCases, testCase{
8221 name: "SkipChangeCipherSpec-Client",
8222 config: Config{
8223 MaxVersion: VersionTLS12,
8224 Bugs: ProtocolBugs{
8225 SkipChangeCipherSpec: true,
8226 },
8227 },
8228 shouldFail: true,
8229 expectedError: ":UNEXPECTED_RECORD:",
8230 })
8231 testCases = append(testCases, testCase{
8232 testType: serverTest,
8233 name: "SkipChangeCipherSpec-Server",
8234 config: Config{
8235 MaxVersion: VersionTLS12,
8236 Bugs: ProtocolBugs{
8237 SkipChangeCipherSpec: true,
8238 },
8239 },
8240 shouldFail: true,
8241 expectedError: ":UNEXPECTED_RECORD:",
8242 })
8243 testCases = append(testCases, testCase{
8244 testType: serverTest,
8245 name: "SkipChangeCipherSpec-Server-NPN",
8246 config: Config{
8247 MaxVersion: VersionTLS12,
8248 NextProtos: []string{"bar"},
8249 Bugs: ProtocolBugs{
8250 SkipChangeCipherSpec: true,
8251 },
8252 },
8253 flags: []string{
8254 "-advertise-npn", "\x03foo\x03bar\x03baz",
8255 },
8256 shouldFail: true,
8257 expectedError: ":UNEXPECTED_RECORD:",
8258 })
8259
8260 // Test synchronization between the handshake and ChangeCipherSpec.
8261 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8262 // rejected. Test both with and without handshake packing to handle both
8263 // when the partial post-CCS message is in its own record and when it is
8264 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008265 for _, packed := range []bool{false, true} {
8266 var suffix string
8267 if packed {
8268 suffix = "-Packed"
8269 }
8270
8271 testCases = append(testCases, testCase{
8272 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8273 config: Config{
8274 MaxVersion: VersionTLS12,
8275 Bugs: ProtocolBugs{
8276 FragmentAcrossChangeCipherSpec: true,
8277 PackHandshakeFlight: packed,
8278 },
8279 },
8280 shouldFail: true,
8281 expectedError: ":UNEXPECTED_RECORD:",
8282 })
8283 testCases = append(testCases, testCase{
8284 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8285 config: Config{
8286 MaxVersion: VersionTLS12,
8287 },
8288 resumeSession: true,
8289 resumeConfig: &Config{
8290 MaxVersion: VersionTLS12,
8291 Bugs: ProtocolBugs{
8292 FragmentAcrossChangeCipherSpec: true,
8293 PackHandshakeFlight: packed,
8294 },
8295 },
8296 shouldFail: true,
8297 expectedError: ":UNEXPECTED_RECORD:",
8298 })
8299 testCases = append(testCases, testCase{
8300 testType: serverTest,
8301 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8302 config: Config{
8303 MaxVersion: VersionTLS12,
8304 Bugs: ProtocolBugs{
8305 FragmentAcrossChangeCipherSpec: true,
8306 PackHandshakeFlight: packed,
8307 },
8308 },
8309 shouldFail: true,
8310 expectedError: ":UNEXPECTED_RECORD:",
8311 })
8312 testCases = append(testCases, testCase{
8313 testType: serverTest,
8314 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8315 config: Config{
8316 MaxVersion: VersionTLS12,
8317 },
8318 resumeSession: true,
8319 resumeConfig: &Config{
8320 MaxVersion: VersionTLS12,
8321 Bugs: ProtocolBugs{
8322 FragmentAcrossChangeCipherSpec: true,
8323 PackHandshakeFlight: packed,
8324 },
8325 },
8326 shouldFail: true,
8327 expectedError: ":UNEXPECTED_RECORD:",
8328 })
8329 testCases = append(testCases, testCase{
8330 testType: serverTest,
8331 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8332 config: Config{
8333 MaxVersion: VersionTLS12,
8334 NextProtos: []string{"bar"},
8335 Bugs: ProtocolBugs{
8336 FragmentAcrossChangeCipherSpec: true,
8337 PackHandshakeFlight: packed,
8338 },
8339 },
8340 flags: []string{
8341 "-advertise-npn", "\x03foo\x03bar\x03baz",
8342 },
8343 shouldFail: true,
8344 expectedError: ":UNEXPECTED_RECORD:",
8345 })
8346 }
8347
David Benjamin61672812016-07-14 23:10:43 -04008348 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8349 // messages in the handshake queue. Do this by testing the server
8350 // reading the client Finished, reversing the flight so Finished comes
8351 // first.
8352 testCases = append(testCases, testCase{
8353 protocol: dtls,
8354 testType: serverTest,
8355 name: "SendUnencryptedFinished-DTLS",
8356 config: Config{
8357 MaxVersion: VersionTLS12,
8358 Bugs: ProtocolBugs{
8359 SendUnencryptedFinished: true,
8360 ReverseHandshakeFragments: true,
8361 },
8362 },
8363 shouldFail: true,
8364 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8365 })
8366
Steven Valdez143e8b32016-07-11 13:19:03 -04008367 // Test synchronization between encryption changes and the handshake in
8368 // TLS 1.3, where ChangeCipherSpec is implicit.
8369 testCases = append(testCases, testCase{
8370 name: "PartialEncryptedExtensionsWithServerHello",
8371 config: Config{
8372 MaxVersion: VersionTLS13,
8373 Bugs: ProtocolBugs{
8374 PartialEncryptedExtensionsWithServerHello: true,
8375 },
8376 },
8377 shouldFail: true,
8378 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8379 })
8380 testCases = append(testCases, testCase{
8381 testType: serverTest,
8382 name: "PartialClientFinishedWithClientHello",
8383 config: Config{
8384 MaxVersion: VersionTLS13,
8385 Bugs: ProtocolBugs{
8386 PartialClientFinishedWithClientHello: true,
8387 },
8388 },
8389 shouldFail: true,
8390 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8391 })
8392
David Benjamin82261be2016-07-07 14:32:50 -07008393 // Test that early ChangeCipherSpecs are handled correctly.
8394 testCases = append(testCases, testCase{
8395 testType: serverTest,
8396 name: "EarlyChangeCipherSpec-server-1",
8397 config: Config{
8398 MaxVersion: VersionTLS12,
8399 Bugs: ProtocolBugs{
8400 EarlyChangeCipherSpec: 1,
8401 },
8402 },
8403 shouldFail: true,
8404 expectedError: ":UNEXPECTED_RECORD:",
8405 })
8406 testCases = append(testCases, testCase{
8407 testType: serverTest,
8408 name: "EarlyChangeCipherSpec-server-2",
8409 config: Config{
8410 MaxVersion: VersionTLS12,
8411 Bugs: ProtocolBugs{
8412 EarlyChangeCipherSpec: 2,
8413 },
8414 },
8415 shouldFail: true,
8416 expectedError: ":UNEXPECTED_RECORD:",
8417 })
8418 testCases = append(testCases, testCase{
8419 protocol: dtls,
8420 name: "StrayChangeCipherSpec",
8421 config: Config{
8422 // TODO(davidben): Once DTLS 1.3 exists, test
8423 // that stray ChangeCipherSpec messages are
8424 // rejected.
8425 MaxVersion: VersionTLS12,
8426 Bugs: ProtocolBugs{
8427 StrayChangeCipherSpec: true,
8428 },
8429 },
8430 })
8431
8432 // Test that the contents of ChangeCipherSpec are checked.
8433 testCases = append(testCases, testCase{
8434 name: "BadChangeCipherSpec-1",
8435 config: Config{
8436 MaxVersion: VersionTLS12,
8437 Bugs: ProtocolBugs{
8438 BadChangeCipherSpec: []byte{2},
8439 },
8440 },
8441 shouldFail: true,
8442 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8443 })
8444 testCases = append(testCases, testCase{
8445 name: "BadChangeCipherSpec-2",
8446 config: Config{
8447 MaxVersion: VersionTLS12,
8448 Bugs: ProtocolBugs{
8449 BadChangeCipherSpec: []byte{1, 1},
8450 },
8451 },
8452 shouldFail: true,
8453 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8454 })
8455 testCases = append(testCases, testCase{
8456 protocol: dtls,
8457 name: "BadChangeCipherSpec-DTLS-1",
8458 config: Config{
8459 MaxVersion: VersionTLS12,
8460 Bugs: ProtocolBugs{
8461 BadChangeCipherSpec: []byte{2},
8462 },
8463 },
8464 shouldFail: true,
8465 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8466 })
8467 testCases = append(testCases, testCase{
8468 protocol: dtls,
8469 name: "BadChangeCipherSpec-DTLS-2",
8470 config: Config{
8471 MaxVersion: VersionTLS12,
8472 Bugs: ProtocolBugs{
8473 BadChangeCipherSpec: []byte{1, 1},
8474 },
8475 },
8476 shouldFail: true,
8477 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8478 })
8479}
8480
David Benjamincd2c8062016-09-09 11:28:16 -04008481type perMessageTest struct {
8482 messageType uint8
8483 test testCase
8484}
8485
8486// makePerMessageTests returns a series of test templates which cover each
8487// message in the TLS handshake. These may be used with bugs like
8488// WrongMessageType to fully test a per-message bug.
8489func makePerMessageTests() []perMessageTest {
8490 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008491 for _, protocol := range []protocol{tls, dtls} {
8492 var suffix string
8493 if protocol == dtls {
8494 suffix = "-DTLS"
8495 }
8496
David Benjamincd2c8062016-09-09 11:28:16 -04008497 ret = append(ret, perMessageTest{
8498 messageType: typeClientHello,
8499 test: testCase{
8500 protocol: protocol,
8501 testType: serverTest,
8502 name: "ClientHello" + suffix,
8503 config: Config{
8504 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008505 },
8506 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008507 })
8508
8509 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008510 ret = append(ret, perMessageTest{
8511 messageType: typeHelloVerifyRequest,
8512 test: testCase{
8513 protocol: protocol,
8514 name: "HelloVerifyRequest" + suffix,
8515 config: Config{
8516 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008517 },
8518 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008519 })
8520 }
8521
David Benjamincd2c8062016-09-09 11:28:16 -04008522 ret = append(ret, perMessageTest{
8523 messageType: typeServerHello,
8524 test: testCase{
8525 protocol: protocol,
8526 name: "ServerHello" + suffix,
8527 config: Config{
8528 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008529 },
8530 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008531 })
8532
David Benjamincd2c8062016-09-09 11:28:16 -04008533 ret = append(ret, perMessageTest{
8534 messageType: typeCertificate,
8535 test: testCase{
8536 protocol: protocol,
8537 name: "ServerCertificate" + suffix,
8538 config: Config{
8539 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008540 },
8541 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008542 })
8543
David Benjamincd2c8062016-09-09 11:28:16 -04008544 ret = append(ret, perMessageTest{
8545 messageType: typeCertificateStatus,
8546 test: testCase{
8547 protocol: protocol,
8548 name: "CertificateStatus" + suffix,
8549 config: Config{
8550 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008551 },
David Benjamincd2c8062016-09-09 11:28:16 -04008552 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008553 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008554 })
8555
David Benjamincd2c8062016-09-09 11:28:16 -04008556 ret = append(ret, perMessageTest{
8557 messageType: typeServerKeyExchange,
8558 test: testCase{
8559 protocol: protocol,
8560 name: "ServerKeyExchange" + suffix,
8561 config: Config{
8562 MaxVersion: VersionTLS12,
8563 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008564 },
8565 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008566 })
8567
David Benjamincd2c8062016-09-09 11:28:16 -04008568 ret = append(ret, perMessageTest{
8569 messageType: typeCertificateRequest,
8570 test: testCase{
8571 protocol: protocol,
8572 name: "CertificateRequest" + suffix,
8573 config: Config{
8574 MaxVersion: VersionTLS12,
8575 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008576 },
8577 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008578 })
8579
David Benjamincd2c8062016-09-09 11:28:16 -04008580 ret = append(ret, perMessageTest{
8581 messageType: typeServerHelloDone,
8582 test: testCase{
8583 protocol: protocol,
8584 name: "ServerHelloDone" + suffix,
8585 config: Config{
8586 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008587 },
8588 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008589 })
8590
David Benjamincd2c8062016-09-09 11:28:16 -04008591 ret = append(ret, perMessageTest{
8592 messageType: typeCertificate,
8593 test: testCase{
8594 testType: serverTest,
8595 protocol: protocol,
8596 name: "ClientCertificate" + suffix,
8597 config: Config{
8598 Certificates: []Certificate{rsaCertificate},
8599 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008600 },
David Benjamincd2c8062016-09-09 11:28:16 -04008601 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008602 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008603 })
8604
David Benjamincd2c8062016-09-09 11:28:16 -04008605 ret = append(ret, perMessageTest{
8606 messageType: typeCertificateVerify,
8607 test: testCase{
8608 testType: serverTest,
8609 protocol: protocol,
8610 name: "CertificateVerify" + suffix,
8611 config: Config{
8612 Certificates: []Certificate{rsaCertificate},
8613 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008614 },
David Benjamincd2c8062016-09-09 11:28:16 -04008615 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008616 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008617 })
8618
David Benjamincd2c8062016-09-09 11:28:16 -04008619 ret = append(ret, perMessageTest{
8620 messageType: typeClientKeyExchange,
8621 test: testCase{
8622 testType: serverTest,
8623 protocol: protocol,
8624 name: "ClientKeyExchange" + suffix,
8625 config: Config{
8626 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008627 },
8628 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008629 })
8630
8631 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008632 ret = append(ret, perMessageTest{
8633 messageType: typeNextProtocol,
8634 test: testCase{
8635 testType: serverTest,
8636 protocol: protocol,
8637 name: "NextProtocol" + suffix,
8638 config: Config{
8639 MaxVersion: VersionTLS12,
8640 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008641 },
David Benjamincd2c8062016-09-09 11:28:16 -04008642 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008643 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008644 })
8645
David Benjamincd2c8062016-09-09 11:28:16 -04008646 ret = append(ret, perMessageTest{
8647 messageType: typeChannelID,
8648 test: testCase{
8649 testType: serverTest,
8650 protocol: protocol,
8651 name: "ChannelID" + suffix,
8652 config: Config{
8653 MaxVersion: VersionTLS12,
8654 ChannelID: channelIDKey,
8655 },
8656 flags: []string{
8657 "-expect-channel-id",
8658 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008659 },
8660 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008661 })
8662 }
8663
David Benjamincd2c8062016-09-09 11:28:16 -04008664 ret = append(ret, perMessageTest{
8665 messageType: typeFinished,
8666 test: testCase{
8667 testType: serverTest,
8668 protocol: protocol,
8669 name: "ClientFinished" + suffix,
8670 config: Config{
8671 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008672 },
8673 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008674 })
8675
David Benjamincd2c8062016-09-09 11:28:16 -04008676 ret = append(ret, perMessageTest{
8677 messageType: typeNewSessionTicket,
8678 test: testCase{
8679 protocol: protocol,
8680 name: "NewSessionTicket" + 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: typeFinished,
8689 test: testCase{
8690 protocol: protocol,
8691 name: "ServerFinished" + 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
8698 }
David Benjamincd2c8062016-09-09 11:28:16 -04008699
8700 ret = append(ret, perMessageTest{
8701 messageType: typeClientHello,
8702 test: testCase{
8703 testType: serverTest,
8704 name: "TLS13-ClientHello",
8705 config: Config{
8706 MaxVersion: VersionTLS13,
8707 },
8708 },
8709 })
8710
8711 ret = append(ret, perMessageTest{
8712 messageType: typeServerHello,
8713 test: testCase{
8714 name: "TLS13-ServerHello",
8715 config: Config{
8716 MaxVersion: VersionTLS13,
8717 },
8718 },
8719 })
8720
8721 ret = append(ret, perMessageTest{
8722 messageType: typeEncryptedExtensions,
8723 test: testCase{
8724 name: "TLS13-EncryptedExtensions",
8725 config: Config{
8726 MaxVersion: VersionTLS13,
8727 },
8728 },
8729 })
8730
8731 ret = append(ret, perMessageTest{
8732 messageType: typeCertificateRequest,
8733 test: testCase{
8734 name: "TLS13-CertificateRequest",
8735 config: Config{
8736 MaxVersion: VersionTLS13,
8737 ClientAuth: RequireAnyClientCert,
8738 },
8739 },
8740 })
8741
8742 ret = append(ret, perMessageTest{
8743 messageType: typeCertificate,
8744 test: testCase{
8745 name: "TLS13-ServerCertificate",
8746 config: Config{
8747 MaxVersion: VersionTLS13,
8748 },
8749 },
8750 })
8751
8752 ret = append(ret, perMessageTest{
8753 messageType: typeCertificateVerify,
8754 test: testCase{
8755 name: "TLS13-ServerCertificateVerify",
8756 config: Config{
8757 MaxVersion: VersionTLS13,
8758 },
8759 },
8760 })
8761
8762 ret = append(ret, perMessageTest{
8763 messageType: typeFinished,
8764 test: testCase{
8765 name: "TLS13-ServerFinished",
8766 config: Config{
8767 MaxVersion: VersionTLS13,
8768 },
8769 },
8770 })
8771
8772 ret = append(ret, perMessageTest{
8773 messageType: typeCertificate,
8774 test: testCase{
8775 testType: serverTest,
8776 name: "TLS13-ClientCertificate",
8777 config: Config{
8778 Certificates: []Certificate{rsaCertificate},
8779 MaxVersion: VersionTLS13,
8780 },
8781 flags: []string{"-require-any-client-certificate"},
8782 },
8783 })
8784
8785 ret = append(ret, perMessageTest{
8786 messageType: typeCertificateVerify,
8787 test: testCase{
8788 testType: serverTest,
8789 name: "TLS13-ClientCertificateVerify",
8790 config: Config{
8791 Certificates: []Certificate{rsaCertificate},
8792 MaxVersion: VersionTLS13,
8793 },
8794 flags: []string{"-require-any-client-certificate"},
8795 },
8796 })
8797
8798 ret = append(ret, perMessageTest{
8799 messageType: typeFinished,
8800 test: testCase{
8801 testType: serverTest,
8802 name: "TLS13-ClientFinished",
8803 config: Config{
8804 MaxVersion: VersionTLS13,
8805 },
8806 },
8807 })
8808
8809 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008810}
8811
David Benjamincd2c8062016-09-09 11:28:16 -04008812func addWrongMessageTypeTests() {
8813 for _, t := range makePerMessageTests() {
8814 t.test.name = "WrongMessageType-" + t.test.name
8815 t.test.config.Bugs.SendWrongMessageType = t.messageType
8816 t.test.shouldFail = true
8817 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8818 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008819
David Benjamincd2c8062016-09-09 11:28:16 -04008820 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8821 // In TLS 1.3, a bad ServerHello means the client sends
8822 // an unencrypted alert while the server expects
8823 // encryption, so the alert is not readable by runner.
8824 t.test.expectedLocalError = "local error: bad record MAC"
8825 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008826
David Benjamincd2c8062016-09-09 11:28:16 -04008827 testCases = append(testCases, t.test)
8828 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008829}
8830
David Benjamin639846e2016-09-09 11:41:18 -04008831func addTrailingMessageDataTests() {
8832 for _, t := range makePerMessageTests() {
8833 t.test.name = "TrailingMessageData-" + t.test.name
8834 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8835 t.test.shouldFail = true
8836 t.test.expectedError = ":DECODE_ERROR:"
8837 t.test.expectedLocalError = "remote error: error decoding message"
8838
8839 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8840 // In TLS 1.3, a bad ServerHello means the client sends
8841 // an unencrypted alert while the server expects
8842 // encryption, so the alert is not readable by runner.
8843 t.test.expectedLocalError = "local error: bad record MAC"
8844 }
8845
8846 if t.messageType == typeFinished {
8847 // Bad Finished messages read as the verify data having
8848 // the wrong length.
8849 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8850 t.test.expectedLocalError = "remote error: error decrypting message"
8851 }
8852
8853 testCases = append(testCases, t.test)
8854 }
8855}
8856
Steven Valdez143e8b32016-07-11 13:19:03 -04008857func addTLS13HandshakeTests() {
8858 testCases = append(testCases, testCase{
8859 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008860 name: "NegotiatePSKResumption-TLS13",
8861 config: Config{
8862 MaxVersion: VersionTLS13,
8863 Bugs: ProtocolBugs{
8864 NegotiatePSKResumption: true,
8865 },
8866 },
8867 resumeSession: true,
8868 shouldFail: true,
8869 expectedError: ":UNEXPECTED_EXTENSION:",
8870 })
8871
8872 testCases = append(testCases, testCase{
8873 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008874 name: "MissingKeyShare-Client",
8875 config: Config{
8876 MaxVersion: VersionTLS13,
8877 Bugs: ProtocolBugs{
8878 MissingKeyShare: true,
8879 },
8880 },
8881 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008882 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008883 })
8884
8885 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008886 testType: serverTest,
8887 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008888 config: Config{
8889 MaxVersion: VersionTLS13,
8890 Bugs: ProtocolBugs{
8891 MissingKeyShare: true,
8892 },
8893 },
8894 shouldFail: true,
8895 expectedError: ":MISSING_KEY_SHARE:",
8896 })
8897
8898 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008899 testType: serverTest,
8900 name: "DuplicateKeyShares",
8901 config: Config{
8902 MaxVersion: VersionTLS13,
8903 Bugs: ProtocolBugs{
8904 DuplicateKeyShares: true,
8905 },
8906 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008907 shouldFail: true,
8908 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008909 })
8910
8911 testCases = append(testCases, testCase{
8912 testType: clientTest,
8913 name: "EmptyEncryptedExtensions",
8914 config: Config{
8915 MaxVersion: VersionTLS13,
8916 Bugs: ProtocolBugs{
8917 EmptyEncryptedExtensions: true,
8918 },
8919 },
8920 shouldFail: true,
8921 expectedLocalError: "remote error: error decoding message",
8922 })
8923
8924 testCases = append(testCases, testCase{
8925 testType: clientTest,
8926 name: "EncryptedExtensionsWithKeyShare",
8927 config: Config{
8928 MaxVersion: VersionTLS13,
8929 Bugs: ProtocolBugs{
8930 EncryptedExtensionsWithKeyShare: true,
8931 },
8932 },
8933 shouldFail: true,
8934 expectedLocalError: "remote error: unsupported extension",
8935 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008936
8937 testCases = append(testCases, testCase{
8938 testType: serverTest,
8939 name: "SendHelloRetryRequest",
8940 config: Config{
8941 MaxVersion: VersionTLS13,
8942 // Require a HelloRetryRequest for every curve.
8943 DefaultCurves: []CurveID{},
8944 },
8945 expectedCurveID: CurveX25519,
8946 })
8947
8948 testCases = append(testCases, testCase{
8949 testType: serverTest,
8950 name: "SendHelloRetryRequest-2",
8951 config: Config{
8952 MaxVersion: VersionTLS13,
8953 DefaultCurves: []CurveID{CurveP384},
8954 },
8955 // Although the ClientHello did not predict our preferred curve,
8956 // we always select it whether it is predicted or not.
8957 expectedCurveID: CurveX25519,
8958 })
8959
8960 testCases = append(testCases, testCase{
8961 name: "UnknownCurve-HelloRetryRequest",
8962 config: Config{
8963 MaxVersion: VersionTLS13,
8964 // P-384 requires HelloRetryRequest in BoringSSL.
8965 CurvePreferences: []CurveID{CurveP384},
8966 Bugs: ProtocolBugs{
8967 SendHelloRetryRequestCurve: bogusCurve,
8968 },
8969 },
8970 shouldFail: true,
8971 expectedError: ":WRONG_CURVE:",
8972 })
8973
8974 testCases = append(testCases, testCase{
8975 name: "DisabledCurve-HelloRetryRequest",
8976 config: Config{
8977 MaxVersion: VersionTLS13,
8978 CurvePreferences: []CurveID{CurveP256},
8979 Bugs: ProtocolBugs{
8980 IgnorePeerCurvePreferences: true,
8981 },
8982 },
8983 flags: []string{"-p384-only"},
8984 shouldFail: true,
8985 expectedError: ":WRONG_CURVE:",
8986 })
8987
8988 testCases = append(testCases, testCase{
8989 name: "UnnecessaryHelloRetryRequest",
8990 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04008991 MaxVersion: VersionTLS13,
8992 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04008993 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04008994 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04008995 },
8996 },
8997 shouldFail: true,
8998 expectedError: ":WRONG_CURVE:",
8999 })
9000
9001 testCases = append(testCases, testCase{
9002 name: "SecondHelloRetryRequest",
9003 config: Config{
9004 MaxVersion: VersionTLS13,
9005 // P-384 requires HelloRetryRequest in BoringSSL.
9006 CurvePreferences: []CurveID{CurveP384},
9007 Bugs: ProtocolBugs{
9008 SecondHelloRetryRequest: true,
9009 },
9010 },
9011 shouldFail: true,
9012 expectedError: ":UNEXPECTED_MESSAGE:",
9013 })
9014
9015 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009016 name: "HelloRetryRequest-Empty",
9017 config: Config{
9018 MaxVersion: VersionTLS13,
9019 Bugs: ProtocolBugs{
9020 AlwaysSendHelloRetryRequest: true,
9021 },
9022 },
9023 shouldFail: true,
9024 expectedError: ":DECODE_ERROR:",
9025 })
9026
9027 testCases = append(testCases, testCase{
9028 name: "HelloRetryRequest-DuplicateCurve",
9029 config: Config{
9030 MaxVersion: VersionTLS13,
9031 // P-384 requires a HelloRetryRequest against BoringSSL's default
9032 // configuration. Assert this ExpectMissingKeyShare.
9033 CurvePreferences: []CurveID{CurveP384},
9034 Bugs: ProtocolBugs{
9035 ExpectMissingKeyShare: true,
9036 DuplicateHelloRetryRequestExtensions: true,
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":DUPLICATE_EXTENSION:",
9041 expectedLocalError: "remote error: illegal parameter",
9042 })
9043
9044 testCases = append(testCases, testCase{
9045 name: "HelloRetryRequest-Cookie",
9046 config: Config{
9047 MaxVersion: VersionTLS13,
9048 Bugs: ProtocolBugs{
9049 SendHelloRetryRequestCookie: []byte("cookie"),
9050 },
9051 },
9052 })
9053
9054 testCases = append(testCases, testCase{
9055 name: "HelloRetryRequest-DuplicateCookie",
9056 config: Config{
9057 MaxVersion: VersionTLS13,
9058 Bugs: ProtocolBugs{
9059 SendHelloRetryRequestCookie: []byte("cookie"),
9060 DuplicateHelloRetryRequestExtensions: true,
9061 },
9062 },
9063 shouldFail: true,
9064 expectedError: ":DUPLICATE_EXTENSION:",
9065 expectedLocalError: "remote error: illegal parameter",
9066 })
9067
9068 testCases = append(testCases, testCase{
9069 name: "HelloRetryRequest-EmptyCookie",
9070 config: Config{
9071 MaxVersion: VersionTLS13,
9072 Bugs: ProtocolBugs{
9073 SendHelloRetryRequestCookie: []byte{},
9074 },
9075 },
9076 shouldFail: true,
9077 expectedError: ":DECODE_ERROR:",
9078 })
9079
9080 testCases = append(testCases, testCase{
9081 name: "HelloRetryRequest-Cookie-Curve",
9082 config: Config{
9083 MaxVersion: VersionTLS13,
9084 // P-384 requires HelloRetryRequest in BoringSSL.
9085 CurvePreferences: []CurveID{CurveP384},
9086 Bugs: ProtocolBugs{
9087 SendHelloRetryRequestCookie: []byte("cookie"),
9088 ExpectMissingKeyShare: true,
9089 },
9090 },
9091 })
9092
9093 testCases = append(testCases, testCase{
9094 name: "HelloRetryRequest-Unknown",
9095 config: Config{
9096 MaxVersion: VersionTLS13,
9097 Bugs: ProtocolBugs{
9098 CustomHelloRetryRequestExtension: "extension",
9099 },
9100 },
9101 shouldFail: true,
9102 expectedError: ":UNEXPECTED_EXTENSION:",
9103 expectedLocalError: "remote error: unsupported extension",
9104 })
9105
9106 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009107 testType: serverTest,
9108 name: "SecondClientHelloMissingKeyShare",
9109 config: Config{
9110 MaxVersion: VersionTLS13,
9111 DefaultCurves: []CurveID{},
9112 Bugs: ProtocolBugs{
9113 SecondClientHelloMissingKeyShare: true,
9114 },
9115 },
9116 shouldFail: true,
9117 expectedError: ":MISSING_KEY_SHARE:",
9118 })
9119
9120 testCases = append(testCases, testCase{
9121 testType: serverTest,
9122 name: "SecondClientHelloWrongCurve",
9123 config: Config{
9124 MaxVersion: VersionTLS13,
9125 DefaultCurves: []CurveID{},
9126 Bugs: ProtocolBugs{
9127 MisinterpretHelloRetryRequestCurve: CurveP521,
9128 },
9129 },
9130 shouldFail: true,
9131 expectedError: ":WRONG_CURVE:",
9132 })
9133
9134 testCases = append(testCases, testCase{
9135 name: "HelloRetryRequestVersionMismatch",
9136 config: Config{
9137 MaxVersion: VersionTLS13,
9138 // P-384 requires HelloRetryRequest in BoringSSL.
9139 CurvePreferences: []CurveID{CurveP384},
9140 Bugs: ProtocolBugs{
9141 SendServerHelloVersion: 0x0305,
9142 },
9143 },
9144 shouldFail: true,
9145 expectedError: ":WRONG_VERSION_NUMBER:",
9146 })
9147
9148 testCases = append(testCases, testCase{
9149 name: "HelloRetryRequestCurveMismatch",
9150 config: Config{
9151 MaxVersion: VersionTLS13,
9152 // P-384 requires HelloRetryRequest in BoringSSL.
9153 CurvePreferences: []CurveID{CurveP384},
9154 Bugs: ProtocolBugs{
9155 // Send P-384 (correct) in the HelloRetryRequest.
9156 SendHelloRetryRequestCurve: CurveP384,
9157 // But send P-256 in the ServerHello.
9158 SendCurve: CurveP256,
9159 },
9160 },
9161 shouldFail: true,
9162 expectedError: ":WRONG_CURVE:",
9163 })
9164
9165 // Test the server selecting a curve that requires a HelloRetryRequest
9166 // without sending it.
9167 testCases = append(testCases, testCase{
9168 name: "SkipHelloRetryRequest",
9169 config: Config{
9170 MaxVersion: VersionTLS13,
9171 // P-384 requires HelloRetryRequest in BoringSSL.
9172 CurvePreferences: []CurveID{CurveP384},
9173 Bugs: ProtocolBugs{
9174 SkipHelloRetryRequest: true,
9175 },
9176 },
9177 shouldFail: true,
9178 expectedError: ":WRONG_CURVE:",
9179 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009180
9181 testCases = append(testCases, testCase{
9182 name: "TLS13-RequestContextInHandshake",
9183 config: Config{
9184 MaxVersion: VersionTLS13,
9185 MinVersion: VersionTLS13,
9186 ClientAuth: RequireAnyClientCert,
9187 Bugs: ProtocolBugs{
9188 SendRequestContext: []byte("request context"),
9189 },
9190 },
9191 flags: []string{
9192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9194 },
9195 shouldFail: true,
9196 expectedError: ":DECODE_ERROR:",
9197 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009198
9199 testCases = append(testCases, testCase{
9200 testType: serverTest,
9201 name: "TLS13-TrailingKeyShareData",
9202 config: Config{
9203 MaxVersion: VersionTLS13,
9204 Bugs: ProtocolBugs{
9205 TrailingKeyShareData: true,
9206 },
9207 },
9208 shouldFail: true,
9209 expectedError: ":DECODE_ERROR:",
9210 })
David Benjamin7f78df42016-10-05 22:33:19 -04009211
9212 testCases = append(testCases, testCase{
9213 name: "TLS13-AlwaysSelectPSKIdentity",
9214 config: Config{
9215 MaxVersion: VersionTLS13,
9216 Bugs: ProtocolBugs{
9217 AlwaysSelectPSKIdentity: true,
9218 },
9219 },
9220 shouldFail: true,
9221 expectedError: ":UNEXPECTED_EXTENSION:",
9222 })
9223
9224 testCases = append(testCases, testCase{
9225 name: "TLS13-InvalidPSKIdentity",
9226 config: Config{
9227 MaxVersion: VersionTLS13,
9228 Bugs: ProtocolBugs{
9229 SelectPSKIdentityOnResume: 1,
9230 },
9231 },
9232 resumeSession: true,
9233 shouldFail: true,
9234 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9235 })
David Benjamin1286bee2016-10-07 15:25:06 -04009236
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009237 testCases = append(testCases, testCase{
9238 testType: serverTest,
9239 name: "TLS13-ExtraPSKIdentity",
9240 config: Config{
9241 MaxVersion: VersionTLS13,
9242 Bugs: ProtocolBugs{
9243 ExtraPSKIdentity: true,
9244 },
9245 },
9246 resumeSession: true,
9247 })
9248
David Benjamin1286bee2016-10-07 15:25:06 -04009249 // Test that unknown NewSessionTicket extensions are tolerated.
9250 testCases = append(testCases, testCase{
9251 name: "TLS13-CustomTicketExtension",
9252 config: Config{
9253 MaxVersion: VersionTLS13,
9254 Bugs: ProtocolBugs{
9255 CustomTicketExtension: "1234",
9256 },
9257 },
9258 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009259}
9260
David Benjaminabbbee12016-10-31 19:20:42 -04009261func addTLS13CipherPreferenceTests() {
9262 // Test that client preference is honored if the shim has AES hardware
9263 // and ChaCha20-Poly1305 is preferred otherwise.
9264 testCases = append(testCases, testCase{
9265 testType: serverTest,
9266 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9267 config: Config{
9268 MaxVersion: VersionTLS13,
9269 CipherSuites: []uint16{
9270 TLS_CHACHA20_POLY1305_SHA256,
9271 TLS_AES_128_GCM_SHA256,
9272 },
9273 },
9274 flags: []string{
9275 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9276 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9277 },
9278 })
9279
9280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9283 config: Config{
9284 MaxVersion: VersionTLS13,
9285 CipherSuites: []uint16{
9286 TLS_AES_128_GCM_SHA256,
9287 TLS_CHACHA20_POLY1305_SHA256,
9288 },
9289 },
9290 flags: []string{
9291 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9292 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9293 },
9294 })
9295
9296 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9297 // whether it has AES hardware.
9298 testCases = append(testCases, testCase{
9299 name: "TLS13-CipherPreference-Client",
9300 config: Config{
9301 MaxVersion: VersionTLS13,
9302 // Use the client cipher order. (This is the default but
9303 // is listed to be explicit.)
9304 PreferServerCipherSuites: false,
9305 },
9306 flags: []string{
9307 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9308 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9309 },
9310 })
9311}
9312
David Benjaminf3fbade2016-09-19 13:08:16 -04009313func addPeekTests() {
9314 // Test SSL_peek works, including on empty records.
9315 testCases = append(testCases, testCase{
9316 name: "Peek-Basic",
9317 sendEmptyRecords: 1,
9318 flags: []string{"-peek-then-read"},
9319 })
9320
9321 // Test SSL_peek can drive the initial handshake.
9322 testCases = append(testCases, testCase{
9323 name: "Peek-ImplicitHandshake",
9324 flags: []string{
9325 "-peek-then-read",
9326 "-implicit-handshake",
9327 },
9328 })
9329
9330 // Test SSL_peek can discover and drive a renegotiation.
9331 testCases = append(testCases, testCase{
9332 name: "Peek-Renegotiate",
9333 config: Config{
9334 MaxVersion: VersionTLS12,
9335 },
9336 renegotiate: 1,
9337 flags: []string{
9338 "-peek-then-read",
9339 "-renegotiate-freely",
9340 "-expect-total-renegotiations", "1",
9341 },
9342 })
9343
9344 // Test SSL_peek can discover a close_notify.
9345 testCases = append(testCases, testCase{
9346 name: "Peek-Shutdown",
9347 config: Config{
9348 Bugs: ProtocolBugs{
9349 ExpectCloseNotify: true,
9350 },
9351 },
9352 flags: []string{
9353 "-peek-then-read",
9354 "-check-close-notify",
9355 },
9356 })
9357
9358 // Test SSL_peek can discover an alert.
9359 testCases = append(testCases, testCase{
9360 name: "Peek-Alert",
9361 config: Config{
9362 Bugs: ProtocolBugs{
9363 SendSpuriousAlert: alertRecordOverflow,
9364 },
9365 },
9366 flags: []string{"-peek-then-read"},
9367 shouldFail: true,
9368 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9369 })
9370
9371 // Test SSL_peek can handle KeyUpdate.
9372 testCases = append(testCases, testCase{
9373 name: "Peek-KeyUpdate",
9374 config: Config{
9375 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009376 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009377 sendKeyUpdates: 1,
9378 keyUpdateRequest: keyUpdateNotRequested,
9379 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009380 })
9381}
9382
David Benjamine6f22212016-11-08 14:28:24 -05009383func addRecordVersionTests() {
9384 for _, ver := range tlsVersions {
9385 // Test that the record version is enforced.
9386 testCases = append(testCases, testCase{
9387 name: "CheckRecordVersion-" + ver.name,
9388 config: Config{
9389 MinVersion: ver.version,
9390 MaxVersion: ver.version,
9391 Bugs: ProtocolBugs{
9392 SendRecordVersion: 0x03ff,
9393 },
9394 },
9395 shouldFail: true,
9396 expectedError: ":WRONG_VERSION_NUMBER:",
9397 })
9398
9399 // Test that the ClientHello may use any record version, for
9400 // compatibility reasons.
9401 testCases = append(testCases, testCase{
9402 testType: serverTest,
9403 name: "LooseInitialRecordVersion-" + ver.name,
9404 config: Config{
9405 MinVersion: ver.version,
9406 MaxVersion: ver.version,
9407 Bugs: ProtocolBugs{
9408 SendInitialRecordVersion: 0x03ff,
9409 },
9410 },
9411 })
9412
9413 // Test that garbage ClientHello record versions are rejected.
9414 testCases = append(testCases, testCase{
9415 testType: serverTest,
9416 name: "GarbageInitialRecordVersion-" + ver.name,
9417 config: Config{
9418 MinVersion: ver.version,
9419 MaxVersion: ver.version,
9420 Bugs: ProtocolBugs{
9421 SendInitialRecordVersion: 0xffff,
9422 },
9423 },
9424 shouldFail: true,
9425 expectedError: ":WRONG_VERSION_NUMBER:",
9426 })
9427 }
9428}
9429
David Benjamin2c516452016-11-15 10:16:54 +09009430func addCertificateTests() {
9431 // Test that a certificate chain with intermediate may be sent and
9432 // received as both client and server.
9433 for _, ver := range tlsVersions {
9434 testCases = append(testCases, testCase{
9435 testType: clientTest,
9436 name: "SendReceiveIntermediate-Client-" + ver.name,
9437 config: Config{
9438 Certificates: []Certificate{rsaChainCertificate},
9439 ClientAuth: RequireAnyClientCert,
9440 },
9441 expectPeerCertificate: &rsaChainCertificate,
9442 flags: []string{
9443 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9444 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9445 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9446 },
9447 })
9448
9449 testCases = append(testCases, testCase{
9450 testType: serverTest,
9451 name: "SendReceiveIntermediate-Server-" + ver.name,
9452 config: Config{
9453 Certificates: []Certificate{rsaChainCertificate},
9454 },
9455 expectPeerCertificate: &rsaChainCertificate,
9456 flags: []string{
9457 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9458 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9459 "-require-any-client-certificate",
9460 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9461 },
9462 })
9463 }
9464}
9465
Adam Langley7c803a62015-06-15 15:35:05 -07009466func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009467 defer wg.Done()
9468
9469 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009470 var err error
9471
David Benjaminba28dfc2016-11-15 17:47:21 +09009472 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009473 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9474 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009475 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009476 if err != nil {
9477 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9478 }
9479 break
9480 }
9481 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009482 } else if *repeatUntilFailure {
9483 for err == nil {
9484 statusChan <- statusMsg{test: test, started: true}
9485 err = runTest(test, shimPath, -1)
9486 }
9487 } else {
9488 statusChan <- statusMsg{test: test, started: true}
9489 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009490 }
Adam Langley95c29f32014-06-20 12:00:00 -07009491 statusChan <- statusMsg{test: test, err: err}
9492 }
9493}
9494
9495type statusMsg struct {
9496 test *testCase
9497 started bool
9498 err error
9499}
9500
David Benjamin5f237bc2015-02-11 17:14:15 -05009501func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009502 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009503
David Benjamin5f237bc2015-02-11 17:14:15 -05009504 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009505 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009506 if !*pipe {
9507 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009508 var erase string
9509 for i := 0; i < lineLen; i++ {
9510 erase += "\b \b"
9511 }
9512 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009513 }
9514
Adam Langley95c29f32014-06-20 12:00:00 -07009515 if msg.started {
9516 started++
9517 } else {
9518 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009519
9520 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009521 if msg.err == errUnimplemented {
9522 if *pipe {
9523 // Print each test instead of a status line.
9524 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9525 }
9526 unimplemented++
9527 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9528 } else {
9529 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9530 failed++
9531 testOutput.addResult(msg.test.name, "FAIL")
9532 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009533 } else {
9534 if *pipe {
9535 // Print each test instead of a status line.
9536 fmt.Printf("PASSED (%s)\n", msg.test.name)
9537 }
9538 testOutput.addResult(msg.test.name, "PASS")
9539 }
Adam Langley95c29f32014-06-20 12:00:00 -07009540 }
9541
David Benjamin5f237bc2015-02-11 17:14:15 -05009542 if !*pipe {
9543 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009544 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009545 lineLen = len(line)
9546 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009547 }
Adam Langley95c29f32014-06-20 12:00:00 -07009548 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009549
9550 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009551}
9552
9553func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009554 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009555 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009556 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009557
Adam Langley7c803a62015-06-15 15:35:05 -07009558 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009559 addCipherSuiteTests()
9560 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009561 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009562 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009563 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009564 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009565 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009566 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009567 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009568 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009569 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009570 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009571 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009572 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009573 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009574 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009575 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009576 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009577 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009578 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009579 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009580 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009581 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009582 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009583 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009584 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009585 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009586 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009587 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009588 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009589 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009590 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009591 addCertificateTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009592
9593 var wg sync.WaitGroup
9594
Adam Langley7c803a62015-06-15 15:35:05 -07009595 statusChan := make(chan statusMsg, *numWorkers)
9596 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009597 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009598
EKRf71d7ed2016-08-06 13:25:12 -07009599 if len(*shimConfigFile) != 0 {
9600 encoded, err := ioutil.ReadFile(*shimConfigFile)
9601 if err != nil {
9602 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9603 os.Exit(1)
9604 }
9605
9606 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9607 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9608 os.Exit(1)
9609 }
9610 }
9611
David Benjamin025b3d32014-07-01 19:53:04 -04009612 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009613
Adam Langley7c803a62015-06-15 15:35:05 -07009614 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009615 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009616 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009617 }
9618
David Benjamin270f0a72016-03-17 14:41:36 -04009619 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009620 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009621 matched := true
9622 if len(*testToRun) != 0 {
9623 var err error
9624 matched, err = filepath.Match(*testToRun, testCases[i].name)
9625 if err != nil {
9626 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9627 os.Exit(1)
9628 }
9629 }
9630
EKRf71d7ed2016-08-06 13:25:12 -07009631 if !*includeDisabled {
9632 for pattern := range shimConfig.DisabledTests {
9633 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9634 if err != nil {
9635 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9636 os.Exit(1)
9637 }
9638
9639 if isDisabled {
9640 matched = false
9641 break
9642 }
9643 }
9644 }
9645
David Benjamin17e12922016-07-28 18:04:43 -04009646 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009647 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009648 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +09009649
9650 // Only run one test if repeating until failure.
9651 if *repeatUntilFailure {
9652 break
9653 }
Adam Langley95c29f32014-06-20 12:00:00 -07009654 }
9655 }
David Benjamin17e12922016-07-28 18:04:43 -04009656
David Benjamin270f0a72016-03-17 14:41:36 -04009657 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009658 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009659 os.Exit(1)
9660 }
Adam Langley95c29f32014-06-20 12:00:00 -07009661
9662 close(testChan)
9663 wg.Wait()
9664 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009665 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009666
9667 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009668
9669 if *jsonOutput != "" {
9670 if err := testOutput.writeTo(*jsonOutput); err != nil {
9671 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9672 }
9673 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009674
EKR842ae6c2016-07-27 09:22:05 +02009675 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9676 os.Exit(1)
9677 }
9678
9679 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009680 os.Exit(1)
9681 }
Adam Langley95c29f32014-06-20 12:00:00 -07009682}