blob: e2fe88562d06fcff31c562032e095a079e5ed8c5 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Matt Braithwaite9c8c4182016-08-24 14:36:54 -070065 includeRC4 = flag.Bool("include-rc4", false, "If true, test RC4 ciphersuites.")
Adam Langley69a01602014-11-17 17:26:55 -080066)
Adam Langley95c29f32014-06-20 12:00:00 -070067
EKRf71d7ed2016-08-06 13:25:12 -070068// ShimConfigurations is used with the “json” package and represents a shim
69// config file.
70type ShimConfiguration struct {
71 // DisabledTests maps from a glob-based pattern to a freeform string.
72 // The glob pattern is used to exclude tests from being run and the
73 // freeform string is unparsed but expected to explain why the test is
74 // disabled.
75 DisabledTests map[string]string
76
77 // ErrorMap maps from expected error strings to the correct error
78 // string for the shim in question. For example, it might map
79 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
80 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
81 ErrorMap map[string]string
82}
83
84var shimConfig ShimConfiguration
85
David Benjamin33863262016-07-08 17:20:12 -070086type testCert int
87
David Benjamin025b3d32014-07-01 19:53:04 -040088const (
David Benjamin33863262016-07-08 17:20:12 -070089 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040090 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070091 testCertECDSAP256
92 testCertECDSAP384
93 testCertECDSAP521
94)
95
96const (
97 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040098 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070099 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
100 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
101 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400102)
103
104const (
David Benjamina08e49d2014-08-24 01:46:07 -0400105 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400106 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700107 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
108 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
109 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400110 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400111)
112
David Benjamin7944a9f2016-07-12 22:27:01 -0400113var (
114 rsaCertificate Certificate
115 rsa1024Certificate Certificate
116 ecdsaP256Certificate Certificate
117 ecdsaP384Certificate Certificate
118 ecdsaP521Certificate Certificate
119)
David Benjamin33863262016-07-08 17:20:12 -0700120
121var testCerts = []struct {
122 id testCert
123 certFile, keyFile string
124 cert *Certificate
125}{
126 {
127 id: testCertRSA,
128 certFile: rsaCertificateFile,
129 keyFile: rsaKeyFile,
130 cert: &rsaCertificate,
131 },
132 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400133 id: testCertRSA1024,
134 certFile: rsa1024CertificateFile,
135 keyFile: rsa1024KeyFile,
136 cert: &rsa1024Certificate,
137 },
138 {
David Benjamin33863262016-07-08 17:20:12 -0700139 id: testCertECDSAP256,
140 certFile: ecdsaP256CertificateFile,
141 keyFile: ecdsaP256KeyFile,
142 cert: &ecdsaP256Certificate,
143 },
144 {
145 id: testCertECDSAP384,
146 certFile: ecdsaP384CertificateFile,
147 keyFile: ecdsaP384KeyFile,
148 cert: &ecdsaP384Certificate,
149 },
150 {
151 id: testCertECDSAP521,
152 certFile: ecdsaP521CertificateFile,
153 keyFile: ecdsaP521KeyFile,
154 cert: &ecdsaP521Certificate,
155 },
156}
157
David Benjamina08e49d2014-08-24 01:46:07 -0400158var channelIDKey *ecdsa.PrivateKey
159var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700160
David Benjamin61f95272014-11-25 01:55:35 -0500161var testOCSPResponse = []byte{1, 2, 3, 4}
162var testSCTList = []byte{5, 6, 7, 8}
163
Adam Langley95c29f32014-06-20 12:00:00 -0700164func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700165 for i := range testCerts {
166 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
167 if err != nil {
168 panic(err)
169 }
170 cert.OCSPStaple = testOCSPResponse
171 cert.SignedCertificateTimestampList = testSCTList
172 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700173 }
David Benjamina08e49d2014-08-24 01:46:07 -0400174
Adam Langley7c803a62015-06-15 15:35:05 -0700175 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400176 if err != nil {
177 panic(err)
178 }
179 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
180 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
181 panic("bad key type")
182 }
183 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
184 if err != nil {
185 panic(err)
186 }
187 if channelIDKey.Curve != elliptic.P256() {
188 panic("bad curve")
189 }
190
191 channelIDBytes = make([]byte, 64)
192 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
193 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700194}
195
David Benjamin33863262016-07-08 17:20:12 -0700196func getRunnerCertificate(t testCert) Certificate {
197 for _, cert := range testCerts {
198 if cert.id == t {
199 return *cert.cert
200 }
201 }
202 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700203}
204
David Benjamin33863262016-07-08 17:20:12 -0700205func getShimCertificate(t testCert) string {
206 for _, cert := range testCerts {
207 if cert.id == t {
208 return cert.certFile
209 }
210 }
211 panic("Unknown test certificate")
212}
213
214func getShimKey(t testCert) string {
215 for _, cert := range testCerts {
216 if cert.id == t {
217 return cert.keyFile
218 }
219 }
220 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700221}
222
David Benjamin025b3d32014-07-01 19:53:04 -0400223type testType int
224
225const (
226 clientTest testType = iota
227 serverTest
228)
229
David Benjamin6fd297b2014-08-11 18:43:38 -0400230type protocol int
231
232const (
233 tls protocol = iota
234 dtls
235)
236
David Benjaminfc7b0862014-09-06 13:21:53 -0400237const (
238 alpn = 1
239 npn = 2
240)
241
Adam Langley95c29f32014-06-20 12:00:00 -0700242type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400243 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400244 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700245 name string
246 config Config
247 shouldFail bool
248 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700249 // expectedLocalError, if not empty, contains a substring that must be
250 // found in the local error.
251 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400252 // expectedVersion, if non-zero, specifies the TLS version that must be
253 // negotiated.
254 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400255 // expectedResumeVersion, if non-zero, specifies the TLS version that
256 // must be negotiated on resumption. If zero, expectedVersion is used.
257 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400258 // expectedCipher, if non-zero, specifies the TLS cipher suite that
259 // should be negotiated.
260 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400261 // expectChannelID controls whether the connection should have
262 // negotiated a Channel ID with channelIDKey.
263 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400264 // expectedNextProto controls whether the connection should
265 // negotiate a next protocol via NPN or ALPN.
266 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400267 // expectNoNextProto, if true, means that no next protocol should be
268 // negotiated.
269 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400270 // expectedNextProtoType, if non-zero, is the expected next
271 // protocol negotiation mechanism.
272 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500273 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
274 // should be negotiated. If zero, none should be negotiated.
275 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100276 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
277 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100278 // expectedSCTList, if not nil, is the expected SCT list to be received.
279 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700280 // expectedPeerSignatureAlgorithm, if not zero, is the signature
281 // algorithm that the peer should have used in the handshake.
282 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400283 // expectedCurveID, if not zero, is the curve that the handshake should
284 // have used.
285 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700286 // messageLen is the length, in bytes, of the test message that will be
287 // sent.
288 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400289 // messageCount is the number of test messages that will be sent.
290 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400291 // certFile is the path to the certificate to use for the server.
292 certFile string
293 // keyFile is the path to the private key to use for the server.
294 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400295 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400296 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400297 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400298 // resumeRenewedSession controls whether a third connection should be
299 // tested which attempts to resume the second connection's session.
300 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700301 // expectResumeRejected, if true, specifies that the attempted
302 // resumption must be rejected by the client. This is only valid for a
303 // serverTest.
304 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400305 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500306 // resumption. Unless newSessionsOnResume is set,
307 // SessionTicketKey, ServerSessionCache, and
308 // ClientSessionCache are copied from the initial connection's
309 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400310 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500311 // newSessionsOnResume, if true, will cause resumeConfig to
312 // use a different session resumption context.
313 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400314 // noSessionCache, if true, will cause the server to run without a
315 // session cache.
316 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400317 // sendPrefix sends a prefix on the socket before actually performing a
318 // handshake.
319 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400320 // shimWritesFirst controls whether the shim sends an initial "hello"
321 // message before doing a roundtrip with the runner.
322 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400323 // shimShutsDown, if true, runs a test where the shim shuts down the
324 // connection immediately after the handshake rather than echoing
325 // messages from the runner.
326 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400327 // renegotiate indicates the number of times the connection should be
328 // renegotiated during the exchange.
329 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400330 // sendHalfHelloRequest, if true, causes the server to send half a
331 // HelloRequest when the handshake completes.
332 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700333 // renegotiateCiphers is a list of ciphersuite ids that will be
334 // switched in just before renegotiation.
335 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500336 // replayWrites, if true, configures the underlying transport
337 // to replay every write it makes in DTLS tests.
338 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500339 // damageFirstWrite, if true, configures the underlying transport to
340 // damage the final byte of the first application data write.
341 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400342 // exportKeyingMaterial, if non-zero, configures the test to exchange
343 // keying material and verify they match.
344 exportKeyingMaterial int
345 exportLabel string
346 exportContext string
347 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400348 // flags, if not empty, contains a list of command-line flags that will
349 // be passed to the shim program.
350 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700351 // testTLSUnique, if true, causes the shim to send the tls-unique value
352 // which will be compared against the expected value.
353 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400354 // sendEmptyRecords is the number of consecutive empty records to send
355 // before and after the test message.
356 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400357 // sendWarningAlerts is the number of consecutive warning alerts to send
358 // before and after the test message.
359 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400360 // sendKeyUpdates is the number of consecutive key updates to send
361 // before and after the test message.
362 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400363 // expectMessageDropped, if true, means the test message is expected to
364 // be dropped by the client rather than echoed back.
365 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700366}
367
Adam Langley7c803a62015-06-15 15:35:05 -0700368var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700369
David Benjamin9867b7d2016-03-01 23:25:48 -0500370func writeTranscript(test *testCase, isResume bool, data []byte) {
371 if len(data) == 0 {
372 return
373 }
374
375 protocol := "tls"
376 if test.protocol == dtls {
377 protocol = "dtls"
378 }
379
380 side := "client"
381 if test.testType == serverTest {
382 side = "server"
383 }
384
385 dir := path.Join(*transcriptDir, protocol, side)
386 if err := os.MkdirAll(dir, 0755); err != nil {
387 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
388 return
389 }
390
391 name := test.name
392 if isResume {
393 name += "-Resume"
394 } else {
395 name += "-Normal"
396 }
397
398 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
399 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
400 }
401}
402
David Benjamin3ed59772016-03-08 12:50:21 -0500403// A timeoutConn implements an idle timeout on each Read and Write operation.
404type timeoutConn struct {
405 net.Conn
406 timeout time.Duration
407}
408
409func (t *timeoutConn) Read(b []byte) (int, error) {
410 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Read(b)
414}
415
416func (t *timeoutConn) Write(b []byte) (int, error) {
417 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
418 return 0, err
419 }
420 return t.Conn.Write(b)
421}
422
David Benjamin8e6db492015-07-25 18:29:23 -0400423func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400424 if !test.noSessionCache {
425 if config.ClientSessionCache == nil {
426 config.ClientSessionCache = NewLRUClientSessionCache(1)
427 }
428 if config.ServerSessionCache == nil {
429 config.ServerSessionCache = NewLRUServerSessionCache(1)
430 }
431 }
432 if test.testType == clientTest {
433 if len(config.Certificates) == 0 {
434 config.Certificates = []Certificate{rsaCertificate}
435 }
436 } else {
437 // Supply a ServerName to ensure a constant session cache key,
438 // rather than falling back to net.Conn.RemoteAddr.
439 if len(config.ServerName) == 0 {
440 config.ServerName = "test"
441 }
442 }
443 if *fuzzer {
444 config.Bugs.NullAllCiphers = true
445 }
446 if *deterministic {
447 config.Rand = &deterministicRand{}
448 }
449
David Benjamin01784b42016-06-07 18:00:52 -0400450 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500451
David Benjamin6fd297b2014-08-11 18:43:38 -0400452 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500453 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
454 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500455 }
456
David Benjamin9867b7d2016-03-01 23:25:48 -0500457 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500458 local, peer := "client", "server"
459 if test.testType == clientTest {
460 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500461 }
David Benjaminebda9b32015-11-02 15:33:18 -0500462 connDebug := &recordingConn{
463 Conn: conn,
464 isDatagram: test.protocol == dtls,
465 local: local,
466 peer: peer,
467 }
468 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug {
470 defer connDebug.WriteTo(os.Stdout)
471 }
472 if len(*transcriptDir) != 0 {
473 defer func() {
474 writeTranscript(test, isResume, connDebug.Transcript())
475 }()
476 }
David Benjaminebda9b32015-11-02 15:33:18 -0500477
478 if config.Bugs.PacketAdaptor != nil {
479 config.Bugs.PacketAdaptor.debug = connDebug
480 }
481 }
482
483 if test.replayWrites {
484 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400485 }
486
David Benjamin3ed59772016-03-08 12:50:21 -0500487 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500488 if test.damageFirstWrite {
489 connDamage = newDamageAdaptor(conn)
490 conn = connDamage
491 }
492
David Benjamin6fd297b2014-08-11 18:43:38 -0400493 if test.sendPrefix != "" {
494 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
495 return err
496 }
David Benjamin98e882e2014-08-08 13:24:34 -0400497 }
498
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400500 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSServer(conn, config)
503 } else {
504 tlsConn = Server(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 } else {
507 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400508 if test.protocol == dtls {
509 tlsConn = DTLSClient(conn, config)
510 } else {
511 tlsConn = Client(conn, config)
512 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400513 }
David Benjamin30789da2015-08-29 22:56:45 -0400514 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400515
Adam Langley95c29f32014-06-20 12:00:00 -0700516 if err := tlsConn.Handshake(); err != nil {
517 return err
518 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700519
David Benjamin01fe8202014-09-24 15:21:44 -0400520 // TODO(davidben): move all per-connection expectations into a dedicated
521 // expectations struct that can be specified separately for the two
522 // legs.
523 expectedVersion := test.expectedVersion
524 if isResume && test.expectedResumeVersion != 0 {
525 expectedVersion = test.expectedResumeVersion
526 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700527 connState := tlsConn.ConnectionState()
528 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400529 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400530 }
531
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700532 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400533 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
534 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700535 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
536 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
537 }
David Benjamin90da8c82015-04-20 14:57:57 -0400538
David Benjamina08e49d2014-08-24 01:46:07 -0400539 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700540 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400541 if channelID == nil {
542 return fmt.Errorf("no channel ID negotiated")
543 }
544 if channelID.Curve != channelIDKey.Curve ||
545 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
546 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
547 return fmt.Errorf("incorrect channel ID")
548 }
549 }
550
David Benjaminae2888f2014-09-06 12:58:58 -0400551 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400553 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
554 }
555 }
556
David Benjaminc7ce9772015-10-09 19:32:41 -0400557 if test.expectNoNextProto {
558 if actual := connState.NegotiatedProtocol; actual != "" {
559 return fmt.Errorf("got unexpected next proto %s", actual)
560 }
561 }
562
David Benjaminfc7b0862014-09-06 13:21:53 -0400563 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400565 return fmt.Errorf("next proto type mismatch")
566 }
567 }
568
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700569 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500570 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
571 }
572
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100573 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300574 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100575 }
576
Paul Lietar4fac72e2015-09-09 13:44:55 +0100577 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
578 return fmt.Errorf("SCT list mismatch")
579 }
580
Nick Harper60edffd2016-06-21 15:19:24 -0700581 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
582 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400583 }
584
Steven Valdez5440fe02016-07-18 12:40:30 -0400585 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
586 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
587 }
588
David Benjaminc565ebb2015-04-03 04:06:36 -0400589 if test.exportKeyingMaterial > 0 {
590 actual := make([]byte, test.exportKeyingMaterial)
591 if _, err := io.ReadFull(tlsConn, actual); err != nil {
592 return err
593 }
594 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
595 if err != nil {
596 return err
597 }
598 if !bytes.Equal(actual, expected) {
599 return fmt.Errorf("keying material mismatch")
600 }
601 }
602
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700603 if test.testTLSUnique {
604 var peersValue [12]byte
605 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
606 return err
607 }
608 expected := tlsConn.ConnectionState().TLSUnique
609 if !bytes.Equal(peersValue[:], expected) {
610 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
611 }
612 }
613
David Benjamine58c4f52014-08-24 03:47:07 -0400614 if test.shimWritesFirst {
615 var buf [5]byte
616 _, err := io.ReadFull(tlsConn, buf[:])
617 if err != nil {
618 return err
619 }
620 if string(buf[:]) != "hello" {
621 return fmt.Errorf("bad initial message")
622 }
623 }
624
Steven Valdez32635b82016-08-16 11:25:03 -0400625 for i := 0; i < test.sendKeyUpdates; i++ {
626 tlsConn.SendKeyUpdate()
627 }
628
David Benjamina8ebe222015-06-06 03:04:39 -0400629 for i := 0; i < test.sendEmptyRecords; i++ {
630 tlsConn.Write(nil)
631 }
632
David Benjamin24f346d2015-06-06 03:28:08 -0400633 for i := 0; i < test.sendWarningAlerts; i++ {
634 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
635 }
636
David Benjamin47921102016-07-28 11:29:18 -0400637 if test.sendHalfHelloRequest {
638 tlsConn.SendHalfHelloRequest()
639 }
640
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 if test.renegotiateCiphers != nil {
643 config.CipherSuites = test.renegotiateCiphers
644 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400645 for i := 0; i < test.renegotiate; i++ {
646 if err := tlsConn.Renegotiate(); err != nil {
647 return err
648 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700649 }
650 } else if test.renegotiateCiphers != nil {
651 panic("renegotiateCiphers without renegotiate")
652 }
653
David Benjamin5fa3eba2015-01-22 16:35:40 -0500654 if test.damageFirstWrite {
655 connDamage.setDamage(true)
656 tlsConn.Write([]byte("DAMAGED WRITE"))
657 connDamage.setDamage(false)
658 }
659
David Benjamin8e6db492015-07-25 18:29:23 -0400660 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400662 if test.protocol == dtls {
663 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
664 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700665 // Read until EOF.
666 _, err := io.Copy(ioutil.Discard, tlsConn)
667 return err
668 }
David Benjamin4417d052015-04-05 04:17:25 -0400669 if messageLen == 0 {
670 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700671 }
Adam Langley95c29f32014-06-20 12:00:00 -0700672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 messageCount := test.messageCount
674 if messageCount == 0 {
675 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400676 }
677
David Benjamin8e6db492015-07-25 18:29:23 -0400678 for j := 0; j < messageCount; j++ {
679 testMessage := make([]byte, messageLen)
680 for i := range testMessage {
681 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400682 }
David Benjamin8e6db492015-07-25 18:29:23 -0400683 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700684
Steven Valdez32635b82016-08-16 11:25:03 -0400685 for i := 0; i < test.sendKeyUpdates; i++ {
686 tlsConn.SendKeyUpdate()
687 }
688
David Benjamin8e6db492015-07-25 18:29:23 -0400689 for i := 0; i < test.sendEmptyRecords; i++ {
690 tlsConn.Write(nil)
691 }
692
693 for i := 0; i < test.sendWarningAlerts; i++ {
694 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
695 }
696
David Benjamin4f75aaf2015-09-01 16:53:10 -0400697 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400698 // The shim will not respond.
699 continue
700 }
701
David Benjamin8e6db492015-07-25 18:29:23 -0400702 buf := make([]byte, len(testMessage))
703 if test.protocol == dtls {
704 bufTmp := make([]byte, len(buf)+1)
705 n, err := tlsConn.Read(bufTmp)
706 if err != nil {
707 return err
708 }
709 if n != len(buf) {
710 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
711 }
712 copy(buf, bufTmp)
713 } else {
714 _, err := io.ReadFull(tlsConn, buf)
715 if err != nil {
716 return err
717 }
718 }
719
720 for i, v := range buf {
721 if v != testMessage[i]^0xff {
722 return fmt.Errorf("bad reply contents at byte %d", i)
723 }
Adam Langley95c29f32014-06-20 12:00:00 -0700724 }
725 }
726
727 return nil
728}
729
David Benjamin325b5c32014-07-01 19:40:31 -0400730func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
731 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700732 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400733 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700734 }
David Benjamin325b5c32014-07-01 19:40:31 -0400735 valgrindArgs = append(valgrindArgs, path)
736 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700737
David Benjamin325b5c32014-07-01 19:40:31 -0400738 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700739}
740
David Benjamin325b5c32014-07-01 19:40:31 -0400741func gdbOf(path string, args ...string) *exec.Cmd {
742 xtermArgs := []string{"-e", "gdb", "--args"}
743 xtermArgs = append(xtermArgs, path)
744 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700745
David Benjamin325b5c32014-07-01 19:40:31 -0400746 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700747}
748
David Benjamind16bf342015-12-18 00:53:12 -0500749func lldbOf(path string, args ...string) *exec.Cmd {
750 xtermArgs := []string{"-e", "lldb", "--"}
751 xtermArgs = append(xtermArgs, path)
752 xtermArgs = append(xtermArgs, args...)
753
754 return exec.Command("xterm", xtermArgs...)
755}
756
EKR842ae6c2016-07-27 09:22:05 +0200757var (
758 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
759 errUnimplemented = errors.New("child process does not implement needed flags")
760)
Adam Langley69a01602014-11-17 17:26:55 -0800761
David Benjamin87c8a642015-02-21 01:54:29 -0500762// accept accepts a connection from listener, unless waitChan signals a process
763// exit first.
764func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
765 type connOrError struct {
766 conn net.Conn
767 err error
768 }
769 connChan := make(chan connOrError, 1)
770 go func() {
771 conn, err := listener.Accept()
772 connChan <- connOrError{conn, err}
773 close(connChan)
774 }()
775 select {
776 case result := <-connChan:
777 return result.conn, result.err
778 case childErr := <-waitChan:
779 waitChan <- childErr
780 return nil, fmt.Errorf("child exited early: %s", childErr)
781 }
782}
783
EKRf71d7ed2016-08-06 13:25:12 -0700784func translateExpectedError(errorStr string) string {
785 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
786 return translated
787 }
788
789 if *looseErrors {
790 return ""
791 }
792
793 return errorStr
794}
795
Adam Langley7c803a62015-06-15 15:35:05 -0700796func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700797 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
798 panic("Error expected without shouldFail in " + test.name)
799 }
800
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700801 if test.expectResumeRejected && !test.resumeSession {
802 panic("expectResumeRejected without resumeSession in " + test.name)
803 }
804
David Benjamin87c8a642015-02-21 01:54:29 -0500805 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
806 if err != nil {
807 panic(err)
808 }
809 defer func() {
810 if listener != nil {
811 listener.Close()
812 }
813 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700814
David Benjamin87c8a642015-02-21 01:54:29 -0500815 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400816 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400817 flags = append(flags, "-server")
818
David Benjamin025b3d32014-07-01 19:53:04 -0400819 flags = append(flags, "-key-file")
820 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825
826 flags = append(flags, "-cert-file")
827 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700828 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400829 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700830 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400831 }
832 }
David Benjamin5a593af2014-08-11 19:51:50 -0400833
David Benjamin6fd297b2014-08-11 18:43:38 -0400834 if test.protocol == dtls {
835 flags = append(flags, "-dtls")
836 }
837
David Benjamin46662482016-08-17 00:51:00 -0400838 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400839 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400840 resumeCount++
841 if test.resumeRenewedSession {
842 resumeCount++
843 }
844 }
845
846 if resumeCount > 0 {
847 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400848 }
849
David Benjamine58c4f52014-08-24 03:47:07 -0400850 if test.shimWritesFirst {
851 flags = append(flags, "-shim-writes-first")
852 }
853
David Benjamin30789da2015-08-29 22:56:45 -0400854 if test.shimShutsDown {
855 flags = append(flags, "-shim-shuts-down")
856 }
857
David Benjaminc565ebb2015-04-03 04:06:36 -0400858 if test.exportKeyingMaterial > 0 {
859 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
860 flags = append(flags, "-export-label", test.exportLabel)
861 flags = append(flags, "-export-context", test.exportContext)
862 if test.useExportContext {
863 flags = append(flags, "-use-export-context")
864 }
865 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700866 if test.expectResumeRejected {
867 flags = append(flags, "-expect-session-miss")
868 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400869
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700870 if test.testTLSUnique {
871 flags = append(flags, "-tls-unique")
872 }
873
David Benjamin025b3d32014-07-01 19:53:04 -0400874 flags = append(flags, test.flags...)
875
876 var shim *exec.Cmd
877 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700878 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700879 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500881 } else if *useLLDB {
882 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400883 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700884 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400885 }
David Benjamin025b3d32014-07-01 19:53:04 -0400886 shim.Stdin = os.Stdin
887 var stdoutBuf, stderrBuf bytes.Buffer
888 shim.Stdout = &stdoutBuf
889 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800890 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500891 shim.Env = os.Environ()
892 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800893 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400894 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800895 }
896 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
897 }
David Benjamin025b3d32014-07-01 19:53:04 -0400898
899 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700900 panic(err)
901 }
David Benjamin87c8a642015-02-21 01:54:29 -0500902 waitChan := make(chan error, 1)
903 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700904
905 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800940 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200941 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
942 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800943 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200944 case 89:
945 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjaminc565ebb2015-04-03 04:06:36 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjaminff3a1492016-03-02 10:12:06 -0500994 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
998 return nil
999}
1000
1001var tlsVersions = []struct {
1002 name string
1003 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001004 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001005 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001006}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001007 {"SSL3", VersionSSL30, "-no-ssl3", false},
1008 {"TLS1", VersionTLS10, "-no-tls1", true},
1009 {"TLS11", VersionTLS11, "-no-tls11", false},
1010 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001011 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001012}
1013
1014var testCipherSuites = []struct {
1015 name string
1016 id uint16
1017}{
1018 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001019 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001020 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001021 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001022 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001023 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001024 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001025 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1026 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001027 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001028 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1029 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001031 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1032 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1034 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001036 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001038 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001040 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001046 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001047 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1048 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1049 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1050 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001051 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1052 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001053 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1054 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001055 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001056 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1057 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001058 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001059}
1060
David Benjamin8b8c0062014-11-23 02:47:52 -05001061func hasComponent(suiteName, component string) bool {
1062 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1063}
1064
David Benjaminf7768e42014-08-31 02:06:47 -04001065func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001066 return hasComponent(suiteName, "GCM") ||
1067 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001068 hasComponent(suiteName, "SHA384") ||
1069 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001070}
1071
Nick Harper1fd39d82016-06-14 18:14:35 -07001072func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001073 // Only AEADs.
1074 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1075 return false
1076 }
1077 // No old CHACHA20_POLY1305.
1078 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1079 return false
1080 }
1081 // Must have ECDHE.
1082 // TODO(davidben,svaldez): Add pure PSK support.
1083 if !hasComponent(suiteName, "ECDHE") {
1084 return false
1085 }
1086 // TODO(davidben,svaldez): Add PSK support.
1087 if hasComponent(suiteName, "PSK") {
1088 return false
1089 }
1090 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001091}
1092
David Benjamin8b8c0062014-11-23 02:47:52 -05001093func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001094 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001095}
1096
Adam Langleya7997f12015-05-14 17:38:50 -07001097func bigFromHex(hex string) *big.Int {
1098 ret, ok := new(big.Int).SetString(hex, 16)
1099 if !ok {
1100 panic("failed to parse hex number 0x" + hex)
1101 }
1102 return ret
1103}
1104
Adam Langley7c803a62015-06-15 15:35:05 -07001105func addBasicTests() {
1106 basicTests := []testCase{
1107 {
Adam Langley7c803a62015-06-15 15:35:05 -07001108 name: "NoFallbackSCSV",
1109 config: Config{
1110 Bugs: ProtocolBugs{
1111 FailIfNotFallbackSCSV: true,
1112 },
1113 },
1114 shouldFail: true,
1115 expectedLocalError: "no fallback SCSV found",
1116 },
1117 {
1118 name: "SendFallbackSCSV",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 FailIfNotFallbackSCSV: true,
1122 },
1123 },
1124 flags: []string{"-fallback-scsv"},
1125 },
1126 {
1127 name: "ClientCertificateTypes",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 ClientAuth: RequestClientCert,
1131 ClientCertificateTypes: []byte{
1132 CertTypeDSSSign,
1133 CertTypeRSASign,
1134 CertTypeECDSASign,
1135 },
1136 },
1137 flags: []string{
1138 "-expect-certificate-types",
1139 base64.StdEncoding.EncodeToString([]byte{
1140 CertTypeDSSSign,
1141 CertTypeRSASign,
1142 CertTypeECDSASign,
1143 }),
1144 },
1145 },
1146 {
Adam Langley7c803a62015-06-15 15:35:05 -07001147 name: "UnauthenticatedECDH",
1148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001149 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1151 Bugs: ProtocolBugs{
1152 UnauthenticatedECDH: true,
1153 },
1154 },
1155 shouldFail: true,
1156 expectedError: ":UNEXPECTED_MESSAGE:",
1157 },
1158 {
1159 name: "SkipCertificateStatus",
1160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1163 Bugs: ProtocolBugs{
1164 SkipCertificateStatus: true,
1165 },
1166 },
1167 flags: []string{
1168 "-enable-ocsp-stapling",
1169 },
1170 },
1171 {
1172 name: "SkipServerKeyExchange",
1173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1176 Bugs: ProtocolBugs{
1177 SkipServerKeyExchange: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedError: ":UNEXPECTED_MESSAGE:",
1182 },
1183 {
Adam Langley7c803a62015-06-15 15:35:05 -07001184 testType: serverTest,
1185 name: "Alert",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "Alert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendSpuriousAlert: alertRecordOverflow,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1205 },
1206 {
1207 testType: serverTest,
1208 name: "FragmentAlert",
1209 config: Config{
1210 Bugs: ProtocolBugs{
1211 FragmentAlert: true,
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":BAD_ALERT:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "FragmentAlert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 FragmentAlert: true,
1225 SendSpuriousAlert: alertRecordOverflow,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":BAD_ALERT:",
1230 },
1231 {
1232 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001233 name: "DoubleAlert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 DoubleAlert: true,
1237 SendSpuriousAlert: alertRecordOverflow,
1238 },
1239 },
1240 shouldFail: true,
1241 expectedError: ":BAD_ALERT:",
1242 },
1243 {
1244 protocol: dtls,
1245 testType: serverTest,
1246 name: "DoubleAlert-DTLS",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 DoubleAlert: true,
1250 SendSpuriousAlert: alertRecordOverflow,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":BAD_ALERT:",
1255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "SkipNewSessionTicket",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 Bugs: ProtocolBugs{
1261 SkipNewSessionTicket: true,
1262 },
1263 },
1264 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001265 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001266 },
1267 {
1268 testType: serverTest,
1269 name: "FallbackSCSV",
1270 config: Config{
1271 MaxVersion: VersionTLS11,
1272 Bugs: ProtocolBugs{
1273 SendFallbackSCSV: true,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":INAPPROPRIATE_FALLBACK:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "FallbackSCSV-VersionMatch",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 },
1288 {
1289 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 name: "FallbackSCSV-VersionMatch-TLS12",
1291 config: Config{
1292 MaxVersion: VersionTLS12,
1293 Bugs: ProtocolBugs{
1294 SendFallbackSCSV: true,
1295 },
1296 },
1297 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1298 },
1299 {
1300 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001308 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 testType: serverTest,
1312 name: "HttpGET",
1313 sendPrefix: "GET / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpPOST",
1320 sendPrefix: "POST / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpHEAD",
1327 sendPrefix: "HEAD / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpPUT",
1334 sendPrefix: "PUT / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpCONNECT",
1341 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTPS_PROXY_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "Garbage",
1348 sendPrefix: "blah",
1349 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001350 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 name: "RSAEphemeralKey",
1354 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001355 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1357 Bugs: ProtocolBugs{
1358 RSAEphemeralKey: true,
1359 },
1360 },
1361 shouldFail: true,
1362 expectedError: ":UNEXPECTED_MESSAGE:",
1363 },
1364 {
1365 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001366 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
1371 protocol: dtls,
1372 name: "DisableEverything-DTLS",
1373 flags: []string{"-no-tls12", "-no-tls1"},
1374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
Adam Langley7c803a62015-06-15 15:35:05 -07001378 protocol: dtls,
1379 testType: serverTest,
1380 name: "MTU",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 MaxPacketLength: 256,
1384 },
1385 },
1386 flags: []string{"-mtu", "256"},
1387 },
1388 {
1389 protocol: dtls,
1390 testType: serverTest,
1391 name: "MTUExceeded",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 MaxPacketLength: 255,
1395 },
1396 },
1397 flags: []string{"-mtu", "256"},
1398 shouldFail: true,
1399 expectedLocalError: "dtls: exceeded maximum packet length",
1400 },
1401 {
1402 name: "CertMismatchRSA",
1403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001406 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 Bugs: ProtocolBugs{
1408 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1413 },
1414 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001415 name: "CertMismatchRSA-TLS13",
1416 config: Config{
1417 MaxVersion: VersionTLS13,
1418 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1419 Certificates: []Certificate{ecdsaP256Certificate},
1420 Bugs: ProtocolBugs{
1421 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1422 },
1423 },
1424 shouldFail: true,
1425 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1426 },
1427 {
Adam Langley7c803a62015-06-15 15:35:05 -07001428 name: "CertMismatchECDSA",
1429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001432 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001433 Bugs: ProtocolBugs{
1434 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1439 },
1440 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001441 name: "CertMismatchECDSA-TLS13",
1442 config: Config{
1443 MaxVersion: VersionTLS13,
1444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Certificates: []Certificate{rsaCertificate},
1446 Bugs: ProtocolBugs{
1447 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1452 },
1453 {
Adam Langley7c803a62015-06-15 15:35:05 -07001454 name: "EmptyCertificateList",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 EmptyCertificateList: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":DECODE_ERROR:",
1464 },
1465 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 name: "EmptyCertificateList-TLS13",
1467 config: Config{
1468 MaxVersion: VersionTLS13,
1469 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1470 Bugs: ProtocolBugs{
1471 EmptyCertificateList: true,
1472 },
1473 },
1474 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001476 },
1477 {
Adam Langley7c803a62015-06-15 15:35:05 -07001478 name: "TLSFatalBadPackets",
1479 damageFirstWrite: true,
1480 shouldFail: true,
1481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets",
1486 damageFirstWrite: true,
1487 },
1488 {
1489 protocol: dtls,
1490 name: "DTLSIgnoreBadPackets-Async",
1491 damageFirstWrite: true,
1492 flags: []string{"-async"},
1493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataBeforeHandshake",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
1505 name: "AppDataBeforeHandshake-Empty",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 AppDataBeforeHandshake: []byte{},
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AppDataBeforeHandshake-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 protocol: dtls,
1527 name: "AppDataBeforeHandshake-DTLS-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
Adam Langley7c803a62015-06-15 15:35:05 -07001537 name: "AppDataAfterChangeCipherSpec",
1538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001539 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001540 Bugs: ProtocolBugs{
1541 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001545 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001546 },
1547 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 name: "AppDataAfterChangeCipherSpec-Empty",
1549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001550 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001551 Bugs: ProtocolBugs{
1552 AppDataAfterChangeCipherSpec: []byte{},
1553 },
1554 },
1555 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001556 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 name: "AppDataAfterChangeCipherSpec-DTLS",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1565 },
1566 },
1567 // BoringSSL's DTLS implementation will drop the out-of-order
1568 // application data.
1569 },
1570 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte{},
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "AlertAfterChangeCipherSpec",
1584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 AlertAfterChangeCipherSpec: alertRecordOverflow,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1592 },
1593 {
1594 protocol: dtls,
1595 name: "AlertAfterChangeCipherSpec-DTLS",
1596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 Bugs: ProtocolBugs{
1599 AlertAfterChangeCipherSpec: alertRecordOverflow,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "ReorderHandshakeFragments-Small-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 ReorderHandshakeFragments: true,
1611 // Small enough that every handshake message is
1612 // fragmented.
1613 MaxHandshakeRecordLength: 2,
1614 },
1615 },
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Large-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Large enough that no handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2048,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "MixCompleteMessageWithFragments-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 MixCompleteMessageWithFragments: true,
1636 MaxHandshakeRecordLength: 2,
1637 },
1638 },
1639 },
1640 {
1641 name: "SendInvalidRecordType",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "SendInvalidRecordType-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 SendInvalidRecordType: true,
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
1662 name: "FalseStart-SkipServerSecondLeg",
1663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 SkipNewSessionTicket: true,
1669 SkipChangeCipherSpec: true,
1670 SkipFinished: true,
1671 ExpectFalseStart: true,
1672 },
1673 },
1674 flags: []string{
1675 "-false-start",
1676 "-handshake-never-done",
1677 "-advertise-alpn", "\x03foo",
1678 },
1679 shimWritesFirst: true,
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg-Implicit",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 },
1694 },
1695 flags: []string{
1696 "-implicit-handshake",
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shouldFail: true,
1702 expectedError: ":UNEXPECTED_RECORD:",
1703 },
1704 {
1705 testType: serverTest,
1706 name: "FailEarlyCallback",
1707 flags: []string{"-fail-early-callback"},
1708 shouldFail: true,
1709 expectedError: ":CONNECTION_REJECTED:",
1710 expectedLocalError: "remote error: access denied",
1711 },
1712 {
Adam Langley7c803a62015-06-15 15:35:05 -07001713 protocol: dtls,
1714 name: "FragmentMessageTypeMismatch-DTLS",
1715 config: Config{
1716 Bugs: ProtocolBugs{
1717 MaxHandshakeRecordLength: 2,
1718 FragmentMessageTypeMismatch: true,
1719 },
1720 },
1721 shouldFail: true,
1722 expectedError: ":FRAGMENT_MISMATCH:",
1723 },
1724 {
1725 protocol: dtls,
1726 name: "FragmentMessageLengthMismatch-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 MaxHandshakeRecordLength: 2,
1730 FragmentMessageLengthMismatch: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":FRAGMENT_MISMATCH:",
1735 },
1736 {
1737 protocol: dtls,
1738 name: "SplitFragments-Header-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 SplitFragments: 2,
1742 },
1743 },
1744 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001745 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001746 },
1747 {
1748 protocol: dtls,
1749 name: "SplitFragments-Boundary-DTLS",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 SplitFragments: dtlsRecordHeaderLen,
1753 },
1754 },
1755 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001756 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001757 },
1758 {
1759 protocol: dtls,
1760 name: "SplitFragments-Body-DTLS",
1761 config: Config{
1762 Bugs: ProtocolBugs{
1763 SplitFragments: dtlsRecordHeaderLen + 1,
1764 },
1765 },
1766 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001767 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 {
1770 protocol: dtls,
1771 name: "SendEmptyFragments-DTLS",
1772 config: Config{
1773 Bugs: ProtocolBugs{
1774 SendEmptyFragments: true,
1775 },
1776 },
1777 },
1778 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001779 name: "BadFinished-Client",
1780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001781 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 Bugs: ProtocolBugs{
1783 BadFinished: true,
1784 },
1785 },
1786 shouldFail: true,
1787 expectedError: ":DIGEST_CHECK_FAILED:",
1788 },
1789 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001790 name: "BadFinished-Client-TLS13",
1791 config: Config{
1792 MaxVersion: VersionTLS13,
1793 Bugs: ProtocolBugs{
1794 BadFinished: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":DIGEST_CHECK_FAILED:",
1799 },
1800 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001801 testType: serverTest,
1802 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 BadFinished: true,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":DIGEST_CHECK_FAILED:",
1811 },
1812 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001813 testType: serverTest,
1814 name: "BadFinished-Server-TLS13",
1815 config: Config{
1816 MaxVersion: VersionTLS13,
1817 Bugs: ProtocolBugs{
1818 BadFinished: true,
1819 },
1820 },
1821 shouldFail: true,
1822 expectedError: ":DIGEST_CHECK_FAILED:",
1823 },
1824 {
Adam Langley7c803a62015-06-15 15:35:05 -07001825 name: "FalseStart-BadFinished",
1826 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001827 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1829 NextProtos: []string{"foo"},
1830 Bugs: ProtocolBugs{
1831 BadFinished: true,
1832 ExpectFalseStart: true,
1833 },
1834 },
1835 flags: []string{
1836 "-false-start",
1837 "-handshake-never-done",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
1845 name: "NoFalseStart-NoALPN",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1849 Bugs: ProtocolBugs{
1850 ExpectFalseStart: true,
1851 AlertBeforeFalseStartTest: alertAccessDenied,
1852 },
1853 },
1854 flags: []string{
1855 "-false-start",
1856 },
1857 shimWritesFirst: true,
1858 shouldFail: true,
1859 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1860 expectedLocalError: "tls: peer did not false start: EOF",
1861 },
1862 {
1863 name: "NoFalseStart-NoAEAD",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 ExpectFalseStart: true,
1870 AlertBeforeFalseStartTest: alertAccessDenied,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-advertise-alpn", "\x03foo",
1876 },
1877 shimWritesFirst: true,
1878 shouldFail: true,
1879 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1880 expectedLocalError: "tls: peer did not false start: EOF",
1881 },
1882 {
1883 name: "NoFalseStart-RSA",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1887 NextProtos: []string{"foo"},
1888 Bugs: ProtocolBugs{
1889 ExpectFalseStart: true,
1890 AlertBeforeFalseStartTest: alertAccessDenied,
1891 },
1892 },
1893 flags: []string{
1894 "-false-start",
1895 "-advertise-alpn", "\x03foo",
1896 },
1897 shimWritesFirst: true,
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1900 expectedLocalError: "tls: peer did not false start: EOF",
1901 },
1902 {
1903 name: "NoFalseStart-DHE_RSA",
1904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001905 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001906 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1907 NextProtos: []string{"foo"},
1908 Bugs: ProtocolBugs{
1909 ExpectFalseStart: true,
1910 AlertBeforeFalseStartTest: alertAccessDenied,
1911 },
1912 },
1913 flags: []string{
1914 "-false-start",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1920 expectedLocalError: "tls: peer did not false start: EOF",
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 protocol: dtls,
1924 name: "SendSplitAlert-Sync",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 SendSplitAlert: true,
1928 },
1929 },
1930 },
1931 {
1932 protocol: dtls,
1933 name: "SendSplitAlert-Async",
1934 config: Config{
1935 Bugs: ProtocolBugs{
1936 SendSplitAlert: true,
1937 },
1938 },
1939 flags: []string{"-async"},
1940 },
1941 {
1942 protocol: dtls,
1943 name: "PackDTLSHandshake",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 MaxHandshakeRecordLength: 2,
1947 PackHandshakeFragments: 20,
1948 PackHandshakeRecords: 200,
1949 },
1950 },
1951 },
1952 {
Adam Langley7c803a62015-06-15 15:35:05 -07001953 name: "SendEmptyRecords-Pass",
1954 sendEmptyRecords: 32,
1955 },
1956 {
1957 name: "SendEmptyRecords",
1958 sendEmptyRecords: 33,
1959 shouldFail: true,
1960 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1961 },
1962 {
1963 name: "SendEmptyRecords-Async",
1964 sendEmptyRecords: 33,
1965 flags: []string{"-async"},
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
David Benjamine8e84b92016-08-03 15:39:47 -04001970 name: "SendWarningAlerts-Pass",
1971 config: Config{
1972 MaxVersion: VersionTLS12,
1973 },
Adam Langley7c803a62015-06-15 15:35:05 -07001974 sendWarningAlerts: 4,
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 protocol: dtls,
1978 name: "SendWarningAlerts-DTLS-Pass",
1979 config: Config{
1980 MaxVersion: VersionTLS12,
1981 },
Adam Langley7c803a62015-06-15 15:35:05 -07001982 sendWarningAlerts: 4,
1983 },
1984 {
David Benjamine8e84b92016-08-03 15:39:47 -04001985 name: "SendWarningAlerts-TLS13",
1986 config: Config{
1987 MaxVersion: VersionTLS13,
1988 },
1989 sendWarningAlerts: 4,
1990 shouldFail: true,
1991 expectedError: ":BAD_ALERT:",
1992 expectedLocalError: "remote error: error decoding message",
1993 },
1994 {
1995 name: "SendWarningAlerts",
1996 config: Config{
1997 MaxVersion: VersionTLS12,
1998 },
Adam Langley7c803a62015-06-15 15:35:05 -07001999 sendWarningAlerts: 5,
2000 shouldFail: true,
2001 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2002 },
2003 {
David Benjamine8e84b92016-08-03 15:39:47 -04002004 name: "SendWarningAlerts-Async",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
Adam Langley7c803a62015-06-15 15:35:05 -07002008 sendWarningAlerts: 5,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2012 },
David Benjaminba4594a2015-06-18 18:36:15 -04002013 {
Steven Valdez32635b82016-08-16 11:25:03 -04002014 name: "SendKeyUpdates",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 },
2018 sendKeyUpdates: 33,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_KEY_UPDATES:",
2021 },
2022 {
David Benjaminba4594a2015-06-18 18:36:15 -04002023 name: "EmptySessionID",
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002026 SessionTicketsDisabled: true,
2027 },
2028 noSessionCache: true,
2029 flags: []string{"-expect-no-session"},
2030 },
David Benjamin30789da2015-08-29 22:56:45 -04002031 {
2032 name: "Unclean-Shutdown",
2033 config: Config{
2034 Bugs: ProtocolBugs{
2035 NoCloseNotify: true,
2036 ExpectCloseNotify: true,
2037 },
2038 },
2039 shimShutsDown: true,
2040 flags: []string{"-check-close-notify"},
2041 shouldFail: true,
2042 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2043 },
2044 {
2045 name: "Unclean-Shutdown-Ignored",
2046 config: Config{
2047 Bugs: ProtocolBugs{
2048 NoCloseNotify: true,
2049 },
2050 },
2051 shimShutsDown: true,
2052 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002053 {
David Benjaminfa214e42016-05-10 17:03:10 -04002054 name: "Unclean-Shutdown-Alert",
2055 config: Config{
2056 Bugs: ProtocolBugs{
2057 SendAlertOnShutdown: alertDecompressionFailure,
2058 ExpectCloseNotify: true,
2059 },
2060 },
2061 shimShutsDown: true,
2062 flags: []string{"-check-close-notify"},
2063 shouldFail: true,
2064 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2065 },
2066 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002067 name: "LargePlaintext",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 SendLargeRecords: true,
2071 },
2072 },
2073 messageLen: maxPlaintext + 1,
2074 shouldFail: true,
2075 expectedError: ":DATA_LENGTH_TOO_LONG:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "LargePlaintext-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SendLargeRecords: true,
2083 },
2084 },
2085 messageLen: maxPlaintext + 1,
2086 shouldFail: true,
2087 expectedError: ":DATA_LENGTH_TOO_LONG:",
2088 },
2089 {
2090 name: "LargeCiphertext",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SendLargeRecords: true,
2094 },
2095 },
2096 messageLen: maxPlaintext * 2,
2097 shouldFail: true,
2098 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2099 },
2100 {
2101 protocol: dtls,
2102 name: "LargeCiphertext-DTLS",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendLargeRecords: true,
2106 },
2107 },
2108 messageLen: maxPlaintext * 2,
2109 // Unlike the other four cases, DTLS drops records which
2110 // are invalid before authentication, so the connection
2111 // does not fail.
2112 expectMessageDropped: true,
2113 },
David Benjamindd6fed92015-10-23 17:41:12 -04002114 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 // In TLS 1.2 and below, empty NewSessionTicket messages
2116 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002117 name: "SendEmptySessionTicket",
2118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002120 Bugs: ProtocolBugs{
2121 SendEmptySessionTicket: true,
2122 FailIfSessionOffered: true,
2123 },
2124 },
David Benjamin46662482016-08-17 00:51:00 -04002125 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002126 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002127 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002128 name: "BadHelloRequest-1",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002141 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002142 },
2143 {
2144 name: "BadHelloRequest-2",
2145 renegotiate: 1,
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002148 Bugs: ProtocolBugs{
2149 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2150 },
2151 },
2152 flags: []string{
2153 "-renegotiate-freely",
2154 "-expect-total-renegotiations", "1",
2155 },
2156 shouldFail: true,
2157 expectedError: ":BAD_HELLO_REQUEST:",
2158 },
David Benjaminef1b0092015-11-21 14:05:44 -05002159 {
2160 testType: serverTest,
2161 name: "SupportTicketsWithSessionID",
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002164 SessionTicketsDisabled: true,
2165 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002166 resumeConfig: &Config{
2167 MaxVersion: VersionTLS12,
2168 },
David Benjaminef1b0092015-11-21 14:05:44 -05002169 resumeSession: true,
2170 },
David Benjamin02edcd02016-07-27 17:40:37 -04002171 {
2172 protocol: dtls,
2173 name: "DTLS-SendExtraFinished",
2174 config: Config{
2175 Bugs: ProtocolBugs{
2176 SendExtraFinished: true,
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":UNEXPECTED_RECORD:",
2181 },
2182 {
2183 protocol: dtls,
2184 name: "DTLS-SendExtraFinished-Reordered",
2185 config: Config{
2186 Bugs: ProtocolBugs{
2187 MaxHandshakeRecordLength: 2,
2188 ReorderHandshakeFragments: true,
2189 SendExtraFinished: true,
2190 },
2191 },
2192 shouldFail: true,
2193 expectedError: ":UNEXPECTED_RECORD:",
2194 },
David Benjamine97fb482016-07-29 09:23:07 -04002195 {
2196 testType: serverTest,
2197 name: "V2ClientHello-EmptyRecordPrefix",
2198 config: Config{
2199 // Choose a cipher suite that does not involve
2200 // elliptic curves, so no extensions are
2201 // involved.
2202 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002203 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002204 Bugs: ProtocolBugs{
2205 SendV2ClientHello: true,
2206 },
2207 },
2208 sendPrefix: string([]byte{
2209 byte(recordTypeHandshake),
2210 3, 1, // version
2211 0, 0, // length
2212 }),
2213 // A no-op empty record may not be sent before V2ClientHello.
2214 shouldFail: true,
2215 expectedError: ":WRONG_VERSION_NUMBER:",
2216 },
2217 {
2218 testType: serverTest,
2219 name: "V2ClientHello-WarningAlertPrefix",
2220 config: Config{
2221 // Choose a cipher suite that does not involve
2222 // elliptic curves, so no extensions are
2223 // involved.
2224 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002225 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002226 Bugs: ProtocolBugs{
2227 SendV2ClientHello: true,
2228 },
2229 },
2230 sendPrefix: string([]byte{
2231 byte(recordTypeAlert),
2232 3, 1, // version
2233 0, 2, // length
2234 alertLevelWarning, byte(alertDecompressionFailure),
2235 }),
2236 // A no-op warning alert may not be sent before V2ClientHello.
2237 shouldFail: true,
2238 expectedError: ":WRONG_VERSION_NUMBER:",
2239 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002240 {
2241 testType: clientTest,
2242 name: "KeyUpdate",
2243 config: Config{
2244 MaxVersion: VersionTLS13,
2245 Bugs: ProtocolBugs{
2246 SendKeyUpdateBeforeEveryAppDataRecord: true,
2247 },
2248 },
2249 },
Adam Langley7c803a62015-06-15 15:35:05 -07002250 }
Adam Langley7c803a62015-06-15 15:35:05 -07002251 testCases = append(testCases, basicTests...)
2252}
2253
Adam Langley95c29f32014-06-20 12:00:00 -07002254func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002255 const bogusCipher = 0xfe00
2256
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002257 if *includeRC4 {
2258 testCipherSuites = append(testCipherSuites, []struct {
2259 name string
2260 id uint16
2261 }{
2262 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
2263 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2264 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
2265 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
2266 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
2267 }...)
2268 }
2269
Adam Langley95c29f32014-06-20 12:00:00 -07002270 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002271 const psk = "12345"
2272 const pskIdentity = "luggage combo"
2273
Adam Langley95c29f32014-06-20 12:00:00 -07002274 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002275 var certFile string
2276 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002277 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002278 cert = ecdsaP256Certificate
2279 certFile = ecdsaP256CertificateFile
2280 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002281 } else {
David Benjamin33863262016-07-08 17:20:12 -07002282 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002283 certFile = rsaCertificateFile
2284 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002285 }
2286
David Benjamin48cae082014-10-27 01:06:24 -04002287 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002288 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002289 flags = append(flags,
2290 "-psk", psk,
2291 "-psk-identity", pskIdentity)
2292 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002293 if hasComponent(suite.name, "NULL") {
2294 // NULL ciphers must be explicitly enabled.
2295 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2296 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002297 if hasComponent(suite.name, "CECPQ1") {
2298 // CECPQ1 ciphers must be explicitly enabled.
2299 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2300 }
David Benjamin881f1962016-08-10 18:29:12 -04002301 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2302 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2303 // for now.
2304 flags = append(flags, "-cipher", suite.name)
2305 }
David Benjamin48cae082014-10-27 01:06:24 -04002306
Adam Langley95c29f32014-06-20 12:00:00 -07002307 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002308 for _, protocol := range []protocol{tls, dtls} {
2309 var prefix string
2310 if protocol == dtls {
2311 if !ver.hasDTLS {
2312 continue
2313 }
2314 prefix = "D"
2315 }
Adam Langley95c29f32014-06-20 12:00:00 -07002316
David Benjamin0407e762016-06-17 16:41:18 -04002317 var shouldServerFail, shouldClientFail bool
2318 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2319 // BoringSSL clients accept ECDHE on SSLv3, but
2320 // a BoringSSL server will never select it
2321 // because the extension is missing.
2322 shouldServerFail = true
2323 }
2324 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2325 shouldClientFail = true
2326 shouldServerFail = true
2327 }
David Benjamin54c217c2016-07-13 12:35:25 -04002328 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002329 shouldClientFail = true
2330 shouldServerFail = true
2331 }
David Benjamin0407e762016-06-17 16:41:18 -04002332 if !isDTLSCipher(suite.name) && protocol == dtls {
2333 shouldClientFail = true
2334 shouldServerFail = true
2335 }
David Benjamin4298d772015-12-19 00:18:25 -05002336
David Benjamin0407e762016-06-17 16:41:18 -04002337 var expectedServerError, expectedClientError string
2338 if shouldServerFail {
2339 expectedServerError = ":NO_SHARED_CIPHER:"
2340 }
2341 if shouldClientFail {
2342 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2343 }
David Benjamin025b3d32014-07-01 19:53:04 -04002344
David Benjamin6fd297b2014-08-11 18:43:38 -04002345 testCases = append(testCases, testCase{
2346 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002347 protocol: protocol,
2348
2349 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002350 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002351 MinVersion: ver.version,
2352 MaxVersion: ver.version,
2353 CipherSuites: []uint16{suite.id},
2354 Certificates: []Certificate{cert},
2355 PreSharedKey: []byte(psk),
2356 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002357 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002358 EnableAllCiphers: shouldServerFail,
2359 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002360 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002361 },
2362 certFile: certFile,
2363 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002364 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002365 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002366 shouldFail: shouldServerFail,
2367 expectedError: expectedServerError,
2368 })
2369
2370 testCases = append(testCases, testCase{
2371 testType: clientTest,
2372 protocol: protocol,
2373 name: prefix + ver.name + "-" + suite.name + "-client",
2374 config: Config{
2375 MinVersion: ver.version,
2376 MaxVersion: ver.version,
2377 CipherSuites: []uint16{suite.id},
2378 Certificates: []Certificate{cert},
2379 PreSharedKey: []byte(psk),
2380 PreSharedKeyIdentity: pskIdentity,
2381 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002382 EnableAllCiphers: shouldClientFail,
2383 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002384 },
2385 },
2386 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002387 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002388 shouldFail: shouldClientFail,
2389 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002390 })
David Benjamin2c99d282015-09-01 10:23:00 -04002391
Nick Harper1fd39d82016-06-14 18:14:35 -07002392 if !shouldClientFail {
2393 // Ensure the maximum record size is accepted.
2394 testCases = append(testCases, testCase{
2395 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2396 config: Config{
2397 MinVersion: ver.version,
2398 MaxVersion: ver.version,
2399 CipherSuites: []uint16{suite.id},
2400 Certificates: []Certificate{cert},
2401 PreSharedKey: []byte(psk),
2402 PreSharedKeyIdentity: pskIdentity,
2403 },
2404 flags: flags,
2405 messageLen: maxPlaintext,
2406 })
2407 }
2408 }
David Benjamin2c99d282015-09-01 10:23:00 -04002409 }
Adam Langley95c29f32014-06-20 12:00:00 -07002410 }
Adam Langleya7997f12015-05-14 17:38:50 -07002411
2412 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002413 name: "NoSharedCipher",
2414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002415 MaxVersion: VersionTLS12,
2416 CipherSuites: []uint16{},
2417 },
2418 shouldFail: true,
2419 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2420 })
2421
2422 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002423 name: "NoSharedCipher-TLS13",
2424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 CipherSuites: []uint16{},
2427 },
2428 shouldFail: true,
2429 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2430 })
2431
2432 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002433 name: "UnsupportedCipherSuite",
2434 config: Config{
2435 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002436 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002437 Bugs: ProtocolBugs{
2438 IgnorePeerCipherPreferences: true,
2439 },
2440 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002441 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002442 shouldFail: true,
2443 expectedError: ":WRONG_CIPHER_RETURNED:",
2444 })
2445
2446 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002447 name: "ServerHelloBogusCipher",
2448 config: Config{
2449 MaxVersion: VersionTLS12,
2450 Bugs: ProtocolBugs{
2451 SendCipherSuite: bogusCipher,
2452 },
2453 },
2454 shouldFail: true,
2455 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2456 })
2457 testCases = append(testCases, testCase{
2458 name: "ServerHelloBogusCipher-TLS13",
2459 config: Config{
2460 MaxVersion: VersionTLS13,
2461 Bugs: ProtocolBugs{
2462 SendCipherSuite: bogusCipher,
2463 },
2464 },
2465 shouldFail: true,
2466 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2467 })
2468
2469 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002470 name: "WeakDH",
2471 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002472 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002473 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2474 Bugs: ProtocolBugs{
2475 // This is a 1023-bit prime number, generated
2476 // with:
2477 // openssl gendh 1023 | openssl asn1parse -i
2478 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2479 },
2480 },
2481 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002482 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002483 })
Adam Langleycef75832015-09-03 14:51:12 -07002484
David Benjamincd24a392015-11-11 13:23:05 -08002485 testCases = append(testCases, testCase{
2486 name: "SillyDH",
2487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002489 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2490 Bugs: ProtocolBugs{
2491 // This is a 4097-bit prime number, generated
2492 // with:
2493 // openssl gendh 4097 | openssl asn1parse -i
2494 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2495 },
2496 },
2497 shouldFail: true,
2498 expectedError: ":DH_P_TOO_LONG:",
2499 })
2500
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002501 // This test ensures that Diffie-Hellman public values are padded with
2502 // zeros so that they're the same length as the prime. This is to avoid
2503 // hitting a bug in yaSSL.
2504 testCases = append(testCases, testCase{
2505 testType: serverTest,
2506 name: "DHPublicValuePadded",
2507 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002508 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002509 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2510 Bugs: ProtocolBugs{
2511 RequireDHPublicValueLen: (1025 + 7) / 8,
2512 },
2513 },
2514 flags: []string{"-use-sparse-dh-prime"},
2515 })
David Benjamincd24a392015-11-11 13:23:05 -08002516
David Benjamin241ae832016-01-15 03:04:54 -05002517 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002518 testCases = append(testCases, testCase{
2519 testType: serverTest,
2520 name: "UnknownCipher",
2521 config: Config{
2522 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2523 },
2524 })
2525
Adam Langleycef75832015-09-03 14:51:12 -07002526 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2527 // 1.1 specific cipher suite settings. A server is setup with the given
2528 // cipher lists and then a connection is made for each member of
2529 // expectations. The cipher suite that the server selects must match
2530 // the specified one.
2531 var versionSpecificCiphersTest = []struct {
2532 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2533 // expectations is a map from TLS version to cipher suite id.
2534 expectations map[uint16]uint16
2535 }{
2536 {
2537 // Test that the null case (where no version-specific ciphers are set)
2538 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002539 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2540 "", // no ciphers specifically for TLS ≥ 1.0
2541 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002542 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002543 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2544 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2545 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2546 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002547 },
2548 },
2549 {
2550 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2551 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002552 "DES-CBC3-SHA:AES128-SHA", // default
2553 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2554 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002555 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002556 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002557 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2558 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2559 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2560 },
2561 },
2562 {
2563 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2564 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002565 "DES-CBC3-SHA:AES128-SHA", // default
2566 "", // no ciphers specifically for TLS ≥ 1.0
2567 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002568 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002569 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2570 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002571 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2572 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2573 },
2574 },
2575 {
2576 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2577 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002578 "DES-CBC3-SHA:AES128-SHA", // default
2579 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2580 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002581 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002582 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002583 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2584 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2585 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2586 },
2587 },
2588 }
2589
2590 for i, test := range versionSpecificCiphersTest {
2591 for version, expectedCipherSuite := range test.expectations {
2592 flags := []string{"-cipher", test.ciphersDefault}
2593 if len(test.ciphersTLS10) > 0 {
2594 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2595 }
2596 if len(test.ciphersTLS11) > 0 {
2597 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2598 }
2599
2600 testCases = append(testCases, testCase{
2601 testType: serverTest,
2602 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2603 config: Config{
2604 MaxVersion: version,
2605 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002606 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002607 },
2608 flags: flags,
2609 expectedCipher: expectedCipherSuite,
2610 })
2611 }
2612 }
Adam Langley95c29f32014-06-20 12:00:00 -07002613}
2614
2615func addBadECDSASignatureTests() {
2616 for badR := BadValue(1); badR < NumBadValues; badR++ {
2617 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002618 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002619 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2620 config: Config{
2621 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002622 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002623 Bugs: ProtocolBugs{
2624 BadECDSAR: badR,
2625 BadECDSAS: badS,
2626 },
2627 },
2628 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002629 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002630 })
2631 }
2632 }
2633}
2634
Adam Langley80842bd2014-06-20 12:00:00 -07002635func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002636 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002637 name: "MaxCBCPadding",
2638 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002639 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2641 Bugs: ProtocolBugs{
2642 MaxPadding: true,
2643 },
2644 },
2645 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2646 })
David Benjamin025b3d32014-07-01 19:53:04 -04002647 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002648 name: "BadCBCPadding",
2649 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002650 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2652 Bugs: ProtocolBugs{
2653 PaddingFirstByteBad: true,
2654 },
2655 },
2656 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002657 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002658 })
2659 // OpenSSL previously had an issue where the first byte of padding in
2660 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002661 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002662 name: "BadCBCPadding255",
2663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002664 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2666 Bugs: ProtocolBugs{
2667 MaxPadding: true,
2668 PaddingFirstByteBadIf255: true,
2669 },
2670 },
2671 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2672 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002673 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002674 })
2675}
2676
Kenny Root7fdeaf12014-08-05 15:23:37 -07002677func addCBCSplittingTests() {
2678 testCases = append(testCases, testCase{
2679 name: "CBCRecordSplitting",
2680 config: Config{
2681 MaxVersion: VersionTLS10,
2682 MinVersion: VersionTLS10,
2683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2684 },
David Benjaminac8302a2015-09-01 17:18:15 -04002685 messageLen: -1, // read until EOF
2686 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002687 flags: []string{
2688 "-async",
2689 "-write-different-record-sizes",
2690 "-cbc-record-splitting",
2691 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002692 })
2693 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002694 name: "CBCRecordSplittingPartialWrite",
2695 config: Config{
2696 MaxVersion: VersionTLS10,
2697 MinVersion: VersionTLS10,
2698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2699 },
2700 messageLen: -1, // read until EOF
2701 flags: []string{
2702 "-async",
2703 "-write-different-record-sizes",
2704 "-cbc-record-splitting",
2705 "-partial-write",
2706 },
2707 })
2708}
2709
David Benjamin636293b2014-07-08 17:59:18 -04002710func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002711 // Add a dummy cert pool to stress certificate authority parsing.
2712 // TODO(davidben): Add tests that those values parse out correctly.
2713 certPool := x509.NewCertPool()
2714 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2715 if err != nil {
2716 panic(err)
2717 }
2718 certPool.AddCert(cert)
2719
David Benjamin636293b2014-07-08 17:59:18 -04002720 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002721 testCases = append(testCases, testCase{
2722 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002723 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002724 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002725 MinVersion: ver.version,
2726 MaxVersion: ver.version,
2727 ClientAuth: RequireAnyClientCert,
2728 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002729 },
2730 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002731 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2732 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002733 },
2734 })
2735 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002736 testType: serverTest,
2737 name: ver.name + "-Server-ClientAuth-RSA",
2738 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002739 MinVersion: ver.version,
2740 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002741 Certificates: []Certificate{rsaCertificate},
2742 },
2743 flags: []string{"-require-any-client-certificate"},
2744 })
David Benjamine098ec22014-08-27 23:13:20 -04002745 if ver.version != VersionSSL30 {
2746 testCases = append(testCases, testCase{
2747 testType: serverTest,
2748 name: ver.name + "-Server-ClientAuth-ECDSA",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002752 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002753 },
2754 flags: []string{"-require-any-client-certificate"},
2755 })
2756 testCases = append(testCases, testCase{
2757 testType: clientTest,
2758 name: ver.name + "-Client-ClientAuth-ECDSA",
2759 config: Config{
2760 MinVersion: ver.version,
2761 MaxVersion: ver.version,
2762 ClientAuth: RequireAnyClientCert,
2763 ClientCAs: certPool,
2764 },
2765 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002766 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2767 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002768 },
2769 })
2770 }
Adam Langley37646832016-08-01 16:16:46 -07002771
2772 testCases = append(testCases, testCase{
2773 name: "NoClientCertificate-" + ver.name,
2774 config: Config{
2775 MinVersion: ver.version,
2776 MaxVersion: ver.version,
2777 ClientAuth: RequireAnyClientCert,
2778 },
2779 shouldFail: true,
2780 expectedLocalError: "client didn't provide a certificate",
2781 })
2782
2783 testCases = append(testCases, testCase{
2784 // Even if not configured to expect a certificate, OpenSSL will
2785 // return X509_V_OK as the verify_result.
2786 testType: serverTest,
2787 name: "NoClientCertificateRequested-Server-" + ver.name,
2788 config: Config{
2789 MinVersion: ver.version,
2790 MaxVersion: ver.version,
2791 },
2792 flags: []string{
2793 "-expect-verify-result",
2794 },
2795 // TODO(davidben): Switch this to true when TLS 1.3
2796 // supports session resumption.
2797 resumeSession: ver.version < VersionTLS13,
2798 })
2799
2800 testCases = append(testCases, testCase{
2801 // If a client certificate is not provided, OpenSSL will still
2802 // return X509_V_OK as the verify_result.
2803 testType: serverTest,
2804 name: "NoClientCertificate-Server-" + ver.name,
2805 config: Config{
2806 MinVersion: ver.version,
2807 MaxVersion: ver.version,
2808 },
2809 flags: []string{
2810 "-expect-verify-result",
2811 "-verify-peer",
2812 },
2813 // TODO(davidben): Switch this to true when TLS 1.3
2814 // supports session resumption.
2815 resumeSession: ver.version < VersionTLS13,
2816 })
2817
2818 testCases = append(testCases, testCase{
2819 testType: serverTest,
2820 name: "RequireAnyClientCertificate-" + ver.name,
2821 config: Config{
2822 MinVersion: ver.version,
2823 MaxVersion: ver.version,
2824 },
2825 flags: []string{"-require-any-client-certificate"},
2826 shouldFail: true,
2827 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2828 })
2829
2830 if ver.version != VersionSSL30 {
2831 testCases = append(testCases, testCase{
2832 testType: serverTest,
2833 name: "SkipClientCertificate-" + ver.name,
2834 config: Config{
2835 MinVersion: ver.version,
2836 MaxVersion: ver.version,
2837 Bugs: ProtocolBugs{
2838 SkipClientCertificate: true,
2839 },
2840 },
2841 // Setting SSL_VERIFY_PEER allows anonymous clients.
2842 flags: []string{"-verify-peer"},
2843 shouldFail: true,
2844 expectedError: ":UNEXPECTED_MESSAGE:",
2845 })
2846 }
David Benjamin636293b2014-07-08 17:59:18 -04002847 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002848
David Benjaminc032dfa2016-05-12 14:54:57 -04002849 // Client auth is only legal in certificate-based ciphers.
2850 testCases = append(testCases, testCase{
2851 testType: clientTest,
2852 name: "ClientAuth-PSK",
2853 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002854 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002855 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2856 PreSharedKey: []byte("secret"),
2857 ClientAuth: RequireAnyClientCert,
2858 },
2859 flags: []string{
2860 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2861 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2862 "-psk", "secret",
2863 },
2864 shouldFail: true,
2865 expectedError: ":UNEXPECTED_MESSAGE:",
2866 })
2867 testCases = append(testCases, testCase{
2868 testType: clientTest,
2869 name: "ClientAuth-ECDHE_PSK",
2870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002871 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002872 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2873 PreSharedKey: []byte("secret"),
2874 ClientAuth: RequireAnyClientCert,
2875 },
2876 flags: []string{
2877 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2878 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2879 "-psk", "secret",
2880 },
2881 shouldFail: true,
2882 expectedError: ":UNEXPECTED_MESSAGE:",
2883 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002884
2885 // Regression test for a bug where the client CA list, if explicitly
2886 // set to NULL, was mis-encoded.
2887 testCases = append(testCases, testCase{
2888 testType: serverTest,
2889 name: "Null-Client-CA-List",
2890 config: Config{
2891 MaxVersion: VersionTLS12,
2892 Certificates: []Certificate{rsaCertificate},
2893 },
2894 flags: []string{
2895 "-require-any-client-certificate",
2896 "-use-null-client-ca-list",
2897 },
2898 })
David Benjamin636293b2014-07-08 17:59:18 -04002899}
2900
Adam Langley75712922014-10-10 16:23:43 -07002901func addExtendedMasterSecretTests() {
2902 const expectEMSFlag = "-expect-extended-master-secret"
2903
2904 for _, with := range []bool{false, true} {
2905 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002906 if with {
2907 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002908 }
2909
2910 for _, isClient := range []bool{false, true} {
2911 suffix := "-Server"
2912 testType := serverTest
2913 if isClient {
2914 suffix = "-Client"
2915 testType = clientTest
2916 }
2917
2918 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002919 // In TLS 1.3, the extension is irrelevant and
2920 // always reports as enabled.
2921 var flags []string
2922 if with || ver.version >= VersionTLS13 {
2923 flags = []string{expectEMSFlag}
2924 }
2925
Adam Langley75712922014-10-10 16:23:43 -07002926 test := testCase{
2927 testType: testType,
2928 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2929 config: Config{
2930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 Bugs: ProtocolBugs{
2933 NoExtendedMasterSecret: !with,
2934 RequireExtendedMasterSecret: with,
2935 },
2936 },
David Benjamin48cae082014-10-27 01:06:24 -04002937 flags: flags,
2938 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002939 }
2940 if test.shouldFail {
2941 test.expectedLocalError = "extended master secret required but not supported by peer"
2942 }
2943 testCases = append(testCases, test)
2944 }
2945 }
2946 }
2947
Adam Langleyba5934b2015-06-02 10:50:35 -07002948 for _, isClient := range []bool{false, true} {
2949 for _, supportedInFirstConnection := range []bool{false, true} {
2950 for _, supportedInResumeConnection := range []bool{false, true} {
2951 boolToWord := func(b bool) string {
2952 if b {
2953 return "Yes"
2954 }
2955 return "No"
2956 }
2957 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2958 if isClient {
2959 suffix += "Client"
2960 } else {
2961 suffix += "Server"
2962 }
2963
2964 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002965 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002966 Bugs: ProtocolBugs{
2967 RequireExtendedMasterSecret: true,
2968 },
2969 }
2970
2971 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002972 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002973 Bugs: ProtocolBugs{
2974 NoExtendedMasterSecret: true,
2975 },
2976 }
2977
2978 test := testCase{
2979 name: "ExtendedMasterSecret-" + suffix,
2980 resumeSession: true,
2981 }
2982
2983 if !isClient {
2984 test.testType = serverTest
2985 }
2986
2987 if supportedInFirstConnection {
2988 test.config = supportedConfig
2989 } else {
2990 test.config = noSupportConfig
2991 }
2992
2993 if supportedInResumeConnection {
2994 test.resumeConfig = &supportedConfig
2995 } else {
2996 test.resumeConfig = &noSupportConfig
2997 }
2998
2999 switch suffix {
3000 case "YesToYes-Client", "YesToYes-Server":
3001 // When a session is resumed, it should
3002 // still be aware that its master
3003 // secret was generated via EMS and
3004 // thus it's safe to use tls-unique.
3005 test.flags = []string{expectEMSFlag}
3006 case "NoToYes-Server":
3007 // If an original connection did not
3008 // contain EMS, but a resumption
3009 // handshake does, then a server should
3010 // not resume the session.
3011 test.expectResumeRejected = true
3012 case "YesToNo-Server":
3013 // Resuming an EMS session without the
3014 // EMS extension should cause the
3015 // server to abort the connection.
3016 test.shouldFail = true
3017 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3018 case "NoToYes-Client":
3019 // A client should abort a connection
3020 // where the server resumed a non-EMS
3021 // session but echoed the EMS
3022 // extension.
3023 test.shouldFail = true
3024 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3025 case "YesToNo-Client":
3026 // A client should abort a connection
3027 // where the server didn't echo EMS
3028 // when the session used it.
3029 test.shouldFail = true
3030 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3031 }
3032
3033 testCases = append(testCases, test)
3034 }
3035 }
3036 }
Adam Langley75712922014-10-10 16:23:43 -07003037}
3038
David Benjamin582ba042016-07-07 12:33:25 -07003039type stateMachineTestConfig struct {
3040 protocol protocol
3041 async bool
3042 splitHandshake, packHandshakeFlight bool
3043}
3044
David Benjamin43ec06f2014-08-05 02:28:57 -04003045// Adds tests that try to cover the range of the handshake state machine, under
3046// various conditions. Some of these are redundant with other tests, but they
3047// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003048func addAllStateMachineCoverageTests() {
3049 for _, async := range []bool{false, true} {
3050 for _, protocol := range []protocol{tls, dtls} {
3051 addStateMachineCoverageTests(stateMachineTestConfig{
3052 protocol: protocol,
3053 async: async,
3054 })
3055 addStateMachineCoverageTests(stateMachineTestConfig{
3056 protocol: protocol,
3057 async: async,
3058 splitHandshake: true,
3059 })
3060 if protocol == tls {
3061 addStateMachineCoverageTests(stateMachineTestConfig{
3062 protocol: protocol,
3063 async: async,
3064 packHandshakeFlight: true,
3065 })
3066 }
3067 }
3068 }
3069}
3070
3071func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003072 var tests []testCase
3073
3074 // Basic handshake, with resumption. Client and server,
3075 // session ID and session ticket.
3076 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003077 name: "Basic-Client",
3078 config: Config{
3079 MaxVersion: VersionTLS12,
3080 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003081 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003082 // Ensure session tickets are used, not session IDs.
3083 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003084 })
3085 tests = append(tests, testCase{
3086 name: "Basic-Client-RenewTicket",
3087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003088 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003089 Bugs: ProtocolBugs{
3090 RenewTicketOnResume: true,
3091 },
3092 },
David Benjamin46662482016-08-17 00:51:00 -04003093 flags: []string{"-expect-ticket-renewal"},
3094 resumeSession: true,
3095 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003096 })
3097 tests = append(tests, testCase{
3098 name: "Basic-Client-NoTicket",
3099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003100 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003101 SessionTicketsDisabled: true,
3102 },
3103 resumeSession: true,
3104 })
3105 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003106 name: "Basic-Client-Implicit",
3107 config: Config{
3108 MaxVersion: VersionTLS12,
3109 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003110 flags: []string{"-implicit-handshake"},
3111 resumeSession: true,
3112 })
3113 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003114 testType: serverTest,
3115 name: "Basic-Server",
3116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003117 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003118 Bugs: ProtocolBugs{
3119 RequireSessionTickets: true,
3120 },
3121 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003122 resumeSession: true,
3123 })
3124 tests = append(tests, testCase{
3125 testType: serverTest,
3126 name: "Basic-Server-NoTickets",
3127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003128 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003129 SessionTicketsDisabled: true,
3130 },
3131 resumeSession: true,
3132 })
3133 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003134 testType: serverTest,
3135 name: "Basic-Server-Implicit",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003139 flags: []string{"-implicit-handshake"},
3140 resumeSession: true,
3141 })
3142 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003143 testType: serverTest,
3144 name: "Basic-Server-EarlyCallback",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003148 flags: []string{"-use-early-callback"},
3149 resumeSession: true,
3150 })
3151
Steven Valdez143e8b32016-07-11 13:19:03 -04003152 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003153 if config.protocol == tls {
3154 tests = append(tests, testCase{
3155 name: "TLS13-1RTT-Client",
3156 config: Config{
3157 MaxVersion: VersionTLS13,
3158 MinVersion: VersionTLS13,
3159 },
David Benjamin46662482016-08-17 00:51:00 -04003160 resumeSession: true,
3161 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003162 })
3163
3164 tests = append(tests, testCase{
3165 testType: serverTest,
3166 name: "TLS13-1RTT-Server",
3167 config: Config{
3168 MaxVersion: VersionTLS13,
3169 MinVersion: VersionTLS13,
3170 },
David Benjamin46662482016-08-17 00:51:00 -04003171 resumeSession: true,
3172 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003173 })
3174
3175 tests = append(tests, testCase{
3176 name: "TLS13-HelloRetryRequest-Client",
3177 config: Config{
3178 MaxVersion: VersionTLS13,
3179 MinVersion: VersionTLS13,
3180 // P-384 requires a HelloRetryRequest against
3181 // BoringSSL's default configuration. Assert
3182 // that we do indeed test this with
3183 // ExpectMissingKeyShare.
3184 CurvePreferences: []CurveID{CurveP384},
3185 Bugs: ProtocolBugs{
3186 ExpectMissingKeyShare: true,
3187 },
3188 },
3189 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3190 resumeSession: true,
3191 })
3192
3193 tests = append(tests, testCase{
3194 testType: serverTest,
3195 name: "TLS13-HelloRetryRequest-Server",
3196 config: Config{
3197 MaxVersion: VersionTLS13,
3198 MinVersion: VersionTLS13,
3199 // Require a HelloRetryRequest for every curve.
3200 DefaultCurves: []CurveID{},
3201 },
3202 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3203 resumeSession: true,
3204 })
3205 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003206
David Benjamin760b1dd2015-05-15 23:33:48 -04003207 // TLS client auth.
3208 tests = append(tests, testCase{
3209 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003210 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003213 ClientAuth: RequestClientCert,
3214 },
3215 })
3216 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003217 testType: serverTest,
3218 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003219 config: Config{
3220 MaxVersion: VersionTLS12,
3221 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003222 // Setting SSL_VERIFY_PEER allows anonymous clients.
3223 flags: []string{"-verify-peer"},
3224 })
David Benjamin582ba042016-07-07 12:33:25 -07003225 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003226 tests = append(tests, testCase{
3227 testType: clientTest,
3228 name: "ClientAuth-NoCertificate-Client-SSL3",
3229 config: Config{
3230 MaxVersion: VersionSSL30,
3231 ClientAuth: RequestClientCert,
3232 },
3233 })
3234 tests = append(tests, testCase{
3235 testType: serverTest,
3236 name: "ClientAuth-NoCertificate-Server-SSL3",
3237 config: Config{
3238 MaxVersion: VersionSSL30,
3239 },
3240 // Setting SSL_VERIFY_PEER allows anonymous clients.
3241 flags: []string{"-verify-peer"},
3242 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003243 tests = append(tests, testCase{
3244 testType: clientTest,
3245 name: "ClientAuth-NoCertificate-Client-TLS13",
3246 config: Config{
3247 MaxVersion: VersionTLS13,
3248 ClientAuth: RequestClientCert,
3249 },
3250 })
3251 tests = append(tests, testCase{
3252 testType: serverTest,
3253 name: "ClientAuth-NoCertificate-Server-TLS13",
3254 config: Config{
3255 MaxVersion: VersionTLS13,
3256 },
3257 // Setting SSL_VERIFY_PEER allows anonymous clients.
3258 flags: []string{"-verify-peer"},
3259 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003260 }
3261 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003262 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003263 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003265 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003266 ClientAuth: RequireAnyClientCert,
3267 },
3268 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003269 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3270 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003271 },
3272 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003273 tests = append(tests, testCase{
3274 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003275 name: "ClientAuth-RSA-Client-TLS13",
3276 config: Config{
3277 MaxVersion: VersionTLS13,
3278 ClientAuth: RequireAnyClientCert,
3279 },
3280 flags: []string{
3281 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3282 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3283 },
3284 })
3285 tests = append(tests, testCase{
3286 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003287 name: "ClientAuth-ECDSA-Client",
3288 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003289 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003290 ClientAuth: RequireAnyClientCert,
3291 },
3292 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003293 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3294 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003295 },
3296 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003297 tests = append(tests, testCase{
3298 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003299 name: "ClientAuth-ECDSA-Client-TLS13",
3300 config: Config{
3301 MaxVersion: VersionTLS13,
3302 ClientAuth: RequireAnyClientCert,
3303 },
3304 flags: []string{
3305 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3306 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3307 },
3308 })
3309 tests = append(tests, testCase{
3310 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003311 name: "ClientAuth-NoCertificate-OldCallback",
3312 config: Config{
3313 MaxVersion: VersionTLS12,
3314 ClientAuth: RequestClientCert,
3315 },
3316 flags: []string{"-use-old-client-cert-callback"},
3317 })
3318 tests = append(tests, testCase{
3319 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003320 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3321 config: Config{
3322 MaxVersion: VersionTLS13,
3323 ClientAuth: RequestClientCert,
3324 },
3325 flags: []string{"-use-old-client-cert-callback"},
3326 })
3327 tests = append(tests, testCase{
3328 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003329 name: "ClientAuth-OldCallback",
3330 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003331 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003332 ClientAuth: RequireAnyClientCert,
3333 },
3334 flags: []string{
3335 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3336 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3337 "-use-old-client-cert-callback",
3338 },
3339 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003340 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003341 testType: clientTest,
3342 name: "ClientAuth-OldCallback-TLS13",
3343 config: Config{
3344 MaxVersion: VersionTLS13,
3345 ClientAuth: RequireAnyClientCert,
3346 },
3347 flags: []string{
3348 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3349 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3350 "-use-old-client-cert-callback",
3351 },
3352 })
3353 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003354 testType: serverTest,
3355 name: "ClientAuth-Server",
3356 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003357 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003358 Certificates: []Certificate{rsaCertificate},
3359 },
3360 flags: []string{"-require-any-client-certificate"},
3361 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003362 tests = append(tests, testCase{
3363 testType: serverTest,
3364 name: "ClientAuth-Server-TLS13",
3365 config: Config{
3366 MaxVersion: VersionTLS13,
3367 Certificates: []Certificate{rsaCertificate},
3368 },
3369 flags: []string{"-require-any-client-certificate"},
3370 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003371
David Benjamin4c3ddf72016-06-29 18:13:53 -04003372 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003373 tests = append(tests, testCase{
3374 testType: serverTest,
3375 name: "Basic-Server-RSA",
3376 config: Config{
3377 MaxVersion: VersionTLS12,
3378 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3379 },
3380 flags: []string{
3381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3383 },
3384 })
3385 tests = append(tests, testCase{
3386 testType: serverTest,
3387 name: "Basic-Server-ECDHE-RSA",
3388 config: Config{
3389 MaxVersion: VersionTLS12,
3390 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3391 },
3392 flags: []string{
3393 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3394 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3395 },
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "Basic-Server-ECDHE-ECDSA",
3400 config: Config{
3401 MaxVersion: VersionTLS12,
3402 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3403 },
3404 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003405 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3406 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 },
3408 })
3409
David Benjamin760b1dd2015-05-15 23:33:48 -04003410 // No session ticket support; server doesn't send NewSessionTicket.
3411 tests = append(tests, testCase{
3412 name: "SessionTicketsDisabled-Client",
3413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003414 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003415 SessionTicketsDisabled: true,
3416 },
3417 })
3418 tests = append(tests, testCase{
3419 testType: serverTest,
3420 name: "SessionTicketsDisabled-Server",
3421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003422 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003423 SessionTicketsDisabled: true,
3424 },
3425 })
3426
3427 // Skip ServerKeyExchange in PSK key exchange if there's no
3428 // identity hint.
3429 tests = append(tests, testCase{
3430 name: "EmptyPSKHint-Client",
3431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003432 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003433 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3434 PreSharedKey: []byte("secret"),
3435 },
3436 flags: []string{"-psk", "secret"},
3437 })
3438 tests = append(tests, testCase{
3439 testType: serverTest,
3440 name: "EmptyPSKHint-Server",
3441 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003442 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003443 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3444 PreSharedKey: []byte("secret"),
3445 },
3446 flags: []string{"-psk", "secret"},
3447 })
3448
David Benjamin4c3ddf72016-06-29 18:13:53 -04003449 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003450 tests = append(tests, testCase{
3451 testType: clientTest,
3452 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003453 config: Config{
3454 MaxVersion: VersionTLS12,
3455 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003456 flags: []string{
3457 "-enable-ocsp-stapling",
3458 "-expect-ocsp-response",
3459 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003460 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003461 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003462 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003463 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003464 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003465 testType: serverTest,
3466 name: "OCSPStapling-Server",
3467 config: Config{
3468 MaxVersion: VersionTLS12,
3469 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003470 expectedOCSPResponse: testOCSPResponse,
3471 flags: []string{
3472 "-ocsp-response",
3473 base64.StdEncoding.EncodeToString(testOCSPResponse),
3474 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003475 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003476 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003477 tests = append(tests, testCase{
3478 testType: clientTest,
3479 name: "OCSPStapling-Client-TLS13",
3480 config: Config{
3481 MaxVersion: VersionTLS13,
3482 },
3483 flags: []string{
3484 "-enable-ocsp-stapling",
3485 "-expect-ocsp-response",
3486 base64.StdEncoding.EncodeToString(testOCSPResponse),
3487 "-verify-peer",
3488 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003489 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003490 })
3491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "OCSPStapling-Server-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 },
3497 expectedOCSPResponse: testOCSPResponse,
3498 flags: []string{
3499 "-ocsp-response",
3500 base64.StdEncoding.EncodeToString(testOCSPResponse),
3501 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003502 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003503 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003504
David Benjamin4c3ddf72016-06-29 18:13:53 -04003505 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003506 for _, vers := range tlsVersions {
3507 if config.protocol == dtls && !vers.hasDTLS {
3508 continue
3509 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003510 for _, testType := range []testType{clientTest, serverTest} {
3511 suffix := "-Client"
3512 if testType == serverTest {
3513 suffix = "-Server"
3514 }
3515 suffix += "-" + vers.name
3516
3517 flag := "-verify-peer"
3518 if testType == serverTest {
3519 flag = "-require-any-client-certificate"
3520 }
3521
3522 tests = append(tests, testCase{
3523 testType: testType,
3524 name: "CertificateVerificationSucceed" + suffix,
3525 config: Config{
3526 MaxVersion: vers.version,
3527 Certificates: []Certificate{rsaCertificate},
3528 },
3529 flags: []string{
3530 flag,
3531 "-expect-verify-result",
3532 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003533 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003534 })
3535 tests = append(tests, testCase{
3536 testType: testType,
3537 name: "CertificateVerificationFail" + suffix,
3538 config: Config{
3539 MaxVersion: vers.version,
3540 Certificates: []Certificate{rsaCertificate},
3541 },
3542 flags: []string{
3543 flag,
3544 "-verify-fail",
3545 },
3546 shouldFail: true,
3547 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3548 })
3549 }
3550
3551 // By default, the client is in a soft fail mode where the peer
3552 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003553 tests = append(tests, testCase{
3554 testType: clientTest,
3555 name: "CertificateVerificationSoftFail-" + vers.name,
3556 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003557 MaxVersion: vers.version,
3558 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003559 },
3560 flags: []string{
3561 "-verify-fail",
3562 "-expect-verify-result",
3563 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003564 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003565 })
3566 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003567
David Benjamin1d4f4c02016-07-26 18:03:08 -04003568 tests = append(tests, testCase{
3569 name: "ShimSendAlert",
3570 flags: []string{"-send-alert"},
3571 shimWritesFirst: true,
3572 shouldFail: true,
3573 expectedLocalError: "remote error: decompression failure",
3574 })
3575
David Benjamin582ba042016-07-07 12:33:25 -07003576 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003577 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 name: "Renegotiate-Client",
3579 config: Config{
3580 MaxVersion: VersionTLS12,
3581 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003582 renegotiate: 1,
3583 flags: []string{
3584 "-renegotiate-freely",
3585 "-expect-total-renegotiations", "1",
3586 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003588
David Benjamin47921102016-07-28 11:29:18 -04003589 tests = append(tests, testCase{
3590 name: "SendHalfHelloRequest",
3591 config: Config{
3592 MaxVersion: VersionTLS12,
3593 Bugs: ProtocolBugs{
3594 PackHelloRequestWithFinished: config.packHandshakeFlight,
3595 },
3596 },
3597 sendHalfHelloRequest: true,
3598 flags: []string{"-renegotiate-ignore"},
3599 shouldFail: true,
3600 expectedError: ":UNEXPECTED_RECORD:",
3601 })
3602
David Benjamin760b1dd2015-05-15 23:33:48 -04003603 // NPN on client and server; results in post-handshake message.
3604 tests = append(tests, testCase{
3605 name: "NPN-Client",
3606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003607 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003608 NextProtos: []string{"foo"},
3609 },
3610 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003611 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003612 expectedNextProto: "foo",
3613 expectedNextProtoType: npn,
3614 })
3615 tests = append(tests, testCase{
3616 testType: serverTest,
3617 name: "NPN-Server",
3618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003619 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003620 NextProtos: []string{"bar"},
3621 },
3622 flags: []string{
3623 "-advertise-npn", "\x03foo\x03bar\x03baz",
3624 "-expect-next-proto", "bar",
3625 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003626 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003627 expectedNextProto: "bar",
3628 expectedNextProtoType: npn,
3629 })
3630
3631 // TODO(davidben): Add tests for when False Start doesn't trigger.
3632
3633 // Client does False Start and negotiates NPN.
3634 tests = append(tests, testCase{
3635 name: "FalseStart",
3636 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003637 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003638 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3639 NextProtos: []string{"foo"},
3640 Bugs: ProtocolBugs{
3641 ExpectFalseStart: true,
3642 },
3643 },
3644 flags: []string{
3645 "-false-start",
3646 "-select-next-proto", "foo",
3647 },
3648 shimWritesFirst: true,
3649 resumeSession: true,
3650 })
3651
3652 // Client does False Start and negotiates ALPN.
3653 tests = append(tests, testCase{
3654 name: "FalseStart-ALPN",
3655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003656 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3658 NextProtos: []string{"foo"},
3659 Bugs: ProtocolBugs{
3660 ExpectFalseStart: true,
3661 },
3662 },
3663 flags: []string{
3664 "-false-start",
3665 "-advertise-alpn", "\x03foo",
3666 },
3667 shimWritesFirst: true,
3668 resumeSession: true,
3669 })
3670
3671 // Client does False Start but doesn't explicitly call
3672 // SSL_connect.
3673 tests = append(tests, testCase{
3674 name: "FalseStart-Implicit",
3675 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003676 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003677 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3678 NextProtos: []string{"foo"},
3679 },
3680 flags: []string{
3681 "-implicit-handshake",
3682 "-false-start",
3683 "-advertise-alpn", "\x03foo",
3684 },
3685 })
3686
3687 // False Start without session tickets.
3688 tests = append(tests, testCase{
3689 name: "FalseStart-SessionTicketsDisabled",
3690 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003691 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3693 NextProtos: []string{"foo"},
3694 SessionTicketsDisabled: true,
3695 Bugs: ProtocolBugs{
3696 ExpectFalseStart: true,
3697 },
3698 },
3699 flags: []string{
3700 "-false-start",
3701 "-select-next-proto", "foo",
3702 },
3703 shimWritesFirst: true,
3704 })
3705
Adam Langleydf759b52016-07-11 15:24:37 -07003706 tests = append(tests, testCase{
3707 name: "FalseStart-CECPQ1",
3708 config: Config{
3709 MaxVersion: VersionTLS12,
3710 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3711 NextProtos: []string{"foo"},
3712 Bugs: ProtocolBugs{
3713 ExpectFalseStart: true,
3714 },
3715 },
3716 flags: []string{
3717 "-false-start",
3718 "-cipher", "DEFAULT:kCECPQ1",
3719 "-select-next-proto", "foo",
3720 },
3721 shimWritesFirst: true,
3722 resumeSession: true,
3723 })
3724
David Benjamin760b1dd2015-05-15 23:33:48 -04003725 // Server parses a V2ClientHello.
3726 tests = append(tests, testCase{
3727 testType: serverTest,
3728 name: "SendV2ClientHello",
3729 config: Config{
3730 // Choose a cipher suite that does not involve
3731 // elliptic curves, so no extensions are
3732 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003733 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003734 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003735 Bugs: ProtocolBugs{
3736 SendV2ClientHello: true,
3737 },
3738 },
3739 })
3740
3741 // Client sends a Channel ID.
3742 tests = append(tests, testCase{
3743 name: "ChannelID-Client",
3744 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003745 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003746 RequestChannelID: true,
3747 },
Adam Langley7c803a62015-06-15 15:35:05 -07003748 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 resumeSession: true,
3750 expectChannelID: true,
3751 })
3752
3753 // Server accepts a Channel ID.
3754 tests = append(tests, testCase{
3755 testType: serverTest,
3756 name: "ChannelID-Server",
3757 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 MaxVersion: VersionTLS12,
3759 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003760 },
3761 flags: []string{
3762 "-expect-channel-id",
3763 base64.StdEncoding.EncodeToString(channelIDBytes),
3764 },
3765 resumeSession: true,
3766 expectChannelID: true,
3767 })
David Benjamin30789da2015-08-29 22:56:45 -04003768
David Benjaminf8fcdf32016-06-08 15:56:13 -04003769 // Channel ID and NPN at the same time, to ensure their relative
3770 // ordering is correct.
3771 tests = append(tests, testCase{
3772 name: "ChannelID-NPN-Client",
3773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003774 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003775 RequestChannelID: true,
3776 NextProtos: []string{"foo"},
3777 },
3778 flags: []string{
3779 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3780 "-select-next-proto", "foo",
3781 },
3782 resumeSession: true,
3783 expectChannelID: true,
3784 expectedNextProto: "foo",
3785 expectedNextProtoType: npn,
3786 })
3787 tests = append(tests, testCase{
3788 testType: serverTest,
3789 name: "ChannelID-NPN-Server",
3790 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003791 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003792 ChannelID: channelIDKey,
3793 NextProtos: []string{"bar"},
3794 },
3795 flags: []string{
3796 "-expect-channel-id",
3797 base64.StdEncoding.EncodeToString(channelIDBytes),
3798 "-advertise-npn", "\x03foo\x03bar\x03baz",
3799 "-expect-next-proto", "bar",
3800 },
3801 resumeSession: true,
3802 expectChannelID: true,
3803 expectedNextProto: "bar",
3804 expectedNextProtoType: npn,
3805 })
3806
David Benjamin30789da2015-08-29 22:56:45 -04003807 // Bidirectional shutdown with the runner initiating.
3808 tests = append(tests, testCase{
3809 name: "Shutdown-Runner",
3810 config: Config{
3811 Bugs: ProtocolBugs{
3812 ExpectCloseNotify: true,
3813 },
3814 },
3815 flags: []string{"-check-close-notify"},
3816 })
3817
3818 // Bidirectional shutdown with the shim initiating. The runner,
3819 // in the meantime, sends garbage before the close_notify which
3820 // the shim must ignore.
3821 tests = append(tests, testCase{
3822 name: "Shutdown-Shim",
3823 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003824 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003825 Bugs: ProtocolBugs{
3826 ExpectCloseNotify: true,
3827 },
3828 },
3829 shimShutsDown: true,
3830 sendEmptyRecords: 1,
3831 sendWarningAlerts: 1,
3832 flags: []string{"-check-close-notify"},
3833 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003834 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003835 // TODO(davidben): DTLS 1.3 will want a similar thing for
3836 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003837 tests = append(tests, testCase{
3838 name: "SkipHelloVerifyRequest",
3839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003840 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003841 Bugs: ProtocolBugs{
3842 SkipHelloVerifyRequest: true,
3843 },
3844 },
3845 })
3846 }
3847
David Benjamin760b1dd2015-05-15 23:33:48 -04003848 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003849 test.protocol = config.protocol
3850 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003851 test.name += "-DTLS"
3852 }
David Benjamin582ba042016-07-07 12:33:25 -07003853 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003854 test.name += "-Async"
3855 test.flags = append(test.flags, "-async")
3856 } else {
3857 test.name += "-Sync"
3858 }
David Benjamin582ba042016-07-07 12:33:25 -07003859 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003860 test.name += "-SplitHandshakeRecords"
3861 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003862 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003863 test.config.Bugs.MaxPacketLength = 256
3864 test.flags = append(test.flags, "-mtu", "256")
3865 }
3866 }
David Benjamin582ba042016-07-07 12:33:25 -07003867 if config.packHandshakeFlight {
3868 test.name += "-PackHandshakeFlight"
3869 test.config.Bugs.PackHandshakeFlight = true
3870 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003872 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003873}
3874
Adam Langley524e7172015-02-20 16:04:00 -08003875func addDDoSCallbackTests() {
3876 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003877 for _, resume := range []bool{false, true} {
3878 suffix := "Resume"
3879 if resume {
3880 suffix = "No" + suffix
3881 }
3882
3883 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003884 testType: serverTest,
3885 name: "Server-DDoS-OK-" + suffix,
3886 config: Config{
3887 MaxVersion: VersionTLS12,
3888 },
Adam Langley524e7172015-02-20 16:04:00 -08003889 flags: []string{"-install-ddos-callback"},
3890 resumeSession: resume,
3891 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003892 testCases = append(testCases, testCase{
3893 testType: serverTest,
3894 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3895 config: Config{
3896 MaxVersion: VersionTLS13,
3897 },
3898 flags: []string{"-install-ddos-callback"},
3899 resumeSession: resume,
3900 })
Adam Langley524e7172015-02-20 16:04:00 -08003901
3902 failFlag := "-fail-ddos-callback"
3903 if resume {
3904 failFlag = "-fail-second-ddos-callback"
3905 }
3906 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003907 testType: serverTest,
3908 name: "Server-DDoS-Reject-" + suffix,
3909 config: Config{
3910 MaxVersion: VersionTLS12,
3911 },
Adam Langley524e7172015-02-20 16:04:00 -08003912 flags: []string{"-install-ddos-callback", failFlag},
3913 resumeSession: resume,
3914 shouldFail: true,
3915 expectedError: ":CONNECTION_REJECTED:",
3916 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003917 testCases = append(testCases, testCase{
3918 testType: serverTest,
3919 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3920 config: Config{
3921 MaxVersion: VersionTLS13,
3922 },
3923 flags: []string{"-install-ddos-callback", failFlag},
3924 resumeSession: resume,
3925 shouldFail: true,
3926 expectedError: ":CONNECTION_REJECTED:",
3927 })
Adam Langley524e7172015-02-20 16:04:00 -08003928 }
3929}
3930
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003931func addVersionNegotiationTests() {
3932 for i, shimVers := range tlsVersions {
3933 // Assemble flags to disable all newer versions on the shim.
3934 var flags []string
3935 for _, vers := range tlsVersions[i+1:] {
3936 flags = append(flags, vers.flag)
3937 }
3938
3939 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003940 protocols := []protocol{tls}
3941 if runnerVers.hasDTLS && shimVers.hasDTLS {
3942 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003943 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003944 for _, protocol := range protocols {
3945 expectedVersion := shimVers.version
3946 if runnerVers.version < shimVers.version {
3947 expectedVersion = runnerVers.version
3948 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003949
David Benjamin8b8c0062014-11-23 02:47:52 -05003950 suffix := shimVers.name + "-" + runnerVers.name
3951 if protocol == dtls {
3952 suffix += "-DTLS"
3953 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003954
David Benjamin1eb367c2014-12-12 18:17:51 -05003955 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3956
David Benjamin1e29a6b2014-12-10 02:27:24 -05003957 clientVers := shimVers.version
3958 if clientVers > VersionTLS10 {
3959 clientVers = VersionTLS10
3960 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003961 serverVers := expectedVersion
3962 if expectedVersion >= VersionTLS13 {
3963 serverVers = VersionTLS10
3964 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003965 testCases = append(testCases, testCase{
3966 protocol: protocol,
3967 testType: clientTest,
3968 name: "VersionNegotiation-Client-" + suffix,
3969 config: Config{
3970 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003971 Bugs: ProtocolBugs{
3972 ExpectInitialRecordVersion: clientVers,
3973 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003974 },
3975 flags: flags,
3976 expectedVersion: expectedVersion,
3977 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003978 testCases = append(testCases, testCase{
3979 protocol: protocol,
3980 testType: clientTest,
3981 name: "VersionNegotiation-Client2-" + suffix,
3982 config: Config{
3983 MaxVersion: runnerVers.version,
3984 Bugs: ProtocolBugs{
3985 ExpectInitialRecordVersion: clientVers,
3986 },
3987 },
3988 flags: []string{"-max-version", shimVersFlag},
3989 expectedVersion: expectedVersion,
3990 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003991
3992 testCases = append(testCases, testCase{
3993 protocol: protocol,
3994 testType: serverTest,
3995 name: "VersionNegotiation-Server-" + suffix,
3996 config: Config{
3997 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003998 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003999 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004000 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004001 },
4002 flags: flags,
4003 expectedVersion: expectedVersion,
4004 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004005 testCases = append(testCases, testCase{
4006 protocol: protocol,
4007 testType: serverTest,
4008 name: "VersionNegotiation-Server2-" + suffix,
4009 config: Config{
4010 MaxVersion: runnerVers.version,
4011 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004012 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004013 },
4014 },
4015 flags: []string{"-max-version", shimVersFlag},
4016 expectedVersion: expectedVersion,
4017 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004018 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004019 }
4020 }
David Benjamin95c69562016-06-29 18:15:03 -04004021
4022 // Test for version tolerance.
4023 testCases = append(testCases, testCase{
4024 testType: serverTest,
4025 name: "MinorVersionTolerance",
4026 config: Config{
4027 Bugs: ProtocolBugs{
4028 SendClientVersion: 0x03ff,
4029 },
4030 },
4031 expectedVersion: VersionTLS13,
4032 })
4033 testCases = append(testCases, testCase{
4034 testType: serverTest,
4035 name: "MajorVersionTolerance",
4036 config: Config{
4037 Bugs: ProtocolBugs{
4038 SendClientVersion: 0x0400,
4039 },
4040 },
4041 expectedVersion: VersionTLS13,
4042 })
4043 testCases = append(testCases, testCase{
4044 protocol: dtls,
4045 testType: serverTest,
4046 name: "MinorVersionTolerance-DTLS",
4047 config: Config{
4048 Bugs: ProtocolBugs{
4049 SendClientVersion: 0x03ff,
4050 },
4051 },
4052 expectedVersion: VersionTLS12,
4053 })
4054 testCases = append(testCases, testCase{
4055 protocol: dtls,
4056 testType: serverTest,
4057 name: "MajorVersionTolerance-DTLS",
4058 config: Config{
4059 Bugs: ProtocolBugs{
4060 SendClientVersion: 0x0400,
4061 },
4062 },
4063 expectedVersion: VersionTLS12,
4064 })
4065
4066 // Test that versions below 3.0 are rejected.
4067 testCases = append(testCases, testCase{
4068 testType: serverTest,
4069 name: "VersionTooLow",
4070 config: Config{
4071 Bugs: ProtocolBugs{
4072 SendClientVersion: 0x0200,
4073 },
4074 },
4075 shouldFail: true,
4076 expectedError: ":UNSUPPORTED_PROTOCOL:",
4077 })
4078 testCases = append(testCases, testCase{
4079 protocol: dtls,
4080 testType: serverTest,
4081 name: "VersionTooLow-DTLS",
4082 config: Config{
4083 Bugs: ProtocolBugs{
4084 // 0x0201 is the lowest version expressable in
4085 // DTLS.
4086 SendClientVersion: 0x0201,
4087 },
4088 },
4089 shouldFail: true,
4090 expectedError: ":UNSUPPORTED_PROTOCOL:",
4091 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004092
4093 // Test TLS 1.3's downgrade signal.
4094 testCases = append(testCases, testCase{
4095 name: "Downgrade-TLS12-Client",
4096 config: Config{
4097 Bugs: ProtocolBugs{
4098 NegotiateVersion: VersionTLS12,
4099 },
4100 },
4101 shouldFail: true,
4102 expectedError: ":DOWNGRADE_DETECTED:",
4103 })
4104 testCases = append(testCases, testCase{
4105 testType: serverTest,
4106 name: "Downgrade-TLS12-Server",
4107 config: Config{
4108 Bugs: ProtocolBugs{
4109 SendClientVersion: VersionTLS12,
4110 },
4111 },
4112 shouldFail: true,
4113 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4114 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004115
4116 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4117 // behave correctly when both real maximum and fallback versions are
4118 // set.
4119 testCases = append(testCases, testCase{
4120 name: "Downgrade-TLS12-Client-Fallback",
4121 config: Config{
4122 Bugs: ProtocolBugs{
4123 FailIfNotFallbackSCSV: true,
4124 },
4125 },
4126 flags: []string{
4127 "-max-version", strconv.Itoa(VersionTLS13),
4128 "-fallback-version", strconv.Itoa(VersionTLS12),
4129 },
4130 shouldFail: true,
4131 expectedError: ":DOWNGRADE_DETECTED:",
4132 })
4133 testCases = append(testCases, testCase{
4134 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4135 flags: []string{
4136 "-max-version", strconv.Itoa(VersionTLS12),
4137 "-fallback-version", strconv.Itoa(VersionTLS12),
4138 },
4139 })
4140
4141 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4142 // just have such connections fail than risk getting confused because we
4143 // didn't sent the 1.3 ClientHello.)
4144 testCases = append(testCases, testCase{
4145 name: "Downgrade-TLS12-Fallback-CheckVersion",
4146 config: Config{
4147 Bugs: ProtocolBugs{
4148 NegotiateVersion: VersionTLS13,
4149 FailIfNotFallbackSCSV: true,
4150 },
4151 },
4152 flags: []string{
4153 "-max-version", strconv.Itoa(VersionTLS13),
4154 "-fallback-version", strconv.Itoa(VersionTLS12),
4155 },
4156 shouldFail: true,
4157 expectedError: ":UNSUPPORTED_PROTOCOL:",
4158 })
4159
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004160}
4161
David Benjaminaccb4542014-12-12 23:44:33 -05004162func addMinimumVersionTests() {
4163 for i, shimVers := range tlsVersions {
4164 // Assemble flags to disable all older versions on the shim.
4165 var flags []string
4166 for _, vers := range tlsVersions[:i] {
4167 flags = append(flags, vers.flag)
4168 }
4169
4170 for _, runnerVers := range tlsVersions {
4171 protocols := []protocol{tls}
4172 if runnerVers.hasDTLS && shimVers.hasDTLS {
4173 protocols = append(protocols, dtls)
4174 }
4175 for _, protocol := range protocols {
4176 suffix := shimVers.name + "-" + runnerVers.name
4177 if protocol == dtls {
4178 suffix += "-DTLS"
4179 }
4180 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4181
David Benjaminaccb4542014-12-12 23:44:33 -05004182 var expectedVersion uint16
4183 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004184 var expectedClientError, expectedServerError string
4185 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004186 if runnerVers.version >= shimVers.version {
4187 expectedVersion = runnerVers.version
4188 } else {
4189 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004190 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4191 expectedServerLocalError = "remote error: protocol version not supported"
4192 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4193 // If the client's minimum version is TLS 1.3 and the runner's
4194 // maximum is below TLS 1.2, the runner will fail to select a
4195 // cipher before the shim rejects the selected version.
4196 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4197 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4198 } else {
4199 expectedClientError = expectedServerError
4200 expectedClientLocalError = expectedServerLocalError
4201 }
David Benjaminaccb4542014-12-12 23:44:33 -05004202 }
4203
4204 testCases = append(testCases, testCase{
4205 protocol: protocol,
4206 testType: clientTest,
4207 name: "MinimumVersion-Client-" + suffix,
4208 config: Config{
4209 MaxVersion: runnerVers.version,
4210 },
David Benjamin87909c02014-12-13 01:55:01 -05004211 flags: flags,
4212 expectedVersion: expectedVersion,
4213 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004214 expectedError: expectedClientError,
4215 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004216 })
4217 testCases = append(testCases, testCase{
4218 protocol: protocol,
4219 testType: clientTest,
4220 name: "MinimumVersion-Client2-" + suffix,
4221 config: Config{
4222 MaxVersion: runnerVers.version,
4223 },
David Benjamin87909c02014-12-13 01:55:01 -05004224 flags: []string{"-min-version", shimVersFlag},
4225 expectedVersion: expectedVersion,
4226 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004227 expectedError: expectedClientError,
4228 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004229 })
4230
4231 testCases = append(testCases, testCase{
4232 protocol: protocol,
4233 testType: serverTest,
4234 name: "MinimumVersion-Server-" + suffix,
4235 config: Config{
4236 MaxVersion: runnerVers.version,
4237 },
David Benjamin87909c02014-12-13 01:55:01 -05004238 flags: flags,
4239 expectedVersion: expectedVersion,
4240 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004241 expectedError: expectedServerError,
4242 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004243 })
4244 testCases = append(testCases, testCase{
4245 protocol: protocol,
4246 testType: serverTest,
4247 name: "MinimumVersion-Server2-" + suffix,
4248 config: Config{
4249 MaxVersion: runnerVers.version,
4250 },
David Benjamin87909c02014-12-13 01:55:01 -05004251 flags: []string{"-min-version", shimVersFlag},
4252 expectedVersion: expectedVersion,
4253 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004254 expectedError: expectedServerError,
4255 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004256 })
4257 }
4258 }
4259 }
4260}
4261
David Benjamine78bfde2014-09-06 12:45:15 -04004262func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004263 // TODO(davidben): Extensions, where applicable, all move their server
4264 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4265 // tests for both. Also test interaction with 0-RTT when implemented.
4266
David Benjamin97d17d92016-07-14 16:12:00 -04004267 // Repeat extensions tests all versions except SSL 3.0.
4268 for _, ver := range tlsVersions {
4269 if ver.version == VersionSSL30 {
4270 continue
4271 }
4272
David Benjamin97d17d92016-07-14 16:12:00 -04004273 // Test that duplicate extensions are rejected.
4274 testCases = append(testCases, testCase{
4275 testType: clientTest,
4276 name: "DuplicateExtensionClient-" + ver.name,
4277 config: Config{
4278 MaxVersion: ver.version,
4279 Bugs: ProtocolBugs{
4280 DuplicateExtension: true,
4281 },
David Benjamine78bfde2014-09-06 12:45:15 -04004282 },
David Benjamin97d17d92016-07-14 16:12:00 -04004283 shouldFail: true,
4284 expectedLocalError: "remote error: error decoding message",
4285 })
4286 testCases = append(testCases, testCase{
4287 testType: serverTest,
4288 name: "DuplicateExtensionServer-" + ver.name,
4289 config: Config{
4290 MaxVersion: ver.version,
4291 Bugs: ProtocolBugs{
4292 DuplicateExtension: true,
4293 },
David Benjamine78bfde2014-09-06 12:45:15 -04004294 },
David Benjamin97d17d92016-07-14 16:12:00 -04004295 shouldFail: true,
4296 expectedLocalError: "remote error: error decoding message",
4297 })
4298
4299 // Test SNI.
4300 testCases = append(testCases, testCase{
4301 testType: clientTest,
4302 name: "ServerNameExtensionClient-" + ver.name,
4303 config: Config{
4304 MaxVersion: ver.version,
4305 Bugs: ProtocolBugs{
4306 ExpectServerName: "example.com",
4307 },
David Benjamine78bfde2014-09-06 12:45:15 -04004308 },
David Benjamin97d17d92016-07-14 16:12:00 -04004309 flags: []string{"-host-name", "example.com"},
4310 })
4311 testCases = append(testCases, testCase{
4312 testType: clientTest,
4313 name: "ServerNameExtensionClientMismatch-" + ver.name,
4314 config: Config{
4315 MaxVersion: ver.version,
4316 Bugs: ProtocolBugs{
4317 ExpectServerName: "mismatch.com",
4318 },
David Benjamine78bfde2014-09-06 12:45:15 -04004319 },
David Benjamin97d17d92016-07-14 16:12:00 -04004320 flags: []string{"-host-name", "example.com"},
4321 shouldFail: true,
4322 expectedLocalError: "tls: unexpected server name",
4323 })
4324 testCases = append(testCases, testCase{
4325 testType: clientTest,
4326 name: "ServerNameExtensionClientMissing-" + ver.name,
4327 config: Config{
4328 MaxVersion: ver.version,
4329 Bugs: ProtocolBugs{
4330 ExpectServerName: "missing.com",
4331 },
David Benjamine78bfde2014-09-06 12:45:15 -04004332 },
David Benjamin97d17d92016-07-14 16:12:00 -04004333 shouldFail: true,
4334 expectedLocalError: "tls: unexpected server name",
4335 })
4336 testCases = append(testCases, testCase{
4337 testType: serverTest,
4338 name: "ServerNameExtensionServer-" + ver.name,
4339 config: Config{
4340 MaxVersion: ver.version,
4341 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004342 },
David Benjamin97d17d92016-07-14 16:12:00 -04004343 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004344 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004345 })
4346
4347 // Test ALPN.
4348 testCases = append(testCases, testCase{
4349 testType: clientTest,
4350 name: "ALPNClient-" + ver.name,
4351 config: Config{
4352 MaxVersion: ver.version,
4353 NextProtos: []string{"foo"},
4354 },
4355 flags: []string{
4356 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4357 "-expect-alpn", "foo",
4358 },
4359 expectedNextProto: "foo",
4360 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004361 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004362 })
4363 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004364 testType: clientTest,
4365 name: "ALPNClient-Mismatch-" + ver.name,
4366 config: Config{
4367 MaxVersion: ver.version,
4368 Bugs: ProtocolBugs{
4369 SendALPN: "baz",
4370 },
4371 },
4372 flags: []string{
4373 "-advertise-alpn", "\x03foo\x03bar",
4374 },
4375 shouldFail: true,
4376 expectedError: ":INVALID_ALPN_PROTOCOL:",
4377 expectedLocalError: "remote error: illegal parameter",
4378 })
4379 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004380 testType: serverTest,
4381 name: "ALPNServer-" + ver.name,
4382 config: Config{
4383 MaxVersion: ver.version,
4384 NextProtos: []string{"foo", "bar", "baz"},
4385 },
4386 flags: []string{
4387 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4388 "-select-alpn", "foo",
4389 },
4390 expectedNextProto: "foo",
4391 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004392 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004393 })
4394 testCases = append(testCases, testCase{
4395 testType: serverTest,
4396 name: "ALPNServer-Decline-" + ver.name,
4397 config: Config{
4398 MaxVersion: ver.version,
4399 NextProtos: []string{"foo", "bar", "baz"},
4400 },
4401 flags: []string{"-decline-alpn"},
4402 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004403 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004404 })
4405
David Benjamin25fe85b2016-08-09 20:00:32 -04004406 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4407 // called once.
4408 testCases = append(testCases, testCase{
4409 testType: serverTest,
4410 name: "ALPNServer-Async-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 NextProtos: []string{"foo", "bar", "baz"},
4414 },
4415 flags: []string{
4416 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4417 "-select-alpn", "foo",
4418 "-async",
4419 },
4420 expectedNextProto: "foo",
4421 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004422 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004423 })
4424
David Benjamin97d17d92016-07-14 16:12:00 -04004425 var emptyString string
4426 testCases = append(testCases, testCase{
4427 testType: clientTest,
4428 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4429 config: Config{
4430 MaxVersion: ver.version,
4431 NextProtos: []string{""},
4432 Bugs: ProtocolBugs{
4433 // A server returning an empty ALPN protocol
4434 // should be rejected.
4435 ALPNProtocol: &emptyString,
4436 },
4437 },
4438 flags: []string{
4439 "-advertise-alpn", "\x03foo",
4440 },
4441 shouldFail: true,
4442 expectedError: ":PARSE_TLSEXT:",
4443 })
4444 testCases = append(testCases, testCase{
4445 testType: serverTest,
4446 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4447 config: Config{
4448 MaxVersion: ver.version,
4449 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004450 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004451 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004452 },
David Benjamin97d17d92016-07-14 16:12:00 -04004453 flags: []string{
4454 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004455 },
David Benjamin97d17d92016-07-14 16:12:00 -04004456 shouldFail: true,
4457 expectedError: ":PARSE_TLSEXT:",
4458 })
4459
4460 // Test NPN and the interaction with ALPN.
4461 if ver.version < VersionTLS13 {
4462 // Test that the server prefers ALPN over NPN.
4463 testCases = append(testCases, testCase{
4464 testType: serverTest,
4465 name: "ALPNServer-Preferred-" + ver.name,
4466 config: Config{
4467 MaxVersion: ver.version,
4468 NextProtos: []string{"foo", "bar", "baz"},
4469 },
4470 flags: []string{
4471 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4472 "-select-alpn", "foo",
4473 "-advertise-npn", "\x03foo\x03bar\x03baz",
4474 },
4475 expectedNextProto: "foo",
4476 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004477 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004478 })
4479 testCases = append(testCases, testCase{
4480 testType: serverTest,
4481 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4482 config: Config{
4483 MaxVersion: ver.version,
4484 NextProtos: []string{"foo", "bar", "baz"},
4485 Bugs: ProtocolBugs{
4486 SwapNPNAndALPN: true,
4487 },
4488 },
4489 flags: []string{
4490 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4491 "-select-alpn", "foo",
4492 "-advertise-npn", "\x03foo\x03bar\x03baz",
4493 },
4494 expectedNextProto: "foo",
4495 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004496 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004497 })
4498
4499 // Test that negotiating both NPN and ALPN is forbidden.
4500 testCases = append(testCases, testCase{
4501 name: "NegotiateALPNAndNPN-" + ver.name,
4502 config: Config{
4503 MaxVersion: ver.version,
4504 NextProtos: []string{"foo", "bar", "baz"},
4505 Bugs: ProtocolBugs{
4506 NegotiateALPNAndNPN: true,
4507 },
4508 },
4509 flags: []string{
4510 "-advertise-alpn", "\x03foo",
4511 "-select-next-proto", "foo",
4512 },
4513 shouldFail: true,
4514 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4515 })
4516 testCases = append(testCases, testCase{
4517 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4518 config: Config{
4519 MaxVersion: ver.version,
4520 NextProtos: []string{"foo", "bar", "baz"},
4521 Bugs: ProtocolBugs{
4522 NegotiateALPNAndNPN: true,
4523 SwapNPNAndALPN: true,
4524 },
4525 },
4526 flags: []string{
4527 "-advertise-alpn", "\x03foo",
4528 "-select-next-proto", "foo",
4529 },
4530 shouldFail: true,
4531 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4532 })
4533
4534 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4535 testCases = append(testCases, testCase{
4536 name: "DisableNPN-" + ver.name,
4537 config: Config{
4538 MaxVersion: ver.version,
4539 NextProtos: []string{"foo"},
4540 },
4541 flags: []string{
4542 "-select-next-proto", "foo",
4543 "-disable-npn",
4544 },
4545 expectNoNextProto: true,
4546 })
4547 }
4548
4549 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004550
4551 // Resume with a corrupt ticket.
4552 testCases = append(testCases, testCase{
4553 testType: serverTest,
4554 name: "CorruptTicket-" + ver.name,
4555 config: Config{
4556 MaxVersion: ver.version,
4557 Bugs: ProtocolBugs{
4558 CorruptTicket: true,
4559 },
4560 },
4561 resumeSession: true,
4562 expectResumeRejected: true,
4563 })
4564 // Test the ticket callback, with and without renewal.
4565 testCases = append(testCases, testCase{
4566 testType: serverTest,
4567 name: "TicketCallback-" + ver.name,
4568 config: Config{
4569 MaxVersion: ver.version,
4570 },
4571 resumeSession: true,
4572 flags: []string{"-use-ticket-callback"},
4573 })
4574 testCases = append(testCases, testCase{
4575 testType: serverTest,
4576 name: "TicketCallback-Renew-" + ver.name,
4577 config: Config{
4578 MaxVersion: ver.version,
4579 Bugs: ProtocolBugs{
4580 ExpectNewTicket: true,
4581 },
4582 },
4583 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4584 resumeSession: true,
4585 })
4586
4587 // Test that the ticket callback is only called once when everything before
4588 // it in the ClientHello is asynchronous. This corrupts the ticket so
4589 // certificate selection callbacks run.
4590 testCases = append(testCases, testCase{
4591 testType: serverTest,
4592 name: "TicketCallback-SingleCall-" + ver.name,
4593 config: Config{
4594 MaxVersion: ver.version,
4595 Bugs: ProtocolBugs{
4596 CorruptTicket: true,
4597 },
4598 },
4599 resumeSession: true,
4600 expectResumeRejected: true,
4601 flags: []string{
4602 "-use-ticket-callback",
4603 "-async",
4604 },
4605 })
4606
4607 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004608 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004609 testCases = append(testCases, testCase{
4610 testType: serverTest,
4611 name: "OversizedSessionId-" + ver.name,
4612 config: Config{
4613 MaxVersion: ver.version,
4614 Bugs: ProtocolBugs{
4615 OversizedSessionId: true,
4616 },
4617 },
4618 resumeSession: true,
4619 shouldFail: true,
4620 expectedError: ":DECODE_ERROR:",
4621 })
4622 }
4623
4624 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4625 // are ignored.
4626 if ver.hasDTLS {
4627 testCases = append(testCases, testCase{
4628 protocol: dtls,
4629 name: "SRTP-Client-" + ver.name,
4630 config: Config{
4631 MaxVersion: ver.version,
4632 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4633 },
4634 flags: []string{
4635 "-srtp-profiles",
4636 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4637 },
4638 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4639 })
4640 testCases = append(testCases, testCase{
4641 protocol: dtls,
4642 testType: serverTest,
4643 name: "SRTP-Server-" + ver.name,
4644 config: Config{
4645 MaxVersion: ver.version,
4646 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4647 },
4648 flags: []string{
4649 "-srtp-profiles",
4650 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4651 },
4652 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4653 })
4654 // Test that the MKI is ignored.
4655 testCases = append(testCases, testCase{
4656 protocol: dtls,
4657 testType: serverTest,
4658 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4659 config: Config{
4660 MaxVersion: ver.version,
4661 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4662 Bugs: ProtocolBugs{
4663 SRTPMasterKeyIdentifer: "bogus",
4664 },
4665 },
4666 flags: []string{
4667 "-srtp-profiles",
4668 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4669 },
4670 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4671 })
4672 // Test that SRTP isn't negotiated on the server if there were
4673 // no matching profiles.
4674 testCases = append(testCases, testCase{
4675 protocol: dtls,
4676 testType: serverTest,
4677 name: "SRTP-Server-NoMatch-" + ver.name,
4678 config: Config{
4679 MaxVersion: ver.version,
4680 SRTPProtectionProfiles: []uint16{100, 101, 102},
4681 },
4682 flags: []string{
4683 "-srtp-profiles",
4684 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4685 },
4686 expectedSRTPProtectionProfile: 0,
4687 })
4688 // Test that the server returning an invalid SRTP profile is
4689 // flagged as an error by the client.
4690 testCases = append(testCases, testCase{
4691 protocol: dtls,
4692 name: "SRTP-Client-NoMatch-" + ver.name,
4693 config: Config{
4694 MaxVersion: ver.version,
4695 Bugs: ProtocolBugs{
4696 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4697 },
4698 },
4699 flags: []string{
4700 "-srtp-profiles",
4701 "SRTP_AES128_CM_SHA1_80",
4702 },
4703 shouldFail: true,
4704 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4705 })
4706 }
4707
4708 // Test SCT list.
4709 testCases = append(testCases, testCase{
4710 name: "SignedCertificateTimestampList-Client-" + ver.name,
4711 testType: clientTest,
4712 config: Config{
4713 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004714 },
David Benjamin97d17d92016-07-14 16:12:00 -04004715 flags: []string{
4716 "-enable-signed-cert-timestamps",
4717 "-expect-signed-cert-timestamps",
4718 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004719 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004720 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004721 })
4722 testCases = append(testCases, testCase{
4723 name: "SendSCTListOnResume-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 Bugs: ProtocolBugs{
4727 SendSCTListOnResume: []byte("bogus"),
4728 },
David Benjamind98452d2015-06-16 14:16:23 -04004729 },
David Benjamin97d17d92016-07-14 16:12:00 -04004730 flags: []string{
4731 "-enable-signed-cert-timestamps",
4732 "-expect-signed-cert-timestamps",
4733 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004734 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004735 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004736 })
4737 testCases = append(testCases, testCase{
4738 name: "SignedCertificateTimestampList-Server-" + ver.name,
4739 testType: serverTest,
4740 config: Config{
4741 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004742 },
David Benjamin97d17d92016-07-14 16:12:00 -04004743 flags: []string{
4744 "-signed-cert-timestamps",
4745 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004746 },
David Benjamin97d17d92016-07-14 16:12:00 -04004747 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004748 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004749 })
4750 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004751
Paul Lietar4fac72e2015-09-09 13:44:55 +01004752 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004753 testType: clientTest,
4754 name: "ClientHelloPadding",
4755 config: Config{
4756 Bugs: ProtocolBugs{
4757 RequireClientHelloSize: 512,
4758 },
4759 },
4760 // This hostname just needs to be long enough to push the
4761 // ClientHello into F5's danger zone between 256 and 511 bytes
4762 // long.
4763 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4764 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004765
4766 // Extensions should not function in SSL 3.0.
4767 testCases = append(testCases, testCase{
4768 testType: serverTest,
4769 name: "SSLv3Extensions-NoALPN",
4770 config: Config{
4771 MaxVersion: VersionSSL30,
4772 NextProtos: []string{"foo", "bar", "baz"},
4773 },
4774 flags: []string{
4775 "-select-alpn", "foo",
4776 },
4777 expectNoNextProto: true,
4778 })
4779
4780 // Test session tickets separately as they follow a different codepath.
4781 testCases = append(testCases, testCase{
4782 testType: serverTest,
4783 name: "SSLv3Extensions-NoTickets",
4784 config: Config{
4785 MaxVersion: VersionSSL30,
4786 Bugs: ProtocolBugs{
4787 // Historically, session tickets in SSL 3.0
4788 // failed in different ways depending on whether
4789 // the client supported renegotiation_info.
4790 NoRenegotiationInfo: true,
4791 },
4792 },
4793 resumeSession: true,
4794 })
4795 testCases = append(testCases, testCase{
4796 testType: serverTest,
4797 name: "SSLv3Extensions-NoTickets2",
4798 config: Config{
4799 MaxVersion: VersionSSL30,
4800 },
4801 resumeSession: true,
4802 })
4803
4804 // But SSL 3.0 does send and process renegotiation_info.
4805 testCases = append(testCases, testCase{
4806 testType: serverTest,
4807 name: "SSLv3Extensions-RenegotiationInfo",
4808 config: Config{
4809 MaxVersion: VersionSSL30,
4810 Bugs: ProtocolBugs{
4811 RequireRenegotiationInfo: true,
4812 },
4813 },
4814 })
4815 testCases = append(testCases, testCase{
4816 testType: serverTest,
4817 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4818 config: Config{
4819 MaxVersion: VersionSSL30,
4820 Bugs: ProtocolBugs{
4821 NoRenegotiationInfo: true,
4822 SendRenegotiationSCSV: true,
4823 RequireRenegotiationInfo: true,
4824 },
4825 },
4826 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004827
4828 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4829 // in ServerHello.
4830 testCases = append(testCases, testCase{
4831 name: "NPN-Forbidden-TLS13",
4832 config: Config{
4833 MaxVersion: VersionTLS13,
4834 NextProtos: []string{"foo"},
4835 Bugs: ProtocolBugs{
4836 NegotiateNPNAtAllVersions: true,
4837 },
4838 },
4839 flags: []string{"-select-next-proto", "foo"},
4840 shouldFail: true,
4841 expectedError: ":ERROR_PARSING_EXTENSION:",
4842 })
4843 testCases = append(testCases, testCase{
4844 name: "EMS-Forbidden-TLS13",
4845 config: Config{
4846 MaxVersion: VersionTLS13,
4847 Bugs: ProtocolBugs{
4848 NegotiateEMSAtAllVersions: true,
4849 },
4850 },
4851 shouldFail: true,
4852 expectedError: ":ERROR_PARSING_EXTENSION:",
4853 })
4854 testCases = append(testCases, testCase{
4855 name: "RenegotiationInfo-Forbidden-TLS13",
4856 config: Config{
4857 MaxVersion: VersionTLS13,
4858 Bugs: ProtocolBugs{
4859 NegotiateRenegotiationInfoAtAllVersions: true,
4860 },
4861 },
4862 shouldFail: true,
4863 expectedError: ":ERROR_PARSING_EXTENSION:",
4864 })
4865 testCases = append(testCases, testCase{
4866 name: "ChannelID-Forbidden-TLS13",
4867 config: Config{
4868 MaxVersion: VersionTLS13,
4869 RequestChannelID: true,
4870 Bugs: ProtocolBugs{
4871 NegotiateChannelIDAtAllVersions: true,
4872 },
4873 },
4874 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4875 shouldFail: true,
4876 expectedError: ":ERROR_PARSING_EXTENSION:",
4877 })
4878 testCases = append(testCases, testCase{
4879 name: "Ticket-Forbidden-TLS13",
4880 config: Config{
4881 MaxVersion: VersionTLS12,
4882 },
4883 resumeConfig: &Config{
4884 MaxVersion: VersionTLS13,
4885 Bugs: ProtocolBugs{
4886 AdvertiseTicketExtension: true,
4887 },
4888 },
4889 resumeSession: true,
4890 shouldFail: true,
4891 expectedError: ":ERROR_PARSING_EXTENSION:",
4892 })
4893
4894 // Test that illegal extensions in TLS 1.3 are declined by the server if
4895 // offered in ClientHello. The runner's server will fail if this occurs,
4896 // so we exercise the offering path. (EMS and Renegotiation Info are
4897 // implicit in every test.)
4898 testCases = append(testCases, testCase{
4899 testType: serverTest,
4900 name: "ChannelID-Declined-TLS13",
4901 config: Config{
4902 MaxVersion: VersionTLS13,
4903 ChannelID: channelIDKey,
4904 },
4905 flags: []string{"-enable-channel-id"},
4906 })
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "NPN-Server",
4910 config: Config{
4911 MaxVersion: VersionTLS13,
4912 NextProtos: []string{"bar"},
4913 },
4914 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4915 })
David Benjamine78bfde2014-09-06 12:45:15 -04004916}
4917
David Benjamin01fe8202014-09-24 15:21:44 -04004918func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004919 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004920 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004921 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4922 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4923 // TLS 1.3 only shares ciphers with TLS 1.2, so
4924 // we skip certain combinations and use a
4925 // different cipher to test with.
4926 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4927 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4928 continue
4929 }
4930 }
4931
David Benjamin8b8c0062014-11-23 02:47:52 -05004932 protocols := []protocol{tls}
4933 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4934 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004935 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004936 for _, protocol := range protocols {
4937 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4938 if protocol == dtls {
4939 suffix += "-DTLS"
4940 }
4941
David Benjaminece3de92015-03-16 18:02:20 -04004942 if sessionVers.version == resumeVers.version {
4943 testCases = append(testCases, testCase{
4944 protocol: protocol,
4945 name: "Resume-Client" + suffix,
4946 resumeSession: true,
4947 config: Config{
4948 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004949 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004950 Bugs: ProtocolBugs{
4951 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4952 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4953 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004954 },
David Benjaminece3de92015-03-16 18:02:20 -04004955 expectedVersion: sessionVers.version,
4956 expectedResumeVersion: resumeVers.version,
4957 })
4958 } else {
David Benjamin405da482016-08-08 17:25:07 -04004959 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4960
4961 // Offering a TLS 1.3 session sends an empty session ID, so
4962 // there is no way to convince a non-lookahead client the
4963 // session was resumed. It will appear to the client that a
4964 // stray ChangeCipherSpec was sent.
4965 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4966 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004967 }
4968
David Benjaminece3de92015-03-16 18:02:20 -04004969 testCases = append(testCases, testCase{
4970 protocol: protocol,
4971 name: "Resume-Client-Mismatch" + suffix,
4972 resumeSession: true,
4973 config: Config{
4974 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004975 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004976 },
David Benjaminece3de92015-03-16 18:02:20 -04004977 expectedVersion: sessionVers.version,
4978 resumeConfig: &Config{
4979 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004980 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004981 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004982 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004983 },
4984 },
4985 expectedResumeVersion: resumeVers.version,
4986 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004987 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004988 })
4989 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004990
4991 testCases = append(testCases, testCase{
4992 protocol: protocol,
4993 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004994 resumeSession: true,
4995 config: Config{
4996 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004997 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004998 },
4999 expectedVersion: sessionVers.version,
5000 resumeConfig: &Config{
5001 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005002 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005003 },
5004 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005005 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005006 expectedResumeVersion: resumeVers.version,
5007 })
5008
David Benjamin8b8c0062014-11-23 02:47:52 -05005009 testCases = append(testCases, testCase{
5010 protocol: protocol,
5011 testType: serverTest,
5012 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005013 resumeSession: true,
5014 config: Config{
5015 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005016 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005017 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005018 expectedVersion: sessionVers.version,
5019 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005020 resumeConfig: &Config{
5021 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005022 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005023 Bugs: ProtocolBugs{
5024 SendBothTickets: true,
5025 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005026 },
5027 expectedResumeVersion: resumeVers.version,
5028 })
5029 }
David Benjamin01fe8202014-09-24 15:21:44 -04005030 }
5031 }
David Benjaminece3de92015-03-16 18:02:20 -04005032
5033 testCases = append(testCases, testCase{
5034 name: "Resume-Client-CipherMismatch",
5035 resumeSession: true,
5036 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005037 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005038 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5039 },
5040 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005041 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005042 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5043 Bugs: ProtocolBugs{
5044 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5045 },
5046 },
5047 shouldFail: true,
5048 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5049 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005050
5051 testCases = append(testCases, testCase{
5052 name: "Resume-Client-CipherMismatch-TLS13",
5053 resumeSession: true,
5054 config: Config{
5055 MaxVersion: VersionTLS13,
5056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5057 },
5058 resumeConfig: &Config{
5059 MaxVersion: VersionTLS13,
5060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5061 Bugs: ProtocolBugs{
5062 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5063 },
5064 },
5065 shouldFail: true,
5066 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5067 })
David Benjamin01fe8202014-09-24 15:21:44 -04005068}
5069
Adam Langley2ae77d22014-10-28 17:29:33 -07005070func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005071 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005072 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005073 testType: serverTest,
5074 name: "Renegotiate-Server-Forbidden",
5075 config: Config{
5076 MaxVersion: VersionTLS12,
5077 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005078 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005079 shouldFail: true,
5080 expectedError: ":NO_RENEGOTIATION:",
5081 expectedLocalError: "remote error: no renegotiation",
5082 })
Adam Langley5021b222015-06-12 18:27:58 -07005083 // The server shouldn't echo the renegotiation extension unless
5084 // requested by the client.
5085 testCases = append(testCases, testCase{
5086 testType: serverTest,
5087 name: "Renegotiate-Server-NoExt",
5088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005089 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005090 Bugs: ProtocolBugs{
5091 NoRenegotiationInfo: true,
5092 RequireRenegotiationInfo: true,
5093 },
5094 },
5095 shouldFail: true,
5096 expectedLocalError: "renegotiation extension missing",
5097 })
5098 // The renegotiation SCSV should be sufficient for the server to echo
5099 // the extension.
5100 testCases = append(testCases, testCase{
5101 testType: serverTest,
5102 name: "Renegotiate-Server-NoExt-SCSV",
5103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005104 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005105 Bugs: ProtocolBugs{
5106 NoRenegotiationInfo: true,
5107 SendRenegotiationSCSV: true,
5108 RequireRenegotiationInfo: true,
5109 },
5110 },
5111 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005112 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005113 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005115 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005116 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005117 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005118 },
5119 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005120 renegotiate: 1,
5121 flags: []string{
5122 "-renegotiate-freely",
5123 "-expect-total-renegotiations", "1",
5124 },
David Benjamincdea40c2015-03-19 14:09:43 -04005125 })
5126 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005127 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005128 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005130 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005131 Bugs: ProtocolBugs{
5132 EmptyRenegotiationInfo: true,
5133 },
5134 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005135 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005136 shouldFail: true,
5137 expectedError: ":RENEGOTIATION_MISMATCH:",
5138 })
5139 testCases = append(testCases, testCase{
5140 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005141 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005143 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005144 Bugs: ProtocolBugs{
5145 BadRenegotiationInfo: true,
5146 },
5147 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005148 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005149 shouldFail: true,
5150 expectedError: ":RENEGOTIATION_MISMATCH:",
5151 })
5152 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005153 name: "Renegotiate-Client-Downgrade",
5154 renegotiate: 1,
5155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005156 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005157 Bugs: ProtocolBugs{
5158 NoRenegotiationInfoAfterInitial: true,
5159 },
5160 },
5161 flags: []string{"-renegotiate-freely"},
5162 shouldFail: true,
5163 expectedError: ":RENEGOTIATION_MISMATCH:",
5164 })
5165 testCases = append(testCases, testCase{
5166 name: "Renegotiate-Client-Upgrade",
5167 renegotiate: 1,
5168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005169 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005170 Bugs: ProtocolBugs{
5171 NoRenegotiationInfoInInitial: true,
5172 },
5173 },
5174 flags: []string{"-renegotiate-freely"},
5175 shouldFail: true,
5176 expectedError: ":RENEGOTIATION_MISMATCH:",
5177 })
5178 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005179 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005180 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005182 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005183 Bugs: ProtocolBugs{
5184 NoRenegotiationInfo: true,
5185 },
5186 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005187 flags: []string{
5188 "-renegotiate-freely",
5189 "-expect-total-renegotiations", "1",
5190 },
David Benjamincff0b902015-05-15 23:09:47 -04005191 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005192
5193 // Test that the server may switch ciphers on renegotiation without
5194 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005195 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005196 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005197 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005199 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005200 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005201 },
5202 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005203 flags: []string{
5204 "-renegotiate-freely",
5205 "-expect-total-renegotiations", "1",
5206 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005207 })
5208 testCases = append(testCases, testCase{
5209 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005210 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005211 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005212 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005213 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5214 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005215 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005216 flags: []string{
5217 "-renegotiate-freely",
5218 "-expect-total-renegotiations", "1",
5219 },
David Benjaminb16346b2015-04-08 19:16:58 -04005220 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005221
5222 // Test that the server may not switch versions on renegotiation.
5223 testCases = append(testCases, testCase{
5224 name: "Renegotiate-Client-SwitchVersion",
5225 config: Config{
5226 MaxVersion: VersionTLS12,
5227 // Pick a cipher which exists at both versions.
5228 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5229 Bugs: ProtocolBugs{
5230 NegotiateVersionOnRenego: VersionTLS11,
5231 },
5232 },
5233 renegotiate: 1,
5234 flags: []string{
5235 "-renegotiate-freely",
5236 "-expect-total-renegotiations", "1",
5237 },
5238 shouldFail: true,
5239 expectedError: ":WRONG_SSL_VERSION:",
5240 })
5241
David Benjaminb16346b2015-04-08 19:16:58 -04005242 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005243 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005244 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005245 config: Config{
5246 MaxVersion: VersionTLS10,
5247 Bugs: ProtocolBugs{
5248 RequireSameRenegoClientVersion: true,
5249 },
5250 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005251 flags: []string{
5252 "-renegotiate-freely",
5253 "-expect-total-renegotiations", "1",
5254 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005255 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005256 testCases = append(testCases, testCase{
5257 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005258 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005259 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005260 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005261 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5262 NextProtos: []string{"foo"},
5263 },
5264 flags: []string{
5265 "-false-start",
5266 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005267 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005268 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005269 },
5270 shimWritesFirst: true,
5271 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005272
5273 // Client-side renegotiation controls.
5274 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005275 name: "Renegotiate-Client-Forbidden-1",
5276 config: Config{
5277 MaxVersion: VersionTLS12,
5278 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005279 renegotiate: 1,
5280 shouldFail: true,
5281 expectedError: ":NO_RENEGOTIATION:",
5282 expectedLocalError: "remote error: no renegotiation",
5283 })
5284 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005285 name: "Renegotiate-Client-Once-1",
5286 config: Config{
5287 MaxVersion: VersionTLS12,
5288 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005289 renegotiate: 1,
5290 flags: []string{
5291 "-renegotiate-once",
5292 "-expect-total-renegotiations", "1",
5293 },
5294 })
5295 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005296 name: "Renegotiate-Client-Freely-1",
5297 config: Config{
5298 MaxVersion: VersionTLS12,
5299 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005300 renegotiate: 1,
5301 flags: []string{
5302 "-renegotiate-freely",
5303 "-expect-total-renegotiations", "1",
5304 },
5305 })
5306 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005307 name: "Renegotiate-Client-Once-2",
5308 config: Config{
5309 MaxVersion: VersionTLS12,
5310 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005311 renegotiate: 2,
5312 flags: []string{"-renegotiate-once"},
5313 shouldFail: true,
5314 expectedError: ":NO_RENEGOTIATION:",
5315 expectedLocalError: "remote error: no renegotiation",
5316 })
5317 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005318 name: "Renegotiate-Client-Freely-2",
5319 config: Config{
5320 MaxVersion: VersionTLS12,
5321 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005322 renegotiate: 2,
5323 flags: []string{
5324 "-renegotiate-freely",
5325 "-expect-total-renegotiations", "2",
5326 },
5327 })
Adam Langley27a0d082015-11-03 13:34:10 -08005328 testCases = append(testCases, testCase{
5329 name: "Renegotiate-Client-NoIgnore",
5330 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005331 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005332 Bugs: ProtocolBugs{
5333 SendHelloRequestBeforeEveryAppDataRecord: true,
5334 },
5335 },
5336 shouldFail: true,
5337 expectedError: ":NO_RENEGOTIATION:",
5338 })
5339 testCases = append(testCases, testCase{
5340 name: "Renegotiate-Client-Ignore",
5341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005342 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005343 Bugs: ProtocolBugs{
5344 SendHelloRequestBeforeEveryAppDataRecord: true,
5345 },
5346 },
5347 flags: []string{
5348 "-renegotiate-ignore",
5349 "-expect-total-renegotiations", "0",
5350 },
5351 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005352
David Benjamin397c8e62016-07-08 14:14:36 -07005353 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005354 testCases = append(testCases, testCase{
5355 name: "StrayHelloRequest",
5356 config: Config{
5357 MaxVersion: VersionTLS12,
5358 Bugs: ProtocolBugs{
5359 SendHelloRequestBeforeEveryHandshakeMessage: true,
5360 },
5361 },
5362 })
5363 testCases = append(testCases, testCase{
5364 name: "StrayHelloRequest-Packed",
5365 config: Config{
5366 MaxVersion: VersionTLS12,
5367 Bugs: ProtocolBugs{
5368 PackHandshakeFlight: true,
5369 SendHelloRequestBeforeEveryHandshakeMessage: true,
5370 },
5371 },
5372 })
5373
David Benjamin12d2c482016-07-24 10:56:51 -04005374 // Test renegotiation works if HelloRequest and server Finished come in
5375 // the same record.
5376 testCases = append(testCases, testCase{
5377 name: "Renegotiate-Client-Packed",
5378 config: Config{
5379 MaxVersion: VersionTLS12,
5380 Bugs: ProtocolBugs{
5381 PackHandshakeFlight: true,
5382 PackHelloRequestWithFinished: true,
5383 },
5384 },
5385 renegotiate: 1,
5386 flags: []string{
5387 "-renegotiate-freely",
5388 "-expect-total-renegotiations", "1",
5389 },
5390 })
5391
David Benjamin397c8e62016-07-08 14:14:36 -07005392 // Renegotiation is forbidden in TLS 1.3.
5393 testCases = append(testCases, testCase{
5394 name: "Renegotiate-Client-TLS13",
5395 config: Config{
5396 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005397 Bugs: ProtocolBugs{
5398 SendHelloRequestBeforeEveryAppDataRecord: true,
5399 },
David Benjamin397c8e62016-07-08 14:14:36 -07005400 },
David Benjamin397c8e62016-07-08 14:14:36 -07005401 flags: []string{
5402 "-renegotiate-freely",
5403 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005404 shouldFail: true,
5405 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005406 })
5407
5408 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5409 testCases = append(testCases, testCase{
5410 name: "StrayHelloRequest-TLS13",
5411 config: Config{
5412 MaxVersion: VersionTLS13,
5413 Bugs: ProtocolBugs{
5414 SendHelloRequestBeforeEveryHandshakeMessage: true,
5415 },
5416 },
5417 shouldFail: true,
5418 expectedError: ":UNEXPECTED_MESSAGE:",
5419 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005420}
5421
David Benjamin5e961c12014-11-07 01:48:35 -05005422func addDTLSReplayTests() {
5423 // Test that sequence number replays are detected.
5424 testCases = append(testCases, testCase{
5425 protocol: dtls,
5426 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005427 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005428 replayWrites: true,
5429 })
5430
David Benjamin8e6db492015-07-25 18:29:23 -04005431 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005432 // than the retransmit window.
5433 testCases = append(testCases, testCase{
5434 protocol: dtls,
5435 name: "DTLS-Replay-LargeGaps",
5436 config: Config{
5437 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005438 SequenceNumberMapping: func(in uint64) uint64 {
5439 return in * 127
5440 },
David Benjamin5e961c12014-11-07 01:48:35 -05005441 },
5442 },
David Benjamin8e6db492015-07-25 18:29:23 -04005443 messageCount: 200,
5444 replayWrites: true,
5445 })
5446
5447 // Test the incoming sequence number changing non-monotonically.
5448 testCases = append(testCases, testCase{
5449 protocol: dtls,
5450 name: "DTLS-Replay-NonMonotonic",
5451 config: Config{
5452 Bugs: ProtocolBugs{
5453 SequenceNumberMapping: func(in uint64) uint64 {
5454 return in ^ 31
5455 },
5456 },
5457 },
5458 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005459 replayWrites: true,
5460 })
5461}
5462
Nick Harper60edffd2016-06-21 15:19:24 -07005463var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005464 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005465 id signatureAlgorithm
5466 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005467}{
Nick Harper60edffd2016-06-21 15:19:24 -07005468 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5469 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5470 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5471 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005472 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005473 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5474 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5475 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005476 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5477 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5478 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005479 // Tests for key types prior to TLS 1.2.
5480 {"RSA", 0, testCertRSA},
5481 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005482}
5483
Nick Harper60edffd2016-06-21 15:19:24 -07005484const fakeSigAlg1 signatureAlgorithm = 0x2a01
5485const fakeSigAlg2 signatureAlgorithm = 0xff01
5486
5487func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005488 // Not all ciphers involve a signature. Advertise a list which gives all
5489 // versions a signing cipher.
5490 signingCiphers := []uint16{
5491 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5492 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5493 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5494 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5495 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5496 }
5497
David Benjaminca3d5452016-07-14 12:51:01 -04005498 var allAlgorithms []signatureAlgorithm
5499 for _, alg := range testSignatureAlgorithms {
5500 if alg.id != 0 {
5501 allAlgorithms = append(allAlgorithms, alg.id)
5502 }
5503 }
5504
Nick Harper60edffd2016-06-21 15:19:24 -07005505 // Make sure each signature algorithm works. Include some fake values in
5506 // the list and ensure they're ignored.
5507 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005508 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005509 if (ver.version < VersionTLS12) != (alg.id == 0) {
5510 continue
5511 }
5512
5513 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5514 // or remove it in C.
5515 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005516 continue
5517 }
Nick Harper60edffd2016-06-21 15:19:24 -07005518
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005519 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005520 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005521 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5522 shouldFail = true
5523 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005524 // RSA-PKCS1 does not exist in TLS 1.3.
5525 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5526 shouldFail = true
5527 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005528
5529 var signError, verifyError string
5530 if shouldFail {
5531 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5532 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005533 }
David Benjamin000800a2014-11-14 01:43:59 -05005534
David Benjamin1fb125c2016-07-08 18:52:12 -07005535 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005536
David Benjamin7a41d372016-07-09 11:21:54 -07005537 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005538 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005539 config: Config{
5540 MaxVersion: ver.version,
5541 ClientAuth: RequireAnyClientCert,
5542 VerifySignatureAlgorithms: []signatureAlgorithm{
5543 fakeSigAlg1,
5544 alg.id,
5545 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005546 },
David Benjamin7a41d372016-07-09 11:21:54 -07005547 },
5548 flags: []string{
5549 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5550 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5551 "-enable-all-curves",
5552 },
5553 shouldFail: shouldFail,
5554 expectedError: signError,
5555 expectedPeerSignatureAlgorithm: alg.id,
5556 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005557
David Benjamin7a41d372016-07-09 11:21:54 -07005558 testCases = append(testCases, testCase{
5559 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005560 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005561 config: Config{
5562 MaxVersion: ver.version,
5563 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5564 SignSignatureAlgorithms: []signatureAlgorithm{
5565 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005566 },
David Benjamin7a41d372016-07-09 11:21:54 -07005567 Bugs: ProtocolBugs{
5568 SkipECDSACurveCheck: shouldFail,
5569 IgnoreSignatureVersionChecks: shouldFail,
5570 // The client won't advertise 1.3-only algorithms after
5571 // version negotiation.
5572 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005573 },
David Benjamin7a41d372016-07-09 11:21:54 -07005574 },
5575 flags: []string{
5576 "-require-any-client-certificate",
5577 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5578 "-enable-all-curves",
5579 },
5580 shouldFail: shouldFail,
5581 expectedError: verifyError,
5582 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005583
5584 testCases = append(testCases, testCase{
5585 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005586 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005587 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005588 MaxVersion: ver.version,
5589 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005590 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005591 fakeSigAlg1,
5592 alg.id,
5593 fakeSigAlg2,
5594 },
5595 },
5596 flags: []string{
5597 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5598 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5599 "-enable-all-curves",
5600 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005601 shouldFail: shouldFail,
5602 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005603 expectedPeerSignatureAlgorithm: alg.id,
5604 })
5605
5606 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005607 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005608 config: Config{
5609 MaxVersion: ver.version,
5610 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005611 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005612 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005613 alg.id,
5614 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005615 Bugs: ProtocolBugs{
5616 SkipECDSACurveCheck: shouldFail,
5617 IgnoreSignatureVersionChecks: shouldFail,
5618 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005619 },
5620 flags: []string{
5621 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5622 "-enable-all-curves",
5623 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005624 shouldFail: shouldFail,
5625 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005626 })
David Benjamin5208fd42016-07-13 21:43:25 -04005627
5628 if !shouldFail {
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "ClientAuth-InvalidSignature" + suffix,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5635 SignSignatureAlgorithms: []signatureAlgorithm{
5636 alg.id,
5637 },
5638 Bugs: ProtocolBugs{
5639 InvalidSignature: true,
5640 },
5641 },
5642 flags: []string{
5643 "-require-any-client-certificate",
5644 "-enable-all-curves",
5645 },
5646 shouldFail: true,
5647 expectedError: ":BAD_SIGNATURE:",
5648 })
5649
5650 testCases = append(testCases, testCase{
5651 name: "ServerAuth-InvalidSignature" + suffix,
5652 config: Config{
5653 MaxVersion: ver.version,
5654 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5655 CipherSuites: signingCiphers,
5656 SignSignatureAlgorithms: []signatureAlgorithm{
5657 alg.id,
5658 },
5659 Bugs: ProtocolBugs{
5660 InvalidSignature: true,
5661 },
5662 },
5663 flags: []string{"-enable-all-curves"},
5664 shouldFail: true,
5665 expectedError: ":BAD_SIGNATURE:",
5666 })
5667 }
David Benjaminca3d5452016-07-14 12:51:01 -04005668
5669 if ver.version >= VersionTLS12 && !shouldFail {
5670 testCases = append(testCases, testCase{
5671 name: "ClientAuth-Sign-Negotiate" + suffix,
5672 config: Config{
5673 MaxVersion: ver.version,
5674 ClientAuth: RequireAnyClientCert,
5675 VerifySignatureAlgorithms: allAlgorithms,
5676 },
5677 flags: []string{
5678 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5679 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5680 "-enable-all-curves",
5681 "-signing-prefs", strconv.Itoa(int(alg.id)),
5682 },
5683 expectedPeerSignatureAlgorithm: alg.id,
5684 })
5685
5686 testCases = append(testCases, testCase{
5687 testType: serverTest,
5688 name: "ServerAuth-Sign-Negotiate" + suffix,
5689 config: Config{
5690 MaxVersion: ver.version,
5691 CipherSuites: signingCiphers,
5692 VerifySignatureAlgorithms: allAlgorithms,
5693 },
5694 flags: []string{
5695 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5696 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5697 "-enable-all-curves",
5698 "-signing-prefs", strconv.Itoa(int(alg.id)),
5699 },
5700 expectedPeerSignatureAlgorithm: alg.id,
5701 })
5702 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005703 }
David Benjamin000800a2014-11-14 01:43:59 -05005704 }
5705
Nick Harper60edffd2016-06-21 15:19:24 -07005706 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005707 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005708 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005709 config: Config{
5710 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005711 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005712 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005713 signatureECDSAWithP521AndSHA512,
5714 signatureRSAPKCS1WithSHA384,
5715 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005716 },
5717 },
5718 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005719 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5720 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005721 },
Nick Harper60edffd2016-06-21 15:19:24 -07005722 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005723 })
5724
5725 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005726 name: "ClientAuth-SignatureType-TLS13",
5727 config: Config{
5728 ClientAuth: RequireAnyClientCert,
5729 MaxVersion: VersionTLS13,
5730 VerifySignatureAlgorithms: []signatureAlgorithm{
5731 signatureECDSAWithP521AndSHA512,
5732 signatureRSAPKCS1WithSHA384,
5733 signatureRSAPSSWithSHA384,
5734 signatureECDSAWithSHA1,
5735 },
5736 },
5737 flags: []string{
5738 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5739 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5740 },
5741 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5742 })
5743
5744 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005745 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005746 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005748 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005749 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005750 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005751 signatureECDSAWithP521AndSHA512,
5752 signatureRSAPKCS1WithSHA384,
5753 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005754 },
5755 },
Nick Harper60edffd2016-06-21 15:19:24 -07005756 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005757 })
5758
Steven Valdez143e8b32016-07-11 13:19:03 -04005759 testCases = append(testCases, testCase{
5760 testType: serverTest,
5761 name: "ServerAuth-SignatureType-TLS13",
5762 config: Config{
5763 MaxVersion: VersionTLS13,
5764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5765 VerifySignatureAlgorithms: []signatureAlgorithm{
5766 signatureECDSAWithP521AndSHA512,
5767 signatureRSAPKCS1WithSHA384,
5768 signatureRSAPSSWithSHA384,
5769 signatureECDSAWithSHA1,
5770 },
5771 },
5772 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5773 })
5774
David Benjamina95e9f32016-07-08 16:28:04 -07005775 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005776 testCases = append(testCases, testCase{
5777 testType: serverTest,
5778 name: "Verify-ClientAuth-SignatureType",
5779 config: Config{
5780 MaxVersion: VersionTLS12,
5781 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005782 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005783 signatureRSAPKCS1WithSHA256,
5784 },
5785 Bugs: ProtocolBugs{
5786 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5787 },
5788 },
5789 flags: []string{
5790 "-require-any-client-certificate",
5791 },
5792 shouldFail: true,
5793 expectedError: ":WRONG_SIGNATURE_TYPE:",
5794 })
5795
5796 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005797 testType: serverTest,
5798 name: "Verify-ClientAuth-SignatureType-TLS13",
5799 config: Config{
5800 MaxVersion: VersionTLS13,
5801 Certificates: []Certificate{rsaCertificate},
5802 SignSignatureAlgorithms: []signatureAlgorithm{
5803 signatureRSAPSSWithSHA256,
5804 },
5805 Bugs: ProtocolBugs{
5806 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5807 },
5808 },
5809 flags: []string{
5810 "-require-any-client-certificate",
5811 },
5812 shouldFail: true,
5813 expectedError: ":WRONG_SIGNATURE_TYPE:",
5814 })
5815
5816 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005817 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005818 config: Config{
5819 MaxVersion: VersionTLS12,
5820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005821 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005822 signatureRSAPKCS1WithSHA256,
5823 },
5824 Bugs: ProtocolBugs{
5825 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5826 },
5827 },
5828 shouldFail: true,
5829 expectedError: ":WRONG_SIGNATURE_TYPE:",
5830 })
5831
Steven Valdez143e8b32016-07-11 13:19:03 -04005832 testCases = append(testCases, testCase{
5833 name: "Verify-ServerAuth-SignatureType-TLS13",
5834 config: Config{
5835 MaxVersion: VersionTLS13,
5836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5837 SignSignatureAlgorithms: []signatureAlgorithm{
5838 signatureRSAPSSWithSHA256,
5839 },
5840 Bugs: ProtocolBugs{
5841 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5842 },
5843 },
5844 shouldFail: true,
5845 expectedError: ":WRONG_SIGNATURE_TYPE:",
5846 })
5847
David Benjamin51dd7d62016-07-08 16:07:01 -07005848 // Test that, if the list is missing, the peer falls back to SHA-1 in
5849 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005850 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005851 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005853 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005854 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005855 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005856 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005857 },
5858 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005859 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005860 },
5861 },
5862 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005863 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5864 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005865 },
5866 })
5867
5868 testCases = append(testCases, testCase{
5869 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005870 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005871 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005872 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005873 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005874 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005875 },
5876 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005877 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005878 },
5879 },
David Benjaminee32bea2016-08-17 13:36:44 -04005880 flags: []string{
5881 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5882 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5883 },
5884 })
5885
5886 testCases = append(testCases, testCase{
5887 name: "ClientAuth-SHA1-Fallback-ECDSA",
5888 config: Config{
5889 MaxVersion: VersionTLS12,
5890 ClientAuth: RequireAnyClientCert,
5891 VerifySignatureAlgorithms: []signatureAlgorithm{
5892 signatureECDSAWithSHA1,
5893 },
5894 Bugs: ProtocolBugs{
5895 NoSignatureAlgorithms: true,
5896 },
5897 },
5898 flags: []string{
5899 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5900 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5901 },
5902 })
5903
5904 testCases = append(testCases, testCase{
5905 testType: serverTest,
5906 name: "ServerAuth-SHA1-Fallback-ECDSA",
5907 config: Config{
5908 MaxVersion: VersionTLS12,
5909 VerifySignatureAlgorithms: []signatureAlgorithm{
5910 signatureECDSAWithSHA1,
5911 },
5912 Bugs: ProtocolBugs{
5913 NoSignatureAlgorithms: true,
5914 },
5915 },
5916 flags: []string{
5917 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5918 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5919 },
David Benjamin000800a2014-11-14 01:43:59 -05005920 })
David Benjamin72dc7832015-03-16 17:49:43 -04005921
David Benjamin51dd7d62016-07-08 16:07:01 -07005922 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005923 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005924 config: Config{
5925 MaxVersion: VersionTLS13,
5926 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005927 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005928 signatureRSAPKCS1WithSHA1,
5929 },
5930 Bugs: ProtocolBugs{
5931 NoSignatureAlgorithms: true,
5932 },
5933 },
5934 flags: []string{
5935 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5936 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5937 },
David Benjamin48901652016-08-01 12:12:47 -04005938 shouldFail: true,
5939 // An empty CertificateRequest signature algorithm list is a
5940 // syntax error in TLS 1.3.
5941 expectedError: ":DECODE_ERROR:",
5942 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005943 })
5944
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005947 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005948 config: Config{
5949 MaxVersion: VersionTLS13,
5950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005951 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005952 signatureRSAPKCS1WithSHA1,
5953 },
5954 Bugs: ProtocolBugs{
5955 NoSignatureAlgorithms: true,
5956 },
5957 },
5958 shouldFail: true,
5959 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5960 })
5961
David Benjaminb62d2872016-07-18 14:55:02 +02005962 // Test that hash preferences are enforced. BoringSSL does not implement
5963 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005964 testCases = append(testCases, testCase{
5965 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005966 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005968 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005969 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005970 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005971 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005972 },
5973 Bugs: ProtocolBugs{
5974 IgnorePeerSignatureAlgorithmPreferences: true,
5975 },
5976 },
5977 flags: []string{"-require-any-client-certificate"},
5978 shouldFail: true,
5979 expectedError: ":WRONG_SIGNATURE_TYPE:",
5980 })
5981
5982 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005983 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005985 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005986 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005987 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005988 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005989 },
5990 Bugs: ProtocolBugs{
5991 IgnorePeerSignatureAlgorithmPreferences: true,
5992 },
5993 },
5994 shouldFail: true,
5995 expectedError: ":WRONG_SIGNATURE_TYPE:",
5996 })
David Benjaminb62d2872016-07-18 14:55:02 +02005997 testCases = append(testCases, testCase{
5998 testType: serverTest,
5999 name: "ClientAuth-Enforced-TLS13",
6000 config: Config{
6001 MaxVersion: VersionTLS13,
6002 Certificates: []Certificate{rsaCertificate},
6003 SignSignatureAlgorithms: []signatureAlgorithm{
6004 signatureRSAPKCS1WithMD5,
6005 },
6006 Bugs: ProtocolBugs{
6007 IgnorePeerSignatureAlgorithmPreferences: true,
6008 IgnoreSignatureVersionChecks: true,
6009 },
6010 },
6011 flags: []string{"-require-any-client-certificate"},
6012 shouldFail: true,
6013 expectedError: ":WRONG_SIGNATURE_TYPE:",
6014 })
6015
6016 testCases = append(testCases, testCase{
6017 name: "ServerAuth-Enforced-TLS13",
6018 config: Config{
6019 MaxVersion: VersionTLS13,
6020 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6021 SignSignatureAlgorithms: []signatureAlgorithm{
6022 signatureRSAPKCS1WithMD5,
6023 },
6024 Bugs: ProtocolBugs{
6025 IgnorePeerSignatureAlgorithmPreferences: true,
6026 IgnoreSignatureVersionChecks: true,
6027 },
6028 },
6029 shouldFail: true,
6030 expectedError: ":WRONG_SIGNATURE_TYPE:",
6031 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006032
6033 // Test that the agreed upon digest respects the client preferences and
6034 // the server digests.
6035 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006036 name: "NoCommonAlgorithms-Digests",
6037 config: Config{
6038 MaxVersion: VersionTLS12,
6039 ClientAuth: RequireAnyClientCert,
6040 VerifySignatureAlgorithms: []signatureAlgorithm{
6041 signatureRSAPKCS1WithSHA512,
6042 signatureRSAPKCS1WithSHA1,
6043 },
6044 },
6045 flags: []string{
6046 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6047 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6048 "-digest-prefs", "SHA256",
6049 },
6050 shouldFail: true,
6051 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6052 })
6053 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006054 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006056 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006057 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006058 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006059 signatureRSAPKCS1WithSHA512,
6060 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006061 },
6062 },
6063 flags: []string{
6064 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6065 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006066 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006067 },
David Benjaminca3d5452016-07-14 12:51:01 -04006068 shouldFail: true,
6069 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6070 })
6071 testCases = append(testCases, testCase{
6072 name: "NoCommonAlgorithms-TLS13",
6073 config: Config{
6074 MaxVersion: VersionTLS13,
6075 ClientAuth: RequireAnyClientCert,
6076 VerifySignatureAlgorithms: []signatureAlgorithm{
6077 signatureRSAPSSWithSHA512,
6078 signatureRSAPSSWithSHA384,
6079 },
6080 },
6081 flags: []string{
6082 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6083 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6084 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6085 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006086 shouldFail: true,
6087 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006088 })
6089 testCases = append(testCases, testCase{
6090 name: "Agree-Digest-SHA256",
6091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006092 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006093 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006094 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006095 signatureRSAPKCS1WithSHA1,
6096 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006097 },
6098 },
6099 flags: []string{
6100 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6101 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006102 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006103 },
Nick Harper60edffd2016-06-21 15:19:24 -07006104 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006105 })
6106 testCases = append(testCases, testCase{
6107 name: "Agree-Digest-SHA1",
6108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006109 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006110 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006111 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006112 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006113 },
6114 },
6115 flags: []string{
6116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006118 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006119 },
Nick Harper60edffd2016-06-21 15:19:24 -07006120 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006121 })
6122 testCases = append(testCases, testCase{
6123 name: "Agree-Digest-Default",
6124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006125 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006126 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006127 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006128 signatureRSAPKCS1WithSHA256,
6129 signatureECDSAWithP256AndSHA256,
6130 signatureRSAPKCS1WithSHA1,
6131 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006132 },
6133 },
6134 flags: []string{
6135 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6136 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6137 },
Nick Harper60edffd2016-06-21 15:19:24 -07006138 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006139 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006140
David Benjaminca3d5452016-07-14 12:51:01 -04006141 // Test that the signing preference list may include extra algorithms
6142 // without negotiation problems.
6143 testCases = append(testCases, testCase{
6144 testType: serverTest,
6145 name: "FilterExtraAlgorithms",
6146 config: Config{
6147 MaxVersion: VersionTLS12,
6148 VerifySignatureAlgorithms: []signatureAlgorithm{
6149 signatureRSAPKCS1WithSHA256,
6150 },
6151 },
6152 flags: []string{
6153 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6154 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6155 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6156 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6157 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6158 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6159 },
6160 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6161 })
6162
David Benjamin4c3ddf72016-06-29 18:13:53 -04006163 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6164 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006165 testCases = append(testCases, testCase{
6166 name: "CheckLeafCurve",
6167 config: Config{
6168 MaxVersion: VersionTLS12,
6169 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006170 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171 },
6172 flags: []string{"-p384-only"},
6173 shouldFail: true,
6174 expectedError: ":BAD_ECC_CERT:",
6175 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006176
6177 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6178 testCases = append(testCases, testCase{
6179 name: "CheckLeafCurve-TLS13",
6180 config: Config{
6181 MaxVersion: VersionTLS13,
6182 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6183 Certificates: []Certificate{ecdsaP256Certificate},
6184 },
6185 flags: []string{"-p384-only"},
6186 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006187
6188 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6189 testCases = append(testCases, testCase{
6190 name: "ECDSACurveMismatch-Verify-TLS12",
6191 config: Config{
6192 MaxVersion: VersionTLS12,
6193 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6194 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006195 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006196 signatureECDSAWithP384AndSHA384,
6197 },
6198 },
6199 })
6200
6201 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6202 testCases = append(testCases, testCase{
6203 name: "ECDSACurveMismatch-Verify-TLS13",
6204 config: Config{
6205 MaxVersion: VersionTLS13,
6206 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6207 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006208 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006209 signatureECDSAWithP384AndSHA384,
6210 },
6211 Bugs: ProtocolBugs{
6212 SkipECDSACurveCheck: true,
6213 },
6214 },
6215 shouldFail: true,
6216 expectedError: ":WRONG_SIGNATURE_TYPE:",
6217 })
6218
6219 // Signature algorithm selection in TLS 1.3 should take the curve into
6220 // account.
6221 testCases = append(testCases, testCase{
6222 testType: serverTest,
6223 name: "ECDSACurveMismatch-Sign-TLS13",
6224 config: Config{
6225 MaxVersion: VersionTLS13,
6226 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006227 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006228 signatureECDSAWithP384AndSHA384,
6229 signatureECDSAWithP256AndSHA256,
6230 },
6231 },
6232 flags: []string{
6233 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6234 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6235 },
6236 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6237 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006238
6239 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6240 // server does not attempt to sign in that case.
6241 testCases = append(testCases, testCase{
6242 testType: serverTest,
6243 name: "RSA-PSS-Large",
6244 config: Config{
6245 MaxVersion: VersionTLS13,
6246 VerifySignatureAlgorithms: []signatureAlgorithm{
6247 signatureRSAPSSWithSHA512,
6248 },
6249 },
6250 flags: []string{
6251 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6252 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6253 },
6254 shouldFail: true,
6255 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6256 })
David Benjamin000800a2014-11-14 01:43:59 -05006257}
6258
David Benjamin83f90402015-01-27 01:09:43 -05006259// timeouts is the retransmit schedule for BoringSSL. It doubles and
6260// caps at 60 seconds. On the 13th timeout, it gives up.
6261var timeouts = []time.Duration{
6262 1 * time.Second,
6263 2 * time.Second,
6264 4 * time.Second,
6265 8 * time.Second,
6266 16 * time.Second,
6267 32 * time.Second,
6268 60 * time.Second,
6269 60 * time.Second,
6270 60 * time.Second,
6271 60 * time.Second,
6272 60 * time.Second,
6273 60 * time.Second,
6274 60 * time.Second,
6275}
6276
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006277// shortTimeouts is an alternate set of timeouts which would occur if the
6278// initial timeout duration was set to 250ms.
6279var shortTimeouts = []time.Duration{
6280 250 * time.Millisecond,
6281 500 * time.Millisecond,
6282 1 * time.Second,
6283 2 * time.Second,
6284 4 * time.Second,
6285 8 * time.Second,
6286 16 * time.Second,
6287 32 * time.Second,
6288 60 * time.Second,
6289 60 * time.Second,
6290 60 * time.Second,
6291 60 * time.Second,
6292 60 * time.Second,
6293}
6294
David Benjamin83f90402015-01-27 01:09:43 -05006295func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006296 // These tests work by coordinating some behavior on both the shim and
6297 // the runner.
6298 //
6299 // TimeoutSchedule configures the runner to send a series of timeout
6300 // opcodes to the shim (see packetAdaptor) immediately before reading
6301 // each peer handshake flight N. The timeout opcode both simulates a
6302 // timeout in the shim and acts as a synchronization point to help the
6303 // runner bracket each handshake flight.
6304 //
6305 // We assume the shim does not read from the channel eagerly. It must
6306 // first wait until it has sent flight N and is ready to receive
6307 // handshake flight N+1. At this point, it will process the timeout
6308 // opcode. It must then immediately respond with a timeout ACK and act
6309 // as if the shim was idle for the specified amount of time.
6310 //
6311 // The runner then drops all packets received before the ACK and
6312 // continues waiting for flight N. This ordering results in one attempt
6313 // at sending flight N to be dropped. For the test to complete, the
6314 // shim must send flight N again, testing that the shim implements DTLS
6315 // retransmit on a timeout.
6316
Steven Valdez143e8b32016-07-11 13:19:03 -04006317 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006318 // likely be more epochs to cross and the final message's retransmit may
6319 // be more complex.
6320
David Benjamin585d7a42016-06-02 14:58:00 -04006321 for _, async := range []bool{true, false} {
6322 var tests []testCase
6323
6324 // Test that this is indeed the timeout schedule. Stress all
6325 // four patterns of handshake.
6326 for i := 1; i < len(timeouts); i++ {
6327 number := strconv.Itoa(i)
6328 tests = append(tests, testCase{
6329 protocol: dtls,
6330 name: "DTLS-Retransmit-Client-" + number,
6331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006332 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006333 Bugs: ProtocolBugs{
6334 TimeoutSchedule: timeouts[:i],
6335 },
6336 },
6337 resumeSession: true,
6338 })
6339 tests = append(tests, testCase{
6340 protocol: dtls,
6341 testType: serverTest,
6342 name: "DTLS-Retransmit-Server-" + number,
6343 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006344 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006345 Bugs: ProtocolBugs{
6346 TimeoutSchedule: timeouts[:i],
6347 },
6348 },
6349 resumeSession: true,
6350 })
6351 }
6352
6353 // Test that exceeding the timeout schedule hits a read
6354 // timeout.
6355 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006356 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006357 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006359 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006360 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006361 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006362 },
6363 },
6364 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006365 shouldFail: true,
6366 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006367 })
David Benjamin585d7a42016-06-02 14:58:00 -04006368
6369 if async {
6370 // Test that timeout handling has a fudge factor, due to API
6371 // problems.
6372 tests = append(tests, testCase{
6373 protocol: dtls,
6374 name: "DTLS-Retransmit-Fudge",
6375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006376 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006377 Bugs: ProtocolBugs{
6378 TimeoutSchedule: []time.Duration{
6379 timeouts[0] - 10*time.Millisecond,
6380 },
6381 },
6382 },
6383 resumeSession: true,
6384 })
6385 }
6386
6387 // Test that the final Finished retransmitting isn't
6388 // duplicated if the peer badly fragments everything.
6389 tests = append(tests, testCase{
6390 testType: serverTest,
6391 protocol: dtls,
6392 name: "DTLS-Retransmit-Fragmented",
6393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006394 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006395 Bugs: ProtocolBugs{
6396 TimeoutSchedule: []time.Duration{timeouts[0]},
6397 MaxHandshakeRecordLength: 2,
6398 },
6399 },
6400 })
6401
6402 // Test the timeout schedule when a shorter initial timeout duration is set.
6403 tests = append(tests, testCase{
6404 protocol: dtls,
6405 name: "DTLS-Retransmit-Short-Client",
6406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006407 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006408 Bugs: ProtocolBugs{
6409 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6410 },
6411 },
6412 resumeSession: true,
6413 flags: []string{"-initial-timeout-duration-ms", "250"},
6414 })
6415 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006416 protocol: dtls,
6417 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006418 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006420 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006421 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006422 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006423 },
6424 },
6425 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006426 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006427 })
David Benjamin585d7a42016-06-02 14:58:00 -04006428
6429 for _, test := range tests {
6430 if async {
6431 test.name += "-Async"
6432 test.flags = append(test.flags, "-async")
6433 }
6434
6435 testCases = append(testCases, test)
6436 }
David Benjamin83f90402015-01-27 01:09:43 -05006437 }
David Benjamin83f90402015-01-27 01:09:43 -05006438}
6439
David Benjaminc565ebb2015-04-03 04:06:36 -04006440func addExportKeyingMaterialTests() {
6441 for _, vers := range tlsVersions {
6442 if vers.version == VersionSSL30 {
6443 continue
6444 }
6445 testCases = append(testCases, testCase{
6446 name: "ExportKeyingMaterial-" + vers.name,
6447 config: Config{
6448 MaxVersion: vers.version,
6449 },
6450 exportKeyingMaterial: 1024,
6451 exportLabel: "label",
6452 exportContext: "context",
6453 useExportContext: true,
6454 })
6455 testCases = append(testCases, testCase{
6456 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6457 config: Config{
6458 MaxVersion: vers.version,
6459 },
6460 exportKeyingMaterial: 1024,
6461 })
6462 testCases = append(testCases, testCase{
6463 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6464 config: Config{
6465 MaxVersion: vers.version,
6466 },
6467 exportKeyingMaterial: 1024,
6468 useExportContext: true,
6469 })
6470 testCases = append(testCases, testCase{
6471 name: "ExportKeyingMaterial-Small-" + vers.name,
6472 config: Config{
6473 MaxVersion: vers.version,
6474 },
6475 exportKeyingMaterial: 1,
6476 exportLabel: "label",
6477 exportContext: "context",
6478 useExportContext: true,
6479 })
6480 }
6481 testCases = append(testCases, testCase{
6482 name: "ExportKeyingMaterial-SSL3",
6483 config: Config{
6484 MaxVersion: VersionSSL30,
6485 },
6486 exportKeyingMaterial: 1024,
6487 exportLabel: "label",
6488 exportContext: "context",
6489 useExportContext: true,
6490 shouldFail: true,
6491 expectedError: "failed to export keying material",
6492 })
6493}
6494
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006495func addTLSUniqueTests() {
6496 for _, isClient := range []bool{false, true} {
6497 for _, isResumption := range []bool{false, true} {
6498 for _, hasEMS := range []bool{false, true} {
6499 var suffix string
6500 if isResumption {
6501 suffix = "Resume-"
6502 } else {
6503 suffix = "Full-"
6504 }
6505
6506 if hasEMS {
6507 suffix += "EMS-"
6508 } else {
6509 suffix += "NoEMS-"
6510 }
6511
6512 if isClient {
6513 suffix += "Client"
6514 } else {
6515 suffix += "Server"
6516 }
6517
6518 test := testCase{
6519 name: "TLSUnique-" + suffix,
6520 testTLSUnique: true,
6521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006522 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006523 Bugs: ProtocolBugs{
6524 NoExtendedMasterSecret: !hasEMS,
6525 },
6526 },
6527 }
6528
6529 if isResumption {
6530 test.resumeSession = true
6531 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006532 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006533 Bugs: ProtocolBugs{
6534 NoExtendedMasterSecret: !hasEMS,
6535 },
6536 }
6537 }
6538
6539 if isResumption && !hasEMS {
6540 test.shouldFail = true
6541 test.expectedError = "failed to get tls-unique"
6542 }
6543
6544 testCases = append(testCases, test)
6545 }
6546 }
6547 }
6548}
6549
Adam Langley09505632015-07-30 18:10:13 -07006550func addCustomExtensionTests() {
6551 expectedContents := "custom extension"
6552 emptyString := ""
6553
6554 for _, isClient := range []bool{false, true} {
6555 suffix := "Server"
6556 flag := "-enable-server-custom-extension"
6557 testType := serverTest
6558 if isClient {
6559 suffix = "Client"
6560 flag = "-enable-client-custom-extension"
6561 testType = clientTest
6562 }
6563
6564 testCases = append(testCases, testCase{
6565 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006566 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006568 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006569 Bugs: ProtocolBugs{
6570 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006571 ExpectedCustomExtension: &expectedContents,
6572 },
6573 },
6574 flags: []string{flag},
6575 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006576 testCases = append(testCases, testCase{
6577 testType: testType,
6578 name: "CustomExtensions-" + suffix + "-TLS13",
6579 config: Config{
6580 MaxVersion: VersionTLS13,
6581 Bugs: ProtocolBugs{
6582 CustomExtension: expectedContents,
6583 ExpectedCustomExtension: &expectedContents,
6584 },
6585 },
6586 flags: []string{flag},
6587 })
Adam Langley09505632015-07-30 18:10:13 -07006588
6589 // If the parse callback fails, the handshake should also fail.
6590 testCases = append(testCases, testCase{
6591 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006592 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006594 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006595 Bugs: ProtocolBugs{
6596 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006597 ExpectedCustomExtension: &expectedContents,
6598 },
6599 },
David Benjamin399e7c92015-07-30 23:01:27 -04006600 flags: []string{flag},
6601 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006602 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6603 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006604 testCases = append(testCases, testCase{
6605 testType: testType,
6606 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6607 config: Config{
6608 MaxVersion: VersionTLS13,
6609 Bugs: ProtocolBugs{
6610 CustomExtension: expectedContents + "foo",
6611 ExpectedCustomExtension: &expectedContents,
6612 },
6613 },
6614 flags: []string{flag},
6615 shouldFail: true,
6616 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6617 })
Adam Langley09505632015-07-30 18:10:13 -07006618
6619 // If the add callback fails, the handshake should also fail.
6620 testCases = append(testCases, testCase{
6621 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006622 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006623 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006624 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006625 Bugs: ProtocolBugs{
6626 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006627 ExpectedCustomExtension: &expectedContents,
6628 },
6629 },
David Benjamin399e7c92015-07-30 23:01:27 -04006630 flags: []string{flag, "-custom-extension-fail-add"},
6631 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006632 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6633 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006634 testCases = append(testCases, testCase{
6635 testType: testType,
6636 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6637 config: Config{
6638 MaxVersion: VersionTLS13,
6639 Bugs: ProtocolBugs{
6640 CustomExtension: expectedContents,
6641 ExpectedCustomExtension: &expectedContents,
6642 },
6643 },
6644 flags: []string{flag, "-custom-extension-fail-add"},
6645 shouldFail: true,
6646 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6647 })
Adam Langley09505632015-07-30 18:10:13 -07006648
6649 // If the add callback returns zero, no extension should be
6650 // added.
6651 skipCustomExtension := expectedContents
6652 if isClient {
6653 // For the case where the client skips sending the
6654 // custom extension, the server must not “echo” it.
6655 skipCustomExtension = ""
6656 }
6657 testCases = append(testCases, testCase{
6658 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006659 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006661 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006662 Bugs: ProtocolBugs{
6663 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006664 ExpectedCustomExtension: &emptyString,
6665 },
6666 },
6667 flags: []string{flag, "-custom-extension-skip"},
6668 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006669 testCases = append(testCases, testCase{
6670 testType: testType,
6671 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6672 config: Config{
6673 MaxVersion: VersionTLS13,
6674 Bugs: ProtocolBugs{
6675 CustomExtension: skipCustomExtension,
6676 ExpectedCustomExtension: &emptyString,
6677 },
6678 },
6679 flags: []string{flag, "-custom-extension-skip"},
6680 })
Adam Langley09505632015-07-30 18:10:13 -07006681 }
6682
6683 // The custom extension add callback should not be called if the client
6684 // doesn't send the extension.
6685 testCases = append(testCases, testCase{
6686 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006687 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006689 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006690 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006691 ExpectedCustomExtension: &emptyString,
6692 },
6693 },
6694 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6695 })
Adam Langley2deb9842015-08-07 11:15:37 -07006696
Steven Valdez143e8b32016-07-11 13:19:03 -04006697 testCases = append(testCases, testCase{
6698 testType: serverTest,
6699 name: "CustomExtensions-NotCalled-Server-TLS13",
6700 config: Config{
6701 MaxVersion: VersionTLS13,
6702 Bugs: ProtocolBugs{
6703 ExpectedCustomExtension: &emptyString,
6704 },
6705 },
6706 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6707 })
6708
Adam Langley2deb9842015-08-07 11:15:37 -07006709 // Test an unknown extension from the server.
6710 testCases = append(testCases, testCase{
6711 testType: clientTest,
6712 name: "UnknownExtension-Client",
6713 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006714 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006715 Bugs: ProtocolBugs{
6716 CustomExtension: expectedContents,
6717 },
6718 },
David Benjamin0c40a962016-08-01 12:05:50 -04006719 shouldFail: true,
6720 expectedError: ":UNEXPECTED_EXTENSION:",
6721 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006722 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006723 testCases = append(testCases, testCase{
6724 testType: clientTest,
6725 name: "UnknownExtension-Client-TLS13",
6726 config: Config{
6727 MaxVersion: VersionTLS13,
6728 Bugs: ProtocolBugs{
6729 CustomExtension: expectedContents,
6730 },
6731 },
David Benjamin0c40a962016-08-01 12:05:50 -04006732 shouldFail: true,
6733 expectedError: ":UNEXPECTED_EXTENSION:",
6734 expectedLocalError: "remote error: unsupported extension",
6735 })
6736
6737 // Test a known but unoffered extension from the server.
6738 testCases = append(testCases, testCase{
6739 testType: clientTest,
6740 name: "UnofferedExtension-Client",
6741 config: Config{
6742 MaxVersion: VersionTLS12,
6743 Bugs: ProtocolBugs{
6744 SendALPN: "alpn",
6745 },
6746 },
6747 shouldFail: true,
6748 expectedError: ":UNEXPECTED_EXTENSION:",
6749 expectedLocalError: "remote error: unsupported extension",
6750 })
6751 testCases = append(testCases, testCase{
6752 testType: clientTest,
6753 name: "UnofferedExtension-Client-TLS13",
6754 config: Config{
6755 MaxVersion: VersionTLS13,
6756 Bugs: ProtocolBugs{
6757 SendALPN: "alpn",
6758 },
6759 },
6760 shouldFail: true,
6761 expectedError: ":UNEXPECTED_EXTENSION:",
6762 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006763 })
Adam Langley09505632015-07-30 18:10:13 -07006764}
6765
David Benjaminb36a3952015-12-01 18:53:13 -05006766func addRSAClientKeyExchangeTests() {
6767 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6768 testCases = append(testCases, testCase{
6769 testType: serverTest,
6770 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6771 config: Config{
6772 // Ensure the ClientHello version and final
6773 // version are different, to detect if the
6774 // server uses the wrong one.
6775 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006776 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006777 Bugs: ProtocolBugs{
6778 BadRSAClientKeyExchange: bad,
6779 },
6780 },
6781 shouldFail: true,
6782 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6783 })
6784 }
6785}
6786
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006787var testCurves = []struct {
6788 name string
6789 id CurveID
6790}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006791 {"P-256", CurveP256},
6792 {"P-384", CurveP384},
6793 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006794 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006795}
6796
Steven Valdez5440fe02016-07-18 12:40:30 -04006797const bogusCurve = 0x1234
6798
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006799func addCurveTests() {
6800 for _, curve := range testCurves {
6801 testCases = append(testCases, testCase{
6802 name: "CurveTest-Client-" + curve.name,
6803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006804 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006805 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6806 CurvePreferences: []CurveID{curve.id},
6807 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006808 flags: []string{
6809 "-enable-all-curves",
6810 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6811 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006812 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006813 })
6814 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006815 name: "CurveTest-Client-" + curve.name + "-TLS13",
6816 config: Config{
6817 MaxVersion: VersionTLS13,
6818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6819 CurvePreferences: []CurveID{curve.id},
6820 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006821 flags: []string{
6822 "-enable-all-curves",
6823 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6824 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006825 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006826 })
6827 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006828 testType: serverTest,
6829 name: "CurveTest-Server-" + curve.name,
6830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006831 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6833 CurvePreferences: []CurveID{curve.id},
6834 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006835 flags: []string{
6836 "-enable-all-curves",
6837 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6838 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006839 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006840 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006841 testCases = append(testCases, testCase{
6842 testType: serverTest,
6843 name: "CurveTest-Server-" + curve.name + "-TLS13",
6844 config: Config{
6845 MaxVersion: VersionTLS13,
6846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6847 CurvePreferences: []CurveID{curve.id},
6848 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006849 flags: []string{
6850 "-enable-all-curves",
6851 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6852 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006853 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006854 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006855 }
David Benjamin241ae832016-01-15 03:04:54 -05006856
6857 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006858 testCases = append(testCases, testCase{
6859 testType: serverTest,
6860 name: "UnknownCurve",
6861 config: Config{
6862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6863 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6864 },
6865 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006866
6867 // The server must not consider ECDHE ciphers when there are no
6868 // supported curves.
6869 testCases = append(testCases, testCase{
6870 testType: serverTest,
6871 name: "NoSupportedCurves",
6872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006873 MaxVersion: VersionTLS12,
6874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6875 Bugs: ProtocolBugs{
6876 NoSupportedCurves: true,
6877 },
6878 },
6879 shouldFail: true,
6880 expectedError: ":NO_SHARED_CIPHER:",
6881 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006882 testCases = append(testCases, testCase{
6883 testType: serverTest,
6884 name: "NoSupportedCurves-TLS13",
6885 config: Config{
6886 MaxVersion: VersionTLS13,
6887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6888 Bugs: ProtocolBugs{
6889 NoSupportedCurves: true,
6890 },
6891 },
6892 shouldFail: true,
6893 expectedError: ":NO_SHARED_CIPHER:",
6894 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006895
6896 // The server must fall back to another cipher when there are no
6897 // supported curves.
6898 testCases = append(testCases, testCase{
6899 testType: serverTest,
6900 name: "NoCommonCurves",
6901 config: Config{
6902 MaxVersion: VersionTLS12,
6903 CipherSuites: []uint16{
6904 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6905 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6906 },
6907 CurvePreferences: []CurveID{CurveP224},
6908 },
6909 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6910 })
6911
6912 // The client must reject bogus curves and disabled curves.
6913 testCases = append(testCases, testCase{
6914 name: "BadECDHECurve",
6915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006916 MaxVersion: VersionTLS12,
6917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6918 Bugs: ProtocolBugs{
6919 SendCurve: bogusCurve,
6920 },
6921 },
6922 shouldFail: true,
6923 expectedError: ":WRONG_CURVE:",
6924 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006925 testCases = append(testCases, testCase{
6926 name: "BadECDHECurve-TLS13",
6927 config: Config{
6928 MaxVersion: VersionTLS13,
6929 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6930 Bugs: ProtocolBugs{
6931 SendCurve: bogusCurve,
6932 },
6933 },
6934 shouldFail: true,
6935 expectedError: ":WRONG_CURVE:",
6936 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006937
6938 testCases = append(testCases, testCase{
6939 name: "UnsupportedCurve",
6940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006941 MaxVersion: VersionTLS12,
6942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6943 CurvePreferences: []CurveID{CurveP256},
6944 Bugs: ProtocolBugs{
6945 IgnorePeerCurvePreferences: true,
6946 },
6947 },
6948 flags: []string{"-p384-only"},
6949 shouldFail: true,
6950 expectedError: ":WRONG_CURVE:",
6951 })
6952
David Benjamin4f921572016-07-17 14:20:10 +02006953 testCases = append(testCases, testCase{
6954 // TODO(davidben): Add a TLS 1.3 version where
6955 // HelloRetryRequest requests an unsupported curve.
6956 name: "UnsupportedCurve-ServerHello-TLS13",
6957 config: Config{
6958 MaxVersion: VersionTLS12,
6959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6960 CurvePreferences: []CurveID{CurveP384},
6961 Bugs: ProtocolBugs{
6962 SendCurve: CurveP256,
6963 },
6964 },
6965 flags: []string{"-p384-only"},
6966 shouldFail: true,
6967 expectedError: ":WRONG_CURVE:",
6968 })
6969
David Benjamin4c3ddf72016-06-29 18:13:53 -04006970 // Test invalid curve points.
6971 testCases = append(testCases, testCase{
6972 name: "InvalidECDHPoint-Client",
6973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006974 MaxVersion: VersionTLS12,
6975 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6976 CurvePreferences: []CurveID{CurveP256},
6977 Bugs: ProtocolBugs{
6978 InvalidECDHPoint: true,
6979 },
6980 },
6981 shouldFail: true,
6982 expectedError: ":INVALID_ENCODING:",
6983 })
6984 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006985 name: "InvalidECDHPoint-Client-TLS13",
6986 config: Config{
6987 MaxVersion: VersionTLS13,
6988 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6989 CurvePreferences: []CurveID{CurveP256},
6990 Bugs: ProtocolBugs{
6991 InvalidECDHPoint: true,
6992 },
6993 },
6994 shouldFail: true,
6995 expectedError: ":INVALID_ENCODING:",
6996 })
6997 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 testType: serverTest,
6999 name: "InvalidECDHPoint-Server",
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 CurvePreferences: []CurveID{CurveP256},
7004 Bugs: ProtocolBugs{
7005 InvalidECDHPoint: true,
7006 },
7007 },
7008 shouldFail: true,
7009 expectedError: ":INVALID_ENCODING:",
7010 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007011 testCases = append(testCases, testCase{
7012 testType: serverTest,
7013 name: "InvalidECDHPoint-Server-TLS13",
7014 config: Config{
7015 MaxVersion: VersionTLS13,
7016 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7017 CurvePreferences: []CurveID{CurveP256},
7018 Bugs: ProtocolBugs{
7019 InvalidECDHPoint: true,
7020 },
7021 },
7022 shouldFail: true,
7023 expectedError: ":INVALID_ENCODING:",
7024 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007025}
7026
Matt Braithwaite54217e42016-06-13 13:03:47 -07007027func addCECPQ1Tests() {
7028 testCases = append(testCases, testCase{
7029 testType: clientTest,
7030 name: "CECPQ1-Client-BadX25519Part",
7031 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007032 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007033 MinVersion: VersionTLS12,
7034 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7035 Bugs: ProtocolBugs{
7036 CECPQ1BadX25519Part: true,
7037 },
7038 },
7039 flags: []string{"-cipher", "kCECPQ1"},
7040 shouldFail: true,
7041 expectedLocalError: "local error: bad record MAC",
7042 })
7043 testCases = append(testCases, testCase{
7044 testType: clientTest,
7045 name: "CECPQ1-Client-BadNewhopePart",
7046 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007047 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007048 MinVersion: VersionTLS12,
7049 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7050 Bugs: ProtocolBugs{
7051 CECPQ1BadNewhopePart: true,
7052 },
7053 },
7054 flags: []string{"-cipher", "kCECPQ1"},
7055 shouldFail: true,
7056 expectedLocalError: "local error: bad record MAC",
7057 })
7058 testCases = append(testCases, testCase{
7059 testType: serverTest,
7060 name: "CECPQ1-Server-BadX25519Part",
7061 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007062 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007063 MinVersion: VersionTLS12,
7064 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7065 Bugs: ProtocolBugs{
7066 CECPQ1BadX25519Part: true,
7067 },
7068 },
7069 flags: []string{"-cipher", "kCECPQ1"},
7070 shouldFail: true,
7071 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7072 })
7073 testCases = append(testCases, testCase{
7074 testType: serverTest,
7075 name: "CECPQ1-Server-BadNewhopePart",
7076 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007077 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007078 MinVersion: VersionTLS12,
7079 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7080 Bugs: ProtocolBugs{
7081 CECPQ1BadNewhopePart: true,
7082 },
7083 },
7084 flags: []string{"-cipher", "kCECPQ1"},
7085 shouldFail: true,
7086 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7087 })
7088}
7089
David Benjamin5c4e8572016-08-19 17:44:53 -04007090func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007091 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007092 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007093 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007094 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007095 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7096 Bugs: ProtocolBugs{
7097 // This is a 1234-bit prime number, generated
7098 // with:
7099 // openssl gendh 1234 | openssl asn1parse -i
7100 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7101 },
7102 },
David Benjamin9e68f192016-06-30 14:55:33 -04007103 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007104 })
7105 testCases = append(testCases, testCase{
7106 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007107 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007108 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007109 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007110 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7111 },
7112 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007113 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007114 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007115}
7116
David Benjaminc9ae27c2016-06-24 22:56:37 -04007117func addTLS13RecordTests() {
7118 testCases = append(testCases, testCase{
7119 name: "TLS13-RecordPadding",
7120 config: Config{
7121 MaxVersion: VersionTLS13,
7122 MinVersion: VersionTLS13,
7123 Bugs: ProtocolBugs{
7124 RecordPadding: 10,
7125 },
7126 },
7127 })
7128
7129 testCases = append(testCases, testCase{
7130 name: "TLS13-EmptyRecords",
7131 config: Config{
7132 MaxVersion: VersionTLS13,
7133 MinVersion: VersionTLS13,
7134 Bugs: ProtocolBugs{
7135 OmitRecordContents: true,
7136 },
7137 },
7138 shouldFail: true,
7139 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7140 })
7141
7142 testCases = append(testCases, testCase{
7143 name: "TLS13-OnlyPadding",
7144 config: Config{
7145 MaxVersion: VersionTLS13,
7146 MinVersion: VersionTLS13,
7147 Bugs: ProtocolBugs{
7148 OmitRecordContents: true,
7149 RecordPadding: 10,
7150 },
7151 },
7152 shouldFail: true,
7153 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7154 })
7155
7156 testCases = append(testCases, testCase{
7157 name: "TLS13-WrongOuterRecord",
7158 config: Config{
7159 MaxVersion: VersionTLS13,
7160 MinVersion: VersionTLS13,
7161 Bugs: ProtocolBugs{
7162 OuterRecordType: recordTypeHandshake,
7163 },
7164 },
7165 shouldFail: true,
7166 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7167 })
7168}
7169
David Benjamin82261be2016-07-07 14:32:50 -07007170func addChangeCipherSpecTests() {
7171 // Test missing ChangeCipherSpecs.
7172 testCases = append(testCases, testCase{
7173 name: "SkipChangeCipherSpec-Client",
7174 config: Config{
7175 MaxVersion: VersionTLS12,
7176 Bugs: ProtocolBugs{
7177 SkipChangeCipherSpec: true,
7178 },
7179 },
7180 shouldFail: true,
7181 expectedError: ":UNEXPECTED_RECORD:",
7182 })
7183 testCases = append(testCases, testCase{
7184 testType: serverTest,
7185 name: "SkipChangeCipherSpec-Server",
7186 config: Config{
7187 MaxVersion: VersionTLS12,
7188 Bugs: ProtocolBugs{
7189 SkipChangeCipherSpec: true,
7190 },
7191 },
7192 shouldFail: true,
7193 expectedError: ":UNEXPECTED_RECORD:",
7194 })
7195 testCases = append(testCases, testCase{
7196 testType: serverTest,
7197 name: "SkipChangeCipherSpec-Server-NPN",
7198 config: Config{
7199 MaxVersion: VersionTLS12,
7200 NextProtos: []string{"bar"},
7201 Bugs: ProtocolBugs{
7202 SkipChangeCipherSpec: true,
7203 },
7204 },
7205 flags: []string{
7206 "-advertise-npn", "\x03foo\x03bar\x03baz",
7207 },
7208 shouldFail: true,
7209 expectedError: ":UNEXPECTED_RECORD:",
7210 })
7211
7212 // Test synchronization between the handshake and ChangeCipherSpec.
7213 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7214 // rejected. Test both with and without handshake packing to handle both
7215 // when the partial post-CCS message is in its own record and when it is
7216 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007217 for _, packed := range []bool{false, true} {
7218 var suffix string
7219 if packed {
7220 suffix = "-Packed"
7221 }
7222
7223 testCases = append(testCases, testCase{
7224 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 Bugs: ProtocolBugs{
7228 FragmentAcrossChangeCipherSpec: true,
7229 PackHandshakeFlight: packed,
7230 },
7231 },
7232 shouldFail: true,
7233 expectedError: ":UNEXPECTED_RECORD:",
7234 })
7235 testCases = append(testCases, testCase{
7236 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7237 config: Config{
7238 MaxVersion: VersionTLS12,
7239 },
7240 resumeSession: true,
7241 resumeConfig: &Config{
7242 MaxVersion: VersionTLS12,
7243 Bugs: ProtocolBugs{
7244 FragmentAcrossChangeCipherSpec: true,
7245 PackHandshakeFlight: packed,
7246 },
7247 },
7248 shouldFail: true,
7249 expectedError: ":UNEXPECTED_RECORD:",
7250 })
7251 testCases = append(testCases, testCase{
7252 testType: serverTest,
7253 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7254 config: Config{
7255 MaxVersion: VersionTLS12,
7256 Bugs: ProtocolBugs{
7257 FragmentAcrossChangeCipherSpec: true,
7258 PackHandshakeFlight: packed,
7259 },
7260 },
7261 shouldFail: true,
7262 expectedError: ":UNEXPECTED_RECORD:",
7263 })
7264 testCases = append(testCases, testCase{
7265 testType: serverTest,
7266 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7267 config: Config{
7268 MaxVersion: VersionTLS12,
7269 },
7270 resumeSession: true,
7271 resumeConfig: &Config{
7272 MaxVersion: VersionTLS12,
7273 Bugs: ProtocolBugs{
7274 FragmentAcrossChangeCipherSpec: true,
7275 PackHandshakeFlight: packed,
7276 },
7277 },
7278 shouldFail: true,
7279 expectedError: ":UNEXPECTED_RECORD:",
7280 })
7281 testCases = append(testCases, testCase{
7282 testType: serverTest,
7283 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7284 config: Config{
7285 MaxVersion: VersionTLS12,
7286 NextProtos: []string{"bar"},
7287 Bugs: ProtocolBugs{
7288 FragmentAcrossChangeCipherSpec: true,
7289 PackHandshakeFlight: packed,
7290 },
7291 },
7292 flags: []string{
7293 "-advertise-npn", "\x03foo\x03bar\x03baz",
7294 },
7295 shouldFail: true,
7296 expectedError: ":UNEXPECTED_RECORD:",
7297 })
7298 }
7299
David Benjamin61672812016-07-14 23:10:43 -04007300 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7301 // messages in the handshake queue. Do this by testing the server
7302 // reading the client Finished, reversing the flight so Finished comes
7303 // first.
7304 testCases = append(testCases, testCase{
7305 protocol: dtls,
7306 testType: serverTest,
7307 name: "SendUnencryptedFinished-DTLS",
7308 config: Config{
7309 MaxVersion: VersionTLS12,
7310 Bugs: ProtocolBugs{
7311 SendUnencryptedFinished: true,
7312 ReverseHandshakeFragments: true,
7313 },
7314 },
7315 shouldFail: true,
7316 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7317 })
7318
Steven Valdez143e8b32016-07-11 13:19:03 -04007319 // Test synchronization between encryption changes and the handshake in
7320 // TLS 1.3, where ChangeCipherSpec is implicit.
7321 testCases = append(testCases, testCase{
7322 name: "PartialEncryptedExtensionsWithServerHello",
7323 config: Config{
7324 MaxVersion: VersionTLS13,
7325 Bugs: ProtocolBugs{
7326 PartialEncryptedExtensionsWithServerHello: true,
7327 },
7328 },
7329 shouldFail: true,
7330 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7331 })
7332 testCases = append(testCases, testCase{
7333 testType: serverTest,
7334 name: "PartialClientFinishedWithClientHello",
7335 config: Config{
7336 MaxVersion: VersionTLS13,
7337 Bugs: ProtocolBugs{
7338 PartialClientFinishedWithClientHello: true,
7339 },
7340 },
7341 shouldFail: true,
7342 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7343 })
7344
David Benjamin82261be2016-07-07 14:32:50 -07007345 // Test that early ChangeCipherSpecs are handled correctly.
7346 testCases = append(testCases, testCase{
7347 testType: serverTest,
7348 name: "EarlyChangeCipherSpec-server-1",
7349 config: Config{
7350 MaxVersion: VersionTLS12,
7351 Bugs: ProtocolBugs{
7352 EarlyChangeCipherSpec: 1,
7353 },
7354 },
7355 shouldFail: true,
7356 expectedError: ":UNEXPECTED_RECORD:",
7357 })
7358 testCases = append(testCases, testCase{
7359 testType: serverTest,
7360 name: "EarlyChangeCipherSpec-server-2",
7361 config: Config{
7362 MaxVersion: VersionTLS12,
7363 Bugs: ProtocolBugs{
7364 EarlyChangeCipherSpec: 2,
7365 },
7366 },
7367 shouldFail: true,
7368 expectedError: ":UNEXPECTED_RECORD:",
7369 })
7370 testCases = append(testCases, testCase{
7371 protocol: dtls,
7372 name: "StrayChangeCipherSpec",
7373 config: Config{
7374 // TODO(davidben): Once DTLS 1.3 exists, test
7375 // that stray ChangeCipherSpec messages are
7376 // rejected.
7377 MaxVersion: VersionTLS12,
7378 Bugs: ProtocolBugs{
7379 StrayChangeCipherSpec: true,
7380 },
7381 },
7382 })
7383
7384 // Test that the contents of ChangeCipherSpec are checked.
7385 testCases = append(testCases, testCase{
7386 name: "BadChangeCipherSpec-1",
7387 config: Config{
7388 MaxVersion: VersionTLS12,
7389 Bugs: ProtocolBugs{
7390 BadChangeCipherSpec: []byte{2},
7391 },
7392 },
7393 shouldFail: true,
7394 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7395 })
7396 testCases = append(testCases, testCase{
7397 name: "BadChangeCipherSpec-2",
7398 config: Config{
7399 MaxVersion: VersionTLS12,
7400 Bugs: ProtocolBugs{
7401 BadChangeCipherSpec: []byte{1, 1},
7402 },
7403 },
7404 shouldFail: true,
7405 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7406 })
7407 testCases = append(testCases, testCase{
7408 protocol: dtls,
7409 name: "BadChangeCipherSpec-DTLS-1",
7410 config: Config{
7411 MaxVersion: VersionTLS12,
7412 Bugs: ProtocolBugs{
7413 BadChangeCipherSpec: []byte{2},
7414 },
7415 },
7416 shouldFail: true,
7417 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7418 })
7419 testCases = append(testCases, testCase{
7420 protocol: dtls,
7421 name: "BadChangeCipherSpec-DTLS-2",
7422 config: Config{
7423 MaxVersion: VersionTLS12,
7424 Bugs: ProtocolBugs{
7425 BadChangeCipherSpec: []byte{1, 1},
7426 },
7427 },
7428 shouldFail: true,
7429 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7430 })
7431}
7432
David Benjamin0b8d5da2016-07-15 00:39:56 -04007433func addWrongMessageTypeTests() {
7434 for _, protocol := range []protocol{tls, dtls} {
7435 var suffix string
7436 if protocol == dtls {
7437 suffix = "-DTLS"
7438 }
7439
7440 testCases = append(testCases, testCase{
7441 protocol: protocol,
7442 testType: serverTest,
7443 name: "WrongMessageType-ClientHello" + suffix,
7444 config: Config{
7445 MaxVersion: VersionTLS12,
7446 Bugs: ProtocolBugs{
7447 SendWrongMessageType: typeClientHello,
7448 },
7449 },
7450 shouldFail: true,
7451 expectedError: ":UNEXPECTED_MESSAGE:",
7452 expectedLocalError: "remote error: unexpected message",
7453 })
7454
7455 if protocol == dtls {
7456 testCases = append(testCases, testCase{
7457 protocol: protocol,
7458 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7459 config: Config{
7460 MaxVersion: VersionTLS12,
7461 Bugs: ProtocolBugs{
7462 SendWrongMessageType: typeHelloVerifyRequest,
7463 },
7464 },
7465 shouldFail: true,
7466 expectedError: ":UNEXPECTED_MESSAGE:",
7467 expectedLocalError: "remote error: unexpected message",
7468 })
7469 }
7470
7471 testCases = append(testCases, testCase{
7472 protocol: protocol,
7473 name: "WrongMessageType-ServerHello" + suffix,
7474 config: Config{
7475 MaxVersion: VersionTLS12,
7476 Bugs: ProtocolBugs{
7477 SendWrongMessageType: typeServerHello,
7478 },
7479 },
7480 shouldFail: true,
7481 expectedError: ":UNEXPECTED_MESSAGE:",
7482 expectedLocalError: "remote error: unexpected message",
7483 })
7484
7485 testCases = append(testCases, testCase{
7486 protocol: protocol,
7487 name: "WrongMessageType-ServerCertificate" + suffix,
7488 config: Config{
7489 MaxVersion: VersionTLS12,
7490 Bugs: ProtocolBugs{
7491 SendWrongMessageType: typeCertificate,
7492 },
7493 },
7494 shouldFail: true,
7495 expectedError: ":UNEXPECTED_MESSAGE:",
7496 expectedLocalError: "remote error: unexpected message",
7497 })
7498
7499 testCases = append(testCases, testCase{
7500 protocol: protocol,
7501 name: "WrongMessageType-CertificateStatus" + suffix,
7502 config: Config{
7503 MaxVersion: VersionTLS12,
7504 Bugs: ProtocolBugs{
7505 SendWrongMessageType: typeCertificateStatus,
7506 },
7507 },
7508 flags: []string{"-enable-ocsp-stapling"},
7509 shouldFail: true,
7510 expectedError: ":UNEXPECTED_MESSAGE:",
7511 expectedLocalError: "remote error: unexpected message",
7512 })
7513
7514 testCases = append(testCases, testCase{
7515 protocol: protocol,
7516 name: "WrongMessageType-ServerKeyExchange" + suffix,
7517 config: Config{
7518 MaxVersion: VersionTLS12,
7519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7520 Bugs: ProtocolBugs{
7521 SendWrongMessageType: typeServerKeyExchange,
7522 },
7523 },
7524 shouldFail: true,
7525 expectedError: ":UNEXPECTED_MESSAGE:",
7526 expectedLocalError: "remote error: unexpected message",
7527 })
7528
7529 testCases = append(testCases, testCase{
7530 protocol: protocol,
7531 name: "WrongMessageType-CertificateRequest" + suffix,
7532 config: Config{
7533 MaxVersion: VersionTLS12,
7534 ClientAuth: RequireAnyClientCert,
7535 Bugs: ProtocolBugs{
7536 SendWrongMessageType: typeCertificateRequest,
7537 },
7538 },
7539 shouldFail: true,
7540 expectedError: ":UNEXPECTED_MESSAGE:",
7541 expectedLocalError: "remote error: unexpected message",
7542 })
7543
7544 testCases = append(testCases, testCase{
7545 protocol: protocol,
7546 name: "WrongMessageType-ServerHelloDone" + suffix,
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 Bugs: ProtocolBugs{
7550 SendWrongMessageType: typeServerHelloDone,
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":UNEXPECTED_MESSAGE:",
7555 expectedLocalError: "remote error: unexpected message",
7556 })
7557
7558 testCases = append(testCases, testCase{
7559 testType: serverTest,
7560 protocol: protocol,
7561 name: "WrongMessageType-ClientCertificate" + suffix,
7562 config: Config{
7563 Certificates: []Certificate{rsaCertificate},
7564 MaxVersion: VersionTLS12,
7565 Bugs: ProtocolBugs{
7566 SendWrongMessageType: typeCertificate,
7567 },
7568 },
7569 flags: []string{"-require-any-client-certificate"},
7570 shouldFail: true,
7571 expectedError: ":UNEXPECTED_MESSAGE:",
7572 expectedLocalError: "remote error: unexpected message",
7573 })
7574
7575 testCases = append(testCases, testCase{
7576 testType: serverTest,
7577 protocol: protocol,
7578 name: "WrongMessageType-CertificateVerify" + suffix,
7579 config: Config{
7580 Certificates: []Certificate{rsaCertificate},
7581 MaxVersion: VersionTLS12,
7582 Bugs: ProtocolBugs{
7583 SendWrongMessageType: typeCertificateVerify,
7584 },
7585 },
7586 flags: []string{"-require-any-client-certificate"},
7587 shouldFail: true,
7588 expectedError: ":UNEXPECTED_MESSAGE:",
7589 expectedLocalError: "remote error: unexpected message",
7590 })
7591
7592 testCases = append(testCases, testCase{
7593 testType: serverTest,
7594 protocol: protocol,
7595 name: "WrongMessageType-ClientKeyExchange" + suffix,
7596 config: Config{
7597 MaxVersion: VersionTLS12,
7598 Bugs: ProtocolBugs{
7599 SendWrongMessageType: typeClientKeyExchange,
7600 },
7601 },
7602 shouldFail: true,
7603 expectedError: ":UNEXPECTED_MESSAGE:",
7604 expectedLocalError: "remote error: unexpected message",
7605 })
7606
7607 if protocol != dtls {
7608 testCases = append(testCases, testCase{
7609 testType: serverTest,
7610 protocol: protocol,
7611 name: "WrongMessageType-NextProtocol" + suffix,
7612 config: Config{
7613 MaxVersion: VersionTLS12,
7614 NextProtos: []string{"bar"},
7615 Bugs: ProtocolBugs{
7616 SendWrongMessageType: typeNextProtocol,
7617 },
7618 },
7619 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7620 shouldFail: true,
7621 expectedError: ":UNEXPECTED_MESSAGE:",
7622 expectedLocalError: "remote error: unexpected message",
7623 })
7624
7625 testCases = append(testCases, testCase{
7626 testType: serverTest,
7627 protocol: protocol,
7628 name: "WrongMessageType-ChannelID" + suffix,
7629 config: Config{
7630 MaxVersion: VersionTLS12,
7631 ChannelID: channelIDKey,
7632 Bugs: ProtocolBugs{
7633 SendWrongMessageType: typeChannelID,
7634 },
7635 },
7636 flags: []string{
7637 "-expect-channel-id",
7638 base64.StdEncoding.EncodeToString(channelIDBytes),
7639 },
7640 shouldFail: true,
7641 expectedError: ":UNEXPECTED_MESSAGE:",
7642 expectedLocalError: "remote error: unexpected message",
7643 })
7644 }
7645
7646 testCases = append(testCases, testCase{
7647 testType: serverTest,
7648 protocol: protocol,
7649 name: "WrongMessageType-ClientFinished" + suffix,
7650 config: Config{
7651 MaxVersion: VersionTLS12,
7652 Bugs: ProtocolBugs{
7653 SendWrongMessageType: typeFinished,
7654 },
7655 },
7656 shouldFail: true,
7657 expectedError: ":UNEXPECTED_MESSAGE:",
7658 expectedLocalError: "remote error: unexpected message",
7659 })
7660
7661 testCases = append(testCases, testCase{
7662 protocol: protocol,
7663 name: "WrongMessageType-NewSessionTicket" + suffix,
7664 config: Config{
7665 MaxVersion: VersionTLS12,
7666 Bugs: ProtocolBugs{
7667 SendWrongMessageType: typeNewSessionTicket,
7668 },
7669 },
7670 shouldFail: true,
7671 expectedError: ":UNEXPECTED_MESSAGE:",
7672 expectedLocalError: "remote error: unexpected message",
7673 })
7674
7675 testCases = append(testCases, testCase{
7676 protocol: protocol,
7677 name: "WrongMessageType-ServerFinished" + suffix,
7678 config: Config{
7679 MaxVersion: VersionTLS12,
7680 Bugs: ProtocolBugs{
7681 SendWrongMessageType: typeFinished,
7682 },
7683 },
7684 shouldFail: true,
7685 expectedError: ":UNEXPECTED_MESSAGE:",
7686 expectedLocalError: "remote error: unexpected message",
7687 })
7688
7689 }
7690}
7691
Steven Valdez143e8b32016-07-11 13:19:03 -04007692func addTLS13WrongMessageTypeTests() {
7693 testCases = append(testCases, testCase{
7694 testType: serverTest,
7695 name: "WrongMessageType-TLS13-ClientHello",
7696 config: Config{
7697 MaxVersion: VersionTLS13,
7698 Bugs: ProtocolBugs{
7699 SendWrongMessageType: typeClientHello,
7700 },
7701 },
7702 shouldFail: true,
7703 expectedError: ":UNEXPECTED_MESSAGE:",
7704 expectedLocalError: "remote error: unexpected message",
7705 })
7706
7707 testCases = append(testCases, testCase{
7708 name: "WrongMessageType-TLS13-ServerHello",
7709 config: Config{
7710 MaxVersion: VersionTLS13,
7711 Bugs: ProtocolBugs{
7712 SendWrongMessageType: typeServerHello,
7713 },
7714 },
7715 shouldFail: true,
7716 expectedError: ":UNEXPECTED_MESSAGE:",
7717 // The alert comes in with the wrong encryption.
7718 expectedLocalError: "local error: bad record MAC",
7719 })
7720
7721 testCases = append(testCases, testCase{
7722 name: "WrongMessageType-TLS13-EncryptedExtensions",
7723 config: Config{
7724 MaxVersion: VersionTLS13,
7725 Bugs: ProtocolBugs{
7726 SendWrongMessageType: typeEncryptedExtensions,
7727 },
7728 },
7729 shouldFail: true,
7730 expectedError: ":UNEXPECTED_MESSAGE:",
7731 expectedLocalError: "remote error: unexpected message",
7732 })
7733
7734 testCases = append(testCases, testCase{
7735 name: "WrongMessageType-TLS13-CertificateRequest",
7736 config: Config{
7737 MaxVersion: VersionTLS13,
7738 ClientAuth: RequireAnyClientCert,
7739 Bugs: ProtocolBugs{
7740 SendWrongMessageType: typeCertificateRequest,
7741 },
7742 },
7743 shouldFail: true,
7744 expectedError: ":UNEXPECTED_MESSAGE:",
7745 expectedLocalError: "remote error: unexpected message",
7746 })
7747
7748 testCases = append(testCases, testCase{
7749 name: "WrongMessageType-TLS13-ServerCertificate",
7750 config: Config{
7751 MaxVersion: VersionTLS13,
7752 Bugs: ProtocolBugs{
7753 SendWrongMessageType: typeCertificate,
7754 },
7755 },
7756 shouldFail: true,
7757 expectedError: ":UNEXPECTED_MESSAGE:",
7758 expectedLocalError: "remote error: unexpected message",
7759 })
7760
7761 testCases = append(testCases, testCase{
7762 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7763 config: Config{
7764 MaxVersion: VersionTLS13,
7765 Bugs: ProtocolBugs{
7766 SendWrongMessageType: typeCertificateVerify,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_MESSAGE:",
7771 expectedLocalError: "remote error: unexpected message",
7772 })
7773
7774 testCases = append(testCases, testCase{
7775 name: "WrongMessageType-TLS13-ServerFinished",
7776 config: Config{
7777 MaxVersion: VersionTLS13,
7778 Bugs: ProtocolBugs{
7779 SendWrongMessageType: typeFinished,
7780 },
7781 },
7782 shouldFail: true,
7783 expectedError: ":UNEXPECTED_MESSAGE:",
7784 expectedLocalError: "remote error: unexpected message",
7785 })
7786
7787 testCases = append(testCases, testCase{
7788 testType: serverTest,
7789 name: "WrongMessageType-TLS13-ClientCertificate",
7790 config: Config{
7791 Certificates: []Certificate{rsaCertificate},
7792 MaxVersion: VersionTLS13,
7793 Bugs: ProtocolBugs{
7794 SendWrongMessageType: typeCertificate,
7795 },
7796 },
7797 flags: []string{"-require-any-client-certificate"},
7798 shouldFail: true,
7799 expectedError: ":UNEXPECTED_MESSAGE:",
7800 expectedLocalError: "remote error: unexpected message",
7801 })
7802
7803 testCases = append(testCases, testCase{
7804 testType: serverTest,
7805 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7806 config: Config{
7807 Certificates: []Certificate{rsaCertificate},
7808 MaxVersion: VersionTLS13,
7809 Bugs: ProtocolBugs{
7810 SendWrongMessageType: typeCertificateVerify,
7811 },
7812 },
7813 flags: []string{"-require-any-client-certificate"},
7814 shouldFail: true,
7815 expectedError: ":UNEXPECTED_MESSAGE:",
7816 expectedLocalError: "remote error: unexpected message",
7817 })
7818
7819 testCases = append(testCases, testCase{
7820 testType: serverTest,
7821 name: "WrongMessageType-TLS13-ClientFinished",
7822 config: Config{
7823 MaxVersion: VersionTLS13,
7824 Bugs: ProtocolBugs{
7825 SendWrongMessageType: typeFinished,
7826 },
7827 },
7828 shouldFail: true,
7829 expectedError: ":UNEXPECTED_MESSAGE:",
7830 expectedLocalError: "remote error: unexpected message",
7831 })
7832}
7833
7834func addTLS13HandshakeTests() {
7835 testCases = append(testCases, testCase{
7836 testType: clientTest,
7837 name: "MissingKeyShare-Client",
7838 config: Config{
7839 MaxVersion: VersionTLS13,
7840 Bugs: ProtocolBugs{
7841 MissingKeyShare: true,
7842 },
7843 },
7844 shouldFail: true,
7845 expectedError: ":MISSING_KEY_SHARE:",
7846 })
7847
7848 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007849 testType: serverTest,
7850 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007851 config: Config{
7852 MaxVersion: VersionTLS13,
7853 Bugs: ProtocolBugs{
7854 MissingKeyShare: true,
7855 },
7856 },
7857 shouldFail: true,
7858 expectedError: ":MISSING_KEY_SHARE:",
7859 })
7860
7861 testCases = append(testCases, testCase{
7862 testType: clientTest,
7863 name: "ClientHelloMissingKeyShare",
7864 config: Config{
7865 MaxVersion: VersionTLS13,
7866 Bugs: ProtocolBugs{
7867 MissingKeyShare: true,
7868 },
7869 },
7870 shouldFail: true,
7871 expectedError: ":MISSING_KEY_SHARE:",
7872 })
7873
7874 testCases = append(testCases, testCase{
7875 testType: clientTest,
7876 name: "MissingKeyShare",
7877 config: Config{
7878 MaxVersion: VersionTLS13,
7879 Bugs: ProtocolBugs{
7880 MissingKeyShare: true,
7881 },
7882 },
7883 shouldFail: true,
7884 expectedError: ":MISSING_KEY_SHARE:",
7885 })
7886
7887 testCases = append(testCases, testCase{
7888 testType: serverTest,
7889 name: "DuplicateKeyShares",
7890 config: Config{
7891 MaxVersion: VersionTLS13,
7892 Bugs: ProtocolBugs{
7893 DuplicateKeyShares: true,
7894 },
7895 },
7896 })
7897
7898 testCases = append(testCases, testCase{
7899 testType: clientTest,
7900 name: "EmptyEncryptedExtensions",
7901 config: Config{
7902 MaxVersion: VersionTLS13,
7903 Bugs: ProtocolBugs{
7904 EmptyEncryptedExtensions: true,
7905 },
7906 },
7907 shouldFail: true,
7908 expectedLocalError: "remote error: error decoding message",
7909 })
7910
7911 testCases = append(testCases, testCase{
7912 testType: clientTest,
7913 name: "EncryptedExtensionsWithKeyShare",
7914 config: Config{
7915 MaxVersion: VersionTLS13,
7916 Bugs: ProtocolBugs{
7917 EncryptedExtensionsWithKeyShare: true,
7918 },
7919 },
7920 shouldFail: true,
7921 expectedLocalError: "remote error: unsupported extension",
7922 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007923
7924 testCases = append(testCases, testCase{
7925 testType: serverTest,
7926 name: "SendHelloRetryRequest",
7927 config: Config{
7928 MaxVersion: VersionTLS13,
7929 // Require a HelloRetryRequest for every curve.
7930 DefaultCurves: []CurveID{},
7931 },
7932 expectedCurveID: CurveX25519,
7933 })
7934
7935 testCases = append(testCases, testCase{
7936 testType: serverTest,
7937 name: "SendHelloRetryRequest-2",
7938 config: Config{
7939 MaxVersion: VersionTLS13,
7940 DefaultCurves: []CurveID{CurveP384},
7941 },
7942 // Although the ClientHello did not predict our preferred curve,
7943 // we always select it whether it is predicted or not.
7944 expectedCurveID: CurveX25519,
7945 })
7946
7947 testCases = append(testCases, testCase{
7948 name: "UnknownCurve-HelloRetryRequest",
7949 config: Config{
7950 MaxVersion: VersionTLS13,
7951 // P-384 requires HelloRetryRequest in BoringSSL.
7952 CurvePreferences: []CurveID{CurveP384},
7953 Bugs: ProtocolBugs{
7954 SendHelloRetryRequestCurve: bogusCurve,
7955 },
7956 },
7957 shouldFail: true,
7958 expectedError: ":WRONG_CURVE:",
7959 })
7960
7961 testCases = append(testCases, testCase{
7962 name: "DisabledCurve-HelloRetryRequest",
7963 config: Config{
7964 MaxVersion: VersionTLS13,
7965 CurvePreferences: []CurveID{CurveP256},
7966 Bugs: ProtocolBugs{
7967 IgnorePeerCurvePreferences: true,
7968 },
7969 },
7970 flags: []string{"-p384-only"},
7971 shouldFail: true,
7972 expectedError: ":WRONG_CURVE:",
7973 })
7974
7975 testCases = append(testCases, testCase{
7976 name: "UnnecessaryHelloRetryRequest",
7977 config: Config{
7978 MaxVersion: VersionTLS13,
7979 Bugs: ProtocolBugs{
7980 UnnecessaryHelloRetryRequest: true,
7981 },
7982 },
7983 shouldFail: true,
7984 expectedError: ":WRONG_CURVE:",
7985 })
7986
7987 testCases = append(testCases, testCase{
7988 name: "SecondHelloRetryRequest",
7989 config: Config{
7990 MaxVersion: VersionTLS13,
7991 // P-384 requires HelloRetryRequest in BoringSSL.
7992 CurvePreferences: []CurveID{CurveP384},
7993 Bugs: ProtocolBugs{
7994 SecondHelloRetryRequest: true,
7995 },
7996 },
7997 shouldFail: true,
7998 expectedError: ":UNEXPECTED_MESSAGE:",
7999 })
8000
8001 testCases = append(testCases, testCase{
8002 testType: serverTest,
8003 name: "SecondClientHelloMissingKeyShare",
8004 config: Config{
8005 MaxVersion: VersionTLS13,
8006 DefaultCurves: []CurveID{},
8007 Bugs: ProtocolBugs{
8008 SecondClientHelloMissingKeyShare: true,
8009 },
8010 },
8011 shouldFail: true,
8012 expectedError: ":MISSING_KEY_SHARE:",
8013 })
8014
8015 testCases = append(testCases, testCase{
8016 testType: serverTest,
8017 name: "SecondClientHelloWrongCurve",
8018 config: Config{
8019 MaxVersion: VersionTLS13,
8020 DefaultCurves: []CurveID{},
8021 Bugs: ProtocolBugs{
8022 MisinterpretHelloRetryRequestCurve: CurveP521,
8023 },
8024 },
8025 shouldFail: true,
8026 expectedError: ":WRONG_CURVE:",
8027 })
8028
8029 testCases = append(testCases, testCase{
8030 name: "HelloRetryRequestVersionMismatch",
8031 config: Config{
8032 MaxVersion: VersionTLS13,
8033 // P-384 requires HelloRetryRequest in BoringSSL.
8034 CurvePreferences: []CurveID{CurveP384},
8035 Bugs: ProtocolBugs{
8036 SendServerHelloVersion: 0x0305,
8037 },
8038 },
8039 shouldFail: true,
8040 expectedError: ":WRONG_VERSION_NUMBER:",
8041 })
8042
8043 testCases = append(testCases, testCase{
8044 name: "HelloRetryRequestCurveMismatch",
8045 config: Config{
8046 MaxVersion: VersionTLS13,
8047 // P-384 requires HelloRetryRequest in BoringSSL.
8048 CurvePreferences: []CurveID{CurveP384},
8049 Bugs: ProtocolBugs{
8050 // Send P-384 (correct) in the HelloRetryRequest.
8051 SendHelloRetryRequestCurve: CurveP384,
8052 // But send P-256 in the ServerHello.
8053 SendCurve: CurveP256,
8054 },
8055 },
8056 shouldFail: true,
8057 expectedError: ":WRONG_CURVE:",
8058 })
8059
8060 // Test the server selecting a curve that requires a HelloRetryRequest
8061 // without sending it.
8062 testCases = append(testCases, testCase{
8063 name: "SkipHelloRetryRequest",
8064 config: Config{
8065 MaxVersion: VersionTLS13,
8066 // P-384 requires HelloRetryRequest in BoringSSL.
8067 CurvePreferences: []CurveID{CurveP384},
8068 Bugs: ProtocolBugs{
8069 SkipHelloRetryRequest: true,
8070 },
8071 },
8072 shouldFail: true,
8073 expectedError: ":WRONG_CURVE:",
8074 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008075
8076 testCases = append(testCases, testCase{
8077 name: "TLS13-RequestContextInHandshake",
8078 config: Config{
8079 MaxVersion: VersionTLS13,
8080 MinVersion: VersionTLS13,
8081 ClientAuth: RequireAnyClientCert,
8082 Bugs: ProtocolBugs{
8083 SendRequestContext: []byte("request context"),
8084 },
8085 },
8086 flags: []string{
8087 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8088 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8089 },
8090 shouldFail: true,
8091 expectedError: ":DECODE_ERROR:",
8092 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008093}
8094
Adam Langley7c803a62015-06-15 15:35:05 -07008095func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008096 defer wg.Done()
8097
8098 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008099 var err error
8100
8101 if *mallocTest < 0 {
8102 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008103 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008104 } else {
8105 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8106 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008107 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008108 if err != nil {
8109 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8110 }
8111 break
8112 }
8113 }
8114 }
Adam Langley95c29f32014-06-20 12:00:00 -07008115 statusChan <- statusMsg{test: test, err: err}
8116 }
8117}
8118
8119type statusMsg struct {
8120 test *testCase
8121 started bool
8122 err error
8123}
8124
David Benjamin5f237bc2015-02-11 17:14:15 -05008125func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008126 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008127
David Benjamin5f237bc2015-02-11 17:14:15 -05008128 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008129 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008130 if !*pipe {
8131 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008132 var erase string
8133 for i := 0; i < lineLen; i++ {
8134 erase += "\b \b"
8135 }
8136 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008137 }
8138
Adam Langley95c29f32014-06-20 12:00:00 -07008139 if msg.started {
8140 started++
8141 } else {
8142 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008143
8144 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008145 if msg.err == errUnimplemented {
8146 if *pipe {
8147 // Print each test instead of a status line.
8148 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8149 }
8150 unimplemented++
8151 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8152 } else {
8153 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8154 failed++
8155 testOutput.addResult(msg.test.name, "FAIL")
8156 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008157 } else {
8158 if *pipe {
8159 // Print each test instead of a status line.
8160 fmt.Printf("PASSED (%s)\n", msg.test.name)
8161 }
8162 testOutput.addResult(msg.test.name, "PASS")
8163 }
Adam Langley95c29f32014-06-20 12:00:00 -07008164 }
8165
David Benjamin5f237bc2015-02-11 17:14:15 -05008166 if !*pipe {
8167 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008168 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008169 lineLen = len(line)
8170 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008171 }
Adam Langley95c29f32014-06-20 12:00:00 -07008172 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008173
8174 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008175}
8176
8177func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008178 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008179 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008180 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008181
Adam Langley7c803a62015-06-15 15:35:05 -07008182 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008183 addCipherSuiteTests()
8184 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008185 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008186 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008187 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008188 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008189 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008190 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008191 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008192 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008193 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008194 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008195 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008196 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008197 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008198 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008199 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008200 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008201 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008202 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008203 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008204 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008205 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008206 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008207 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008208 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008209 addTLS13WrongMessageTypeTests()
8210 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008211
8212 var wg sync.WaitGroup
8213
Adam Langley7c803a62015-06-15 15:35:05 -07008214 statusChan := make(chan statusMsg, *numWorkers)
8215 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008216 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008217
EKRf71d7ed2016-08-06 13:25:12 -07008218 if len(*shimConfigFile) != 0 {
8219 encoded, err := ioutil.ReadFile(*shimConfigFile)
8220 if err != nil {
8221 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8222 os.Exit(1)
8223 }
8224
8225 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8226 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8227 os.Exit(1)
8228 }
8229 }
8230
David Benjamin025b3d32014-07-01 19:53:04 -04008231 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008232
Adam Langley7c803a62015-06-15 15:35:05 -07008233 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008234 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008235 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008236 }
8237
David Benjamin270f0a72016-03-17 14:41:36 -04008238 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008239 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008240 matched := true
8241 if len(*testToRun) != 0 {
8242 var err error
8243 matched, err = filepath.Match(*testToRun, testCases[i].name)
8244 if err != nil {
8245 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8246 os.Exit(1)
8247 }
8248 }
8249
EKRf71d7ed2016-08-06 13:25:12 -07008250 if !*includeDisabled {
8251 for pattern := range shimConfig.DisabledTests {
8252 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8253 if err != nil {
8254 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8255 os.Exit(1)
8256 }
8257
8258 if isDisabled {
8259 matched = false
8260 break
8261 }
8262 }
8263 }
8264
David Benjamin17e12922016-07-28 18:04:43 -04008265 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008266 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008267 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008268 }
8269 }
David Benjamin17e12922016-07-28 18:04:43 -04008270
David Benjamin270f0a72016-03-17 14:41:36 -04008271 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008272 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008273 os.Exit(1)
8274 }
Adam Langley95c29f32014-06-20 12:00:00 -07008275
8276 close(testChan)
8277 wg.Wait()
8278 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008279 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008280
8281 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008282
8283 if *jsonOutput != "" {
8284 if err := testOutput.writeTo(*jsonOutput); err != nil {
8285 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8286 }
8287 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008288
EKR842ae6c2016-07-27 09:22:05 +02008289 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8290 os.Exit(1)
8291 }
8292
8293 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008294 os.Exit(1)
8295 }
Adam Langley95c29f32014-06-20 12:00:00 -07008296}