blob: 742fb9e05c6ca328b1b8bf577250594f65235d29 [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.")
Matt Braithwaite9c8c4182016-08-24 14:36:54 -070065 includeRC4 = flag.Bool("include-rc4", false, "If true, test RC4 ciphersuites.")
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 Benjamin33863262016-07-08 17:20:12 -070091 testCertECDSAP256
92 testCertECDSAP384
93 testCertECDSAP521
94)
95
96const (
97 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040098 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070099 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
100 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
101 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400102)
103
104const (
David Benjamina08e49d2014-08-24 01:46:07 -0400105 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400106 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700107 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
108 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
109 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400110 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400111)
112
David Benjamin7944a9f2016-07-12 22:27:01 -0400113var (
114 rsaCertificate Certificate
115 rsa1024Certificate Certificate
116 ecdsaP256Certificate Certificate
117 ecdsaP384Certificate Certificate
118 ecdsaP521Certificate Certificate
119)
David Benjamin33863262016-07-08 17:20:12 -0700120
121var testCerts = []struct {
122 id testCert
123 certFile, keyFile string
124 cert *Certificate
125}{
126 {
127 id: testCertRSA,
128 certFile: rsaCertificateFile,
129 keyFile: rsaKeyFile,
130 cert: &rsaCertificate,
131 },
132 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400133 id: testCertRSA1024,
134 certFile: rsa1024CertificateFile,
135 keyFile: rsa1024KeyFile,
136 cert: &rsa1024Certificate,
137 },
138 {
David Benjamin33863262016-07-08 17:20:12 -0700139 id: testCertECDSAP256,
140 certFile: ecdsaP256CertificateFile,
141 keyFile: ecdsaP256KeyFile,
142 cert: &ecdsaP256Certificate,
143 },
144 {
145 id: testCertECDSAP384,
146 certFile: ecdsaP384CertificateFile,
147 keyFile: ecdsaP384KeyFile,
148 cert: &ecdsaP384Certificate,
149 },
150 {
151 id: testCertECDSAP521,
152 certFile: ecdsaP521CertificateFile,
153 keyFile: ecdsaP521KeyFile,
154 cert: &ecdsaP521Certificate,
155 },
156}
157
David Benjamina08e49d2014-08-24 01:46:07 -0400158var channelIDKey *ecdsa.PrivateKey
159var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700160
David Benjamin61f95272014-11-25 01:55:35 -0500161var testOCSPResponse = []byte{1, 2, 3, 4}
162var testSCTList = []byte{5, 6, 7, 8}
163
Adam Langley95c29f32014-06-20 12:00:00 -0700164func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700165 for i := range testCerts {
166 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
167 if err != nil {
168 panic(err)
169 }
170 cert.OCSPStaple = testOCSPResponse
171 cert.SignedCertificateTimestampList = testSCTList
172 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700173 }
David Benjamina08e49d2014-08-24 01:46:07 -0400174
Adam Langley7c803a62015-06-15 15:35:05 -0700175 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400176 if err != nil {
177 panic(err)
178 }
179 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
180 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
181 panic("bad key type")
182 }
183 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
184 if err != nil {
185 panic(err)
186 }
187 if channelIDKey.Curve != elliptic.P256() {
188 panic("bad curve")
189 }
190
191 channelIDBytes = make([]byte, 64)
192 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
193 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700194}
195
David Benjamin33863262016-07-08 17:20:12 -0700196func getRunnerCertificate(t testCert) Certificate {
197 for _, cert := range testCerts {
198 if cert.id == t {
199 return *cert.cert
200 }
201 }
202 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700203}
204
David Benjamin33863262016-07-08 17:20:12 -0700205func getShimCertificate(t testCert) string {
206 for _, cert := range testCerts {
207 if cert.id == t {
208 return cert.certFile
209 }
210 }
211 panic("Unknown test certificate")
212}
213
214func getShimKey(t testCert) string {
215 for _, cert := range testCerts {
216 if cert.id == t {
217 return cert.keyFile
218 }
219 }
220 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700221}
222
David Benjamin025b3d32014-07-01 19:53:04 -0400223type testType int
224
225const (
226 clientTest testType = iota
227 serverTest
228)
229
David Benjamin6fd297b2014-08-11 18:43:38 -0400230type protocol int
231
232const (
233 tls protocol = iota
234 dtls
235)
236
David Benjaminfc7b0862014-09-06 13:21:53 -0400237const (
238 alpn = 1
239 npn = 2
240)
241
Adam Langley95c29f32014-06-20 12:00:00 -0700242type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400243 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400244 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700245 name string
246 config Config
247 shouldFail bool
248 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700249 // expectedLocalError, if not empty, contains a substring that must be
250 // found in the local error.
251 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400252 // expectedVersion, if non-zero, specifies the TLS version that must be
253 // negotiated.
254 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400255 // expectedResumeVersion, if non-zero, specifies the TLS version that
256 // must be negotiated on resumption. If zero, expectedVersion is used.
257 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400258 // expectedCipher, if non-zero, specifies the TLS cipher suite that
259 // should be negotiated.
260 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400261 // expectChannelID controls whether the connection should have
262 // negotiated a Channel ID with channelIDKey.
263 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400264 // expectedNextProto controls whether the connection should
265 // negotiate a next protocol via NPN or ALPN.
266 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400267 // expectNoNextProto, if true, means that no next protocol should be
268 // negotiated.
269 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400270 // expectedNextProtoType, if non-zero, is the expected next
271 // protocol negotiation mechanism.
272 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500273 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
274 // should be negotiated. If zero, none should be negotiated.
275 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100276 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
277 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100278 // expectedSCTList, if not nil, is the expected SCT list to be received.
279 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700280 // expectedPeerSignatureAlgorithm, if not zero, is the signature
281 // algorithm that the peer should have used in the handshake.
282 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400283 // expectedCurveID, if not zero, is the curve that the handshake should
284 // have used.
285 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700286 // messageLen is the length, in bytes, of the test message that will be
287 // sent.
288 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400289 // messageCount is the number of test messages that will be sent.
290 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400291 // certFile is the path to the certificate to use for the server.
292 certFile string
293 // keyFile is the path to the private key to use for the server.
294 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400295 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400296 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400297 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400298 // resumeRenewedSession controls whether a third connection should be
299 // tested which attempts to resume the second connection's session.
300 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700301 // expectResumeRejected, if true, specifies that the attempted
302 // resumption must be rejected by the client. This is only valid for a
303 // serverTest.
304 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400305 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500306 // resumption. Unless newSessionsOnResume is set,
307 // SessionTicketKey, ServerSessionCache, and
308 // ClientSessionCache are copied from the initial connection's
309 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400310 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500311 // newSessionsOnResume, if true, will cause resumeConfig to
312 // use a different session resumption context.
313 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400314 // noSessionCache, if true, will cause the server to run without a
315 // session cache.
316 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400317 // sendPrefix sends a prefix on the socket before actually performing a
318 // handshake.
319 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400320 // shimWritesFirst controls whether the shim sends an initial "hello"
321 // message before doing a roundtrip with the runner.
322 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400323 // shimShutsDown, if true, runs a test where the shim shuts down the
324 // connection immediately after the handshake rather than echoing
325 // messages from the runner.
326 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400327 // renegotiate indicates the number of times the connection should be
328 // renegotiated during the exchange.
329 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400330 // sendHalfHelloRequest, if true, causes the server to send half a
331 // HelloRequest when the handshake completes.
332 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700333 // renegotiateCiphers is a list of ciphersuite ids that will be
334 // switched in just before renegotiation.
335 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500336 // replayWrites, if true, configures the underlying transport
337 // to replay every write it makes in DTLS tests.
338 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500339 // damageFirstWrite, if true, configures the underlying transport to
340 // damage the final byte of the first application data write.
341 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400342 // exportKeyingMaterial, if non-zero, configures the test to exchange
343 // keying material and verify they match.
344 exportKeyingMaterial int
345 exportLabel string
346 exportContext string
347 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400348 // flags, if not empty, contains a list of command-line flags that will
349 // be passed to the shim program.
350 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700351 // testTLSUnique, if true, causes the shim to send the tls-unique value
352 // which will be compared against the expected value.
353 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400354 // sendEmptyRecords is the number of consecutive empty records to send
355 // before and after the test message.
356 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400357 // sendWarningAlerts is the number of consecutive warning alerts to send
358 // before and after the test message.
359 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400360 // sendKeyUpdates is the number of consecutive key updates to send
361 // before and after the test message.
362 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400363 // expectMessageDropped, if true, means the test message is expected to
364 // be dropped by the client rather than echoed back.
365 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700366}
367
Adam Langley7c803a62015-06-15 15:35:05 -0700368var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700369
David Benjamin9867b7d2016-03-01 23:25:48 -0500370func writeTranscript(test *testCase, isResume bool, data []byte) {
371 if len(data) == 0 {
372 return
373 }
374
375 protocol := "tls"
376 if test.protocol == dtls {
377 protocol = "dtls"
378 }
379
380 side := "client"
381 if test.testType == serverTest {
382 side = "server"
383 }
384
385 dir := path.Join(*transcriptDir, protocol, side)
386 if err := os.MkdirAll(dir, 0755); err != nil {
387 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
388 return
389 }
390
391 name := test.name
392 if isResume {
393 name += "-Resume"
394 } else {
395 name += "-Normal"
396 }
397
398 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
399 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
400 }
401}
402
David Benjamin3ed59772016-03-08 12:50:21 -0500403// A timeoutConn implements an idle timeout on each Read and Write operation.
404type timeoutConn struct {
405 net.Conn
406 timeout time.Duration
407}
408
409func (t *timeoutConn) Read(b []byte) (int, error) {
410 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Read(b)
414}
415
416func (t *timeoutConn) Write(b []byte) (int, error) {
417 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
418 return 0, err
419 }
420 return t.Conn.Write(b)
421}
422
David Benjamin8e6db492015-07-25 18:29:23 -0400423func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400424 if !test.noSessionCache {
425 if config.ClientSessionCache == nil {
426 config.ClientSessionCache = NewLRUClientSessionCache(1)
427 }
428 if config.ServerSessionCache == nil {
429 config.ServerSessionCache = NewLRUServerSessionCache(1)
430 }
431 }
432 if test.testType == clientTest {
433 if len(config.Certificates) == 0 {
434 config.Certificates = []Certificate{rsaCertificate}
435 }
436 } else {
437 // Supply a ServerName to ensure a constant session cache key,
438 // rather than falling back to net.Conn.RemoteAddr.
439 if len(config.ServerName) == 0 {
440 config.ServerName = "test"
441 }
442 }
443 if *fuzzer {
444 config.Bugs.NullAllCiphers = true
445 }
446 if *deterministic {
447 config.Rand = &deterministicRand{}
448 }
449
David Benjamin01784b42016-06-07 18:00:52 -0400450 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500451
David Benjamin6fd297b2014-08-11 18:43:38 -0400452 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500453 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
454 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500455 }
456
David Benjamin9867b7d2016-03-01 23:25:48 -0500457 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500458 local, peer := "client", "server"
459 if test.testType == clientTest {
460 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500461 }
David Benjaminebda9b32015-11-02 15:33:18 -0500462 connDebug := &recordingConn{
463 Conn: conn,
464 isDatagram: test.protocol == dtls,
465 local: local,
466 peer: peer,
467 }
468 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug {
470 defer connDebug.WriteTo(os.Stdout)
471 }
472 if len(*transcriptDir) != 0 {
473 defer func() {
474 writeTranscript(test, isResume, connDebug.Transcript())
475 }()
476 }
David Benjaminebda9b32015-11-02 15:33:18 -0500477
478 if config.Bugs.PacketAdaptor != nil {
479 config.Bugs.PacketAdaptor.debug = connDebug
480 }
481 }
482
483 if test.replayWrites {
484 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400485 }
486
David Benjamin3ed59772016-03-08 12:50:21 -0500487 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500488 if test.damageFirstWrite {
489 connDamage = newDamageAdaptor(conn)
490 conn = connDamage
491 }
492
David Benjamin6fd297b2014-08-11 18:43:38 -0400493 if test.sendPrefix != "" {
494 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
495 return err
496 }
David Benjamin98e882e2014-08-08 13:24:34 -0400497 }
498
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400500 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSServer(conn, config)
503 } else {
504 tlsConn = Server(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 } else {
507 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400508 if test.protocol == dtls {
509 tlsConn = DTLSClient(conn, config)
510 } else {
511 tlsConn = Client(conn, config)
512 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400513 }
David Benjamin30789da2015-08-29 22:56:45 -0400514 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400515
Adam Langley95c29f32014-06-20 12:00:00 -0700516 if err := tlsConn.Handshake(); err != nil {
517 return err
518 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700519
David Benjamin01fe8202014-09-24 15:21:44 -0400520 // TODO(davidben): move all per-connection expectations into a dedicated
521 // expectations struct that can be specified separately for the two
522 // legs.
523 expectedVersion := test.expectedVersion
524 if isResume && test.expectedResumeVersion != 0 {
525 expectedVersion = test.expectedResumeVersion
526 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700527 connState := tlsConn.ConnectionState()
528 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400529 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400530 }
531
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700532 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400533 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
534 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700535 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
536 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
537 }
David Benjamin90da8c82015-04-20 14:57:57 -0400538
David Benjamina08e49d2014-08-24 01:46:07 -0400539 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700540 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400541 if channelID == nil {
542 return fmt.Errorf("no channel ID negotiated")
543 }
544 if channelID.Curve != channelIDKey.Curve ||
545 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
546 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
547 return fmt.Errorf("incorrect channel ID")
548 }
549 }
550
David Benjaminae2888f2014-09-06 12:58:58 -0400551 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400553 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
554 }
555 }
556
David Benjaminc7ce9772015-10-09 19:32:41 -0400557 if test.expectNoNextProto {
558 if actual := connState.NegotiatedProtocol; actual != "" {
559 return fmt.Errorf("got unexpected next proto %s", actual)
560 }
561 }
562
David Benjaminfc7b0862014-09-06 13:21:53 -0400563 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400565 return fmt.Errorf("next proto type mismatch")
566 }
567 }
568
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700569 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500570 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
571 }
572
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100573 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300574 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100575 }
576
Paul Lietar4fac72e2015-09-09 13:44:55 +0100577 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
578 return fmt.Errorf("SCT list mismatch")
579 }
580
Nick Harper60edffd2016-06-21 15:19:24 -0700581 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
582 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400583 }
584
Steven Valdez5440fe02016-07-18 12:40:30 -0400585 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
586 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
587 }
588
David Benjaminc565ebb2015-04-03 04:06:36 -0400589 if test.exportKeyingMaterial > 0 {
590 actual := make([]byte, test.exportKeyingMaterial)
591 if _, err := io.ReadFull(tlsConn, actual); err != nil {
592 return err
593 }
594 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
595 if err != nil {
596 return err
597 }
598 if !bytes.Equal(actual, expected) {
599 return fmt.Errorf("keying material mismatch")
600 }
601 }
602
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700603 if test.testTLSUnique {
604 var peersValue [12]byte
605 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
606 return err
607 }
608 expected := tlsConn.ConnectionState().TLSUnique
609 if !bytes.Equal(peersValue[:], expected) {
610 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
611 }
612 }
613
David Benjamine58c4f52014-08-24 03:47:07 -0400614 if test.shimWritesFirst {
615 var buf [5]byte
616 _, err := io.ReadFull(tlsConn, buf[:])
617 if err != nil {
618 return err
619 }
620 if string(buf[:]) != "hello" {
621 return fmt.Errorf("bad initial message")
622 }
623 }
624
Steven Valdez32635b82016-08-16 11:25:03 -0400625 for i := 0; i < test.sendKeyUpdates; i++ {
626 tlsConn.SendKeyUpdate()
627 }
628
David Benjamina8ebe222015-06-06 03:04:39 -0400629 for i := 0; i < test.sendEmptyRecords; i++ {
630 tlsConn.Write(nil)
631 }
632
David Benjamin24f346d2015-06-06 03:28:08 -0400633 for i := 0; i < test.sendWarningAlerts; i++ {
634 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
635 }
636
David Benjamin47921102016-07-28 11:29:18 -0400637 if test.sendHalfHelloRequest {
638 tlsConn.SendHalfHelloRequest()
639 }
640
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 if test.renegotiateCiphers != nil {
643 config.CipherSuites = test.renegotiateCiphers
644 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400645 for i := 0; i < test.renegotiate; i++ {
646 if err := tlsConn.Renegotiate(); err != nil {
647 return err
648 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700649 }
650 } else if test.renegotiateCiphers != nil {
651 panic("renegotiateCiphers without renegotiate")
652 }
653
David Benjamin5fa3eba2015-01-22 16:35:40 -0500654 if test.damageFirstWrite {
655 connDamage.setDamage(true)
656 tlsConn.Write([]byte("DAMAGED WRITE"))
657 connDamage.setDamage(false)
658 }
659
David Benjamin8e6db492015-07-25 18:29:23 -0400660 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400662 if test.protocol == dtls {
663 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
664 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700665 // Read until EOF.
666 _, err := io.Copy(ioutil.Discard, tlsConn)
667 return err
668 }
David Benjamin4417d052015-04-05 04:17:25 -0400669 if messageLen == 0 {
670 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700671 }
Adam Langley95c29f32014-06-20 12:00:00 -0700672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 messageCount := test.messageCount
674 if messageCount == 0 {
675 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400676 }
677
David Benjamin8e6db492015-07-25 18:29:23 -0400678 for j := 0; j < messageCount; j++ {
679 testMessage := make([]byte, messageLen)
680 for i := range testMessage {
681 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400682 }
David Benjamin8e6db492015-07-25 18:29:23 -0400683 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700684
Steven Valdez32635b82016-08-16 11:25:03 -0400685 for i := 0; i < test.sendKeyUpdates; i++ {
686 tlsConn.SendKeyUpdate()
687 }
688
David Benjamin8e6db492015-07-25 18:29:23 -0400689 for i := 0; i < test.sendEmptyRecords; i++ {
690 tlsConn.Write(nil)
691 }
692
693 for i := 0; i < test.sendWarningAlerts; i++ {
694 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
695 }
696
David Benjamin4f75aaf2015-09-01 16:53:10 -0400697 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400698 // The shim will not respond.
699 continue
700 }
701
David Benjamin8e6db492015-07-25 18:29:23 -0400702 buf := make([]byte, len(testMessage))
703 if test.protocol == dtls {
704 bufTmp := make([]byte, len(buf)+1)
705 n, err := tlsConn.Read(bufTmp)
706 if err != nil {
707 return err
708 }
709 if n != len(buf) {
710 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
711 }
712 copy(buf, bufTmp)
713 } else {
714 _, err := io.ReadFull(tlsConn, buf)
715 if err != nil {
716 return err
717 }
718 }
719
720 for i, v := range buf {
721 if v != testMessage[i]^0xff {
722 return fmt.Errorf("bad reply contents at byte %d", i)
723 }
Adam Langley95c29f32014-06-20 12:00:00 -0700724 }
725 }
726
727 return nil
728}
729
David Benjamin325b5c32014-07-01 19:40:31 -0400730func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
731 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700732 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400733 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700734 }
David Benjamin325b5c32014-07-01 19:40:31 -0400735 valgrindArgs = append(valgrindArgs, path)
736 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700737
David Benjamin325b5c32014-07-01 19:40:31 -0400738 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700739}
740
David Benjamin325b5c32014-07-01 19:40:31 -0400741func gdbOf(path string, args ...string) *exec.Cmd {
742 xtermArgs := []string{"-e", "gdb", "--args"}
743 xtermArgs = append(xtermArgs, path)
744 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700745
David Benjamin325b5c32014-07-01 19:40:31 -0400746 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700747}
748
David Benjamind16bf342015-12-18 00:53:12 -0500749func lldbOf(path string, args ...string) *exec.Cmd {
750 xtermArgs := []string{"-e", "lldb", "--"}
751 xtermArgs = append(xtermArgs, path)
752 xtermArgs = append(xtermArgs, args...)
753
754 return exec.Command("xterm", xtermArgs...)
755}
756
EKR842ae6c2016-07-27 09:22:05 +0200757var (
758 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
759 errUnimplemented = errors.New("child process does not implement needed flags")
760)
Adam Langley69a01602014-11-17 17:26:55 -0800761
David Benjamin87c8a642015-02-21 01:54:29 -0500762// accept accepts a connection from listener, unless waitChan signals a process
763// exit first.
764func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
765 type connOrError struct {
766 conn net.Conn
767 err error
768 }
769 connChan := make(chan connOrError, 1)
770 go func() {
771 conn, err := listener.Accept()
772 connChan <- connOrError{conn, err}
773 close(connChan)
774 }()
775 select {
776 case result := <-connChan:
777 return result.conn, result.err
778 case childErr := <-waitChan:
779 waitChan <- childErr
780 return nil, fmt.Errorf("child exited early: %s", childErr)
781 }
782}
783
EKRf71d7ed2016-08-06 13:25:12 -0700784func translateExpectedError(errorStr string) string {
785 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
786 return translated
787 }
788
789 if *looseErrors {
790 return ""
791 }
792
793 return errorStr
794}
795
Adam Langley7c803a62015-06-15 15:35:05 -0700796func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700797 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
798 panic("Error expected without shouldFail in " + test.name)
799 }
800
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700801 if test.expectResumeRejected && !test.resumeSession {
802 panic("expectResumeRejected without resumeSession in " + test.name)
803 }
804
David Benjamin87c8a642015-02-21 01:54:29 -0500805 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
806 if err != nil {
807 panic(err)
808 }
809 defer func() {
810 if listener != nil {
811 listener.Close()
812 }
813 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700814
David Benjamin87c8a642015-02-21 01:54:29 -0500815 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400816 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400817 flags = append(flags, "-server")
818
David Benjamin025b3d32014-07-01 19:53:04 -0400819 flags = append(flags, "-key-file")
820 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825
826 flags = append(flags, "-cert-file")
827 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700828 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400829 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700830 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400831 }
832 }
David Benjamin5a593af2014-08-11 19:51:50 -0400833
David Benjamin6fd297b2014-08-11 18:43:38 -0400834 if test.protocol == dtls {
835 flags = append(flags, "-dtls")
836 }
837
David Benjamin46662482016-08-17 00:51:00 -0400838 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400839 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400840 resumeCount++
841 if test.resumeRenewedSession {
842 resumeCount++
843 }
844 }
845
846 if resumeCount > 0 {
847 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400848 }
849
David Benjamine58c4f52014-08-24 03:47:07 -0400850 if test.shimWritesFirst {
851 flags = append(flags, "-shim-writes-first")
852 }
853
David Benjamin30789da2015-08-29 22:56:45 -0400854 if test.shimShutsDown {
855 flags = append(flags, "-shim-shuts-down")
856 }
857
David Benjaminc565ebb2015-04-03 04:06:36 -0400858 if test.exportKeyingMaterial > 0 {
859 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
860 flags = append(flags, "-export-label", test.exportLabel)
861 flags = append(flags, "-export-context", test.exportContext)
862 if test.useExportContext {
863 flags = append(flags, "-use-export-context")
864 }
865 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700866 if test.expectResumeRejected {
867 flags = append(flags, "-expect-session-miss")
868 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400869
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700870 if test.testTLSUnique {
871 flags = append(flags, "-tls-unique")
872 }
873
David Benjamin025b3d32014-07-01 19:53:04 -0400874 flags = append(flags, test.flags...)
875
876 var shim *exec.Cmd
877 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700878 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700879 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500881 } else if *useLLDB {
882 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400883 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700884 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400885 }
David Benjamin025b3d32014-07-01 19:53:04 -0400886 shim.Stdin = os.Stdin
887 var stdoutBuf, stderrBuf bytes.Buffer
888 shim.Stdout = &stdoutBuf
889 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800890 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500891 shim.Env = os.Environ()
892 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800893 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400894 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800895 }
896 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
897 }
David Benjamin025b3d32014-07-01 19:53:04 -0400898
899 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700900 panic(err)
901 }
David Benjamin87c8a642015-02-21 01:54:29 -0500902 waitChan := make(chan error, 1)
903 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700904
905 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800940 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200941 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
942 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800943 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200944 case 89:
945 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjaminc565ebb2015-04-03 04:06:36 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjaminff3a1492016-03-02 10:12:06 -0500994 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
998 return nil
999}
1000
1001var tlsVersions = []struct {
1002 name string
1003 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001004 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001005 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001006}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001007 {"SSL3", VersionSSL30, "-no-ssl3", false},
1008 {"TLS1", VersionTLS10, "-no-tls1", true},
1009 {"TLS11", VersionTLS11, "-no-tls11", false},
1010 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001011 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001012}
1013
1014var testCipherSuites = []struct {
1015 name string
1016 id uint16
1017}{
1018 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001019 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001020 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001021 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001022 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001023 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001024 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001025 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1026 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001027 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001028 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1029 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001031 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1032 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1034 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001036 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001038 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001040 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001046 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001047 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1048 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1049 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1050 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001051 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1052 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001053 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1054 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001055 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001056 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1057 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001058 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001059}
1060
David Benjamin8b8c0062014-11-23 02:47:52 -05001061func hasComponent(suiteName, component string) bool {
1062 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1063}
1064
David Benjaminf7768e42014-08-31 02:06:47 -04001065func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001066 return hasComponent(suiteName, "GCM") ||
1067 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001068 hasComponent(suiteName, "SHA384") ||
1069 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001070}
1071
Nick Harper1fd39d82016-06-14 18:14:35 -07001072func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001073 // Only AEADs.
1074 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1075 return false
1076 }
1077 // No old CHACHA20_POLY1305.
1078 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1079 return false
1080 }
1081 // Must have ECDHE.
1082 // TODO(davidben,svaldez): Add pure PSK support.
1083 if !hasComponent(suiteName, "ECDHE") {
1084 return false
1085 }
1086 // TODO(davidben,svaldez): Add PSK support.
1087 if hasComponent(suiteName, "PSK") {
1088 return false
1089 }
1090 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001091}
1092
David Benjamin8b8c0062014-11-23 02:47:52 -05001093func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001094 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001095}
1096
Adam Langleya7997f12015-05-14 17:38:50 -07001097func bigFromHex(hex string) *big.Int {
1098 ret, ok := new(big.Int).SetString(hex, 16)
1099 if !ok {
1100 panic("failed to parse hex number 0x" + hex)
1101 }
1102 return ret
1103}
1104
Adam Langley7c803a62015-06-15 15:35:05 -07001105func addBasicTests() {
1106 basicTests := []testCase{
1107 {
Adam Langley7c803a62015-06-15 15:35:05 -07001108 name: "NoFallbackSCSV",
1109 config: Config{
1110 Bugs: ProtocolBugs{
1111 FailIfNotFallbackSCSV: true,
1112 },
1113 },
1114 shouldFail: true,
1115 expectedLocalError: "no fallback SCSV found",
1116 },
1117 {
1118 name: "SendFallbackSCSV",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 FailIfNotFallbackSCSV: true,
1122 },
1123 },
1124 flags: []string{"-fallback-scsv"},
1125 },
1126 {
1127 name: "ClientCertificateTypes",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 ClientAuth: RequestClientCert,
1131 ClientCertificateTypes: []byte{
1132 CertTypeDSSSign,
1133 CertTypeRSASign,
1134 CertTypeECDSASign,
1135 },
1136 },
1137 flags: []string{
1138 "-expect-certificate-types",
1139 base64.StdEncoding.EncodeToString([]byte{
1140 CertTypeDSSSign,
1141 CertTypeRSASign,
1142 CertTypeECDSASign,
1143 }),
1144 },
1145 },
1146 {
Adam Langley7c803a62015-06-15 15:35:05 -07001147 name: "UnauthenticatedECDH",
1148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001149 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1151 Bugs: ProtocolBugs{
1152 UnauthenticatedECDH: true,
1153 },
1154 },
1155 shouldFail: true,
1156 expectedError: ":UNEXPECTED_MESSAGE:",
1157 },
1158 {
1159 name: "SkipCertificateStatus",
1160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1163 Bugs: ProtocolBugs{
1164 SkipCertificateStatus: true,
1165 },
1166 },
1167 flags: []string{
1168 "-enable-ocsp-stapling",
1169 },
1170 },
1171 {
1172 name: "SkipServerKeyExchange",
1173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1176 Bugs: ProtocolBugs{
1177 SkipServerKeyExchange: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedError: ":UNEXPECTED_MESSAGE:",
1182 },
1183 {
Adam Langley7c803a62015-06-15 15:35:05 -07001184 testType: serverTest,
1185 name: "Alert",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "Alert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendSpuriousAlert: alertRecordOverflow,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1205 },
1206 {
1207 testType: serverTest,
1208 name: "FragmentAlert",
1209 config: Config{
1210 Bugs: ProtocolBugs{
1211 FragmentAlert: true,
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":BAD_ALERT:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "FragmentAlert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 FragmentAlert: true,
1225 SendSpuriousAlert: alertRecordOverflow,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":BAD_ALERT:",
1230 },
1231 {
1232 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001233 name: "DoubleAlert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 DoubleAlert: true,
1237 SendSpuriousAlert: alertRecordOverflow,
1238 },
1239 },
1240 shouldFail: true,
1241 expectedError: ":BAD_ALERT:",
1242 },
1243 {
1244 protocol: dtls,
1245 testType: serverTest,
1246 name: "DoubleAlert-DTLS",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 DoubleAlert: true,
1250 SendSpuriousAlert: alertRecordOverflow,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":BAD_ALERT:",
1255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "SkipNewSessionTicket",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 Bugs: ProtocolBugs{
1261 SkipNewSessionTicket: true,
1262 },
1263 },
1264 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001265 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001266 },
1267 {
1268 testType: serverTest,
1269 name: "FallbackSCSV",
1270 config: Config{
1271 MaxVersion: VersionTLS11,
1272 Bugs: ProtocolBugs{
1273 SendFallbackSCSV: true,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":INAPPROPRIATE_FALLBACK:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "FallbackSCSV-VersionMatch",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 },
1288 {
1289 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 name: "FallbackSCSV-VersionMatch-TLS12",
1291 config: Config{
1292 MaxVersion: VersionTLS12,
1293 Bugs: ProtocolBugs{
1294 SendFallbackSCSV: true,
1295 },
1296 },
1297 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1298 },
1299 {
1300 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001308 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 testType: serverTest,
1312 name: "HttpGET",
1313 sendPrefix: "GET / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpPOST",
1320 sendPrefix: "POST / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpHEAD",
1327 sendPrefix: "HEAD / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpPUT",
1334 sendPrefix: "PUT / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpCONNECT",
1341 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTPS_PROXY_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "Garbage",
1348 sendPrefix: "blah",
1349 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001350 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 name: "RSAEphemeralKey",
1354 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001355 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1357 Bugs: ProtocolBugs{
1358 RSAEphemeralKey: true,
1359 },
1360 },
1361 shouldFail: true,
1362 expectedError: ":UNEXPECTED_MESSAGE:",
1363 },
1364 {
1365 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001366 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
1371 protocol: dtls,
1372 name: "DisableEverything-DTLS",
1373 flags: []string{"-no-tls12", "-no-tls1"},
1374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
Adam Langley7c803a62015-06-15 15:35:05 -07001378 protocol: dtls,
1379 testType: serverTest,
1380 name: "MTU",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 MaxPacketLength: 256,
1384 },
1385 },
1386 flags: []string{"-mtu", "256"},
1387 },
1388 {
1389 protocol: dtls,
1390 testType: serverTest,
1391 name: "MTUExceeded",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 MaxPacketLength: 255,
1395 },
1396 },
1397 flags: []string{"-mtu", "256"},
1398 shouldFail: true,
1399 expectedLocalError: "dtls: exceeded maximum packet length",
1400 },
1401 {
1402 name: "CertMismatchRSA",
1403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001406 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 Bugs: ProtocolBugs{
1408 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1413 },
1414 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001415 name: "CertMismatchRSA-TLS13",
1416 config: Config{
1417 MaxVersion: VersionTLS13,
1418 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1419 Certificates: []Certificate{ecdsaP256Certificate},
1420 Bugs: ProtocolBugs{
1421 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1422 },
1423 },
1424 shouldFail: true,
1425 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1426 },
1427 {
Adam Langley7c803a62015-06-15 15:35:05 -07001428 name: "CertMismatchECDSA",
1429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001432 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001433 Bugs: ProtocolBugs{
1434 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1439 },
1440 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001441 name: "CertMismatchECDSA-TLS13",
1442 config: Config{
1443 MaxVersion: VersionTLS13,
1444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Certificates: []Certificate{rsaCertificate},
1446 Bugs: ProtocolBugs{
1447 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1452 },
1453 {
Adam Langley7c803a62015-06-15 15:35:05 -07001454 name: "EmptyCertificateList",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 EmptyCertificateList: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":DECODE_ERROR:",
1464 },
1465 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 name: "EmptyCertificateList-TLS13",
1467 config: Config{
1468 MaxVersion: VersionTLS13,
1469 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1470 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:",
1710 expectedLocalError: "remote error: access denied",
1711 },
1712 {
Adam Langley7c803a62015-06-15 15:35:05 -07001713 protocol: dtls,
1714 name: "FragmentMessageTypeMismatch-DTLS",
1715 config: Config{
1716 Bugs: ProtocolBugs{
1717 MaxHandshakeRecordLength: 2,
1718 FragmentMessageTypeMismatch: true,
1719 },
1720 },
1721 shouldFail: true,
1722 expectedError: ":FRAGMENT_MISMATCH:",
1723 },
1724 {
1725 protocol: dtls,
1726 name: "FragmentMessageLengthMismatch-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 MaxHandshakeRecordLength: 2,
1730 FragmentMessageLengthMismatch: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":FRAGMENT_MISMATCH:",
1735 },
1736 {
1737 protocol: dtls,
1738 name: "SplitFragments-Header-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 SplitFragments: 2,
1742 },
1743 },
1744 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001745 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001746 },
1747 {
1748 protocol: dtls,
1749 name: "SplitFragments-Boundary-DTLS",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 SplitFragments: dtlsRecordHeaderLen,
1753 },
1754 },
1755 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001756 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001757 },
1758 {
1759 protocol: dtls,
1760 name: "SplitFragments-Body-DTLS",
1761 config: Config{
1762 Bugs: ProtocolBugs{
1763 SplitFragments: dtlsRecordHeaderLen + 1,
1764 },
1765 },
1766 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001767 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 {
1770 protocol: dtls,
1771 name: "SendEmptyFragments-DTLS",
1772 config: Config{
1773 Bugs: ProtocolBugs{
1774 SendEmptyFragments: true,
1775 },
1776 },
1777 },
1778 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001779 name: "BadFinished-Client",
1780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001781 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 Bugs: ProtocolBugs{
1783 BadFinished: true,
1784 },
1785 },
1786 shouldFail: true,
1787 expectedError: ":DIGEST_CHECK_FAILED:",
1788 },
1789 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001790 name: "BadFinished-Client-TLS13",
1791 config: Config{
1792 MaxVersion: VersionTLS13,
1793 Bugs: ProtocolBugs{
1794 BadFinished: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":DIGEST_CHECK_FAILED:",
1799 },
1800 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001801 testType: serverTest,
1802 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 BadFinished: true,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":DIGEST_CHECK_FAILED:",
1811 },
1812 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001813 testType: serverTest,
1814 name: "BadFinished-Server-TLS13",
1815 config: Config{
1816 MaxVersion: VersionTLS13,
1817 Bugs: ProtocolBugs{
1818 BadFinished: true,
1819 },
1820 },
1821 shouldFail: true,
1822 expectedError: ":DIGEST_CHECK_FAILED:",
1823 },
1824 {
Adam Langley7c803a62015-06-15 15:35:05 -07001825 name: "FalseStart-BadFinished",
1826 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001827 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1829 NextProtos: []string{"foo"},
1830 Bugs: ProtocolBugs{
1831 BadFinished: true,
1832 ExpectFalseStart: true,
1833 },
1834 },
1835 flags: []string{
1836 "-false-start",
1837 "-handshake-never-done",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
1845 name: "NoFalseStart-NoALPN",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1849 Bugs: ProtocolBugs{
1850 ExpectFalseStart: true,
1851 AlertBeforeFalseStartTest: alertAccessDenied,
1852 },
1853 },
1854 flags: []string{
1855 "-false-start",
1856 },
1857 shimWritesFirst: true,
1858 shouldFail: true,
1859 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1860 expectedLocalError: "tls: peer did not false start: EOF",
1861 },
1862 {
1863 name: "NoFalseStart-NoAEAD",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 ExpectFalseStart: true,
1870 AlertBeforeFalseStartTest: alertAccessDenied,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-advertise-alpn", "\x03foo",
1876 },
1877 shimWritesFirst: true,
1878 shouldFail: true,
1879 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1880 expectedLocalError: "tls: peer did not false start: EOF",
1881 },
1882 {
1883 name: "NoFalseStart-RSA",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1887 NextProtos: []string{"foo"},
1888 Bugs: ProtocolBugs{
1889 ExpectFalseStart: true,
1890 AlertBeforeFalseStartTest: alertAccessDenied,
1891 },
1892 },
1893 flags: []string{
1894 "-false-start",
1895 "-advertise-alpn", "\x03foo",
1896 },
1897 shimWritesFirst: true,
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1900 expectedLocalError: "tls: peer did not false start: EOF",
1901 },
1902 {
1903 name: "NoFalseStart-DHE_RSA",
1904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001905 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001906 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1907 NextProtos: []string{"foo"},
1908 Bugs: ProtocolBugs{
1909 ExpectFalseStart: true,
1910 AlertBeforeFalseStartTest: alertAccessDenied,
1911 },
1912 },
1913 flags: []string{
1914 "-false-start",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1920 expectedLocalError: "tls: peer did not false start: EOF",
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 protocol: dtls,
1924 name: "SendSplitAlert-Sync",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 SendSplitAlert: true,
1928 },
1929 },
1930 },
1931 {
1932 protocol: dtls,
1933 name: "SendSplitAlert-Async",
1934 config: Config{
1935 Bugs: ProtocolBugs{
1936 SendSplitAlert: true,
1937 },
1938 },
1939 flags: []string{"-async"},
1940 },
1941 {
1942 protocol: dtls,
1943 name: "PackDTLSHandshake",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 MaxHandshakeRecordLength: 2,
1947 PackHandshakeFragments: 20,
1948 PackHandshakeRecords: 200,
1949 },
1950 },
1951 },
1952 {
Adam Langley7c803a62015-06-15 15:35:05 -07001953 name: "SendEmptyRecords-Pass",
1954 sendEmptyRecords: 32,
1955 },
1956 {
1957 name: "SendEmptyRecords",
1958 sendEmptyRecords: 33,
1959 shouldFail: true,
1960 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1961 },
1962 {
1963 name: "SendEmptyRecords-Async",
1964 sendEmptyRecords: 33,
1965 flags: []string{"-async"},
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
David Benjamine8e84b92016-08-03 15:39:47 -04001970 name: "SendWarningAlerts-Pass",
1971 config: Config{
1972 MaxVersion: VersionTLS12,
1973 },
Adam Langley7c803a62015-06-15 15:35:05 -07001974 sendWarningAlerts: 4,
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 protocol: dtls,
1978 name: "SendWarningAlerts-DTLS-Pass",
1979 config: Config{
1980 MaxVersion: VersionTLS12,
1981 },
Adam Langley7c803a62015-06-15 15:35:05 -07001982 sendWarningAlerts: 4,
1983 },
1984 {
David Benjamine8e84b92016-08-03 15:39:47 -04001985 name: "SendWarningAlerts-TLS13",
1986 config: Config{
1987 MaxVersion: VersionTLS13,
1988 },
1989 sendWarningAlerts: 4,
1990 shouldFail: true,
1991 expectedError: ":BAD_ALERT:",
1992 expectedLocalError: "remote error: error decoding message",
1993 },
1994 {
1995 name: "SendWarningAlerts",
1996 config: Config{
1997 MaxVersion: VersionTLS12,
1998 },
Adam Langley7c803a62015-06-15 15:35:05 -07001999 sendWarningAlerts: 5,
2000 shouldFail: true,
2001 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2002 },
2003 {
David Benjamine8e84b92016-08-03 15:39:47 -04002004 name: "SendWarningAlerts-Async",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
Adam Langley7c803a62015-06-15 15:35:05 -07002008 sendWarningAlerts: 5,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2012 },
David Benjaminba4594a2015-06-18 18:36:15 -04002013 {
Steven Valdez32635b82016-08-16 11:25:03 -04002014 name: "SendKeyUpdates",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 },
2018 sendKeyUpdates: 33,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_KEY_UPDATES:",
2021 },
2022 {
David Benjaminba4594a2015-06-18 18:36:15 -04002023 name: "EmptySessionID",
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002026 SessionTicketsDisabled: true,
2027 },
2028 noSessionCache: true,
2029 flags: []string{"-expect-no-session"},
2030 },
David Benjamin30789da2015-08-29 22:56:45 -04002031 {
2032 name: "Unclean-Shutdown",
2033 config: Config{
2034 Bugs: ProtocolBugs{
2035 NoCloseNotify: true,
2036 ExpectCloseNotify: true,
2037 },
2038 },
2039 shimShutsDown: true,
2040 flags: []string{"-check-close-notify"},
2041 shouldFail: true,
2042 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2043 },
2044 {
2045 name: "Unclean-Shutdown-Ignored",
2046 config: Config{
2047 Bugs: ProtocolBugs{
2048 NoCloseNotify: true,
2049 },
2050 },
2051 shimShutsDown: true,
2052 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002053 {
David Benjaminfa214e42016-05-10 17:03:10 -04002054 name: "Unclean-Shutdown-Alert",
2055 config: Config{
2056 Bugs: ProtocolBugs{
2057 SendAlertOnShutdown: alertDecompressionFailure,
2058 ExpectCloseNotify: true,
2059 },
2060 },
2061 shimShutsDown: true,
2062 flags: []string{"-check-close-notify"},
2063 shouldFail: true,
2064 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2065 },
2066 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002067 name: "LargePlaintext",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 SendLargeRecords: true,
2071 },
2072 },
2073 messageLen: maxPlaintext + 1,
2074 shouldFail: true,
2075 expectedError: ":DATA_LENGTH_TOO_LONG:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "LargePlaintext-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SendLargeRecords: true,
2083 },
2084 },
2085 messageLen: maxPlaintext + 1,
2086 shouldFail: true,
2087 expectedError: ":DATA_LENGTH_TOO_LONG:",
2088 },
2089 {
2090 name: "LargeCiphertext",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SendLargeRecords: true,
2094 },
2095 },
2096 messageLen: maxPlaintext * 2,
2097 shouldFail: true,
2098 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2099 },
2100 {
2101 protocol: dtls,
2102 name: "LargeCiphertext-DTLS",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendLargeRecords: true,
2106 },
2107 },
2108 messageLen: maxPlaintext * 2,
2109 // Unlike the other four cases, DTLS drops records which
2110 // are invalid before authentication, so the connection
2111 // does not fail.
2112 expectMessageDropped: true,
2113 },
David Benjamindd6fed92015-10-23 17:41:12 -04002114 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 // In TLS 1.2 and below, empty NewSessionTicket messages
2116 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002117 name: "SendEmptySessionTicket",
2118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002120 Bugs: ProtocolBugs{
2121 SendEmptySessionTicket: true,
2122 FailIfSessionOffered: true,
2123 },
2124 },
David Benjamin46662482016-08-17 00:51:00 -04002125 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002126 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002127 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002128 name: "BadHelloRequest-1",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002141 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002142 },
2143 {
2144 name: "BadHelloRequest-2",
2145 renegotiate: 1,
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002148 Bugs: ProtocolBugs{
2149 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2150 },
2151 },
2152 flags: []string{
2153 "-renegotiate-freely",
2154 "-expect-total-renegotiations", "1",
2155 },
2156 shouldFail: true,
2157 expectedError: ":BAD_HELLO_REQUEST:",
2158 },
David Benjaminef1b0092015-11-21 14:05:44 -05002159 {
2160 testType: serverTest,
2161 name: "SupportTicketsWithSessionID",
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002164 SessionTicketsDisabled: true,
2165 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002166 resumeConfig: &Config{
2167 MaxVersion: VersionTLS12,
2168 },
David Benjaminef1b0092015-11-21 14:05:44 -05002169 resumeSession: true,
2170 },
David Benjamin02edcd02016-07-27 17:40:37 -04002171 {
2172 protocol: dtls,
2173 name: "DTLS-SendExtraFinished",
2174 config: Config{
2175 Bugs: ProtocolBugs{
2176 SendExtraFinished: true,
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":UNEXPECTED_RECORD:",
2181 },
2182 {
2183 protocol: dtls,
2184 name: "DTLS-SendExtraFinished-Reordered",
2185 config: Config{
2186 Bugs: ProtocolBugs{
2187 MaxHandshakeRecordLength: 2,
2188 ReorderHandshakeFragments: true,
2189 SendExtraFinished: true,
2190 },
2191 },
2192 shouldFail: true,
2193 expectedError: ":UNEXPECTED_RECORD:",
2194 },
David Benjamine97fb482016-07-29 09:23:07 -04002195 {
2196 testType: serverTest,
2197 name: "V2ClientHello-EmptyRecordPrefix",
2198 config: Config{
2199 // Choose a cipher suite that does not involve
2200 // elliptic curves, so no extensions are
2201 // involved.
2202 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002203 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002204 Bugs: ProtocolBugs{
2205 SendV2ClientHello: true,
2206 },
2207 },
2208 sendPrefix: string([]byte{
2209 byte(recordTypeHandshake),
2210 3, 1, // version
2211 0, 0, // length
2212 }),
2213 // A no-op empty record may not be sent before V2ClientHello.
2214 shouldFail: true,
2215 expectedError: ":WRONG_VERSION_NUMBER:",
2216 },
2217 {
2218 testType: serverTest,
2219 name: "V2ClientHello-WarningAlertPrefix",
2220 config: Config{
2221 // Choose a cipher suite that does not involve
2222 // elliptic curves, so no extensions are
2223 // involved.
2224 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002225 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002226 Bugs: ProtocolBugs{
2227 SendV2ClientHello: true,
2228 },
2229 },
2230 sendPrefix: string([]byte{
2231 byte(recordTypeAlert),
2232 3, 1, // version
2233 0, 2, // length
2234 alertLevelWarning, byte(alertDecompressionFailure),
2235 }),
2236 // A no-op warning alert may not be sent before V2ClientHello.
2237 shouldFail: true,
2238 expectedError: ":WRONG_VERSION_NUMBER:",
2239 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002240 {
2241 testType: clientTest,
2242 name: "KeyUpdate",
2243 config: Config{
2244 MaxVersion: VersionTLS13,
2245 Bugs: ProtocolBugs{
2246 SendKeyUpdateBeforeEveryAppDataRecord: true,
2247 },
2248 },
2249 },
Adam Langley7c803a62015-06-15 15:35:05 -07002250 }
Adam Langley7c803a62015-06-15 15:35:05 -07002251 testCases = append(testCases, basicTests...)
2252}
2253
Adam Langley95c29f32014-06-20 12:00:00 -07002254func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002255 const bogusCipher = 0xfe00
2256
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002257 if *includeRC4 {
2258 testCipherSuites = append(testCipherSuites, []struct {
2259 name string
2260 id uint16
2261 }{
2262 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
2263 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2264 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
2265 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
2266 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
2267 }...)
2268 }
2269
Adam Langley95c29f32014-06-20 12:00:00 -07002270 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002271 const psk = "12345"
2272 const pskIdentity = "luggage combo"
2273
Adam Langley95c29f32014-06-20 12:00:00 -07002274 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002275 var certFile string
2276 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002277 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002278 cert = ecdsaP256Certificate
2279 certFile = ecdsaP256CertificateFile
2280 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002281 } else {
David Benjamin33863262016-07-08 17:20:12 -07002282 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002283 certFile = rsaCertificateFile
2284 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002285 }
2286
David Benjamin48cae082014-10-27 01:06:24 -04002287 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002288 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002289 flags = append(flags,
2290 "-psk", psk,
2291 "-psk-identity", pskIdentity)
2292 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002293 if hasComponent(suite.name, "NULL") {
2294 // NULL ciphers must be explicitly enabled.
2295 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2296 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002297 if hasComponent(suite.name, "CECPQ1") {
2298 // CECPQ1 ciphers must be explicitly enabled.
2299 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2300 }
David Benjamin881f1962016-08-10 18:29:12 -04002301 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2302 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2303 // for now.
2304 flags = append(flags, "-cipher", suite.name)
2305 }
David Benjamin48cae082014-10-27 01:06:24 -04002306
Adam Langley95c29f32014-06-20 12:00:00 -07002307 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002308 for _, protocol := range []protocol{tls, dtls} {
2309 var prefix string
2310 if protocol == dtls {
2311 if !ver.hasDTLS {
2312 continue
2313 }
2314 prefix = "D"
2315 }
Adam Langley95c29f32014-06-20 12:00:00 -07002316
David Benjamin0407e762016-06-17 16:41:18 -04002317 var shouldServerFail, shouldClientFail bool
2318 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2319 // BoringSSL clients accept ECDHE on SSLv3, but
2320 // a BoringSSL server will never select it
2321 // because the extension is missing.
2322 shouldServerFail = true
2323 }
2324 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2325 shouldClientFail = true
2326 shouldServerFail = true
2327 }
David Benjamin54c217c2016-07-13 12:35:25 -04002328 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002329 shouldClientFail = true
2330 shouldServerFail = true
2331 }
David Benjamin0407e762016-06-17 16:41:18 -04002332 if !isDTLSCipher(suite.name) && protocol == dtls {
2333 shouldClientFail = true
2334 shouldServerFail = true
2335 }
David Benjamin4298d772015-12-19 00:18:25 -05002336
David Benjamin0407e762016-06-17 16:41:18 -04002337 var expectedServerError, expectedClientError string
2338 if shouldServerFail {
2339 expectedServerError = ":NO_SHARED_CIPHER:"
2340 }
2341 if shouldClientFail {
2342 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2343 }
David Benjamin025b3d32014-07-01 19:53:04 -04002344
David Benjamin6fd297b2014-08-11 18:43:38 -04002345 testCases = append(testCases, testCase{
2346 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002347 protocol: protocol,
2348
2349 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002350 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002351 MinVersion: ver.version,
2352 MaxVersion: ver.version,
2353 CipherSuites: []uint16{suite.id},
2354 Certificates: []Certificate{cert},
2355 PreSharedKey: []byte(psk),
2356 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002357 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002358 EnableAllCiphers: shouldServerFail,
2359 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002360 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002361 },
2362 certFile: certFile,
2363 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002364 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002365 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002366 shouldFail: shouldServerFail,
2367 expectedError: expectedServerError,
2368 })
2369
2370 testCases = append(testCases, testCase{
2371 testType: clientTest,
2372 protocol: protocol,
2373 name: prefix + ver.name + "-" + suite.name + "-client",
2374 config: Config{
2375 MinVersion: ver.version,
2376 MaxVersion: ver.version,
2377 CipherSuites: []uint16{suite.id},
2378 Certificates: []Certificate{cert},
2379 PreSharedKey: []byte(psk),
2380 PreSharedKeyIdentity: pskIdentity,
2381 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002382 EnableAllCiphers: shouldClientFail,
2383 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002384 },
2385 },
2386 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002387 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002388 shouldFail: shouldClientFail,
2389 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002390 })
David Benjamin2c99d282015-09-01 10:23:00 -04002391
Nick Harper1fd39d82016-06-14 18:14:35 -07002392 if !shouldClientFail {
2393 // Ensure the maximum record size is accepted.
2394 testCases = append(testCases, testCase{
2395 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2396 config: Config{
2397 MinVersion: ver.version,
2398 MaxVersion: ver.version,
2399 CipherSuites: []uint16{suite.id},
2400 Certificates: []Certificate{cert},
2401 PreSharedKey: []byte(psk),
2402 PreSharedKeyIdentity: pskIdentity,
2403 },
2404 flags: flags,
2405 messageLen: maxPlaintext,
2406 })
2407 }
2408 }
David Benjamin2c99d282015-09-01 10:23:00 -04002409 }
Adam Langley95c29f32014-06-20 12:00:00 -07002410 }
Adam Langleya7997f12015-05-14 17:38:50 -07002411
2412 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002413 name: "NoSharedCipher",
2414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002415 MaxVersion: VersionTLS12,
2416 CipherSuites: []uint16{},
2417 },
2418 shouldFail: true,
2419 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2420 })
2421
2422 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002423 name: "NoSharedCipher-TLS13",
2424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 CipherSuites: []uint16{},
2427 },
2428 shouldFail: true,
2429 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2430 })
2431
2432 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002433 name: "UnsupportedCipherSuite",
2434 config: Config{
2435 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002436 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002437 Bugs: ProtocolBugs{
2438 IgnorePeerCipherPreferences: true,
2439 },
2440 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002441 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002442 shouldFail: true,
2443 expectedError: ":WRONG_CIPHER_RETURNED:",
2444 })
2445
2446 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002447 name: "ServerHelloBogusCipher",
2448 config: Config{
2449 MaxVersion: VersionTLS12,
2450 Bugs: ProtocolBugs{
2451 SendCipherSuite: bogusCipher,
2452 },
2453 },
2454 shouldFail: true,
2455 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2456 })
2457 testCases = append(testCases, testCase{
2458 name: "ServerHelloBogusCipher-TLS13",
2459 config: Config{
2460 MaxVersion: VersionTLS13,
2461 Bugs: ProtocolBugs{
2462 SendCipherSuite: bogusCipher,
2463 },
2464 },
2465 shouldFail: true,
2466 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2467 })
2468
2469 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002470 name: "WeakDH",
2471 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002472 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002473 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2474 Bugs: ProtocolBugs{
2475 // This is a 1023-bit prime number, generated
2476 // with:
2477 // openssl gendh 1023 | openssl asn1parse -i
2478 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2479 },
2480 },
2481 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002482 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002483 })
Adam Langleycef75832015-09-03 14:51:12 -07002484
David Benjamincd24a392015-11-11 13:23:05 -08002485 testCases = append(testCases, testCase{
2486 name: "SillyDH",
2487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002489 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2490 Bugs: ProtocolBugs{
2491 // This is a 4097-bit prime number, generated
2492 // with:
2493 // openssl gendh 4097 | openssl asn1parse -i
2494 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2495 },
2496 },
2497 shouldFail: true,
2498 expectedError: ":DH_P_TOO_LONG:",
2499 })
2500
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002501 // This test ensures that Diffie-Hellman public values are padded with
2502 // zeros so that they're the same length as the prime. This is to avoid
2503 // hitting a bug in yaSSL.
2504 testCases = append(testCases, testCase{
2505 testType: serverTest,
2506 name: "DHPublicValuePadded",
2507 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002508 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002509 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2510 Bugs: ProtocolBugs{
2511 RequireDHPublicValueLen: (1025 + 7) / 8,
2512 },
2513 },
2514 flags: []string{"-use-sparse-dh-prime"},
2515 })
David Benjamincd24a392015-11-11 13:23:05 -08002516
David Benjamin241ae832016-01-15 03:04:54 -05002517 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002518 testCases = append(testCases, testCase{
2519 testType: serverTest,
2520 name: "UnknownCipher",
2521 config: Config{
2522 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2523 },
2524 })
2525
Adam Langleycef75832015-09-03 14:51:12 -07002526 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2527 // 1.1 specific cipher suite settings. A server is setup with the given
2528 // cipher lists and then a connection is made for each member of
2529 // expectations. The cipher suite that the server selects must match
2530 // the specified one.
2531 var versionSpecificCiphersTest = []struct {
2532 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2533 // expectations is a map from TLS version to cipher suite id.
2534 expectations map[uint16]uint16
2535 }{
2536 {
2537 // Test that the null case (where no version-specific ciphers are set)
2538 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002539 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2540 "", // no ciphers specifically for TLS ≥ 1.0
2541 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002542 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002543 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2544 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2545 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2546 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002547 },
2548 },
2549 {
2550 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2551 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002552 "DES-CBC3-SHA:AES128-SHA", // default
2553 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2554 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002555 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002556 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002557 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2558 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2559 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2560 },
2561 },
2562 {
2563 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2564 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002565 "DES-CBC3-SHA:AES128-SHA", // default
2566 "", // no ciphers specifically for TLS ≥ 1.0
2567 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002568 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002569 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2570 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002571 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2572 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2573 },
2574 },
2575 {
2576 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2577 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002578 "DES-CBC3-SHA:AES128-SHA", // default
2579 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2580 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002581 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002582 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002583 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2584 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2585 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2586 },
2587 },
2588 }
2589
2590 for i, test := range versionSpecificCiphersTest {
2591 for version, expectedCipherSuite := range test.expectations {
2592 flags := []string{"-cipher", test.ciphersDefault}
2593 if len(test.ciphersTLS10) > 0 {
2594 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2595 }
2596 if len(test.ciphersTLS11) > 0 {
2597 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2598 }
2599
2600 testCases = append(testCases, testCase{
2601 testType: serverTest,
2602 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2603 config: Config{
2604 MaxVersion: version,
2605 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002606 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 -07002607 },
2608 flags: flags,
2609 expectedCipher: expectedCipherSuite,
2610 })
2611 }
2612 }
Adam Langley95c29f32014-06-20 12:00:00 -07002613}
2614
2615func addBadECDSASignatureTests() {
2616 for badR := BadValue(1); badR < NumBadValues; badR++ {
2617 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002618 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002619 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2620 config: Config{
2621 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002622 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002623 Bugs: ProtocolBugs{
2624 BadECDSAR: badR,
2625 BadECDSAS: badS,
2626 },
2627 },
2628 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002629 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002630 })
2631 }
2632 }
2633}
2634
Adam Langley80842bd2014-06-20 12:00:00 -07002635func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002636 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002637 name: "MaxCBCPadding",
2638 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002639 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2641 Bugs: ProtocolBugs{
2642 MaxPadding: true,
2643 },
2644 },
2645 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2646 })
David Benjamin025b3d32014-07-01 19:53:04 -04002647 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002648 name: "BadCBCPadding",
2649 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002650 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2652 Bugs: ProtocolBugs{
2653 PaddingFirstByteBad: true,
2654 },
2655 },
2656 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002657 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002658 })
2659 // OpenSSL previously had an issue where the first byte of padding in
2660 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002661 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002662 name: "BadCBCPadding255",
2663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002664 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2666 Bugs: ProtocolBugs{
2667 MaxPadding: true,
2668 PaddingFirstByteBadIf255: true,
2669 },
2670 },
2671 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2672 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002673 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002674 })
2675}
2676
Kenny Root7fdeaf12014-08-05 15:23:37 -07002677func addCBCSplittingTests() {
2678 testCases = append(testCases, testCase{
2679 name: "CBCRecordSplitting",
2680 config: Config{
2681 MaxVersion: VersionTLS10,
2682 MinVersion: VersionTLS10,
2683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2684 },
David Benjaminac8302a2015-09-01 17:18:15 -04002685 messageLen: -1, // read until EOF
2686 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002687 flags: []string{
2688 "-async",
2689 "-write-different-record-sizes",
2690 "-cbc-record-splitting",
2691 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002692 })
2693 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002694 name: "CBCRecordSplittingPartialWrite",
2695 config: Config{
2696 MaxVersion: VersionTLS10,
2697 MinVersion: VersionTLS10,
2698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2699 },
2700 messageLen: -1, // read until EOF
2701 flags: []string{
2702 "-async",
2703 "-write-different-record-sizes",
2704 "-cbc-record-splitting",
2705 "-partial-write",
2706 },
2707 })
2708}
2709
David Benjamin636293b2014-07-08 17:59:18 -04002710func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002711 // Add a dummy cert pool to stress certificate authority parsing.
2712 // TODO(davidben): Add tests that those values parse out correctly.
2713 certPool := x509.NewCertPool()
2714 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2715 if err != nil {
2716 panic(err)
2717 }
2718 certPool.AddCert(cert)
2719
David Benjamin636293b2014-07-08 17:59:18 -04002720 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002721 testCases = append(testCases, testCase{
2722 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002723 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002724 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002725 MinVersion: ver.version,
2726 MaxVersion: ver.version,
2727 ClientAuth: RequireAnyClientCert,
2728 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002729 },
2730 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002731 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2732 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002733 },
2734 })
2735 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002736 testType: serverTest,
2737 name: ver.name + "-Server-ClientAuth-RSA",
2738 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002739 MinVersion: ver.version,
2740 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002741 Certificates: []Certificate{rsaCertificate},
2742 },
2743 flags: []string{"-require-any-client-certificate"},
2744 })
David Benjamine098ec22014-08-27 23:13:20 -04002745 if ver.version != VersionSSL30 {
2746 testCases = append(testCases, testCase{
2747 testType: serverTest,
2748 name: ver.name + "-Server-ClientAuth-ECDSA",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002752 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002753 },
2754 flags: []string{"-require-any-client-certificate"},
2755 })
2756 testCases = append(testCases, testCase{
2757 testType: clientTest,
2758 name: ver.name + "-Client-ClientAuth-ECDSA",
2759 config: Config{
2760 MinVersion: ver.version,
2761 MaxVersion: ver.version,
2762 ClientAuth: RequireAnyClientCert,
2763 ClientCAs: certPool,
2764 },
2765 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002766 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2767 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002768 },
2769 })
2770 }
Adam Langley37646832016-08-01 16:16:46 -07002771
2772 testCases = append(testCases, testCase{
2773 name: "NoClientCertificate-" + ver.name,
2774 config: Config{
2775 MinVersion: ver.version,
2776 MaxVersion: ver.version,
2777 ClientAuth: RequireAnyClientCert,
2778 },
2779 shouldFail: true,
2780 expectedLocalError: "client didn't provide a certificate",
2781 })
2782
2783 testCases = append(testCases, testCase{
2784 // Even if not configured to expect a certificate, OpenSSL will
2785 // return X509_V_OK as the verify_result.
2786 testType: serverTest,
2787 name: "NoClientCertificateRequested-Server-" + ver.name,
2788 config: Config{
2789 MinVersion: ver.version,
2790 MaxVersion: ver.version,
2791 },
2792 flags: []string{
2793 "-expect-verify-result",
2794 },
2795 // TODO(davidben): Switch this to true when TLS 1.3
2796 // supports session resumption.
2797 resumeSession: ver.version < VersionTLS13,
2798 })
2799
2800 testCases = append(testCases, testCase{
2801 // If a client certificate is not provided, OpenSSL will still
2802 // return X509_V_OK as the verify_result.
2803 testType: serverTest,
2804 name: "NoClientCertificate-Server-" + ver.name,
2805 config: Config{
2806 MinVersion: ver.version,
2807 MaxVersion: ver.version,
2808 },
2809 flags: []string{
2810 "-expect-verify-result",
2811 "-verify-peer",
2812 },
2813 // TODO(davidben): Switch this to true when TLS 1.3
2814 // supports session resumption.
2815 resumeSession: ver.version < VersionTLS13,
2816 })
2817
2818 testCases = append(testCases, testCase{
2819 testType: serverTest,
2820 name: "RequireAnyClientCertificate-" + ver.name,
2821 config: Config{
2822 MinVersion: ver.version,
2823 MaxVersion: ver.version,
2824 },
2825 flags: []string{"-require-any-client-certificate"},
2826 shouldFail: true,
2827 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2828 })
2829
2830 if ver.version != VersionSSL30 {
2831 testCases = append(testCases, testCase{
2832 testType: serverTest,
2833 name: "SkipClientCertificate-" + ver.name,
2834 config: Config{
2835 MinVersion: ver.version,
2836 MaxVersion: ver.version,
2837 Bugs: ProtocolBugs{
2838 SkipClientCertificate: true,
2839 },
2840 },
2841 // Setting SSL_VERIFY_PEER allows anonymous clients.
2842 flags: []string{"-verify-peer"},
2843 shouldFail: true,
2844 expectedError: ":UNEXPECTED_MESSAGE:",
2845 })
2846 }
David Benjamin636293b2014-07-08 17:59:18 -04002847 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002848
David Benjaminc032dfa2016-05-12 14:54:57 -04002849 // Client auth is only legal in certificate-based ciphers.
2850 testCases = append(testCases, testCase{
2851 testType: clientTest,
2852 name: "ClientAuth-PSK",
2853 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002854 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002855 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2856 PreSharedKey: []byte("secret"),
2857 ClientAuth: RequireAnyClientCert,
2858 },
2859 flags: []string{
2860 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2861 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2862 "-psk", "secret",
2863 },
2864 shouldFail: true,
2865 expectedError: ":UNEXPECTED_MESSAGE:",
2866 })
2867 testCases = append(testCases, testCase{
2868 testType: clientTest,
2869 name: "ClientAuth-ECDHE_PSK",
2870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002871 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002872 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2873 PreSharedKey: []byte("secret"),
2874 ClientAuth: RequireAnyClientCert,
2875 },
2876 flags: []string{
2877 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2878 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2879 "-psk", "secret",
2880 },
2881 shouldFail: true,
2882 expectedError: ":UNEXPECTED_MESSAGE:",
2883 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002884
2885 // Regression test for a bug where the client CA list, if explicitly
2886 // set to NULL, was mis-encoded.
2887 testCases = append(testCases, testCase{
2888 testType: serverTest,
2889 name: "Null-Client-CA-List",
2890 config: Config{
2891 MaxVersion: VersionTLS12,
2892 Certificates: []Certificate{rsaCertificate},
2893 },
2894 flags: []string{
2895 "-require-any-client-certificate",
2896 "-use-null-client-ca-list",
2897 },
2898 })
David Benjamin636293b2014-07-08 17:59:18 -04002899}
2900
Adam Langley75712922014-10-10 16:23:43 -07002901func addExtendedMasterSecretTests() {
2902 const expectEMSFlag = "-expect-extended-master-secret"
2903
2904 for _, with := range []bool{false, true} {
2905 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002906 if with {
2907 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002908 }
2909
2910 for _, isClient := range []bool{false, true} {
2911 suffix := "-Server"
2912 testType := serverTest
2913 if isClient {
2914 suffix = "-Client"
2915 testType = clientTest
2916 }
2917
2918 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002919 // In TLS 1.3, the extension is irrelevant and
2920 // always reports as enabled.
2921 var flags []string
2922 if with || ver.version >= VersionTLS13 {
2923 flags = []string{expectEMSFlag}
2924 }
2925
Adam Langley75712922014-10-10 16:23:43 -07002926 test := testCase{
2927 testType: testType,
2928 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2929 config: Config{
2930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 Bugs: ProtocolBugs{
2933 NoExtendedMasterSecret: !with,
2934 RequireExtendedMasterSecret: with,
2935 },
2936 },
David Benjamin48cae082014-10-27 01:06:24 -04002937 flags: flags,
2938 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002939 }
2940 if test.shouldFail {
2941 test.expectedLocalError = "extended master secret required but not supported by peer"
2942 }
2943 testCases = append(testCases, test)
2944 }
2945 }
2946 }
2947
Adam Langleyba5934b2015-06-02 10:50:35 -07002948 for _, isClient := range []bool{false, true} {
2949 for _, supportedInFirstConnection := range []bool{false, true} {
2950 for _, supportedInResumeConnection := range []bool{false, true} {
2951 boolToWord := func(b bool) string {
2952 if b {
2953 return "Yes"
2954 }
2955 return "No"
2956 }
2957 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2958 if isClient {
2959 suffix += "Client"
2960 } else {
2961 suffix += "Server"
2962 }
2963
2964 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002965 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002966 Bugs: ProtocolBugs{
2967 RequireExtendedMasterSecret: true,
2968 },
2969 }
2970
2971 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002972 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002973 Bugs: ProtocolBugs{
2974 NoExtendedMasterSecret: true,
2975 },
2976 }
2977
2978 test := testCase{
2979 name: "ExtendedMasterSecret-" + suffix,
2980 resumeSession: true,
2981 }
2982
2983 if !isClient {
2984 test.testType = serverTest
2985 }
2986
2987 if supportedInFirstConnection {
2988 test.config = supportedConfig
2989 } else {
2990 test.config = noSupportConfig
2991 }
2992
2993 if supportedInResumeConnection {
2994 test.resumeConfig = &supportedConfig
2995 } else {
2996 test.resumeConfig = &noSupportConfig
2997 }
2998
2999 switch suffix {
3000 case "YesToYes-Client", "YesToYes-Server":
3001 // When a session is resumed, it should
3002 // still be aware that its master
3003 // secret was generated via EMS and
3004 // thus it's safe to use tls-unique.
3005 test.flags = []string{expectEMSFlag}
3006 case "NoToYes-Server":
3007 // If an original connection did not
3008 // contain EMS, but a resumption
3009 // handshake does, then a server should
3010 // not resume the session.
3011 test.expectResumeRejected = true
3012 case "YesToNo-Server":
3013 // Resuming an EMS session without the
3014 // EMS extension should cause the
3015 // server to abort the connection.
3016 test.shouldFail = true
3017 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3018 case "NoToYes-Client":
3019 // A client should abort a connection
3020 // where the server resumed a non-EMS
3021 // session but echoed the EMS
3022 // extension.
3023 test.shouldFail = true
3024 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3025 case "YesToNo-Client":
3026 // A client should abort a connection
3027 // where the server didn't echo EMS
3028 // when the session used it.
3029 test.shouldFail = true
3030 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3031 }
3032
3033 testCases = append(testCases, test)
3034 }
3035 }
3036 }
David Benjamin163c9562016-08-29 23:14:17 -04003037
3038 // Switching EMS on renegotiation is forbidden.
3039 testCases = append(testCases, testCase{
3040 name: "ExtendedMasterSecret-Renego-NoEMS",
3041 config: Config{
3042 MaxVersion: VersionTLS12,
3043 Bugs: ProtocolBugs{
3044 NoExtendedMasterSecret: true,
3045 NoExtendedMasterSecretOnRenegotiation: true,
3046 },
3047 },
3048 renegotiate: 1,
3049 flags: []string{
3050 "-renegotiate-freely",
3051 "-expect-total-renegotiations", "1",
3052 },
3053 })
3054
3055 testCases = append(testCases, testCase{
3056 name: "ExtendedMasterSecret-Renego-Upgrade",
3057 config: Config{
3058 MaxVersion: VersionTLS12,
3059 Bugs: ProtocolBugs{
3060 NoExtendedMasterSecret: true,
3061 },
3062 },
3063 renegotiate: 1,
3064 flags: []string{
3065 "-renegotiate-freely",
3066 "-expect-total-renegotiations", "1",
3067 },
3068 shouldFail: true,
3069 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3070 })
3071
3072 testCases = append(testCases, testCase{
3073 name: "ExtendedMasterSecret-Renego-Downgrade",
3074 config: Config{
3075 MaxVersion: VersionTLS12,
3076 Bugs: ProtocolBugs{
3077 NoExtendedMasterSecretOnRenegotiation: true,
3078 },
3079 },
3080 renegotiate: 1,
3081 flags: []string{
3082 "-renegotiate-freely",
3083 "-expect-total-renegotiations", "1",
3084 },
3085 shouldFail: true,
3086 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3087 })
Adam Langley75712922014-10-10 16:23:43 -07003088}
3089
David Benjamin582ba042016-07-07 12:33:25 -07003090type stateMachineTestConfig struct {
3091 protocol protocol
3092 async bool
3093 splitHandshake, packHandshakeFlight bool
3094}
3095
David Benjamin43ec06f2014-08-05 02:28:57 -04003096// Adds tests that try to cover the range of the handshake state machine, under
3097// various conditions. Some of these are redundant with other tests, but they
3098// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003099func addAllStateMachineCoverageTests() {
3100 for _, async := range []bool{false, true} {
3101 for _, protocol := range []protocol{tls, dtls} {
3102 addStateMachineCoverageTests(stateMachineTestConfig{
3103 protocol: protocol,
3104 async: async,
3105 })
3106 addStateMachineCoverageTests(stateMachineTestConfig{
3107 protocol: protocol,
3108 async: async,
3109 splitHandshake: true,
3110 })
3111 if protocol == tls {
3112 addStateMachineCoverageTests(stateMachineTestConfig{
3113 protocol: protocol,
3114 async: async,
3115 packHandshakeFlight: true,
3116 })
3117 }
3118 }
3119 }
3120}
3121
3122func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003123 var tests []testCase
3124
3125 // Basic handshake, with resumption. Client and server,
3126 // session ID and session ticket.
3127 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003128 name: "Basic-Client",
3129 config: Config{
3130 MaxVersion: VersionTLS12,
3131 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003132 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003133 // Ensure session tickets are used, not session IDs.
3134 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003135 })
3136 tests = append(tests, testCase{
3137 name: "Basic-Client-RenewTicket",
3138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003139 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003140 Bugs: ProtocolBugs{
3141 RenewTicketOnResume: true,
3142 },
3143 },
David Benjamin46662482016-08-17 00:51:00 -04003144 flags: []string{"-expect-ticket-renewal"},
3145 resumeSession: true,
3146 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003147 })
3148 tests = append(tests, testCase{
3149 name: "Basic-Client-NoTicket",
3150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003151 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003152 SessionTicketsDisabled: true,
3153 },
3154 resumeSession: true,
3155 })
3156 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003157 name: "Basic-Client-Implicit",
3158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003161 flags: []string{"-implicit-handshake"},
3162 resumeSession: true,
3163 })
3164 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003165 testType: serverTest,
3166 name: "Basic-Server",
3167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003168 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003169 Bugs: ProtocolBugs{
3170 RequireSessionTickets: true,
3171 },
3172 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003173 resumeSession: true,
3174 })
3175 tests = append(tests, testCase{
3176 testType: serverTest,
3177 name: "Basic-Server-NoTickets",
3178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003179 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003180 SessionTicketsDisabled: true,
3181 },
3182 resumeSession: true,
3183 })
3184 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003185 testType: serverTest,
3186 name: "Basic-Server-Implicit",
3187 config: Config{
3188 MaxVersion: VersionTLS12,
3189 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003190 flags: []string{"-implicit-handshake"},
3191 resumeSession: true,
3192 })
3193 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003194 testType: serverTest,
3195 name: "Basic-Server-EarlyCallback",
3196 config: Config{
3197 MaxVersion: VersionTLS12,
3198 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003199 flags: []string{"-use-early-callback"},
3200 resumeSession: true,
3201 })
3202
Steven Valdez143e8b32016-07-11 13:19:03 -04003203 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003204 if config.protocol == tls {
3205 tests = append(tests, testCase{
3206 name: "TLS13-1RTT-Client",
3207 config: Config{
3208 MaxVersion: VersionTLS13,
3209 MinVersion: VersionTLS13,
3210 },
David Benjamin46662482016-08-17 00:51:00 -04003211 resumeSession: true,
3212 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003213 })
3214
3215 tests = append(tests, testCase{
3216 testType: serverTest,
3217 name: "TLS13-1RTT-Server",
3218 config: Config{
3219 MaxVersion: VersionTLS13,
3220 MinVersion: VersionTLS13,
3221 },
David Benjamin46662482016-08-17 00:51:00 -04003222 resumeSession: true,
3223 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003224 })
3225
3226 tests = append(tests, testCase{
3227 name: "TLS13-HelloRetryRequest-Client",
3228 config: Config{
3229 MaxVersion: VersionTLS13,
3230 MinVersion: VersionTLS13,
3231 // P-384 requires a HelloRetryRequest against
3232 // BoringSSL's default configuration. Assert
3233 // that we do indeed test this with
3234 // ExpectMissingKeyShare.
3235 CurvePreferences: []CurveID{CurveP384},
3236 Bugs: ProtocolBugs{
3237 ExpectMissingKeyShare: true,
3238 },
3239 },
3240 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3241 resumeSession: true,
3242 })
3243
3244 tests = append(tests, testCase{
3245 testType: serverTest,
3246 name: "TLS13-HelloRetryRequest-Server",
3247 config: Config{
3248 MaxVersion: VersionTLS13,
3249 MinVersion: VersionTLS13,
3250 // Require a HelloRetryRequest for every curve.
3251 DefaultCurves: []CurveID{},
3252 },
3253 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3254 resumeSession: true,
3255 })
3256 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003257
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 // TLS client auth.
3259 tests = append(tests, testCase{
3260 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003261 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003264 ClientAuth: RequestClientCert,
3265 },
3266 })
3267 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003268 testType: serverTest,
3269 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003270 config: Config{
3271 MaxVersion: VersionTLS12,
3272 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003273 // Setting SSL_VERIFY_PEER allows anonymous clients.
3274 flags: []string{"-verify-peer"},
3275 })
David Benjamin582ba042016-07-07 12:33:25 -07003276 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003277 tests = append(tests, testCase{
3278 testType: clientTest,
3279 name: "ClientAuth-NoCertificate-Client-SSL3",
3280 config: Config{
3281 MaxVersion: VersionSSL30,
3282 ClientAuth: RequestClientCert,
3283 },
3284 })
3285 tests = append(tests, testCase{
3286 testType: serverTest,
3287 name: "ClientAuth-NoCertificate-Server-SSL3",
3288 config: Config{
3289 MaxVersion: VersionSSL30,
3290 },
3291 // Setting SSL_VERIFY_PEER allows anonymous clients.
3292 flags: []string{"-verify-peer"},
3293 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003294 tests = append(tests, testCase{
3295 testType: clientTest,
3296 name: "ClientAuth-NoCertificate-Client-TLS13",
3297 config: Config{
3298 MaxVersion: VersionTLS13,
3299 ClientAuth: RequestClientCert,
3300 },
3301 })
3302 tests = append(tests, testCase{
3303 testType: serverTest,
3304 name: "ClientAuth-NoCertificate-Server-TLS13",
3305 config: Config{
3306 MaxVersion: VersionTLS13,
3307 },
3308 // Setting SSL_VERIFY_PEER allows anonymous clients.
3309 flags: []string{"-verify-peer"},
3310 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003311 }
3312 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003313 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003314 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003315 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003316 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003317 ClientAuth: RequireAnyClientCert,
3318 },
3319 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003320 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3321 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003322 },
3323 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003324 tests = append(tests, testCase{
3325 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003326 name: "ClientAuth-RSA-Client-TLS13",
3327 config: Config{
3328 MaxVersion: VersionTLS13,
3329 ClientAuth: RequireAnyClientCert,
3330 },
3331 flags: []string{
3332 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3333 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3334 },
3335 })
3336 tests = append(tests, testCase{
3337 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003338 name: "ClientAuth-ECDSA-Client",
3339 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003340 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003341 ClientAuth: RequireAnyClientCert,
3342 },
3343 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003344 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3345 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003346 },
3347 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003348 tests = append(tests, testCase{
3349 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003350 name: "ClientAuth-ECDSA-Client-TLS13",
3351 config: Config{
3352 MaxVersion: VersionTLS13,
3353 ClientAuth: RequireAnyClientCert,
3354 },
3355 flags: []string{
3356 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3357 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3358 },
3359 })
3360 tests = append(tests, testCase{
3361 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003362 name: "ClientAuth-NoCertificate-OldCallback",
3363 config: Config{
3364 MaxVersion: VersionTLS12,
3365 ClientAuth: RequestClientCert,
3366 },
3367 flags: []string{"-use-old-client-cert-callback"},
3368 })
3369 tests = append(tests, testCase{
3370 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003371 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3372 config: Config{
3373 MaxVersion: VersionTLS13,
3374 ClientAuth: RequestClientCert,
3375 },
3376 flags: []string{"-use-old-client-cert-callback"},
3377 })
3378 tests = append(tests, testCase{
3379 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003380 name: "ClientAuth-OldCallback",
3381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003382 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003383 ClientAuth: RequireAnyClientCert,
3384 },
3385 flags: []string{
3386 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3387 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3388 "-use-old-client-cert-callback",
3389 },
3390 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003392 testType: clientTest,
3393 name: "ClientAuth-OldCallback-TLS13",
3394 config: Config{
3395 MaxVersion: VersionTLS13,
3396 ClientAuth: RequireAnyClientCert,
3397 },
3398 flags: []string{
3399 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3400 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3401 "-use-old-client-cert-callback",
3402 },
3403 })
3404 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003405 testType: serverTest,
3406 name: "ClientAuth-Server",
3407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003408 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003409 Certificates: []Certificate{rsaCertificate},
3410 },
3411 flags: []string{"-require-any-client-certificate"},
3412 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003413 tests = append(tests, testCase{
3414 testType: serverTest,
3415 name: "ClientAuth-Server-TLS13",
3416 config: Config{
3417 MaxVersion: VersionTLS13,
3418 Certificates: []Certificate{rsaCertificate},
3419 },
3420 flags: []string{"-require-any-client-certificate"},
3421 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003422
David Benjamin4c3ddf72016-06-29 18:13:53 -04003423 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 tests = append(tests, testCase{
3425 testType: serverTest,
3426 name: "Basic-Server-RSA",
3427 config: Config{
3428 MaxVersion: VersionTLS12,
3429 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3430 },
3431 flags: []string{
3432 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3433 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3434 },
3435 })
3436 tests = append(tests, testCase{
3437 testType: serverTest,
3438 name: "Basic-Server-ECDHE-RSA",
3439 config: Config{
3440 MaxVersion: VersionTLS12,
3441 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3442 },
3443 flags: []string{
3444 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3445 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3446 },
3447 })
3448 tests = append(tests, testCase{
3449 testType: serverTest,
3450 name: "Basic-Server-ECDHE-ECDSA",
3451 config: Config{
3452 MaxVersion: VersionTLS12,
3453 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3454 },
3455 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003456 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3457 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003458 },
3459 })
3460
David Benjamin760b1dd2015-05-15 23:33:48 -04003461 // No session ticket support; server doesn't send NewSessionTicket.
3462 tests = append(tests, testCase{
3463 name: "SessionTicketsDisabled-Client",
3464 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003465 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003466 SessionTicketsDisabled: true,
3467 },
3468 })
3469 tests = append(tests, testCase{
3470 testType: serverTest,
3471 name: "SessionTicketsDisabled-Server",
3472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003473 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003474 SessionTicketsDisabled: true,
3475 },
3476 })
3477
3478 // Skip ServerKeyExchange in PSK key exchange if there's no
3479 // identity hint.
3480 tests = append(tests, testCase{
3481 name: "EmptyPSKHint-Client",
3482 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003483 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003484 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3485 PreSharedKey: []byte("secret"),
3486 },
3487 flags: []string{"-psk", "secret"},
3488 })
3489 tests = append(tests, testCase{
3490 testType: serverTest,
3491 name: "EmptyPSKHint-Server",
3492 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003493 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003494 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3495 PreSharedKey: []byte("secret"),
3496 },
3497 flags: []string{"-psk", "secret"},
3498 })
3499
David Benjamin4c3ddf72016-06-29 18:13:53 -04003500 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003501 tests = append(tests, testCase{
3502 testType: clientTest,
3503 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003504 config: Config{
3505 MaxVersion: VersionTLS12,
3506 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003507 flags: []string{
3508 "-enable-ocsp-stapling",
3509 "-expect-ocsp-response",
3510 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003511 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003512 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003513 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003514 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003515 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516 testType: serverTest,
3517 name: "OCSPStapling-Server",
3518 config: Config{
3519 MaxVersion: VersionTLS12,
3520 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003521 expectedOCSPResponse: testOCSPResponse,
3522 flags: []string{
3523 "-ocsp-response",
3524 base64.StdEncoding.EncodeToString(testOCSPResponse),
3525 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003526 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003527 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003528 tests = append(tests, testCase{
3529 testType: clientTest,
3530 name: "OCSPStapling-Client-TLS13",
3531 config: Config{
3532 MaxVersion: VersionTLS13,
3533 },
3534 flags: []string{
3535 "-enable-ocsp-stapling",
3536 "-expect-ocsp-response",
3537 base64.StdEncoding.EncodeToString(testOCSPResponse),
3538 "-verify-peer",
3539 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003540 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003541 })
3542 tests = append(tests, testCase{
3543 testType: serverTest,
3544 name: "OCSPStapling-Server-TLS13",
3545 config: Config{
3546 MaxVersion: VersionTLS13,
3547 },
3548 expectedOCSPResponse: testOCSPResponse,
3549 flags: []string{
3550 "-ocsp-response",
3551 base64.StdEncoding.EncodeToString(testOCSPResponse),
3552 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003553 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003554 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003555
David Benjamin4c3ddf72016-06-29 18:13:53 -04003556 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003557 for _, vers := range tlsVersions {
3558 if config.protocol == dtls && !vers.hasDTLS {
3559 continue
3560 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003561 for _, testType := range []testType{clientTest, serverTest} {
3562 suffix := "-Client"
3563 if testType == serverTest {
3564 suffix = "-Server"
3565 }
3566 suffix += "-" + vers.name
3567
3568 flag := "-verify-peer"
3569 if testType == serverTest {
3570 flag = "-require-any-client-certificate"
3571 }
3572
3573 tests = append(tests, testCase{
3574 testType: testType,
3575 name: "CertificateVerificationSucceed" + suffix,
3576 config: Config{
3577 MaxVersion: vers.version,
3578 Certificates: []Certificate{rsaCertificate},
3579 },
3580 flags: []string{
3581 flag,
3582 "-expect-verify-result",
3583 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003584 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003585 })
3586 tests = append(tests, testCase{
3587 testType: testType,
3588 name: "CertificateVerificationFail" + suffix,
3589 config: Config{
3590 MaxVersion: vers.version,
3591 Certificates: []Certificate{rsaCertificate},
3592 },
3593 flags: []string{
3594 flag,
3595 "-verify-fail",
3596 },
3597 shouldFail: true,
3598 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3599 })
3600 }
3601
3602 // By default, the client is in a soft fail mode where the peer
3603 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003604 tests = append(tests, testCase{
3605 testType: clientTest,
3606 name: "CertificateVerificationSoftFail-" + vers.name,
3607 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003608 MaxVersion: vers.version,
3609 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003610 },
3611 flags: []string{
3612 "-verify-fail",
3613 "-expect-verify-result",
3614 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003615 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003616 })
3617 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003618
David Benjamin1d4f4c02016-07-26 18:03:08 -04003619 tests = append(tests, testCase{
3620 name: "ShimSendAlert",
3621 flags: []string{"-send-alert"},
3622 shimWritesFirst: true,
3623 shouldFail: true,
3624 expectedLocalError: "remote error: decompression failure",
3625 })
3626
David Benjamin582ba042016-07-07 12:33:25 -07003627 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003628 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003629 name: "Renegotiate-Client",
3630 config: Config{
3631 MaxVersion: VersionTLS12,
3632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003633 renegotiate: 1,
3634 flags: []string{
3635 "-renegotiate-freely",
3636 "-expect-total-renegotiations", "1",
3637 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003638 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003639
David Benjamin47921102016-07-28 11:29:18 -04003640 tests = append(tests, testCase{
3641 name: "SendHalfHelloRequest",
3642 config: Config{
3643 MaxVersion: VersionTLS12,
3644 Bugs: ProtocolBugs{
3645 PackHelloRequestWithFinished: config.packHandshakeFlight,
3646 },
3647 },
3648 sendHalfHelloRequest: true,
3649 flags: []string{"-renegotiate-ignore"},
3650 shouldFail: true,
3651 expectedError: ":UNEXPECTED_RECORD:",
3652 })
3653
David Benjamin760b1dd2015-05-15 23:33:48 -04003654 // NPN on client and server; results in post-handshake message.
3655 tests = append(tests, testCase{
3656 name: "NPN-Client",
3657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003658 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003659 NextProtos: []string{"foo"},
3660 },
3661 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003662 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003663 expectedNextProto: "foo",
3664 expectedNextProtoType: npn,
3665 })
3666 tests = append(tests, testCase{
3667 testType: serverTest,
3668 name: "NPN-Server",
3669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003671 NextProtos: []string{"bar"},
3672 },
3673 flags: []string{
3674 "-advertise-npn", "\x03foo\x03bar\x03baz",
3675 "-expect-next-proto", "bar",
3676 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003677 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003678 expectedNextProto: "bar",
3679 expectedNextProtoType: npn,
3680 })
3681
3682 // TODO(davidben): Add tests for when False Start doesn't trigger.
3683
3684 // Client does False Start and negotiates NPN.
3685 tests = append(tests, testCase{
3686 name: "FalseStart",
3687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3690 NextProtos: []string{"foo"},
3691 Bugs: ProtocolBugs{
3692 ExpectFalseStart: true,
3693 },
3694 },
3695 flags: []string{
3696 "-false-start",
3697 "-select-next-proto", "foo",
3698 },
3699 shimWritesFirst: true,
3700 resumeSession: true,
3701 })
3702
3703 // Client does False Start and negotiates ALPN.
3704 tests = append(tests, testCase{
3705 name: "FalseStart-ALPN",
3706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003707 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3709 NextProtos: []string{"foo"},
3710 Bugs: ProtocolBugs{
3711 ExpectFalseStart: true,
3712 },
3713 },
3714 flags: []string{
3715 "-false-start",
3716 "-advertise-alpn", "\x03foo",
3717 },
3718 shimWritesFirst: true,
3719 resumeSession: true,
3720 })
3721
3722 // Client does False Start but doesn't explicitly call
3723 // SSL_connect.
3724 tests = append(tests, testCase{
3725 name: "FalseStart-Implicit",
3726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3729 NextProtos: []string{"foo"},
3730 },
3731 flags: []string{
3732 "-implicit-handshake",
3733 "-false-start",
3734 "-advertise-alpn", "\x03foo",
3735 },
3736 })
3737
3738 // False Start without session tickets.
3739 tests = append(tests, testCase{
3740 name: "FalseStart-SessionTicketsDisabled",
3741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003742 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3744 NextProtos: []string{"foo"},
3745 SessionTicketsDisabled: true,
3746 Bugs: ProtocolBugs{
3747 ExpectFalseStart: true,
3748 },
3749 },
3750 flags: []string{
3751 "-false-start",
3752 "-select-next-proto", "foo",
3753 },
3754 shimWritesFirst: true,
3755 })
3756
Adam Langleydf759b52016-07-11 15:24:37 -07003757 tests = append(tests, testCase{
3758 name: "FalseStart-CECPQ1",
3759 config: Config{
3760 MaxVersion: VersionTLS12,
3761 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3762 NextProtos: []string{"foo"},
3763 Bugs: ProtocolBugs{
3764 ExpectFalseStart: true,
3765 },
3766 },
3767 flags: []string{
3768 "-false-start",
3769 "-cipher", "DEFAULT:kCECPQ1",
3770 "-select-next-proto", "foo",
3771 },
3772 shimWritesFirst: true,
3773 resumeSession: true,
3774 })
3775
David Benjamin760b1dd2015-05-15 23:33:48 -04003776 // Server parses a V2ClientHello.
3777 tests = append(tests, testCase{
3778 testType: serverTest,
3779 name: "SendV2ClientHello",
3780 config: Config{
3781 // Choose a cipher suite that does not involve
3782 // elliptic curves, so no extensions are
3783 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003784 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003785 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 Bugs: ProtocolBugs{
3787 SendV2ClientHello: true,
3788 },
3789 },
3790 })
3791
3792 // Client sends a Channel ID.
3793 tests = append(tests, testCase{
3794 name: "ChannelID-Client",
3795 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003796 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003797 RequestChannelID: true,
3798 },
Adam Langley7c803a62015-06-15 15:35:05 -07003799 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003800 resumeSession: true,
3801 expectChannelID: true,
3802 })
3803
3804 // Server accepts a Channel ID.
3805 tests = append(tests, testCase{
3806 testType: serverTest,
3807 name: "ChannelID-Server",
3808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 MaxVersion: VersionTLS12,
3810 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003811 },
3812 flags: []string{
3813 "-expect-channel-id",
3814 base64.StdEncoding.EncodeToString(channelIDBytes),
3815 },
3816 resumeSession: true,
3817 expectChannelID: true,
3818 })
David Benjamin30789da2015-08-29 22:56:45 -04003819
David Benjaminf8fcdf32016-06-08 15:56:13 -04003820 // Channel ID and NPN at the same time, to ensure their relative
3821 // ordering is correct.
3822 tests = append(tests, testCase{
3823 name: "ChannelID-NPN-Client",
3824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003825 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003826 RequestChannelID: true,
3827 NextProtos: []string{"foo"},
3828 },
3829 flags: []string{
3830 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3831 "-select-next-proto", "foo",
3832 },
3833 resumeSession: true,
3834 expectChannelID: true,
3835 expectedNextProto: "foo",
3836 expectedNextProtoType: npn,
3837 })
3838 tests = append(tests, testCase{
3839 testType: serverTest,
3840 name: "ChannelID-NPN-Server",
3841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003842 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003843 ChannelID: channelIDKey,
3844 NextProtos: []string{"bar"},
3845 },
3846 flags: []string{
3847 "-expect-channel-id",
3848 base64.StdEncoding.EncodeToString(channelIDBytes),
3849 "-advertise-npn", "\x03foo\x03bar\x03baz",
3850 "-expect-next-proto", "bar",
3851 },
3852 resumeSession: true,
3853 expectChannelID: true,
3854 expectedNextProto: "bar",
3855 expectedNextProtoType: npn,
3856 })
3857
David Benjamin30789da2015-08-29 22:56:45 -04003858 // Bidirectional shutdown with the runner initiating.
3859 tests = append(tests, testCase{
3860 name: "Shutdown-Runner",
3861 config: Config{
3862 Bugs: ProtocolBugs{
3863 ExpectCloseNotify: true,
3864 },
3865 },
3866 flags: []string{"-check-close-notify"},
3867 })
3868
3869 // Bidirectional shutdown with the shim initiating. The runner,
3870 // in the meantime, sends garbage before the close_notify which
3871 // the shim must ignore.
3872 tests = append(tests, testCase{
3873 name: "Shutdown-Shim",
3874 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003875 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003876 Bugs: ProtocolBugs{
3877 ExpectCloseNotify: true,
3878 },
3879 },
3880 shimShutsDown: true,
3881 sendEmptyRecords: 1,
3882 sendWarningAlerts: 1,
3883 flags: []string{"-check-close-notify"},
3884 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003885 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003886 // TODO(davidben): DTLS 1.3 will want a similar thing for
3887 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003888 tests = append(tests, testCase{
3889 name: "SkipHelloVerifyRequest",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 Bugs: ProtocolBugs{
3893 SkipHelloVerifyRequest: true,
3894 },
3895 },
3896 })
3897 }
3898
David Benjamin760b1dd2015-05-15 23:33:48 -04003899 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003900 test.protocol = config.protocol
3901 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003902 test.name += "-DTLS"
3903 }
David Benjamin582ba042016-07-07 12:33:25 -07003904 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003905 test.name += "-Async"
3906 test.flags = append(test.flags, "-async")
3907 } else {
3908 test.name += "-Sync"
3909 }
David Benjamin582ba042016-07-07 12:33:25 -07003910 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003911 test.name += "-SplitHandshakeRecords"
3912 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003913 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003914 test.config.Bugs.MaxPacketLength = 256
3915 test.flags = append(test.flags, "-mtu", "256")
3916 }
3917 }
David Benjamin582ba042016-07-07 12:33:25 -07003918 if config.packHandshakeFlight {
3919 test.name += "-PackHandshakeFlight"
3920 test.config.Bugs.PackHandshakeFlight = true
3921 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003922 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003923 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003924}
3925
Adam Langley524e7172015-02-20 16:04:00 -08003926func addDDoSCallbackTests() {
3927 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003928 for _, resume := range []bool{false, true} {
3929 suffix := "Resume"
3930 if resume {
3931 suffix = "No" + suffix
3932 }
3933
3934 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003935 testType: serverTest,
3936 name: "Server-DDoS-OK-" + suffix,
3937 config: Config{
3938 MaxVersion: VersionTLS12,
3939 },
Adam Langley524e7172015-02-20 16:04:00 -08003940 flags: []string{"-install-ddos-callback"},
3941 resumeSession: resume,
3942 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003943 testCases = append(testCases, testCase{
3944 testType: serverTest,
3945 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3946 config: Config{
3947 MaxVersion: VersionTLS13,
3948 },
3949 flags: []string{"-install-ddos-callback"},
3950 resumeSession: resume,
3951 })
Adam Langley524e7172015-02-20 16:04:00 -08003952
3953 failFlag := "-fail-ddos-callback"
3954 if resume {
3955 failFlag = "-fail-second-ddos-callback"
3956 }
3957 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003958 testType: serverTest,
3959 name: "Server-DDoS-Reject-" + suffix,
3960 config: Config{
3961 MaxVersion: VersionTLS12,
3962 },
Adam Langley524e7172015-02-20 16:04:00 -08003963 flags: []string{"-install-ddos-callback", failFlag},
3964 resumeSession: resume,
3965 shouldFail: true,
3966 expectedError: ":CONNECTION_REJECTED:",
3967 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003968 testCases = append(testCases, testCase{
3969 testType: serverTest,
3970 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3971 config: Config{
3972 MaxVersion: VersionTLS13,
3973 },
3974 flags: []string{"-install-ddos-callback", failFlag},
3975 resumeSession: resume,
3976 shouldFail: true,
3977 expectedError: ":CONNECTION_REJECTED:",
3978 })
Adam Langley524e7172015-02-20 16:04:00 -08003979 }
3980}
3981
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003982func addVersionNegotiationTests() {
3983 for i, shimVers := range tlsVersions {
3984 // Assemble flags to disable all newer versions on the shim.
3985 var flags []string
3986 for _, vers := range tlsVersions[i+1:] {
3987 flags = append(flags, vers.flag)
3988 }
3989
3990 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003991 protocols := []protocol{tls}
3992 if runnerVers.hasDTLS && shimVers.hasDTLS {
3993 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003994 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003995 for _, protocol := range protocols {
3996 expectedVersion := shimVers.version
3997 if runnerVers.version < shimVers.version {
3998 expectedVersion = runnerVers.version
3999 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004000
David Benjamin8b8c0062014-11-23 02:47:52 -05004001 suffix := shimVers.name + "-" + runnerVers.name
4002 if protocol == dtls {
4003 suffix += "-DTLS"
4004 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004005
David Benjamin1eb367c2014-12-12 18:17:51 -05004006 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4007
David Benjamin1e29a6b2014-12-10 02:27:24 -05004008 clientVers := shimVers.version
4009 if clientVers > VersionTLS10 {
4010 clientVers = VersionTLS10
4011 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004012 serverVers := expectedVersion
4013 if expectedVersion >= VersionTLS13 {
4014 serverVers = VersionTLS10
4015 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004016 testCases = append(testCases, testCase{
4017 protocol: protocol,
4018 testType: clientTest,
4019 name: "VersionNegotiation-Client-" + suffix,
4020 config: Config{
4021 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004022 Bugs: ProtocolBugs{
4023 ExpectInitialRecordVersion: clientVers,
4024 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004025 },
4026 flags: flags,
4027 expectedVersion: expectedVersion,
4028 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004029 testCases = append(testCases, testCase{
4030 protocol: protocol,
4031 testType: clientTest,
4032 name: "VersionNegotiation-Client2-" + suffix,
4033 config: Config{
4034 MaxVersion: runnerVers.version,
4035 Bugs: ProtocolBugs{
4036 ExpectInitialRecordVersion: clientVers,
4037 },
4038 },
4039 flags: []string{"-max-version", shimVersFlag},
4040 expectedVersion: expectedVersion,
4041 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004042
4043 testCases = append(testCases, testCase{
4044 protocol: protocol,
4045 testType: serverTest,
4046 name: "VersionNegotiation-Server-" + suffix,
4047 config: Config{
4048 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004049 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004050 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004051 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004052 },
4053 flags: flags,
4054 expectedVersion: expectedVersion,
4055 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004056 testCases = append(testCases, testCase{
4057 protocol: protocol,
4058 testType: serverTest,
4059 name: "VersionNegotiation-Server2-" + suffix,
4060 config: Config{
4061 MaxVersion: runnerVers.version,
4062 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004063 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004064 },
4065 },
4066 flags: []string{"-max-version", shimVersFlag},
4067 expectedVersion: expectedVersion,
4068 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004069 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004070 }
4071 }
David Benjamin95c69562016-06-29 18:15:03 -04004072
4073 // Test for version tolerance.
4074 testCases = append(testCases, testCase{
4075 testType: serverTest,
4076 name: "MinorVersionTolerance",
4077 config: Config{
4078 Bugs: ProtocolBugs{
4079 SendClientVersion: 0x03ff,
4080 },
4081 },
4082 expectedVersion: VersionTLS13,
4083 })
4084 testCases = append(testCases, testCase{
4085 testType: serverTest,
4086 name: "MajorVersionTolerance",
4087 config: Config{
4088 Bugs: ProtocolBugs{
4089 SendClientVersion: 0x0400,
4090 },
4091 },
4092 expectedVersion: VersionTLS13,
4093 })
4094 testCases = append(testCases, testCase{
4095 protocol: dtls,
4096 testType: serverTest,
4097 name: "MinorVersionTolerance-DTLS",
4098 config: Config{
4099 Bugs: ProtocolBugs{
4100 SendClientVersion: 0x03ff,
4101 },
4102 },
4103 expectedVersion: VersionTLS12,
4104 })
4105 testCases = append(testCases, testCase{
4106 protocol: dtls,
4107 testType: serverTest,
4108 name: "MajorVersionTolerance-DTLS",
4109 config: Config{
4110 Bugs: ProtocolBugs{
4111 SendClientVersion: 0x0400,
4112 },
4113 },
4114 expectedVersion: VersionTLS12,
4115 })
4116
4117 // Test that versions below 3.0 are rejected.
4118 testCases = append(testCases, testCase{
4119 testType: serverTest,
4120 name: "VersionTooLow",
4121 config: Config{
4122 Bugs: ProtocolBugs{
4123 SendClientVersion: 0x0200,
4124 },
4125 },
4126 shouldFail: true,
4127 expectedError: ":UNSUPPORTED_PROTOCOL:",
4128 })
4129 testCases = append(testCases, testCase{
4130 protocol: dtls,
4131 testType: serverTest,
4132 name: "VersionTooLow-DTLS",
4133 config: Config{
4134 Bugs: ProtocolBugs{
4135 // 0x0201 is the lowest version expressable in
4136 // DTLS.
4137 SendClientVersion: 0x0201,
4138 },
4139 },
4140 shouldFail: true,
4141 expectedError: ":UNSUPPORTED_PROTOCOL:",
4142 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004143
4144 // Test TLS 1.3's downgrade signal.
4145 testCases = append(testCases, testCase{
4146 name: "Downgrade-TLS12-Client",
4147 config: Config{
4148 Bugs: ProtocolBugs{
4149 NegotiateVersion: VersionTLS12,
4150 },
4151 },
4152 shouldFail: true,
4153 expectedError: ":DOWNGRADE_DETECTED:",
4154 })
4155 testCases = append(testCases, testCase{
4156 testType: serverTest,
4157 name: "Downgrade-TLS12-Server",
4158 config: Config{
4159 Bugs: ProtocolBugs{
4160 SendClientVersion: VersionTLS12,
4161 },
4162 },
4163 shouldFail: true,
4164 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4165 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004166
4167 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4168 // behave correctly when both real maximum and fallback versions are
4169 // set.
4170 testCases = append(testCases, testCase{
4171 name: "Downgrade-TLS12-Client-Fallback",
4172 config: Config{
4173 Bugs: ProtocolBugs{
4174 FailIfNotFallbackSCSV: true,
4175 },
4176 },
4177 flags: []string{
4178 "-max-version", strconv.Itoa(VersionTLS13),
4179 "-fallback-version", strconv.Itoa(VersionTLS12),
4180 },
4181 shouldFail: true,
4182 expectedError: ":DOWNGRADE_DETECTED:",
4183 })
4184 testCases = append(testCases, testCase{
4185 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4186 flags: []string{
4187 "-max-version", strconv.Itoa(VersionTLS12),
4188 "-fallback-version", strconv.Itoa(VersionTLS12),
4189 },
4190 })
4191
4192 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4193 // just have such connections fail than risk getting confused because we
4194 // didn't sent the 1.3 ClientHello.)
4195 testCases = append(testCases, testCase{
4196 name: "Downgrade-TLS12-Fallback-CheckVersion",
4197 config: Config{
4198 Bugs: ProtocolBugs{
4199 NegotiateVersion: VersionTLS13,
4200 FailIfNotFallbackSCSV: true,
4201 },
4202 },
4203 flags: []string{
4204 "-max-version", strconv.Itoa(VersionTLS13),
4205 "-fallback-version", strconv.Itoa(VersionTLS12),
4206 },
4207 shouldFail: true,
4208 expectedError: ":UNSUPPORTED_PROTOCOL:",
4209 })
4210
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004211}
4212
David Benjaminaccb4542014-12-12 23:44:33 -05004213func addMinimumVersionTests() {
4214 for i, shimVers := range tlsVersions {
4215 // Assemble flags to disable all older versions on the shim.
4216 var flags []string
4217 for _, vers := range tlsVersions[:i] {
4218 flags = append(flags, vers.flag)
4219 }
4220
4221 for _, runnerVers := range tlsVersions {
4222 protocols := []protocol{tls}
4223 if runnerVers.hasDTLS && shimVers.hasDTLS {
4224 protocols = append(protocols, dtls)
4225 }
4226 for _, protocol := range protocols {
4227 suffix := shimVers.name + "-" + runnerVers.name
4228 if protocol == dtls {
4229 suffix += "-DTLS"
4230 }
4231 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4232
David Benjaminaccb4542014-12-12 23:44:33 -05004233 var expectedVersion uint16
4234 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004235 var expectedClientError, expectedServerError string
4236 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004237 if runnerVers.version >= shimVers.version {
4238 expectedVersion = runnerVers.version
4239 } else {
4240 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004241 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4242 expectedServerLocalError = "remote error: protocol version not supported"
4243 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4244 // If the client's minimum version is TLS 1.3 and the runner's
4245 // maximum is below TLS 1.2, the runner will fail to select a
4246 // cipher before the shim rejects the selected version.
4247 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4248 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4249 } else {
4250 expectedClientError = expectedServerError
4251 expectedClientLocalError = expectedServerLocalError
4252 }
David Benjaminaccb4542014-12-12 23:44:33 -05004253 }
4254
4255 testCases = append(testCases, testCase{
4256 protocol: protocol,
4257 testType: clientTest,
4258 name: "MinimumVersion-Client-" + suffix,
4259 config: Config{
4260 MaxVersion: runnerVers.version,
4261 },
David Benjamin87909c02014-12-13 01:55:01 -05004262 flags: flags,
4263 expectedVersion: expectedVersion,
4264 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004265 expectedError: expectedClientError,
4266 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004267 })
4268 testCases = append(testCases, testCase{
4269 protocol: protocol,
4270 testType: clientTest,
4271 name: "MinimumVersion-Client2-" + suffix,
4272 config: Config{
4273 MaxVersion: runnerVers.version,
4274 },
David Benjamin87909c02014-12-13 01:55:01 -05004275 flags: []string{"-min-version", shimVersFlag},
4276 expectedVersion: expectedVersion,
4277 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004278 expectedError: expectedClientError,
4279 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004280 })
4281
4282 testCases = append(testCases, testCase{
4283 protocol: protocol,
4284 testType: serverTest,
4285 name: "MinimumVersion-Server-" + suffix,
4286 config: Config{
4287 MaxVersion: runnerVers.version,
4288 },
David Benjamin87909c02014-12-13 01:55:01 -05004289 flags: flags,
4290 expectedVersion: expectedVersion,
4291 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004292 expectedError: expectedServerError,
4293 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004294 })
4295 testCases = append(testCases, testCase{
4296 protocol: protocol,
4297 testType: serverTest,
4298 name: "MinimumVersion-Server2-" + suffix,
4299 config: Config{
4300 MaxVersion: runnerVers.version,
4301 },
David Benjamin87909c02014-12-13 01:55:01 -05004302 flags: []string{"-min-version", shimVersFlag},
4303 expectedVersion: expectedVersion,
4304 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004305 expectedError: expectedServerError,
4306 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004307 })
4308 }
4309 }
4310 }
4311}
4312
David Benjamine78bfde2014-09-06 12:45:15 -04004313func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004314 // TODO(davidben): Extensions, where applicable, all move their server
4315 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4316 // tests for both. Also test interaction with 0-RTT when implemented.
4317
David Benjamin97d17d92016-07-14 16:12:00 -04004318 // Repeat extensions tests all versions except SSL 3.0.
4319 for _, ver := range tlsVersions {
4320 if ver.version == VersionSSL30 {
4321 continue
4322 }
4323
David Benjamin97d17d92016-07-14 16:12:00 -04004324 // Test that duplicate extensions are rejected.
4325 testCases = append(testCases, testCase{
4326 testType: clientTest,
4327 name: "DuplicateExtensionClient-" + ver.name,
4328 config: Config{
4329 MaxVersion: ver.version,
4330 Bugs: ProtocolBugs{
4331 DuplicateExtension: true,
4332 },
David Benjamine78bfde2014-09-06 12:45:15 -04004333 },
David Benjamin97d17d92016-07-14 16:12:00 -04004334 shouldFail: true,
4335 expectedLocalError: "remote error: error decoding message",
4336 })
4337 testCases = append(testCases, testCase{
4338 testType: serverTest,
4339 name: "DuplicateExtensionServer-" + ver.name,
4340 config: Config{
4341 MaxVersion: ver.version,
4342 Bugs: ProtocolBugs{
4343 DuplicateExtension: true,
4344 },
David Benjamine78bfde2014-09-06 12:45:15 -04004345 },
David Benjamin97d17d92016-07-14 16:12:00 -04004346 shouldFail: true,
4347 expectedLocalError: "remote error: error decoding message",
4348 })
4349
4350 // Test SNI.
4351 testCases = append(testCases, testCase{
4352 testType: clientTest,
4353 name: "ServerNameExtensionClient-" + ver.name,
4354 config: Config{
4355 MaxVersion: ver.version,
4356 Bugs: ProtocolBugs{
4357 ExpectServerName: "example.com",
4358 },
David Benjamine78bfde2014-09-06 12:45:15 -04004359 },
David Benjamin97d17d92016-07-14 16:12:00 -04004360 flags: []string{"-host-name", "example.com"},
4361 })
4362 testCases = append(testCases, testCase{
4363 testType: clientTest,
4364 name: "ServerNameExtensionClientMismatch-" + ver.name,
4365 config: Config{
4366 MaxVersion: ver.version,
4367 Bugs: ProtocolBugs{
4368 ExpectServerName: "mismatch.com",
4369 },
David Benjamine78bfde2014-09-06 12:45:15 -04004370 },
David Benjamin97d17d92016-07-14 16:12:00 -04004371 flags: []string{"-host-name", "example.com"},
4372 shouldFail: true,
4373 expectedLocalError: "tls: unexpected server name",
4374 })
4375 testCases = append(testCases, testCase{
4376 testType: clientTest,
4377 name: "ServerNameExtensionClientMissing-" + ver.name,
4378 config: Config{
4379 MaxVersion: ver.version,
4380 Bugs: ProtocolBugs{
4381 ExpectServerName: "missing.com",
4382 },
David Benjamine78bfde2014-09-06 12:45:15 -04004383 },
David Benjamin97d17d92016-07-14 16:12:00 -04004384 shouldFail: true,
4385 expectedLocalError: "tls: unexpected server name",
4386 })
4387 testCases = append(testCases, testCase{
4388 testType: serverTest,
4389 name: "ServerNameExtensionServer-" + ver.name,
4390 config: Config{
4391 MaxVersion: ver.version,
4392 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004393 },
David Benjamin97d17d92016-07-14 16:12:00 -04004394 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004395 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004396 })
4397
4398 // Test ALPN.
4399 testCases = append(testCases, testCase{
4400 testType: clientTest,
4401 name: "ALPNClient-" + ver.name,
4402 config: Config{
4403 MaxVersion: ver.version,
4404 NextProtos: []string{"foo"},
4405 },
4406 flags: []string{
4407 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4408 "-expect-alpn", "foo",
4409 },
4410 expectedNextProto: "foo",
4411 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004412 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004413 })
4414 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004415 testType: clientTest,
4416 name: "ALPNClient-Mismatch-" + ver.name,
4417 config: Config{
4418 MaxVersion: ver.version,
4419 Bugs: ProtocolBugs{
4420 SendALPN: "baz",
4421 },
4422 },
4423 flags: []string{
4424 "-advertise-alpn", "\x03foo\x03bar",
4425 },
4426 shouldFail: true,
4427 expectedError: ":INVALID_ALPN_PROTOCOL:",
4428 expectedLocalError: "remote error: illegal parameter",
4429 })
4430 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004431 testType: serverTest,
4432 name: "ALPNServer-" + ver.name,
4433 config: Config{
4434 MaxVersion: ver.version,
4435 NextProtos: []string{"foo", "bar", "baz"},
4436 },
4437 flags: []string{
4438 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4439 "-select-alpn", "foo",
4440 },
4441 expectedNextProto: "foo",
4442 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004443 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004444 })
4445 testCases = append(testCases, testCase{
4446 testType: serverTest,
4447 name: "ALPNServer-Decline-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo", "bar", "baz"},
4451 },
4452 flags: []string{"-decline-alpn"},
4453 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004454 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004455 })
4456
David Benjamin25fe85b2016-08-09 20:00:32 -04004457 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4458 // called once.
4459 testCases = append(testCases, testCase{
4460 testType: serverTest,
4461 name: "ALPNServer-Async-" + ver.name,
4462 config: Config{
4463 MaxVersion: ver.version,
4464 NextProtos: []string{"foo", "bar", "baz"},
4465 },
4466 flags: []string{
4467 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4468 "-select-alpn", "foo",
4469 "-async",
4470 },
4471 expectedNextProto: "foo",
4472 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004473 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004474 })
4475
David Benjamin97d17d92016-07-14 16:12:00 -04004476 var emptyString string
4477 testCases = append(testCases, testCase{
4478 testType: clientTest,
4479 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4480 config: Config{
4481 MaxVersion: ver.version,
4482 NextProtos: []string{""},
4483 Bugs: ProtocolBugs{
4484 // A server returning an empty ALPN protocol
4485 // should be rejected.
4486 ALPNProtocol: &emptyString,
4487 },
4488 },
4489 flags: []string{
4490 "-advertise-alpn", "\x03foo",
4491 },
4492 shouldFail: true,
4493 expectedError: ":PARSE_TLSEXT:",
4494 })
4495 testCases = append(testCases, testCase{
4496 testType: serverTest,
4497 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4498 config: Config{
4499 MaxVersion: ver.version,
4500 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004501 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004502 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004503 },
David Benjamin97d17d92016-07-14 16:12:00 -04004504 flags: []string{
4505 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004506 },
David Benjamin97d17d92016-07-14 16:12:00 -04004507 shouldFail: true,
4508 expectedError: ":PARSE_TLSEXT:",
4509 })
4510
4511 // Test NPN and the interaction with ALPN.
4512 if ver.version < VersionTLS13 {
4513 // Test that the server prefers ALPN over NPN.
4514 testCases = append(testCases, testCase{
4515 testType: serverTest,
4516 name: "ALPNServer-Preferred-" + ver.name,
4517 config: Config{
4518 MaxVersion: ver.version,
4519 NextProtos: []string{"foo", "bar", "baz"},
4520 },
4521 flags: []string{
4522 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4523 "-select-alpn", "foo",
4524 "-advertise-npn", "\x03foo\x03bar\x03baz",
4525 },
4526 expectedNextProto: "foo",
4527 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004528 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004529 })
4530 testCases = append(testCases, testCase{
4531 testType: serverTest,
4532 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4533 config: Config{
4534 MaxVersion: ver.version,
4535 NextProtos: []string{"foo", "bar", "baz"},
4536 Bugs: ProtocolBugs{
4537 SwapNPNAndALPN: true,
4538 },
4539 },
4540 flags: []string{
4541 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4542 "-select-alpn", "foo",
4543 "-advertise-npn", "\x03foo\x03bar\x03baz",
4544 },
4545 expectedNextProto: "foo",
4546 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004547 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004548 })
4549
4550 // Test that negotiating both NPN and ALPN is forbidden.
4551 testCases = append(testCases, testCase{
4552 name: "NegotiateALPNAndNPN-" + ver.name,
4553 config: Config{
4554 MaxVersion: ver.version,
4555 NextProtos: []string{"foo", "bar", "baz"},
4556 Bugs: ProtocolBugs{
4557 NegotiateALPNAndNPN: true,
4558 },
4559 },
4560 flags: []string{
4561 "-advertise-alpn", "\x03foo",
4562 "-select-next-proto", "foo",
4563 },
4564 shouldFail: true,
4565 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4566 })
4567 testCases = append(testCases, testCase{
4568 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4569 config: Config{
4570 MaxVersion: ver.version,
4571 NextProtos: []string{"foo", "bar", "baz"},
4572 Bugs: ProtocolBugs{
4573 NegotiateALPNAndNPN: true,
4574 SwapNPNAndALPN: true,
4575 },
4576 },
4577 flags: []string{
4578 "-advertise-alpn", "\x03foo",
4579 "-select-next-proto", "foo",
4580 },
4581 shouldFail: true,
4582 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4583 })
4584
4585 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4586 testCases = append(testCases, testCase{
4587 name: "DisableNPN-" + ver.name,
4588 config: Config{
4589 MaxVersion: ver.version,
4590 NextProtos: []string{"foo"},
4591 },
4592 flags: []string{
4593 "-select-next-proto", "foo",
4594 "-disable-npn",
4595 },
4596 expectNoNextProto: true,
4597 })
4598 }
4599
4600 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004601
4602 // Resume with a corrupt ticket.
4603 testCases = append(testCases, testCase{
4604 testType: serverTest,
4605 name: "CorruptTicket-" + ver.name,
4606 config: Config{
4607 MaxVersion: ver.version,
4608 Bugs: ProtocolBugs{
4609 CorruptTicket: true,
4610 },
4611 },
4612 resumeSession: true,
4613 expectResumeRejected: true,
4614 })
4615 // Test the ticket callback, with and without renewal.
4616 testCases = append(testCases, testCase{
4617 testType: serverTest,
4618 name: "TicketCallback-" + ver.name,
4619 config: Config{
4620 MaxVersion: ver.version,
4621 },
4622 resumeSession: true,
4623 flags: []string{"-use-ticket-callback"},
4624 })
4625 testCases = append(testCases, testCase{
4626 testType: serverTest,
4627 name: "TicketCallback-Renew-" + ver.name,
4628 config: Config{
4629 MaxVersion: ver.version,
4630 Bugs: ProtocolBugs{
4631 ExpectNewTicket: true,
4632 },
4633 },
4634 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4635 resumeSession: true,
4636 })
4637
4638 // Test that the ticket callback is only called once when everything before
4639 // it in the ClientHello is asynchronous. This corrupts the ticket so
4640 // certificate selection callbacks run.
4641 testCases = append(testCases, testCase{
4642 testType: serverTest,
4643 name: "TicketCallback-SingleCall-" + ver.name,
4644 config: Config{
4645 MaxVersion: ver.version,
4646 Bugs: ProtocolBugs{
4647 CorruptTicket: true,
4648 },
4649 },
4650 resumeSession: true,
4651 expectResumeRejected: true,
4652 flags: []string{
4653 "-use-ticket-callback",
4654 "-async",
4655 },
4656 })
4657
4658 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004659 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004660 testCases = append(testCases, testCase{
4661 testType: serverTest,
4662 name: "OversizedSessionId-" + ver.name,
4663 config: Config{
4664 MaxVersion: ver.version,
4665 Bugs: ProtocolBugs{
4666 OversizedSessionId: true,
4667 },
4668 },
4669 resumeSession: true,
4670 shouldFail: true,
4671 expectedError: ":DECODE_ERROR:",
4672 })
4673 }
4674
4675 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4676 // are ignored.
4677 if ver.hasDTLS {
4678 testCases = append(testCases, testCase{
4679 protocol: dtls,
4680 name: "SRTP-Client-" + ver.name,
4681 config: Config{
4682 MaxVersion: ver.version,
4683 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4684 },
4685 flags: []string{
4686 "-srtp-profiles",
4687 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4688 },
4689 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4690 })
4691 testCases = append(testCases, testCase{
4692 protocol: dtls,
4693 testType: serverTest,
4694 name: "SRTP-Server-" + ver.name,
4695 config: Config{
4696 MaxVersion: ver.version,
4697 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4698 },
4699 flags: []string{
4700 "-srtp-profiles",
4701 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4702 },
4703 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4704 })
4705 // Test that the MKI is ignored.
4706 testCases = append(testCases, testCase{
4707 protocol: dtls,
4708 testType: serverTest,
4709 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4710 config: Config{
4711 MaxVersion: ver.version,
4712 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4713 Bugs: ProtocolBugs{
4714 SRTPMasterKeyIdentifer: "bogus",
4715 },
4716 },
4717 flags: []string{
4718 "-srtp-profiles",
4719 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4720 },
4721 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4722 })
4723 // Test that SRTP isn't negotiated on the server if there were
4724 // no matching profiles.
4725 testCases = append(testCases, testCase{
4726 protocol: dtls,
4727 testType: serverTest,
4728 name: "SRTP-Server-NoMatch-" + ver.name,
4729 config: Config{
4730 MaxVersion: ver.version,
4731 SRTPProtectionProfiles: []uint16{100, 101, 102},
4732 },
4733 flags: []string{
4734 "-srtp-profiles",
4735 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4736 },
4737 expectedSRTPProtectionProfile: 0,
4738 })
4739 // Test that the server returning an invalid SRTP profile is
4740 // flagged as an error by the client.
4741 testCases = append(testCases, testCase{
4742 protocol: dtls,
4743 name: "SRTP-Client-NoMatch-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4748 },
4749 },
4750 flags: []string{
4751 "-srtp-profiles",
4752 "SRTP_AES128_CM_SHA1_80",
4753 },
4754 shouldFail: true,
4755 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4756 })
4757 }
4758
4759 // Test SCT list.
4760 testCases = append(testCases, testCase{
4761 name: "SignedCertificateTimestampList-Client-" + ver.name,
4762 testType: clientTest,
4763 config: Config{
4764 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004765 },
David Benjamin97d17d92016-07-14 16:12:00 -04004766 flags: []string{
4767 "-enable-signed-cert-timestamps",
4768 "-expect-signed-cert-timestamps",
4769 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004770 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004771 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004772 })
4773 testCases = append(testCases, testCase{
4774 name: "SendSCTListOnResume-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 Bugs: ProtocolBugs{
4778 SendSCTListOnResume: []byte("bogus"),
4779 },
David Benjamind98452d2015-06-16 14:16:23 -04004780 },
David Benjamin97d17d92016-07-14 16:12:00 -04004781 flags: []string{
4782 "-enable-signed-cert-timestamps",
4783 "-expect-signed-cert-timestamps",
4784 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004785 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004786 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004787 })
4788 testCases = append(testCases, testCase{
4789 name: "SignedCertificateTimestampList-Server-" + ver.name,
4790 testType: serverTest,
4791 config: Config{
4792 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004793 },
David Benjamin97d17d92016-07-14 16:12:00 -04004794 flags: []string{
4795 "-signed-cert-timestamps",
4796 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004797 },
David Benjamin97d17d92016-07-14 16:12:00 -04004798 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004799 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004800 })
4801 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004802
Paul Lietar4fac72e2015-09-09 13:44:55 +01004803 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004804 testType: clientTest,
4805 name: "ClientHelloPadding",
4806 config: Config{
4807 Bugs: ProtocolBugs{
4808 RequireClientHelloSize: 512,
4809 },
4810 },
4811 // This hostname just needs to be long enough to push the
4812 // ClientHello into F5's danger zone between 256 and 511 bytes
4813 // long.
4814 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4815 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004816
4817 // Extensions should not function in SSL 3.0.
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
4820 name: "SSLv3Extensions-NoALPN",
4821 config: Config{
4822 MaxVersion: VersionSSL30,
4823 NextProtos: []string{"foo", "bar", "baz"},
4824 },
4825 flags: []string{
4826 "-select-alpn", "foo",
4827 },
4828 expectNoNextProto: true,
4829 })
4830
4831 // Test session tickets separately as they follow a different codepath.
4832 testCases = append(testCases, testCase{
4833 testType: serverTest,
4834 name: "SSLv3Extensions-NoTickets",
4835 config: Config{
4836 MaxVersion: VersionSSL30,
4837 Bugs: ProtocolBugs{
4838 // Historically, session tickets in SSL 3.0
4839 // failed in different ways depending on whether
4840 // the client supported renegotiation_info.
4841 NoRenegotiationInfo: true,
4842 },
4843 },
4844 resumeSession: true,
4845 })
4846 testCases = append(testCases, testCase{
4847 testType: serverTest,
4848 name: "SSLv3Extensions-NoTickets2",
4849 config: Config{
4850 MaxVersion: VersionSSL30,
4851 },
4852 resumeSession: true,
4853 })
4854
4855 // But SSL 3.0 does send and process renegotiation_info.
4856 testCases = append(testCases, testCase{
4857 testType: serverTest,
4858 name: "SSLv3Extensions-RenegotiationInfo",
4859 config: Config{
4860 MaxVersion: VersionSSL30,
4861 Bugs: ProtocolBugs{
4862 RequireRenegotiationInfo: true,
4863 },
4864 },
4865 })
4866 testCases = append(testCases, testCase{
4867 testType: serverTest,
4868 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4869 config: Config{
4870 MaxVersion: VersionSSL30,
4871 Bugs: ProtocolBugs{
4872 NoRenegotiationInfo: true,
4873 SendRenegotiationSCSV: true,
4874 RequireRenegotiationInfo: true,
4875 },
4876 },
4877 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004878
4879 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4880 // in ServerHello.
4881 testCases = append(testCases, testCase{
4882 name: "NPN-Forbidden-TLS13",
4883 config: Config{
4884 MaxVersion: VersionTLS13,
4885 NextProtos: []string{"foo"},
4886 Bugs: ProtocolBugs{
4887 NegotiateNPNAtAllVersions: true,
4888 },
4889 },
4890 flags: []string{"-select-next-proto", "foo"},
4891 shouldFail: true,
4892 expectedError: ":ERROR_PARSING_EXTENSION:",
4893 })
4894 testCases = append(testCases, testCase{
4895 name: "EMS-Forbidden-TLS13",
4896 config: Config{
4897 MaxVersion: VersionTLS13,
4898 Bugs: ProtocolBugs{
4899 NegotiateEMSAtAllVersions: true,
4900 },
4901 },
4902 shouldFail: true,
4903 expectedError: ":ERROR_PARSING_EXTENSION:",
4904 })
4905 testCases = append(testCases, testCase{
4906 name: "RenegotiationInfo-Forbidden-TLS13",
4907 config: Config{
4908 MaxVersion: VersionTLS13,
4909 Bugs: ProtocolBugs{
4910 NegotiateRenegotiationInfoAtAllVersions: true,
4911 },
4912 },
4913 shouldFail: true,
4914 expectedError: ":ERROR_PARSING_EXTENSION:",
4915 })
4916 testCases = append(testCases, testCase{
4917 name: "ChannelID-Forbidden-TLS13",
4918 config: Config{
4919 MaxVersion: VersionTLS13,
4920 RequestChannelID: true,
4921 Bugs: ProtocolBugs{
4922 NegotiateChannelIDAtAllVersions: true,
4923 },
4924 },
4925 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4926 shouldFail: true,
4927 expectedError: ":ERROR_PARSING_EXTENSION:",
4928 })
4929 testCases = append(testCases, testCase{
4930 name: "Ticket-Forbidden-TLS13",
4931 config: Config{
4932 MaxVersion: VersionTLS12,
4933 },
4934 resumeConfig: &Config{
4935 MaxVersion: VersionTLS13,
4936 Bugs: ProtocolBugs{
4937 AdvertiseTicketExtension: true,
4938 },
4939 },
4940 resumeSession: true,
4941 shouldFail: true,
4942 expectedError: ":ERROR_PARSING_EXTENSION:",
4943 })
4944
4945 // Test that illegal extensions in TLS 1.3 are declined by the server if
4946 // offered in ClientHello. The runner's server will fail if this occurs,
4947 // so we exercise the offering path. (EMS and Renegotiation Info are
4948 // implicit in every test.)
4949 testCases = append(testCases, testCase{
4950 testType: serverTest,
4951 name: "ChannelID-Declined-TLS13",
4952 config: Config{
4953 MaxVersion: VersionTLS13,
4954 ChannelID: channelIDKey,
4955 },
4956 flags: []string{"-enable-channel-id"},
4957 })
4958 testCases = append(testCases, testCase{
4959 testType: serverTest,
4960 name: "NPN-Server",
4961 config: Config{
4962 MaxVersion: VersionTLS13,
4963 NextProtos: []string{"bar"},
4964 },
4965 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4966 })
David Benjamine78bfde2014-09-06 12:45:15 -04004967}
4968
David Benjamin01fe8202014-09-24 15:21:44 -04004969func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004970 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004971 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004972 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4973 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4974 // TLS 1.3 only shares ciphers with TLS 1.2, so
4975 // we skip certain combinations and use a
4976 // different cipher to test with.
4977 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4978 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4979 continue
4980 }
4981 }
4982
David Benjamin8b8c0062014-11-23 02:47:52 -05004983 protocols := []protocol{tls}
4984 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4985 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004986 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004987 for _, protocol := range protocols {
4988 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4989 if protocol == dtls {
4990 suffix += "-DTLS"
4991 }
4992
David Benjaminece3de92015-03-16 18:02:20 -04004993 if sessionVers.version == resumeVers.version {
4994 testCases = append(testCases, testCase{
4995 protocol: protocol,
4996 name: "Resume-Client" + suffix,
4997 resumeSession: true,
4998 config: Config{
4999 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005000 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005001 Bugs: ProtocolBugs{
5002 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5003 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5004 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005005 },
David Benjaminece3de92015-03-16 18:02:20 -04005006 expectedVersion: sessionVers.version,
5007 expectedResumeVersion: resumeVers.version,
5008 })
5009 } else {
David Benjamin405da482016-08-08 17:25:07 -04005010 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5011
5012 // Offering a TLS 1.3 session sends an empty session ID, so
5013 // there is no way to convince a non-lookahead client the
5014 // session was resumed. It will appear to the client that a
5015 // stray ChangeCipherSpec was sent.
5016 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5017 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005018 }
5019
David Benjaminece3de92015-03-16 18:02:20 -04005020 testCases = append(testCases, testCase{
5021 protocol: protocol,
5022 name: "Resume-Client-Mismatch" + suffix,
5023 resumeSession: true,
5024 config: Config{
5025 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005026 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005027 },
David Benjaminece3de92015-03-16 18:02:20 -04005028 expectedVersion: sessionVers.version,
5029 resumeConfig: &Config{
5030 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005031 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005032 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005033 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005034 },
5035 },
5036 expectedResumeVersion: resumeVers.version,
5037 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005038 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005039 })
5040 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005041
5042 testCases = append(testCases, testCase{
5043 protocol: protocol,
5044 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005045 resumeSession: true,
5046 config: Config{
5047 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005048 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005049 },
5050 expectedVersion: sessionVers.version,
5051 resumeConfig: &Config{
5052 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005053 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005054 },
5055 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005056 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005057 expectedResumeVersion: resumeVers.version,
5058 })
5059
David Benjamin8b8c0062014-11-23 02:47:52 -05005060 testCases = append(testCases, testCase{
5061 protocol: protocol,
5062 testType: serverTest,
5063 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 resumeSession: true,
5065 config: Config{
5066 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005067 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005068 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005069 expectedVersion: sessionVers.version,
5070 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005071 resumeConfig: &Config{
5072 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005073 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005074 Bugs: ProtocolBugs{
5075 SendBothTickets: true,
5076 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 },
5078 expectedResumeVersion: resumeVers.version,
5079 })
5080 }
David Benjamin01fe8202014-09-24 15:21:44 -04005081 }
5082 }
David Benjaminece3de92015-03-16 18:02:20 -04005083
5084 testCases = append(testCases, testCase{
5085 name: "Resume-Client-CipherMismatch",
5086 resumeSession: true,
5087 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005088 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005089 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5090 },
5091 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005092 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005093 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5094 Bugs: ProtocolBugs{
5095 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5096 },
5097 },
5098 shouldFail: true,
5099 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5100 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005101
5102 testCases = append(testCases, testCase{
5103 name: "Resume-Client-CipherMismatch-TLS13",
5104 resumeSession: true,
5105 config: Config{
5106 MaxVersion: VersionTLS13,
5107 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5108 },
5109 resumeConfig: &Config{
5110 MaxVersion: VersionTLS13,
5111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5112 Bugs: ProtocolBugs{
5113 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5114 },
5115 },
5116 shouldFail: true,
5117 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5118 })
David Benjamin01fe8202014-09-24 15:21:44 -04005119}
5120
Adam Langley2ae77d22014-10-28 17:29:33 -07005121func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005122 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005123 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005124 testType: serverTest,
5125 name: "Renegotiate-Server-Forbidden",
5126 config: Config{
5127 MaxVersion: VersionTLS12,
5128 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005129 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005130 shouldFail: true,
5131 expectedError: ":NO_RENEGOTIATION:",
5132 expectedLocalError: "remote error: no renegotiation",
5133 })
Adam Langley5021b222015-06-12 18:27:58 -07005134 // The server shouldn't echo the renegotiation extension unless
5135 // requested by the client.
5136 testCases = append(testCases, testCase{
5137 testType: serverTest,
5138 name: "Renegotiate-Server-NoExt",
5139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005140 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005141 Bugs: ProtocolBugs{
5142 NoRenegotiationInfo: true,
5143 RequireRenegotiationInfo: true,
5144 },
5145 },
5146 shouldFail: true,
5147 expectedLocalError: "renegotiation extension missing",
5148 })
5149 // The renegotiation SCSV should be sufficient for the server to echo
5150 // the extension.
5151 testCases = append(testCases, testCase{
5152 testType: serverTest,
5153 name: "Renegotiate-Server-NoExt-SCSV",
5154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005155 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005156 Bugs: ProtocolBugs{
5157 NoRenegotiationInfo: true,
5158 SendRenegotiationSCSV: true,
5159 RequireRenegotiationInfo: true,
5160 },
5161 },
5162 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005163 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005164 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005166 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005167 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005168 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005169 },
5170 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005171 renegotiate: 1,
5172 flags: []string{
5173 "-renegotiate-freely",
5174 "-expect-total-renegotiations", "1",
5175 },
David Benjamincdea40c2015-03-19 14:09:43 -04005176 })
5177 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005178 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005179 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005181 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005182 Bugs: ProtocolBugs{
5183 EmptyRenegotiationInfo: true,
5184 },
5185 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005186 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005187 shouldFail: true,
5188 expectedError: ":RENEGOTIATION_MISMATCH:",
5189 })
5190 testCases = append(testCases, testCase{
5191 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005192 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005194 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005195 Bugs: ProtocolBugs{
5196 BadRenegotiationInfo: true,
5197 },
5198 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005199 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005200 shouldFail: true,
5201 expectedError: ":RENEGOTIATION_MISMATCH:",
5202 })
5203 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005204 name: "Renegotiate-Client-Downgrade",
5205 renegotiate: 1,
5206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005207 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005208 Bugs: ProtocolBugs{
5209 NoRenegotiationInfoAfterInitial: true,
5210 },
5211 },
5212 flags: []string{"-renegotiate-freely"},
5213 shouldFail: true,
5214 expectedError: ":RENEGOTIATION_MISMATCH:",
5215 })
5216 testCases = append(testCases, testCase{
5217 name: "Renegotiate-Client-Upgrade",
5218 renegotiate: 1,
5219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005220 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005221 Bugs: ProtocolBugs{
5222 NoRenegotiationInfoInInitial: true,
5223 },
5224 },
5225 flags: []string{"-renegotiate-freely"},
5226 shouldFail: true,
5227 expectedError: ":RENEGOTIATION_MISMATCH:",
5228 })
5229 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005230 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005231 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005232 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005233 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005234 Bugs: ProtocolBugs{
5235 NoRenegotiationInfo: true,
5236 },
5237 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238 flags: []string{
5239 "-renegotiate-freely",
5240 "-expect-total-renegotiations", "1",
5241 },
David Benjamincff0b902015-05-15 23:09:47 -04005242 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005243
5244 // Test that the server may switch ciphers on renegotiation without
5245 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005246 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005247 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005248 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005249 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005250 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005251 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005252 },
5253 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005254 flags: []string{
5255 "-renegotiate-freely",
5256 "-expect-total-renegotiations", "1",
5257 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005258 })
5259 testCases = append(testCases, testCase{
5260 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005261 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005262 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005263 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005264 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5265 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005266 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005267 flags: []string{
5268 "-renegotiate-freely",
5269 "-expect-total-renegotiations", "1",
5270 },
David Benjaminb16346b2015-04-08 19:16:58 -04005271 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005272
5273 // Test that the server may not switch versions on renegotiation.
5274 testCases = append(testCases, testCase{
5275 name: "Renegotiate-Client-SwitchVersion",
5276 config: Config{
5277 MaxVersion: VersionTLS12,
5278 // Pick a cipher which exists at both versions.
5279 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5280 Bugs: ProtocolBugs{
5281 NegotiateVersionOnRenego: VersionTLS11,
5282 },
5283 },
5284 renegotiate: 1,
5285 flags: []string{
5286 "-renegotiate-freely",
5287 "-expect-total-renegotiations", "1",
5288 },
5289 shouldFail: true,
5290 expectedError: ":WRONG_SSL_VERSION:",
5291 })
5292
David Benjaminb16346b2015-04-08 19:16:58 -04005293 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005294 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005295 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005296 config: Config{
5297 MaxVersion: VersionTLS10,
5298 Bugs: ProtocolBugs{
5299 RequireSameRenegoClientVersion: true,
5300 },
5301 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005302 flags: []string{
5303 "-renegotiate-freely",
5304 "-expect-total-renegotiations", "1",
5305 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005306 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005307 testCases = append(testCases, testCase{
5308 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005309 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005310 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005311 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5313 NextProtos: []string{"foo"},
5314 },
5315 flags: []string{
5316 "-false-start",
5317 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005318 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005319 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005320 },
5321 shimWritesFirst: true,
5322 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005323
5324 // Client-side renegotiation controls.
5325 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005326 name: "Renegotiate-Client-Forbidden-1",
5327 config: Config{
5328 MaxVersion: VersionTLS12,
5329 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005330 renegotiate: 1,
5331 shouldFail: true,
5332 expectedError: ":NO_RENEGOTIATION:",
5333 expectedLocalError: "remote error: no renegotiation",
5334 })
5335 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005336 name: "Renegotiate-Client-Once-1",
5337 config: Config{
5338 MaxVersion: VersionTLS12,
5339 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005340 renegotiate: 1,
5341 flags: []string{
5342 "-renegotiate-once",
5343 "-expect-total-renegotiations", "1",
5344 },
5345 })
5346 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005347 name: "Renegotiate-Client-Freely-1",
5348 config: Config{
5349 MaxVersion: VersionTLS12,
5350 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005351 renegotiate: 1,
5352 flags: []string{
5353 "-renegotiate-freely",
5354 "-expect-total-renegotiations", "1",
5355 },
5356 })
5357 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005358 name: "Renegotiate-Client-Once-2",
5359 config: Config{
5360 MaxVersion: VersionTLS12,
5361 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005362 renegotiate: 2,
5363 flags: []string{"-renegotiate-once"},
5364 shouldFail: true,
5365 expectedError: ":NO_RENEGOTIATION:",
5366 expectedLocalError: "remote error: no renegotiation",
5367 })
5368 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005369 name: "Renegotiate-Client-Freely-2",
5370 config: Config{
5371 MaxVersion: VersionTLS12,
5372 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005373 renegotiate: 2,
5374 flags: []string{
5375 "-renegotiate-freely",
5376 "-expect-total-renegotiations", "2",
5377 },
5378 })
Adam Langley27a0d082015-11-03 13:34:10 -08005379 testCases = append(testCases, testCase{
5380 name: "Renegotiate-Client-NoIgnore",
5381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005382 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005383 Bugs: ProtocolBugs{
5384 SendHelloRequestBeforeEveryAppDataRecord: true,
5385 },
5386 },
5387 shouldFail: true,
5388 expectedError: ":NO_RENEGOTIATION:",
5389 })
5390 testCases = append(testCases, testCase{
5391 name: "Renegotiate-Client-Ignore",
5392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005393 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005394 Bugs: ProtocolBugs{
5395 SendHelloRequestBeforeEveryAppDataRecord: true,
5396 },
5397 },
5398 flags: []string{
5399 "-renegotiate-ignore",
5400 "-expect-total-renegotiations", "0",
5401 },
5402 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005403
David Benjamin397c8e62016-07-08 14:14:36 -07005404 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005405 testCases = append(testCases, testCase{
5406 name: "StrayHelloRequest",
5407 config: Config{
5408 MaxVersion: VersionTLS12,
5409 Bugs: ProtocolBugs{
5410 SendHelloRequestBeforeEveryHandshakeMessage: true,
5411 },
5412 },
5413 })
5414 testCases = append(testCases, testCase{
5415 name: "StrayHelloRequest-Packed",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 Bugs: ProtocolBugs{
5419 PackHandshakeFlight: true,
5420 SendHelloRequestBeforeEveryHandshakeMessage: true,
5421 },
5422 },
5423 })
5424
David Benjamin12d2c482016-07-24 10:56:51 -04005425 // Test renegotiation works if HelloRequest and server Finished come in
5426 // the same record.
5427 testCases = append(testCases, testCase{
5428 name: "Renegotiate-Client-Packed",
5429 config: Config{
5430 MaxVersion: VersionTLS12,
5431 Bugs: ProtocolBugs{
5432 PackHandshakeFlight: true,
5433 PackHelloRequestWithFinished: true,
5434 },
5435 },
5436 renegotiate: 1,
5437 flags: []string{
5438 "-renegotiate-freely",
5439 "-expect-total-renegotiations", "1",
5440 },
5441 })
5442
David Benjamin397c8e62016-07-08 14:14:36 -07005443 // Renegotiation is forbidden in TLS 1.3.
5444 testCases = append(testCases, testCase{
5445 name: "Renegotiate-Client-TLS13",
5446 config: Config{
5447 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005448 Bugs: ProtocolBugs{
5449 SendHelloRequestBeforeEveryAppDataRecord: true,
5450 },
David Benjamin397c8e62016-07-08 14:14:36 -07005451 },
David Benjamin397c8e62016-07-08 14:14:36 -07005452 flags: []string{
5453 "-renegotiate-freely",
5454 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005455 shouldFail: true,
5456 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005457 })
5458
5459 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5460 testCases = append(testCases, testCase{
5461 name: "StrayHelloRequest-TLS13",
5462 config: Config{
5463 MaxVersion: VersionTLS13,
5464 Bugs: ProtocolBugs{
5465 SendHelloRequestBeforeEveryHandshakeMessage: true,
5466 },
5467 },
5468 shouldFail: true,
5469 expectedError: ":UNEXPECTED_MESSAGE:",
5470 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005471}
5472
David Benjamin5e961c12014-11-07 01:48:35 -05005473func addDTLSReplayTests() {
5474 // Test that sequence number replays are detected.
5475 testCases = append(testCases, testCase{
5476 protocol: dtls,
5477 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005478 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005479 replayWrites: true,
5480 })
5481
David Benjamin8e6db492015-07-25 18:29:23 -04005482 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005483 // than the retransmit window.
5484 testCases = append(testCases, testCase{
5485 protocol: dtls,
5486 name: "DTLS-Replay-LargeGaps",
5487 config: Config{
5488 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005489 SequenceNumberMapping: func(in uint64) uint64 {
5490 return in * 127
5491 },
David Benjamin5e961c12014-11-07 01:48:35 -05005492 },
5493 },
David Benjamin8e6db492015-07-25 18:29:23 -04005494 messageCount: 200,
5495 replayWrites: true,
5496 })
5497
5498 // Test the incoming sequence number changing non-monotonically.
5499 testCases = append(testCases, testCase{
5500 protocol: dtls,
5501 name: "DTLS-Replay-NonMonotonic",
5502 config: Config{
5503 Bugs: ProtocolBugs{
5504 SequenceNumberMapping: func(in uint64) uint64 {
5505 return in ^ 31
5506 },
5507 },
5508 },
5509 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005510 replayWrites: true,
5511 })
5512}
5513
Nick Harper60edffd2016-06-21 15:19:24 -07005514var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005515 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005516 id signatureAlgorithm
5517 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005518}{
Nick Harper60edffd2016-06-21 15:19:24 -07005519 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5520 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5521 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5522 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005523 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005524 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5525 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5526 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005527 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5528 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5529 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005530 // Tests for key types prior to TLS 1.2.
5531 {"RSA", 0, testCertRSA},
5532 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005533}
5534
Nick Harper60edffd2016-06-21 15:19:24 -07005535const fakeSigAlg1 signatureAlgorithm = 0x2a01
5536const fakeSigAlg2 signatureAlgorithm = 0xff01
5537
5538func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005539 // Not all ciphers involve a signature. Advertise a list which gives all
5540 // versions a signing cipher.
5541 signingCiphers := []uint16{
5542 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5543 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5544 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5545 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5546 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5547 }
5548
David Benjaminca3d5452016-07-14 12:51:01 -04005549 var allAlgorithms []signatureAlgorithm
5550 for _, alg := range testSignatureAlgorithms {
5551 if alg.id != 0 {
5552 allAlgorithms = append(allAlgorithms, alg.id)
5553 }
5554 }
5555
Nick Harper60edffd2016-06-21 15:19:24 -07005556 // Make sure each signature algorithm works. Include some fake values in
5557 // the list and ensure they're ignored.
5558 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005559 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005560 if (ver.version < VersionTLS12) != (alg.id == 0) {
5561 continue
5562 }
5563
5564 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5565 // or remove it in C.
5566 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005567 continue
5568 }
Nick Harper60edffd2016-06-21 15:19:24 -07005569
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005570 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005571 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005572 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5573 shouldFail = true
5574 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005575 // RSA-PKCS1 does not exist in TLS 1.3.
5576 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5577 shouldFail = true
5578 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005579
5580 var signError, verifyError string
5581 if shouldFail {
5582 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5583 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005584 }
David Benjamin000800a2014-11-14 01:43:59 -05005585
David Benjamin1fb125c2016-07-08 18:52:12 -07005586 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005587
David Benjamin7a41d372016-07-09 11:21:54 -07005588 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005589 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005590 config: Config{
5591 MaxVersion: ver.version,
5592 ClientAuth: RequireAnyClientCert,
5593 VerifySignatureAlgorithms: []signatureAlgorithm{
5594 fakeSigAlg1,
5595 alg.id,
5596 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005597 },
David Benjamin7a41d372016-07-09 11:21:54 -07005598 },
5599 flags: []string{
5600 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5601 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5602 "-enable-all-curves",
5603 },
5604 shouldFail: shouldFail,
5605 expectedError: signError,
5606 expectedPeerSignatureAlgorithm: alg.id,
5607 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005608
David Benjamin7a41d372016-07-09 11:21:54 -07005609 testCases = append(testCases, testCase{
5610 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005611 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005612 config: Config{
5613 MaxVersion: ver.version,
5614 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5615 SignSignatureAlgorithms: []signatureAlgorithm{
5616 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005617 },
David Benjamin7a41d372016-07-09 11:21:54 -07005618 Bugs: ProtocolBugs{
5619 SkipECDSACurveCheck: shouldFail,
5620 IgnoreSignatureVersionChecks: shouldFail,
5621 // The client won't advertise 1.3-only algorithms after
5622 // version negotiation.
5623 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005624 },
David Benjamin7a41d372016-07-09 11:21:54 -07005625 },
5626 flags: []string{
5627 "-require-any-client-certificate",
5628 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5629 "-enable-all-curves",
5630 },
5631 shouldFail: shouldFail,
5632 expectedError: verifyError,
5633 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005634
5635 testCases = append(testCases, testCase{
5636 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005637 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005638 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005639 MaxVersion: ver.version,
5640 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005641 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005642 fakeSigAlg1,
5643 alg.id,
5644 fakeSigAlg2,
5645 },
5646 },
5647 flags: []string{
5648 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5649 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5650 "-enable-all-curves",
5651 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005652 shouldFail: shouldFail,
5653 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005654 expectedPeerSignatureAlgorithm: alg.id,
5655 })
5656
5657 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005658 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005659 config: Config{
5660 MaxVersion: ver.version,
5661 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005662 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005663 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005664 alg.id,
5665 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005666 Bugs: ProtocolBugs{
5667 SkipECDSACurveCheck: shouldFail,
5668 IgnoreSignatureVersionChecks: shouldFail,
5669 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005670 },
5671 flags: []string{
5672 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5673 "-enable-all-curves",
5674 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005675 shouldFail: shouldFail,
5676 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005677 })
David Benjamin5208fd42016-07-13 21:43:25 -04005678
5679 if !shouldFail {
5680 testCases = append(testCases, testCase{
5681 testType: serverTest,
5682 name: "ClientAuth-InvalidSignature" + suffix,
5683 config: Config{
5684 MaxVersion: ver.version,
5685 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5686 SignSignatureAlgorithms: []signatureAlgorithm{
5687 alg.id,
5688 },
5689 Bugs: ProtocolBugs{
5690 InvalidSignature: true,
5691 },
5692 },
5693 flags: []string{
5694 "-require-any-client-certificate",
5695 "-enable-all-curves",
5696 },
5697 shouldFail: true,
5698 expectedError: ":BAD_SIGNATURE:",
5699 })
5700
5701 testCases = append(testCases, testCase{
5702 name: "ServerAuth-InvalidSignature" + suffix,
5703 config: Config{
5704 MaxVersion: ver.version,
5705 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5706 CipherSuites: signingCiphers,
5707 SignSignatureAlgorithms: []signatureAlgorithm{
5708 alg.id,
5709 },
5710 Bugs: ProtocolBugs{
5711 InvalidSignature: true,
5712 },
5713 },
5714 flags: []string{"-enable-all-curves"},
5715 shouldFail: true,
5716 expectedError: ":BAD_SIGNATURE:",
5717 })
5718 }
David Benjaminca3d5452016-07-14 12:51:01 -04005719
5720 if ver.version >= VersionTLS12 && !shouldFail {
5721 testCases = append(testCases, testCase{
5722 name: "ClientAuth-Sign-Negotiate" + suffix,
5723 config: Config{
5724 MaxVersion: ver.version,
5725 ClientAuth: RequireAnyClientCert,
5726 VerifySignatureAlgorithms: allAlgorithms,
5727 },
5728 flags: []string{
5729 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5730 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5731 "-enable-all-curves",
5732 "-signing-prefs", strconv.Itoa(int(alg.id)),
5733 },
5734 expectedPeerSignatureAlgorithm: alg.id,
5735 })
5736
5737 testCases = append(testCases, testCase{
5738 testType: serverTest,
5739 name: "ServerAuth-Sign-Negotiate" + suffix,
5740 config: Config{
5741 MaxVersion: ver.version,
5742 CipherSuites: signingCiphers,
5743 VerifySignatureAlgorithms: allAlgorithms,
5744 },
5745 flags: []string{
5746 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5747 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5748 "-enable-all-curves",
5749 "-signing-prefs", strconv.Itoa(int(alg.id)),
5750 },
5751 expectedPeerSignatureAlgorithm: alg.id,
5752 })
5753 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005754 }
David Benjamin000800a2014-11-14 01:43:59 -05005755 }
5756
Nick Harper60edffd2016-06-21 15:19:24 -07005757 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005758 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005759 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005760 config: Config{
5761 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005762 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005763 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005764 signatureECDSAWithP521AndSHA512,
5765 signatureRSAPKCS1WithSHA384,
5766 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005767 },
5768 },
5769 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005770 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5771 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005772 },
Nick Harper60edffd2016-06-21 15:19:24 -07005773 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005774 })
5775
5776 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005777 name: "ClientAuth-SignatureType-TLS13",
5778 config: Config{
5779 ClientAuth: RequireAnyClientCert,
5780 MaxVersion: VersionTLS13,
5781 VerifySignatureAlgorithms: []signatureAlgorithm{
5782 signatureECDSAWithP521AndSHA512,
5783 signatureRSAPKCS1WithSHA384,
5784 signatureRSAPSSWithSHA384,
5785 signatureECDSAWithSHA1,
5786 },
5787 },
5788 flags: []string{
5789 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5790 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5791 },
5792 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5793 })
5794
5795 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005796 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005797 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005799 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005801 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005802 signatureECDSAWithP521AndSHA512,
5803 signatureRSAPKCS1WithSHA384,
5804 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005805 },
5806 },
Nick Harper60edffd2016-06-21 15:19:24 -07005807 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005808 })
5809
Steven Valdez143e8b32016-07-11 13:19:03 -04005810 testCases = append(testCases, testCase{
5811 testType: serverTest,
5812 name: "ServerAuth-SignatureType-TLS13",
5813 config: Config{
5814 MaxVersion: VersionTLS13,
5815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5816 VerifySignatureAlgorithms: []signatureAlgorithm{
5817 signatureECDSAWithP521AndSHA512,
5818 signatureRSAPKCS1WithSHA384,
5819 signatureRSAPSSWithSHA384,
5820 signatureECDSAWithSHA1,
5821 },
5822 },
5823 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5824 })
5825
David Benjamina95e9f32016-07-08 16:28:04 -07005826 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005827 testCases = append(testCases, testCase{
5828 testType: serverTest,
5829 name: "Verify-ClientAuth-SignatureType",
5830 config: Config{
5831 MaxVersion: VersionTLS12,
5832 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005833 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005834 signatureRSAPKCS1WithSHA256,
5835 },
5836 Bugs: ProtocolBugs{
5837 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5838 },
5839 },
5840 flags: []string{
5841 "-require-any-client-certificate",
5842 },
5843 shouldFail: true,
5844 expectedError: ":WRONG_SIGNATURE_TYPE:",
5845 })
5846
5847 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005848 testType: serverTest,
5849 name: "Verify-ClientAuth-SignatureType-TLS13",
5850 config: Config{
5851 MaxVersion: VersionTLS13,
5852 Certificates: []Certificate{rsaCertificate},
5853 SignSignatureAlgorithms: []signatureAlgorithm{
5854 signatureRSAPSSWithSHA256,
5855 },
5856 Bugs: ProtocolBugs{
5857 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5858 },
5859 },
5860 flags: []string{
5861 "-require-any-client-certificate",
5862 },
5863 shouldFail: true,
5864 expectedError: ":WRONG_SIGNATURE_TYPE:",
5865 })
5866
5867 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005868 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005869 config: Config{
5870 MaxVersion: VersionTLS12,
5871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005872 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005873 signatureRSAPKCS1WithSHA256,
5874 },
5875 Bugs: ProtocolBugs{
5876 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5877 },
5878 },
5879 shouldFail: true,
5880 expectedError: ":WRONG_SIGNATURE_TYPE:",
5881 })
5882
Steven Valdez143e8b32016-07-11 13:19:03 -04005883 testCases = append(testCases, testCase{
5884 name: "Verify-ServerAuth-SignatureType-TLS13",
5885 config: Config{
5886 MaxVersion: VersionTLS13,
5887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5888 SignSignatureAlgorithms: []signatureAlgorithm{
5889 signatureRSAPSSWithSHA256,
5890 },
5891 Bugs: ProtocolBugs{
5892 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5893 },
5894 },
5895 shouldFail: true,
5896 expectedError: ":WRONG_SIGNATURE_TYPE:",
5897 })
5898
David Benjamin51dd7d62016-07-08 16:07:01 -07005899 // Test that, if the list is missing, the peer falls back to SHA-1 in
5900 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005901 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005902 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005904 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005905 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005906 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005907 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005908 },
5909 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005910 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005911 },
5912 },
5913 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005914 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5915 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005916 },
5917 })
5918
5919 testCases = append(testCases, testCase{
5920 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005921 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005922 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005923 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005924 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005925 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005926 },
5927 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005928 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005929 },
5930 },
David Benjaminee32bea2016-08-17 13:36:44 -04005931 flags: []string{
5932 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5933 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5934 },
5935 })
5936
5937 testCases = append(testCases, testCase{
5938 name: "ClientAuth-SHA1-Fallback-ECDSA",
5939 config: Config{
5940 MaxVersion: VersionTLS12,
5941 ClientAuth: RequireAnyClientCert,
5942 VerifySignatureAlgorithms: []signatureAlgorithm{
5943 signatureECDSAWithSHA1,
5944 },
5945 Bugs: ProtocolBugs{
5946 NoSignatureAlgorithms: true,
5947 },
5948 },
5949 flags: []string{
5950 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5951 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5952 },
5953 })
5954
5955 testCases = append(testCases, testCase{
5956 testType: serverTest,
5957 name: "ServerAuth-SHA1-Fallback-ECDSA",
5958 config: Config{
5959 MaxVersion: VersionTLS12,
5960 VerifySignatureAlgorithms: []signatureAlgorithm{
5961 signatureECDSAWithSHA1,
5962 },
5963 Bugs: ProtocolBugs{
5964 NoSignatureAlgorithms: true,
5965 },
5966 },
5967 flags: []string{
5968 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5969 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5970 },
David Benjamin000800a2014-11-14 01:43:59 -05005971 })
David Benjamin72dc7832015-03-16 17:49:43 -04005972
David Benjamin51dd7d62016-07-08 16:07:01 -07005973 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005974 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005975 config: Config{
5976 MaxVersion: VersionTLS13,
5977 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005978 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005979 signatureRSAPKCS1WithSHA1,
5980 },
5981 Bugs: ProtocolBugs{
5982 NoSignatureAlgorithms: true,
5983 },
5984 },
5985 flags: []string{
5986 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5987 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5988 },
David Benjamin48901652016-08-01 12:12:47 -04005989 shouldFail: true,
5990 // An empty CertificateRequest signature algorithm list is a
5991 // syntax error in TLS 1.3.
5992 expectedError: ":DECODE_ERROR:",
5993 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005994 })
5995
5996 testCases = append(testCases, testCase{
5997 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005998 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005999 config: Config{
6000 MaxVersion: VersionTLS13,
6001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006002 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006003 signatureRSAPKCS1WithSHA1,
6004 },
6005 Bugs: ProtocolBugs{
6006 NoSignatureAlgorithms: true,
6007 },
6008 },
6009 shouldFail: true,
6010 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6011 })
6012
David Benjaminb62d2872016-07-18 14:55:02 +02006013 // Test that hash preferences are enforced. BoringSSL does not implement
6014 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006015 testCases = append(testCases, testCase{
6016 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006017 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006019 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006020 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006021 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006022 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006023 },
6024 Bugs: ProtocolBugs{
6025 IgnorePeerSignatureAlgorithmPreferences: true,
6026 },
6027 },
6028 flags: []string{"-require-any-client-certificate"},
6029 shouldFail: true,
6030 expectedError: ":WRONG_SIGNATURE_TYPE:",
6031 })
6032
6033 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006034 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006036 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006038 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006039 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006040 },
6041 Bugs: ProtocolBugs{
6042 IgnorePeerSignatureAlgorithmPreferences: true,
6043 },
6044 },
6045 shouldFail: true,
6046 expectedError: ":WRONG_SIGNATURE_TYPE:",
6047 })
David Benjaminb62d2872016-07-18 14:55:02 +02006048 testCases = append(testCases, testCase{
6049 testType: serverTest,
6050 name: "ClientAuth-Enforced-TLS13",
6051 config: Config{
6052 MaxVersion: VersionTLS13,
6053 Certificates: []Certificate{rsaCertificate},
6054 SignSignatureAlgorithms: []signatureAlgorithm{
6055 signatureRSAPKCS1WithMD5,
6056 },
6057 Bugs: ProtocolBugs{
6058 IgnorePeerSignatureAlgorithmPreferences: true,
6059 IgnoreSignatureVersionChecks: true,
6060 },
6061 },
6062 flags: []string{"-require-any-client-certificate"},
6063 shouldFail: true,
6064 expectedError: ":WRONG_SIGNATURE_TYPE:",
6065 })
6066
6067 testCases = append(testCases, testCase{
6068 name: "ServerAuth-Enforced-TLS13",
6069 config: Config{
6070 MaxVersion: VersionTLS13,
6071 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6072 SignSignatureAlgorithms: []signatureAlgorithm{
6073 signatureRSAPKCS1WithMD5,
6074 },
6075 Bugs: ProtocolBugs{
6076 IgnorePeerSignatureAlgorithmPreferences: true,
6077 IgnoreSignatureVersionChecks: true,
6078 },
6079 },
6080 shouldFail: true,
6081 expectedError: ":WRONG_SIGNATURE_TYPE:",
6082 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006083
6084 // Test that the agreed upon digest respects the client preferences and
6085 // the server digests.
6086 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006087 name: "NoCommonAlgorithms-Digests",
6088 config: Config{
6089 MaxVersion: VersionTLS12,
6090 ClientAuth: RequireAnyClientCert,
6091 VerifySignatureAlgorithms: []signatureAlgorithm{
6092 signatureRSAPKCS1WithSHA512,
6093 signatureRSAPKCS1WithSHA1,
6094 },
6095 },
6096 flags: []string{
6097 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6098 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6099 "-digest-prefs", "SHA256",
6100 },
6101 shouldFail: true,
6102 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6103 })
6104 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006105 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006107 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006108 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006109 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006110 signatureRSAPKCS1WithSHA512,
6111 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006112 },
6113 },
6114 flags: []string{
6115 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6116 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006117 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006118 },
David Benjaminca3d5452016-07-14 12:51:01 -04006119 shouldFail: true,
6120 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6121 })
6122 testCases = append(testCases, testCase{
6123 name: "NoCommonAlgorithms-TLS13",
6124 config: Config{
6125 MaxVersion: VersionTLS13,
6126 ClientAuth: RequireAnyClientCert,
6127 VerifySignatureAlgorithms: []signatureAlgorithm{
6128 signatureRSAPSSWithSHA512,
6129 signatureRSAPSSWithSHA384,
6130 },
6131 },
6132 flags: []string{
6133 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6134 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6135 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6136 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006137 shouldFail: true,
6138 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006139 })
6140 testCases = append(testCases, testCase{
6141 name: "Agree-Digest-SHA256",
6142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006143 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006144 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006145 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006146 signatureRSAPKCS1WithSHA1,
6147 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006148 },
6149 },
6150 flags: []string{
6151 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6152 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006153 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006154 },
Nick Harper60edffd2016-06-21 15:19:24 -07006155 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006156 })
6157 testCases = append(testCases, testCase{
6158 name: "Agree-Digest-SHA1",
6159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006160 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006161 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006162 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006163 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006164 },
6165 },
6166 flags: []string{
6167 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6168 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006169 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006170 },
Nick Harper60edffd2016-06-21 15:19:24 -07006171 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006172 })
6173 testCases = append(testCases, testCase{
6174 name: "Agree-Digest-Default",
6175 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006176 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006177 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006178 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006179 signatureRSAPKCS1WithSHA256,
6180 signatureECDSAWithP256AndSHA256,
6181 signatureRSAPKCS1WithSHA1,
6182 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006183 },
6184 },
6185 flags: []string{
6186 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6187 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6188 },
Nick Harper60edffd2016-06-21 15:19:24 -07006189 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006190 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006191
David Benjaminca3d5452016-07-14 12:51:01 -04006192 // Test that the signing preference list may include extra algorithms
6193 // without negotiation problems.
6194 testCases = append(testCases, testCase{
6195 testType: serverTest,
6196 name: "FilterExtraAlgorithms",
6197 config: Config{
6198 MaxVersion: VersionTLS12,
6199 VerifySignatureAlgorithms: []signatureAlgorithm{
6200 signatureRSAPKCS1WithSHA256,
6201 },
6202 },
6203 flags: []string{
6204 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6205 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6206 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6207 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6208 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6209 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6210 },
6211 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6212 })
6213
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6215 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006216 testCases = append(testCases, testCase{
6217 name: "CheckLeafCurve",
6218 config: Config{
6219 MaxVersion: VersionTLS12,
6220 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006221 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006222 },
6223 flags: []string{"-p384-only"},
6224 shouldFail: true,
6225 expectedError: ":BAD_ECC_CERT:",
6226 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006227
6228 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6229 testCases = append(testCases, testCase{
6230 name: "CheckLeafCurve-TLS13",
6231 config: Config{
6232 MaxVersion: VersionTLS13,
6233 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6234 Certificates: []Certificate{ecdsaP256Certificate},
6235 },
6236 flags: []string{"-p384-only"},
6237 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006238
6239 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6240 testCases = append(testCases, testCase{
6241 name: "ECDSACurveMismatch-Verify-TLS12",
6242 config: Config{
6243 MaxVersion: VersionTLS12,
6244 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6245 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006246 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006247 signatureECDSAWithP384AndSHA384,
6248 },
6249 },
6250 })
6251
6252 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6253 testCases = append(testCases, testCase{
6254 name: "ECDSACurveMismatch-Verify-TLS13",
6255 config: Config{
6256 MaxVersion: VersionTLS13,
6257 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6258 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006259 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006260 signatureECDSAWithP384AndSHA384,
6261 },
6262 Bugs: ProtocolBugs{
6263 SkipECDSACurveCheck: true,
6264 },
6265 },
6266 shouldFail: true,
6267 expectedError: ":WRONG_SIGNATURE_TYPE:",
6268 })
6269
6270 // Signature algorithm selection in TLS 1.3 should take the curve into
6271 // account.
6272 testCases = append(testCases, testCase{
6273 testType: serverTest,
6274 name: "ECDSACurveMismatch-Sign-TLS13",
6275 config: Config{
6276 MaxVersion: VersionTLS13,
6277 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006278 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006279 signatureECDSAWithP384AndSHA384,
6280 signatureECDSAWithP256AndSHA256,
6281 },
6282 },
6283 flags: []string{
6284 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6285 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6286 },
6287 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6288 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006289
6290 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6291 // server does not attempt to sign in that case.
6292 testCases = append(testCases, testCase{
6293 testType: serverTest,
6294 name: "RSA-PSS-Large",
6295 config: Config{
6296 MaxVersion: VersionTLS13,
6297 VerifySignatureAlgorithms: []signatureAlgorithm{
6298 signatureRSAPSSWithSHA512,
6299 },
6300 },
6301 flags: []string{
6302 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6303 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6304 },
6305 shouldFail: true,
6306 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6307 })
David Benjamin57e929f2016-08-30 00:30:38 -04006308
6309 // Test that RSA-PSS is enabled by default for TLS 1.2.
6310 testCases = append(testCases, testCase{
6311 testType: clientTest,
6312 name: "RSA-PSS-Default-Verify",
6313 config: Config{
6314 MaxVersion: VersionTLS12,
6315 SignSignatureAlgorithms: []signatureAlgorithm{
6316 signatureRSAPSSWithSHA256,
6317 },
6318 },
6319 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6320 })
6321
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
6324 name: "RSA-PSS-Default-Sign",
6325 config: Config{
6326 MaxVersion: VersionTLS12,
6327 VerifySignatureAlgorithms: []signatureAlgorithm{
6328 signatureRSAPSSWithSHA256,
6329 },
6330 },
6331 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6332 })
David Benjamin000800a2014-11-14 01:43:59 -05006333}
6334
David Benjamin83f90402015-01-27 01:09:43 -05006335// timeouts is the retransmit schedule for BoringSSL. It doubles and
6336// caps at 60 seconds. On the 13th timeout, it gives up.
6337var timeouts = []time.Duration{
6338 1 * time.Second,
6339 2 * time.Second,
6340 4 * time.Second,
6341 8 * time.Second,
6342 16 * time.Second,
6343 32 * time.Second,
6344 60 * time.Second,
6345 60 * time.Second,
6346 60 * time.Second,
6347 60 * time.Second,
6348 60 * time.Second,
6349 60 * time.Second,
6350 60 * time.Second,
6351}
6352
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006353// shortTimeouts is an alternate set of timeouts which would occur if the
6354// initial timeout duration was set to 250ms.
6355var shortTimeouts = []time.Duration{
6356 250 * time.Millisecond,
6357 500 * time.Millisecond,
6358 1 * time.Second,
6359 2 * time.Second,
6360 4 * time.Second,
6361 8 * time.Second,
6362 16 * time.Second,
6363 32 * time.Second,
6364 60 * time.Second,
6365 60 * time.Second,
6366 60 * time.Second,
6367 60 * time.Second,
6368 60 * time.Second,
6369}
6370
David Benjamin83f90402015-01-27 01:09:43 -05006371func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006372 // These tests work by coordinating some behavior on both the shim and
6373 // the runner.
6374 //
6375 // TimeoutSchedule configures the runner to send a series of timeout
6376 // opcodes to the shim (see packetAdaptor) immediately before reading
6377 // each peer handshake flight N. The timeout opcode both simulates a
6378 // timeout in the shim and acts as a synchronization point to help the
6379 // runner bracket each handshake flight.
6380 //
6381 // We assume the shim does not read from the channel eagerly. It must
6382 // first wait until it has sent flight N and is ready to receive
6383 // handshake flight N+1. At this point, it will process the timeout
6384 // opcode. It must then immediately respond with a timeout ACK and act
6385 // as if the shim was idle for the specified amount of time.
6386 //
6387 // The runner then drops all packets received before the ACK and
6388 // continues waiting for flight N. This ordering results in one attempt
6389 // at sending flight N to be dropped. For the test to complete, the
6390 // shim must send flight N again, testing that the shim implements DTLS
6391 // retransmit on a timeout.
6392
Steven Valdez143e8b32016-07-11 13:19:03 -04006393 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006394 // likely be more epochs to cross and the final message's retransmit may
6395 // be more complex.
6396
David Benjamin585d7a42016-06-02 14:58:00 -04006397 for _, async := range []bool{true, false} {
6398 var tests []testCase
6399
6400 // Test that this is indeed the timeout schedule. Stress all
6401 // four patterns of handshake.
6402 for i := 1; i < len(timeouts); i++ {
6403 number := strconv.Itoa(i)
6404 tests = append(tests, testCase{
6405 protocol: dtls,
6406 name: "DTLS-Retransmit-Client-" + number,
6407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006408 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006409 Bugs: ProtocolBugs{
6410 TimeoutSchedule: timeouts[:i],
6411 },
6412 },
6413 resumeSession: true,
6414 })
6415 tests = append(tests, testCase{
6416 protocol: dtls,
6417 testType: serverTest,
6418 name: "DTLS-Retransmit-Server-" + number,
6419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006420 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006421 Bugs: ProtocolBugs{
6422 TimeoutSchedule: timeouts[:i],
6423 },
6424 },
6425 resumeSession: true,
6426 })
6427 }
6428
6429 // Test that exceeding the timeout schedule hits a read
6430 // timeout.
6431 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006432 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006433 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006435 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006436 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006437 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006438 },
6439 },
6440 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006441 shouldFail: true,
6442 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006443 })
David Benjamin585d7a42016-06-02 14:58:00 -04006444
6445 if async {
6446 // Test that timeout handling has a fudge factor, due to API
6447 // problems.
6448 tests = append(tests, testCase{
6449 protocol: dtls,
6450 name: "DTLS-Retransmit-Fudge",
6451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006452 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006453 Bugs: ProtocolBugs{
6454 TimeoutSchedule: []time.Duration{
6455 timeouts[0] - 10*time.Millisecond,
6456 },
6457 },
6458 },
6459 resumeSession: true,
6460 })
6461 }
6462
6463 // Test that the final Finished retransmitting isn't
6464 // duplicated if the peer badly fragments everything.
6465 tests = append(tests, testCase{
6466 testType: serverTest,
6467 protocol: dtls,
6468 name: "DTLS-Retransmit-Fragmented",
6469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006470 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006471 Bugs: ProtocolBugs{
6472 TimeoutSchedule: []time.Duration{timeouts[0]},
6473 MaxHandshakeRecordLength: 2,
6474 },
6475 },
6476 })
6477
6478 // Test the timeout schedule when a shorter initial timeout duration is set.
6479 tests = append(tests, testCase{
6480 protocol: dtls,
6481 name: "DTLS-Retransmit-Short-Client",
6482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006483 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006484 Bugs: ProtocolBugs{
6485 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6486 },
6487 },
6488 resumeSession: true,
6489 flags: []string{"-initial-timeout-duration-ms", "250"},
6490 })
6491 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006492 protocol: dtls,
6493 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006494 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006495 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006496 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006497 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006498 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006499 },
6500 },
6501 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006502 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006503 })
David Benjamin585d7a42016-06-02 14:58:00 -04006504
6505 for _, test := range tests {
6506 if async {
6507 test.name += "-Async"
6508 test.flags = append(test.flags, "-async")
6509 }
6510
6511 testCases = append(testCases, test)
6512 }
David Benjamin83f90402015-01-27 01:09:43 -05006513 }
David Benjamin83f90402015-01-27 01:09:43 -05006514}
6515
David Benjaminc565ebb2015-04-03 04:06:36 -04006516func addExportKeyingMaterialTests() {
6517 for _, vers := range tlsVersions {
6518 if vers.version == VersionSSL30 {
6519 continue
6520 }
6521 testCases = append(testCases, testCase{
6522 name: "ExportKeyingMaterial-" + vers.name,
6523 config: Config{
6524 MaxVersion: vers.version,
6525 },
6526 exportKeyingMaterial: 1024,
6527 exportLabel: "label",
6528 exportContext: "context",
6529 useExportContext: true,
6530 })
6531 testCases = append(testCases, testCase{
6532 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6533 config: Config{
6534 MaxVersion: vers.version,
6535 },
6536 exportKeyingMaterial: 1024,
6537 })
6538 testCases = append(testCases, testCase{
6539 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6540 config: Config{
6541 MaxVersion: vers.version,
6542 },
6543 exportKeyingMaterial: 1024,
6544 useExportContext: true,
6545 })
6546 testCases = append(testCases, testCase{
6547 name: "ExportKeyingMaterial-Small-" + vers.name,
6548 config: Config{
6549 MaxVersion: vers.version,
6550 },
6551 exportKeyingMaterial: 1,
6552 exportLabel: "label",
6553 exportContext: "context",
6554 useExportContext: true,
6555 })
6556 }
6557 testCases = append(testCases, testCase{
6558 name: "ExportKeyingMaterial-SSL3",
6559 config: Config{
6560 MaxVersion: VersionSSL30,
6561 },
6562 exportKeyingMaterial: 1024,
6563 exportLabel: "label",
6564 exportContext: "context",
6565 useExportContext: true,
6566 shouldFail: true,
6567 expectedError: "failed to export keying material",
6568 })
6569}
6570
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006571func addTLSUniqueTests() {
6572 for _, isClient := range []bool{false, true} {
6573 for _, isResumption := range []bool{false, true} {
6574 for _, hasEMS := range []bool{false, true} {
6575 var suffix string
6576 if isResumption {
6577 suffix = "Resume-"
6578 } else {
6579 suffix = "Full-"
6580 }
6581
6582 if hasEMS {
6583 suffix += "EMS-"
6584 } else {
6585 suffix += "NoEMS-"
6586 }
6587
6588 if isClient {
6589 suffix += "Client"
6590 } else {
6591 suffix += "Server"
6592 }
6593
6594 test := testCase{
6595 name: "TLSUnique-" + suffix,
6596 testTLSUnique: true,
6597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006598 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006599 Bugs: ProtocolBugs{
6600 NoExtendedMasterSecret: !hasEMS,
6601 },
6602 },
6603 }
6604
6605 if isResumption {
6606 test.resumeSession = true
6607 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006608 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006609 Bugs: ProtocolBugs{
6610 NoExtendedMasterSecret: !hasEMS,
6611 },
6612 }
6613 }
6614
6615 if isResumption && !hasEMS {
6616 test.shouldFail = true
6617 test.expectedError = "failed to get tls-unique"
6618 }
6619
6620 testCases = append(testCases, test)
6621 }
6622 }
6623 }
6624}
6625
Adam Langley09505632015-07-30 18:10:13 -07006626func addCustomExtensionTests() {
6627 expectedContents := "custom extension"
6628 emptyString := ""
6629
6630 for _, isClient := range []bool{false, true} {
6631 suffix := "Server"
6632 flag := "-enable-server-custom-extension"
6633 testType := serverTest
6634 if isClient {
6635 suffix = "Client"
6636 flag = "-enable-client-custom-extension"
6637 testType = clientTest
6638 }
6639
6640 testCases = append(testCases, testCase{
6641 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006642 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006645 Bugs: ProtocolBugs{
6646 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006647 ExpectedCustomExtension: &expectedContents,
6648 },
6649 },
6650 flags: []string{flag},
6651 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006652 testCases = append(testCases, testCase{
6653 testType: testType,
6654 name: "CustomExtensions-" + suffix + "-TLS13",
6655 config: Config{
6656 MaxVersion: VersionTLS13,
6657 Bugs: ProtocolBugs{
6658 CustomExtension: expectedContents,
6659 ExpectedCustomExtension: &expectedContents,
6660 },
6661 },
6662 flags: []string{flag},
6663 })
Adam Langley09505632015-07-30 18:10:13 -07006664
6665 // If the parse callback fails, the handshake should also fail.
6666 testCases = append(testCases, testCase{
6667 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006668 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006671 Bugs: ProtocolBugs{
6672 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006673 ExpectedCustomExtension: &expectedContents,
6674 },
6675 },
David Benjamin399e7c92015-07-30 23:01:27 -04006676 flags: []string{flag},
6677 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006678 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6679 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006680 testCases = append(testCases, testCase{
6681 testType: testType,
6682 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6683 config: Config{
6684 MaxVersion: VersionTLS13,
6685 Bugs: ProtocolBugs{
6686 CustomExtension: expectedContents + "foo",
6687 ExpectedCustomExtension: &expectedContents,
6688 },
6689 },
6690 flags: []string{flag},
6691 shouldFail: true,
6692 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6693 })
Adam Langley09505632015-07-30 18:10:13 -07006694
6695 // If the add callback fails, the handshake should also fail.
6696 testCases = append(testCases, testCase{
6697 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006698 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006699 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006700 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006701 Bugs: ProtocolBugs{
6702 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006703 ExpectedCustomExtension: &expectedContents,
6704 },
6705 },
David Benjamin399e7c92015-07-30 23:01:27 -04006706 flags: []string{flag, "-custom-extension-fail-add"},
6707 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006708 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6709 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006710 testCases = append(testCases, testCase{
6711 testType: testType,
6712 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6713 config: Config{
6714 MaxVersion: VersionTLS13,
6715 Bugs: ProtocolBugs{
6716 CustomExtension: expectedContents,
6717 ExpectedCustomExtension: &expectedContents,
6718 },
6719 },
6720 flags: []string{flag, "-custom-extension-fail-add"},
6721 shouldFail: true,
6722 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6723 })
Adam Langley09505632015-07-30 18:10:13 -07006724
6725 // If the add callback returns zero, no extension should be
6726 // added.
6727 skipCustomExtension := expectedContents
6728 if isClient {
6729 // For the case where the client skips sending the
6730 // custom extension, the server must not “echo” it.
6731 skipCustomExtension = ""
6732 }
6733 testCases = append(testCases, testCase{
6734 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006735 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006736 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006737 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006738 Bugs: ProtocolBugs{
6739 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006740 ExpectedCustomExtension: &emptyString,
6741 },
6742 },
6743 flags: []string{flag, "-custom-extension-skip"},
6744 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006745 testCases = append(testCases, testCase{
6746 testType: testType,
6747 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6748 config: Config{
6749 MaxVersion: VersionTLS13,
6750 Bugs: ProtocolBugs{
6751 CustomExtension: skipCustomExtension,
6752 ExpectedCustomExtension: &emptyString,
6753 },
6754 },
6755 flags: []string{flag, "-custom-extension-skip"},
6756 })
Adam Langley09505632015-07-30 18:10:13 -07006757 }
6758
6759 // The custom extension add callback should not be called if the client
6760 // doesn't send the extension.
6761 testCases = append(testCases, testCase{
6762 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006763 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006765 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006766 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006767 ExpectedCustomExtension: &emptyString,
6768 },
6769 },
6770 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6771 })
Adam Langley2deb9842015-08-07 11:15:37 -07006772
Steven Valdez143e8b32016-07-11 13:19:03 -04006773 testCases = append(testCases, testCase{
6774 testType: serverTest,
6775 name: "CustomExtensions-NotCalled-Server-TLS13",
6776 config: Config{
6777 MaxVersion: VersionTLS13,
6778 Bugs: ProtocolBugs{
6779 ExpectedCustomExtension: &emptyString,
6780 },
6781 },
6782 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6783 })
6784
Adam Langley2deb9842015-08-07 11:15:37 -07006785 // Test an unknown extension from the server.
6786 testCases = append(testCases, testCase{
6787 testType: clientTest,
6788 name: "UnknownExtension-Client",
6789 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006790 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006791 Bugs: ProtocolBugs{
6792 CustomExtension: expectedContents,
6793 },
6794 },
David Benjamin0c40a962016-08-01 12:05:50 -04006795 shouldFail: true,
6796 expectedError: ":UNEXPECTED_EXTENSION:",
6797 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006798 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006799 testCases = append(testCases, testCase{
6800 testType: clientTest,
6801 name: "UnknownExtension-Client-TLS13",
6802 config: Config{
6803 MaxVersion: VersionTLS13,
6804 Bugs: ProtocolBugs{
6805 CustomExtension: expectedContents,
6806 },
6807 },
David Benjamin0c40a962016-08-01 12:05:50 -04006808 shouldFail: true,
6809 expectedError: ":UNEXPECTED_EXTENSION:",
6810 expectedLocalError: "remote error: unsupported extension",
6811 })
6812
6813 // Test a known but unoffered extension from the server.
6814 testCases = append(testCases, testCase{
6815 testType: clientTest,
6816 name: "UnofferedExtension-Client",
6817 config: Config{
6818 MaxVersion: VersionTLS12,
6819 Bugs: ProtocolBugs{
6820 SendALPN: "alpn",
6821 },
6822 },
6823 shouldFail: true,
6824 expectedError: ":UNEXPECTED_EXTENSION:",
6825 expectedLocalError: "remote error: unsupported extension",
6826 })
6827 testCases = append(testCases, testCase{
6828 testType: clientTest,
6829 name: "UnofferedExtension-Client-TLS13",
6830 config: Config{
6831 MaxVersion: VersionTLS13,
6832 Bugs: ProtocolBugs{
6833 SendALPN: "alpn",
6834 },
6835 },
6836 shouldFail: true,
6837 expectedError: ":UNEXPECTED_EXTENSION:",
6838 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006839 })
Adam Langley09505632015-07-30 18:10:13 -07006840}
6841
David Benjaminb36a3952015-12-01 18:53:13 -05006842func addRSAClientKeyExchangeTests() {
6843 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6844 testCases = append(testCases, testCase{
6845 testType: serverTest,
6846 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6847 config: Config{
6848 // Ensure the ClientHello version and final
6849 // version are different, to detect if the
6850 // server uses the wrong one.
6851 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006852 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006853 Bugs: ProtocolBugs{
6854 BadRSAClientKeyExchange: bad,
6855 },
6856 },
6857 shouldFail: true,
6858 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6859 })
6860 }
6861}
6862
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006863var testCurves = []struct {
6864 name string
6865 id CurveID
6866}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006867 {"P-256", CurveP256},
6868 {"P-384", CurveP384},
6869 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006870 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006871}
6872
Steven Valdez5440fe02016-07-18 12:40:30 -04006873const bogusCurve = 0x1234
6874
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006875func addCurveTests() {
6876 for _, curve := range testCurves {
6877 testCases = append(testCases, testCase{
6878 name: "CurveTest-Client-" + curve.name,
6879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006880 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006881 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6882 CurvePreferences: []CurveID{curve.id},
6883 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006884 flags: []string{
6885 "-enable-all-curves",
6886 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6887 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006888 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006889 })
6890 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006891 name: "CurveTest-Client-" + curve.name + "-TLS13",
6892 config: Config{
6893 MaxVersion: VersionTLS13,
6894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6895 CurvePreferences: []CurveID{curve.id},
6896 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006897 flags: []string{
6898 "-enable-all-curves",
6899 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6900 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006901 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006902 })
6903 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006904 testType: serverTest,
6905 name: "CurveTest-Server-" + curve.name,
6906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006907 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6909 CurvePreferences: []CurveID{curve.id},
6910 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006911 flags: []string{
6912 "-enable-all-curves",
6913 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6914 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006915 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006916 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006917 testCases = append(testCases, testCase{
6918 testType: serverTest,
6919 name: "CurveTest-Server-" + curve.name + "-TLS13",
6920 config: Config{
6921 MaxVersion: VersionTLS13,
6922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6923 CurvePreferences: []CurveID{curve.id},
6924 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006925 flags: []string{
6926 "-enable-all-curves",
6927 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6928 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006929 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006930 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006931 }
David Benjamin241ae832016-01-15 03:04:54 -05006932
6933 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006934 testCases = append(testCases, testCase{
6935 testType: serverTest,
6936 name: "UnknownCurve",
6937 config: Config{
6938 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6939 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6940 },
6941 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006942
6943 // The server must not consider ECDHE ciphers when there are no
6944 // supported curves.
6945 testCases = append(testCases, testCase{
6946 testType: serverTest,
6947 name: "NoSupportedCurves",
6948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006949 MaxVersion: VersionTLS12,
6950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6951 Bugs: ProtocolBugs{
6952 NoSupportedCurves: true,
6953 },
6954 },
6955 shouldFail: true,
6956 expectedError: ":NO_SHARED_CIPHER:",
6957 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006958 testCases = append(testCases, testCase{
6959 testType: serverTest,
6960 name: "NoSupportedCurves-TLS13",
6961 config: Config{
6962 MaxVersion: VersionTLS13,
6963 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6964 Bugs: ProtocolBugs{
6965 NoSupportedCurves: true,
6966 },
6967 },
6968 shouldFail: true,
6969 expectedError: ":NO_SHARED_CIPHER:",
6970 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006971
6972 // The server must fall back to another cipher when there are no
6973 // supported curves.
6974 testCases = append(testCases, testCase{
6975 testType: serverTest,
6976 name: "NoCommonCurves",
6977 config: Config{
6978 MaxVersion: VersionTLS12,
6979 CipherSuites: []uint16{
6980 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6981 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6982 },
6983 CurvePreferences: []CurveID{CurveP224},
6984 },
6985 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6986 })
6987
6988 // The client must reject bogus curves and disabled curves.
6989 testCases = append(testCases, testCase{
6990 name: "BadECDHECurve",
6991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006992 MaxVersion: VersionTLS12,
6993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6994 Bugs: ProtocolBugs{
6995 SendCurve: bogusCurve,
6996 },
6997 },
6998 shouldFail: true,
6999 expectedError: ":WRONG_CURVE:",
7000 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007001 testCases = append(testCases, testCase{
7002 name: "BadECDHECurve-TLS13",
7003 config: Config{
7004 MaxVersion: VersionTLS13,
7005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7006 Bugs: ProtocolBugs{
7007 SendCurve: bogusCurve,
7008 },
7009 },
7010 shouldFail: true,
7011 expectedError: ":WRONG_CURVE:",
7012 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013
7014 testCases = append(testCases, testCase{
7015 name: "UnsupportedCurve",
7016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007017 MaxVersion: VersionTLS12,
7018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7019 CurvePreferences: []CurveID{CurveP256},
7020 Bugs: ProtocolBugs{
7021 IgnorePeerCurvePreferences: true,
7022 },
7023 },
7024 flags: []string{"-p384-only"},
7025 shouldFail: true,
7026 expectedError: ":WRONG_CURVE:",
7027 })
7028
David Benjamin4f921572016-07-17 14:20:10 +02007029 testCases = append(testCases, testCase{
7030 // TODO(davidben): Add a TLS 1.3 version where
7031 // HelloRetryRequest requests an unsupported curve.
7032 name: "UnsupportedCurve-ServerHello-TLS13",
7033 config: Config{
7034 MaxVersion: VersionTLS12,
7035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7036 CurvePreferences: []CurveID{CurveP384},
7037 Bugs: ProtocolBugs{
7038 SendCurve: CurveP256,
7039 },
7040 },
7041 flags: []string{"-p384-only"},
7042 shouldFail: true,
7043 expectedError: ":WRONG_CURVE:",
7044 })
7045
David Benjamin4c3ddf72016-06-29 18:13:53 -04007046 // Test invalid curve points.
7047 testCases = append(testCases, testCase{
7048 name: "InvalidECDHPoint-Client",
7049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007050 MaxVersion: VersionTLS12,
7051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7052 CurvePreferences: []CurveID{CurveP256},
7053 Bugs: ProtocolBugs{
7054 InvalidECDHPoint: true,
7055 },
7056 },
7057 shouldFail: true,
7058 expectedError: ":INVALID_ENCODING:",
7059 })
7060 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007061 name: "InvalidECDHPoint-Client-TLS13",
7062 config: Config{
7063 MaxVersion: VersionTLS13,
7064 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7065 CurvePreferences: []CurveID{CurveP256},
7066 Bugs: ProtocolBugs{
7067 InvalidECDHPoint: true,
7068 },
7069 },
7070 shouldFail: true,
7071 expectedError: ":INVALID_ENCODING:",
7072 })
7073 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007074 testType: serverTest,
7075 name: "InvalidECDHPoint-Server",
7076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007077 MaxVersion: VersionTLS12,
7078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7079 CurvePreferences: []CurveID{CurveP256},
7080 Bugs: ProtocolBugs{
7081 InvalidECDHPoint: true,
7082 },
7083 },
7084 shouldFail: true,
7085 expectedError: ":INVALID_ENCODING:",
7086 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007087 testCases = append(testCases, testCase{
7088 testType: serverTest,
7089 name: "InvalidECDHPoint-Server-TLS13",
7090 config: Config{
7091 MaxVersion: VersionTLS13,
7092 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7093 CurvePreferences: []CurveID{CurveP256},
7094 Bugs: ProtocolBugs{
7095 InvalidECDHPoint: true,
7096 },
7097 },
7098 shouldFail: true,
7099 expectedError: ":INVALID_ENCODING:",
7100 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007101}
7102
Matt Braithwaite54217e42016-06-13 13:03:47 -07007103func addCECPQ1Tests() {
7104 testCases = append(testCases, testCase{
7105 testType: clientTest,
7106 name: "CECPQ1-Client-BadX25519Part",
7107 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007108 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007109 MinVersion: VersionTLS12,
7110 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7111 Bugs: ProtocolBugs{
7112 CECPQ1BadX25519Part: true,
7113 },
7114 },
7115 flags: []string{"-cipher", "kCECPQ1"},
7116 shouldFail: true,
7117 expectedLocalError: "local error: bad record MAC",
7118 })
7119 testCases = append(testCases, testCase{
7120 testType: clientTest,
7121 name: "CECPQ1-Client-BadNewhopePart",
7122 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007123 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007124 MinVersion: VersionTLS12,
7125 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7126 Bugs: ProtocolBugs{
7127 CECPQ1BadNewhopePart: true,
7128 },
7129 },
7130 flags: []string{"-cipher", "kCECPQ1"},
7131 shouldFail: true,
7132 expectedLocalError: "local error: bad record MAC",
7133 })
7134 testCases = append(testCases, testCase{
7135 testType: serverTest,
7136 name: "CECPQ1-Server-BadX25519Part",
7137 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007138 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007139 MinVersion: VersionTLS12,
7140 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7141 Bugs: ProtocolBugs{
7142 CECPQ1BadX25519Part: true,
7143 },
7144 },
7145 flags: []string{"-cipher", "kCECPQ1"},
7146 shouldFail: true,
7147 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7148 })
7149 testCases = append(testCases, testCase{
7150 testType: serverTest,
7151 name: "CECPQ1-Server-BadNewhopePart",
7152 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007153 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007154 MinVersion: VersionTLS12,
7155 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7156 Bugs: ProtocolBugs{
7157 CECPQ1BadNewhopePart: true,
7158 },
7159 },
7160 flags: []string{"-cipher", "kCECPQ1"},
7161 shouldFail: true,
7162 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7163 })
7164}
7165
David Benjamin5c4e8572016-08-19 17:44:53 -04007166func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007167 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007168 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007169 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007170 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007171 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7172 Bugs: ProtocolBugs{
7173 // This is a 1234-bit prime number, generated
7174 // with:
7175 // openssl gendh 1234 | openssl asn1parse -i
7176 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7177 },
7178 },
David Benjamin9e68f192016-06-30 14:55:33 -04007179 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007180 })
7181 testCases = append(testCases, testCase{
7182 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007183 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007184 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007185 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007186 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7187 },
7188 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007189 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007190 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007191}
7192
David Benjaminc9ae27c2016-06-24 22:56:37 -04007193func addTLS13RecordTests() {
7194 testCases = append(testCases, testCase{
7195 name: "TLS13-RecordPadding",
7196 config: Config{
7197 MaxVersion: VersionTLS13,
7198 MinVersion: VersionTLS13,
7199 Bugs: ProtocolBugs{
7200 RecordPadding: 10,
7201 },
7202 },
7203 })
7204
7205 testCases = append(testCases, testCase{
7206 name: "TLS13-EmptyRecords",
7207 config: Config{
7208 MaxVersion: VersionTLS13,
7209 MinVersion: VersionTLS13,
7210 Bugs: ProtocolBugs{
7211 OmitRecordContents: true,
7212 },
7213 },
7214 shouldFail: true,
7215 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7216 })
7217
7218 testCases = append(testCases, testCase{
7219 name: "TLS13-OnlyPadding",
7220 config: Config{
7221 MaxVersion: VersionTLS13,
7222 MinVersion: VersionTLS13,
7223 Bugs: ProtocolBugs{
7224 OmitRecordContents: true,
7225 RecordPadding: 10,
7226 },
7227 },
7228 shouldFail: true,
7229 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7230 })
7231
7232 testCases = append(testCases, testCase{
7233 name: "TLS13-WrongOuterRecord",
7234 config: Config{
7235 MaxVersion: VersionTLS13,
7236 MinVersion: VersionTLS13,
7237 Bugs: ProtocolBugs{
7238 OuterRecordType: recordTypeHandshake,
7239 },
7240 },
7241 shouldFail: true,
7242 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7243 })
7244}
7245
David Benjamin82261be2016-07-07 14:32:50 -07007246func addChangeCipherSpecTests() {
7247 // Test missing ChangeCipherSpecs.
7248 testCases = append(testCases, testCase{
7249 name: "SkipChangeCipherSpec-Client",
7250 config: Config{
7251 MaxVersion: VersionTLS12,
7252 Bugs: ProtocolBugs{
7253 SkipChangeCipherSpec: true,
7254 },
7255 },
7256 shouldFail: true,
7257 expectedError: ":UNEXPECTED_RECORD:",
7258 })
7259 testCases = append(testCases, testCase{
7260 testType: serverTest,
7261 name: "SkipChangeCipherSpec-Server",
7262 config: Config{
7263 MaxVersion: VersionTLS12,
7264 Bugs: ProtocolBugs{
7265 SkipChangeCipherSpec: true,
7266 },
7267 },
7268 shouldFail: true,
7269 expectedError: ":UNEXPECTED_RECORD:",
7270 })
7271 testCases = append(testCases, testCase{
7272 testType: serverTest,
7273 name: "SkipChangeCipherSpec-Server-NPN",
7274 config: Config{
7275 MaxVersion: VersionTLS12,
7276 NextProtos: []string{"bar"},
7277 Bugs: ProtocolBugs{
7278 SkipChangeCipherSpec: true,
7279 },
7280 },
7281 flags: []string{
7282 "-advertise-npn", "\x03foo\x03bar\x03baz",
7283 },
7284 shouldFail: true,
7285 expectedError: ":UNEXPECTED_RECORD:",
7286 })
7287
7288 // Test synchronization between the handshake and ChangeCipherSpec.
7289 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7290 // rejected. Test both with and without handshake packing to handle both
7291 // when the partial post-CCS message is in its own record and when it is
7292 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007293 for _, packed := range []bool{false, true} {
7294 var suffix string
7295 if packed {
7296 suffix = "-Packed"
7297 }
7298
7299 testCases = append(testCases, testCase{
7300 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7301 config: Config{
7302 MaxVersion: VersionTLS12,
7303 Bugs: ProtocolBugs{
7304 FragmentAcrossChangeCipherSpec: true,
7305 PackHandshakeFlight: packed,
7306 },
7307 },
7308 shouldFail: true,
7309 expectedError: ":UNEXPECTED_RECORD:",
7310 })
7311 testCases = append(testCases, testCase{
7312 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7313 config: Config{
7314 MaxVersion: VersionTLS12,
7315 },
7316 resumeSession: true,
7317 resumeConfig: &Config{
7318 MaxVersion: VersionTLS12,
7319 Bugs: ProtocolBugs{
7320 FragmentAcrossChangeCipherSpec: true,
7321 PackHandshakeFlight: packed,
7322 },
7323 },
7324 shouldFail: true,
7325 expectedError: ":UNEXPECTED_RECORD:",
7326 })
7327 testCases = append(testCases, testCase{
7328 testType: serverTest,
7329 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7330 config: Config{
7331 MaxVersion: VersionTLS12,
7332 Bugs: ProtocolBugs{
7333 FragmentAcrossChangeCipherSpec: true,
7334 PackHandshakeFlight: packed,
7335 },
7336 },
7337 shouldFail: true,
7338 expectedError: ":UNEXPECTED_RECORD:",
7339 })
7340 testCases = append(testCases, testCase{
7341 testType: serverTest,
7342 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7343 config: Config{
7344 MaxVersion: VersionTLS12,
7345 },
7346 resumeSession: true,
7347 resumeConfig: &Config{
7348 MaxVersion: VersionTLS12,
7349 Bugs: ProtocolBugs{
7350 FragmentAcrossChangeCipherSpec: true,
7351 PackHandshakeFlight: packed,
7352 },
7353 },
7354 shouldFail: true,
7355 expectedError: ":UNEXPECTED_RECORD:",
7356 })
7357 testCases = append(testCases, testCase{
7358 testType: serverTest,
7359 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7360 config: Config{
7361 MaxVersion: VersionTLS12,
7362 NextProtos: []string{"bar"},
7363 Bugs: ProtocolBugs{
7364 FragmentAcrossChangeCipherSpec: true,
7365 PackHandshakeFlight: packed,
7366 },
7367 },
7368 flags: []string{
7369 "-advertise-npn", "\x03foo\x03bar\x03baz",
7370 },
7371 shouldFail: true,
7372 expectedError: ":UNEXPECTED_RECORD:",
7373 })
7374 }
7375
David Benjamin61672812016-07-14 23:10:43 -04007376 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7377 // messages in the handshake queue. Do this by testing the server
7378 // reading the client Finished, reversing the flight so Finished comes
7379 // first.
7380 testCases = append(testCases, testCase{
7381 protocol: dtls,
7382 testType: serverTest,
7383 name: "SendUnencryptedFinished-DTLS",
7384 config: Config{
7385 MaxVersion: VersionTLS12,
7386 Bugs: ProtocolBugs{
7387 SendUnencryptedFinished: true,
7388 ReverseHandshakeFragments: true,
7389 },
7390 },
7391 shouldFail: true,
7392 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7393 })
7394
Steven Valdez143e8b32016-07-11 13:19:03 -04007395 // Test synchronization between encryption changes and the handshake in
7396 // TLS 1.3, where ChangeCipherSpec is implicit.
7397 testCases = append(testCases, testCase{
7398 name: "PartialEncryptedExtensionsWithServerHello",
7399 config: Config{
7400 MaxVersion: VersionTLS13,
7401 Bugs: ProtocolBugs{
7402 PartialEncryptedExtensionsWithServerHello: true,
7403 },
7404 },
7405 shouldFail: true,
7406 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7407 })
7408 testCases = append(testCases, testCase{
7409 testType: serverTest,
7410 name: "PartialClientFinishedWithClientHello",
7411 config: Config{
7412 MaxVersion: VersionTLS13,
7413 Bugs: ProtocolBugs{
7414 PartialClientFinishedWithClientHello: true,
7415 },
7416 },
7417 shouldFail: true,
7418 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7419 })
7420
David Benjamin82261be2016-07-07 14:32:50 -07007421 // Test that early ChangeCipherSpecs are handled correctly.
7422 testCases = append(testCases, testCase{
7423 testType: serverTest,
7424 name: "EarlyChangeCipherSpec-server-1",
7425 config: Config{
7426 MaxVersion: VersionTLS12,
7427 Bugs: ProtocolBugs{
7428 EarlyChangeCipherSpec: 1,
7429 },
7430 },
7431 shouldFail: true,
7432 expectedError: ":UNEXPECTED_RECORD:",
7433 })
7434 testCases = append(testCases, testCase{
7435 testType: serverTest,
7436 name: "EarlyChangeCipherSpec-server-2",
7437 config: Config{
7438 MaxVersion: VersionTLS12,
7439 Bugs: ProtocolBugs{
7440 EarlyChangeCipherSpec: 2,
7441 },
7442 },
7443 shouldFail: true,
7444 expectedError: ":UNEXPECTED_RECORD:",
7445 })
7446 testCases = append(testCases, testCase{
7447 protocol: dtls,
7448 name: "StrayChangeCipherSpec",
7449 config: Config{
7450 // TODO(davidben): Once DTLS 1.3 exists, test
7451 // that stray ChangeCipherSpec messages are
7452 // rejected.
7453 MaxVersion: VersionTLS12,
7454 Bugs: ProtocolBugs{
7455 StrayChangeCipherSpec: true,
7456 },
7457 },
7458 })
7459
7460 // Test that the contents of ChangeCipherSpec are checked.
7461 testCases = append(testCases, testCase{
7462 name: "BadChangeCipherSpec-1",
7463 config: Config{
7464 MaxVersion: VersionTLS12,
7465 Bugs: ProtocolBugs{
7466 BadChangeCipherSpec: []byte{2},
7467 },
7468 },
7469 shouldFail: true,
7470 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7471 })
7472 testCases = append(testCases, testCase{
7473 name: "BadChangeCipherSpec-2",
7474 config: Config{
7475 MaxVersion: VersionTLS12,
7476 Bugs: ProtocolBugs{
7477 BadChangeCipherSpec: []byte{1, 1},
7478 },
7479 },
7480 shouldFail: true,
7481 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7482 })
7483 testCases = append(testCases, testCase{
7484 protocol: dtls,
7485 name: "BadChangeCipherSpec-DTLS-1",
7486 config: Config{
7487 MaxVersion: VersionTLS12,
7488 Bugs: ProtocolBugs{
7489 BadChangeCipherSpec: []byte{2},
7490 },
7491 },
7492 shouldFail: true,
7493 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7494 })
7495 testCases = append(testCases, testCase{
7496 protocol: dtls,
7497 name: "BadChangeCipherSpec-DTLS-2",
7498 config: Config{
7499 MaxVersion: VersionTLS12,
7500 Bugs: ProtocolBugs{
7501 BadChangeCipherSpec: []byte{1, 1},
7502 },
7503 },
7504 shouldFail: true,
7505 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7506 })
7507}
7508
David Benjamin0b8d5da2016-07-15 00:39:56 -04007509func addWrongMessageTypeTests() {
7510 for _, protocol := range []protocol{tls, dtls} {
7511 var suffix string
7512 if protocol == dtls {
7513 suffix = "-DTLS"
7514 }
7515
7516 testCases = append(testCases, testCase{
7517 protocol: protocol,
7518 testType: serverTest,
7519 name: "WrongMessageType-ClientHello" + suffix,
7520 config: Config{
7521 MaxVersion: VersionTLS12,
7522 Bugs: ProtocolBugs{
7523 SendWrongMessageType: typeClientHello,
7524 },
7525 },
7526 shouldFail: true,
7527 expectedError: ":UNEXPECTED_MESSAGE:",
7528 expectedLocalError: "remote error: unexpected message",
7529 })
7530
7531 if protocol == dtls {
7532 testCases = append(testCases, testCase{
7533 protocol: protocol,
7534 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7535 config: Config{
7536 MaxVersion: VersionTLS12,
7537 Bugs: ProtocolBugs{
7538 SendWrongMessageType: typeHelloVerifyRequest,
7539 },
7540 },
7541 shouldFail: true,
7542 expectedError: ":UNEXPECTED_MESSAGE:",
7543 expectedLocalError: "remote error: unexpected message",
7544 })
7545 }
7546
7547 testCases = append(testCases, testCase{
7548 protocol: protocol,
7549 name: "WrongMessageType-ServerHello" + suffix,
7550 config: Config{
7551 MaxVersion: VersionTLS12,
7552 Bugs: ProtocolBugs{
7553 SendWrongMessageType: typeServerHello,
7554 },
7555 },
7556 shouldFail: true,
7557 expectedError: ":UNEXPECTED_MESSAGE:",
7558 expectedLocalError: "remote error: unexpected message",
7559 })
7560
7561 testCases = append(testCases, testCase{
7562 protocol: protocol,
7563 name: "WrongMessageType-ServerCertificate" + suffix,
7564 config: Config{
7565 MaxVersion: VersionTLS12,
7566 Bugs: ProtocolBugs{
7567 SendWrongMessageType: typeCertificate,
7568 },
7569 },
7570 shouldFail: true,
7571 expectedError: ":UNEXPECTED_MESSAGE:",
7572 expectedLocalError: "remote error: unexpected message",
7573 })
7574
7575 testCases = append(testCases, testCase{
7576 protocol: protocol,
7577 name: "WrongMessageType-CertificateStatus" + suffix,
7578 config: Config{
7579 MaxVersion: VersionTLS12,
7580 Bugs: ProtocolBugs{
7581 SendWrongMessageType: typeCertificateStatus,
7582 },
7583 },
7584 flags: []string{"-enable-ocsp-stapling"},
7585 shouldFail: true,
7586 expectedError: ":UNEXPECTED_MESSAGE:",
7587 expectedLocalError: "remote error: unexpected message",
7588 })
7589
7590 testCases = append(testCases, testCase{
7591 protocol: protocol,
7592 name: "WrongMessageType-ServerKeyExchange" + suffix,
7593 config: Config{
7594 MaxVersion: VersionTLS12,
7595 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7596 Bugs: ProtocolBugs{
7597 SendWrongMessageType: typeServerKeyExchange,
7598 },
7599 },
7600 shouldFail: true,
7601 expectedError: ":UNEXPECTED_MESSAGE:",
7602 expectedLocalError: "remote error: unexpected message",
7603 })
7604
7605 testCases = append(testCases, testCase{
7606 protocol: protocol,
7607 name: "WrongMessageType-CertificateRequest" + suffix,
7608 config: Config{
7609 MaxVersion: VersionTLS12,
7610 ClientAuth: RequireAnyClientCert,
7611 Bugs: ProtocolBugs{
7612 SendWrongMessageType: typeCertificateRequest,
7613 },
7614 },
7615 shouldFail: true,
7616 expectedError: ":UNEXPECTED_MESSAGE:",
7617 expectedLocalError: "remote error: unexpected message",
7618 })
7619
7620 testCases = append(testCases, testCase{
7621 protocol: protocol,
7622 name: "WrongMessageType-ServerHelloDone" + suffix,
7623 config: Config{
7624 MaxVersion: VersionTLS12,
7625 Bugs: ProtocolBugs{
7626 SendWrongMessageType: typeServerHelloDone,
7627 },
7628 },
7629 shouldFail: true,
7630 expectedError: ":UNEXPECTED_MESSAGE:",
7631 expectedLocalError: "remote error: unexpected message",
7632 })
7633
7634 testCases = append(testCases, testCase{
7635 testType: serverTest,
7636 protocol: protocol,
7637 name: "WrongMessageType-ClientCertificate" + suffix,
7638 config: Config{
7639 Certificates: []Certificate{rsaCertificate},
7640 MaxVersion: VersionTLS12,
7641 Bugs: ProtocolBugs{
7642 SendWrongMessageType: typeCertificate,
7643 },
7644 },
7645 flags: []string{"-require-any-client-certificate"},
7646 shouldFail: true,
7647 expectedError: ":UNEXPECTED_MESSAGE:",
7648 expectedLocalError: "remote error: unexpected message",
7649 })
7650
7651 testCases = append(testCases, testCase{
7652 testType: serverTest,
7653 protocol: protocol,
7654 name: "WrongMessageType-CertificateVerify" + suffix,
7655 config: Config{
7656 Certificates: []Certificate{rsaCertificate},
7657 MaxVersion: VersionTLS12,
7658 Bugs: ProtocolBugs{
7659 SendWrongMessageType: typeCertificateVerify,
7660 },
7661 },
7662 flags: []string{"-require-any-client-certificate"},
7663 shouldFail: true,
7664 expectedError: ":UNEXPECTED_MESSAGE:",
7665 expectedLocalError: "remote error: unexpected message",
7666 })
7667
7668 testCases = append(testCases, testCase{
7669 testType: serverTest,
7670 protocol: protocol,
7671 name: "WrongMessageType-ClientKeyExchange" + suffix,
7672 config: Config{
7673 MaxVersion: VersionTLS12,
7674 Bugs: ProtocolBugs{
7675 SendWrongMessageType: typeClientKeyExchange,
7676 },
7677 },
7678 shouldFail: true,
7679 expectedError: ":UNEXPECTED_MESSAGE:",
7680 expectedLocalError: "remote error: unexpected message",
7681 })
7682
7683 if protocol != dtls {
7684 testCases = append(testCases, testCase{
7685 testType: serverTest,
7686 protocol: protocol,
7687 name: "WrongMessageType-NextProtocol" + suffix,
7688 config: Config{
7689 MaxVersion: VersionTLS12,
7690 NextProtos: []string{"bar"},
7691 Bugs: ProtocolBugs{
7692 SendWrongMessageType: typeNextProtocol,
7693 },
7694 },
7695 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7696 shouldFail: true,
7697 expectedError: ":UNEXPECTED_MESSAGE:",
7698 expectedLocalError: "remote error: unexpected message",
7699 })
7700
7701 testCases = append(testCases, testCase{
7702 testType: serverTest,
7703 protocol: protocol,
7704 name: "WrongMessageType-ChannelID" + suffix,
7705 config: Config{
7706 MaxVersion: VersionTLS12,
7707 ChannelID: channelIDKey,
7708 Bugs: ProtocolBugs{
7709 SendWrongMessageType: typeChannelID,
7710 },
7711 },
7712 flags: []string{
7713 "-expect-channel-id",
7714 base64.StdEncoding.EncodeToString(channelIDBytes),
7715 },
7716 shouldFail: true,
7717 expectedError: ":UNEXPECTED_MESSAGE:",
7718 expectedLocalError: "remote error: unexpected message",
7719 })
7720 }
7721
7722 testCases = append(testCases, testCase{
7723 testType: serverTest,
7724 protocol: protocol,
7725 name: "WrongMessageType-ClientFinished" + suffix,
7726 config: Config{
7727 MaxVersion: VersionTLS12,
7728 Bugs: ProtocolBugs{
7729 SendWrongMessageType: typeFinished,
7730 },
7731 },
7732 shouldFail: true,
7733 expectedError: ":UNEXPECTED_MESSAGE:",
7734 expectedLocalError: "remote error: unexpected message",
7735 })
7736
7737 testCases = append(testCases, testCase{
7738 protocol: protocol,
7739 name: "WrongMessageType-NewSessionTicket" + suffix,
7740 config: Config{
7741 MaxVersion: VersionTLS12,
7742 Bugs: ProtocolBugs{
7743 SendWrongMessageType: typeNewSessionTicket,
7744 },
7745 },
7746 shouldFail: true,
7747 expectedError: ":UNEXPECTED_MESSAGE:",
7748 expectedLocalError: "remote error: unexpected message",
7749 })
7750
7751 testCases = append(testCases, testCase{
7752 protocol: protocol,
7753 name: "WrongMessageType-ServerFinished" + suffix,
7754 config: Config{
7755 MaxVersion: VersionTLS12,
7756 Bugs: ProtocolBugs{
7757 SendWrongMessageType: typeFinished,
7758 },
7759 },
7760 shouldFail: true,
7761 expectedError: ":UNEXPECTED_MESSAGE:",
7762 expectedLocalError: "remote error: unexpected message",
7763 })
7764
7765 }
7766}
7767
Steven Valdez143e8b32016-07-11 13:19:03 -04007768func addTLS13WrongMessageTypeTests() {
7769 testCases = append(testCases, testCase{
7770 testType: serverTest,
7771 name: "WrongMessageType-TLS13-ClientHello",
7772 config: Config{
7773 MaxVersion: VersionTLS13,
7774 Bugs: ProtocolBugs{
7775 SendWrongMessageType: typeClientHello,
7776 },
7777 },
7778 shouldFail: true,
7779 expectedError: ":UNEXPECTED_MESSAGE:",
7780 expectedLocalError: "remote error: unexpected message",
7781 })
7782
7783 testCases = append(testCases, testCase{
7784 name: "WrongMessageType-TLS13-ServerHello",
7785 config: Config{
7786 MaxVersion: VersionTLS13,
7787 Bugs: ProtocolBugs{
7788 SendWrongMessageType: typeServerHello,
7789 },
7790 },
7791 shouldFail: true,
7792 expectedError: ":UNEXPECTED_MESSAGE:",
7793 // The alert comes in with the wrong encryption.
7794 expectedLocalError: "local error: bad record MAC",
7795 })
7796
7797 testCases = append(testCases, testCase{
7798 name: "WrongMessageType-TLS13-EncryptedExtensions",
7799 config: Config{
7800 MaxVersion: VersionTLS13,
7801 Bugs: ProtocolBugs{
7802 SendWrongMessageType: typeEncryptedExtensions,
7803 },
7804 },
7805 shouldFail: true,
7806 expectedError: ":UNEXPECTED_MESSAGE:",
7807 expectedLocalError: "remote error: unexpected message",
7808 })
7809
7810 testCases = append(testCases, testCase{
7811 name: "WrongMessageType-TLS13-CertificateRequest",
7812 config: Config{
7813 MaxVersion: VersionTLS13,
7814 ClientAuth: RequireAnyClientCert,
7815 Bugs: ProtocolBugs{
7816 SendWrongMessageType: typeCertificateRequest,
7817 },
7818 },
7819 shouldFail: true,
7820 expectedError: ":UNEXPECTED_MESSAGE:",
7821 expectedLocalError: "remote error: unexpected message",
7822 })
7823
7824 testCases = append(testCases, testCase{
7825 name: "WrongMessageType-TLS13-ServerCertificate",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 Bugs: ProtocolBugs{
7829 SendWrongMessageType: typeCertificate,
7830 },
7831 },
7832 shouldFail: true,
7833 expectedError: ":UNEXPECTED_MESSAGE:",
7834 expectedLocalError: "remote error: unexpected message",
7835 })
7836
7837 testCases = append(testCases, testCase{
7838 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7839 config: Config{
7840 MaxVersion: VersionTLS13,
7841 Bugs: ProtocolBugs{
7842 SendWrongMessageType: typeCertificateVerify,
7843 },
7844 },
7845 shouldFail: true,
7846 expectedError: ":UNEXPECTED_MESSAGE:",
7847 expectedLocalError: "remote error: unexpected message",
7848 })
7849
7850 testCases = append(testCases, testCase{
7851 name: "WrongMessageType-TLS13-ServerFinished",
7852 config: Config{
7853 MaxVersion: VersionTLS13,
7854 Bugs: ProtocolBugs{
7855 SendWrongMessageType: typeFinished,
7856 },
7857 },
7858 shouldFail: true,
7859 expectedError: ":UNEXPECTED_MESSAGE:",
7860 expectedLocalError: "remote error: unexpected message",
7861 })
7862
7863 testCases = append(testCases, testCase{
7864 testType: serverTest,
7865 name: "WrongMessageType-TLS13-ClientCertificate",
7866 config: Config{
7867 Certificates: []Certificate{rsaCertificate},
7868 MaxVersion: VersionTLS13,
7869 Bugs: ProtocolBugs{
7870 SendWrongMessageType: typeCertificate,
7871 },
7872 },
7873 flags: []string{"-require-any-client-certificate"},
7874 shouldFail: true,
7875 expectedError: ":UNEXPECTED_MESSAGE:",
7876 expectedLocalError: "remote error: unexpected message",
7877 })
7878
7879 testCases = append(testCases, testCase{
7880 testType: serverTest,
7881 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7882 config: Config{
7883 Certificates: []Certificate{rsaCertificate},
7884 MaxVersion: VersionTLS13,
7885 Bugs: ProtocolBugs{
7886 SendWrongMessageType: typeCertificateVerify,
7887 },
7888 },
7889 flags: []string{"-require-any-client-certificate"},
7890 shouldFail: true,
7891 expectedError: ":UNEXPECTED_MESSAGE:",
7892 expectedLocalError: "remote error: unexpected message",
7893 })
7894
7895 testCases = append(testCases, testCase{
7896 testType: serverTest,
7897 name: "WrongMessageType-TLS13-ClientFinished",
7898 config: Config{
7899 MaxVersion: VersionTLS13,
7900 Bugs: ProtocolBugs{
7901 SendWrongMessageType: typeFinished,
7902 },
7903 },
7904 shouldFail: true,
7905 expectedError: ":UNEXPECTED_MESSAGE:",
7906 expectedLocalError: "remote error: unexpected message",
7907 })
7908}
7909
7910func addTLS13HandshakeTests() {
7911 testCases = append(testCases, testCase{
7912 testType: clientTest,
7913 name: "MissingKeyShare-Client",
7914 config: Config{
7915 MaxVersion: VersionTLS13,
7916 Bugs: ProtocolBugs{
7917 MissingKeyShare: true,
7918 },
7919 },
7920 shouldFail: true,
7921 expectedError: ":MISSING_KEY_SHARE:",
7922 })
7923
7924 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007925 testType: serverTest,
7926 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007927 config: Config{
7928 MaxVersion: VersionTLS13,
7929 Bugs: ProtocolBugs{
7930 MissingKeyShare: true,
7931 },
7932 },
7933 shouldFail: true,
7934 expectedError: ":MISSING_KEY_SHARE:",
7935 })
7936
7937 testCases = append(testCases, testCase{
7938 testType: clientTest,
7939 name: "ClientHelloMissingKeyShare",
7940 config: Config{
7941 MaxVersion: VersionTLS13,
7942 Bugs: ProtocolBugs{
7943 MissingKeyShare: true,
7944 },
7945 },
7946 shouldFail: true,
7947 expectedError: ":MISSING_KEY_SHARE:",
7948 })
7949
7950 testCases = append(testCases, testCase{
7951 testType: clientTest,
7952 name: "MissingKeyShare",
7953 config: Config{
7954 MaxVersion: VersionTLS13,
7955 Bugs: ProtocolBugs{
7956 MissingKeyShare: true,
7957 },
7958 },
7959 shouldFail: true,
7960 expectedError: ":MISSING_KEY_SHARE:",
7961 })
7962
7963 testCases = append(testCases, testCase{
7964 testType: serverTest,
7965 name: "DuplicateKeyShares",
7966 config: Config{
7967 MaxVersion: VersionTLS13,
7968 Bugs: ProtocolBugs{
7969 DuplicateKeyShares: true,
7970 },
7971 },
7972 })
7973
7974 testCases = append(testCases, testCase{
7975 testType: clientTest,
7976 name: "EmptyEncryptedExtensions",
7977 config: Config{
7978 MaxVersion: VersionTLS13,
7979 Bugs: ProtocolBugs{
7980 EmptyEncryptedExtensions: true,
7981 },
7982 },
7983 shouldFail: true,
7984 expectedLocalError: "remote error: error decoding message",
7985 })
7986
7987 testCases = append(testCases, testCase{
7988 testType: clientTest,
7989 name: "EncryptedExtensionsWithKeyShare",
7990 config: Config{
7991 MaxVersion: VersionTLS13,
7992 Bugs: ProtocolBugs{
7993 EncryptedExtensionsWithKeyShare: true,
7994 },
7995 },
7996 shouldFail: true,
7997 expectedLocalError: "remote error: unsupported extension",
7998 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007999
8000 testCases = append(testCases, testCase{
8001 testType: serverTest,
8002 name: "SendHelloRetryRequest",
8003 config: Config{
8004 MaxVersion: VersionTLS13,
8005 // Require a HelloRetryRequest for every curve.
8006 DefaultCurves: []CurveID{},
8007 },
8008 expectedCurveID: CurveX25519,
8009 })
8010
8011 testCases = append(testCases, testCase{
8012 testType: serverTest,
8013 name: "SendHelloRetryRequest-2",
8014 config: Config{
8015 MaxVersion: VersionTLS13,
8016 DefaultCurves: []CurveID{CurveP384},
8017 },
8018 // Although the ClientHello did not predict our preferred curve,
8019 // we always select it whether it is predicted or not.
8020 expectedCurveID: CurveX25519,
8021 })
8022
8023 testCases = append(testCases, testCase{
8024 name: "UnknownCurve-HelloRetryRequest",
8025 config: Config{
8026 MaxVersion: VersionTLS13,
8027 // P-384 requires HelloRetryRequest in BoringSSL.
8028 CurvePreferences: []CurveID{CurveP384},
8029 Bugs: ProtocolBugs{
8030 SendHelloRetryRequestCurve: bogusCurve,
8031 },
8032 },
8033 shouldFail: true,
8034 expectedError: ":WRONG_CURVE:",
8035 })
8036
8037 testCases = append(testCases, testCase{
8038 name: "DisabledCurve-HelloRetryRequest",
8039 config: Config{
8040 MaxVersion: VersionTLS13,
8041 CurvePreferences: []CurveID{CurveP256},
8042 Bugs: ProtocolBugs{
8043 IgnorePeerCurvePreferences: true,
8044 },
8045 },
8046 flags: []string{"-p384-only"},
8047 shouldFail: true,
8048 expectedError: ":WRONG_CURVE:",
8049 })
8050
8051 testCases = append(testCases, testCase{
8052 name: "UnnecessaryHelloRetryRequest",
8053 config: Config{
8054 MaxVersion: VersionTLS13,
8055 Bugs: ProtocolBugs{
8056 UnnecessaryHelloRetryRequest: true,
8057 },
8058 },
8059 shouldFail: true,
8060 expectedError: ":WRONG_CURVE:",
8061 })
8062
8063 testCases = append(testCases, testCase{
8064 name: "SecondHelloRetryRequest",
8065 config: Config{
8066 MaxVersion: VersionTLS13,
8067 // P-384 requires HelloRetryRequest in BoringSSL.
8068 CurvePreferences: []CurveID{CurveP384},
8069 Bugs: ProtocolBugs{
8070 SecondHelloRetryRequest: true,
8071 },
8072 },
8073 shouldFail: true,
8074 expectedError: ":UNEXPECTED_MESSAGE:",
8075 })
8076
8077 testCases = append(testCases, testCase{
8078 testType: serverTest,
8079 name: "SecondClientHelloMissingKeyShare",
8080 config: Config{
8081 MaxVersion: VersionTLS13,
8082 DefaultCurves: []CurveID{},
8083 Bugs: ProtocolBugs{
8084 SecondClientHelloMissingKeyShare: true,
8085 },
8086 },
8087 shouldFail: true,
8088 expectedError: ":MISSING_KEY_SHARE:",
8089 })
8090
8091 testCases = append(testCases, testCase{
8092 testType: serverTest,
8093 name: "SecondClientHelloWrongCurve",
8094 config: Config{
8095 MaxVersion: VersionTLS13,
8096 DefaultCurves: []CurveID{},
8097 Bugs: ProtocolBugs{
8098 MisinterpretHelloRetryRequestCurve: CurveP521,
8099 },
8100 },
8101 shouldFail: true,
8102 expectedError: ":WRONG_CURVE:",
8103 })
8104
8105 testCases = append(testCases, testCase{
8106 name: "HelloRetryRequestVersionMismatch",
8107 config: Config{
8108 MaxVersion: VersionTLS13,
8109 // P-384 requires HelloRetryRequest in BoringSSL.
8110 CurvePreferences: []CurveID{CurveP384},
8111 Bugs: ProtocolBugs{
8112 SendServerHelloVersion: 0x0305,
8113 },
8114 },
8115 shouldFail: true,
8116 expectedError: ":WRONG_VERSION_NUMBER:",
8117 })
8118
8119 testCases = append(testCases, testCase{
8120 name: "HelloRetryRequestCurveMismatch",
8121 config: Config{
8122 MaxVersion: VersionTLS13,
8123 // P-384 requires HelloRetryRequest in BoringSSL.
8124 CurvePreferences: []CurveID{CurveP384},
8125 Bugs: ProtocolBugs{
8126 // Send P-384 (correct) in the HelloRetryRequest.
8127 SendHelloRetryRequestCurve: CurveP384,
8128 // But send P-256 in the ServerHello.
8129 SendCurve: CurveP256,
8130 },
8131 },
8132 shouldFail: true,
8133 expectedError: ":WRONG_CURVE:",
8134 })
8135
8136 // Test the server selecting a curve that requires a HelloRetryRequest
8137 // without sending it.
8138 testCases = append(testCases, testCase{
8139 name: "SkipHelloRetryRequest",
8140 config: Config{
8141 MaxVersion: VersionTLS13,
8142 // P-384 requires HelloRetryRequest in BoringSSL.
8143 CurvePreferences: []CurveID{CurveP384},
8144 Bugs: ProtocolBugs{
8145 SkipHelloRetryRequest: true,
8146 },
8147 },
8148 shouldFail: true,
8149 expectedError: ":WRONG_CURVE:",
8150 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008151
8152 testCases = append(testCases, testCase{
8153 name: "TLS13-RequestContextInHandshake",
8154 config: Config{
8155 MaxVersion: VersionTLS13,
8156 MinVersion: VersionTLS13,
8157 ClientAuth: RequireAnyClientCert,
8158 Bugs: ProtocolBugs{
8159 SendRequestContext: []byte("request context"),
8160 },
8161 },
8162 flags: []string{
8163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8165 },
8166 shouldFail: true,
8167 expectedError: ":DECODE_ERROR:",
8168 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008169}
8170
Adam Langley7c803a62015-06-15 15:35:05 -07008171func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008172 defer wg.Done()
8173
8174 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008175 var err error
8176
8177 if *mallocTest < 0 {
8178 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008179 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008180 } else {
8181 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8182 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008183 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008184 if err != nil {
8185 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8186 }
8187 break
8188 }
8189 }
8190 }
Adam Langley95c29f32014-06-20 12:00:00 -07008191 statusChan <- statusMsg{test: test, err: err}
8192 }
8193}
8194
8195type statusMsg struct {
8196 test *testCase
8197 started bool
8198 err error
8199}
8200
David Benjamin5f237bc2015-02-11 17:14:15 -05008201func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008202 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008203
David Benjamin5f237bc2015-02-11 17:14:15 -05008204 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008205 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008206 if !*pipe {
8207 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008208 var erase string
8209 for i := 0; i < lineLen; i++ {
8210 erase += "\b \b"
8211 }
8212 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008213 }
8214
Adam Langley95c29f32014-06-20 12:00:00 -07008215 if msg.started {
8216 started++
8217 } else {
8218 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008219
8220 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008221 if msg.err == errUnimplemented {
8222 if *pipe {
8223 // Print each test instead of a status line.
8224 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8225 }
8226 unimplemented++
8227 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8228 } else {
8229 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8230 failed++
8231 testOutput.addResult(msg.test.name, "FAIL")
8232 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008233 } else {
8234 if *pipe {
8235 // Print each test instead of a status line.
8236 fmt.Printf("PASSED (%s)\n", msg.test.name)
8237 }
8238 testOutput.addResult(msg.test.name, "PASS")
8239 }
Adam Langley95c29f32014-06-20 12:00:00 -07008240 }
8241
David Benjamin5f237bc2015-02-11 17:14:15 -05008242 if !*pipe {
8243 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008244 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008245 lineLen = len(line)
8246 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008247 }
Adam Langley95c29f32014-06-20 12:00:00 -07008248 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008249
8250 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008251}
8252
8253func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008254 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008255 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008256 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008257
Adam Langley7c803a62015-06-15 15:35:05 -07008258 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008259 addCipherSuiteTests()
8260 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008261 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008262 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008263 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008264 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008265 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008266 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008267 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008268 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008269 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008270 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008271 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008272 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008273 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008274 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008275 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008276 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008277 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008278 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008279 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008280 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008281 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008282 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008283 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008284 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008285 addTLS13WrongMessageTypeTests()
8286 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008287
8288 var wg sync.WaitGroup
8289
Adam Langley7c803a62015-06-15 15:35:05 -07008290 statusChan := make(chan statusMsg, *numWorkers)
8291 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008292 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008293
EKRf71d7ed2016-08-06 13:25:12 -07008294 if len(*shimConfigFile) != 0 {
8295 encoded, err := ioutil.ReadFile(*shimConfigFile)
8296 if err != nil {
8297 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8298 os.Exit(1)
8299 }
8300
8301 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8302 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8303 os.Exit(1)
8304 }
8305 }
8306
David Benjamin025b3d32014-07-01 19:53:04 -04008307 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008308
Adam Langley7c803a62015-06-15 15:35:05 -07008309 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008310 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008311 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008312 }
8313
David Benjamin270f0a72016-03-17 14:41:36 -04008314 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008315 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008316 matched := true
8317 if len(*testToRun) != 0 {
8318 var err error
8319 matched, err = filepath.Match(*testToRun, testCases[i].name)
8320 if err != nil {
8321 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8322 os.Exit(1)
8323 }
8324 }
8325
EKRf71d7ed2016-08-06 13:25:12 -07008326 if !*includeDisabled {
8327 for pattern := range shimConfig.DisabledTests {
8328 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8329 if err != nil {
8330 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8331 os.Exit(1)
8332 }
8333
8334 if isDisabled {
8335 matched = false
8336 break
8337 }
8338 }
8339 }
8340
David Benjamin17e12922016-07-28 18:04:43 -04008341 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008342 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008343 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008344 }
8345 }
David Benjamin17e12922016-07-28 18:04:43 -04008346
David Benjamin270f0a72016-03-17 14:41:36 -04008347 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008348 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008349 os.Exit(1)
8350 }
Adam Langley95c29f32014-06-20 12:00:00 -07008351
8352 close(testChan)
8353 wg.Wait()
8354 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008355 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008356
8357 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008358
8359 if *jsonOutput != "" {
8360 if err := testOutput.writeTo(*jsonOutput); err != nil {
8361 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8362 }
8363 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008364
EKR842ae6c2016-07-27 09:22:05 +02008365 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8366 os.Exit(1)
8367 }
8368
8369 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008370 os.Exit(1)
8371 }
Adam Langley95c29f32014-06-20 12:00:00 -07008372}