blob: cbb87869cd2a970ae844d818f385cfdcd0cfea9c [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 },
David Benjaminabe94e32016-09-04 14:18:58 -04002250 {
2251 name: "SendSNIWarningAlert",
2252 config: Config{
2253 MaxVersion: VersionTLS12,
2254 Bugs: ProtocolBugs{
2255 SendSNIWarningAlert: true,
2256 },
2257 },
2258 },
Adam Langley7c803a62015-06-15 15:35:05 -07002259 }
Adam Langley7c803a62015-06-15 15:35:05 -07002260 testCases = append(testCases, basicTests...)
2261}
2262
Adam Langley95c29f32014-06-20 12:00:00 -07002263func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002264 const bogusCipher = 0xfe00
2265
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002266 if *includeRC4 {
2267 testCipherSuites = append(testCipherSuites, []struct {
2268 name string
2269 id uint16
2270 }{
2271 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
2272 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2273 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
2274 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
2275 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
2276 }...)
2277 }
2278
Adam Langley95c29f32014-06-20 12:00:00 -07002279 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002280 const psk = "12345"
2281 const pskIdentity = "luggage combo"
2282
Adam Langley95c29f32014-06-20 12:00:00 -07002283 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002284 var certFile string
2285 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002286 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002287 cert = ecdsaP256Certificate
2288 certFile = ecdsaP256CertificateFile
2289 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002290 } else {
David Benjamin33863262016-07-08 17:20:12 -07002291 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002292 certFile = rsaCertificateFile
2293 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002294 }
2295
David Benjamin48cae082014-10-27 01:06:24 -04002296 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002297 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002298 flags = append(flags,
2299 "-psk", psk,
2300 "-psk-identity", pskIdentity)
2301 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002302 if hasComponent(suite.name, "NULL") {
2303 // NULL ciphers must be explicitly enabled.
2304 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2305 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002306 if hasComponent(suite.name, "CECPQ1") {
2307 // CECPQ1 ciphers must be explicitly enabled.
2308 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2309 }
David Benjamin881f1962016-08-10 18:29:12 -04002310 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2311 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2312 // for now.
2313 flags = append(flags, "-cipher", suite.name)
2314 }
David Benjamin48cae082014-10-27 01:06:24 -04002315
Adam Langley95c29f32014-06-20 12:00:00 -07002316 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002317 for _, protocol := range []protocol{tls, dtls} {
2318 var prefix string
2319 if protocol == dtls {
2320 if !ver.hasDTLS {
2321 continue
2322 }
2323 prefix = "D"
2324 }
Adam Langley95c29f32014-06-20 12:00:00 -07002325
David Benjamin0407e762016-06-17 16:41:18 -04002326 var shouldServerFail, shouldClientFail bool
2327 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2328 // BoringSSL clients accept ECDHE on SSLv3, but
2329 // a BoringSSL server will never select it
2330 // because the extension is missing.
2331 shouldServerFail = true
2332 }
2333 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2334 shouldClientFail = true
2335 shouldServerFail = true
2336 }
David Benjamin54c217c2016-07-13 12:35:25 -04002337 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002338 shouldClientFail = true
2339 shouldServerFail = true
2340 }
David Benjamin0407e762016-06-17 16:41:18 -04002341 if !isDTLSCipher(suite.name) && protocol == dtls {
2342 shouldClientFail = true
2343 shouldServerFail = true
2344 }
David Benjamin4298d772015-12-19 00:18:25 -05002345
David Benjamin0407e762016-06-17 16:41:18 -04002346 var expectedServerError, expectedClientError string
2347 if shouldServerFail {
2348 expectedServerError = ":NO_SHARED_CIPHER:"
2349 }
2350 if shouldClientFail {
2351 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2352 }
David Benjamin025b3d32014-07-01 19:53:04 -04002353
David Benjamin6fd297b2014-08-11 18:43:38 -04002354 testCases = append(testCases, testCase{
2355 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002356 protocol: protocol,
2357
2358 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002359 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002360 MinVersion: ver.version,
2361 MaxVersion: ver.version,
2362 CipherSuites: []uint16{suite.id},
2363 Certificates: []Certificate{cert},
2364 PreSharedKey: []byte(psk),
2365 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002366 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002367 EnableAllCiphers: shouldServerFail,
2368 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002369 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002370 },
2371 certFile: certFile,
2372 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002373 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002374 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002375 shouldFail: shouldServerFail,
2376 expectedError: expectedServerError,
2377 })
2378
2379 testCases = append(testCases, testCase{
2380 testType: clientTest,
2381 protocol: protocol,
2382 name: prefix + ver.name + "-" + suite.name + "-client",
2383 config: Config{
2384 MinVersion: ver.version,
2385 MaxVersion: ver.version,
2386 CipherSuites: []uint16{suite.id},
2387 Certificates: []Certificate{cert},
2388 PreSharedKey: []byte(psk),
2389 PreSharedKeyIdentity: pskIdentity,
2390 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002391 EnableAllCiphers: shouldClientFail,
2392 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002393 },
2394 },
2395 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002396 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002397 shouldFail: shouldClientFail,
2398 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002399 })
David Benjamin2c99d282015-09-01 10:23:00 -04002400
Nick Harper1fd39d82016-06-14 18:14:35 -07002401 if !shouldClientFail {
2402 // Ensure the maximum record size is accepted.
2403 testCases = append(testCases, testCase{
2404 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2405 config: Config{
2406 MinVersion: ver.version,
2407 MaxVersion: ver.version,
2408 CipherSuites: []uint16{suite.id},
2409 Certificates: []Certificate{cert},
2410 PreSharedKey: []byte(psk),
2411 PreSharedKeyIdentity: pskIdentity,
2412 },
2413 flags: flags,
2414 messageLen: maxPlaintext,
2415 })
2416 }
2417 }
David Benjamin2c99d282015-09-01 10:23:00 -04002418 }
Adam Langley95c29f32014-06-20 12:00:00 -07002419 }
Adam Langleya7997f12015-05-14 17:38:50 -07002420
2421 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002422 name: "NoSharedCipher",
2423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002424 MaxVersion: VersionTLS12,
2425 CipherSuites: []uint16{},
2426 },
2427 shouldFail: true,
2428 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2429 })
2430
2431 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002432 name: "NoSharedCipher-TLS13",
2433 config: Config{
2434 MaxVersion: VersionTLS13,
2435 CipherSuites: []uint16{},
2436 },
2437 shouldFail: true,
2438 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2439 })
2440
2441 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002442 name: "UnsupportedCipherSuite",
2443 config: Config{
2444 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002445 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002446 Bugs: ProtocolBugs{
2447 IgnorePeerCipherPreferences: true,
2448 },
2449 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002450 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002451 shouldFail: true,
2452 expectedError: ":WRONG_CIPHER_RETURNED:",
2453 })
2454
2455 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002456 name: "ServerHelloBogusCipher",
2457 config: Config{
2458 MaxVersion: VersionTLS12,
2459 Bugs: ProtocolBugs{
2460 SendCipherSuite: bogusCipher,
2461 },
2462 },
2463 shouldFail: true,
2464 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2465 })
2466 testCases = append(testCases, testCase{
2467 name: "ServerHelloBogusCipher-TLS13",
2468 config: Config{
2469 MaxVersion: VersionTLS13,
2470 Bugs: ProtocolBugs{
2471 SendCipherSuite: bogusCipher,
2472 },
2473 },
2474 shouldFail: true,
2475 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2476 })
2477
2478 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002479 name: "WeakDH",
2480 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002481 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002482 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2483 Bugs: ProtocolBugs{
2484 // This is a 1023-bit prime number, generated
2485 // with:
2486 // openssl gendh 1023 | openssl asn1parse -i
2487 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2488 },
2489 },
2490 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002491 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002492 })
Adam Langleycef75832015-09-03 14:51:12 -07002493
David Benjamincd24a392015-11-11 13:23:05 -08002494 testCases = append(testCases, testCase{
2495 name: "SillyDH",
2496 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002497 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002498 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2499 Bugs: ProtocolBugs{
2500 // This is a 4097-bit prime number, generated
2501 // with:
2502 // openssl gendh 4097 | openssl asn1parse -i
2503 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2504 },
2505 },
2506 shouldFail: true,
2507 expectedError: ":DH_P_TOO_LONG:",
2508 })
2509
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002510 // This test ensures that Diffie-Hellman public values are padded with
2511 // zeros so that they're the same length as the prime. This is to avoid
2512 // hitting a bug in yaSSL.
2513 testCases = append(testCases, testCase{
2514 testType: serverTest,
2515 name: "DHPublicValuePadded",
2516 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002517 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002518 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2519 Bugs: ProtocolBugs{
2520 RequireDHPublicValueLen: (1025 + 7) / 8,
2521 },
2522 },
2523 flags: []string{"-use-sparse-dh-prime"},
2524 })
David Benjamincd24a392015-11-11 13:23:05 -08002525
David Benjamin241ae832016-01-15 03:04:54 -05002526 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002527 testCases = append(testCases, testCase{
2528 testType: serverTest,
2529 name: "UnknownCipher",
2530 config: Config{
2531 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2532 },
2533 })
2534
Adam Langleycef75832015-09-03 14:51:12 -07002535 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2536 // 1.1 specific cipher suite settings. A server is setup with the given
2537 // cipher lists and then a connection is made for each member of
2538 // expectations. The cipher suite that the server selects must match
2539 // the specified one.
2540 var versionSpecificCiphersTest = []struct {
2541 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2542 // expectations is a map from TLS version to cipher suite id.
2543 expectations map[uint16]uint16
2544 }{
2545 {
2546 // Test that the null case (where no version-specific ciphers are set)
2547 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002548 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2549 "", // no ciphers specifically for TLS ≥ 1.0
2550 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002551 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002552 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2553 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2554 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2555 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002556 },
2557 },
2558 {
2559 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2560 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002561 "DES-CBC3-SHA:AES128-SHA", // default
2562 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2563 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002564 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002565 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002566 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2567 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2568 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2569 },
2570 },
2571 {
2572 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2573 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002574 "DES-CBC3-SHA:AES128-SHA", // default
2575 "", // no ciphers specifically for TLS ≥ 1.0
2576 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002577 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002578 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2579 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002580 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2581 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2582 },
2583 },
2584 {
2585 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2586 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002587 "DES-CBC3-SHA:AES128-SHA", // default
2588 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2589 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002590 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002591 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002592 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2593 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2594 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2595 },
2596 },
2597 }
2598
2599 for i, test := range versionSpecificCiphersTest {
2600 for version, expectedCipherSuite := range test.expectations {
2601 flags := []string{"-cipher", test.ciphersDefault}
2602 if len(test.ciphersTLS10) > 0 {
2603 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2604 }
2605 if len(test.ciphersTLS11) > 0 {
2606 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2607 }
2608
2609 testCases = append(testCases, testCase{
2610 testType: serverTest,
2611 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2612 config: Config{
2613 MaxVersion: version,
2614 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002615 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 -07002616 },
2617 flags: flags,
2618 expectedCipher: expectedCipherSuite,
2619 })
2620 }
2621 }
Adam Langley95c29f32014-06-20 12:00:00 -07002622}
2623
2624func addBadECDSASignatureTests() {
2625 for badR := BadValue(1); badR < NumBadValues; badR++ {
2626 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002627 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002628 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2629 config: Config{
2630 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002631 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002632 Bugs: ProtocolBugs{
2633 BadECDSAR: badR,
2634 BadECDSAS: badS,
2635 },
2636 },
2637 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002638 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002639 })
2640 }
2641 }
2642}
2643
Adam Langley80842bd2014-06-20 12:00:00 -07002644func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002645 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002646 name: "MaxCBCPadding",
2647 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002648 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002649 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2650 Bugs: ProtocolBugs{
2651 MaxPadding: true,
2652 },
2653 },
2654 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2655 })
David Benjamin025b3d32014-07-01 19:53:04 -04002656 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002657 name: "BadCBCPadding",
2658 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002659 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002660 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2661 Bugs: ProtocolBugs{
2662 PaddingFirstByteBad: true,
2663 },
2664 },
2665 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002666 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002667 })
2668 // OpenSSL previously had an issue where the first byte of padding in
2669 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002670 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002671 name: "BadCBCPadding255",
2672 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002673 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002674 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2675 Bugs: ProtocolBugs{
2676 MaxPadding: true,
2677 PaddingFirstByteBadIf255: true,
2678 },
2679 },
2680 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2681 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002682 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002683 })
2684}
2685
Kenny Root7fdeaf12014-08-05 15:23:37 -07002686func addCBCSplittingTests() {
2687 testCases = append(testCases, testCase{
2688 name: "CBCRecordSplitting",
2689 config: Config{
2690 MaxVersion: VersionTLS10,
2691 MinVersion: VersionTLS10,
2692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2693 },
David Benjaminac8302a2015-09-01 17:18:15 -04002694 messageLen: -1, // read until EOF
2695 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002696 flags: []string{
2697 "-async",
2698 "-write-different-record-sizes",
2699 "-cbc-record-splitting",
2700 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002701 })
2702 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002703 name: "CBCRecordSplittingPartialWrite",
2704 config: Config{
2705 MaxVersion: VersionTLS10,
2706 MinVersion: VersionTLS10,
2707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2708 },
2709 messageLen: -1, // read until EOF
2710 flags: []string{
2711 "-async",
2712 "-write-different-record-sizes",
2713 "-cbc-record-splitting",
2714 "-partial-write",
2715 },
2716 })
2717}
2718
David Benjamin636293b2014-07-08 17:59:18 -04002719func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002720 // Add a dummy cert pool to stress certificate authority parsing.
2721 // TODO(davidben): Add tests that those values parse out correctly.
2722 certPool := x509.NewCertPool()
2723 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2724 if err != nil {
2725 panic(err)
2726 }
2727 certPool.AddCert(cert)
2728
David Benjamin636293b2014-07-08 17:59:18 -04002729 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002730 testCases = append(testCases, testCase{
2731 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002732 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002733 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002734 MinVersion: ver.version,
2735 MaxVersion: ver.version,
2736 ClientAuth: RequireAnyClientCert,
2737 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002738 },
2739 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002740 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2741 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002742 },
2743 })
2744 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002745 testType: serverTest,
2746 name: ver.name + "-Server-ClientAuth-RSA",
2747 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002748 MinVersion: ver.version,
2749 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002750 Certificates: []Certificate{rsaCertificate},
2751 },
2752 flags: []string{"-require-any-client-certificate"},
2753 })
David Benjamine098ec22014-08-27 23:13:20 -04002754 if ver.version != VersionSSL30 {
2755 testCases = append(testCases, testCase{
2756 testType: serverTest,
2757 name: ver.name + "-Server-ClientAuth-ECDSA",
2758 config: Config{
2759 MinVersion: ver.version,
2760 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002761 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002762 },
2763 flags: []string{"-require-any-client-certificate"},
2764 })
2765 testCases = append(testCases, testCase{
2766 testType: clientTest,
2767 name: ver.name + "-Client-ClientAuth-ECDSA",
2768 config: Config{
2769 MinVersion: ver.version,
2770 MaxVersion: ver.version,
2771 ClientAuth: RequireAnyClientCert,
2772 ClientCAs: certPool,
2773 },
2774 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002775 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2776 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002777 },
2778 })
2779 }
Adam Langley37646832016-08-01 16:16:46 -07002780
2781 testCases = append(testCases, testCase{
2782 name: "NoClientCertificate-" + ver.name,
2783 config: Config{
2784 MinVersion: ver.version,
2785 MaxVersion: ver.version,
2786 ClientAuth: RequireAnyClientCert,
2787 },
2788 shouldFail: true,
2789 expectedLocalError: "client didn't provide a certificate",
2790 })
2791
2792 testCases = append(testCases, testCase{
2793 // Even if not configured to expect a certificate, OpenSSL will
2794 // return X509_V_OK as the verify_result.
2795 testType: serverTest,
2796 name: "NoClientCertificateRequested-Server-" + ver.name,
2797 config: Config{
2798 MinVersion: ver.version,
2799 MaxVersion: ver.version,
2800 },
2801 flags: []string{
2802 "-expect-verify-result",
2803 },
2804 // TODO(davidben): Switch this to true when TLS 1.3
2805 // supports session resumption.
2806 resumeSession: ver.version < VersionTLS13,
2807 })
2808
2809 testCases = append(testCases, testCase{
2810 // If a client certificate is not provided, OpenSSL will still
2811 // return X509_V_OK as the verify_result.
2812 testType: serverTest,
2813 name: "NoClientCertificate-Server-" + ver.name,
2814 config: Config{
2815 MinVersion: ver.version,
2816 MaxVersion: ver.version,
2817 },
2818 flags: []string{
2819 "-expect-verify-result",
2820 "-verify-peer",
2821 },
2822 // TODO(davidben): Switch this to true when TLS 1.3
2823 // supports session resumption.
2824 resumeSession: ver.version < VersionTLS13,
2825 })
2826
2827 testCases = append(testCases, testCase{
2828 testType: serverTest,
2829 name: "RequireAnyClientCertificate-" + ver.name,
2830 config: Config{
2831 MinVersion: ver.version,
2832 MaxVersion: ver.version,
2833 },
2834 flags: []string{"-require-any-client-certificate"},
2835 shouldFail: true,
2836 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2837 })
2838
2839 if ver.version != VersionSSL30 {
2840 testCases = append(testCases, testCase{
2841 testType: serverTest,
2842 name: "SkipClientCertificate-" + ver.name,
2843 config: Config{
2844 MinVersion: ver.version,
2845 MaxVersion: ver.version,
2846 Bugs: ProtocolBugs{
2847 SkipClientCertificate: true,
2848 },
2849 },
2850 // Setting SSL_VERIFY_PEER allows anonymous clients.
2851 flags: []string{"-verify-peer"},
2852 shouldFail: true,
2853 expectedError: ":UNEXPECTED_MESSAGE:",
2854 })
2855 }
David Benjamin636293b2014-07-08 17:59:18 -04002856 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002857
David Benjaminc032dfa2016-05-12 14:54:57 -04002858 // Client auth is only legal in certificate-based ciphers.
2859 testCases = append(testCases, testCase{
2860 testType: clientTest,
2861 name: "ClientAuth-PSK",
2862 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002863 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002864 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2865 PreSharedKey: []byte("secret"),
2866 ClientAuth: RequireAnyClientCert,
2867 },
2868 flags: []string{
2869 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2870 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2871 "-psk", "secret",
2872 },
2873 shouldFail: true,
2874 expectedError: ":UNEXPECTED_MESSAGE:",
2875 })
2876 testCases = append(testCases, testCase{
2877 testType: clientTest,
2878 name: "ClientAuth-ECDHE_PSK",
2879 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002880 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002881 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2882 PreSharedKey: []byte("secret"),
2883 ClientAuth: RequireAnyClientCert,
2884 },
2885 flags: []string{
2886 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2887 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2888 "-psk", "secret",
2889 },
2890 shouldFail: true,
2891 expectedError: ":UNEXPECTED_MESSAGE:",
2892 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002893
2894 // Regression test for a bug where the client CA list, if explicitly
2895 // set to NULL, was mis-encoded.
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: "Null-Client-CA-List",
2899 config: Config{
2900 MaxVersion: VersionTLS12,
2901 Certificates: []Certificate{rsaCertificate},
2902 },
2903 flags: []string{
2904 "-require-any-client-certificate",
2905 "-use-null-client-ca-list",
2906 },
2907 })
David Benjamin636293b2014-07-08 17:59:18 -04002908}
2909
Adam Langley75712922014-10-10 16:23:43 -07002910func addExtendedMasterSecretTests() {
2911 const expectEMSFlag = "-expect-extended-master-secret"
2912
2913 for _, with := range []bool{false, true} {
2914 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002915 if with {
2916 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002917 }
2918
2919 for _, isClient := range []bool{false, true} {
2920 suffix := "-Server"
2921 testType := serverTest
2922 if isClient {
2923 suffix = "-Client"
2924 testType = clientTest
2925 }
2926
2927 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002928 // In TLS 1.3, the extension is irrelevant and
2929 // always reports as enabled.
2930 var flags []string
2931 if with || ver.version >= VersionTLS13 {
2932 flags = []string{expectEMSFlag}
2933 }
2934
Adam Langley75712922014-10-10 16:23:43 -07002935 test := testCase{
2936 testType: testType,
2937 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2938 config: Config{
2939 MinVersion: ver.version,
2940 MaxVersion: ver.version,
2941 Bugs: ProtocolBugs{
2942 NoExtendedMasterSecret: !with,
2943 RequireExtendedMasterSecret: with,
2944 },
2945 },
David Benjamin48cae082014-10-27 01:06:24 -04002946 flags: flags,
2947 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002948 }
2949 if test.shouldFail {
2950 test.expectedLocalError = "extended master secret required but not supported by peer"
2951 }
2952 testCases = append(testCases, test)
2953 }
2954 }
2955 }
2956
Adam Langleyba5934b2015-06-02 10:50:35 -07002957 for _, isClient := range []bool{false, true} {
2958 for _, supportedInFirstConnection := range []bool{false, true} {
2959 for _, supportedInResumeConnection := range []bool{false, true} {
2960 boolToWord := func(b bool) string {
2961 if b {
2962 return "Yes"
2963 }
2964 return "No"
2965 }
2966 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2967 if isClient {
2968 suffix += "Client"
2969 } else {
2970 suffix += "Server"
2971 }
2972
2973 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002974 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002975 Bugs: ProtocolBugs{
2976 RequireExtendedMasterSecret: true,
2977 },
2978 }
2979
2980 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002981 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002982 Bugs: ProtocolBugs{
2983 NoExtendedMasterSecret: true,
2984 },
2985 }
2986
2987 test := testCase{
2988 name: "ExtendedMasterSecret-" + suffix,
2989 resumeSession: true,
2990 }
2991
2992 if !isClient {
2993 test.testType = serverTest
2994 }
2995
2996 if supportedInFirstConnection {
2997 test.config = supportedConfig
2998 } else {
2999 test.config = noSupportConfig
3000 }
3001
3002 if supportedInResumeConnection {
3003 test.resumeConfig = &supportedConfig
3004 } else {
3005 test.resumeConfig = &noSupportConfig
3006 }
3007
3008 switch suffix {
3009 case "YesToYes-Client", "YesToYes-Server":
3010 // When a session is resumed, it should
3011 // still be aware that its master
3012 // secret was generated via EMS and
3013 // thus it's safe to use tls-unique.
3014 test.flags = []string{expectEMSFlag}
3015 case "NoToYes-Server":
3016 // If an original connection did not
3017 // contain EMS, but a resumption
3018 // handshake does, then a server should
3019 // not resume the session.
3020 test.expectResumeRejected = true
3021 case "YesToNo-Server":
3022 // Resuming an EMS session without the
3023 // EMS extension should cause the
3024 // server to abort the connection.
3025 test.shouldFail = true
3026 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3027 case "NoToYes-Client":
3028 // A client should abort a connection
3029 // where the server resumed a non-EMS
3030 // session but echoed the EMS
3031 // extension.
3032 test.shouldFail = true
3033 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3034 case "YesToNo-Client":
3035 // A client should abort a connection
3036 // where the server didn't echo EMS
3037 // when the session used it.
3038 test.shouldFail = true
3039 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3040 }
3041
3042 testCases = append(testCases, test)
3043 }
3044 }
3045 }
David Benjamin163c9562016-08-29 23:14:17 -04003046
3047 // Switching EMS on renegotiation is forbidden.
3048 testCases = append(testCases, testCase{
3049 name: "ExtendedMasterSecret-Renego-NoEMS",
3050 config: Config{
3051 MaxVersion: VersionTLS12,
3052 Bugs: ProtocolBugs{
3053 NoExtendedMasterSecret: true,
3054 NoExtendedMasterSecretOnRenegotiation: true,
3055 },
3056 },
3057 renegotiate: 1,
3058 flags: []string{
3059 "-renegotiate-freely",
3060 "-expect-total-renegotiations", "1",
3061 },
3062 })
3063
3064 testCases = append(testCases, testCase{
3065 name: "ExtendedMasterSecret-Renego-Upgrade",
3066 config: Config{
3067 MaxVersion: VersionTLS12,
3068 Bugs: ProtocolBugs{
3069 NoExtendedMasterSecret: true,
3070 },
3071 },
3072 renegotiate: 1,
3073 flags: []string{
3074 "-renegotiate-freely",
3075 "-expect-total-renegotiations", "1",
3076 },
3077 shouldFail: true,
3078 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3079 })
3080
3081 testCases = append(testCases, testCase{
3082 name: "ExtendedMasterSecret-Renego-Downgrade",
3083 config: Config{
3084 MaxVersion: VersionTLS12,
3085 Bugs: ProtocolBugs{
3086 NoExtendedMasterSecretOnRenegotiation: true,
3087 },
3088 },
3089 renegotiate: 1,
3090 flags: []string{
3091 "-renegotiate-freely",
3092 "-expect-total-renegotiations", "1",
3093 },
3094 shouldFail: true,
3095 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3096 })
Adam Langley75712922014-10-10 16:23:43 -07003097}
3098
David Benjamin582ba042016-07-07 12:33:25 -07003099type stateMachineTestConfig struct {
3100 protocol protocol
3101 async bool
3102 splitHandshake, packHandshakeFlight bool
3103}
3104
David Benjamin43ec06f2014-08-05 02:28:57 -04003105// Adds tests that try to cover the range of the handshake state machine, under
3106// various conditions. Some of these are redundant with other tests, but they
3107// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003108func addAllStateMachineCoverageTests() {
3109 for _, async := range []bool{false, true} {
3110 for _, protocol := range []protocol{tls, dtls} {
3111 addStateMachineCoverageTests(stateMachineTestConfig{
3112 protocol: protocol,
3113 async: async,
3114 })
3115 addStateMachineCoverageTests(stateMachineTestConfig{
3116 protocol: protocol,
3117 async: async,
3118 splitHandshake: true,
3119 })
3120 if protocol == tls {
3121 addStateMachineCoverageTests(stateMachineTestConfig{
3122 protocol: protocol,
3123 async: async,
3124 packHandshakeFlight: true,
3125 })
3126 }
3127 }
3128 }
3129}
3130
3131func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003132 var tests []testCase
3133
3134 // Basic handshake, with resumption. Client and server,
3135 // session ID and session ticket.
3136 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003137 name: "Basic-Client",
3138 config: Config{
3139 MaxVersion: VersionTLS12,
3140 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003141 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003142 // Ensure session tickets are used, not session IDs.
3143 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003144 })
3145 tests = append(tests, testCase{
3146 name: "Basic-Client-RenewTicket",
3147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003148 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003149 Bugs: ProtocolBugs{
3150 RenewTicketOnResume: true,
3151 },
3152 },
David Benjamin46662482016-08-17 00:51:00 -04003153 flags: []string{"-expect-ticket-renewal"},
3154 resumeSession: true,
3155 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003156 })
3157 tests = append(tests, testCase{
3158 name: "Basic-Client-NoTicket",
3159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003160 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003161 SessionTicketsDisabled: true,
3162 },
3163 resumeSession: true,
3164 })
3165 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003166 name: "Basic-Client-Implicit",
3167 config: Config{
3168 MaxVersion: VersionTLS12,
3169 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003170 flags: []string{"-implicit-handshake"},
3171 resumeSession: true,
3172 })
3173 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003174 testType: serverTest,
3175 name: "Basic-Server",
3176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003177 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003178 Bugs: ProtocolBugs{
3179 RequireSessionTickets: true,
3180 },
3181 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003182 resumeSession: true,
3183 })
3184 tests = append(tests, testCase{
3185 testType: serverTest,
3186 name: "Basic-Server-NoTickets",
3187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003188 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003189 SessionTicketsDisabled: true,
3190 },
3191 resumeSession: true,
3192 })
3193 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003194 testType: serverTest,
3195 name: "Basic-Server-Implicit",
3196 config: Config{
3197 MaxVersion: VersionTLS12,
3198 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003199 flags: []string{"-implicit-handshake"},
3200 resumeSession: true,
3201 })
3202 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003203 testType: serverTest,
3204 name: "Basic-Server-EarlyCallback",
3205 config: Config{
3206 MaxVersion: VersionTLS12,
3207 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003208 flags: []string{"-use-early-callback"},
3209 resumeSession: true,
3210 })
3211
Steven Valdez143e8b32016-07-11 13:19:03 -04003212 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003213 if config.protocol == tls {
3214 tests = append(tests, testCase{
3215 name: "TLS13-1RTT-Client",
3216 config: Config{
3217 MaxVersion: VersionTLS13,
3218 MinVersion: VersionTLS13,
3219 },
David Benjamin46662482016-08-17 00:51:00 -04003220 resumeSession: true,
3221 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003222 })
3223
3224 tests = append(tests, testCase{
3225 testType: serverTest,
3226 name: "TLS13-1RTT-Server",
3227 config: Config{
3228 MaxVersion: VersionTLS13,
3229 MinVersion: VersionTLS13,
3230 },
David Benjamin46662482016-08-17 00:51:00 -04003231 resumeSession: true,
3232 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003233 })
3234
3235 tests = append(tests, testCase{
3236 name: "TLS13-HelloRetryRequest-Client",
3237 config: Config{
3238 MaxVersion: VersionTLS13,
3239 MinVersion: VersionTLS13,
3240 // P-384 requires a HelloRetryRequest against
3241 // BoringSSL's default configuration. Assert
3242 // that we do indeed test this with
3243 // ExpectMissingKeyShare.
3244 CurvePreferences: []CurveID{CurveP384},
3245 Bugs: ProtocolBugs{
3246 ExpectMissingKeyShare: true,
3247 },
3248 },
3249 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3250 resumeSession: true,
3251 })
3252
3253 tests = append(tests, testCase{
3254 testType: serverTest,
3255 name: "TLS13-HelloRetryRequest-Server",
3256 config: Config{
3257 MaxVersion: VersionTLS13,
3258 MinVersion: VersionTLS13,
3259 // Require a HelloRetryRequest for every curve.
3260 DefaultCurves: []CurveID{},
3261 },
3262 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3263 resumeSession: true,
3264 })
3265 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003266
David Benjamin760b1dd2015-05-15 23:33:48 -04003267 // TLS client auth.
3268 tests = append(tests, testCase{
3269 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003270 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003272 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003273 ClientAuth: RequestClientCert,
3274 },
3275 })
3276 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003277 testType: serverTest,
3278 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003279 config: Config{
3280 MaxVersion: VersionTLS12,
3281 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003282 // Setting SSL_VERIFY_PEER allows anonymous clients.
3283 flags: []string{"-verify-peer"},
3284 })
David Benjamin582ba042016-07-07 12:33:25 -07003285 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003286 tests = append(tests, testCase{
3287 testType: clientTest,
3288 name: "ClientAuth-NoCertificate-Client-SSL3",
3289 config: Config{
3290 MaxVersion: VersionSSL30,
3291 ClientAuth: RequestClientCert,
3292 },
3293 })
3294 tests = append(tests, testCase{
3295 testType: serverTest,
3296 name: "ClientAuth-NoCertificate-Server-SSL3",
3297 config: Config{
3298 MaxVersion: VersionSSL30,
3299 },
3300 // Setting SSL_VERIFY_PEER allows anonymous clients.
3301 flags: []string{"-verify-peer"},
3302 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003303 tests = append(tests, testCase{
3304 testType: clientTest,
3305 name: "ClientAuth-NoCertificate-Client-TLS13",
3306 config: Config{
3307 MaxVersion: VersionTLS13,
3308 ClientAuth: RequestClientCert,
3309 },
3310 })
3311 tests = append(tests, testCase{
3312 testType: serverTest,
3313 name: "ClientAuth-NoCertificate-Server-TLS13",
3314 config: Config{
3315 MaxVersion: VersionTLS13,
3316 },
3317 // Setting SSL_VERIFY_PEER allows anonymous clients.
3318 flags: []string{"-verify-peer"},
3319 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003320 }
3321 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003322 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003323 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003325 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003326 ClientAuth: RequireAnyClientCert,
3327 },
3328 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003329 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3330 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003331 },
3332 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003333 tests = append(tests, testCase{
3334 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003335 name: "ClientAuth-RSA-Client-TLS13",
3336 config: Config{
3337 MaxVersion: VersionTLS13,
3338 ClientAuth: RequireAnyClientCert,
3339 },
3340 flags: []string{
3341 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3342 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3343 },
3344 })
3345 tests = append(tests, testCase{
3346 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003347 name: "ClientAuth-ECDSA-Client",
3348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003349 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003350 ClientAuth: RequireAnyClientCert,
3351 },
3352 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003353 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3354 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003355 },
3356 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003357 tests = append(tests, testCase{
3358 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003359 name: "ClientAuth-ECDSA-Client-TLS13",
3360 config: Config{
3361 MaxVersion: VersionTLS13,
3362 ClientAuth: RequireAnyClientCert,
3363 },
3364 flags: []string{
3365 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3366 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3367 },
3368 })
3369 tests = append(tests, testCase{
3370 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003371 name: "ClientAuth-NoCertificate-OldCallback",
3372 config: Config{
3373 MaxVersion: VersionTLS12,
3374 ClientAuth: RequestClientCert,
3375 },
3376 flags: []string{"-use-old-client-cert-callback"},
3377 })
3378 tests = append(tests, testCase{
3379 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003380 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3381 config: Config{
3382 MaxVersion: VersionTLS13,
3383 ClientAuth: RequestClientCert,
3384 },
3385 flags: []string{"-use-old-client-cert-callback"},
3386 })
3387 tests = append(tests, testCase{
3388 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003389 name: "ClientAuth-OldCallback",
3390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003391 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003392 ClientAuth: RequireAnyClientCert,
3393 },
3394 flags: []string{
3395 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3396 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3397 "-use-old-client-cert-callback",
3398 },
3399 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003401 testType: clientTest,
3402 name: "ClientAuth-OldCallback-TLS13",
3403 config: Config{
3404 MaxVersion: VersionTLS13,
3405 ClientAuth: RequireAnyClientCert,
3406 },
3407 flags: []string{
3408 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3409 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3410 "-use-old-client-cert-callback",
3411 },
3412 })
3413 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003414 testType: serverTest,
3415 name: "ClientAuth-Server",
3416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003417 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003418 Certificates: []Certificate{rsaCertificate},
3419 },
3420 flags: []string{"-require-any-client-certificate"},
3421 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003422 tests = append(tests, testCase{
3423 testType: serverTest,
3424 name: "ClientAuth-Server-TLS13",
3425 config: Config{
3426 MaxVersion: VersionTLS13,
3427 Certificates: []Certificate{rsaCertificate},
3428 },
3429 flags: []string{"-require-any-client-certificate"},
3430 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003431
David Benjamin4c3ddf72016-06-29 18:13:53 -04003432 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003433 tests = append(tests, testCase{
3434 testType: serverTest,
3435 name: "Basic-Server-RSA",
3436 config: Config{
3437 MaxVersion: VersionTLS12,
3438 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3439 },
3440 flags: []string{
3441 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3442 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3443 },
3444 })
3445 tests = append(tests, testCase{
3446 testType: serverTest,
3447 name: "Basic-Server-ECDHE-RSA",
3448 config: Config{
3449 MaxVersion: VersionTLS12,
3450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3451 },
3452 flags: []string{
3453 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3454 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3455 },
3456 })
3457 tests = append(tests, testCase{
3458 testType: serverTest,
3459 name: "Basic-Server-ECDHE-ECDSA",
3460 config: Config{
3461 MaxVersion: VersionTLS12,
3462 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3463 },
3464 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003465 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3466 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003467 },
3468 })
3469
David Benjamin760b1dd2015-05-15 23:33:48 -04003470 // No session ticket support; server doesn't send NewSessionTicket.
3471 tests = append(tests, testCase{
3472 name: "SessionTicketsDisabled-Client",
3473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003474 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003475 SessionTicketsDisabled: true,
3476 },
3477 })
3478 tests = append(tests, testCase{
3479 testType: serverTest,
3480 name: "SessionTicketsDisabled-Server",
3481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003482 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 SessionTicketsDisabled: true,
3484 },
3485 })
3486
3487 // Skip ServerKeyExchange in PSK key exchange if there's no
3488 // identity hint.
3489 tests = append(tests, testCase{
3490 name: "EmptyPSKHint-Client",
3491 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003492 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003493 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3494 PreSharedKey: []byte("secret"),
3495 },
3496 flags: []string{"-psk", "secret"},
3497 })
3498 tests = append(tests, testCase{
3499 testType: serverTest,
3500 name: "EmptyPSKHint-Server",
3501 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003502 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003503 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3504 PreSharedKey: []byte("secret"),
3505 },
3506 flags: []string{"-psk", "secret"},
3507 })
3508
David Benjamin4c3ddf72016-06-29 18:13:53 -04003509 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003510 tests = append(tests, testCase{
3511 testType: clientTest,
3512 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003513 config: Config{
3514 MaxVersion: VersionTLS12,
3515 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003516 flags: []string{
3517 "-enable-ocsp-stapling",
3518 "-expect-ocsp-response",
3519 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003520 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003521 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003522 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003523 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003524 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003525 testType: serverTest,
3526 name: "OCSPStapling-Server",
3527 config: Config{
3528 MaxVersion: VersionTLS12,
3529 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003530 expectedOCSPResponse: testOCSPResponse,
3531 flags: []string{
3532 "-ocsp-response",
3533 base64.StdEncoding.EncodeToString(testOCSPResponse),
3534 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003535 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003536 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003537 tests = append(tests, testCase{
3538 testType: clientTest,
3539 name: "OCSPStapling-Client-TLS13",
3540 config: Config{
3541 MaxVersion: VersionTLS13,
3542 },
3543 flags: []string{
3544 "-enable-ocsp-stapling",
3545 "-expect-ocsp-response",
3546 base64.StdEncoding.EncodeToString(testOCSPResponse),
3547 "-verify-peer",
3548 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003549 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003550 })
3551 tests = append(tests, testCase{
3552 testType: serverTest,
3553 name: "OCSPStapling-Server-TLS13",
3554 config: Config{
3555 MaxVersion: VersionTLS13,
3556 },
3557 expectedOCSPResponse: testOCSPResponse,
3558 flags: []string{
3559 "-ocsp-response",
3560 base64.StdEncoding.EncodeToString(testOCSPResponse),
3561 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003562 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003563 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003564
David Benjamin4c3ddf72016-06-29 18:13:53 -04003565 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003566 for _, vers := range tlsVersions {
3567 if config.protocol == dtls && !vers.hasDTLS {
3568 continue
3569 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003570 for _, testType := range []testType{clientTest, serverTest} {
3571 suffix := "-Client"
3572 if testType == serverTest {
3573 suffix = "-Server"
3574 }
3575 suffix += "-" + vers.name
3576
3577 flag := "-verify-peer"
3578 if testType == serverTest {
3579 flag = "-require-any-client-certificate"
3580 }
3581
3582 tests = append(tests, testCase{
3583 testType: testType,
3584 name: "CertificateVerificationSucceed" + suffix,
3585 config: Config{
3586 MaxVersion: vers.version,
3587 Certificates: []Certificate{rsaCertificate},
3588 },
3589 flags: []string{
3590 flag,
3591 "-expect-verify-result",
3592 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003593 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003594 })
3595 tests = append(tests, testCase{
3596 testType: testType,
3597 name: "CertificateVerificationFail" + suffix,
3598 config: Config{
3599 MaxVersion: vers.version,
3600 Certificates: []Certificate{rsaCertificate},
3601 },
3602 flags: []string{
3603 flag,
3604 "-verify-fail",
3605 },
3606 shouldFail: true,
3607 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3608 })
3609 }
3610
3611 // By default, the client is in a soft fail mode where the peer
3612 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003613 tests = append(tests, testCase{
3614 testType: clientTest,
3615 name: "CertificateVerificationSoftFail-" + vers.name,
3616 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003617 MaxVersion: vers.version,
3618 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003619 },
3620 flags: []string{
3621 "-verify-fail",
3622 "-expect-verify-result",
3623 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003624 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003625 })
3626 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003627
David Benjamin1d4f4c02016-07-26 18:03:08 -04003628 tests = append(tests, testCase{
3629 name: "ShimSendAlert",
3630 flags: []string{"-send-alert"},
3631 shimWritesFirst: true,
3632 shouldFail: true,
3633 expectedLocalError: "remote error: decompression failure",
3634 })
3635
David Benjamin582ba042016-07-07 12:33:25 -07003636 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003637 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003638 name: "Renegotiate-Client",
3639 config: Config{
3640 MaxVersion: VersionTLS12,
3641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003642 renegotiate: 1,
3643 flags: []string{
3644 "-renegotiate-freely",
3645 "-expect-total-renegotiations", "1",
3646 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003647 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003648
David Benjamin47921102016-07-28 11:29:18 -04003649 tests = append(tests, testCase{
3650 name: "SendHalfHelloRequest",
3651 config: Config{
3652 MaxVersion: VersionTLS12,
3653 Bugs: ProtocolBugs{
3654 PackHelloRequestWithFinished: config.packHandshakeFlight,
3655 },
3656 },
3657 sendHalfHelloRequest: true,
3658 flags: []string{"-renegotiate-ignore"},
3659 shouldFail: true,
3660 expectedError: ":UNEXPECTED_RECORD:",
3661 })
3662
David Benjamin760b1dd2015-05-15 23:33:48 -04003663 // NPN on client and server; results in post-handshake message.
3664 tests = append(tests, testCase{
3665 name: "NPN-Client",
3666 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003667 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003668 NextProtos: []string{"foo"},
3669 },
3670 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003671 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003672 expectedNextProto: "foo",
3673 expectedNextProtoType: npn,
3674 })
3675 tests = append(tests, testCase{
3676 testType: serverTest,
3677 name: "NPN-Server",
3678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003679 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003680 NextProtos: []string{"bar"},
3681 },
3682 flags: []string{
3683 "-advertise-npn", "\x03foo\x03bar\x03baz",
3684 "-expect-next-proto", "bar",
3685 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003686 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003687 expectedNextProto: "bar",
3688 expectedNextProtoType: npn,
3689 })
3690
3691 // TODO(davidben): Add tests for when False Start doesn't trigger.
3692
3693 // Client does False Start and negotiates NPN.
3694 tests = append(tests, testCase{
3695 name: "FalseStart",
3696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003697 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3699 NextProtos: []string{"foo"},
3700 Bugs: ProtocolBugs{
3701 ExpectFalseStart: true,
3702 },
3703 },
3704 flags: []string{
3705 "-false-start",
3706 "-select-next-proto", "foo",
3707 },
3708 shimWritesFirst: true,
3709 resumeSession: true,
3710 })
3711
3712 // Client does False Start and negotiates ALPN.
3713 tests = append(tests, testCase{
3714 name: "FalseStart-ALPN",
3715 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003716 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3718 NextProtos: []string{"foo"},
3719 Bugs: ProtocolBugs{
3720 ExpectFalseStart: true,
3721 },
3722 },
3723 flags: []string{
3724 "-false-start",
3725 "-advertise-alpn", "\x03foo",
3726 },
3727 shimWritesFirst: true,
3728 resumeSession: true,
3729 })
3730
3731 // Client does False Start but doesn't explicitly call
3732 // SSL_connect.
3733 tests = append(tests, testCase{
3734 name: "FalseStart-Implicit",
3735 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3738 NextProtos: []string{"foo"},
3739 },
3740 flags: []string{
3741 "-implicit-handshake",
3742 "-false-start",
3743 "-advertise-alpn", "\x03foo",
3744 },
3745 })
3746
3747 // False Start without session tickets.
3748 tests = append(tests, testCase{
3749 name: "FalseStart-SessionTicketsDisabled",
3750 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003751 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003752 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3753 NextProtos: []string{"foo"},
3754 SessionTicketsDisabled: true,
3755 Bugs: ProtocolBugs{
3756 ExpectFalseStart: true,
3757 },
3758 },
3759 flags: []string{
3760 "-false-start",
3761 "-select-next-proto", "foo",
3762 },
3763 shimWritesFirst: true,
3764 })
3765
Adam Langleydf759b52016-07-11 15:24:37 -07003766 tests = append(tests, testCase{
3767 name: "FalseStart-CECPQ1",
3768 config: Config{
3769 MaxVersion: VersionTLS12,
3770 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3771 NextProtos: []string{"foo"},
3772 Bugs: ProtocolBugs{
3773 ExpectFalseStart: true,
3774 },
3775 },
3776 flags: []string{
3777 "-false-start",
3778 "-cipher", "DEFAULT:kCECPQ1",
3779 "-select-next-proto", "foo",
3780 },
3781 shimWritesFirst: true,
3782 resumeSession: true,
3783 })
3784
David Benjamin760b1dd2015-05-15 23:33:48 -04003785 // Server parses a V2ClientHello.
3786 tests = append(tests, testCase{
3787 testType: serverTest,
3788 name: "SendV2ClientHello",
3789 config: Config{
3790 // Choose a cipher suite that does not involve
3791 // elliptic curves, so no extensions are
3792 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003793 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003794 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003795 Bugs: ProtocolBugs{
3796 SendV2ClientHello: true,
3797 },
3798 },
3799 })
3800
3801 // Client sends a Channel ID.
3802 tests = append(tests, testCase{
3803 name: "ChannelID-Client",
3804 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003805 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 RequestChannelID: true,
3807 },
Adam Langley7c803a62015-06-15 15:35:05 -07003808 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003809 resumeSession: true,
3810 expectChannelID: true,
3811 })
3812
3813 // Server accepts a Channel ID.
3814 tests = append(tests, testCase{
3815 testType: serverTest,
3816 name: "ChannelID-Server",
3817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003818 MaxVersion: VersionTLS12,
3819 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003820 },
3821 flags: []string{
3822 "-expect-channel-id",
3823 base64.StdEncoding.EncodeToString(channelIDBytes),
3824 },
3825 resumeSession: true,
3826 expectChannelID: true,
3827 })
David Benjamin30789da2015-08-29 22:56:45 -04003828
David Benjaminf8fcdf32016-06-08 15:56:13 -04003829 // Channel ID and NPN at the same time, to ensure their relative
3830 // ordering is correct.
3831 tests = append(tests, testCase{
3832 name: "ChannelID-NPN-Client",
3833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003834 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003835 RequestChannelID: true,
3836 NextProtos: []string{"foo"},
3837 },
3838 flags: []string{
3839 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3840 "-select-next-proto", "foo",
3841 },
3842 resumeSession: true,
3843 expectChannelID: true,
3844 expectedNextProto: "foo",
3845 expectedNextProtoType: npn,
3846 })
3847 tests = append(tests, testCase{
3848 testType: serverTest,
3849 name: "ChannelID-NPN-Server",
3850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003851 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003852 ChannelID: channelIDKey,
3853 NextProtos: []string{"bar"},
3854 },
3855 flags: []string{
3856 "-expect-channel-id",
3857 base64.StdEncoding.EncodeToString(channelIDBytes),
3858 "-advertise-npn", "\x03foo\x03bar\x03baz",
3859 "-expect-next-proto", "bar",
3860 },
3861 resumeSession: true,
3862 expectChannelID: true,
3863 expectedNextProto: "bar",
3864 expectedNextProtoType: npn,
3865 })
3866
David Benjamin30789da2015-08-29 22:56:45 -04003867 // Bidirectional shutdown with the runner initiating.
3868 tests = append(tests, testCase{
3869 name: "Shutdown-Runner",
3870 config: Config{
3871 Bugs: ProtocolBugs{
3872 ExpectCloseNotify: true,
3873 },
3874 },
3875 flags: []string{"-check-close-notify"},
3876 })
3877
3878 // Bidirectional shutdown with the shim initiating. The runner,
3879 // in the meantime, sends garbage before the close_notify which
3880 // the shim must ignore.
3881 tests = append(tests, testCase{
3882 name: "Shutdown-Shim",
3883 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003884 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003885 Bugs: ProtocolBugs{
3886 ExpectCloseNotify: true,
3887 },
3888 },
3889 shimShutsDown: true,
3890 sendEmptyRecords: 1,
3891 sendWarningAlerts: 1,
3892 flags: []string{"-check-close-notify"},
3893 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003894 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 // TODO(davidben): DTLS 1.3 will want a similar thing for
3896 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003897 tests = append(tests, testCase{
3898 name: "SkipHelloVerifyRequest",
3899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003900 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003901 Bugs: ProtocolBugs{
3902 SkipHelloVerifyRequest: true,
3903 },
3904 },
3905 })
3906 }
3907
David Benjamin760b1dd2015-05-15 23:33:48 -04003908 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003909 test.protocol = config.protocol
3910 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003911 test.name += "-DTLS"
3912 }
David Benjamin582ba042016-07-07 12:33:25 -07003913 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003914 test.name += "-Async"
3915 test.flags = append(test.flags, "-async")
3916 } else {
3917 test.name += "-Sync"
3918 }
David Benjamin582ba042016-07-07 12:33:25 -07003919 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003920 test.name += "-SplitHandshakeRecords"
3921 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003922 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003923 test.config.Bugs.MaxPacketLength = 256
3924 test.flags = append(test.flags, "-mtu", "256")
3925 }
3926 }
David Benjamin582ba042016-07-07 12:33:25 -07003927 if config.packHandshakeFlight {
3928 test.name += "-PackHandshakeFlight"
3929 test.config.Bugs.PackHandshakeFlight = true
3930 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003931 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003932 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003933}
3934
Adam Langley524e7172015-02-20 16:04:00 -08003935func addDDoSCallbackTests() {
3936 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003937 for _, resume := range []bool{false, true} {
3938 suffix := "Resume"
3939 if resume {
3940 suffix = "No" + suffix
3941 }
3942
3943 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003944 testType: serverTest,
3945 name: "Server-DDoS-OK-" + suffix,
3946 config: Config{
3947 MaxVersion: VersionTLS12,
3948 },
Adam Langley524e7172015-02-20 16:04:00 -08003949 flags: []string{"-install-ddos-callback"},
3950 resumeSession: resume,
3951 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003952 testCases = append(testCases, testCase{
3953 testType: serverTest,
3954 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3955 config: Config{
3956 MaxVersion: VersionTLS13,
3957 },
3958 flags: []string{"-install-ddos-callback"},
3959 resumeSession: resume,
3960 })
Adam Langley524e7172015-02-20 16:04:00 -08003961
3962 failFlag := "-fail-ddos-callback"
3963 if resume {
3964 failFlag = "-fail-second-ddos-callback"
3965 }
3966 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 testType: serverTest,
3968 name: "Server-DDoS-Reject-" + suffix,
3969 config: Config{
3970 MaxVersion: VersionTLS12,
3971 },
Adam Langley524e7172015-02-20 16:04:00 -08003972 flags: []string{"-install-ddos-callback", failFlag},
3973 resumeSession: resume,
3974 shouldFail: true,
3975 expectedError: ":CONNECTION_REJECTED:",
3976 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003977 testCases = append(testCases, testCase{
3978 testType: serverTest,
3979 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3980 config: Config{
3981 MaxVersion: VersionTLS13,
3982 },
3983 flags: []string{"-install-ddos-callback", failFlag},
3984 resumeSession: resume,
3985 shouldFail: true,
3986 expectedError: ":CONNECTION_REJECTED:",
3987 })
Adam Langley524e7172015-02-20 16:04:00 -08003988 }
3989}
3990
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003991func addVersionNegotiationTests() {
3992 for i, shimVers := range tlsVersions {
3993 // Assemble flags to disable all newer versions on the shim.
3994 var flags []string
3995 for _, vers := range tlsVersions[i+1:] {
3996 flags = append(flags, vers.flag)
3997 }
3998
3999 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004000 protocols := []protocol{tls}
4001 if runnerVers.hasDTLS && shimVers.hasDTLS {
4002 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004003 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004004 for _, protocol := range protocols {
4005 expectedVersion := shimVers.version
4006 if runnerVers.version < shimVers.version {
4007 expectedVersion = runnerVers.version
4008 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004009
David Benjamin8b8c0062014-11-23 02:47:52 -05004010 suffix := shimVers.name + "-" + runnerVers.name
4011 if protocol == dtls {
4012 suffix += "-DTLS"
4013 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004014
David Benjamin1eb367c2014-12-12 18:17:51 -05004015 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4016
David Benjamin1e29a6b2014-12-10 02:27:24 -05004017 clientVers := shimVers.version
4018 if clientVers > VersionTLS10 {
4019 clientVers = VersionTLS10
4020 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004021 serverVers := expectedVersion
4022 if expectedVersion >= VersionTLS13 {
4023 serverVers = VersionTLS10
4024 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004025 testCases = append(testCases, testCase{
4026 protocol: protocol,
4027 testType: clientTest,
4028 name: "VersionNegotiation-Client-" + suffix,
4029 config: Config{
4030 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004031 Bugs: ProtocolBugs{
4032 ExpectInitialRecordVersion: clientVers,
4033 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004034 },
4035 flags: flags,
4036 expectedVersion: expectedVersion,
4037 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004038 testCases = append(testCases, testCase{
4039 protocol: protocol,
4040 testType: clientTest,
4041 name: "VersionNegotiation-Client2-" + suffix,
4042 config: Config{
4043 MaxVersion: runnerVers.version,
4044 Bugs: ProtocolBugs{
4045 ExpectInitialRecordVersion: clientVers,
4046 },
4047 },
4048 flags: []string{"-max-version", shimVersFlag},
4049 expectedVersion: expectedVersion,
4050 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004051
4052 testCases = append(testCases, testCase{
4053 protocol: protocol,
4054 testType: serverTest,
4055 name: "VersionNegotiation-Server-" + suffix,
4056 config: Config{
4057 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004058 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004059 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004060 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004061 },
4062 flags: flags,
4063 expectedVersion: expectedVersion,
4064 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004065 testCases = append(testCases, testCase{
4066 protocol: protocol,
4067 testType: serverTest,
4068 name: "VersionNegotiation-Server2-" + suffix,
4069 config: Config{
4070 MaxVersion: runnerVers.version,
4071 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004072 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004073 },
4074 },
4075 flags: []string{"-max-version", shimVersFlag},
4076 expectedVersion: expectedVersion,
4077 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004078 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004079 }
4080 }
David Benjamin95c69562016-06-29 18:15:03 -04004081
4082 // Test for version tolerance.
4083 testCases = append(testCases, testCase{
4084 testType: serverTest,
4085 name: "MinorVersionTolerance",
4086 config: Config{
4087 Bugs: ProtocolBugs{
4088 SendClientVersion: 0x03ff,
4089 },
4090 },
4091 expectedVersion: VersionTLS13,
4092 })
4093 testCases = append(testCases, testCase{
4094 testType: serverTest,
4095 name: "MajorVersionTolerance",
4096 config: Config{
4097 Bugs: ProtocolBugs{
4098 SendClientVersion: 0x0400,
4099 },
4100 },
4101 expectedVersion: VersionTLS13,
4102 })
4103 testCases = append(testCases, testCase{
4104 protocol: dtls,
4105 testType: serverTest,
4106 name: "MinorVersionTolerance-DTLS",
4107 config: Config{
4108 Bugs: ProtocolBugs{
4109 SendClientVersion: 0x03ff,
4110 },
4111 },
4112 expectedVersion: VersionTLS12,
4113 })
4114 testCases = append(testCases, testCase{
4115 protocol: dtls,
4116 testType: serverTest,
4117 name: "MajorVersionTolerance-DTLS",
4118 config: Config{
4119 Bugs: ProtocolBugs{
4120 SendClientVersion: 0x0400,
4121 },
4122 },
4123 expectedVersion: VersionTLS12,
4124 })
4125
4126 // Test that versions below 3.0 are rejected.
4127 testCases = append(testCases, testCase{
4128 testType: serverTest,
4129 name: "VersionTooLow",
4130 config: Config{
4131 Bugs: ProtocolBugs{
4132 SendClientVersion: 0x0200,
4133 },
4134 },
4135 shouldFail: true,
4136 expectedError: ":UNSUPPORTED_PROTOCOL:",
4137 })
4138 testCases = append(testCases, testCase{
4139 protocol: dtls,
4140 testType: serverTest,
4141 name: "VersionTooLow-DTLS",
4142 config: Config{
4143 Bugs: ProtocolBugs{
4144 // 0x0201 is the lowest version expressable in
4145 // DTLS.
4146 SendClientVersion: 0x0201,
4147 },
4148 },
4149 shouldFail: true,
4150 expectedError: ":UNSUPPORTED_PROTOCOL:",
4151 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004152
4153 // Test TLS 1.3's downgrade signal.
4154 testCases = append(testCases, testCase{
4155 name: "Downgrade-TLS12-Client",
4156 config: Config{
4157 Bugs: ProtocolBugs{
4158 NegotiateVersion: VersionTLS12,
4159 },
4160 },
4161 shouldFail: true,
4162 expectedError: ":DOWNGRADE_DETECTED:",
4163 })
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "Downgrade-TLS12-Server",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: VersionTLS12,
4170 },
4171 },
4172 shouldFail: true,
4173 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4174 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004175
4176 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4177 // behave correctly when both real maximum and fallback versions are
4178 // set.
4179 testCases = append(testCases, testCase{
4180 name: "Downgrade-TLS12-Client-Fallback",
4181 config: Config{
4182 Bugs: ProtocolBugs{
4183 FailIfNotFallbackSCSV: true,
4184 },
4185 },
4186 flags: []string{
4187 "-max-version", strconv.Itoa(VersionTLS13),
4188 "-fallback-version", strconv.Itoa(VersionTLS12),
4189 },
4190 shouldFail: true,
4191 expectedError: ":DOWNGRADE_DETECTED:",
4192 })
4193 testCases = append(testCases, testCase{
4194 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4195 flags: []string{
4196 "-max-version", strconv.Itoa(VersionTLS12),
4197 "-fallback-version", strconv.Itoa(VersionTLS12),
4198 },
4199 })
4200
4201 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4202 // just have such connections fail than risk getting confused because we
4203 // didn't sent the 1.3 ClientHello.)
4204 testCases = append(testCases, testCase{
4205 name: "Downgrade-TLS12-Fallback-CheckVersion",
4206 config: Config{
4207 Bugs: ProtocolBugs{
4208 NegotiateVersion: VersionTLS13,
4209 FailIfNotFallbackSCSV: true,
4210 },
4211 },
4212 flags: []string{
4213 "-max-version", strconv.Itoa(VersionTLS13),
4214 "-fallback-version", strconv.Itoa(VersionTLS12),
4215 },
4216 shouldFail: true,
4217 expectedError: ":UNSUPPORTED_PROTOCOL:",
4218 })
4219
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004220}
4221
David Benjaminaccb4542014-12-12 23:44:33 -05004222func addMinimumVersionTests() {
4223 for i, shimVers := range tlsVersions {
4224 // Assemble flags to disable all older versions on the shim.
4225 var flags []string
4226 for _, vers := range tlsVersions[:i] {
4227 flags = append(flags, vers.flag)
4228 }
4229
4230 for _, runnerVers := range tlsVersions {
4231 protocols := []protocol{tls}
4232 if runnerVers.hasDTLS && shimVers.hasDTLS {
4233 protocols = append(protocols, dtls)
4234 }
4235 for _, protocol := range protocols {
4236 suffix := shimVers.name + "-" + runnerVers.name
4237 if protocol == dtls {
4238 suffix += "-DTLS"
4239 }
4240 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4241
David Benjaminaccb4542014-12-12 23:44:33 -05004242 var expectedVersion uint16
4243 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004244 var expectedClientError, expectedServerError string
4245 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004246 if runnerVers.version >= shimVers.version {
4247 expectedVersion = runnerVers.version
4248 } else {
4249 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004250 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4251 expectedServerLocalError = "remote error: protocol version not supported"
4252 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4253 // If the client's minimum version is TLS 1.3 and the runner's
4254 // maximum is below TLS 1.2, the runner will fail to select a
4255 // cipher before the shim rejects the selected version.
4256 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4257 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4258 } else {
4259 expectedClientError = expectedServerError
4260 expectedClientLocalError = expectedServerLocalError
4261 }
David Benjaminaccb4542014-12-12 23:44:33 -05004262 }
4263
4264 testCases = append(testCases, testCase{
4265 protocol: protocol,
4266 testType: clientTest,
4267 name: "MinimumVersion-Client-" + suffix,
4268 config: Config{
4269 MaxVersion: runnerVers.version,
4270 },
David Benjamin87909c02014-12-13 01:55:01 -05004271 flags: flags,
4272 expectedVersion: expectedVersion,
4273 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004274 expectedError: expectedClientError,
4275 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004276 })
4277 testCases = append(testCases, testCase{
4278 protocol: protocol,
4279 testType: clientTest,
4280 name: "MinimumVersion-Client2-" + suffix,
4281 config: Config{
4282 MaxVersion: runnerVers.version,
4283 },
David Benjamin87909c02014-12-13 01:55:01 -05004284 flags: []string{"-min-version", shimVersFlag},
4285 expectedVersion: expectedVersion,
4286 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004287 expectedError: expectedClientError,
4288 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004289 })
4290
4291 testCases = append(testCases, testCase{
4292 protocol: protocol,
4293 testType: serverTest,
4294 name: "MinimumVersion-Server-" + suffix,
4295 config: Config{
4296 MaxVersion: runnerVers.version,
4297 },
David Benjamin87909c02014-12-13 01:55:01 -05004298 flags: flags,
4299 expectedVersion: expectedVersion,
4300 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004301 expectedError: expectedServerError,
4302 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004303 })
4304 testCases = append(testCases, testCase{
4305 protocol: protocol,
4306 testType: serverTest,
4307 name: "MinimumVersion-Server2-" + suffix,
4308 config: Config{
4309 MaxVersion: runnerVers.version,
4310 },
David Benjamin87909c02014-12-13 01:55:01 -05004311 flags: []string{"-min-version", shimVersFlag},
4312 expectedVersion: expectedVersion,
4313 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004314 expectedError: expectedServerError,
4315 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004316 })
4317 }
4318 }
4319 }
4320}
4321
David Benjamine78bfde2014-09-06 12:45:15 -04004322func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004323 // TODO(davidben): Extensions, where applicable, all move their server
4324 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4325 // tests for both. Also test interaction with 0-RTT when implemented.
4326
David Benjamin97d17d92016-07-14 16:12:00 -04004327 // Repeat extensions tests all versions except SSL 3.0.
4328 for _, ver := range tlsVersions {
4329 if ver.version == VersionSSL30 {
4330 continue
4331 }
4332
David Benjamin97d17d92016-07-14 16:12:00 -04004333 // Test that duplicate extensions are rejected.
4334 testCases = append(testCases, testCase{
4335 testType: clientTest,
4336 name: "DuplicateExtensionClient-" + ver.name,
4337 config: Config{
4338 MaxVersion: ver.version,
4339 Bugs: ProtocolBugs{
4340 DuplicateExtension: true,
4341 },
David Benjamine78bfde2014-09-06 12:45:15 -04004342 },
David Benjamin97d17d92016-07-14 16:12:00 -04004343 shouldFail: true,
4344 expectedLocalError: "remote error: error decoding message",
4345 })
4346 testCases = append(testCases, testCase{
4347 testType: serverTest,
4348 name: "DuplicateExtensionServer-" + ver.name,
4349 config: Config{
4350 MaxVersion: ver.version,
4351 Bugs: ProtocolBugs{
4352 DuplicateExtension: true,
4353 },
David Benjamine78bfde2014-09-06 12:45:15 -04004354 },
David Benjamin97d17d92016-07-14 16:12:00 -04004355 shouldFail: true,
4356 expectedLocalError: "remote error: error decoding message",
4357 })
4358
4359 // Test SNI.
4360 testCases = append(testCases, testCase{
4361 testType: clientTest,
4362 name: "ServerNameExtensionClient-" + ver.name,
4363 config: Config{
4364 MaxVersion: ver.version,
4365 Bugs: ProtocolBugs{
4366 ExpectServerName: "example.com",
4367 },
David Benjamine78bfde2014-09-06 12:45:15 -04004368 },
David Benjamin97d17d92016-07-14 16:12:00 -04004369 flags: []string{"-host-name", "example.com"},
4370 })
4371 testCases = append(testCases, testCase{
4372 testType: clientTest,
4373 name: "ServerNameExtensionClientMismatch-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 Bugs: ProtocolBugs{
4377 ExpectServerName: "mismatch.com",
4378 },
David Benjamine78bfde2014-09-06 12:45:15 -04004379 },
David Benjamin97d17d92016-07-14 16:12:00 -04004380 flags: []string{"-host-name", "example.com"},
4381 shouldFail: true,
4382 expectedLocalError: "tls: unexpected server name",
4383 })
4384 testCases = append(testCases, testCase{
4385 testType: clientTest,
4386 name: "ServerNameExtensionClientMissing-" + ver.name,
4387 config: Config{
4388 MaxVersion: ver.version,
4389 Bugs: ProtocolBugs{
4390 ExpectServerName: "missing.com",
4391 },
David Benjamine78bfde2014-09-06 12:45:15 -04004392 },
David Benjamin97d17d92016-07-14 16:12:00 -04004393 shouldFail: true,
4394 expectedLocalError: "tls: unexpected server name",
4395 })
4396 testCases = append(testCases, testCase{
4397 testType: serverTest,
4398 name: "ServerNameExtensionServer-" + ver.name,
4399 config: Config{
4400 MaxVersion: ver.version,
4401 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004402 },
David Benjamin97d17d92016-07-14 16:12:00 -04004403 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004404 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004405 })
4406
4407 // Test ALPN.
4408 testCases = append(testCases, testCase{
4409 testType: clientTest,
4410 name: "ALPNClient-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 NextProtos: []string{"foo"},
4414 },
4415 flags: []string{
4416 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4417 "-expect-alpn", "foo",
4418 },
4419 expectedNextProto: "foo",
4420 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004421 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004422 })
4423 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004424 testType: clientTest,
4425 name: "ALPNClient-Mismatch-" + ver.name,
4426 config: Config{
4427 MaxVersion: ver.version,
4428 Bugs: ProtocolBugs{
4429 SendALPN: "baz",
4430 },
4431 },
4432 flags: []string{
4433 "-advertise-alpn", "\x03foo\x03bar",
4434 },
4435 shouldFail: true,
4436 expectedError: ":INVALID_ALPN_PROTOCOL:",
4437 expectedLocalError: "remote error: illegal parameter",
4438 })
4439 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004440 testType: serverTest,
4441 name: "ALPNServer-" + ver.name,
4442 config: Config{
4443 MaxVersion: ver.version,
4444 NextProtos: []string{"foo", "bar", "baz"},
4445 },
4446 flags: []string{
4447 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4448 "-select-alpn", "foo",
4449 },
4450 expectedNextProto: "foo",
4451 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004452 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004453 })
4454 testCases = append(testCases, testCase{
4455 testType: serverTest,
4456 name: "ALPNServer-Decline-" + ver.name,
4457 config: Config{
4458 MaxVersion: ver.version,
4459 NextProtos: []string{"foo", "bar", "baz"},
4460 },
4461 flags: []string{"-decline-alpn"},
4462 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004463 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004464 })
4465
David Benjamin25fe85b2016-08-09 20:00:32 -04004466 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4467 // called once.
4468 testCases = append(testCases, testCase{
4469 testType: serverTest,
4470 name: "ALPNServer-Async-" + ver.name,
4471 config: Config{
4472 MaxVersion: ver.version,
4473 NextProtos: []string{"foo", "bar", "baz"},
4474 },
4475 flags: []string{
4476 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4477 "-select-alpn", "foo",
4478 "-async",
4479 },
4480 expectedNextProto: "foo",
4481 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004482 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004483 })
4484
David Benjamin97d17d92016-07-14 16:12:00 -04004485 var emptyString string
4486 testCases = append(testCases, testCase{
4487 testType: clientTest,
4488 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4489 config: Config{
4490 MaxVersion: ver.version,
4491 NextProtos: []string{""},
4492 Bugs: ProtocolBugs{
4493 // A server returning an empty ALPN protocol
4494 // should be rejected.
4495 ALPNProtocol: &emptyString,
4496 },
4497 },
4498 flags: []string{
4499 "-advertise-alpn", "\x03foo",
4500 },
4501 shouldFail: true,
4502 expectedError: ":PARSE_TLSEXT:",
4503 })
4504 testCases = append(testCases, testCase{
4505 testType: serverTest,
4506 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4507 config: Config{
4508 MaxVersion: ver.version,
4509 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004510 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004511 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004512 },
David Benjamin97d17d92016-07-14 16:12:00 -04004513 flags: []string{
4514 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004515 },
David Benjamin97d17d92016-07-14 16:12:00 -04004516 shouldFail: true,
4517 expectedError: ":PARSE_TLSEXT:",
4518 })
4519
4520 // Test NPN and the interaction with ALPN.
4521 if ver.version < VersionTLS13 {
4522 // Test that the server prefers ALPN over NPN.
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "ALPNServer-Preferred-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 NextProtos: []string{"foo", "bar", "baz"},
4529 },
4530 flags: []string{
4531 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4532 "-select-alpn", "foo",
4533 "-advertise-npn", "\x03foo\x03bar\x03baz",
4534 },
4535 expectedNextProto: "foo",
4536 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004537 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004538 })
4539 testCases = append(testCases, testCase{
4540 testType: serverTest,
4541 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4542 config: Config{
4543 MaxVersion: ver.version,
4544 NextProtos: []string{"foo", "bar", "baz"},
4545 Bugs: ProtocolBugs{
4546 SwapNPNAndALPN: true,
4547 },
4548 },
4549 flags: []string{
4550 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4551 "-select-alpn", "foo",
4552 "-advertise-npn", "\x03foo\x03bar\x03baz",
4553 },
4554 expectedNextProto: "foo",
4555 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004556 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004557 })
4558
4559 // Test that negotiating both NPN and ALPN is forbidden.
4560 testCases = append(testCases, testCase{
4561 name: "NegotiateALPNAndNPN-" + ver.name,
4562 config: Config{
4563 MaxVersion: ver.version,
4564 NextProtos: []string{"foo", "bar", "baz"},
4565 Bugs: ProtocolBugs{
4566 NegotiateALPNAndNPN: true,
4567 },
4568 },
4569 flags: []string{
4570 "-advertise-alpn", "\x03foo",
4571 "-select-next-proto", "foo",
4572 },
4573 shouldFail: true,
4574 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4575 })
4576 testCases = append(testCases, testCase{
4577 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4578 config: Config{
4579 MaxVersion: ver.version,
4580 NextProtos: []string{"foo", "bar", "baz"},
4581 Bugs: ProtocolBugs{
4582 NegotiateALPNAndNPN: true,
4583 SwapNPNAndALPN: true,
4584 },
4585 },
4586 flags: []string{
4587 "-advertise-alpn", "\x03foo",
4588 "-select-next-proto", "foo",
4589 },
4590 shouldFail: true,
4591 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4592 })
4593
4594 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4595 testCases = append(testCases, testCase{
4596 name: "DisableNPN-" + ver.name,
4597 config: Config{
4598 MaxVersion: ver.version,
4599 NextProtos: []string{"foo"},
4600 },
4601 flags: []string{
4602 "-select-next-proto", "foo",
4603 "-disable-npn",
4604 },
4605 expectNoNextProto: true,
4606 })
4607 }
4608
4609 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004610
4611 // Resume with a corrupt ticket.
4612 testCases = append(testCases, testCase{
4613 testType: serverTest,
4614 name: "CorruptTicket-" + ver.name,
4615 config: Config{
4616 MaxVersion: ver.version,
4617 Bugs: ProtocolBugs{
4618 CorruptTicket: true,
4619 },
4620 },
4621 resumeSession: true,
4622 expectResumeRejected: true,
4623 })
4624 // Test the ticket callback, with and without renewal.
4625 testCases = append(testCases, testCase{
4626 testType: serverTest,
4627 name: "TicketCallback-" + ver.name,
4628 config: Config{
4629 MaxVersion: ver.version,
4630 },
4631 resumeSession: true,
4632 flags: []string{"-use-ticket-callback"},
4633 })
4634 testCases = append(testCases, testCase{
4635 testType: serverTest,
4636 name: "TicketCallback-Renew-" + ver.name,
4637 config: Config{
4638 MaxVersion: ver.version,
4639 Bugs: ProtocolBugs{
4640 ExpectNewTicket: true,
4641 },
4642 },
4643 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4644 resumeSession: true,
4645 })
4646
4647 // Test that the ticket callback is only called once when everything before
4648 // it in the ClientHello is asynchronous. This corrupts the ticket so
4649 // certificate selection callbacks run.
4650 testCases = append(testCases, testCase{
4651 testType: serverTest,
4652 name: "TicketCallback-SingleCall-" + ver.name,
4653 config: Config{
4654 MaxVersion: ver.version,
4655 Bugs: ProtocolBugs{
4656 CorruptTicket: true,
4657 },
4658 },
4659 resumeSession: true,
4660 expectResumeRejected: true,
4661 flags: []string{
4662 "-use-ticket-callback",
4663 "-async",
4664 },
4665 })
4666
4667 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004668 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004669 testCases = append(testCases, testCase{
4670 testType: serverTest,
4671 name: "OversizedSessionId-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 Bugs: ProtocolBugs{
4675 OversizedSessionId: true,
4676 },
4677 },
4678 resumeSession: true,
4679 shouldFail: true,
4680 expectedError: ":DECODE_ERROR:",
4681 })
4682 }
4683
4684 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4685 // are ignored.
4686 if ver.hasDTLS {
4687 testCases = append(testCases, testCase{
4688 protocol: dtls,
4689 name: "SRTP-Client-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4693 },
4694 flags: []string{
4695 "-srtp-profiles",
4696 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4697 },
4698 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4699 })
4700 testCases = append(testCases, testCase{
4701 protocol: dtls,
4702 testType: serverTest,
4703 name: "SRTP-Server-" + ver.name,
4704 config: Config{
4705 MaxVersion: ver.version,
4706 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4707 },
4708 flags: []string{
4709 "-srtp-profiles",
4710 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4711 },
4712 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4713 })
4714 // Test that the MKI is ignored.
4715 testCases = append(testCases, testCase{
4716 protocol: dtls,
4717 testType: serverTest,
4718 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4719 config: Config{
4720 MaxVersion: ver.version,
4721 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4722 Bugs: ProtocolBugs{
4723 SRTPMasterKeyIdentifer: "bogus",
4724 },
4725 },
4726 flags: []string{
4727 "-srtp-profiles",
4728 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4729 },
4730 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4731 })
4732 // Test that SRTP isn't negotiated on the server if there were
4733 // no matching profiles.
4734 testCases = append(testCases, testCase{
4735 protocol: dtls,
4736 testType: serverTest,
4737 name: "SRTP-Server-NoMatch-" + ver.name,
4738 config: Config{
4739 MaxVersion: ver.version,
4740 SRTPProtectionProfiles: []uint16{100, 101, 102},
4741 },
4742 flags: []string{
4743 "-srtp-profiles",
4744 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4745 },
4746 expectedSRTPProtectionProfile: 0,
4747 })
4748 // Test that the server returning an invalid SRTP profile is
4749 // flagged as an error by the client.
4750 testCases = append(testCases, testCase{
4751 protocol: dtls,
4752 name: "SRTP-Client-NoMatch-" + ver.name,
4753 config: Config{
4754 MaxVersion: ver.version,
4755 Bugs: ProtocolBugs{
4756 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4757 },
4758 },
4759 flags: []string{
4760 "-srtp-profiles",
4761 "SRTP_AES128_CM_SHA1_80",
4762 },
4763 shouldFail: true,
4764 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4765 })
4766 }
4767
4768 // Test SCT list.
4769 testCases = append(testCases, testCase{
4770 name: "SignedCertificateTimestampList-Client-" + ver.name,
4771 testType: clientTest,
4772 config: Config{
4773 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004774 },
David Benjamin97d17d92016-07-14 16:12:00 -04004775 flags: []string{
4776 "-enable-signed-cert-timestamps",
4777 "-expect-signed-cert-timestamps",
4778 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004779 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004780 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004781 })
4782 testCases = append(testCases, testCase{
4783 name: "SendSCTListOnResume-" + ver.name,
4784 config: Config{
4785 MaxVersion: ver.version,
4786 Bugs: ProtocolBugs{
4787 SendSCTListOnResume: []byte("bogus"),
4788 },
David Benjamind98452d2015-06-16 14:16:23 -04004789 },
David Benjamin97d17d92016-07-14 16:12:00 -04004790 flags: []string{
4791 "-enable-signed-cert-timestamps",
4792 "-expect-signed-cert-timestamps",
4793 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004794 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004795 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004796 })
4797 testCases = append(testCases, testCase{
4798 name: "SignedCertificateTimestampList-Server-" + ver.name,
4799 testType: serverTest,
4800 config: Config{
4801 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004802 },
David Benjamin97d17d92016-07-14 16:12:00 -04004803 flags: []string{
4804 "-signed-cert-timestamps",
4805 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004806 },
David Benjamin97d17d92016-07-14 16:12:00 -04004807 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004808 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004809 })
4810 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004811
Paul Lietar4fac72e2015-09-09 13:44:55 +01004812 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004813 testType: clientTest,
4814 name: "ClientHelloPadding",
4815 config: Config{
4816 Bugs: ProtocolBugs{
4817 RequireClientHelloSize: 512,
4818 },
4819 },
4820 // This hostname just needs to be long enough to push the
4821 // ClientHello into F5's danger zone between 256 and 511 bytes
4822 // long.
4823 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4824 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004825
4826 // Extensions should not function in SSL 3.0.
4827 testCases = append(testCases, testCase{
4828 testType: serverTest,
4829 name: "SSLv3Extensions-NoALPN",
4830 config: Config{
4831 MaxVersion: VersionSSL30,
4832 NextProtos: []string{"foo", "bar", "baz"},
4833 },
4834 flags: []string{
4835 "-select-alpn", "foo",
4836 },
4837 expectNoNextProto: true,
4838 })
4839
4840 // Test session tickets separately as they follow a different codepath.
4841 testCases = append(testCases, testCase{
4842 testType: serverTest,
4843 name: "SSLv3Extensions-NoTickets",
4844 config: Config{
4845 MaxVersion: VersionSSL30,
4846 Bugs: ProtocolBugs{
4847 // Historically, session tickets in SSL 3.0
4848 // failed in different ways depending on whether
4849 // the client supported renegotiation_info.
4850 NoRenegotiationInfo: true,
4851 },
4852 },
4853 resumeSession: true,
4854 })
4855 testCases = append(testCases, testCase{
4856 testType: serverTest,
4857 name: "SSLv3Extensions-NoTickets2",
4858 config: Config{
4859 MaxVersion: VersionSSL30,
4860 },
4861 resumeSession: true,
4862 })
4863
4864 // But SSL 3.0 does send and process renegotiation_info.
4865 testCases = append(testCases, testCase{
4866 testType: serverTest,
4867 name: "SSLv3Extensions-RenegotiationInfo",
4868 config: Config{
4869 MaxVersion: VersionSSL30,
4870 Bugs: ProtocolBugs{
4871 RequireRenegotiationInfo: true,
4872 },
4873 },
4874 })
4875 testCases = append(testCases, testCase{
4876 testType: serverTest,
4877 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4878 config: Config{
4879 MaxVersion: VersionSSL30,
4880 Bugs: ProtocolBugs{
4881 NoRenegotiationInfo: true,
4882 SendRenegotiationSCSV: true,
4883 RequireRenegotiationInfo: true,
4884 },
4885 },
4886 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004887
4888 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4889 // in ServerHello.
4890 testCases = append(testCases, testCase{
4891 name: "NPN-Forbidden-TLS13",
4892 config: Config{
4893 MaxVersion: VersionTLS13,
4894 NextProtos: []string{"foo"},
4895 Bugs: ProtocolBugs{
4896 NegotiateNPNAtAllVersions: true,
4897 },
4898 },
4899 flags: []string{"-select-next-proto", "foo"},
4900 shouldFail: true,
4901 expectedError: ":ERROR_PARSING_EXTENSION:",
4902 })
4903 testCases = append(testCases, testCase{
4904 name: "EMS-Forbidden-TLS13",
4905 config: Config{
4906 MaxVersion: VersionTLS13,
4907 Bugs: ProtocolBugs{
4908 NegotiateEMSAtAllVersions: true,
4909 },
4910 },
4911 shouldFail: true,
4912 expectedError: ":ERROR_PARSING_EXTENSION:",
4913 })
4914 testCases = append(testCases, testCase{
4915 name: "RenegotiationInfo-Forbidden-TLS13",
4916 config: Config{
4917 MaxVersion: VersionTLS13,
4918 Bugs: ProtocolBugs{
4919 NegotiateRenegotiationInfoAtAllVersions: true,
4920 },
4921 },
4922 shouldFail: true,
4923 expectedError: ":ERROR_PARSING_EXTENSION:",
4924 })
4925 testCases = append(testCases, testCase{
4926 name: "ChannelID-Forbidden-TLS13",
4927 config: Config{
4928 MaxVersion: VersionTLS13,
4929 RequestChannelID: true,
4930 Bugs: ProtocolBugs{
4931 NegotiateChannelIDAtAllVersions: true,
4932 },
4933 },
4934 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4935 shouldFail: true,
4936 expectedError: ":ERROR_PARSING_EXTENSION:",
4937 })
4938 testCases = append(testCases, testCase{
4939 name: "Ticket-Forbidden-TLS13",
4940 config: Config{
4941 MaxVersion: VersionTLS12,
4942 },
4943 resumeConfig: &Config{
4944 MaxVersion: VersionTLS13,
4945 Bugs: ProtocolBugs{
4946 AdvertiseTicketExtension: true,
4947 },
4948 },
4949 resumeSession: true,
4950 shouldFail: true,
4951 expectedError: ":ERROR_PARSING_EXTENSION:",
4952 })
4953
4954 // Test that illegal extensions in TLS 1.3 are declined by the server if
4955 // offered in ClientHello. The runner's server will fail if this occurs,
4956 // so we exercise the offering path. (EMS and Renegotiation Info are
4957 // implicit in every test.)
4958 testCases = append(testCases, testCase{
4959 testType: serverTest,
4960 name: "ChannelID-Declined-TLS13",
4961 config: Config{
4962 MaxVersion: VersionTLS13,
4963 ChannelID: channelIDKey,
4964 },
4965 flags: []string{"-enable-channel-id"},
4966 })
4967 testCases = append(testCases, testCase{
4968 testType: serverTest,
4969 name: "NPN-Server",
4970 config: Config{
4971 MaxVersion: VersionTLS13,
4972 NextProtos: []string{"bar"},
4973 },
4974 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4975 })
David Benjamine78bfde2014-09-06 12:45:15 -04004976}
4977
David Benjamin01fe8202014-09-24 15:21:44 -04004978func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004979 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004980 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004981 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4982 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4983 // TLS 1.3 only shares ciphers with TLS 1.2, so
4984 // we skip certain combinations and use a
4985 // different cipher to test with.
4986 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4987 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4988 continue
4989 }
4990 }
4991
David Benjamin8b8c0062014-11-23 02:47:52 -05004992 protocols := []protocol{tls}
4993 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4994 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004995 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004996 for _, protocol := range protocols {
4997 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4998 if protocol == dtls {
4999 suffix += "-DTLS"
5000 }
5001
David Benjaminece3de92015-03-16 18:02:20 -04005002 if sessionVers.version == resumeVers.version {
5003 testCases = append(testCases, testCase{
5004 protocol: protocol,
5005 name: "Resume-Client" + suffix,
5006 resumeSession: true,
5007 config: Config{
5008 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005009 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005010 Bugs: ProtocolBugs{
5011 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5012 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5013 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005014 },
David Benjaminece3de92015-03-16 18:02:20 -04005015 expectedVersion: sessionVers.version,
5016 expectedResumeVersion: resumeVers.version,
5017 })
5018 } else {
David Benjamin405da482016-08-08 17:25:07 -04005019 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5020
5021 // Offering a TLS 1.3 session sends an empty session ID, so
5022 // there is no way to convince a non-lookahead client the
5023 // session was resumed. It will appear to the client that a
5024 // stray ChangeCipherSpec was sent.
5025 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5026 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005027 }
5028
David Benjaminece3de92015-03-16 18:02:20 -04005029 testCases = append(testCases, testCase{
5030 protocol: protocol,
5031 name: "Resume-Client-Mismatch" + suffix,
5032 resumeSession: true,
5033 config: Config{
5034 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005035 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005036 },
David Benjaminece3de92015-03-16 18:02:20 -04005037 expectedVersion: sessionVers.version,
5038 resumeConfig: &Config{
5039 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005040 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005041 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005042 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005043 },
5044 },
5045 expectedResumeVersion: resumeVers.version,
5046 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005047 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005048 })
5049 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005050
5051 testCases = append(testCases, testCase{
5052 protocol: protocol,
5053 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005054 resumeSession: true,
5055 config: Config{
5056 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005057 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005058 },
5059 expectedVersion: sessionVers.version,
5060 resumeConfig: &Config{
5061 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005062 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005063 },
5064 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005065 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005066 expectedResumeVersion: resumeVers.version,
5067 })
5068
David Benjamin8b8c0062014-11-23 02:47:52 -05005069 testCases = append(testCases, testCase{
5070 protocol: protocol,
5071 testType: serverTest,
5072 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005073 resumeSession: true,
5074 config: Config{
5075 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005076 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005078 expectedVersion: sessionVers.version,
5079 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005080 resumeConfig: &Config{
5081 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005082 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005083 Bugs: ProtocolBugs{
5084 SendBothTickets: true,
5085 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005086 },
5087 expectedResumeVersion: resumeVers.version,
5088 })
5089 }
David Benjamin01fe8202014-09-24 15:21:44 -04005090 }
5091 }
David Benjaminece3de92015-03-16 18:02:20 -04005092
5093 testCases = append(testCases, testCase{
5094 name: "Resume-Client-CipherMismatch",
5095 resumeSession: true,
5096 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005097 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005098 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5099 },
5100 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005101 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005102 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5103 Bugs: ProtocolBugs{
5104 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5105 },
5106 },
5107 shouldFail: true,
5108 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5109 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005110
5111 testCases = append(testCases, testCase{
5112 name: "Resume-Client-CipherMismatch-TLS13",
5113 resumeSession: true,
5114 config: Config{
5115 MaxVersion: VersionTLS13,
5116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5117 },
5118 resumeConfig: &Config{
5119 MaxVersion: VersionTLS13,
5120 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5121 Bugs: ProtocolBugs{
5122 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5123 },
5124 },
5125 shouldFail: true,
5126 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5127 })
David Benjamin01fe8202014-09-24 15:21:44 -04005128}
5129
Adam Langley2ae77d22014-10-28 17:29:33 -07005130func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005131 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005132 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005133 testType: serverTest,
5134 name: "Renegotiate-Server-Forbidden",
5135 config: Config{
5136 MaxVersion: VersionTLS12,
5137 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005138 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005139 shouldFail: true,
5140 expectedError: ":NO_RENEGOTIATION:",
5141 expectedLocalError: "remote error: no renegotiation",
5142 })
Adam Langley5021b222015-06-12 18:27:58 -07005143 // The server shouldn't echo the renegotiation extension unless
5144 // requested by the client.
5145 testCases = append(testCases, testCase{
5146 testType: serverTest,
5147 name: "Renegotiate-Server-NoExt",
5148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005149 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005150 Bugs: ProtocolBugs{
5151 NoRenegotiationInfo: true,
5152 RequireRenegotiationInfo: true,
5153 },
5154 },
5155 shouldFail: true,
5156 expectedLocalError: "renegotiation extension missing",
5157 })
5158 // The renegotiation SCSV should be sufficient for the server to echo
5159 // the extension.
5160 testCases = append(testCases, testCase{
5161 testType: serverTest,
5162 name: "Renegotiate-Server-NoExt-SCSV",
5163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005164 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005165 Bugs: ProtocolBugs{
5166 NoRenegotiationInfo: true,
5167 SendRenegotiationSCSV: true,
5168 RequireRenegotiationInfo: true,
5169 },
5170 },
5171 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005172 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005173 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005175 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005176 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005177 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005178 },
5179 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005180 renegotiate: 1,
5181 flags: []string{
5182 "-renegotiate-freely",
5183 "-expect-total-renegotiations", "1",
5184 },
David Benjamincdea40c2015-03-19 14:09:43 -04005185 })
5186 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005187 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005188 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005190 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005191 Bugs: ProtocolBugs{
5192 EmptyRenegotiationInfo: true,
5193 },
5194 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005195 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005196 shouldFail: true,
5197 expectedError: ":RENEGOTIATION_MISMATCH:",
5198 })
5199 testCases = append(testCases, testCase{
5200 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005201 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005203 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005204 Bugs: ProtocolBugs{
5205 BadRenegotiationInfo: true,
5206 },
5207 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005208 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005209 shouldFail: true,
5210 expectedError: ":RENEGOTIATION_MISMATCH:",
5211 })
5212 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005213 name: "Renegotiate-Client-Downgrade",
5214 renegotiate: 1,
5215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005216 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005217 Bugs: ProtocolBugs{
5218 NoRenegotiationInfoAfterInitial: true,
5219 },
5220 },
5221 flags: []string{"-renegotiate-freely"},
5222 shouldFail: true,
5223 expectedError: ":RENEGOTIATION_MISMATCH:",
5224 })
5225 testCases = append(testCases, testCase{
5226 name: "Renegotiate-Client-Upgrade",
5227 renegotiate: 1,
5228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005229 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005230 Bugs: ProtocolBugs{
5231 NoRenegotiationInfoInInitial: true,
5232 },
5233 },
5234 flags: []string{"-renegotiate-freely"},
5235 shouldFail: true,
5236 expectedError: ":RENEGOTIATION_MISMATCH:",
5237 })
5238 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005239 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005240 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005241 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005242 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005243 Bugs: ProtocolBugs{
5244 NoRenegotiationInfo: true,
5245 },
5246 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005247 flags: []string{
5248 "-renegotiate-freely",
5249 "-expect-total-renegotiations", "1",
5250 },
David Benjamincff0b902015-05-15 23:09:47 -04005251 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005252
5253 // Test that the server may switch ciphers on renegotiation without
5254 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005255 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005256 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005257 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005258 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005259 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005260 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005261 },
5262 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005263 flags: []string{
5264 "-renegotiate-freely",
5265 "-expect-total-renegotiations", "1",
5266 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005267 })
5268 testCases = append(testCases, testCase{
5269 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005270 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005271 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005272 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005273 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5274 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005275 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005276 flags: []string{
5277 "-renegotiate-freely",
5278 "-expect-total-renegotiations", "1",
5279 },
David Benjaminb16346b2015-04-08 19:16:58 -04005280 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005281
5282 // Test that the server may not switch versions on renegotiation.
5283 testCases = append(testCases, testCase{
5284 name: "Renegotiate-Client-SwitchVersion",
5285 config: Config{
5286 MaxVersion: VersionTLS12,
5287 // Pick a cipher which exists at both versions.
5288 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5289 Bugs: ProtocolBugs{
5290 NegotiateVersionOnRenego: VersionTLS11,
5291 },
5292 },
5293 renegotiate: 1,
5294 flags: []string{
5295 "-renegotiate-freely",
5296 "-expect-total-renegotiations", "1",
5297 },
5298 shouldFail: true,
5299 expectedError: ":WRONG_SSL_VERSION:",
5300 })
5301
David Benjaminb16346b2015-04-08 19:16:58 -04005302 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005303 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005304 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005305 config: Config{
5306 MaxVersion: VersionTLS10,
5307 Bugs: ProtocolBugs{
5308 RequireSameRenegoClientVersion: true,
5309 },
5310 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005311 flags: []string{
5312 "-renegotiate-freely",
5313 "-expect-total-renegotiations", "1",
5314 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005315 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005316 testCases = append(testCases, testCase{
5317 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005318 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005319 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005320 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005321 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5322 NextProtos: []string{"foo"},
5323 },
5324 flags: []string{
5325 "-false-start",
5326 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005327 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005328 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005329 },
5330 shimWritesFirst: true,
5331 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005332
5333 // Client-side renegotiation controls.
5334 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005335 name: "Renegotiate-Client-Forbidden-1",
5336 config: Config{
5337 MaxVersion: VersionTLS12,
5338 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005339 renegotiate: 1,
5340 shouldFail: true,
5341 expectedError: ":NO_RENEGOTIATION:",
5342 expectedLocalError: "remote error: no renegotiation",
5343 })
5344 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005345 name: "Renegotiate-Client-Once-1",
5346 config: Config{
5347 MaxVersion: VersionTLS12,
5348 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005349 renegotiate: 1,
5350 flags: []string{
5351 "-renegotiate-once",
5352 "-expect-total-renegotiations", "1",
5353 },
5354 })
5355 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005356 name: "Renegotiate-Client-Freely-1",
5357 config: Config{
5358 MaxVersion: VersionTLS12,
5359 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005360 renegotiate: 1,
5361 flags: []string{
5362 "-renegotiate-freely",
5363 "-expect-total-renegotiations", "1",
5364 },
5365 })
5366 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005367 name: "Renegotiate-Client-Once-2",
5368 config: Config{
5369 MaxVersion: VersionTLS12,
5370 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005371 renegotiate: 2,
5372 flags: []string{"-renegotiate-once"},
5373 shouldFail: true,
5374 expectedError: ":NO_RENEGOTIATION:",
5375 expectedLocalError: "remote error: no renegotiation",
5376 })
5377 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005378 name: "Renegotiate-Client-Freely-2",
5379 config: Config{
5380 MaxVersion: VersionTLS12,
5381 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005382 renegotiate: 2,
5383 flags: []string{
5384 "-renegotiate-freely",
5385 "-expect-total-renegotiations", "2",
5386 },
5387 })
Adam Langley27a0d082015-11-03 13:34:10 -08005388 testCases = append(testCases, testCase{
5389 name: "Renegotiate-Client-NoIgnore",
5390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005391 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005392 Bugs: ProtocolBugs{
5393 SendHelloRequestBeforeEveryAppDataRecord: true,
5394 },
5395 },
5396 shouldFail: true,
5397 expectedError: ":NO_RENEGOTIATION:",
5398 })
5399 testCases = append(testCases, testCase{
5400 name: "Renegotiate-Client-Ignore",
5401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005402 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005403 Bugs: ProtocolBugs{
5404 SendHelloRequestBeforeEveryAppDataRecord: true,
5405 },
5406 },
5407 flags: []string{
5408 "-renegotiate-ignore",
5409 "-expect-total-renegotiations", "0",
5410 },
5411 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005412
David Benjamin397c8e62016-07-08 14:14:36 -07005413 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005414 testCases = append(testCases, testCase{
5415 name: "StrayHelloRequest",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 Bugs: ProtocolBugs{
5419 SendHelloRequestBeforeEveryHandshakeMessage: true,
5420 },
5421 },
5422 })
5423 testCases = append(testCases, testCase{
5424 name: "StrayHelloRequest-Packed",
5425 config: Config{
5426 MaxVersion: VersionTLS12,
5427 Bugs: ProtocolBugs{
5428 PackHandshakeFlight: true,
5429 SendHelloRequestBeforeEveryHandshakeMessage: true,
5430 },
5431 },
5432 })
5433
David Benjamin12d2c482016-07-24 10:56:51 -04005434 // Test renegotiation works if HelloRequest and server Finished come in
5435 // the same record.
5436 testCases = append(testCases, testCase{
5437 name: "Renegotiate-Client-Packed",
5438 config: Config{
5439 MaxVersion: VersionTLS12,
5440 Bugs: ProtocolBugs{
5441 PackHandshakeFlight: true,
5442 PackHelloRequestWithFinished: true,
5443 },
5444 },
5445 renegotiate: 1,
5446 flags: []string{
5447 "-renegotiate-freely",
5448 "-expect-total-renegotiations", "1",
5449 },
5450 })
5451
David Benjamin397c8e62016-07-08 14:14:36 -07005452 // Renegotiation is forbidden in TLS 1.3.
5453 testCases = append(testCases, testCase{
5454 name: "Renegotiate-Client-TLS13",
5455 config: Config{
5456 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005457 Bugs: ProtocolBugs{
5458 SendHelloRequestBeforeEveryAppDataRecord: true,
5459 },
David Benjamin397c8e62016-07-08 14:14:36 -07005460 },
David Benjamin397c8e62016-07-08 14:14:36 -07005461 flags: []string{
5462 "-renegotiate-freely",
5463 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005464 shouldFail: true,
5465 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005466 })
5467
5468 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5469 testCases = append(testCases, testCase{
5470 name: "StrayHelloRequest-TLS13",
5471 config: Config{
5472 MaxVersion: VersionTLS13,
5473 Bugs: ProtocolBugs{
5474 SendHelloRequestBeforeEveryHandshakeMessage: true,
5475 },
5476 },
5477 shouldFail: true,
5478 expectedError: ":UNEXPECTED_MESSAGE:",
5479 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005480}
5481
David Benjamin5e961c12014-11-07 01:48:35 -05005482func addDTLSReplayTests() {
5483 // Test that sequence number replays are detected.
5484 testCases = append(testCases, testCase{
5485 protocol: dtls,
5486 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005487 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005488 replayWrites: true,
5489 })
5490
David Benjamin8e6db492015-07-25 18:29:23 -04005491 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005492 // than the retransmit window.
5493 testCases = append(testCases, testCase{
5494 protocol: dtls,
5495 name: "DTLS-Replay-LargeGaps",
5496 config: Config{
5497 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005498 SequenceNumberMapping: func(in uint64) uint64 {
5499 return in * 127
5500 },
David Benjamin5e961c12014-11-07 01:48:35 -05005501 },
5502 },
David Benjamin8e6db492015-07-25 18:29:23 -04005503 messageCount: 200,
5504 replayWrites: true,
5505 })
5506
5507 // Test the incoming sequence number changing non-monotonically.
5508 testCases = append(testCases, testCase{
5509 protocol: dtls,
5510 name: "DTLS-Replay-NonMonotonic",
5511 config: Config{
5512 Bugs: ProtocolBugs{
5513 SequenceNumberMapping: func(in uint64) uint64 {
5514 return in ^ 31
5515 },
5516 },
5517 },
5518 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005519 replayWrites: true,
5520 })
5521}
5522
Nick Harper60edffd2016-06-21 15:19:24 -07005523var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005524 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005525 id signatureAlgorithm
5526 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005527}{
Nick Harper60edffd2016-06-21 15:19:24 -07005528 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5529 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5530 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5531 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005532 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005533 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5534 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5535 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005536 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5537 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5538 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005539 // Tests for key types prior to TLS 1.2.
5540 {"RSA", 0, testCertRSA},
5541 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005542}
5543
Nick Harper60edffd2016-06-21 15:19:24 -07005544const fakeSigAlg1 signatureAlgorithm = 0x2a01
5545const fakeSigAlg2 signatureAlgorithm = 0xff01
5546
5547func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005548 // Not all ciphers involve a signature. Advertise a list which gives all
5549 // versions a signing cipher.
5550 signingCiphers := []uint16{
5551 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5552 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5553 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5554 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5555 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5556 }
5557
David Benjaminca3d5452016-07-14 12:51:01 -04005558 var allAlgorithms []signatureAlgorithm
5559 for _, alg := range testSignatureAlgorithms {
5560 if alg.id != 0 {
5561 allAlgorithms = append(allAlgorithms, alg.id)
5562 }
5563 }
5564
Nick Harper60edffd2016-06-21 15:19:24 -07005565 // Make sure each signature algorithm works. Include some fake values in
5566 // the list and ensure they're ignored.
5567 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005568 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005569 if (ver.version < VersionTLS12) != (alg.id == 0) {
5570 continue
5571 }
5572
5573 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5574 // or remove it in C.
5575 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005576 continue
5577 }
Nick Harper60edffd2016-06-21 15:19:24 -07005578
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005579 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005580 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005581 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5582 shouldFail = true
5583 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005584 // RSA-PKCS1 does not exist in TLS 1.3.
5585 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5586 shouldFail = true
5587 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005588
5589 var signError, verifyError string
5590 if shouldFail {
5591 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5592 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005593 }
David Benjamin000800a2014-11-14 01:43:59 -05005594
David Benjamin1fb125c2016-07-08 18:52:12 -07005595 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005596
David Benjamin7a41d372016-07-09 11:21:54 -07005597 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005598 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005599 config: Config{
5600 MaxVersion: ver.version,
5601 ClientAuth: RequireAnyClientCert,
5602 VerifySignatureAlgorithms: []signatureAlgorithm{
5603 fakeSigAlg1,
5604 alg.id,
5605 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005606 },
David Benjamin7a41d372016-07-09 11:21:54 -07005607 },
5608 flags: []string{
5609 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5610 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5611 "-enable-all-curves",
5612 },
5613 shouldFail: shouldFail,
5614 expectedError: signError,
5615 expectedPeerSignatureAlgorithm: alg.id,
5616 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005617
David Benjamin7a41d372016-07-09 11:21:54 -07005618 testCases = append(testCases, testCase{
5619 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005620 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005621 config: Config{
5622 MaxVersion: ver.version,
5623 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5624 SignSignatureAlgorithms: []signatureAlgorithm{
5625 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005626 },
David Benjamin7a41d372016-07-09 11:21:54 -07005627 Bugs: ProtocolBugs{
5628 SkipECDSACurveCheck: shouldFail,
5629 IgnoreSignatureVersionChecks: shouldFail,
5630 // The client won't advertise 1.3-only algorithms after
5631 // version negotiation.
5632 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005633 },
David Benjamin7a41d372016-07-09 11:21:54 -07005634 },
5635 flags: []string{
5636 "-require-any-client-certificate",
5637 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5638 "-enable-all-curves",
5639 },
5640 shouldFail: shouldFail,
5641 expectedError: verifyError,
5642 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005643
5644 testCases = append(testCases, testCase{
5645 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005646 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005647 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005648 MaxVersion: ver.version,
5649 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005650 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005651 fakeSigAlg1,
5652 alg.id,
5653 fakeSigAlg2,
5654 },
5655 },
5656 flags: []string{
5657 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5658 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5659 "-enable-all-curves",
5660 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005661 shouldFail: shouldFail,
5662 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005663 expectedPeerSignatureAlgorithm: alg.id,
5664 })
5665
5666 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005667 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005668 config: Config{
5669 MaxVersion: ver.version,
5670 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005671 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005672 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005673 alg.id,
5674 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005675 Bugs: ProtocolBugs{
5676 SkipECDSACurveCheck: shouldFail,
5677 IgnoreSignatureVersionChecks: shouldFail,
5678 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005679 },
5680 flags: []string{
5681 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5682 "-enable-all-curves",
5683 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005684 shouldFail: shouldFail,
5685 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005686 })
David Benjamin5208fd42016-07-13 21:43:25 -04005687
5688 if !shouldFail {
5689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "ClientAuth-InvalidSignature" + suffix,
5692 config: Config{
5693 MaxVersion: ver.version,
5694 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5695 SignSignatureAlgorithms: []signatureAlgorithm{
5696 alg.id,
5697 },
5698 Bugs: ProtocolBugs{
5699 InvalidSignature: true,
5700 },
5701 },
5702 flags: []string{
5703 "-require-any-client-certificate",
5704 "-enable-all-curves",
5705 },
5706 shouldFail: true,
5707 expectedError: ":BAD_SIGNATURE:",
5708 })
5709
5710 testCases = append(testCases, testCase{
5711 name: "ServerAuth-InvalidSignature" + suffix,
5712 config: Config{
5713 MaxVersion: ver.version,
5714 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5715 CipherSuites: signingCiphers,
5716 SignSignatureAlgorithms: []signatureAlgorithm{
5717 alg.id,
5718 },
5719 Bugs: ProtocolBugs{
5720 InvalidSignature: true,
5721 },
5722 },
5723 flags: []string{"-enable-all-curves"},
5724 shouldFail: true,
5725 expectedError: ":BAD_SIGNATURE:",
5726 })
5727 }
David Benjaminca3d5452016-07-14 12:51:01 -04005728
5729 if ver.version >= VersionTLS12 && !shouldFail {
5730 testCases = append(testCases, testCase{
5731 name: "ClientAuth-Sign-Negotiate" + suffix,
5732 config: Config{
5733 MaxVersion: ver.version,
5734 ClientAuth: RequireAnyClientCert,
5735 VerifySignatureAlgorithms: allAlgorithms,
5736 },
5737 flags: []string{
5738 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5739 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5740 "-enable-all-curves",
5741 "-signing-prefs", strconv.Itoa(int(alg.id)),
5742 },
5743 expectedPeerSignatureAlgorithm: alg.id,
5744 })
5745
5746 testCases = append(testCases, testCase{
5747 testType: serverTest,
5748 name: "ServerAuth-Sign-Negotiate" + suffix,
5749 config: Config{
5750 MaxVersion: ver.version,
5751 CipherSuites: signingCiphers,
5752 VerifySignatureAlgorithms: allAlgorithms,
5753 },
5754 flags: []string{
5755 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5756 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5757 "-enable-all-curves",
5758 "-signing-prefs", strconv.Itoa(int(alg.id)),
5759 },
5760 expectedPeerSignatureAlgorithm: alg.id,
5761 })
5762 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005763 }
David Benjamin000800a2014-11-14 01:43:59 -05005764 }
5765
Nick Harper60edffd2016-06-21 15:19:24 -07005766 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005767 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005768 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005769 config: Config{
5770 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005771 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005772 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005773 signatureECDSAWithP521AndSHA512,
5774 signatureRSAPKCS1WithSHA384,
5775 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005776 },
5777 },
5778 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005779 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5780 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005781 },
Nick Harper60edffd2016-06-21 15:19:24 -07005782 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005783 })
5784
5785 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005786 name: "ClientAuth-SignatureType-TLS13",
5787 config: Config{
5788 ClientAuth: RequireAnyClientCert,
5789 MaxVersion: VersionTLS13,
5790 VerifySignatureAlgorithms: []signatureAlgorithm{
5791 signatureECDSAWithP521AndSHA512,
5792 signatureRSAPKCS1WithSHA384,
5793 signatureRSAPSSWithSHA384,
5794 signatureECDSAWithSHA1,
5795 },
5796 },
5797 flags: []string{
5798 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5799 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5800 },
5801 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5802 })
5803
5804 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005805 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005806 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005808 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005809 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005810 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005811 signatureECDSAWithP521AndSHA512,
5812 signatureRSAPKCS1WithSHA384,
5813 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005814 },
5815 },
Nick Harper60edffd2016-06-21 15:19:24 -07005816 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005817 })
5818
Steven Valdez143e8b32016-07-11 13:19:03 -04005819 testCases = append(testCases, testCase{
5820 testType: serverTest,
5821 name: "ServerAuth-SignatureType-TLS13",
5822 config: Config{
5823 MaxVersion: VersionTLS13,
5824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5825 VerifySignatureAlgorithms: []signatureAlgorithm{
5826 signatureECDSAWithP521AndSHA512,
5827 signatureRSAPKCS1WithSHA384,
5828 signatureRSAPSSWithSHA384,
5829 signatureECDSAWithSHA1,
5830 },
5831 },
5832 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5833 })
5834
David Benjamina95e9f32016-07-08 16:28:04 -07005835 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005836 testCases = append(testCases, testCase{
5837 testType: serverTest,
5838 name: "Verify-ClientAuth-SignatureType",
5839 config: Config{
5840 MaxVersion: VersionTLS12,
5841 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005842 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005843 signatureRSAPKCS1WithSHA256,
5844 },
5845 Bugs: ProtocolBugs{
5846 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5847 },
5848 },
5849 flags: []string{
5850 "-require-any-client-certificate",
5851 },
5852 shouldFail: true,
5853 expectedError: ":WRONG_SIGNATURE_TYPE:",
5854 })
5855
5856 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005857 testType: serverTest,
5858 name: "Verify-ClientAuth-SignatureType-TLS13",
5859 config: Config{
5860 MaxVersion: VersionTLS13,
5861 Certificates: []Certificate{rsaCertificate},
5862 SignSignatureAlgorithms: []signatureAlgorithm{
5863 signatureRSAPSSWithSHA256,
5864 },
5865 Bugs: ProtocolBugs{
5866 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5867 },
5868 },
5869 flags: []string{
5870 "-require-any-client-certificate",
5871 },
5872 shouldFail: true,
5873 expectedError: ":WRONG_SIGNATURE_TYPE:",
5874 })
5875
5876 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005877 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005878 config: Config{
5879 MaxVersion: VersionTLS12,
5880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005881 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005882 signatureRSAPKCS1WithSHA256,
5883 },
5884 Bugs: ProtocolBugs{
5885 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5886 },
5887 },
5888 shouldFail: true,
5889 expectedError: ":WRONG_SIGNATURE_TYPE:",
5890 })
5891
Steven Valdez143e8b32016-07-11 13:19:03 -04005892 testCases = append(testCases, testCase{
5893 name: "Verify-ServerAuth-SignatureType-TLS13",
5894 config: Config{
5895 MaxVersion: VersionTLS13,
5896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5897 SignSignatureAlgorithms: []signatureAlgorithm{
5898 signatureRSAPSSWithSHA256,
5899 },
5900 Bugs: ProtocolBugs{
5901 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5902 },
5903 },
5904 shouldFail: true,
5905 expectedError: ":WRONG_SIGNATURE_TYPE:",
5906 })
5907
David Benjamin51dd7d62016-07-08 16:07:01 -07005908 // Test that, if the list is missing, the peer falls back to SHA-1 in
5909 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005910 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005911 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005913 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005914 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005915 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005916 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005917 },
5918 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005919 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005920 },
5921 },
5922 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005923 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5924 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005925 },
5926 })
5927
5928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005930 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005931 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005932 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005933 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005934 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005935 },
5936 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005937 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005938 },
5939 },
David Benjaminee32bea2016-08-17 13:36:44 -04005940 flags: []string{
5941 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5942 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5943 },
5944 })
5945
5946 testCases = append(testCases, testCase{
5947 name: "ClientAuth-SHA1-Fallback-ECDSA",
5948 config: Config{
5949 MaxVersion: VersionTLS12,
5950 ClientAuth: RequireAnyClientCert,
5951 VerifySignatureAlgorithms: []signatureAlgorithm{
5952 signatureECDSAWithSHA1,
5953 },
5954 Bugs: ProtocolBugs{
5955 NoSignatureAlgorithms: true,
5956 },
5957 },
5958 flags: []string{
5959 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5960 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5961 },
5962 })
5963
5964 testCases = append(testCases, testCase{
5965 testType: serverTest,
5966 name: "ServerAuth-SHA1-Fallback-ECDSA",
5967 config: Config{
5968 MaxVersion: VersionTLS12,
5969 VerifySignatureAlgorithms: []signatureAlgorithm{
5970 signatureECDSAWithSHA1,
5971 },
5972 Bugs: ProtocolBugs{
5973 NoSignatureAlgorithms: true,
5974 },
5975 },
5976 flags: []string{
5977 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5978 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5979 },
David Benjamin000800a2014-11-14 01:43:59 -05005980 })
David Benjamin72dc7832015-03-16 17:49:43 -04005981
David Benjamin51dd7d62016-07-08 16:07:01 -07005982 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005983 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005984 config: Config{
5985 MaxVersion: VersionTLS13,
5986 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005987 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005988 signatureRSAPKCS1WithSHA1,
5989 },
5990 Bugs: ProtocolBugs{
5991 NoSignatureAlgorithms: true,
5992 },
5993 },
5994 flags: []string{
5995 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5996 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5997 },
David Benjamin48901652016-08-01 12:12:47 -04005998 shouldFail: true,
5999 // An empty CertificateRequest signature algorithm list is a
6000 // syntax error in TLS 1.3.
6001 expectedError: ":DECODE_ERROR:",
6002 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006003 })
6004
6005 testCases = append(testCases, testCase{
6006 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006007 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006008 config: Config{
6009 MaxVersion: VersionTLS13,
6010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006011 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006012 signatureRSAPKCS1WithSHA1,
6013 },
6014 Bugs: ProtocolBugs{
6015 NoSignatureAlgorithms: true,
6016 },
6017 },
6018 shouldFail: true,
6019 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6020 })
6021
David Benjaminb62d2872016-07-18 14:55:02 +02006022 // Test that hash preferences are enforced. BoringSSL does not implement
6023 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006024 testCases = append(testCases, testCase{
6025 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006026 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006028 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006029 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006030 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006031 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006032 },
6033 Bugs: ProtocolBugs{
6034 IgnorePeerSignatureAlgorithmPreferences: true,
6035 },
6036 },
6037 flags: []string{"-require-any-client-certificate"},
6038 shouldFail: true,
6039 expectedError: ":WRONG_SIGNATURE_TYPE:",
6040 })
6041
6042 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006043 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006045 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006046 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006047 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006048 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006049 },
6050 Bugs: ProtocolBugs{
6051 IgnorePeerSignatureAlgorithmPreferences: true,
6052 },
6053 },
6054 shouldFail: true,
6055 expectedError: ":WRONG_SIGNATURE_TYPE:",
6056 })
David Benjaminb62d2872016-07-18 14:55:02 +02006057 testCases = append(testCases, testCase{
6058 testType: serverTest,
6059 name: "ClientAuth-Enforced-TLS13",
6060 config: Config{
6061 MaxVersion: VersionTLS13,
6062 Certificates: []Certificate{rsaCertificate},
6063 SignSignatureAlgorithms: []signatureAlgorithm{
6064 signatureRSAPKCS1WithMD5,
6065 },
6066 Bugs: ProtocolBugs{
6067 IgnorePeerSignatureAlgorithmPreferences: true,
6068 IgnoreSignatureVersionChecks: true,
6069 },
6070 },
6071 flags: []string{"-require-any-client-certificate"},
6072 shouldFail: true,
6073 expectedError: ":WRONG_SIGNATURE_TYPE:",
6074 })
6075
6076 testCases = append(testCases, testCase{
6077 name: "ServerAuth-Enforced-TLS13",
6078 config: Config{
6079 MaxVersion: VersionTLS13,
6080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6081 SignSignatureAlgorithms: []signatureAlgorithm{
6082 signatureRSAPKCS1WithMD5,
6083 },
6084 Bugs: ProtocolBugs{
6085 IgnorePeerSignatureAlgorithmPreferences: true,
6086 IgnoreSignatureVersionChecks: true,
6087 },
6088 },
6089 shouldFail: true,
6090 expectedError: ":WRONG_SIGNATURE_TYPE:",
6091 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006092
6093 // Test that the agreed upon digest respects the client preferences and
6094 // the server digests.
6095 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006096 name: "NoCommonAlgorithms-Digests",
6097 config: Config{
6098 MaxVersion: VersionTLS12,
6099 ClientAuth: RequireAnyClientCert,
6100 VerifySignatureAlgorithms: []signatureAlgorithm{
6101 signatureRSAPKCS1WithSHA512,
6102 signatureRSAPKCS1WithSHA1,
6103 },
6104 },
6105 flags: []string{
6106 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6107 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6108 "-digest-prefs", "SHA256",
6109 },
6110 shouldFail: true,
6111 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6112 })
6113 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006114 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006116 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006117 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006118 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006119 signatureRSAPKCS1WithSHA512,
6120 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006121 },
6122 },
6123 flags: []string{
6124 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6125 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006126 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006127 },
David Benjaminca3d5452016-07-14 12:51:01 -04006128 shouldFail: true,
6129 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6130 })
6131 testCases = append(testCases, testCase{
6132 name: "NoCommonAlgorithms-TLS13",
6133 config: Config{
6134 MaxVersion: VersionTLS13,
6135 ClientAuth: RequireAnyClientCert,
6136 VerifySignatureAlgorithms: []signatureAlgorithm{
6137 signatureRSAPSSWithSHA512,
6138 signatureRSAPSSWithSHA384,
6139 },
6140 },
6141 flags: []string{
6142 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6143 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6144 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6145 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006146 shouldFail: true,
6147 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006148 })
6149 testCases = append(testCases, testCase{
6150 name: "Agree-Digest-SHA256",
6151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006152 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006153 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006154 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006155 signatureRSAPKCS1WithSHA1,
6156 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006157 },
6158 },
6159 flags: []string{
6160 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6161 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006162 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006163 },
Nick Harper60edffd2016-06-21 15:19:24 -07006164 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006165 })
6166 testCases = append(testCases, testCase{
6167 name: "Agree-Digest-SHA1",
6168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006169 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006170 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006171 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006172 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006173 },
6174 },
6175 flags: []string{
6176 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6177 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006178 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006179 },
Nick Harper60edffd2016-06-21 15:19:24 -07006180 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006181 })
6182 testCases = append(testCases, testCase{
6183 name: "Agree-Digest-Default",
6184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006185 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006186 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006187 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006188 signatureRSAPKCS1WithSHA256,
6189 signatureECDSAWithP256AndSHA256,
6190 signatureRSAPKCS1WithSHA1,
6191 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006192 },
6193 },
6194 flags: []string{
6195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6197 },
Nick Harper60edffd2016-06-21 15:19:24 -07006198 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006199 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006200
David Benjaminca3d5452016-07-14 12:51:01 -04006201 // Test that the signing preference list may include extra algorithms
6202 // without negotiation problems.
6203 testCases = append(testCases, testCase{
6204 testType: serverTest,
6205 name: "FilterExtraAlgorithms",
6206 config: Config{
6207 MaxVersion: VersionTLS12,
6208 VerifySignatureAlgorithms: []signatureAlgorithm{
6209 signatureRSAPKCS1WithSHA256,
6210 },
6211 },
6212 flags: []string{
6213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6215 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6216 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6217 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6218 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6219 },
6220 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6221 })
6222
David Benjamin4c3ddf72016-06-29 18:13:53 -04006223 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6224 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006225 testCases = append(testCases, testCase{
6226 name: "CheckLeafCurve",
6227 config: Config{
6228 MaxVersion: VersionTLS12,
6229 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006230 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006231 },
6232 flags: []string{"-p384-only"},
6233 shouldFail: true,
6234 expectedError: ":BAD_ECC_CERT:",
6235 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006236
6237 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6238 testCases = append(testCases, testCase{
6239 name: "CheckLeafCurve-TLS13",
6240 config: Config{
6241 MaxVersion: VersionTLS13,
6242 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6243 Certificates: []Certificate{ecdsaP256Certificate},
6244 },
6245 flags: []string{"-p384-only"},
6246 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006247
6248 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6249 testCases = append(testCases, testCase{
6250 name: "ECDSACurveMismatch-Verify-TLS12",
6251 config: Config{
6252 MaxVersion: VersionTLS12,
6253 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6254 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006255 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006256 signatureECDSAWithP384AndSHA384,
6257 },
6258 },
6259 })
6260
6261 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6262 testCases = append(testCases, testCase{
6263 name: "ECDSACurveMismatch-Verify-TLS13",
6264 config: Config{
6265 MaxVersion: VersionTLS13,
6266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6267 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006268 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006269 signatureECDSAWithP384AndSHA384,
6270 },
6271 Bugs: ProtocolBugs{
6272 SkipECDSACurveCheck: true,
6273 },
6274 },
6275 shouldFail: true,
6276 expectedError: ":WRONG_SIGNATURE_TYPE:",
6277 })
6278
6279 // Signature algorithm selection in TLS 1.3 should take the curve into
6280 // account.
6281 testCases = append(testCases, testCase{
6282 testType: serverTest,
6283 name: "ECDSACurveMismatch-Sign-TLS13",
6284 config: Config{
6285 MaxVersion: VersionTLS13,
6286 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006287 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006288 signatureECDSAWithP384AndSHA384,
6289 signatureECDSAWithP256AndSHA256,
6290 },
6291 },
6292 flags: []string{
6293 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6294 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6295 },
6296 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6297 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006298
6299 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6300 // server does not attempt to sign in that case.
6301 testCases = append(testCases, testCase{
6302 testType: serverTest,
6303 name: "RSA-PSS-Large",
6304 config: Config{
6305 MaxVersion: VersionTLS13,
6306 VerifySignatureAlgorithms: []signatureAlgorithm{
6307 signatureRSAPSSWithSHA512,
6308 },
6309 },
6310 flags: []string{
6311 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6312 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6313 },
6314 shouldFail: true,
6315 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6316 })
David Benjamin57e929f2016-08-30 00:30:38 -04006317
6318 // Test that RSA-PSS is enabled by default for TLS 1.2.
6319 testCases = append(testCases, testCase{
6320 testType: clientTest,
6321 name: "RSA-PSS-Default-Verify",
6322 config: Config{
6323 MaxVersion: VersionTLS12,
6324 SignSignatureAlgorithms: []signatureAlgorithm{
6325 signatureRSAPSSWithSHA256,
6326 },
6327 },
6328 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6329 })
6330
6331 testCases = append(testCases, testCase{
6332 testType: serverTest,
6333 name: "RSA-PSS-Default-Sign",
6334 config: Config{
6335 MaxVersion: VersionTLS12,
6336 VerifySignatureAlgorithms: []signatureAlgorithm{
6337 signatureRSAPSSWithSHA256,
6338 },
6339 },
6340 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6341 })
David Benjamin000800a2014-11-14 01:43:59 -05006342}
6343
David Benjamin83f90402015-01-27 01:09:43 -05006344// timeouts is the retransmit schedule for BoringSSL. It doubles and
6345// caps at 60 seconds. On the 13th timeout, it gives up.
6346var timeouts = []time.Duration{
6347 1 * time.Second,
6348 2 * time.Second,
6349 4 * time.Second,
6350 8 * time.Second,
6351 16 * time.Second,
6352 32 * time.Second,
6353 60 * time.Second,
6354 60 * time.Second,
6355 60 * time.Second,
6356 60 * time.Second,
6357 60 * time.Second,
6358 60 * time.Second,
6359 60 * time.Second,
6360}
6361
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006362// shortTimeouts is an alternate set of timeouts which would occur if the
6363// initial timeout duration was set to 250ms.
6364var shortTimeouts = []time.Duration{
6365 250 * time.Millisecond,
6366 500 * time.Millisecond,
6367 1 * time.Second,
6368 2 * time.Second,
6369 4 * time.Second,
6370 8 * time.Second,
6371 16 * time.Second,
6372 32 * time.Second,
6373 60 * time.Second,
6374 60 * time.Second,
6375 60 * time.Second,
6376 60 * time.Second,
6377 60 * time.Second,
6378}
6379
David Benjamin83f90402015-01-27 01:09:43 -05006380func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006381 // These tests work by coordinating some behavior on both the shim and
6382 // the runner.
6383 //
6384 // TimeoutSchedule configures the runner to send a series of timeout
6385 // opcodes to the shim (see packetAdaptor) immediately before reading
6386 // each peer handshake flight N. The timeout opcode both simulates a
6387 // timeout in the shim and acts as a synchronization point to help the
6388 // runner bracket each handshake flight.
6389 //
6390 // We assume the shim does not read from the channel eagerly. It must
6391 // first wait until it has sent flight N and is ready to receive
6392 // handshake flight N+1. At this point, it will process the timeout
6393 // opcode. It must then immediately respond with a timeout ACK and act
6394 // as if the shim was idle for the specified amount of time.
6395 //
6396 // The runner then drops all packets received before the ACK and
6397 // continues waiting for flight N. This ordering results in one attempt
6398 // at sending flight N to be dropped. For the test to complete, the
6399 // shim must send flight N again, testing that the shim implements DTLS
6400 // retransmit on a timeout.
6401
Steven Valdez143e8b32016-07-11 13:19:03 -04006402 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006403 // likely be more epochs to cross and the final message's retransmit may
6404 // be more complex.
6405
David Benjamin585d7a42016-06-02 14:58:00 -04006406 for _, async := range []bool{true, false} {
6407 var tests []testCase
6408
6409 // Test that this is indeed the timeout schedule. Stress all
6410 // four patterns of handshake.
6411 for i := 1; i < len(timeouts); i++ {
6412 number := strconv.Itoa(i)
6413 tests = append(tests, testCase{
6414 protocol: dtls,
6415 name: "DTLS-Retransmit-Client-" + number,
6416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006417 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006418 Bugs: ProtocolBugs{
6419 TimeoutSchedule: timeouts[:i],
6420 },
6421 },
6422 resumeSession: true,
6423 })
6424 tests = append(tests, testCase{
6425 protocol: dtls,
6426 testType: serverTest,
6427 name: "DTLS-Retransmit-Server-" + number,
6428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006429 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006430 Bugs: ProtocolBugs{
6431 TimeoutSchedule: timeouts[:i],
6432 },
6433 },
6434 resumeSession: true,
6435 })
6436 }
6437
6438 // Test that exceeding the timeout schedule hits a read
6439 // timeout.
6440 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006441 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006442 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006444 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006445 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006446 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006447 },
6448 },
6449 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006450 shouldFail: true,
6451 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006452 })
David Benjamin585d7a42016-06-02 14:58:00 -04006453
6454 if async {
6455 // Test that timeout handling has a fudge factor, due to API
6456 // problems.
6457 tests = append(tests, testCase{
6458 protocol: dtls,
6459 name: "DTLS-Retransmit-Fudge",
6460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006462 Bugs: ProtocolBugs{
6463 TimeoutSchedule: []time.Duration{
6464 timeouts[0] - 10*time.Millisecond,
6465 },
6466 },
6467 },
6468 resumeSession: true,
6469 })
6470 }
6471
6472 // Test that the final Finished retransmitting isn't
6473 // duplicated if the peer badly fragments everything.
6474 tests = append(tests, testCase{
6475 testType: serverTest,
6476 protocol: dtls,
6477 name: "DTLS-Retransmit-Fragmented",
6478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006479 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006480 Bugs: ProtocolBugs{
6481 TimeoutSchedule: []time.Duration{timeouts[0]},
6482 MaxHandshakeRecordLength: 2,
6483 },
6484 },
6485 })
6486
6487 // Test the timeout schedule when a shorter initial timeout duration is set.
6488 tests = append(tests, testCase{
6489 protocol: dtls,
6490 name: "DTLS-Retransmit-Short-Client",
6491 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006492 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006493 Bugs: ProtocolBugs{
6494 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6495 },
6496 },
6497 resumeSession: true,
6498 flags: []string{"-initial-timeout-duration-ms", "250"},
6499 })
6500 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006501 protocol: dtls,
6502 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006503 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006505 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006506 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006507 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006508 },
6509 },
6510 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006511 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006512 })
David Benjamin585d7a42016-06-02 14:58:00 -04006513
6514 for _, test := range tests {
6515 if async {
6516 test.name += "-Async"
6517 test.flags = append(test.flags, "-async")
6518 }
6519
6520 testCases = append(testCases, test)
6521 }
David Benjamin83f90402015-01-27 01:09:43 -05006522 }
David Benjamin83f90402015-01-27 01:09:43 -05006523}
6524
David Benjaminc565ebb2015-04-03 04:06:36 -04006525func addExportKeyingMaterialTests() {
6526 for _, vers := range tlsVersions {
6527 if vers.version == VersionSSL30 {
6528 continue
6529 }
6530 testCases = append(testCases, testCase{
6531 name: "ExportKeyingMaterial-" + vers.name,
6532 config: Config{
6533 MaxVersion: vers.version,
6534 },
6535 exportKeyingMaterial: 1024,
6536 exportLabel: "label",
6537 exportContext: "context",
6538 useExportContext: true,
6539 })
6540 testCases = append(testCases, testCase{
6541 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6542 config: Config{
6543 MaxVersion: vers.version,
6544 },
6545 exportKeyingMaterial: 1024,
6546 })
6547 testCases = append(testCases, testCase{
6548 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6549 config: Config{
6550 MaxVersion: vers.version,
6551 },
6552 exportKeyingMaterial: 1024,
6553 useExportContext: true,
6554 })
6555 testCases = append(testCases, testCase{
6556 name: "ExportKeyingMaterial-Small-" + vers.name,
6557 config: Config{
6558 MaxVersion: vers.version,
6559 },
6560 exportKeyingMaterial: 1,
6561 exportLabel: "label",
6562 exportContext: "context",
6563 useExportContext: true,
6564 })
6565 }
6566 testCases = append(testCases, testCase{
6567 name: "ExportKeyingMaterial-SSL3",
6568 config: Config{
6569 MaxVersion: VersionSSL30,
6570 },
6571 exportKeyingMaterial: 1024,
6572 exportLabel: "label",
6573 exportContext: "context",
6574 useExportContext: true,
6575 shouldFail: true,
6576 expectedError: "failed to export keying material",
6577 })
6578}
6579
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006580func addTLSUniqueTests() {
6581 for _, isClient := range []bool{false, true} {
6582 for _, isResumption := range []bool{false, true} {
6583 for _, hasEMS := range []bool{false, true} {
6584 var suffix string
6585 if isResumption {
6586 suffix = "Resume-"
6587 } else {
6588 suffix = "Full-"
6589 }
6590
6591 if hasEMS {
6592 suffix += "EMS-"
6593 } else {
6594 suffix += "NoEMS-"
6595 }
6596
6597 if isClient {
6598 suffix += "Client"
6599 } else {
6600 suffix += "Server"
6601 }
6602
6603 test := testCase{
6604 name: "TLSUnique-" + suffix,
6605 testTLSUnique: true,
6606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006607 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006608 Bugs: ProtocolBugs{
6609 NoExtendedMasterSecret: !hasEMS,
6610 },
6611 },
6612 }
6613
6614 if isResumption {
6615 test.resumeSession = true
6616 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006617 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006618 Bugs: ProtocolBugs{
6619 NoExtendedMasterSecret: !hasEMS,
6620 },
6621 }
6622 }
6623
6624 if isResumption && !hasEMS {
6625 test.shouldFail = true
6626 test.expectedError = "failed to get tls-unique"
6627 }
6628
6629 testCases = append(testCases, test)
6630 }
6631 }
6632 }
6633}
6634
Adam Langley09505632015-07-30 18:10:13 -07006635func addCustomExtensionTests() {
6636 expectedContents := "custom extension"
6637 emptyString := ""
6638
6639 for _, isClient := range []bool{false, true} {
6640 suffix := "Server"
6641 flag := "-enable-server-custom-extension"
6642 testType := serverTest
6643 if isClient {
6644 suffix = "Client"
6645 flag = "-enable-client-custom-extension"
6646 testType = clientTest
6647 }
6648
6649 testCases = append(testCases, testCase{
6650 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006651 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006652 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006653 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006654 Bugs: ProtocolBugs{
6655 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006656 ExpectedCustomExtension: &expectedContents,
6657 },
6658 },
6659 flags: []string{flag},
6660 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006661 testCases = append(testCases, testCase{
6662 testType: testType,
6663 name: "CustomExtensions-" + suffix + "-TLS13",
6664 config: Config{
6665 MaxVersion: VersionTLS13,
6666 Bugs: ProtocolBugs{
6667 CustomExtension: expectedContents,
6668 ExpectedCustomExtension: &expectedContents,
6669 },
6670 },
6671 flags: []string{flag},
6672 })
Adam Langley09505632015-07-30 18:10:13 -07006673
6674 // If the parse callback fails, the handshake should also fail.
6675 testCases = append(testCases, testCase{
6676 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006677 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006679 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006680 Bugs: ProtocolBugs{
6681 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006682 ExpectedCustomExtension: &expectedContents,
6683 },
6684 },
David Benjamin399e7c92015-07-30 23:01:27 -04006685 flags: []string{flag},
6686 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006687 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6688 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006689 testCases = append(testCases, testCase{
6690 testType: testType,
6691 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6692 config: Config{
6693 MaxVersion: VersionTLS13,
6694 Bugs: ProtocolBugs{
6695 CustomExtension: expectedContents + "foo",
6696 ExpectedCustomExtension: &expectedContents,
6697 },
6698 },
6699 flags: []string{flag},
6700 shouldFail: true,
6701 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6702 })
Adam Langley09505632015-07-30 18:10:13 -07006703
6704 // If the add callback fails, the handshake should also fail.
6705 testCases = append(testCases, testCase{
6706 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006707 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006708 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006709 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006710 Bugs: ProtocolBugs{
6711 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006712 ExpectedCustomExtension: &expectedContents,
6713 },
6714 },
David Benjamin399e7c92015-07-30 23:01:27 -04006715 flags: []string{flag, "-custom-extension-fail-add"},
6716 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006717 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6718 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006719 testCases = append(testCases, testCase{
6720 testType: testType,
6721 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6722 config: Config{
6723 MaxVersion: VersionTLS13,
6724 Bugs: ProtocolBugs{
6725 CustomExtension: expectedContents,
6726 ExpectedCustomExtension: &expectedContents,
6727 },
6728 },
6729 flags: []string{flag, "-custom-extension-fail-add"},
6730 shouldFail: true,
6731 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6732 })
Adam Langley09505632015-07-30 18:10:13 -07006733
6734 // If the add callback returns zero, no extension should be
6735 // added.
6736 skipCustomExtension := expectedContents
6737 if isClient {
6738 // For the case where the client skips sending the
6739 // custom extension, the server must not “echo” it.
6740 skipCustomExtension = ""
6741 }
6742 testCases = append(testCases, testCase{
6743 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006744 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006745 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006746 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006747 Bugs: ProtocolBugs{
6748 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006749 ExpectedCustomExtension: &emptyString,
6750 },
6751 },
6752 flags: []string{flag, "-custom-extension-skip"},
6753 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006754 testCases = append(testCases, testCase{
6755 testType: testType,
6756 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6757 config: Config{
6758 MaxVersion: VersionTLS13,
6759 Bugs: ProtocolBugs{
6760 CustomExtension: skipCustomExtension,
6761 ExpectedCustomExtension: &emptyString,
6762 },
6763 },
6764 flags: []string{flag, "-custom-extension-skip"},
6765 })
Adam Langley09505632015-07-30 18:10:13 -07006766 }
6767
6768 // The custom extension add callback should not be called if the client
6769 // doesn't send the extension.
6770 testCases = append(testCases, testCase{
6771 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006772 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006774 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006775 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006776 ExpectedCustomExtension: &emptyString,
6777 },
6778 },
6779 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6780 })
Adam Langley2deb9842015-08-07 11:15:37 -07006781
Steven Valdez143e8b32016-07-11 13:19:03 -04006782 testCases = append(testCases, testCase{
6783 testType: serverTest,
6784 name: "CustomExtensions-NotCalled-Server-TLS13",
6785 config: Config{
6786 MaxVersion: VersionTLS13,
6787 Bugs: ProtocolBugs{
6788 ExpectedCustomExtension: &emptyString,
6789 },
6790 },
6791 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6792 })
6793
Adam Langley2deb9842015-08-07 11:15:37 -07006794 // Test an unknown extension from the server.
6795 testCases = append(testCases, testCase{
6796 testType: clientTest,
6797 name: "UnknownExtension-Client",
6798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006799 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006800 Bugs: ProtocolBugs{
6801 CustomExtension: expectedContents,
6802 },
6803 },
David Benjamin0c40a962016-08-01 12:05:50 -04006804 shouldFail: true,
6805 expectedError: ":UNEXPECTED_EXTENSION:",
6806 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006807 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006808 testCases = append(testCases, testCase{
6809 testType: clientTest,
6810 name: "UnknownExtension-Client-TLS13",
6811 config: Config{
6812 MaxVersion: VersionTLS13,
6813 Bugs: ProtocolBugs{
6814 CustomExtension: expectedContents,
6815 },
6816 },
David Benjamin0c40a962016-08-01 12:05:50 -04006817 shouldFail: true,
6818 expectedError: ":UNEXPECTED_EXTENSION:",
6819 expectedLocalError: "remote error: unsupported extension",
6820 })
6821
6822 // Test a known but unoffered extension from the server.
6823 testCases = append(testCases, testCase{
6824 testType: clientTest,
6825 name: "UnofferedExtension-Client",
6826 config: Config{
6827 MaxVersion: VersionTLS12,
6828 Bugs: ProtocolBugs{
6829 SendALPN: "alpn",
6830 },
6831 },
6832 shouldFail: true,
6833 expectedError: ":UNEXPECTED_EXTENSION:",
6834 expectedLocalError: "remote error: unsupported extension",
6835 })
6836 testCases = append(testCases, testCase{
6837 testType: clientTest,
6838 name: "UnofferedExtension-Client-TLS13",
6839 config: Config{
6840 MaxVersion: VersionTLS13,
6841 Bugs: ProtocolBugs{
6842 SendALPN: "alpn",
6843 },
6844 },
6845 shouldFail: true,
6846 expectedError: ":UNEXPECTED_EXTENSION:",
6847 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006848 })
Adam Langley09505632015-07-30 18:10:13 -07006849}
6850
David Benjaminb36a3952015-12-01 18:53:13 -05006851func addRSAClientKeyExchangeTests() {
6852 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6853 testCases = append(testCases, testCase{
6854 testType: serverTest,
6855 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6856 config: Config{
6857 // Ensure the ClientHello version and final
6858 // version are different, to detect if the
6859 // server uses the wrong one.
6860 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006861 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006862 Bugs: ProtocolBugs{
6863 BadRSAClientKeyExchange: bad,
6864 },
6865 },
6866 shouldFail: true,
6867 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6868 })
6869 }
6870}
6871
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006872var testCurves = []struct {
6873 name string
6874 id CurveID
6875}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006876 {"P-256", CurveP256},
6877 {"P-384", CurveP384},
6878 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006879 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006880}
6881
Steven Valdez5440fe02016-07-18 12:40:30 -04006882const bogusCurve = 0x1234
6883
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006884func addCurveTests() {
6885 for _, curve := range testCurves {
6886 testCases = append(testCases, testCase{
6887 name: "CurveTest-Client-" + curve.name,
6888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006889 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006890 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6891 CurvePreferences: []CurveID{curve.id},
6892 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006893 flags: []string{
6894 "-enable-all-curves",
6895 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6896 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006897 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006898 })
6899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006900 name: "CurveTest-Client-" + curve.name + "-TLS13",
6901 config: Config{
6902 MaxVersion: VersionTLS13,
6903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6904 CurvePreferences: []CurveID{curve.id},
6905 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006906 flags: []string{
6907 "-enable-all-curves",
6908 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6909 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006910 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006911 })
6912 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006913 testType: serverTest,
6914 name: "CurveTest-Server-" + curve.name,
6915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006916 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6918 CurvePreferences: []CurveID{curve.id},
6919 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006920 flags: []string{
6921 "-enable-all-curves",
6922 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6923 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006924 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006925 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006926 testCases = append(testCases, testCase{
6927 testType: serverTest,
6928 name: "CurveTest-Server-" + curve.name + "-TLS13",
6929 config: Config{
6930 MaxVersion: VersionTLS13,
6931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6932 CurvePreferences: []CurveID{curve.id},
6933 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006934 flags: []string{
6935 "-enable-all-curves",
6936 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6937 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006938 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006939 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006940 }
David Benjamin241ae832016-01-15 03:04:54 -05006941
6942 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006943 testCases = append(testCases, testCase{
6944 testType: serverTest,
6945 name: "UnknownCurve",
6946 config: Config{
6947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6948 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6949 },
6950 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006951
6952 // The server must not consider ECDHE ciphers when there are no
6953 // supported curves.
6954 testCases = append(testCases, testCase{
6955 testType: serverTest,
6956 name: "NoSupportedCurves",
6957 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006958 MaxVersion: VersionTLS12,
6959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6960 Bugs: ProtocolBugs{
6961 NoSupportedCurves: true,
6962 },
6963 },
6964 shouldFail: true,
6965 expectedError: ":NO_SHARED_CIPHER:",
6966 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006967 testCases = append(testCases, testCase{
6968 testType: serverTest,
6969 name: "NoSupportedCurves-TLS13",
6970 config: Config{
6971 MaxVersion: VersionTLS13,
6972 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6973 Bugs: ProtocolBugs{
6974 NoSupportedCurves: true,
6975 },
6976 },
6977 shouldFail: true,
6978 expectedError: ":NO_SHARED_CIPHER:",
6979 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006980
6981 // The server must fall back to another cipher when there are no
6982 // supported curves.
6983 testCases = append(testCases, testCase{
6984 testType: serverTest,
6985 name: "NoCommonCurves",
6986 config: Config{
6987 MaxVersion: VersionTLS12,
6988 CipherSuites: []uint16{
6989 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6990 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6991 },
6992 CurvePreferences: []CurveID{CurveP224},
6993 },
6994 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6995 })
6996
6997 // The client must reject bogus curves and disabled curves.
6998 testCases = append(testCases, testCase{
6999 name: "BadECDHECurve",
7000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007001 MaxVersion: VersionTLS12,
7002 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7003 Bugs: ProtocolBugs{
7004 SendCurve: bogusCurve,
7005 },
7006 },
7007 shouldFail: true,
7008 expectedError: ":WRONG_CURVE:",
7009 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007010 testCases = append(testCases, testCase{
7011 name: "BadECDHECurve-TLS13",
7012 config: Config{
7013 MaxVersion: VersionTLS13,
7014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7015 Bugs: ProtocolBugs{
7016 SendCurve: bogusCurve,
7017 },
7018 },
7019 shouldFail: true,
7020 expectedError: ":WRONG_CURVE:",
7021 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007022
7023 testCases = append(testCases, testCase{
7024 name: "UnsupportedCurve",
7025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007026 MaxVersion: VersionTLS12,
7027 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7028 CurvePreferences: []CurveID{CurveP256},
7029 Bugs: ProtocolBugs{
7030 IgnorePeerCurvePreferences: true,
7031 },
7032 },
7033 flags: []string{"-p384-only"},
7034 shouldFail: true,
7035 expectedError: ":WRONG_CURVE:",
7036 })
7037
David Benjamin4f921572016-07-17 14:20:10 +02007038 testCases = append(testCases, testCase{
7039 // TODO(davidben): Add a TLS 1.3 version where
7040 // HelloRetryRequest requests an unsupported curve.
7041 name: "UnsupportedCurve-ServerHello-TLS13",
7042 config: Config{
7043 MaxVersion: VersionTLS12,
7044 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7045 CurvePreferences: []CurveID{CurveP384},
7046 Bugs: ProtocolBugs{
7047 SendCurve: CurveP256,
7048 },
7049 },
7050 flags: []string{"-p384-only"},
7051 shouldFail: true,
7052 expectedError: ":WRONG_CURVE:",
7053 })
7054
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055 // Test invalid curve points.
7056 testCases = append(testCases, testCase{
7057 name: "InvalidECDHPoint-Client",
7058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007059 MaxVersion: VersionTLS12,
7060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7061 CurvePreferences: []CurveID{CurveP256},
7062 Bugs: ProtocolBugs{
7063 InvalidECDHPoint: true,
7064 },
7065 },
7066 shouldFail: true,
7067 expectedError: ":INVALID_ENCODING:",
7068 })
7069 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007070 name: "InvalidECDHPoint-Client-TLS13",
7071 config: Config{
7072 MaxVersion: VersionTLS13,
7073 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7074 CurvePreferences: []CurveID{CurveP256},
7075 Bugs: ProtocolBugs{
7076 InvalidECDHPoint: true,
7077 },
7078 },
7079 shouldFail: true,
7080 expectedError: ":INVALID_ENCODING:",
7081 })
7082 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083 testType: serverTest,
7084 name: "InvalidECDHPoint-Server",
7085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007086 MaxVersion: VersionTLS12,
7087 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7088 CurvePreferences: []CurveID{CurveP256},
7089 Bugs: ProtocolBugs{
7090 InvalidECDHPoint: true,
7091 },
7092 },
7093 shouldFail: true,
7094 expectedError: ":INVALID_ENCODING:",
7095 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007096 testCases = append(testCases, testCase{
7097 testType: serverTest,
7098 name: "InvalidECDHPoint-Server-TLS13",
7099 config: Config{
7100 MaxVersion: VersionTLS13,
7101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7102 CurvePreferences: []CurveID{CurveP256},
7103 Bugs: ProtocolBugs{
7104 InvalidECDHPoint: true,
7105 },
7106 },
7107 shouldFail: true,
7108 expectedError: ":INVALID_ENCODING:",
7109 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007110}
7111
Matt Braithwaite54217e42016-06-13 13:03:47 -07007112func addCECPQ1Tests() {
7113 testCases = append(testCases, testCase{
7114 testType: clientTest,
7115 name: "CECPQ1-Client-BadX25519Part",
7116 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007117 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007118 MinVersion: VersionTLS12,
7119 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7120 Bugs: ProtocolBugs{
7121 CECPQ1BadX25519Part: true,
7122 },
7123 },
7124 flags: []string{"-cipher", "kCECPQ1"},
7125 shouldFail: true,
7126 expectedLocalError: "local error: bad record MAC",
7127 })
7128 testCases = append(testCases, testCase{
7129 testType: clientTest,
7130 name: "CECPQ1-Client-BadNewhopePart",
7131 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007132 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007133 MinVersion: VersionTLS12,
7134 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7135 Bugs: ProtocolBugs{
7136 CECPQ1BadNewhopePart: true,
7137 },
7138 },
7139 flags: []string{"-cipher", "kCECPQ1"},
7140 shouldFail: true,
7141 expectedLocalError: "local error: bad record MAC",
7142 })
7143 testCases = append(testCases, testCase{
7144 testType: serverTest,
7145 name: "CECPQ1-Server-BadX25519Part",
7146 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007147 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007148 MinVersion: VersionTLS12,
7149 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7150 Bugs: ProtocolBugs{
7151 CECPQ1BadX25519Part: true,
7152 },
7153 },
7154 flags: []string{"-cipher", "kCECPQ1"},
7155 shouldFail: true,
7156 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7157 })
7158 testCases = append(testCases, testCase{
7159 testType: serverTest,
7160 name: "CECPQ1-Server-BadNewhopePart",
7161 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007162 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007163 MinVersion: VersionTLS12,
7164 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7165 Bugs: ProtocolBugs{
7166 CECPQ1BadNewhopePart: true,
7167 },
7168 },
7169 flags: []string{"-cipher", "kCECPQ1"},
7170 shouldFail: true,
7171 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7172 })
7173}
7174
David Benjamin5c4e8572016-08-19 17:44:53 -04007175func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007176 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007177 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007178 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007179 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007180 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7181 Bugs: ProtocolBugs{
7182 // This is a 1234-bit prime number, generated
7183 // with:
7184 // openssl gendh 1234 | openssl asn1parse -i
7185 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7186 },
7187 },
David Benjamin9e68f192016-06-30 14:55:33 -04007188 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007189 })
7190 testCases = append(testCases, testCase{
7191 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007192 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007193 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007194 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007195 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7196 },
7197 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007198 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007199 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007200}
7201
David Benjaminc9ae27c2016-06-24 22:56:37 -04007202func addTLS13RecordTests() {
7203 testCases = append(testCases, testCase{
7204 name: "TLS13-RecordPadding",
7205 config: Config{
7206 MaxVersion: VersionTLS13,
7207 MinVersion: VersionTLS13,
7208 Bugs: ProtocolBugs{
7209 RecordPadding: 10,
7210 },
7211 },
7212 })
7213
7214 testCases = append(testCases, testCase{
7215 name: "TLS13-EmptyRecords",
7216 config: Config{
7217 MaxVersion: VersionTLS13,
7218 MinVersion: VersionTLS13,
7219 Bugs: ProtocolBugs{
7220 OmitRecordContents: true,
7221 },
7222 },
7223 shouldFail: true,
7224 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7225 })
7226
7227 testCases = append(testCases, testCase{
7228 name: "TLS13-OnlyPadding",
7229 config: Config{
7230 MaxVersion: VersionTLS13,
7231 MinVersion: VersionTLS13,
7232 Bugs: ProtocolBugs{
7233 OmitRecordContents: true,
7234 RecordPadding: 10,
7235 },
7236 },
7237 shouldFail: true,
7238 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7239 })
7240
7241 testCases = append(testCases, testCase{
7242 name: "TLS13-WrongOuterRecord",
7243 config: Config{
7244 MaxVersion: VersionTLS13,
7245 MinVersion: VersionTLS13,
7246 Bugs: ProtocolBugs{
7247 OuterRecordType: recordTypeHandshake,
7248 },
7249 },
7250 shouldFail: true,
7251 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7252 })
7253}
7254
David Benjamin82261be2016-07-07 14:32:50 -07007255func addChangeCipherSpecTests() {
7256 // Test missing ChangeCipherSpecs.
7257 testCases = append(testCases, testCase{
7258 name: "SkipChangeCipherSpec-Client",
7259 config: Config{
7260 MaxVersion: VersionTLS12,
7261 Bugs: ProtocolBugs{
7262 SkipChangeCipherSpec: true,
7263 },
7264 },
7265 shouldFail: true,
7266 expectedError: ":UNEXPECTED_RECORD:",
7267 })
7268 testCases = append(testCases, testCase{
7269 testType: serverTest,
7270 name: "SkipChangeCipherSpec-Server",
7271 config: Config{
7272 MaxVersion: VersionTLS12,
7273 Bugs: ProtocolBugs{
7274 SkipChangeCipherSpec: true,
7275 },
7276 },
7277 shouldFail: true,
7278 expectedError: ":UNEXPECTED_RECORD:",
7279 })
7280 testCases = append(testCases, testCase{
7281 testType: serverTest,
7282 name: "SkipChangeCipherSpec-Server-NPN",
7283 config: Config{
7284 MaxVersion: VersionTLS12,
7285 NextProtos: []string{"bar"},
7286 Bugs: ProtocolBugs{
7287 SkipChangeCipherSpec: true,
7288 },
7289 },
7290 flags: []string{
7291 "-advertise-npn", "\x03foo\x03bar\x03baz",
7292 },
7293 shouldFail: true,
7294 expectedError: ":UNEXPECTED_RECORD:",
7295 })
7296
7297 // Test synchronization between the handshake and ChangeCipherSpec.
7298 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7299 // rejected. Test both with and without handshake packing to handle both
7300 // when the partial post-CCS message is in its own record and when it is
7301 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007302 for _, packed := range []bool{false, true} {
7303 var suffix string
7304 if packed {
7305 suffix = "-Packed"
7306 }
7307
7308 testCases = append(testCases, testCase{
7309 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7310 config: Config{
7311 MaxVersion: VersionTLS12,
7312 Bugs: ProtocolBugs{
7313 FragmentAcrossChangeCipherSpec: true,
7314 PackHandshakeFlight: packed,
7315 },
7316 },
7317 shouldFail: true,
7318 expectedError: ":UNEXPECTED_RECORD:",
7319 })
7320 testCases = append(testCases, testCase{
7321 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 },
7325 resumeSession: true,
7326 resumeConfig: &Config{
7327 MaxVersion: VersionTLS12,
7328 Bugs: ProtocolBugs{
7329 FragmentAcrossChangeCipherSpec: true,
7330 PackHandshakeFlight: packed,
7331 },
7332 },
7333 shouldFail: true,
7334 expectedError: ":UNEXPECTED_RECORD:",
7335 })
7336 testCases = append(testCases, testCase{
7337 testType: serverTest,
7338 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7339 config: Config{
7340 MaxVersion: VersionTLS12,
7341 Bugs: ProtocolBugs{
7342 FragmentAcrossChangeCipherSpec: true,
7343 PackHandshakeFlight: packed,
7344 },
7345 },
7346 shouldFail: true,
7347 expectedError: ":UNEXPECTED_RECORD:",
7348 })
7349 testCases = append(testCases, testCase{
7350 testType: serverTest,
7351 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 },
7355 resumeSession: true,
7356 resumeConfig: &Config{
7357 MaxVersion: VersionTLS12,
7358 Bugs: ProtocolBugs{
7359 FragmentAcrossChangeCipherSpec: true,
7360 PackHandshakeFlight: packed,
7361 },
7362 },
7363 shouldFail: true,
7364 expectedError: ":UNEXPECTED_RECORD:",
7365 })
7366 testCases = append(testCases, testCase{
7367 testType: serverTest,
7368 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7369 config: Config{
7370 MaxVersion: VersionTLS12,
7371 NextProtos: []string{"bar"},
7372 Bugs: ProtocolBugs{
7373 FragmentAcrossChangeCipherSpec: true,
7374 PackHandshakeFlight: packed,
7375 },
7376 },
7377 flags: []string{
7378 "-advertise-npn", "\x03foo\x03bar\x03baz",
7379 },
7380 shouldFail: true,
7381 expectedError: ":UNEXPECTED_RECORD:",
7382 })
7383 }
7384
David Benjamin61672812016-07-14 23:10:43 -04007385 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7386 // messages in the handshake queue. Do this by testing the server
7387 // reading the client Finished, reversing the flight so Finished comes
7388 // first.
7389 testCases = append(testCases, testCase{
7390 protocol: dtls,
7391 testType: serverTest,
7392 name: "SendUnencryptedFinished-DTLS",
7393 config: Config{
7394 MaxVersion: VersionTLS12,
7395 Bugs: ProtocolBugs{
7396 SendUnencryptedFinished: true,
7397 ReverseHandshakeFragments: true,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7402 })
7403
Steven Valdez143e8b32016-07-11 13:19:03 -04007404 // Test synchronization between encryption changes and the handshake in
7405 // TLS 1.3, where ChangeCipherSpec is implicit.
7406 testCases = append(testCases, testCase{
7407 name: "PartialEncryptedExtensionsWithServerHello",
7408 config: Config{
7409 MaxVersion: VersionTLS13,
7410 Bugs: ProtocolBugs{
7411 PartialEncryptedExtensionsWithServerHello: true,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7416 })
7417 testCases = append(testCases, testCase{
7418 testType: serverTest,
7419 name: "PartialClientFinishedWithClientHello",
7420 config: Config{
7421 MaxVersion: VersionTLS13,
7422 Bugs: ProtocolBugs{
7423 PartialClientFinishedWithClientHello: true,
7424 },
7425 },
7426 shouldFail: true,
7427 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7428 })
7429
David Benjamin82261be2016-07-07 14:32:50 -07007430 // Test that early ChangeCipherSpecs are handled correctly.
7431 testCases = append(testCases, testCase{
7432 testType: serverTest,
7433 name: "EarlyChangeCipherSpec-server-1",
7434 config: Config{
7435 MaxVersion: VersionTLS12,
7436 Bugs: ProtocolBugs{
7437 EarlyChangeCipherSpec: 1,
7438 },
7439 },
7440 shouldFail: true,
7441 expectedError: ":UNEXPECTED_RECORD:",
7442 })
7443 testCases = append(testCases, testCase{
7444 testType: serverTest,
7445 name: "EarlyChangeCipherSpec-server-2",
7446 config: Config{
7447 MaxVersion: VersionTLS12,
7448 Bugs: ProtocolBugs{
7449 EarlyChangeCipherSpec: 2,
7450 },
7451 },
7452 shouldFail: true,
7453 expectedError: ":UNEXPECTED_RECORD:",
7454 })
7455 testCases = append(testCases, testCase{
7456 protocol: dtls,
7457 name: "StrayChangeCipherSpec",
7458 config: Config{
7459 // TODO(davidben): Once DTLS 1.3 exists, test
7460 // that stray ChangeCipherSpec messages are
7461 // rejected.
7462 MaxVersion: VersionTLS12,
7463 Bugs: ProtocolBugs{
7464 StrayChangeCipherSpec: true,
7465 },
7466 },
7467 })
7468
7469 // Test that the contents of ChangeCipherSpec are checked.
7470 testCases = append(testCases, testCase{
7471 name: "BadChangeCipherSpec-1",
7472 config: Config{
7473 MaxVersion: VersionTLS12,
7474 Bugs: ProtocolBugs{
7475 BadChangeCipherSpec: []byte{2},
7476 },
7477 },
7478 shouldFail: true,
7479 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7480 })
7481 testCases = append(testCases, testCase{
7482 name: "BadChangeCipherSpec-2",
7483 config: Config{
7484 MaxVersion: VersionTLS12,
7485 Bugs: ProtocolBugs{
7486 BadChangeCipherSpec: []byte{1, 1},
7487 },
7488 },
7489 shouldFail: true,
7490 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7491 })
7492 testCases = append(testCases, testCase{
7493 protocol: dtls,
7494 name: "BadChangeCipherSpec-DTLS-1",
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Bugs: ProtocolBugs{
7498 BadChangeCipherSpec: []byte{2},
7499 },
7500 },
7501 shouldFail: true,
7502 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7503 })
7504 testCases = append(testCases, testCase{
7505 protocol: dtls,
7506 name: "BadChangeCipherSpec-DTLS-2",
7507 config: Config{
7508 MaxVersion: VersionTLS12,
7509 Bugs: ProtocolBugs{
7510 BadChangeCipherSpec: []byte{1, 1},
7511 },
7512 },
7513 shouldFail: true,
7514 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7515 })
7516}
7517
David Benjamin0b8d5da2016-07-15 00:39:56 -04007518func addWrongMessageTypeTests() {
7519 for _, protocol := range []protocol{tls, dtls} {
7520 var suffix string
7521 if protocol == dtls {
7522 suffix = "-DTLS"
7523 }
7524
7525 testCases = append(testCases, testCase{
7526 protocol: protocol,
7527 testType: serverTest,
7528 name: "WrongMessageType-ClientHello" + suffix,
7529 config: Config{
7530 MaxVersion: VersionTLS12,
7531 Bugs: ProtocolBugs{
7532 SendWrongMessageType: typeClientHello,
7533 },
7534 },
7535 shouldFail: true,
7536 expectedError: ":UNEXPECTED_MESSAGE:",
7537 expectedLocalError: "remote error: unexpected message",
7538 })
7539
7540 if protocol == dtls {
7541 testCases = append(testCases, testCase{
7542 protocol: protocol,
7543 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7544 config: Config{
7545 MaxVersion: VersionTLS12,
7546 Bugs: ProtocolBugs{
7547 SendWrongMessageType: typeHelloVerifyRequest,
7548 },
7549 },
7550 shouldFail: true,
7551 expectedError: ":UNEXPECTED_MESSAGE:",
7552 expectedLocalError: "remote error: unexpected message",
7553 })
7554 }
7555
7556 testCases = append(testCases, testCase{
7557 protocol: protocol,
7558 name: "WrongMessageType-ServerHello" + suffix,
7559 config: Config{
7560 MaxVersion: VersionTLS12,
7561 Bugs: ProtocolBugs{
7562 SendWrongMessageType: typeServerHello,
7563 },
7564 },
7565 shouldFail: true,
7566 expectedError: ":UNEXPECTED_MESSAGE:",
7567 expectedLocalError: "remote error: unexpected message",
7568 })
7569
7570 testCases = append(testCases, testCase{
7571 protocol: protocol,
7572 name: "WrongMessageType-ServerCertificate" + suffix,
7573 config: Config{
7574 MaxVersion: VersionTLS12,
7575 Bugs: ProtocolBugs{
7576 SendWrongMessageType: typeCertificate,
7577 },
7578 },
7579 shouldFail: true,
7580 expectedError: ":UNEXPECTED_MESSAGE:",
7581 expectedLocalError: "remote error: unexpected message",
7582 })
7583
7584 testCases = append(testCases, testCase{
7585 protocol: protocol,
7586 name: "WrongMessageType-CertificateStatus" + suffix,
7587 config: Config{
7588 MaxVersion: VersionTLS12,
7589 Bugs: ProtocolBugs{
7590 SendWrongMessageType: typeCertificateStatus,
7591 },
7592 },
7593 flags: []string{"-enable-ocsp-stapling"},
7594 shouldFail: true,
7595 expectedError: ":UNEXPECTED_MESSAGE:",
7596 expectedLocalError: "remote error: unexpected message",
7597 })
7598
7599 testCases = append(testCases, testCase{
7600 protocol: protocol,
7601 name: "WrongMessageType-ServerKeyExchange" + suffix,
7602 config: Config{
7603 MaxVersion: VersionTLS12,
7604 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7605 Bugs: ProtocolBugs{
7606 SendWrongMessageType: typeServerKeyExchange,
7607 },
7608 },
7609 shouldFail: true,
7610 expectedError: ":UNEXPECTED_MESSAGE:",
7611 expectedLocalError: "remote error: unexpected message",
7612 })
7613
7614 testCases = append(testCases, testCase{
7615 protocol: protocol,
7616 name: "WrongMessageType-CertificateRequest" + suffix,
7617 config: Config{
7618 MaxVersion: VersionTLS12,
7619 ClientAuth: RequireAnyClientCert,
7620 Bugs: ProtocolBugs{
7621 SendWrongMessageType: typeCertificateRequest,
7622 },
7623 },
7624 shouldFail: true,
7625 expectedError: ":UNEXPECTED_MESSAGE:",
7626 expectedLocalError: "remote error: unexpected message",
7627 })
7628
7629 testCases = append(testCases, testCase{
7630 protocol: protocol,
7631 name: "WrongMessageType-ServerHelloDone" + suffix,
7632 config: Config{
7633 MaxVersion: VersionTLS12,
7634 Bugs: ProtocolBugs{
7635 SendWrongMessageType: typeServerHelloDone,
7636 },
7637 },
7638 shouldFail: true,
7639 expectedError: ":UNEXPECTED_MESSAGE:",
7640 expectedLocalError: "remote error: unexpected message",
7641 })
7642
7643 testCases = append(testCases, testCase{
7644 testType: serverTest,
7645 protocol: protocol,
7646 name: "WrongMessageType-ClientCertificate" + suffix,
7647 config: Config{
7648 Certificates: []Certificate{rsaCertificate},
7649 MaxVersion: VersionTLS12,
7650 Bugs: ProtocolBugs{
7651 SendWrongMessageType: typeCertificate,
7652 },
7653 },
7654 flags: []string{"-require-any-client-certificate"},
7655 shouldFail: true,
7656 expectedError: ":UNEXPECTED_MESSAGE:",
7657 expectedLocalError: "remote error: unexpected message",
7658 })
7659
7660 testCases = append(testCases, testCase{
7661 testType: serverTest,
7662 protocol: protocol,
7663 name: "WrongMessageType-CertificateVerify" + suffix,
7664 config: Config{
7665 Certificates: []Certificate{rsaCertificate},
7666 MaxVersion: VersionTLS12,
7667 Bugs: ProtocolBugs{
7668 SendWrongMessageType: typeCertificateVerify,
7669 },
7670 },
7671 flags: []string{"-require-any-client-certificate"},
7672 shouldFail: true,
7673 expectedError: ":UNEXPECTED_MESSAGE:",
7674 expectedLocalError: "remote error: unexpected message",
7675 })
7676
7677 testCases = append(testCases, testCase{
7678 testType: serverTest,
7679 protocol: protocol,
7680 name: "WrongMessageType-ClientKeyExchange" + suffix,
7681 config: Config{
7682 MaxVersion: VersionTLS12,
7683 Bugs: ProtocolBugs{
7684 SendWrongMessageType: typeClientKeyExchange,
7685 },
7686 },
7687 shouldFail: true,
7688 expectedError: ":UNEXPECTED_MESSAGE:",
7689 expectedLocalError: "remote error: unexpected message",
7690 })
7691
7692 if protocol != dtls {
7693 testCases = append(testCases, testCase{
7694 testType: serverTest,
7695 protocol: protocol,
7696 name: "WrongMessageType-NextProtocol" + suffix,
7697 config: Config{
7698 MaxVersion: VersionTLS12,
7699 NextProtos: []string{"bar"},
7700 Bugs: ProtocolBugs{
7701 SendWrongMessageType: typeNextProtocol,
7702 },
7703 },
7704 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7705 shouldFail: true,
7706 expectedError: ":UNEXPECTED_MESSAGE:",
7707 expectedLocalError: "remote error: unexpected message",
7708 })
7709
7710 testCases = append(testCases, testCase{
7711 testType: serverTest,
7712 protocol: protocol,
7713 name: "WrongMessageType-ChannelID" + suffix,
7714 config: Config{
7715 MaxVersion: VersionTLS12,
7716 ChannelID: channelIDKey,
7717 Bugs: ProtocolBugs{
7718 SendWrongMessageType: typeChannelID,
7719 },
7720 },
7721 flags: []string{
7722 "-expect-channel-id",
7723 base64.StdEncoding.EncodeToString(channelIDBytes),
7724 },
7725 shouldFail: true,
7726 expectedError: ":UNEXPECTED_MESSAGE:",
7727 expectedLocalError: "remote error: unexpected message",
7728 })
7729 }
7730
7731 testCases = append(testCases, testCase{
7732 testType: serverTest,
7733 protocol: protocol,
7734 name: "WrongMessageType-ClientFinished" + suffix,
7735 config: Config{
7736 MaxVersion: VersionTLS12,
7737 Bugs: ProtocolBugs{
7738 SendWrongMessageType: typeFinished,
7739 },
7740 },
7741 shouldFail: true,
7742 expectedError: ":UNEXPECTED_MESSAGE:",
7743 expectedLocalError: "remote error: unexpected message",
7744 })
7745
7746 testCases = append(testCases, testCase{
7747 protocol: protocol,
7748 name: "WrongMessageType-NewSessionTicket" + suffix,
7749 config: Config{
7750 MaxVersion: VersionTLS12,
7751 Bugs: ProtocolBugs{
7752 SendWrongMessageType: typeNewSessionTicket,
7753 },
7754 },
7755 shouldFail: true,
7756 expectedError: ":UNEXPECTED_MESSAGE:",
7757 expectedLocalError: "remote error: unexpected message",
7758 })
7759
7760 testCases = append(testCases, testCase{
7761 protocol: protocol,
7762 name: "WrongMessageType-ServerFinished" + suffix,
7763 config: Config{
7764 MaxVersion: VersionTLS12,
7765 Bugs: ProtocolBugs{
7766 SendWrongMessageType: typeFinished,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_MESSAGE:",
7771 expectedLocalError: "remote error: unexpected message",
7772 })
7773
7774 }
7775}
7776
Steven Valdez143e8b32016-07-11 13:19:03 -04007777func addTLS13WrongMessageTypeTests() {
7778 testCases = append(testCases, testCase{
7779 testType: serverTest,
7780 name: "WrongMessageType-TLS13-ClientHello",
7781 config: Config{
7782 MaxVersion: VersionTLS13,
7783 Bugs: ProtocolBugs{
7784 SendWrongMessageType: typeClientHello,
7785 },
7786 },
7787 shouldFail: true,
7788 expectedError: ":UNEXPECTED_MESSAGE:",
7789 expectedLocalError: "remote error: unexpected message",
7790 })
7791
7792 testCases = append(testCases, testCase{
7793 name: "WrongMessageType-TLS13-ServerHello",
7794 config: Config{
7795 MaxVersion: VersionTLS13,
7796 Bugs: ProtocolBugs{
7797 SendWrongMessageType: typeServerHello,
7798 },
7799 },
7800 shouldFail: true,
7801 expectedError: ":UNEXPECTED_MESSAGE:",
7802 // The alert comes in with the wrong encryption.
7803 expectedLocalError: "local error: bad record MAC",
7804 })
7805
7806 testCases = append(testCases, testCase{
7807 name: "WrongMessageType-TLS13-EncryptedExtensions",
7808 config: Config{
7809 MaxVersion: VersionTLS13,
7810 Bugs: ProtocolBugs{
7811 SendWrongMessageType: typeEncryptedExtensions,
7812 },
7813 },
7814 shouldFail: true,
7815 expectedError: ":UNEXPECTED_MESSAGE:",
7816 expectedLocalError: "remote error: unexpected message",
7817 })
7818
7819 testCases = append(testCases, testCase{
7820 name: "WrongMessageType-TLS13-CertificateRequest",
7821 config: Config{
7822 MaxVersion: VersionTLS13,
7823 ClientAuth: RequireAnyClientCert,
7824 Bugs: ProtocolBugs{
7825 SendWrongMessageType: typeCertificateRequest,
7826 },
7827 },
7828 shouldFail: true,
7829 expectedError: ":UNEXPECTED_MESSAGE:",
7830 expectedLocalError: "remote error: unexpected message",
7831 })
7832
7833 testCases = append(testCases, testCase{
7834 name: "WrongMessageType-TLS13-ServerCertificate",
7835 config: Config{
7836 MaxVersion: VersionTLS13,
7837 Bugs: ProtocolBugs{
7838 SendWrongMessageType: typeCertificate,
7839 },
7840 },
7841 shouldFail: true,
7842 expectedError: ":UNEXPECTED_MESSAGE:",
7843 expectedLocalError: "remote error: unexpected message",
7844 })
7845
7846 testCases = append(testCases, testCase{
7847 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7848 config: Config{
7849 MaxVersion: VersionTLS13,
7850 Bugs: ProtocolBugs{
7851 SendWrongMessageType: typeCertificateVerify,
7852 },
7853 },
7854 shouldFail: true,
7855 expectedError: ":UNEXPECTED_MESSAGE:",
7856 expectedLocalError: "remote error: unexpected message",
7857 })
7858
7859 testCases = append(testCases, testCase{
7860 name: "WrongMessageType-TLS13-ServerFinished",
7861 config: Config{
7862 MaxVersion: VersionTLS13,
7863 Bugs: ProtocolBugs{
7864 SendWrongMessageType: typeFinished,
7865 },
7866 },
7867 shouldFail: true,
7868 expectedError: ":UNEXPECTED_MESSAGE:",
7869 expectedLocalError: "remote error: unexpected message",
7870 })
7871
7872 testCases = append(testCases, testCase{
7873 testType: serverTest,
7874 name: "WrongMessageType-TLS13-ClientCertificate",
7875 config: Config{
7876 Certificates: []Certificate{rsaCertificate},
7877 MaxVersion: VersionTLS13,
7878 Bugs: ProtocolBugs{
7879 SendWrongMessageType: typeCertificate,
7880 },
7881 },
7882 flags: []string{"-require-any-client-certificate"},
7883 shouldFail: true,
7884 expectedError: ":UNEXPECTED_MESSAGE:",
7885 expectedLocalError: "remote error: unexpected message",
7886 })
7887
7888 testCases = append(testCases, testCase{
7889 testType: serverTest,
7890 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7891 config: Config{
7892 Certificates: []Certificate{rsaCertificate},
7893 MaxVersion: VersionTLS13,
7894 Bugs: ProtocolBugs{
7895 SendWrongMessageType: typeCertificateVerify,
7896 },
7897 },
7898 flags: []string{"-require-any-client-certificate"},
7899 shouldFail: true,
7900 expectedError: ":UNEXPECTED_MESSAGE:",
7901 expectedLocalError: "remote error: unexpected message",
7902 })
7903
7904 testCases = append(testCases, testCase{
7905 testType: serverTest,
7906 name: "WrongMessageType-TLS13-ClientFinished",
7907 config: Config{
7908 MaxVersion: VersionTLS13,
7909 Bugs: ProtocolBugs{
7910 SendWrongMessageType: typeFinished,
7911 },
7912 },
7913 shouldFail: true,
7914 expectedError: ":UNEXPECTED_MESSAGE:",
7915 expectedLocalError: "remote error: unexpected message",
7916 })
7917}
7918
7919func addTLS13HandshakeTests() {
7920 testCases = append(testCases, testCase{
7921 testType: clientTest,
7922 name: "MissingKeyShare-Client",
7923 config: Config{
7924 MaxVersion: VersionTLS13,
7925 Bugs: ProtocolBugs{
7926 MissingKeyShare: true,
7927 },
7928 },
7929 shouldFail: true,
7930 expectedError: ":MISSING_KEY_SHARE:",
7931 })
7932
7933 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007934 testType: serverTest,
7935 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007936 config: Config{
7937 MaxVersion: VersionTLS13,
7938 Bugs: ProtocolBugs{
7939 MissingKeyShare: true,
7940 },
7941 },
7942 shouldFail: true,
7943 expectedError: ":MISSING_KEY_SHARE:",
7944 })
7945
7946 testCases = append(testCases, testCase{
7947 testType: clientTest,
7948 name: "ClientHelloMissingKeyShare",
7949 config: Config{
7950 MaxVersion: VersionTLS13,
7951 Bugs: ProtocolBugs{
7952 MissingKeyShare: true,
7953 },
7954 },
7955 shouldFail: true,
7956 expectedError: ":MISSING_KEY_SHARE:",
7957 })
7958
7959 testCases = append(testCases, testCase{
7960 testType: clientTest,
7961 name: "MissingKeyShare",
7962 config: Config{
7963 MaxVersion: VersionTLS13,
7964 Bugs: ProtocolBugs{
7965 MissingKeyShare: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":MISSING_KEY_SHARE:",
7970 })
7971
7972 testCases = append(testCases, testCase{
7973 testType: serverTest,
7974 name: "DuplicateKeyShares",
7975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 Bugs: ProtocolBugs{
7978 DuplicateKeyShares: true,
7979 },
7980 },
7981 })
7982
7983 testCases = append(testCases, testCase{
7984 testType: clientTest,
7985 name: "EmptyEncryptedExtensions",
7986 config: Config{
7987 MaxVersion: VersionTLS13,
7988 Bugs: ProtocolBugs{
7989 EmptyEncryptedExtensions: true,
7990 },
7991 },
7992 shouldFail: true,
7993 expectedLocalError: "remote error: error decoding message",
7994 })
7995
7996 testCases = append(testCases, testCase{
7997 testType: clientTest,
7998 name: "EncryptedExtensionsWithKeyShare",
7999 config: Config{
8000 MaxVersion: VersionTLS13,
8001 Bugs: ProtocolBugs{
8002 EncryptedExtensionsWithKeyShare: true,
8003 },
8004 },
8005 shouldFail: true,
8006 expectedLocalError: "remote error: unsupported extension",
8007 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008008
8009 testCases = append(testCases, testCase{
8010 testType: serverTest,
8011 name: "SendHelloRetryRequest",
8012 config: Config{
8013 MaxVersion: VersionTLS13,
8014 // Require a HelloRetryRequest for every curve.
8015 DefaultCurves: []CurveID{},
8016 },
8017 expectedCurveID: CurveX25519,
8018 })
8019
8020 testCases = append(testCases, testCase{
8021 testType: serverTest,
8022 name: "SendHelloRetryRequest-2",
8023 config: Config{
8024 MaxVersion: VersionTLS13,
8025 DefaultCurves: []CurveID{CurveP384},
8026 },
8027 // Although the ClientHello did not predict our preferred curve,
8028 // we always select it whether it is predicted or not.
8029 expectedCurveID: CurveX25519,
8030 })
8031
8032 testCases = append(testCases, testCase{
8033 name: "UnknownCurve-HelloRetryRequest",
8034 config: Config{
8035 MaxVersion: VersionTLS13,
8036 // P-384 requires HelloRetryRequest in BoringSSL.
8037 CurvePreferences: []CurveID{CurveP384},
8038 Bugs: ProtocolBugs{
8039 SendHelloRetryRequestCurve: bogusCurve,
8040 },
8041 },
8042 shouldFail: true,
8043 expectedError: ":WRONG_CURVE:",
8044 })
8045
8046 testCases = append(testCases, testCase{
8047 name: "DisabledCurve-HelloRetryRequest",
8048 config: Config{
8049 MaxVersion: VersionTLS13,
8050 CurvePreferences: []CurveID{CurveP256},
8051 Bugs: ProtocolBugs{
8052 IgnorePeerCurvePreferences: true,
8053 },
8054 },
8055 flags: []string{"-p384-only"},
8056 shouldFail: true,
8057 expectedError: ":WRONG_CURVE:",
8058 })
8059
8060 testCases = append(testCases, testCase{
8061 name: "UnnecessaryHelloRetryRequest",
8062 config: Config{
8063 MaxVersion: VersionTLS13,
8064 Bugs: ProtocolBugs{
8065 UnnecessaryHelloRetryRequest: true,
8066 },
8067 },
8068 shouldFail: true,
8069 expectedError: ":WRONG_CURVE:",
8070 })
8071
8072 testCases = append(testCases, testCase{
8073 name: "SecondHelloRetryRequest",
8074 config: Config{
8075 MaxVersion: VersionTLS13,
8076 // P-384 requires HelloRetryRequest in BoringSSL.
8077 CurvePreferences: []CurveID{CurveP384},
8078 Bugs: ProtocolBugs{
8079 SecondHelloRetryRequest: true,
8080 },
8081 },
8082 shouldFail: true,
8083 expectedError: ":UNEXPECTED_MESSAGE:",
8084 })
8085
8086 testCases = append(testCases, testCase{
8087 testType: serverTest,
8088 name: "SecondClientHelloMissingKeyShare",
8089 config: Config{
8090 MaxVersion: VersionTLS13,
8091 DefaultCurves: []CurveID{},
8092 Bugs: ProtocolBugs{
8093 SecondClientHelloMissingKeyShare: true,
8094 },
8095 },
8096 shouldFail: true,
8097 expectedError: ":MISSING_KEY_SHARE:",
8098 })
8099
8100 testCases = append(testCases, testCase{
8101 testType: serverTest,
8102 name: "SecondClientHelloWrongCurve",
8103 config: Config{
8104 MaxVersion: VersionTLS13,
8105 DefaultCurves: []CurveID{},
8106 Bugs: ProtocolBugs{
8107 MisinterpretHelloRetryRequestCurve: CurveP521,
8108 },
8109 },
8110 shouldFail: true,
8111 expectedError: ":WRONG_CURVE:",
8112 })
8113
8114 testCases = append(testCases, testCase{
8115 name: "HelloRetryRequestVersionMismatch",
8116 config: Config{
8117 MaxVersion: VersionTLS13,
8118 // P-384 requires HelloRetryRequest in BoringSSL.
8119 CurvePreferences: []CurveID{CurveP384},
8120 Bugs: ProtocolBugs{
8121 SendServerHelloVersion: 0x0305,
8122 },
8123 },
8124 shouldFail: true,
8125 expectedError: ":WRONG_VERSION_NUMBER:",
8126 })
8127
8128 testCases = append(testCases, testCase{
8129 name: "HelloRetryRequestCurveMismatch",
8130 config: Config{
8131 MaxVersion: VersionTLS13,
8132 // P-384 requires HelloRetryRequest in BoringSSL.
8133 CurvePreferences: []CurveID{CurveP384},
8134 Bugs: ProtocolBugs{
8135 // Send P-384 (correct) in the HelloRetryRequest.
8136 SendHelloRetryRequestCurve: CurveP384,
8137 // But send P-256 in the ServerHello.
8138 SendCurve: CurveP256,
8139 },
8140 },
8141 shouldFail: true,
8142 expectedError: ":WRONG_CURVE:",
8143 })
8144
8145 // Test the server selecting a curve that requires a HelloRetryRequest
8146 // without sending it.
8147 testCases = append(testCases, testCase{
8148 name: "SkipHelloRetryRequest",
8149 config: Config{
8150 MaxVersion: VersionTLS13,
8151 // P-384 requires HelloRetryRequest in BoringSSL.
8152 CurvePreferences: []CurveID{CurveP384},
8153 Bugs: ProtocolBugs{
8154 SkipHelloRetryRequest: true,
8155 },
8156 },
8157 shouldFail: true,
8158 expectedError: ":WRONG_CURVE:",
8159 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008160
8161 testCases = append(testCases, testCase{
8162 name: "TLS13-RequestContextInHandshake",
8163 config: Config{
8164 MaxVersion: VersionTLS13,
8165 MinVersion: VersionTLS13,
8166 ClientAuth: RequireAnyClientCert,
8167 Bugs: ProtocolBugs{
8168 SendRequestContext: []byte("request context"),
8169 },
8170 },
8171 flags: []string{
8172 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8173 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8174 },
8175 shouldFail: true,
8176 expectedError: ":DECODE_ERROR:",
8177 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008178}
8179
Adam Langley7c803a62015-06-15 15:35:05 -07008180func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008181 defer wg.Done()
8182
8183 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008184 var err error
8185
8186 if *mallocTest < 0 {
8187 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008188 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008189 } else {
8190 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8191 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008192 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008193 if err != nil {
8194 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8195 }
8196 break
8197 }
8198 }
8199 }
Adam Langley95c29f32014-06-20 12:00:00 -07008200 statusChan <- statusMsg{test: test, err: err}
8201 }
8202}
8203
8204type statusMsg struct {
8205 test *testCase
8206 started bool
8207 err error
8208}
8209
David Benjamin5f237bc2015-02-11 17:14:15 -05008210func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008211 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008212
David Benjamin5f237bc2015-02-11 17:14:15 -05008213 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008214 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008215 if !*pipe {
8216 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008217 var erase string
8218 for i := 0; i < lineLen; i++ {
8219 erase += "\b \b"
8220 }
8221 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008222 }
8223
Adam Langley95c29f32014-06-20 12:00:00 -07008224 if msg.started {
8225 started++
8226 } else {
8227 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008228
8229 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008230 if msg.err == errUnimplemented {
8231 if *pipe {
8232 // Print each test instead of a status line.
8233 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8234 }
8235 unimplemented++
8236 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8237 } else {
8238 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8239 failed++
8240 testOutput.addResult(msg.test.name, "FAIL")
8241 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008242 } else {
8243 if *pipe {
8244 // Print each test instead of a status line.
8245 fmt.Printf("PASSED (%s)\n", msg.test.name)
8246 }
8247 testOutput.addResult(msg.test.name, "PASS")
8248 }
Adam Langley95c29f32014-06-20 12:00:00 -07008249 }
8250
David Benjamin5f237bc2015-02-11 17:14:15 -05008251 if !*pipe {
8252 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008253 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008254 lineLen = len(line)
8255 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008256 }
Adam Langley95c29f32014-06-20 12:00:00 -07008257 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008258
8259 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008260}
8261
8262func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008263 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008264 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008265 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008266
Adam Langley7c803a62015-06-15 15:35:05 -07008267 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008268 addCipherSuiteTests()
8269 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008270 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008271 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008272 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008273 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008274 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008275 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008276 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008277 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008278 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008279 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008280 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008281 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008282 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008283 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008284 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008285 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008286 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008287 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008288 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008289 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008290 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008291 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008292 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008293 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008294 addTLS13WrongMessageTypeTests()
8295 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008296
8297 var wg sync.WaitGroup
8298
Adam Langley7c803a62015-06-15 15:35:05 -07008299 statusChan := make(chan statusMsg, *numWorkers)
8300 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008301 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008302
EKRf71d7ed2016-08-06 13:25:12 -07008303 if len(*shimConfigFile) != 0 {
8304 encoded, err := ioutil.ReadFile(*shimConfigFile)
8305 if err != nil {
8306 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8307 os.Exit(1)
8308 }
8309
8310 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8311 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8312 os.Exit(1)
8313 }
8314 }
8315
David Benjamin025b3d32014-07-01 19:53:04 -04008316 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008317
Adam Langley7c803a62015-06-15 15:35:05 -07008318 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008319 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008320 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008321 }
8322
David Benjamin270f0a72016-03-17 14:41:36 -04008323 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008324 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008325 matched := true
8326 if len(*testToRun) != 0 {
8327 var err error
8328 matched, err = filepath.Match(*testToRun, testCases[i].name)
8329 if err != nil {
8330 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8331 os.Exit(1)
8332 }
8333 }
8334
EKRf71d7ed2016-08-06 13:25:12 -07008335 if !*includeDisabled {
8336 for pattern := range shimConfig.DisabledTests {
8337 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8338 if err != nil {
8339 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8340 os.Exit(1)
8341 }
8342
8343 if isDisabled {
8344 matched = false
8345 break
8346 }
8347 }
8348 }
8349
David Benjamin17e12922016-07-28 18:04:43 -04008350 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008351 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008352 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008353 }
8354 }
David Benjamin17e12922016-07-28 18:04:43 -04008355
David Benjamin270f0a72016-03-17 14:41:36 -04008356 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008357 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008358 os.Exit(1)
8359 }
Adam Langley95c29f32014-06-20 12:00:00 -07008360
8361 close(testChan)
8362 wg.Wait()
8363 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008364 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008365
8366 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008367
8368 if *jsonOutput != "" {
8369 if err := testOutput.writeTo(*jsonOutput); err != nil {
8370 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8371 }
8372 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008373
EKR842ae6c2016-07-27 09:22:05 +02008374 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8375 os.Exit(1)
8376 }
8377
8378 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008379 os.Exit(1)
8380 }
Adam Langley95c29f32014-06-20 12:00:00 -07008381}