blob: 3e4ba2e8c74d174a81ff407c6a3851371de3be52 [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 }
Adam Langley37646832016-08-01 16:16:46 -07002733
2734 testCases = append(testCases, testCase{
2735 name: "NoClientCertificate-" + ver.name,
2736 config: Config{
2737 MinVersion: ver.version,
2738 MaxVersion: ver.version,
2739 ClientAuth: RequireAnyClientCert,
2740 },
2741 shouldFail: true,
2742 expectedLocalError: "client didn't provide a certificate",
2743 })
2744
2745 testCases = append(testCases, testCase{
2746 // Even if not configured to expect a certificate, OpenSSL will
2747 // return X509_V_OK as the verify_result.
2748 testType: serverTest,
2749 name: "NoClientCertificateRequested-Server-" + ver.name,
2750 config: Config{
2751 MinVersion: ver.version,
2752 MaxVersion: ver.version,
2753 },
2754 flags: []string{
2755 "-expect-verify-result",
2756 },
2757 // TODO(davidben): Switch this to true when TLS 1.3
2758 // supports session resumption.
2759 resumeSession: ver.version < VersionTLS13,
2760 })
2761
2762 testCases = append(testCases, testCase{
2763 // If a client certificate is not provided, OpenSSL will still
2764 // return X509_V_OK as the verify_result.
2765 testType: serverTest,
2766 name: "NoClientCertificate-Server-" + ver.name,
2767 config: Config{
2768 MinVersion: ver.version,
2769 MaxVersion: ver.version,
2770 },
2771 flags: []string{
2772 "-expect-verify-result",
2773 "-verify-peer",
2774 },
2775 // TODO(davidben): Switch this to true when TLS 1.3
2776 // supports session resumption.
2777 resumeSession: ver.version < VersionTLS13,
2778 })
2779
2780 testCases = append(testCases, testCase{
2781 testType: serverTest,
2782 name: "RequireAnyClientCertificate-" + ver.name,
2783 config: Config{
2784 MinVersion: ver.version,
2785 MaxVersion: ver.version,
2786 },
2787 flags: []string{"-require-any-client-certificate"},
2788 shouldFail: true,
2789 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2790 })
2791
2792 if ver.version != VersionSSL30 {
2793 testCases = append(testCases, testCase{
2794 testType: serverTest,
2795 name: "SkipClientCertificate-" + ver.name,
2796 config: Config{
2797 MinVersion: ver.version,
2798 MaxVersion: ver.version,
2799 Bugs: ProtocolBugs{
2800 SkipClientCertificate: true,
2801 },
2802 },
2803 // Setting SSL_VERIFY_PEER allows anonymous clients.
2804 flags: []string{"-verify-peer"},
2805 shouldFail: true,
2806 expectedError: ":UNEXPECTED_MESSAGE:",
2807 })
2808 }
David Benjamin636293b2014-07-08 17:59:18 -04002809 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002810
David Benjaminc032dfa2016-05-12 14:54:57 -04002811 // Client auth is only legal in certificate-based ciphers.
2812 testCases = append(testCases, testCase{
2813 testType: clientTest,
2814 name: "ClientAuth-PSK",
2815 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002816 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002817 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2818 PreSharedKey: []byte("secret"),
2819 ClientAuth: RequireAnyClientCert,
2820 },
2821 flags: []string{
2822 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2823 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2824 "-psk", "secret",
2825 },
2826 shouldFail: true,
2827 expectedError: ":UNEXPECTED_MESSAGE:",
2828 })
2829 testCases = append(testCases, testCase{
2830 testType: clientTest,
2831 name: "ClientAuth-ECDHE_PSK",
2832 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002833 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002834 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2835 PreSharedKey: []byte("secret"),
2836 ClientAuth: RequireAnyClientCert,
2837 },
2838 flags: []string{
2839 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2840 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2841 "-psk", "secret",
2842 },
2843 shouldFail: true,
2844 expectedError: ":UNEXPECTED_MESSAGE:",
2845 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002846
2847 // Regression test for a bug where the client CA list, if explicitly
2848 // set to NULL, was mis-encoded.
2849 testCases = append(testCases, testCase{
2850 testType: serverTest,
2851 name: "Null-Client-CA-List",
2852 config: Config{
2853 MaxVersion: VersionTLS12,
2854 Certificates: []Certificate{rsaCertificate},
2855 },
2856 flags: []string{
2857 "-require-any-client-certificate",
2858 "-use-null-client-ca-list",
2859 },
2860 })
David Benjamin636293b2014-07-08 17:59:18 -04002861}
2862
Adam Langley75712922014-10-10 16:23:43 -07002863func addExtendedMasterSecretTests() {
2864 const expectEMSFlag = "-expect-extended-master-secret"
2865
2866 for _, with := range []bool{false, true} {
2867 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002868 if with {
2869 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002870 }
2871
2872 for _, isClient := range []bool{false, true} {
2873 suffix := "-Server"
2874 testType := serverTest
2875 if isClient {
2876 suffix = "-Client"
2877 testType = clientTest
2878 }
2879
2880 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002881 // In TLS 1.3, the extension is irrelevant and
2882 // always reports as enabled.
2883 var flags []string
2884 if with || ver.version >= VersionTLS13 {
2885 flags = []string{expectEMSFlag}
2886 }
2887
Adam Langley75712922014-10-10 16:23:43 -07002888 test := testCase{
2889 testType: testType,
2890 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2891 config: Config{
2892 MinVersion: ver.version,
2893 MaxVersion: ver.version,
2894 Bugs: ProtocolBugs{
2895 NoExtendedMasterSecret: !with,
2896 RequireExtendedMasterSecret: with,
2897 },
2898 },
David Benjamin48cae082014-10-27 01:06:24 -04002899 flags: flags,
2900 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002901 }
2902 if test.shouldFail {
2903 test.expectedLocalError = "extended master secret required but not supported by peer"
2904 }
2905 testCases = append(testCases, test)
2906 }
2907 }
2908 }
2909
Adam Langleyba5934b2015-06-02 10:50:35 -07002910 for _, isClient := range []bool{false, true} {
2911 for _, supportedInFirstConnection := range []bool{false, true} {
2912 for _, supportedInResumeConnection := range []bool{false, true} {
2913 boolToWord := func(b bool) string {
2914 if b {
2915 return "Yes"
2916 }
2917 return "No"
2918 }
2919 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2920 if isClient {
2921 suffix += "Client"
2922 } else {
2923 suffix += "Server"
2924 }
2925
2926 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002927 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002928 Bugs: ProtocolBugs{
2929 RequireExtendedMasterSecret: true,
2930 },
2931 }
2932
2933 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002935 Bugs: ProtocolBugs{
2936 NoExtendedMasterSecret: true,
2937 },
2938 }
2939
2940 test := testCase{
2941 name: "ExtendedMasterSecret-" + suffix,
2942 resumeSession: true,
2943 }
2944
2945 if !isClient {
2946 test.testType = serverTest
2947 }
2948
2949 if supportedInFirstConnection {
2950 test.config = supportedConfig
2951 } else {
2952 test.config = noSupportConfig
2953 }
2954
2955 if supportedInResumeConnection {
2956 test.resumeConfig = &supportedConfig
2957 } else {
2958 test.resumeConfig = &noSupportConfig
2959 }
2960
2961 switch suffix {
2962 case "YesToYes-Client", "YesToYes-Server":
2963 // When a session is resumed, it should
2964 // still be aware that its master
2965 // secret was generated via EMS and
2966 // thus it's safe to use tls-unique.
2967 test.flags = []string{expectEMSFlag}
2968 case "NoToYes-Server":
2969 // If an original connection did not
2970 // contain EMS, but a resumption
2971 // handshake does, then a server should
2972 // not resume the session.
2973 test.expectResumeRejected = true
2974 case "YesToNo-Server":
2975 // Resuming an EMS session without the
2976 // EMS extension should cause the
2977 // server to abort the connection.
2978 test.shouldFail = true
2979 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2980 case "NoToYes-Client":
2981 // A client should abort a connection
2982 // where the server resumed a non-EMS
2983 // session but echoed the EMS
2984 // extension.
2985 test.shouldFail = true
2986 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2987 case "YesToNo-Client":
2988 // A client should abort a connection
2989 // where the server didn't echo EMS
2990 // when the session used it.
2991 test.shouldFail = true
2992 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2993 }
2994
2995 testCases = append(testCases, test)
2996 }
2997 }
2998 }
Adam Langley75712922014-10-10 16:23:43 -07002999}
3000
David Benjamin582ba042016-07-07 12:33:25 -07003001type stateMachineTestConfig struct {
3002 protocol protocol
3003 async bool
3004 splitHandshake, packHandshakeFlight bool
3005}
3006
David Benjamin43ec06f2014-08-05 02:28:57 -04003007// Adds tests that try to cover the range of the handshake state machine, under
3008// various conditions. Some of these are redundant with other tests, but they
3009// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003010func addAllStateMachineCoverageTests() {
3011 for _, async := range []bool{false, true} {
3012 for _, protocol := range []protocol{tls, dtls} {
3013 addStateMachineCoverageTests(stateMachineTestConfig{
3014 protocol: protocol,
3015 async: async,
3016 })
3017 addStateMachineCoverageTests(stateMachineTestConfig{
3018 protocol: protocol,
3019 async: async,
3020 splitHandshake: true,
3021 })
3022 if protocol == tls {
3023 addStateMachineCoverageTests(stateMachineTestConfig{
3024 protocol: protocol,
3025 async: async,
3026 packHandshakeFlight: true,
3027 })
3028 }
3029 }
3030 }
3031}
3032
3033func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003034 var tests []testCase
3035
3036 // Basic handshake, with resumption. Client and server,
3037 // session ID and session ticket.
3038 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003039 name: "Basic-Client",
3040 config: Config{
3041 MaxVersion: VersionTLS12,
3042 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003044 // Ensure session tickets are used, not session IDs.
3045 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003046 })
3047 tests = append(tests, testCase{
3048 name: "Basic-Client-RenewTicket",
3049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003051 Bugs: ProtocolBugs{
3052 RenewTicketOnResume: true,
3053 },
3054 },
David Benjaminba4594a2015-06-18 18:36:15 -04003055 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003056 resumeSession: true,
3057 })
3058 tests = append(tests, testCase{
3059 name: "Basic-Client-NoTicket",
3060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003061 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003062 SessionTicketsDisabled: true,
3063 },
3064 resumeSession: true,
3065 })
3066 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 name: "Basic-Client-Implicit",
3068 config: Config{
3069 MaxVersion: VersionTLS12,
3070 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003071 flags: []string{"-implicit-handshake"},
3072 resumeSession: true,
3073 })
3074 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003075 testType: serverTest,
3076 name: "Basic-Server",
3077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003078 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003079 Bugs: ProtocolBugs{
3080 RequireSessionTickets: true,
3081 },
3082 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003083 resumeSession: true,
3084 })
3085 tests = append(tests, testCase{
3086 testType: serverTest,
3087 name: "Basic-Server-NoTickets",
3088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003089 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 SessionTicketsDisabled: true,
3091 },
3092 resumeSession: true,
3093 })
3094 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003095 testType: serverTest,
3096 name: "Basic-Server-Implicit",
3097 config: Config{
3098 MaxVersion: VersionTLS12,
3099 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003100 flags: []string{"-implicit-handshake"},
3101 resumeSession: true,
3102 })
3103 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003104 testType: serverTest,
3105 name: "Basic-Server-EarlyCallback",
3106 config: Config{
3107 MaxVersion: VersionTLS12,
3108 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003109 flags: []string{"-use-early-callback"},
3110 resumeSession: true,
3111 })
3112
Steven Valdez143e8b32016-07-11 13:19:03 -04003113 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003114 if config.protocol == tls {
3115 tests = append(tests, testCase{
3116 name: "TLS13-1RTT-Client",
3117 config: Config{
3118 MaxVersion: VersionTLS13,
3119 MinVersion: VersionTLS13,
3120 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003121 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003122 })
3123
3124 tests = append(tests, testCase{
3125 testType: serverTest,
3126 name: "TLS13-1RTT-Server",
3127 config: Config{
3128 MaxVersion: VersionTLS13,
3129 MinVersion: VersionTLS13,
3130 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003131 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003132 })
3133
3134 tests = append(tests, testCase{
3135 name: "TLS13-HelloRetryRequest-Client",
3136 config: Config{
3137 MaxVersion: VersionTLS13,
3138 MinVersion: VersionTLS13,
3139 // P-384 requires a HelloRetryRequest against
3140 // BoringSSL's default configuration. Assert
3141 // that we do indeed test this with
3142 // ExpectMissingKeyShare.
3143 CurvePreferences: []CurveID{CurveP384},
3144 Bugs: ProtocolBugs{
3145 ExpectMissingKeyShare: true,
3146 },
3147 },
3148 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3149 resumeSession: true,
3150 })
3151
3152 tests = append(tests, testCase{
3153 testType: serverTest,
3154 name: "TLS13-HelloRetryRequest-Server",
3155 config: Config{
3156 MaxVersion: VersionTLS13,
3157 MinVersion: VersionTLS13,
3158 // Require a HelloRetryRequest for every curve.
3159 DefaultCurves: []CurveID{},
3160 },
3161 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3162 resumeSession: true,
3163 })
3164 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003165
David Benjamin760b1dd2015-05-15 23:33:48 -04003166 // TLS client auth.
3167 tests = append(tests, testCase{
3168 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003169 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003171 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003172 ClientAuth: RequestClientCert,
3173 },
3174 })
3175 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003176 testType: serverTest,
3177 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003178 config: Config{
3179 MaxVersion: VersionTLS12,
3180 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003181 // Setting SSL_VERIFY_PEER allows anonymous clients.
3182 flags: []string{"-verify-peer"},
3183 })
David Benjamin582ba042016-07-07 12:33:25 -07003184 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003185 tests = append(tests, testCase{
3186 testType: clientTest,
3187 name: "ClientAuth-NoCertificate-Client-SSL3",
3188 config: Config{
3189 MaxVersion: VersionSSL30,
3190 ClientAuth: RequestClientCert,
3191 },
3192 })
3193 tests = append(tests, testCase{
3194 testType: serverTest,
3195 name: "ClientAuth-NoCertificate-Server-SSL3",
3196 config: Config{
3197 MaxVersion: VersionSSL30,
3198 },
3199 // Setting SSL_VERIFY_PEER allows anonymous clients.
3200 flags: []string{"-verify-peer"},
3201 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003202 tests = append(tests, testCase{
3203 testType: clientTest,
3204 name: "ClientAuth-NoCertificate-Client-TLS13",
3205 config: Config{
3206 MaxVersion: VersionTLS13,
3207 ClientAuth: RequestClientCert,
3208 },
3209 })
3210 tests = append(tests, testCase{
3211 testType: serverTest,
3212 name: "ClientAuth-NoCertificate-Server-TLS13",
3213 config: Config{
3214 MaxVersion: VersionTLS13,
3215 },
3216 // Setting SSL_VERIFY_PEER allows anonymous clients.
3217 flags: []string{"-verify-peer"},
3218 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003219 }
3220 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003221 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003222 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003224 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 ClientAuth: RequireAnyClientCert,
3226 },
3227 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003228 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3229 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 },
3231 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003232 tests = append(tests, testCase{
3233 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003234 name: "ClientAuth-RSA-Client-TLS13",
3235 config: Config{
3236 MaxVersion: VersionTLS13,
3237 ClientAuth: RequireAnyClientCert,
3238 },
3239 flags: []string{
3240 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3241 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3242 },
3243 })
3244 tests = append(tests, testCase{
3245 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003246 name: "ClientAuth-ECDSA-Client",
3247 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003248 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003249 ClientAuth: RequireAnyClientCert,
3250 },
3251 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003252 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3253 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003254 },
3255 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003256 tests = append(tests, testCase{
3257 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003258 name: "ClientAuth-ECDSA-Client-TLS13",
3259 config: Config{
3260 MaxVersion: VersionTLS13,
3261 ClientAuth: RequireAnyClientCert,
3262 },
3263 flags: []string{
3264 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3265 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3266 },
3267 })
3268 tests = append(tests, testCase{
3269 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003270 name: "ClientAuth-NoCertificate-OldCallback",
3271 config: Config{
3272 MaxVersion: VersionTLS12,
3273 ClientAuth: RequestClientCert,
3274 },
3275 flags: []string{"-use-old-client-cert-callback"},
3276 })
3277 tests = append(tests, testCase{
3278 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003279 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3280 config: Config{
3281 MaxVersion: VersionTLS13,
3282 ClientAuth: RequestClientCert,
3283 },
3284 flags: []string{"-use-old-client-cert-callback"},
3285 })
3286 tests = append(tests, testCase{
3287 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003288 name: "ClientAuth-OldCallback",
3289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003291 ClientAuth: RequireAnyClientCert,
3292 },
3293 flags: []string{
3294 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3295 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3296 "-use-old-client-cert-callback",
3297 },
3298 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003299 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003300 testType: clientTest,
3301 name: "ClientAuth-OldCallback-TLS13",
3302 config: Config{
3303 MaxVersion: VersionTLS13,
3304 ClientAuth: RequireAnyClientCert,
3305 },
3306 flags: []string{
3307 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3308 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3309 "-use-old-client-cert-callback",
3310 },
3311 })
3312 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003313 testType: serverTest,
3314 name: "ClientAuth-Server",
3315 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003316 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003317 Certificates: []Certificate{rsaCertificate},
3318 },
3319 flags: []string{"-require-any-client-certificate"},
3320 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003321 tests = append(tests, testCase{
3322 testType: serverTest,
3323 name: "ClientAuth-Server-TLS13",
3324 config: Config{
3325 MaxVersion: VersionTLS13,
3326 Certificates: []Certificate{rsaCertificate},
3327 },
3328 flags: []string{"-require-any-client-certificate"},
3329 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003330
David Benjamin4c3ddf72016-06-29 18:13:53 -04003331 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003332 tests = append(tests, testCase{
3333 testType: serverTest,
3334 name: "Basic-Server-RSA",
3335 config: Config{
3336 MaxVersion: VersionTLS12,
3337 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3338 },
3339 flags: []string{
3340 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3341 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3342 },
3343 })
3344 tests = append(tests, testCase{
3345 testType: serverTest,
3346 name: "Basic-Server-ECDHE-RSA",
3347 config: Config{
3348 MaxVersion: VersionTLS12,
3349 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3350 },
3351 flags: []string{
3352 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3353 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3354 },
3355 })
3356 tests = append(tests, testCase{
3357 testType: serverTest,
3358 name: "Basic-Server-ECDHE-ECDSA",
3359 config: Config{
3360 MaxVersion: VersionTLS12,
3361 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3362 },
3363 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003364 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3365 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003366 },
3367 })
3368
David Benjamin760b1dd2015-05-15 23:33:48 -04003369 // No session ticket support; server doesn't send NewSessionTicket.
3370 tests = append(tests, testCase{
3371 name: "SessionTicketsDisabled-Client",
3372 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003373 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003374 SessionTicketsDisabled: true,
3375 },
3376 })
3377 tests = append(tests, testCase{
3378 testType: serverTest,
3379 name: "SessionTicketsDisabled-Server",
3380 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003381 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003382 SessionTicketsDisabled: true,
3383 },
3384 })
3385
3386 // Skip ServerKeyExchange in PSK key exchange if there's no
3387 // identity hint.
3388 tests = append(tests, testCase{
3389 name: "EmptyPSKHint-Client",
3390 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003391 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003392 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3393 PreSharedKey: []byte("secret"),
3394 },
3395 flags: []string{"-psk", "secret"},
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "EmptyPSKHint-Server",
3400 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003401 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3403 PreSharedKey: []byte("secret"),
3404 },
3405 flags: []string{"-psk", "secret"},
3406 })
3407
David Benjamin4c3ddf72016-06-29 18:13:53 -04003408 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003409 tests = append(tests, testCase{
3410 testType: clientTest,
3411 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003412 config: Config{
3413 MaxVersion: VersionTLS12,
3414 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003415 flags: []string{
3416 "-enable-ocsp-stapling",
3417 "-expect-ocsp-response",
3418 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003419 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003420 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003421 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003422 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003423 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 testType: serverTest,
3425 name: "OCSPStapling-Server",
3426 config: Config{
3427 MaxVersion: VersionTLS12,
3428 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003429 expectedOCSPResponse: testOCSPResponse,
3430 flags: []string{
3431 "-ocsp-response",
3432 base64.StdEncoding.EncodeToString(testOCSPResponse),
3433 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003434 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003435 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003436 tests = append(tests, testCase{
3437 testType: clientTest,
3438 name: "OCSPStapling-Client-TLS13",
3439 config: Config{
3440 MaxVersion: VersionTLS13,
3441 },
3442 flags: []string{
3443 "-enable-ocsp-stapling",
3444 "-expect-ocsp-response",
3445 base64.StdEncoding.EncodeToString(testOCSPResponse),
3446 "-verify-peer",
3447 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003448 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003449 })
3450 tests = append(tests, testCase{
3451 testType: serverTest,
3452 name: "OCSPStapling-Server-TLS13",
3453 config: Config{
3454 MaxVersion: VersionTLS13,
3455 },
3456 expectedOCSPResponse: testOCSPResponse,
3457 flags: []string{
3458 "-ocsp-response",
3459 base64.StdEncoding.EncodeToString(testOCSPResponse),
3460 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003461 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003462 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003463
David Benjamin4c3ddf72016-06-29 18:13:53 -04003464 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003465 for _, vers := range tlsVersions {
3466 if config.protocol == dtls && !vers.hasDTLS {
3467 continue
3468 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003469 for _, testType := range []testType{clientTest, serverTest} {
3470 suffix := "-Client"
3471 if testType == serverTest {
3472 suffix = "-Server"
3473 }
3474 suffix += "-" + vers.name
3475
3476 flag := "-verify-peer"
3477 if testType == serverTest {
3478 flag = "-require-any-client-certificate"
3479 }
3480
3481 tests = append(tests, testCase{
3482 testType: testType,
3483 name: "CertificateVerificationSucceed" + suffix,
3484 config: Config{
3485 MaxVersion: vers.version,
3486 Certificates: []Certificate{rsaCertificate},
3487 },
3488 flags: []string{
3489 flag,
3490 "-expect-verify-result",
3491 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003492 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003493 })
3494 tests = append(tests, testCase{
3495 testType: testType,
3496 name: "CertificateVerificationFail" + suffix,
3497 config: Config{
3498 MaxVersion: vers.version,
3499 Certificates: []Certificate{rsaCertificate},
3500 },
3501 flags: []string{
3502 flag,
3503 "-verify-fail",
3504 },
3505 shouldFail: true,
3506 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3507 })
3508 }
3509
3510 // By default, the client is in a soft fail mode where the peer
3511 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003512 tests = append(tests, testCase{
3513 testType: clientTest,
3514 name: "CertificateVerificationSoftFail-" + vers.name,
3515 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003516 MaxVersion: vers.version,
3517 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003518 },
3519 flags: []string{
3520 "-verify-fail",
3521 "-expect-verify-result",
3522 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003523 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003524 })
3525 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003526
David Benjamin1d4f4c02016-07-26 18:03:08 -04003527 tests = append(tests, testCase{
3528 name: "ShimSendAlert",
3529 flags: []string{"-send-alert"},
3530 shimWritesFirst: true,
3531 shouldFail: true,
3532 expectedLocalError: "remote error: decompression failure",
3533 })
3534
David Benjamin582ba042016-07-07 12:33:25 -07003535 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003536 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003537 name: "Renegotiate-Client",
3538 config: Config{
3539 MaxVersion: VersionTLS12,
3540 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003541 renegotiate: 1,
3542 flags: []string{
3543 "-renegotiate-freely",
3544 "-expect-total-renegotiations", "1",
3545 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003546 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003547
David Benjamin47921102016-07-28 11:29:18 -04003548 tests = append(tests, testCase{
3549 name: "SendHalfHelloRequest",
3550 config: Config{
3551 MaxVersion: VersionTLS12,
3552 Bugs: ProtocolBugs{
3553 PackHelloRequestWithFinished: config.packHandshakeFlight,
3554 },
3555 },
3556 sendHalfHelloRequest: true,
3557 flags: []string{"-renegotiate-ignore"},
3558 shouldFail: true,
3559 expectedError: ":UNEXPECTED_RECORD:",
3560 })
3561
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 // NPN on client and server; results in post-handshake message.
3563 tests = append(tests, testCase{
3564 name: "NPN-Client",
3565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003566 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003567 NextProtos: []string{"foo"},
3568 },
3569 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003570 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003571 expectedNextProto: "foo",
3572 expectedNextProtoType: npn,
3573 })
3574 tests = append(tests, testCase{
3575 testType: serverTest,
3576 name: "NPN-Server",
3577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003579 NextProtos: []string{"bar"},
3580 },
3581 flags: []string{
3582 "-advertise-npn", "\x03foo\x03bar\x03baz",
3583 "-expect-next-proto", "bar",
3584 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003585 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 expectedNextProto: "bar",
3587 expectedNextProtoType: npn,
3588 })
3589
3590 // TODO(davidben): Add tests for when False Start doesn't trigger.
3591
3592 // Client does False Start and negotiates NPN.
3593 tests = append(tests, testCase{
3594 name: "FalseStart",
3595 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003596 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003597 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3598 NextProtos: []string{"foo"},
3599 Bugs: ProtocolBugs{
3600 ExpectFalseStart: true,
3601 },
3602 },
3603 flags: []string{
3604 "-false-start",
3605 "-select-next-proto", "foo",
3606 },
3607 shimWritesFirst: true,
3608 resumeSession: true,
3609 })
3610
3611 // Client does False Start and negotiates ALPN.
3612 tests = append(tests, testCase{
3613 name: "FalseStart-ALPN",
3614 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003615 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003616 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3617 NextProtos: []string{"foo"},
3618 Bugs: ProtocolBugs{
3619 ExpectFalseStart: true,
3620 },
3621 },
3622 flags: []string{
3623 "-false-start",
3624 "-advertise-alpn", "\x03foo",
3625 },
3626 shimWritesFirst: true,
3627 resumeSession: true,
3628 })
3629
3630 // Client does False Start but doesn't explicitly call
3631 // SSL_connect.
3632 tests = append(tests, testCase{
3633 name: "FalseStart-Implicit",
3634 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003635 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003636 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3637 NextProtos: []string{"foo"},
3638 },
3639 flags: []string{
3640 "-implicit-handshake",
3641 "-false-start",
3642 "-advertise-alpn", "\x03foo",
3643 },
3644 })
3645
3646 // False Start without session tickets.
3647 tests = append(tests, testCase{
3648 name: "FalseStart-SessionTicketsDisabled",
3649 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003650 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3652 NextProtos: []string{"foo"},
3653 SessionTicketsDisabled: true,
3654 Bugs: ProtocolBugs{
3655 ExpectFalseStart: true,
3656 },
3657 },
3658 flags: []string{
3659 "-false-start",
3660 "-select-next-proto", "foo",
3661 },
3662 shimWritesFirst: true,
3663 })
3664
Adam Langleydf759b52016-07-11 15:24:37 -07003665 tests = append(tests, testCase{
3666 name: "FalseStart-CECPQ1",
3667 config: Config{
3668 MaxVersion: VersionTLS12,
3669 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3670 NextProtos: []string{"foo"},
3671 Bugs: ProtocolBugs{
3672 ExpectFalseStart: true,
3673 },
3674 },
3675 flags: []string{
3676 "-false-start",
3677 "-cipher", "DEFAULT:kCECPQ1",
3678 "-select-next-proto", "foo",
3679 },
3680 shimWritesFirst: true,
3681 resumeSession: true,
3682 })
3683
David Benjamin760b1dd2015-05-15 23:33:48 -04003684 // Server parses a V2ClientHello.
3685 tests = append(tests, testCase{
3686 testType: serverTest,
3687 name: "SendV2ClientHello",
3688 config: Config{
3689 // Choose a cipher suite that does not involve
3690 // elliptic curves, so no extensions are
3691 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003692 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003693 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3694 Bugs: ProtocolBugs{
3695 SendV2ClientHello: true,
3696 },
3697 },
3698 })
3699
3700 // Client sends a Channel ID.
3701 tests = append(tests, testCase{
3702 name: "ChannelID-Client",
3703 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003704 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003705 RequestChannelID: true,
3706 },
Adam Langley7c803a62015-06-15 15:35:05 -07003707 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003708 resumeSession: true,
3709 expectChannelID: true,
3710 })
3711
3712 // Server accepts a Channel ID.
3713 tests = append(tests, testCase{
3714 testType: serverTest,
3715 name: "ChannelID-Server",
3716 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717 MaxVersion: VersionTLS12,
3718 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003719 },
3720 flags: []string{
3721 "-expect-channel-id",
3722 base64.StdEncoding.EncodeToString(channelIDBytes),
3723 },
3724 resumeSession: true,
3725 expectChannelID: true,
3726 })
David Benjamin30789da2015-08-29 22:56:45 -04003727
David Benjaminf8fcdf32016-06-08 15:56:13 -04003728 // Channel ID and NPN at the same time, to ensure their relative
3729 // ordering is correct.
3730 tests = append(tests, testCase{
3731 name: "ChannelID-NPN-Client",
3732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003733 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003734 RequestChannelID: true,
3735 NextProtos: []string{"foo"},
3736 },
3737 flags: []string{
3738 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3739 "-select-next-proto", "foo",
3740 },
3741 resumeSession: true,
3742 expectChannelID: true,
3743 expectedNextProto: "foo",
3744 expectedNextProtoType: npn,
3745 })
3746 tests = append(tests, testCase{
3747 testType: serverTest,
3748 name: "ChannelID-NPN-Server",
3749 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003750 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003751 ChannelID: channelIDKey,
3752 NextProtos: []string{"bar"},
3753 },
3754 flags: []string{
3755 "-expect-channel-id",
3756 base64.StdEncoding.EncodeToString(channelIDBytes),
3757 "-advertise-npn", "\x03foo\x03bar\x03baz",
3758 "-expect-next-proto", "bar",
3759 },
3760 resumeSession: true,
3761 expectChannelID: true,
3762 expectedNextProto: "bar",
3763 expectedNextProtoType: npn,
3764 })
3765
David Benjamin30789da2015-08-29 22:56:45 -04003766 // Bidirectional shutdown with the runner initiating.
3767 tests = append(tests, testCase{
3768 name: "Shutdown-Runner",
3769 config: Config{
3770 Bugs: ProtocolBugs{
3771 ExpectCloseNotify: true,
3772 },
3773 },
3774 flags: []string{"-check-close-notify"},
3775 })
3776
3777 // Bidirectional shutdown with the shim initiating. The runner,
3778 // in the meantime, sends garbage before the close_notify which
3779 // the shim must ignore.
3780 tests = append(tests, testCase{
3781 name: "Shutdown-Shim",
3782 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003783 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003784 Bugs: ProtocolBugs{
3785 ExpectCloseNotify: true,
3786 },
3787 },
3788 shimShutsDown: true,
3789 sendEmptyRecords: 1,
3790 sendWarningAlerts: 1,
3791 flags: []string{"-check-close-notify"},
3792 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003793 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003794 // TODO(davidben): DTLS 1.3 will want a similar thing for
3795 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003796 tests = append(tests, testCase{
3797 name: "SkipHelloVerifyRequest",
3798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003799 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003800 Bugs: ProtocolBugs{
3801 SkipHelloVerifyRequest: true,
3802 },
3803 },
3804 })
3805 }
3806
David Benjamin760b1dd2015-05-15 23:33:48 -04003807 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003808 test.protocol = config.protocol
3809 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003810 test.name += "-DTLS"
3811 }
David Benjamin582ba042016-07-07 12:33:25 -07003812 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003813 test.name += "-Async"
3814 test.flags = append(test.flags, "-async")
3815 } else {
3816 test.name += "-Sync"
3817 }
David Benjamin582ba042016-07-07 12:33:25 -07003818 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003819 test.name += "-SplitHandshakeRecords"
3820 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003821 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003822 test.config.Bugs.MaxPacketLength = 256
3823 test.flags = append(test.flags, "-mtu", "256")
3824 }
3825 }
David Benjamin582ba042016-07-07 12:33:25 -07003826 if config.packHandshakeFlight {
3827 test.name += "-PackHandshakeFlight"
3828 test.config.Bugs.PackHandshakeFlight = true
3829 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003830 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003831 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003832}
3833
Adam Langley524e7172015-02-20 16:04:00 -08003834func addDDoSCallbackTests() {
3835 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003836 for _, resume := range []bool{false, true} {
3837 suffix := "Resume"
3838 if resume {
3839 suffix = "No" + suffix
3840 }
3841
3842 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003843 testType: serverTest,
3844 name: "Server-DDoS-OK-" + suffix,
3845 config: Config{
3846 MaxVersion: VersionTLS12,
3847 },
Adam Langley524e7172015-02-20 16:04:00 -08003848 flags: []string{"-install-ddos-callback"},
3849 resumeSession: resume,
3850 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003851 testCases = append(testCases, testCase{
3852 testType: serverTest,
3853 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3854 config: Config{
3855 MaxVersion: VersionTLS13,
3856 },
3857 flags: []string{"-install-ddos-callback"},
3858 resumeSession: resume,
3859 })
Adam Langley524e7172015-02-20 16:04:00 -08003860
3861 failFlag := "-fail-ddos-callback"
3862 if resume {
3863 failFlag = "-fail-second-ddos-callback"
3864 }
3865 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003866 testType: serverTest,
3867 name: "Server-DDoS-Reject-" + suffix,
3868 config: Config{
3869 MaxVersion: VersionTLS12,
3870 },
Adam Langley524e7172015-02-20 16:04:00 -08003871 flags: []string{"-install-ddos-callback", failFlag},
3872 resumeSession: resume,
3873 shouldFail: true,
3874 expectedError: ":CONNECTION_REJECTED:",
3875 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003876 testCases = append(testCases, testCase{
3877 testType: serverTest,
3878 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3879 config: Config{
3880 MaxVersion: VersionTLS13,
3881 },
3882 flags: []string{"-install-ddos-callback", failFlag},
3883 resumeSession: resume,
3884 shouldFail: true,
3885 expectedError: ":CONNECTION_REJECTED:",
3886 })
Adam Langley524e7172015-02-20 16:04:00 -08003887 }
3888}
3889
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003890func addVersionNegotiationTests() {
3891 for i, shimVers := range tlsVersions {
3892 // Assemble flags to disable all newer versions on the shim.
3893 var flags []string
3894 for _, vers := range tlsVersions[i+1:] {
3895 flags = append(flags, vers.flag)
3896 }
3897
3898 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003899 protocols := []protocol{tls}
3900 if runnerVers.hasDTLS && shimVers.hasDTLS {
3901 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003902 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003903 for _, protocol := range protocols {
3904 expectedVersion := shimVers.version
3905 if runnerVers.version < shimVers.version {
3906 expectedVersion = runnerVers.version
3907 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003908
David Benjamin8b8c0062014-11-23 02:47:52 -05003909 suffix := shimVers.name + "-" + runnerVers.name
3910 if protocol == dtls {
3911 suffix += "-DTLS"
3912 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003913
David Benjamin1eb367c2014-12-12 18:17:51 -05003914 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3915
David Benjamin1e29a6b2014-12-10 02:27:24 -05003916 clientVers := shimVers.version
3917 if clientVers > VersionTLS10 {
3918 clientVers = VersionTLS10
3919 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003920 serverVers := expectedVersion
3921 if expectedVersion >= VersionTLS13 {
3922 serverVers = VersionTLS10
3923 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003924 testCases = append(testCases, testCase{
3925 protocol: protocol,
3926 testType: clientTest,
3927 name: "VersionNegotiation-Client-" + suffix,
3928 config: Config{
3929 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003930 Bugs: ProtocolBugs{
3931 ExpectInitialRecordVersion: clientVers,
3932 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003933 },
3934 flags: flags,
3935 expectedVersion: expectedVersion,
3936 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003937 testCases = append(testCases, testCase{
3938 protocol: protocol,
3939 testType: clientTest,
3940 name: "VersionNegotiation-Client2-" + suffix,
3941 config: Config{
3942 MaxVersion: runnerVers.version,
3943 Bugs: ProtocolBugs{
3944 ExpectInitialRecordVersion: clientVers,
3945 },
3946 },
3947 flags: []string{"-max-version", shimVersFlag},
3948 expectedVersion: expectedVersion,
3949 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003950
3951 testCases = append(testCases, testCase{
3952 protocol: protocol,
3953 testType: serverTest,
3954 name: "VersionNegotiation-Server-" + suffix,
3955 config: Config{
3956 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003957 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003958 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003959 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003960 },
3961 flags: flags,
3962 expectedVersion: expectedVersion,
3963 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003964 testCases = append(testCases, testCase{
3965 protocol: protocol,
3966 testType: serverTest,
3967 name: "VersionNegotiation-Server2-" + suffix,
3968 config: Config{
3969 MaxVersion: runnerVers.version,
3970 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003971 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003972 },
3973 },
3974 flags: []string{"-max-version", shimVersFlag},
3975 expectedVersion: expectedVersion,
3976 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003977 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003978 }
3979 }
David Benjamin95c69562016-06-29 18:15:03 -04003980
3981 // Test for version tolerance.
3982 testCases = append(testCases, testCase{
3983 testType: serverTest,
3984 name: "MinorVersionTolerance",
3985 config: Config{
3986 Bugs: ProtocolBugs{
3987 SendClientVersion: 0x03ff,
3988 },
3989 },
3990 expectedVersion: VersionTLS13,
3991 })
3992 testCases = append(testCases, testCase{
3993 testType: serverTest,
3994 name: "MajorVersionTolerance",
3995 config: Config{
3996 Bugs: ProtocolBugs{
3997 SendClientVersion: 0x0400,
3998 },
3999 },
4000 expectedVersion: VersionTLS13,
4001 })
4002 testCases = append(testCases, testCase{
4003 protocol: dtls,
4004 testType: serverTest,
4005 name: "MinorVersionTolerance-DTLS",
4006 config: Config{
4007 Bugs: ProtocolBugs{
4008 SendClientVersion: 0x03ff,
4009 },
4010 },
4011 expectedVersion: VersionTLS12,
4012 })
4013 testCases = append(testCases, testCase{
4014 protocol: dtls,
4015 testType: serverTest,
4016 name: "MajorVersionTolerance-DTLS",
4017 config: Config{
4018 Bugs: ProtocolBugs{
4019 SendClientVersion: 0x0400,
4020 },
4021 },
4022 expectedVersion: VersionTLS12,
4023 })
4024
4025 // Test that versions below 3.0 are rejected.
4026 testCases = append(testCases, testCase{
4027 testType: serverTest,
4028 name: "VersionTooLow",
4029 config: Config{
4030 Bugs: ProtocolBugs{
4031 SendClientVersion: 0x0200,
4032 },
4033 },
4034 shouldFail: true,
4035 expectedError: ":UNSUPPORTED_PROTOCOL:",
4036 })
4037 testCases = append(testCases, testCase{
4038 protocol: dtls,
4039 testType: serverTest,
4040 name: "VersionTooLow-DTLS",
4041 config: Config{
4042 Bugs: ProtocolBugs{
4043 // 0x0201 is the lowest version expressable in
4044 // DTLS.
4045 SendClientVersion: 0x0201,
4046 },
4047 },
4048 shouldFail: true,
4049 expectedError: ":UNSUPPORTED_PROTOCOL:",
4050 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004051
4052 // Test TLS 1.3's downgrade signal.
4053 testCases = append(testCases, testCase{
4054 name: "Downgrade-TLS12-Client",
4055 config: Config{
4056 Bugs: ProtocolBugs{
4057 NegotiateVersion: VersionTLS12,
4058 },
4059 },
4060 shouldFail: true,
4061 expectedError: ":DOWNGRADE_DETECTED:",
4062 })
4063 testCases = append(testCases, testCase{
4064 testType: serverTest,
4065 name: "Downgrade-TLS12-Server",
4066 config: Config{
4067 Bugs: ProtocolBugs{
4068 SendClientVersion: VersionTLS12,
4069 },
4070 },
4071 shouldFail: true,
4072 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4073 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004074
4075 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4076 // behave correctly when both real maximum and fallback versions are
4077 // set.
4078 testCases = append(testCases, testCase{
4079 name: "Downgrade-TLS12-Client-Fallback",
4080 config: Config{
4081 Bugs: ProtocolBugs{
4082 FailIfNotFallbackSCSV: true,
4083 },
4084 },
4085 flags: []string{
4086 "-max-version", strconv.Itoa(VersionTLS13),
4087 "-fallback-version", strconv.Itoa(VersionTLS12),
4088 },
4089 shouldFail: true,
4090 expectedError: ":DOWNGRADE_DETECTED:",
4091 })
4092 testCases = append(testCases, testCase{
4093 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4094 flags: []string{
4095 "-max-version", strconv.Itoa(VersionTLS12),
4096 "-fallback-version", strconv.Itoa(VersionTLS12),
4097 },
4098 })
4099
4100 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4101 // just have such connections fail than risk getting confused because we
4102 // didn't sent the 1.3 ClientHello.)
4103 testCases = append(testCases, testCase{
4104 name: "Downgrade-TLS12-Fallback-CheckVersion",
4105 config: Config{
4106 Bugs: ProtocolBugs{
4107 NegotiateVersion: VersionTLS13,
4108 FailIfNotFallbackSCSV: true,
4109 },
4110 },
4111 flags: []string{
4112 "-max-version", strconv.Itoa(VersionTLS13),
4113 "-fallback-version", strconv.Itoa(VersionTLS12),
4114 },
4115 shouldFail: true,
4116 expectedError: ":UNSUPPORTED_PROTOCOL:",
4117 })
4118
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004119}
4120
David Benjaminaccb4542014-12-12 23:44:33 -05004121func addMinimumVersionTests() {
4122 for i, shimVers := range tlsVersions {
4123 // Assemble flags to disable all older versions on the shim.
4124 var flags []string
4125 for _, vers := range tlsVersions[:i] {
4126 flags = append(flags, vers.flag)
4127 }
4128
4129 for _, runnerVers := range tlsVersions {
4130 protocols := []protocol{tls}
4131 if runnerVers.hasDTLS && shimVers.hasDTLS {
4132 protocols = append(protocols, dtls)
4133 }
4134 for _, protocol := range protocols {
4135 suffix := shimVers.name + "-" + runnerVers.name
4136 if protocol == dtls {
4137 suffix += "-DTLS"
4138 }
4139 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4140
David Benjaminaccb4542014-12-12 23:44:33 -05004141 var expectedVersion uint16
4142 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004143 var expectedClientError, expectedServerError string
4144 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004145 if runnerVers.version >= shimVers.version {
4146 expectedVersion = runnerVers.version
4147 } else {
4148 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004149 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4150 expectedServerLocalError = "remote error: protocol version not supported"
4151 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4152 // If the client's minimum version is TLS 1.3 and the runner's
4153 // maximum is below TLS 1.2, the runner will fail to select a
4154 // cipher before the shim rejects the selected version.
4155 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4156 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4157 } else {
4158 expectedClientError = expectedServerError
4159 expectedClientLocalError = expectedServerLocalError
4160 }
David Benjaminaccb4542014-12-12 23:44:33 -05004161 }
4162
4163 testCases = append(testCases, testCase{
4164 protocol: protocol,
4165 testType: clientTest,
4166 name: "MinimumVersion-Client-" + suffix,
4167 config: Config{
4168 MaxVersion: runnerVers.version,
4169 },
David Benjamin87909c02014-12-13 01:55:01 -05004170 flags: flags,
4171 expectedVersion: expectedVersion,
4172 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004173 expectedError: expectedClientError,
4174 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004175 })
4176 testCases = append(testCases, testCase{
4177 protocol: protocol,
4178 testType: clientTest,
4179 name: "MinimumVersion-Client2-" + suffix,
4180 config: Config{
4181 MaxVersion: runnerVers.version,
4182 },
David Benjamin87909c02014-12-13 01:55:01 -05004183 flags: []string{"-min-version", shimVersFlag},
4184 expectedVersion: expectedVersion,
4185 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004186 expectedError: expectedClientError,
4187 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004188 })
4189
4190 testCases = append(testCases, testCase{
4191 protocol: protocol,
4192 testType: serverTest,
4193 name: "MinimumVersion-Server-" + suffix,
4194 config: Config{
4195 MaxVersion: runnerVers.version,
4196 },
David Benjamin87909c02014-12-13 01:55:01 -05004197 flags: flags,
4198 expectedVersion: expectedVersion,
4199 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004200 expectedError: expectedServerError,
4201 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004202 })
4203 testCases = append(testCases, testCase{
4204 protocol: protocol,
4205 testType: serverTest,
4206 name: "MinimumVersion-Server2-" + suffix,
4207 config: Config{
4208 MaxVersion: runnerVers.version,
4209 },
David Benjamin87909c02014-12-13 01:55:01 -05004210 flags: []string{"-min-version", shimVersFlag},
4211 expectedVersion: expectedVersion,
4212 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004213 expectedError: expectedServerError,
4214 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004215 })
4216 }
4217 }
4218 }
4219}
4220
David Benjamine78bfde2014-09-06 12:45:15 -04004221func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004222 // TODO(davidben): Extensions, where applicable, all move their server
4223 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4224 // tests for both. Also test interaction with 0-RTT when implemented.
4225
David Benjamin97d17d92016-07-14 16:12:00 -04004226 // Repeat extensions tests all versions except SSL 3.0.
4227 for _, ver := range tlsVersions {
4228 if ver.version == VersionSSL30 {
4229 continue
4230 }
4231
David Benjamin97d17d92016-07-14 16:12:00 -04004232 // Test that duplicate extensions are rejected.
4233 testCases = append(testCases, testCase{
4234 testType: clientTest,
4235 name: "DuplicateExtensionClient-" + ver.name,
4236 config: Config{
4237 MaxVersion: ver.version,
4238 Bugs: ProtocolBugs{
4239 DuplicateExtension: true,
4240 },
David Benjamine78bfde2014-09-06 12:45:15 -04004241 },
David Benjamin97d17d92016-07-14 16:12:00 -04004242 shouldFail: true,
4243 expectedLocalError: "remote error: error decoding message",
4244 })
4245 testCases = append(testCases, testCase{
4246 testType: serverTest,
4247 name: "DuplicateExtensionServer-" + ver.name,
4248 config: Config{
4249 MaxVersion: ver.version,
4250 Bugs: ProtocolBugs{
4251 DuplicateExtension: true,
4252 },
David Benjamine78bfde2014-09-06 12:45:15 -04004253 },
David Benjamin97d17d92016-07-14 16:12:00 -04004254 shouldFail: true,
4255 expectedLocalError: "remote error: error decoding message",
4256 })
4257
4258 // Test SNI.
4259 testCases = append(testCases, testCase{
4260 testType: clientTest,
4261 name: "ServerNameExtensionClient-" + ver.name,
4262 config: Config{
4263 MaxVersion: ver.version,
4264 Bugs: ProtocolBugs{
4265 ExpectServerName: "example.com",
4266 },
David Benjamine78bfde2014-09-06 12:45:15 -04004267 },
David Benjamin97d17d92016-07-14 16:12:00 -04004268 flags: []string{"-host-name", "example.com"},
4269 })
4270 testCases = append(testCases, testCase{
4271 testType: clientTest,
4272 name: "ServerNameExtensionClientMismatch-" + ver.name,
4273 config: Config{
4274 MaxVersion: ver.version,
4275 Bugs: ProtocolBugs{
4276 ExpectServerName: "mismatch.com",
4277 },
David Benjamine78bfde2014-09-06 12:45:15 -04004278 },
David Benjamin97d17d92016-07-14 16:12:00 -04004279 flags: []string{"-host-name", "example.com"},
4280 shouldFail: true,
4281 expectedLocalError: "tls: unexpected server name",
4282 })
4283 testCases = append(testCases, testCase{
4284 testType: clientTest,
4285 name: "ServerNameExtensionClientMissing-" + ver.name,
4286 config: Config{
4287 MaxVersion: ver.version,
4288 Bugs: ProtocolBugs{
4289 ExpectServerName: "missing.com",
4290 },
David Benjamine78bfde2014-09-06 12:45:15 -04004291 },
David Benjamin97d17d92016-07-14 16:12:00 -04004292 shouldFail: true,
4293 expectedLocalError: "tls: unexpected server name",
4294 })
4295 testCases = append(testCases, testCase{
4296 testType: serverTest,
4297 name: "ServerNameExtensionServer-" + ver.name,
4298 config: Config{
4299 MaxVersion: ver.version,
4300 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004301 },
David Benjamin97d17d92016-07-14 16:12:00 -04004302 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004303 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004304 })
4305
4306 // Test ALPN.
4307 testCases = append(testCases, testCase{
4308 testType: clientTest,
4309 name: "ALPNClient-" + ver.name,
4310 config: Config{
4311 MaxVersion: ver.version,
4312 NextProtos: []string{"foo"},
4313 },
4314 flags: []string{
4315 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4316 "-expect-alpn", "foo",
4317 },
4318 expectedNextProto: "foo",
4319 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004320 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004321 })
4322 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004323 testType: clientTest,
4324 name: "ALPNClient-Mismatch-" + ver.name,
4325 config: Config{
4326 MaxVersion: ver.version,
4327 Bugs: ProtocolBugs{
4328 SendALPN: "baz",
4329 },
4330 },
4331 flags: []string{
4332 "-advertise-alpn", "\x03foo\x03bar",
4333 },
4334 shouldFail: true,
4335 expectedError: ":INVALID_ALPN_PROTOCOL:",
4336 expectedLocalError: "remote error: illegal parameter",
4337 })
4338 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004339 testType: serverTest,
4340 name: "ALPNServer-" + ver.name,
4341 config: Config{
4342 MaxVersion: ver.version,
4343 NextProtos: []string{"foo", "bar", "baz"},
4344 },
4345 flags: []string{
4346 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4347 "-select-alpn", "foo",
4348 },
4349 expectedNextProto: "foo",
4350 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004351 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004352 })
4353 testCases = append(testCases, testCase{
4354 testType: serverTest,
4355 name: "ALPNServer-Decline-" + ver.name,
4356 config: Config{
4357 MaxVersion: ver.version,
4358 NextProtos: []string{"foo", "bar", "baz"},
4359 },
4360 flags: []string{"-decline-alpn"},
4361 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004362 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004363 })
4364
David Benjamin25fe85b2016-08-09 20:00:32 -04004365 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4366 // called once.
4367 testCases = append(testCases, testCase{
4368 testType: serverTest,
4369 name: "ALPNServer-Async-" + ver.name,
4370 config: Config{
4371 MaxVersion: ver.version,
4372 NextProtos: []string{"foo", "bar", "baz"},
4373 },
4374 flags: []string{
4375 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4376 "-select-alpn", "foo",
4377 "-async",
4378 },
4379 expectedNextProto: "foo",
4380 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004381 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004382 })
4383
David Benjamin97d17d92016-07-14 16:12:00 -04004384 var emptyString string
4385 testCases = append(testCases, testCase{
4386 testType: clientTest,
4387 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4388 config: Config{
4389 MaxVersion: ver.version,
4390 NextProtos: []string{""},
4391 Bugs: ProtocolBugs{
4392 // A server returning an empty ALPN protocol
4393 // should be rejected.
4394 ALPNProtocol: &emptyString,
4395 },
4396 },
4397 flags: []string{
4398 "-advertise-alpn", "\x03foo",
4399 },
4400 shouldFail: true,
4401 expectedError: ":PARSE_TLSEXT:",
4402 })
4403 testCases = append(testCases, testCase{
4404 testType: serverTest,
4405 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4406 config: Config{
4407 MaxVersion: ver.version,
4408 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004409 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004410 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004411 },
David Benjamin97d17d92016-07-14 16:12:00 -04004412 flags: []string{
4413 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004414 },
David Benjamin97d17d92016-07-14 16:12:00 -04004415 shouldFail: true,
4416 expectedError: ":PARSE_TLSEXT:",
4417 })
4418
4419 // Test NPN and the interaction with ALPN.
4420 if ver.version < VersionTLS13 {
4421 // Test that the server prefers ALPN over NPN.
4422 testCases = append(testCases, testCase{
4423 testType: serverTest,
4424 name: "ALPNServer-Preferred-" + ver.name,
4425 config: Config{
4426 MaxVersion: ver.version,
4427 NextProtos: []string{"foo", "bar", "baz"},
4428 },
4429 flags: []string{
4430 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4431 "-select-alpn", "foo",
4432 "-advertise-npn", "\x03foo\x03bar\x03baz",
4433 },
4434 expectedNextProto: "foo",
4435 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004436 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004437 })
4438 testCases = append(testCases, testCase{
4439 testType: serverTest,
4440 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4441 config: Config{
4442 MaxVersion: ver.version,
4443 NextProtos: []string{"foo", "bar", "baz"},
4444 Bugs: ProtocolBugs{
4445 SwapNPNAndALPN: true,
4446 },
4447 },
4448 flags: []string{
4449 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4450 "-select-alpn", "foo",
4451 "-advertise-npn", "\x03foo\x03bar\x03baz",
4452 },
4453 expectedNextProto: "foo",
4454 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004455 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004456 })
4457
4458 // Test that negotiating both NPN and ALPN is forbidden.
4459 testCases = append(testCases, testCase{
4460 name: "NegotiateALPNAndNPN-" + ver.name,
4461 config: Config{
4462 MaxVersion: ver.version,
4463 NextProtos: []string{"foo", "bar", "baz"},
4464 Bugs: ProtocolBugs{
4465 NegotiateALPNAndNPN: true,
4466 },
4467 },
4468 flags: []string{
4469 "-advertise-alpn", "\x03foo",
4470 "-select-next-proto", "foo",
4471 },
4472 shouldFail: true,
4473 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4474 })
4475 testCases = append(testCases, testCase{
4476 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4477 config: Config{
4478 MaxVersion: ver.version,
4479 NextProtos: []string{"foo", "bar", "baz"},
4480 Bugs: ProtocolBugs{
4481 NegotiateALPNAndNPN: true,
4482 SwapNPNAndALPN: true,
4483 },
4484 },
4485 flags: []string{
4486 "-advertise-alpn", "\x03foo",
4487 "-select-next-proto", "foo",
4488 },
4489 shouldFail: true,
4490 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4491 })
4492
4493 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4494 testCases = append(testCases, testCase{
4495 name: "DisableNPN-" + ver.name,
4496 config: Config{
4497 MaxVersion: ver.version,
4498 NextProtos: []string{"foo"},
4499 },
4500 flags: []string{
4501 "-select-next-proto", "foo",
4502 "-disable-npn",
4503 },
4504 expectNoNextProto: true,
4505 })
4506 }
4507
4508 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004509
4510 // Resume with a corrupt ticket.
4511 testCases = append(testCases, testCase{
4512 testType: serverTest,
4513 name: "CorruptTicket-" + ver.name,
4514 config: Config{
4515 MaxVersion: ver.version,
4516 Bugs: ProtocolBugs{
4517 CorruptTicket: true,
4518 },
4519 },
4520 resumeSession: true,
4521 expectResumeRejected: true,
4522 })
4523 // Test the ticket callback, with and without renewal.
4524 testCases = append(testCases, testCase{
4525 testType: serverTest,
4526 name: "TicketCallback-" + ver.name,
4527 config: Config{
4528 MaxVersion: ver.version,
4529 },
4530 resumeSession: true,
4531 flags: []string{"-use-ticket-callback"},
4532 })
4533 testCases = append(testCases, testCase{
4534 testType: serverTest,
4535 name: "TicketCallback-Renew-" + ver.name,
4536 config: Config{
4537 MaxVersion: ver.version,
4538 Bugs: ProtocolBugs{
4539 ExpectNewTicket: true,
4540 },
4541 },
4542 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4543 resumeSession: true,
4544 })
4545
4546 // Test that the ticket callback is only called once when everything before
4547 // it in the ClientHello is asynchronous. This corrupts the ticket so
4548 // certificate selection callbacks run.
4549 testCases = append(testCases, testCase{
4550 testType: serverTest,
4551 name: "TicketCallback-SingleCall-" + ver.name,
4552 config: Config{
4553 MaxVersion: ver.version,
4554 Bugs: ProtocolBugs{
4555 CorruptTicket: true,
4556 },
4557 },
4558 resumeSession: true,
4559 expectResumeRejected: true,
4560 flags: []string{
4561 "-use-ticket-callback",
4562 "-async",
4563 },
4564 })
4565
4566 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004567 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004568 testCases = append(testCases, testCase{
4569 testType: serverTest,
4570 name: "OversizedSessionId-" + ver.name,
4571 config: Config{
4572 MaxVersion: ver.version,
4573 Bugs: ProtocolBugs{
4574 OversizedSessionId: true,
4575 },
4576 },
4577 resumeSession: true,
4578 shouldFail: true,
4579 expectedError: ":DECODE_ERROR:",
4580 })
4581 }
4582
4583 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4584 // are ignored.
4585 if ver.hasDTLS {
4586 testCases = append(testCases, testCase{
4587 protocol: dtls,
4588 name: "SRTP-Client-" + ver.name,
4589 config: Config{
4590 MaxVersion: ver.version,
4591 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4592 },
4593 flags: []string{
4594 "-srtp-profiles",
4595 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4596 },
4597 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4598 })
4599 testCases = append(testCases, testCase{
4600 protocol: dtls,
4601 testType: serverTest,
4602 name: "SRTP-Server-" + ver.name,
4603 config: Config{
4604 MaxVersion: ver.version,
4605 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4606 },
4607 flags: []string{
4608 "-srtp-profiles",
4609 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4610 },
4611 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4612 })
4613 // Test that the MKI is ignored.
4614 testCases = append(testCases, testCase{
4615 protocol: dtls,
4616 testType: serverTest,
4617 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4618 config: Config{
4619 MaxVersion: ver.version,
4620 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4621 Bugs: ProtocolBugs{
4622 SRTPMasterKeyIdentifer: "bogus",
4623 },
4624 },
4625 flags: []string{
4626 "-srtp-profiles",
4627 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4628 },
4629 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4630 })
4631 // Test that SRTP isn't negotiated on the server if there were
4632 // no matching profiles.
4633 testCases = append(testCases, testCase{
4634 protocol: dtls,
4635 testType: serverTest,
4636 name: "SRTP-Server-NoMatch-" + ver.name,
4637 config: Config{
4638 MaxVersion: ver.version,
4639 SRTPProtectionProfiles: []uint16{100, 101, 102},
4640 },
4641 flags: []string{
4642 "-srtp-profiles",
4643 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4644 },
4645 expectedSRTPProtectionProfile: 0,
4646 })
4647 // Test that the server returning an invalid SRTP profile is
4648 // flagged as an error by the client.
4649 testCases = append(testCases, testCase{
4650 protocol: dtls,
4651 name: "SRTP-Client-NoMatch-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4656 },
4657 },
4658 flags: []string{
4659 "-srtp-profiles",
4660 "SRTP_AES128_CM_SHA1_80",
4661 },
4662 shouldFail: true,
4663 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4664 })
4665 }
4666
4667 // Test SCT list.
4668 testCases = append(testCases, testCase{
4669 name: "SignedCertificateTimestampList-Client-" + ver.name,
4670 testType: clientTest,
4671 config: Config{
4672 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004673 },
David Benjamin97d17d92016-07-14 16:12:00 -04004674 flags: []string{
4675 "-enable-signed-cert-timestamps",
4676 "-expect-signed-cert-timestamps",
4677 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004678 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004679 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004680 })
4681 testCases = append(testCases, testCase{
4682 name: "SendSCTListOnResume-" + ver.name,
4683 config: Config{
4684 MaxVersion: ver.version,
4685 Bugs: ProtocolBugs{
4686 SendSCTListOnResume: []byte("bogus"),
4687 },
David Benjamind98452d2015-06-16 14:16:23 -04004688 },
David Benjamin97d17d92016-07-14 16:12:00 -04004689 flags: []string{
4690 "-enable-signed-cert-timestamps",
4691 "-expect-signed-cert-timestamps",
4692 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004693 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004694 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004695 })
4696 testCases = append(testCases, testCase{
4697 name: "SignedCertificateTimestampList-Server-" + ver.name,
4698 testType: serverTest,
4699 config: Config{
4700 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004701 },
David Benjamin97d17d92016-07-14 16:12:00 -04004702 flags: []string{
4703 "-signed-cert-timestamps",
4704 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004705 },
David Benjamin97d17d92016-07-14 16:12:00 -04004706 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004707 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004708 })
4709 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004710
Paul Lietar4fac72e2015-09-09 13:44:55 +01004711 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004712 testType: clientTest,
4713 name: "ClientHelloPadding",
4714 config: Config{
4715 Bugs: ProtocolBugs{
4716 RequireClientHelloSize: 512,
4717 },
4718 },
4719 // This hostname just needs to be long enough to push the
4720 // ClientHello into F5's danger zone between 256 and 511 bytes
4721 // long.
4722 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4723 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004724
4725 // Extensions should not function in SSL 3.0.
4726 testCases = append(testCases, testCase{
4727 testType: serverTest,
4728 name: "SSLv3Extensions-NoALPN",
4729 config: Config{
4730 MaxVersion: VersionSSL30,
4731 NextProtos: []string{"foo", "bar", "baz"},
4732 },
4733 flags: []string{
4734 "-select-alpn", "foo",
4735 },
4736 expectNoNextProto: true,
4737 })
4738
4739 // Test session tickets separately as they follow a different codepath.
4740 testCases = append(testCases, testCase{
4741 testType: serverTest,
4742 name: "SSLv3Extensions-NoTickets",
4743 config: Config{
4744 MaxVersion: VersionSSL30,
4745 Bugs: ProtocolBugs{
4746 // Historically, session tickets in SSL 3.0
4747 // failed in different ways depending on whether
4748 // the client supported renegotiation_info.
4749 NoRenegotiationInfo: true,
4750 },
4751 },
4752 resumeSession: true,
4753 })
4754 testCases = append(testCases, testCase{
4755 testType: serverTest,
4756 name: "SSLv3Extensions-NoTickets2",
4757 config: Config{
4758 MaxVersion: VersionSSL30,
4759 },
4760 resumeSession: true,
4761 })
4762
4763 // But SSL 3.0 does send and process renegotiation_info.
4764 testCases = append(testCases, testCase{
4765 testType: serverTest,
4766 name: "SSLv3Extensions-RenegotiationInfo",
4767 config: Config{
4768 MaxVersion: VersionSSL30,
4769 Bugs: ProtocolBugs{
4770 RequireRenegotiationInfo: true,
4771 },
4772 },
4773 })
4774 testCases = append(testCases, testCase{
4775 testType: serverTest,
4776 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4777 config: Config{
4778 MaxVersion: VersionSSL30,
4779 Bugs: ProtocolBugs{
4780 NoRenegotiationInfo: true,
4781 SendRenegotiationSCSV: true,
4782 RequireRenegotiationInfo: true,
4783 },
4784 },
4785 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004786
4787 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4788 // in ServerHello.
4789 testCases = append(testCases, testCase{
4790 name: "NPN-Forbidden-TLS13",
4791 config: Config{
4792 MaxVersion: VersionTLS13,
4793 NextProtos: []string{"foo"},
4794 Bugs: ProtocolBugs{
4795 NegotiateNPNAtAllVersions: true,
4796 },
4797 },
4798 flags: []string{"-select-next-proto", "foo"},
4799 shouldFail: true,
4800 expectedError: ":ERROR_PARSING_EXTENSION:",
4801 })
4802 testCases = append(testCases, testCase{
4803 name: "EMS-Forbidden-TLS13",
4804 config: Config{
4805 MaxVersion: VersionTLS13,
4806 Bugs: ProtocolBugs{
4807 NegotiateEMSAtAllVersions: true,
4808 },
4809 },
4810 shouldFail: true,
4811 expectedError: ":ERROR_PARSING_EXTENSION:",
4812 })
4813 testCases = append(testCases, testCase{
4814 name: "RenegotiationInfo-Forbidden-TLS13",
4815 config: Config{
4816 MaxVersion: VersionTLS13,
4817 Bugs: ProtocolBugs{
4818 NegotiateRenegotiationInfoAtAllVersions: true,
4819 },
4820 },
4821 shouldFail: true,
4822 expectedError: ":ERROR_PARSING_EXTENSION:",
4823 })
4824 testCases = append(testCases, testCase{
4825 name: "ChannelID-Forbidden-TLS13",
4826 config: Config{
4827 MaxVersion: VersionTLS13,
4828 RequestChannelID: true,
4829 Bugs: ProtocolBugs{
4830 NegotiateChannelIDAtAllVersions: true,
4831 },
4832 },
4833 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4834 shouldFail: true,
4835 expectedError: ":ERROR_PARSING_EXTENSION:",
4836 })
4837 testCases = append(testCases, testCase{
4838 name: "Ticket-Forbidden-TLS13",
4839 config: Config{
4840 MaxVersion: VersionTLS12,
4841 },
4842 resumeConfig: &Config{
4843 MaxVersion: VersionTLS13,
4844 Bugs: ProtocolBugs{
4845 AdvertiseTicketExtension: true,
4846 },
4847 },
4848 resumeSession: true,
4849 shouldFail: true,
4850 expectedError: ":ERROR_PARSING_EXTENSION:",
4851 })
4852
4853 // Test that illegal extensions in TLS 1.3 are declined by the server if
4854 // offered in ClientHello. The runner's server will fail if this occurs,
4855 // so we exercise the offering path. (EMS and Renegotiation Info are
4856 // implicit in every test.)
4857 testCases = append(testCases, testCase{
4858 testType: serverTest,
4859 name: "ChannelID-Declined-TLS13",
4860 config: Config{
4861 MaxVersion: VersionTLS13,
4862 ChannelID: channelIDKey,
4863 },
4864 flags: []string{"-enable-channel-id"},
4865 })
4866 testCases = append(testCases, testCase{
4867 testType: serverTest,
4868 name: "NPN-Server",
4869 config: Config{
4870 MaxVersion: VersionTLS13,
4871 NextProtos: []string{"bar"},
4872 },
4873 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4874 })
David Benjamine78bfde2014-09-06 12:45:15 -04004875}
4876
David Benjamin01fe8202014-09-24 15:21:44 -04004877func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004878 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004879 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004880 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4881 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4882 // TLS 1.3 only shares ciphers with TLS 1.2, so
4883 // we skip certain combinations and use a
4884 // different cipher to test with.
4885 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4886 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4887 continue
4888 }
4889 }
4890
David Benjamin8b8c0062014-11-23 02:47:52 -05004891 protocols := []protocol{tls}
4892 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4893 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004894 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004895 for _, protocol := range protocols {
4896 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4897 if protocol == dtls {
4898 suffix += "-DTLS"
4899 }
4900
David Benjaminece3de92015-03-16 18:02:20 -04004901 if sessionVers.version == resumeVers.version {
4902 testCases = append(testCases, testCase{
4903 protocol: protocol,
4904 name: "Resume-Client" + suffix,
4905 resumeSession: true,
4906 config: Config{
4907 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004908 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004909 Bugs: ProtocolBugs{
4910 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4911 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4912 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004913 },
David Benjaminece3de92015-03-16 18:02:20 -04004914 expectedVersion: sessionVers.version,
4915 expectedResumeVersion: resumeVers.version,
4916 })
4917 } else {
David Benjamin405da482016-08-08 17:25:07 -04004918 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4919
4920 // Offering a TLS 1.3 session sends an empty session ID, so
4921 // there is no way to convince a non-lookahead client the
4922 // session was resumed. It will appear to the client that a
4923 // stray ChangeCipherSpec was sent.
4924 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4925 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004926 }
4927
David Benjaminece3de92015-03-16 18:02:20 -04004928 testCases = append(testCases, testCase{
4929 protocol: protocol,
4930 name: "Resume-Client-Mismatch" + suffix,
4931 resumeSession: true,
4932 config: Config{
4933 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004934 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004935 },
David Benjaminece3de92015-03-16 18:02:20 -04004936 expectedVersion: sessionVers.version,
4937 resumeConfig: &Config{
4938 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004939 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004940 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004941 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004942 },
4943 },
4944 expectedResumeVersion: resumeVers.version,
4945 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004946 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004947 })
4948 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004949
4950 testCases = append(testCases, testCase{
4951 protocol: protocol,
4952 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004953 resumeSession: true,
4954 config: Config{
4955 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004956 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004957 },
4958 expectedVersion: sessionVers.version,
4959 resumeConfig: &Config{
4960 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004961 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004962 },
4963 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004964 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004965 expectedResumeVersion: resumeVers.version,
4966 })
4967
David Benjamin8b8c0062014-11-23 02:47:52 -05004968 testCases = append(testCases, testCase{
4969 protocol: protocol,
4970 testType: serverTest,
4971 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004972 resumeSession: true,
4973 config: Config{
4974 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004975 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004976 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004977 expectedVersion: sessionVers.version,
4978 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004979 resumeConfig: &Config{
4980 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004981 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004982 Bugs: ProtocolBugs{
4983 SendBothTickets: true,
4984 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004985 },
4986 expectedResumeVersion: resumeVers.version,
4987 })
4988 }
David Benjamin01fe8202014-09-24 15:21:44 -04004989 }
4990 }
David Benjaminece3de92015-03-16 18:02:20 -04004991
4992 testCases = append(testCases, testCase{
4993 name: "Resume-Client-CipherMismatch",
4994 resumeSession: true,
4995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004996 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004997 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4998 },
4999 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005000 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005001 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5002 Bugs: ProtocolBugs{
5003 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5004 },
5005 },
5006 shouldFail: true,
5007 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5008 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005009
5010 testCases = append(testCases, testCase{
5011 name: "Resume-Client-CipherMismatch-TLS13",
5012 resumeSession: true,
5013 config: Config{
5014 MaxVersion: VersionTLS13,
5015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5016 },
5017 resumeConfig: &Config{
5018 MaxVersion: VersionTLS13,
5019 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5020 Bugs: ProtocolBugs{
5021 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5022 },
5023 },
5024 shouldFail: true,
5025 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5026 })
David Benjamin01fe8202014-09-24 15:21:44 -04005027}
5028
Adam Langley2ae77d22014-10-28 17:29:33 -07005029func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005030 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005031 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005032 testType: serverTest,
5033 name: "Renegotiate-Server-Forbidden",
5034 config: Config{
5035 MaxVersion: VersionTLS12,
5036 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005037 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005038 shouldFail: true,
5039 expectedError: ":NO_RENEGOTIATION:",
5040 expectedLocalError: "remote error: no renegotiation",
5041 })
Adam Langley5021b222015-06-12 18:27:58 -07005042 // The server shouldn't echo the renegotiation extension unless
5043 // requested by the client.
5044 testCases = append(testCases, testCase{
5045 testType: serverTest,
5046 name: "Renegotiate-Server-NoExt",
5047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005048 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005049 Bugs: ProtocolBugs{
5050 NoRenegotiationInfo: true,
5051 RequireRenegotiationInfo: true,
5052 },
5053 },
5054 shouldFail: true,
5055 expectedLocalError: "renegotiation extension missing",
5056 })
5057 // The renegotiation SCSV should be sufficient for the server to echo
5058 // the extension.
5059 testCases = append(testCases, testCase{
5060 testType: serverTest,
5061 name: "Renegotiate-Server-NoExt-SCSV",
5062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005063 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005064 Bugs: ProtocolBugs{
5065 NoRenegotiationInfo: true,
5066 SendRenegotiationSCSV: true,
5067 RequireRenegotiationInfo: true,
5068 },
5069 },
5070 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005071 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005072 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005073 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005074 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005075 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005076 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005077 },
5078 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005079 renegotiate: 1,
5080 flags: []string{
5081 "-renegotiate-freely",
5082 "-expect-total-renegotiations", "1",
5083 },
David Benjamincdea40c2015-03-19 14:09:43 -04005084 })
5085 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005086 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005087 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005089 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005090 Bugs: ProtocolBugs{
5091 EmptyRenegotiationInfo: true,
5092 },
5093 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005094 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005095 shouldFail: true,
5096 expectedError: ":RENEGOTIATION_MISMATCH:",
5097 })
5098 testCases = append(testCases, testCase{
5099 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005100 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005102 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005103 Bugs: ProtocolBugs{
5104 BadRenegotiationInfo: true,
5105 },
5106 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005107 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005108 shouldFail: true,
5109 expectedError: ":RENEGOTIATION_MISMATCH:",
5110 })
5111 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005112 name: "Renegotiate-Client-Downgrade",
5113 renegotiate: 1,
5114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005115 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005116 Bugs: ProtocolBugs{
5117 NoRenegotiationInfoAfterInitial: true,
5118 },
5119 },
5120 flags: []string{"-renegotiate-freely"},
5121 shouldFail: true,
5122 expectedError: ":RENEGOTIATION_MISMATCH:",
5123 })
5124 testCases = append(testCases, testCase{
5125 name: "Renegotiate-Client-Upgrade",
5126 renegotiate: 1,
5127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005128 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005129 Bugs: ProtocolBugs{
5130 NoRenegotiationInfoInInitial: true,
5131 },
5132 },
5133 flags: []string{"-renegotiate-freely"},
5134 shouldFail: true,
5135 expectedError: ":RENEGOTIATION_MISMATCH:",
5136 })
5137 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005138 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005139 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005140 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005141 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005142 Bugs: ProtocolBugs{
5143 NoRenegotiationInfo: true,
5144 },
5145 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005146 flags: []string{
5147 "-renegotiate-freely",
5148 "-expect-total-renegotiations", "1",
5149 },
David Benjamincff0b902015-05-15 23:09:47 -04005150 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005151
5152 // Test that the server may switch ciphers on renegotiation without
5153 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005154 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005155 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005156 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005157 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005158 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005159 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5160 },
5161 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005162 flags: []string{
5163 "-renegotiate-freely",
5164 "-expect-total-renegotiations", "1",
5165 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005166 })
5167 testCases = append(testCases, testCase{
5168 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005169 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005170 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005171 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005172 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5173 },
5174 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005175 flags: []string{
5176 "-renegotiate-freely",
5177 "-expect-total-renegotiations", "1",
5178 },
David Benjaminb16346b2015-04-08 19:16:58 -04005179 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005180
5181 // Test that the server may not switch versions on renegotiation.
5182 testCases = append(testCases, testCase{
5183 name: "Renegotiate-Client-SwitchVersion",
5184 config: Config{
5185 MaxVersion: VersionTLS12,
5186 // Pick a cipher which exists at both versions.
5187 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5188 Bugs: ProtocolBugs{
5189 NegotiateVersionOnRenego: VersionTLS11,
5190 },
5191 },
5192 renegotiate: 1,
5193 flags: []string{
5194 "-renegotiate-freely",
5195 "-expect-total-renegotiations", "1",
5196 },
5197 shouldFail: true,
5198 expectedError: ":WRONG_SSL_VERSION:",
5199 })
5200
David Benjaminb16346b2015-04-08 19:16:58 -04005201 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005202 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005203 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005204 config: Config{
5205 MaxVersion: VersionTLS10,
5206 Bugs: ProtocolBugs{
5207 RequireSameRenegoClientVersion: true,
5208 },
5209 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005210 flags: []string{
5211 "-renegotiate-freely",
5212 "-expect-total-renegotiations", "1",
5213 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005214 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005215 testCases = append(testCases, testCase{
5216 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005217 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005218 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005219 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5221 NextProtos: []string{"foo"},
5222 },
5223 flags: []string{
5224 "-false-start",
5225 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005226 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005227 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005228 },
5229 shimWritesFirst: true,
5230 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005231
5232 // Client-side renegotiation controls.
5233 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005234 name: "Renegotiate-Client-Forbidden-1",
5235 config: Config{
5236 MaxVersion: VersionTLS12,
5237 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238 renegotiate: 1,
5239 shouldFail: true,
5240 expectedError: ":NO_RENEGOTIATION:",
5241 expectedLocalError: "remote error: no renegotiation",
5242 })
5243 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005244 name: "Renegotiate-Client-Once-1",
5245 config: Config{
5246 MaxVersion: VersionTLS12,
5247 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005248 renegotiate: 1,
5249 flags: []string{
5250 "-renegotiate-once",
5251 "-expect-total-renegotiations", "1",
5252 },
5253 })
5254 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005255 name: "Renegotiate-Client-Freely-1",
5256 config: Config{
5257 MaxVersion: VersionTLS12,
5258 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005259 renegotiate: 1,
5260 flags: []string{
5261 "-renegotiate-freely",
5262 "-expect-total-renegotiations", "1",
5263 },
5264 })
5265 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005266 name: "Renegotiate-Client-Once-2",
5267 config: Config{
5268 MaxVersion: VersionTLS12,
5269 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005270 renegotiate: 2,
5271 flags: []string{"-renegotiate-once"},
5272 shouldFail: true,
5273 expectedError: ":NO_RENEGOTIATION:",
5274 expectedLocalError: "remote error: no renegotiation",
5275 })
5276 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005277 name: "Renegotiate-Client-Freely-2",
5278 config: Config{
5279 MaxVersion: VersionTLS12,
5280 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005281 renegotiate: 2,
5282 flags: []string{
5283 "-renegotiate-freely",
5284 "-expect-total-renegotiations", "2",
5285 },
5286 })
Adam Langley27a0d082015-11-03 13:34:10 -08005287 testCases = append(testCases, testCase{
5288 name: "Renegotiate-Client-NoIgnore",
5289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005290 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005291 Bugs: ProtocolBugs{
5292 SendHelloRequestBeforeEveryAppDataRecord: true,
5293 },
5294 },
5295 shouldFail: true,
5296 expectedError: ":NO_RENEGOTIATION:",
5297 })
5298 testCases = append(testCases, testCase{
5299 name: "Renegotiate-Client-Ignore",
5300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005301 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005302 Bugs: ProtocolBugs{
5303 SendHelloRequestBeforeEveryAppDataRecord: true,
5304 },
5305 },
5306 flags: []string{
5307 "-renegotiate-ignore",
5308 "-expect-total-renegotiations", "0",
5309 },
5310 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005311
David Benjamin397c8e62016-07-08 14:14:36 -07005312 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005313 testCases = append(testCases, testCase{
5314 name: "StrayHelloRequest",
5315 config: Config{
5316 MaxVersion: VersionTLS12,
5317 Bugs: ProtocolBugs{
5318 SendHelloRequestBeforeEveryHandshakeMessage: true,
5319 },
5320 },
5321 })
5322 testCases = append(testCases, testCase{
5323 name: "StrayHelloRequest-Packed",
5324 config: Config{
5325 MaxVersion: VersionTLS12,
5326 Bugs: ProtocolBugs{
5327 PackHandshakeFlight: true,
5328 SendHelloRequestBeforeEveryHandshakeMessage: true,
5329 },
5330 },
5331 })
5332
David Benjamin12d2c482016-07-24 10:56:51 -04005333 // Test renegotiation works if HelloRequest and server Finished come in
5334 // the same record.
5335 testCases = append(testCases, testCase{
5336 name: "Renegotiate-Client-Packed",
5337 config: Config{
5338 MaxVersion: VersionTLS12,
5339 Bugs: ProtocolBugs{
5340 PackHandshakeFlight: true,
5341 PackHelloRequestWithFinished: true,
5342 },
5343 },
5344 renegotiate: 1,
5345 flags: []string{
5346 "-renegotiate-freely",
5347 "-expect-total-renegotiations", "1",
5348 },
5349 })
5350
David Benjamin397c8e62016-07-08 14:14:36 -07005351 // Renegotiation is forbidden in TLS 1.3.
5352 testCases = append(testCases, testCase{
5353 name: "Renegotiate-Client-TLS13",
5354 config: Config{
5355 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005356 Bugs: ProtocolBugs{
5357 SendHelloRequestBeforeEveryAppDataRecord: true,
5358 },
David Benjamin397c8e62016-07-08 14:14:36 -07005359 },
David Benjamin397c8e62016-07-08 14:14:36 -07005360 flags: []string{
5361 "-renegotiate-freely",
5362 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005363 shouldFail: true,
5364 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005365 })
5366
5367 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5368 testCases = append(testCases, testCase{
5369 name: "StrayHelloRequest-TLS13",
5370 config: Config{
5371 MaxVersion: VersionTLS13,
5372 Bugs: ProtocolBugs{
5373 SendHelloRequestBeforeEveryHandshakeMessage: true,
5374 },
5375 },
5376 shouldFail: true,
5377 expectedError: ":UNEXPECTED_MESSAGE:",
5378 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005379}
5380
David Benjamin5e961c12014-11-07 01:48:35 -05005381func addDTLSReplayTests() {
5382 // Test that sequence number replays are detected.
5383 testCases = append(testCases, testCase{
5384 protocol: dtls,
5385 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005386 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005387 replayWrites: true,
5388 })
5389
David Benjamin8e6db492015-07-25 18:29:23 -04005390 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005391 // than the retransmit window.
5392 testCases = append(testCases, testCase{
5393 protocol: dtls,
5394 name: "DTLS-Replay-LargeGaps",
5395 config: Config{
5396 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005397 SequenceNumberMapping: func(in uint64) uint64 {
5398 return in * 127
5399 },
David Benjamin5e961c12014-11-07 01:48:35 -05005400 },
5401 },
David Benjamin8e6db492015-07-25 18:29:23 -04005402 messageCount: 200,
5403 replayWrites: true,
5404 })
5405
5406 // Test the incoming sequence number changing non-monotonically.
5407 testCases = append(testCases, testCase{
5408 protocol: dtls,
5409 name: "DTLS-Replay-NonMonotonic",
5410 config: Config{
5411 Bugs: ProtocolBugs{
5412 SequenceNumberMapping: func(in uint64) uint64 {
5413 return in ^ 31
5414 },
5415 },
5416 },
5417 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005418 replayWrites: true,
5419 })
5420}
5421
Nick Harper60edffd2016-06-21 15:19:24 -07005422var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005423 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005424 id signatureAlgorithm
5425 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005426}{
Nick Harper60edffd2016-06-21 15:19:24 -07005427 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5428 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5429 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5430 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005431 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005432 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5433 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5434 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005435 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5436 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5437 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005438 // Tests for key types prior to TLS 1.2.
5439 {"RSA", 0, testCertRSA},
5440 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005441}
5442
Nick Harper60edffd2016-06-21 15:19:24 -07005443const fakeSigAlg1 signatureAlgorithm = 0x2a01
5444const fakeSigAlg2 signatureAlgorithm = 0xff01
5445
5446func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005447 // Not all ciphers involve a signature. Advertise a list which gives all
5448 // versions a signing cipher.
5449 signingCiphers := []uint16{
5450 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5451 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5452 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5453 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5454 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5455 }
5456
David Benjaminca3d5452016-07-14 12:51:01 -04005457 var allAlgorithms []signatureAlgorithm
5458 for _, alg := range testSignatureAlgorithms {
5459 if alg.id != 0 {
5460 allAlgorithms = append(allAlgorithms, alg.id)
5461 }
5462 }
5463
Nick Harper60edffd2016-06-21 15:19:24 -07005464 // Make sure each signature algorithm works. Include some fake values in
5465 // the list and ensure they're ignored.
5466 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005467 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005468 if (ver.version < VersionTLS12) != (alg.id == 0) {
5469 continue
5470 }
5471
5472 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5473 // or remove it in C.
5474 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005475 continue
5476 }
Nick Harper60edffd2016-06-21 15:19:24 -07005477
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005478 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005479 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005480 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5481 shouldFail = true
5482 }
5483 // RSA-PSS does not exist in TLS 1.2.
5484 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5485 shouldFail = true
5486 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005487 // RSA-PKCS1 does not exist in TLS 1.3.
5488 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5489 shouldFail = true
5490 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005491
5492 var signError, verifyError string
5493 if shouldFail {
5494 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5495 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005496 }
David Benjamin000800a2014-11-14 01:43:59 -05005497
David Benjamin1fb125c2016-07-08 18:52:12 -07005498 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005499
David Benjamin7a41d372016-07-09 11:21:54 -07005500 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005501 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005502 config: Config{
5503 MaxVersion: ver.version,
5504 ClientAuth: RequireAnyClientCert,
5505 VerifySignatureAlgorithms: []signatureAlgorithm{
5506 fakeSigAlg1,
5507 alg.id,
5508 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005509 },
David Benjamin7a41d372016-07-09 11:21:54 -07005510 },
5511 flags: []string{
5512 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5513 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5514 "-enable-all-curves",
5515 },
5516 shouldFail: shouldFail,
5517 expectedError: signError,
5518 expectedPeerSignatureAlgorithm: alg.id,
5519 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005520
David Benjamin7a41d372016-07-09 11:21:54 -07005521 testCases = append(testCases, testCase{
5522 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005523 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005524 config: Config{
5525 MaxVersion: ver.version,
5526 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5527 SignSignatureAlgorithms: []signatureAlgorithm{
5528 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005529 },
David Benjamin7a41d372016-07-09 11:21:54 -07005530 Bugs: ProtocolBugs{
5531 SkipECDSACurveCheck: shouldFail,
5532 IgnoreSignatureVersionChecks: shouldFail,
5533 // The client won't advertise 1.3-only algorithms after
5534 // version negotiation.
5535 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005536 },
David Benjamin7a41d372016-07-09 11:21:54 -07005537 },
5538 flags: []string{
5539 "-require-any-client-certificate",
5540 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5541 "-enable-all-curves",
5542 },
5543 shouldFail: shouldFail,
5544 expectedError: verifyError,
5545 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005546
5547 testCases = append(testCases, testCase{
5548 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005549 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005550 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005551 MaxVersion: ver.version,
5552 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005553 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005554 fakeSigAlg1,
5555 alg.id,
5556 fakeSigAlg2,
5557 },
5558 },
5559 flags: []string{
5560 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5561 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5562 "-enable-all-curves",
5563 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005564 shouldFail: shouldFail,
5565 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005566 expectedPeerSignatureAlgorithm: alg.id,
5567 })
5568
5569 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005570 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005571 config: Config{
5572 MaxVersion: ver.version,
5573 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005574 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005575 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005576 alg.id,
5577 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005578 Bugs: ProtocolBugs{
5579 SkipECDSACurveCheck: shouldFail,
5580 IgnoreSignatureVersionChecks: shouldFail,
5581 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005582 },
5583 flags: []string{
5584 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5585 "-enable-all-curves",
5586 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005587 shouldFail: shouldFail,
5588 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005589 })
David Benjamin5208fd42016-07-13 21:43:25 -04005590
5591 if !shouldFail {
5592 testCases = append(testCases, testCase{
5593 testType: serverTest,
5594 name: "ClientAuth-InvalidSignature" + suffix,
5595 config: Config{
5596 MaxVersion: ver.version,
5597 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5598 SignSignatureAlgorithms: []signatureAlgorithm{
5599 alg.id,
5600 },
5601 Bugs: ProtocolBugs{
5602 InvalidSignature: true,
5603 },
5604 },
5605 flags: []string{
5606 "-require-any-client-certificate",
5607 "-enable-all-curves",
5608 },
5609 shouldFail: true,
5610 expectedError: ":BAD_SIGNATURE:",
5611 })
5612
5613 testCases = append(testCases, testCase{
5614 name: "ServerAuth-InvalidSignature" + suffix,
5615 config: Config{
5616 MaxVersion: ver.version,
5617 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5618 CipherSuites: signingCiphers,
5619 SignSignatureAlgorithms: []signatureAlgorithm{
5620 alg.id,
5621 },
5622 Bugs: ProtocolBugs{
5623 InvalidSignature: true,
5624 },
5625 },
5626 flags: []string{"-enable-all-curves"},
5627 shouldFail: true,
5628 expectedError: ":BAD_SIGNATURE:",
5629 })
5630 }
David Benjaminca3d5452016-07-14 12:51:01 -04005631
5632 if ver.version >= VersionTLS12 && !shouldFail {
5633 testCases = append(testCases, testCase{
5634 name: "ClientAuth-Sign-Negotiate" + suffix,
5635 config: Config{
5636 MaxVersion: ver.version,
5637 ClientAuth: RequireAnyClientCert,
5638 VerifySignatureAlgorithms: allAlgorithms,
5639 },
5640 flags: []string{
5641 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5642 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5643 "-enable-all-curves",
5644 "-signing-prefs", strconv.Itoa(int(alg.id)),
5645 },
5646 expectedPeerSignatureAlgorithm: alg.id,
5647 })
5648
5649 testCases = append(testCases, testCase{
5650 testType: serverTest,
5651 name: "ServerAuth-Sign-Negotiate" + suffix,
5652 config: Config{
5653 MaxVersion: ver.version,
5654 CipherSuites: signingCiphers,
5655 VerifySignatureAlgorithms: allAlgorithms,
5656 },
5657 flags: []string{
5658 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5659 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5660 "-enable-all-curves",
5661 "-signing-prefs", strconv.Itoa(int(alg.id)),
5662 },
5663 expectedPeerSignatureAlgorithm: alg.id,
5664 })
5665 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005666 }
David Benjamin000800a2014-11-14 01:43:59 -05005667 }
5668
Nick Harper60edffd2016-06-21 15:19:24 -07005669 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005670 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005671 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005672 config: Config{
5673 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005674 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005675 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005676 signatureECDSAWithP521AndSHA512,
5677 signatureRSAPKCS1WithSHA384,
5678 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005679 },
5680 },
5681 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005682 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5683 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005684 },
Nick Harper60edffd2016-06-21 15:19:24 -07005685 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005686 })
5687
5688 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005689 name: "ClientAuth-SignatureType-TLS13",
5690 config: Config{
5691 ClientAuth: RequireAnyClientCert,
5692 MaxVersion: VersionTLS13,
5693 VerifySignatureAlgorithms: []signatureAlgorithm{
5694 signatureECDSAWithP521AndSHA512,
5695 signatureRSAPKCS1WithSHA384,
5696 signatureRSAPSSWithSHA384,
5697 signatureECDSAWithSHA1,
5698 },
5699 },
5700 flags: []string{
5701 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5702 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5703 },
5704 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5705 })
5706
5707 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005708 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005709 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005710 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005711 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005712 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005713 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005714 signatureECDSAWithP521AndSHA512,
5715 signatureRSAPKCS1WithSHA384,
5716 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005717 },
5718 },
Nick Harper60edffd2016-06-21 15:19:24 -07005719 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005720 })
5721
Steven Valdez143e8b32016-07-11 13:19:03 -04005722 testCases = append(testCases, testCase{
5723 testType: serverTest,
5724 name: "ServerAuth-SignatureType-TLS13",
5725 config: Config{
5726 MaxVersion: VersionTLS13,
5727 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5728 VerifySignatureAlgorithms: []signatureAlgorithm{
5729 signatureECDSAWithP521AndSHA512,
5730 signatureRSAPKCS1WithSHA384,
5731 signatureRSAPSSWithSHA384,
5732 signatureECDSAWithSHA1,
5733 },
5734 },
5735 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5736 })
5737
David Benjamina95e9f32016-07-08 16:28:04 -07005738 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005739 testCases = append(testCases, testCase{
5740 testType: serverTest,
5741 name: "Verify-ClientAuth-SignatureType",
5742 config: Config{
5743 MaxVersion: VersionTLS12,
5744 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005745 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005746 signatureRSAPKCS1WithSHA256,
5747 },
5748 Bugs: ProtocolBugs{
5749 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5750 },
5751 },
5752 flags: []string{
5753 "-require-any-client-certificate",
5754 },
5755 shouldFail: true,
5756 expectedError: ":WRONG_SIGNATURE_TYPE:",
5757 })
5758
5759 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005760 testType: serverTest,
5761 name: "Verify-ClientAuth-SignatureType-TLS13",
5762 config: Config{
5763 MaxVersion: VersionTLS13,
5764 Certificates: []Certificate{rsaCertificate},
5765 SignSignatureAlgorithms: []signatureAlgorithm{
5766 signatureRSAPSSWithSHA256,
5767 },
5768 Bugs: ProtocolBugs{
5769 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5770 },
5771 },
5772 flags: []string{
5773 "-require-any-client-certificate",
5774 },
5775 shouldFail: true,
5776 expectedError: ":WRONG_SIGNATURE_TYPE:",
5777 })
5778
5779 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005780 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005781 config: Config{
5782 MaxVersion: VersionTLS12,
5783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005784 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005785 signatureRSAPKCS1WithSHA256,
5786 },
5787 Bugs: ProtocolBugs{
5788 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5789 },
5790 },
5791 shouldFail: true,
5792 expectedError: ":WRONG_SIGNATURE_TYPE:",
5793 })
5794
Steven Valdez143e8b32016-07-11 13:19:03 -04005795 testCases = append(testCases, testCase{
5796 name: "Verify-ServerAuth-SignatureType-TLS13",
5797 config: Config{
5798 MaxVersion: VersionTLS13,
5799 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5800 SignSignatureAlgorithms: []signatureAlgorithm{
5801 signatureRSAPSSWithSHA256,
5802 },
5803 Bugs: ProtocolBugs{
5804 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5805 },
5806 },
5807 shouldFail: true,
5808 expectedError: ":WRONG_SIGNATURE_TYPE:",
5809 })
5810
David Benjamin51dd7d62016-07-08 16:07:01 -07005811 // Test that, if the list is missing, the peer falls back to SHA-1 in
5812 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005813 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005814 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005816 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005817 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005818 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005819 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005820 },
5821 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005822 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005823 },
5824 },
5825 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005828 },
5829 })
5830
5831 testCases = append(testCases, testCase{
5832 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005833 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005834 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005835 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005836 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005837 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005838 },
5839 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005840 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005841 },
5842 },
David Benjaminee32bea2016-08-17 13:36:44 -04005843 flags: []string{
5844 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5845 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5846 },
5847 })
5848
5849 testCases = append(testCases, testCase{
5850 name: "ClientAuth-SHA1-Fallback-ECDSA",
5851 config: Config{
5852 MaxVersion: VersionTLS12,
5853 ClientAuth: RequireAnyClientCert,
5854 VerifySignatureAlgorithms: []signatureAlgorithm{
5855 signatureECDSAWithSHA1,
5856 },
5857 Bugs: ProtocolBugs{
5858 NoSignatureAlgorithms: true,
5859 },
5860 },
5861 flags: []string{
5862 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5863 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5864 },
5865 })
5866
5867 testCases = append(testCases, testCase{
5868 testType: serverTest,
5869 name: "ServerAuth-SHA1-Fallback-ECDSA",
5870 config: Config{
5871 MaxVersion: VersionTLS12,
5872 VerifySignatureAlgorithms: []signatureAlgorithm{
5873 signatureECDSAWithSHA1,
5874 },
5875 Bugs: ProtocolBugs{
5876 NoSignatureAlgorithms: true,
5877 },
5878 },
5879 flags: []string{
5880 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5881 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5882 },
David Benjamin000800a2014-11-14 01:43:59 -05005883 })
David Benjamin72dc7832015-03-16 17:49:43 -04005884
David Benjamin51dd7d62016-07-08 16:07:01 -07005885 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005886 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005887 config: Config{
5888 MaxVersion: VersionTLS13,
5889 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005890 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005891 signatureRSAPKCS1WithSHA1,
5892 },
5893 Bugs: ProtocolBugs{
5894 NoSignatureAlgorithms: true,
5895 },
5896 },
5897 flags: []string{
5898 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5899 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5900 },
David Benjamin48901652016-08-01 12:12:47 -04005901 shouldFail: true,
5902 // An empty CertificateRequest signature algorithm list is a
5903 // syntax error in TLS 1.3.
5904 expectedError: ":DECODE_ERROR:",
5905 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005906 })
5907
5908 testCases = append(testCases, testCase{
5909 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005910 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005911 config: Config{
5912 MaxVersion: VersionTLS13,
5913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005914 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005915 signatureRSAPKCS1WithSHA1,
5916 },
5917 Bugs: ProtocolBugs{
5918 NoSignatureAlgorithms: true,
5919 },
5920 },
5921 shouldFail: true,
5922 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5923 })
5924
David Benjaminb62d2872016-07-18 14:55:02 +02005925 // Test that hash preferences are enforced. BoringSSL does not implement
5926 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005927 testCases = append(testCases, testCase{
5928 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005929 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005930 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005931 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005932 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005933 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005934 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005935 },
5936 Bugs: ProtocolBugs{
5937 IgnorePeerSignatureAlgorithmPreferences: true,
5938 },
5939 },
5940 flags: []string{"-require-any-client-certificate"},
5941 shouldFail: true,
5942 expectedError: ":WRONG_SIGNATURE_TYPE:",
5943 })
5944
5945 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005946 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005947 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005948 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005950 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005951 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005952 },
5953 Bugs: ProtocolBugs{
5954 IgnorePeerSignatureAlgorithmPreferences: true,
5955 },
5956 },
5957 shouldFail: true,
5958 expectedError: ":WRONG_SIGNATURE_TYPE:",
5959 })
David Benjaminb62d2872016-07-18 14:55:02 +02005960 testCases = append(testCases, testCase{
5961 testType: serverTest,
5962 name: "ClientAuth-Enforced-TLS13",
5963 config: Config{
5964 MaxVersion: VersionTLS13,
5965 Certificates: []Certificate{rsaCertificate},
5966 SignSignatureAlgorithms: []signatureAlgorithm{
5967 signatureRSAPKCS1WithMD5,
5968 },
5969 Bugs: ProtocolBugs{
5970 IgnorePeerSignatureAlgorithmPreferences: true,
5971 IgnoreSignatureVersionChecks: true,
5972 },
5973 },
5974 flags: []string{"-require-any-client-certificate"},
5975 shouldFail: true,
5976 expectedError: ":WRONG_SIGNATURE_TYPE:",
5977 })
5978
5979 testCases = append(testCases, testCase{
5980 name: "ServerAuth-Enforced-TLS13",
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5984 SignSignatureAlgorithms: []signatureAlgorithm{
5985 signatureRSAPKCS1WithMD5,
5986 },
5987 Bugs: ProtocolBugs{
5988 IgnorePeerSignatureAlgorithmPreferences: true,
5989 IgnoreSignatureVersionChecks: true,
5990 },
5991 },
5992 shouldFail: true,
5993 expectedError: ":WRONG_SIGNATURE_TYPE:",
5994 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005995
5996 // Test that the agreed upon digest respects the client preferences and
5997 // the server digests.
5998 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005999 name: "NoCommonAlgorithms-Digests",
6000 config: Config{
6001 MaxVersion: VersionTLS12,
6002 ClientAuth: RequireAnyClientCert,
6003 VerifySignatureAlgorithms: []signatureAlgorithm{
6004 signatureRSAPKCS1WithSHA512,
6005 signatureRSAPKCS1WithSHA1,
6006 },
6007 },
6008 flags: []string{
6009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6011 "-digest-prefs", "SHA256",
6012 },
6013 shouldFail: true,
6014 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6015 })
6016 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006017 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006018 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 signatureRSAPKCS1WithSHA512,
6023 signatureRSAPKCS1WithSHA1,
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 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006030 },
David Benjaminca3d5452016-07-14 12:51:01 -04006031 shouldFail: true,
6032 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6033 })
6034 testCases = append(testCases, testCase{
6035 name: "NoCommonAlgorithms-TLS13",
6036 config: Config{
6037 MaxVersion: VersionTLS13,
6038 ClientAuth: RequireAnyClientCert,
6039 VerifySignatureAlgorithms: []signatureAlgorithm{
6040 signatureRSAPSSWithSHA512,
6041 signatureRSAPSSWithSHA384,
6042 },
6043 },
6044 flags: []string{
6045 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6046 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6047 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6048 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006049 shouldFail: true,
6050 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006051 })
6052 testCases = append(testCases, testCase{
6053 name: "Agree-Digest-SHA256",
6054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006055 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006056 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006057 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006058 signatureRSAPKCS1WithSHA1,
6059 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006060 },
6061 },
6062 flags: []string{
6063 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6064 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006065 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006066 },
Nick Harper60edffd2016-06-21 15:19:24 -07006067 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006068 })
6069 testCases = append(testCases, testCase{
6070 name: "Agree-Digest-SHA1",
6071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006072 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006073 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006074 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006075 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006076 },
6077 },
6078 flags: []string{
6079 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6080 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006081 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006082 },
Nick Harper60edffd2016-06-21 15:19:24 -07006083 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006084 })
6085 testCases = append(testCases, testCase{
6086 name: "Agree-Digest-Default",
6087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006088 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006089 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006090 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006091 signatureRSAPKCS1WithSHA256,
6092 signatureECDSAWithP256AndSHA256,
6093 signatureRSAPKCS1WithSHA1,
6094 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006095 },
6096 },
6097 flags: []string{
6098 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6099 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6100 },
Nick Harper60edffd2016-06-21 15:19:24 -07006101 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006102 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006103
David Benjaminca3d5452016-07-14 12:51:01 -04006104 // Test that the signing preference list may include extra algorithms
6105 // without negotiation problems.
6106 testCases = append(testCases, testCase{
6107 testType: serverTest,
6108 name: "FilterExtraAlgorithms",
6109 config: Config{
6110 MaxVersion: VersionTLS12,
6111 VerifySignatureAlgorithms: []signatureAlgorithm{
6112 signatureRSAPKCS1WithSHA256,
6113 },
6114 },
6115 flags: []string{
6116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6118 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6119 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6120 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6121 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6122 },
6123 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6124 })
6125
David Benjamin4c3ddf72016-06-29 18:13:53 -04006126 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6127 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006128 testCases = append(testCases, testCase{
6129 name: "CheckLeafCurve",
6130 config: Config{
6131 MaxVersion: VersionTLS12,
6132 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006133 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006134 },
6135 flags: []string{"-p384-only"},
6136 shouldFail: true,
6137 expectedError: ":BAD_ECC_CERT:",
6138 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006139
6140 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6141 testCases = append(testCases, testCase{
6142 name: "CheckLeafCurve-TLS13",
6143 config: Config{
6144 MaxVersion: VersionTLS13,
6145 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6146 Certificates: []Certificate{ecdsaP256Certificate},
6147 },
6148 flags: []string{"-p384-only"},
6149 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006150
6151 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6152 testCases = append(testCases, testCase{
6153 name: "ECDSACurveMismatch-Verify-TLS12",
6154 config: Config{
6155 MaxVersion: VersionTLS12,
6156 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6157 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006158 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006159 signatureECDSAWithP384AndSHA384,
6160 },
6161 },
6162 })
6163
6164 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6165 testCases = append(testCases, testCase{
6166 name: "ECDSACurveMismatch-Verify-TLS13",
6167 config: Config{
6168 MaxVersion: VersionTLS13,
6169 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6170 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006171 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006172 signatureECDSAWithP384AndSHA384,
6173 },
6174 Bugs: ProtocolBugs{
6175 SkipECDSACurveCheck: true,
6176 },
6177 },
6178 shouldFail: true,
6179 expectedError: ":WRONG_SIGNATURE_TYPE:",
6180 })
6181
6182 // Signature algorithm selection in TLS 1.3 should take the curve into
6183 // account.
6184 testCases = append(testCases, testCase{
6185 testType: serverTest,
6186 name: "ECDSACurveMismatch-Sign-TLS13",
6187 config: Config{
6188 MaxVersion: VersionTLS13,
6189 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006190 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006191 signatureECDSAWithP384AndSHA384,
6192 signatureECDSAWithP256AndSHA256,
6193 },
6194 },
6195 flags: []string{
6196 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6197 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6198 },
6199 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6200 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006201
6202 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6203 // server does not attempt to sign in that case.
6204 testCases = append(testCases, testCase{
6205 testType: serverTest,
6206 name: "RSA-PSS-Large",
6207 config: Config{
6208 MaxVersion: VersionTLS13,
6209 VerifySignatureAlgorithms: []signatureAlgorithm{
6210 signatureRSAPSSWithSHA512,
6211 },
6212 },
6213 flags: []string{
6214 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6215 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6216 },
6217 shouldFail: true,
6218 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6219 })
David Benjamin000800a2014-11-14 01:43:59 -05006220}
6221
David Benjamin83f90402015-01-27 01:09:43 -05006222// timeouts is the retransmit schedule for BoringSSL. It doubles and
6223// caps at 60 seconds. On the 13th timeout, it gives up.
6224var timeouts = []time.Duration{
6225 1 * time.Second,
6226 2 * time.Second,
6227 4 * time.Second,
6228 8 * time.Second,
6229 16 * time.Second,
6230 32 * time.Second,
6231 60 * time.Second,
6232 60 * time.Second,
6233 60 * time.Second,
6234 60 * time.Second,
6235 60 * time.Second,
6236 60 * time.Second,
6237 60 * time.Second,
6238}
6239
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006240// shortTimeouts is an alternate set of timeouts which would occur if the
6241// initial timeout duration was set to 250ms.
6242var shortTimeouts = []time.Duration{
6243 250 * time.Millisecond,
6244 500 * time.Millisecond,
6245 1 * time.Second,
6246 2 * time.Second,
6247 4 * time.Second,
6248 8 * time.Second,
6249 16 * time.Second,
6250 32 * time.Second,
6251 60 * time.Second,
6252 60 * time.Second,
6253 60 * time.Second,
6254 60 * time.Second,
6255 60 * time.Second,
6256}
6257
David Benjamin83f90402015-01-27 01:09:43 -05006258func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006259 // These tests work by coordinating some behavior on both the shim and
6260 // the runner.
6261 //
6262 // TimeoutSchedule configures the runner to send a series of timeout
6263 // opcodes to the shim (see packetAdaptor) immediately before reading
6264 // each peer handshake flight N. The timeout opcode both simulates a
6265 // timeout in the shim and acts as a synchronization point to help the
6266 // runner bracket each handshake flight.
6267 //
6268 // We assume the shim does not read from the channel eagerly. It must
6269 // first wait until it has sent flight N and is ready to receive
6270 // handshake flight N+1. At this point, it will process the timeout
6271 // opcode. It must then immediately respond with a timeout ACK and act
6272 // as if the shim was idle for the specified amount of time.
6273 //
6274 // The runner then drops all packets received before the ACK and
6275 // continues waiting for flight N. This ordering results in one attempt
6276 // at sending flight N to be dropped. For the test to complete, the
6277 // shim must send flight N again, testing that the shim implements DTLS
6278 // retransmit on a timeout.
6279
Steven Valdez143e8b32016-07-11 13:19:03 -04006280 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006281 // likely be more epochs to cross and the final message's retransmit may
6282 // be more complex.
6283
David Benjamin585d7a42016-06-02 14:58:00 -04006284 for _, async := range []bool{true, false} {
6285 var tests []testCase
6286
6287 // Test that this is indeed the timeout schedule. Stress all
6288 // four patterns of handshake.
6289 for i := 1; i < len(timeouts); i++ {
6290 number := strconv.Itoa(i)
6291 tests = append(tests, testCase{
6292 protocol: dtls,
6293 name: "DTLS-Retransmit-Client-" + number,
6294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006296 Bugs: ProtocolBugs{
6297 TimeoutSchedule: timeouts[:i],
6298 },
6299 },
6300 resumeSession: true,
6301 })
6302 tests = append(tests, testCase{
6303 protocol: dtls,
6304 testType: serverTest,
6305 name: "DTLS-Retransmit-Server-" + number,
6306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006307 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006308 Bugs: ProtocolBugs{
6309 TimeoutSchedule: timeouts[:i],
6310 },
6311 },
6312 resumeSession: true,
6313 })
6314 }
6315
6316 // Test that exceeding the timeout schedule hits a read
6317 // timeout.
6318 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006319 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006320 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006322 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006323 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006324 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006325 },
6326 },
6327 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006328 shouldFail: true,
6329 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006330 })
David Benjamin585d7a42016-06-02 14:58:00 -04006331
6332 if async {
6333 // Test that timeout handling has a fudge factor, due to API
6334 // problems.
6335 tests = append(tests, testCase{
6336 protocol: dtls,
6337 name: "DTLS-Retransmit-Fudge",
6338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006339 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006340 Bugs: ProtocolBugs{
6341 TimeoutSchedule: []time.Duration{
6342 timeouts[0] - 10*time.Millisecond,
6343 },
6344 },
6345 },
6346 resumeSession: true,
6347 })
6348 }
6349
6350 // Test that the final Finished retransmitting isn't
6351 // duplicated if the peer badly fragments everything.
6352 tests = append(tests, testCase{
6353 testType: serverTest,
6354 protocol: dtls,
6355 name: "DTLS-Retransmit-Fragmented",
6356 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006357 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006358 Bugs: ProtocolBugs{
6359 TimeoutSchedule: []time.Duration{timeouts[0]},
6360 MaxHandshakeRecordLength: 2,
6361 },
6362 },
6363 })
6364
6365 // Test the timeout schedule when a shorter initial timeout duration is set.
6366 tests = append(tests, testCase{
6367 protocol: dtls,
6368 name: "DTLS-Retransmit-Short-Client",
6369 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006370 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006371 Bugs: ProtocolBugs{
6372 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6373 },
6374 },
6375 resumeSession: true,
6376 flags: []string{"-initial-timeout-duration-ms", "250"},
6377 })
6378 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006379 protocol: dtls,
6380 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006381 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006383 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006384 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006385 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006386 },
6387 },
6388 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006389 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006390 })
David Benjamin585d7a42016-06-02 14:58:00 -04006391
6392 for _, test := range tests {
6393 if async {
6394 test.name += "-Async"
6395 test.flags = append(test.flags, "-async")
6396 }
6397
6398 testCases = append(testCases, test)
6399 }
David Benjamin83f90402015-01-27 01:09:43 -05006400 }
David Benjamin83f90402015-01-27 01:09:43 -05006401}
6402
David Benjaminc565ebb2015-04-03 04:06:36 -04006403func addExportKeyingMaterialTests() {
6404 for _, vers := range tlsVersions {
6405 if vers.version == VersionSSL30 {
6406 continue
6407 }
6408 testCases = append(testCases, testCase{
6409 name: "ExportKeyingMaterial-" + vers.name,
6410 config: Config{
6411 MaxVersion: vers.version,
6412 },
6413 exportKeyingMaterial: 1024,
6414 exportLabel: "label",
6415 exportContext: "context",
6416 useExportContext: true,
6417 })
6418 testCases = append(testCases, testCase{
6419 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6420 config: Config{
6421 MaxVersion: vers.version,
6422 },
6423 exportKeyingMaterial: 1024,
6424 })
6425 testCases = append(testCases, testCase{
6426 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6427 config: Config{
6428 MaxVersion: vers.version,
6429 },
6430 exportKeyingMaterial: 1024,
6431 useExportContext: true,
6432 })
6433 testCases = append(testCases, testCase{
6434 name: "ExportKeyingMaterial-Small-" + vers.name,
6435 config: Config{
6436 MaxVersion: vers.version,
6437 },
6438 exportKeyingMaterial: 1,
6439 exportLabel: "label",
6440 exportContext: "context",
6441 useExportContext: true,
6442 })
6443 }
6444 testCases = append(testCases, testCase{
6445 name: "ExportKeyingMaterial-SSL3",
6446 config: Config{
6447 MaxVersion: VersionSSL30,
6448 },
6449 exportKeyingMaterial: 1024,
6450 exportLabel: "label",
6451 exportContext: "context",
6452 useExportContext: true,
6453 shouldFail: true,
6454 expectedError: "failed to export keying material",
6455 })
6456}
6457
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006458func addTLSUniqueTests() {
6459 for _, isClient := range []bool{false, true} {
6460 for _, isResumption := range []bool{false, true} {
6461 for _, hasEMS := range []bool{false, true} {
6462 var suffix string
6463 if isResumption {
6464 suffix = "Resume-"
6465 } else {
6466 suffix = "Full-"
6467 }
6468
6469 if hasEMS {
6470 suffix += "EMS-"
6471 } else {
6472 suffix += "NoEMS-"
6473 }
6474
6475 if isClient {
6476 suffix += "Client"
6477 } else {
6478 suffix += "Server"
6479 }
6480
6481 test := testCase{
6482 name: "TLSUnique-" + suffix,
6483 testTLSUnique: true,
6484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006485 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006486 Bugs: ProtocolBugs{
6487 NoExtendedMasterSecret: !hasEMS,
6488 },
6489 },
6490 }
6491
6492 if isResumption {
6493 test.resumeSession = true
6494 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006495 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006496 Bugs: ProtocolBugs{
6497 NoExtendedMasterSecret: !hasEMS,
6498 },
6499 }
6500 }
6501
6502 if isResumption && !hasEMS {
6503 test.shouldFail = true
6504 test.expectedError = "failed to get tls-unique"
6505 }
6506
6507 testCases = append(testCases, test)
6508 }
6509 }
6510 }
6511}
6512
Adam Langley09505632015-07-30 18:10:13 -07006513func addCustomExtensionTests() {
6514 expectedContents := "custom extension"
6515 emptyString := ""
6516
6517 for _, isClient := range []bool{false, true} {
6518 suffix := "Server"
6519 flag := "-enable-server-custom-extension"
6520 testType := serverTest
6521 if isClient {
6522 suffix = "Client"
6523 flag = "-enable-client-custom-extension"
6524 testType = clientTest
6525 }
6526
6527 testCases = append(testCases, testCase{
6528 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006529 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006532 Bugs: ProtocolBugs{
6533 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006534 ExpectedCustomExtension: &expectedContents,
6535 },
6536 },
6537 flags: []string{flag},
6538 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006539 testCases = append(testCases, testCase{
6540 testType: testType,
6541 name: "CustomExtensions-" + suffix + "-TLS13",
6542 config: Config{
6543 MaxVersion: VersionTLS13,
6544 Bugs: ProtocolBugs{
6545 CustomExtension: expectedContents,
6546 ExpectedCustomExtension: &expectedContents,
6547 },
6548 },
6549 flags: []string{flag},
6550 })
Adam Langley09505632015-07-30 18:10:13 -07006551
6552 // If the parse callback fails, the handshake should also fail.
6553 testCases = append(testCases, testCase{
6554 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006555 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006557 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006558 Bugs: ProtocolBugs{
6559 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006560 ExpectedCustomExtension: &expectedContents,
6561 },
6562 },
David Benjamin399e7c92015-07-30 23:01:27 -04006563 flags: []string{flag},
6564 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006565 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6566 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006567 testCases = append(testCases, testCase{
6568 testType: testType,
6569 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6570 config: Config{
6571 MaxVersion: VersionTLS13,
6572 Bugs: ProtocolBugs{
6573 CustomExtension: expectedContents + "foo",
6574 ExpectedCustomExtension: &expectedContents,
6575 },
6576 },
6577 flags: []string{flag},
6578 shouldFail: true,
6579 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6580 })
Adam Langley09505632015-07-30 18:10:13 -07006581
6582 // If the add callback fails, the handshake should also fail.
6583 testCases = append(testCases, testCase{
6584 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006585 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006586 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006587 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006588 Bugs: ProtocolBugs{
6589 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006590 ExpectedCustomExtension: &expectedContents,
6591 },
6592 },
David Benjamin399e7c92015-07-30 23:01:27 -04006593 flags: []string{flag, "-custom-extension-fail-add"},
6594 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006595 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6596 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006597 testCases = append(testCases, testCase{
6598 testType: testType,
6599 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6600 config: Config{
6601 MaxVersion: VersionTLS13,
6602 Bugs: ProtocolBugs{
6603 CustomExtension: expectedContents,
6604 ExpectedCustomExtension: &expectedContents,
6605 },
6606 },
6607 flags: []string{flag, "-custom-extension-fail-add"},
6608 shouldFail: true,
6609 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6610 })
Adam Langley09505632015-07-30 18:10:13 -07006611
6612 // If the add callback returns zero, no extension should be
6613 // added.
6614 skipCustomExtension := expectedContents
6615 if isClient {
6616 // For the case where the client skips sending the
6617 // custom extension, the server must not “echo” it.
6618 skipCustomExtension = ""
6619 }
6620 testCases = append(testCases, testCase{
6621 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006622 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006623 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006624 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006625 Bugs: ProtocolBugs{
6626 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006627 ExpectedCustomExtension: &emptyString,
6628 },
6629 },
6630 flags: []string{flag, "-custom-extension-skip"},
6631 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006632 testCases = append(testCases, testCase{
6633 testType: testType,
6634 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6635 config: Config{
6636 MaxVersion: VersionTLS13,
6637 Bugs: ProtocolBugs{
6638 CustomExtension: skipCustomExtension,
6639 ExpectedCustomExtension: &emptyString,
6640 },
6641 },
6642 flags: []string{flag, "-custom-extension-skip"},
6643 })
Adam Langley09505632015-07-30 18:10:13 -07006644 }
6645
6646 // The custom extension add callback should not be called if the client
6647 // doesn't send the extension.
6648 testCases = append(testCases, testCase{
6649 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006650 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006651 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006652 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006653 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006654 ExpectedCustomExtension: &emptyString,
6655 },
6656 },
6657 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6658 })
Adam Langley2deb9842015-08-07 11:15:37 -07006659
Steven Valdez143e8b32016-07-11 13:19:03 -04006660 testCases = append(testCases, testCase{
6661 testType: serverTest,
6662 name: "CustomExtensions-NotCalled-Server-TLS13",
6663 config: Config{
6664 MaxVersion: VersionTLS13,
6665 Bugs: ProtocolBugs{
6666 ExpectedCustomExtension: &emptyString,
6667 },
6668 },
6669 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6670 })
6671
Adam Langley2deb9842015-08-07 11:15:37 -07006672 // Test an unknown extension from the server.
6673 testCases = append(testCases, testCase{
6674 testType: clientTest,
6675 name: "UnknownExtension-Client",
6676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006677 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006678 Bugs: ProtocolBugs{
6679 CustomExtension: expectedContents,
6680 },
6681 },
David Benjamin0c40a962016-08-01 12:05:50 -04006682 shouldFail: true,
6683 expectedError: ":UNEXPECTED_EXTENSION:",
6684 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006685 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006686 testCases = append(testCases, testCase{
6687 testType: clientTest,
6688 name: "UnknownExtension-Client-TLS13",
6689 config: Config{
6690 MaxVersion: VersionTLS13,
6691 Bugs: ProtocolBugs{
6692 CustomExtension: expectedContents,
6693 },
6694 },
David Benjamin0c40a962016-08-01 12:05:50 -04006695 shouldFail: true,
6696 expectedError: ":UNEXPECTED_EXTENSION:",
6697 expectedLocalError: "remote error: unsupported extension",
6698 })
6699
6700 // Test a known but unoffered extension from the server.
6701 testCases = append(testCases, testCase{
6702 testType: clientTest,
6703 name: "UnofferedExtension-Client",
6704 config: Config{
6705 MaxVersion: VersionTLS12,
6706 Bugs: ProtocolBugs{
6707 SendALPN: "alpn",
6708 },
6709 },
6710 shouldFail: true,
6711 expectedError: ":UNEXPECTED_EXTENSION:",
6712 expectedLocalError: "remote error: unsupported extension",
6713 })
6714 testCases = append(testCases, testCase{
6715 testType: clientTest,
6716 name: "UnofferedExtension-Client-TLS13",
6717 config: Config{
6718 MaxVersion: VersionTLS13,
6719 Bugs: ProtocolBugs{
6720 SendALPN: "alpn",
6721 },
6722 },
6723 shouldFail: true,
6724 expectedError: ":UNEXPECTED_EXTENSION:",
6725 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006726 })
Adam Langley09505632015-07-30 18:10:13 -07006727}
6728
David Benjaminb36a3952015-12-01 18:53:13 -05006729func addRSAClientKeyExchangeTests() {
6730 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6731 testCases = append(testCases, testCase{
6732 testType: serverTest,
6733 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6734 config: Config{
6735 // Ensure the ClientHello version and final
6736 // version are different, to detect if the
6737 // server uses the wrong one.
6738 MaxVersion: VersionTLS11,
6739 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6740 Bugs: ProtocolBugs{
6741 BadRSAClientKeyExchange: bad,
6742 },
6743 },
6744 shouldFail: true,
6745 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6746 })
6747 }
6748}
6749
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006750var testCurves = []struct {
6751 name string
6752 id CurveID
6753}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006754 {"P-256", CurveP256},
6755 {"P-384", CurveP384},
6756 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006757 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006758}
6759
Steven Valdez5440fe02016-07-18 12:40:30 -04006760const bogusCurve = 0x1234
6761
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006762func addCurveTests() {
6763 for _, curve := range testCurves {
6764 testCases = append(testCases, testCase{
6765 name: "CurveTest-Client-" + curve.name,
6766 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006767 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006768 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6769 CurvePreferences: []CurveID{curve.id},
6770 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006771 flags: []string{"-enable-all-curves"},
6772 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006773 })
6774 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006775 name: "CurveTest-Client-" + curve.name + "-TLS13",
6776 config: Config{
6777 MaxVersion: VersionTLS13,
6778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6779 CurvePreferences: []CurveID{curve.id},
6780 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006781 flags: []string{"-enable-all-curves"},
6782 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006783 })
6784 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006785 testType: serverTest,
6786 name: "CurveTest-Server-" + curve.name,
6787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006788 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6790 CurvePreferences: []CurveID{curve.id},
6791 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006792 flags: []string{"-enable-all-curves"},
6793 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006794 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006795 testCases = append(testCases, testCase{
6796 testType: serverTest,
6797 name: "CurveTest-Server-" + curve.name + "-TLS13",
6798 config: Config{
6799 MaxVersion: VersionTLS13,
6800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6801 CurvePreferences: []CurveID{curve.id},
6802 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006803 flags: []string{"-enable-all-curves"},
6804 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006805 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006806 }
David Benjamin241ae832016-01-15 03:04:54 -05006807
6808 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006809 testCases = append(testCases, testCase{
6810 testType: serverTest,
6811 name: "UnknownCurve",
6812 config: Config{
6813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6814 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6815 },
6816 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006817
6818 // The server must not consider ECDHE ciphers when there are no
6819 // supported curves.
6820 testCases = append(testCases, testCase{
6821 testType: serverTest,
6822 name: "NoSupportedCurves",
6823 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006824 MaxVersion: VersionTLS12,
6825 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6826 Bugs: ProtocolBugs{
6827 NoSupportedCurves: true,
6828 },
6829 },
6830 shouldFail: true,
6831 expectedError: ":NO_SHARED_CIPHER:",
6832 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006833 testCases = append(testCases, testCase{
6834 testType: serverTest,
6835 name: "NoSupportedCurves-TLS13",
6836 config: Config{
6837 MaxVersion: VersionTLS13,
6838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6839 Bugs: ProtocolBugs{
6840 NoSupportedCurves: true,
6841 },
6842 },
6843 shouldFail: true,
6844 expectedError: ":NO_SHARED_CIPHER:",
6845 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006846
6847 // The server must fall back to another cipher when there are no
6848 // supported curves.
6849 testCases = append(testCases, testCase{
6850 testType: serverTest,
6851 name: "NoCommonCurves",
6852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 CipherSuites: []uint16{
6855 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6856 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6857 },
6858 CurvePreferences: []CurveID{CurveP224},
6859 },
6860 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6861 })
6862
6863 // The client must reject bogus curves and disabled curves.
6864 testCases = append(testCases, testCase{
6865 name: "BadECDHECurve",
6866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006867 MaxVersion: VersionTLS12,
6868 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6869 Bugs: ProtocolBugs{
6870 SendCurve: bogusCurve,
6871 },
6872 },
6873 shouldFail: true,
6874 expectedError: ":WRONG_CURVE:",
6875 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006876 testCases = append(testCases, testCase{
6877 name: "BadECDHECurve-TLS13",
6878 config: Config{
6879 MaxVersion: VersionTLS13,
6880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6881 Bugs: ProtocolBugs{
6882 SendCurve: bogusCurve,
6883 },
6884 },
6885 shouldFail: true,
6886 expectedError: ":WRONG_CURVE:",
6887 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006888
6889 testCases = append(testCases, testCase{
6890 name: "UnsupportedCurve",
6891 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006892 MaxVersion: VersionTLS12,
6893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6894 CurvePreferences: []CurveID{CurveP256},
6895 Bugs: ProtocolBugs{
6896 IgnorePeerCurvePreferences: true,
6897 },
6898 },
6899 flags: []string{"-p384-only"},
6900 shouldFail: true,
6901 expectedError: ":WRONG_CURVE:",
6902 })
6903
David Benjamin4f921572016-07-17 14:20:10 +02006904 testCases = append(testCases, testCase{
6905 // TODO(davidben): Add a TLS 1.3 version where
6906 // HelloRetryRequest requests an unsupported curve.
6907 name: "UnsupportedCurve-ServerHello-TLS13",
6908 config: Config{
6909 MaxVersion: VersionTLS12,
6910 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6911 CurvePreferences: []CurveID{CurveP384},
6912 Bugs: ProtocolBugs{
6913 SendCurve: CurveP256,
6914 },
6915 },
6916 flags: []string{"-p384-only"},
6917 shouldFail: true,
6918 expectedError: ":WRONG_CURVE:",
6919 })
6920
David Benjamin4c3ddf72016-06-29 18:13:53 -04006921 // Test invalid curve points.
6922 testCases = append(testCases, testCase{
6923 name: "InvalidECDHPoint-Client",
6924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006925 MaxVersion: VersionTLS12,
6926 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6927 CurvePreferences: []CurveID{CurveP256},
6928 Bugs: ProtocolBugs{
6929 InvalidECDHPoint: true,
6930 },
6931 },
6932 shouldFail: true,
6933 expectedError: ":INVALID_ENCODING:",
6934 })
6935 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006936 name: "InvalidECDHPoint-Client-TLS13",
6937 config: Config{
6938 MaxVersion: VersionTLS13,
6939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6940 CurvePreferences: []CurveID{CurveP256},
6941 Bugs: ProtocolBugs{
6942 InvalidECDHPoint: true,
6943 },
6944 },
6945 shouldFail: true,
6946 expectedError: ":INVALID_ENCODING:",
6947 })
6948 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006949 testType: serverTest,
6950 name: "InvalidECDHPoint-Server",
6951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006952 MaxVersion: VersionTLS12,
6953 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6954 CurvePreferences: []CurveID{CurveP256},
6955 Bugs: ProtocolBugs{
6956 InvalidECDHPoint: true,
6957 },
6958 },
6959 shouldFail: true,
6960 expectedError: ":INVALID_ENCODING:",
6961 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006962 testCases = append(testCases, testCase{
6963 testType: serverTest,
6964 name: "InvalidECDHPoint-Server-TLS13",
6965 config: Config{
6966 MaxVersion: VersionTLS13,
6967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6968 CurvePreferences: []CurveID{CurveP256},
6969 Bugs: ProtocolBugs{
6970 InvalidECDHPoint: true,
6971 },
6972 },
6973 shouldFail: true,
6974 expectedError: ":INVALID_ENCODING:",
6975 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006976}
6977
Matt Braithwaite54217e42016-06-13 13:03:47 -07006978func addCECPQ1Tests() {
6979 testCases = append(testCases, testCase{
6980 testType: clientTest,
6981 name: "CECPQ1-Client-BadX25519Part",
6982 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006983 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006984 MinVersion: VersionTLS12,
6985 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6986 Bugs: ProtocolBugs{
6987 CECPQ1BadX25519Part: true,
6988 },
6989 },
6990 flags: []string{"-cipher", "kCECPQ1"},
6991 shouldFail: true,
6992 expectedLocalError: "local error: bad record MAC",
6993 })
6994 testCases = append(testCases, testCase{
6995 testType: clientTest,
6996 name: "CECPQ1-Client-BadNewhopePart",
6997 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006998 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006999 MinVersion: VersionTLS12,
7000 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7001 Bugs: ProtocolBugs{
7002 CECPQ1BadNewhopePart: true,
7003 },
7004 },
7005 flags: []string{"-cipher", "kCECPQ1"},
7006 shouldFail: true,
7007 expectedLocalError: "local error: bad record MAC",
7008 })
7009 testCases = append(testCases, testCase{
7010 testType: serverTest,
7011 name: "CECPQ1-Server-BadX25519Part",
7012 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007013 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007014 MinVersion: VersionTLS12,
7015 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7016 Bugs: ProtocolBugs{
7017 CECPQ1BadX25519Part: true,
7018 },
7019 },
7020 flags: []string{"-cipher", "kCECPQ1"},
7021 shouldFail: true,
7022 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7023 })
7024 testCases = append(testCases, testCase{
7025 testType: serverTest,
7026 name: "CECPQ1-Server-BadNewhopePart",
7027 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007028 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007029 MinVersion: VersionTLS12,
7030 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7031 Bugs: ProtocolBugs{
7032 CECPQ1BadNewhopePart: true,
7033 },
7034 },
7035 flags: []string{"-cipher", "kCECPQ1"},
7036 shouldFail: true,
7037 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7038 })
7039}
7040
David Benjamin4cc36ad2015-12-19 14:23:26 -05007041func addKeyExchangeInfoTests() {
7042 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05007043 name: "KeyExchangeInfo-DHE-Client",
7044 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007045 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007046 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7047 Bugs: ProtocolBugs{
7048 // This is a 1234-bit prime number, generated
7049 // with:
7050 // openssl gendh 1234 | openssl asn1parse -i
7051 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7052 },
7053 },
David Benjamin9e68f192016-06-30 14:55:33 -04007054 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007055 })
7056 testCases = append(testCases, testCase{
7057 testType: serverTest,
7058 name: "KeyExchangeInfo-DHE-Server",
7059 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007060 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007061 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7062 },
7063 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007064 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007065 })
7066
7067 testCases = append(testCases, testCase{
7068 name: "KeyExchangeInfo-ECDHE-Client",
7069 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007070 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007071 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7072 CurvePreferences: []CurveID{CurveX25519},
7073 },
David Benjamin9e68f192016-06-30 14:55:33 -04007074 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007075 })
7076 testCases = append(testCases, testCase{
7077 testType: serverTest,
7078 name: "KeyExchangeInfo-ECDHE-Server",
7079 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007080 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7082 CurvePreferences: []CurveID{CurveX25519},
7083 },
David Benjamin9e68f192016-06-30 14:55:33 -04007084 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007085 })
7086}
7087
David Benjaminc9ae27c2016-06-24 22:56:37 -04007088func addTLS13RecordTests() {
7089 testCases = append(testCases, testCase{
7090 name: "TLS13-RecordPadding",
7091 config: Config{
7092 MaxVersion: VersionTLS13,
7093 MinVersion: VersionTLS13,
7094 Bugs: ProtocolBugs{
7095 RecordPadding: 10,
7096 },
7097 },
7098 })
7099
7100 testCases = append(testCases, testCase{
7101 name: "TLS13-EmptyRecords",
7102 config: Config{
7103 MaxVersion: VersionTLS13,
7104 MinVersion: VersionTLS13,
7105 Bugs: ProtocolBugs{
7106 OmitRecordContents: true,
7107 },
7108 },
7109 shouldFail: true,
7110 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7111 })
7112
7113 testCases = append(testCases, testCase{
7114 name: "TLS13-OnlyPadding",
7115 config: Config{
7116 MaxVersion: VersionTLS13,
7117 MinVersion: VersionTLS13,
7118 Bugs: ProtocolBugs{
7119 OmitRecordContents: true,
7120 RecordPadding: 10,
7121 },
7122 },
7123 shouldFail: true,
7124 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7125 })
7126
7127 testCases = append(testCases, testCase{
7128 name: "TLS13-WrongOuterRecord",
7129 config: Config{
7130 MaxVersion: VersionTLS13,
7131 MinVersion: VersionTLS13,
7132 Bugs: ProtocolBugs{
7133 OuterRecordType: recordTypeHandshake,
7134 },
7135 },
7136 shouldFail: true,
7137 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7138 })
7139}
7140
David Benjamin82261be2016-07-07 14:32:50 -07007141func addChangeCipherSpecTests() {
7142 // Test missing ChangeCipherSpecs.
7143 testCases = append(testCases, testCase{
7144 name: "SkipChangeCipherSpec-Client",
7145 config: Config{
7146 MaxVersion: VersionTLS12,
7147 Bugs: ProtocolBugs{
7148 SkipChangeCipherSpec: true,
7149 },
7150 },
7151 shouldFail: true,
7152 expectedError: ":UNEXPECTED_RECORD:",
7153 })
7154 testCases = append(testCases, testCase{
7155 testType: serverTest,
7156 name: "SkipChangeCipherSpec-Server",
7157 config: Config{
7158 MaxVersion: VersionTLS12,
7159 Bugs: ProtocolBugs{
7160 SkipChangeCipherSpec: true,
7161 },
7162 },
7163 shouldFail: true,
7164 expectedError: ":UNEXPECTED_RECORD:",
7165 })
7166 testCases = append(testCases, testCase{
7167 testType: serverTest,
7168 name: "SkipChangeCipherSpec-Server-NPN",
7169 config: Config{
7170 MaxVersion: VersionTLS12,
7171 NextProtos: []string{"bar"},
7172 Bugs: ProtocolBugs{
7173 SkipChangeCipherSpec: true,
7174 },
7175 },
7176 flags: []string{
7177 "-advertise-npn", "\x03foo\x03bar\x03baz",
7178 },
7179 shouldFail: true,
7180 expectedError: ":UNEXPECTED_RECORD:",
7181 })
7182
7183 // Test synchronization between the handshake and ChangeCipherSpec.
7184 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7185 // rejected. Test both with and without handshake packing to handle both
7186 // when the partial post-CCS message is in its own record and when it is
7187 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007188 for _, packed := range []bool{false, true} {
7189 var suffix string
7190 if packed {
7191 suffix = "-Packed"
7192 }
7193
7194 testCases = append(testCases, testCase{
7195 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7196 config: Config{
7197 MaxVersion: VersionTLS12,
7198 Bugs: ProtocolBugs{
7199 FragmentAcrossChangeCipherSpec: true,
7200 PackHandshakeFlight: packed,
7201 },
7202 },
7203 shouldFail: true,
7204 expectedError: ":UNEXPECTED_RECORD:",
7205 })
7206 testCases = append(testCases, testCase{
7207 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7208 config: Config{
7209 MaxVersion: VersionTLS12,
7210 },
7211 resumeSession: true,
7212 resumeConfig: &Config{
7213 MaxVersion: VersionTLS12,
7214 Bugs: ProtocolBugs{
7215 FragmentAcrossChangeCipherSpec: true,
7216 PackHandshakeFlight: packed,
7217 },
7218 },
7219 shouldFail: true,
7220 expectedError: ":UNEXPECTED_RECORD:",
7221 })
7222 testCases = append(testCases, testCase{
7223 testType: serverTest,
7224 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 Bugs: ProtocolBugs{
7228 FragmentAcrossChangeCipherSpec: true,
7229 PackHandshakeFlight: packed,
7230 },
7231 },
7232 shouldFail: true,
7233 expectedError: ":UNEXPECTED_RECORD:",
7234 })
7235 testCases = append(testCases, testCase{
7236 testType: serverTest,
7237 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7238 config: Config{
7239 MaxVersion: VersionTLS12,
7240 },
7241 resumeSession: true,
7242 resumeConfig: &Config{
7243 MaxVersion: VersionTLS12,
7244 Bugs: ProtocolBugs{
7245 FragmentAcrossChangeCipherSpec: true,
7246 PackHandshakeFlight: packed,
7247 },
7248 },
7249 shouldFail: true,
7250 expectedError: ":UNEXPECTED_RECORD:",
7251 })
7252 testCases = append(testCases, testCase{
7253 testType: serverTest,
7254 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7255 config: Config{
7256 MaxVersion: VersionTLS12,
7257 NextProtos: []string{"bar"},
7258 Bugs: ProtocolBugs{
7259 FragmentAcrossChangeCipherSpec: true,
7260 PackHandshakeFlight: packed,
7261 },
7262 },
7263 flags: []string{
7264 "-advertise-npn", "\x03foo\x03bar\x03baz",
7265 },
7266 shouldFail: true,
7267 expectedError: ":UNEXPECTED_RECORD:",
7268 })
7269 }
7270
David Benjamin61672812016-07-14 23:10:43 -04007271 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7272 // messages in the handshake queue. Do this by testing the server
7273 // reading the client Finished, reversing the flight so Finished comes
7274 // first.
7275 testCases = append(testCases, testCase{
7276 protocol: dtls,
7277 testType: serverTest,
7278 name: "SendUnencryptedFinished-DTLS",
7279 config: Config{
7280 MaxVersion: VersionTLS12,
7281 Bugs: ProtocolBugs{
7282 SendUnencryptedFinished: true,
7283 ReverseHandshakeFragments: true,
7284 },
7285 },
7286 shouldFail: true,
7287 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7288 })
7289
Steven Valdez143e8b32016-07-11 13:19:03 -04007290 // Test synchronization between encryption changes and the handshake in
7291 // TLS 1.3, where ChangeCipherSpec is implicit.
7292 testCases = append(testCases, testCase{
7293 name: "PartialEncryptedExtensionsWithServerHello",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 Bugs: ProtocolBugs{
7297 PartialEncryptedExtensionsWithServerHello: true,
7298 },
7299 },
7300 shouldFail: true,
7301 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7302 })
7303 testCases = append(testCases, testCase{
7304 testType: serverTest,
7305 name: "PartialClientFinishedWithClientHello",
7306 config: Config{
7307 MaxVersion: VersionTLS13,
7308 Bugs: ProtocolBugs{
7309 PartialClientFinishedWithClientHello: true,
7310 },
7311 },
7312 shouldFail: true,
7313 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7314 })
7315
David Benjamin82261be2016-07-07 14:32:50 -07007316 // Test that early ChangeCipherSpecs are handled correctly.
7317 testCases = append(testCases, testCase{
7318 testType: serverTest,
7319 name: "EarlyChangeCipherSpec-server-1",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 Bugs: ProtocolBugs{
7323 EarlyChangeCipherSpec: 1,
7324 },
7325 },
7326 shouldFail: true,
7327 expectedError: ":UNEXPECTED_RECORD:",
7328 })
7329 testCases = append(testCases, testCase{
7330 testType: serverTest,
7331 name: "EarlyChangeCipherSpec-server-2",
7332 config: Config{
7333 MaxVersion: VersionTLS12,
7334 Bugs: ProtocolBugs{
7335 EarlyChangeCipherSpec: 2,
7336 },
7337 },
7338 shouldFail: true,
7339 expectedError: ":UNEXPECTED_RECORD:",
7340 })
7341 testCases = append(testCases, testCase{
7342 protocol: dtls,
7343 name: "StrayChangeCipherSpec",
7344 config: Config{
7345 // TODO(davidben): Once DTLS 1.3 exists, test
7346 // that stray ChangeCipherSpec messages are
7347 // rejected.
7348 MaxVersion: VersionTLS12,
7349 Bugs: ProtocolBugs{
7350 StrayChangeCipherSpec: true,
7351 },
7352 },
7353 })
7354
7355 // Test that the contents of ChangeCipherSpec are checked.
7356 testCases = append(testCases, testCase{
7357 name: "BadChangeCipherSpec-1",
7358 config: Config{
7359 MaxVersion: VersionTLS12,
7360 Bugs: ProtocolBugs{
7361 BadChangeCipherSpec: []byte{2},
7362 },
7363 },
7364 shouldFail: true,
7365 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7366 })
7367 testCases = append(testCases, testCase{
7368 name: "BadChangeCipherSpec-2",
7369 config: Config{
7370 MaxVersion: VersionTLS12,
7371 Bugs: ProtocolBugs{
7372 BadChangeCipherSpec: []byte{1, 1},
7373 },
7374 },
7375 shouldFail: true,
7376 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7377 })
7378 testCases = append(testCases, testCase{
7379 protocol: dtls,
7380 name: "BadChangeCipherSpec-DTLS-1",
7381 config: Config{
7382 MaxVersion: VersionTLS12,
7383 Bugs: ProtocolBugs{
7384 BadChangeCipherSpec: []byte{2},
7385 },
7386 },
7387 shouldFail: true,
7388 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7389 })
7390 testCases = append(testCases, testCase{
7391 protocol: dtls,
7392 name: "BadChangeCipherSpec-DTLS-2",
7393 config: Config{
7394 MaxVersion: VersionTLS12,
7395 Bugs: ProtocolBugs{
7396 BadChangeCipherSpec: []byte{1, 1},
7397 },
7398 },
7399 shouldFail: true,
7400 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7401 })
7402}
7403
David Benjamin0b8d5da2016-07-15 00:39:56 -04007404func addWrongMessageTypeTests() {
7405 for _, protocol := range []protocol{tls, dtls} {
7406 var suffix string
7407 if protocol == dtls {
7408 suffix = "-DTLS"
7409 }
7410
7411 testCases = append(testCases, testCase{
7412 protocol: protocol,
7413 testType: serverTest,
7414 name: "WrongMessageType-ClientHello" + suffix,
7415 config: Config{
7416 MaxVersion: VersionTLS12,
7417 Bugs: ProtocolBugs{
7418 SendWrongMessageType: typeClientHello,
7419 },
7420 },
7421 shouldFail: true,
7422 expectedError: ":UNEXPECTED_MESSAGE:",
7423 expectedLocalError: "remote error: unexpected message",
7424 })
7425
7426 if protocol == dtls {
7427 testCases = append(testCases, testCase{
7428 protocol: protocol,
7429 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7430 config: Config{
7431 MaxVersion: VersionTLS12,
7432 Bugs: ProtocolBugs{
7433 SendWrongMessageType: typeHelloVerifyRequest,
7434 },
7435 },
7436 shouldFail: true,
7437 expectedError: ":UNEXPECTED_MESSAGE:",
7438 expectedLocalError: "remote error: unexpected message",
7439 })
7440 }
7441
7442 testCases = append(testCases, testCase{
7443 protocol: protocol,
7444 name: "WrongMessageType-ServerHello" + suffix,
7445 config: Config{
7446 MaxVersion: VersionTLS12,
7447 Bugs: ProtocolBugs{
7448 SendWrongMessageType: typeServerHello,
7449 },
7450 },
7451 shouldFail: true,
7452 expectedError: ":UNEXPECTED_MESSAGE:",
7453 expectedLocalError: "remote error: unexpected message",
7454 })
7455
7456 testCases = append(testCases, testCase{
7457 protocol: protocol,
7458 name: "WrongMessageType-ServerCertificate" + suffix,
7459 config: Config{
7460 MaxVersion: VersionTLS12,
7461 Bugs: ProtocolBugs{
7462 SendWrongMessageType: typeCertificate,
7463 },
7464 },
7465 shouldFail: true,
7466 expectedError: ":UNEXPECTED_MESSAGE:",
7467 expectedLocalError: "remote error: unexpected message",
7468 })
7469
7470 testCases = append(testCases, testCase{
7471 protocol: protocol,
7472 name: "WrongMessageType-CertificateStatus" + suffix,
7473 config: Config{
7474 MaxVersion: VersionTLS12,
7475 Bugs: ProtocolBugs{
7476 SendWrongMessageType: typeCertificateStatus,
7477 },
7478 },
7479 flags: []string{"-enable-ocsp-stapling"},
7480 shouldFail: true,
7481 expectedError: ":UNEXPECTED_MESSAGE:",
7482 expectedLocalError: "remote error: unexpected message",
7483 })
7484
7485 testCases = append(testCases, testCase{
7486 protocol: protocol,
7487 name: "WrongMessageType-ServerKeyExchange" + suffix,
7488 config: Config{
7489 MaxVersion: VersionTLS12,
7490 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7491 Bugs: ProtocolBugs{
7492 SendWrongMessageType: typeServerKeyExchange,
7493 },
7494 },
7495 shouldFail: true,
7496 expectedError: ":UNEXPECTED_MESSAGE:",
7497 expectedLocalError: "remote error: unexpected message",
7498 })
7499
7500 testCases = append(testCases, testCase{
7501 protocol: protocol,
7502 name: "WrongMessageType-CertificateRequest" + suffix,
7503 config: Config{
7504 MaxVersion: VersionTLS12,
7505 ClientAuth: RequireAnyClientCert,
7506 Bugs: ProtocolBugs{
7507 SendWrongMessageType: typeCertificateRequest,
7508 },
7509 },
7510 shouldFail: true,
7511 expectedError: ":UNEXPECTED_MESSAGE:",
7512 expectedLocalError: "remote error: unexpected message",
7513 })
7514
7515 testCases = append(testCases, testCase{
7516 protocol: protocol,
7517 name: "WrongMessageType-ServerHelloDone" + suffix,
7518 config: Config{
7519 MaxVersion: VersionTLS12,
7520 Bugs: ProtocolBugs{
7521 SendWrongMessageType: typeServerHelloDone,
7522 },
7523 },
7524 shouldFail: true,
7525 expectedError: ":UNEXPECTED_MESSAGE:",
7526 expectedLocalError: "remote error: unexpected message",
7527 })
7528
7529 testCases = append(testCases, testCase{
7530 testType: serverTest,
7531 protocol: protocol,
7532 name: "WrongMessageType-ClientCertificate" + suffix,
7533 config: Config{
7534 Certificates: []Certificate{rsaCertificate},
7535 MaxVersion: VersionTLS12,
7536 Bugs: ProtocolBugs{
7537 SendWrongMessageType: typeCertificate,
7538 },
7539 },
7540 flags: []string{"-require-any-client-certificate"},
7541 shouldFail: true,
7542 expectedError: ":UNEXPECTED_MESSAGE:",
7543 expectedLocalError: "remote error: unexpected message",
7544 })
7545
7546 testCases = append(testCases, testCase{
7547 testType: serverTest,
7548 protocol: protocol,
7549 name: "WrongMessageType-CertificateVerify" + suffix,
7550 config: Config{
7551 Certificates: []Certificate{rsaCertificate},
7552 MaxVersion: VersionTLS12,
7553 Bugs: ProtocolBugs{
7554 SendWrongMessageType: typeCertificateVerify,
7555 },
7556 },
7557 flags: []string{"-require-any-client-certificate"},
7558 shouldFail: true,
7559 expectedError: ":UNEXPECTED_MESSAGE:",
7560 expectedLocalError: "remote error: unexpected message",
7561 })
7562
7563 testCases = append(testCases, testCase{
7564 testType: serverTest,
7565 protocol: protocol,
7566 name: "WrongMessageType-ClientKeyExchange" + suffix,
7567 config: Config{
7568 MaxVersion: VersionTLS12,
7569 Bugs: ProtocolBugs{
7570 SendWrongMessageType: typeClientKeyExchange,
7571 },
7572 },
7573 shouldFail: true,
7574 expectedError: ":UNEXPECTED_MESSAGE:",
7575 expectedLocalError: "remote error: unexpected message",
7576 })
7577
7578 if protocol != dtls {
7579 testCases = append(testCases, testCase{
7580 testType: serverTest,
7581 protocol: protocol,
7582 name: "WrongMessageType-NextProtocol" + suffix,
7583 config: Config{
7584 MaxVersion: VersionTLS12,
7585 NextProtos: []string{"bar"},
7586 Bugs: ProtocolBugs{
7587 SendWrongMessageType: typeNextProtocol,
7588 },
7589 },
7590 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7591 shouldFail: true,
7592 expectedError: ":UNEXPECTED_MESSAGE:",
7593 expectedLocalError: "remote error: unexpected message",
7594 })
7595
7596 testCases = append(testCases, testCase{
7597 testType: serverTest,
7598 protocol: protocol,
7599 name: "WrongMessageType-ChannelID" + suffix,
7600 config: Config{
7601 MaxVersion: VersionTLS12,
7602 ChannelID: channelIDKey,
7603 Bugs: ProtocolBugs{
7604 SendWrongMessageType: typeChannelID,
7605 },
7606 },
7607 flags: []string{
7608 "-expect-channel-id",
7609 base64.StdEncoding.EncodeToString(channelIDBytes),
7610 },
7611 shouldFail: true,
7612 expectedError: ":UNEXPECTED_MESSAGE:",
7613 expectedLocalError: "remote error: unexpected message",
7614 })
7615 }
7616
7617 testCases = append(testCases, testCase{
7618 testType: serverTest,
7619 protocol: protocol,
7620 name: "WrongMessageType-ClientFinished" + suffix,
7621 config: Config{
7622 MaxVersion: VersionTLS12,
7623 Bugs: ProtocolBugs{
7624 SendWrongMessageType: typeFinished,
7625 },
7626 },
7627 shouldFail: true,
7628 expectedError: ":UNEXPECTED_MESSAGE:",
7629 expectedLocalError: "remote error: unexpected message",
7630 })
7631
7632 testCases = append(testCases, testCase{
7633 protocol: protocol,
7634 name: "WrongMessageType-NewSessionTicket" + suffix,
7635 config: Config{
7636 MaxVersion: VersionTLS12,
7637 Bugs: ProtocolBugs{
7638 SendWrongMessageType: typeNewSessionTicket,
7639 },
7640 },
7641 shouldFail: true,
7642 expectedError: ":UNEXPECTED_MESSAGE:",
7643 expectedLocalError: "remote error: unexpected message",
7644 })
7645
7646 testCases = append(testCases, testCase{
7647 protocol: protocol,
7648 name: "WrongMessageType-ServerFinished" + suffix,
7649 config: Config{
7650 MaxVersion: VersionTLS12,
7651 Bugs: ProtocolBugs{
7652 SendWrongMessageType: typeFinished,
7653 },
7654 },
7655 shouldFail: true,
7656 expectedError: ":UNEXPECTED_MESSAGE:",
7657 expectedLocalError: "remote error: unexpected message",
7658 })
7659
7660 }
7661}
7662
Steven Valdez143e8b32016-07-11 13:19:03 -04007663func addTLS13WrongMessageTypeTests() {
7664 testCases = append(testCases, testCase{
7665 testType: serverTest,
7666 name: "WrongMessageType-TLS13-ClientHello",
7667 config: Config{
7668 MaxVersion: VersionTLS13,
7669 Bugs: ProtocolBugs{
7670 SendWrongMessageType: typeClientHello,
7671 },
7672 },
7673 shouldFail: true,
7674 expectedError: ":UNEXPECTED_MESSAGE:",
7675 expectedLocalError: "remote error: unexpected message",
7676 })
7677
7678 testCases = append(testCases, testCase{
7679 name: "WrongMessageType-TLS13-ServerHello",
7680 config: Config{
7681 MaxVersion: VersionTLS13,
7682 Bugs: ProtocolBugs{
7683 SendWrongMessageType: typeServerHello,
7684 },
7685 },
7686 shouldFail: true,
7687 expectedError: ":UNEXPECTED_MESSAGE:",
7688 // The alert comes in with the wrong encryption.
7689 expectedLocalError: "local error: bad record MAC",
7690 })
7691
7692 testCases = append(testCases, testCase{
7693 name: "WrongMessageType-TLS13-EncryptedExtensions",
7694 config: Config{
7695 MaxVersion: VersionTLS13,
7696 Bugs: ProtocolBugs{
7697 SendWrongMessageType: typeEncryptedExtensions,
7698 },
7699 },
7700 shouldFail: true,
7701 expectedError: ":UNEXPECTED_MESSAGE:",
7702 expectedLocalError: "remote error: unexpected message",
7703 })
7704
7705 testCases = append(testCases, testCase{
7706 name: "WrongMessageType-TLS13-CertificateRequest",
7707 config: Config{
7708 MaxVersion: VersionTLS13,
7709 ClientAuth: RequireAnyClientCert,
7710 Bugs: ProtocolBugs{
7711 SendWrongMessageType: typeCertificateRequest,
7712 },
7713 },
7714 shouldFail: true,
7715 expectedError: ":UNEXPECTED_MESSAGE:",
7716 expectedLocalError: "remote error: unexpected message",
7717 })
7718
7719 testCases = append(testCases, testCase{
7720 name: "WrongMessageType-TLS13-ServerCertificate",
7721 config: Config{
7722 MaxVersion: VersionTLS13,
7723 Bugs: ProtocolBugs{
7724 SendWrongMessageType: typeCertificate,
7725 },
7726 },
7727 shouldFail: true,
7728 expectedError: ":UNEXPECTED_MESSAGE:",
7729 expectedLocalError: "remote error: unexpected message",
7730 })
7731
7732 testCases = append(testCases, testCase{
7733 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7734 config: Config{
7735 MaxVersion: VersionTLS13,
7736 Bugs: ProtocolBugs{
7737 SendWrongMessageType: typeCertificateVerify,
7738 },
7739 },
7740 shouldFail: true,
7741 expectedError: ":UNEXPECTED_MESSAGE:",
7742 expectedLocalError: "remote error: unexpected message",
7743 })
7744
7745 testCases = append(testCases, testCase{
7746 name: "WrongMessageType-TLS13-ServerFinished",
7747 config: Config{
7748 MaxVersion: VersionTLS13,
7749 Bugs: ProtocolBugs{
7750 SendWrongMessageType: typeFinished,
7751 },
7752 },
7753 shouldFail: true,
7754 expectedError: ":UNEXPECTED_MESSAGE:",
7755 expectedLocalError: "remote error: unexpected message",
7756 })
7757
7758 testCases = append(testCases, testCase{
7759 testType: serverTest,
7760 name: "WrongMessageType-TLS13-ClientCertificate",
7761 config: Config{
7762 Certificates: []Certificate{rsaCertificate},
7763 MaxVersion: VersionTLS13,
7764 Bugs: ProtocolBugs{
7765 SendWrongMessageType: typeCertificate,
7766 },
7767 },
7768 flags: []string{"-require-any-client-certificate"},
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_MESSAGE:",
7771 expectedLocalError: "remote error: unexpected message",
7772 })
7773
7774 testCases = append(testCases, testCase{
7775 testType: serverTest,
7776 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7777 config: Config{
7778 Certificates: []Certificate{rsaCertificate},
7779 MaxVersion: VersionTLS13,
7780 Bugs: ProtocolBugs{
7781 SendWrongMessageType: typeCertificateVerify,
7782 },
7783 },
7784 flags: []string{"-require-any-client-certificate"},
7785 shouldFail: true,
7786 expectedError: ":UNEXPECTED_MESSAGE:",
7787 expectedLocalError: "remote error: unexpected message",
7788 })
7789
7790 testCases = append(testCases, testCase{
7791 testType: serverTest,
7792 name: "WrongMessageType-TLS13-ClientFinished",
7793 config: Config{
7794 MaxVersion: VersionTLS13,
7795 Bugs: ProtocolBugs{
7796 SendWrongMessageType: typeFinished,
7797 },
7798 },
7799 shouldFail: true,
7800 expectedError: ":UNEXPECTED_MESSAGE:",
7801 expectedLocalError: "remote error: unexpected message",
7802 })
7803}
7804
7805func addTLS13HandshakeTests() {
7806 testCases = append(testCases, testCase{
7807 testType: clientTest,
7808 name: "MissingKeyShare-Client",
7809 config: Config{
7810 MaxVersion: VersionTLS13,
7811 Bugs: ProtocolBugs{
7812 MissingKeyShare: true,
7813 },
7814 },
7815 shouldFail: true,
7816 expectedError: ":MISSING_KEY_SHARE:",
7817 })
7818
7819 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007820 testType: serverTest,
7821 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007822 config: Config{
7823 MaxVersion: VersionTLS13,
7824 Bugs: ProtocolBugs{
7825 MissingKeyShare: true,
7826 },
7827 },
7828 shouldFail: true,
7829 expectedError: ":MISSING_KEY_SHARE:",
7830 })
7831
7832 testCases = append(testCases, testCase{
7833 testType: clientTest,
7834 name: "ClientHelloMissingKeyShare",
7835 config: Config{
7836 MaxVersion: VersionTLS13,
7837 Bugs: ProtocolBugs{
7838 MissingKeyShare: true,
7839 },
7840 },
7841 shouldFail: true,
7842 expectedError: ":MISSING_KEY_SHARE:",
7843 })
7844
7845 testCases = append(testCases, testCase{
7846 testType: clientTest,
7847 name: "MissingKeyShare",
7848 config: Config{
7849 MaxVersion: VersionTLS13,
7850 Bugs: ProtocolBugs{
7851 MissingKeyShare: true,
7852 },
7853 },
7854 shouldFail: true,
7855 expectedError: ":MISSING_KEY_SHARE:",
7856 })
7857
7858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "DuplicateKeyShares",
7861 config: Config{
7862 MaxVersion: VersionTLS13,
7863 Bugs: ProtocolBugs{
7864 DuplicateKeyShares: true,
7865 },
7866 },
7867 })
7868
7869 testCases = append(testCases, testCase{
7870 testType: clientTest,
7871 name: "EmptyEncryptedExtensions",
7872 config: Config{
7873 MaxVersion: VersionTLS13,
7874 Bugs: ProtocolBugs{
7875 EmptyEncryptedExtensions: true,
7876 },
7877 },
7878 shouldFail: true,
7879 expectedLocalError: "remote error: error decoding message",
7880 })
7881
7882 testCases = append(testCases, testCase{
7883 testType: clientTest,
7884 name: "EncryptedExtensionsWithKeyShare",
7885 config: Config{
7886 MaxVersion: VersionTLS13,
7887 Bugs: ProtocolBugs{
7888 EncryptedExtensionsWithKeyShare: true,
7889 },
7890 },
7891 shouldFail: true,
7892 expectedLocalError: "remote error: unsupported extension",
7893 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007894
7895 testCases = append(testCases, testCase{
7896 testType: serverTest,
7897 name: "SendHelloRetryRequest",
7898 config: Config{
7899 MaxVersion: VersionTLS13,
7900 // Require a HelloRetryRequest for every curve.
7901 DefaultCurves: []CurveID{},
7902 },
7903 expectedCurveID: CurveX25519,
7904 })
7905
7906 testCases = append(testCases, testCase{
7907 testType: serverTest,
7908 name: "SendHelloRetryRequest-2",
7909 config: Config{
7910 MaxVersion: VersionTLS13,
7911 DefaultCurves: []CurveID{CurveP384},
7912 },
7913 // Although the ClientHello did not predict our preferred curve,
7914 // we always select it whether it is predicted or not.
7915 expectedCurveID: CurveX25519,
7916 })
7917
7918 testCases = append(testCases, testCase{
7919 name: "UnknownCurve-HelloRetryRequest",
7920 config: Config{
7921 MaxVersion: VersionTLS13,
7922 // P-384 requires HelloRetryRequest in BoringSSL.
7923 CurvePreferences: []CurveID{CurveP384},
7924 Bugs: ProtocolBugs{
7925 SendHelloRetryRequestCurve: bogusCurve,
7926 },
7927 },
7928 shouldFail: true,
7929 expectedError: ":WRONG_CURVE:",
7930 })
7931
7932 testCases = append(testCases, testCase{
7933 name: "DisabledCurve-HelloRetryRequest",
7934 config: Config{
7935 MaxVersion: VersionTLS13,
7936 CurvePreferences: []CurveID{CurveP256},
7937 Bugs: ProtocolBugs{
7938 IgnorePeerCurvePreferences: true,
7939 },
7940 },
7941 flags: []string{"-p384-only"},
7942 shouldFail: true,
7943 expectedError: ":WRONG_CURVE:",
7944 })
7945
7946 testCases = append(testCases, testCase{
7947 name: "UnnecessaryHelloRetryRequest",
7948 config: Config{
7949 MaxVersion: VersionTLS13,
7950 Bugs: ProtocolBugs{
7951 UnnecessaryHelloRetryRequest: true,
7952 },
7953 },
7954 shouldFail: true,
7955 expectedError: ":WRONG_CURVE:",
7956 })
7957
7958 testCases = append(testCases, testCase{
7959 name: "SecondHelloRetryRequest",
7960 config: Config{
7961 MaxVersion: VersionTLS13,
7962 // P-384 requires HelloRetryRequest in BoringSSL.
7963 CurvePreferences: []CurveID{CurveP384},
7964 Bugs: ProtocolBugs{
7965 SecondHelloRetryRequest: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":UNEXPECTED_MESSAGE:",
7970 })
7971
7972 testCases = append(testCases, testCase{
7973 testType: serverTest,
7974 name: "SecondClientHelloMissingKeyShare",
7975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 DefaultCurves: []CurveID{},
7978 Bugs: ProtocolBugs{
7979 SecondClientHelloMissingKeyShare: true,
7980 },
7981 },
7982 shouldFail: true,
7983 expectedError: ":MISSING_KEY_SHARE:",
7984 })
7985
7986 testCases = append(testCases, testCase{
7987 testType: serverTest,
7988 name: "SecondClientHelloWrongCurve",
7989 config: Config{
7990 MaxVersion: VersionTLS13,
7991 DefaultCurves: []CurveID{},
7992 Bugs: ProtocolBugs{
7993 MisinterpretHelloRetryRequestCurve: CurveP521,
7994 },
7995 },
7996 shouldFail: true,
7997 expectedError: ":WRONG_CURVE:",
7998 })
7999
8000 testCases = append(testCases, testCase{
8001 name: "HelloRetryRequestVersionMismatch",
8002 config: Config{
8003 MaxVersion: VersionTLS13,
8004 // P-384 requires HelloRetryRequest in BoringSSL.
8005 CurvePreferences: []CurveID{CurveP384},
8006 Bugs: ProtocolBugs{
8007 SendServerHelloVersion: 0x0305,
8008 },
8009 },
8010 shouldFail: true,
8011 expectedError: ":WRONG_VERSION_NUMBER:",
8012 })
8013
8014 testCases = append(testCases, testCase{
8015 name: "HelloRetryRequestCurveMismatch",
8016 config: Config{
8017 MaxVersion: VersionTLS13,
8018 // P-384 requires HelloRetryRequest in BoringSSL.
8019 CurvePreferences: []CurveID{CurveP384},
8020 Bugs: ProtocolBugs{
8021 // Send P-384 (correct) in the HelloRetryRequest.
8022 SendHelloRetryRequestCurve: CurveP384,
8023 // But send P-256 in the ServerHello.
8024 SendCurve: CurveP256,
8025 },
8026 },
8027 shouldFail: true,
8028 expectedError: ":WRONG_CURVE:",
8029 })
8030
8031 // Test the server selecting a curve that requires a HelloRetryRequest
8032 // without sending it.
8033 testCases = append(testCases, testCase{
8034 name: "SkipHelloRetryRequest",
8035 config: Config{
8036 MaxVersion: VersionTLS13,
8037 // P-384 requires HelloRetryRequest in BoringSSL.
8038 CurvePreferences: []CurveID{CurveP384},
8039 Bugs: ProtocolBugs{
8040 SkipHelloRetryRequest: true,
8041 },
8042 },
8043 shouldFail: true,
8044 expectedError: ":WRONG_CURVE:",
8045 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008046
8047 testCases = append(testCases, testCase{
8048 name: "TLS13-RequestContextInHandshake",
8049 config: Config{
8050 MaxVersion: VersionTLS13,
8051 MinVersion: VersionTLS13,
8052 ClientAuth: RequireAnyClientCert,
8053 Bugs: ProtocolBugs{
8054 SendRequestContext: []byte("request context"),
8055 },
8056 },
8057 flags: []string{
8058 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8059 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8060 },
8061 shouldFail: true,
8062 expectedError: ":DECODE_ERROR:",
8063 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008064}
8065
Adam Langley7c803a62015-06-15 15:35:05 -07008066func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008067 defer wg.Done()
8068
8069 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008070 var err error
8071
8072 if *mallocTest < 0 {
8073 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008074 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008075 } else {
8076 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8077 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008078 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008079 if err != nil {
8080 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8081 }
8082 break
8083 }
8084 }
8085 }
Adam Langley95c29f32014-06-20 12:00:00 -07008086 statusChan <- statusMsg{test: test, err: err}
8087 }
8088}
8089
8090type statusMsg struct {
8091 test *testCase
8092 started bool
8093 err error
8094}
8095
David Benjamin5f237bc2015-02-11 17:14:15 -05008096func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008097 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008098
David Benjamin5f237bc2015-02-11 17:14:15 -05008099 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008100 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008101 if !*pipe {
8102 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008103 var erase string
8104 for i := 0; i < lineLen; i++ {
8105 erase += "\b \b"
8106 }
8107 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008108 }
8109
Adam Langley95c29f32014-06-20 12:00:00 -07008110 if msg.started {
8111 started++
8112 } else {
8113 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008114
8115 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008116 if msg.err == errUnimplemented {
8117 if *pipe {
8118 // Print each test instead of a status line.
8119 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8120 }
8121 unimplemented++
8122 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8123 } else {
8124 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8125 failed++
8126 testOutput.addResult(msg.test.name, "FAIL")
8127 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008128 } else {
8129 if *pipe {
8130 // Print each test instead of a status line.
8131 fmt.Printf("PASSED (%s)\n", msg.test.name)
8132 }
8133 testOutput.addResult(msg.test.name, "PASS")
8134 }
Adam Langley95c29f32014-06-20 12:00:00 -07008135 }
8136
David Benjamin5f237bc2015-02-11 17:14:15 -05008137 if !*pipe {
8138 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008139 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008140 lineLen = len(line)
8141 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008142 }
Adam Langley95c29f32014-06-20 12:00:00 -07008143 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008144
8145 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008146}
8147
8148func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008149 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008150 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008151 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008152
Adam Langley7c803a62015-06-15 15:35:05 -07008153 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008154 addCipherSuiteTests()
8155 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008156 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008157 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008158 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008159 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008160 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008161 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008162 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008163 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008164 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008165 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008166 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008167 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008168 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008169 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008170 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008171 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008172 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008173 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008174 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008175 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008176 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008177 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008178 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008179 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008180 addTLS13WrongMessageTypeTests()
8181 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008182
8183 var wg sync.WaitGroup
8184
Adam Langley7c803a62015-06-15 15:35:05 -07008185 statusChan := make(chan statusMsg, *numWorkers)
8186 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008187 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008188
EKRf71d7ed2016-08-06 13:25:12 -07008189 if len(*shimConfigFile) != 0 {
8190 encoded, err := ioutil.ReadFile(*shimConfigFile)
8191 if err != nil {
8192 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8193 os.Exit(1)
8194 }
8195
8196 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8197 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8198 os.Exit(1)
8199 }
8200 }
8201
David Benjamin025b3d32014-07-01 19:53:04 -04008202 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008203
Adam Langley7c803a62015-06-15 15:35:05 -07008204 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008205 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008206 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008207 }
8208
David Benjamin270f0a72016-03-17 14:41:36 -04008209 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008210 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008211 matched := true
8212 if len(*testToRun) != 0 {
8213 var err error
8214 matched, err = filepath.Match(*testToRun, testCases[i].name)
8215 if err != nil {
8216 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8217 os.Exit(1)
8218 }
8219 }
8220
EKRf71d7ed2016-08-06 13:25:12 -07008221 if !*includeDisabled {
8222 for pattern := range shimConfig.DisabledTests {
8223 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8224 if err != nil {
8225 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8226 os.Exit(1)
8227 }
8228
8229 if isDisabled {
8230 matched = false
8231 break
8232 }
8233 }
8234 }
8235
David Benjamin17e12922016-07-28 18:04:43 -04008236 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008237 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008238 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008239 }
8240 }
David Benjamin17e12922016-07-28 18:04:43 -04008241
David Benjamin270f0a72016-03-17 14:41:36 -04008242 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008243 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008244 os.Exit(1)
8245 }
Adam Langley95c29f32014-06-20 12:00:00 -07008246
8247 close(testChan)
8248 wg.Wait()
8249 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008250 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008251
8252 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008253
8254 if *jsonOutput != "" {
8255 if err := testOutput.writeTo(*jsonOutput); err != nil {
8256 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8257 }
8258 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008259
EKR842ae6c2016-07-27 09:22:05 +02008260 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8261 os.Exit(1)
8262 }
8263
8264 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008265 os.Exit(1)
8266 }
Adam Langley95c29f32014-06-20 12:00:00 -07008267}