blob: ad71167aa7079813490f01691531be8cbc3c63bf [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
David Benjamine1cc35e2016-11-16 16:25:58 +09005808 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5809 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005810 testCases = append(testCases, testCase{
5811 name: "Resume-Client-CipherMismatch-TLS13",
5812 resumeSession: true,
5813 config: Config{
5814 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005815 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005816 },
5817 resumeConfig: &Config{
5818 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005819 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5820 },
5821 })
5822
5823 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5824 testCases = append(testCases, testCase{
5825 name: "Resume-Client-PRFMismatch-TLS13",
5826 resumeSession: true,
5827 config: Config{
5828 MaxVersion: VersionTLS13,
5829 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5830 },
5831 resumeConfig: &Config{
5832 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005833 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005834 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005835 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005836 },
5837 },
5838 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005839 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005840 })
Steven Valdeza833c352016-11-01 13:39:36 -04005841
5842 testCases = append(testCases, testCase{
5843 testType: serverTest,
5844 name: "Resume-Server-BinderWrongLength",
5845 resumeSession: true,
5846 config: Config{
5847 MaxVersion: VersionTLS13,
5848 Bugs: ProtocolBugs{
5849 SendShortPSKBinder: true,
5850 },
5851 },
5852 shouldFail: true,
5853 expectedLocalError: "remote error: error decrypting message",
5854 expectedError: ":DIGEST_CHECK_FAILED:",
5855 })
5856
5857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "Resume-Server-NoPSKBinder",
5860 resumeSession: true,
5861 config: Config{
5862 MaxVersion: VersionTLS13,
5863 Bugs: ProtocolBugs{
5864 SendNoPSKBinder: true,
5865 },
5866 },
5867 shouldFail: true,
5868 expectedLocalError: "remote error: error decoding message",
5869 expectedError: ":DECODE_ERROR:",
5870 })
5871
5872 testCases = append(testCases, testCase{
5873 testType: serverTest,
5874 name: "Resume-Server-InvalidPSKBinder",
5875 resumeSession: true,
5876 config: Config{
5877 MaxVersion: VersionTLS13,
5878 Bugs: ProtocolBugs{
5879 SendInvalidPSKBinder: true,
5880 },
5881 },
5882 shouldFail: true,
5883 expectedLocalError: "remote error: error decrypting message",
5884 expectedError: ":DIGEST_CHECK_FAILED:",
5885 })
5886
5887 testCases = append(testCases, testCase{
5888 testType: serverTest,
5889 name: "Resume-Server-PSKBinderFirstExtension",
5890 resumeSession: true,
5891 config: Config{
5892 MaxVersion: VersionTLS13,
5893 Bugs: ProtocolBugs{
5894 PSKBinderFirst: true,
5895 },
5896 },
5897 shouldFail: true,
5898 expectedLocalError: "remote error: illegal parameter",
5899 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
5900 })
David Benjamin01fe8202014-09-24 15:21:44 -04005901}
5902
Adam Langley2ae77d22014-10-28 17:29:33 -07005903func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005904 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005905 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005906 testType: serverTest,
5907 name: "Renegotiate-Server-Forbidden",
5908 config: Config{
5909 MaxVersion: VersionTLS12,
5910 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005911 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005912 shouldFail: true,
5913 expectedError: ":NO_RENEGOTIATION:",
5914 expectedLocalError: "remote error: no renegotiation",
5915 })
Adam Langley5021b222015-06-12 18:27:58 -07005916 // The server shouldn't echo the renegotiation extension unless
5917 // requested by the client.
5918 testCases = append(testCases, testCase{
5919 testType: serverTest,
5920 name: "Renegotiate-Server-NoExt",
5921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005922 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005923 Bugs: ProtocolBugs{
5924 NoRenegotiationInfo: true,
5925 RequireRenegotiationInfo: true,
5926 },
5927 },
5928 shouldFail: true,
5929 expectedLocalError: "renegotiation extension missing",
5930 })
5931 // The renegotiation SCSV should be sufficient for the server to echo
5932 // the extension.
5933 testCases = append(testCases, testCase{
5934 testType: serverTest,
5935 name: "Renegotiate-Server-NoExt-SCSV",
5936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005937 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005938 Bugs: ProtocolBugs{
5939 NoRenegotiationInfo: true,
5940 SendRenegotiationSCSV: true,
5941 RequireRenegotiationInfo: true,
5942 },
5943 },
5944 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005945 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005946 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005947 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005948 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005949 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005950 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005951 },
5952 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005953 renegotiate: 1,
5954 flags: []string{
5955 "-renegotiate-freely",
5956 "-expect-total-renegotiations", "1",
5957 },
David Benjamincdea40c2015-03-19 14:09:43 -04005958 })
5959 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005960 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005961 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005963 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005964 Bugs: ProtocolBugs{
5965 EmptyRenegotiationInfo: true,
5966 },
5967 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005968 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005969 shouldFail: true,
5970 expectedError: ":RENEGOTIATION_MISMATCH:",
5971 })
5972 testCases = append(testCases, testCase{
5973 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005974 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005976 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005977 Bugs: ProtocolBugs{
5978 BadRenegotiationInfo: true,
5979 },
5980 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005981 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005982 shouldFail: true,
5983 expectedError: ":RENEGOTIATION_MISMATCH:",
5984 })
5985 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005986 name: "Renegotiate-Client-Downgrade",
5987 renegotiate: 1,
5988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005989 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005990 Bugs: ProtocolBugs{
5991 NoRenegotiationInfoAfterInitial: true,
5992 },
5993 },
5994 flags: []string{"-renegotiate-freely"},
5995 shouldFail: true,
5996 expectedError: ":RENEGOTIATION_MISMATCH:",
5997 })
5998 testCases = append(testCases, testCase{
5999 name: "Renegotiate-Client-Upgrade",
6000 renegotiate: 1,
6001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006002 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006003 Bugs: ProtocolBugs{
6004 NoRenegotiationInfoInInitial: true,
6005 },
6006 },
6007 flags: []string{"-renegotiate-freely"},
6008 shouldFail: true,
6009 expectedError: ":RENEGOTIATION_MISMATCH:",
6010 })
6011 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006012 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006013 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006015 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006016 Bugs: ProtocolBugs{
6017 NoRenegotiationInfo: true,
6018 },
6019 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006020 flags: []string{
6021 "-renegotiate-freely",
6022 "-expect-total-renegotiations", "1",
6023 },
David Benjamincff0b902015-05-15 23:09:47 -04006024 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006025
6026 // Test that the server may switch ciphers on renegotiation without
6027 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006028 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006029 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006030 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006031 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006032 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006033 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006034 },
6035 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006036 flags: []string{
6037 "-renegotiate-freely",
6038 "-expect-total-renegotiations", "1",
6039 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006040 })
6041 testCases = append(testCases, testCase{
6042 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006043 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006044 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006045 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006046 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6047 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006048 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006049 flags: []string{
6050 "-renegotiate-freely",
6051 "-expect-total-renegotiations", "1",
6052 },
David Benjaminb16346b2015-04-08 19:16:58 -04006053 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006054
6055 // Test that the server may not switch versions on renegotiation.
6056 testCases = append(testCases, testCase{
6057 name: "Renegotiate-Client-SwitchVersion",
6058 config: Config{
6059 MaxVersion: VersionTLS12,
6060 // Pick a cipher which exists at both versions.
6061 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6062 Bugs: ProtocolBugs{
6063 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006064 // Avoid failing early at the record layer.
6065 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006066 },
6067 },
6068 renegotiate: 1,
6069 flags: []string{
6070 "-renegotiate-freely",
6071 "-expect-total-renegotiations", "1",
6072 },
6073 shouldFail: true,
6074 expectedError: ":WRONG_SSL_VERSION:",
6075 })
6076
David Benjaminb16346b2015-04-08 19:16:58 -04006077 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006078 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006079 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006080 config: Config{
6081 MaxVersion: VersionTLS10,
6082 Bugs: ProtocolBugs{
6083 RequireSameRenegoClientVersion: true,
6084 },
6085 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006086 flags: []string{
6087 "-renegotiate-freely",
6088 "-expect-total-renegotiations", "1",
6089 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006090 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006091 testCases = append(testCases, testCase{
6092 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006093 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006094 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006095 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006096 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6097 NextProtos: []string{"foo"},
6098 },
6099 flags: []string{
6100 "-false-start",
6101 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006102 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006103 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006104 },
6105 shimWritesFirst: true,
6106 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006107
6108 // Client-side renegotiation controls.
6109 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006110 name: "Renegotiate-Client-Forbidden-1",
6111 config: Config{
6112 MaxVersion: VersionTLS12,
6113 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006114 renegotiate: 1,
6115 shouldFail: true,
6116 expectedError: ":NO_RENEGOTIATION:",
6117 expectedLocalError: "remote error: no renegotiation",
6118 })
6119 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006120 name: "Renegotiate-Client-Once-1",
6121 config: Config{
6122 MaxVersion: VersionTLS12,
6123 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006124 renegotiate: 1,
6125 flags: []string{
6126 "-renegotiate-once",
6127 "-expect-total-renegotiations", "1",
6128 },
6129 })
6130 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006131 name: "Renegotiate-Client-Freely-1",
6132 config: Config{
6133 MaxVersion: VersionTLS12,
6134 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006135 renegotiate: 1,
6136 flags: []string{
6137 "-renegotiate-freely",
6138 "-expect-total-renegotiations", "1",
6139 },
6140 })
6141 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006142 name: "Renegotiate-Client-Once-2",
6143 config: Config{
6144 MaxVersion: VersionTLS12,
6145 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006146 renegotiate: 2,
6147 flags: []string{"-renegotiate-once"},
6148 shouldFail: true,
6149 expectedError: ":NO_RENEGOTIATION:",
6150 expectedLocalError: "remote error: no renegotiation",
6151 })
6152 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006153 name: "Renegotiate-Client-Freely-2",
6154 config: Config{
6155 MaxVersion: VersionTLS12,
6156 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006157 renegotiate: 2,
6158 flags: []string{
6159 "-renegotiate-freely",
6160 "-expect-total-renegotiations", "2",
6161 },
6162 })
Adam Langley27a0d082015-11-03 13:34:10 -08006163 testCases = append(testCases, testCase{
6164 name: "Renegotiate-Client-NoIgnore",
6165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006166 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006167 Bugs: ProtocolBugs{
6168 SendHelloRequestBeforeEveryAppDataRecord: true,
6169 },
6170 },
6171 shouldFail: true,
6172 expectedError: ":NO_RENEGOTIATION:",
6173 })
6174 testCases = append(testCases, testCase{
6175 name: "Renegotiate-Client-Ignore",
6176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006177 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006178 Bugs: ProtocolBugs{
6179 SendHelloRequestBeforeEveryAppDataRecord: true,
6180 },
6181 },
6182 flags: []string{
6183 "-renegotiate-ignore",
6184 "-expect-total-renegotiations", "0",
6185 },
6186 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006187
David Benjamin34941c02016-10-08 11:45:31 -04006188 // Renegotiation is not allowed at SSL 3.0.
6189 testCases = append(testCases, testCase{
6190 name: "Renegotiate-Client-SSL3",
6191 config: Config{
6192 MaxVersion: VersionSSL30,
6193 },
6194 renegotiate: 1,
6195 flags: []string{
6196 "-renegotiate-freely",
6197 "-expect-total-renegotiations", "1",
6198 },
6199 shouldFail: true,
6200 expectedError: ":NO_RENEGOTIATION:",
6201 expectedLocalError: "remote error: no renegotiation",
6202 })
6203
David Benjamin397c8e62016-07-08 14:14:36 -07006204 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006205 testCases = append(testCases, testCase{
6206 name: "StrayHelloRequest",
6207 config: Config{
6208 MaxVersion: VersionTLS12,
6209 Bugs: ProtocolBugs{
6210 SendHelloRequestBeforeEveryHandshakeMessage: true,
6211 },
6212 },
6213 })
6214 testCases = append(testCases, testCase{
6215 name: "StrayHelloRequest-Packed",
6216 config: Config{
6217 MaxVersion: VersionTLS12,
6218 Bugs: ProtocolBugs{
6219 PackHandshakeFlight: true,
6220 SendHelloRequestBeforeEveryHandshakeMessage: true,
6221 },
6222 },
6223 })
6224
David Benjamin12d2c482016-07-24 10:56:51 -04006225 // Test renegotiation works if HelloRequest and server Finished come in
6226 // the same record.
6227 testCases = append(testCases, testCase{
6228 name: "Renegotiate-Client-Packed",
6229 config: Config{
6230 MaxVersion: VersionTLS12,
6231 Bugs: ProtocolBugs{
6232 PackHandshakeFlight: true,
6233 PackHelloRequestWithFinished: true,
6234 },
6235 },
6236 renegotiate: 1,
6237 flags: []string{
6238 "-renegotiate-freely",
6239 "-expect-total-renegotiations", "1",
6240 },
6241 })
6242
David Benjamin397c8e62016-07-08 14:14:36 -07006243 // Renegotiation is forbidden in TLS 1.3.
6244 testCases = append(testCases, testCase{
6245 name: "Renegotiate-Client-TLS13",
6246 config: Config{
6247 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006248 Bugs: ProtocolBugs{
6249 SendHelloRequestBeforeEveryAppDataRecord: true,
6250 },
David Benjamin397c8e62016-07-08 14:14:36 -07006251 },
David Benjamin397c8e62016-07-08 14:14:36 -07006252 flags: []string{
6253 "-renegotiate-freely",
6254 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006255 shouldFail: true,
6256 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006257 })
6258
6259 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6260 testCases = append(testCases, testCase{
6261 name: "StrayHelloRequest-TLS13",
6262 config: Config{
6263 MaxVersion: VersionTLS13,
6264 Bugs: ProtocolBugs{
6265 SendHelloRequestBeforeEveryHandshakeMessage: true,
6266 },
6267 },
6268 shouldFail: true,
6269 expectedError: ":UNEXPECTED_MESSAGE:",
6270 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006271}
6272
David Benjamin5e961c12014-11-07 01:48:35 -05006273func addDTLSReplayTests() {
6274 // Test that sequence number replays are detected.
6275 testCases = append(testCases, testCase{
6276 protocol: dtls,
6277 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006278 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006279 replayWrites: true,
6280 })
6281
David Benjamin8e6db492015-07-25 18:29:23 -04006282 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006283 // than the retransmit window.
6284 testCases = append(testCases, testCase{
6285 protocol: dtls,
6286 name: "DTLS-Replay-LargeGaps",
6287 config: Config{
6288 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006289 SequenceNumberMapping: func(in uint64) uint64 {
6290 return in * 127
6291 },
David Benjamin5e961c12014-11-07 01:48:35 -05006292 },
6293 },
David Benjamin8e6db492015-07-25 18:29:23 -04006294 messageCount: 200,
6295 replayWrites: true,
6296 })
6297
6298 // Test the incoming sequence number changing non-monotonically.
6299 testCases = append(testCases, testCase{
6300 protocol: dtls,
6301 name: "DTLS-Replay-NonMonotonic",
6302 config: Config{
6303 Bugs: ProtocolBugs{
6304 SequenceNumberMapping: func(in uint64) uint64 {
6305 return in ^ 31
6306 },
6307 },
6308 },
6309 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006310 replayWrites: true,
6311 })
6312}
6313
Nick Harper60edffd2016-06-21 15:19:24 -07006314var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006315 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006316 id signatureAlgorithm
6317 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006318}{
Nick Harper60edffd2016-06-21 15:19:24 -07006319 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6320 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6321 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6322 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006323 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006324 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6325 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6326 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006327 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6328 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6329 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006330 // Tests for key types prior to TLS 1.2.
6331 {"RSA", 0, testCertRSA},
6332 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006333}
6334
Nick Harper60edffd2016-06-21 15:19:24 -07006335const fakeSigAlg1 signatureAlgorithm = 0x2a01
6336const fakeSigAlg2 signatureAlgorithm = 0xff01
6337
6338func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006339 // Not all ciphers involve a signature. Advertise a list which gives all
6340 // versions a signing cipher.
6341 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006342 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006343 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6344 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6345 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6346 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6347 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6348 }
6349
David Benjaminca3d5452016-07-14 12:51:01 -04006350 var allAlgorithms []signatureAlgorithm
6351 for _, alg := range testSignatureAlgorithms {
6352 if alg.id != 0 {
6353 allAlgorithms = append(allAlgorithms, alg.id)
6354 }
6355 }
6356
Nick Harper60edffd2016-06-21 15:19:24 -07006357 // Make sure each signature algorithm works. Include some fake values in
6358 // the list and ensure they're ignored.
6359 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006360 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006361 if (ver.version < VersionTLS12) != (alg.id == 0) {
6362 continue
6363 }
6364
6365 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6366 // or remove it in C.
6367 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006368 continue
6369 }
Nick Harper60edffd2016-06-21 15:19:24 -07006370
David Benjamin3ef76972016-10-17 17:59:54 -04006371 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006372 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006373 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006374 shouldSignFail = true
6375 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006376 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006377 // RSA-PKCS1 does not exist in TLS 1.3.
6378 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006379 shouldSignFail = true
6380 shouldVerifyFail = true
6381 }
6382
6383 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6384 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6385 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006386 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006387
6388 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006389 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006390 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006391 }
6392 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006393 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006394 }
David Benjamin000800a2014-11-14 01:43:59 -05006395
David Benjamin1fb125c2016-07-08 18:52:12 -07006396 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006397
David Benjamin7a41d372016-07-09 11:21:54 -07006398 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006399 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006400 config: Config{
6401 MaxVersion: ver.version,
6402 ClientAuth: RequireAnyClientCert,
6403 VerifySignatureAlgorithms: []signatureAlgorithm{
6404 fakeSigAlg1,
6405 alg.id,
6406 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006407 },
David Benjamin7a41d372016-07-09 11:21:54 -07006408 },
6409 flags: []string{
6410 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6411 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6412 "-enable-all-curves",
6413 },
David Benjamin3ef76972016-10-17 17:59:54 -04006414 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006415 expectedError: signError,
6416 expectedPeerSignatureAlgorithm: alg.id,
6417 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006418
David Benjamin7a41d372016-07-09 11:21:54 -07006419 testCases = append(testCases, testCase{
6420 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006421 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006422 config: Config{
6423 MaxVersion: ver.version,
6424 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6425 SignSignatureAlgorithms: []signatureAlgorithm{
6426 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006427 },
David Benjamin7a41d372016-07-09 11:21:54 -07006428 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006429 SkipECDSACurveCheck: shouldVerifyFail,
6430 IgnoreSignatureVersionChecks: shouldVerifyFail,
6431 // Some signature algorithms may not be advertised.
6432 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006433 },
David Benjamin7a41d372016-07-09 11:21:54 -07006434 },
6435 flags: []string{
6436 "-require-any-client-certificate",
6437 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6438 "-enable-all-curves",
6439 },
David Benjamin3ef76972016-10-17 17:59:54 -04006440 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006441 expectedError: verifyError,
6442 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006443
6444 testCases = append(testCases, testCase{
6445 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006446 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006447 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006448 MaxVersion: ver.version,
6449 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006450 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006451 fakeSigAlg1,
6452 alg.id,
6453 fakeSigAlg2,
6454 },
6455 },
6456 flags: []string{
6457 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6458 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6459 "-enable-all-curves",
6460 },
David Benjamin3ef76972016-10-17 17:59:54 -04006461 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006462 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006463 expectedPeerSignatureAlgorithm: alg.id,
6464 })
6465
6466 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006467 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006468 config: Config{
6469 MaxVersion: ver.version,
6470 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006471 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006472 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006473 alg.id,
6474 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006475 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006476 SkipECDSACurveCheck: shouldVerifyFail,
6477 IgnoreSignatureVersionChecks: shouldVerifyFail,
6478 // Some signature algorithms may not be advertised.
6479 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006480 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006481 },
6482 flags: []string{
6483 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6484 "-enable-all-curves",
6485 },
David Benjamin3ef76972016-10-17 17:59:54 -04006486 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006487 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006488 })
David Benjamin5208fd42016-07-13 21:43:25 -04006489
David Benjamin3ef76972016-10-17 17:59:54 -04006490 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006491 testCases = append(testCases, testCase{
6492 testType: serverTest,
6493 name: "ClientAuth-InvalidSignature" + suffix,
6494 config: Config{
6495 MaxVersion: ver.version,
6496 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6497 SignSignatureAlgorithms: []signatureAlgorithm{
6498 alg.id,
6499 },
6500 Bugs: ProtocolBugs{
6501 InvalidSignature: true,
6502 },
6503 },
6504 flags: []string{
6505 "-require-any-client-certificate",
6506 "-enable-all-curves",
6507 },
6508 shouldFail: true,
6509 expectedError: ":BAD_SIGNATURE:",
6510 })
6511
6512 testCases = append(testCases, testCase{
6513 name: "ServerAuth-InvalidSignature" + suffix,
6514 config: Config{
6515 MaxVersion: ver.version,
6516 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6517 CipherSuites: signingCiphers,
6518 SignSignatureAlgorithms: []signatureAlgorithm{
6519 alg.id,
6520 },
6521 Bugs: ProtocolBugs{
6522 InvalidSignature: true,
6523 },
6524 },
6525 flags: []string{"-enable-all-curves"},
6526 shouldFail: true,
6527 expectedError: ":BAD_SIGNATURE:",
6528 })
6529 }
David Benjaminca3d5452016-07-14 12:51:01 -04006530
David Benjamin3ef76972016-10-17 17:59:54 -04006531 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006532 testCases = append(testCases, testCase{
6533 name: "ClientAuth-Sign-Negotiate" + suffix,
6534 config: Config{
6535 MaxVersion: ver.version,
6536 ClientAuth: RequireAnyClientCert,
6537 VerifySignatureAlgorithms: allAlgorithms,
6538 },
6539 flags: []string{
6540 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6541 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6542 "-enable-all-curves",
6543 "-signing-prefs", strconv.Itoa(int(alg.id)),
6544 },
6545 expectedPeerSignatureAlgorithm: alg.id,
6546 })
6547
6548 testCases = append(testCases, testCase{
6549 testType: serverTest,
6550 name: "ServerAuth-Sign-Negotiate" + suffix,
6551 config: Config{
6552 MaxVersion: ver.version,
6553 CipherSuites: signingCiphers,
6554 VerifySignatureAlgorithms: allAlgorithms,
6555 },
6556 flags: []string{
6557 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6558 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6559 "-enable-all-curves",
6560 "-signing-prefs", strconv.Itoa(int(alg.id)),
6561 },
6562 expectedPeerSignatureAlgorithm: alg.id,
6563 })
6564 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006565 }
David Benjamin000800a2014-11-14 01:43:59 -05006566 }
6567
Nick Harper60edffd2016-06-21 15:19:24 -07006568 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006569 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006570 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006571 config: Config{
6572 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006573 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006574 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006575 signatureECDSAWithP521AndSHA512,
6576 signatureRSAPKCS1WithSHA384,
6577 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006578 },
6579 },
6580 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006583 },
Nick Harper60edffd2016-06-21 15:19:24 -07006584 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006585 })
6586
6587 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006588 name: "ClientAuth-SignatureType-TLS13",
6589 config: Config{
6590 ClientAuth: RequireAnyClientCert,
6591 MaxVersion: VersionTLS13,
6592 VerifySignatureAlgorithms: []signatureAlgorithm{
6593 signatureECDSAWithP521AndSHA512,
6594 signatureRSAPKCS1WithSHA384,
6595 signatureRSAPSSWithSHA384,
6596 signatureECDSAWithSHA1,
6597 },
6598 },
6599 flags: []string{
6600 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6601 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6602 },
6603 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6604 })
6605
6606 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006607 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006608 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006610 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006611 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006612 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006613 signatureECDSAWithP521AndSHA512,
6614 signatureRSAPKCS1WithSHA384,
6615 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006616 },
6617 },
Nick Harper60edffd2016-06-21 15:19:24 -07006618 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006619 })
6620
Steven Valdez143e8b32016-07-11 13:19:03 -04006621 testCases = append(testCases, testCase{
6622 testType: serverTest,
6623 name: "ServerAuth-SignatureType-TLS13",
6624 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006625 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006626 VerifySignatureAlgorithms: []signatureAlgorithm{
6627 signatureECDSAWithP521AndSHA512,
6628 signatureRSAPKCS1WithSHA384,
6629 signatureRSAPSSWithSHA384,
6630 signatureECDSAWithSHA1,
6631 },
6632 },
6633 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6634 })
6635
David Benjamina95e9f32016-07-08 16:28:04 -07006636 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006637 testCases = append(testCases, testCase{
6638 testType: serverTest,
6639 name: "Verify-ClientAuth-SignatureType",
6640 config: Config{
6641 MaxVersion: VersionTLS12,
6642 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006643 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006644 signatureRSAPKCS1WithSHA256,
6645 },
6646 Bugs: ProtocolBugs{
6647 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6648 },
6649 },
6650 flags: []string{
6651 "-require-any-client-certificate",
6652 },
6653 shouldFail: true,
6654 expectedError: ":WRONG_SIGNATURE_TYPE:",
6655 })
6656
6657 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006658 testType: serverTest,
6659 name: "Verify-ClientAuth-SignatureType-TLS13",
6660 config: Config{
6661 MaxVersion: VersionTLS13,
6662 Certificates: []Certificate{rsaCertificate},
6663 SignSignatureAlgorithms: []signatureAlgorithm{
6664 signatureRSAPSSWithSHA256,
6665 },
6666 Bugs: ProtocolBugs{
6667 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6668 },
6669 },
6670 flags: []string{
6671 "-require-any-client-certificate",
6672 },
6673 shouldFail: true,
6674 expectedError: ":WRONG_SIGNATURE_TYPE:",
6675 })
6676
6677 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006678 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006679 config: Config{
6680 MaxVersion: VersionTLS12,
6681 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006682 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006683 signatureRSAPKCS1WithSHA256,
6684 },
6685 Bugs: ProtocolBugs{
6686 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6687 },
6688 },
6689 shouldFail: true,
6690 expectedError: ":WRONG_SIGNATURE_TYPE:",
6691 })
6692
Steven Valdez143e8b32016-07-11 13:19:03 -04006693 testCases = append(testCases, testCase{
6694 name: "Verify-ServerAuth-SignatureType-TLS13",
6695 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006696 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006697 SignSignatureAlgorithms: []signatureAlgorithm{
6698 signatureRSAPSSWithSHA256,
6699 },
6700 Bugs: ProtocolBugs{
6701 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6702 },
6703 },
6704 shouldFail: true,
6705 expectedError: ":WRONG_SIGNATURE_TYPE:",
6706 })
6707
David Benjamin51dd7d62016-07-08 16:07:01 -07006708 // Test that, if the list is missing, the peer falls back to SHA-1 in
6709 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006710 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006711 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006712 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006713 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006714 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006715 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006716 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006717 },
6718 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006719 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006720 },
6721 },
6722 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006723 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6724 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006725 },
6726 })
6727
6728 testCases = append(testCases, testCase{
6729 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006730 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006731 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006732 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006733 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006734 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006735 },
6736 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006737 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006738 },
6739 },
David Benjaminee32bea2016-08-17 13:36:44 -04006740 flags: []string{
6741 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6742 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6743 },
6744 })
6745
6746 testCases = append(testCases, testCase{
6747 name: "ClientAuth-SHA1-Fallback-ECDSA",
6748 config: Config{
6749 MaxVersion: VersionTLS12,
6750 ClientAuth: RequireAnyClientCert,
6751 VerifySignatureAlgorithms: []signatureAlgorithm{
6752 signatureECDSAWithSHA1,
6753 },
6754 Bugs: ProtocolBugs{
6755 NoSignatureAlgorithms: true,
6756 },
6757 },
6758 flags: []string{
6759 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6760 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6761 },
6762 })
6763
6764 testCases = append(testCases, testCase{
6765 testType: serverTest,
6766 name: "ServerAuth-SHA1-Fallback-ECDSA",
6767 config: Config{
6768 MaxVersion: VersionTLS12,
6769 VerifySignatureAlgorithms: []signatureAlgorithm{
6770 signatureECDSAWithSHA1,
6771 },
6772 Bugs: ProtocolBugs{
6773 NoSignatureAlgorithms: true,
6774 },
6775 },
6776 flags: []string{
6777 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6778 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6779 },
David Benjamin000800a2014-11-14 01:43:59 -05006780 })
David Benjamin72dc7832015-03-16 17:49:43 -04006781
David Benjamin51dd7d62016-07-08 16:07:01 -07006782 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006783 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006784 config: Config{
6785 MaxVersion: VersionTLS13,
6786 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006787 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006788 signatureRSAPKCS1WithSHA1,
6789 },
6790 Bugs: ProtocolBugs{
6791 NoSignatureAlgorithms: true,
6792 },
6793 },
6794 flags: []string{
6795 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6796 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6797 },
David Benjamin48901652016-08-01 12:12:47 -04006798 shouldFail: true,
6799 // An empty CertificateRequest signature algorithm list is a
6800 // syntax error in TLS 1.3.
6801 expectedError: ":DECODE_ERROR:",
6802 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006803 })
6804
6805 testCases = append(testCases, testCase{
6806 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006807 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006808 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006809 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006810 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006811 signatureRSAPKCS1WithSHA1,
6812 },
6813 Bugs: ProtocolBugs{
6814 NoSignatureAlgorithms: true,
6815 },
6816 },
6817 shouldFail: true,
6818 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6819 })
6820
David Benjaminb62d2872016-07-18 14:55:02 +02006821 // Test that hash preferences are enforced. BoringSSL does not implement
6822 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006823 testCases = append(testCases, testCase{
6824 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006825 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006827 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006828 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006829 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006830 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006831 },
6832 Bugs: ProtocolBugs{
6833 IgnorePeerSignatureAlgorithmPreferences: true,
6834 },
6835 },
6836 flags: []string{"-require-any-client-certificate"},
6837 shouldFail: true,
6838 expectedError: ":WRONG_SIGNATURE_TYPE:",
6839 })
6840
6841 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006842 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006844 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006846 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006847 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006848 },
6849 Bugs: ProtocolBugs{
6850 IgnorePeerSignatureAlgorithmPreferences: true,
6851 },
6852 },
6853 shouldFail: true,
6854 expectedError: ":WRONG_SIGNATURE_TYPE:",
6855 })
David Benjaminb62d2872016-07-18 14:55:02 +02006856 testCases = append(testCases, testCase{
6857 testType: serverTest,
6858 name: "ClientAuth-Enforced-TLS13",
6859 config: Config{
6860 MaxVersion: VersionTLS13,
6861 Certificates: []Certificate{rsaCertificate},
6862 SignSignatureAlgorithms: []signatureAlgorithm{
6863 signatureRSAPKCS1WithMD5,
6864 },
6865 Bugs: ProtocolBugs{
6866 IgnorePeerSignatureAlgorithmPreferences: true,
6867 IgnoreSignatureVersionChecks: true,
6868 },
6869 },
6870 flags: []string{"-require-any-client-certificate"},
6871 shouldFail: true,
6872 expectedError: ":WRONG_SIGNATURE_TYPE:",
6873 })
6874
6875 testCases = append(testCases, testCase{
6876 name: "ServerAuth-Enforced-TLS13",
6877 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006878 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006879 SignSignatureAlgorithms: []signatureAlgorithm{
6880 signatureRSAPKCS1WithMD5,
6881 },
6882 Bugs: ProtocolBugs{
6883 IgnorePeerSignatureAlgorithmPreferences: true,
6884 IgnoreSignatureVersionChecks: true,
6885 },
6886 },
6887 shouldFail: true,
6888 expectedError: ":WRONG_SIGNATURE_TYPE:",
6889 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006890
6891 // Test that the agreed upon digest respects the client preferences and
6892 // the server digests.
6893 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006894 name: "NoCommonAlgorithms-Digests",
6895 config: Config{
6896 MaxVersion: VersionTLS12,
6897 ClientAuth: RequireAnyClientCert,
6898 VerifySignatureAlgorithms: []signatureAlgorithm{
6899 signatureRSAPKCS1WithSHA512,
6900 signatureRSAPKCS1WithSHA1,
6901 },
6902 },
6903 flags: []string{
6904 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6905 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6906 "-digest-prefs", "SHA256",
6907 },
6908 shouldFail: true,
6909 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6910 })
6911 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006912 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006914 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006915 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006916 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006917 signatureRSAPKCS1WithSHA512,
6918 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006919 },
6920 },
6921 flags: []string{
6922 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6923 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006924 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006925 },
David Benjaminca3d5452016-07-14 12:51:01 -04006926 shouldFail: true,
6927 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6928 })
6929 testCases = append(testCases, testCase{
6930 name: "NoCommonAlgorithms-TLS13",
6931 config: Config{
6932 MaxVersion: VersionTLS13,
6933 ClientAuth: RequireAnyClientCert,
6934 VerifySignatureAlgorithms: []signatureAlgorithm{
6935 signatureRSAPSSWithSHA512,
6936 signatureRSAPSSWithSHA384,
6937 },
6938 },
6939 flags: []string{
6940 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6941 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6942 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6943 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006944 shouldFail: true,
6945 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006946 })
6947 testCases = append(testCases, testCase{
6948 name: "Agree-Digest-SHA256",
6949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006950 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006951 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006952 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006953 signatureRSAPKCS1WithSHA1,
6954 signatureRSAPKCS1WithSHA256,
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", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006961 },
Nick Harper60edffd2016-06-21 15:19:24 -07006962 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006963 })
6964 testCases = append(testCases, testCase{
6965 name: "Agree-Digest-SHA1",
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 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006971 },
6972 },
6973 flags: []string{
6974 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6975 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006976 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006977 },
Nick Harper60edffd2016-06-21 15:19:24 -07006978 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006979 })
6980 testCases = append(testCases, testCase{
6981 name: "Agree-Digest-Default",
6982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006983 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006984 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006985 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006986 signatureRSAPKCS1WithSHA256,
6987 signatureECDSAWithP256AndSHA256,
6988 signatureRSAPKCS1WithSHA1,
6989 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006990 },
6991 },
6992 flags: []string{
6993 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6994 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6995 },
Nick Harper60edffd2016-06-21 15:19:24 -07006996 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006997 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998
David Benjaminca3d5452016-07-14 12:51:01 -04006999 // Test that the signing preference list may include extra algorithms
7000 // without negotiation problems.
7001 testCases = append(testCases, testCase{
7002 testType: serverTest,
7003 name: "FilterExtraAlgorithms",
7004 config: Config{
7005 MaxVersion: VersionTLS12,
7006 VerifySignatureAlgorithms: []signatureAlgorithm{
7007 signatureRSAPKCS1WithSHA256,
7008 },
7009 },
7010 flags: []string{
7011 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7012 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7013 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7014 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7015 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7016 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7017 },
7018 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7019 })
7020
David Benjamin4c3ddf72016-06-29 18:13:53 -04007021 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7022 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007023 testCases = append(testCases, testCase{
7024 name: "CheckLeafCurve",
7025 config: Config{
7026 MaxVersion: VersionTLS12,
7027 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007028 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007029 },
7030 flags: []string{"-p384-only"},
7031 shouldFail: true,
7032 expectedError: ":BAD_ECC_CERT:",
7033 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007034
7035 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7036 testCases = append(testCases, testCase{
7037 name: "CheckLeafCurve-TLS13",
7038 config: Config{
7039 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007040 Certificates: []Certificate{ecdsaP256Certificate},
7041 },
7042 flags: []string{"-p384-only"},
7043 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007044
7045 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7046 testCases = append(testCases, testCase{
7047 name: "ECDSACurveMismatch-Verify-TLS12",
7048 config: Config{
7049 MaxVersion: VersionTLS12,
7050 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7051 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007052 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007053 signatureECDSAWithP384AndSHA384,
7054 },
7055 },
7056 })
7057
7058 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7059 testCases = append(testCases, testCase{
7060 name: "ECDSACurveMismatch-Verify-TLS13",
7061 config: Config{
7062 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007063 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007064 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007065 signatureECDSAWithP384AndSHA384,
7066 },
7067 Bugs: ProtocolBugs{
7068 SkipECDSACurveCheck: true,
7069 },
7070 },
7071 shouldFail: true,
7072 expectedError: ":WRONG_SIGNATURE_TYPE:",
7073 })
7074
7075 // Signature algorithm selection in TLS 1.3 should take the curve into
7076 // account.
7077 testCases = append(testCases, testCase{
7078 testType: serverTest,
7079 name: "ECDSACurveMismatch-Sign-TLS13",
7080 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007081 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007082 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007083 signatureECDSAWithP384AndSHA384,
7084 signatureECDSAWithP256AndSHA256,
7085 },
7086 },
7087 flags: []string{
7088 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7089 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7090 },
7091 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7092 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007093
7094 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7095 // server does not attempt to sign in that case.
7096 testCases = append(testCases, testCase{
7097 testType: serverTest,
7098 name: "RSA-PSS-Large",
7099 config: Config{
7100 MaxVersion: VersionTLS13,
7101 VerifySignatureAlgorithms: []signatureAlgorithm{
7102 signatureRSAPSSWithSHA512,
7103 },
7104 },
7105 flags: []string{
7106 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7107 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7108 },
7109 shouldFail: true,
7110 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7111 })
David Benjamin57e929f2016-08-30 00:30:38 -04007112
7113 // Test that RSA-PSS is enabled by default for TLS 1.2.
7114 testCases = append(testCases, testCase{
7115 testType: clientTest,
7116 name: "RSA-PSS-Default-Verify",
7117 config: Config{
7118 MaxVersion: VersionTLS12,
7119 SignSignatureAlgorithms: []signatureAlgorithm{
7120 signatureRSAPSSWithSHA256,
7121 },
7122 },
7123 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7124 })
7125
7126 testCases = append(testCases, testCase{
7127 testType: serverTest,
7128 name: "RSA-PSS-Default-Sign",
7129 config: Config{
7130 MaxVersion: VersionTLS12,
7131 VerifySignatureAlgorithms: []signatureAlgorithm{
7132 signatureRSAPSSWithSHA256,
7133 },
7134 },
7135 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7136 })
David Benjamin000800a2014-11-14 01:43:59 -05007137}
7138
David Benjamin83f90402015-01-27 01:09:43 -05007139// timeouts is the retransmit schedule for BoringSSL. It doubles and
7140// caps at 60 seconds. On the 13th timeout, it gives up.
7141var timeouts = []time.Duration{
7142 1 * time.Second,
7143 2 * time.Second,
7144 4 * time.Second,
7145 8 * time.Second,
7146 16 * time.Second,
7147 32 * time.Second,
7148 60 * time.Second,
7149 60 * time.Second,
7150 60 * time.Second,
7151 60 * time.Second,
7152 60 * time.Second,
7153 60 * time.Second,
7154 60 * time.Second,
7155}
7156
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007157// shortTimeouts is an alternate set of timeouts which would occur if the
7158// initial timeout duration was set to 250ms.
7159var shortTimeouts = []time.Duration{
7160 250 * time.Millisecond,
7161 500 * time.Millisecond,
7162 1 * time.Second,
7163 2 * time.Second,
7164 4 * time.Second,
7165 8 * time.Second,
7166 16 * time.Second,
7167 32 * time.Second,
7168 60 * time.Second,
7169 60 * time.Second,
7170 60 * time.Second,
7171 60 * time.Second,
7172 60 * time.Second,
7173}
7174
David Benjamin83f90402015-01-27 01:09:43 -05007175func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007176 // These tests work by coordinating some behavior on both the shim and
7177 // the runner.
7178 //
7179 // TimeoutSchedule configures the runner to send a series of timeout
7180 // opcodes to the shim (see packetAdaptor) immediately before reading
7181 // each peer handshake flight N. The timeout opcode both simulates a
7182 // timeout in the shim and acts as a synchronization point to help the
7183 // runner bracket each handshake flight.
7184 //
7185 // We assume the shim does not read from the channel eagerly. It must
7186 // first wait until it has sent flight N and is ready to receive
7187 // handshake flight N+1. At this point, it will process the timeout
7188 // opcode. It must then immediately respond with a timeout ACK and act
7189 // as if the shim was idle for the specified amount of time.
7190 //
7191 // The runner then drops all packets received before the ACK and
7192 // continues waiting for flight N. This ordering results in one attempt
7193 // at sending flight N to be dropped. For the test to complete, the
7194 // shim must send flight N again, testing that the shim implements DTLS
7195 // retransmit on a timeout.
7196
Steven Valdez143e8b32016-07-11 13:19:03 -04007197 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007198 // likely be more epochs to cross and the final message's retransmit may
7199 // be more complex.
7200
David Benjamin585d7a42016-06-02 14:58:00 -04007201 for _, async := range []bool{true, false} {
7202 var tests []testCase
7203
7204 // Test that this is indeed the timeout schedule. Stress all
7205 // four patterns of handshake.
7206 for i := 1; i < len(timeouts); i++ {
7207 number := strconv.Itoa(i)
7208 tests = append(tests, testCase{
7209 protocol: dtls,
7210 name: "DTLS-Retransmit-Client-" + number,
7211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007212 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007213 Bugs: ProtocolBugs{
7214 TimeoutSchedule: timeouts[:i],
7215 },
7216 },
7217 resumeSession: true,
7218 })
7219 tests = append(tests, testCase{
7220 protocol: dtls,
7221 testType: serverTest,
7222 name: "DTLS-Retransmit-Server-" + number,
7223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007224 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007225 Bugs: ProtocolBugs{
7226 TimeoutSchedule: timeouts[:i],
7227 },
7228 },
7229 resumeSession: true,
7230 })
7231 }
7232
7233 // Test that exceeding the timeout schedule hits a read
7234 // timeout.
7235 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007236 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007237 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007239 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007240 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007241 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007242 },
7243 },
7244 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007245 shouldFail: true,
7246 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007247 })
David Benjamin585d7a42016-06-02 14:58:00 -04007248
7249 if async {
7250 // Test that timeout handling has a fudge factor, due to API
7251 // problems.
7252 tests = append(tests, testCase{
7253 protocol: dtls,
7254 name: "DTLS-Retransmit-Fudge",
7255 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007256 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007257 Bugs: ProtocolBugs{
7258 TimeoutSchedule: []time.Duration{
7259 timeouts[0] - 10*time.Millisecond,
7260 },
7261 },
7262 },
7263 resumeSession: true,
7264 })
7265 }
7266
7267 // Test that the final Finished retransmitting isn't
7268 // duplicated if the peer badly fragments everything.
7269 tests = append(tests, testCase{
7270 testType: serverTest,
7271 protocol: dtls,
7272 name: "DTLS-Retransmit-Fragmented",
7273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007274 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007275 Bugs: ProtocolBugs{
7276 TimeoutSchedule: []time.Duration{timeouts[0]},
7277 MaxHandshakeRecordLength: 2,
7278 },
7279 },
7280 })
7281
7282 // Test the timeout schedule when a shorter initial timeout duration is set.
7283 tests = append(tests, testCase{
7284 protocol: dtls,
7285 name: "DTLS-Retransmit-Short-Client",
7286 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007287 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007288 Bugs: ProtocolBugs{
7289 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7290 },
7291 },
7292 resumeSession: true,
7293 flags: []string{"-initial-timeout-duration-ms", "250"},
7294 })
7295 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007296 protocol: dtls,
7297 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007298 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007299 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007300 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007301 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007302 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007303 },
7304 },
7305 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007306 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007307 })
David Benjamin585d7a42016-06-02 14:58:00 -04007308
7309 for _, test := range tests {
7310 if async {
7311 test.name += "-Async"
7312 test.flags = append(test.flags, "-async")
7313 }
7314
7315 testCases = append(testCases, test)
7316 }
David Benjamin83f90402015-01-27 01:09:43 -05007317 }
David Benjamin83f90402015-01-27 01:09:43 -05007318}
7319
David Benjaminc565ebb2015-04-03 04:06:36 -04007320func addExportKeyingMaterialTests() {
7321 for _, vers := range tlsVersions {
7322 if vers.version == VersionSSL30 {
7323 continue
7324 }
7325 testCases = append(testCases, testCase{
7326 name: "ExportKeyingMaterial-" + vers.name,
7327 config: Config{
7328 MaxVersion: vers.version,
7329 },
7330 exportKeyingMaterial: 1024,
7331 exportLabel: "label",
7332 exportContext: "context",
7333 useExportContext: true,
7334 })
7335 testCases = append(testCases, testCase{
7336 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7337 config: Config{
7338 MaxVersion: vers.version,
7339 },
7340 exportKeyingMaterial: 1024,
7341 })
7342 testCases = append(testCases, testCase{
7343 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7344 config: Config{
7345 MaxVersion: vers.version,
7346 },
7347 exportKeyingMaterial: 1024,
7348 useExportContext: true,
7349 })
7350 testCases = append(testCases, testCase{
7351 name: "ExportKeyingMaterial-Small-" + vers.name,
7352 config: Config{
7353 MaxVersion: vers.version,
7354 },
7355 exportKeyingMaterial: 1,
7356 exportLabel: "label",
7357 exportContext: "context",
7358 useExportContext: true,
7359 })
7360 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007361
David Benjaminc565ebb2015-04-03 04:06:36 -04007362 testCases = append(testCases, testCase{
7363 name: "ExportKeyingMaterial-SSL3",
7364 config: Config{
7365 MaxVersion: VersionSSL30,
7366 },
7367 exportKeyingMaterial: 1024,
7368 exportLabel: "label",
7369 exportContext: "context",
7370 useExportContext: true,
7371 shouldFail: true,
7372 expectedError: "failed to export keying material",
7373 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007374
7375 // Exporters work during a False Start.
7376 testCases = append(testCases, testCase{
7377 name: "ExportKeyingMaterial-FalseStart",
7378 config: Config{
7379 MaxVersion: VersionTLS12,
7380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7381 NextProtos: []string{"foo"},
7382 Bugs: ProtocolBugs{
7383 ExpectFalseStart: true,
7384 },
7385 },
7386 flags: []string{
7387 "-false-start",
7388 "-advertise-alpn", "\x03foo",
7389 },
7390 shimWritesFirst: true,
7391 exportKeyingMaterial: 1024,
7392 exportLabel: "label",
7393 exportContext: "context",
7394 useExportContext: true,
7395 })
7396
7397 // Exporters do not work in the middle of a renegotiation. Test this by
7398 // triggering the exporter after every SSL_read call and configuring the
7399 // shim to run asynchronously.
7400 testCases = append(testCases, testCase{
7401 name: "ExportKeyingMaterial-Renegotiate",
7402 config: Config{
7403 MaxVersion: VersionTLS12,
7404 },
7405 renegotiate: 1,
7406 flags: []string{
7407 "-async",
7408 "-use-exporter-between-reads",
7409 "-renegotiate-freely",
7410 "-expect-total-renegotiations", "1",
7411 },
7412 shouldFail: true,
7413 expectedError: "failed to export keying material",
7414 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007415}
7416
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007417func addTLSUniqueTests() {
7418 for _, isClient := range []bool{false, true} {
7419 for _, isResumption := range []bool{false, true} {
7420 for _, hasEMS := range []bool{false, true} {
7421 var suffix string
7422 if isResumption {
7423 suffix = "Resume-"
7424 } else {
7425 suffix = "Full-"
7426 }
7427
7428 if hasEMS {
7429 suffix += "EMS-"
7430 } else {
7431 suffix += "NoEMS-"
7432 }
7433
7434 if isClient {
7435 suffix += "Client"
7436 } else {
7437 suffix += "Server"
7438 }
7439
7440 test := testCase{
7441 name: "TLSUnique-" + suffix,
7442 testTLSUnique: true,
7443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007444 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007445 Bugs: ProtocolBugs{
7446 NoExtendedMasterSecret: !hasEMS,
7447 },
7448 },
7449 }
7450
7451 if isResumption {
7452 test.resumeSession = true
7453 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007454 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007455 Bugs: ProtocolBugs{
7456 NoExtendedMasterSecret: !hasEMS,
7457 },
7458 }
7459 }
7460
7461 if isResumption && !hasEMS {
7462 test.shouldFail = true
7463 test.expectedError = "failed to get tls-unique"
7464 }
7465
7466 testCases = append(testCases, test)
7467 }
7468 }
7469 }
7470}
7471
Adam Langley09505632015-07-30 18:10:13 -07007472func addCustomExtensionTests() {
7473 expectedContents := "custom extension"
7474 emptyString := ""
7475
7476 for _, isClient := range []bool{false, true} {
7477 suffix := "Server"
7478 flag := "-enable-server-custom-extension"
7479 testType := serverTest
7480 if isClient {
7481 suffix = "Client"
7482 flag = "-enable-client-custom-extension"
7483 testType = clientTest
7484 }
7485
7486 testCases = append(testCases, testCase{
7487 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007488 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007490 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007491 Bugs: ProtocolBugs{
7492 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007493 ExpectedCustomExtension: &expectedContents,
7494 },
7495 },
7496 flags: []string{flag},
7497 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007498 testCases = append(testCases, testCase{
7499 testType: testType,
7500 name: "CustomExtensions-" + suffix + "-TLS13",
7501 config: Config{
7502 MaxVersion: VersionTLS13,
7503 Bugs: ProtocolBugs{
7504 CustomExtension: expectedContents,
7505 ExpectedCustomExtension: &expectedContents,
7506 },
7507 },
7508 flags: []string{flag},
7509 })
Adam Langley09505632015-07-30 18:10:13 -07007510
7511 // If the parse callback fails, the handshake should also fail.
7512 testCases = append(testCases, testCase{
7513 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007514 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007516 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007517 Bugs: ProtocolBugs{
7518 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007519 ExpectedCustomExtension: &expectedContents,
7520 },
7521 },
David Benjamin399e7c92015-07-30 23:01:27 -04007522 flags: []string{flag},
7523 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007524 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7525 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007526 testCases = append(testCases, testCase{
7527 testType: testType,
7528 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7529 config: Config{
7530 MaxVersion: VersionTLS13,
7531 Bugs: ProtocolBugs{
7532 CustomExtension: expectedContents + "foo",
7533 ExpectedCustomExtension: &expectedContents,
7534 },
7535 },
7536 flags: []string{flag},
7537 shouldFail: true,
7538 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7539 })
Adam Langley09505632015-07-30 18:10:13 -07007540
7541 // If the add callback fails, the handshake should also fail.
7542 testCases = append(testCases, testCase{
7543 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007544 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007546 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007547 Bugs: ProtocolBugs{
7548 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007549 ExpectedCustomExtension: &expectedContents,
7550 },
7551 },
David Benjamin399e7c92015-07-30 23:01:27 -04007552 flags: []string{flag, "-custom-extension-fail-add"},
7553 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007554 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7555 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007556 testCases = append(testCases, testCase{
7557 testType: testType,
7558 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7559 config: Config{
7560 MaxVersion: VersionTLS13,
7561 Bugs: ProtocolBugs{
7562 CustomExtension: expectedContents,
7563 ExpectedCustomExtension: &expectedContents,
7564 },
7565 },
7566 flags: []string{flag, "-custom-extension-fail-add"},
7567 shouldFail: true,
7568 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7569 })
Adam Langley09505632015-07-30 18:10:13 -07007570
7571 // If the add callback returns zero, no extension should be
7572 // added.
7573 skipCustomExtension := expectedContents
7574 if isClient {
7575 // For the case where the client skips sending the
7576 // custom extension, the server must not “echo” it.
7577 skipCustomExtension = ""
7578 }
7579 testCases = append(testCases, testCase{
7580 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007581 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007583 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007584 Bugs: ProtocolBugs{
7585 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007586 ExpectedCustomExtension: &emptyString,
7587 },
7588 },
7589 flags: []string{flag, "-custom-extension-skip"},
7590 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007591 testCases = append(testCases, testCase{
7592 testType: testType,
7593 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7594 config: Config{
7595 MaxVersion: VersionTLS13,
7596 Bugs: ProtocolBugs{
7597 CustomExtension: skipCustomExtension,
7598 ExpectedCustomExtension: &emptyString,
7599 },
7600 },
7601 flags: []string{flag, "-custom-extension-skip"},
7602 })
Adam Langley09505632015-07-30 18:10:13 -07007603 }
7604
7605 // The custom extension add callback should not be called if the client
7606 // doesn't send the extension.
7607 testCases = append(testCases, testCase{
7608 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007609 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007611 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007612 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007613 ExpectedCustomExtension: &emptyString,
7614 },
7615 },
7616 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7617 })
Adam Langley2deb9842015-08-07 11:15:37 -07007618
Steven Valdez143e8b32016-07-11 13:19:03 -04007619 testCases = append(testCases, testCase{
7620 testType: serverTest,
7621 name: "CustomExtensions-NotCalled-Server-TLS13",
7622 config: Config{
7623 MaxVersion: VersionTLS13,
7624 Bugs: ProtocolBugs{
7625 ExpectedCustomExtension: &emptyString,
7626 },
7627 },
7628 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7629 })
7630
Adam Langley2deb9842015-08-07 11:15:37 -07007631 // Test an unknown extension from the server.
7632 testCases = append(testCases, testCase{
7633 testType: clientTest,
7634 name: "UnknownExtension-Client",
7635 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007636 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007637 Bugs: ProtocolBugs{
7638 CustomExtension: expectedContents,
7639 },
7640 },
David Benjamin0c40a962016-08-01 12:05:50 -04007641 shouldFail: true,
7642 expectedError: ":UNEXPECTED_EXTENSION:",
7643 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007644 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007645 testCases = append(testCases, testCase{
7646 testType: clientTest,
7647 name: "UnknownExtension-Client-TLS13",
7648 config: Config{
7649 MaxVersion: VersionTLS13,
7650 Bugs: ProtocolBugs{
7651 CustomExtension: expectedContents,
7652 },
7653 },
David Benjamin0c40a962016-08-01 12:05:50 -04007654 shouldFail: true,
7655 expectedError: ":UNEXPECTED_EXTENSION:",
7656 expectedLocalError: "remote error: unsupported extension",
7657 })
David Benjamin490469f2016-10-05 22:44:38 -04007658 testCases = append(testCases, testCase{
7659 testType: clientTest,
7660 name: "UnknownUnencryptedExtension-Client-TLS13",
7661 config: Config{
7662 MaxVersion: VersionTLS13,
7663 Bugs: ProtocolBugs{
7664 CustomUnencryptedExtension: expectedContents,
7665 },
7666 },
7667 shouldFail: true,
7668 expectedError: ":UNEXPECTED_EXTENSION:",
7669 // The shim must send an alert, but alerts at this point do not
7670 // get successfully decrypted by the runner.
7671 expectedLocalError: "local error: bad record MAC",
7672 })
7673 testCases = append(testCases, testCase{
7674 testType: clientTest,
7675 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7676 config: Config{
7677 MaxVersion: VersionTLS13,
7678 Bugs: ProtocolBugs{
7679 SendUnencryptedALPN: "foo",
7680 },
7681 },
7682 flags: []string{
7683 "-advertise-alpn", "\x03foo\x03bar",
7684 },
7685 shouldFail: true,
7686 expectedError: ":UNEXPECTED_EXTENSION:",
7687 // The shim must send an alert, but alerts at this point do not
7688 // get successfully decrypted by the runner.
7689 expectedLocalError: "local error: bad record MAC",
7690 })
David Benjamin0c40a962016-08-01 12:05:50 -04007691
7692 // Test a known but unoffered extension from the server.
7693 testCases = append(testCases, testCase{
7694 testType: clientTest,
7695 name: "UnofferedExtension-Client",
7696 config: Config{
7697 MaxVersion: VersionTLS12,
7698 Bugs: ProtocolBugs{
7699 SendALPN: "alpn",
7700 },
7701 },
7702 shouldFail: true,
7703 expectedError: ":UNEXPECTED_EXTENSION:",
7704 expectedLocalError: "remote error: unsupported extension",
7705 })
7706 testCases = append(testCases, testCase{
7707 testType: clientTest,
7708 name: "UnofferedExtension-Client-TLS13",
7709 config: Config{
7710 MaxVersion: VersionTLS13,
7711 Bugs: ProtocolBugs{
7712 SendALPN: "alpn",
7713 },
7714 },
7715 shouldFail: true,
7716 expectedError: ":UNEXPECTED_EXTENSION:",
7717 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007718 })
Adam Langley09505632015-07-30 18:10:13 -07007719}
7720
David Benjaminb36a3952015-12-01 18:53:13 -05007721func addRSAClientKeyExchangeTests() {
7722 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7723 testCases = append(testCases, testCase{
7724 testType: serverTest,
7725 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7726 config: Config{
7727 // Ensure the ClientHello version and final
7728 // version are different, to detect if the
7729 // server uses the wrong one.
7730 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007731 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007732 Bugs: ProtocolBugs{
7733 BadRSAClientKeyExchange: bad,
7734 },
7735 },
7736 shouldFail: true,
7737 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7738 })
7739 }
David Benjamine63d9d72016-09-19 18:27:34 -04007740
7741 // The server must compare whatever was in ClientHello.version for the
7742 // RSA premaster.
7743 testCases = append(testCases, testCase{
7744 testType: serverTest,
7745 name: "SendClientVersion-RSA",
7746 config: Config{
7747 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7748 Bugs: ProtocolBugs{
7749 SendClientVersion: 0x1234,
7750 },
7751 },
7752 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7753 })
David Benjaminb36a3952015-12-01 18:53:13 -05007754}
7755
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007756var testCurves = []struct {
7757 name string
7758 id CurveID
7759}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007760 {"P-256", CurveP256},
7761 {"P-384", CurveP384},
7762 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007763 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007764}
7765
Steven Valdez5440fe02016-07-18 12:40:30 -04007766const bogusCurve = 0x1234
7767
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007768func addCurveTests() {
7769 for _, curve := range testCurves {
7770 testCases = append(testCases, testCase{
7771 name: "CurveTest-Client-" + curve.name,
7772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007773 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007774 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7775 CurvePreferences: []CurveID{curve.id},
7776 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007777 flags: []string{
7778 "-enable-all-curves",
7779 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7780 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007781 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007782 })
7783 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007784 name: "CurveTest-Client-" + curve.name + "-TLS13",
7785 config: Config{
7786 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007787 CurvePreferences: []CurveID{curve.id},
7788 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007789 flags: []string{
7790 "-enable-all-curves",
7791 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7792 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007793 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007794 })
7795 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007796 testType: serverTest,
7797 name: "CurveTest-Server-" + curve.name,
7798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007799 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7801 CurvePreferences: []CurveID{curve.id},
7802 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007803 flags: []string{
7804 "-enable-all-curves",
7805 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7806 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007807 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007808 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007809 testCases = append(testCases, testCase{
7810 testType: serverTest,
7811 name: "CurveTest-Server-" + curve.name + "-TLS13",
7812 config: Config{
7813 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007814 CurvePreferences: []CurveID{curve.id},
7815 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007816 flags: []string{
7817 "-enable-all-curves",
7818 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7819 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007820 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007821 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007822 }
David Benjamin241ae832016-01-15 03:04:54 -05007823
7824 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007825 testCases = append(testCases, testCase{
7826 testType: serverTest,
7827 name: "UnknownCurve",
7828 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007829 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007830 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7831 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7832 },
7833 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007834
Steven Valdez803c77a2016-09-06 14:13:43 -04007835 // The server must be tolerant to bogus curves.
7836 testCases = append(testCases, testCase{
7837 testType: serverTest,
7838 name: "UnknownCurve-TLS13",
7839 config: Config{
7840 MaxVersion: VersionTLS13,
7841 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7842 },
7843 })
7844
David Benjamin4c3ddf72016-06-29 18:13:53 -04007845 // The server must not consider ECDHE ciphers when there are no
7846 // supported curves.
7847 testCases = append(testCases, testCase{
7848 testType: serverTest,
7849 name: "NoSupportedCurves",
7850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007851 MaxVersion: VersionTLS12,
7852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7853 Bugs: ProtocolBugs{
7854 NoSupportedCurves: true,
7855 },
7856 },
7857 shouldFail: true,
7858 expectedError: ":NO_SHARED_CIPHER:",
7859 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007860 testCases = append(testCases, testCase{
7861 testType: serverTest,
7862 name: "NoSupportedCurves-TLS13",
7863 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007864 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007865 Bugs: ProtocolBugs{
7866 NoSupportedCurves: true,
7867 },
7868 },
7869 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007870 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007871 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007872
7873 // The server must fall back to another cipher when there are no
7874 // supported curves.
7875 testCases = append(testCases, testCase{
7876 testType: serverTest,
7877 name: "NoCommonCurves",
7878 config: Config{
7879 MaxVersion: VersionTLS12,
7880 CipherSuites: []uint16{
7881 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7882 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7883 },
7884 CurvePreferences: []CurveID{CurveP224},
7885 },
7886 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7887 })
7888
7889 // The client must reject bogus curves and disabled curves.
7890 testCases = append(testCases, testCase{
7891 name: "BadECDHECurve",
7892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007893 MaxVersion: VersionTLS12,
7894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7895 Bugs: ProtocolBugs{
7896 SendCurve: bogusCurve,
7897 },
7898 },
7899 shouldFail: true,
7900 expectedError: ":WRONG_CURVE:",
7901 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007902 testCases = append(testCases, testCase{
7903 name: "BadECDHECurve-TLS13",
7904 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007905 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007906 Bugs: ProtocolBugs{
7907 SendCurve: bogusCurve,
7908 },
7909 },
7910 shouldFail: true,
7911 expectedError: ":WRONG_CURVE:",
7912 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007913
7914 testCases = append(testCases, testCase{
7915 name: "UnsupportedCurve",
7916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007917 MaxVersion: VersionTLS12,
7918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7919 CurvePreferences: []CurveID{CurveP256},
7920 Bugs: ProtocolBugs{
7921 IgnorePeerCurvePreferences: true,
7922 },
7923 },
7924 flags: []string{"-p384-only"},
7925 shouldFail: true,
7926 expectedError: ":WRONG_CURVE:",
7927 })
7928
David Benjamin4f921572016-07-17 14:20:10 +02007929 testCases = append(testCases, testCase{
7930 // TODO(davidben): Add a TLS 1.3 version where
7931 // HelloRetryRequest requests an unsupported curve.
7932 name: "UnsupportedCurve-ServerHello-TLS13",
7933 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007934 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007935 CurvePreferences: []CurveID{CurveP384},
7936 Bugs: ProtocolBugs{
7937 SendCurve: CurveP256,
7938 },
7939 },
7940 flags: []string{"-p384-only"},
7941 shouldFail: true,
7942 expectedError: ":WRONG_CURVE:",
7943 })
7944
David Benjamin4c3ddf72016-06-29 18:13:53 -04007945 // Test invalid curve points.
7946 testCases = append(testCases, testCase{
7947 name: "InvalidECDHPoint-Client",
7948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007949 MaxVersion: VersionTLS12,
7950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7951 CurvePreferences: []CurveID{CurveP256},
7952 Bugs: ProtocolBugs{
7953 InvalidECDHPoint: true,
7954 },
7955 },
7956 shouldFail: true,
7957 expectedError: ":INVALID_ENCODING:",
7958 })
7959 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007960 name: "InvalidECDHPoint-Client-TLS13",
7961 config: Config{
7962 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007963 CurvePreferences: []CurveID{CurveP256},
7964 Bugs: ProtocolBugs{
7965 InvalidECDHPoint: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":INVALID_ENCODING:",
7970 })
7971 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007972 testType: serverTest,
7973 name: "InvalidECDHPoint-Server",
7974 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007975 MaxVersion: VersionTLS12,
7976 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7977 CurvePreferences: []CurveID{CurveP256},
7978 Bugs: ProtocolBugs{
7979 InvalidECDHPoint: true,
7980 },
7981 },
7982 shouldFail: true,
7983 expectedError: ":INVALID_ENCODING:",
7984 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007985 testCases = append(testCases, testCase{
7986 testType: serverTest,
7987 name: "InvalidECDHPoint-Server-TLS13",
7988 config: Config{
7989 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007990 CurvePreferences: []CurveID{CurveP256},
7991 Bugs: ProtocolBugs{
7992 InvalidECDHPoint: true,
7993 },
7994 },
7995 shouldFail: true,
7996 expectedError: ":INVALID_ENCODING:",
7997 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007998}
7999
Matt Braithwaite54217e42016-06-13 13:03:47 -07008000func addCECPQ1Tests() {
8001 testCases = append(testCases, testCase{
8002 testType: clientTest,
8003 name: "CECPQ1-Client-BadX25519Part",
8004 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008005 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008006 MinVersion: VersionTLS12,
8007 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8008 Bugs: ProtocolBugs{
8009 CECPQ1BadX25519Part: true,
8010 },
8011 },
8012 flags: []string{"-cipher", "kCECPQ1"},
8013 shouldFail: true,
8014 expectedLocalError: "local error: bad record MAC",
8015 })
8016 testCases = append(testCases, testCase{
8017 testType: clientTest,
8018 name: "CECPQ1-Client-BadNewhopePart",
8019 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008020 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008021 MinVersion: VersionTLS12,
8022 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8023 Bugs: ProtocolBugs{
8024 CECPQ1BadNewhopePart: true,
8025 },
8026 },
8027 flags: []string{"-cipher", "kCECPQ1"},
8028 shouldFail: true,
8029 expectedLocalError: "local error: bad record MAC",
8030 })
8031 testCases = append(testCases, testCase{
8032 testType: serverTest,
8033 name: "CECPQ1-Server-BadX25519Part",
8034 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008035 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008036 MinVersion: VersionTLS12,
8037 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8038 Bugs: ProtocolBugs{
8039 CECPQ1BadX25519Part: true,
8040 },
8041 },
8042 flags: []string{"-cipher", "kCECPQ1"},
8043 shouldFail: true,
8044 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8045 })
8046 testCases = append(testCases, testCase{
8047 testType: serverTest,
8048 name: "CECPQ1-Server-BadNewhopePart",
8049 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008050 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008051 MinVersion: VersionTLS12,
8052 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8053 Bugs: ProtocolBugs{
8054 CECPQ1BadNewhopePart: true,
8055 },
8056 },
8057 flags: []string{"-cipher", "kCECPQ1"},
8058 shouldFail: true,
8059 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8060 })
8061}
8062
David Benjamin5c4e8572016-08-19 17:44:53 -04008063func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008064 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008065 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008066 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008067 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008068 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8069 Bugs: ProtocolBugs{
8070 // This is a 1234-bit prime number, generated
8071 // with:
8072 // openssl gendh 1234 | openssl asn1parse -i
8073 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8074 },
8075 },
David Benjamin9e68f192016-06-30 14:55:33 -04008076 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008077 })
8078 testCases = append(testCases, testCase{
8079 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008080 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008081 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008082 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008083 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8084 },
8085 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008086 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008087 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008088}
8089
David Benjaminc9ae27c2016-06-24 22:56:37 -04008090func addTLS13RecordTests() {
8091 testCases = append(testCases, testCase{
8092 name: "TLS13-RecordPadding",
8093 config: Config{
8094 MaxVersion: VersionTLS13,
8095 MinVersion: VersionTLS13,
8096 Bugs: ProtocolBugs{
8097 RecordPadding: 10,
8098 },
8099 },
8100 })
8101
8102 testCases = append(testCases, testCase{
8103 name: "TLS13-EmptyRecords",
8104 config: Config{
8105 MaxVersion: VersionTLS13,
8106 MinVersion: VersionTLS13,
8107 Bugs: ProtocolBugs{
8108 OmitRecordContents: true,
8109 },
8110 },
8111 shouldFail: true,
8112 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8113 })
8114
8115 testCases = append(testCases, testCase{
8116 name: "TLS13-OnlyPadding",
8117 config: Config{
8118 MaxVersion: VersionTLS13,
8119 MinVersion: VersionTLS13,
8120 Bugs: ProtocolBugs{
8121 OmitRecordContents: true,
8122 RecordPadding: 10,
8123 },
8124 },
8125 shouldFail: true,
8126 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8127 })
8128
8129 testCases = append(testCases, testCase{
8130 name: "TLS13-WrongOuterRecord",
8131 config: Config{
8132 MaxVersion: VersionTLS13,
8133 MinVersion: VersionTLS13,
8134 Bugs: ProtocolBugs{
8135 OuterRecordType: recordTypeHandshake,
8136 },
8137 },
8138 shouldFail: true,
8139 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8140 })
8141}
8142
Steven Valdez5b986082016-09-01 12:29:49 -04008143func addSessionTicketTests() {
8144 testCases = append(testCases, testCase{
8145 // In TLS 1.2 and below, empty NewSessionTicket messages
8146 // mean the server changed its mind on sending a ticket.
8147 name: "SendEmptySessionTicket",
8148 config: Config{
8149 MaxVersion: VersionTLS12,
8150 Bugs: ProtocolBugs{
8151 SendEmptySessionTicket: true,
8152 },
8153 },
8154 flags: []string{"-expect-no-session"},
8155 })
8156
8157 // Test that the server ignores unknown PSK modes.
8158 testCases = append(testCases, testCase{
8159 testType: serverTest,
8160 name: "TLS13-SendUnknownModeSessionTicket-Server",
8161 config: Config{
8162 MaxVersion: VersionTLS13,
8163 Bugs: ProtocolBugs{
8164 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008165 },
8166 },
8167 resumeSession: true,
8168 expectedResumeVersion: VersionTLS13,
8169 })
8170
Steven Valdeza833c352016-11-01 13:39:36 -04008171 // Test that the server does not send session tickets with no matching key exchange mode.
8172 testCases = append(testCases, testCase{
8173 testType: serverTest,
8174 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8175 config: Config{
8176 MaxVersion: VersionTLS13,
8177 Bugs: ProtocolBugs{
8178 SendPSKKeyExchangeModes: []byte{0x1a},
8179 ExpectNoNewSessionTicket: true,
8180 },
8181 },
8182 })
8183
8184 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008185 testCases = append(testCases, testCase{
8186 testType: serverTest,
8187 name: "TLS13-SendBadKEModeSessionTicket-Server",
8188 config: Config{
8189 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008190 },
8191 resumeConfig: &Config{
8192 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008193 Bugs: ProtocolBugs{
8194 SendPSKKeyExchangeModes: []byte{0x1a},
8195 },
8196 },
8197 resumeSession: true,
8198 expectResumeRejected: true,
8199 })
8200
Steven Valdeza833c352016-11-01 13:39:36 -04008201 // Test that the client ticket age is sent correctly.
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-TestValidTicketAge-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: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008209 },
8210 },
Steven Valdeza833c352016-11-01 13:39:36 -04008211 resumeSession: true,
8212 flags: []string{
8213 "-resumption-delay", "10",
8214 },
Steven Valdez5b986082016-09-01 12:29:49 -04008215 })
8216
Steven Valdeza833c352016-11-01 13:39:36 -04008217 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008218 testCases = append(testCases, testCase{
8219 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008220 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008221 config: Config{
8222 MaxVersion: VersionTLS13,
8223 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008224 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008225 },
8226 },
Steven Valdeza833c352016-11-01 13:39:36 -04008227 resumeSession: true,
8228 shouldFail: true,
8229 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008230 })
8231
Steven Valdez5b986082016-09-01 12:29:49 -04008232}
8233
David Benjamin82261be2016-07-07 14:32:50 -07008234func addChangeCipherSpecTests() {
8235 // Test missing ChangeCipherSpecs.
8236 testCases = append(testCases, testCase{
8237 name: "SkipChangeCipherSpec-Client",
8238 config: Config{
8239 MaxVersion: VersionTLS12,
8240 Bugs: ProtocolBugs{
8241 SkipChangeCipherSpec: true,
8242 },
8243 },
8244 shouldFail: true,
8245 expectedError: ":UNEXPECTED_RECORD:",
8246 })
8247 testCases = append(testCases, testCase{
8248 testType: serverTest,
8249 name: "SkipChangeCipherSpec-Server",
8250 config: Config{
8251 MaxVersion: VersionTLS12,
8252 Bugs: ProtocolBugs{
8253 SkipChangeCipherSpec: true,
8254 },
8255 },
8256 shouldFail: true,
8257 expectedError: ":UNEXPECTED_RECORD:",
8258 })
8259 testCases = append(testCases, testCase{
8260 testType: serverTest,
8261 name: "SkipChangeCipherSpec-Server-NPN",
8262 config: Config{
8263 MaxVersion: VersionTLS12,
8264 NextProtos: []string{"bar"},
8265 Bugs: ProtocolBugs{
8266 SkipChangeCipherSpec: true,
8267 },
8268 },
8269 flags: []string{
8270 "-advertise-npn", "\x03foo\x03bar\x03baz",
8271 },
8272 shouldFail: true,
8273 expectedError: ":UNEXPECTED_RECORD:",
8274 })
8275
8276 // Test synchronization between the handshake and ChangeCipherSpec.
8277 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8278 // rejected. Test both with and without handshake packing to handle both
8279 // when the partial post-CCS message is in its own record and when it is
8280 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008281 for _, packed := range []bool{false, true} {
8282 var suffix string
8283 if packed {
8284 suffix = "-Packed"
8285 }
8286
8287 testCases = append(testCases, testCase{
8288 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8289 config: 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 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8301 config: Config{
8302 MaxVersion: VersionTLS12,
8303 },
8304 resumeSession: true,
8305 resumeConfig: &Config{
8306 MaxVersion: VersionTLS12,
8307 Bugs: ProtocolBugs{
8308 FragmentAcrossChangeCipherSpec: true,
8309 PackHandshakeFlight: packed,
8310 },
8311 },
8312 shouldFail: true,
8313 expectedError: ":UNEXPECTED_RECORD:",
8314 })
8315 testCases = append(testCases, testCase{
8316 testType: serverTest,
8317 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8318 config: Config{
8319 MaxVersion: VersionTLS12,
8320 Bugs: ProtocolBugs{
8321 FragmentAcrossChangeCipherSpec: true,
8322 PackHandshakeFlight: packed,
8323 },
8324 },
8325 shouldFail: true,
8326 expectedError: ":UNEXPECTED_RECORD:",
8327 })
8328 testCases = append(testCases, testCase{
8329 testType: serverTest,
8330 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8331 config: Config{
8332 MaxVersion: VersionTLS12,
8333 },
8334 resumeSession: true,
8335 resumeConfig: &Config{
8336 MaxVersion: VersionTLS12,
8337 Bugs: ProtocolBugs{
8338 FragmentAcrossChangeCipherSpec: true,
8339 PackHandshakeFlight: packed,
8340 },
8341 },
8342 shouldFail: true,
8343 expectedError: ":UNEXPECTED_RECORD:",
8344 })
8345 testCases = append(testCases, testCase{
8346 testType: serverTest,
8347 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8348 config: Config{
8349 MaxVersion: VersionTLS12,
8350 NextProtos: []string{"bar"},
8351 Bugs: ProtocolBugs{
8352 FragmentAcrossChangeCipherSpec: true,
8353 PackHandshakeFlight: packed,
8354 },
8355 },
8356 flags: []string{
8357 "-advertise-npn", "\x03foo\x03bar\x03baz",
8358 },
8359 shouldFail: true,
8360 expectedError: ":UNEXPECTED_RECORD:",
8361 })
8362 }
8363
David Benjamin61672812016-07-14 23:10:43 -04008364 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8365 // messages in the handshake queue. Do this by testing the server
8366 // reading the client Finished, reversing the flight so Finished comes
8367 // first.
8368 testCases = append(testCases, testCase{
8369 protocol: dtls,
8370 testType: serverTest,
8371 name: "SendUnencryptedFinished-DTLS",
8372 config: Config{
8373 MaxVersion: VersionTLS12,
8374 Bugs: ProtocolBugs{
8375 SendUnencryptedFinished: true,
8376 ReverseHandshakeFragments: true,
8377 },
8378 },
8379 shouldFail: true,
8380 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8381 })
8382
Steven Valdez143e8b32016-07-11 13:19:03 -04008383 // Test synchronization between encryption changes and the handshake in
8384 // TLS 1.3, where ChangeCipherSpec is implicit.
8385 testCases = append(testCases, testCase{
8386 name: "PartialEncryptedExtensionsWithServerHello",
8387 config: Config{
8388 MaxVersion: VersionTLS13,
8389 Bugs: ProtocolBugs{
8390 PartialEncryptedExtensionsWithServerHello: true,
8391 },
8392 },
8393 shouldFail: true,
8394 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8395 })
8396 testCases = append(testCases, testCase{
8397 testType: serverTest,
8398 name: "PartialClientFinishedWithClientHello",
8399 config: Config{
8400 MaxVersion: VersionTLS13,
8401 Bugs: ProtocolBugs{
8402 PartialClientFinishedWithClientHello: true,
8403 },
8404 },
8405 shouldFail: true,
8406 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8407 })
8408
David Benjamin82261be2016-07-07 14:32:50 -07008409 // Test that early ChangeCipherSpecs are handled correctly.
8410 testCases = append(testCases, testCase{
8411 testType: serverTest,
8412 name: "EarlyChangeCipherSpec-server-1",
8413 config: Config{
8414 MaxVersion: VersionTLS12,
8415 Bugs: ProtocolBugs{
8416 EarlyChangeCipherSpec: 1,
8417 },
8418 },
8419 shouldFail: true,
8420 expectedError: ":UNEXPECTED_RECORD:",
8421 })
8422 testCases = append(testCases, testCase{
8423 testType: serverTest,
8424 name: "EarlyChangeCipherSpec-server-2",
8425 config: Config{
8426 MaxVersion: VersionTLS12,
8427 Bugs: ProtocolBugs{
8428 EarlyChangeCipherSpec: 2,
8429 },
8430 },
8431 shouldFail: true,
8432 expectedError: ":UNEXPECTED_RECORD:",
8433 })
8434 testCases = append(testCases, testCase{
8435 protocol: dtls,
8436 name: "StrayChangeCipherSpec",
8437 config: Config{
8438 // TODO(davidben): Once DTLS 1.3 exists, test
8439 // that stray ChangeCipherSpec messages are
8440 // rejected.
8441 MaxVersion: VersionTLS12,
8442 Bugs: ProtocolBugs{
8443 StrayChangeCipherSpec: true,
8444 },
8445 },
8446 })
8447
8448 // Test that the contents of ChangeCipherSpec are checked.
8449 testCases = append(testCases, testCase{
8450 name: "BadChangeCipherSpec-1",
8451 config: Config{
8452 MaxVersion: VersionTLS12,
8453 Bugs: ProtocolBugs{
8454 BadChangeCipherSpec: []byte{2},
8455 },
8456 },
8457 shouldFail: true,
8458 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8459 })
8460 testCases = append(testCases, testCase{
8461 name: "BadChangeCipherSpec-2",
8462 config: Config{
8463 MaxVersion: VersionTLS12,
8464 Bugs: ProtocolBugs{
8465 BadChangeCipherSpec: []byte{1, 1},
8466 },
8467 },
8468 shouldFail: true,
8469 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8470 })
8471 testCases = append(testCases, testCase{
8472 protocol: dtls,
8473 name: "BadChangeCipherSpec-DTLS-1",
8474 config: Config{
8475 MaxVersion: VersionTLS12,
8476 Bugs: ProtocolBugs{
8477 BadChangeCipherSpec: []byte{2},
8478 },
8479 },
8480 shouldFail: true,
8481 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8482 })
8483 testCases = append(testCases, testCase{
8484 protocol: dtls,
8485 name: "BadChangeCipherSpec-DTLS-2",
8486 config: Config{
8487 MaxVersion: VersionTLS12,
8488 Bugs: ProtocolBugs{
8489 BadChangeCipherSpec: []byte{1, 1},
8490 },
8491 },
8492 shouldFail: true,
8493 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8494 })
8495}
8496
David Benjamincd2c8062016-09-09 11:28:16 -04008497type perMessageTest struct {
8498 messageType uint8
8499 test testCase
8500}
8501
8502// makePerMessageTests returns a series of test templates which cover each
8503// message in the TLS handshake. These may be used with bugs like
8504// WrongMessageType to fully test a per-message bug.
8505func makePerMessageTests() []perMessageTest {
8506 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008507 for _, protocol := range []protocol{tls, dtls} {
8508 var suffix string
8509 if protocol == dtls {
8510 suffix = "-DTLS"
8511 }
8512
David Benjamincd2c8062016-09-09 11:28:16 -04008513 ret = append(ret, perMessageTest{
8514 messageType: typeClientHello,
8515 test: testCase{
8516 protocol: protocol,
8517 testType: serverTest,
8518 name: "ClientHello" + suffix,
8519 config: Config{
8520 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008521 },
8522 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008523 })
8524
8525 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008526 ret = append(ret, perMessageTest{
8527 messageType: typeHelloVerifyRequest,
8528 test: testCase{
8529 protocol: protocol,
8530 name: "HelloVerifyRequest" + suffix,
8531 config: Config{
8532 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008533 },
8534 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008535 })
8536 }
8537
David Benjamincd2c8062016-09-09 11:28:16 -04008538 ret = append(ret, perMessageTest{
8539 messageType: typeServerHello,
8540 test: testCase{
8541 protocol: protocol,
8542 name: "ServerHello" + suffix,
8543 config: Config{
8544 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008545 },
8546 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008547 })
8548
David Benjamincd2c8062016-09-09 11:28:16 -04008549 ret = append(ret, perMessageTest{
8550 messageType: typeCertificate,
8551 test: testCase{
8552 protocol: protocol,
8553 name: "ServerCertificate" + suffix,
8554 config: Config{
8555 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008556 },
8557 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008558 })
8559
David Benjamincd2c8062016-09-09 11:28:16 -04008560 ret = append(ret, perMessageTest{
8561 messageType: typeCertificateStatus,
8562 test: testCase{
8563 protocol: protocol,
8564 name: "CertificateStatus" + suffix,
8565 config: Config{
8566 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008567 },
David Benjamincd2c8062016-09-09 11:28:16 -04008568 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008569 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008570 })
8571
David Benjamincd2c8062016-09-09 11:28:16 -04008572 ret = append(ret, perMessageTest{
8573 messageType: typeServerKeyExchange,
8574 test: testCase{
8575 protocol: protocol,
8576 name: "ServerKeyExchange" + suffix,
8577 config: Config{
8578 MaxVersion: VersionTLS12,
8579 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008580 },
8581 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008582 })
8583
David Benjamincd2c8062016-09-09 11:28:16 -04008584 ret = append(ret, perMessageTest{
8585 messageType: typeCertificateRequest,
8586 test: testCase{
8587 protocol: protocol,
8588 name: "CertificateRequest" + suffix,
8589 config: Config{
8590 MaxVersion: VersionTLS12,
8591 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008592 },
8593 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008594 })
8595
David Benjamincd2c8062016-09-09 11:28:16 -04008596 ret = append(ret, perMessageTest{
8597 messageType: typeServerHelloDone,
8598 test: testCase{
8599 protocol: protocol,
8600 name: "ServerHelloDone" + suffix,
8601 config: Config{
8602 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008603 },
8604 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008605 })
8606
David Benjamincd2c8062016-09-09 11:28:16 -04008607 ret = append(ret, perMessageTest{
8608 messageType: typeCertificate,
8609 test: testCase{
8610 testType: serverTest,
8611 protocol: protocol,
8612 name: "ClientCertificate" + suffix,
8613 config: Config{
8614 Certificates: []Certificate{rsaCertificate},
8615 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008616 },
David Benjamincd2c8062016-09-09 11:28:16 -04008617 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008618 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008619 })
8620
David Benjamincd2c8062016-09-09 11:28:16 -04008621 ret = append(ret, perMessageTest{
8622 messageType: typeCertificateVerify,
8623 test: testCase{
8624 testType: serverTest,
8625 protocol: protocol,
8626 name: "CertificateVerify" + suffix,
8627 config: Config{
8628 Certificates: []Certificate{rsaCertificate},
8629 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008630 },
David Benjamincd2c8062016-09-09 11:28:16 -04008631 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008632 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008633 })
8634
David Benjamincd2c8062016-09-09 11:28:16 -04008635 ret = append(ret, perMessageTest{
8636 messageType: typeClientKeyExchange,
8637 test: testCase{
8638 testType: serverTest,
8639 protocol: protocol,
8640 name: "ClientKeyExchange" + suffix,
8641 config: Config{
8642 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008643 },
8644 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008645 })
8646
8647 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008648 ret = append(ret, perMessageTest{
8649 messageType: typeNextProtocol,
8650 test: testCase{
8651 testType: serverTest,
8652 protocol: protocol,
8653 name: "NextProtocol" + suffix,
8654 config: Config{
8655 MaxVersion: VersionTLS12,
8656 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008657 },
David Benjamincd2c8062016-09-09 11:28:16 -04008658 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008659 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008660 })
8661
David Benjamincd2c8062016-09-09 11:28:16 -04008662 ret = append(ret, perMessageTest{
8663 messageType: typeChannelID,
8664 test: testCase{
8665 testType: serverTest,
8666 protocol: protocol,
8667 name: "ChannelID" + suffix,
8668 config: Config{
8669 MaxVersion: VersionTLS12,
8670 ChannelID: channelIDKey,
8671 },
8672 flags: []string{
8673 "-expect-channel-id",
8674 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008675 },
8676 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008677 })
8678 }
8679
David Benjamincd2c8062016-09-09 11:28:16 -04008680 ret = append(ret, perMessageTest{
8681 messageType: typeFinished,
8682 test: testCase{
8683 testType: serverTest,
8684 protocol: protocol,
8685 name: "ClientFinished" + suffix,
8686 config: Config{
8687 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008688 },
8689 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008690 })
8691
David Benjamincd2c8062016-09-09 11:28:16 -04008692 ret = append(ret, perMessageTest{
8693 messageType: typeNewSessionTicket,
8694 test: testCase{
8695 protocol: protocol,
8696 name: "NewSessionTicket" + suffix,
8697 config: Config{
8698 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008699 },
8700 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008701 })
8702
David Benjamincd2c8062016-09-09 11:28:16 -04008703 ret = append(ret, perMessageTest{
8704 messageType: typeFinished,
8705 test: testCase{
8706 protocol: protocol,
8707 name: "ServerFinished" + suffix,
8708 config: Config{
8709 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008710 },
8711 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008712 })
8713
8714 }
David Benjamincd2c8062016-09-09 11:28:16 -04008715
8716 ret = append(ret, perMessageTest{
8717 messageType: typeClientHello,
8718 test: testCase{
8719 testType: serverTest,
8720 name: "TLS13-ClientHello",
8721 config: Config{
8722 MaxVersion: VersionTLS13,
8723 },
8724 },
8725 })
8726
8727 ret = append(ret, perMessageTest{
8728 messageType: typeServerHello,
8729 test: testCase{
8730 name: "TLS13-ServerHello",
8731 config: Config{
8732 MaxVersion: VersionTLS13,
8733 },
8734 },
8735 })
8736
8737 ret = append(ret, perMessageTest{
8738 messageType: typeEncryptedExtensions,
8739 test: testCase{
8740 name: "TLS13-EncryptedExtensions",
8741 config: Config{
8742 MaxVersion: VersionTLS13,
8743 },
8744 },
8745 })
8746
8747 ret = append(ret, perMessageTest{
8748 messageType: typeCertificateRequest,
8749 test: testCase{
8750 name: "TLS13-CertificateRequest",
8751 config: Config{
8752 MaxVersion: VersionTLS13,
8753 ClientAuth: RequireAnyClientCert,
8754 },
8755 },
8756 })
8757
8758 ret = append(ret, perMessageTest{
8759 messageType: typeCertificate,
8760 test: testCase{
8761 name: "TLS13-ServerCertificate",
8762 config: Config{
8763 MaxVersion: VersionTLS13,
8764 },
8765 },
8766 })
8767
8768 ret = append(ret, perMessageTest{
8769 messageType: typeCertificateVerify,
8770 test: testCase{
8771 name: "TLS13-ServerCertificateVerify",
8772 config: Config{
8773 MaxVersion: VersionTLS13,
8774 },
8775 },
8776 })
8777
8778 ret = append(ret, perMessageTest{
8779 messageType: typeFinished,
8780 test: testCase{
8781 name: "TLS13-ServerFinished",
8782 config: Config{
8783 MaxVersion: VersionTLS13,
8784 },
8785 },
8786 })
8787
8788 ret = append(ret, perMessageTest{
8789 messageType: typeCertificate,
8790 test: testCase{
8791 testType: serverTest,
8792 name: "TLS13-ClientCertificate",
8793 config: Config{
8794 Certificates: []Certificate{rsaCertificate},
8795 MaxVersion: VersionTLS13,
8796 },
8797 flags: []string{"-require-any-client-certificate"},
8798 },
8799 })
8800
8801 ret = append(ret, perMessageTest{
8802 messageType: typeCertificateVerify,
8803 test: testCase{
8804 testType: serverTest,
8805 name: "TLS13-ClientCertificateVerify",
8806 config: Config{
8807 Certificates: []Certificate{rsaCertificate},
8808 MaxVersion: VersionTLS13,
8809 },
8810 flags: []string{"-require-any-client-certificate"},
8811 },
8812 })
8813
8814 ret = append(ret, perMessageTest{
8815 messageType: typeFinished,
8816 test: testCase{
8817 testType: serverTest,
8818 name: "TLS13-ClientFinished",
8819 config: Config{
8820 MaxVersion: VersionTLS13,
8821 },
8822 },
8823 })
8824
8825 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008826}
8827
David Benjamincd2c8062016-09-09 11:28:16 -04008828func addWrongMessageTypeTests() {
8829 for _, t := range makePerMessageTests() {
8830 t.test.name = "WrongMessageType-" + t.test.name
8831 t.test.config.Bugs.SendWrongMessageType = t.messageType
8832 t.test.shouldFail = true
8833 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8834 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008835
David Benjamincd2c8062016-09-09 11:28:16 -04008836 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8837 // In TLS 1.3, a bad ServerHello means the client sends
8838 // an unencrypted alert while the server expects
8839 // encryption, so the alert is not readable by runner.
8840 t.test.expectedLocalError = "local error: bad record MAC"
8841 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008842
David Benjamincd2c8062016-09-09 11:28:16 -04008843 testCases = append(testCases, t.test)
8844 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008845}
8846
David Benjamin639846e2016-09-09 11:41:18 -04008847func addTrailingMessageDataTests() {
8848 for _, t := range makePerMessageTests() {
8849 t.test.name = "TrailingMessageData-" + t.test.name
8850 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8851 t.test.shouldFail = true
8852 t.test.expectedError = ":DECODE_ERROR:"
8853 t.test.expectedLocalError = "remote error: error decoding message"
8854
8855 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8856 // In TLS 1.3, a bad ServerHello means the client sends
8857 // an unencrypted alert while the server expects
8858 // encryption, so the alert is not readable by runner.
8859 t.test.expectedLocalError = "local error: bad record MAC"
8860 }
8861
8862 if t.messageType == typeFinished {
8863 // Bad Finished messages read as the verify data having
8864 // the wrong length.
8865 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8866 t.test.expectedLocalError = "remote error: error decrypting message"
8867 }
8868
8869 testCases = append(testCases, t.test)
8870 }
8871}
8872
Steven Valdez143e8b32016-07-11 13:19:03 -04008873func addTLS13HandshakeTests() {
8874 testCases = append(testCases, testCase{
8875 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008876 name: "NegotiatePSKResumption-TLS13",
8877 config: Config{
8878 MaxVersion: VersionTLS13,
8879 Bugs: ProtocolBugs{
8880 NegotiatePSKResumption: true,
8881 },
8882 },
8883 resumeSession: true,
8884 shouldFail: true,
8885 expectedError: ":UNEXPECTED_EXTENSION:",
8886 })
8887
8888 testCases = append(testCases, testCase{
8889 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008890 name: "MissingKeyShare-Client",
8891 config: Config{
8892 MaxVersion: VersionTLS13,
8893 Bugs: ProtocolBugs{
8894 MissingKeyShare: true,
8895 },
8896 },
8897 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008898 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008899 })
8900
8901 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008902 testType: serverTest,
8903 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008904 config: Config{
8905 MaxVersion: VersionTLS13,
8906 Bugs: ProtocolBugs{
8907 MissingKeyShare: true,
8908 },
8909 },
8910 shouldFail: true,
8911 expectedError: ":MISSING_KEY_SHARE:",
8912 })
8913
8914 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008915 testType: serverTest,
8916 name: "DuplicateKeyShares",
8917 config: Config{
8918 MaxVersion: VersionTLS13,
8919 Bugs: ProtocolBugs{
8920 DuplicateKeyShares: true,
8921 },
8922 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008923 shouldFail: true,
8924 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008925 })
8926
8927 testCases = append(testCases, testCase{
8928 testType: clientTest,
8929 name: "EmptyEncryptedExtensions",
8930 config: Config{
8931 MaxVersion: VersionTLS13,
8932 Bugs: ProtocolBugs{
8933 EmptyEncryptedExtensions: true,
8934 },
8935 },
8936 shouldFail: true,
8937 expectedLocalError: "remote error: error decoding message",
8938 })
8939
8940 testCases = append(testCases, testCase{
8941 testType: clientTest,
8942 name: "EncryptedExtensionsWithKeyShare",
8943 config: Config{
8944 MaxVersion: VersionTLS13,
8945 Bugs: ProtocolBugs{
8946 EncryptedExtensionsWithKeyShare: true,
8947 },
8948 },
8949 shouldFail: true,
8950 expectedLocalError: "remote error: unsupported extension",
8951 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008952
8953 testCases = append(testCases, testCase{
8954 testType: serverTest,
8955 name: "SendHelloRetryRequest",
8956 config: Config{
8957 MaxVersion: VersionTLS13,
8958 // Require a HelloRetryRequest for every curve.
8959 DefaultCurves: []CurveID{},
8960 },
8961 expectedCurveID: CurveX25519,
8962 })
8963
8964 testCases = append(testCases, testCase{
8965 testType: serverTest,
8966 name: "SendHelloRetryRequest-2",
8967 config: Config{
8968 MaxVersion: VersionTLS13,
8969 DefaultCurves: []CurveID{CurveP384},
8970 },
8971 // Although the ClientHello did not predict our preferred curve,
8972 // we always select it whether it is predicted or not.
8973 expectedCurveID: CurveX25519,
8974 })
8975
8976 testCases = append(testCases, testCase{
8977 name: "UnknownCurve-HelloRetryRequest",
8978 config: Config{
8979 MaxVersion: VersionTLS13,
8980 // P-384 requires HelloRetryRequest in BoringSSL.
8981 CurvePreferences: []CurveID{CurveP384},
8982 Bugs: ProtocolBugs{
8983 SendHelloRetryRequestCurve: bogusCurve,
8984 },
8985 },
8986 shouldFail: true,
8987 expectedError: ":WRONG_CURVE:",
8988 })
8989
8990 testCases = append(testCases, testCase{
8991 name: "DisabledCurve-HelloRetryRequest",
8992 config: Config{
8993 MaxVersion: VersionTLS13,
8994 CurvePreferences: []CurveID{CurveP256},
8995 Bugs: ProtocolBugs{
8996 IgnorePeerCurvePreferences: true,
8997 },
8998 },
8999 flags: []string{"-p384-only"},
9000 shouldFail: true,
9001 expectedError: ":WRONG_CURVE:",
9002 })
9003
9004 testCases = append(testCases, testCase{
9005 name: "UnnecessaryHelloRetryRequest",
9006 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009007 MaxVersion: VersionTLS13,
9008 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009009 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009010 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009011 },
9012 },
9013 shouldFail: true,
9014 expectedError: ":WRONG_CURVE:",
9015 })
9016
9017 testCases = append(testCases, testCase{
9018 name: "SecondHelloRetryRequest",
9019 config: Config{
9020 MaxVersion: VersionTLS13,
9021 // P-384 requires HelloRetryRequest in BoringSSL.
9022 CurvePreferences: []CurveID{CurveP384},
9023 Bugs: ProtocolBugs{
9024 SecondHelloRetryRequest: true,
9025 },
9026 },
9027 shouldFail: true,
9028 expectedError: ":UNEXPECTED_MESSAGE:",
9029 })
9030
9031 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009032 name: "HelloRetryRequest-Empty",
9033 config: Config{
9034 MaxVersion: VersionTLS13,
9035 Bugs: ProtocolBugs{
9036 AlwaysSendHelloRetryRequest: true,
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":DECODE_ERROR:",
9041 })
9042
9043 testCases = append(testCases, testCase{
9044 name: "HelloRetryRequest-DuplicateCurve",
9045 config: Config{
9046 MaxVersion: VersionTLS13,
9047 // P-384 requires a HelloRetryRequest against BoringSSL's default
9048 // configuration. Assert this ExpectMissingKeyShare.
9049 CurvePreferences: []CurveID{CurveP384},
9050 Bugs: ProtocolBugs{
9051 ExpectMissingKeyShare: true,
9052 DuplicateHelloRetryRequestExtensions: true,
9053 },
9054 },
9055 shouldFail: true,
9056 expectedError: ":DUPLICATE_EXTENSION:",
9057 expectedLocalError: "remote error: illegal parameter",
9058 })
9059
9060 testCases = append(testCases, testCase{
9061 name: "HelloRetryRequest-Cookie",
9062 config: Config{
9063 MaxVersion: VersionTLS13,
9064 Bugs: ProtocolBugs{
9065 SendHelloRetryRequestCookie: []byte("cookie"),
9066 },
9067 },
9068 })
9069
9070 testCases = append(testCases, testCase{
9071 name: "HelloRetryRequest-DuplicateCookie",
9072 config: Config{
9073 MaxVersion: VersionTLS13,
9074 Bugs: ProtocolBugs{
9075 SendHelloRetryRequestCookie: []byte("cookie"),
9076 DuplicateHelloRetryRequestExtensions: true,
9077 },
9078 },
9079 shouldFail: true,
9080 expectedError: ":DUPLICATE_EXTENSION:",
9081 expectedLocalError: "remote error: illegal parameter",
9082 })
9083
9084 testCases = append(testCases, testCase{
9085 name: "HelloRetryRequest-EmptyCookie",
9086 config: Config{
9087 MaxVersion: VersionTLS13,
9088 Bugs: ProtocolBugs{
9089 SendHelloRetryRequestCookie: []byte{},
9090 },
9091 },
9092 shouldFail: true,
9093 expectedError: ":DECODE_ERROR:",
9094 })
9095
9096 testCases = append(testCases, testCase{
9097 name: "HelloRetryRequest-Cookie-Curve",
9098 config: Config{
9099 MaxVersion: VersionTLS13,
9100 // P-384 requires HelloRetryRequest in BoringSSL.
9101 CurvePreferences: []CurveID{CurveP384},
9102 Bugs: ProtocolBugs{
9103 SendHelloRetryRequestCookie: []byte("cookie"),
9104 ExpectMissingKeyShare: true,
9105 },
9106 },
9107 })
9108
9109 testCases = append(testCases, testCase{
9110 name: "HelloRetryRequest-Unknown",
9111 config: Config{
9112 MaxVersion: VersionTLS13,
9113 Bugs: ProtocolBugs{
9114 CustomHelloRetryRequestExtension: "extension",
9115 },
9116 },
9117 shouldFail: true,
9118 expectedError: ":UNEXPECTED_EXTENSION:",
9119 expectedLocalError: "remote error: unsupported extension",
9120 })
9121
9122 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009123 testType: serverTest,
9124 name: "SecondClientHelloMissingKeyShare",
9125 config: Config{
9126 MaxVersion: VersionTLS13,
9127 DefaultCurves: []CurveID{},
9128 Bugs: ProtocolBugs{
9129 SecondClientHelloMissingKeyShare: true,
9130 },
9131 },
9132 shouldFail: true,
9133 expectedError: ":MISSING_KEY_SHARE:",
9134 })
9135
9136 testCases = append(testCases, testCase{
9137 testType: serverTest,
9138 name: "SecondClientHelloWrongCurve",
9139 config: Config{
9140 MaxVersion: VersionTLS13,
9141 DefaultCurves: []CurveID{},
9142 Bugs: ProtocolBugs{
9143 MisinterpretHelloRetryRequestCurve: CurveP521,
9144 },
9145 },
9146 shouldFail: true,
9147 expectedError: ":WRONG_CURVE:",
9148 })
9149
9150 testCases = append(testCases, testCase{
9151 name: "HelloRetryRequestVersionMismatch",
9152 config: Config{
9153 MaxVersion: VersionTLS13,
9154 // P-384 requires HelloRetryRequest in BoringSSL.
9155 CurvePreferences: []CurveID{CurveP384},
9156 Bugs: ProtocolBugs{
9157 SendServerHelloVersion: 0x0305,
9158 },
9159 },
9160 shouldFail: true,
9161 expectedError: ":WRONG_VERSION_NUMBER:",
9162 })
9163
9164 testCases = append(testCases, testCase{
9165 name: "HelloRetryRequestCurveMismatch",
9166 config: Config{
9167 MaxVersion: VersionTLS13,
9168 // P-384 requires HelloRetryRequest in BoringSSL.
9169 CurvePreferences: []CurveID{CurveP384},
9170 Bugs: ProtocolBugs{
9171 // Send P-384 (correct) in the HelloRetryRequest.
9172 SendHelloRetryRequestCurve: CurveP384,
9173 // But send P-256 in the ServerHello.
9174 SendCurve: CurveP256,
9175 },
9176 },
9177 shouldFail: true,
9178 expectedError: ":WRONG_CURVE:",
9179 })
9180
9181 // Test the server selecting a curve that requires a HelloRetryRequest
9182 // without sending it.
9183 testCases = append(testCases, testCase{
9184 name: "SkipHelloRetryRequest",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 // P-384 requires HelloRetryRequest in BoringSSL.
9188 CurvePreferences: []CurveID{CurveP384},
9189 Bugs: ProtocolBugs{
9190 SkipHelloRetryRequest: true,
9191 },
9192 },
9193 shouldFail: true,
9194 expectedError: ":WRONG_CURVE:",
9195 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009196
9197 testCases = append(testCases, testCase{
9198 name: "TLS13-RequestContextInHandshake",
9199 config: Config{
9200 MaxVersion: VersionTLS13,
9201 MinVersion: VersionTLS13,
9202 ClientAuth: RequireAnyClientCert,
9203 Bugs: ProtocolBugs{
9204 SendRequestContext: []byte("request context"),
9205 },
9206 },
9207 flags: []string{
9208 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9209 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9210 },
9211 shouldFail: true,
9212 expectedError: ":DECODE_ERROR:",
9213 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009214
9215 testCases = append(testCases, testCase{
9216 testType: serverTest,
9217 name: "TLS13-TrailingKeyShareData",
9218 config: Config{
9219 MaxVersion: VersionTLS13,
9220 Bugs: ProtocolBugs{
9221 TrailingKeyShareData: true,
9222 },
9223 },
9224 shouldFail: true,
9225 expectedError: ":DECODE_ERROR:",
9226 })
David Benjamin7f78df42016-10-05 22:33:19 -04009227
9228 testCases = append(testCases, testCase{
9229 name: "TLS13-AlwaysSelectPSKIdentity",
9230 config: Config{
9231 MaxVersion: VersionTLS13,
9232 Bugs: ProtocolBugs{
9233 AlwaysSelectPSKIdentity: true,
9234 },
9235 },
9236 shouldFail: true,
9237 expectedError: ":UNEXPECTED_EXTENSION:",
9238 })
9239
9240 testCases = append(testCases, testCase{
9241 name: "TLS13-InvalidPSKIdentity",
9242 config: Config{
9243 MaxVersion: VersionTLS13,
9244 Bugs: ProtocolBugs{
9245 SelectPSKIdentityOnResume: 1,
9246 },
9247 },
9248 resumeSession: true,
9249 shouldFail: true,
9250 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9251 })
David Benjamin1286bee2016-10-07 15:25:06 -04009252
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009253 testCases = append(testCases, testCase{
9254 testType: serverTest,
9255 name: "TLS13-ExtraPSKIdentity",
9256 config: Config{
9257 MaxVersion: VersionTLS13,
9258 Bugs: ProtocolBugs{
9259 ExtraPSKIdentity: true,
9260 },
9261 },
9262 resumeSession: true,
9263 })
9264
David Benjamin1286bee2016-10-07 15:25:06 -04009265 // Test that unknown NewSessionTicket extensions are tolerated.
9266 testCases = append(testCases, testCase{
9267 name: "TLS13-CustomTicketExtension",
9268 config: Config{
9269 MaxVersion: VersionTLS13,
9270 Bugs: ProtocolBugs{
9271 CustomTicketExtension: "1234",
9272 },
9273 },
9274 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009275}
9276
David Benjaminabbbee12016-10-31 19:20:42 -04009277func addTLS13CipherPreferenceTests() {
9278 // Test that client preference is honored if the shim has AES hardware
9279 // and ChaCha20-Poly1305 is preferred otherwise.
9280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9283 config: Config{
9284 MaxVersion: VersionTLS13,
9285 CipherSuites: []uint16{
9286 TLS_CHACHA20_POLY1305_SHA256,
9287 TLS_AES_128_GCM_SHA256,
9288 },
9289 },
9290 flags: []string{
9291 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9292 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9293 },
9294 })
9295
9296 testCases = append(testCases, testCase{
9297 testType: serverTest,
9298 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9299 config: Config{
9300 MaxVersion: VersionTLS13,
9301 CipherSuites: []uint16{
9302 TLS_AES_128_GCM_SHA256,
9303 TLS_CHACHA20_POLY1305_SHA256,
9304 },
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 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9313 // whether it has AES hardware.
9314 testCases = append(testCases, testCase{
9315 name: "TLS13-CipherPreference-Client",
9316 config: Config{
9317 MaxVersion: VersionTLS13,
9318 // Use the client cipher order. (This is the default but
9319 // is listed to be explicit.)
9320 PreferServerCipherSuites: false,
9321 },
9322 flags: []string{
9323 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9324 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9325 },
9326 })
9327}
9328
David Benjaminf3fbade2016-09-19 13:08:16 -04009329func addPeekTests() {
9330 // Test SSL_peek works, including on empty records.
9331 testCases = append(testCases, testCase{
9332 name: "Peek-Basic",
9333 sendEmptyRecords: 1,
9334 flags: []string{"-peek-then-read"},
9335 })
9336
9337 // Test SSL_peek can drive the initial handshake.
9338 testCases = append(testCases, testCase{
9339 name: "Peek-ImplicitHandshake",
9340 flags: []string{
9341 "-peek-then-read",
9342 "-implicit-handshake",
9343 },
9344 })
9345
9346 // Test SSL_peek can discover and drive a renegotiation.
9347 testCases = append(testCases, testCase{
9348 name: "Peek-Renegotiate",
9349 config: Config{
9350 MaxVersion: VersionTLS12,
9351 },
9352 renegotiate: 1,
9353 flags: []string{
9354 "-peek-then-read",
9355 "-renegotiate-freely",
9356 "-expect-total-renegotiations", "1",
9357 },
9358 })
9359
9360 // Test SSL_peek can discover a close_notify.
9361 testCases = append(testCases, testCase{
9362 name: "Peek-Shutdown",
9363 config: Config{
9364 Bugs: ProtocolBugs{
9365 ExpectCloseNotify: true,
9366 },
9367 },
9368 flags: []string{
9369 "-peek-then-read",
9370 "-check-close-notify",
9371 },
9372 })
9373
9374 // Test SSL_peek can discover an alert.
9375 testCases = append(testCases, testCase{
9376 name: "Peek-Alert",
9377 config: Config{
9378 Bugs: ProtocolBugs{
9379 SendSpuriousAlert: alertRecordOverflow,
9380 },
9381 },
9382 flags: []string{"-peek-then-read"},
9383 shouldFail: true,
9384 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9385 })
9386
9387 // Test SSL_peek can handle KeyUpdate.
9388 testCases = append(testCases, testCase{
9389 name: "Peek-KeyUpdate",
9390 config: Config{
9391 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009392 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009393 sendKeyUpdates: 1,
9394 keyUpdateRequest: keyUpdateNotRequested,
9395 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009396 })
9397}
9398
David Benjamine6f22212016-11-08 14:28:24 -05009399func addRecordVersionTests() {
9400 for _, ver := range tlsVersions {
9401 // Test that the record version is enforced.
9402 testCases = append(testCases, testCase{
9403 name: "CheckRecordVersion-" + ver.name,
9404 config: Config{
9405 MinVersion: ver.version,
9406 MaxVersion: ver.version,
9407 Bugs: ProtocolBugs{
9408 SendRecordVersion: 0x03ff,
9409 },
9410 },
9411 shouldFail: true,
9412 expectedError: ":WRONG_VERSION_NUMBER:",
9413 })
9414
9415 // Test that the ClientHello may use any record version, for
9416 // compatibility reasons.
9417 testCases = append(testCases, testCase{
9418 testType: serverTest,
9419 name: "LooseInitialRecordVersion-" + ver.name,
9420 config: Config{
9421 MinVersion: ver.version,
9422 MaxVersion: ver.version,
9423 Bugs: ProtocolBugs{
9424 SendInitialRecordVersion: 0x03ff,
9425 },
9426 },
9427 })
9428
9429 // Test that garbage ClientHello record versions are rejected.
9430 testCases = append(testCases, testCase{
9431 testType: serverTest,
9432 name: "GarbageInitialRecordVersion-" + ver.name,
9433 config: Config{
9434 MinVersion: ver.version,
9435 MaxVersion: ver.version,
9436 Bugs: ProtocolBugs{
9437 SendInitialRecordVersion: 0xffff,
9438 },
9439 },
9440 shouldFail: true,
9441 expectedError: ":WRONG_VERSION_NUMBER:",
9442 })
9443 }
9444}
9445
David Benjamin2c516452016-11-15 10:16:54 +09009446func addCertificateTests() {
9447 // Test that a certificate chain with intermediate may be sent and
9448 // received as both client and server.
9449 for _, ver := range tlsVersions {
9450 testCases = append(testCases, testCase{
9451 testType: clientTest,
9452 name: "SendReceiveIntermediate-Client-" + ver.name,
9453 config: Config{
9454 Certificates: []Certificate{rsaChainCertificate},
9455 ClientAuth: RequireAnyClientCert,
9456 },
9457 expectPeerCertificate: &rsaChainCertificate,
9458 flags: []string{
9459 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9460 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9461 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9462 },
9463 })
9464
9465 testCases = append(testCases, testCase{
9466 testType: serverTest,
9467 name: "SendReceiveIntermediate-Server-" + ver.name,
9468 config: Config{
9469 Certificates: []Certificate{rsaChainCertificate},
9470 },
9471 expectPeerCertificate: &rsaChainCertificate,
9472 flags: []string{
9473 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9474 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9475 "-require-any-client-certificate",
9476 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9477 },
9478 })
9479 }
9480}
9481
Adam Langley7c803a62015-06-15 15:35:05 -07009482func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009483 defer wg.Done()
9484
9485 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009486 var err error
9487
David Benjaminba28dfc2016-11-15 17:47:21 +09009488 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009489 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9490 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009491 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009492 if err != nil {
9493 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9494 }
9495 break
9496 }
9497 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009498 } else if *repeatUntilFailure {
9499 for err == nil {
9500 statusChan <- statusMsg{test: test, started: true}
9501 err = runTest(test, shimPath, -1)
9502 }
9503 } else {
9504 statusChan <- statusMsg{test: test, started: true}
9505 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009506 }
Adam Langley95c29f32014-06-20 12:00:00 -07009507 statusChan <- statusMsg{test: test, err: err}
9508 }
9509}
9510
9511type statusMsg struct {
9512 test *testCase
9513 started bool
9514 err error
9515}
9516
David Benjamin5f237bc2015-02-11 17:14:15 -05009517func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009518 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009519
David Benjamin5f237bc2015-02-11 17:14:15 -05009520 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009521 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009522 if !*pipe {
9523 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009524 var erase string
9525 for i := 0; i < lineLen; i++ {
9526 erase += "\b \b"
9527 }
9528 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009529 }
9530
Adam Langley95c29f32014-06-20 12:00:00 -07009531 if msg.started {
9532 started++
9533 } else {
9534 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009535
9536 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009537 if msg.err == errUnimplemented {
9538 if *pipe {
9539 // Print each test instead of a status line.
9540 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9541 }
9542 unimplemented++
9543 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9544 } else {
9545 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9546 failed++
9547 testOutput.addResult(msg.test.name, "FAIL")
9548 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009549 } else {
9550 if *pipe {
9551 // Print each test instead of a status line.
9552 fmt.Printf("PASSED (%s)\n", msg.test.name)
9553 }
9554 testOutput.addResult(msg.test.name, "PASS")
9555 }
Adam Langley95c29f32014-06-20 12:00:00 -07009556 }
9557
David Benjamin5f237bc2015-02-11 17:14:15 -05009558 if !*pipe {
9559 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009560 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009561 lineLen = len(line)
9562 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009563 }
Adam Langley95c29f32014-06-20 12:00:00 -07009564 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009565
9566 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009567}
9568
9569func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009570 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009571 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009572 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009573
Adam Langley7c803a62015-06-15 15:35:05 -07009574 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009575 addCipherSuiteTests()
9576 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009577 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009578 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009579 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009580 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009581 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009582 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009583 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009584 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009585 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009586 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009587 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009588 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009589 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009590 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009591 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009592 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009593 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009594 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009595 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009596 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009597 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009598 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009599 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009600 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009601 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009602 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009603 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009604 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009605 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009606 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009607 addCertificateTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009608
9609 var wg sync.WaitGroup
9610
Adam Langley7c803a62015-06-15 15:35:05 -07009611 statusChan := make(chan statusMsg, *numWorkers)
9612 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009613 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009614
EKRf71d7ed2016-08-06 13:25:12 -07009615 if len(*shimConfigFile) != 0 {
9616 encoded, err := ioutil.ReadFile(*shimConfigFile)
9617 if err != nil {
9618 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9619 os.Exit(1)
9620 }
9621
9622 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9623 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9624 os.Exit(1)
9625 }
9626 }
9627
David Benjamin025b3d32014-07-01 19:53:04 -04009628 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009629
Adam Langley7c803a62015-06-15 15:35:05 -07009630 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009631 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009632 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009633 }
9634
David Benjamin270f0a72016-03-17 14:41:36 -04009635 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009636 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009637 matched := true
9638 if len(*testToRun) != 0 {
9639 var err error
9640 matched, err = filepath.Match(*testToRun, testCases[i].name)
9641 if err != nil {
9642 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9643 os.Exit(1)
9644 }
9645 }
9646
EKRf71d7ed2016-08-06 13:25:12 -07009647 if !*includeDisabled {
9648 for pattern := range shimConfig.DisabledTests {
9649 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9650 if err != nil {
9651 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9652 os.Exit(1)
9653 }
9654
9655 if isDisabled {
9656 matched = false
9657 break
9658 }
9659 }
9660 }
9661
David Benjamin17e12922016-07-28 18:04:43 -04009662 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009663 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009664 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +09009665
9666 // Only run one test if repeating until failure.
9667 if *repeatUntilFailure {
9668 break
9669 }
Adam Langley95c29f32014-06-20 12:00:00 -07009670 }
9671 }
David Benjamin17e12922016-07-28 18:04:43 -04009672
David Benjamin270f0a72016-03-17 14:41:36 -04009673 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009674 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009675 os.Exit(1)
9676 }
Adam Langley95c29f32014-06-20 12:00:00 -07009677
9678 close(testChan)
9679 wg.Wait()
9680 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009681 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009682
9683 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009684
9685 if *jsonOutput != "" {
9686 if err := testOutput.writeTo(*jsonOutput); err != nil {
9687 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9688 }
9689 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009690
EKR842ae6c2016-07-27 09:22:05 +02009691 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9692 os.Exit(1)
9693 }
9694
9695 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009696 os.Exit(1)
9697 }
Adam Langley95c29f32014-06-20 12:00:00 -07009698}