blob: f999f480d153f644c24bd5b6b90ade179473fd41 [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.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700297 // expectResumeRejected, if true, specifies that the attempted
298 // resumption must be rejected by the client. This is only valid for a
299 // serverTest.
300 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400301 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500302 // resumption. Unless newSessionsOnResume is set,
303 // SessionTicketKey, ServerSessionCache, and
304 // ClientSessionCache are copied from the initial connection's
305 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400306 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500307 // newSessionsOnResume, if true, will cause resumeConfig to
308 // use a different session resumption context.
309 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400310 // noSessionCache, if true, will cause the server to run without a
311 // session cache.
312 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400313 // sendPrefix sends a prefix on the socket before actually performing a
314 // handshake.
315 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400316 // shimWritesFirst controls whether the shim sends an initial "hello"
317 // message before doing a roundtrip with the runner.
318 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400319 // shimShutsDown, if true, runs a test where the shim shuts down the
320 // connection immediately after the handshake rather than echoing
321 // messages from the runner.
322 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400323 // renegotiate indicates the number of times the connection should be
324 // renegotiated during the exchange.
325 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400326 // sendHalfHelloRequest, if true, causes the server to send half a
327 // HelloRequest when the handshake completes.
328 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700329 // renegotiateCiphers is a list of ciphersuite ids that will be
330 // switched in just before renegotiation.
331 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500332 // replayWrites, if true, configures the underlying transport
333 // to replay every write it makes in DTLS tests.
334 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500335 // damageFirstWrite, if true, configures the underlying transport to
336 // damage the final byte of the first application data write.
337 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400338 // exportKeyingMaterial, if non-zero, configures the test to exchange
339 // keying material and verify they match.
340 exportKeyingMaterial int
341 exportLabel string
342 exportContext string
343 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400344 // flags, if not empty, contains a list of command-line flags that will
345 // be passed to the shim program.
346 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700347 // testTLSUnique, if true, causes the shim to send the tls-unique value
348 // which will be compared against the expected value.
349 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400350 // sendEmptyRecords is the number of consecutive empty records to send
351 // before and after the test message.
352 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400353 // sendWarningAlerts is the number of consecutive warning alerts to send
354 // before and after the test message.
355 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400356 // expectMessageDropped, if true, means the test message is expected to
357 // be dropped by the client rather than echoed back.
358 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700359}
360
Adam Langley7c803a62015-06-15 15:35:05 -0700361var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700362
David Benjamin9867b7d2016-03-01 23:25:48 -0500363func writeTranscript(test *testCase, isResume bool, data []byte) {
364 if len(data) == 0 {
365 return
366 }
367
368 protocol := "tls"
369 if test.protocol == dtls {
370 protocol = "dtls"
371 }
372
373 side := "client"
374 if test.testType == serverTest {
375 side = "server"
376 }
377
378 dir := path.Join(*transcriptDir, protocol, side)
379 if err := os.MkdirAll(dir, 0755); err != nil {
380 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
381 return
382 }
383
384 name := test.name
385 if isResume {
386 name += "-Resume"
387 } else {
388 name += "-Normal"
389 }
390
391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjamin8e6db492015-07-25 18:29:23 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
439 if *deterministic {
440 config.Rand = &deterministicRand{}
441 }
442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
467 writeTranscript(test, isResume, connDebug.Transcript())
468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
David Benjamina8ebe222015-06-06 03:04:39 -0400618 for i := 0; i < test.sendEmptyRecords; i++ {
619 tlsConn.Write(nil)
620 }
621
David Benjamin24f346d2015-06-06 03:28:08 -0400622 for i := 0; i < test.sendWarningAlerts; i++ {
623 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
624 }
625
David Benjamin47921102016-07-28 11:29:18 -0400626 if test.sendHalfHelloRequest {
627 tlsConn.SendHalfHelloRequest()
628 }
629
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400630 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700631 if test.renegotiateCiphers != nil {
632 config.CipherSuites = test.renegotiateCiphers
633 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400634 for i := 0; i < test.renegotiate; i++ {
635 if err := tlsConn.Renegotiate(); err != nil {
636 return err
637 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700638 }
639 } else if test.renegotiateCiphers != nil {
640 panic("renegotiateCiphers without renegotiate")
641 }
642
David Benjamin5fa3eba2015-01-22 16:35:40 -0500643 if test.damageFirstWrite {
644 connDamage.setDamage(true)
645 tlsConn.Write([]byte("DAMAGED WRITE"))
646 connDamage.setDamage(false)
647 }
648
David Benjamin8e6db492015-07-25 18:29:23 -0400649 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700650 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400651 if test.protocol == dtls {
652 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
653 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700654 // Read until EOF.
655 _, err := io.Copy(ioutil.Discard, tlsConn)
656 return err
657 }
David Benjamin4417d052015-04-05 04:17:25 -0400658 if messageLen == 0 {
659 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700660 }
Adam Langley95c29f32014-06-20 12:00:00 -0700661
David Benjamin8e6db492015-07-25 18:29:23 -0400662 messageCount := test.messageCount
663 if messageCount == 0 {
664 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400665 }
666
David Benjamin8e6db492015-07-25 18:29:23 -0400667 for j := 0; j < messageCount; j++ {
668 testMessage := make([]byte, messageLen)
669 for i := range testMessage {
670 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400671 }
David Benjamin8e6db492015-07-25 18:29:23 -0400672 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700673
David Benjamin8e6db492015-07-25 18:29:23 -0400674 for i := 0; i < test.sendEmptyRecords; i++ {
675 tlsConn.Write(nil)
676 }
677
678 for i := 0; i < test.sendWarningAlerts; i++ {
679 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
680 }
681
David Benjamin4f75aaf2015-09-01 16:53:10 -0400682 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400683 // The shim will not respond.
684 continue
685 }
686
David Benjamin8e6db492015-07-25 18:29:23 -0400687 buf := make([]byte, len(testMessage))
688 if test.protocol == dtls {
689 bufTmp := make([]byte, len(buf)+1)
690 n, err := tlsConn.Read(bufTmp)
691 if err != nil {
692 return err
693 }
694 if n != len(buf) {
695 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
696 }
697 copy(buf, bufTmp)
698 } else {
699 _, err := io.ReadFull(tlsConn, buf)
700 if err != nil {
701 return err
702 }
703 }
704
705 for i, v := range buf {
706 if v != testMessage[i]^0xff {
707 return fmt.Errorf("bad reply contents at byte %d", i)
708 }
Adam Langley95c29f32014-06-20 12:00:00 -0700709 }
710 }
711
712 return nil
713}
714
David Benjamin325b5c32014-07-01 19:40:31 -0400715func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
716 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700717 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400718 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700719 }
David Benjamin325b5c32014-07-01 19:40:31 -0400720 valgrindArgs = append(valgrindArgs, path)
721 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700722
David Benjamin325b5c32014-07-01 19:40:31 -0400723 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700724}
725
David Benjamin325b5c32014-07-01 19:40:31 -0400726func gdbOf(path string, args ...string) *exec.Cmd {
727 xtermArgs := []string{"-e", "gdb", "--args"}
728 xtermArgs = append(xtermArgs, path)
729 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700730
David Benjamin325b5c32014-07-01 19:40:31 -0400731 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732}
733
David Benjamind16bf342015-12-18 00:53:12 -0500734func lldbOf(path string, args ...string) *exec.Cmd {
735 xtermArgs := []string{"-e", "lldb", "--"}
736 xtermArgs = append(xtermArgs, path)
737 xtermArgs = append(xtermArgs, args...)
738
739 return exec.Command("xterm", xtermArgs...)
740}
741
EKR842ae6c2016-07-27 09:22:05 +0200742var (
743 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
744 errUnimplemented = errors.New("child process does not implement needed flags")
745)
Adam Langley69a01602014-11-17 17:26:55 -0800746
David Benjamin87c8a642015-02-21 01:54:29 -0500747// accept accepts a connection from listener, unless waitChan signals a process
748// exit first.
749func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
750 type connOrError struct {
751 conn net.Conn
752 err error
753 }
754 connChan := make(chan connOrError, 1)
755 go func() {
756 conn, err := listener.Accept()
757 connChan <- connOrError{conn, err}
758 close(connChan)
759 }()
760 select {
761 case result := <-connChan:
762 return result.conn, result.err
763 case childErr := <-waitChan:
764 waitChan <- childErr
765 return nil, fmt.Errorf("child exited early: %s", childErr)
766 }
767}
768
EKRf71d7ed2016-08-06 13:25:12 -0700769func translateExpectedError(errorStr string) string {
770 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
771 return translated
772 }
773
774 if *looseErrors {
775 return ""
776 }
777
778 return errorStr
779}
780
Adam Langley7c803a62015-06-15 15:35:05 -0700781func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700782 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
783 panic("Error expected without shouldFail in " + test.name)
784 }
785
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700786 if test.expectResumeRejected && !test.resumeSession {
787 panic("expectResumeRejected without resumeSession in " + test.name)
788 }
789
David Benjamin87c8a642015-02-21 01:54:29 -0500790 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
791 if err != nil {
792 panic(err)
793 }
794 defer func() {
795 if listener != nil {
796 listener.Close()
797 }
798 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700799
David Benjamin87c8a642015-02-21 01:54:29 -0500800 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400801 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400802 flags = append(flags, "-server")
803
David Benjamin025b3d32014-07-01 19:53:04 -0400804 flags = append(flags, "-key-file")
805 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700806 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400807 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700808 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400809 }
810
811 flags = append(flags, "-cert-file")
812 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700813 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400814 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700815 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400816 }
817 }
David Benjamin5a593af2014-08-11 19:51:50 -0400818
David Benjamin6fd297b2014-08-11 18:43:38 -0400819 if test.protocol == dtls {
820 flags = append(flags, "-dtls")
821 }
822
David Benjamin5a593af2014-08-11 19:51:50 -0400823 if test.resumeSession {
824 flags = append(flags, "-resume")
825 }
826
David Benjamine58c4f52014-08-24 03:47:07 -0400827 if test.shimWritesFirst {
828 flags = append(flags, "-shim-writes-first")
829 }
830
David Benjamin30789da2015-08-29 22:56:45 -0400831 if test.shimShutsDown {
832 flags = append(flags, "-shim-shuts-down")
833 }
834
David Benjaminc565ebb2015-04-03 04:06:36 -0400835 if test.exportKeyingMaterial > 0 {
836 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
837 flags = append(flags, "-export-label", test.exportLabel)
838 flags = append(flags, "-export-context", test.exportContext)
839 if test.useExportContext {
840 flags = append(flags, "-use-export-context")
841 }
842 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700843 if test.expectResumeRejected {
844 flags = append(flags, "-expect-session-miss")
845 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400846
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700847 if test.testTLSUnique {
848 flags = append(flags, "-tls-unique")
849 }
850
David Benjamin025b3d32014-07-01 19:53:04 -0400851 flags = append(flags, test.flags...)
852
853 var shim *exec.Cmd
854 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700855 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700856 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700857 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500858 } else if *useLLDB {
859 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400860 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700861 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400862 }
David Benjamin025b3d32014-07-01 19:53:04 -0400863 shim.Stdin = os.Stdin
864 var stdoutBuf, stderrBuf bytes.Buffer
865 shim.Stdout = &stdoutBuf
866 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800867 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500868 shim.Env = os.Environ()
869 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800870 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400871 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800872 }
873 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
874 }
David Benjamin025b3d32014-07-01 19:53:04 -0400875
876 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700877 panic(err)
878 }
David Benjamin87c8a642015-02-21 01:54:29 -0500879 waitChan := make(chan error, 1)
880 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700881
882 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700883
David Benjamin87c8a642015-02-21 01:54:29 -0500884 conn, err := acceptOrWait(listener, waitChan)
885 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400886 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500887 conn.Close()
888 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500889
David Benjamin1d5c83e2014-07-22 19:20:02 -0400890 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400891 var resumeConfig Config
892 if test.resumeConfig != nil {
893 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400894 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500895 resumeConfig.SessionTicketKey = config.SessionTicketKey
896 resumeConfig.ClientSessionCache = config.ClientSessionCache
897 resumeConfig.ServerSessionCache = config.ServerSessionCache
898 }
David Benjamin2e045a92016-06-08 13:09:56 -0400899 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400900 } else {
901 resumeConfig = config
902 }
David Benjamin87c8a642015-02-21 01:54:29 -0500903 var connResume net.Conn
904 connResume, err = acceptOrWait(listener, waitChan)
905 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400906 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500907 connResume.Close()
908 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400909 }
910
David Benjamin87c8a642015-02-21 01:54:29 -0500911 // Close the listener now. This is to avoid hangs should the shim try to
912 // open more connections than expected.
913 listener.Close()
914 listener = nil
915
916 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800917 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200918 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
919 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800920 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200921 case 89:
922 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800923 }
924 }
Adam Langley95c29f32014-06-20 12:00:00 -0700925
David Benjamin9bea3492016-03-02 10:59:16 -0500926 // Account for Windows line endings.
927 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
928 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500929
930 // Separate the errors from the shim and those from tools like
931 // AddressSanitizer.
932 var extraStderr string
933 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
934 stderr = stderrParts[0]
935 extraStderr = stderrParts[1]
936 }
937
Adam Langley95c29f32014-06-20 12:00:00 -0700938 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700939 expectedError := translateExpectedError(test.expectedError)
940 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200941
Adam Langleyac61fa32014-06-23 12:03:11 -0700942 localError := "none"
943 if err != nil {
944 localError = err.Error()
945 }
946 if len(test.expectedLocalError) != 0 {
947 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
948 }
Adam Langley95c29f32014-06-20 12:00:00 -0700949
950 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700951 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700952 if childErr != nil {
953 childError = childErr.Error()
954 }
955
956 var msg string
957 switch {
958 case failed && !test.shouldFail:
959 msg = "unexpected failure"
960 case !failed && test.shouldFail:
961 msg = "unexpected success"
962 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700963 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700964 default:
965 panic("internal error")
966 }
967
David Benjaminc565ebb2015-04-03 04:06:36 -0400968 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 -0700969 }
970
David Benjaminff3a1492016-03-02 10:12:06 -0500971 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
972 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700973 }
974
975 return nil
976}
977
978var tlsVersions = []struct {
979 name string
980 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400981 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500982 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700983}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500984 {"SSL3", VersionSSL30, "-no-ssl3", false},
985 {"TLS1", VersionTLS10, "-no-tls1", true},
986 {"TLS11", VersionTLS11, "-no-tls11", false},
987 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400988 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700989}
990
991var testCipherSuites = []struct {
992 name string
993 id uint16
994}{
995 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400996 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700997 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400998 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400999 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001000 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001001 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001002 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1003 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001004 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001005 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1006 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001007 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001008 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1009 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001010 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1011 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001012 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001013 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001014 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001015 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001016 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001017 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001018 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001019 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001020 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001021 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001022 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001023 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001024 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001025 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001026 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1027 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1028 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1029 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001030 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1031 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001032 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1033 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001034 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001035 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1036 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001037 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001039 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001040 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001041}
1042
David Benjamin8b8c0062014-11-23 02:47:52 -05001043func hasComponent(suiteName, component string) bool {
1044 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1045}
1046
David Benjaminf7768e42014-08-31 02:06:47 -04001047func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001048 return hasComponent(suiteName, "GCM") ||
1049 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001050 hasComponent(suiteName, "SHA384") ||
1051 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001052}
1053
Nick Harper1fd39d82016-06-14 18:14:35 -07001054func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001055 // Only AEADs.
1056 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1057 return false
1058 }
1059 // No old CHACHA20_POLY1305.
1060 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1061 return false
1062 }
1063 // Must have ECDHE.
1064 // TODO(davidben,svaldez): Add pure PSK support.
1065 if !hasComponent(suiteName, "ECDHE") {
1066 return false
1067 }
1068 // TODO(davidben,svaldez): Add PSK support.
1069 if hasComponent(suiteName, "PSK") {
1070 return false
1071 }
1072 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001073}
1074
David Benjamin8b8c0062014-11-23 02:47:52 -05001075func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001076 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001077}
1078
Adam Langleya7997f12015-05-14 17:38:50 -07001079func bigFromHex(hex string) *big.Int {
1080 ret, ok := new(big.Int).SetString(hex, 16)
1081 if !ok {
1082 panic("failed to parse hex number 0x" + hex)
1083 }
1084 return ret
1085}
1086
Adam Langley7c803a62015-06-15 15:35:05 -07001087func addBasicTests() {
1088 basicTests := []testCase{
1089 {
Adam Langley7c803a62015-06-15 15:35:05 -07001090 name: "NoFallbackSCSV",
1091 config: Config{
1092 Bugs: ProtocolBugs{
1093 FailIfNotFallbackSCSV: true,
1094 },
1095 },
1096 shouldFail: true,
1097 expectedLocalError: "no fallback SCSV found",
1098 },
1099 {
1100 name: "SendFallbackSCSV",
1101 config: Config{
1102 Bugs: ProtocolBugs{
1103 FailIfNotFallbackSCSV: true,
1104 },
1105 },
1106 flags: []string{"-fallback-scsv"},
1107 },
1108 {
1109 name: "ClientCertificateTypes",
1110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001111 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001112 ClientAuth: RequestClientCert,
1113 ClientCertificateTypes: []byte{
1114 CertTypeDSSSign,
1115 CertTypeRSASign,
1116 CertTypeECDSASign,
1117 },
1118 },
1119 flags: []string{
1120 "-expect-certificate-types",
1121 base64.StdEncoding.EncodeToString([]byte{
1122 CertTypeDSSSign,
1123 CertTypeRSASign,
1124 CertTypeECDSASign,
1125 }),
1126 },
1127 },
1128 {
Adam Langley7c803a62015-06-15 15:35:05 -07001129 name: "UnauthenticatedECDH",
1130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001131 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001132 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1133 Bugs: ProtocolBugs{
1134 UnauthenticatedECDH: true,
1135 },
1136 },
1137 shouldFail: true,
1138 expectedError: ":UNEXPECTED_MESSAGE:",
1139 },
1140 {
1141 name: "SkipCertificateStatus",
1142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001143 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001144 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1145 Bugs: ProtocolBugs{
1146 SkipCertificateStatus: true,
1147 },
1148 },
1149 flags: []string{
1150 "-enable-ocsp-stapling",
1151 },
1152 },
1153 {
1154 name: "SkipServerKeyExchange",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 SkipServerKeyExchange: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
Adam Langley7c803a62015-06-15 15:35:05 -07001166 testType: serverTest,
1167 name: "Alert",
1168 config: Config{
1169 Bugs: ProtocolBugs{
1170 SendSpuriousAlert: alertRecordOverflow,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1175 },
1176 {
1177 protocol: dtls,
1178 testType: serverTest,
1179 name: "Alert-DTLS",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 SendSpuriousAlert: alertRecordOverflow,
1183 },
1184 },
1185 shouldFail: true,
1186 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1187 },
1188 {
1189 testType: serverTest,
1190 name: "FragmentAlert",
1191 config: Config{
1192 Bugs: ProtocolBugs{
1193 FragmentAlert: true,
1194 SendSpuriousAlert: alertRecordOverflow,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":BAD_ALERT:",
1199 },
1200 {
1201 protocol: dtls,
1202 testType: serverTest,
1203 name: "FragmentAlert-DTLS",
1204 config: Config{
1205 Bugs: ProtocolBugs{
1206 FragmentAlert: true,
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":BAD_ALERT:",
1212 },
1213 {
1214 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001215 name: "DoubleAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 DoubleAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "DoubleAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 DoubleAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
Adam Langley7c803a62015-06-15 15:35:05 -07001239 name: "SkipNewSessionTicket",
1240 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001241 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001242 Bugs: ProtocolBugs{
1243 SkipNewSessionTicket: true,
1244 },
1245 },
1246 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001247 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001248 },
1249 {
1250 testType: serverTest,
1251 name: "FallbackSCSV",
1252 config: Config{
1253 MaxVersion: VersionTLS11,
1254 Bugs: ProtocolBugs{
1255 SendFallbackSCSV: true,
1256 },
1257 },
1258 shouldFail: true,
1259 expectedError: ":INAPPROPRIATE_FALLBACK:",
1260 },
1261 {
1262 testType: serverTest,
1263 name: "FallbackSCSV-VersionMatch",
1264 config: Config{
1265 Bugs: ProtocolBugs{
1266 SendFallbackSCSV: true,
1267 },
1268 },
1269 },
1270 {
1271 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001272 name: "FallbackSCSV-VersionMatch-TLS12",
1273 config: Config{
1274 MaxVersion: VersionTLS12,
1275 Bugs: ProtocolBugs{
1276 SendFallbackSCSV: true,
1277 },
1278 },
1279 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1280 },
1281 {
1282 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001283 name: "FragmentedClientVersion",
1284 config: Config{
1285 Bugs: ProtocolBugs{
1286 MaxHandshakeRecordLength: 1,
1287 FragmentClientVersion: true,
1288 },
1289 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001290 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001291 },
1292 {
Adam Langley7c803a62015-06-15 15:35:05 -07001293 testType: serverTest,
1294 name: "HttpGET",
1295 sendPrefix: "GET / HTTP/1.0\n",
1296 shouldFail: true,
1297 expectedError: ":HTTP_REQUEST:",
1298 },
1299 {
1300 testType: serverTest,
1301 name: "HttpPOST",
1302 sendPrefix: "POST / HTTP/1.0\n",
1303 shouldFail: true,
1304 expectedError: ":HTTP_REQUEST:",
1305 },
1306 {
1307 testType: serverTest,
1308 name: "HttpHEAD",
1309 sendPrefix: "HEAD / HTTP/1.0\n",
1310 shouldFail: true,
1311 expectedError: ":HTTP_REQUEST:",
1312 },
1313 {
1314 testType: serverTest,
1315 name: "HttpPUT",
1316 sendPrefix: "PUT / HTTP/1.0\n",
1317 shouldFail: true,
1318 expectedError: ":HTTP_REQUEST:",
1319 },
1320 {
1321 testType: serverTest,
1322 name: "HttpCONNECT",
1323 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1324 shouldFail: true,
1325 expectedError: ":HTTPS_PROXY_REQUEST:",
1326 },
1327 {
1328 testType: serverTest,
1329 name: "Garbage",
1330 sendPrefix: "blah",
1331 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001332 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001333 },
1334 {
Adam Langley7c803a62015-06-15 15:35:05 -07001335 name: "RSAEphemeralKey",
1336 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001337 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001338 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1339 Bugs: ProtocolBugs{
1340 RSAEphemeralKey: true,
1341 },
1342 },
1343 shouldFail: true,
1344 expectedError: ":UNEXPECTED_MESSAGE:",
1345 },
1346 {
1347 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001348 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001349 shouldFail: true,
1350 expectedError: ":WRONG_SSL_VERSION:",
1351 },
1352 {
1353 protocol: dtls,
1354 name: "DisableEverything-DTLS",
1355 flags: []string{"-no-tls12", "-no-tls1"},
1356 shouldFail: true,
1357 expectedError: ":WRONG_SSL_VERSION:",
1358 },
1359 {
Adam Langley7c803a62015-06-15 15:35:05 -07001360 protocol: dtls,
1361 testType: serverTest,
1362 name: "MTU",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 MaxPacketLength: 256,
1366 },
1367 },
1368 flags: []string{"-mtu", "256"},
1369 },
1370 {
1371 protocol: dtls,
1372 testType: serverTest,
1373 name: "MTUExceeded",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 MaxPacketLength: 255,
1377 },
1378 },
1379 flags: []string{"-mtu", "256"},
1380 shouldFail: true,
1381 expectedLocalError: "dtls: exceeded maximum packet length",
1382 },
1383 {
1384 name: "CertMismatchRSA",
1385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001386 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001387 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001388 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001389 Bugs: ProtocolBugs{
1390 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1391 },
1392 },
1393 shouldFail: true,
1394 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1395 },
1396 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001397 name: "CertMismatchRSA-TLS13",
1398 config: Config{
1399 MaxVersion: VersionTLS13,
1400 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1401 Certificates: []Certificate{ecdsaP256Certificate},
1402 Bugs: ProtocolBugs{
1403 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1404 },
1405 },
1406 shouldFail: true,
1407 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1408 },
1409 {
Adam Langley7c803a62015-06-15 15:35:05 -07001410 name: "CertMismatchECDSA",
1411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001412 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001414 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001415 Bugs: ProtocolBugs{
1416 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1421 },
1422 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001423 name: "CertMismatchECDSA-TLS13",
1424 config: Config{
1425 MaxVersion: VersionTLS13,
1426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1427 Certificates: []Certificate{rsaCertificate},
1428 Bugs: ProtocolBugs{
1429 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1434 },
1435 {
Adam Langley7c803a62015-06-15 15:35:05 -07001436 name: "EmptyCertificateList",
1437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001438 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001439 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1440 Bugs: ProtocolBugs{
1441 EmptyCertificateList: true,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":DECODE_ERROR:",
1446 },
1447 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001448 name: "EmptyCertificateList-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Bugs: ProtocolBugs{
1453 EmptyCertificateList: true,
1454 },
1455 },
1456 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001457 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001458 },
1459 {
Adam Langley7c803a62015-06-15 15:35:05 -07001460 name: "TLSFatalBadPackets",
1461 damageFirstWrite: true,
1462 shouldFail: true,
1463 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1464 },
1465 {
1466 protocol: dtls,
1467 name: "DTLSIgnoreBadPackets",
1468 damageFirstWrite: true,
1469 },
1470 {
1471 protocol: dtls,
1472 name: "DTLSIgnoreBadPackets-Async",
1473 damageFirstWrite: true,
1474 flags: []string{"-async"},
1475 },
1476 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001477 name: "AppDataBeforeHandshake",
1478 config: Config{
1479 Bugs: ProtocolBugs{
1480 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":UNEXPECTED_RECORD:",
1485 },
1486 {
1487 name: "AppDataBeforeHandshake-Empty",
1488 config: Config{
1489 Bugs: ProtocolBugs{
1490 AppDataBeforeHandshake: []byte{},
1491 },
1492 },
1493 shouldFail: true,
1494 expectedError: ":UNEXPECTED_RECORD:",
1495 },
1496 {
1497 protocol: dtls,
1498 name: "AppDataBeforeHandshake-DTLS",
1499 config: Config{
1500 Bugs: ProtocolBugs{
1501 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":UNEXPECTED_RECORD:",
1506 },
1507 {
1508 protocol: dtls,
1509 name: "AppDataBeforeHandshake-DTLS-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
Adam Langley7c803a62015-06-15 15:35:05 -07001519 name: "AppDataAfterChangeCipherSpec",
1520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001521 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001522 Bugs: ProtocolBugs{
1523 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001527 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001528 },
1529 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001530 name: "AppDataAfterChangeCipherSpec-Empty",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte{},
1535 },
1536 },
1537 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001538 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 protocol: dtls,
1542 name: "AppDataAfterChangeCipherSpec-DTLS",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001545 Bugs: ProtocolBugs{
1546 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1547 },
1548 },
1549 // BoringSSL's DTLS implementation will drop the out-of-order
1550 // application data.
1551 },
1552 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001553 protocol: dtls,
1554 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1555 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001556 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 Bugs: ProtocolBugs{
1558 AppDataAfterChangeCipherSpec: []byte{},
1559 },
1560 },
1561 // BoringSSL's DTLS implementation will drop the out-of-order
1562 // application data.
1563 },
1564 {
Adam Langley7c803a62015-06-15 15:35:05 -07001565 name: "AlertAfterChangeCipherSpec",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001568 Bugs: ProtocolBugs{
1569 AlertAfterChangeCipherSpec: alertRecordOverflow,
1570 },
1571 },
1572 shouldFail: true,
1573 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1574 },
1575 {
1576 protocol: dtls,
1577 name: "AlertAfterChangeCipherSpec-DTLS",
1578 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001579 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001580 Bugs: ProtocolBugs{
1581 AlertAfterChangeCipherSpec: alertRecordOverflow,
1582 },
1583 },
1584 shouldFail: true,
1585 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1586 },
1587 {
1588 protocol: dtls,
1589 name: "ReorderHandshakeFragments-Small-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 // Small enough that every handshake message is
1594 // fragmented.
1595 MaxHandshakeRecordLength: 2,
1596 },
1597 },
1598 },
1599 {
1600 protocol: dtls,
1601 name: "ReorderHandshakeFragments-Large-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 ReorderHandshakeFragments: true,
1605 // Large enough that no handshake message is
1606 // fragmented.
1607 MaxHandshakeRecordLength: 2048,
1608 },
1609 },
1610 },
1611 {
1612 protocol: dtls,
1613 name: "MixCompleteMessageWithFragments-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 ReorderHandshakeFragments: true,
1617 MixCompleteMessageWithFragments: true,
1618 MaxHandshakeRecordLength: 2,
1619 },
1620 },
1621 },
1622 {
1623 name: "SendInvalidRecordType",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 SendInvalidRecordType: true,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":UNEXPECTED_RECORD:",
1631 },
1632 {
1633 protocol: dtls,
1634 name: "SendInvalidRecordType-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SendInvalidRecordType: true,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":UNEXPECTED_RECORD:",
1642 },
1643 {
1644 name: "FalseStart-SkipServerSecondLeg",
1645 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001646 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001647 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1648 NextProtos: []string{"foo"},
1649 Bugs: ProtocolBugs{
1650 SkipNewSessionTicket: true,
1651 SkipChangeCipherSpec: true,
1652 SkipFinished: true,
1653 ExpectFalseStart: true,
1654 },
1655 },
1656 flags: []string{
1657 "-false-start",
1658 "-handshake-never-done",
1659 "-advertise-alpn", "\x03foo",
1660 },
1661 shimWritesFirst: true,
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg-Implicit",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 },
1676 },
1677 flags: []string{
1678 "-implicit-handshake",
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shouldFail: true,
1684 expectedError: ":UNEXPECTED_RECORD:",
1685 },
1686 {
1687 testType: serverTest,
1688 name: "FailEarlyCallback",
1689 flags: []string{"-fail-early-callback"},
1690 shouldFail: true,
1691 expectedError: ":CONNECTION_REJECTED:",
1692 expectedLocalError: "remote error: access denied",
1693 },
1694 {
Adam Langley7c803a62015-06-15 15:35:05 -07001695 protocol: dtls,
1696 name: "FragmentMessageTypeMismatch-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 MaxHandshakeRecordLength: 2,
1700 FragmentMessageTypeMismatch: true,
1701 },
1702 },
1703 shouldFail: true,
1704 expectedError: ":FRAGMENT_MISMATCH:",
1705 },
1706 {
1707 protocol: dtls,
1708 name: "FragmentMessageLengthMismatch-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 MaxHandshakeRecordLength: 2,
1712 FragmentMessageLengthMismatch: true,
1713 },
1714 },
1715 shouldFail: true,
1716 expectedError: ":FRAGMENT_MISMATCH:",
1717 },
1718 {
1719 protocol: dtls,
1720 name: "SplitFragments-Header-DTLS",
1721 config: Config{
1722 Bugs: ProtocolBugs{
1723 SplitFragments: 2,
1724 },
1725 },
1726 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001727 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001728 },
1729 {
1730 protocol: dtls,
1731 name: "SplitFragments-Boundary-DTLS",
1732 config: Config{
1733 Bugs: ProtocolBugs{
1734 SplitFragments: dtlsRecordHeaderLen,
1735 },
1736 },
1737 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001738 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Body-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: dtlsRecordHeaderLen + 1,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SendEmptyFragments-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SendEmptyFragments: true,
1757 },
1758 },
1759 },
1760 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001761 name: "BadFinished-Client",
1762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001763 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001764 Bugs: ProtocolBugs{
1765 BadFinished: true,
1766 },
1767 },
1768 shouldFail: true,
1769 expectedError: ":DIGEST_CHECK_FAILED:",
1770 },
1771 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001772 name: "BadFinished-Client-TLS13",
1773 config: Config{
1774 MaxVersion: VersionTLS13,
1775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 testType: serverTest,
1784 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001786 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001795 testType: serverTest,
1796 name: "BadFinished-Server-TLS13",
1797 config: Config{
1798 MaxVersion: VersionTLS13,
1799 Bugs: ProtocolBugs{
1800 BadFinished: true,
1801 },
1802 },
1803 shouldFail: true,
1804 expectedError: ":DIGEST_CHECK_FAILED:",
1805 },
1806 {
Adam Langley7c803a62015-06-15 15:35:05 -07001807 name: "FalseStart-BadFinished",
1808 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1811 NextProtos: []string{"foo"},
1812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 ExpectFalseStart: true,
1815 },
1816 },
1817 flags: []string{
1818 "-false-start",
1819 "-handshake-never-done",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":DIGEST_CHECK_FAILED:",
1825 },
1826 {
1827 name: "NoFalseStart-NoALPN",
1828 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001829 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001830 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 },
1839 shimWritesFirst: true,
1840 shouldFail: true,
1841 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1842 expectedLocalError: "tls: peer did not false start: EOF",
1843 },
1844 {
1845 name: "NoFalseStart-NoAEAD",
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_CBC_SHA},
1849 NextProtos: []string{"foo"},
1850 Bugs: ProtocolBugs{
1851 ExpectFalseStart: true,
1852 AlertBeforeFalseStartTest: alertAccessDenied,
1853 },
1854 },
1855 flags: []string{
1856 "-false-start",
1857 "-advertise-alpn", "\x03foo",
1858 },
1859 shimWritesFirst: true,
1860 shouldFail: true,
1861 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1862 expectedLocalError: "tls: peer did not false start: EOF",
1863 },
1864 {
1865 name: "NoFalseStart-RSA",
1866 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001867 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001868 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1869 NextProtos: []string{"foo"},
1870 Bugs: ProtocolBugs{
1871 ExpectFalseStart: true,
1872 AlertBeforeFalseStartTest: alertAccessDenied,
1873 },
1874 },
1875 flags: []string{
1876 "-false-start",
1877 "-advertise-alpn", "\x03foo",
1878 },
1879 shimWritesFirst: true,
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1882 expectedLocalError: "tls: peer did not false start: EOF",
1883 },
1884 {
1885 name: "NoFalseStart-DHE_RSA",
1886 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001887 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001888 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1889 NextProtos: []string{"foo"},
1890 Bugs: ProtocolBugs{
1891 ExpectFalseStart: true,
1892 AlertBeforeFalseStartTest: alertAccessDenied,
1893 },
1894 },
1895 flags: []string{
1896 "-false-start",
1897 "-advertise-alpn", "\x03foo",
1898 },
1899 shimWritesFirst: true,
1900 shouldFail: true,
1901 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1902 expectedLocalError: "tls: peer did not false start: EOF",
1903 },
1904 {
Adam Langley7c803a62015-06-15 15:35:05 -07001905 protocol: dtls,
1906 name: "SendSplitAlert-Sync",
1907 config: Config{
1908 Bugs: ProtocolBugs{
1909 SendSplitAlert: true,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "SendSplitAlert-Async",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 SendSplitAlert: true,
1919 },
1920 },
1921 flags: []string{"-async"},
1922 },
1923 {
1924 protocol: dtls,
1925 name: "PackDTLSHandshake",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 MaxHandshakeRecordLength: 2,
1929 PackHandshakeFragments: 20,
1930 PackHandshakeRecords: 200,
1931 },
1932 },
1933 },
1934 {
Adam Langley7c803a62015-06-15 15:35:05 -07001935 name: "SendEmptyRecords-Pass",
1936 sendEmptyRecords: 32,
1937 },
1938 {
1939 name: "SendEmptyRecords",
1940 sendEmptyRecords: 33,
1941 shouldFail: true,
1942 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1943 },
1944 {
1945 name: "SendEmptyRecords-Async",
1946 sendEmptyRecords: 33,
1947 flags: []string{"-async"},
1948 shouldFail: true,
1949 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1950 },
1951 {
David Benjamine8e84b92016-08-03 15:39:47 -04001952 name: "SendWarningAlerts-Pass",
1953 config: Config{
1954 MaxVersion: VersionTLS12,
1955 },
Adam Langley7c803a62015-06-15 15:35:05 -07001956 sendWarningAlerts: 4,
1957 },
1958 {
David Benjamine8e84b92016-08-03 15:39:47 -04001959 protocol: dtls,
1960 name: "SendWarningAlerts-DTLS-Pass",
1961 config: Config{
1962 MaxVersion: VersionTLS12,
1963 },
Adam Langley7c803a62015-06-15 15:35:05 -07001964 sendWarningAlerts: 4,
1965 },
1966 {
David Benjamine8e84b92016-08-03 15:39:47 -04001967 name: "SendWarningAlerts-TLS13",
1968 config: Config{
1969 MaxVersion: VersionTLS13,
1970 },
1971 sendWarningAlerts: 4,
1972 shouldFail: true,
1973 expectedError: ":BAD_ALERT:",
1974 expectedLocalError: "remote error: error decoding message",
1975 },
1976 {
1977 name: "SendWarningAlerts",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 5,
1982 shouldFail: true,
1983 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1984 },
1985 {
David Benjamine8e84b92016-08-03 15:39:47 -04001986 name: "SendWarningAlerts-Async",
1987 config: Config{
1988 MaxVersion: VersionTLS12,
1989 },
Adam Langley7c803a62015-06-15 15:35:05 -07001990 sendWarningAlerts: 5,
1991 flags: []string{"-async"},
1992 shouldFail: true,
1993 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1994 },
David Benjaminba4594a2015-06-18 18:36:15 -04001995 {
1996 name: "EmptySessionID",
1997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001998 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001999 SessionTicketsDisabled: true,
2000 },
2001 noSessionCache: true,
2002 flags: []string{"-expect-no-session"},
2003 },
David Benjamin30789da2015-08-29 22:56:45 -04002004 {
2005 name: "Unclean-Shutdown",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 NoCloseNotify: true,
2009 ExpectCloseNotify: true,
2010 },
2011 },
2012 shimShutsDown: true,
2013 flags: []string{"-check-close-notify"},
2014 shouldFail: true,
2015 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2016 },
2017 {
2018 name: "Unclean-Shutdown-Ignored",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 NoCloseNotify: true,
2022 },
2023 },
2024 shimShutsDown: true,
2025 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002026 {
David Benjaminfa214e42016-05-10 17:03:10 -04002027 name: "Unclean-Shutdown-Alert",
2028 config: Config{
2029 Bugs: ProtocolBugs{
2030 SendAlertOnShutdown: alertDecompressionFailure,
2031 ExpectCloseNotify: true,
2032 },
2033 },
2034 shimShutsDown: true,
2035 flags: []string{"-check-close-notify"},
2036 shouldFail: true,
2037 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2038 },
2039 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002040 name: "LargePlaintext",
2041 config: Config{
2042 Bugs: ProtocolBugs{
2043 SendLargeRecords: true,
2044 },
2045 },
2046 messageLen: maxPlaintext + 1,
2047 shouldFail: true,
2048 expectedError: ":DATA_LENGTH_TOO_LONG:",
2049 },
2050 {
2051 protocol: dtls,
2052 name: "LargePlaintext-DTLS",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 SendLargeRecords: true,
2056 },
2057 },
2058 messageLen: maxPlaintext + 1,
2059 shouldFail: true,
2060 expectedError: ":DATA_LENGTH_TOO_LONG:",
2061 },
2062 {
2063 name: "LargeCiphertext",
2064 config: Config{
2065 Bugs: ProtocolBugs{
2066 SendLargeRecords: true,
2067 },
2068 },
2069 messageLen: maxPlaintext * 2,
2070 shouldFail: true,
2071 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2072 },
2073 {
2074 protocol: dtls,
2075 name: "LargeCiphertext-DTLS",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendLargeRecords: true,
2079 },
2080 },
2081 messageLen: maxPlaintext * 2,
2082 // Unlike the other four cases, DTLS drops records which
2083 // are invalid before authentication, so the connection
2084 // does not fail.
2085 expectMessageDropped: true,
2086 },
David Benjamindd6fed92015-10-23 17:41:12 -04002087 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 // In TLS 1.2 and below, empty NewSessionTicket messages
2089 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002090 name: "SendEmptySessionTicket",
2091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002092 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002093 Bugs: ProtocolBugs{
2094 SendEmptySessionTicket: true,
2095 FailIfSessionOffered: true,
2096 },
2097 },
2098 flags: []string{"-expect-no-session"},
2099 resumeSession: true,
2100 expectResumeRejected: true,
2101 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002102 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002103 name: "BadHelloRequest-1",
2104 renegotiate: 1,
2105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002106 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002107 Bugs: ProtocolBugs{
2108 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2109 },
2110 },
2111 flags: []string{
2112 "-renegotiate-freely",
2113 "-expect-total-renegotiations", "1",
2114 },
2115 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002116 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002117 },
2118 {
2119 name: "BadHelloRequest-2",
2120 renegotiate: 1,
2121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002123 Bugs: ProtocolBugs{
2124 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2125 },
2126 },
2127 flags: []string{
2128 "-renegotiate-freely",
2129 "-expect-total-renegotiations", "1",
2130 },
2131 shouldFail: true,
2132 expectedError: ":BAD_HELLO_REQUEST:",
2133 },
David Benjaminef1b0092015-11-21 14:05:44 -05002134 {
2135 testType: serverTest,
2136 name: "SupportTicketsWithSessionID",
2137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002138 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002139 SessionTicketsDisabled: true,
2140 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002141 resumeConfig: &Config{
2142 MaxVersion: VersionTLS12,
2143 },
David Benjaminef1b0092015-11-21 14:05:44 -05002144 resumeSession: true,
2145 },
David Benjamin02edcd02016-07-27 17:40:37 -04002146 {
2147 protocol: dtls,
2148 name: "DTLS-SendExtraFinished",
2149 config: Config{
2150 Bugs: ProtocolBugs{
2151 SendExtraFinished: true,
2152 },
2153 },
2154 shouldFail: true,
2155 expectedError: ":UNEXPECTED_RECORD:",
2156 },
2157 {
2158 protocol: dtls,
2159 name: "DTLS-SendExtraFinished-Reordered",
2160 config: Config{
2161 Bugs: ProtocolBugs{
2162 MaxHandshakeRecordLength: 2,
2163 ReorderHandshakeFragments: true,
2164 SendExtraFinished: true,
2165 },
2166 },
2167 shouldFail: true,
2168 expectedError: ":UNEXPECTED_RECORD:",
2169 },
David Benjamine97fb482016-07-29 09:23:07 -04002170 {
2171 testType: serverTest,
2172 name: "V2ClientHello-EmptyRecordPrefix",
2173 config: Config{
2174 // Choose a cipher suite that does not involve
2175 // elliptic curves, so no extensions are
2176 // involved.
2177 MaxVersion: VersionTLS12,
2178 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2179 Bugs: ProtocolBugs{
2180 SendV2ClientHello: true,
2181 },
2182 },
2183 sendPrefix: string([]byte{
2184 byte(recordTypeHandshake),
2185 3, 1, // version
2186 0, 0, // length
2187 }),
2188 // A no-op empty record may not be sent before V2ClientHello.
2189 shouldFail: true,
2190 expectedError: ":WRONG_VERSION_NUMBER:",
2191 },
2192 {
2193 testType: serverTest,
2194 name: "V2ClientHello-WarningAlertPrefix",
2195 config: Config{
2196 // Choose a cipher suite that does not involve
2197 // elliptic curves, so no extensions are
2198 // involved.
2199 MaxVersion: VersionTLS12,
2200 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2201 Bugs: ProtocolBugs{
2202 SendV2ClientHello: true,
2203 },
2204 },
2205 sendPrefix: string([]byte{
2206 byte(recordTypeAlert),
2207 3, 1, // version
2208 0, 2, // length
2209 alertLevelWarning, byte(alertDecompressionFailure),
2210 }),
2211 // A no-op warning alert may not be sent before V2ClientHello.
2212 shouldFail: true,
2213 expectedError: ":WRONG_VERSION_NUMBER:",
2214 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002215 {
2216 testType: clientTest,
2217 name: "KeyUpdate",
2218 config: Config{
2219 MaxVersion: VersionTLS13,
2220 Bugs: ProtocolBugs{
2221 SendKeyUpdateBeforeEveryAppDataRecord: true,
2222 },
2223 },
2224 },
Adam Langley7c803a62015-06-15 15:35:05 -07002225 }
Adam Langley7c803a62015-06-15 15:35:05 -07002226 testCases = append(testCases, basicTests...)
2227}
2228
Adam Langley95c29f32014-06-20 12:00:00 -07002229func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002230 const bogusCipher = 0xfe00
2231
Adam Langley95c29f32014-06-20 12:00:00 -07002232 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002233 const psk = "12345"
2234 const pskIdentity = "luggage combo"
2235
Adam Langley95c29f32014-06-20 12:00:00 -07002236 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002237 var certFile string
2238 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002239 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002240 cert = ecdsaP256Certificate
2241 certFile = ecdsaP256CertificateFile
2242 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002243 } else {
David Benjamin33863262016-07-08 17:20:12 -07002244 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002245 certFile = rsaCertificateFile
2246 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002247 }
2248
David Benjamin48cae082014-10-27 01:06:24 -04002249 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002250 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002251 flags = append(flags,
2252 "-psk", psk,
2253 "-psk-identity", pskIdentity)
2254 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002255 if hasComponent(suite.name, "NULL") {
2256 // NULL ciphers must be explicitly enabled.
2257 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2258 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002259 if hasComponent(suite.name, "CECPQ1") {
2260 // CECPQ1 ciphers must be explicitly enabled.
2261 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2262 }
David Benjamin881f1962016-08-10 18:29:12 -04002263 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2264 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2265 // for now.
2266 flags = append(flags, "-cipher", suite.name)
2267 }
David Benjamin48cae082014-10-27 01:06:24 -04002268
Adam Langley95c29f32014-06-20 12:00:00 -07002269 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002270 for _, protocol := range []protocol{tls, dtls} {
2271 var prefix string
2272 if protocol == dtls {
2273 if !ver.hasDTLS {
2274 continue
2275 }
2276 prefix = "D"
2277 }
Adam Langley95c29f32014-06-20 12:00:00 -07002278
David Benjamin0407e762016-06-17 16:41:18 -04002279 var shouldServerFail, shouldClientFail bool
2280 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2281 // BoringSSL clients accept ECDHE on SSLv3, but
2282 // a BoringSSL server will never select it
2283 // because the extension is missing.
2284 shouldServerFail = true
2285 }
2286 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2287 shouldClientFail = true
2288 shouldServerFail = true
2289 }
David Benjamin54c217c2016-07-13 12:35:25 -04002290 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002291 shouldClientFail = true
2292 shouldServerFail = true
2293 }
David Benjamin0407e762016-06-17 16:41:18 -04002294 if !isDTLSCipher(suite.name) && protocol == dtls {
2295 shouldClientFail = true
2296 shouldServerFail = true
2297 }
David Benjamin4298d772015-12-19 00:18:25 -05002298
David Benjamin0407e762016-06-17 16:41:18 -04002299 var expectedServerError, expectedClientError string
2300 if shouldServerFail {
2301 expectedServerError = ":NO_SHARED_CIPHER:"
2302 }
2303 if shouldClientFail {
2304 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2305 }
David Benjamin025b3d32014-07-01 19:53:04 -04002306
David Benjamin6fd297b2014-08-11 18:43:38 -04002307 testCases = append(testCases, testCase{
2308 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002309 protocol: protocol,
2310
2311 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002312 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002313 MinVersion: ver.version,
2314 MaxVersion: ver.version,
2315 CipherSuites: []uint16{suite.id},
2316 Certificates: []Certificate{cert},
2317 PreSharedKey: []byte(psk),
2318 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002319 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002320 EnableAllCiphers: shouldServerFail,
2321 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002322 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002323 },
2324 certFile: certFile,
2325 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002326 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002327 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002328 shouldFail: shouldServerFail,
2329 expectedError: expectedServerError,
2330 })
2331
2332 testCases = append(testCases, testCase{
2333 testType: clientTest,
2334 protocol: protocol,
2335 name: prefix + ver.name + "-" + suite.name + "-client",
2336 config: Config{
2337 MinVersion: ver.version,
2338 MaxVersion: ver.version,
2339 CipherSuites: []uint16{suite.id},
2340 Certificates: []Certificate{cert},
2341 PreSharedKey: []byte(psk),
2342 PreSharedKeyIdentity: pskIdentity,
2343 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002344 EnableAllCiphers: shouldClientFail,
2345 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002346 },
2347 },
2348 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002349 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002350 shouldFail: shouldClientFail,
2351 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002352 })
David Benjamin2c99d282015-09-01 10:23:00 -04002353
Nick Harper1fd39d82016-06-14 18:14:35 -07002354 if !shouldClientFail {
2355 // Ensure the maximum record size is accepted.
2356 testCases = append(testCases, testCase{
2357 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2358 config: Config{
2359 MinVersion: ver.version,
2360 MaxVersion: ver.version,
2361 CipherSuites: []uint16{suite.id},
2362 Certificates: []Certificate{cert},
2363 PreSharedKey: []byte(psk),
2364 PreSharedKeyIdentity: pskIdentity,
2365 },
2366 flags: flags,
2367 messageLen: maxPlaintext,
2368 })
2369 }
2370 }
David Benjamin2c99d282015-09-01 10:23:00 -04002371 }
Adam Langley95c29f32014-06-20 12:00:00 -07002372 }
Adam Langleya7997f12015-05-14 17:38:50 -07002373
2374 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002375 name: "NoSharedCipher",
2376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002377 MaxVersion: VersionTLS12,
2378 CipherSuites: []uint16{},
2379 },
2380 shouldFail: true,
2381 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2382 })
2383
2384 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002385 name: "NoSharedCipher-TLS13",
2386 config: Config{
2387 MaxVersion: VersionTLS13,
2388 CipherSuites: []uint16{},
2389 },
2390 shouldFail: true,
2391 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2392 })
2393
2394 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002395 name: "UnsupportedCipherSuite",
2396 config: Config{
2397 MaxVersion: VersionTLS12,
2398 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2399 Bugs: ProtocolBugs{
2400 IgnorePeerCipherPreferences: true,
2401 },
2402 },
2403 flags: []string{"-cipher", "DEFAULT:!RC4"},
2404 shouldFail: true,
2405 expectedError: ":WRONG_CIPHER_RETURNED:",
2406 })
2407
2408 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002409 name: "ServerHelloBogusCipher",
2410 config: Config{
2411 MaxVersion: VersionTLS12,
2412 Bugs: ProtocolBugs{
2413 SendCipherSuite: bogusCipher,
2414 },
2415 },
2416 shouldFail: true,
2417 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2418 })
2419 testCases = append(testCases, testCase{
2420 name: "ServerHelloBogusCipher-TLS13",
2421 config: Config{
2422 MaxVersion: VersionTLS13,
2423 Bugs: ProtocolBugs{
2424 SendCipherSuite: bogusCipher,
2425 },
2426 },
2427 shouldFail: true,
2428 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2429 })
2430
2431 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002432 name: "WeakDH",
2433 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002434 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002435 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2436 Bugs: ProtocolBugs{
2437 // This is a 1023-bit prime number, generated
2438 // with:
2439 // openssl gendh 1023 | openssl asn1parse -i
2440 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2441 },
2442 },
2443 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002444 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002445 })
Adam Langleycef75832015-09-03 14:51:12 -07002446
David Benjamincd24a392015-11-11 13:23:05 -08002447 testCases = append(testCases, testCase{
2448 name: "SillyDH",
2449 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002450 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002451 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2452 Bugs: ProtocolBugs{
2453 // This is a 4097-bit prime number, generated
2454 // with:
2455 // openssl gendh 4097 | openssl asn1parse -i
2456 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2457 },
2458 },
2459 shouldFail: true,
2460 expectedError: ":DH_P_TOO_LONG:",
2461 })
2462
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002463 // This test ensures that Diffie-Hellman public values are padded with
2464 // zeros so that they're the same length as the prime. This is to avoid
2465 // hitting a bug in yaSSL.
2466 testCases = append(testCases, testCase{
2467 testType: serverTest,
2468 name: "DHPublicValuePadded",
2469 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002470 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002471 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2472 Bugs: ProtocolBugs{
2473 RequireDHPublicValueLen: (1025 + 7) / 8,
2474 },
2475 },
2476 flags: []string{"-use-sparse-dh-prime"},
2477 })
David Benjamincd24a392015-11-11 13:23:05 -08002478
David Benjamin241ae832016-01-15 03:04:54 -05002479 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002480 testCases = append(testCases, testCase{
2481 testType: serverTest,
2482 name: "UnknownCipher",
2483 config: Config{
2484 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2485 },
2486 })
2487
Adam Langleycef75832015-09-03 14:51:12 -07002488 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2489 // 1.1 specific cipher suite settings. A server is setup with the given
2490 // cipher lists and then a connection is made for each member of
2491 // expectations. The cipher suite that the server selects must match
2492 // the specified one.
2493 var versionSpecificCiphersTest = []struct {
2494 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2495 // expectations is a map from TLS version to cipher suite id.
2496 expectations map[uint16]uint16
2497 }{
2498 {
2499 // Test that the null case (where no version-specific ciphers are set)
2500 // works as expected.
2501 "RC4-SHA:AES128-SHA", // default ciphers
2502 "", // no ciphers specifically for TLS ≥ 1.0
2503 "", // no ciphers specifically for TLS ≥ 1.1
2504 map[uint16]uint16{
2505 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2506 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2507 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2508 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2509 },
2510 },
2511 {
2512 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2513 // cipher.
2514 "RC4-SHA:AES128-SHA", // default
2515 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2516 "", // no ciphers specifically for TLS ≥ 1.1
2517 map[uint16]uint16{
2518 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2519 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2520 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2521 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2522 },
2523 },
2524 {
2525 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2526 // cipher.
2527 "RC4-SHA:AES128-SHA", // default
2528 "", // no ciphers specifically for TLS ≥ 1.0
2529 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2530 map[uint16]uint16{
2531 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2532 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2533 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2534 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2535 },
2536 },
2537 {
2538 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2539 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2540 "RC4-SHA:AES128-SHA", // default
2541 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2542 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2543 map[uint16]uint16{
2544 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2545 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2546 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2547 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2548 },
2549 },
2550 }
2551
2552 for i, test := range versionSpecificCiphersTest {
2553 for version, expectedCipherSuite := range test.expectations {
2554 flags := []string{"-cipher", test.ciphersDefault}
2555 if len(test.ciphersTLS10) > 0 {
2556 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2557 }
2558 if len(test.ciphersTLS11) > 0 {
2559 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2560 }
2561
2562 testCases = append(testCases, testCase{
2563 testType: serverTest,
2564 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2565 config: Config{
2566 MaxVersion: version,
2567 MinVersion: version,
2568 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2569 },
2570 flags: flags,
2571 expectedCipher: expectedCipherSuite,
2572 })
2573 }
2574 }
Adam Langley95c29f32014-06-20 12:00:00 -07002575}
2576
2577func addBadECDSASignatureTests() {
2578 for badR := BadValue(1); badR < NumBadValues; badR++ {
2579 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002580 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002581 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2582 config: Config{
2583 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002584 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002585 Bugs: ProtocolBugs{
2586 BadECDSAR: badR,
2587 BadECDSAS: badS,
2588 },
2589 },
2590 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002591 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002592 })
2593 }
2594 }
2595}
2596
Adam Langley80842bd2014-06-20 12:00:00 -07002597func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002598 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002599 name: "MaxCBCPadding",
2600 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002601 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2603 Bugs: ProtocolBugs{
2604 MaxPadding: true,
2605 },
2606 },
2607 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2608 })
David Benjamin025b3d32014-07-01 19:53:04 -04002609 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002610 name: "BadCBCPadding",
2611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002612 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2614 Bugs: ProtocolBugs{
2615 PaddingFirstByteBad: true,
2616 },
2617 },
2618 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002619 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002620 })
2621 // OpenSSL previously had an issue where the first byte of padding in
2622 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002623 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002624 name: "BadCBCPadding255",
2625 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002626 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002627 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2628 Bugs: ProtocolBugs{
2629 MaxPadding: true,
2630 PaddingFirstByteBadIf255: true,
2631 },
2632 },
2633 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2634 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002635 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002636 })
2637}
2638
Kenny Root7fdeaf12014-08-05 15:23:37 -07002639func addCBCSplittingTests() {
2640 testCases = append(testCases, testCase{
2641 name: "CBCRecordSplitting",
2642 config: Config{
2643 MaxVersion: VersionTLS10,
2644 MinVersion: VersionTLS10,
2645 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2646 },
David Benjaminac8302a2015-09-01 17:18:15 -04002647 messageLen: -1, // read until EOF
2648 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002649 flags: []string{
2650 "-async",
2651 "-write-different-record-sizes",
2652 "-cbc-record-splitting",
2653 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002654 })
2655 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002656 name: "CBCRecordSplittingPartialWrite",
2657 config: Config{
2658 MaxVersion: VersionTLS10,
2659 MinVersion: VersionTLS10,
2660 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2661 },
2662 messageLen: -1, // read until EOF
2663 flags: []string{
2664 "-async",
2665 "-write-different-record-sizes",
2666 "-cbc-record-splitting",
2667 "-partial-write",
2668 },
2669 })
2670}
2671
David Benjamin636293b2014-07-08 17:59:18 -04002672func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002673 // Add a dummy cert pool to stress certificate authority parsing.
2674 // TODO(davidben): Add tests that those values parse out correctly.
2675 certPool := x509.NewCertPool()
2676 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2677 if err != nil {
2678 panic(err)
2679 }
2680 certPool.AddCert(cert)
2681
David Benjamin636293b2014-07-08 17:59:18 -04002682 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002683 testCases = append(testCases, testCase{
2684 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002685 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002686 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002687 MinVersion: ver.version,
2688 MaxVersion: ver.version,
2689 ClientAuth: RequireAnyClientCert,
2690 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002691 },
2692 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002695 },
2696 })
2697 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002698 testType: serverTest,
2699 name: ver.name + "-Server-ClientAuth-RSA",
2700 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002701 MinVersion: ver.version,
2702 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002703 Certificates: []Certificate{rsaCertificate},
2704 },
2705 flags: []string{"-require-any-client-certificate"},
2706 })
David Benjamine098ec22014-08-27 23:13:20 -04002707 if ver.version != VersionSSL30 {
2708 testCases = append(testCases, testCase{
2709 testType: serverTest,
2710 name: ver.name + "-Server-ClientAuth-ECDSA",
2711 config: Config{
2712 MinVersion: ver.version,
2713 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002714 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002715 },
2716 flags: []string{"-require-any-client-certificate"},
2717 })
2718 testCases = append(testCases, testCase{
2719 testType: clientTest,
2720 name: ver.name + "-Client-ClientAuth-ECDSA",
2721 config: Config{
2722 MinVersion: ver.version,
2723 MaxVersion: ver.version,
2724 ClientAuth: RequireAnyClientCert,
2725 ClientCAs: certPool,
2726 },
2727 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002728 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2729 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002730 },
2731 })
2732 }
David Benjamin636293b2014-07-08 17:59:18 -04002733 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002734
2735 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002736 name: "NoClientCertificate",
2737 config: Config{
2738 MaxVersion: VersionTLS12,
2739 ClientAuth: RequireAnyClientCert,
2740 },
2741 shouldFail: true,
2742 expectedLocalError: "client didn't provide a certificate",
2743 })
2744
2745 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002746 name: "NoClientCertificate-TLS13",
2747 config: Config{
2748 MaxVersion: VersionTLS13,
2749 ClientAuth: RequireAnyClientCert,
2750 },
2751 shouldFail: true,
2752 expectedLocalError: "client didn't provide a certificate",
2753 })
2754
2755 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002756 testType: serverTest,
2757 name: "RequireAnyClientCertificate",
2758 config: Config{
2759 MaxVersion: VersionTLS12,
2760 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002761 flags: []string{"-require-any-client-certificate"},
2762 shouldFail: true,
2763 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2764 })
2765
2766 testCases = append(testCases, testCase{
2767 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002768 name: "RequireAnyClientCertificate-TLS13",
2769 config: Config{
2770 MaxVersion: VersionTLS13,
2771 },
2772 flags: []string{"-require-any-client-certificate"},
2773 shouldFail: true,
2774 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2775 })
2776
2777 testCases = append(testCases, testCase{
2778 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002779 name: "RequireAnyClientCertificate-SSL3",
2780 config: Config{
2781 MaxVersion: VersionSSL30,
2782 },
2783 flags: []string{"-require-any-client-certificate"},
2784 shouldFail: true,
2785 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2786 })
2787
2788 testCases = append(testCases, testCase{
2789 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002790 name: "SkipClientCertificate",
2791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002792 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002793 Bugs: ProtocolBugs{
2794 SkipClientCertificate: true,
2795 },
2796 },
2797 // Setting SSL_VERIFY_PEER allows anonymous clients.
2798 flags: []string{"-verify-peer"},
2799 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002800 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002801 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002802
Steven Valdez143e8b32016-07-11 13:19:03 -04002803 testCases = append(testCases, testCase{
2804 testType: serverTest,
2805 name: "SkipClientCertificate-TLS13",
2806 config: Config{
2807 MaxVersion: VersionTLS13,
2808 Bugs: ProtocolBugs{
2809 SkipClientCertificate: true,
2810 },
2811 },
2812 // Setting SSL_VERIFY_PEER allows anonymous clients.
2813 flags: []string{"-verify-peer"},
2814 shouldFail: true,
2815 expectedError: ":UNEXPECTED_MESSAGE:",
2816 })
2817
David Benjaminc032dfa2016-05-12 14:54:57 -04002818 // Client auth is only legal in certificate-based ciphers.
2819 testCases = append(testCases, testCase{
2820 testType: clientTest,
2821 name: "ClientAuth-PSK",
2822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002823 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002824 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2825 PreSharedKey: []byte("secret"),
2826 ClientAuth: RequireAnyClientCert,
2827 },
2828 flags: []string{
2829 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2830 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2831 "-psk", "secret",
2832 },
2833 shouldFail: true,
2834 expectedError: ":UNEXPECTED_MESSAGE:",
2835 })
2836 testCases = append(testCases, testCase{
2837 testType: clientTest,
2838 name: "ClientAuth-ECDHE_PSK",
2839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002840 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002841 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2842 PreSharedKey: []byte("secret"),
2843 ClientAuth: RequireAnyClientCert,
2844 },
2845 flags: []string{
2846 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2847 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2848 "-psk", "secret",
2849 },
2850 shouldFail: true,
2851 expectedError: ":UNEXPECTED_MESSAGE:",
2852 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002853
2854 // Regression test for a bug where the client CA list, if explicitly
2855 // set to NULL, was mis-encoded.
2856 testCases = append(testCases, testCase{
2857 testType: serverTest,
2858 name: "Null-Client-CA-List",
2859 config: Config{
2860 MaxVersion: VersionTLS12,
2861 Certificates: []Certificate{rsaCertificate},
2862 },
2863 flags: []string{
2864 "-require-any-client-certificate",
2865 "-use-null-client-ca-list",
2866 },
2867 })
David Benjamin636293b2014-07-08 17:59:18 -04002868}
2869
Adam Langley75712922014-10-10 16:23:43 -07002870func addExtendedMasterSecretTests() {
2871 const expectEMSFlag = "-expect-extended-master-secret"
2872
2873 for _, with := range []bool{false, true} {
2874 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002875 if with {
2876 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002877 }
2878
2879 for _, isClient := range []bool{false, true} {
2880 suffix := "-Server"
2881 testType := serverTest
2882 if isClient {
2883 suffix = "-Client"
2884 testType = clientTest
2885 }
2886
2887 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002888 // In TLS 1.3, the extension is irrelevant and
2889 // always reports as enabled.
2890 var flags []string
2891 if with || ver.version >= VersionTLS13 {
2892 flags = []string{expectEMSFlag}
2893 }
2894
Adam Langley75712922014-10-10 16:23:43 -07002895 test := testCase{
2896 testType: testType,
2897 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2898 config: Config{
2899 MinVersion: ver.version,
2900 MaxVersion: ver.version,
2901 Bugs: ProtocolBugs{
2902 NoExtendedMasterSecret: !with,
2903 RequireExtendedMasterSecret: with,
2904 },
2905 },
David Benjamin48cae082014-10-27 01:06:24 -04002906 flags: flags,
2907 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002908 }
2909 if test.shouldFail {
2910 test.expectedLocalError = "extended master secret required but not supported by peer"
2911 }
2912 testCases = append(testCases, test)
2913 }
2914 }
2915 }
2916
Adam Langleyba5934b2015-06-02 10:50:35 -07002917 for _, isClient := range []bool{false, true} {
2918 for _, supportedInFirstConnection := range []bool{false, true} {
2919 for _, supportedInResumeConnection := range []bool{false, true} {
2920 boolToWord := func(b bool) string {
2921 if b {
2922 return "Yes"
2923 }
2924 return "No"
2925 }
2926 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2927 if isClient {
2928 suffix += "Client"
2929 } else {
2930 suffix += "Server"
2931 }
2932
2933 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002935 Bugs: ProtocolBugs{
2936 RequireExtendedMasterSecret: true,
2937 },
2938 }
2939
2940 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002941 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002942 Bugs: ProtocolBugs{
2943 NoExtendedMasterSecret: true,
2944 },
2945 }
2946
2947 test := testCase{
2948 name: "ExtendedMasterSecret-" + suffix,
2949 resumeSession: true,
2950 }
2951
2952 if !isClient {
2953 test.testType = serverTest
2954 }
2955
2956 if supportedInFirstConnection {
2957 test.config = supportedConfig
2958 } else {
2959 test.config = noSupportConfig
2960 }
2961
2962 if supportedInResumeConnection {
2963 test.resumeConfig = &supportedConfig
2964 } else {
2965 test.resumeConfig = &noSupportConfig
2966 }
2967
2968 switch suffix {
2969 case "YesToYes-Client", "YesToYes-Server":
2970 // When a session is resumed, it should
2971 // still be aware that its master
2972 // secret was generated via EMS and
2973 // thus it's safe to use tls-unique.
2974 test.flags = []string{expectEMSFlag}
2975 case "NoToYes-Server":
2976 // If an original connection did not
2977 // contain EMS, but a resumption
2978 // handshake does, then a server should
2979 // not resume the session.
2980 test.expectResumeRejected = true
2981 case "YesToNo-Server":
2982 // Resuming an EMS session without the
2983 // EMS extension should cause the
2984 // server to abort the connection.
2985 test.shouldFail = true
2986 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2987 case "NoToYes-Client":
2988 // A client should abort a connection
2989 // where the server resumed a non-EMS
2990 // session but echoed the EMS
2991 // extension.
2992 test.shouldFail = true
2993 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2994 case "YesToNo-Client":
2995 // A client should abort a connection
2996 // where the server didn't echo EMS
2997 // when the session used it.
2998 test.shouldFail = true
2999 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3000 }
3001
3002 testCases = append(testCases, test)
3003 }
3004 }
3005 }
Adam Langley75712922014-10-10 16:23:43 -07003006}
3007
David Benjamin582ba042016-07-07 12:33:25 -07003008type stateMachineTestConfig struct {
3009 protocol protocol
3010 async bool
3011 splitHandshake, packHandshakeFlight bool
3012}
3013
David Benjamin43ec06f2014-08-05 02:28:57 -04003014// Adds tests that try to cover the range of the handshake state machine, under
3015// various conditions. Some of these are redundant with other tests, but they
3016// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003017func addAllStateMachineCoverageTests() {
3018 for _, async := range []bool{false, true} {
3019 for _, protocol := range []protocol{tls, dtls} {
3020 addStateMachineCoverageTests(stateMachineTestConfig{
3021 protocol: protocol,
3022 async: async,
3023 })
3024 addStateMachineCoverageTests(stateMachineTestConfig{
3025 protocol: protocol,
3026 async: async,
3027 splitHandshake: true,
3028 })
3029 if protocol == tls {
3030 addStateMachineCoverageTests(stateMachineTestConfig{
3031 protocol: protocol,
3032 async: async,
3033 packHandshakeFlight: true,
3034 })
3035 }
3036 }
3037 }
3038}
3039
3040func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003041 var tests []testCase
3042
3043 // Basic handshake, with resumption. Client and server,
3044 // session ID and session ticket.
3045 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003046 name: "Basic-Client",
3047 config: Config{
3048 MaxVersion: VersionTLS12,
3049 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003050 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003051 // Ensure session tickets are used, not session IDs.
3052 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003053 })
3054 tests = append(tests, testCase{
3055 name: "Basic-Client-RenewTicket",
3056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003057 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003058 Bugs: ProtocolBugs{
3059 RenewTicketOnResume: true,
3060 },
3061 },
David Benjaminba4594a2015-06-18 18:36:15 -04003062 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003063 resumeSession: true,
3064 })
3065 tests = append(tests, testCase{
3066 name: "Basic-Client-NoTicket",
3067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003069 SessionTicketsDisabled: true,
3070 },
3071 resumeSession: true,
3072 })
3073 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003074 name: "Basic-Client-Implicit",
3075 config: Config{
3076 MaxVersion: VersionTLS12,
3077 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003078 flags: []string{"-implicit-handshake"},
3079 resumeSession: true,
3080 })
3081 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003082 testType: serverTest,
3083 name: "Basic-Server",
3084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003085 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003086 Bugs: ProtocolBugs{
3087 RequireSessionTickets: true,
3088 },
3089 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 resumeSession: true,
3091 })
3092 tests = append(tests, testCase{
3093 testType: serverTest,
3094 name: "Basic-Server-NoTickets",
3095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 SessionTicketsDisabled: true,
3098 },
3099 resumeSession: true,
3100 })
3101 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003102 testType: serverTest,
3103 name: "Basic-Server-Implicit",
3104 config: Config{
3105 MaxVersion: VersionTLS12,
3106 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003107 flags: []string{"-implicit-handshake"},
3108 resumeSession: true,
3109 })
3110 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 testType: serverTest,
3112 name: "Basic-Server-EarlyCallback",
3113 config: Config{
3114 MaxVersion: VersionTLS12,
3115 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003116 flags: []string{"-use-early-callback"},
3117 resumeSession: true,
3118 })
3119
Steven Valdez143e8b32016-07-11 13:19:03 -04003120 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003121 if config.protocol == tls {
3122 tests = append(tests, testCase{
3123 name: "TLS13-1RTT-Client",
3124 config: Config{
3125 MaxVersion: VersionTLS13,
3126 MinVersion: VersionTLS13,
3127 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003128 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003129 })
3130
3131 tests = append(tests, testCase{
3132 testType: serverTest,
3133 name: "TLS13-1RTT-Server",
3134 config: Config{
3135 MaxVersion: VersionTLS13,
3136 MinVersion: VersionTLS13,
3137 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003138 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003139 })
3140
3141 tests = append(tests, testCase{
3142 name: "TLS13-HelloRetryRequest-Client",
3143 config: Config{
3144 MaxVersion: VersionTLS13,
3145 MinVersion: VersionTLS13,
3146 // P-384 requires a HelloRetryRequest against
3147 // BoringSSL's default configuration. Assert
3148 // that we do indeed test this with
3149 // ExpectMissingKeyShare.
3150 CurvePreferences: []CurveID{CurveP384},
3151 Bugs: ProtocolBugs{
3152 ExpectMissingKeyShare: true,
3153 },
3154 },
3155 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3156 resumeSession: true,
3157 })
3158
3159 tests = append(tests, testCase{
3160 testType: serverTest,
3161 name: "TLS13-HelloRetryRequest-Server",
3162 config: Config{
3163 MaxVersion: VersionTLS13,
3164 MinVersion: VersionTLS13,
3165 // Require a HelloRetryRequest for every curve.
3166 DefaultCurves: []CurveID{},
3167 },
3168 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3169 resumeSession: true,
3170 })
3171 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003172
David Benjamin760b1dd2015-05-15 23:33:48 -04003173 // TLS client auth.
3174 tests = append(tests, testCase{
3175 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003176 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003178 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003179 ClientAuth: RequestClientCert,
3180 },
3181 })
3182 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003183 testType: serverTest,
3184 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003185 config: Config{
3186 MaxVersion: VersionTLS12,
3187 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003188 // Setting SSL_VERIFY_PEER allows anonymous clients.
3189 flags: []string{"-verify-peer"},
3190 })
David Benjamin582ba042016-07-07 12:33:25 -07003191 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003192 tests = append(tests, testCase{
3193 testType: clientTest,
3194 name: "ClientAuth-NoCertificate-Client-SSL3",
3195 config: Config{
3196 MaxVersion: VersionSSL30,
3197 ClientAuth: RequestClientCert,
3198 },
3199 })
3200 tests = append(tests, testCase{
3201 testType: serverTest,
3202 name: "ClientAuth-NoCertificate-Server-SSL3",
3203 config: Config{
3204 MaxVersion: VersionSSL30,
3205 },
3206 // Setting SSL_VERIFY_PEER allows anonymous clients.
3207 flags: []string{"-verify-peer"},
3208 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003209 tests = append(tests, testCase{
3210 testType: clientTest,
3211 name: "ClientAuth-NoCertificate-Client-TLS13",
3212 config: Config{
3213 MaxVersion: VersionTLS13,
3214 ClientAuth: RequestClientCert,
3215 },
3216 })
3217 tests = append(tests, testCase{
3218 testType: serverTest,
3219 name: "ClientAuth-NoCertificate-Server-TLS13",
3220 config: Config{
3221 MaxVersion: VersionTLS13,
3222 },
3223 // Setting SSL_VERIFY_PEER allows anonymous clients.
3224 flags: []string{"-verify-peer"},
3225 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003226 }
3227 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003228 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003229 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003231 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003232 ClientAuth: RequireAnyClientCert,
3233 },
3234 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003235 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3236 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003237 },
3238 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003239 tests = append(tests, testCase{
3240 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003241 name: "ClientAuth-RSA-Client-TLS13",
3242 config: Config{
3243 MaxVersion: VersionTLS13,
3244 ClientAuth: RequireAnyClientCert,
3245 },
3246 flags: []string{
3247 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3248 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3249 },
3250 })
3251 tests = append(tests, testCase{
3252 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003253 name: "ClientAuth-ECDSA-Client",
3254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003255 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003256 ClientAuth: RequireAnyClientCert,
3257 },
3258 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003259 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3260 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003261 },
3262 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003263 tests = append(tests, testCase{
3264 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003265 name: "ClientAuth-ECDSA-Client-TLS13",
3266 config: Config{
3267 MaxVersion: VersionTLS13,
3268 ClientAuth: RequireAnyClientCert,
3269 },
3270 flags: []string{
3271 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3272 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3273 },
3274 })
3275 tests = append(tests, testCase{
3276 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003277 name: "ClientAuth-NoCertificate-OldCallback",
3278 config: Config{
3279 MaxVersion: VersionTLS12,
3280 ClientAuth: RequestClientCert,
3281 },
3282 flags: []string{"-use-old-client-cert-callback"},
3283 })
3284 tests = append(tests, testCase{
3285 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003286 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3287 config: Config{
3288 MaxVersion: VersionTLS13,
3289 ClientAuth: RequestClientCert,
3290 },
3291 flags: []string{"-use-old-client-cert-callback"},
3292 })
3293 tests = append(tests, testCase{
3294 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003295 name: "ClientAuth-OldCallback",
3296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003297 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003298 ClientAuth: RequireAnyClientCert,
3299 },
3300 flags: []string{
3301 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3302 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3303 "-use-old-client-cert-callback",
3304 },
3305 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003306 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003307 testType: clientTest,
3308 name: "ClientAuth-OldCallback-TLS13",
3309 config: Config{
3310 MaxVersion: VersionTLS13,
3311 ClientAuth: RequireAnyClientCert,
3312 },
3313 flags: []string{
3314 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3315 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3316 "-use-old-client-cert-callback",
3317 },
3318 })
3319 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003320 testType: serverTest,
3321 name: "ClientAuth-Server",
3322 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003323 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003324 Certificates: []Certificate{rsaCertificate},
3325 },
3326 flags: []string{"-require-any-client-certificate"},
3327 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003328 tests = append(tests, testCase{
3329 testType: serverTest,
3330 name: "ClientAuth-Server-TLS13",
3331 config: Config{
3332 MaxVersion: VersionTLS13,
3333 Certificates: []Certificate{rsaCertificate},
3334 },
3335 flags: []string{"-require-any-client-certificate"},
3336 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003337
David Benjamin4c3ddf72016-06-29 18:13:53 -04003338 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003339 tests = append(tests, testCase{
3340 testType: serverTest,
3341 name: "Basic-Server-RSA",
3342 config: Config{
3343 MaxVersion: VersionTLS12,
3344 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3345 },
3346 flags: []string{
3347 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3348 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3349 },
3350 })
3351 tests = append(tests, testCase{
3352 testType: serverTest,
3353 name: "Basic-Server-ECDHE-RSA",
3354 config: Config{
3355 MaxVersion: VersionTLS12,
3356 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3357 },
3358 flags: []string{
3359 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3360 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3361 },
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "Basic-Server-ECDHE-ECDSA",
3366 config: Config{
3367 MaxVersion: VersionTLS12,
3368 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3369 },
3370 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003371 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3372 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003373 },
3374 })
3375
David Benjamin760b1dd2015-05-15 23:33:48 -04003376 // No session ticket support; server doesn't send NewSessionTicket.
3377 tests = append(tests, testCase{
3378 name: "SessionTicketsDisabled-Client",
3379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003380 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 SessionTicketsDisabled: true,
3382 },
3383 })
3384 tests = append(tests, testCase{
3385 testType: serverTest,
3386 name: "SessionTicketsDisabled-Server",
3387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003388 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003389 SessionTicketsDisabled: true,
3390 },
3391 })
3392
3393 // Skip ServerKeyExchange in PSK key exchange if there's no
3394 // identity hint.
3395 tests = append(tests, testCase{
3396 name: "EmptyPSKHint-Client",
3397 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003398 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003399 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3400 PreSharedKey: []byte("secret"),
3401 },
3402 flags: []string{"-psk", "secret"},
3403 })
3404 tests = append(tests, testCase{
3405 testType: serverTest,
3406 name: "EmptyPSKHint-Server",
3407 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003408 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003409 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3410 PreSharedKey: []byte("secret"),
3411 },
3412 flags: []string{"-psk", "secret"},
3413 })
3414
David Benjamin4c3ddf72016-06-29 18:13:53 -04003415 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003416 tests = append(tests, testCase{
3417 testType: clientTest,
3418 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003419 config: Config{
3420 MaxVersion: VersionTLS12,
3421 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003422 flags: []string{
3423 "-enable-ocsp-stapling",
3424 "-expect-ocsp-response",
3425 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003426 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003427 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003428 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003429 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003430 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003431 testType: serverTest,
3432 name: "OCSPStapling-Server",
3433 config: Config{
3434 MaxVersion: VersionTLS12,
3435 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003436 expectedOCSPResponse: testOCSPResponse,
3437 flags: []string{
3438 "-ocsp-response",
3439 base64.StdEncoding.EncodeToString(testOCSPResponse),
3440 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003441 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003442 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003443 tests = append(tests, testCase{
3444 testType: clientTest,
3445 name: "OCSPStapling-Client-TLS13",
3446 config: Config{
3447 MaxVersion: VersionTLS13,
3448 },
3449 flags: []string{
3450 "-enable-ocsp-stapling",
3451 "-expect-ocsp-response",
3452 base64.StdEncoding.EncodeToString(testOCSPResponse),
3453 "-verify-peer",
3454 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003455 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003456 })
3457 tests = append(tests, testCase{
3458 testType: serverTest,
3459 name: "OCSPStapling-Server-TLS13",
3460 config: Config{
3461 MaxVersion: VersionTLS13,
3462 },
3463 expectedOCSPResponse: testOCSPResponse,
3464 flags: []string{
3465 "-ocsp-response",
3466 base64.StdEncoding.EncodeToString(testOCSPResponse),
3467 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003468 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003469 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003470
David Benjamin4c3ddf72016-06-29 18:13:53 -04003471 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003472 for _, vers := range tlsVersions {
3473 if config.protocol == dtls && !vers.hasDTLS {
3474 continue
3475 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003476 for _, testType := range []testType{clientTest, serverTest} {
3477 suffix := "-Client"
3478 if testType == serverTest {
3479 suffix = "-Server"
3480 }
3481 suffix += "-" + vers.name
3482
3483 flag := "-verify-peer"
3484 if testType == serverTest {
3485 flag = "-require-any-client-certificate"
3486 }
3487
3488 tests = append(tests, testCase{
3489 testType: testType,
3490 name: "CertificateVerificationSucceed" + suffix,
3491 config: Config{
3492 MaxVersion: vers.version,
3493 Certificates: []Certificate{rsaCertificate},
3494 },
3495 flags: []string{
3496 flag,
3497 "-expect-verify-result",
3498 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003499 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003500 })
3501 tests = append(tests, testCase{
3502 testType: testType,
3503 name: "CertificateVerificationFail" + suffix,
3504 config: Config{
3505 MaxVersion: vers.version,
3506 Certificates: []Certificate{rsaCertificate},
3507 },
3508 flags: []string{
3509 flag,
3510 "-verify-fail",
3511 },
3512 shouldFail: true,
3513 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3514 })
3515 }
3516
3517 // By default, the client is in a soft fail mode where the peer
3518 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003519 tests = append(tests, testCase{
3520 testType: clientTest,
3521 name: "CertificateVerificationSoftFail-" + vers.name,
3522 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003523 MaxVersion: vers.version,
3524 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003525 },
3526 flags: []string{
3527 "-verify-fail",
3528 "-expect-verify-result",
3529 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003530 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003531 })
3532 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003533
David Benjamin1d4f4c02016-07-26 18:03:08 -04003534 tests = append(tests, testCase{
3535 name: "ShimSendAlert",
3536 flags: []string{"-send-alert"},
3537 shimWritesFirst: true,
3538 shouldFail: true,
3539 expectedLocalError: "remote error: decompression failure",
3540 })
3541
David Benjamin582ba042016-07-07 12:33:25 -07003542 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003543 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003544 name: "Renegotiate-Client",
3545 config: Config{
3546 MaxVersion: VersionTLS12,
3547 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003548 renegotiate: 1,
3549 flags: []string{
3550 "-renegotiate-freely",
3551 "-expect-total-renegotiations", "1",
3552 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003553 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003554
David Benjamin47921102016-07-28 11:29:18 -04003555 tests = append(tests, testCase{
3556 name: "SendHalfHelloRequest",
3557 config: Config{
3558 MaxVersion: VersionTLS12,
3559 Bugs: ProtocolBugs{
3560 PackHelloRequestWithFinished: config.packHandshakeFlight,
3561 },
3562 },
3563 sendHalfHelloRequest: true,
3564 flags: []string{"-renegotiate-ignore"},
3565 shouldFail: true,
3566 expectedError: ":UNEXPECTED_RECORD:",
3567 })
3568
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 // NPN on client and server; results in post-handshake message.
3570 tests = append(tests, testCase{
3571 name: "NPN-Client",
3572 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003573 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003574 NextProtos: []string{"foo"},
3575 },
3576 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003577 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003578 expectedNextProto: "foo",
3579 expectedNextProtoType: npn,
3580 })
3581 tests = append(tests, testCase{
3582 testType: serverTest,
3583 name: "NPN-Server",
3584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003585 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 NextProtos: []string{"bar"},
3587 },
3588 flags: []string{
3589 "-advertise-npn", "\x03foo\x03bar\x03baz",
3590 "-expect-next-proto", "bar",
3591 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003592 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003593 expectedNextProto: "bar",
3594 expectedNextProtoType: npn,
3595 })
3596
3597 // TODO(davidben): Add tests for when False Start doesn't trigger.
3598
3599 // Client does False Start and negotiates NPN.
3600 tests = append(tests, testCase{
3601 name: "FalseStart",
3602 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003603 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003604 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3605 NextProtos: []string{"foo"},
3606 Bugs: ProtocolBugs{
3607 ExpectFalseStart: true,
3608 },
3609 },
3610 flags: []string{
3611 "-false-start",
3612 "-select-next-proto", "foo",
3613 },
3614 shimWritesFirst: true,
3615 resumeSession: true,
3616 })
3617
3618 // Client does False Start and negotiates ALPN.
3619 tests = append(tests, testCase{
3620 name: "FalseStart-ALPN",
3621 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003622 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3624 NextProtos: []string{"foo"},
3625 Bugs: ProtocolBugs{
3626 ExpectFalseStart: true,
3627 },
3628 },
3629 flags: []string{
3630 "-false-start",
3631 "-advertise-alpn", "\x03foo",
3632 },
3633 shimWritesFirst: true,
3634 resumeSession: true,
3635 })
3636
3637 // Client does False Start but doesn't explicitly call
3638 // SSL_connect.
3639 tests = append(tests, testCase{
3640 name: "FalseStart-Implicit",
3641 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003642 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003643 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3644 NextProtos: []string{"foo"},
3645 },
3646 flags: []string{
3647 "-implicit-handshake",
3648 "-false-start",
3649 "-advertise-alpn", "\x03foo",
3650 },
3651 })
3652
3653 // False Start without session tickets.
3654 tests = append(tests, testCase{
3655 name: "FalseStart-SessionTicketsDisabled",
3656 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003657 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3659 NextProtos: []string{"foo"},
3660 SessionTicketsDisabled: true,
3661 Bugs: ProtocolBugs{
3662 ExpectFalseStart: true,
3663 },
3664 },
3665 flags: []string{
3666 "-false-start",
3667 "-select-next-proto", "foo",
3668 },
3669 shimWritesFirst: true,
3670 })
3671
Adam Langleydf759b52016-07-11 15:24:37 -07003672 tests = append(tests, testCase{
3673 name: "FalseStart-CECPQ1",
3674 config: Config{
3675 MaxVersion: VersionTLS12,
3676 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3677 NextProtos: []string{"foo"},
3678 Bugs: ProtocolBugs{
3679 ExpectFalseStart: true,
3680 },
3681 },
3682 flags: []string{
3683 "-false-start",
3684 "-cipher", "DEFAULT:kCECPQ1",
3685 "-select-next-proto", "foo",
3686 },
3687 shimWritesFirst: true,
3688 resumeSession: true,
3689 })
3690
David Benjamin760b1dd2015-05-15 23:33:48 -04003691 // Server parses a V2ClientHello.
3692 tests = append(tests, testCase{
3693 testType: serverTest,
3694 name: "SendV2ClientHello",
3695 config: Config{
3696 // Choose a cipher suite that does not involve
3697 // elliptic curves, so no extensions are
3698 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003699 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003700 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3701 Bugs: ProtocolBugs{
3702 SendV2ClientHello: true,
3703 },
3704 },
3705 })
3706
3707 // Client sends a Channel ID.
3708 tests = append(tests, testCase{
3709 name: "ChannelID-Client",
3710 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003711 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003712 RequestChannelID: true,
3713 },
Adam Langley7c803a62015-06-15 15:35:05 -07003714 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003715 resumeSession: true,
3716 expectChannelID: true,
3717 })
3718
3719 // Server accepts a Channel ID.
3720 tests = append(tests, testCase{
3721 testType: serverTest,
3722 name: "ChannelID-Server",
3723 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 MaxVersion: VersionTLS12,
3725 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003726 },
3727 flags: []string{
3728 "-expect-channel-id",
3729 base64.StdEncoding.EncodeToString(channelIDBytes),
3730 },
3731 resumeSession: true,
3732 expectChannelID: true,
3733 })
David Benjamin30789da2015-08-29 22:56:45 -04003734
David Benjaminf8fcdf32016-06-08 15:56:13 -04003735 // Channel ID and NPN at the same time, to ensure their relative
3736 // ordering is correct.
3737 tests = append(tests, testCase{
3738 name: "ChannelID-NPN-Client",
3739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003740 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003741 RequestChannelID: true,
3742 NextProtos: []string{"foo"},
3743 },
3744 flags: []string{
3745 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3746 "-select-next-proto", "foo",
3747 },
3748 resumeSession: true,
3749 expectChannelID: true,
3750 expectedNextProto: "foo",
3751 expectedNextProtoType: npn,
3752 })
3753 tests = append(tests, testCase{
3754 testType: serverTest,
3755 name: "ChannelID-NPN-Server",
3756 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003757 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003758 ChannelID: channelIDKey,
3759 NextProtos: []string{"bar"},
3760 },
3761 flags: []string{
3762 "-expect-channel-id",
3763 base64.StdEncoding.EncodeToString(channelIDBytes),
3764 "-advertise-npn", "\x03foo\x03bar\x03baz",
3765 "-expect-next-proto", "bar",
3766 },
3767 resumeSession: true,
3768 expectChannelID: true,
3769 expectedNextProto: "bar",
3770 expectedNextProtoType: npn,
3771 })
3772
David Benjamin30789da2015-08-29 22:56:45 -04003773 // Bidirectional shutdown with the runner initiating.
3774 tests = append(tests, testCase{
3775 name: "Shutdown-Runner",
3776 config: Config{
3777 Bugs: ProtocolBugs{
3778 ExpectCloseNotify: true,
3779 },
3780 },
3781 flags: []string{"-check-close-notify"},
3782 })
3783
3784 // Bidirectional shutdown with the shim initiating. The runner,
3785 // in the meantime, sends garbage before the close_notify which
3786 // the shim must ignore.
3787 tests = append(tests, testCase{
3788 name: "Shutdown-Shim",
3789 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003790 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003791 Bugs: ProtocolBugs{
3792 ExpectCloseNotify: true,
3793 },
3794 },
3795 shimShutsDown: true,
3796 sendEmptyRecords: 1,
3797 sendWarningAlerts: 1,
3798 flags: []string{"-check-close-notify"},
3799 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003800 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003801 // TODO(davidben): DTLS 1.3 will want a similar thing for
3802 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003803 tests = append(tests, testCase{
3804 name: "SkipHelloVerifyRequest",
3805 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003806 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003807 Bugs: ProtocolBugs{
3808 SkipHelloVerifyRequest: true,
3809 },
3810 },
3811 })
3812 }
3813
David Benjamin760b1dd2015-05-15 23:33:48 -04003814 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003815 test.protocol = config.protocol
3816 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003817 test.name += "-DTLS"
3818 }
David Benjamin582ba042016-07-07 12:33:25 -07003819 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003820 test.name += "-Async"
3821 test.flags = append(test.flags, "-async")
3822 } else {
3823 test.name += "-Sync"
3824 }
David Benjamin582ba042016-07-07 12:33:25 -07003825 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003826 test.name += "-SplitHandshakeRecords"
3827 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003828 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003829 test.config.Bugs.MaxPacketLength = 256
3830 test.flags = append(test.flags, "-mtu", "256")
3831 }
3832 }
David Benjamin582ba042016-07-07 12:33:25 -07003833 if config.packHandshakeFlight {
3834 test.name += "-PackHandshakeFlight"
3835 test.config.Bugs.PackHandshakeFlight = true
3836 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003837 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003838 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003839}
3840
Adam Langley524e7172015-02-20 16:04:00 -08003841func addDDoSCallbackTests() {
3842 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003843 for _, resume := range []bool{false, true} {
3844 suffix := "Resume"
3845 if resume {
3846 suffix = "No" + suffix
3847 }
3848
3849 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003850 testType: serverTest,
3851 name: "Server-DDoS-OK-" + suffix,
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 },
Adam Langley524e7172015-02-20 16:04:00 -08003855 flags: []string{"-install-ddos-callback"},
3856 resumeSession: resume,
3857 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003858 testCases = append(testCases, testCase{
3859 testType: serverTest,
3860 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3861 config: Config{
3862 MaxVersion: VersionTLS13,
3863 },
3864 flags: []string{"-install-ddos-callback"},
3865 resumeSession: resume,
3866 })
Adam Langley524e7172015-02-20 16:04:00 -08003867
3868 failFlag := "-fail-ddos-callback"
3869 if resume {
3870 failFlag = "-fail-second-ddos-callback"
3871 }
3872 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003873 testType: serverTest,
3874 name: "Server-DDoS-Reject-" + suffix,
3875 config: Config{
3876 MaxVersion: VersionTLS12,
3877 },
Adam Langley524e7172015-02-20 16:04:00 -08003878 flags: []string{"-install-ddos-callback", failFlag},
3879 resumeSession: resume,
3880 shouldFail: true,
3881 expectedError: ":CONNECTION_REJECTED:",
3882 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003883 testCases = append(testCases, testCase{
3884 testType: serverTest,
3885 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3886 config: Config{
3887 MaxVersion: VersionTLS13,
3888 },
3889 flags: []string{"-install-ddos-callback", failFlag},
3890 resumeSession: resume,
3891 shouldFail: true,
3892 expectedError: ":CONNECTION_REJECTED:",
3893 })
Adam Langley524e7172015-02-20 16:04:00 -08003894 }
3895}
3896
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003897func addVersionNegotiationTests() {
3898 for i, shimVers := range tlsVersions {
3899 // Assemble flags to disable all newer versions on the shim.
3900 var flags []string
3901 for _, vers := range tlsVersions[i+1:] {
3902 flags = append(flags, vers.flag)
3903 }
3904
3905 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003906 protocols := []protocol{tls}
3907 if runnerVers.hasDTLS && shimVers.hasDTLS {
3908 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003909 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003910 for _, protocol := range protocols {
3911 expectedVersion := shimVers.version
3912 if runnerVers.version < shimVers.version {
3913 expectedVersion = runnerVers.version
3914 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003915
David Benjamin8b8c0062014-11-23 02:47:52 -05003916 suffix := shimVers.name + "-" + runnerVers.name
3917 if protocol == dtls {
3918 suffix += "-DTLS"
3919 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003920
David Benjamin1eb367c2014-12-12 18:17:51 -05003921 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3922
David Benjamin1e29a6b2014-12-10 02:27:24 -05003923 clientVers := shimVers.version
3924 if clientVers > VersionTLS10 {
3925 clientVers = VersionTLS10
3926 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003927 serverVers := expectedVersion
3928 if expectedVersion >= VersionTLS13 {
3929 serverVers = VersionTLS10
3930 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003931 testCases = append(testCases, testCase{
3932 protocol: protocol,
3933 testType: clientTest,
3934 name: "VersionNegotiation-Client-" + suffix,
3935 config: Config{
3936 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003937 Bugs: ProtocolBugs{
3938 ExpectInitialRecordVersion: clientVers,
3939 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003940 },
3941 flags: flags,
3942 expectedVersion: expectedVersion,
3943 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003944 testCases = append(testCases, testCase{
3945 protocol: protocol,
3946 testType: clientTest,
3947 name: "VersionNegotiation-Client2-" + suffix,
3948 config: Config{
3949 MaxVersion: runnerVers.version,
3950 Bugs: ProtocolBugs{
3951 ExpectInitialRecordVersion: clientVers,
3952 },
3953 },
3954 flags: []string{"-max-version", shimVersFlag},
3955 expectedVersion: expectedVersion,
3956 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003957
3958 testCases = append(testCases, testCase{
3959 protocol: protocol,
3960 testType: serverTest,
3961 name: "VersionNegotiation-Server-" + suffix,
3962 config: Config{
3963 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003964 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003965 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003966 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003967 },
3968 flags: flags,
3969 expectedVersion: expectedVersion,
3970 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003971 testCases = append(testCases, testCase{
3972 protocol: protocol,
3973 testType: serverTest,
3974 name: "VersionNegotiation-Server2-" + suffix,
3975 config: Config{
3976 MaxVersion: runnerVers.version,
3977 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003978 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003979 },
3980 },
3981 flags: []string{"-max-version", shimVersFlag},
3982 expectedVersion: expectedVersion,
3983 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003984 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003985 }
3986 }
David Benjamin95c69562016-06-29 18:15:03 -04003987
3988 // Test for version tolerance.
3989 testCases = append(testCases, testCase{
3990 testType: serverTest,
3991 name: "MinorVersionTolerance",
3992 config: Config{
3993 Bugs: ProtocolBugs{
3994 SendClientVersion: 0x03ff,
3995 },
3996 },
3997 expectedVersion: VersionTLS13,
3998 })
3999 testCases = append(testCases, testCase{
4000 testType: serverTest,
4001 name: "MajorVersionTolerance",
4002 config: Config{
4003 Bugs: ProtocolBugs{
4004 SendClientVersion: 0x0400,
4005 },
4006 },
4007 expectedVersion: VersionTLS13,
4008 })
4009 testCases = append(testCases, testCase{
4010 protocol: dtls,
4011 testType: serverTest,
4012 name: "MinorVersionTolerance-DTLS",
4013 config: Config{
4014 Bugs: ProtocolBugs{
4015 SendClientVersion: 0x03ff,
4016 },
4017 },
4018 expectedVersion: VersionTLS12,
4019 })
4020 testCases = append(testCases, testCase{
4021 protocol: dtls,
4022 testType: serverTest,
4023 name: "MajorVersionTolerance-DTLS",
4024 config: Config{
4025 Bugs: ProtocolBugs{
4026 SendClientVersion: 0x0400,
4027 },
4028 },
4029 expectedVersion: VersionTLS12,
4030 })
4031
4032 // Test that versions below 3.0 are rejected.
4033 testCases = append(testCases, testCase{
4034 testType: serverTest,
4035 name: "VersionTooLow",
4036 config: Config{
4037 Bugs: ProtocolBugs{
4038 SendClientVersion: 0x0200,
4039 },
4040 },
4041 shouldFail: true,
4042 expectedError: ":UNSUPPORTED_PROTOCOL:",
4043 })
4044 testCases = append(testCases, testCase{
4045 protocol: dtls,
4046 testType: serverTest,
4047 name: "VersionTooLow-DTLS",
4048 config: Config{
4049 Bugs: ProtocolBugs{
4050 // 0x0201 is the lowest version expressable in
4051 // DTLS.
4052 SendClientVersion: 0x0201,
4053 },
4054 },
4055 shouldFail: true,
4056 expectedError: ":UNSUPPORTED_PROTOCOL:",
4057 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004058
4059 // Test TLS 1.3's downgrade signal.
4060 testCases = append(testCases, testCase{
4061 name: "Downgrade-TLS12-Client",
4062 config: Config{
4063 Bugs: ProtocolBugs{
4064 NegotiateVersion: VersionTLS12,
4065 },
4066 },
4067 shouldFail: true,
4068 expectedError: ":DOWNGRADE_DETECTED:",
4069 })
4070 testCases = append(testCases, testCase{
4071 testType: serverTest,
4072 name: "Downgrade-TLS12-Server",
4073 config: Config{
4074 Bugs: ProtocolBugs{
4075 SendClientVersion: VersionTLS12,
4076 },
4077 },
4078 shouldFail: true,
4079 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4080 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004081
4082 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4083 // behave correctly when both real maximum and fallback versions are
4084 // set.
4085 testCases = append(testCases, testCase{
4086 name: "Downgrade-TLS12-Client-Fallback",
4087 config: Config{
4088 Bugs: ProtocolBugs{
4089 FailIfNotFallbackSCSV: true,
4090 },
4091 },
4092 flags: []string{
4093 "-max-version", strconv.Itoa(VersionTLS13),
4094 "-fallback-version", strconv.Itoa(VersionTLS12),
4095 },
4096 shouldFail: true,
4097 expectedError: ":DOWNGRADE_DETECTED:",
4098 })
4099 testCases = append(testCases, testCase{
4100 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4101 flags: []string{
4102 "-max-version", strconv.Itoa(VersionTLS12),
4103 "-fallback-version", strconv.Itoa(VersionTLS12),
4104 },
4105 })
4106
4107 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4108 // just have such connections fail than risk getting confused because we
4109 // didn't sent the 1.3 ClientHello.)
4110 testCases = append(testCases, testCase{
4111 name: "Downgrade-TLS12-Fallback-CheckVersion",
4112 config: Config{
4113 Bugs: ProtocolBugs{
4114 NegotiateVersion: VersionTLS13,
4115 FailIfNotFallbackSCSV: true,
4116 },
4117 },
4118 flags: []string{
4119 "-max-version", strconv.Itoa(VersionTLS13),
4120 "-fallback-version", strconv.Itoa(VersionTLS12),
4121 },
4122 shouldFail: true,
4123 expectedError: ":UNSUPPORTED_PROTOCOL:",
4124 })
4125
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004126}
4127
David Benjaminaccb4542014-12-12 23:44:33 -05004128func addMinimumVersionTests() {
4129 for i, shimVers := range tlsVersions {
4130 // Assemble flags to disable all older versions on the shim.
4131 var flags []string
4132 for _, vers := range tlsVersions[:i] {
4133 flags = append(flags, vers.flag)
4134 }
4135
4136 for _, runnerVers := range tlsVersions {
4137 protocols := []protocol{tls}
4138 if runnerVers.hasDTLS && shimVers.hasDTLS {
4139 protocols = append(protocols, dtls)
4140 }
4141 for _, protocol := range protocols {
4142 suffix := shimVers.name + "-" + runnerVers.name
4143 if protocol == dtls {
4144 suffix += "-DTLS"
4145 }
4146 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4147
David Benjaminaccb4542014-12-12 23:44:33 -05004148 var expectedVersion uint16
4149 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004150 var expectedClientError, expectedServerError string
4151 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004152 if runnerVers.version >= shimVers.version {
4153 expectedVersion = runnerVers.version
4154 } else {
4155 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004156 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4157 expectedServerLocalError = "remote error: protocol version not supported"
4158 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4159 // If the client's minimum version is TLS 1.3 and the runner's
4160 // maximum is below TLS 1.2, the runner will fail to select a
4161 // cipher before the shim rejects the selected version.
4162 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4163 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4164 } else {
4165 expectedClientError = expectedServerError
4166 expectedClientLocalError = expectedServerLocalError
4167 }
David Benjaminaccb4542014-12-12 23:44:33 -05004168 }
4169
4170 testCases = append(testCases, testCase{
4171 protocol: protocol,
4172 testType: clientTest,
4173 name: "MinimumVersion-Client-" + suffix,
4174 config: Config{
4175 MaxVersion: runnerVers.version,
4176 },
David Benjamin87909c02014-12-13 01:55:01 -05004177 flags: flags,
4178 expectedVersion: expectedVersion,
4179 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004180 expectedError: expectedClientError,
4181 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004182 })
4183 testCases = append(testCases, testCase{
4184 protocol: protocol,
4185 testType: clientTest,
4186 name: "MinimumVersion-Client2-" + suffix,
4187 config: Config{
4188 MaxVersion: runnerVers.version,
4189 },
David Benjamin87909c02014-12-13 01:55:01 -05004190 flags: []string{"-min-version", shimVersFlag},
4191 expectedVersion: expectedVersion,
4192 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004193 expectedError: expectedClientError,
4194 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004195 })
4196
4197 testCases = append(testCases, testCase{
4198 protocol: protocol,
4199 testType: serverTest,
4200 name: "MinimumVersion-Server-" + suffix,
4201 config: Config{
4202 MaxVersion: runnerVers.version,
4203 },
David Benjamin87909c02014-12-13 01:55:01 -05004204 flags: flags,
4205 expectedVersion: expectedVersion,
4206 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004207 expectedError: expectedServerError,
4208 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004209 })
4210 testCases = append(testCases, testCase{
4211 protocol: protocol,
4212 testType: serverTest,
4213 name: "MinimumVersion-Server2-" + suffix,
4214 config: Config{
4215 MaxVersion: runnerVers.version,
4216 },
David Benjamin87909c02014-12-13 01:55:01 -05004217 flags: []string{"-min-version", shimVersFlag},
4218 expectedVersion: expectedVersion,
4219 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004220 expectedError: expectedServerError,
4221 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004222 })
4223 }
4224 }
4225 }
4226}
4227
David Benjamine78bfde2014-09-06 12:45:15 -04004228func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004229 // TODO(davidben): Extensions, where applicable, all move their server
4230 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4231 // tests for both. Also test interaction with 0-RTT when implemented.
4232
David Benjamin97d17d92016-07-14 16:12:00 -04004233 // Repeat extensions tests all versions except SSL 3.0.
4234 for _, ver := range tlsVersions {
4235 if ver.version == VersionSSL30 {
4236 continue
4237 }
4238
David Benjamin97d17d92016-07-14 16:12:00 -04004239 // Test that duplicate extensions are rejected.
4240 testCases = append(testCases, testCase{
4241 testType: clientTest,
4242 name: "DuplicateExtensionClient-" + ver.name,
4243 config: Config{
4244 MaxVersion: ver.version,
4245 Bugs: ProtocolBugs{
4246 DuplicateExtension: true,
4247 },
David Benjamine78bfde2014-09-06 12:45:15 -04004248 },
David Benjamin97d17d92016-07-14 16:12:00 -04004249 shouldFail: true,
4250 expectedLocalError: "remote error: error decoding message",
4251 })
4252 testCases = append(testCases, testCase{
4253 testType: serverTest,
4254 name: "DuplicateExtensionServer-" + ver.name,
4255 config: Config{
4256 MaxVersion: ver.version,
4257 Bugs: ProtocolBugs{
4258 DuplicateExtension: true,
4259 },
David Benjamine78bfde2014-09-06 12:45:15 -04004260 },
David Benjamin97d17d92016-07-14 16:12:00 -04004261 shouldFail: true,
4262 expectedLocalError: "remote error: error decoding message",
4263 })
4264
4265 // Test SNI.
4266 testCases = append(testCases, testCase{
4267 testType: clientTest,
4268 name: "ServerNameExtensionClient-" + ver.name,
4269 config: Config{
4270 MaxVersion: ver.version,
4271 Bugs: ProtocolBugs{
4272 ExpectServerName: "example.com",
4273 },
David Benjamine78bfde2014-09-06 12:45:15 -04004274 },
David Benjamin97d17d92016-07-14 16:12:00 -04004275 flags: []string{"-host-name", "example.com"},
4276 })
4277 testCases = append(testCases, testCase{
4278 testType: clientTest,
4279 name: "ServerNameExtensionClientMismatch-" + ver.name,
4280 config: Config{
4281 MaxVersion: ver.version,
4282 Bugs: ProtocolBugs{
4283 ExpectServerName: "mismatch.com",
4284 },
David Benjamine78bfde2014-09-06 12:45:15 -04004285 },
David Benjamin97d17d92016-07-14 16:12:00 -04004286 flags: []string{"-host-name", "example.com"},
4287 shouldFail: true,
4288 expectedLocalError: "tls: unexpected server name",
4289 })
4290 testCases = append(testCases, testCase{
4291 testType: clientTest,
4292 name: "ServerNameExtensionClientMissing-" + ver.name,
4293 config: Config{
4294 MaxVersion: ver.version,
4295 Bugs: ProtocolBugs{
4296 ExpectServerName: "missing.com",
4297 },
David Benjamine78bfde2014-09-06 12:45:15 -04004298 },
David Benjamin97d17d92016-07-14 16:12:00 -04004299 shouldFail: true,
4300 expectedLocalError: "tls: unexpected server name",
4301 })
4302 testCases = append(testCases, testCase{
4303 testType: serverTest,
4304 name: "ServerNameExtensionServer-" + ver.name,
4305 config: Config{
4306 MaxVersion: ver.version,
4307 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004308 },
David Benjamin97d17d92016-07-14 16:12:00 -04004309 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004310 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004311 })
4312
4313 // Test ALPN.
4314 testCases = append(testCases, testCase{
4315 testType: clientTest,
4316 name: "ALPNClient-" + ver.name,
4317 config: Config{
4318 MaxVersion: ver.version,
4319 NextProtos: []string{"foo"},
4320 },
4321 flags: []string{
4322 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4323 "-expect-alpn", "foo",
4324 },
4325 expectedNextProto: "foo",
4326 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004327 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004328 })
4329 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004330 testType: clientTest,
4331 name: "ALPNClient-Mismatch-" + ver.name,
4332 config: Config{
4333 MaxVersion: ver.version,
4334 Bugs: ProtocolBugs{
4335 SendALPN: "baz",
4336 },
4337 },
4338 flags: []string{
4339 "-advertise-alpn", "\x03foo\x03bar",
4340 },
4341 shouldFail: true,
4342 expectedError: ":INVALID_ALPN_PROTOCOL:",
4343 expectedLocalError: "remote error: illegal parameter",
4344 })
4345 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004346 testType: serverTest,
4347 name: "ALPNServer-" + ver.name,
4348 config: Config{
4349 MaxVersion: ver.version,
4350 NextProtos: []string{"foo", "bar", "baz"},
4351 },
4352 flags: []string{
4353 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4354 "-select-alpn", "foo",
4355 },
4356 expectedNextProto: "foo",
4357 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004358 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004359 })
4360 testCases = append(testCases, testCase{
4361 testType: serverTest,
4362 name: "ALPNServer-Decline-" + ver.name,
4363 config: Config{
4364 MaxVersion: ver.version,
4365 NextProtos: []string{"foo", "bar", "baz"},
4366 },
4367 flags: []string{"-decline-alpn"},
4368 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004369 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004370 })
4371
David Benjamin25fe85b2016-08-09 20:00:32 -04004372 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4373 // called once.
4374 testCases = append(testCases, testCase{
4375 testType: serverTest,
4376 name: "ALPNServer-Async-" + ver.name,
4377 config: Config{
4378 MaxVersion: ver.version,
4379 NextProtos: []string{"foo", "bar", "baz"},
4380 },
4381 flags: []string{
4382 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4383 "-select-alpn", "foo",
4384 "-async",
4385 },
4386 expectedNextProto: "foo",
4387 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004388 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004389 })
4390
David Benjamin97d17d92016-07-14 16:12:00 -04004391 var emptyString string
4392 testCases = append(testCases, testCase{
4393 testType: clientTest,
4394 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4395 config: Config{
4396 MaxVersion: ver.version,
4397 NextProtos: []string{""},
4398 Bugs: ProtocolBugs{
4399 // A server returning an empty ALPN protocol
4400 // should be rejected.
4401 ALPNProtocol: &emptyString,
4402 },
4403 },
4404 flags: []string{
4405 "-advertise-alpn", "\x03foo",
4406 },
4407 shouldFail: true,
4408 expectedError: ":PARSE_TLSEXT:",
4409 })
4410 testCases = append(testCases, testCase{
4411 testType: serverTest,
4412 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4413 config: Config{
4414 MaxVersion: ver.version,
4415 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004416 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004417 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004418 },
David Benjamin97d17d92016-07-14 16:12:00 -04004419 flags: []string{
4420 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004421 },
David Benjamin97d17d92016-07-14 16:12:00 -04004422 shouldFail: true,
4423 expectedError: ":PARSE_TLSEXT:",
4424 })
4425
4426 // Test NPN and the interaction with ALPN.
4427 if ver.version < VersionTLS13 {
4428 // Test that the server prefers ALPN over NPN.
4429 testCases = append(testCases, testCase{
4430 testType: serverTest,
4431 name: "ALPNServer-Preferred-" + ver.name,
4432 config: Config{
4433 MaxVersion: ver.version,
4434 NextProtos: []string{"foo", "bar", "baz"},
4435 },
4436 flags: []string{
4437 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4438 "-select-alpn", "foo",
4439 "-advertise-npn", "\x03foo\x03bar\x03baz",
4440 },
4441 expectedNextProto: "foo",
4442 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004443 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004444 })
4445 testCases = append(testCases, testCase{
4446 testType: serverTest,
4447 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo", "bar", "baz"},
4451 Bugs: ProtocolBugs{
4452 SwapNPNAndALPN: true,
4453 },
4454 },
4455 flags: []string{
4456 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4457 "-select-alpn", "foo",
4458 "-advertise-npn", "\x03foo\x03bar\x03baz",
4459 },
4460 expectedNextProto: "foo",
4461 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004462 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004463 })
4464
4465 // Test that negotiating both NPN and ALPN is forbidden.
4466 testCases = append(testCases, testCase{
4467 name: "NegotiateALPNAndNPN-" + ver.name,
4468 config: Config{
4469 MaxVersion: ver.version,
4470 NextProtos: []string{"foo", "bar", "baz"},
4471 Bugs: ProtocolBugs{
4472 NegotiateALPNAndNPN: true,
4473 },
4474 },
4475 flags: []string{
4476 "-advertise-alpn", "\x03foo",
4477 "-select-next-proto", "foo",
4478 },
4479 shouldFail: true,
4480 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4481 })
4482 testCases = append(testCases, testCase{
4483 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4484 config: Config{
4485 MaxVersion: ver.version,
4486 NextProtos: []string{"foo", "bar", "baz"},
4487 Bugs: ProtocolBugs{
4488 NegotiateALPNAndNPN: true,
4489 SwapNPNAndALPN: true,
4490 },
4491 },
4492 flags: []string{
4493 "-advertise-alpn", "\x03foo",
4494 "-select-next-proto", "foo",
4495 },
4496 shouldFail: true,
4497 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4498 })
4499
4500 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4501 testCases = append(testCases, testCase{
4502 name: "DisableNPN-" + ver.name,
4503 config: Config{
4504 MaxVersion: ver.version,
4505 NextProtos: []string{"foo"},
4506 },
4507 flags: []string{
4508 "-select-next-proto", "foo",
4509 "-disable-npn",
4510 },
4511 expectNoNextProto: true,
4512 })
4513 }
4514
4515 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004516
4517 // Resume with a corrupt ticket.
4518 testCases = append(testCases, testCase{
4519 testType: serverTest,
4520 name: "CorruptTicket-" + ver.name,
4521 config: Config{
4522 MaxVersion: ver.version,
4523 Bugs: ProtocolBugs{
4524 CorruptTicket: true,
4525 },
4526 },
4527 resumeSession: true,
4528 expectResumeRejected: true,
4529 })
4530 // Test the ticket callback, with and without renewal.
4531 testCases = append(testCases, testCase{
4532 testType: serverTest,
4533 name: "TicketCallback-" + ver.name,
4534 config: Config{
4535 MaxVersion: ver.version,
4536 },
4537 resumeSession: true,
4538 flags: []string{"-use-ticket-callback"},
4539 })
4540 testCases = append(testCases, testCase{
4541 testType: serverTest,
4542 name: "TicketCallback-Renew-" + ver.name,
4543 config: Config{
4544 MaxVersion: ver.version,
4545 Bugs: ProtocolBugs{
4546 ExpectNewTicket: true,
4547 },
4548 },
4549 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4550 resumeSession: true,
4551 })
4552
4553 // Test that the ticket callback is only called once when everything before
4554 // it in the ClientHello is asynchronous. This corrupts the ticket so
4555 // certificate selection callbacks run.
4556 testCases = append(testCases, testCase{
4557 testType: serverTest,
4558 name: "TicketCallback-SingleCall-" + ver.name,
4559 config: Config{
4560 MaxVersion: ver.version,
4561 Bugs: ProtocolBugs{
4562 CorruptTicket: true,
4563 },
4564 },
4565 resumeSession: true,
4566 expectResumeRejected: true,
4567 flags: []string{
4568 "-use-ticket-callback",
4569 "-async",
4570 },
4571 })
4572
4573 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004574 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004575 testCases = append(testCases, testCase{
4576 testType: serverTest,
4577 name: "OversizedSessionId-" + ver.name,
4578 config: Config{
4579 MaxVersion: ver.version,
4580 Bugs: ProtocolBugs{
4581 OversizedSessionId: true,
4582 },
4583 },
4584 resumeSession: true,
4585 shouldFail: true,
4586 expectedError: ":DECODE_ERROR:",
4587 })
4588 }
4589
4590 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4591 // are ignored.
4592 if ver.hasDTLS {
4593 testCases = append(testCases, testCase{
4594 protocol: dtls,
4595 name: "SRTP-Client-" + ver.name,
4596 config: Config{
4597 MaxVersion: ver.version,
4598 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4599 },
4600 flags: []string{
4601 "-srtp-profiles",
4602 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4603 },
4604 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4605 })
4606 testCases = append(testCases, testCase{
4607 protocol: dtls,
4608 testType: serverTest,
4609 name: "SRTP-Server-" + ver.name,
4610 config: Config{
4611 MaxVersion: ver.version,
4612 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4613 },
4614 flags: []string{
4615 "-srtp-profiles",
4616 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4617 },
4618 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4619 })
4620 // Test that the MKI is ignored.
4621 testCases = append(testCases, testCase{
4622 protocol: dtls,
4623 testType: serverTest,
4624 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4625 config: Config{
4626 MaxVersion: ver.version,
4627 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4628 Bugs: ProtocolBugs{
4629 SRTPMasterKeyIdentifer: "bogus",
4630 },
4631 },
4632 flags: []string{
4633 "-srtp-profiles",
4634 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4635 },
4636 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4637 })
4638 // Test that SRTP isn't negotiated on the server if there were
4639 // no matching profiles.
4640 testCases = append(testCases, testCase{
4641 protocol: dtls,
4642 testType: serverTest,
4643 name: "SRTP-Server-NoMatch-" + ver.name,
4644 config: Config{
4645 MaxVersion: ver.version,
4646 SRTPProtectionProfiles: []uint16{100, 101, 102},
4647 },
4648 flags: []string{
4649 "-srtp-profiles",
4650 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4651 },
4652 expectedSRTPProtectionProfile: 0,
4653 })
4654 // Test that the server returning an invalid SRTP profile is
4655 // flagged as an error by the client.
4656 testCases = append(testCases, testCase{
4657 protocol: dtls,
4658 name: "SRTP-Client-NoMatch-" + ver.name,
4659 config: Config{
4660 MaxVersion: ver.version,
4661 Bugs: ProtocolBugs{
4662 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4663 },
4664 },
4665 flags: []string{
4666 "-srtp-profiles",
4667 "SRTP_AES128_CM_SHA1_80",
4668 },
4669 shouldFail: true,
4670 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4671 })
4672 }
4673
4674 // Test SCT list.
4675 testCases = append(testCases, testCase{
4676 name: "SignedCertificateTimestampList-Client-" + ver.name,
4677 testType: clientTest,
4678 config: Config{
4679 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004680 },
David Benjamin97d17d92016-07-14 16:12:00 -04004681 flags: []string{
4682 "-enable-signed-cert-timestamps",
4683 "-expect-signed-cert-timestamps",
4684 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004685 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004686 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004687 })
4688 testCases = append(testCases, testCase{
4689 name: "SendSCTListOnResume-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 Bugs: ProtocolBugs{
4693 SendSCTListOnResume: []byte("bogus"),
4694 },
David Benjamind98452d2015-06-16 14:16:23 -04004695 },
David Benjamin97d17d92016-07-14 16:12:00 -04004696 flags: []string{
4697 "-enable-signed-cert-timestamps",
4698 "-expect-signed-cert-timestamps",
4699 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004700 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004701 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004702 })
4703 testCases = append(testCases, testCase{
4704 name: "SignedCertificateTimestampList-Server-" + ver.name,
4705 testType: serverTest,
4706 config: Config{
4707 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004708 },
David Benjamin97d17d92016-07-14 16:12:00 -04004709 flags: []string{
4710 "-signed-cert-timestamps",
4711 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004712 },
David Benjamin97d17d92016-07-14 16:12:00 -04004713 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004714 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004715 })
4716 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004717
Paul Lietar4fac72e2015-09-09 13:44:55 +01004718 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004719 testType: clientTest,
4720 name: "ClientHelloPadding",
4721 config: Config{
4722 Bugs: ProtocolBugs{
4723 RequireClientHelloSize: 512,
4724 },
4725 },
4726 // This hostname just needs to be long enough to push the
4727 // ClientHello into F5's danger zone between 256 and 511 bytes
4728 // long.
4729 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4730 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004731
4732 // Extensions should not function in SSL 3.0.
4733 testCases = append(testCases, testCase{
4734 testType: serverTest,
4735 name: "SSLv3Extensions-NoALPN",
4736 config: Config{
4737 MaxVersion: VersionSSL30,
4738 NextProtos: []string{"foo", "bar", "baz"},
4739 },
4740 flags: []string{
4741 "-select-alpn", "foo",
4742 },
4743 expectNoNextProto: true,
4744 })
4745
4746 // Test session tickets separately as they follow a different codepath.
4747 testCases = append(testCases, testCase{
4748 testType: serverTest,
4749 name: "SSLv3Extensions-NoTickets",
4750 config: Config{
4751 MaxVersion: VersionSSL30,
4752 Bugs: ProtocolBugs{
4753 // Historically, session tickets in SSL 3.0
4754 // failed in different ways depending on whether
4755 // the client supported renegotiation_info.
4756 NoRenegotiationInfo: true,
4757 },
4758 },
4759 resumeSession: true,
4760 })
4761 testCases = append(testCases, testCase{
4762 testType: serverTest,
4763 name: "SSLv3Extensions-NoTickets2",
4764 config: Config{
4765 MaxVersion: VersionSSL30,
4766 },
4767 resumeSession: true,
4768 })
4769
4770 // But SSL 3.0 does send and process renegotiation_info.
4771 testCases = append(testCases, testCase{
4772 testType: serverTest,
4773 name: "SSLv3Extensions-RenegotiationInfo",
4774 config: Config{
4775 MaxVersion: VersionSSL30,
4776 Bugs: ProtocolBugs{
4777 RequireRenegotiationInfo: true,
4778 },
4779 },
4780 })
4781 testCases = append(testCases, testCase{
4782 testType: serverTest,
4783 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4784 config: Config{
4785 MaxVersion: VersionSSL30,
4786 Bugs: ProtocolBugs{
4787 NoRenegotiationInfo: true,
4788 SendRenegotiationSCSV: true,
4789 RequireRenegotiationInfo: true,
4790 },
4791 },
4792 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004793
4794 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4795 // in ServerHello.
4796 testCases = append(testCases, testCase{
4797 name: "NPN-Forbidden-TLS13",
4798 config: Config{
4799 MaxVersion: VersionTLS13,
4800 NextProtos: []string{"foo"},
4801 Bugs: ProtocolBugs{
4802 NegotiateNPNAtAllVersions: true,
4803 },
4804 },
4805 flags: []string{"-select-next-proto", "foo"},
4806 shouldFail: true,
4807 expectedError: ":ERROR_PARSING_EXTENSION:",
4808 })
4809 testCases = append(testCases, testCase{
4810 name: "EMS-Forbidden-TLS13",
4811 config: Config{
4812 MaxVersion: VersionTLS13,
4813 Bugs: ProtocolBugs{
4814 NegotiateEMSAtAllVersions: true,
4815 },
4816 },
4817 shouldFail: true,
4818 expectedError: ":ERROR_PARSING_EXTENSION:",
4819 })
4820 testCases = append(testCases, testCase{
4821 name: "RenegotiationInfo-Forbidden-TLS13",
4822 config: Config{
4823 MaxVersion: VersionTLS13,
4824 Bugs: ProtocolBugs{
4825 NegotiateRenegotiationInfoAtAllVersions: true,
4826 },
4827 },
4828 shouldFail: true,
4829 expectedError: ":ERROR_PARSING_EXTENSION:",
4830 })
4831 testCases = append(testCases, testCase{
4832 name: "ChannelID-Forbidden-TLS13",
4833 config: Config{
4834 MaxVersion: VersionTLS13,
4835 RequestChannelID: true,
4836 Bugs: ProtocolBugs{
4837 NegotiateChannelIDAtAllVersions: true,
4838 },
4839 },
4840 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4841 shouldFail: true,
4842 expectedError: ":ERROR_PARSING_EXTENSION:",
4843 })
4844 testCases = append(testCases, testCase{
4845 name: "Ticket-Forbidden-TLS13",
4846 config: Config{
4847 MaxVersion: VersionTLS12,
4848 },
4849 resumeConfig: &Config{
4850 MaxVersion: VersionTLS13,
4851 Bugs: ProtocolBugs{
4852 AdvertiseTicketExtension: true,
4853 },
4854 },
4855 resumeSession: true,
4856 shouldFail: true,
4857 expectedError: ":ERROR_PARSING_EXTENSION:",
4858 })
4859
4860 // Test that illegal extensions in TLS 1.3 are declined by the server if
4861 // offered in ClientHello. The runner's server will fail if this occurs,
4862 // so we exercise the offering path. (EMS and Renegotiation Info are
4863 // implicit in every test.)
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "ChannelID-Declined-TLS13",
4867 config: Config{
4868 MaxVersion: VersionTLS13,
4869 ChannelID: channelIDKey,
4870 },
4871 flags: []string{"-enable-channel-id"},
4872 })
4873 testCases = append(testCases, testCase{
4874 testType: serverTest,
4875 name: "NPN-Server",
4876 config: Config{
4877 MaxVersion: VersionTLS13,
4878 NextProtos: []string{"bar"},
4879 },
4880 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4881 })
David Benjamine78bfde2014-09-06 12:45:15 -04004882}
4883
David Benjamin01fe8202014-09-24 15:21:44 -04004884func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004885 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004886 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004887 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4888 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4889 // TLS 1.3 only shares ciphers with TLS 1.2, so
4890 // we skip certain combinations and use a
4891 // different cipher to test with.
4892 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4893 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4894 continue
4895 }
4896 }
4897
David Benjamin8b8c0062014-11-23 02:47:52 -05004898 protocols := []protocol{tls}
4899 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4900 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004901 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004902 for _, protocol := range protocols {
4903 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4904 if protocol == dtls {
4905 suffix += "-DTLS"
4906 }
4907
David Benjaminece3de92015-03-16 18:02:20 -04004908 if sessionVers.version == resumeVers.version {
4909 testCases = append(testCases, testCase{
4910 protocol: protocol,
4911 name: "Resume-Client" + suffix,
4912 resumeSession: true,
4913 config: Config{
4914 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004915 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004916 Bugs: ProtocolBugs{
4917 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4918 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4919 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004920 },
David Benjaminece3de92015-03-16 18:02:20 -04004921 expectedVersion: sessionVers.version,
4922 expectedResumeVersion: resumeVers.version,
4923 })
4924 } else {
David Benjamin405da482016-08-08 17:25:07 -04004925 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4926
4927 // Offering a TLS 1.3 session sends an empty session ID, so
4928 // there is no way to convince a non-lookahead client the
4929 // session was resumed. It will appear to the client that a
4930 // stray ChangeCipherSpec was sent.
4931 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4932 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004933 }
4934
David Benjaminece3de92015-03-16 18:02:20 -04004935 testCases = append(testCases, testCase{
4936 protocol: protocol,
4937 name: "Resume-Client-Mismatch" + suffix,
4938 resumeSession: true,
4939 config: Config{
4940 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004941 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004942 },
David Benjaminece3de92015-03-16 18:02:20 -04004943 expectedVersion: sessionVers.version,
4944 resumeConfig: &Config{
4945 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004946 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004947 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004948 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004949 },
4950 },
4951 expectedResumeVersion: resumeVers.version,
4952 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004953 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004954 })
4955 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004956
4957 testCases = append(testCases, testCase{
4958 protocol: protocol,
4959 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004960 resumeSession: true,
4961 config: Config{
4962 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004963 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004964 },
4965 expectedVersion: sessionVers.version,
4966 resumeConfig: &Config{
4967 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004968 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004969 },
4970 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004971 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004972 expectedResumeVersion: resumeVers.version,
4973 })
4974
David Benjamin8b8c0062014-11-23 02:47:52 -05004975 testCases = append(testCases, testCase{
4976 protocol: protocol,
4977 testType: serverTest,
4978 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004979 resumeSession: true,
4980 config: Config{
4981 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004982 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004983 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004984 expectedVersion: sessionVers.version,
4985 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004986 resumeConfig: &Config{
4987 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004988 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004989 Bugs: ProtocolBugs{
4990 SendBothTickets: true,
4991 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004992 },
4993 expectedResumeVersion: resumeVers.version,
4994 })
4995 }
David Benjamin01fe8202014-09-24 15:21:44 -04004996 }
4997 }
David Benjaminece3de92015-03-16 18:02:20 -04004998
4999 testCases = append(testCases, testCase{
5000 name: "Resume-Client-CipherMismatch",
5001 resumeSession: true,
5002 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005003 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005004 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5005 },
5006 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005007 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005008 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5009 Bugs: ProtocolBugs{
5010 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5011 },
5012 },
5013 shouldFail: true,
5014 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5015 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005016
5017 testCases = append(testCases, testCase{
5018 name: "Resume-Client-CipherMismatch-TLS13",
5019 resumeSession: true,
5020 config: Config{
5021 MaxVersion: VersionTLS13,
5022 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5023 },
5024 resumeConfig: &Config{
5025 MaxVersion: VersionTLS13,
5026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5027 Bugs: ProtocolBugs{
5028 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5029 },
5030 },
5031 shouldFail: true,
5032 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5033 })
David Benjamin01fe8202014-09-24 15:21:44 -04005034}
5035
Adam Langley2ae77d22014-10-28 17:29:33 -07005036func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005037 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005038 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005039 testType: serverTest,
5040 name: "Renegotiate-Server-Forbidden",
5041 config: Config{
5042 MaxVersion: VersionTLS12,
5043 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005044 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005045 shouldFail: true,
5046 expectedError: ":NO_RENEGOTIATION:",
5047 expectedLocalError: "remote error: no renegotiation",
5048 })
Adam Langley5021b222015-06-12 18:27:58 -07005049 // The server shouldn't echo the renegotiation extension unless
5050 // requested by the client.
5051 testCases = append(testCases, testCase{
5052 testType: serverTest,
5053 name: "Renegotiate-Server-NoExt",
5054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005055 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005056 Bugs: ProtocolBugs{
5057 NoRenegotiationInfo: true,
5058 RequireRenegotiationInfo: true,
5059 },
5060 },
5061 shouldFail: true,
5062 expectedLocalError: "renegotiation extension missing",
5063 })
5064 // The renegotiation SCSV should be sufficient for the server to echo
5065 // the extension.
5066 testCases = append(testCases, testCase{
5067 testType: serverTest,
5068 name: "Renegotiate-Server-NoExt-SCSV",
5069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005070 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005071 Bugs: ProtocolBugs{
5072 NoRenegotiationInfo: true,
5073 SendRenegotiationSCSV: true,
5074 RequireRenegotiationInfo: true,
5075 },
5076 },
5077 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005078 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005079 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005081 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005082 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005083 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005084 },
5085 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005086 renegotiate: 1,
5087 flags: []string{
5088 "-renegotiate-freely",
5089 "-expect-total-renegotiations", "1",
5090 },
David Benjamincdea40c2015-03-19 14:09:43 -04005091 })
5092 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005093 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005094 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005096 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005097 Bugs: ProtocolBugs{
5098 EmptyRenegotiationInfo: true,
5099 },
5100 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005101 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005102 shouldFail: true,
5103 expectedError: ":RENEGOTIATION_MISMATCH:",
5104 })
5105 testCases = append(testCases, testCase{
5106 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005107 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005109 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005110 Bugs: ProtocolBugs{
5111 BadRenegotiationInfo: true,
5112 },
5113 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005114 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005115 shouldFail: true,
5116 expectedError: ":RENEGOTIATION_MISMATCH:",
5117 })
5118 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005119 name: "Renegotiate-Client-Downgrade",
5120 renegotiate: 1,
5121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005122 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005123 Bugs: ProtocolBugs{
5124 NoRenegotiationInfoAfterInitial: true,
5125 },
5126 },
5127 flags: []string{"-renegotiate-freely"},
5128 shouldFail: true,
5129 expectedError: ":RENEGOTIATION_MISMATCH:",
5130 })
5131 testCases = append(testCases, testCase{
5132 name: "Renegotiate-Client-Upgrade",
5133 renegotiate: 1,
5134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005135 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005136 Bugs: ProtocolBugs{
5137 NoRenegotiationInfoInInitial: true,
5138 },
5139 },
5140 flags: []string{"-renegotiate-freely"},
5141 shouldFail: true,
5142 expectedError: ":RENEGOTIATION_MISMATCH:",
5143 })
5144 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005145 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005146 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005148 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005149 Bugs: ProtocolBugs{
5150 NoRenegotiationInfo: true,
5151 },
5152 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005153 flags: []string{
5154 "-renegotiate-freely",
5155 "-expect-total-renegotiations", "1",
5156 },
David Benjamincff0b902015-05-15 23:09:47 -04005157 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005158
5159 // Test that the server may switch ciphers on renegotiation without
5160 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005161 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005162 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005163 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005165 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005166 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5167 },
5168 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005169 flags: []string{
5170 "-renegotiate-freely",
5171 "-expect-total-renegotiations", "1",
5172 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005173 })
5174 testCases = append(testCases, testCase{
5175 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005176 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005177 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005178 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5180 },
5181 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005182 flags: []string{
5183 "-renegotiate-freely",
5184 "-expect-total-renegotiations", "1",
5185 },
David Benjaminb16346b2015-04-08 19:16:58 -04005186 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005187
5188 // Test that the server may not switch versions on renegotiation.
5189 testCases = append(testCases, testCase{
5190 name: "Renegotiate-Client-SwitchVersion",
5191 config: Config{
5192 MaxVersion: VersionTLS12,
5193 // Pick a cipher which exists at both versions.
5194 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5195 Bugs: ProtocolBugs{
5196 NegotiateVersionOnRenego: VersionTLS11,
5197 },
5198 },
5199 renegotiate: 1,
5200 flags: []string{
5201 "-renegotiate-freely",
5202 "-expect-total-renegotiations", "1",
5203 },
5204 shouldFail: true,
5205 expectedError: ":WRONG_SSL_VERSION:",
5206 })
5207
David Benjaminb16346b2015-04-08 19:16:58 -04005208 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005209 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005210 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005211 config: Config{
5212 MaxVersion: VersionTLS10,
5213 Bugs: ProtocolBugs{
5214 RequireSameRenegoClientVersion: true,
5215 },
5216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005217 flags: []string{
5218 "-renegotiate-freely",
5219 "-expect-total-renegotiations", "1",
5220 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005221 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005222 testCases = append(testCases, testCase{
5223 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005224 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005225 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005226 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005227 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5228 NextProtos: []string{"foo"},
5229 },
5230 flags: []string{
5231 "-false-start",
5232 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005233 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005234 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005235 },
5236 shimWritesFirst: true,
5237 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238
5239 // Client-side renegotiation controls.
5240 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005241 name: "Renegotiate-Client-Forbidden-1",
5242 config: Config{
5243 MaxVersion: VersionTLS12,
5244 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005245 renegotiate: 1,
5246 shouldFail: true,
5247 expectedError: ":NO_RENEGOTIATION:",
5248 expectedLocalError: "remote error: no renegotiation",
5249 })
5250 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005251 name: "Renegotiate-Client-Once-1",
5252 config: Config{
5253 MaxVersion: VersionTLS12,
5254 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005255 renegotiate: 1,
5256 flags: []string{
5257 "-renegotiate-once",
5258 "-expect-total-renegotiations", "1",
5259 },
5260 })
5261 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005262 name: "Renegotiate-Client-Freely-1",
5263 config: Config{
5264 MaxVersion: VersionTLS12,
5265 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005266 renegotiate: 1,
5267 flags: []string{
5268 "-renegotiate-freely",
5269 "-expect-total-renegotiations", "1",
5270 },
5271 })
5272 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005273 name: "Renegotiate-Client-Once-2",
5274 config: Config{
5275 MaxVersion: VersionTLS12,
5276 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005277 renegotiate: 2,
5278 flags: []string{"-renegotiate-once"},
5279 shouldFail: true,
5280 expectedError: ":NO_RENEGOTIATION:",
5281 expectedLocalError: "remote error: no renegotiation",
5282 })
5283 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005284 name: "Renegotiate-Client-Freely-2",
5285 config: Config{
5286 MaxVersion: VersionTLS12,
5287 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005288 renegotiate: 2,
5289 flags: []string{
5290 "-renegotiate-freely",
5291 "-expect-total-renegotiations", "2",
5292 },
5293 })
Adam Langley27a0d082015-11-03 13:34:10 -08005294 testCases = append(testCases, testCase{
5295 name: "Renegotiate-Client-NoIgnore",
5296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005297 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005298 Bugs: ProtocolBugs{
5299 SendHelloRequestBeforeEveryAppDataRecord: true,
5300 },
5301 },
5302 shouldFail: true,
5303 expectedError: ":NO_RENEGOTIATION:",
5304 })
5305 testCases = append(testCases, testCase{
5306 name: "Renegotiate-Client-Ignore",
5307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005308 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005309 Bugs: ProtocolBugs{
5310 SendHelloRequestBeforeEveryAppDataRecord: true,
5311 },
5312 },
5313 flags: []string{
5314 "-renegotiate-ignore",
5315 "-expect-total-renegotiations", "0",
5316 },
5317 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005318
David Benjamin397c8e62016-07-08 14:14:36 -07005319 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005320 testCases = append(testCases, testCase{
5321 name: "StrayHelloRequest",
5322 config: Config{
5323 MaxVersion: VersionTLS12,
5324 Bugs: ProtocolBugs{
5325 SendHelloRequestBeforeEveryHandshakeMessage: true,
5326 },
5327 },
5328 })
5329 testCases = append(testCases, testCase{
5330 name: "StrayHelloRequest-Packed",
5331 config: Config{
5332 MaxVersion: VersionTLS12,
5333 Bugs: ProtocolBugs{
5334 PackHandshakeFlight: true,
5335 SendHelloRequestBeforeEveryHandshakeMessage: true,
5336 },
5337 },
5338 })
5339
David Benjamin12d2c482016-07-24 10:56:51 -04005340 // Test renegotiation works if HelloRequest and server Finished come in
5341 // the same record.
5342 testCases = append(testCases, testCase{
5343 name: "Renegotiate-Client-Packed",
5344 config: Config{
5345 MaxVersion: VersionTLS12,
5346 Bugs: ProtocolBugs{
5347 PackHandshakeFlight: true,
5348 PackHelloRequestWithFinished: true,
5349 },
5350 },
5351 renegotiate: 1,
5352 flags: []string{
5353 "-renegotiate-freely",
5354 "-expect-total-renegotiations", "1",
5355 },
5356 })
5357
David Benjamin397c8e62016-07-08 14:14:36 -07005358 // Renegotiation is forbidden in TLS 1.3.
5359 testCases = append(testCases, testCase{
5360 name: "Renegotiate-Client-TLS13",
5361 config: Config{
5362 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005363 Bugs: ProtocolBugs{
5364 SendHelloRequestBeforeEveryAppDataRecord: true,
5365 },
David Benjamin397c8e62016-07-08 14:14:36 -07005366 },
David Benjamin397c8e62016-07-08 14:14:36 -07005367 flags: []string{
5368 "-renegotiate-freely",
5369 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005370 shouldFail: true,
5371 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005372 })
5373
5374 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5375 testCases = append(testCases, testCase{
5376 name: "StrayHelloRequest-TLS13",
5377 config: Config{
5378 MaxVersion: VersionTLS13,
5379 Bugs: ProtocolBugs{
5380 SendHelloRequestBeforeEveryHandshakeMessage: true,
5381 },
5382 },
5383 shouldFail: true,
5384 expectedError: ":UNEXPECTED_MESSAGE:",
5385 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005386}
5387
David Benjamin5e961c12014-11-07 01:48:35 -05005388func addDTLSReplayTests() {
5389 // Test that sequence number replays are detected.
5390 testCases = append(testCases, testCase{
5391 protocol: dtls,
5392 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005393 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005394 replayWrites: true,
5395 })
5396
David Benjamin8e6db492015-07-25 18:29:23 -04005397 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005398 // than the retransmit window.
5399 testCases = append(testCases, testCase{
5400 protocol: dtls,
5401 name: "DTLS-Replay-LargeGaps",
5402 config: Config{
5403 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005404 SequenceNumberMapping: func(in uint64) uint64 {
5405 return in * 127
5406 },
David Benjamin5e961c12014-11-07 01:48:35 -05005407 },
5408 },
David Benjamin8e6db492015-07-25 18:29:23 -04005409 messageCount: 200,
5410 replayWrites: true,
5411 })
5412
5413 // Test the incoming sequence number changing non-monotonically.
5414 testCases = append(testCases, testCase{
5415 protocol: dtls,
5416 name: "DTLS-Replay-NonMonotonic",
5417 config: Config{
5418 Bugs: ProtocolBugs{
5419 SequenceNumberMapping: func(in uint64) uint64 {
5420 return in ^ 31
5421 },
5422 },
5423 },
5424 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005425 replayWrites: true,
5426 })
5427}
5428
Nick Harper60edffd2016-06-21 15:19:24 -07005429var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005430 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005431 id signatureAlgorithm
5432 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005433}{
Nick Harper60edffd2016-06-21 15:19:24 -07005434 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5435 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5436 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5437 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005438 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005439 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5440 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5441 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005442 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5443 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5444 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005445 // Tests for key types prior to TLS 1.2.
5446 {"RSA", 0, testCertRSA},
5447 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005448}
5449
Nick Harper60edffd2016-06-21 15:19:24 -07005450const fakeSigAlg1 signatureAlgorithm = 0x2a01
5451const fakeSigAlg2 signatureAlgorithm = 0xff01
5452
5453func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005454 // Not all ciphers involve a signature. Advertise a list which gives all
5455 // versions a signing cipher.
5456 signingCiphers := []uint16{
5457 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5458 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5459 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5460 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5461 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5462 }
5463
David Benjaminca3d5452016-07-14 12:51:01 -04005464 var allAlgorithms []signatureAlgorithm
5465 for _, alg := range testSignatureAlgorithms {
5466 if alg.id != 0 {
5467 allAlgorithms = append(allAlgorithms, alg.id)
5468 }
5469 }
5470
Nick Harper60edffd2016-06-21 15:19:24 -07005471 // Make sure each signature algorithm works. Include some fake values in
5472 // the list and ensure they're ignored.
5473 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005474 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005475 if (ver.version < VersionTLS12) != (alg.id == 0) {
5476 continue
5477 }
5478
5479 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5480 // or remove it in C.
5481 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005482 continue
5483 }
Nick Harper60edffd2016-06-21 15:19:24 -07005484
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005485 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005486 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005487 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5488 shouldFail = true
5489 }
5490 // RSA-PSS does not exist in TLS 1.2.
5491 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5492 shouldFail = true
5493 }
5494
5495 var signError, verifyError string
5496 if shouldFail {
5497 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5498 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005499 }
David Benjamin000800a2014-11-14 01:43:59 -05005500
David Benjamin1fb125c2016-07-08 18:52:12 -07005501 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005502
David Benjamin7a41d372016-07-09 11:21:54 -07005503 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005504 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005505 config: Config{
5506 MaxVersion: ver.version,
5507 ClientAuth: RequireAnyClientCert,
5508 VerifySignatureAlgorithms: []signatureAlgorithm{
5509 fakeSigAlg1,
5510 alg.id,
5511 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005512 },
David Benjamin7a41d372016-07-09 11:21:54 -07005513 },
5514 flags: []string{
5515 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5516 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5517 "-enable-all-curves",
5518 },
5519 shouldFail: shouldFail,
5520 expectedError: signError,
5521 expectedPeerSignatureAlgorithm: alg.id,
5522 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005523
David Benjamin7a41d372016-07-09 11:21:54 -07005524 testCases = append(testCases, testCase{
5525 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005526 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005527 config: Config{
5528 MaxVersion: ver.version,
5529 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5530 SignSignatureAlgorithms: []signatureAlgorithm{
5531 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005532 },
David Benjamin7a41d372016-07-09 11:21:54 -07005533 Bugs: ProtocolBugs{
5534 SkipECDSACurveCheck: shouldFail,
5535 IgnoreSignatureVersionChecks: shouldFail,
5536 // The client won't advertise 1.3-only algorithms after
5537 // version negotiation.
5538 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005539 },
David Benjamin7a41d372016-07-09 11:21:54 -07005540 },
5541 flags: []string{
5542 "-require-any-client-certificate",
5543 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5544 "-enable-all-curves",
5545 },
5546 shouldFail: shouldFail,
5547 expectedError: verifyError,
5548 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005549
5550 testCases = append(testCases, testCase{
5551 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005552 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005553 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005554 MaxVersion: ver.version,
5555 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005556 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005557 fakeSigAlg1,
5558 alg.id,
5559 fakeSigAlg2,
5560 },
5561 },
5562 flags: []string{
5563 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5564 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5565 "-enable-all-curves",
5566 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005567 shouldFail: shouldFail,
5568 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005569 expectedPeerSignatureAlgorithm: alg.id,
5570 })
5571
5572 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005573 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005574 config: Config{
5575 MaxVersion: ver.version,
5576 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005577 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005578 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005579 alg.id,
5580 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005581 Bugs: ProtocolBugs{
5582 SkipECDSACurveCheck: shouldFail,
5583 IgnoreSignatureVersionChecks: shouldFail,
5584 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005585 },
5586 flags: []string{
5587 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5588 "-enable-all-curves",
5589 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005590 shouldFail: shouldFail,
5591 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005592 })
David Benjamin5208fd42016-07-13 21:43:25 -04005593
5594 if !shouldFail {
5595 testCases = append(testCases, testCase{
5596 testType: serverTest,
5597 name: "ClientAuth-InvalidSignature" + suffix,
5598 config: Config{
5599 MaxVersion: ver.version,
5600 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5601 SignSignatureAlgorithms: []signatureAlgorithm{
5602 alg.id,
5603 },
5604 Bugs: ProtocolBugs{
5605 InvalidSignature: true,
5606 },
5607 },
5608 flags: []string{
5609 "-require-any-client-certificate",
5610 "-enable-all-curves",
5611 },
5612 shouldFail: true,
5613 expectedError: ":BAD_SIGNATURE:",
5614 })
5615
5616 testCases = append(testCases, testCase{
5617 name: "ServerAuth-InvalidSignature" + suffix,
5618 config: Config{
5619 MaxVersion: ver.version,
5620 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5621 CipherSuites: signingCiphers,
5622 SignSignatureAlgorithms: []signatureAlgorithm{
5623 alg.id,
5624 },
5625 Bugs: ProtocolBugs{
5626 InvalidSignature: true,
5627 },
5628 },
5629 flags: []string{"-enable-all-curves"},
5630 shouldFail: true,
5631 expectedError: ":BAD_SIGNATURE:",
5632 })
5633 }
David Benjaminca3d5452016-07-14 12:51:01 -04005634
5635 if ver.version >= VersionTLS12 && !shouldFail {
5636 testCases = append(testCases, testCase{
5637 name: "ClientAuth-Sign-Negotiate" + suffix,
5638 config: Config{
5639 MaxVersion: ver.version,
5640 ClientAuth: RequireAnyClientCert,
5641 VerifySignatureAlgorithms: allAlgorithms,
5642 },
5643 flags: []string{
5644 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5645 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5646 "-enable-all-curves",
5647 "-signing-prefs", strconv.Itoa(int(alg.id)),
5648 },
5649 expectedPeerSignatureAlgorithm: alg.id,
5650 })
5651
5652 testCases = append(testCases, testCase{
5653 testType: serverTest,
5654 name: "ServerAuth-Sign-Negotiate" + suffix,
5655 config: Config{
5656 MaxVersion: ver.version,
5657 CipherSuites: signingCiphers,
5658 VerifySignatureAlgorithms: allAlgorithms,
5659 },
5660 flags: []string{
5661 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5662 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5663 "-enable-all-curves",
5664 "-signing-prefs", strconv.Itoa(int(alg.id)),
5665 },
5666 expectedPeerSignatureAlgorithm: alg.id,
5667 })
5668 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005669 }
David Benjamin000800a2014-11-14 01:43:59 -05005670 }
5671
Nick Harper60edffd2016-06-21 15:19:24 -07005672 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005673 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005674 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005675 config: Config{
5676 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005677 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005678 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005679 signatureECDSAWithP521AndSHA512,
5680 signatureRSAPKCS1WithSHA384,
5681 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005682 },
5683 },
5684 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005687 },
Nick Harper60edffd2016-06-21 15:19:24 -07005688 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005689 })
5690
5691 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005692 name: "ClientAuth-SignatureType-TLS13",
5693 config: Config{
5694 ClientAuth: RequireAnyClientCert,
5695 MaxVersion: VersionTLS13,
5696 VerifySignatureAlgorithms: []signatureAlgorithm{
5697 signatureECDSAWithP521AndSHA512,
5698 signatureRSAPKCS1WithSHA384,
5699 signatureRSAPSSWithSHA384,
5700 signatureECDSAWithSHA1,
5701 },
5702 },
5703 flags: []string{
5704 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5705 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5706 },
5707 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5708 })
5709
5710 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005711 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005712 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005713 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005714 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005715 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005716 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005717 signatureECDSAWithP521AndSHA512,
5718 signatureRSAPKCS1WithSHA384,
5719 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005720 },
5721 },
Nick Harper60edffd2016-06-21 15:19:24 -07005722 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005723 })
5724
Steven Valdez143e8b32016-07-11 13:19:03 -04005725 testCases = append(testCases, testCase{
5726 testType: serverTest,
5727 name: "ServerAuth-SignatureType-TLS13",
5728 config: Config{
5729 MaxVersion: VersionTLS13,
5730 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5731 VerifySignatureAlgorithms: []signatureAlgorithm{
5732 signatureECDSAWithP521AndSHA512,
5733 signatureRSAPKCS1WithSHA384,
5734 signatureRSAPSSWithSHA384,
5735 signatureECDSAWithSHA1,
5736 },
5737 },
5738 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5739 })
5740
David Benjamina95e9f32016-07-08 16:28:04 -07005741 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005742 testCases = append(testCases, testCase{
5743 testType: serverTest,
5744 name: "Verify-ClientAuth-SignatureType",
5745 config: Config{
5746 MaxVersion: VersionTLS12,
5747 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005748 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005749 signatureRSAPKCS1WithSHA256,
5750 },
5751 Bugs: ProtocolBugs{
5752 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5753 },
5754 },
5755 flags: []string{
5756 "-require-any-client-certificate",
5757 },
5758 shouldFail: true,
5759 expectedError: ":WRONG_SIGNATURE_TYPE:",
5760 })
5761
5762 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005763 testType: serverTest,
5764 name: "Verify-ClientAuth-SignatureType-TLS13",
5765 config: Config{
5766 MaxVersion: VersionTLS13,
5767 Certificates: []Certificate{rsaCertificate},
5768 SignSignatureAlgorithms: []signatureAlgorithm{
5769 signatureRSAPSSWithSHA256,
5770 },
5771 Bugs: ProtocolBugs{
5772 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5773 },
5774 },
5775 flags: []string{
5776 "-require-any-client-certificate",
5777 },
5778 shouldFail: true,
5779 expectedError: ":WRONG_SIGNATURE_TYPE:",
5780 })
5781
5782 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005783 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005784 config: Config{
5785 MaxVersion: VersionTLS12,
5786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005787 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005788 signatureRSAPKCS1WithSHA256,
5789 },
5790 Bugs: ProtocolBugs{
5791 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5792 },
5793 },
5794 shouldFail: true,
5795 expectedError: ":WRONG_SIGNATURE_TYPE:",
5796 })
5797
Steven Valdez143e8b32016-07-11 13:19:03 -04005798 testCases = append(testCases, testCase{
5799 name: "Verify-ServerAuth-SignatureType-TLS13",
5800 config: Config{
5801 MaxVersion: VersionTLS13,
5802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5803 SignSignatureAlgorithms: []signatureAlgorithm{
5804 signatureRSAPSSWithSHA256,
5805 },
5806 Bugs: ProtocolBugs{
5807 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5808 },
5809 },
5810 shouldFail: true,
5811 expectedError: ":WRONG_SIGNATURE_TYPE:",
5812 })
5813
David Benjamin51dd7d62016-07-08 16:07:01 -07005814 // Test that, if the list is missing, the peer falls back to SHA-1 in
5815 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005816 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005817 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005819 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005820 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005821 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005822 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005823 },
5824 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005825 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005826 },
5827 },
5828 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005829 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5830 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005831 },
5832 })
5833
5834 testCases = append(testCases, testCase{
5835 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005836 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005838 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005839 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005840 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005841 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005842 },
5843 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005844 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005845 },
5846 },
5847 })
David Benjamin72dc7832015-03-16 17:49:43 -04005848
David Benjamin51dd7d62016-07-08 16:07:01 -07005849 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005850 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005851 config: Config{
5852 MaxVersion: VersionTLS13,
5853 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005854 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005855 signatureRSAPKCS1WithSHA1,
5856 },
5857 Bugs: ProtocolBugs{
5858 NoSignatureAlgorithms: true,
5859 },
5860 },
5861 flags: []string{
5862 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5863 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5864 },
David Benjamin48901652016-08-01 12:12:47 -04005865 shouldFail: true,
5866 // An empty CertificateRequest signature algorithm list is a
5867 // syntax error in TLS 1.3.
5868 expectedError: ":DECODE_ERROR:",
5869 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005870 })
5871
5872 testCases = append(testCases, testCase{
5873 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005874 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005875 config: Config{
5876 MaxVersion: VersionTLS13,
5877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005878 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005879 signatureRSAPKCS1WithSHA1,
5880 },
5881 Bugs: ProtocolBugs{
5882 NoSignatureAlgorithms: true,
5883 },
5884 },
5885 shouldFail: true,
5886 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5887 })
5888
David Benjaminb62d2872016-07-18 14:55:02 +02005889 // Test that hash preferences are enforced. BoringSSL does not implement
5890 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005891 testCases = append(testCases, testCase{
5892 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005893 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005895 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005896 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005897 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005898 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005899 },
5900 Bugs: ProtocolBugs{
5901 IgnorePeerSignatureAlgorithmPreferences: true,
5902 },
5903 },
5904 flags: []string{"-require-any-client-certificate"},
5905 shouldFail: true,
5906 expectedError: ":WRONG_SIGNATURE_TYPE:",
5907 })
5908
5909 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005910 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005912 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005914 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005915 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005916 },
5917 Bugs: ProtocolBugs{
5918 IgnorePeerSignatureAlgorithmPreferences: true,
5919 },
5920 },
5921 shouldFail: true,
5922 expectedError: ":WRONG_SIGNATURE_TYPE:",
5923 })
David Benjaminb62d2872016-07-18 14:55:02 +02005924 testCases = append(testCases, testCase{
5925 testType: serverTest,
5926 name: "ClientAuth-Enforced-TLS13",
5927 config: Config{
5928 MaxVersion: VersionTLS13,
5929 Certificates: []Certificate{rsaCertificate},
5930 SignSignatureAlgorithms: []signatureAlgorithm{
5931 signatureRSAPKCS1WithMD5,
5932 },
5933 Bugs: ProtocolBugs{
5934 IgnorePeerSignatureAlgorithmPreferences: true,
5935 IgnoreSignatureVersionChecks: true,
5936 },
5937 },
5938 flags: []string{"-require-any-client-certificate"},
5939 shouldFail: true,
5940 expectedError: ":WRONG_SIGNATURE_TYPE:",
5941 })
5942
5943 testCases = append(testCases, testCase{
5944 name: "ServerAuth-Enforced-TLS13",
5945 config: Config{
5946 MaxVersion: VersionTLS13,
5947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5948 SignSignatureAlgorithms: []signatureAlgorithm{
5949 signatureRSAPKCS1WithMD5,
5950 },
5951 Bugs: ProtocolBugs{
5952 IgnorePeerSignatureAlgorithmPreferences: true,
5953 IgnoreSignatureVersionChecks: true,
5954 },
5955 },
5956 shouldFail: true,
5957 expectedError: ":WRONG_SIGNATURE_TYPE:",
5958 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005959
5960 // Test that the agreed upon digest respects the client preferences and
5961 // the server digests.
5962 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005963 name: "NoCommonAlgorithms-Digests",
5964 config: Config{
5965 MaxVersion: VersionTLS12,
5966 ClientAuth: RequireAnyClientCert,
5967 VerifySignatureAlgorithms: []signatureAlgorithm{
5968 signatureRSAPKCS1WithSHA512,
5969 signatureRSAPKCS1WithSHA1,
5970 },
5971 },
5972 flags: []string{
5973 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5974 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5975 "-digest-prefs", "SHA256",
5976 },
5977 shouldFail: true,
5978 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5979 })
5980 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005981 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005983 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005984 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005985 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005986 signatureRSAPKCS1WithSHA512,
5987 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005988 },
5989 },
5990 flags: []string{
5991 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5992 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005993 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005994 },
David Benjaminca3d5452016-07-14 12:51:01 -04005995 shouldFail: true,
5996 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5997 })
5998 testCases = append(testCases, testCase{
5999 name: "NoCommonAlgorithms-TLS13",
6000 config: Config{
6001 MaxVersion: VersionTLS13,
6002 ClientAuth: RequireAnyClientCert,
6003 VerifySignatureAlgorithms: []signatureAlgorithm{
6004 signatureRSAPSSWithSHA512,
6005 signatureRSAPSSWithSHA384,
6006 },
6007 },
6008 flags: []string{
6009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6011 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6012 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006013 shouldFail: true,
6014 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006015 })
6016 testCases = append(testCases, testCase{
6017 name: "Agree-Digest-SHA256",
6018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006019 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006020 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006021 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006022 signatureRSAPKCS1WithSHA1,
6023 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006024 },
6025 },
6026 flags: []string{
6027 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6028 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006029 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006030 },
Nick Harper60edffd2016-06-21 15:19:24 -07006031 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006032 })
6033 testCases = append(testCases, testCase{
6034 name: "Agree-Digest-SHA1",
6035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006036 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006037 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006038 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006039 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006040 },
6041 },
6042 flags: []string{
6043 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6044 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006045 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006046 },
Nick Harper60edffd2016-06-21 15:19:24 -07006047 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006048 })
6049 testCases = append(testCases, testCase{
6050 name: "Agree-Digest-Default",
6051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006052 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006053 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006054 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006055 signatureRSAPKCS1WithSHA256,
6056 signatureECDSAWithP256AndSHA256,
6057 signatureRSAPKCS1WithSHA1,
6058 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006059 },
6060 },
6061 flags: []string{
6062 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6063 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6064 },
Nick Harper60edffd2016-06-21 15:19:24 -07006065 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006066 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006067
David Benjaminca3d5452016-07-14 12:51:01 -04006068 // Test that the signing preference list may include extra algorithms
6069 // without negotiation problems.
6070 testCases = append(testCases, testCase{
6071 testType: serverTest,
6072 name: "FilterExtraAlgorithms",
6073 config: Config{
6074 MaxVersion: VersionTLS12,
6075 VerifySignatureAlgorithms: []signatureAlgorithm{
6076 signatureRSAPKCS1WithSHA256,
6077 },
6078 },
6079 flags: []string{
6080 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6081 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6082 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6083 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6084 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6085 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6086 },
6087 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6088 })
6089
David Benjamin4c3ddf72016-06-29 18:13:53 -04006090 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6091 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006092 testCases = append(testCases, testCase{
6093 name: "CheckLeafCurve",
6094 config: Config{
6095 MaxVersion: VersionTLS12,
6096 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006097 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 },
6099 flags: []string{"-p384-only"},
6100 shouldFail: true,
6101 expectedError: ":BAD_ECC_CERT:",
6102 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006103
6104 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6105 testCases = append(testCases, testCase{
6106 name: "CheckLeafCurve-TLS13",
6107 config: Config{
6108 MaxVersion: VersionTLS13,
6109 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6110 Certificates: []Certificate{ecdsaP256Certificate},
6111 },
6112 flags: []string{"-p384-only"},
6113 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006114
6115 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6116 testCases = append(testCases, testCase{
6117 name: "ECDSACurveMismatch-Verify-TLS12",
6118 config: Config{
6119 MaxVersion: VersionTLS12,
6120 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6121 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006122 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006123 signatureECDSAWithP384AndSHA384,
6124 },
6125 },
6126 })
6127
6128 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6129 testCases = append(testCases, testCase{
6130 name: "ECDSACurveMismatch-Verify-TLS13",
6131 config: Config{
6132 MaxVersion: VersionTLS13,
6133 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6134 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006135 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006136 signatureECDSAWithP384AndSHA384,
6137 },
6138 Bugs: ProtocolBugs{
6139 SkipECDSACurveCheck: true,
6140 },
6141 },
6142 shouldFail: true,
6143 expectedError: ":WRONG_SIGNATURE_TYPE:",
6144 })
6145
6146 // Signature algorithm selection in TLS 1.3 should take the curve into
6147 // account.
6148 testCases = append(testCases, testCase{
6149 testType: serverTest,
6150 name: "ECDSACurveMismatch-Sign-TLS13",
6151 config: Config{
6152 MaxVersion: VersionTLS13,
6153 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006154 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006155 signatureECDSAWithP384AndSHA384,
6156 signatureECDSAWithP256AndSHA256,
6157 },
6158 },
6159 flags: []string{
6160 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6161 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6162 },
6163 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6164 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006165
6166 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6167 // server does not attempt to sign in that case.
6168 testCases = append(testCases, testCase{
6169 testType: serverTest,
6170 name: "RSA-PSS-Large",
6171 config: Config{
6172 MaxVersion: VersionTLS13,
6173 VerifySignatureAlgorithms: []signatureAlgorithm{
6174 signatureRSAPSSWithSHA512,
6175 },
6176 },
6177 flags: []string{
6178 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6179 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6180 },
6181 shouldFail: true,
6182 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6183 })
David Benjamin000800a2014-11-14 01:43:59 -05006184}
6185
David Benjamin83f90402015-01-27 01:09:43 -05006186// timeouts is the retransmit schedule for BoringSSL. It doubles and
6187// caps at 60 seconds. On the 13th timeout, it gives up.
6188var timeouts = []time.Duration{
6189 1 * time.Second,
6190 2 * time.Second,
6191 4 * time.Second,
6192 8 * time.Second,
6193 16 * time.Second,
6194 32 * time.Second,
6195 60 * time.Second,
6196 60 * time.Second,
6197 60 * time.Second,
6198 60 * time.Second,
6199 60 * time.Second,
6200 60 * time.Second,
6201 60 * time.Second,
6202}
6203
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006204// shortTimeouts is an alternate set of timeouts which would occur if the
6205// initial timeout duration was set to 250ms.
6206var shortTimeouts = []time.Duration{
6207 250 * time.Millisecond,
6208 500 * time.Millisecond,
6209 1 * time.Second,
6210 2 * time.Second,
6211 4 * time.Second,
6212 8 * time.Second,
6213 16 * time.Second,
6214 32 * time.Second,
6215 60 * time.Second,
6216 60 * time.Second,
6217 60 * time.Second,
6218 60 * time.Second,
6219 60 * time.Second,
6220}
6221
David Benjamin83f90402015-01-27 01:09:43 -05006222func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006223 // These tests work by coordinating some behavior on both the shim and
6224 // the runner.
6225 //
6226 // TimeoutSchedule configures the runner to send a series of timeout
6227 // opcodes to the shim (see packetAdaptor) immediately before reading
6228 // each peer handshake flight N. The timeout opcode both simulates a
6229 // timeout in the shim and acts as a synchronization point to help the
6230 // runner bracket each handshake flight.
6231 //
6232 // We assume the shim does not read from the channel eagerly. It must
6233 // first wait until it has sent flight N and is ready to receive
6234 // handshake flight N+1. At this point, it will process the timeout
6235 // opcode. It must then immediately respond with a timeout ACK and act
6236 // as if the shim was idle for the specified amount of time.
6237 //
6238 // The runner then drops all packets received before the ACK and
6239 // continues waiting for flight N. This ordering results in one attempt
6240 // at sending flight N to be dropped. For the test to complete, the
6241 // shim must send flight N again, testing that the shim implements DTLS
6242 // retransmit on a timeout.
6243
Steven Valdez143e8b32016-07-11 13:19:03 -04006244 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006245 // likely be more epochs to cross and the final message's retransmit may
6246 // be more complex.
6247
David Benjamin585d7a42016-06-02 14:58:00 -04006248 for _, async := range []bool{true, false} {
6249 var tests []testCase
6250
6251 // Test that this is indeed the timeout schedule. Stress all
6252 // four patterns of handshake.
6253 for i := 1; i < len(timeouts); i++ {
6254 number := strconv.Itoa(i)
6255 tests = append(tests, testCase{
6256 protocol: dtls,
6257 name: "DTLS-Retransmit-Client-" + number,
6258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006259 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006260 Bugs: ProtocolBugs{
6261 TimeoutSchedule: timeouts[:i],
6262 },
6263 },
6264 resumeSession: true,
6265 })
6266 tests = append(tests, testCase{
6267 protocol: dtls,
6268 testType: serverTest,
6269 name: "DTLS-Retransmit-Server-" + number,
6270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006271 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006272 Bugs: ProtocolBugs{
6273 TimeoutSchedule: timeouts[:i],
6274 },
6275 },
6276 resumeSession: true,
6277 })
6278 }
6279
6280 // Test that exceeding the timeout schedule hits a read
6281 // timeout.
6282 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006283 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006284 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006286 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006287 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006288 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006289 },
6290 },
6291 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006292 shouldFail: true,
6293 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006294 })
David Benjamin585d7a42016-06-02 14:58:00 -04006295
6296 if async {
6297 // Test that timeout handling has a fudge factor, due to API
6298 // problems.
6299 tests = append(tests, testCase{
6300 protocol: dtls,
6301 name: "DTLS-Retransmit-Fudge",
6302 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006303 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006304 Bugs: ProtocolBugs{
6305 TimeoutSchedule: []time.Duration{
6306 timeouts[0] - 10*time.Millisecond,
6307 },
6308 },
6309 },
6310 resumeSession: true,
6311 })
6312 }
6313
6314 // Test that the final Finished retransmitting isn't
6315 // duplicated if the peer badly fragments everything.
6316 tests = append(tests, testCase{
6317 testType: serverTest,
6318 protocol: dtls,
6319 name: "DTLS-Retransmit-Fragmented",
6320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006321 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006322 Bugs: ProtocolBugs{
6323 TimeoutSchedule: []time.Duration{timeouts[0]},
6324 MaxHandshakeRecordLength: 2,
6325 },
6326 },
6327 })
6328
6329 // Test the timeout schedule when a shorter initial timeout duration is set.
6330 tests = append(tests, testCase{
6331 protocol: dtls,
6332 name: "DTLS-Retransmit-Short-Client",
6333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006334 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006335 Bugs: ProtocolBugs{
6336 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6337 },
6338 },
6339 resumeSession: true,
6340 flags: []string{"-initial-timeout-duration-ms", "250"},
6341 })
6342 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006343 protocol: dtls,
6344 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006345 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006346 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006347 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006348 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006349 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006350 },
6351 },
6352 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006353 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006354 })
David Benjamin585d7a42016-06-02 14:58:00 -04006355
6356 for _, test := range tests {
6357 if async {
6358 test.name += "-Async"
6359 test.flags = append(test.flags, "-async")
6360 }
6361
6362 testCases = append(testCases, test)
6363 }
David Benjamin83f90402015-01-27 01:09:43 -05006364 }
David Benjamin83f90402015-01-27 01:09:43 -05006365}
6366
David Benjaminc565ebb2015-04-03 04:06:36 -04006367func addExportKeyingMaterialTests() {
6368 for _, vers := range tlsVersions {
6369 if vers.version == VersionSSL30 {
6370 continue
6371 }
6372 testCases = append(testCases, testCase{
6373 name: "ExportKeyingMaterial-" + vers.name,
6374 config: Config{
6375 MaxVersion: vers.version,
6376 },
6377 exportKeyingMaterial: 1024,
6378 exportLabel: "label",
6379 exportContext: "context",
6380 useExportContext: true,
6381 })
6382 testCases = append(testCases, testCase{
6383 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6384 config: Config{
6385 MaxVersion: vers.version,
6386 },
6387 exportKeyingMaterial: 1024,
6388 })
6389 testCases = append(testCases, testCase{
6390 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6391 config: Config{
6392 MaxVersion: vers.version,
6393 },
6394 exportKeyingMaterial: 1024,
6395 useExportContext: true,
6396 })
6397 testCases = append(testCases, testCase{
6398 name: "ExportKeyingMaterial-Small-" + vers.name,
6399 config: Config{
6400 MaxVersion: vers.version,
6401 },
6402 exportKeyingMaterial: 1,
6403 exportLabel: "label",
6404 exportContext: "context",
6405 useExportContext: true,
6406 })
6407 }
6408 testCases = append(testCases, testCase{
6409 name: "ExportKeyingMaterial-SSL3",
6410 config: Config{
6411 MaxVersion: VersionSSL30,
6412 },
6413 exportKeyingMaterial: 1024,
6414 exportLabel: "label",
6415 exportContext: "context",
6416 useExportContext: true,
6417 shouldFail: true,
6418 expectedError: "failed to export keying material",
6419 })
6420}
6421
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006422func addTLSUniqueTests() {
6423 for _, isClient := range []bool{false, true} {
6424 for _, isResumption := range []bool{false, true} {
6425 for _, hasEMS := range []bool{false, true} {
6426 var suffix string
6427 if isResumption {
6428 suffix = "Resume-"
6429 } else {
6430 suffix = "Full-"
6431 }
6432
6433 if hasEMS {
6434 suffix += "EMS-"
6435 } else {
6436 suffix += "NoEMS-"
6437 }
6438
6439 if isClient {
6440 suffix += "Client"
6441 } else {
6442 suffix += "Server"
6443 }
6444
6445 test := testCase{
6446 name: "TLSUnique-" + suffix,
6447 testTLSUnique: true,
6448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006449 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006450 Bugs: ProtocolBugs{
6451 NoExtendedMasterSecret: !hasEMS,
6452 },
6453 },
6454 }
6455
6456 if isResumption {
6457 test.resumeSession = true
6458 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006459 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006460 Bugs: ProtocolBugs{
6461 NoExtendedMasterSecret: !hasEMS,
6462 },
6463 }
6464 }
6465
6466 if isResumption && !hasEMS {
6467 test.shouldFail = true
6468 test.expectedError = "failed to get tls-unique"
6469 }
6470
6471 testCases = append(testCases, test)
6472 }
6473 }
6474 }
6475}
6476
Adam Langley09505632015-07-30 18:10:13 -07006477func addCustomExtensionTests() {
6478 expectedContents := "custom extension"
6479 emptyString := ""
6480
6481 for _, isClient := range []bool{false, true} {
6482 suffix := "Server"
6483 flag := "-enable-server-custom-extension"
6484 testType := serverTest
6485 if isClient {
6486 suffix = "Client"
6487 flag = "-enable-client-custom-extension"
6488 testType = clientTest
6489 }
6490
6491 testCases = append(testCases, testCase{
6492 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006493 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006495 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006496 Bugs: ProtocolBugs{
6497 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006498 ExpectedCustomExtension: &expectedContents,
6499 },
6500 },
6501 flags: []string{flag},
6502 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006503 testCases = append(testCases, testCase{
6504 testType: testType,
6505 name: "CustomExtensions-" + suffix + "-TLS13",
6506 config: Config{
6507 MaxVersion: VersionTLS13,
6508 Bugs: ProtocolBugs{
6509 CustomExtension: expectedContents,
6510 ExpectedCustomExtension: &expectedContents,
6511 },
6512 },
6513 flags: []string{flag},
6514 })
Adam Langley09505632015-07-30 18:10:13 -07006515
6516 // If the parse callback fails, the handshake should also fail.
6517 testCases = append(testCases, testCase{
6518 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006519 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006521 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006522 Bugs: ProtocolBugs{
6523 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006524 ExpectedCustomExtension: &expectedContents,
6525 },
6526 },
David Benjamin399e7c92015-07-30 23:01:27 -04006527 flags: []string{flag},
6528 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006529 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6530 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006531 testCases = append(testCases, testCase{
6532 testType: testType,
6533 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6534 config: Config{
6535 MaxVersion: VersionTLS13,
6536 Bugs: ProtocolBugs{
6537 CustomExtension: expectedContents + "foo",
6538 ExpectedCustomExtension: &expectedContents,
6539 },
6540 },
6541 flags: []string{flag},
6542 shouldFail: true,
6543 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6544 })
Adam Langley09505632015-07-30 18:10:13 -07006545
6546 // If the add callback fails, the handshake should also fail.
6547 testCases = append(testCases, testCase{
6548 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006549 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006551 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006552 Bugs: ProtocolBugs{
6553 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006554 ExpectedCustomExtension: &expectedContents,
6555 },
6556 },
David Benjamin399e7c92015-07-30 23:01:27 -04006557 flags: []string{flag, "-custom-extension-fail-add"},
6558 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006559 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6560 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006561 testCases = append(testCases, testCase{
6562 testType: testType,
6563 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6564 config: Config{
6565 MaxVersion: VersionTLS13,
6566 Bugs: ProtocolBugs{
6567 CustomExtension: expectedContents,
6568 ExpectedCustomExtension: &expectedContents,
6569 },
6570 },
6571 flags: []string{flag, "-custom-extension-fail-add"},
6572 shouldFail: true,
6573 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6574 })
Adam Langley09505632015-07-30 18:10:13 -07006575
6576 // If the add callback returns zero, no extension should be
6577 // added.
6578 skipCustomExtension := expectedContents
6579 if isClient {
6580 // For the case where the client skips sending the
6581 // custom extension, the server must not “echo” it.
6582 skipCustomExtension = ""
6583 }
6584 testCases = append(testCases, testCase{
6585 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006586 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006588 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006589 Bugs: ProtocolBugs{
6590 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006591 ExpectedCustomExtension: &emptyString,
6592 },
6593 },
6594 flags: []string{flag, "-custom-extension-skip"},
6595 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006596 testCases = append(testCases, testCase{
6597 testType: testType,
6598 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6599 config: Config{
6600 MaxVersion: VersionTLS13,
6601 Bugs: ProtocolBugs{
6602 CustomExtension: skipCustomExtension,
6603 ExpectedCustomExtension: &emptyString,
6604 },
6605 },
6606 flags: []string{flag, "-custom-extension-skip"},
6607 })
Adam Langley09505632015-07-30 18:10:13 -07006608 }
6609
6610 // The custom extension add callback should not be called if the client
6611 // doesn't send the extension.
6612 testCases = append(testCases, testCase{
6613 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006614 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006615 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006616 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006617 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006618 ExpectedCustomExtension: &emptyString,
6619 },
6620 },
6621 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6622 })
Adam Langley2deb9842015-08-07 11:15:37 -07006623
Steven Valdez143e8b32016-07-11 13:19:03 -04006624 testCases = append(testCases, testCase{
6625 testType: serverTest,
6626 name: "CustomExtensions-NotCalled-Server-TLS13",
6627 config: Config{
6628 MaxVersion: VersionTLS13,
6629 Bugs: ProtocolBugs{
6630 ExpectedCustomExtension: &emptyString,
6631 },
6632 },
6633 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6634 })
6635
Adam Langley2deb9842015-08-07 11:15:37 -07006636 // Test an unknown extension from the server.
6637 testCases = append(testCases, testCase{
6638 testType: clientTest,
6639 name: "UnknownExtension-Client",
6640 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006641 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006642 Bugs: ProtocolBugs{
6643 CustomExtension: expectedContents,
6644 },
6645 },
David Benjamin0c40a962016-08-01 12:05:50 -04006646 shouldFail: true,
6647 expectedError: ":UNEXPECTED_EXTENSION:",
6648 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006649 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006650 testCases = append(testCases, testCase{
6651 testType: clientTest,
6652 name: "UnknownExtension-Client-TLS13",
6653 config: Config{
6654 MaxVersion: VersionTLS13,
6655 Bugs: ProtocolBugs{
6656 CustomExtension: expectedContents,
6657 },
6658 },
David Benjamin0c40a962016-08-01 12:05:50 -04006659 shouldFail: true,
6660 expectedError: ":UNEXPECTED_EXTENSION:",
6661 expectedLocalError: "remote error: unsupported extension",
6662 })
6663
6664 // Test a known but unoffered extension from the server.
6665 testCases = append(testCases, testCase{
6666 testType: clientTest,
6667 name: "UnofferedExtension-Client",
6668 config: Config{
6669 MaxVersion: VersionTLS12,
6670 Bugs: ProtocolBugs{
6671 SendALPN: "alpn",
6672 },
6673 },
6674 shouldFail: true,
6675 expectedError: ":UNEXPECTED_EXTENSION:",
6676 expectedLocalError: "remote error: unsupported extension",
6677 })
6678 testCases = append(testCases, testCase{
6679 testType: clientTest,
6680 name: "UnofferedExtension-Client-TLS13",
6681 config: Config{
6682 MaxVersion: VersionTLS13,
6683 Bugs: ProtocolBugs{
6684 SendALPN: "alpn",
6685 },
6686 },
6687 shouldFail: true,
6688 expectedError: ":UNEXPECTED_EXTENSION:",
6689 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006690 })
Adam Langley09505632015-07-30 18:10:13 -07006691}
6692
David Benjaminb36a3952015-12-01 18:53:13 -05006693func addRSAClientKeyExchangeTests() {
6694 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6695 testCases = append(testCases, testCase{
6696 testType: serverTest,
6697 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6698 config: Config{
6699 // Ensure the ClientHello version and final
6700 // version are different, to detect if the
6701 // server uses the wrong one.
6702 MaxVersion: VersionTLS11,
6703 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6704 Bugs: ProtocolBugs{
6705 BadRSAClientKeyExchange: bad,
6706 },
6707 },
6708 shouldFail: true,
6709 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6710 })
6711 }
6712}
6713
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006714var testCurves = []struct {
6715 name string
6716 id CurveID
6717}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006718 {"P-256", CurveP256},
6719 {"P-384", CurveP384},
6720 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006721 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006722}
6723
Steven Valdez5440fe02016-07-18 12:40:30 -04006724const bogusCurve = 0x1234
6725
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006726func addCurveTests() {
6727 for _, curve := range testCurves {
6728 testCases = append(testCases, testCase{
6729 name: "CurveTest-Client-" + curve.name,
6730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006731 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006732 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6733 CurvePreferences: []CurveID{curve.id},
6734 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006735 flags: []string{"-enable-all-curves"},
6736 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006737 })
6738 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006739 name: "CurveTest-Client-" + curve.name + "-TLS13",
6740 config: Config{
6741 MaxVersion: VersionTLS13,
6742 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6743 CurvePreferences: []CurveID{curve.id},
6744 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006745 flags: []string{"-enable-all-curves"},
6746 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006747 })
6748 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006749 testType: serverTest,
6750 name: "CurveTest-Server-" + curve.name,
6751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006752 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006753 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6754 CurvePreferences: []CurveID{curve.id},
6755 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006756 flags: []string{"-enable-all-curves"},
6757 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006758 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: "CurveTest-Server-" + curve.name + "-TLS13",
6762 config: Config{
6763 MaxVersion: VersionTLS13,
6764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6765 CurvePreferences: []CurveID{curve.id},
6766 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006767 flags: []string{"-enable-all-curves"},
6768 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006769 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006770 }
David Benjamin241ae832016-01-15 03:04:54 -05006771
6772 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006773 testCases = append(testCases, testCase{
6774 testType: serverTest,
6775 name: "UnknownCurve",
6776 config: Config{
6777 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6778 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6779 },
6780 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006781
6782 // The server must not consider ECDHE ciphers when there are no
6783 // supported curves.
6784 testCases = append(testCases, testCase{
6785 testType: serverTest,
6786 name: "NoSupportedCurves",
6787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006788 MaxVersion: VersionTLS12,
6789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6790 Bugs: ProtocolBugs{
6791 NoSupportedCurves: true,
6792 },
6793 },
6794 shouldFail: true,
6795 expectedError: ":NO_SHARED_CIPHER:",
6796 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006797 testCases = append(testCases, testCase{
6798 testType: serverTest,
6799 name: "NoSupportedCurves-TLS13",
6800 config: Config{
6801 MaxVersion: VersionTLS13,
6802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6803 Bugs: ProtocolBugs{
6804 NoSupportedCurves: true,
6805 },
6806 },
6807 shouldFail: true,
6808 expectedError: ":NO_SHARED_CIPHER:",
6809 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006810
6811 // The server must fall back to another cipher when there are no
6812 // supported curves.
6813 testCases = append(testCases, testCase{
6814 testType: serverTest,
6815 name: "NoCommonCurves",
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 CipherSuites: []uint16{
6819 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6820 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6821 },
6822 CurvePreferences: []CurveID{CurveP224},
6823 },
6824 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6825 })
6826
6827 // The client must reject bogus curves and disabled curves.
6828 testCases = append(testCases, testCase{
6829 name: "BadECDHECurve",
6830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006831 MaxVersion: VersionTLS12,
6832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6833 Bugs: ProtocolBugs{
6834 SendCurve: bogusCurve,
6835 },
6836 },
6837 shouldFail: true,
6838 expectedError: ":WRONG_CURVE:",
6839 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006840 testCases = append(testCases, testCase{
6841 name: "BadECDHECurve-TLS13",
6842 config: Config{
6843 MaxVersion: VersionTLS13,
6844 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6845 Bugs: ProtocolBugs{
6846 SendCurve: bogusCurve,
6847 },
6848 },
6849 shouldFail: true,
6850 expectedError: ":WRONG_CURVE:",
6851 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006852
6853 testCases = append(testCases, testCase{
6854 name: "UnsupportedCurve",
6855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006856 MaxVersion: VersionTLS12,
6857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6858 CurvePreferences: []CurveID{CurveP256},
6859 Bugs: ProtocolBugs{
6860 IgnorePeerCurvePreferences: true,
6861 },
6862 },
6863 flags: []string{"-p384-only"},
6864 shouldFail: true,
6865 expectedError: ":WRONG_CURVE:",
6866 })
6867
David Benjamin4f921572016-07-17 14:20:10 +02006868 testCases = append(testCases, testCase{
6869 // TODO(davidben): Add a TLS 1.3 version where
6870 // HelloRetryRequest requests an unsupported curve.
6871 name: "UnsupportedCurve-ServerHello-TLS13",
6872 config: Config{
6873 MaxVersion: VersionTLS12,
6874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6875 CurvePreferences: []CurveID{CurveP384},
6876 Bugs: ProtocolBugs{
6877 SendCurve: CurveP256,
6878 },
6879 },
6880 flags: []string{"-p384-only"},
6881 shouldFail: true,
6882 expectedError: ":WRONG_CURVE:",
6883 })
6884
David Benjamin4c3ddf72016-06-29 18:13:53 -04006885 // Test invalid curve points.
6886 testCases = append(testCases, testCase{
6887 name: "InvalidECDHPoint-Client",
6888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006889 MaxVersion: VersionTLS12,
6890 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6891 CurvePreferences: []CurveID{CurveP256},
6892 Bugs: ProtocolBugs{
6893 InvalidECDHPoint: true,
6894 },
6895 },
6896 shouldFail: true,
6897 expectedError: ":INVALID_ENCODING:",
6898 })
6899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006900 name: "InvalidECDHPoint-Client-TLS13",
6901 config: Config{
6902 MaxVersion: VersionTLS13,
6903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6904 CurvePreferences: []CurveID{CurveP256},
6905 Bugs: ProtocolBugs{
6906 InvalidECDHPoint: true,
6907 },
6908 },
6909 shouldFail: true,
6910 expectedError: ":INVALID_ENCODING:",
6911 })
6912 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006913 testType: serverTest,
6914 name: "InvalidECDHPoint-Server",
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 CurvePreferences: []CurveID{CurveP256},
6919 Bugs: ProtocolBugs{
6920 InvalidECDHPoint: true,
6921 },
6922 },
6923 shouldFail: true,
6924 expectedError: ":INVALID_ENCODING:",
6925 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006926 testCases = append(testCases, testCase{
6927 testType: serverTest,
6928 name: "InvalidECDHPoint-Server-TLS13",
6929 config: Config{
6930 MaxVersion: VersionTLS13,
6931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6932 CurvePreferences: []CurveID{CurveP256},
6933 Bugs: ProtocolBugs{
6934 InvalidECDHPoint: true,
6935 },
6936 },
6937 shouldFail: true,
6938 expectedError: ":INVALID_ENCODING:",
6939 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006940}
6941
Matt Braithwaite54217e42016-06-13 13:03:47 -07006942func addCECPQ1Tests() {
6943 testCases = append(testCases, testCase{
6944 testType: clientTest,
6945 name: "CECPQ1-Client-BadX25519Part",
6946 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006947 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006948 MinVersion: VersionTLS12,
6949 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6950 Bugs: ProtocolBugs{
6951 CECPQ1BadX25519Part: true,
6952 },
6953 },
6954 flags: []string{"-cipher", "kCECPQ1"},
6955 shouldFail: true,
6956 expectedLocalError: "local error: bad record MAC",
6957 })
6958 testCases = append(testCases, testCase{
6959 testType: clientTest,
6960 name: "CECPQ1-Client-BadNewhopePart",
6961 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006962 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006963 MinVersion: VersionTLS12,
6964 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6965 Bugs: ProtocolBugs{
6966 CECPQ1BadNewhopePart: true,
6967 },
6968 },
6969 flags: []string{"-cipher", "kCECPQ1"},
6970 shouldFail: true,
6971 expectedLocalError: "local error: bad record MAC",
6972 })
6973 testCases = append(testCases, testCase{
6974 testType: serverTest,
6975 name: "CECPQ1-Server-BadX25519Part",
6976 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006977 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006978 MinVersion: VersionTLS12,
6979 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6980 Bugs: ProtocolBugs{
6981 CECPQ1BadX25519Part: true,
6982 },
6983 },
6984 flags: []string{"-cipher", "kCECPQ1"},
6985 shouldFail: true,
6986 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6987 })
6988 testCases = append(testCases, testCase{
6989 testType: serverTest,
6990 name: "CECPQ1-Server-BadNewhopePart",
6991 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006992 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006993 MinVersion: VersionTLS12,
6994 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6995 Bugs: ProtocolBugs{
6996 CECPQ1BadNewhopePart: true,
6997 },
6998 },
6999 flags: []string{"-cipher", "kCECPQ1"},
7000 shouldFail: true,
7001 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7002 })
7003}
7004
David Benjamin4cc36ad2015-12-19 14:23:26 -05007005func addKeyExchangeInfoTests() {
7006 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05007007 name: "KeyExchangeInfo-DHE-Client",
7008 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007009 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007010 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7011 Bugs: ProtocolBugs{
7012 // This is a 1234-bit prime number, generated
7013 // with:
7014 // openssl gendh 1234 | openssl asn1parse -i
7015 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7016 },
7017 },
David Benjamin9e68f192016-06-30 14:55:33 -04007018 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007019 })
7020 testCases = append(testCases, testCase{
7021 testType: serverTest,
7022 name: "KeyExchangeInfo-DHE-Server",
7023 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007024 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007025 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7026 },
7027 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007028 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007029 })
7030
7031 testCases = append(testCases, testCase{
7032 name: "KeyExchangeInfo-ECDHE-Client",
7033 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007034 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7036 CurvePreferences: []CurveID{CurveX25519},
7037 },
David Benjamin9e68f192016-06-30 14:55:33 -04007038 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007039 })
7040 testCases = append(testCases, testCase{
7041 testType: serverTest,
7042 name: "KeyExchangeInfo-ECDHE-Server",
7043 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007044 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007045 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7046 CurvePreferences: []CurveID{CurveX25519},
7047 },
David Benjamin9e68f192016-06-30 14:55:33 -04007048 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007049 })
7050}
7051
David Benjaminc9ae27c2016-06-24 22:56:37 -04007052func addTLS13RecordTests() {
7053 testCases = append(testCases, testCase{
7054 name: "TLS13-RecordPadding",
7055 config: Config{
7056 MaxVersion: VersionTLS13,
7057 MinVersion: VersionTLS13,
7058 Bugs: ProtocolBugs{
7059 RecordPadding: 10,
7060 },
7061 },
7062 })
7063
7064 testCases = append(testCases, testCase{
7065 name: "TLS13-EmptyRecords",
7066 config: Config{
7067 MaxVersion: VersionTLS13,
7068 MinVersion: VersionTLS13,
7069 Bugs: ProtocolBugs{
7070 OmitRecordContents: true,
7071 },
7072 },
7073 shouldFail: true,
7074 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7075 })
7076
7077 testCases = append(testCases, testCase{
7078 name: "TLS13-OnlyPadding",
7079 config: Config{
7080 MaxVersion: VersionTLS13,
7081 MinVersion: VersionTLS13,
7082 Bugs: ProtocolBugs{
7083 OmitRecordContents: true,
7084 RecordPadding: 10,
7085 },
7086 },
7087 shouldFail: true,
7088 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7089 })
7090
7091 testCases = append(testCases, testCase{
7092 name: "TLS13-WrongOuterRecord",
7093 config: Config{
7094 MaxVersion: VersionTLS13,
7095 MinVersion: VersionTLS13,
7096 Bugs: ProtocolBugs{
7097 OuterRecordType: recordTypeHandshake,
7098 },
7099 },
7100 shouldFail: true,
7101 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7102 })
7103}
7104
David Benjamin82261be2016-07-07 14:32:50 -07007105func addChangeCipherSpecTests() {
7106 // Test missing ChangeCipherSpecs.
7107 testCases = append(testCases, testCase{
7108 name: "SkipChangeCipherSpec-Client",
7109 config: Config{
7110 MaxVersion: VersionTLS12,
7111 Bugs: ProtocolBugs{
7112 SkipChangeCipherSpec: true,
7113 },
7114 },
7115 shouldFail: true,
7116 expectedError: ":UNEXPECTED_RECORD:",
7117 })
7118 testCases = append(testCases, testCase{
7119 testType: serverTest,
7120 name: "SkipChangeCipherSpec-Server",
7121 config: Config{
7122 MaxVersion: VersionTLS12,
7123 Bugs: ProtocolBugs{
7124 SkipChangeCipherSpec: true,
7125 },
7126 },
7127 shouldFail: true,
7128 expectedError: ":UNEXPECTED_RECORD:",
7129 })
7130 testCases = append(testCases, testCase{
7131 testType: serverTest,
7132 name: "SkipChangeCipherSpec-Server-NPN",
7133 config: Config{
7134 MaxVersion: VersionTLS12,
7135 NextProtos: []string{"bar"},
7136 Bugs: ProtocolBugs{
7137 SkipChangeCipherSpec: true,
7138 },
7139 },
7140 flags: []string{
7141 "-advertise-npn", "\x03foo\x03bar\x03baz",
7142 },
7143 shouldFail: true,
7144 expectedError: ":UNEXPECTED_RECORD:",
7145 })
7146
7147 // Test synchronization between the handshake and ChangeCipherSpec.
7148 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7149 // rejected. Test both with and without handshake packing to handle both
7150 // when the partial post-CCS message is in its own record and when it is
7151 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007152 for _, packed := range []bool{false, true} {
7153 var suffix string
7154 if packed {
7155 suffix = "-Packed"
7156 }
7157
7158 testCases = append(testCases, testCase{
7159 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7160 config: Config{
7161 MaxVersion: VersionTLS12,
7162 Bugs: ProtocolBugs{
7163 FragmentAcrossChangeCipherSpec: true,
7164 PackHandshakeFlight: packed,
7165 },
7166 },
7167 shouldFail: true,
7168 expectedError: ":UNEXPECTED_RECORD:",
7169 })
7170 testCases = append(testCases, testCase{
7171 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7172 config: Config{
7173 MaxVersion: VersionTLS12,
7174 },
7175 resumeSession: true,
7176 resumeConfig: &Config{
7177 MaxVersion: VersionTLS12,
7178 Bugs: ProtocolBugs{
7179 FragmentAcrossChangeCipherSpec: true,
7180 PackHandshakeFlight: packed,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_RECORD:",
7185 })
7186 testCases = append(testCases, testCase{
7187 testType: serverTest,
7188 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7189 config: Config{
7190 MaxVersion: VersionTLS12,
7191 Bugs: ProtocolBugs{
7192 FragmentAcrossChangeCipherSpec: true,
7193 PackHandshakeFlight: packed,
7194 },
7195 },
7196 shouldFail: true,
7197 expectedError: ":UNEXPECTED_RECORD:",
7198 })
7199 testCases = append(testCases, testCase{
7200 testType: serverTest,
7201 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7202 config: Config{
7203 MaxVersion: VersionTLS12,
7204 },
7205 resumeSession: true,
7206 resumeConfig: &Config{
7207 MaxVersion: VersionTLS12,
7208 Bugs: ProtocolBugs{
7209 FragmentAcrossChangeCipherSpec: true,
7210 PackHandshakeFlight: packed,
7211 },
7212 },
7213 shouldFail: true,
7214 expectedError: ":UNEXPECTED_RECORD:",
7215 })
7216 testCases = append(testCases, testCase{
7217 testType: serverTest,
7218 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7219 config: Config{
7220 MaxVersion: VersionTLS12,
7221 NextProtos: []string{"bar"},
7222 Bugs: ProtocolBugs{
7223 FragmentAcrossChangeCipherSpec: true,
7224 PackHandshakeFlight: packed,
7225 },
7226 },
7227 flags: []string{
7228 "-advertise-npn", "\x03foo\x03bar\x03baz",
7229 },
7230 shouldFail: true,
7231 expectedError: ":UNEXPECTED_RECORD:",
7232 })
7233 }
7234
David Benjamin61672812016-07-14 23:10:43 -04007235 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7236 // messages in the handshake queue. Do this by testing the server
7237 // reading the client Finished, reversing the flight so Finished comes
7238 // first.
7239 testCases = append(testCases, testCase{
7240 protocol: dtls,
7241 testType: serverTest,
7242 name: "SendUnencryptedFinished-DTLS",
7243 config: Config{
7244 MaxVersion: VersionTLS12,
7245 Bugs: ProtocolBugs{
7246 SendUnencryptedFinished: true,
7247 ReverseHandshakeFragments: true,
7248 },
7249 },
7250 shouldFail: true,
7251 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7252 })
7253
Steven Valdez143e8b32016-07-11 13:19:03 -04007254 // Test synchronization between encryption changes and the handshake in
7255 // TLS 1.3, where ChangeCipherSpec is implicit.
7256 testCases = append(testCases, testCase{
7257 name: "PartialEncryptedExtensionsWithServerHello",
7258 config: Config{
7259 MaxVersion: VersionTLS13,
7260 Bugs: ProtocolBugs{
7261 PartialEncryptedExtensionsWithServerHello: true,
7262 },
7263 },
7264 shouldFail: true,
7265 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7266 })
7267 testCases = append(testCases, testCase{
7268 testType: serverTest,
7269 name: "PartialClientFinishedWithClientHello",
7270 config: Config{
7271 MaxVersion: VersionTLS13,
7272 Bugs: ProtocolBugs{
7273 PartialClientFinishedWithClientHello: true,
7274 },
7275 },
7276 shouldFail: true,
7277 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7278 })
7279
David Benjamin82261be2016-07-07 14:32:50 -07007280 // Test that early ChangeCipherSpecs are handled correctly.
7281 testCases = append(testCases, testCase{
7282 testType: serverTest,
7283 name: "EarlyChangeCipherSpec-server-1",
7284 config: Config{
7285 MaxVersion: VersionTLS12,
7286 Bugs: ProtocolBugs{
7287 EarlyChangeCipherSpec: 1,
7288 },
7289 },
7290 shouldFail: true,
7291 expectedError: ":UNEXPECTED_RECORD:",
7292 })
7293 testCases = append(testCases, testCase{
7294 testType: serverTest,
7295 name: "EarlyChangeCipherSpec-server-2",
7296 config: Config{
7297 MaxVersion: VersionTLS12,
7298 Bugs: ProtocolBugs{
7299 EarlyChangeCipherSpec: 2,
7300 },
7301 },
7302 shouldFail: true,
7303 expectedError: ":UNEXPECTED_RECORD:",
7304 })
7305 testCases = append(testCases, testCase{
7306 protocol: dtls,
7307 name: "StrayChangeCipherSpec",
7308 config: Config{
7309 // TODO(davidben): Once DTLS 1.3 exists, test
7310 // that stray ChangeCipherSpec messages are
7311 // rejected.
7312 MaxVersion: VersionTLS12,
7313 Bugs: ProtocolBugs{
7314 StrayChangeCipherSpec: true,
7315 },
7316 },
7317 })
7318
7319 // Test that the contents of ChangeCipherSpec are checked.
7320 testCases = append(testCases, testCase{
7321 name: "BadChangeCipherSpec-1",
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 Bugs: ProtocolBugs{
7325 BadChangeCipherSpec: []byte{2},
7326 },
7327 },
7328 shouldFail: true,
7329 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7330 })
7331 testCases = append(testCases, testCase{
7332 name: "BadChangeCipherSpec-2",
7333 config: Config{
7334 MaxVersion: VersionTLS12,
7335 Bugs: ProtocolBugs{
7336 BadChangeCipherSpec: []byte{1, 1},
7337 },
7338 },
7339 shouldFail: true,
7340 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7341 })
7342 testCases = append(testCases, testCase{
7343 protocol: dtls,
7344 name: "BadChangeCipherSpec-DTLS-1",
7345 config: Config{
7346 MaxVersion: VersionTLS12,
7347 Bugs: ProtocolBugs{
7348 BadChangeCipherSpec: []byte{2},
7349 },
7350 },
7351 shouldFail: true,
7352 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7353 })
7354 testCases = append(testCases, testCase{
7355 protocol: dtls,
7356 name: "BadChangeCipherSpec-DTLS-2",
7357 config: Config{
7358 MaxVersion: VersionTLS12,
7359 Bugs: ProtocolBugs{
7360 BadChangeCipherSpec: []byte{1, 1},
7361 },
7362 },
7363 shouldFail: true,
7364 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7365 })
7366}
7367
David Benjamin0b8d5da2016-07-15 00:39:56 -04007368func addWrongMessageTypeTests() {
7369 for _, protocol := range []protocol{tls, dtls} {
7370 var suffix string
7371 if protocol == dtls {
7372 suffix = "-DTLS"
7373 }
7374
7375 testCases = append(testCases, testCase{
7376 protocol: protocol,
7377 testType: serverTest,
7378 name: "WrongMessageType-ClientHello" + suffix,
7379 config: Config{
7380 MaxVersion: VersionTLS12,
7381 Bugs: ProtocolBugs{
7382 SendWrongMessageType: typeClientHello,
7383 },
7384 },
7385 shouldFail: true,
7386 expectedError: ":UNEXPECTED_MESSAGE:",
7387 expectedLocalError: "remote error: unexpected message",
7388 })
7389
7390 if protocol == dtls {
7391 testCases = append(testCases, testCase{
7392 protocol: protocol,
7393 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7394 config: Config{
7395 MaxVersion: VersionTLS12,
7396 Bugs: ProtocolBugs{
7397 SendWrongMessageType: typeHelloVerifyRequest,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":UNEXPECTED_MESSAGE:",
7402 expectedLocalError: "remote error: unexpected message",
7403 })
7404 }
7405
7406 testCases = append(testCases, testCase{
7407 protocol: protocol,
7408 name: "WrongMessageType-ServerHello" + suffix,
7409 config: Config{
7410 MaxVersion: VersionTLS12,
7411 Bugs: ProtocolBugs{
7412 SendWrongMessageType: typeServerHello,
7413 },
7414 },
7415 shouldFail: true,
7416 expectedError: ":UNEXPECTED_MESSAGE:",
7417 expectedLocalError: "remote error: unexpected message",
7418 })
7419
7420 testCases = append(testCases, testCase{
7421 protocol: protocol,
7422 name: "WrongMessageType-ServerCertificate" + suffix,
7423 config: Config{
7424 MaxVersion: VersionTLS12,
7425 Bugs: ProtocolBugs{
7426 SendWrongMessageType: typeCertificate,
7427 },
7428 },
7429 shouldFail: true,
7430 expectedError: ":UNEXPECTED_MESSAGE:",
7431 expectedLocalError: "remote error: unexpected message",
7432 })
7433
7434 testCases = append(testCases, testCase{
7435 protocol: protocol,
7436 name: "WrongMessageType-CertificateStatus" + suffix,
7437 config: Config{
7438 MaxVersion: VersionTLS12,
7439 Bugs: ProtocolBugs{
7440 SendWrongMessageType: typeCertificateStatus,
7441 },
7442 },
7443 flags: []string{"-enable-ocsp-stapling"},
7444 shouldFail: true,
7445 expectedError: ":UNEXPECTED_MESSAGE:",
7446 expectedLocalError: "remote error: unexpected message",
7447 })
7448
7449 testCases = append(testCases, testCase{
7450 protocol: protocol,
7451 name: "WrongMessageType-ServerKeyExchange" + suffix,
7452 config: Config{
7453 MaxVersion: VersionTLS12,
7454 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7455 Bugs: ProtocolBugs{
7456 SendWrongMessageType: typeServerKeyExchange,
7457 },
7458 },
7459 shouldFail: true,
7460 expectedError: ":UNEXPECTED_MESSAGE:",
7461 expectedLocalError: "remote error: unexpected message",
7462 })
7463
7464 testCases = append(testCases, testCase{
7465 protocol: protocol,
7466 name: "WrongMessageType-CertificateRequest" + suffix,
7467 config: Config{
7468 MaxVersion: VersionTLS12,
7469 ClientAuth: RequireAnyClientCert,
7470 Bugs: ProtocolBugs{
7471 SendWrongMessageType: typeCertificateRequest,
7472 },
7473 },
7474 shouldFail: true,
7475 expectedError: ":UNEXPECTED_MESSAGE:",
7476 expectedLocalError: "remote error: unexpected message",
7477 })
7478
7479 testCases = append(testCases, testCase{
7480 protocol: protocol,
7481 name: "WrongMessageType-ServerHelloDone" + suffix,
7482 config: Config{
7483 MaxVersion: VersionTLS12,
7484 Bugs: ProtocolBugs{
7485 SendWrongMessageType: typeServerHelloDone,
7486 },
7487 },
7488 shouldFail: true,
7489 expectedError: ":UNEXPECTED_MESSAGE:",
7490 expectedLocalError: "remote error: unexpected message",
7491 })
7492
7493 testCases = append(testCases, testCase{
7494 testType: serverTest,
7495 protocol: protocol,
7496 name: "WrongMessageType-ClientCertificate" + suffix,
7497 config: Config{
7498 Certificates: []Certificate{rsaCertificate},
7499 MaxVersion: VersionTLS12,
7500 Bugs: ProtocolBugs{
7501 SendWrongMessageType: typeCertificate,
7502 },
7503 },
7504 flags: []string{"-require-any-client-certificate"},
7505 shouldFail: true,
7506 expectedError: ":UNEXPECTED_MESSAGE:",
7507 expectedLocalError: "remote error: unexpected message",
7508 })
7509
7510 testCases = append(testCases, testCase{
7511 testType: serverTest,
7512 protocol: protocol,
7513 name: "WrongMessageType-CertificateVerify" + suffix,
7514 config: Config{
7515 Certificates: []Certificate{rsaCertificate},
7516 MaxVersion: VersionTLS12,
7517 Bugs: ProtocolBugs{
7518 SendWrongMessageType: typeCertificateVerify,
7519 },
7520 },
7521 flags: []string{"-require-any-client-certificate"},
7522 shouldFail: true,
7523 expectedError: ":UNEXPECTED_MESSAGE:",
7524 expectedLocalError: "remote error: unexpected message",
7525 })
7526
7527 testCases = append(testCases, testCase{
7528 testType: serverTest,
7529 protocol: protocol,
7530 name: "WrongMessageType-ClientKeyExchange" + suffix,
7531 config: Config{
7532 MaxVersion: VersionTLS12,
7533 Bugs: ProtocolBugs{
7534 SendWrongMessageType: typeClientKeyExchange,
7535 },
7536 },
7537 shouldFail: true,
7538 expectedError: ":UNEXPECTED_MESSAGE:",
7539 expectedLocalError: "remote error: unexpected message",
7540 })
7541
7542 if protocol != dtls {
7543 testCases = append(testCases, testCase{
7544 testType: serverTest,
7545 protocol: protocol,
7546 name: "WrongMessageType-NextProtocol" + suffix,
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 NextProtos: []string{"bar"},
7550 Bugs: ProtocolBugs{
7551 SendWrongMessageType: typeNextProtocol,
7552 },
7553 },
7554 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7555 shouldFail: true,
7556 expectedError: ":UNEXPECTED_MESSAGE:",
7557 expectedLocalError: "remote error: unexpected message",
7558 })
7559
7560 testCases = append(testCases, testCase{
7561 testType: serverTest,
7562 protocol: protocol,
7563 name: "WrongMessageType-ChannelID" + suffix,
7564 config: Config{
7565 MaxVersion: VersionTLS12,
7566 ChannelID: channelIDKey,
7567 Bugs: ProtocolBugs{
7568 SendWrongMessageType: typeChannelID,
7569 },
7570 },
7571 flags: []string{
7572 "-expect-channel-id",
7573 base64.StdEncoding.EncodeToString(channelIDBytes),
7574 },
7575 shouldFail: true,
7576 expectedError: ":UNEXPECTED_MESSAGE:",
7577 expectedLocalError: "remote error: unexpected message",
7578 })
7579 }
7580
7581 testCases = append(testCases, testCase{
7582 testType: serverTest,
7583 protocol: protocol,
7584 name: "WrongMessageType-ClientFinished" + suffix,
7585 config: Config{
7586 MaxVersion: VersionTLS12,
7587 Bugs: ProtocolBugs{
7588 SendWrongMessageType: typeFinished,
7589 },
7590 },
7591 shouldFail: true,
7592 expectedError: ":UNEXPECTED_MESSAGE:",
7593 expectedLocalError: "remote error: unexpected message",
7594 })
7595
7596 testCases = append(testCases, testCase{
7597 protocol: protocol,
7598 name: "WrongMessageType-NewSessionTicket" + suffix,
7599 config: Config{
7600 MaxVersion: VersionTLS12,
7601 Bugs: ProtocolBugs{
7602 SendWrongMessageType: typeNewSessionTicket,
7603 },
7604 },
7605 shouldFail: true,
7606 expectedError: ":UNEXPECTED_MESSAGE:",
7607 expectedLocalError: "remote error: unexpected message",
7608 })
7609
7610 testCases = append(testCases, testCase{
7611 protocol: protocol,
7612 name: "WrongMessageType-ServerFinished" + suffix,
7613 config: Config{
7614 MaxVersion: VersionTLS12,
7615 Bugs: ProtocolBugs{
7616 SendWrongMessageType: typeFinished,
7617 },
7618 },
7619 shouldFail: true,
7620 expectedError: ":UNEXPECTED_MESSAGE:",
7621 expectedLocalError: "remote error: unexpected message",
7622 })
7623
7624 }
7625}
7626
Steven Valdez143e8b32016-07-11 13:19:03 -04007627func addTLS13WrongMessageTypeTests() {
7628 testCases = append(testCases, testCase{
7629 testType: serverTest,
7630 name: "WrongMessageType-TLS13-ClientHello",
7631 config: Config{
7632 MaxVersion: VersionTLS13,
7633 Bugs: ProtocolBugs{
7634 SendWrongMessageType: typeClientHello,
7635 },
7636 },
7637 shouldFail: true,
7638 expectedError: ":UNEXPECTED_MESSAGE:",
7639 expectedLocalError: "remote error: unexpected message",
7640 })
7641
7642 testCases = append(testCases, testCase{
7643 name: "WrongMessageType-TLS13-ServerHello",
7644 config: Config{
7645 MaxVersion: VersionTLS13,
7646 Bugs: ProtocolBugs{
7647 SendWrongMessageType: typeServerHello,
7648 },
7649 },
7650 shouldFail: true,
7651 expectedError: ":UNEXPECTED_MESSAGE:",
7652 // The alert comes in with the wrong encryption.
7653 expectedLocalError: "local error: bad record MAC",
7654 })
7655
7656 testCases = append(testCases, testCase{
7657 name: "WrongMessageType-TLS13-EncryptedExtensions",
7658 config: Config{
7659 MaxVersion: VersionTLS13,
7660 Bugs: ProtocolBugs{
7661 SendWrongMessageType: typeEncryptedExtensions,
7662 },
7663 },
7664 shouldFail: true,
7665 expectedError: ":UNEXPECTED_MESSAGE:",
7666 expectedLocalError: "remote error: unexpected message",
7667 })
7668
7669 testCases = append(testCases, testCase{
7670 name: "WrongMessageType-TLS13-CertificateRequest",
7671 config: Config{
7672 MaxVersion: VersionTLS13,
7673 ClientAuth: RequireAnyClientCert,
7674 Bugs: ProtocolBugs{
7675 SendWrongMessageType: typeCertificateRequest,
7676 },
7677 },
7678 shouldFail: true,
7679 expectedError: ":UNEXPECTED_MESSAGE:",
7680 expectedLocalError: "remote error: unexpected message",
7681 })
7682
7683 testCases = append(testCases, testCase{
7684 name: "WrongMessageType-TLS13-ServerCertificate",
7685 config: Config{
7686 MaxVersion: VersionTLS13,
7687 Bugs: ProtocolBugs{
7688 SendWrongMessageType: typeCertificate,
7689 },
7690 },
7691 shouldFail: true,
7692 expectedError: ":UNEXPECTED_MESSAGE:",
7693 expectedLocalError: "remote error: unexpected message",
7694 })
7695
7696 testCases = append(testCases, testCase{
7697 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7698 config: Config{
7699 MaxVersion: VersionTLS13,
7700 Bugs: ProtocolBugs{
7701 SendWrongMessageType: typeCertificateVerify,
7702 },
7703 },
7704 shouldFail: true,
7705 expectedError: ":UNEXPECTED_MESSAGE:",
7706 expectedLocalError: "remote error: unexpected message",
7707 })
7708
7709 testCases = append(testCases, testCase{
7710 name: "WrongMessageType-TLS13-ServerFinished",
7711 config: Config{
7712 MaxVersion: VersionTLS13,
7713 Bugs: ProtocolBugs{
7714 SendWrongMessageType: typeFinished,
7715 },
7716 },
7717 shouldFail: true,
7718 expectedError: ":UNEXPECTED_MESSAGE:",
7719 expectedLocalError: "remote error: unexpected message",
7720 })
7721
7722 testCases = append(testCases, testCase{
7723 testType: serverTest,
7724 name: "WrongMessageType-TLS13-ClientCertificate",
7725 config: Config{
7726 Certificates: []Certificate{rsaCertificate},
7727 MaxVersion: VersionTLS13,
7728 Bugs: ProtocolBugs{
7729 SendWrongMessageType: typeCertificate,
7730 },
7731 },
7732 flags: []string{"-require-any-client-certificate"},
7733 shouldFail: true,
7734 expectedError: ":UNEXPECTED_MESSAGE:",
7735 expectedLocalError: "remote error: unexpected message",
7736 })
7737
7738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7741 config: Config{
7742 Certificates: []Certificate{rsaCertificate},
7743 MaxVersion: VersionTLS13,
7744 Bugs: ProtocolBugs{
7745 SendWrongMessageType: typeCertificateVerify,
7746 },
7747 },
7748 flags: []string{"-require-any-client-certificate"},
7749 shouldFail: true,
7750 expectedError: ":UNEXPECTED_MESSAGE:",
7751 expectedLocalError: "remote error: unexpected message",
7752 })
7753
7754 testCases = append(testCases, testCase{
7755 testType: serverTest,
7756 name: "WrongMessageType-TLS13-ClientFinished",
7757 config: Config{
7758 MaxVersion: VersionTLS13,
7759 Bugs: ProtocolBugs{
7760 SendWrongMessageType: typeFinished,
7761 },
7762 },
7763 shouldFail: true,
7764 expectedError: ":UNEXPECTED_MESSAGE:",
7765 expectedLocalError: "remote error: unexpected message",
7766 })
7767}
7768
7769func addTLS13HandshakeTests() {
7770 testCases = append(testCases, testCase{
7771 testType: clientTest,
7772 name: "MissingKeyShare-Client",
7773 config: Config{
7774 MaxVersion: VersionTLS13,
7775 Bugs: ProtocolBugs{
7776 MissingKeyShare: true,
7777 },
7778 },
7779 shouldFail: true,
7780 expectedError: ":MISSING_KEY_SHARE:",
7781 })
7782
7783 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007784 testType: serverTest,
7785 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007786 config: Config{
7787 MaxVersion: VersionTLS13,
7788 Bugs: ProtocolBugs{
7789 MissingKeyShare: true,
7790 },
7791 },
7792 shouldFail: true,
7793 expectedError: ":MISSING_KEY_SHARE:",
7794 })
7795
7796 testCases = append(testCases, testCase{
7797 testType: clientTest,
7798 name: "ClientHelloMissingKeyShare",
7799 config: Config{
7800 MaxVersion: VersionTLS13,
7801 Bugs: ProtocolBugs{
7802 MissingKeyShare: true,
7803 },
7804 },
7805 shouldFail: true,
7806 expectedError: ":MISSING_KEY_SHARE:",
7807 })
7808
7809 testCases = append(testCases, testCase{
7810 testType: clientTest,
7811 name: "MissingKeyShare",
7812 config: Config{
7813 MaxVersion: VersionTLS13,
7814 Bugs: ProtocolBugs{
7815 MissingKeyShare: true,
7816 },
7817 },
7818 shouldFail: true,
7819 expectedError: ":MISSING_KEY_SHARE:",
7820 })
7821
7822 testCases = append(testCases, testCase{
7823 testType: serverTest,
7824 name: "DuplicateKeyShares",
7825 config: Config{
7826 MaxVersion: VersionTLS13,
7827 Bugs: ProtocolBugs{
7828 DuplicateKeyShares: true,
7829 },
7830 },
7831 })
7832
7833 testCases = append(testCases, testCase{
7834 testType: clientTest,
7835 name: "EmptyEncryptedExtensions",
7836 config: Config{
7837 MaxVersion: VersionTLS13,
7838 Bugs: ProtocolBugs{
7839 EmptyEncryptedExtensions: true,
7840 },
7841 },
7842 shouldFail: true,
7843 expectedLocalError: "remote error: error decoding message",
7844 })
7845
7846 testCases = append(testCases, testCase{
7847 testType: clientTest,
7848 name: "EncryptedExtensionsWithKeyShare",
7849 config: Config{
7850 MaxVersion: VersionTLS13,
7851 Bugs: ProtocolBugs{
7852 EncryptedExtensionsWithKeyShare: true,
7853 },
7854 },
7855 shouldFail: true,
7856 expectedLocalError: "remote error: unsupported extension",
7857 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007858
7859 testCases = append(testCases, testCase{
7860 testType: serverTest,
7861 name: "SendHelloRetryRequest",
7862 config: Config{
7863 MaxVersion: VersionTLS13,
7864 // Require a HelloRetryRequest for every curve.
7865 DefaultCurves: []CurveID{},
7866 },
7867 expectedCurveID: CurveX25519,
7868 })
7869
7870 testCases = append(testCases, testCase{
7871 testType: serverTest,
7872 name: "SendHelloRetryRequest-2",
7873 config: Config{
7874 MaxVersion: VersionTLS13,
7875 DefaultCurves: []CurveID{CurveP384},
7876 },
7877 // Although the ClientHello did not predict our preferred curve,
7878 // we always select it whether it is predicted or not.
7879 expectedCurveID: CurveX25519,
7880 })
7881
7882 testCases = append(testCases, testCase{
7883 name: "UnknownCurve-HelloRetryRequest",
7884 config: Config{
7885 MaxVersion: VersionTLS13,
7886 // P-384 requires HelloRetryRequest in BoringSSL.
7887 CurvePreferences: []CurveID{CurveP384},
7888 Bugs: ProtocolBugs{
7889 SendHelloRetryRequestCurve: bogusCurve,
7890 },
7891 },
7892 shouldFail: true,
7893 expectedError: ":WRONG_CURVE:",
7894 })
7895
7896 testCases = append(testCases, testCase{
7897 name: "DisabledCurve-HelloRetryRequest",
7898 config: Config{
7899 MaxVersion: VersionTLS13,
7900 CurvePreferences: []CurveID{CurveP256},
7901 Bugs: ProtocolBugs{
7902 IgnorePeerCurvePreferences: true,
7903 },
7904 },
7905 flags: []string{"-p384-only"},
7906 shouldFail: true,
7907 expectedError: ":WRONG_CURVE:",
7908 })
7909
7910 testCases = append(testCases, testCase{
7911 name: "UnnecessaryHelloRetryRequest",
7912 config: Config{
7913 MaxVersion: VersionTLS13,
7914 Bugs: ProtocolBugs{
7915 UnnecessaryHelloRetryRequest: true,
7916 },
7917 },
7918 shouldFail: true,
7919 expectedError: ":WRONG_CURVE:",
7920 })
7921
7922 testCases = append(testCases, testCase{
7923 name: "SecondHelloRetryRequest",
7924 config: Config{
7925 MaxVersion: VersionTLS13,
7926 // P-384 requires HelloRetryRequest in BoringSSL.
7927 CurvePreferences: []CurveID{CurveP384},
7928 Bugs: ProtocolBugs{
7929 SecondHelloRetryRequest: true,
7930 },
7931 },
7932 shouldFail: true,
7933 expectedError: ":UNEXPECTED_MESSAGE:",
7934 })
7935
7936 testCases = append(testCases, testCase{
7937 testType: serverTest,
7938 name: "SecondClientHelloMissingKeyShare",
7939 config: Config{
7940 MaxVersion: VersionTLS13,
7941 DefaultCurves: []CurveID{},
7942 Bugs: ProtocolBugs{
7943 SecondClientHelloMissingKeyShare: true,
7944 },
7945 },
7946 shouldFail: true,
7947 expectedError: ":MISSING_KEY_SHARE:",
7948 })
7949
7950 testCases = append(testCases, testCase{
7951 testType: serverTest,
7952 name: "SecondClientHelloWrongCurve",
7953 config: Config{
7954 MaxVersion: VersionTLS13,
7955 DefaultCurves: []CurveID{},
7956 Bugs: ProtocolBugs{
7957 MisinterpretHelloRetryRequestCurve: CurveP521,
7958 },
7959 },
7960 shouldFail: true,
7961 expectedError: ":WRONG_CURVE:",
7962 })
7963
7964 testCases = append(testCases, testCase{
7965 name: "HelloRetryRequestVersionMismatch",
7966 config: Config{
7967 MaxVersion: VersionTLS13,
7968 // P-384 requires HelloRetryRequest in BoringSSL.
7969 CurvePreferences: []CurveID{CurveP384},
7970 Bugs: ProtocolBugs{
7971 SendServerHelloVersion: 0x0305,
7972 },
7973 },
7974 shouldFail: true,
7975 expectedError: ":WRONG_VERSION_NUMBER:",
7976 })
7977
7978 testCases = append(testCases, testCase{
7979 name: "HelloRetryRequestCurveMismatch",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 // P-384 requires HelloRetryRequest in BoringSSL.
7983 CurvePreferences: []CurveID{CurveP384},
7984 Bugs: ProtocolBugs{
7985 // Send P-384 (correct) in the HelloRetryRequest.
7986 SendHelloRetryRequestCurve: CurveP384,
7987 // But send P-256 in the ServerHello.
7988 SendCurve: CurveP256,
7989 },
7990 },
7991 shouldFail: true,
7992 expectedError: ":WRONG_CURVE:",
7993 })
7994
7995 // Test the server selecting a curve that requires a HelloRetryRequest
7996 // without sending it.
7997 testCases = append(testCases, testCase{
7998 name: "SkipHelloRetryRequest",
7999 config: Config{
8000 MaxVersion: VersionTLS13,
8001 // P-384 requires HelloRetryRequest in BoringSSL.
8002 CurvePreferences: []CurveID{CurveP384},
8003 Bugs: ProtocolBugs{
8004 SkipHelloRetryRequest: true,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedError: ":WRONG_CURVE:",
8009 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008010
8011 testCases = append(testCases, testCase{
8012 name: "TLS13-RequestContextInHandshake",
8013 config: Config{
8014 MaxVersion: VersionTLS13,
8015 MinVersion: VersionTLS13,
8016 ClientAuth: RequireAnyClientCert,
8017 Bugs: ProtocolBugs{
8018 SendRequestContext: []byte("request context"),
8019 },
8020 },
8021 flags: []string{
8022 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8023 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8024 },
8025 shouldFail: true,
8026 expectedError: ":DECODE_ERROR:",
8027 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008028}
8029
Adam Langley7c803a62015-06-15 15:35:05 -07008030func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008031 defer wg.Done()
8032
8033 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008034 var err error
8035
8036 if *mallocTest < 0 {
8037 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008038 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008039 } else {
8040 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8041 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008042 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008043 if err != nil {
8044 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8045 }
8046 break
8047 }
8048 }
8049 }
Adam Langley95c29f32014-06-20 12:00:00 -07008050 statusChan <- statusMsg{test: test, err: err}
8051 }
8052}
8053
8054type statusMsg struct {
8055 test *testCase
8056 started bool
8057 err error
8058}
8059
David Benjamin5f237bc2015-02-11 17:14:15 -05008060func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008061 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008062
David Benjamin5f237bc2015-02-11 17:14:15 -05008063 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008064 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008065 if !*pipe {
8066 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008067 var erase string
8068 for i := 0; i < lineLen; i++ {
8069 erase += "\b \b"
8070 }
8071 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008072 }
8073
Adam Langley95c29f32014-06-20 12:00:00 -07008074 if msg.started {
8075 started++
8076 } else {
8077 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008078
8079 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008080 if msg.err == errUnimplemented {
8081 if *pipe {
8082 // Print each test instead of a status line.
8083 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8084 }
8085 unimplemented++
8086 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8087 } else {
8088 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8089 failed++
8090 testOutput.addResult(msg.test.name, "FAIL")
8091 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008092 } else {
8093 if *pipe {
8094 // Print each test instead of a status line.
8095 fmt.Printf("PASSED (%s)\n", msg.test.name)
8096 }
8097 testOutput.addResult(msg.test.name, "PASS")
8098 }
Adam Langley95c29f32014-06-20 12:00:00 -07008099 }
8100
David Benjamin5f237bc2015-02-11 17:14:15 -05008101 if !*pipe {
8102 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008103 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008104 lineLen = len(line)
8105 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008106 }
Adam Langley95c29f32014-06-20 12:00:00 -07008107 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008108
8109 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008110}
8111
8112func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008113 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008114 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008115 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008116
Adam Langley7c803a62015-06-15 15:35:05 -07008117 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008118 addCipherSuiteTests()
8119 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008120 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008121 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008122 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008123 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008124 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008125 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008126 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008127 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008128 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008129 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008130 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008131 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008132 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008133 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008134 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008135 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008136 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008137 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008138 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008139 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008140 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008141 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008142 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008143 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008144 addTLS13WrongMessageTypeTests()
8145 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008146
8147 var wg sync.WaitGroup
8148
Adam Langley7c803a62015-06-15 15:35:05 -07008149 statusChan := make(chan statusMsg, *numWorkers)
8150 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008151 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008152
EKRf71d7ed2016-08-06 13:25:12 -07008153 if len(*shimConfigFile) != 0 {
8154 encoded, err := ioutil.ReadFile(*shimConfigFile)
8155 if err != nil {
8156 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8157 os.Exit(1)
8158 }
8159
8160 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8161 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8162 os.Exit(1)
8163 }
8164 }
8165
David Benjamin025b3d32014-07-01 19:53:04 -04008166 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008167
Adam Langley7c803a62015-06-15 15:35:05 -07008168 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008169 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008170 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008171 }
8172
David Benjamin270f0a72016-03-17 14:41:36 -04008173 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008174 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008175 matched := true
8176 if len(*testToRun) != 0 {
8177 var err error
8178 matched, err = filepath.Match(*testToRun, testCases[i].name)
8179 if err != nil {
8180 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8181 os.Exit(1)
8182 }
8183 }
8184
EKRf71d7ed2016-08-06 13:25:12 -07008185 if !*includeDisabled {
8186 for pattern := range shimConfig.DisabledTests {
8187 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8188 if err != nil {
8189 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8190 os.Exit(1)
8191 }
8192
8193 if isDisabled {
8194 matched = false
8195 break
8196 }
8197 }
8198 }
8199
David Benjamin17e12922016-07-28 18:04:43 -04008200 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008201 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008202 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008203 }
8204 }
David Benjamin17e12922016-07-28 18:04:43 -04008205
David Benjamin270f0a72016-03-17 14:41:36 -04008206 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008207 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008208 os.Exit(1)
8209 }
Adam Langley95c29f32014-06-20 12:00:00 -07008210
8211 close(testChan)
8212 wg.Wait()
8213 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008214 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008215
8216 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008217
8218 if *jsonOutput != "" {
8219 if err := testOutput.writeTo(*jsonOutput); err != nil {
8220 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8221 }
8222 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008223
EKR842ae6c2016-07-27 09:22:05 +02008224 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8225 os.Exit(1)
8226 }
8227
8228 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008229 os.Exit(1)
8230 }
Adam Langley95c29f32014-06-20 12:00:00 -07008231}