blob: 54e601b86baaa73bd9e6b31a2a3408f42433753b [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700297 // expectResumeRejected, if true, specifies that the attempted
298 // resumption must be rejected by the client. This is only valid for a
299 // serverTest.
300 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400301 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500302 // resumption. Unless newSessionsOnResume is set,
303 // SessionTicketKey, ServerSessionCache, and
304 // ClientSessionCache are copied from the initial connection's
305 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400306 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500307 // newSessionsOnResume, if true, will cause resumeConfig to
308 // use a different session resumption context.
309 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400310 // noSessionCache, if true, will cause the server to run without a
311 // session cache.
312 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400313 // sendPrefix sends a prefix on the socket before actually performing a
314 // handshake.
315 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400316 // shimWritesFirst controls whether the shim sends an initial "hello"
317 // message before doing a roundtrip with the runner.
318 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400319 // shimShutsDown, if true, runs a test where the shim shuts down the
320 // connection immediately after the handshake rather than echoing
321 // messages from the runner.
322 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400323 // renegotiate indicates the number of times the connection should be
324 // renegotiated during the exchange.
325 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400326 // sendHalfHelloRequest, if true, causes the server to send half a
327 // HelloRequest when the handshake completes.
328 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700329 // renegotiateCiphers is a list of ciphersuite ids that will be
330 // switched in just before renegotiation.
331 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500332 // replayWrites, if true, configures the underlying transport
333 // to replay every write it makes in DTLS tests.
334 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500335 // damageFirstWrite, if true, configures the underlying transport to
336 // damage the final byte of the first application data write.
337 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400338 // exportKeyingMaterial, if non-zero, configures the test to exchange
339 // keying material and verify they match.
340 exportKeyingMaterial int
341 exportLabel string
342 exportContext string
343 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400344 // flags, if not empty, contains a list of command-line flags that will
345 // be passed to the shim program.
346 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700347 // testTLSUnique, if true, causes the shim to send the tls-unique value
348 // which will be compared against the expected value.
349 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400350 // sendEmptyRecords is the number of consecutive empty records to send
351 // before and after the test message.
352 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400353 // sendWarningAlerts is the number of consecutive warning alerts to send
354 // before and after the test message.
355 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400356 // expectMessageDropped, if true, means the test message is expected to
357 // be dropped by the client rather than echoed back.
358 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700359}
360
Adam Langley7c803a62015-06-15 15:35:05 -0700361var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700362
David Benjamin9867b7d2016-03-01 23:25:48 -0500363func writeTranscript(test *testCase, isResume bool, data []byte) {
364 if len(data) == 0 {
365 return
366 }
367
368 protocol := "tls"
369 if test.protocol == dtls {
370 protocol = "dtls"
371 }
372
373 side := "client"
374 if test.testType == serverTest {
375 side = "server"
376 }
377
378 dir := path.Join(*transcriptDir, protocol, side)
379 if err := os.MkdirAll(dir, 0755); err != nil {
380 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
381 return
382 }
383
384 name := test.name
385 if isResume {
386 name += "-Resume"
387 } else {
388 name += "-Normal"
389 }
390
391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjamin8e6db492015-07-25 18:29:23 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
439 if *deterministic {
440 config.Rand = &deterministicRand{}
441 }
442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
467 writeTranscript(test, isResume, connDebug.Transcript())
468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
David Benjamina8ebe222015-06-06 03:04:39 -0400618 for i := 0; i < test.sendEmptyRecords; i++ {
619 tlsConn.Write(nil)
620 }
621
David Benjamin24f346d2015-06-06 03:28:08 -0400622 for i := 0; i < test.sendWarningAlerts; i++ {
623 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
624 }
625
David Benjamin47921102016-07-28 11:29:18 -0400626 if test.sendHalfHelloRequest {
627 tlsConn.SendHalfHelloRequest()
628 }
629
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400630 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700631 if test.renegotiateCiphers != nil {
632 config.CipherSuites = test.renegotiateCiphers
633 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400634 for i := 0; i < test.renegotiate; i++ {
635 if err := tlsConn.Renegotiate(); err != nil {
636 return err
637 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700638 }
639 } else if test.renegotiateCiphers != nil {
640 panic("renegotiateCiphers without renegotiate")
641 }
642
David Benjamin5fa3eba2015-01-22 16:35:40 -0500643 if test.damageFirstWrite {
644 connDamage.setDamage(true)
645 tlsConn.Write([]byte("DAMAGED WRITE"))
646 connDamage.setDamage(false)
647 }
648
David Benjamin8e6db492015-07-25 18:29:23 -0400649 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700650 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400651 if test.protocol == dtls {
652 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
653 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700654 // Read until EOF.
655 _, err := io.Copy(ioutil.Discard, tlsConn)
656 return err
657 }
David Benjamin4417d052015-04-05 04:17:25 -0400658 if messageLen == 0 {
659 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700660 }
Adam Langley95c29f32014-06-20 12:00:00 -0700661
David Benjamin8e6db492015-07-25 18:29:23 -0400662 messageCount := test.messageCount
663 if messageCount == 0 {
664 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400665 }
666
David Benjamin8e6db492015-07-25 18:29:23 -0400667 for j := 0; j < messageCount; j++ {
668 testMessage := make([]byte, messageLen)
669 for i := range testMessage {
670 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400671 }
David Benjamin8e6db492015-07-25 18:29:23 -0400672 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700673
David Benjamin8e6db492015-07-25 18:29:23 -0400674 for i := 0; i < test.sendEmptyRecords; i++ {
675 tlsConn.Write(nil)
676 }
677
678 for i := 0; i < test.sendWarningAlerts; i++ {
679 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
680 }
681
David Benjamin4f75aaf2015-09-01 16:53:10 -0400682 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400683 // The shim will not respond.
684 continue
685 }
686
David Benjamin8e6db492015-07-25 18:29:23 -0400687 buf := make([]byte, len(testMessage))
688 if test.protocol == dtls {
689 bufTmp := make([]byte, len(buf)+1)
690 n, err := tlsConn.Read(bufTmp)
691 if err != nil {
692 return err
693 }
694 if n != len(buf) {
695 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
696 }
697 copy(buf, bufTmp)
698 } else {
699 _, err := io.ReadFull(tlsConn, buf)
700 if err != nil {
701 return err
702 }
703 }
704
705 for i, v := range buf {
706 if v != testMessage[i]^0xff {
707 return fmt.Errorf("bad reply contents at byte %d", i)
708 }
Adam Langley95c29f32014-06-20 12:00:00 -0700709 }
710 }
711
712 return nil
713}
714
David Benjamin325b5c32014-07-01 19:40:31 -0400715func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
716 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700717 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400718 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700719 }
David Benjamin325b5c32014-07-01 19:40:31 -0400720 valgrindArgs = append(valgrindArgs, path)
721 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700722
David Benjamin325b5c32014-07-01 19:40:31 -0400723 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700724}
725
David Benjamin325b5c32014-07-01 19:40:31 -0400726func gdbOf(path string, args ...string) *exec.Cmd {
727 xtermArgs := []string{"-e", "gdb", "--args"}
728 xtermArgs = append(xtermArgs, path)
729 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700730
David Benjamin325b5c32014-07-01 19:40:31 -0400731 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732}
733
David Benjamind16bf342015-12-18 00:53:12 -0500734func lldbOf(path string, args ...string) *exec.Cmd {
735 xtermArgs := []string{"-e", "lldb", "--"}
736 xtermArgs = append(xtermArgs, path)
737 xtermArgs = append(xtermArgs, args...)
738
739 return exec.Command("xterm", xtermArgs...)
740}
741
EKR842ae6c2016-07-27 09:22:05 +0200742var (
743 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
744 errUnimplemented = errors.New("child process does not implement needed flags")
745)
Adam Langley69a01602014-11-17 17:26:55 -0800746
David Benjamin87c8a642015-02-21 01:54:29 -0500747// accept accepts a connection from listener, unless waitChan signals a process
748// exit first.
749func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
750 type connOrError struct {
751 conn net.Conn
752 err error
753 }
754 connChan := make(chan connOrError, 1)
755 go func() {
756 conn, err := listener.Accept()
757 connChan <- connOrError{conn, err}
758 close(connChan)
759 }()
760 select {
761 case result := <-connChan:
762 return result.conn, result.err
763 case childErr := <-waitChan:
764 waitChan <- childErr
765 return nil, fmt.Errorf("child exited early: %s", childErr)
766 }
767}
768
EKRf71d7ed2016-08-06 13:25:12 -0700769func translateExpectedError(errorStr string) string {
770 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
771 return translated
772 }
773
774 if *looseErrors {
775 return ""
776 }
777
778 return errorStr
779}
780
Adam Langley7c803a62015-06-15 15:35:05 -0700781func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700782 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
783 panic("Error expected without shouldFail in " + test.name)
784 }
785
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700786 if test.expectResumeRejected && !test.resumeSession {
787 panic("expectResumeRejected without resumeSession in " + test.name)
788 }
789
David Benjamin87c8a642015-02-21 01:54:29 -0500790 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
791 if err != nil {
792 panic(err)
793 }
794 defer func() {
795 if listener != nil {
796 listener.Close()
797 }
798 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700799
David Benjamin87c8a642015-02-21 01:54:29 -0500800 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400801 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400802 flags = append(flags, "-server")
803
David Benjamin025b3d32014-07-01 19:53:04 -0400804 flags = append(flags, "-key-file")
805 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700806 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400807 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700808 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400809 }
810
811 flags = append(flags, "-cert-file")
812 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700813 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400814 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700815 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400816 }
817 }
David Benjamin5a593af2014-08-11 19:51:50 -0400818
David Benjamin6fd297b2014-08-11 18:43:38 -0400819 if test.protocol == dtls {
820 flags = append(flags, "-dtls")
821 }
822
David Benjamin5a593af2014-08-11 19:51:50 -0400823 if test.resumeSession {
824 flags = append(flags, "-resume")
825 }
826
David Benjamine58c4f52014-08-24 03:47:07 -0400827 if test.shimWritesFirst {
828 flags = append(flags, "-shim-writes-first")
829 }
830
David Benjamin30789da2015-08-29 22:56:45 -0400831 if test.shimShutsDown {
832 flags = append(flags, "-shim-shuts-down")
833 }
834
David Benjaminc565ebb2015-04-03 04:06:36 -0400835 if test.exportKeyingMaterial > 0 {
836 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
837 flags = append(flags, "-export-label", test.exportLabel)
838 flags = append(flags, "-export-context", test.exportContext)
839 if test.useExportContext {
840 flags = append(flags, "-use-export-context")
841 }
842 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700843 if test.expectResumeRejected {
844 flags = append(flags, "-expect-session-miss")
845 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400846
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700847 if test.testTLSUnique {
848 flags = append(flags, "-tls-unique")
849 }
850
David Benjamin025b3d32014-07-01 19:53:04 -0400851 flags = append(flags, test.flags...)
852
853 var shim *exec.Cmd
854 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700855 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700856 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700857 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500858 } else if *useLLDB {
859 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400860 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700861 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400862 }
David Benjamin025b3d32014-07-01 19:53:04 -0400863 shim.Stdin = os.Stdin
864 var stdoutBuf, stderrBuf bytes.Buffer
865 shim.Stdout = &stdoutBuf
866 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800867 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500868 shim.Env = os.Environ()
869 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800870 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400871 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800872 }
873 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
874 }
David Benjamin025b3d32014-07-01 19:53:04 -0400875
876 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700877 panic(err)
878 }
David Benjamin87c8a642015-02-21 01:54:29 -0500879 waitChan := make(chan error, 1)
880 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700881
882 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700883
David Benjamin87c8a642015-02-21 01:54:29 -0500884 conn, err := acceptOrWait(listener, waitChan)
885 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400886 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500887 conn.Close()
888 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500889
David Benjamin1d5c83e2014-07-22 19:20:02 -0400890 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400891 var resumeConfig Config
892 if test.resumeConfig != nil {
893 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400894 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500895 resumeConfig.SessionTicketKey = config.SessionTicketKey
896 resumeConfig.ClientSessionCache = config.ClientSessionCache
897 resumeConfig.ServerSessionCache = config.ServerSessionCache
898 }
David Benjamin2e045a92016-06-08 13:09:56 -0400899 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400900 } else {
901 resumeConfig = config
902 }
David Benjamin87c8a642015-02-21 01:54:29 -0500903 var connResume net.Conn
904 connResume, err = acceptOrWait(listener, waitChan)
905 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400906 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500907 connResume.Close()
908 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400909 }
910
David Benjamin87c8a642015-02-21 01:54:29 -0500911 // Close the listener now. This is to avoid hangs should the shim try to
912 // open more connections than expected.
913 listener.Close()
914 listener = nil
915
916 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800917 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200918 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
919 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800920 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200921 case 89:
922 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800923 }
924 }
Adam Langley95c29f32014-06-20 12:00:00 -0700925
David Benjamin9bea3492016-03-02 10:59:16 -0500926 // Account for Windows line endings.
927 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
928 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500929
930 // Separate the errors from the shim and those from tools like
931 // AddressSanitizer.
932 var extraStderr string
933 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
934 stderr = stderrParts[0]
935 extraStderr = stderrParts[1]
936 }
937
Adam Langley95c29f32014-06-20 12:00:00 -0700938 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700939 expectedError := translateExpectedError(test.expectedError)
940 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200941
Adam Langleyac61fa32014-06-23 12:03:11 -0700942 localError := "none"
943 if err != nil {
944 localError = err.Error()
945 }
946 if len(test.expectedLocalError) != 0 {
947 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
948 }
Adam Langley95c29f32014-06-20 12:00:00 -0700949
950 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700951 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700952 if childErr != nil {
953 childError = childErr.Error()
954 }
955
956 var msg string
957 switch {
958 case failed && !test.shouldFail:
959 msg = "unexpected failure"
960 case !failed && test.shouldFail:
961 msg = "unexpected success"
962 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700963 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700964 default:
965 panic("internal error")
966 }
967
David Benjaminc565ebb2015-04-03 04:06:36 -0400968 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700969 }
970
David Benjaminff3a1492016-03-02 10:12:06 -0500971 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
972 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700973 }
974
975 return nil
976}
977
978var tlsVersions = []struct {
979 name string
980 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400981 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500982 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700983}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500984 {"SSL3", VersionSSL30, "-no-ssl3", false},
985 {"TLS1", VersionTLS10, "-no-tls1", true},
986 {"TLS11", VersionTLS11, "-no-tls11", false},
987 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400988 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700989}
990
991var testCipherSuites = []struct {
992 name string
993 id uint16
994}{
995 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400996 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700997 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400998 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400999 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001000 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001001 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001002 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1003 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001004 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001005 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1006 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001007 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001008 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1009 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001010 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1011 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001012 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001013 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001014 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001015 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001016 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001017 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001018 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001019 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001020 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001021 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001022 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001023 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001024 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001025 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001026 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1027 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1028 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1029 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001030 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1031 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001032 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1033 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001034 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001035 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1036 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001037 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001039 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001040 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001041}
1042
David Benjamin8b8c0062014-11-23 02:47:52 -05001043func hasComponent(suiteName, component string) bool {
1044 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1045}
1046
David Benjaminf7768e42014-08-31 02:06:47 -04001047func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001048 return hasComponent(suiteName, "GCM") ||
1049 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001050 hasComponent(suiteName, "SHA384") ||
1051 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001052}
1053
Nick Harper1fd39d82016-06-14 18:14:35 -07001054func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001055 // Only AEADs.
1056 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1057 return false
1058 }
1059 // No old CHACHA20_POLY1305.
1060 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1061 return false
1062 }
1063 // Must have ECDHE.
1064 // TODO(davidben,svaldez): Add pure PSK support.
1065 if !hasComponent(suiteName, "ECDHE") {
1066 return false
1067 }
1068 // TODO(davidben,svaldez): Add PSK support.
1069 if hasComponent(suiteName, "PSK") {
1070 return false
1071 }
1072 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001073}
1074
David Benjamin8b8c0062014-11-23 02:47:52 -05001075func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001076 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001077}
1078
Adam Langleya7997f12015-05-14 17:38:50 -07001079func bigFromHex(hex string) *big.Int {
1080 ret, ok := new(big.Int).SetString(hex, 16)
1081 if !ok {
1082 panic("failed to parse hex number 0x" + hex)
1083 }
1084 return ret
1085}
1086
Adam Langley7c803a62015-06-15 15:35:05 -07001087func addBasicTests() {
1088 basicTests := []testCase{
1089 {
Adam Langley7c803a62015-06-15 15:35:05 -07001090 name: "NoFallbackSCSV",
1091 config: Config{
1092 Bugs: ProtocolBugs{
1093 FailIfNotFallbackSCSV: true,
1094 },
1095 },
1096 shouldFail: true,
1097 expectedLocalError: "no fallback SCSV found",
1098 },
1099 {
1100 name: "SendFallbackSCSV",
1101 config: Config{
1102 Bugs: ProtocolBugs{
1103 FailIfNotFallbackSCSV: true,
1104 },
1105 },
1106 flags: []string{"-fallback-scsv"},
1107 },
1108 {
1109 name: "ClientCertificateTypes",
1110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001111 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001112 ClientAuth: RequestClientCert,
1113 ClientCertificateTypes: []byte{
1114 CertTypeDSSSign,
1115 CertTypeRSASign,
1116 CertTypeECDSASign,
1117 },
1118 },
1119 flags: []string{
1120 "-expect-certificate-types",
1121 base64.StdEncoding.EncodeToString([]byte{
1122 CertTypeDSSSign,
1123 CertTypeRSASign,
1124 CertTypeECDSASign,
1125 }),
1126 },
1127 },
1128 {
Adam Langley7c803a62015-06-15 15:35:05 -07001129 name: "UnauthenticatedECDH",
1130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001131 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001132 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1133 Bugs: ProtocolBugs{
1134 UnauthenticatedECDH: true,
1135 },
1136 },
1137 shouldFail: true,
1138 expectedError: ":UNEXPECTED_MESSAGE:",
1139 },
1140 {
1141 name: "SkipCertificateStatus",
1142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001143 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001144 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1145 Bugs: ProtocolBugs{
1146 SkipCertificateStatus: true,
1147 },
1148 },
1149 flags: []string{
1150 "-enable-ocsp-stapling",
1151 },
1152 },
1153 {
1154 name: "SkipServerKeyExchange",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 SkipServerKeyExchange: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
Adam Langley7c803a62015-06-15 15:35:05 -07001166 testType: serverTest,
1167 name: "Alert",
1168 config: Config{
1169 Bugs: ProtocolBugs{
1170 SendSpuriousAlert: alertRecordOverflow,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1175 },
1176 {
1177 protocol: dtls,
1178 testType: serverTest,
1179 name: "Alert-DTLS",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 SendSpuriousAlert: alertRecordOverflow,
1183 },
1184 },
1185 shouldFail: true,
1186 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1187 },
1188 {
1189 testType: serverTest,
1190 name: "FragmentAlert",
1191 config: Config{
1192 Bugs: ProtocolBugs{
1193 FragmentAlert: true,
1194 SendSpuriousAlert: alertRecordOverflow,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":BAD_ALERT:",
1199 },
1200 {
1201 protocol: dtls,
1202 testType: serverTest,
1203 name: "FragmentAlert-DTLS",
1204 config: Config{
1205 Bugs: ProtocolBugs{
1206 FragmentAlert: true,
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":BAD_ALERT:",
1212 },
1213 {
1214 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001215 name: "DoubleAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 DoubleAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "DoubleAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 DoubleAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
Adam Langley7c803a62015-06-15 15:35:05 -07001239 name: "SkipNewSessionTicket",
1240 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001241 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001242 Bugs: ProtocolBugs{
1243 SkipNewSessionTicket: true,
1244 },
1245 },
1246 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001247 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001248 },
1249 {
1250 testType: serverTest,
1251 name: "FallbackSCSV",
1252 config: Config{
1253 MaxVersion: VersionTLS11,
1254 Bugs: ProtocolBugs{
1255 SendFallbackSCSV: true,
1256 },
1257 },
1258 shouldFail: true,
1259 expectedError: ":INAPPROPRIATE_FALLBACK:",
1260 },
1261 {
1262 testType: serverTest,
1263 name: "FallbackSCSV-VersionMatch",
1264 config: Config{
1265 Bugs: ProtocolBugs{
1266 SendFallbackSCSV: true,
1267 },
1268 },
1269 },
1270 {
1271 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001272 name: "FallbackSCSV-VersionMatch-TLS12",
1273 config: Config{
1274 MaxVersion: VersionTLS12,
1275 Bugs: ProtocolBugs{
1276 SendFallbackSCSV: true,
1277 },
1278 },
1279 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1280 },
1281 {
1282 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001283 name: "FragmentedClientVersion",
1284 config: Config{
1285 Bugs: ProtocolBugs{
1286 MaxHandshakeRecordLength: 1,
1287 FragmentClientVersion: true,
1288 },
1289 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001290 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001291 },
1292 {
Adam Langley7c803a62015-06-15 15:35:05 -07001293 testType: serverTest,
1294 name: "HttpGET",
1295 sendPrefix: "GET / HTTP/1.0\n",
1296 shouldFail: true,
1297 expectedError: ":HTTP_REQUEST:",
1298 },
1299 {
1300 testType: serverTest,
1301 name: "HttpPOST",
1302 sendPrefix: "POST / HTTP/1.0\n",
1303 shouldFail: true,
1304 expectedError: ":HTTP_REQUEST:",
1305 },
1306 {
1307 testType: serverTest,
1308 name: "HttpHEAD",
1309 sendPrefix: "HEAD / HTTP/1.0\n",
1310 shouldFail: true,
1311 expectedError: ":HTTP_REQUEST:",
1312 },
1313 {
1314 testType: serverTest,
1315 name: "HttpPUT",
1316 sendPrefix: "PUT / HTTP/1.0\n",
1317 shouldFail: true,
1318 expectedError: ":HTTP_REQUEST:",
1319 },
1320 {
1321 testType: serverTest,
1322 name: "HttpCONNECT",
1323 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1324 shouldFail: true,
1325 expectedError: ":HTTPS_PROXY_REQUEST:",
1326 },
1327 {
1328 testType: serverTest,
1329 name: "Garbage",
1330 sendPrefix: "blah",
1331 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001332 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001333 },
1334 {
Adam Langley7c803a62015-06-15 15:35:05 -07001335 name: "RSAEphemeralKey",
1336 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001337 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001338 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1339 Bugs: ProtocolBugs{
1340 RSAEphemeralKey: true,
1341 },
1342 },
1343 shouldFail: true,
1344 expectedError: ":UNEXPECTED_MESSAGE:",
1345 },
1346 {
1347 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001348 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001349 shouldFail: true,
1350 expectedError: ":WRONG_SSL_VERSION:",
1351 },
1352 {
1353 protocol: dtls,
1354 name: "DisableEverything-DTLS",
1355 flags: []string{"-no-tls12", "-no-tls1"},
1356 shouldFail: true,
1357 expectedError: ":WRONG_SSL_VERSION:",
1358 },
1359 {
Adam Langley7c803a62015-06-15 15:35:05 -07001360 protocol: dtls,
1361 testType: serverTest,
1362 name: "MTU",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 MaxPacketLength: 256,
1366 },
1367 },
1368 flags: []string{"-mtu", "256"},
1369 },
1370 {
1371 protocol: dtls,
1372 testType: serverTest,
1373 name: "MTUExceeded",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 MaxPacketLength: 255,
1377 },
1378 },
1379 flags: []string{"-mtu", "256"},
1380 shouldFail: true,
1381 expectedLocalError: "dtls: exceeded maximum packet length",
1382 },
1383 {
1384 name: "CertMismatchRSA",
1385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001386 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001387 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001388 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001389 Bugs: ProtocolBugs{
1390 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1391 },
1392 },
1393 shouldFail: true,
1394 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1395 },
1396 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001397 name: "CertMismatchRSA-TLS13",
1398 config: Config{
1399 MaxVersion: VersionTLS13,
1400 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1401 Certificates: []Certificate{ecdsaP256Certificate},
1402 Bugs: ProtocolBugs{
1403 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1404 },
1405 },
1406 shouldFail: true,
1407 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1408 },
1409 {
Adam Langley7c803a62015-06-15 15:35:05 -07001410 name: "CertMismatchECDSA",
1411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001412 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001414 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001415 Bugs: ProtocolBugs{
1416 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1421 },
1422 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001423 name: "CertMismatchECDSA-TLS13",
1424 config: Config{
1425 MaxVersion: VersionTLS13,
1426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1427 Certificates: []Certificate{rsaCertificate},
1428 Bugs: ProtocolBugs{
1429 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1434 },
1435 {
Adam Langley7c803a62015-06-15 15:35:05 -07001436 name: "EmptyCertificateList",
1437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001438 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001439 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1440 Bugs: ProtocolBugs{
1441 EmptyCertificateList: true,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":DECODE_ERROR:",
1446 },
1447 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001448 name: "EmptyCertificateList-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Bugs: ProtocolBugs{
1453 EmptyCertificateList: true,
1454 },
1455 },
1456 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001457 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001458 },
1459 {
Adam Langley7c803a62015-06-15 15:35:05 -07001460 name: "TLSFatalBadPackets",
1461 damageFirstWrite: true,
1462 shouldFail: true,
1463 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1464 },
1465 {
1466 protocol: dtls,
1467 name: "DTLSIgnoreBadPackets",
1468 damageFirstWrite: true,
1469 },
1470 {
1471 protocol: dtls,
1472 name: "DTLSIgnoreBadPackets-Async",
1473 damageFirstWrite: true,
1474 flags: []string{"-async"},
1475 },
1476 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001477 name: "AppDataBeforeHandshake",
1478 config: Config{
1479 Bugs: ProtocolBugs{
1480 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":UNEXPECTED_RECORD:",
1485 },
1486 {
1487 name: "AppDataBeforeHandshake-Empty",
1488 config: Config{
1489 Bugs: ProtocolBugs{
1490 AppDataBeforeHandshake: []byte{},
1491 },
1492 },
1493 shouldFail: true,
1494 expectedError: ":UNEXPECTED_RECORD:",
1495 },
1496 {
1497 protocol: dtls,
1498 name: "AppDataBeforeHandshake-DTLS",
1499 config: Config{
1500 Bugs: ProtocolBugs{
1501 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":UNEXPECTED_RECORD:",
1506 },
1507 {
1508 protocol: dtls,
1509 name: "AppDataBeforeHandshake-DTLS-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
Adam Langley7c803a62015-06-15 15:35:05 -07001519 name: "AppDataAfterChangeCipherSpec",
1520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001521 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001522 Bugs: ProtocolBugs{
1523 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001527 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001528 },
1529 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001530 name: "AppDataAfterChangeCipherSpec-Empty",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte{},
1535 },
1536 },
1537 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001538 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 protocol: dtls,
1542 name: "AppDataAfterChangeCipherSpec-DTLS",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001545 Bugs: ProtocolBugs{
1546 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1547 },
1548 },
1549 // BoringSSL's DTLS implementation will drop the out-of-order
1550 // application data.
1551 },
1552 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001553 protocol: dtls,
1554 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1555 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001556 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 Bugs: ProtocolBugs{
1558 AppDataAfterChangeCipherSpec: []byte{},
1559 },
1560 },
1561 // BoringSSL's DTLS implementation will drop the out-of-order
1562 // application data.
1563 },
1564 {
Adam Langley7c803a62015-06-15 15:35:05 -07001565 name: "AlertAfterChangeCipherSpec",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001568 Bugs: ProtocolBugs{
1569 AlertAfterChangeCipherSpec: alertRecordOverflow,
1570 },
1571 },
1572 shouldFail: true,
1573 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1574 },
1575 {
1576 protocol: dtls,
1577 name: "AlertAfterChangeCipherSpec-DTLS",
1578 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001579 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001580 Bugs: ProtocolBugs{
1581 AlertAfterChangeCipherSpec: alertRecordOverflow,
1582 },
1583 },
1584 shouldFail: true,
1585 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1586 },
1587 {
1588 protocol: dtls,
1589 name: "ReorderHandshakeFragments-Small-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 // Small enough that every handshake message is
1594 // fragmented.
1595 MaxHandshakeRecordLength: 2,
1596 },
1597 },
1598 },
1599 {
1600 protocol: dtls,
1601 name: "ReorderHandshakeFragments-Large-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 ReorderHandshakeFragments: true,
1605 // Large enough that no handshake message is
1606 // fragmented.
1607 MaxHandshakeRecordLength: 2048,
1608 },
1609 },
1610 },
1611 {
1612 protocol: dtls,
1613 name: "MixCompleteMessageWithFragments-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 ReorderHandshakeFragments: true,
1617 MixCompleteMessageWithFragments: true,
1618 MaxHandshakeRecordLength: 2,
1619 },
1620 },
1621 },
1622 {
1623 name: "SendInvalidRecordType",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 SendInvalidRecordType: true,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":UNEXPECTED_RECORD:",
1631 },
1632 {
1633 protocol: dtls,
1634 name: "SendInvalidRecordType-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SendInvalidRecordType: true,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":UNEXPECTED_RECORD:",
1642 },
1643 {
1644 name: "FalseStart-SkipServerSecondLeg",
1645 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001646 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001647 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1648 NextProtos: []string{"foo"},
1649 Bugs: ProtocolBugs{
1650 SkipNewSessionTicket: true,
1651 SkipChangeCipherSpec: true,
1652 SkipFinished: true,
1653 ExpectFalseStart: true,
1654 },
1655 },
1656 flags: []string{
1657 "-false-start",
1658 "-handshake-never-done",
1659 "-advertise-alpn", "\x03foo",
1660 },
1661 shimWritesFirst: true,
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg-Implicit",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 },
1676 },
1677 flags: []string{
1678 "-implicit-handshake",
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shouldFail: true,
1684 expectedError: ":UNEXPECTED_RECORD:",
1685 },
1686 {
1687 testType: serverTest,
1688 name: "FailEarlyCallback",
1689 flags: []string{"-fail-early-callback"},
1690 shouldFail: true,
1691 expectedError: ":CONNECTION_REJECTED:",
1692 expectedLocalError: "remote error: access denied",
1693 },
1694 {
Adam Langley7c803a62015-06-15 15:35:05 -07001695 protocol: dtls,
1696 name: "FragmentMessageTypeMismatch-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 MaxHandshakeRecordLength: 2,
1700 FragmentMessageTypeMismatch: true,
1701 },
1702 },
1703 shouldFail: true,
1704 expectedError: ":FRAGMENT_MISMATCH:",
1705 },
1706 {
1707 protocol: dtls,
1708 name: "FragmentMessageLengthMismatch-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 MaxHandshakeRecordLength: 2,
1712 FragmentMessageLengthMismatch: true,
1713 },
1714 },
1715 shouldFail: true,
1716 expectedError: ":FRAGMENT_MISMATCH:",
1717 },
1718 {
1719 protocol: dtls,
1720 name: "SplitFragments-Header-DTLS",
1721 config: Config{
1722 Bugs: ProtocolBugs{
1723 SplitFragments: 2,
1724 },
1725 },
1726 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001727 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001728 },
1729 {
1730 protocol: dtls,
1731 name: "SplitFragments-Boundary-DTLS",
1732 config: Config{
1733 Bugs: ProtocolBugs{
1734 SplitFragments: dtlsRecordHeaderLen,
1735 },
1736 },
1737 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001738 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Body-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: dtlsRecordHeaderLen + 1,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SendEmptyFragments-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SendEmptyFragments: true,
1757 },
1758 },
1759 },
1760 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001761 name: "BadFinished-Client",
1762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001763 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001764 Bugs: ProtocolBugs{
1765 BadFinished: true,
1766 },
1767 },
1768 shouldFail: true,
1769 expectedError: ":DIGEST_CHECK_FAILED:",
1770 },
1771 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001772 name: "BadFinished-Client-TLS13",
1773 config: Config{
1774 MaxVersion: VersionTLS13,
1775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 testType: serverTest,
1784 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001786 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001795 testType: serverTest,
1796 name: "BadFinished-Server-TLS13",
1797 config: Config{
1798 MaxVersion: VersionTLS13,
1799 Bugs: ProtocolBugs{
1800 BadFinished: true,
1801 },
1802 },
1803 shouldFail: true,
1804 expectedError: ":DIGEST_CHECK_FAILED:",
1805 },
1806 {
Adam Langley7c803a62015-06-15 15:35:05 -07001807 name: "FalseStart-BadFinished",
1808 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1811 NextProtos: []string{"foo"},
1812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 ExpectFalseStart: true,
1815 },
1816 },
1817 flags: []string{
1818 "-false-start",
1819 "-handshake-never-done",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":DIGEST_CHECK_FAILED:",
1825 },
1826 {
1827 name: "NoFalseStart-NoALPN",
1828 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001829 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001830 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 },
1839 shimWritesFirst: true,
1840 shouldFail: true,
1841 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1842 expectedLocalError: "tls: peer did not false start: EOF",
1843 },
1844 {
1845 name: "NoFalseStart-NoAEAD",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1849 NextProtos: []string{"foo"},
1850 Bugs: ProtocolBugs{
1851 ExpectFalseStart: true,
1852 AlertBeforeFalseStartTest: alertAccessDenied,
1853 },
1854 },
1855 flags: []string{
1856 "-false-start",
1857 "-advertise-alpn", "\x03foo",
1858 },
1859 shimWritesFirst: true,
1860 shouldFail: true,
1861 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1862 expectedLocalError: "tls: peer did not false start: EOF",
1863 },
1864 {
1865 name: "NoFalseStart-RSA",
1866 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001867 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001868 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1869 NextProtos: []string{"foo"},
1870 Bugs: ProtocolBugs{
1871 ExpectFalseStart: true,
1872 AlertBeforeFalseStartTest: alertAccessDenied,
1873 },
1874 },
1875 flags: []string{
1876 "-false-start",
1877 "-advertise-alpn", "\x03foo",
1878 },
1879 shimWritesFirst: true,
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1882 expectedLocalError: "tls: peer did not false start: EOF",
1883 },
1884 {
1885 name: "NoFalseStart-DHE_RSA",
1886 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001887 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001888 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1889 NextProtos: []string{"foo"},
1890 Bugs: ProtocolBugs{
1891 ExpectFalseStart: true,
1892 AlertBeforeFalseStartTest: alertAccessDenied,
1893 },
1894 },
1895 flags: []string{
1896 "-false-start",
1897 "-advertise-alpn", "\x03foo",
1898 },
1899 shimWritesFirst: true,
1900 shouldFail: true,
1901 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1902 expectedLocalError: "tls: peer did not false start: EOF",
1903 },
1904 {
Adam Langley7c803a62015-06-15 15:35:05 -07001905 protocol: dtls,
1906 name: "SendSplitAlert-Sync",
1907 config: Config{
1908 Bugs: ProtocolBugs{
1909 SendSplitAlert: true,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "SendSplitAlert-Async",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 SendSplitAlert: true,
1919 },
1920 },
1921 flags: []string{"-async"},
1922 },
1923 {
1924 protocol: dtls,
1925 name: "PackDTLSHandshake",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 MaxHandshakeRecordLength: 2,
1929 PackHandshakeFragments: 20,
1930 PackHandshakeRecords: 200,
1931 },
1932 },
1933 },
1934 {
Adam Langley7c803a62015-06-15 15:35:05 -07001935 name: "SendEmptyRecords-Pass",
1936 sendEmptyRecords: 32,
1937 },
1938 {
1939 name: "SendEmptyRecords",
1940 sendEmptyRecords: 33,
1941 shouldFail: true,
1942 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1943 },
1944 {
1945 name: "SendEmptyRecords-Async",
1946 sendEmptyRecords: 33,
1947 flags: []string{"-async"},
1948 shouldFail: true,
1949 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1950 },
1951 {
David Benjamine8e84b92016-08-03 15:39:47 -04001952 name: "SendWarningAlerts-Pass",
1953 config: Config{
1954 MaxVersion: VersionTLS12,
1955 },
Adam Langley7c803a62015-06-15 15:35:05 -07001956 sendWarningAlerts: 4,
1957 },
1958 {
David Benjamine8e84b92016-08-03 15:39:47 -04001959 protocol: dtls,
1960 name: "SendWarningAlerts-DTLS-Pass",
1961 config: Config{
1962 MaxVersion: VersionTLS12,
1963 },
Adam Langley7c803a62015-06-15 15:35:05 -07001964 sendWarningAlerts: 4,
1965 },
1966 {
David Benjamine8e84b92016-08-03 15:39:47 -04001967 name: "SendWarningAlerts-TLS13",
1968 config: Config{
1969 MaxVersion: VersionTLS13,
1970 },
1971 sendWarningAlerts: 4,
1972 shouldFail: true,
1973 expectedError: ":BAD_ALERT:",
1974 expectedLocalError: "remote error: error decoding message",
1975 },
1976 {
1977 name: "SendWarningAlerts",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 5,
1982 shouldFail: true,
1983 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1984 },
1985 {
David Benjamine8e84b92016-08-03 15:39:47 -04001986 name: "SendWarningAlerts-Async",
1987 config: Config{
1988 MaxVersion: VersionTLS12,
1989 },
Adam Langley7c803a62015-06-15 15:35:05 -07001990 sendWarningAlerts: 5,
1991 flags: []string{"-async"},
1992 shouldFail: true,
1993 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1994 },
David Benjaminba4594a2015-06-18 18:36:15 -04001995 {
1996 name: "EmptySessionID",
1997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001998 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001999 SessionTicketsDisabled: true,
2000 },
2001 noSessionCache: true,
2002 flags: []string{"-expect-no-session"},
2003 },
David Benjamin30789da2015-08-29 22:56:45 -04002004 {
2005 name: "Unclean-Shutdown",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 NoCloseNotify: true,
2009 ExpectCloseNotify: true,
2010 },
2011 },
2012 shimShutsDown: true,
2013 flags: []string{"-check-close-notify"},
2014 shouldFail: true,
2015 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2016 },
2017 {
2018 name: "Unclean-Shutdown-Ignored",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 NoCloseNotify: true,
2022 },
2023 },
2024 shimShutsDown: true,
2025 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002026 {
David Benjaminfa214e42016-05-10 17:03:10 -04002027 name: "Unclean-Shutdown-Alert",
2028 config: Config{
2029 Bugs: ProtocolBugs{
2030 SendAlertOnShutdown: alertDecompressionFailure,
2031 ExpectCloseNotify: true,
2032 },
2033 },
2034 shimShutsDown: true,
2035 flags: []string{"-check-close-notify"},
2036 shouldFail: true,
2037 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2038 },
2039 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002040 name: "LargePlaintext",
2041 config: Config{
2042 Bugs: ProtocolBugs{
2043 SendLargeRecords: true,
2044 },
2045 },
2046 messageLen: maxPlaintext + 1,
2047 shouldFail: true,
2048 expectedError: ":DATA_LENGTH_TOO_LONG:",
2049 },
2050 {
2051 protocol: dtls,
2052 name: "LargePlaintext-DTLS",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 SendLargeRecords: true,
2056 },
2057 },
2058 messageLen: maxPlaintext + 1,
2059 shouldFail: true,
2060 expectedError: ":DATA_LENGTH_TOO_LONG:",
2061 },
2062 {
2063 name: "LargeCiphertext",
2064 config: Config{
2065 Bugs: ProtocolBugs{
2066 SendLargeRecords: true,
2067 },
2068 },
2069 messageLen: maxPlaintext * 2,
2070 shouldFail: true,
2071 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2072 },
2073 {
2074 protocol: dtls,
2075 name: "LargeCiphertext-DTLS",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendLargeRecords: true,
2079 },
2080 },
2081 messageLen: maxPlaintext * 2,
2082 // Unlike the other four cases, DTLS drops records which
2083 // are invalid before authentication, so the connection
2084 // does not fail.
2085 expectMessageDropped: true,
2086 },
David Benjamindd6fed92015-10-23 17:41:12 -04002087 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 // In TLS 1.2 and below, empty NewSessionTicket messages
2089 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002090 name: "SendEmptySessionTicket",
2091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002092 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002093 Bugs: ProtocolBugs{
2094 SendEmptySessionTicket: true,
2095 FailIfSessionOffered: true,
2096 },
2097 },
2098 flags: []string{"-expect-no-session"},
2099 resumeSession: true,
2100 expectResumeRejected: true,
2101 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002102 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002103 name: "BadHelloRequest-1",
2104 renegotiate: 1,
2105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002106 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002107 Bugs: ProtocolBugs{
2108 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2109 },
2110 },
2111 flags: []string{
2112 "-renegotiate-freely",
2113 "-expect-total-renegotiations", "1",
2114 },
2115 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002116 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002117 },
2118 {
2119 name: "BadHelloRequest-2",
2120 renegotiate: 1,
2121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002123 Bugs: ProtocolBugs{
2124 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2125 },
2126 },
2127 flags: []string{
2128 "-renegotiate-freely",
2129 "-expect-total-renegotiations", "1",
2130 },
2131 shouldFail: true,
2132 expectedError: ":BAD_HELLO_REQUEST:",
2133 },
David Benjaminef1b0092015-11-21 14:05:44 -05002134 {
2135 testType: serverTest,
2136 name: "SupportTicketsWithSessionID",
2137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002138 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002139 SessionTicketsDisabled: true,
2140 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002141 resumeConfig: &Config{
2142 MaxVersion: VersionTLS12,
2143 },
David Benjaminef1b0092015-11-21 14:05:44 -05002144 resumeSession: true,
2145 },
David Benjamin02edcd02016-07-27 17:40:37 -04002146 {
2147 protocol: dtls,
2148 name: "DTLS-SendExtraFinished",
2149 config: Config{
2150 Bugs: ProtocolBugs{
2151 SendExtraFinished: true,
2152 },
2153 },
2154 shouldFail: true,
2155 expectedError: ":UNEXPECTED_RECORD:",
2156 },
2157 {
2158 protocol: dtls,
2159 name: "DTLS-SendExtraFinished-Reordered",
2160 config: Config{
2161 Bugs: ProtocolBugs{
2162 MaxHandshakeRecordLength: 2,
2163 ReorderHandshakeFragments: true,
2164 SendExtraFinished: true,
2165 },
2166 },
2167 shouldFail: true,
2168 expectedError: ":UNEXPECTED_RECORD:",
2169 },
David Benjamine97fb482016-07-29 09:23:07 -04002170 {
2171 testType: serverTest,
2172 name: "V2ClientHello-EmptyRecordPrefix",
2173 config: Config{
2174 // Choose a cipher suite that does not involve
2175 // elliptic curves, so no extensions are
2176 // involved.
2177 MaxVersion: VersionTLS12,
2178 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2179 Bugs: ProtocolBugs{
2180 SendV2ClientHello: true,
2181 },
2182 },
2183 sendPrefix: string([]byte{
2184 byte(recordTypeHandshake),
2185 3, 1, // version
2186 0, 0, // length
2187 }),
2188 // A no-op empty record may not be sent before V2ClientHello.
2189 shouldFail: true,
2190 expectedError: ":WRONG_VERSION_NUMBER:",
2191 },
2192 {
2193 testType: serverTest,
2194 name: "V2ClientHello-WarningAlertPrefix",
2195 config: Config{
2196 // Choose a cipher suite that does not involve
2197 // elliptic curves, so no extensions are
2198 // involved.
2199 MaxVersion: VersionTLS12,
2200 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2201 Bugs: ProtocolBugs{
2202 SendV2ClientHello: true,
2203 },
2204 },
2205 sendPrefix: string([]byte{
2206 byte(recordTypeAlert),
2207 3, 1, // version
2208 0, 2, // length
2209 alertLevelWarning, byte(alertDecompressionFailure),
2210 }),
2211 // A no-op warning alert may not be sent before V2ClientHello.
2212 shouldFail: true,
2213 expectedError: ":WRONG_VERSION_NUMBER:",
2214 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002215 {
2216 testType: clientTest,
2217 name: "KeyUpdate",
2218 config: Config{
2219 MaxVersion: VersionTLS13,
2220 Bugs: ProtocolBugs{
2221 SendKeyUpdateBeforeEveryAppDataRecord: true,
2222 },
2223 },
2224 },
Adam Langley7c803a62015-06-15 15:35:05 -07002225 }
Adam Langley7c803a62015-06-15 15:35:05 -07002226 testCases = append(testCases, basicTests...)
2227}
2228
Adam Langley95c29f32014-06-20 12:00:00 -07002229func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002230 const bogusCipher = 0xfe00
2231
Adam Langley95c29f32014-06-20 12:00:00 -07002232 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002233 const psk = "12345"
2234 const pskIdentity = "luggage combo"
2235
Adam Langley95c29f32014-06-20 12:00:00 -07002236 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002237 var certFile string
2238 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002239 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002240 cert = ecdsaP256Certificate
2241 certFile = ecdsaP256CertificateFile
2242 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002243 } else {
David Benjamin33863262016-07-08 17:20:12 -07002244 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002245 certFile = rsaCertificateFile
2246 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002247 }
2248
David Benjamin48cae082014-10-27 01:06:24 -04002249 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002250 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002251 flags = append(flags,
2252 "-psk", psk,
2253 "-psk-identity", pskIdentity)
2254 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002255 if hasComponent(suite.name, "NULL") {
2256 // NULL ciphers must be explicitly enabled.
2257 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2258 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002259 if hasComponent(suite.name, "CECPQ1") {
2260 // CECPQ1 ciphers must be explicitly enabled.
2261 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2262 }
David Benjamin881f1962016-08-10 18:29:12 -04002263 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2264 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2265 // for now.
2266 flags = append(flags, "-cipher", suite.name)
2267 }
David Benjamin48cae082014-10-27 01:06:24 -04002268
Adam Langley95c29f32014-06-20 12:00:00 -07002269 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002270 for _, protocol := range []protocol{tls, dtls} {
2271 var prefix string
2272 if protocol == dtls {
2273 if !ver.hasDTLS {
2274 continue
2275 }
2276 prefix = "D"
2277 }
Adam Langley95c29f32014-06-20 12:00:00 -07002278
David Benjamin0407e762016-06-17 16:41:18 -04002279 var shouldServerFail, shouldClientFail bool
2280 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2281 // BoringSSL clients accept ECDHE on SSLv3, but
2282 // a BoringSSL server will never select it
2283 // because the extension is missing.
2284 shouldServerFail = true
2285 }
2286 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2287 shouldClientFail = true
2288 shouldServerFail = true
2289 }
David Benjamin54c217c2016-07-13 12:35:25 -04002290 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002291 shouldClientFail = true
2292 shouldServerFail = true
2293 }
David Benjamin0407e762016-06-17 16:41:18 -04002294 if !isDTLSCipher(suite.name) && protocol == dtls {
2295 shouldClientFail = true
2296 shouldServerFail = true
2297 }
David Benjamin4298d772015-12-19 00:18:25 -05002298
David Benjamin0407e762016-06-17 16:41:18 -04002299 var expectedServerError, expectedClientError string
2300 if shouldServerFail {
2301 expectedServerError = ":NO_SHARED_CIPHER:"
2302 }
2303 if shouldClientFail {
2304 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2305 }
David Benjamin025b3d32014-07-01 19:53:04 -04002306
David Benjamin6fd297b2014-08-11 18:43:38 -04002307 testCases = append(testCases, testCase{
2308 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002309 protocol: protocol,
2310
2311 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002312 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002313 MinVersion: ver.version,
2314 MaxVersion: ver.version,
2315 CipherSuites: []uint16{suite.id},
2316 Certificates: []Certificate{cert},
2317 PreSharedKey: []byte(psk),
2318 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002319 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002320 EnableAllCiphers: shouldServerFail,
2321 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002322 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002323 },
2324 certFile: certFile,
2325 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002326 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002327 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002328 shouldFail: shouldServerFail,
2329 expectedError: expectedServerError,
2330 })
2331
2332 testCases = append(testCases, testCase{
2333 testType: clientTest,
2334 protocol: protocol,
2335 name: prefix + ver.name + "-" + suite.name + "-client",
2336 config: Config{
2337 MinVersion: ver.version,
2338 MaxVersion: ver.version,
2339 CipherSuites: []uint16{suite.id},
2340 Certificates: []Certificate{cert},
2341 PreSharedKey: []byte(psk),
2342 PreSharedKeyIdentity: pskIdentity,
2343 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002344 EnableAllCiphers: shouldClientFail,
2345 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002346 },
2347 },
2348 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002349 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002350 shouldFail: shouldClientFail,
2351 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002352 })
David Benjamin2c99d282015-09-01 10:23:00 -04002353
Nick Harper1fd39d82016-06-14 18:14:35 -07002354 if !shouldClientFail {
2355 // Ensure the maximum record size is accepted.
2356 testCases = append(testCases, testCase{
2357 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2358 config: Config{
2359 MinVersion: ver.version,
2360 MaxVersion: ver.version,
2361 CipherSuites: []uint16{suite.id},
2362 Certificates: []Certificate{cert},
2363 PreSharedKey: []byte(psk),
2364 PreSharedKeyIdentity: pskIdentity,
2365 },
2366 flags: flags,
2367 messageLen: maxPlaintext,
2368 })
2369 }
2370 }
David Benjamin2c99d282015-09-01 10:23:00 -04002371 }
Adam Langley95c29f32014-06-20 12:00:00 -07002372 }
Adam Langleya7997f12015-05-14 17:38:50 -07002373
2374 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002375 name: "NoSharedCipher",
2376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002377 MaxVersion: VersionTLS12,
2378 CipherSuites: []uint16{},
2379 },
2380 shouldFail: true,
2381 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2382 })
2383
2384 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002385 name: "NoSharedCipher-TLS13",
2386 config: Config{
2387 MaxVersion: VersionTLS13,
2388 CipherSuites: []uint16{},
2389 },
2390 shouldFail: true,
2391 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2392 })
2393
2394 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002395 name: "UnsupportedCipherSuite",
2396 config: Config{
2397 MaxVersion: VersionTLS12,
2398 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2399 Bugs: ProtocolBugs{
2400 IgnorePeerCipherPreferences: true,
2401 },
2402 },
2403 flags: []string{"-cipher", "DEFAULT:!RC4"},
2404 shouldFail: true,
2405 expectedError: ":WRONG_CIPHER_RETURNED:",
2406 })
2407
2408 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002409 name: "ServerHelloBogusCipher",
2410 config: Config{
2411 MaxVersion: VersionTLS12,
2412 Bugs: ProtocolBugs{
2413 SendCipherSuite: bogusCipher,
2414 },
2415 },
2416 shouldFail: true,
2417 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2418 })
2419 testCases = append(testCases, testCase{
2420 name: "ServerHelloBogusCipher-TLS13",
2421 config: Config{
2422 MaxVersion: VersionTLS13,
2423 Bugs: ProtocolBugs{
2424 SendCipherSuite: bogusCipher,
2425 },
2426 },
2427 shouldFail: true,
2428 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2429 })
2430
2431 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002432 name: "WeakDH",
2433 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002434 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002435 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2436 Bugs: ProtocolBugs{
2437 // This is a 1023-bit prime number, generated
2438 // with:
2439 // openssl gendh 1023 | openssl asn1parse -i
2440 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2441 },
2442 },
2443 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002444 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002445 })
Adam Langleycef75832015-09-03 14:51:12 -07002446
David Benjamincd24a392015-11-11 13:23:05 -08002447 testCases = append(testCases, testCase{
2448 name: "SillyDH",
2449 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002450 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002451 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2452 Bugs: ProtocolBugs{
2453 // This is a 4097-bit prime number, generated
2454 // with:
2455 // openssl gendh 4097 | openssl asn1parse -i
2456 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2457 },
2458 },
2459 shouldFail: true,
2460 expectedError: ":DH_P_TOO_LONG:",
2461 })
2462
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002463 // This test ensures that Diffie-Hellman public values are padded with
2464 // zeros so that they're the same length as the prime. This is to avoid
2465 // hitting a bug in yaSSL.
2466 testCases = append(testCases, testCase{
2467 testType: serverTest,
2468 name: "DHPublicValuePadded",
2469 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002470 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002471 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2472 Bugs: ProtocolBugs{
2473 RequireDHPublicValueLen: (1025 + 7) / 8,
2474 },
2475 },
2476 flags: []string{"-use-sparse-dh-prime"},
2477 })
David Benjamincd24a392015-11-11 13:23:05 -08002478
David Benjamin241ae832016-01-15 03:04:54 -05002479 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002480 testCases = append(testCases, testCase{
2481 testType: serverTest,
2482 name: "UnknownCipher",
2483 config: Config{
2484 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2485 },
2486 })
2487
Adam Langleycef75832015-09-03 14:51:12 -07002488 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2489 // 1.1 specific cipher suite settings. A server is setup with the given
2490 // cipher lists and then a connection is made for each member of
2491 // expectations. The cipher suite that the server selects must match
2492 // the specified one.
2493 var versionSpecificCiphersTest = []struct {
2494 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2495 // expectations is a map from TLS version to cipher suite id.
2496 expectations map[uint16]uint16
2497 }{
2498 {
2499 // Test that the null case (where no version-specific ciphers are set)
2500 // works as expected.
2501 "RC4-SHA:AES128-SHA", // default ciphers
2502 "", // no ciphers specifically for TLS ≥ 1.0
2503 "", // no ciphers specifically for TLS ≥ 1.1
2504 map[uint16]uint16{
2505 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2506 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2507 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2508 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2509 },
2510 },
2511 {
2512 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2513 // cipher.
2514 "RC4-SHA:AES128-SHA", // default
2515 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2516 "", // no ciphers specifically for TLS ≥ 1.1
2517 map[uint16]uint16{
2518 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2519 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2520 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2521 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2522 },
2523 },
2524 {
2525 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2526 // cipher.
2527 "RC4-SHA:AES128-SHA", // default
2528 "", // no ciphers specifically for TLS ≥ 1.0
2529 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2530 map[uint16]uint16{
2531 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2532 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2533 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2534 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2535 },
2536 },
2537 {
2538 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2539 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2540 "RC4-SHA:AES128-SHA", // default
2541 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2542 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2543 map[uint16]uint16{
2544 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2545 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2546 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2547 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2548 },
2549 },
2550 }
2551
2552 for i, test := range versionSpecificCiphersTest {
2553 for version, expectedCipherSuite := range test.expectations {
2554 flags := []string{"-cipher", test.ciphersDefault}
2555 if len(test.ciphersTLS10) > 0 {
2556 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2557 }
2558 if len(test.ciphersTLS11) > 0 {
2559 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2560 }
2561
2562 testCases = append(testCases, testCase{
2563 testType: serverTest,
2564 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2565 config: Config{
2566 MaxVersion: version,
2567 MinVersion: version,
2568 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2569 },
2570 flags: flags,
2571 expectedCipher: expectedCipherSuite,
2572 })
2573 }
2574 }
Adam Langley95c29f32014-06-20 12:00:00 -07002575}
2576
2577func addBadECDSASignatureTests() {
2578 for badR := BadValue(1); badR < NumBadValues; badR++ {
2579 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002580 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002581 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2582 config: Config{
2583 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002584 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002585 Bugs: ProtocolBugs{
2586 BadECDSAR: badR,
2587 BadECDSAS: badS,
2588 },
2589 },
2590 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002591 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002592 })
2593 }
2594 }
2595}
2596
Adam Langley80842bd2014-06-20 12:00:00 -07002597func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002598 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002599 name: "MaxCBCPadding",
2600 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002601 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2603 Bugs: ProtocolBugs{
2604 MaxPadding: true,
2605 },
2606 },
2607 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2608 })
David Benjamin025b3d32014-07-01 19:53:04 -04002609 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002610 name: "BadCBCPadding",
2611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002612 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2614 Bugs: ProtocolBugs{
2615 PaddingFirstByteBad: true,
2616 },
2617 },
2618 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002619 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002620 })
2621 // OpenSSL previously had an issue where the first byte of padding in
2622 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002623 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002624 name: "BadCBCPadding255",
2625 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002626 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002627 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2628 Bugs: ProtocolBugs{
2629 MaxPadding: true,
2630 PaddingFirstByteBadIf255: true,
2631 },
2632 },
2633 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2634 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002635 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002636 })
2637}
2638
Kenny Root7fdeaf12014-08-05 15:23:37 -07002639func addCBCSplittingTests() {
2640 testCases = append(testCases, testCase{
2641 name: "CBCRecordSplitting",
2642 config: Config{
2643 MaxVersion: VersionTLS10,
2644 MinVersion: VersionTLS10,
2645 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2646 },
David Benjaminac8302a2015-09-01 17:18:15 -04002647 messageLen: -1, // read until EOF
2648 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002649 flags: []string{
2650 "-async",
2651 "-write-different-record-sizes",
2652 "-cbc-record-splitting",
2653 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002654 })
2655 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002656 name: "CBCRecordSplittingPartialWrite",
2657 config: Config{
2658 MaxVersion: VersionTLS10,
2659 MinVersion: VersionTLS10,
2660 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2661 },
2662 messageLen: -1, // read until EOF
2663 flags: []string{
2664 "-async",
2665 "-write-different-record-sizes",
2666 "-cbc-record-splitting",
2667 "-partial-write",
2668 },
2669 })
2670}
2671
David Benjamin636293b2014-07-08 17:59:18 -04002672func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002673 // Add a dummy cert pool to stress certificate authority parsing.
2674 // TODO(davidben): Add tests that those values parse out correctly.
2675 certPool := x509.NewCertPool()
2676 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2677 if err != nil {
2678 panic(err)
2679 }
2680 certPool.AddCert(cert)
2681
David Benjamin636293b2014-07-08 17:59:18 -04002682 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002683 testCases = append(testCases, testCase{
2684 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002685 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002686 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002687 MinVersion: ver.version,
2688 MaxVersion: ver.version,
2689 ClientAuth: RequireAnyClientCert,
2690 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002691 },
2692 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002695 },
2696 })
2697 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002698 testType: serverTest,
2699 name: ver.name + "-Server-ClientAuth-RSA",
2700 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002701 MinVersion: ver.version,
2702 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002703 Certificates: []Certificate{rsaCertificate},
2704 },
2705 flags: []string{"-require-any-client-certificate"},
2706 })
David Benjamine098ec22014-08-27 23:13:20 -04002707 if ver.version != VersionSSL30 {
2708 testCases = append(testCases, testCase{
2709 testType: serverTest,
2710 name: ver.name + "-Server-ClientAuth-ECDSA",
2711 config: Config{
2712 MinVersion: ver.version,
2713 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002714 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002715 },
2716 flags: []string{"-require-any-client-certificate"},
2717 })
2718 testCases = append(testCases, testCase{
2719 testType: clientTest,
2720 name: ver.name + "-Client-ClientAuth-ECDSA",
2721 config: Config{
2722 MinVersion: ver.version,
2723 MaxVersion: ver.version,
2724 ClientAuth: RequireAnyClientCert,
2725 ClientCAs: certPool,
2726 },
2727 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002728 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2729 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002730 },
2731 })
2732 }
David Benjamin636293b2014-07-08 17:59:18 -04002733 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002734
2735 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002736 name: "NoClientCertificate",
2737 config: Config{
2738 MaxVersion: VersionTLS12,
2739 ClientAuth: RequireAnyClientCert,
2740 },
2741 shouldFail: true,
2742 expectedLocalError: "client didn't provide a certificate",
2743 })
2744
2745 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002746 name: "NoClientCertificate-TLS13",
2747 config: Config{
2748 MaxVersion: VersionTLS13,
2749 ClientAuth: RequireAnyClientCert,
2750 },
2751 shouldFail: true,
2752 expectedLocalError: "client didn't provide a certificate",
2753 })
2754
2755 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002756 testType: serverTest,
2757 name: "RequireAnyClientCertificate",
2758 config: Config{
2759 MaxVersion: VersionTLS12,
2760 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002761 flags: []string{"-require-any-client-certificate"},
2762 shouldFail: true,
2763 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2764 })
2765
2766 testCases = append(testCases, testCase{
2767 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002768 name: "RequireAnyClientCertificate-TLS13",
2769 config: Config{
2770 MaxVersion: VersionTLS13,
2771 },
2772 flags: []string{"-require-any-client-certificate"},
2773 shouldFail: true,
2774 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2775 })
2776
2777 testCases = append(testCases, testCase{
2778 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002779 name: "RequireAnyClientCertificate-SSL3",
2780 config: Config{
2781 MaxVersion: VersionSSL30,
2782 },
2783 flags: []string{"-require-any-client-certificate"},
2784 shouldFail: true,
2785 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2786 })
2787
2788 testCases = append(testCases, testCase{
2789 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002790 name: "SkipClientCertificate",
2791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002792 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002793 Bugs: ProtocolBugs{
2794 SkipClientCertificate: true,
2795 },
2796 },
2797 // Setting SSL_VERIFY_PEER allows anonymous clients.
2798 flags: []string{"-verify-peer"},
2799 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002800 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002801 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002802
Steven Valdez143e8b32016-07-11 13:19:03 -04002803 testCases = append(testCases, testCase{
2804 testType: serverTest,
2805 name: "SkipClientCertificate-TLS13",
2806 config: Config{
2807 MaxVersion: VersionTLS13,
2808 Bugs: ProtocolBugs{
2809 SkipClientCertificate: true,
2810 },
2811 },
2812 // Setting SSL_VERIFY_PEER allows anonymous clients.
2813 flags: []string{"-verify-peer"},
2814 shouldFail: true,
2815 expectedError: ":UNEXPECTED_MESSAGE:",
2816 })
2817
David Benjaminc032dfa2016-05-12 14:54:57 -04002818 // Client auth is only legal in certificate-based ciphers.
2819 testCases = append(testCases, testCase{
2820 testType: clientTest,
2821 name: "ClientAuth-PSK",
2822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002823 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002824 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2825 PreSharedKey: []byte("secret"),
2826 ClientAuth: RequireAnyClientCert,
2827 },
2828 flags: []string{
2829 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2830 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2831 "-psk", "secret",
2832 },
2833 shouldFail: true,
2834 expectedError: ":UNEXPECTED_MESSAGE:",
2835 })
2836 testCases = append(testCases, testCase{
2837 testType: clientTest,
2838 name: "ClientAuth-ECDHE_PSK",
2839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002840 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002841 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2842 PreSharedKey: []byte("secret"),
2843 ClientAuth: RequireAnyClientCert,
2844 },
2845 flags: []string{
2846 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2847 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2848 "-psk", "secret",
2849 },
2850 shouldFail: true,
2851 expectedError: ":UNEXPECTED_MESSAGE:",
2852 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002853
2854 // Regression test for a bug where the client CA list, if explicitly
2855 // set to NULL, was mis-encoded.
2856 testCases = append(testCases, testCase{
2857 testType: serverTest,
2858 name: "Null-Client-CA-List",
2859 config: Config{
2860 MaxVersion: VersionTLS12,
2861 Certificates: []Certificate{rsaCertificate},
2862 },
2863 flags: []string{
2864 "-require-any-client-certificate",
2865 "-use-null-client-ca-list",
2866 },
2867 })
David Benjamin636293b2014-07-08 17:59:18 -04002868}
2869
Adam Langley75712922014-10-10 16:23:43 -07002870func addExtendedMasterSecretTests() {
2871 const expectEMSFlag = "-expect-extended-master-secret"
2872
2873 for _, with := range []bool{false, true} {
2874 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002875 if with {
2876 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002877 }
2878
2879 for _, isClient := range []bool{false, true} {
2880 suffix := "-Server"
2881 testType := serverTest
2882 if isClient {
2883 suffix = "-Client"
2884 testType = clientTest
2885 }
2886
2887 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002888 // In TLS 1.3, the extension is irrelevant and
2889 // always reports as enabled.
2890 var flags []string
2891 if with || ver.version >= VersionTLS13 {
2892 flags = []string{expectEMSFlag}
2893 }
2894
Adam Langley75712922014-10-10 16:23:43 -07002895 test := testCase{
2896 testType: testType,
2897 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2898 config: Config{
2899 MinVersion: ver.version,
2900 MaxVersion: ver.version,
2901 Bugs: ProtocolBugs{
2902 NoExtendedMasterSecret: !with,
2903 RequireExtendedMasterSecret: with,
2904 },
2905 },
David Benjamin48cae082014-10-27 01:06:24 -04002906 flags: flags,
2907 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002908 }
2909 if test.shouldFail {
2910 test.expectedLocalError = "extended master secret required but not supported by peer"
2911 }
2912 testCases = append(testCases, test)
2913 }
2914 }
2915 }
2916
Adam Langleyba5934b2015-06-02 10:50:35 -07002917 for _, isClient := range []bool{false, true} {
2918 for _, supportedInFirstConnection := range []bool{false, true} {
2919 for _, supportedInResumeConnection := range []bool{false, true} {
2920 boolToWord := func(b bool) string {
2921 if b {
2922 return "Yes"
2923 }
2924 return "No"
2925 }
2926 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2927 if isClient {
2928 suffix += "Client"
2929 } else {
2930 suffix += "Server"
2931 }
2932
2933 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002935 Bugs: ProtocolBugs{
2936 RequireExtendedMasterSecret: true,
2937 },
2938 }
2939
2940 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002941 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002942 Bugs: ProtocolBugs{
2943 NoExtendedMasterSecret: true,
2944 },
2945 }
2946
2947 test := testCase{
2948 name: "ExtendedMasterSecret-" + suffix,
2949 resumeSession: true,
2950 }
2951
2952 if !isClient {
2953 test.testType = serverTest
2954 }
2955
2956 if supportedInFirstConnection {
2957 test.config = supportedConfig
2958 } else {
2959 test.config = noSupportConfig
2960 }
2961
2962 if supportedInResumeConnection {
2963 test.resumeConfig = &supportedConfig
2964 } else {
2965 test.resumeConfig = &noSupportConfig
2966 }
2967
2968 switch suffix {
2969 case "YesToYes-Client", "YesToYes-Server":
2970 // When a session is resumed, it should
2971 // still be aware that its master
2972 // secret was generated via EMS and
2973 // thus it's safe to use tls-unique.
2974 test.flags = []string{expectEMSFlag}
2975 case "NoToYes-Server":
2976 // If an original connection did not
2977 // contain EMS, but a resumption
2978 // handshake does, then a server should
2979 // not resume the session.
2980 test.expectResumeRejected = true
2981 case "YesToNo-Server":
2982 // Resuming an EMS session without the
2983 // EMS extension should cause the
2984 // server to abort the connection.
2985 test.shouldFail = true
2986 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2987 case "NoToYes-Client":
2988 // A client should abort a connection
2989 // where the server resumed a non-EMS
2990 // session but echoed the EMS
2991 // extension.
2992 test.shouldFail = true
2993 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2994 case "YesToNo-Client":
2995 // A client should abort a connection
2996 // where the server didn't echo EMS
2997 // when the session used it.
2998 test.shouldFail = true
2999 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3000 }
3001
3002 testCases = append(testCases, test)
3003 }
3004 }
3005 }
Adam Langley75712922014-10-10 16:23:43 -07003006}
3007
David Benjamin582ba042016-07-07 12:33:25 -07003008type stateMachineTestConfig struct {
3009 protocol protocol
3010 async bool
3011 splitHandshake, packHandshakeFlight bool
3012}
3013
David Benjamin43ec06f2014-08-05 02:28:57 -04003014// Adds tests that try to cover the range of the handshake state machine, under
3015// various conditions. Some of these are redundant with other tests, but they
3016// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003017func addAllStateMachineCoverageTests() {
3018 for _, async := range []bool{false, true} {
3019 for _, protocol := range []protocol{tls, dtls} {
3020 addStateMachineCoverageTests(stateMachineTestConfig{
3021 protocol: protocol,
3022 async: async,
3023 })
3024 addStateMachineCoverageTests(stateMachineTestConfig{
3025 protocol: protocol,
3026 async: async,
3027 splitHandshake: true,
3028 })
3029 if protocol == tls {
3030 addStateMachineCoverageTests(stateMachineTestConfig{
3031 protocol: protocol,
3032 async: async,
3033 packHandshakeFlight: true,
3034 })
3035 }
3036 }
3037 }
3038}
3039
3040func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003041 var tests []testCase
3042
3043 // Basic handshake, with resumption. Client and server,
3044 // session ID and session ticket.
3045 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003046 name: "Basic-Client",
3047 config: Config{
3048 MaxVersion: VersionTLS12,
3049 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003050 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003051 // Ensure session tickets are used, not session IDs.
3052 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003053 })
3054 tests = append(tests, testCase{
3055 name: "Basic-Client-RenewTicket",
3056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003057 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003058 Bugs: ProtocolBugs{
3059 RenewTicketOnResume: true,
3060 },
3061 },
David Benjaminba4594a2015-06-18 18:36:15 -04003062 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003063 resumeSession: true,
3064 })
3065 tests = append(tests, testCase{
3066 name: "Basic-Client-NoTicket",
3067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003069 SessionTicketsDisabled: true,
3070 },
3071 resumeSession: true,
3072 })
3073 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003074 name: "Basic-Client-Implicit",
3075 config: Config{
3076 MaxVersion: VersionTLS12,
3077 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003078 flags: []string{"-implicit-handshake"},
3079 resumeSession: true,
3080 })
3081 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003082 testType: serverTest,
3083 name: "Basic-Server",
3084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003085 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003086 Bugs: ProtocolBugs{
3087 RequireSessionTickets: true,
3088 },
3089 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 resumeSession: true,
3091 })
3092 tests = append(tests, testCase{
3093 testType: serverTest,
3094 name: "Basic-Server-NoTickets",
3095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 SessionTicketsDisabled: true,
3098 },
3099 resumeSession: true,
3100 })
3101 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003102 testType: serverTest,
3103 name: "Basic-Server-Implicit",
3104 config: Config{
3105 MaxVersion: VersionTLS12,
3106 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003107 flags: []string{"-implicit-handshake"},
3108 resumeSession: true,
3109 })
3110 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 testType: serverTest,
3112 name: "Basic-Server-EarlyCallback",
3113 config: Config{
3114 MaxVersion: VersionTLS12,
3115 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003116 flags: []string{"-use-early-callback"},
3117 resumeSession: true,
3118 })
3119
Steven Valdez143e8b32016-07-11 13:19:03 -04003120 // TLS 1.3 basic handshake shapes.
3121 tests = append(tests, testCase{
3122 name: "TLS13-1RTT-Client",
3123 config: Config{
3124 MaxVersion: VersionTLS13,
3125 },
3126 })
3127 tests = append(tests, testCase{
3128 testType: serverTest,
3129 name: "TLS13-1RTT-Server",
3130 config: Config{
3131 MaxVersion: VersionTLS13,
3132 },
3133 })
3134
David Benjamin760b1dd2015-05-15 23:33:48 -04003135 // TLS client auth.
3136 tests = append(tests, testCase{
3137 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003138 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003140 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003141 ClientAuth: RequestClientCert,
3142 },
3143 })
3144 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003145 testType: serverTest,
3146 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003147 config: Config{
3148 MaxVersion: VersionTLS12,
3149 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003150 // Setting SSL_VERIFY_PEER allows anonymous clients.
3151 flags: []string{"-verify-peer"},
3152 })
David Benjamin582ba042016-07-07 12:33:25 -07003153 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003154 tests = append(tests, testCase{
3155 testType: clientTest,
3156 name: "ClientAuth-NoCertificate-Client-SSL3",
3157 config: Config{
3158 MaxVersion: VersionSSL30,
3159 ClientAuth: RequestClientCert,
3160 },
3161 })
3162 tests = append(tests, testCase{
3163 testType: serverTest,
3164 name: "ClientAuth-NoCertificate-Server-SSL3",
3165 config: Config{
3166 MaxVersion: VersionSSL30,
3167 },
3168 // Setting SSL_VERIFY_PEER allows anonymous clients.
3169 flags: []string{"-verify-peer"},
3170 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003171 tests = append(tests, testCase{
3172 testType: clientTest,
3173 name: "ClientAuth-NoCertificate-Client-TLS13",
3174 config: Config{
3175 MaxVersion: VersionTLS13,
3176 ClientAuth: RequestClientCert,
3177 },
3178 })
3179 tests = append(tests, testCase{
3180 testType: serverTest,
3181 name: "ClientAuth-NoCertificate-Server-TLS13",
3182 config: Config{
3183 MaxVersion: VersionTLS13,
3184 },
3185 // Setting SSL_VERIFY_PEER allows anonymous clients.
3186 flags: []string{"-verify-peer"},
3187 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003188 }
3189 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003190 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003191 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003192 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003193 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003194 ClientAuth: RequireAnyClientCert,
3195 },
3196 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003199 },
3200 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003201 tests = append(tests, testCase{
3202 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003203 name: "ClientAuth-RSA-Client-TLS13",
3204 config: Config{
3205 MaxVersion: VersionTLS13,
3206 ClientAuth: RequireAnyClientCert,
3207 },
3208 flags: []string{
3209 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3210 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3211 },
3212 })
3213 tests = append(tests, testCase{
3214 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003215 name: "ClientAuth-ECDSA-Client",
3216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003217 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003218 ClientAuth: RequireAnyClientCert,
3219 },
3220 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003221 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3222 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003223 },
3224 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003225 tests = append(tests, testCase{
3226 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003227 name: "ClientAuth-ECDSA-Client-TLS13",
3228 config: Config{
3229 MaxVersion: VersionTLS13,
3230 ClientAuth: RequireAnyClientCert,
3231 },
3232 flags: []string{
3233 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3234 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3235 },
3236 })
3237 tests = append(tests, testCase{
3238 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003239 name: "ClientAuth-NoCertificate-OldCallback",
3240 config: Config{
3241 MaxVersion: VersionTLS12,
3242 ClientAuth: RequestClientCert,
3243 },
3244 flags: []string{"-use-old-client-cert-callback"},
3245 })
3246 tests = append(tests, testCase{
3247 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003248 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3249 config: Config{
3250 MaxVersion: VersionTLS13,
3251 ClientAuth: RequestClientCert,
3252 },
3253 flags: []string{"-use-old-client-cert-callback"},
3254 })
3255 tests = append(tests, testCase{
3256 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003257 name: "ClientAuth-OldCallback",
3258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003259 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003260 ClientAuth: RequireAnyClientCert,
3261 },
3262 flags: []string{
3263 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3264 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3265 "-use-old-client-cert-callback",
3266 },
3267 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003269 testType: clientTest,
3270 name: "ClientAuth-OldCallback-TLS13",
3271 config: Config{
3272 MaxVersion: VersionTLS13,
3273 ClientAuth: RequireAnyClientCert,
3274 },
3275 flags: []string{
3276 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3277 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3278 "-use-old-client-cert-callback",
3279 },
3280 })
3281 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003282 testType: serverTest,
3283 name: "ClientAuth-Server",
3284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003285 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003286 Certificates: []Certificate{rsaCertificate},
3287 },
3288 flags: []string{"-require-any-client-certificate"},
3289 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003290 tests = append(tests, testCase{
3291 testType: serverTest,
3292 name: "ClientAuth-Server-TLS13",
3293 config: Config{
3294 MaxVersion: VersionTLS13,
3295 Certificates: []Certificate{rsaCertificate},
3296 },
3297 flags: []string{"-require-any-client-certificate"},
3298 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003299
David Benjamin4c3ddf72016-06-29 18:13:53 -04003300 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003301 tests = append(tests, testCase{
3302 testType: serverTest,
3303 name: "Basic-Server-RSA",
3304 config: Config{
3305 MaxVersion: VersionTLS12,
3306 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3307 },
3308 flags: []string{
3309 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3310 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3311 },
3312 })
3313 tests = append(tests, testCase{
3314 testType: serverTest,
3315 name: "Basic-Server-ECDHE-RSA",
3316 config: Config{
3317 MaxVersion: VersionTLS12,
3318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3319 },
3320 flags: []string{
3321 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3322 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3323 },
3324 })
3325 tests = append(tests, testCase{
3326 testType: serverTest,
3327 name: "Basic-Server-ECDHE-ECDSA",
3328 config: Config{
3329 MaxVersion: VersionTLS12,
3330 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3331 },
3332 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003333 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3334 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003335 },
3336 })
3337
David Benjamin760b1dd2015-05-15 23:33:48 -04003338 // No session ticket support; server doesn't send NewSessionTicket.
3339 tests = append(tests, testCase{
3340 name: "SessionTicketsDisabled-Client",
3341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003342 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003343 SessionTicketsDisabled: true,
3344 },
3345 })
3346 tests = append(tests, testCase{
3347 testType: serverTest,
3348 name: "SessionTicketsDisabled-Server",
3349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003350 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003351 SessionTicketsDisabled: true,
3352 },
3353 })
3354
3355 // Skip ServerKeyExchange in PSK key exchange if there's no
3356 // identity hint.
3357 tests = append(tests, testCase{
3358 name: "EmptyPSKHint-Client",
3359 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003360 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003361 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3362 PreSharedKey: []byte("secret"),
3363 },
3364 flags: []string{"-psk", "secret"},
3365 })
3366 tests = append(tests, testCase{
3367 testType: serverTest,
3368 name: "EmptyPSKHint-Server",
3369 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003370 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003371 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3372 PreSharedKey: []byte("secret"),
3373 },
3374 flags: []string{"-psk", "secret"},
3375 })
3376
David Benjamin4c3ddf72016-06-29 18:13:53 -04003377 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003378 tests = append(tests, testCase{
3379 testType: clientTest,
3380 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003381 config: Config{
3382 MaxVersion: VersionTLS12,
3383 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003384 flags: []string{
3385 "-enable-ocsp-stapling",
3386 "-expect-ocsp-response",
3387 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003388 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003389 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003390 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003391 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003392 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003393 testType: serverTest,
3394 name: "OCSPStapling-Server",
3395 config: Config{
3396 MaxVersion: VersionTLS12,
3397 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003398 expectedOCSPResponse: testOCSPResponse,
3399 flags: []string{
3400 "-ocsp-response",
3401 base64.StdEncoding.EncodeToString(testOCSPResponse),
3402 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003403 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003404 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003405 tests = append(tests, testCase{
3406 testType: clientTest,
3407 name: "OCSPStapling-Client-TLS13",
3408 config: Config{
3409 MaxVersion: VersionTLS13,
3410 },
3411 flags: []string{
3412 "-enable-ocsp-stapling",
3413 "-expect-ocsp-response",
3414 base64.StdEncoding.EncodeToString(testOCSPResponse),
3415 "-verify-peer",
3416 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003417 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003418 })
3419 tests = append(tests, testCase{
3420 testType: serverTest,
3421 name: "OCSPStapling-Server-TLS13",
3422 config: Config{
3423 MaxVersion: VersionTLS13,
3424 },
3425 expectedOCSPResponse: testOCSPResponse,
3426 flags: []string{
3427 "-ocsp-response",
3428 base64.StdEncoding.EncodeToString(testOCSPResponse),
3429 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003430 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003431 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003432
David Benjamin4c3ddf72016-06-29 18:13:53 -04003433 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003434 for _, vers := range tlsVersions {
3435 if config.protocol == dtls && !vers.hasDTLS {
3436 continue
3437 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003438 for _, testType := range []testType{clientTest, serverTest} {
3439 suffix := "-Client"
3440 if testType == serverTest {
3441 suffix = "-Server"
3442 }
3443 suffix += "-" + vers.name
3444
3445 flag := "-verify-peer"
3446 if testType == serverTest {
3447 flag = "-require-any-client-certificate"
3448 }
3449
3450 tests = append(tests, testCase{
3451 testType: testType,
3452 name: "CertificateVerificationSucceed" + suffix,
3453 config: Config{
3454 MaxVersion: vers.version,
3455 Certificates: []Certificate{rsaCertificate},
3456 },
3457 flags: []string{
3458 flag,
3459 "-expect-verify-result",
3460 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003461 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003462 })
3463 tests = append(tests, testCase{
3464 testType: testType,
3465 name: "CertificateVerificationFail" + suffix,
3466 config: Config{
3467 MaxVersion: vers.version,
3468 Certificates: []Certificate{rsaCertificate},
3469 },
3470 flags: []string{
3471 flag,
3472 "-verify-fail",
3473 },
3474 shouldFail: true,
3475 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3476 })
3477 }
3478
3479 // By default, the client is in a soft fail mode where the peer
3480 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003481 tests = append(tests, testCase{
3482 testType: clientTest,
3483 name: "CertificateVerificationSoftFail-" + vers.name,
3484 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003485 MaxVersion: vers.version,
3486 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003487 },
3488 flags: []string{
3489 "-verify-fail",
3490 "-expect-verify-result",
3491 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003492 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003493 })
3494 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003495
David Benjamin1d4f4c02016-07-26 18:03:08 -04003496 tests = append(tests, testCase{
3497 name: "ShimSendAlert",
3498 flags: []string{"-send-alert"},
3499 shimWritesFirst: true,
3500 shouldFail: true,
3501 expectedLocalError: "remote error: decompression failure",
3502 })
3503
David Benjamin582ba042016-07-07 12:33:25 -07003504 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003505 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003506 name: "Renegotiate-Client",
3507 config: Config{
3508 MaxVersion: VersionTLS12,
3509 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003510 renegotiate: 1,
3511 flags: []string{
3512 "-renegotiate-freely",
3513 "-expect-total-renegotiations", "1",
3514 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003515 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516
David Benjamin47921102016-07-28 11:29:18 -04003517 tests = append(tests, testCase{
3518 name: "SendHalfHelloRequest",
3519 config: Config{
3520 MaxVersion: VersionTLS12,
3521 Bugs: ProtocolBugs{
3522 PackHelloRequestWithFinished: config.packHandshakeFlight,
3523 },
3524 },
3525 sendHalfHelloRequest: true,
3526 flags: []string{"-renegotiate-ignore"},
3527 shouldFail: true,
3528 expectedError: ":UNEXPECTED_RECORD:",
3529 })
3530
David Benjamin760b1dd2015-05-15 23:33:48 -04003531 // NPN on client and server; results in post-handshake message.
3532 tests = append(tests, testCase{
3533 name: "NPN-Client",
3534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003535 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003536 NextProtos: []string{"foo"},
3537 },
3538 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003539 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003540 expectedNextProto: "foo",
3541 expectedNextProtoType: npn,
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "NPN-Server",
3546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003547 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003548 NextProtos: []string{"bar"},
3549 },
3550 flags: []string{
3551 "-advertise-npn", "\x03foo\x03bar\x03baz",
3552 "-expect-next-proto", "bar",
3553 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003554 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003555 expectedNextProto: "bar",
3556 expectedNextProtoType: npn,
3557 })
3558
3559 // TODO(davidben): Add tests for when False Start doesn't trigger.
3560
3561 // Client does False Start and negotiates NPN.
3562 tests = append(tests, testCase{
3563 name: "FalseStart",
3564 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003565 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3567 NextProtos: []string{"foo"},
3568 Bugs: ProtocolBugs{
3569 ExpectFalseStart: true,
3570 },
3571 },
3572 flags: []string{
3573 "-false-start",
3574 "-select-next-proto", "foo",
3575 },
3576 shimWritesFirst: true,
3577 resumeSession: true,
3578 })
3579
3580 // Client does False Start and negotiates ALPN.
3581 tests = append(tests, testCase{
3582 name: "FalseStart-ALPN",
3583 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003584 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003585 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3586 NextProtos: []string{"foo"},
3587 Bugs: ProtocolBugs{
3588 ExpectFalseStart: true,
3589 },
3590 },
3591 flags: []string{
3592 "-false-start",
3593 "-advertise-alpn", "\x03foo",
3594 },
3595 shimWritesFirst: true,
3596 resumeSession: true,
3597 })
3598
3599 // Client does False Start but doesn't explicitly call
3600 // SSL_connect.
3601 tests = append(tests, testCase{
3602 name: "FalseStart-Implicit",
3603 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003604 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003605 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3606 NextProtos: []string{"foo"},
3607 },
3608 flags: []string{
3609 "-implicit-handshake",
3610 "-false-start",
3611 "-advertise-alpn", "\x03foo",
3612 },
3613 })
3614
3615 // False Start without session tickets.
3616 tests = append(tests, testCase{
3617 name: "FalseStart-SessionTicketsDisabled",
3618 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003619 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003620 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3621 NextProtos: []string{"foo"},
3622 SessionTicketsDisabled: true,
3623 Bugs: ProtocolBugs{
3624 ExpectFalseStart: true,
3625 },
3626 },
3627 flags: []string{
3628 "-false-start",
3629 "-select-next-proto", "foo",
3630 },
3631 shimWritesFirst: true,
3632 })
3633
Adam Langleydf759b52016-07-11 15:24:37 -07003634 tests = append(tests, testCase{
3635 name: "FalseStart-CECPQ1",
3636 config: Config{
3637 MaxVersion: VersionTLS12,
3638 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3639 NextProtos: []string{"foo"},
3640 Bugs: ProtocolBugs{
3641 ExpectFalseStart: true,
3642 },
3643 },
3644 flags: []string{
3645 "-false-start",
3646 "-cipher", "DEFAULT:kCECPQ1",
3647 "-select-next-proto", "foo",
3648 },
3649 shimWritesFirst: true,
3650 resumeSession: true,
3651 })
3652
David Benjamin760b1dd2015-05-15 23:33:48 -04003653 // Server parses a V2ClientHello.
3654 tests = append(tests, testCase{
3655 testType: serverTest,
3656 name: "SendV2ClientHello",
3657 config: Config{
3658 // Choose a cipher suite that does not involve
3659 // elliptic curves, so no extensions are
3660 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003661 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003662 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3663 Bugs: ProtocolBugs{
3664 SendV2ClientHello: true,
3665 },
3666 },
3667 })
3668
3669 // Client sends a Channel ID.
3670 tests = append(tests, testCase{
3671 name: "ChannelID-Client",
3672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003673 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003674 RequestChannelID: true,
3675 },
Adam Langley7c803a62015-06-15 15:35:05 -07003676 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003677 resumeSession: true,
3678 expectChannelID: true,
3679 })
3680
3681 // Server accepts a Channel ID.
3682 tests = append(tests, testCase{
3683 testType: serverTest,
3684 name: "ChannelID-Server",
3685 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003686 MaxVersion: VersionTLS12,
3687 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003688 },
3689 flags: []string{
3690 "-expect-channel-id",
3691 base64.StdEncoding.EncodeToString(channelIDBytes),
3692 },
3693 resumeSession: true,
3694 expectChannelID: true,
3695 })
David Benjamin30789da2015-08-29 22:56:45 -04003696
David Benjaminf8fcdf32016-06-08 15:56:13 -04003697 // Channel ID and NPN at the same time, to ensure their relative
3698 // ordering is correct.
3699 tests = append(tests, testCase{
3700 name: "ChannelID-NPN-Client",
3701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003702 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003703 RequestChannelID: true,
3704 NextProtos: []string{"foo"},
3705 },
3706 flags: []string{
3707 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3708 "-select-next-proto", "foo",
3709 },
3710 resumeSession: true,
3711 expectChannelID: true,
3712 expectedNextProto: "foo",
3713 expectedNextProtoType: npn,
3714 })
3715 tests = append(tests, testCase{
3716 testType: serverTest,
3717 name: "ChannelID-NPN-Server",
3718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003719 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003720 ChannelID: channelIDKey,
3721 NextProtos: []string{"bar"},
3722 },
3723 flags: []string{
3724 "-expect-channel-id",
3725 base64.StdEncoding.EncodeToString(channelIDBytes),
3726 "-advertise-npn", "\x03foo\x03bar\x03baz",
3727 "-expect-next-proto", "bar",
3728 },
3729 resumeSession: true,
3730 expectChannelID: true,
3731 expectedNextProto: "bar",
3732 expectedNextProtoType: npn,
3733 })
3734
David Benjamin30789da2015-08-29 22:56:45 -04003735 // Bidirectional shutdown with the runner initiating.
3736 tests = append(tests, testCase{
3737 name: "Shutdown-Runner",
3738 config: Config{
3739 Bugs: ProtocolBugs{
3740 ExpectCloseNotify: true,
3741 },
3742 },
3743 flags: []string{"-check-close-notify"},
3744 })
3745
3746 // Bidirectional shutdown with the shim initiating. The runner,
3747 // in the meantime, sends garbage before the close_notify which
3748 // the shim must ignore.
3749 tests = append(tests, testCase{
3750 name: "Shutdown-Shim",
3751 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003752 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003753 Bugs: ProtocolBugs{
3754 ExpectCloseNotify: true,
3755 },
3756 },
3757 shimShutsDown: true,
3758 sendEmptyRecords: 1,
3759 sendWarningAlerts: 1,
3760 flags: []string{"-check-close-notify"},
3761 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003762 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003763 // TODO(davidben): DTLS 1.3 will want a similar thing for
3764 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003765 tests = append(tests, testCase{
3766 name: "SkipHelloVerifyRequest",
3767 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003768 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003769 Bugs: ProtocolBugs{
3770 SkipHelloVerifyRequest: true,
3771 },
3772 },
3773 })
3774 }
3775
David Benjamin760b1dd2015-05-15 23:33:48 -04003776 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003777 test.protocol = config.protocol
3778 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003779 test.name += "-DTLS"
3780 }
David Benjamin582ba042016-07-07 12:33:25 -07003781 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003782 test.name += "-Async"
3783 test.flags = append(test.flags, "-async")
3784 } else {
3785 test.name += "-Sync"
3786 }
David Benjamin582ba042016-07-07 12:33:25 -07003787 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003788 test.name += "-SplitHandshakeRecords"
3789 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003790 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003791 test.config.Bugs.MaxPacketLength = 256
3792 test.flags = append(test.flags, "-mtu", "256")
3793 }
3794 }
David Benjamin582ba042016-07-07 12:33:25 -07003795 if config.packHandshakeFlight {
3796 test.name += "-PackHandshakeFlight"
3797 test.config.Bugs.PackHandshakeFlight = true
3798 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003799 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003800 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003801}
3802
Adam Langley524e7172015-02-20 16:04:00 -08003803func addDDoSCallbackTests() {
3804 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003805 for _, resume := range []bool{false, true} {
3806 suffix := "Resume"
3807 if resume {
3808 suffix = "No" + suffix
3809 }
3810
3811 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003812 testType: serverTest,
3813 name: "Server-DDoS-OK-" + suffix,
3814 config: Config{
3815 MaxVersion: VersionTLS12,
3816 },
Adam Langley524e7172015-02-20 16:04:00 -08003817 flags: []string{"-install-ddos-callback"},
3818 resumeSession: resume,
3819 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003820 testCases = append(testCases, testCase{
3821 testType: serverTest,
3822 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3823 config: Config{
3824 MaxVersion: VersionTLS13,
3825 },
3826 flags: []string{"-install-ddos-callback"},
3827 resumeSession: resume,
3828 })
Adam Langley524e7172015-02-20 16:04:00 -08003829
3830 failFlag := "-fail-ddos-callback"
3831 if resume {
3832 failFlag = "-fail-second-ddos-callback"
3833 }
3834 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003835 testType: serverTest,
3836 name: "Server-DDoS-Reject-" + suffix,
3837 config: Config{
3838 MaxVersion: VersionTLS12,
3839 },
Adam Langley524e7172015-02-20 16:04:00 -08003840 flags: []string{"-install-ddos-callback", failFlag},
3841 resumeSession: resume,
3842 shouldFail: true,
3843 expectedError: ":CONNECTION_REJECTED:",
3844 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003845 testCases = append(testCases, testCase{
3846 testType: serverTest,
3847 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3848 config: Config{
3849 MaxVersion: VersionTLS13,
3850 },
3851 flags: []string{"-install-ddos-callback", failFlag},
3852 resumeSession: resume,
3853 shouldFail: true,
3854 expectedError: ":CONNECTION_REJECTED:",
3855 })
Adam Langley524e7172015-02-20 16:04:00 -08003856 }
3857}
3858
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003859func addVersionNegotiationTests() {
3860 for i, shimVers := range tlsVersions {
3861 // Assemble flags to disable all newer versions on the shim.
3862 var flags []string
3863 for _, vers := range tlsVersions[i+1:] {
3864 flags = append(flags, vers.flag)
3865 }
3866
3867 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003868 protocols := []protocol{tls}
3869 if runnerVers.hasDTLS && shimVers.hasDTLS {
3870 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003871 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003872 for _, protocol := range protocols {
3873 expectedVersion := shimVers.version
3874 if runnerVers.version < shimVers.version {
3875 expectedVersion = runnerVers.version
3876 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003877
David Benjamin8b8c0062014-11-23 02:47:52 -05003878 suffix := shimVers.name + "-" + runnerVers.name
3879 if protocol == dtls {
3880 suffix += "-DTLS"
3881 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003882
David Benjamin1eb367c2014-12-12 18:17:51 -05003883 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3884
David Benjamin1e29a6b2014-12-10 02:27:24 -05003885 clientVers := shimVers.version
3886 if clientVers > VersionTLS10 {
3887 clientVers = VersionTLS10
3888 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003889 serverVers := expectedVersion
3890 if expectedVersion >= VersionTLS13 {
3891 serverVers = VersionTLS10
3892 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003893 testCases = append(testCases, testCase{
3894 protocol: protocol,
3895 testType: clientTest,
3896 name: "VersionNegotiation-Client-" + suffix,
3897 config: Config{
3898 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003899 Bugs: ProtocolBugs{
3900 ExpectInitialRecordVersion: clientVers,
3901 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003902 },
3903 flags: flags,
3904 expectedVersion: expectedVersion,
3905 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003906 testCases = append(testCases, testCase{
3907 protocol: protocol,
3908 testType: clientTest,
3909 name: "VersionNegotiation-Client2-" + suffix,
3910 config: Config{
3911 MaxVersion: runnerVers.version,
3912 Bugs: ProtocolBugs{
3913 ExpectInitialRecordVersion: clientVers,
3914 },
3915 },
3916 flags: []string{"-max-version", shimVersFlag},
3917 expectedVersion: expectedVersion,
3918 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003919
3920 testCases = append(testCases, testCase{
3921 protocol: protocol,
3922 testType: serverTest,
3923 name: "VersionNegotiation-Server-" + suffix,
3924 config: Config{
3925 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003926 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003927 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003928 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003929 },
3930 flags: flags,
3931 expectedVersion: expectedVersion,
3932 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003933 testCases = append(testCases, testCase{
3934 protocol: protocol,
3935 testType: serverTest,
3936 name: "VersionNegotiation-Server2-" + suffix,
3937 config: Config{
3938 MaxVersion: runnerVers.version,
3939 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003940 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003941 },
3942 },
3943 flags: []string{"-max-version", shimVersFlag},
3944 expectedVersion: expectedVersion,
3945 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003946 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003947 }
3948 }
David Benjamin95c69562016-06-29 18:15:03 -04003949
3950 // Test for version tolerance.
3951 testCases = append(testCases, testCase{
3952 testType: serverTest,
3953 name: "MinorVersionTolerance",
3954 config: Config{
3955 Bugs: ProtocolBugs{
3956 SendClientVersion: 0x03ff,
3957 },
3958 },
3959 expectedVersion: VersionTLS13,
3960 })
3961 testCases = append(testCases, testCase{
3962 testType: serverTest,
3963 name: "MajorVersionTolerance",
3964 config: Config{
3965 Bugs: ProtocolBugs{
3966 SendClientVersion: 0x0400,
3967 },
3968 },
3969 expectedVersion: VersionTLS13,
3970 })
3971 testCases = append(testCases, testCase{
3972 protocol: dtls,
3973 testType: serverTest,
3974 name: "MinorVersionTolerance-DTLS",
3975 config: Config{
3976 Bugs: ProtocolBugs{
3977 SendClientVersion: 0x03ff,
3978 },
3979 },
3980 expectedVersion: VersionTLS12,
3981 })
3982 testCases = append(testCases, testCase{
3983 protocol: dtls,
3984 testType: serverTest,
3985 name: "MajorVersionTolerance-DTLS",
3986 config: Config{
3987 Bugs: ProtocolBugs{
3988 SendClientVersion: 0x0400,
3989 },
3990 },
3991 expectedVersion: VersionTLS12,
3992 })
3993
3994 // Test that versions below 3.0 are rejected.
3995 testCases = append(testCases, testCase{
3996 testType: serverTest,
3997 name: "VersionTooLow",
3998 config: Config{
3999 Bugs: ProtocolBugs{
4000 SendClientVersion: 0x0200,
4001 },
4002 },
4003 shouldFail: true,
4004 expectedError: ":UNSUPPORTED_PROTOCOL:",
4005 })
4006 testCases = append(testCases, testCase{
4007 protocol: dtls,
4008 testType: serverTest,
4009 name: "VersionTooLow-DTLS",
4010 config: Config{
4011 Bugs: ProtocolBugs{
4012 // 0x0201 is the lowest version expressable in
4013 // DTLS.
4014 SendClientVersion: 0x0201,
4015 },
4016 },
4017 shouldFail: true,
4018 expectedError: ":UNSUPPORTED_PROTOCOL:",
4019 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004020
4021 // Test TLS 1.3's downgrade signal.
4022 testCases = append(testCases, testCase{
4023 name: "Downgrade-TLS12-Client",
4024 config: Config{
4025 Bugs: ProtocolBugs{
4026 NegotiateVersion: VersionTLS12,
4027 },
4028 },
4029 shouldFail: true,
4030 expectedError: ":DOWNGRADE_DETECTED:",
4031 })
4032 testCases = append(testCases, testCase{
4033 testType: serverTest,
4034 name: "Downgrade-TLS12-Server",
4035 config: Config{
4036 Bugs: ProtocolBugs{
4037 SendClientVersion: VersionTLS12,
4038 },
4039 },
4040 shouldFail: true,
4041 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4042 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004043
4044 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4045 // behave correctly when both real maximum and fallback versions are
4046 // set.
4047 testCases = append(testCases, testCase{
4048 name: "Downgrade-TLS12-Client-Fallback",
4049 config: Config{
4050 Bugs: ProtocolBugs{
4051 FailIfNotFallbackSCSV: true,
4052 },
4053 },
4054 flags: []string{
4055 "-max-version", strconv.Itoa(VersionTLS13),
4056 "-fallback-version", strconv.Itoa(VersionTLS12),
4057 },
4058 shouldFail: true,
4059 expectedError: ":DOWNGRADE_DETECTED:",
4060 })
4061 testCases = append(testCases, testCase{
4062 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4063 flags: []string{
4064 "-max-version", strconv.Itoa(VersionTLS12),
4065 "-fallback-version", strconv.Itoa(VersionTLS12),
4066 },
4067 })
4068
4069 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4070 // just have such connections fail than risk getting confused because we
4071 // didn't sent the 1.3 ClientHello.)
4072 testCases = append(testCases, testCase{
4073 name: "Downgrade-TLS12-Fallback-CheckVersion",
4074 config: Config{
4075 Bugs: ProtocolBugs{
4076 NegotiateVersion: VersionTLS13,
4077 FailIfNotFallbackSCSV: true,
4078 },
4079 },
4080 flags: []string{
4081 "-max-version", strconv.Itoa(VersionTLS13),
4082 "-fallback-version", strconv.Itoa(VersionTLS12),
4083 },
4084 shouldFail: true,
4085 expectedError: ":UNSUPPORTED_PROTOCOL:",
4086 })
4087
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004088}
4089
David Benjaminaccb4542014-12-12 23:44:33 -05004090func addMinimumVersionTests() {
4091 for i, shimVers := range tlsVersions {
4092 // Assemble flags to disable all older versions on the shim.
4093 var flags []string
4094 for _, vers := range tlsVersions[:i] {
4095 flags = append(flags, vers.flag)
4096 }
4097
4098 for _, runnerVers := range tlsVersions {
4099 protocols := []protocol{tls}
4100 if runnerVers.hasDTLS && shimVers.hasDTLS {
4101 protocols = append(protocols, dtls)
4102 }
4103 for _, protocol := range protocols {
4104 suffix := shimVers.name + "-" + runnerVers.name
4105 if protocol == dtls {
4106 suffix += "-DTLS"
4107 }
4108 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4109
David Benjaminaccb4542014-12-12 23:44:33 -05004110 var expectedVersion uint16
4111 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004112 var expectedClientError, expectedServerError string
4113 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004114 if runnerVers.version >= shimVers.version {
4115 expectedVersion = runnerVers.version
4116 } else {
4117 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004118 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4119 expectedServerLocalError = "remote error: protocol version not supported"
4120 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4121 // If the client's minimum version is TLS 1.3 and the runner's
4122 // maximum is below TLS 1.2, the runner will fail to select a
4123 // cipher before the shim rejects the selected version.
4124 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4125 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4126 } else {
4127 expectedClientError = expectedServerError
4128 expectedClientLocalError = expectedServerLocalError
4129 }
David Benjaminaccb4542014-12-12 23:44:33 -05004130 }
4131
4132 testCases = append(testCases, testCase{
4133 protocol: protocol,
4134 testType: clientTest,
4135 name: "MinimumVersion-Client-" + suffix,
4136 config: Config{
4137 MaxVersion: runnerVers.version,
4138 },
David Benjamin87909c02014-12-13 01:55:01 -05004139 flags: flags,
4140 expectedVersion: expectedVersion,
4141 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004142 expectedError: expectedClientError,
4143 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004144 })
4145 testCases = append(testCases, testCase{
4146 protocol: protocol,
4147 testType: clientTest,
4148 name: "MinimumVersion-Client2-" + suffix,
4149 config: Config{
4150 MaxVersion: runnerVers.version,
4151 },
David Benjamin87909c02014-12-13 01:55:01 -05004152 flags: []string{"-min-version", shimVersFlag},
4153 expectedVersion: expectedVersion,
4154 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004155 expectedError: expectedClientError,
4156 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004157 })
4158
4159 testCases = append(testCases, testCase{
4160 protocol: protocol,
4161 testType: serverTest,
4162 name: "MinimumVersion-Server-" + suffix,
4163 config: Config{
4164 MaxVersion: runnerVers.version,
4165 },
David Benjamin87909c02014-12-13 01:55:01 -05004166 flags: flags,
4167 expectedVersion: expectedVersion,
4168 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004169 expectedError: expectedServerError,
4170 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004171 })
4172 testCases = append(testCases, testCase{
4173 protocol: protocol,
4174 testType: serverTest,
4175 name: "MinimumVersion-Server2-" + suffix,
4176 config: Config{
4177 MaxVersion: runnerVers.version,
4178 },
David Benjamin87909c02014-12-13 01:55:01 -05004179 flags: []string{"-min-version", shimVersFlag},
4180 expectedVersion: expectedVersion,
4181 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004182 expectedError: expectedServerError,
4183 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004184 })
4185 }
4186 }
4187 }
4188}
4189
David Benjamine78bfde2014-09-06 12:45:15 -04004190func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004191 // TODO(davidben): Extensions, where applicable, all move their server
4192 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4193 // tests for both. Also test interaction with 0-RTT when implemented.
4194
David Benjamin97d17d92016-07-14 16:12:00 -04004195 // Repeat extensions tests all versions except SSL 3.0.
4196 for _, ver := range tlsVersions {
4197 if ver.version == VersionSSL30 {
4198 continue
4199 }
4200
David Benjamin97d17d92016-07-14 16:12:00 -04004201 // Test that duplicate extensions are rejected.
4202 testCases = append(testCases, testCase{
4203 testType: clientTest,
4204 name: "DuplicateExtensionClient-" + ver.name,
4205 config: Config{
4206 MaxVersion: ver.version,
4207 Bugs: ProtocolBugs{
4208 DuplicateExtension: true,
4209 },
David Benjamine78bfde2014-09-06 12:45:15 -04004210 },
David Benjamin97d17d92016-07-14 16:12:00 -04004211 shouldFail: true,
4212 expectedLocalError: "remote error: error decoding message",
4213 })
4214 testCases = append(testCases, testCase{
4215 testType: serverTest,
4216 name: "DuplicateExtensionServer-" + ver.name,
4217 config: Config{
4218 MaxVersion: ver.version,
4219 Bugs: ProtocolBugs{
4220 DuplicateExtension: true,
4221 },
David Benjamine78bfde2014-09-06 12:45:15 -04004222 },
David Benjamin97d17d92016-07-14 16:12:00 -04004223 shouldFail: true,
4224 expectedLocalError: "remote error: error decoding message",
4225 })
4226
4227 // Test SNI.
4228 testCases = append(testCases, testCase{
4229 testType: clientTest,
4230 name: "ServerNameExtensionClient-" + ver.name,
4231 config: Config{
4232 MaxVersion: ver.version,
4233 Bugs: ProtocolBugs{
4234 ExpectServerName: "example.com",
4235 },
David Benjamine78bfde2014-09-06 12:45:15 -04004236 },
David Benjamin97d17d92016-07-14 16:12:00 -04004237 flags: []string{"-host-name", "example.com"},
4238 })
4239 testCases = append(testCases, testCase{
4240 testType: clientTest,
4241 name: "ServerNameExtensionClientMismatch-" + ver.name,
4242 config: Config{
4243 MaxVersion: ver.version,
4244 Bugs: ProtocolBugs{
4245 ExpectServerName: "mismatch.com",
4246 },
David Benjamine78bfde2014-09-06 12:45:15 -04004247 },
David Benjamin97d17d92016-07-14 16:12:00 -04004248 flags: []string{"-host-name", "example.com"},
4249 shouldFail: true,
4250 expectedLocalError: "tls: unexpected server name",
4251 })
4252 testCases = append(testCases, testCase{
4253 testType: clientTest,
4254 name: "ServerNameExtensionClientMissing-" + ver.name,
4255 config: Config{
4256 MaxVersion: ver.version,
4257 Bugs: ProtocolBugs{
4258 ExpectServerName: "missing.com",
4259 },
David Benjamine78bfde2014-09-06 12:45:15 -04004260 },
David Benjamin97d17d92016-07-14 16:12:00 -04004261 shouldFail: true,
4262 expectedLocalError: "tls: unexpected server name",
4263 })
4264 testCases = append(testCases, testCase{
4265 testType: serverTest,
4266 name: "ServerNameExtensionServer-" + ver.name,
4267 config: Config{
4268 MaxVersion: ver.version,
4269 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004270 },
David Benjamin97d17d92016-07-14 16:12:00 -04004271 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004272 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004273 })
4274
4275 // Test ALPN.
4276 testCases = append(testCases, testCase{
4277 testType: clientTest,
4278 name: "ALPNClient-" + ver.name,
4279 config: Config{
4280 MaxVersion: ver.version,
4281 NextProtos: []string{"foo"},
4282 },
4283 flags: []string{
4284 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4285 "-expect-alpn", "foo",
4286 },
4287 expectedNextProto: "foo",
4288 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004289 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004290 })
4291 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004292 testType: clientTest,
4293 name: "ALPNClient-Mismatch-" + ver.name,
4294 config: Config{
4295 MaxVersion: ver.version,
4296 Bugs: ProtocolBugs{
4297 SendALPN: "baz",
4298 },
4299 },
4300 flags: []string{
4301 "-advertise-alpn", "\x03foo\x03bar",
4302 },
4303 shouldFail: true,
4304 expectedError: ":INVALID_ALPN_PROTOCOL:",
4305 expectedLocalError: "remote error: illegal parameter",
4306 })
4307 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004308 testType: serverTest,
4309 name: "ALPNServer-" + ver.name,
4310 config: Config{
4311 MaxVersion: ver.version,
4312 NextProtos: []string{"foo", "bar", "baz"},
4313 },
4314 flags: []string{
4315 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4316 "-select-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{
4323 testType: serverTest,
4324 name: "ALPNServer-Decline-" + ver.name,
4325 config: Config{
4326 MaxVersion: ver.version,
4327 NextProtos: []string{"foo", "bar", "baz"},
4328 },
4329 flags: []string{"-decline-alpn"},
4330 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004331 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004332 })
4333
David Benjamin25fe85b2016-08-09 20:00:32 -04004334 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4335 // called once.
4336 testCases = append(testCases, testCase{
4337 testType: serverTest,
4338 name: "ALPNServer-Async-" + ver.name,
4339 config: Config{
4340 MaxVersion: ver.version,
4341 NextProtos: []string{"foo", "bar", "baz"},
4342 },
4343 flags: []string{
4344 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4345 "-select-alpn", "foo",
4346 "-async",
4347 },
4348 expectedNextProto: "foo",
4349 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004350 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004351 })
4352
David Benjamin97d17d92016-07-14 16:12:00 -04004353 var emptyString string
4354 testCases = append(testCases, testCase{
4355 testType: clientTest,
4356 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4357 config: Config{
4358 MaxVersion: ver.version,
4359 NextProtos: []string{""},
4360 Bugs: ProtocolBugs{
4361 // A server returning an empty ALPN protocol
4362 // should be rejected.
4363 ALPNProtocol: &emptyString,
4364 },
4365 },
4366 flags: []string{
4367 "-advertise-alpn", "\x03foo",
4368 },
4369 shouldFail: true,
4370 expectedError: ":PARSE_TLSEXT:",
4371 })
4372 testCases = append(testCases, testCase{
4373 testType: serverTest,
4374 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4375 config: Config{
4376 MaxVersion: ver.version,
4377 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004378 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004379 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004380 },
David Benjamin97d17d92016-07-14 16:12:00 -04004381 flags: []string{
4382 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004383 },
David Benjamin97d17d92016-07-14 16:12:00 -04004384 shouldFail: true,
4385 expectedError: ":PARSE_TLSEXT:",
4386 })
4387
4388 // Test NPN and the interaction with ALPN.
4389 if ver.version < VersionTLS13 {
4390 // Test that the server prefers ALPN over NPN.
4391 testCases = append(testCases, testCase{
4392 testType: serverTest,
4393 name: "ALPNServer-Preferred-" + ver.name,
4394 config: Config{
4395 MaxVersion: ver.version,
4396 NextProtos: []string{"foo", "bar", "baz"},
4397 },
4398 flags: []string{
4399 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4400 "-select-alpn", "foo",
4401 "-advertise-npn", "\x03foo\x03bar\x03baz",
4402 },
4403 expectedNextProto: "foo",
4404 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004405 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004406 })
4407 testCases = append(testCases, testCase{
4408 testType: serverTest,
4409 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4410 config: Config{
4411 MaxVersion: ver.version,
4412 NextProtos: []string{"foo", "bar", "baz"},
4413 Bugs: ProtocolBugs{
4414 SwapNPNAndALPN: true,
4415 },
4416 },
4417 flags: []string{
4418 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4419 "-select-alpn", "foo",
4420 "-advertise-npn", "\x03foo\x03bar\x03baz",
4421 },
4422 expectedNextProto: "foo",
4423 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004424 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004425 })
4426
4427 // Test that negotiating both NPN and ALPN is forbidden.
4428 testCases = append(testCases, testCase{
4429 name: "NegotiateALPNAndNPN-" + ver.name,
4430 config: Config{
4431 MaxVersion: ver.version,
4432 NextProtos: []string{"foo", "bar", "baz"},
4433 Bugs: ProtocolBugs{
4434 NegotiateALPNAndNPN: true,
4435 },
4436 },
4437 flags: []string{
4438 "-advertise-alpn", "\x03foo",
4439 "-select-next-proto", "foo",
4440 },
4441 shouldFail: true,
4442 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4443 })
4444 testCases = append(testCases, testCase{
4445 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4446 config: Config{
4447 MaxVersion: ver.version,
4448 NextProtos: []string{"foo", "bar", "baz"},
4449 Bugs: ProtocolBugs{
4450 NegotiateALPNAndNPN: true,
4451 SwapNPNAndALPN: true,
4452 },
4453 },
4454 flags: []string{
4455 "-advertise-alpn", "\x03foo",
4456 "-select-next-proto", "foo",
4457 },
4458 shouldFail: true,
4459 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4460 })
4461
4462 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4463 testCases = append(testCases, testCase{
4464 name: "DisableNPN-" + ver.name,
4465 config: Config{
4466 MaxVersion: ver.version,
4467 NextProtos: []string{"foo"},
4468 },
4469 flags: []string{
4470 "-select-next-proto", "foo",
4471 "-disable-npn",
4472 },
4473 expectNoNextProto: true,
4474 })
4475 }
4476
4477 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004478
4479 // Resume with a corrupt ticket.
4480 testCases = append(testCases, testCase{
4481 testType: serverTest,
4482 name: "CorruptTicket-" + ver.name,
4483 config: Config{
4484 MaxVersion: ver.version,
4485 Bugs: ProtocolBugs{
4486 CorruptTicket: true,
4487 },
4488 },
4489 resumeSession: true,
4490 expectResumeRejected: true,
4491 })
4492 // Test the ticket callback, with and without renewal.
4493 testCases = append(testCases, testCase{
4494 testType: serverTest,
4495 name: "TicketCallback-" + ver.name,
4496 config: Config{
4497 MaxVersion: ver.version,
4498 },
4499 resumeSession: true,
4500 flags: []string{"-use-ticket-callback"},
4501 })
4502 testCases = append(testCases, testCase{
4503 testType: serverTest,
4504 name: "TicketCallback-Renew-" + ver.name,
4505 config: Config{
4506 MaxVersion: ver.version,
4507 Bugs: ProtocolBugs{
4508 ExpectNewTicket: true,
4509 },
4510 },
4511 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4512 resumeSession: true,
4513 })
4514
4515 // Test that the ticket callback is only called once when everything before
4516 // it in the ClientHello is asynchronous. This corrupts the ticket so
4517 // certificate selection callbacks run.
4518 testCases = append(testCases, testCase{
4519 testType: serverTest,
4520 name: "TicketCallback-SingleCall-" + ver.name,
4521 config: Config{
4522 MaxVersion: ver.version,
4523 Bugs: ProtocolBugs{
4524 CorruptTicket: true,
4525 },
4526 },
4527 resumeSession: true,
4528 expectResumeRejected: true,
4529 flags: []string{
4530 "-use-ticket-callback",
4531 "-async",
4532 },
4533 })
4534
4535 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004536 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004537 testCases = append(testCases, testCase{
4538 testType: serverTest,
4539 name: "OversizedSessionId-" + ver.name,
4540 config: Config{
4541 MaxVersion: ver.version,
4542 Bugs: ProtocolBugs{
4543 OversizedSessionId: true,
4544 },
4545 },
4546 resumeSession: true,
4547 shouldFail: true,
4548 expectedError: ":DECODE_ERROR:",
4549 })
4550 }
4551
4552 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4553 // are ignored.
4554 if ver.hasDTLS {
4555 testCases = append(testCases, testCase{
4556 protocol: dtls,
4557 name: "SRTP-Client-" + ver.name,
4558 config: Config{
4559 MaxVersion: ver.version,
4560 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4561 },
4562 flags: []string{
4563 "-srtp-profiles",
4564 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4565 },
4566 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4567 })
4568 testCases = append(testCases, testCase{
4569 protocol: dtls,
4570 testType: serverTest,
4571 name: "SRTP-Server-" + ver.name,
4572 config: Config{
4573 MaxVersion: ver.version,
4574 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4575 },
4576 flags: []string{
4577 "-srtp-profiles",
4578 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4579 },
4580 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4581 })
4582 // Test that the MKI is ignored.
4583 testCases = append(testCases, testCase{
4584 protocol: dtls,
4585 testType: serverTest,
4586 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4587 config: Config{
4588 MaxVersion: ver.version,
4589 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4590 Bugs: ProtocolBugs{
4591 SRTPMasterKeyIdentifer: "bogus",
4592 },
4593 },
4594 flags: []string{
4595 "-srtp-profiles",
4596 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4597 },
4598 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4599 })
4600 // Test that SRTP isn't negotiated on the server if there were
4601 // no matching profiles.
4602 testCases = append(testCases, testCase{
4603 protocol: dtls,
4604 testType: serverTest,
4605 name: "SRTP-Server-NoMatch-" + ver.name,
4606 config: Config{
4607 MaxVersion: ver.version,
4608 SRTPProtectionProfiles: []uint16{100, 101, 102},
4609 },
4610 flags: []string{
4611 "-srtp-profiles",
4612 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4613 },
4614 expectedSRTPProtectionProfile: 0,
4615 })
4616 // Test that the server returning an invalid SRTP profile is
4617 // flagged as an error by the client.
4618 testCases = append(testCases, testCase{
4619 protocol: dtls,
4620 name: "SRTP-Client-NoMatch-" + ver.name,
4621 config: Config{
4622 MaxVersion: ver.version,
4623 Bugs: ProtocolBugs{
4624 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4625 },
4626 },
4627 flags: []string{
4628 "-srtp-profiles",
4629 "SRTP_AES128_CM_SHA1_80",
4630 },
4631 shouldFail: true,
4632 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4633 })
4634 }
4635
4636 // Test SCT list.
4637 testCases = append(testCases, testCase{
4638 name: "SignedCertificateTimestampList-Client-" + ver.name,
4639 testType: clientTest,
4640 config: Config{
4641 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004642 },
David Benjamin97d17d92016-07-14 16:12:00 -04004643 flags: []string{
4644 "-enable-signed-cert-timestamps",
4645 "-expect-signed-cert-timestamps",
4646 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004647 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004648 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004649 })
4650 testCases = append(testCases, testCase{
4651 name: "SendSCTListOnResume-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 SendSCTListOnResume: []byte("bogus"),
4656 },
David Benjamind98452d2015-06-16 14:16:23 -04004657 },
David Benjamin97d17d92016-07-14 16:12:00 -04004658 flags: []string{
4659 "-enable-signed-cert-timestamps",
4660 "-expect-signed-cert-timestamps",
4661 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004662 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004663 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004664 })
4665 testCases = append(testCases, testCase{
4666 name: "SignedCertificateTimestampList-Server-" + ver.name,
4667 testType: serverTest,
4668 config: Config{
4669 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004670 },
David Benjamin97d17d92016-07-14 16:12:00 -04004671 flags: []string{
4672 "-signed-cert-timestamps",
4673 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004674 },
David Benjamin97d17d92016-07-14 16:12:00 -04004675 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004676 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004677 })
4678 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004679
Paul Lietar4fac72e2015-09-09 13:44:55 +01004680 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004681 testType: clientTest,
4682 name: "ClientHelloPadding",
4683 config: Config{
4684 Bugs: ProtocolBugs{
4685 RequireClientHelloSize: 512,
4686 },
4687 },
4688 // This hostname just needs to be long enough to push the
4689 // ClientHello into F5's danger zone between 256 and 511 bytes
4690 // long.
4691 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4692 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004693
4694 // Extensions should not function in SSL 3.0.
4695 testCases = append(testCases, testCase{
4696 testType: serverTest,
4697 name: "SSLv3Extensions-NoALPN",
4698 config: Config{
4699 MaxVersion: VersionSSL30,
4700 NextProtos: []string{"foo", "bar", "baz"},
4701 },
4702 flags: []string{
4703 "-select-alpn", "foo",
4704 },
4705 expectNoNextProto: true,
4706 })
4707
4708 // Test session tickets separately as they follow a different codepath.
4709 testCases = append(testCases, testCase{
4710 testType: serverTest,
4711 name: "SSLv3Extensions-NoTickets",
4712 config: Config{
4713 MaxVersion: VersionSSL30,
4714 Bugs: ProtocolBugs{
4715 // Historically, session tickets in SSL 3.0
4716 // failed in different ways depending on whether
4717 // the client supported renegotiation_info.
4718 NoRenegotiationInfo: true,
4719 },
4720 },
4721 resumeSession: true,
4722 })
4723 testCases = append(testCases, testCase{
4724 testType: serverTest,
4725 name: "SSLv3Extensions-NoTickets2",
4726 config: Config{
4727 MaxVersion: VersionSSL30,
4728 },
4729 resumeSession: true,
4730 })
4731
4732 // But SSL 3.0 does send and process renegotiation_info.
4733 testCases = append(testCases, testCase{
4734 testType: serverTest,
4735 name: "SSLv3Extensions-RenegotiationInfo",
4736 config: Config{
4737 MaxVersion: VersionSSL30,
4738 Bugs: ProtocolBugs{
4739 RequireRenegotiationInfo: true,
4740 },
4741 },
4742 })
4743 testCases = append(testCases, testCase{
4744 testType: serverTest,
4745 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4746 config: Config{
4747 MaxVersion: VersionSSL30,
4748 Bugs: ProtocolBugs{
4749 NoRenegotiationInfo: true,
4750 SendRenegotiationSCSV: true,
4751 RequireRenegotiationInfo: true,
4752 },
4753 },
4754 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004755
4756 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4757 // in ServerHello.
4758 testCases = append(testCases, testCase{
4759 name: "NPN-Forbidden-TLS13",
4760 config: Config{
4761 MaxVersion: VersionTLS13,
4762 NextProtos: []string{"foo"},
4763 Bugs: ProtocolBugs{
4764 NegotiateNPNAtAllVersions: true,
4765 },
4766 },
4767 flags: []string{"-select-next-proto", "foo"},
4768 shouldFail: true,
4769 expectedError: ":ERROR_PARSING_EXTENSION:",
4770 })
4771 testCases = append(testCases, testCase{
4772 name: "EMS-Forbidden-TLS13",
4773 config: Config{
4774 MaxVersion: VersionTLS13,
4775 Bugs: ProtocolBugs{
4776 NegotiateEMSAtAllVersions: true,
4777 },
4778 },
4779 shouldFail: true,
4780 expectedError: ":ERROR_PARSING_EXTENSION:",
4781 })
4782 testCases = append(testCases, testCase{
4783 name: "RenegotiationInfo-Forbidden-TLS13",
4784 config: Config{
4785 MaxVersion: VersionTLS13,
4786 Bugs: ProtocolBugs{
4787 NegotiateRenegotiationInfoAtAllVersions: true,
4788 },
4789 },
4790 shouldFail: true,
4791 expectedError: ":ERROR_PARSING_EXTENSION:",
4792 })
4793 testCases = append(testCases, testCase{
4794 name: "ChannelID-Forbidden-TLS13",
4795 config: Config{
4796 MaxVersion: VersionTLS13,
4797 RequestChannelID: true,
4798 Bugs: ProtocolBugs{
4799 NegotiateChannelIDAtAllVersions: true,
4800 },
4801 },
4802 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4803 shouldFail: true,
4804 expectedError: ":ERROR_PARSING_EXTENSION:",
4805 })
4806 testCases = append(testCases, testCase{
4807 name: "Ticket-Forbidden-TLS13",
4808 config: Config{
4809 MaxVersion: VersionTLS12,
4810 },
4811 resumeConfig: &Config{
4812 MaxVersion: VersionTLS13,
4813 Bugs: ProtocolBugs{
4814 AdvertiseTicketExtension: true,
4815 },
4816 },
4817 resumeSession: true,
4818 shouldFail: true,
4819 expectedError: ":ERROR_PARSING_EXTENSION:",
4820 })
4821
4822 // Test that illegal extensions in TLS 1.3 are declined by the server if
4823 // offered in ClientHello. The runner's server will fail if this occurs,
4824 // so we exercise the offering path. (EMS and Renegotiation Info are
4825 // implicit in every test.)
4826 testCases = append(testCases, testCase{
4827 testType: serverTest,
4828 name: "ChannelID-Declined-TLS13",
4829 config: Config{
4830 MaxVersion: VersionTLS13,
4831 ChannelID: channelIDKey,
4832 },
4833 flags: []string{"-enable-channel-id"},
4834 })
4835 testCases = append(testCases, testCase{
4836 testType: serverTest,
4837 name: "NPN-Server",
4838 config: Config{
4839 MaxVersion: VersionTLS13,
4840 NextProtos: []string{"bar"},
4841 },
4842 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4843 })
David Benjamine78bfde2014-09-06 12:45:15 -04004844}
4845
David Benjamin01fe8202014-09-24 15:21:44 -04004846func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004847 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004848 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004849 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4850 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4851 // TLS 1.3 only shares ciphers with TLS 1.2, so
4852 // we skip certain combinations and use a
4853 // different cipher to test with.
4854 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4855 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4856 continue
4857 }
4858 }
4859
David Benjamin8b8c0062014-11-23 02:47:52 -05004860 protocols := []protocol{tls}
4861 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4862 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004863 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004864 for _, protocol := range protocols {
4865 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4866 if protocol == dtls {
4867 suffix += "-DTLS"
4868 }
4869
David Benjaminece3de92015-03-16 18:02:20 -04004870 if sessionVers.version == resumeVers.version {
4871 testCases = append(testCases, testCase{
4872 protocol: protocol,
4873 name: "Resume-Client" + suffix,
4874 resumeSession: true,
4875 config: Config{
4876 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004877 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004878 Bugs: ProtocolBugs{
4879 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4880 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4881 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004882 },
David Benjaminece3de92015-03-16 18:02:20 -04004883 expectedVersion: sessionVers.version,
4884 expectedResumeVersion: resumeVers.version,
4885 })
4886 } else {
David Benjamin405da482016-08-08 17:25:07 -04004887 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4888
4889 // Offering a TLS 1.3 session sends an empty session ID, so
4890 // there is no way to convince a non-lookahead client the
4891 // session was resumed. It will appear to the client that a
4892 // stray ChangeCipherSpec was sent.
4893 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4894 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004895 }
4896
David Benjaminece3de92015-03-16 18:02:20 -04004897 testCases = append(testCases, testCase{
4898 protocol: protocol,
4899 name: "Resume-Client-Mismatch" + suffix,
4900 resumeSession: true,
4901 config: Config{
4902 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004903 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004904 },
David Benjaminece3de92015-03-16 18:02:20 -04004905 expectedVersion: sessionVers.version,
4906 resumeConfig: &Config{
4907 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004908 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004909 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004910 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004911 },
4912 },
4913 expectedResumeVersion: resumeVers.version,
4914 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004915 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004916 })
4917 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004918
4919 testCases = append(testCases, testCase{
4920 protocol: protocol,
4921 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004922 resumeSession: true,
4923 config: Config{
4924 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004925 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004926 },
4927 expectedVersion: sessionVers.version,
4928 resumeConfig: &Config{
4929 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004930 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004931 },
4932 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004933 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004934 expectedResumeVersion: resumeVers.version,
4935 })
4936
David Benjamin8b8c0062014-11-23 02:47:52 -05004937 testCases = append(testCases, testCase{
4938 protocol: protocol,
4939 testType: serverTest,
4940 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004941 resumeSession: true,
4942 config: Config{
4943 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004944 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004945 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004946 expectedVersion: sessionVers.version,
4947 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004948 resumeConfig: &Config{
4949 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004950 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004951 Bugs: ProtocolBugs{
4952 SendBothTickets: true,
4953 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004954 },
4955 expectedResumeVersion: resumeVers.version,
4956 })
4957 }
David Benjamin01fe8202014-09-24 15:21:44 -04004958 }
4959 }
David Benjaminece3de92015-03-16 18:02:20 -04004960
4961 testCases = append(testCases, testCase{
4962 name: "Resume-Client-CipherMismatch",
4963 resumeSession: true,
4964 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004965 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004966 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4967 },
4968 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004969 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004970 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4971 Bugs: ProtocolBugs{
4972 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4973 },
4974 },
4975 shouldFail: true,
4976 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4977 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004978
4979 testCases = append(testCases, testCase{
4980 name: "Resume-Client-CipherMismatch-TLS13",
4981 resumeSession: true,
4982 config: Config{
4983 MaxVersion: VersionTLS13,
4984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4985 },
4986 resumeConfig: &Config{
4987 MaxVersion: VersionTLS13,
4988 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4989 Bugs: ProtocolBugs{
4990 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
4991 },
4992 },
4993 shouldFail: true,
4994 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4995 })
David Benjamin01fe8202014-09-24 15:21:44 -04004996}
4997
Adam Langley2ae77d22014-10-28 17:29:33 -07004998func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004999 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005000 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005001 testType: serverTest,
5002 name: "Renegotiate-Server-Forbidden",
5003 config: Config{
5004 MaxVersion: VersionTLS12,
5005 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005006 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005007 shouldFail: true,
5008 expectedError: ":NO_RENEGOTIATION:",
5009 expectedLocalError: "remote error: no renegotiation",
5010 })
Adam Langley5021b222015-06-12 18:27:58 -07005011 // The server shouldn't echo the renegotiation extension unless
5012 // requested by the client.
5013 testCases = append(testCases, testCase{
5014 testType: serverTest,
5015 name: "Renegotiate-Server-NoExt",
5016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005017 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005018 Bugs: ProtocolBugs{
5019 NoRenegotiationInfo: true,
5020 RequireRenegotiationInfo: true,
5021 },
5022 },
5023 shouldFail: true,
5024 expectedLocalError: "renegotiation extension missing",
5025 })
5026 // The renegotiation SCSV should be sufficient for the server to echo
5027 // the extension.
5028 testCases = append(testCases, testCase{
5029 testType: serverTest,
5030 name: "Renegotiate-Server-NoExt-SCSV",
5031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005032 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005033 Bugs: ProtocolBugs{
5034 NoRenegotiationInfo: true,
5035 SendRenegotiationSCSV: true,
5036 RequireRenegotiationInfo: true,
5037 },
5038 },
5039 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005040 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005041 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005043 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005044 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005045 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005046 },
5047 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005048 renegotiate: 1,
5049 flags: []string{
5050 "-renegotiate-freely",
5051 "-expect-total-renegotiations", "1",
5052 },
David Benjamincdea40c2015-03-19 14:09:43 -04005053 })
5054 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005055 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005056 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005058 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005059 Bugs: ProtocolBugs{
5060 EmptyRenegotiationInfo: true,
5061 },
5062 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005063 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005064 shouldFail: true,
5065 expectedError: ":RENEGOTIATION_MISMATCH:",
5066 })
5067 testCases = append(testCases, testCase{
5068 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005069 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005071 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005072 Bugs: ProtocolBugs{
5073 BadRenegotiationInfo: true,
5074 },
5075 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005076 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005077 shouldFail: true,
5078 expectedError: ":RENEGOTIATION_MISMATCH:",
5079 })
5080 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005081 name: "Renegotiate-Client-Downgrade",
5082 renegotiate: 1,
5083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005084 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005085 Bugs: ProtocolBugs{
5086 NoRenegotiationInfoAfterInitial: true,
5087 },
5088 },
5089 flags: []string{"-renegotiate-freely"},
5090 shouldFail: true,
5091 expectedError: ":RENEGOTIATION_MISMATCH:",
5092 })
5093 testCases = append(testCases, testCase{
5094 name: "Renegotiate-Client-Upgrade",
5095 renegotiate: 1,
5096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005097 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005098 Bugs: ProtocolBugs{
5099 NoRenegotiationInfoInInitial: true,
5100 },
5101 },
5102 flags: []string{"-renegotiate-freely"},
5103 shouldFail: true,
5104 expectedError: ":RENEGOTIATION_MISMATCH:",
5105 })
5106 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005107 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005108 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005110 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005111 Bugs: ProtocolBugs{
5112 NoRenegotiationInfo: true,
5113 },
5114 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005115 flags: []string{
5116 "-renegotiate-freely",
5117 "-expect-total-renegotiations", "1",
5118 },
David Benjamincff0b902015-05-15 23:09:47 -04005119 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005120
5121 // Test that the server may switch ciphers on renegotiation without
5122 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005123 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005124 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005125 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005126 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005127 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005128 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5129 },
5130 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005131 flags: []string{
5132 "-renegotiate-freely",
5133 "-expect-total-renegotiations", "1",
5134 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005135 })
5136 testCases = append(testCases, testCase{
5137 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005139 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005140 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005141 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5142 },
5143 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005144 flags: []string{
5145 "-renegotiate-freely",
5146 "-expect-total-renegotiations", "1",
5147 },
David Benjaminb16346b2015-04-08 19:16:58 -04005148 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005149
5150 // Test that the server may not switch versions on renegotiation.
5151 testCases = append(testCases, testCase{
5152 name: "Renegotiate-Client-SwitchVersion",
5153 config: Config{
5154 MaxVersion: VersionTLS12,
5155 // Pick a cipher which exists at both versions.
5156 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5157 Bugs: ProtocolBugs{
5158 NegotiateVersionOnRenego: VersionTLS11,
5159 },
5160 },
5161 renegotiate: 1,
5162 flags: []string{
5163 "-renegotiate-freely",
5164 "-expect-total-renegotiations", "1",
5165 },
5166 shouldFail: true,
5167 expectedError: ":WRONG_SSL_VERSION:",
5168 })
5169
David Benjaminb16346b2015-04-08 19:16:58 -04005170 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005171 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005172 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005173 config: Config{
5174 MaxVersion: VersionTLS10,
5175 Bugs: ProtocolBugs{
5176 RequireSameRenegoClientVersion: true,
5177 },
5178 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005179 flags: []string{
5180 "-renegotiate-freely",
5181 "-expect-total-renegotiations", "1",
5182 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005183 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005184 testCases = append(testCases, testCase{
5185 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005186 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005187 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005188 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5190 NextProtos: []string{"foo"},
5191 },
5192 flags: []string{
5193 "-false-start",
5194 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005195 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005196 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005197 },
5198 shimWritesFirst: true,
5199 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005200
5201 // Client-side renegotiation controls.
5202 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005203 name: "Renegotiate-Client-Forbidden-1",
5204 config: Config{
5205 MaxVersion: VersionTLS12,
5206 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005207 renegotiate: 1,
5208 shouldFail: true,
5209 expectedError: ":NO_RENEGOTIATION:",
5210 expectedLocalError: "remote error: no renegotiation",
5211 })
5212 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005213 name: "Renegotiate-Client-Once-1",
5214 config: Config{
5215 MaxVersion: VersionTLS12,
5216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005217 renegotiate: 1,
5218 flags: []string{
5219 "-renegotiate-once",
5220 "-expect-total-renegotiations", "1",
5221 },
5222 })
5223 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005224 name: "Renegotiate-Client-Freely-1",
5225 config: Config{
5226 MaxVersion: VersionTLS12,
5227 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005228 renegotiate: 1,
5229 flags: []string{
5230 "-renegotiate-freely",
5231 "-expect-total-renegotiations", "1",
5232 },
5233 })
5234 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005235 name: "Renegotiate-Client-Once-2",
5236 config: Config{
5237 MaxVersion: VersionTLS12,
5238 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005239 renegotiate: 2,
5240 flags: []string{"-renegotiate-once"},
5241 shouldFail: true,
5242 expectedError: ":NO_RENEGOTIATION:",
5243 expectedLocalError: "remote error: no renegotiation",
5244 })
5245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005246 name: "Renegotiate-Client-Freely-2",
5247 config: Config{
5248 MaxVersion: VersionTLS12,
5249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005250 renegotiate: 2,
5251 flags: []string{
5252 "-renegotiate-freely",
5253 "-expect-total-renegotiations", "2",
5254 },
5255 })
Adam Langley27a0d082015-11-03 13:34:10 -08005256 testCases = append(testCases, testCase{
5257 name: "Renegotiate-Client-NoIgnore",
5258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005259 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005260 Bugs: ProtocolBugs{
5261 SendHelloRequestBeforeEveryAppDataRecord: true,
5262 },
5263 },
5264 shouldFail: true,
5265 expectedError: ":NO_RENEGOTIATION:",
5266 })
5267 testCases = append(testCases, testCase{
5268 name: "Renegotiate-Client-Ignore",
5269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005270 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005271 Bugs: ProtocolBugs{
5272 SendHelloRequestBeforeEveryAppDataRecord: true,
5273 },
5274 },
5275 flags: []string{
5276 "-renegotiate-ignore",
5277 "-expect-total-renegotiations", "0",
5278 },
5279 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005280
David Benjamin397c8e62016-07-08 14:14:36 -07005281 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005282 testCases = append(testCases, testCase{
5283 name: "StrayHelloRequest",
5284 config: Config{
5285 MaxVersion: VersionTLS12,
5286 Bugs: ProtocolBugs{
5287 SendHelloRequestBeforeEveryHandshakeMessage: true,
5288 },
5289 },
5290 })
5291 testCases = append(testCases, testCase{
5292 name: "StrayHelloRequest-Packed",
5293 config: Config{
5294 MaxVersion: VersionTLS12,
5295 Bugs: ProtocolBugs{
5296 PackHandshakeFlight: true,
5297 SendHelloRequestBeforeEveryHandshakeMessage: true,
5298 },
5299 },
5300 })
5301
David Benjamin12d2c482016-07-24 10:56:51 -04005302 // Test renegotiation works if HelloRequest and server Finished come in
5303 // the same record.
5304 testCases = append(testCases, testCase{
5305 name: "Renegotiate-Client-Packed",
5306 config: Config{
5307 MaxVersion: VersionTLS12,
5308 Bugs: ProtocolBugs{
5309 PackHandshakeFlight: true,
5310 PackHelloRequestWithFinished: true,
5311 },
5312 },
5313 renegotiate: 1,
5314 flags: []string{
5315 "-renegotiate-freely",
5316 "-expect-total-renegotiations", "1",
5317 },
5318 })
5319
David Benjamin397c8e62016-07-08 14:14:36 -07005320 // Renegotiation is forbidden in TLS 1.3.
5321 testCases = append(testCases, testCase{
5322 name: "Renegotiate-Client-TLS13",
5323 config: Config{
5324 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005325 Bugs: ProtocolBugs{
5326 SendHelloRequestBeforeEveryAppDataRecord: true,
5327 },
David Benjamin397c8e62016-07-08 14:14:36 -07005328 },
David Benjamin397c8e62016-07-08 14:14:36 -07005329 flags: []string{
5330 "-renegotiate-freely",
5331 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005332 shouldFail: true,
5333 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005334 })
5335
5336 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5337 testCases = append(testCases, testCase{
5338 name: "StrayHelloRequest-TLS13",
5339 config: Config{
5340 MaxVersion: VersionTLS13,
5341 Bugs: ProtocolBugs{
5342 SendHelloRequestBeforeEveryHandshakeMessage: true,
5343 },
5344 },
5345 shouldFail: true,
5346 expectedError: ":UNEXPECTED_MESSAGE:",
5347 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005348}
5349
David Benjamin5e961c12014-11-07 01:48:35 -05005350func addDTLSReplayTests() {
5351 // Test that sequence number replays are detected.
5352 testCases = append(testCases, testCase{
5353 protocol: dtls,
5354 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005355 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005356 replayWrites: true,
5357 })
5358
David Benjamin8e6db492015-07-25 18:29:23 -04005359 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005360 // than the retransmit window.
5361 testCases = append(testCases, testCase{
5362 protocol: dtls,
5363 name: "DTLS-Replay-LargeGaps",
5364 config: Config{
5365 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005366 SequenceNumberMapping: func(in uint64) uint64 {
5367 return in * 127
5368 },
David Benjamin5e961c12014-11-07 01:48:35 -05005369 },
5370 },
David Benjamin8e6db492015-07-25 18:29:23 -04005371 messageCount: 200,
5372 replayWrites: true,
5373 })
5374
5375 // Test the incoming sequence number changing non-monotonically.
5376 testCases = append(testCases, testCase{
5377 protocol: dtls,
5378 name: "DTLS-Replay-NonMonotonic",
5379 config: Config{
5380 Bugs: ProtocolBugs{
5381 SequenceNumberMapping: func(in uint64) uint64 {
5382 return in ^ 31
5383 },
5384 },
5385 },
5386 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005387 replayWrites: true,
5388 })
5389}
5390
Nick Harper60edffd2016-06-21 15:19:24 -07005391var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005392 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005393 id signatureAlgorithm
5394 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005395}{
Nick Harper60edffd2016-06-21 15:19:24 -07005396 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5397 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5398 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5399 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005400 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005401 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5402 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5403 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005404 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5405 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5406 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005407 // Tests for key types prior to TLS 1.2.
5408 {"RSA", 0, testCertRSA},
5409 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005410}
5411
Nick Harper60edffd2016-06-21 15:19:24 -07005412const fakeSigAlg1 signatureAlgorithm = 0x2a01
5413const fakeSigAlg2 signatureAlgorithm = 0xff01
5414
5415func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005416 // Not all ciphers involve a signature. Advertise a list which gives all
5417 // versions a signing cipher.
5418 signingCiphers := []uint16{
5419 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5420 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5421 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5422 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5423 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5424 }
5425
David Benjaminca3d5452016-07-14 12:51:01 -04005426 var allAlgorithms []signatureAlgorithm
5427 for _, alg := range testSignatureAlgorithms {
5428 if alg.id != 0 {
5429 allAlgorithms = append(allAlgorithms, alg.id)
5430 }
5431 }
5432
Nick Harper60edffd2016-06-21 15:19:24 -07005433 // Make sure each signature algorithm works. Include some fake values in
5434 // the list and ensure they're ignored.
5435 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005436 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005437 if (ver.version < VersionTLS12) != (alg.id == 0) {
5438 continue
5439 }
5440
5441 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5442 // or remove it in C.
5443 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005444 continue
5445 }
Nick Harper60edffd2016-06-21 15:19:24 -07005446
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005447 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005448 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005449 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5450 shouldFail = true
5451 }
5452 // RSA-PSS does not exist in TLS 1.2.
5453 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5454 shouldFail = true
5455 }
5456
5457 var signError, verifyError string
5458 if shouldFail {
5459 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5460 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005461 }
David Benjamin000800a2014-11-14 01:43:59 -05005462
David Benjamin1fb125c2016-07-08 18:52:12 -07005463 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005464
David Benjamin7a41d372016-07-09 11:21:54 -07005465 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005466 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005467 config: Config{
5468 MaxVersion: ver.version,
5469 ClientAuth: RequireAnyClientCert,
5470 VerifySignatureAlgorithms: []signatureAlgorithm{
5471 fakeSigAlg1,
5472 alg.id,
5473 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005474 },
David Benjamin7a41d372016-07-09 11:21:54 -07005475 },
5476 flags: []string{
5477 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5478 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5479 "-enable-all-curves",
5480 },
5481 shouldFail: shouldFail,
5482 expectedError: signError,
5483 expectedPeerSignatureAlgorithm: alg.id,
5484 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005485
David Benjamin7a41d372016-07-09 11:21:54 -07005486 testCases = append(testCases, testCase{
5487 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005488 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005489 config: Config{
5490 MaxVersion: ver.version,
5491 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5492 SignSignatureAlgorithms: []signatureAlgorithm{
5493 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005494 },
David Benjamin7a41d372016-07-09 11:21:54 -07005495 Bugs: ProtocolBugs{
5496 SkipECDSACurveCheck: shouldFail,
5497 IgnoreSignatureVersionChecks: shouldFail,
5498 // The client won't advertise 1.3-only algorithms after
5499 // version negotiation.
5500 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005501 },
David Benjamin7a41d372016-07-09 11:21:54 -07005502 },
5503 flags: []string{
5504 "-require-any-client-certificate",
5505 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5506 "-enable-all-curves",
5507 },
5508 shouldFail: shouldFail,
5509 expectedError: verifyError,
5510 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005511
5512 testCases = append(testCases, testCase{
5513 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005514 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005515 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005516 MaxVersion: ver.version,
5517 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005518 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005519 fakeSigAlg1,
5520 alg.id,
5521 fakeSigAlg2,
5522 },
5523 },
5524 flags: []string{
5525 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5526 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5527 "-enable-all-curves",
5528 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005529 shouldFail: shouldFail,
5530 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005531 expectedPeerSignatureAlgorithm: alg.id,
5532 })
5533
5534 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005535 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005536 config: Config{
5537 MaxVersion: ver.version,
5538 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005539 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005540 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005541 alg.id,
5542 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005543 Bugs: ProtocolBugs{
5544 SkipECDSACurveCheck: shouldFail,
5545 IgnoreSignatureVersionChecks: shouldFail,
5546 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005547 },
5548 flags: []string{
5549 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5550 "-enable-all-curves",
5551 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005552 shouldFail: shouldFail,
5553 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005554 })
David Benjamin5208fd42016-07-13 21:43:25 -04005555
5556 if !shouldFail {
5557 testCases = append(testCases, testCase{
5558 testType: serverTest,
5559 name: "ClientAuth-InvalidSignature" + suffix,
5560 config: Config{
5561 MaxVersion: ver.version,
5562 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5563 SignSignatureAlgorithms: []signatureAlgorithm{
5564 alg.id,
5565 },
5566 Bugs: ProtocolBugs{
5567 InvalidSignature: true,
5568 },
5569 },
5570 flags: []string{
5571 "-require-any-client-certificate",
5572 "-enable-all-curves",
5573 },
5574 shouldFail: true,
5575 expectedError: ":BAD_SIGNATURE:",
5576 })
5577
5578 testCases = append(testCases, testCase{
5579 name: "ServerAuth-InvalidSignature" + suffix,
5580 config: Config{
5581 MaxVersion: ver.version,
5582 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5583 CipherSuites: signingCiphers,
5584 SignSignatureAlgorithms: []signatureAlgorithm{
5585 alg.id,
5586 },
5587 Bugs: ProtocolBugs{
5588 InvalidSignature: true,
5589 },
5590 },
5591 flags: []string{"-enable-all-curves"},
5592 shouldFail: true,
5593 expectedError: ":BAD_SIGNATURE:",
5594 })
5595 }
David Benjaminca3d5452016-07-14 12:51:01 -04005596
5597 if ver.version >= VersionTLS12 && !shouldFail {
5598 testCases = append(testCases, testCase{
5599 name: "ClientAuth-Sign-Negotiate" + suffix,
5600 config: Config{
5601 MaxVersion: ver.version,
5602 ClientAuth: RequireAnyClientCert,
5603 VerifySignatureAlgorithms: allAlgorithms,
5604 },
5605 flags: []string{
5606 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5607 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5608 "-enable-all-curves",
5609 "-signing-prefs", strconv.Itoa(int(alg.id)),
5610 },
5611 expectedPeerSignatureAlgorithm: alg.id,
5612 })
5613
5614 testCases = append(testCases, testCase{
5615 testType: serverTest,
5616 name: "ServerAuth-Sign-Negotiate" + suffix,
5617 config: Config{
5618 MaxVersion: ver.version,
5619 CipherSuites: signingCiphers,
5620 VerifySignatureAlgorithms: allAlgorithms,
5621 },
5622 flags: []string{
5623 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5624 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5625 "-enable-all-curves",
5626 "-signing-prefs", strconv.Itoa(int(alg.id)),
5627 },
5628 expectedPeerSignatureAlgorithm: alg.id,
5629 })
5630 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005631 }
David Benjamin000800a2014-11-14 01:43:59 -05005632 }
5633
Nick Harper60edffd2016-06-21 15:19:24 -07005634 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005635 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005636 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005637 config: Config{
5638 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005639 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005640 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005641 signatureECDSAWithP521AndSHA512,
5642 signatureRSAPKCS1WithSHA384,
5643 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005644 },
5645 },
5646 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005647 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5648 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005649 },
Nick Harper60edffd2016-06-21 15:19:24 -07005650 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005651 })
5652
5653 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005654 name: "ClientAuth-SignatureType-TLS13",
5655 config: Config{
5656 ClientAuth: RequireAnyClientCert,
5657 MaxVersion: VersionTLS13,
5658 VerifySignatureAlgorithms: []signatureAlgorithm{
5659 signatureECDSAWithP521AndSHA512,
5660 signatureRSAPKCS1WithSHA384,
5661 signatureRSAPSSWithSHA384,
5662 signatureECDSAWithSHA1,
5663 },
5664 },
5665 flags: []string{
5666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5668 },
5669 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5670 })
5671
5672 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005673 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005674 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005676 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005677 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005678 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005679 signatureECDSAWithP521AndSHA512,
5680 signatureRSAPKCS1WithSHA384,
5681 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005682 },
5683 },
Nick Harper60edffd2016-06-21 15:19:24 -07005684 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005685 })
5686
Steven Valdez143e8b32016-07-11 13:19:03 -04005687 testCases = append(testCases, testCase{
5688 testType: serverTest,
5689 name: "ServerAuth-SignatureType-TLS13",
5690 config: Config{
5691 MaxVersion: VersionTLS13,
5692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5693 VerifySignatureAlgorithms: []signatureAlgorithm{
5694 signatureECDSAWithP521AndSHA512,
5695 signatureRSAPKCS1WithSHA384,
5696 signatureRSAPSSWithSHA384,
5697 signatureECDSAWithSHA1,
5698 },
5699 },
5700 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5701 })
5702
David Benjamina95e9f32016-07-08 16:28:04 -07005703 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005704 testCases = append(testCases, testCase{
5705 testType: serverTest,
5706 name: "Verify-ClientAuth-SignatureType",
5707 config: Config{
5708 MaxVersion: VersionTLS12,
5709 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005710 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005711 signatureRSAPKCS1WithSHA256,
5712 },
5713 Bugs: ProtocolBugs{
5714 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5715 },
5716 },
5717 flags: []string{
5718 "-require-any-client-certificate",
5719 },
5720 shouldFail: true,
5721 expectedError: ":WRONG_SIGNATURE_TYPE:",
5722 })
5723
5724 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005725 testType: serverTest,
5726 name: "Verify-ClientAuth-SignatureType-TLS13",
5727 config: Config{
5728 MaxVersion: VersionTLS13,
5729 Certificates: []Certificate{rsaCertificate},
5730 SignSignatureAlgorithms: []signatureAlgorithm{
5731 signatureRSAPSSWithSHA256,
5732 },
5733 Bugs: ProtocolBugs{
5734 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5735 },
5736 },
5737 flags: []string{
5738 "-require-any-client-certificate",
5739 },
5740 shouldFail: true,
5741 expectedError: ":WRONG_SIGNATURE_TYPE:",
5742 })
5743
5744 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005745 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005746 config: Config{
5747 MaxVersion: VersionTLS12,
5748 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005749 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005750 signatureRSAPKCS1WithSHA256,
5751 },
5752 Bugs: ProtocolBugs{
5753 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5754 },
5755 },
5756 shouldFail: true,
5757 expectedError: ":WRONG_SIGNATURE_TYPE:",
5758 })
5759
Steven Valdez143e8b32016-07-11 13:19:03 -04005760 testCases = append(testCases, testCase{
5761 name: "Verify-ServerAuth-SignatureType-TLS13",
5762 config: Config{
5763 MaxVersion: VersionTLS13,
5764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5765 SignSignatureAlgorithms: []signatureAlgorithm{
5766 signatureRSAPSSWithSHA256,
5767 },
5768 Bugs: ProtocolBugs{
5769 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5770 },
5771 },
5772 shouldFail: true,
5773 expectedError: ":WRONG_SIGNATURE_TYPE:",
5774 })
5775
David Benjamin51dd7d62016-07-08 16:07:01 -07005776 // Test that, if the list is missing, the peer falls back to SHA-1 in
5777 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005778 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005779 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005781 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005782 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005783 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005784 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005785 },
5786 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005787 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005788 },
5789 },
5790 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005791 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5792 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005793 },
5794 })
5795
5796 testCases = append(testCases, testCase{
5797 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005798 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005800 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005802 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005803 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005804 },
5805 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005806 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005807 },
5808 },
5809 })
David Benjamin72dc7832015-03-16 17:49:43 -04005810
David Benjamin51dd7d62016-07-08 16:07:01 -07005811 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005812 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005813 config: Config{
5814 MaxVersion: VersionTLS13,
5815 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005816 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005817 signatureRSAPKCS1WithSHA1,
5818 },
5819 Bugs: ProtocolBugs{
5820 NoSignatureAlgorithms: true,
5821 },
5822 },
5823 flags: []string{
5824 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5825 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5826 },
David Benjamin48901652016-08-01 12:12:47 -04005827 shouldFail: true,
5828 // An empty CertificateRequest signature algorithm list is a
5829 // syntax error in TLS 1.3.
5830 expectedError: ":DECODE_ERROR:",
5831 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005832 })
5833
5834 testCases = append(testCases, testCase{
5835 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005836 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005837 config: Config{
5838 MaxVersion: VersionTLS13,
5839 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005840 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005841 signatureRSAPKCS1WithSHA1,
5842 },
5843 Bugs: ProtocolBugs{
5844 NoSignatureAlgorithms: true,
5845 },
5846 },
5847 shouldFail: true,
5848 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5849 })
5850
David Benjaminb62d2872016-07-18 14:55:02 +02005851 // Test that hash preferences are enforced. BoringSSL does not implement
5852 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005853 testCases = append(testCases, testCase{
5854 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005855 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005856 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005857 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005858 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005859 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005860 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005861 },
5862 Bugs: ProtocolBugs{
5863 IgnorePeerSignatureAlgorithmPreferences: true,
5864 },
5865 },
5866 flags: []string{"-require-any-client-certificate"},
5867 shouldFail: true,
5868 expectedError: ":WRONG_SIGNATURE_TYPE:",
5869 })
5870
5871 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005872 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005874 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005875 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005876 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005877 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005878 },
5879 Bugs: ProtocolBugs{
5880 IgnorePeerSignatureAlgorithmPreferences: true,
5881 },
5882 },
5883 shouldFail: true,
5884 expectedError: ":WRONG_SIGNATURE_TYPE:",
5885 })
David Benjaminb62d2872016-07-18 14:55:02 +02005886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "ClientAuth-Enforced-TLS13",
5889 config: Config{
5890 MaxVersion: VersionTLS13,
5891 Certificates: []Certificate{rsaCertificate},
5892 SignSignatureAlgorithms: []signatureAlgorithm{
5893 signatureRSAPKCS1WithMD5,
5894 },
5895 Bugs: ProtocolBugs{
5896 IgnorePeerSignatureAlgorithmPreferences: true,
5897 IgnoreSignatureVersionChecks: true,
5898 },
5899 },
5900 flags: []string{"-require-any-client-certificate"},
5901 shouldFail: true,
5902 expectedError: ":WRONG_SIGNATURE_TYPE:",
5903 })
5904
5905 testCases = append(testCases, testCase{
5906 name: "ServerAuth-Enforced-TLS13",
5907 config: Config{
5908 MaxVersion: VersionTLS13,
5909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5910 SignSignatureAlgorithms: []signatureAlgorithm{
5911 signatureRSAPKCS1WithMD5,
5912 },
5913 Bugs: ProtocolBugs{
5914 IgnorePeerSignatureAlgorithmPreferences: true,
5915 IgnoreSignatureVersionChecks: true,
5916 },
5917 },
5918 shouldFail: true,
5919 expectedError: ":WRONG_SIGNATURE_TYPE:",
5920 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005921
5922 // Test that the agreed upon digest respects the client preferences and
5923 // the server digests.
5924 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005925 name: "NoCommonAlgorithms-Digests",
5926 config: Config{
5927 MaxVersion: VersionTLS12,
5928 ClientAuth: RequireAnyClientCert,
5929 VerifySignatureAlgorithms: []signatureAlgorithm{
5930 signatureRSAPKCS1WithSHA512,
5931 signatureRSAPKCS1WithSHA1,
5932 },
5933 },
5934 flags: []string{
5935 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5936 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5937 "-digest-prefs", "SHA256",
5938 },
5939 shouldFail: true,
5940 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5941 })
5942 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005943 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005945 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005946 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005947 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005948 signatureRSAPKCS1WithSHA512,
5949 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005950 },
5951 },
5952 flags: []string{
5953 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5954 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005955 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005956 },
David Benjaminca3d5452016-07-14 12:51:01 -04005957 shouldFail: true,
5958 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5959 })
5960 testCases = append(testCases, testCase{
5961 name: "NoCommonAlgorithms-TLS13",
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 ClientAuth: RequireAnyClientCert,
5965 VerifySignatureAlgorithms: []signatureAlgorithm{
5966 signatureRSAPSSWithSHA512,
5967 signatureRSAPSSWithSHA384,
5968 },
5969 },
5970 flags: []string{
5971 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5972 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5973 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5974 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005975 shouldFail: true,
5976 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005977 })
5978 testCases = append(testCases, testCase{
5979 name: "Agree-Digest-SHA256",
5980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005981 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005982 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005983 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005984 signatureRSAPKCS1WithSHA1,
5985 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005986 },
5987 },
5988 flags: []string{
5989 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5990 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005991 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005992 },
Nick Harper60edffd2016-06-21 15:19:24 -07005993 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005994 })
5995 testCases = append(testCases, testCase{
5996 name: "Agree-Digest-SHA1",
5997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005998 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005999 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006000 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006001 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006002 },
6003 },
6004 flags: []string{
6005 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6006 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006007 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006008 },
Nick Harper60edffd2016-06-21 15:19:24 -07006009 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006010 })
6011 testCases = append(testCases, testCase{
6012 name: "Agree-Digest-Default",
6013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006014 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006015 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006016 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006017 signatureRSAPKCS1WithSHA256,
6018 signatureECDSAWithP256AndSHA256,
6019 signatureRSAPKCS1WithSHA1,
6020 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006021 },
6022 },
6023 flags: []string{
6024 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6025 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6026 },
Nick Harper60edffd2016-06-21 15:19:24 -07006027 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006028 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006029
David Benjaminca3d5452016-07-14 12:51:01 -04006030 // Test that the signing preference list may include extra algorithms
6031 // without negotiation problems.
6032 testCases = append(testCases, testCase{
6033 testType: serverTest,
6034 name: "FilterExtraAlgorithms",
6035 config: Config{
6036 MaxVersion: VersionTLS12,
6037 VerifySignatureAlgorithms: []signatureAlgorithm{
6038 signatureRSAPKCS1WithSHA256,
6039 },
6040 },
6041 flags: []string{
6042 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6043 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6044 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6045 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6046 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6047 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6048 },
6049 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6050 })
6051
David Benjamin4c3ddf72016-06-29 18:13:53 -04006052 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6053 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006054 testCases = append(testCases, testCase{
6055 name: "CheckLeafCurve",
6056 config: Config{
6057 MaxVersion: VersionTLS12,
6058 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006059 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006060 },
6061 flags: []string{"-p384-only"},
6062 shouldFail: true,
6063 expectedError: ":BAD_ECC_CERT:",
6064 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006065
6066 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6067 testCases = append(testCases, testCase{
6068 name: "CheckLeafCurve-TLS13",
6069 config: Config{
6070 MaxVersion: VersionTLS13,
6071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6072 Certificates: []Certificate{ecdsaP256Certificate},
6073 },
6074 flags: []string{"-p384-only"},
6075 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006076
6077 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6078 testCases = append(testCases, testCase{
6079 name: "ECDSACurveMismatch-Verify-TLS12",
6080 config: Config{
6081 MaxVersion: VersionTLS12,
6082 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6083 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006084 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006085 signatureECDSAWithP384AndSHA384,
6086 },
6087 },
6088 })
6089
6090 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6091 testCases = append(testCases, testCase{
6092 name: "ECDSACurveMismatch-Verify-TLS13",
6093 config: Config{
6094 MaxVersion: VersionTLS13,
6095 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6096 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006097 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006098 signatureECDSAWithP384AndSHA384,
6099 },
6100 Bugs: ProtocolBugs{
6101 SkipECDSACurveCheck: true,
6102 },
6103 },
6104 shouldFail: true,
6105 expectedError: ":WRONG_SIGNATURE_TYPE:",
6106 })
6107
6108 // Signature algorithm selection in TLS 1.3 should take the curve into
6109 // account.
6110 testCases = append(testCases, testCase{
6111 testType: serverTest,
6112 name: "ECDSACurveMismatch-Sign-TLS13",
6113 config: Config{
6114 MaxVersion: VersionTLS13,
6115 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006116 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006117 signatureECDSAWithP384AndSHA384,
6118 signatureECDSAWithP256AndSHA256,
6119 },
6120 },
6121 flags: []string{
6122 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6123 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6124 },
6125 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6126 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006127
6128 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6129 // server does not attempt to sign in that case.
6130 testCases = append(testCases, testCase{
6131 testType: serverTest,
6132 name: "RSA-PSS-Large",
6133 config: Config{
6134 MaxVersion: VersionTLS13,
6135 VerifySignatureAlgorithms: []signatureAlgorithm{
6136 signatureRSAPSSWithSHA512,
6137 },
6138 },
6139 flags: []string{
6140 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6141 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6142 },
6143 shouldFail: true,
6144 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6145 })
David Benjamin000800a2014-11-14 01:43:59 -05006146}
6147
David Benjamin83f90402015-01-27 01:09:43 -05006148// timeouts is the retransmit schedule for BoringSSL. It doubles and
6149// caps at 60 seconds. On the 13th timeout, it gives up.
6150var timeouts = []time.Duration{
6151 1 * time.Second,
6152 2 * time.Second,
6153 4 * time.Second,
6154 8 * time.Second,
6155 16 * time.Second,
6156 32 * time.Second,
6157 60 * time.Second,
6158 60 * time.Second,
6159 60 * time.Second,
6160 60 * time.Second,
6161 60 * time.Second,
6162 60 * time.Second,
6163 60 * time.Second,
6164}
6165
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006166// shortTimeouts is an alternate set of timeouts which would occur if the
6167// initial timeout duration was set to 250ms.
6168var shortTimeouts = []time.Duration{
6169 250 * time.Millisecond,
6170 500 * time.Millisecond,
6171 1 * time.Second,
6172 2 * time.Second,
6173 4 * time.Second,
6174 8 * time.Second,
6175 16 * time.Second,
6176 32 * time.Second,
6177 60 * time.Second,
6178 60 * time.Second,
6179 60 * time.Second,
6180 60 * time.Second,
6181 60 * time.Second,
6182}
6183
David Benjamin83f90402015-01-27 01:09:43 -05006184func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006185 // These tests work by coordinating some behavior on both the shim and
6186 // the runner.
6187 //
6188 // TimeoutSchedule configures the runner to send a series of timeout
6189 // opcodes to the shim (see packetAdaptor) immediately before reading
6190 // each peer handshake flight N. The timeout opcode both simulates a
6191 // timeout in the shim and acts as a synchronization point to help the
6192 // runner bracket each handshake flight.
6193 //
6194 // We assume the shim does not read from the channel eagerly. It must
6195 // first wait until it has sent flight N and is ready to receive
6196 // handshake flight N+1. At this point, it will process the timeout
6197 // opcode. It must then immediately respond with a timeout ACK and act
6198 // as if the shim was idle for the specified amount of time.
6199 //
6200 // The runner then drops all packets received before the ACK and
6201 // continues waiting for flight N. This ordering results in one attempt
6202 // at sending flight N to be dropped. For the test to complete, the
6203 // shim must send flight N again, testing that the shim implements DTLS
6204 // retransmit on a timeout.
6205
Steven Valdez143e8b32016-07-11 13:19:03 -04006206 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006207 // likely be more epochs to cross and the final message's retransmit may
6208 // be more complex.
6209
David Benjamin585d7a42016-06-02 14:58:00 -04006210 for _, async := range []bool{true, false} {
6211 var tests []testCase
6212
6213 // Test that this is indeed the timeout schedule. Stress all
6214 // four patterns of handshake.
6215 for i := 1; i < len(timeouts); i++ {
6216 number := strconv.Itoa(i)
6217 tests = append(tests, testCase{
6218 protocol: dtls,
6219 name: "DTLS-Retransmit-Client-" + number,
6220 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006221 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006222 Bugs: ProtocolBugs{
6223 TimeoutSchedule: timeouts[:i],
6224 },
6225 },
6226 resumeSession: true,
6227 })
6228 tests = append(tests, testCase{
6229 protocol: dtls,
6230 testType: serverTest,
6231 name: "DTLS-Retransmit-Server-" + number,
6232 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006233 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006234 Bugs: ProtocolBugs{
6235 TimeoutSchedule: timeouts[:i],
6236 },
6237 },
6238 resumeSession: true,
6239 })
6240 }
6241
6242 // Test that exceeding the timeout schedule hits a read
6243 // timeout.
6244 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006245 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006246 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006247 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006248 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006249 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006250 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006251 },
6252 },
6253 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006254 shouldFail: true,
6255 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006256 })
David Benjamin585d7a42016-06-02 14:58:00 -04006257
6258 if async {
6259 // Test that timeout handling has a fudge factor, due to API
6260 // problems.
6261 tests = append(tests, testCase{
6262 protocol: dtls,
6263 name: "DTLS-Retransmit-Fudge",
6264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006265 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006266 Bugs: ProtocolBugs{
6267 TimeoutSchedule: []time.Duration{
6268 timeouts[0] - 10*time.Millisecond,
6269 },
6270 },
6271 },
6272 resumeSession: true,
6273 })
6274 }
6275
6276 // Test that the final Finished retransmitting isn't
6277 // duplicated if the peer badly fragments everything.
6278 tests = append(tests, testCase{
6279 testType: serverTest,
6280 protocol: dtls,
6281 name: "DTLS-Retransmit-Fragmented",
6282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006283 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006284 Bugs: ProtocolBugs{
6285 TimeoutSchedule: []time.Duration{timeouts[0]},
6286 MaxHandshakeRecordLength: 2,
6287 },
6288 },
6289 })
6290
6291 // Test the timeout schedule when a shorter initial timeout duration is set.
6292 tests = append(tests, testCase{
6293 protocol: dtls,
6294 name: "DTLS-Retransmit-Short-Client",
6295 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006296 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006297 Bugs: ProtocolBugs{
6298 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6299 },
6300 },
6301 resumeSession: true,
6302 flags: []string{"-initial-timeout-duration-ms", "250"},
6303 })
6304 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006305 protocol: dtls,
6306 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006307 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006309 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006310 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006311 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006312 },
6313 },
6314 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006315 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006316 })
David Benjamin585d7a42016-06-02 14:58:00 -04006317
6318 for _, test := range tests {
6319 if async {
6320 test.name += "-Async"
6321 test.flags = append(test.flags, "-async")
6322 }
6323
6324 testCases = append(testCases, test)
6325 }
David Benjamin83f90402015-01-27 01:09:43 -05006326 }
David Benjamin83f90402015-01-27 01:09:43 -05006327}
6328
David Benjaminc565ebb2015-04-03 04:06:36 -04006329func addExportKeyingMaterialTests() {
6330 for _, vers := range tlsVersions {
6331 if vers.version == VersionSSL30 {
6332 continue
6333 }
6334 testCases = append(testCases, testCase{
6335 name: "ExportKeyingMaterial-" + vers.name,
6336 config: Config{
6337 MaxVersion: vers.version,
6338 },
6339 exportKeyingMaterial: 1024,
6340 exportLabel: "label",
6341 exportContext: "context",
6342 useExportContext: true,
6343 })
6344 testCases = append(testCases, testCase{
6345 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6346 config: Config{
6347 MaxVersion: vers.version,
6348 },
6349 exportKeyingMaterial: 1024,
6350 })
6351 testCases = append(testCases, testCase{
6352 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6353 config: Config{
6354 MaxVersion: vers.version,
6355 },
6356 exportKeyingMaterial: 1024,
6357 useExportContext: true,
6358 })
6359 testCases = append(testCases, testCase{
6360 name: "ExportKeyingMaterial-Small-" + vers.name,
6361 config: Config{
6362 MaxVersion: vers.version,
6363 },
6364 exportKeyingMaterial: 1,
6365 exportLabel: "label",
6366 exportContext: "context",
6367 useExportContext: true,
6368 })
6369 }
6370 testCases = append(testCases, testCase{
6371 name: "ExportKeyingMaterial-SSL3",
6372 config: Config{
6373 MaxVersion: VersionSSL30,
6374 },
6375 exportKeyingMaterial: 1024,
6376 exportLabel: "label",
6377 exportContext: "context",
6378 useExportContext: true,
6379 shouldFail: true,
6380 expectedError: "failed to export keying material",
6381 })
6382}
6383
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006384func addTLSUniqueTests() {
6385 for _, isClient := range []bool{false, true} {
6386 for _, isResumption := range []bool{false, true} {
6387 for _, hasEMS := range []bool{false, true} {
6388 var suffix string
6389 if isResumption {
6390 suffix = "Resume-"
6391 } else {
6392 suffix = "Full-"
6393 }
6394
6395 if hasEMS {
6396 suffix += "EMS-"
6397 } else {
6398 suffix += "NoEMS-"
6399 }
6400
6401 if isClient {
6402 suffix += "Client"
6403 } else {
6404 suffix += "Server"
6405 }
6406
6407 test := testCase{
6408 name: "TLSUnique-" + suffix,
6409 testTLSUnique: true,
6410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006411 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006412 Bugs: ProtocolBugs{
6413 NoExtendedMasterSecret: !hasEMS,
6414 },
6415 },
6416 }
6417
6418 if isResumption {
6419 test.resumeSession = true
6420 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006421 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006422 Bugs: ProtocolBugs{
6423 NoExtendedMasterSecret: !hasEMS,
6424 },
6425 }
6426 }
6427
6428 if isResumption && !hasEMS {
6429 test.shouldFail = true
6430 test.expectedError = "failed to get tls-unique"
6431 }
6432
6433 testCases = append(testCases, test)
6434 }
6435 }
6436 }
6437}
6438
Adam Langley09505632015-07-30 18:10:13 -07006439func addCustomExtensionTests() {
6440 expectedContents := "custom extension"
6441 emptyString := ""
6442
6443 for _, isClient := range []bool{false, true} {
6444 suffix := "Server"
6445 flag := "-enable-server-custom-extension"
6446 testType := serverTest
6447 if isClient {
6448 suffix = "Client"
6449 flag = "-enable-client-custom-extension"
6450 testType = clientTest
6451 }
6452
6453 testCases = append(testCases, testCase{
6454 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006455 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006457 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006458 Bugs: ProtocolBugs{
6459 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006460 ExpectedCustomExtension: &expectedContents,
6461 },
6462 },
6463 flags: []string{flag},
6464 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006465 testCases = append(testCases, testCase{
6466 testType: testType,
6467 name: "CustomExtensions-" + suffix + "-TLS13",
6468 config: Config{
6469 MaxVersion: VersionTLS13,
6470 Bugs: ProtocolBugs{
6471 CustomExtension: expectedContents,
6472 ExpectedCustomExtension: &expectedContents,
6473 },
6474 },
6475 flags: []string{flag},
6476 })
Adam Langley09505632015-07-30 18:10:13 -07006477
6478 // If the parse callback fails, the handshake should also fail.
6479 testCases = append(testCases, testCase{
6480 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006481 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006483 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006484 Bugs: ProtocolBugs{
6485 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006486 ExpectedCustomExtension: &expectedContents,
6487 },
6488 },
David Benjamin399e7c92015-07-30 23:01:27 -04006489 flags: []string{flag},
6490 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006491 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6492 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006493 testCases = append(testCases, testCase{
6494 testType: testType,
6495 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6496 config: Config{
6497 MaxVersion: VersionTLS13,
6498 Bugs: ProtocolBugs{
6499 CustomExtension: expectedContents + "foo",
6500 ExpectedCustomExtension: &expectedContents,
6501 },
6502 },
6503 flags: []string{flag},
6504 shouldFail: true,
6505 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6506 })
Adam Langley09505632015-07-30 18:10:13 -07006507
6508 // If the add callback fails, the handshake should also fail.
6509 testCases = append(testCases, testCase{
6510 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006511 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006513 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006514 Bugs: ProtocolBugs{
6515 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006516 ExpectedCustomExtension: &expectedContents,
6517 },
6518 },
David Benjamin399e7c92015-07-30 23:01:27 -04006519 flags: []string{flag, "-custom-extension-fail-add"},
6520 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006521 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6522 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006523 testCases = append(testCases, testCase{
6524 testType: testType,
6525 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6526 config: Config{
6527 MaxVersion: VersionTLS13,
6528 Bugs: ProtocolBugs{
6529 CustomExtension: expectedContents,
6530 ExpectedCustomExtension: &expectedContents,
6531 },
6532 },
6533 flags: []string{flag, "-custom-extension-fail-add"},
6534 shouldFail: true,
6535 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6536 })
Adam Langley09505632015-07-30 18:10:13 -07006537
6538 // If the add callback returns zero, no extension should be
6539 // added.
6540 skipCustomExtension := expectedContents
6541 if isClient {
6542 // For the case where the client skips sending the
6543 // custom extension, the server must not “echo” it.
6544 skipCustomExtension = ""
6545 }
6546 testCases = append(testCases, testCase{
6547 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006548 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006550 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006551 Bugs: ProtocolBugs{
6552 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006553 ExpectedCustomExtension: &emptyString,
6554 },
6555 },
6556 flags: []string{flag, "-custom-extension-skip"},
6557 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006558 testCases = append(testCases, testCase{
6559 testType: testType,
6560 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6561 config: Config{
6562 MaxVersion: VersionTLS13,
6563 Bugs: ProtocolBugs{
6564 CustomExtension: skipCustomExtension,
6565 ExpectedCustomExtension: &emptyString,
6566 },
6567 },
6568 flags: []string{flag, "-custom-extension-skip"},
6569 })
Adam Langley09505632015-07-30 18:10:13 -07006570 }
6571
6572 // The custom extension add callback should not be called if the client
6573 // doesn't send the extension.
6574 testCases = append(testCases, testCase{
6575 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006576 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006578 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006579 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006580 ExpectedCustomExtension: &emptyString,
6581 },
6582 },
6583 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6584 })
Adam Langley2deb9842015-08-07 11:15:37 -07006585
Steven Valdez143e8b32016-07-11 13:19:03 -04006586 testCases = append(testCases, testCase{
6587 testType: serverTest,
6588 name: "CustomExtensions-NotCalled-Server-TLS13",
6589 config: Config{
6590 MaxVersion: VersionTLS13,
6591 Bugs: ProtocolBugs{
6592 ExpectedCustomExtension: &emptyString,
6593 },
6594 },
6595 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6596 })
6597
Adam Langley2deb9842015-08-07 11:15:37 -07006598 // Test an unknown extension from the server.
6599 testCases = append(testCases, testCase{
6600 testType: clientTest,
6601 name: "UnknownExtension-Client",
6602 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006603 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006604 Bugs: ProtocolBugs{
6605 CustomExtension: expectedContents,
6606 },
6607 },
David Benjamin0c40a962016-08-01 12:05:50 -04006608 shouldFail: true,
6609 expectedError: ":UNEXPECTED_EXTENSION:",
6610 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006611 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006612 testCases = append(testCases, testCase{
6613 testType: clientTest,
6614 name: "UnknownExtension-Client-TLS13",
6615 config: Config{
6616 MaxVersion: VersionTLS13,
6617 Bugs: ProtocolBugs{
6618 CustomExtension: expectedContents,
6619 },
6620 },
David Benjamin0c40a962016-08-01 12:05:50 -04006621 shouldFail: true,
6622 expectedError: ":UNEXPECTED_EXTENSION:",
6623 expectedLocalError: "remote error: unsupported extension",
6624 })
6625
6626 // Test a known but unoffered extension from the server.
6627 testCases = append(testCases, testCase{
6628 testType: clientTest,
6629 name: "UnofferedExtension-Client",
6630 config: Config{
6631 MaxVersion: VersionTLS12,
6632 Bugs: ProtocolBugs{
6633 SendALPN: "alpn",
6634 },
6635 },
6636 shouldFail: true,
6637 expectedError: ":UNEXPECTED_EXTENSION:",
6638 expectedLocalError: "remote error: unsupported extension",
6639 })
6640 testCases = append(testCases, testCase{
6641 testType: clientTest,
6642 name: "UnofferedExtension-Client-TLS13",
6643 config: Config{
6644 MaxVersion: VersionTLS13,
6645 Bugs: ProtocolBugs{
6646 SendALPN: "alpn",
6647 },
6648 },
6649 shouldFail: true,
6650 expectedError: ":UNEXPECTED_EXTENSION:",
6651 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006652 })
Adam Langley09505632015-07-30 18:10:13 -07006653}
6654
David Benjaminb36a3952015-12-01 18:53:13 -05006655func addRSAClientKeyExchangeTests() {
6656 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6657 testCases = append(testCases, testCase{
6658 testType: serverTest,
6659 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6660 config: Config{
6661 // Ensure the ClientHello version and final
6662 // version are different, to detect if the
6663 // server uses the wrong one.
6664 MaxVersion: VersionTLS11,
6665 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6666 Bugs: ProtocolBugs{
6667 BadRSAClientKeyExchange: bad,
6668 },
6669 },
6670 shouldFail: true,
6671 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6672 })
6673 }
6674}
6675
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006676var testCurves = []struct {
6677 name string
6678 id CurveID
6679}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006680 {"P-256", CurveP256},
6681 {"P-384", CurveP384},
6682 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006683 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006684}
6685
Steven Valdez5440fe02016-07-18 12:40:30 -04006686const bogusCurve = 0x1234
6687
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006688func addCurveTests() {
6689 for _, curve := range testCurves {
6690 testCases = append(testCases, testCase{
6691 name: "CurveTest-Client-" + curve.name,
6692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006693 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6695 CurvePreferences: []CurveID{curve.id},
6696 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006697 flags: []string{"-enable-all-curves"},
6698 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006699 })
6700 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006701 name: "CurveTest-Client-" + curve.name + "-TLS13",
6702 config: Config{
6703 MaxVersion: VersionTLS13,
6704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6705 CurvePreferences: []CurveID{curve.id},
6706 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006707 flags: []string{"-enable-all-curves"},
6708 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006709 })
6710 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006711 testType: serverTest,
6712 name: "CurveTest-Server-" + curve.name,
6713 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006714 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006715 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6716 CurvePreferences: []CurveID{curve.id},
6717 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006718 flags: []string{"-enable-all-curves"},
6719 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006720 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006721 testCases = append(testCases, testCase{
6722 testType: serverTest,
6723 name: "CurveTest-Server-" + curve.name + "-TLS13",
6724 config: Config{
6725 MaxVersion: VersionTLS13,
6726 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6727 CurvePreferences: []CurveID{curve.id},
6728 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006729 flags: []string{"-enable-all-curves"},
6730 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006731 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006732 }
David Benjamin241ae832016-01-15 03:04:54 -05006733
6734 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006735 testCases = append(testCases, testCase{
6736 testType: serverTest,
6737 name: "UnknownCurve",
6738 config: Config{
6739 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6740 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6741 },
6742 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006743
6744 // The server must not consider ECDHE ciphers when there are no
6745 // supported curves.
6746 testCases = append(testCases, testCase{
6747 testType: serverTest,
6748 name: "NoSupportedCurves",
6749 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006750 MaxVersion: VersionTLS12,
6751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6752 Bugs: ProtocolBugs{
6753 NoSupportedCurves: true,
6754 },
6755 },
6756 shouldFail: true,
6757 expectedError: ":NO_SHARED_CIPHER:",
6758 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: "NoSupportedCurves-TLS13",
6762 config: Config{
6763 MaxVersion: VersionTLS13,
6764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6765 Bugs: ProtocolBugs{
6766 NoSupportedCurves: true,
6767 },
6768 },
6769 shouldFail: true,
6770 expectedError: ":NO_SHARED_CIPHER:",
6771 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006772
6773 // The server must fall back to another cipher when there are no
6774 // supported curves.
6775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "NoCommonCurves",
6778 config: Config{
6779 MaxVersion: VersionTLS12,
6780 CipherSuites: []uint16{
6781 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6782 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6783 },
6784 CurvePreferences: []CurveID{CurveP224},
6785 },
6786 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6787 })
6788
6789 // The client must reject bogus curves and disabled curves.
6790 testCases = append(testCases, testCase{
6791 name: "BadECDHECurve",
6792 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006793 MaxVersion: VersionTLS12,
6794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6795 Bugs: ProtocolBugs{
6796 SendCurve: bogusCurve,
6797 },
6798 },
6799 shouldFail: true,
6800 expectedError: ":WRONG_CURVE:",
6801 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006802 testCases = append(testCases, testCase{
6803 name: "BadECDHECurve-TLS13",
6804 config: Config{
6805 MaxVersion: VersionTLS13,
6806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6807 Bugs: ProtocolBugs{
6808 SendCurve: bogusCurve,
6809 },
6810 },
6811 shouldFail: true,
6812 expectedError: ":WRONG_CURVE:",
6813 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006814
6815 testCases = append(testCases, testCase{
6816 name: "UnsupportedCurve",
6817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006818 MaxVersion: VersionTLS12,
6819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6820 CurvePreferences: []CurveID{CurveP256},
6821 Bugs: ProtocolBugs{
6822 IgnorePeerCurvePreferences: true,
6823 },
6824 },
6825 flags: []string{"-p384-only"},
6826 shouldFail: true,
6827 expectedError: ":WRONG_CURVE:",
6828 })
6829
David Benjamin4f921572016-07-17 14:20:10 +02006830 testCases = append(testCases, testCase{
6831 // TODO(davidben): Add a TLS 1.3 version where
6832 // HelloRetryRequest requests an unsupported curve.
6833 name: "UnsupportedCurve-ServerHello-TLS13",
6834 config: Config{
6835 MaxVersion: VersionTLS12,
6836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6837 CurvePreferences: []CurveID{CurveP384},
6838 Bugs: ProtocolBugs{
6839 SendCurve: CurveP256,
6840 },
6841 },
6842 flags: []string{"-p384-only"},
6843 shouldFail: true,
6844 expectedError: ":WRONG_CURVE:",
6845 })
6846
David Benjamin4c3ddf72016-06-29 18:13:53 -04006847 // Test invalid curve points.
6848 testCases = append(testCases, testCase{
6849 name: "InvalidECDHPoint-Client",
6850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006851 MaxVersion: VersionTLS12,
6852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6853 CurvePreferences: []CurveID{CurveP256},
6854 Bugs: ProtocolBugs{
6855 InvalidECDHPoint: true,
6856 },
6857 },
6858 shouldFail: true,
6859 expectedError: ":INVALID_ENCODING:",
6860 })
6861 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006862 name: "InvalidECDHPoint-Client-TLS13",
6863 config: Config{
6864 MaxVersion: VersionTLS13,
6865 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6866 CurvePreferences: []CurveID{CurveP256},
6867 Bugs: ProtocolBugs{
6868 InvalidECDHPoint: true,
6869 },
6870 },
6871 shouldFail: true,
6872 expectedError: ":INVALID_ENCODING:",
6873 })
6874 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006875 testType: serverTest,
6876 name: "InvalidECDHPoint-Server",
6877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006878 MaxVersion: VersionTLS12,
6879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6880 CurvePreferences: []CurveID{CurveP256},
6881 Bugs: ProtocolBugs{
6882 InvalidECDHPoint: true,
6883 },
6884 },
6885 shouldFail: true,
6886 expectedError: ":INVALID_ENCODING:",
6887 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006888 testCases = append(testCases, testCase{
6889 testType: serverTest,
6890 name: "InvalidECDHPoint-Server-TLS13",
6891 config: Config{
6892 MaxVersion: VersionTLS13,
6893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6894 CurvePreferences: []CurveID{CurveP256},
6895 Bugs: ProtocolBugs{
6896 InvalidECDHPoint: true,
6897 },
6898 },
6899 shouldFail: true,
6900 expectedError: ":INVALID_ENCODING:",
6901 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006902}
6903
Matt Braithwaite54217e42016-06-13 13:03:47 -07006904func addCECPQ1Tests() {
6905 testCases = append(testCases, testCase{
6906 testType: clientTest,
6907 name: "CECPQ1-Client-BadX25519Part",
6908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006909 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006910 MinVersion: VersionTLS12,
6911 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6912 Bugs: ProtocolBugs{
6913 CECPQ1BadX25519Part: true,
6914 },
6915 },
6916 flags: []string{"-cipher", "kCECPQ1"},
6917 shouldFail: true,
6918 expectedLocalError: "local error: bad record MAC",
6919 })
6920 testCases = append(testCases, testCase{
6921 testType: clientTest,
6922 name: "CECPQ1-Client-BadNewhopePart",
6923 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006924 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006925 MinVersion: VersionTLS12,
6926 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6927 Bugs: ProtocolBugs{
6928 CECPQ1BadNewhopePart: true,
6929 },
6930 },
6931 flags: []string{"-cipher", "kCECPQ1"},
6932 shouldFail: true,
6933 expectedLocalError: "local error: bad record MAC",
6934 })
6935 testCases = append(testCases, testCase{
6936 testType: serverTest,
6937 name: "CECPQ1-Server-BadX25519Part",
6938 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006939 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006940 MinVersion: VersionTLS12,
6941 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6942 Bugs: ProtocolBugs{
6943 CECPQ1BadX25519Part: true,
6944 },
6945 },
6946 flags: []string{"-cipher", "kCECPQ1"},
6947 shouldFail: true,
6948 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6949 })
6950 testCases = append(testCases, testCase{
6951 testType: serverTest,
6952 name: "CECPQ1-Server-BadNewhopePart",
6953 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006954 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006955 MinVersion: VersionTLS12,
6956 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6957 Bugs: ProtocolBugs{
6958 CECPQ1BadNewhopePart: true,
6959 },
6960 },
6961 flags: []string{"-cipher", "kCECPQ1"},
6962 shouldFail: true,
6963 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6964 })
6965}
6966
David Benjamin4cc36ad2015-12-19 14:23:26 -05006967func addKeyExchangeInfoTests() {
6968 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006969 name: "KeyExchangeInfo-DHE-Client",
6970 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006971 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006972 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6973 Bugs: ProtocolBugs{
6974 // This is a 1234-bit prime number, generated
6975 // with:
6976 // openssl gendh 1234 | openssl asn1parse -i
6977 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6978 },
6979 },
David Benjamin9e68f192016-06-30 14:55:33 -04006980 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006981 })
6982 testCases = append(testCases, testCase{
6983 testType: serverTest,
6984 name: "KeyExchangeInfo-DHE-Server",
6985 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006986 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006987 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6988 },
6989 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006990 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006991 })
6992
6993 testCases = append(testCases, testCase{
6994 name: "KeyExchangeInfo-ECDHE-Client",
6995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006996 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006997 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6998 CurvePreferences: []CurveID{CurveX25519},
6999 },
David Benjamin9e68f192016-06-30 14:55:33 -04007000 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007001 })
7002 testCases = append(testCases, testCase{
7003 testType: serverTest,
7004 name: "KeyExchangeInfo-ECDHE-Server",
7005 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007006 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007007 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7008 CurvePreferences: []CurveID{CurveX25519},
7009 },
David Benjamin9e68f192016-06-30 14:55:33 -04007010 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007011 })
7012}
7013
David Benjaminc9ae27c2016-06-24 22:56:37 -04007014func addTLS13RecordTests() {
7015 testCases = append(testCases, testCase{
7016 name: "TLS13-RecordPadding",
7017 config: Config{
7018 MaxVersion: VersionTLS13,
7019 MinVersion: VersionTLS13,
7020 Bugs: ProtocolBugs{
7021 RecordPadding: 10,
7022 },
7023 },
7024 })
7025
7026 testCases = append(testCases, testCase{
7027 name: "TLS13-EmptyRecords",
7028 config: Config{
7029 MaxVersion: VersionTLS13,
7030 MinVersion: VersionTLS13,
7031 Bugs: ProtocolBugs{
7032 OmitRecordContents: true,
7033 },
7034 },
7035 shouldFail: true,
7036 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7037 })
7038
7039 testCases = append(testCases, testCase{
7040 name: "TLS13-OnlyPadding",
7041 config: Config{
7042 MaxVersion: VersionTLS13,
7043 MinVersion: VersionTLS13,
7044 Bugs: ProtocolBugs{
7045 OmitRecordContents: true,
7046 RecordPadding: 10,
7047 },
7048 },
7049 shouldFail: true,
7050 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7051 })
7052
7053 testCases = append(testCases, testCase{
7054 name: "TLS13-WrongOuterRecord",
7055 config: Config{
7056 MaxVersion: VersionTLS13,
7057 MinVersion: VersionTLS13,
7058 Bugs: ProtocolBugs{
7059 OuterRecordType: recordTypeHandshake,
7060 },
7061 },
7062 shouldFail: true,
7063 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7064 })
7065}
7066
David Benjamin82261be2016-07-07 14:32:50 -07007067func addChangeCipherSpecTests() {
7068 // Test missing ChangeCipherSpecs.
7069 testCases = append(testCases, testCase{
7070 name: "SkipChangeCipherSpec-Client",
7071 config: Config{
7072 MaxVersion: VersionTLS12,
7073 Bugs: ProtocolBugs{
7074 SkipChangeCipherSpec: true,
7075 },
7076 },
7077 shouldFail: true,
7078 expectedError: ":UNEXPECTED_RECORD:",
7079 })
7080 testCases = append(testCases, testCase{
7081 testType: serverTest,
7082 name: "SkipChangeCipherSpec-Server",
7083 config: Config{
7084 MaxVersion: VersionTLS12,
7085 Bugs: ProtocolBugs{
7086 SkipChangeCipherSpec: true,
7087 },
7088 },
7089 shouldFail: true,
7090 expectedError: ":UNEXPECTED_RECORD:",
7091 })
7092 testCases = append(testCases, testCase{
7093 testType: serverTest,
7094 name: "SkipChangeCipherSpec-Server-NPN",
7095 config: Config{
7096 MaxVersion: VersionTLS12,
7097 NextProtos: []string{"bar"},
7098 Bugs: ProtocolBugs{
7099 SkipChangeCipherSpec: true,
7100 },
7101 },
7102 flags: []string{
7103 "-advertise-npn", "\x03foo\x03bar\x03baz",
7104 },
7105 shouldFail: true,
7106 expectedError: ":UNEXPECTED_RECORD:",
7107 })
7108
7109 // Test synchronization between the handshake and ChangeCipherSpec.
7110 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7111 // rejected. Test both with and without handshake packing to handle both
7112 // when the partial post-CCS message is in its own record and when it is
7113 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007114 for _, packed := range []bool{false, true} {
7115 var suffix string
7116 if packed {
7117 suffix = "-Packed"
7118 }
7119
7120 testCases = append(testCases, testCase{
7121 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7122 config: Config{
7123 MaxVersion: VersionTLS12,
7124 Bugs: ProtocolBugs{
7125 FragmentAcrossChangeCipherSpec: true,
7126 PackHandshakeFlight: packed,
7127 },
7128 },
7129 shouldFail: true,
7130 expectedError: ":UNEXPECTED_RECORD:",
7131 })
7132 testCases = append(testCases, testCase{
7133 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7134 config: Config{
7135 MaxVersion: VersionTLS12,
7136 },
7137 resumeSession: true,
7138 resumeConfig: &Config{
7139 MaxVersion: VersionTLS12,
7140 Bugs: ProtocolBugs{
7141 FragmentAcrossChangeCipherSpec: true,
7142 PackHandshakeFlight: packed,
7143 },
7144 },
7145 shouldFail: true,
7146 expectedError: ":UNEXPECTED_RECORD:",
7147 })
7148 testCases = append(testCases, testCase{
7149 testType: serverTest,
7150 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7151 config: Config{
7152 MaxVersion: VersionTLS12,
7153 Bugs: ProtocolBugs{
7154 FragmentAcrossChangeCipherSpec: true,
7155 PackHandshakeFlight: packed,
7156 },
7157 },
7158 shouldFail: true,
7159 expectedError: ":UNEXPECTED_RECORD:",
7160 })
7161 testCases = append(testCases, testCase{
7162 testType: serverTest,
7163 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7164 config: Config{
7165 MaxVersion: VersionTLS12,
7166 },
7167 resumeSession: true,
7168 resumeConfig: &Config{
7169 MaxVersion: VersionTLS12,
7170 Bugs: ProtocolBugs{
7171 FragmentAcrossChangeCipherSpec: true,
7172 PackHandshakeFlight: packed,
7173 },
7174 },
7175 shouldFail: true,
7176 expectedError: ":UNEXPECTED_RECORD:",
7177 })
7178 testCases = append(testCases, testCase{
7179 testType: serverTest,
7180 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7181 config: Config{
7182 MaxVersion: VersionTLS12,
7183 NextProtos: []string{"bar"},
7184 Bugs: ProtocolBugs{
7185 FragmentAcrossChangeCipherSpec: true,
7186 PackHandshakeFlight: packed,
7187 },
7188 },
7189 flags: []string{
7190 "-advertise-npn", "\x03foo\x03bar\x03baz",
7191 },
7192 shouldFail: true,
7193 expectedError: ":UNEXPECTED_RECORD:",
7194 })
7195 }
7196
David Benjamin61672812016-07-14 23:10:43 -04007197 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7198 // messages in the handshake queue. Do this by testing the server
7199 // reading the client Finished, reversing the flight so Finished comes
7200 // first.
7201 testCases = append(testCases, testCase{
7202 protocol: dtls,
7203 testType: serverTest,
7204 name: "SendUnencryptedFinished-DTLS",
7205 config: Config{
7206 MaxVersion: VersionTLS12,
7207 Bugs: ProtocolBugs{
7208 SendUnencryptedFinished: true,
7209 ReverseHandshakeFragments: true,
7210 },
7211 },
7212 shouldFail: true,
7213 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7214 })
7215
Steven Valdez143e8b32016-07-11 13:19:03 -04007216 // Test synchronization between encryption changes and the handshake in
7217 // TLS 1.3, where ChangeCipherSpec is implicit.
7218 testCases = append(testCases, testCase{
7219 name: "PartialEncryptedExtensionsWithServerHello",
7220 config: Config{
7221 MaxVersion: VersionTLS13,
7222 Bugs: ProtocolBugs{
7223 PartialEncryptedExtensionsWithServerHello: true,
7224 },
7225 },
7226 shouldFail: true,
7227 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7228 })
7229 testCases = append(testCases, testCase{
7230 testType: serverTest,
7231 name: "PartialClientFinishedWithClientHello",
7232 config: Config{
7233 MaxVersion: VersionTLS13,
7234 Bugs: ProtocolBugs{
7235 PartialClientFinishedWithClientHello: true,
7236 },
7237 },
7238 shouldFail: true,
7239 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7240 })
7241
David Benjamin82261be2016-07-07 14:32:50 -07007242 // Test that early ChangeCipherSpecs are handled correctly.
7243 testCases = append(testCases, testCase{
7244 testType: serverTest,
7245 name: "EarlyChangeCipherSpec-server-1",
7246 config: Config{
7247 MaxVersion: VersionTLS12,
7248 Bugs: ProtocolBugs{
7249 EarlyChangeCipherSpec: 1,
7250 },
7251 },
7252 shouldFail: true,
7253 expectedError: ":UNEXPECTED_RECORD:",
7254 })
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 name: "EarlyChangeCipherSpec-server-2",
7258 config: Config{
7259 MaxVersion: VersionTLS12,
7260 Bugs: ProtocolBugs{
7261 EarlyChangeCipherSpec: 2,
7262 },
7263 },
7264 shouldFail: true,
7265 expectedError: ":UNEXPECTED_RECORD:",
7266 })
7267 testCases = append(testCases, testCase{
7268 protocol: dtls,
7269 name: "StrayChangeCipherSpec",
7270 config: Config{
7271 // TODO(davidben): Once DTLS 1.3 exists, test
7272 // that stray ChangeCipherSpec messages are
7273 // rejected.
7274 MaxVersion: VersionTLS12,
7275 Bugs: ProtocolBugs{
7276 StrayChangeCipherSpec: true,
7277 },
7278 },
7279 })
7280
7281 // Test that the contents of ChangeCipherSpec are checked.
7282 testCases = append(testCases, testCase{
7283 name: "BadChangeCipherSpec-1",
7284 config: Config{
7285 MaxVersion: VersionTLS12,
7286 Bugs: ProtocolBugs{
7287 BadChangeCipherSpec: []byte{2},
7288 },
7289 },
7290 shouldFail: true,
7291 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7292 })
7293 testCases = append(testCases, testCase{
7294 name: "BadChangeCipherSpec-2",
7295 config: Config{
7296 MaxVersion: VersionTLS12,
7297 Bugs: ProtocolBugs{
7298 BadChangeCipherSpec: []byte{1, 1},
7299 },
7300 },
7301 shouldFail: true,
7302 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7303 })
7304 testCases = append(testCases, testCase{
7305 protocol: dtls,
7306 name: "BadChangeCipherSpec-DTLS-1",
7307 config: Config{
7308 MaxVersion: VersionTLS12,
7309 Bugs: ProtocolBugs{
7310 BadChangeCipherSpec: []byte{2},
7311 },
7312 },
7313 shouldFail: true,
7314 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7315 })
7316 testCases = append(testCases, testCase{
7317 protocol: dtls,
7318 name: "BadChangeCipherSpec-DTLS-2",
7319 config: Config{
7320 MaxVersion: VersionTLS12,
7321 Bugs: ProtocolBugs{
7322 BadChangeCipherSpec: []byte{1, 1},
7323 },
7324 },
7325 shouldFail: true,
7326 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7327 })
7328}
7329
David Benjamin0b8d5da2016-07-15 00:39:56 -04007330func addWrongMessageTypeTests() {
7331 for _, protocol := range []protocol{tls, dtls} {
7332 var suffix string
7333 if protocol == dtls {
7334 suffix = "-DTLS"
7335 }
7336
7337 testCases = append(testCases, testCase{
7338 protocol: protocol,
7339 testType: serverTest,
7340 name: "WrongMessageType-ClientHello" + suffix,
7341 config: Config{
7342 MaxVersion: VersionTLS12,
7343 Bugs: ProtocolBugs{
7344 SendWrongMessageType: typeClientHello,
7345 },
7346 },
7347 shouldFail: true,
7348 expectedError: ":UNEXPECTED_MESSAGE:",
7349 expectedLocalError: "remote error: unexpected message",
7350 })
7351
7352 if protocol == dtls {
7353 testCases = append(testCases, testCase{
7354 protocol: protocol,
7355 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7356 config: Config{
7357 MaxVersion: VersionTLS12,
7358 Bugs: ProtocolBugs{
7359 SendWrongMessageType: typeHelloVerifyRequest,
7360 },
7361 },
7362 shouldFail: true,
7363 expectedError: ":UNEXPECTED_MESSAGE:",
7364 expectedLocalError: "remote error: unexpected message",
7365 })
7366 }
7367
7368 testCases = append(testCases, testCase{
7369 protocol: protocol,
7370 name: "WrongMessageType-ServerHello" + suffix,
7371 config: Config{
7372 MaxVersion: VersionTLS12,
7373 Bugs: ProtocolBugs{
7374 SendWrongMessageType: typeServerHello,
7375 },
7376 },
7377 shouldFail: true,
7378 expectedError: ":UNEXPECTED_MESSAGE:",
7379 expectedLocalError: "remote error: unexpected message",
7380 })
7381
7382 testCases = append(testCases, testCase{
7383 protocol: protocol,
7384 name: "WrongMessageType-ServerCertificate" + suffix,
7385 config: Config{
7386 MaxVersion: VersionTLS12,
7387 Bugs: ProtocolBugs{
7388 SendWrongMessageType: typeCertificate,
7389 },
7390 },
7391 shouldFail: true,
7392 expectedError: ":UNEXPECTED_MESSAGE:",
7393 expectedLocalError: "remote error: unexpected message",
7394 })
7395
7396 testCases = append(testCases, testCase{
7397 protocol: protocol,
7398 name: "WrongMessageType-CertificateStatus" + suffix,
7399 config: Config{
7400 MaxVersion: VersionTLS12,
7401 Bugs: ProtocolBugs{
7402 SendWrongMessageType: typeCertificateStatus,
7403 },
7404 },
7405 flags: []string{"-enable-ocsp-stapling"},
7406 shouldFail: true,
7407 expectedError: ":UNEXPECTED_MESSAGE:",
7408 expectedLocalError: "remote error: unexpected message",
7409 })
7410
7411 testCases = append(testCases, testCase{
7412 protocol: protocol,
7413 name: "WrongMessageType-ServerKeyExchange" + suffix,
7414 config: Config{
7415 MaxVersion: VersionTLS12,
7416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7417 Bugs: ProtocolBugs{
7418 SendWrongMessageType: typeServerKeyExchange,
7419 },
7420 },
7421 shouldFail: true,
7422 expectedError: ":UNEXPECTED_MESSAGE:",
7423 expectedLocalError: "remote error: unexpected message",
7424 })
7425
7426 testCases = append(testCases, testCase{
7427 protocol: protocol,
7428 name: "WrongMessageType-CertificateRequest" + suffix,
7429 config: Config{
7430 MaxVersion: VersionTLS12,
7431 ClientAuth: RequireAnyClientCert,
7432 Bugs: ProtocolBugs{
7433 SendWrongMessageType: typeCertificateRequest,
7434 },
7435 },
7436 shouldFail: true,
7437 expectedError: ":UNEXPECTED_MESSAGE:",
7438 expectedLocalError: "remote error: unexpected message",
7439 })
7440
7441 testCases = append(testCases, testCase{
7442 protocol: protocol,
7443 name: "WrongMessageType-ServerHelloDone" + suffix,
7444 config: Config{
7445 MaxVersion: VersionTLS12,
7446 Bugs: ProtocolBugs{
7447 SendWrongMessageType: typeServerHelloDone,
7448 },
7449 },
7450 shouldFail: true,
7451 expectedError: ":UNEXPECTED_MESSAGE:",
7452 expectedLocalError: "remote error: unexpected message",
7453 })
7454
7455 testCases = append(testCases, testCase{
7456 testType: serverTest,
7457 protocol: protocol,
7458 name: "WrongMessageType-ClientCertificate" + suffix,
7459 config: Config{
7460 Certificates: []Certificate{rsaCertificate},
7461 MaxVersion: VersionTLS12,
7462 Bugs: ProtocolBugs{
7463 SendWrongMessageType: typeCertificate,
7464 },
7465 },
7466 flags: []string{"-require-any-client-certificate"},
7467 shouldFail: true,
7468 expectedError: ":UNEXPECTED_MESSAGE:",
7469 expectedLocalError: "remote error: unexpected message",
7470 })
7471
7472 testCases = append(testCases, testCase{
7473 testType: serverTest,
7474 protocol: protocol,
7475 name: "WrongMessageType-CertificateVerify" + suffix,
7476 config: Config{
7477 Certificates: []Certificate{rsaCertificate},
7478 MaxVersion: VersionTLS12,
7479 Bugs: ProtocolBugs{
7480 SendWrongMessageType: typeCertificateVerify,
7481 },
7482 },
7483 flags: []string{"-require-any-client-certificate"},
7484 shouldFail: true,
7485 expectedError: ":UNEXPECTED_MESSAGE:",
7486 expectedLocalError: "remote error: unexpected message",
7487 })
7488
7489 testCases = append(testCases, testCase{
7490 testType: serverTest,
7491 protocol: protocol,
7492 name: "WrongMessageType-ClientKeyExchange" + suffix,
7493 config: Config{
7494 MaxVersion: VersionTLS12,
7495 Bugs: ProtocolBugs{
7496 SendWrongMessageType: typeClientKeyExchange,
7497 },
7498 },
7499 shouldFail: true,
7500 expectedError: ":UNEXPECTED_MESSAGE:",
7501 expectedLocalError: "remote error: unexpected message",
7502 })
7503
7504 if protocol != dtls {
7505 testCases = append(testCases, testCase{
7506 testType: serverTest,
7507 protocol: protocol,
7508 name: "WrongMessageType-NextProtocol" + suffix,
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 NextProtos: []string{"bar"},
7512 Bugs: ProtocolBugs{
7513 SendWrongMessageType: typeNextProtocol,
7514 },
7515 },
7516 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7517 shouldFail: true,
7518 expectedError: ":UNEXPECTED_MESSAGE:",
7519 expectedLocalError: "remote error: unexpected message",
7520 })
7521
7522 testCases = append(testCases, testCase{
7523 testType: serverTest,
7524 protocol: protocol,
7525 name: "WrongMessageType-ChannelID" + suffix,
7526 config: Config{
7527 MaxVersion: VersionTLS12,
7528 ChannelID: channelIDKey,
7529 Bugs: ProtocolBugs{
7530 SendWrongMessageType: typeChannelID,
7531 },
7532 },
7533 flags: []string{
7534 "-expect-channel-id",
7535 base64.StdEncoding.EncodeToString(channelIDBytes),
7536 },
7537 shouldFail: true,
7538 expectedError: ":UNEXPECTED_MESSAGE:",
7539 expectedLocalError: "remote error: unexpected message",
7540 })
7541 }
7542
7543 testCases = append(testCases, testCase{
7544 testType: serverTest,
7545 protocol: protocol,
7546 name: "WrongMessageType-ClientFinished" + suffix,
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 Bugs: ProtocolBugs{
7550 SendWrongMessageType: typeFinished,
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":UNEXPECTED_MESSAGE:",
7555 expectedLocalError: "remote error: unexpected message",
7556 })
7557
7558 testCases = append(testCases, testCase{
7559 protocol: protocol,
7560 name: "WrongMessageType-NewSessionTicket" + suffix,
7561 config: Config{
7562 MaxVersion: VersionTLS12,
7563 Bugs: ProtocolBugs{
7564 SendWrongMessageType: typeNewSessionTicket,
7565 },
7566 },
7567 shouldFail: true,
7568 expectedError: ":UNEXPECTED_MESSAGE:",
7569 expectedLocalError: "remote error: unexpected message",
7570 })
7571
7572 testCases = append(testCases, testCase{
7573 protocol: protocol,
7574 name: "WrongMessageType-ServerFinished" + suffix,
7575 config: Config{
7576 MaxVersion: VersionTLS12,
7577 Bugs: ProtocolBugs{
7578 SendWrongMessageType: typeFinished,
7579 },
7580 },
7581 shouldFail: true,
7582 expectedError: ":UNEXPECTED_MESSAGE:",
7583 expectedLocalError: "remote error: unexpected message",
7584 })
7585
7586 }
7587}
7588
Steven Valdez143e8b32016-07-11 13:19:03 -04007589func addTLS13WrongMessageTypeTests() {
7590 testCases = append(testCases, testCase{
7591 testType: serverTest,
7592 name: "WrongMessageType-TLS13-ClientHello",
7593 config: Config{
7594 MaxVersion: VersionTLS13,
7595 Bugs: ProtocolBugs{
7596 SendWrongMessageType: typeClientHello,
7597 },
7598 },
7599 shouldFail: true,
7600 expectedError: ":UNEXPECTED_MESSAGE:",
7601 expectedLocalError: "remote error: unexpected message",
7602 })
7603
7604 testCases = append(testCases, testCase{
7605 name: "WrongMessageType-TLS13-ServerHello",
7606 config: Config{
7607 MaxVersion: VersionTLS13,
7608 Bugs: ProtocolBugs{
7609 SendWrongMessageType: typeServerHello,
7610 },
7611 },
7612 shouldFail: true,
7613 expectedError: ":UNEXPECTED_MESSAGE:",
7614 // The alert comes in with the wrong encryption.
7615 expectedLocalError: "local error: bad record MAC",
7616 })
7617
7618 testCases = append(testCases, testCase{
7619 name: "WrongMessageType-TLS13-EncryptedExtensions",
7620 config: Config{
7621 MaxVersion: VersionTLS13,
7622 Bugs: ProtocolBugs{
7623 SendWrongMessageType: typeEncryptedExtensions,
7624 },
7625 },
7626 shouldFail: true,
7627 expectedError: ":UNEXPECTED_MESSAGE:",
7628 expectedLocalError: "remote error: unexpected message",
7629 })
7630
7631 testCases = append(testCases, testCase{
7632 name: "WrongMessageType-TLS13-CertificateRequest",
7633 config: Config{
7634 MaxVersion: VersionTLS13,
7635 ClientAuth: RequireAnyClientCert,
7636 Bugs: ProtocolBugs{
7637 SendWrongMessageType: typeCertificateRequest,
7638 },
7639 },
7640 shouldFail: true,
7641 expectedError: ":UNEXPECTED_MESSAGE:",
7642 expectedLocalError: "remote error: unexpected message",
7643 })
7644
7645 testCases = append(testCases, testCase{
7646 name: "WrongMessageType-TLS13-ServerCertificate",
7647 config: Config{
7648 MaxVersion: VersionTLS13,
7649 Bugs: ProtocolBugs{
7650 SendWrongMessageType: typeCertificate,
7651 },
7652 },
7653 shouldFail: true,
7654 expectedError: ":UNEXPECTED_MESSAGE:",
7655 expectedLocalError: "remote error: unexpected message",
7656 })
7657
7658 testCases = append(testCases, testCase{
7659 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7660 config: Config{
7661 MaxVersion: VersionTLS13,
7662 Bugs: ProtocolBugs{
7663 SendWrongMessageType: typeCertificateVerify,
7664 },
7665 },
7666 shouldFail: true,
7667 expectedError: ":UNEXPECTED_MESSAGE:",
7668 expectedLocalError: "remote error: unexpected message",
7669 })
7670
7671 testCases = append(testCases, testCase{
7672 name: "WrongMessageType-TLS13-ServerFinished",
7673 config: Config{
7674 MaxVersion: VersionTLS13,
7675 Bugs: ProtocolBugs{
7676 SendWrongMessageType: typeFinished,
7677 },
7678 },
7679 shouldFail: true,
7680 expectedError: ":UNEXPECTED_MESSAGE:",
7681 expectedLocalError: "remote error: unexpected message",
7682 })
7683
7684 testCases = append(testCases, testCase{
7685 testType: serverTest,
7686 name: "WrongMessageType-TLS13-ClientCertificate",
7687 config: Config{
7688 Certificates: []Certificate{rsaCertificate},
7689 MaxVersion: VersionTLS13,
7690 Bugs: ProtocolBugs{
7691 SendWrongMessageType: typeCertificate,
7692 },
7693 },
7694 flags: []string{"-require-any-client-certificate"},
7695 shouldFail: true,
7696 expectedError: ":UNEXPECTED_MESSAGE:",
7697 expectedLocalError: "remote error: unexpected message",
7698 })
7699
7700 testCases = append(testCases, testCase{
7701 testType: serverTest,
7702 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7703 config: Config{
7704 Certificates: []Certificate{rsaCertificate},
7705 MaxVersion: VersionTLS13,
7706 Bugs: ProtocolBugs{
7707 SendWrongMessageType: typeCertificateVerify,
7708 },
7709 },
7710 flags: []string{"-require-any-client-certificate"},
7711 shouldFail: true,
7712 expectedError: ":UNEXPECTED_MESSAGE:",
7713 expectedLocalError: "remote error: unexpected message",
7714 })
7715
7716 testCases = append(testCases, testCase{
7717 testType: serverTest,
7718 name: "WrongMessageType-TLS13-ClientFinished",
7719 config: Config{
7720 MaxVersion: VersionTLS13,
7721 Bugs: ProtocolBugs{
7722 SendWrongMessageType: typeFinished,
7723 },
7724 },
7725 shouldFail: true,
7726 expectedError: ":UNEXPECTED_MESSAGE:",
7727 expectedLocalError: "remote error: unexpected message",
7728 })
7729}
7730
7731func addTLS13HandshakeTests() {
7732 testCases = append(testCases, testCase{
7733 testType: clientTest,
7734 name: "MissingKeyShare-Client",
7735 config: Config{
7736 MaxVersion: VersionTLS13,
7737 Bugs: ProtocolBugs{
7738 MissingKeyShare: true,
7739 },
7740 },
7741 shouldFail: true,
7742 expectedError: ":MISSING_KEY_SHARE:",
7743 })
7744
7745 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007746 testType: serverTest,
7747 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007748 config: Config{
7749 MaxVersion: VersionTLS13,
7750 Bugs: ProtocolBugs{
7751 MissingKeyShare: true,
7752 },
7753 },
7754 shouldFail: true,
7755 expectedError: ":MISSING_KEY_SHARE:",
7756 })
7757
7758 testCases = append(testCases, testCase{
7759 testType: clientTest,
7760 name: "ClientHelloMissingKeyShare",
7761 config: Config{
7762 MaxVersion: VersionTLS13,
7763 Bugs: ProtocolBugs{
7764 MissingKeyShare: true,
7765 },
7766 },
7767 shouldFail: true,
7768 expectedError: ":MISSING_KEY_SHARE:",
7769 })
7770
7771 testCases = append(testCases, testCase{
7772 testType: clientTest,
7773 name: "MissingKeyShare",
7774 config: Config{
7775 MaxVersion: VersionTLS13,
7776 Bugs: ProtocolBugs{
7777 MissingKeyShare: true,
7778 },
7779 },
7780 shouldFail: true,
7781 expectedError: ":MISSING_KEY_SHARE:",
7782 })
7783
7784 testCases = append(testCases, testCase{
7785 testType: serverTest,
7786 name: "DuplicateKeyShares",
7787 config: Config{
7788 MaxVersion: VersionTLS13,
7789 Bugs: ProtocolBugs{
7790 DuplicateKeyShares: true,
7791 },
7792 },
7793 })
7794
7795 testCases = append(testCases, testCase{
7796 testType: clientTest,
7797 name: "EmptyEncryptedExtensions",
7798 config: Config{
7799 MaxVersion: VersionTLS13,
7800 Bugs: ProtocolBugs{
7801 EmptyEncryptedExtensions: true,
7802 },
7803 },
7804 shouldFail: true,
7805 expectedLocalError: "remote error: error decoding message",
7806 })
7807
7808 testCases = append(testCases, testCase{
7809 testType: clientTest,
7810 name: "EncryptedExtensionsWithKeyShare",
7811 config: Config{
7812 MaxVersion: VersionTLS13,
7813 Bugs: ProtocolBugs{
7814 EncryptedExtensionsWithKeyShare: true,
7815 },
7816 },
7817 shouldFail: true,
7818 expectedLocalError: "remote error: unsupported extension",
7819 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007820
7821 testCases = append(testCases, testCase{
7822 testType: serverTest,
7823 name: "SendHelloRetryRequest",
7824 config: Config{
7825 MaxVersion: VersionTLS13,
7826 // Require a HelloRetryRequest for every curve.
7827 DefaultCurves: []CurveID{},
7828 },
7829 expectedCurveID: CurveX25519,
7830 })
7831
7832 testCases = append(testCases, testCase{
7833 testType: serverTest,
7834 name: "SendHelloRetryRequest-2",
7835 config: Config{
7836 MaxVersion: VersionTLS13,
7837 DefaultCurves: []CurveID{CurveP384},
7838 },
7839 // Although the ClientHello did not predict our preferred curve,
7840 // we always select it whether it is predicted or not.
7841 expectedCurveID: CurveX25519,
7842 })
7843
7844 testCases = append(testCases, testCase{
7845 name: "UnknownCurve-HelloRetryRequest",
7846 config: Config{
7847 MaxVersion: VersionTLS13,
7848 // P-384 requires HelloRetryRequest in BoringSSL.
7849 CurvePreferences: []CurveID{CurveP384},
7850 Bugs: ProtocolBugs{
7851 SendHelloRetryRequestCurve: bogusCurve,
7852 },
7853 },
7854 shouldFail: true,
7855 expectedError: ":WRONG_CURVE:",
7856 })
7857
7858 testCases = append(testCases, testCase{
7859 name: "DisabledCurve-HelloRetryRequest",
7860 config: Config{
7861 MaxVersion: VersionTLS13,
7862 CurvePreferences: []CurveID{CurveP256},
7863 Bugs: ProtocolBugs{
7864 IgnorePeerCurvePreferences: true,
7865 },
7866 },
7867 flags: []string{"-p384-only"},
7868 shouldFail: true,
7869 expectedError: ":WRONG_CURVE:",
7870 })
7871
7872 testCases = append(testCases, testCase{
7873 name: "UnnecessaryHelloRetryRequest",
7874 config: Config{
7875 MaxVersion: VersionTLS13,
7876 Bugs: ProtocolBugs{
7877 UnnecessaryHelloRetryRequest: true,
7878 },
7879 },
7880 shouldFail: true,
7881 expectedError: ":WRONG_CURVE:",
7882 })
7883
7884 testCases = append(testCases, testCase{
7885 name: "SecondHelloRetryRequest",
7886 config: Config{
7887 MaxVersion: VersionTLS13,
7888 // P-384 requires HelloRetryRequest in BoringSSL.
7889 CurvePreferences: []CurveID{CurveP384},
7890 Bugs: ProtocolBugs{
7891 SecondHelloRetryRequest: true,
7892 },
7893 },
7894 shouldFail: true,
7895 expectedError: ":UNEXPECTED_MESSAGE:",
7896 })
7897
7898 testCases = append(testCases, testCase{
7899 testType: serverTest,
7900 name: "SecondClientHelloMissingKeyShare",
7901 config: Config{
7902 MaxVersion: VersionTLS13,
7903 DefaultCurves: []CurveID{},
7904 Bugs: ProtocolBugs{
7905 SecondClientHelloMissingKeyShare: true,
7906 },
7907 },
7908 shouldFail: true,
7909 expectedError: ":MISSING_KEY_SHARE:",
7910 })
7911
7912 testCases = append(testCases, testCase{
7913 testType: serverTest,
7914 name: "SecondClientHelloWrongCurve",
7915 config: Config{
7916 MaxVersion: VersionTLS13,
7917 DefaultCurves: []CurveID{},
7918 Bugs: ProtocolBugs{
7919 MisinterpretHelloRetryRequestCurve: CurveP521,
7920 },
7921 },
7922 shouldFail: true,
7923 expectedError: ":WRONG_CURVE:",
7924 })
7925
7926 testCases = append(testCases, testCase{
7927 name: "HelloRetryRequestVersionMismatch",
7928 config: Config{
7929 MaxVersion: VersionTLS13,
7930 // P-384 requires HelloRetryRequest in BoringSSL.
7931 CurvePreferences: []CurveID{CurveP384},
7932 Bugs: ProtocolBugs{
7933 SendServerHelloVersion: 0x0305,
7934 },
7935 },
7936 shouldFail: true,
7937 expectedError: ":WRONG_VERSION_NUMBER:",
7938 })
7939
7940 testCases = append(testCases, testCase{
7941 name: "HelloRetryRequestCurveMismatch",
7942 config: Config{
7943 MaxVersion: VersionTLS13,
7944 // P-384 requires HelloRetryRequest in BoringSSL.
7945 CurvePreferences: []CurveID{CurveP384},
7946 Bugs: ProtocolBugs{
7947 // Send P-384 (correct) in the HelloRetryRequest.
7948 SendHelloRetryRequestCurve: CurveP384,
7949 // But send P-256 in the ServerHello.
7950 SendCurve: CurveP256,
7951 },
7952 },
7953 shouldFail: true,
7954 expectedError: ":WRONG_CURVE:",
7955 })
7956
7957 // Test the server selecting a curve that requires a HelloRetryRequest
7958 // without sending it.
7959 testCases = append(testCases, testCase{
7960 name: "SkipHelloRetryRequest",
7961 config: Config{
7962 MaxVersion: VersionTLS13,
7963 // P-384 requires HelloRetryRequest in BoringSSL.
7964 CurvePreferences: []CurveID{CurveP384},
7965 Bugs: ProtocolBugs{
7966 SkipHelloRetryRequest: true,
7967 },
7968 },
7969 shouldFail: true,
7970 expectedError: ":WRONG_CURVE:",
7971 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007972}
7973
Adam Langley7c803a62015-06-15 15:35:05 -07007974func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007975 defer wg.Done()
7976
7977 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007978 var err error
7979
7980 if *mallocTest < 0 {
7981 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007982 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007983 } else {
7984 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7985 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007986 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007987 if err != nil {
7988 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7989 }
7990 break
7991 }
7992 }
7993 }
Adam Langley95c29f32014-06-20 12:00:00 -07007994 statusChan <- statusMsg{test: test, err: err}
7995 }
7996}
7997
7998type statusMsg struct {
7999 test *testCase
8000 started bool
8001 err error
8002}
8003
David Benjamin5f237bc2015-02-11 17:14:15 -05008004func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008005 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008006
David Benjamin5f237bc2015-02-11 17:14:15 -05008007 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008008 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008009 if !*pipe {
8010 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008011 var erase string
8012 for i := 0; i < lineLen; i++ {
8013 erase += "\b \b"
8014 }
8015 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008016 }
8017
Adam Langley95c29f32014-06-20 12:00:00 -07008018 if msg.started {
8019 started++
8020 } else {
8021 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008022
8023 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008024 if msg.err == errUnimplemented {
8025 if *pipe {
8026 // Print each test instead of a status line.
8027 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8028 }
8029 unimplemented++
8030 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8031 } else {
8032 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8033 failed++
8034 testOutput.addResult(msg.test.name, "FAIL")
8035 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008036 } else {
8037 if *pipe {
8038 // Print each test instead of a status line.
8039 fmt.Printf("PASSED (%s)\n", msg.test.name)
8040 }
8041 testOutput.addResult(msg.test.name, "PASS")
8042 }
Adam Langley95c29f32014-06-20 12:00:00 -07008043 }
8044
David Benjamin5f237bc2015-02-11 17:14:15 -05008045 if !*pipe {
8046 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008047 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008048 lineLen = len(line)
8049 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008050 }
Adam Langley95c29f32014-06-20 12:00:00 -07008051 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008052
8053 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008054}
8055
8056func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008057 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008058 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008059 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008060
Adam Langley7c803a62015-06-15 15:35:05 -07008061 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008062 addCipherSuiteTests()
8063 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008064 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008065 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008066 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008067 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008068 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008069 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008070 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008071 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008072 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008073 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008074 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008075 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008076 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008077 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008078 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008079 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008080 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008081 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008082 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008083 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008084 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008085 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008086 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008087 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008088 addTLS13WrongMessageTypeTests()
8089 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008090
8091 var wg sync.WaitGroup
8092
Adam Langley7c803a62015-06-15 15:35:05 -07008093 statusChan := make(chan statusMsg, *numWorkers)
8094 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008095 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008096
EKRf71d7ed2016-08-06 13:25:12 -07008097 if len(*shimConfigFile) != 0 {
8098 encoded, err := ioutil.ReadFile(*shimConfigFile)
8099 if err != nil {
8100 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8101 os.Exit(1)
8102 }
8103
8104 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8105 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8106 os.Exit(1)
8107 }
8108 }
8109
David Benjamin025b3d32014-07-01 19:53:04 -04008110 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008111
Adam Langley7c803a62015-06-15 15:35:05 -07008112 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008113 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008114 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008115 }
8116
David Benjamin270f0a72016-03-17 14:41:36 -04008117 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008118 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008119 matched := true
8120 if len(*testToRun) != 0 {
8121 var err error
8122 matched, err = filepath.Match(*testToRun, testCases[i].name)
8123 if err != nil {
8124 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8125 os.Exit(1)
8126 }
8127 }
8128
EKRf71d7ed2016-08-06 13:25:12 -07008129 if !*includeDisabled {
8130 for pattern := range shimConfig.DisabledTests {
8131 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8132 if err != nil {
8133 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8134 os.Exit(1)
8135 }
8136
8137 if isDisabled {
8138 matched = false
8139 break
8140 }
8141 }
8142 }
8143
David Benjamin17e12922016-07-28 18:04:43 -04008144 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008145 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008146 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008147 }
8148 }
David Benjamin17e12922016-07-28 18:04:43 -04008149
David Benjamin270f0a72016-03-17 14:41:36 -04008150 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008151 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008152 os.Exit(1)
8153 }
Adam Langley95c29f32014-06-20 12:00:00 -07008154
8155 close(testChan)
8156 wg.Wait()
8157 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008158 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008159
8160 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008161
8162 if *jsonOutput != "" {
8163 if err := testOutput.writeTo(*jsonOutput); err != nil {
8164 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8165 }
8166 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008167
EKR842ae6c2016-07-27 09:22:05 +02008168 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8169 os.Exit(1)
8170 }
8171
8172 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008173 os.Exit(1)
8174 }
Adam Langley95c29f32014-06-20 12:00:00 -07008175}