blob: 19b8ee778b366bdbfaf48b5697beb5d38dc06ad6 [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
Steven Valdez32635b82016-08-16 11:25:03 -0400356 // sendKeyUpdates is the number of consecutive key updates to send
357 // before and after the test message.
358 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400359 // expectMessageDropped, if true, means the test message is expected to
360 // be dropped by the client rather than echoed back.
361 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700362}
363
Adam Langley7c803a62015-06-15 15:35:05 -0700364var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700365
David Benjamin9867b7d2016-03-01 23:25:48 -0500366func writeTranscript(test *testCase, isResume bool, data []byte) {
367 if len(data) == 0 {
368 return
369 }
370
371 protocol := "tls"
372 if test.protocol == dtls {
373 protocol = "dtls"
374 }
375
376 side := "client"
377 if test.testType == serverTest {
378 side = "server"
379 }
380
381 dir := path.Join(*transcriptDir, protocol, side)
382 if err := os.MkdirAll(dir, 0755); err != nil {
383 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
384 return
385 }
386
387 name := test.name
388 if isResume {
389 name += "-Resume"
390 } else {
391 name += "-Normal"
392 }
393
394 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
395 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
396 }
397}
398
David Benjamin3ed59772016-03-08 12:50:21 -0500399// A timeoutConn implements an idle timeout on each Read and Write operation.
400type timeoutConn struct {
401 net.Conn
402 timeout time.Duration
403}
404
405func (t *timeoutConn) Read(b []byte) (int, error) {
406 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
407 return 0, err
408 }
409 return t.Conn.Read(b)
410}
411
412func (t *timeoutConn) Write(b []byte) (int, error) {
413 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
414 return 0, err
415 }
416 return t.Conn.Write(b)
417}
418
David Benjamin8e6db492015-07-25 18:29:23 -0400419func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400420 if !test.noSessionCache {
421 if config.ClientSessionCache == nil {
422 config.ClientSessionCache = NewLRUClientSessionCache(1)
423 }
424 if config.ServerSessionCache == nil {
425 config.ServerSessionCache = NewLRUServerSessionCache(1)
426 }
427 }
428 if test.testType == clientTest {
429 if len(config.Certificates) == 0 {
430 config.Certificates = []Certificate{rsaCertificate}
431 }
432 } else {
433 // Supply a ServerName to ensure a constant session cache key,
434 // rather than falling back to net.Conn.RemoteAddr.
435 if len(config.ServerName) == 0 {
436 config.ServerName = "test"
437 }
438 }
439 if *fuzzer {
440 config.Bugs.NullAllCiphers = true
441 }
442 if *deterministic {
443 config.Rand = &deterministicRand{}
444 }
445
David Benjamin01784b42016-06-07 18:00:52 -0400446 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500447
David Benjamin6fd297b2014-08-11 18:43:38 -0400448 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500449 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
450 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500451 }
452
David Benjamin9867b7d2016-03-01 23:25:48 -0500453 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500454 local, peer := "client", "server"
455 if test.testType == clientTest {
456 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500457 }
David Benjaminebda9b32015-11-02 15:33:18 -0500458 connDebug := &recordingConn{
459 Conn: conn,
460 isDatagram: test.protocol == dtls,
461 local: local,
462 peer: peer,
463 }
464 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500465 if *flagDebug {
466 defer connDebug.WriteTo(os.Stdout)
467 }
468 if len(*transcriptDir) != 0 {
469 defer func() {
470 writeTranscript(test, isResume, connDebug.Transcript())
471 }()
472 }
David Benjaminebda9b32015-11-02 15:33:18 -0500473
474 if config.Bugs.PacketAdaptor != nil {
475 config.Bugs.PacketAdaptor.debug = connDebug
476 }
477 }
478
479 if test.replayWrites {
480 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400481 }
482
David Benjamin3ed59772016-03-08 12:50:21 -0500483 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500484 if test.damageFirstWrite {
485 connDamage = newDamageAdaptor(conn)
486 conn = connDamage
487 }
488
David Benjamin6fd297b2014-08-11 18:43:38 -0400489 if test.sendPrefix != "" {
490 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
491 return err
492 }
David Benjamin98e882e2014-08-08 13:24:34 -0400493 }
494
David Benjamin1d5c83e2014-07-22 19:20:02 -0400495 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400496 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 if test.protocol == dtls {
498 tlsConn = DTLSServer(conn, config)
499 } else {
500 tlsConn = Server(conn, config)
501 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400502 } else {
503 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400504 if test.protocol == dtls {
505 tlsConn = DTLSClient(conn, config)
506 } else {
507 tlsConn = Client(conn, config)
508 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400509 }
David Benjamin30789da2015-08-29 22:56:45 -0400510 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511
Adam Langley95c29f32014-06-20 12:00:00 -0700512 if err := tlsConn.Handshake(); err != nil {
513 return err
514 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700515
David Benjamin01fe8202014-09-24 15:21:44 -0400516 // TODO(davidben): move all per-connection expectations into a dedicated
517 // expectations struct that can be specified separately for the two
518 // legs.
519 expectedVersion := test.expectedVersion
520 if isResume && test.expectedResumeVersion != 0 {
521 expectedVersion = test.expectedResumeVersion
522 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700523 connState := tlsConn.ConnectionState()
524 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400525 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400526 }
527
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400529 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
530 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
532 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
533 }
David Benjamin90da8c82015-04-20 14:57:57 -0400534
David Benjamina08e49d2014-08-24 01:46:07 -0400535 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700536 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400537 if channelID == nil {
538 return fmt.Errorf("no channel ID negotiated")
539 }
540 if channelID.Curve != channelIDKey.Curve ||
541 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
542 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
543 return fmt.Errorf("incorrect channel ID")
544 }
545 }
546
David Benjaminae2888f2014-09-06 12:58:58 -0400547 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400549 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
550 }
551 }
552
David Benjaminc7ce9772015-10-09 19:32:41 -0400553 if test.expectNoNextProto {
554 if actual := connState.NegotiatedProtocol; actual != "" {
555 return fmt.Errorf("got unexpected next proto %s", actual)
556 }
557 }
558
David Benjaminfc7b0862014-09-06 13:21:53 -0400559 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700560 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400561 return fmt.Errorf("next proto type mismatch")
562 }
563 }
564
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700565 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500566 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
567 }
568
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100569 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300570 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100571 }
572
Paul Lietar4fac72e2015-09-09 13:44:55 +0100573 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
574 return fmt.Errorf("SCT list mismatch")
575 }
576
Nick Harper60edffd2016-06-21 15:19:24 -0700577 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
578 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400579 }
580
Steven Valdez5440fe02016-07-18 12:40:30 -0400581 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
582 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
583 }
584
David Benjaminc565ebb2015-04-03 04:06:36 -0400585 if test.exportKeyingMaterial > 0 {
586 actual := make([]byte, test.exportKeyingMaterial)
587 if _, err := io.ReadFull(tlsConn, actual); err != nil {
588 return err
589 }
590 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
591 if err != nil {
592 return err
593 }
594 if !bytes.Equal(actual, expected) {
595 return fmt.Errorf("keying material mismatch")
596 }
597 }
598
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700599 if test.testTLSUnique {
600 var peersValue [12]byte
601 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
602 return err
603 }
604 expected := tlsConn.ConnectionState().TLSUnique
605 if !bytes.Equal(peersValue[:], expected) {
606 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
607 }
608 }
609
David Benjamine58c4f52014-08-24 03:47:07 -0400610 if test.shimWritesFirst {
611 var buf [5]byte
612 _, err := io.ReadFull(tlsConn, buf[:])
613 if err != nil {
614 return err
615 }
616 if string(buf[:]) != "hello" {
617 return fmt.Errorf("bad initial message")
618 }
619 }
620
Steven Valdez32635b82016-08-16 11:25:03 -0400621 for i := 0; i < test.sendKeyUpdates; i++ {
622 tlsConn.SendKeyUpdate()
623 }
624
David Benjamina8ebe222015-06-06 03:04:39 -0400625 for i := 0; i < test.sendEmptyRecords; i++ {
626 tlsConn.Write(nil)
627 }
628
David Benjamin24f346d2015-06-06 03:28:08 -0400629 for i := 0; i < test.sendWarningAlerts; i++ {
630 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
631 }
632
David Benjamin47921102016-07-28 11:29:18 -0400633 if test.sendHalfHelloRequest {
634 tlsConn.SendHalfHelloRequest()
635 }
636
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400637 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700638 if test.renegotiateCiphers != nil {
639 config.CipherSuites = test.renegotiateCiphers
640 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 for i := 0; i < test.renegotiate; i++ {
642 if err := tlsConn.Renegotiate(); err != nil {
643 return err
644 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700645 }
646 } else if test.renegotiateCiphers != nil {
647 panic("renegotiateCiphers without renegotiate")
648 }
649
David Benjamin5fa3eba2015-01-22 16:35:40 -0500650 if test.damageFirstWrite {
651 connDamage.setDamage(true)
652 tlsConn.Write([]byte("DAMAGED WRITE"))
653 connDamage.setDamage(false)
654 }
655
David Benjamin8e6db492015-07-25 18:29:23 -0400656 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700657 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400658 if test.protocol == dtls {
659 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
660 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 // Read until EOF.
662 _, err := io.Copy(ioutil.Discard, tlsConn)
663 return err
664 }
David Benjamin4417d052015-04-05 04:17:25 -0400665 if messageLen == 0 {
666 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700667 }
Adam Langley95c29f32014-06-20 12:00:00 -0700668
David Benjamin8e6db492015-07-25 18:29:23 -0400669 messageCount := test.messageCount
670 if messageCount == 0 {
671 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400672 }
673
David Benjamin8e6db492015-07-25 18:29:23 -0400674 for j := 0; j < messageCount; j++ {
675 testMessage := make([]byte, messageLen)
676 for i := range testMessage {
677 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400678 }
David Benjamin8e6db492015-07-25 18:29:23 -0400679 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700680
Steven Valdez32635b82016-08-16 11:25:03 -0400681 for i := 0; i < test.sendKeyUpdates; i++ {
682 tlsConn.SendKeyUpdate()
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 for i := 0; i < test.sendEmptyRecords; i++ {
686 tlsConn.Write(nil)
687 }
688
689 for i := 0; i < test.sendWarningAlerts; i++ {
690 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
691 }
692
David Benjamin4f75aaf2015-09-01 16:53:10 -0400693 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400694 // The shim will not respond.
695 continue
696 }
697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 buf := make([]byte, len(testMessage))
699 if test.protocol == dtls {
700 bufTmp := make([]byte, len(buf)+1)
701 n, err := tlsConn.Read(bufTmp)
702 if err != nil {
703 return err
704 }
705 if n != len(buf) {
706 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
707 }
708 copy(buf, bufTmp)
709 } else {
710 _, err := io.ReadFull(tlsConn, buf)
711 if err != nil {
712 return err
713 }
714 }
715
716 for i, v := range buf {
717 if v != testMessage[i]^0xff {
718 return fmt.Errorf("bad reply contents at byte %d", i)
719 }
Adam Langley95c29f32014-06-20 12:00:00 -0700720 }
721 }
722
723 return nil
724}
725
David Benjamin325b5c32014-07-01 19:40:31 -0400726func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400729 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700730 }
David Benjamin325b5c32014-07-01 19:40:31 -0400731 valgrindArgs = append(valgrindArgs, path)
732 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700733
David Benjamin325b5c32014-07-01 19:40:31 -0400734 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700735}
736
David Benjamin325b5c32014-07-01 19:40:31 -0400737func gdbOf(path string, args ...string) *exec.Cmd {
738 xtermArgs := []string{"-e", "gdb", "--args"}
739 xtermArgs = append(xtermArgs, path)
740 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700741
David Benjamin325b5c32014-07-01 19:40:31 -0400742 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700743}
744
David Benjamind16bf342015-12-18 00:53:12 -0500745func lldbOf(path string, args ...string) *exec.Cmd {
746 xtermArgs := []string{"-e", "lldb", "--"}
747 xtermArgs = append(xtermArgs, path)
748 xtermArgs = append(xtermArgs, args...)
749
750 return exec.Command("xterm", xtermArgs...)
751}
752
EKR842ae6c2016-07-27 09:22:05 +0200753var (
754 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
755 errUnimplemented = errors.New("child process does not implement needed flags")
756)
Adam Langley69a01602014-11-17 17:26:55 -0800757
David Benjamin87c8a642015-02-21 01:54:29 -0500758// accept accepts a connection from listener, unless waitChan signals a process
759// exit first.
760func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
761 type connOrError struct {
762 conn net.Conn
763 err error
764 }
765 connChan := make(chan connOrError, 1)
766 go func() {
767 conn, err := listener.Accept()
768 connChan <- connOrError{conn, err}
769 close(connChan)
770 }()
771 select {
772 case result := <-connChan:
773 return result.conn, result.err
774 case childErr := <-waitChan:
775 waitChan <- childErr
776 return nil, fmt.Errorf("child exited early: %s", childErr)
777 }
778}
779
EKRf71d7ed2016-08-06 13:25:12 -0700780func translateExpectedError(errorStr string) string {
781 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
782 return translated
783 }
784
785 if *looseErrors {
786 return ""
787 }
788
789 return errorStr
790}
791
Adam Langley7c803a62015-06-15 15:35:05 -0700792func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700793 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
794 panic("Error expected without shouldFail in " + test.name)
795 }
796
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700797 if test.expectResumeRejected && !test.resumeSession {
798 panic("expectResumeRejected without resumeSession in " + test.name)
799 }
800
David Benjamin87c8a642015-02-21 01:54:29 -0500801 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
802 if err != nil {
803 panic(err)
804 }
805 defer func() {
806 if listener != nil {
807 listener.Close()
808 }
809 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700810
David Benjamin87c8a642015-02-21 01:54:29 -0500811 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400812 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400813 flags = append(flags, "-server")
814
David Benjamin025b3d32014-07-01 19:53:04 -0400815 flags = append(flags, "-key-file")
816 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700817 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400818 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700819 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400820 }
821
822 flags = append(flags, "-cert-file")
823 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828 }
David Benjamin5a593af2014-08-11 19:51:50 -0400829
David Benjamin6fd297b2014-08-11 18:43:38 -0400830 if test.protocol == dtls {
831 flags = append(flags, "-dtls")
832 }
833
David Benjamin5a593af2014-08-11 19:51:50 -0400834 if test.resumeSession {
835 flags = append(flags, "-resume")
836 }
837
David Benjamine58c4f52014-08-24 03:47:07 -0400838 if test.shimWritesFirst {
839 flags = append(flags, "-shim-writes-first")
840 }
841
David Benjamin30789da2015-08-29 22:56:45 -0400842 if test.shimShutsDown {
843 flags = append(flags, "-shim-shuts-down")
844 }
845
David Benjaminc565ebb2015-04-03 04:06:36 -0400846 if test.exportKeyingMaterial > 0 {
847 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
848 flags = append(flags, "-export-label", test.exportLabel)
849 flags = append(flags, "-export-context", test.exportContext)
850 if test.useExportContext {
851 flags = append(flags, "-use-export-context")
852 }
853 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700854 if test.expectResumeRejected {
855 flags = append(flags, "-expect-session-miss")
856 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400857
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700858 if test.testTLSUnique {
859 flags = append(flags, "-tls-unique")
860 }
861
David Benjamin025b3d32014-07-01 19:53:04 -0400862 flags = append(flags, test.flags...)
863
864 var shim *exec.Cmd
865 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700866 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700867 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700868 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500869 } else if *useLLDB {
870 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400871 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700872 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400873 }
David Benjamin025b3d32014-07-01 19:53:04 -0400874 shim.Stdin = os.Stdin
875 var stdoutBuf, stderrBuf bytes.Buffer
876 shim.Stdout = &stdoutBuf
877 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800878 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500879 shim.Env = os.Environ()
880 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800881 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400882 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800883 }
884 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
885 }
David Benjamin025b3d32014-07-01 19:53:04 -0400886
887 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700888 panic(err)
889 }
David Benjamin87c8a642015-02-21 01:54:29 -0500890 waitChan := make(chan error, 1)
891 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700892
893 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700894
David Benjamin87c8a642015-02-21 01:54:29 -0500895 conn, err := acceptOrWait(listener, waitChan)
896 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400897 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500898 conn.Close()
899 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500900
David Benjamin1d5c83e2014-07-22 19:20:02 -0400901 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400902 var resumeConfig Config
903 if test.resumeConfig != nil {
904 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400905 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500906 resumeConfig.SessionTicketKey = config.SessionTicketKey
907 resumeConfig.ClientSessionCache = config.ClientSessionCache
908 resumeConfig.ServerSessionCache = config.ServerSessionCache
909 }
David Benjamin2e045a92016-06-08 13:09:56 -0400910 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400911 } else {
912 resumeConfig = config
913 }
David Benjamin87c8a642015-02-21 01:54:29 -0500914 var connResume net.Conn
915 connResume, err = acceptOrWait(listener, waitChan)
916 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400917 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500918 connResume.Close()
919 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400920 }
921
David Benjamin87c8a642015-02-21 01:54:29 -0500922 // Close the listener now. This is to avoid hangs should the shim try to
923 // open more connections than expected.
924 listener.Close()
925 listener = nil
926
927 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800928 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200929 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
930 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800931 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200932 case 89:
933 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800934 }
935 }
Adam Langley95c29f32014-06-20 12:00:00 -0700936
David Benjamin9bea3492016-03-02 10:59:16 -0500937 // Account for Windows line endings.
938 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
939 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500940
941 // Separate the errors from the shim and those from tools like
942 // AddressSanitizer.
943 var extraStderr string
944 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
945 stderr = stderrParts[0]
946 extraStderr = stderrParts[1]
947 }
948
Adam Langley95c29f32014-06-20 12:00:00 -0700949 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700950 expectedError := translateExpectedError(test.expectedError)
951 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200952
Adam Langleyac61fa32014-06-23 12:03:11 -0700953 localError := "none"
954 if err != nil {
955 localError = err.Error()
956 }
957 if len(test.expectedLocalError) != 0 {
958 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
959 }
Adam Langley95c29f32014-06-20 12:00:00 -0700960
961 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700962 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700963 if childErr != nil {
964 childError = childErr.Error()
965 }
966
967 var msg string
968 switch {
969 case failed && !test.shouldFail:
970 msg = "unexpected failure"
971 case !failed && test.shouldFail:
972 msg = "unexpected success"
973 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700974 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 default:
976 panic("internal error")
977 }
978
David Benjaminc565ebb2015-04-03 04:06:36 -0400979 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 -0700980 }
981
David Benjaminff3a1492016-03-02 10:12:06 -0500982 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
983 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700984 }
985
986 return nil
987}
988
989var tlsVersions = []struct {
990 name string
991 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400992 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500993 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700994}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500995 {"SSL3", VersionSSL30, "-no-ssl3", false},
996 {"TLS1", VersionTLS10, "-no-tls1", true},
997 {"TLS11", VersionTLS11, "-no-tls11", false},
998 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400999 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001000}
1001
1002var testCipherSuites = []struct {
1003 name string
1004 id uint16
1005}{
1006 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001007 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001008 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001009 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001010 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001011 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001012 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001013 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1014 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001015 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001016 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1017 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001018 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001019 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1020 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001021 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1022 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001023 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001024 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001025 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001026 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001028 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001029 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001031 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001032 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001034 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001035 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001036 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001037 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1038 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1039 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1040 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001041 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1042 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001043 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1044 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001046 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1047 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001048 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001049 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001050 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001051 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001052}
1053
David Benjamin8b8c0062014-11-23 02:47:52 -05001054func hasComponent(suiteName, component string) bool {
1055 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1056}
1057
David Benjaminf7768e42014-08-31 02:06:47 -04001058func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001059 return hasComponent(suiteName, "GCM") ||
1060 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001061 hasComponent(suiteName, "SHA384") ||
1062 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001063}
1064
Nick Harper1fd39d82016-06-14 18:14:35 -07001065func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001066 // Only AEADs.
1067 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1068 return false
1069 }
1070 // No old CHACHA20_POLY1305.
1071 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1072 return false
1073 }
1074 // Must have ECDHE.
1075 // TODO(davidben,svaldez): Add pure PSK support.
1076 if !hasComponent(suiteName, "ECDHE") {
1077 return false
1078 }
1079 // TODO(davidben,svaldez): Add PSK support.
1080 if hasComponent(suiteName, "PSK") {
1081 return false
1082 }
1083 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001084}
1085
David Benjamin8b8c0062014-11-23 02:47:52 -05001086func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001087 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001088}
1089
Adam Langleya7997f12015-05-14 17:38:50 -07001090func bigFromHex(hex string) *big.Int {
1091 ret, ok := new(big.Int).SetString(hex, 16)
1092 if !ok {
1093 panic("failed to parse hex number 0x" + hex)
1094 }
1095 return ret
1096}
1097
Adam Langley7c803a62015-06-15 15:35:05 -07001098func addBasicTests() {
1099 basicTests := []testCase{
1100 {
Adam Langley7c803a62015-06-15 15:35:05 -07001101 name: "NoFallbackSCSV",
1102 config: Config{
1103 Bugs: ProtocolBugs{
1104 FailIfNotFallbackSCSV: true,
1105 },
1106 },
1107 shouldFail: true,
1108 expectedLocalError: "no fallback SCSV found",
1109 },
1110 {
1111 name: "SendFallbackSCSV",
1112 config: Config{
1113 Bugs: ProtocolBugs{
1114 FailIfNotFallbackSCSV: true,
1115 },
1116 },
1117 flags: []string{"-fallback-scsv"},
1118 },
1119 {
1120 name: "ClientCertificateTypes",
1121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001122 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001123 ClientAuth: RequestClientCert,
1124 ClientCertificateTypes: []byte{
1125 CertTypeDSSSign,
1126 CertTypeRSASign,
1127 CertTypeECDSASign,
1128 },
1129 },
1130 flags: []string{
1131 "-expect-certificate-types",
1132 base64.StdEncoding.EncodeToString([]byte{
1133 CertTypeDSSSign,
1134 CertTypeRSASign,
1135 CertTypeECDSASign,
1136 }),
1137 },
1138 },
1139 {
Adam Langley7c803a62015-06-15 15:35:05 -07001140 name: "UnauthenticatedECDH",
1141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001142 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001143 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1144 Bugs: ProtocolBugs{
1145 UnauthenticatedECDH: true,
1146 },
1147 },
1148 shouldFail: true,
1149 expectedError: ":UNEXPECTED_MESSAGE:",
1150 },
1151 {
1152 name: "SkipCertificateStatus",
1153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001154 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001155 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1156 Bugs: ProtocolBugs{
1157 SkipCertificateStatus: true,
1158 },
1159 },
1160 flags: []string{
1161 "-enable-ocsp-stapling",
1162 },
1163 },
1164 {
1165 name: "SkipServerKeyExchange",
1166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001167 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001168 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1169 Bugs: ProtocolBugs{
1170 SkipServerKeyExchange: true,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedError: ":UNEXPECTED_MESSAGE:",
1175 },
1176 {
Adam Langley7c803a62015-06-15 15:35:05 -07001177 testType: serverTest,
1178 name: "Alert",
1179 config: Config{
1180 Bugs: ProtocolBugs{
1181 SendSpuriousAlert: alertRecordOverflow,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1186 },
1187 {
1188 protocol: dtls,
1189 testType: serverTest,
1190 name: "Alert-DTLS",
1191 config: Config{
1192 Bugs: ProtocolBugs{
1193 SendSpuriousAlert: alertRecordOverflow,
1194 },
1195 },
1196 shouldFail: true,
1197 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1198 },
1199 {
1200 testType: serverTest,
1201 name: "FragmentAlert",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 FragmentAlert: true,
1205 SendSpuriousAlert: alertRecordOverflow,
1206 },
1207 },
1208 shouldFail: true,
1209 expectedError: ":BAD_ALERT:",
1210 },
1211 {
1212 protocol: dtls,
1213 testType: serverTest,
1214 name: "FragmentAlert-DTLS",
1215 config: Config{
1216 Bugs: ProtocolBugs{
1217 FragmentAlert: true,
1218 SendSpuriousAlert: alertRecordOverflow,
1219 },
1220 },
1221 shouldFail: true,
1222 expectedError: ":BAD_ALERT:",
1223 },
1224 {
1225 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001226 name: "DoubleAlert",
1227 config: Config{
1228 Bugs: ProtocolBugs{
1229 DoubleAlert: true,
1230 SendSpuriousAlert: alertRecordOverflow,
1231 },
1232 },
1233 shouldFail: true,
1234 expectedError: ":BAD_ALERT:",
1235 },
1236 {
1237 protocol: dtls,
1238 testType: serverTest,
1239 name: "DoubleAlert-DTLS",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 DoubleAlert: true,
1243 SendSpuriousAlert: alertRecordOverflow,
1244 },
1245 },
1246 shouldFail: true,
1247 expectedError: ":BAD_ALERT:",
1248 },
1249 {
Adam Langley7c803a62015-06-15 15:35:05 -07001250 name: "SkipNewSessionTicket",
1251 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001252 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001253 Bugs: ProtocolBugs{
1254 SkipNewSessionTicket: true,
1255 },
1256 },
1257 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001258 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001259 },
1260 {
1261 testType: serverTest,
1262 name: "FallbackSCSV",
1263 config: Config{
1264 MaxVersion: VersionTLS11,
1265 Bugs: ProtocolBugs{
1266 SendFallbackSCSV: true,
1267 },
1268 },
1269 shouldFail: true,
1270 expectedError: ":INAPPROPRIATE_FALLBACK:",
1271 },
1272 {
1273 testType: serverTest,
1274 name: "FallbackSCSV-VersionMatch",
1275 config: Config{
1276 Bugs: ProtocolBugs{
1277 SendFallbackSCSV: true,
1278 },
1279 },
1280 },
1281 {
1282 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001283 name: "FallbackSCSV-VersionMatch-TLS12",
1284 config: Config{
1285 MaxVersion: VersionTLS12,
1286 Bugs: ProtocolBugs{
1287 SendFallbackSCSV: true,
1288 },
1289 },
1290 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1291 },
1292 {
1293 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001294 name: "FragmentedClientVersion",
1295 config: Config{
1296 Bugs: ProtocolBugs{
1297 MaxHandshakeRecordLength: 1,
1298 FragmentClientVersion: true,
1299 },
1300 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001301 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001302 },
1303 {
Adam Langley7c803a62015-06-15 15:35:05 -07001304 testType: serverTest,
1305 name: "HttpGET",
1306 sendPrefix: "GET / HTTP/1.0\n",
1307 shouldFail: true,
1308 expectedError: ":HTTP_REQUEST:",
1309 },
1310 {
1311 testType: serverTest,
1312 name: "HttpPOST",
1313 sendPrefix: "POST / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpHEAD",
1320 sendPrefix: "HEAD / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpPUT",
1327 sendPrefix: "PUT / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpCONNECT",
1334 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTPS_PROXY_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "Garbage",
1341 sendPrefix: "blah",
1342 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001343 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001344 },
1345 {
Adam Langley7c803a62015-06-15 15:35:05 -07001346 name: "RSAEphemeralKey",
1347 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001348 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001349 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1350 Bugs: ProtocolBugs{
1351 RSAEphemeralKey: true,
1352 },
1353 },
1354 shouldFail: true,
1355 expectedError: ":UNEXPECTED_MESSAGE:",
1356 },
1357 {
1358 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001359 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001360 shouldFail: true,
1361 expectedError: ":WRONG_SSL_VERSION:",
1362 },
1363 {
1364 protocol: dtls,
1365 name: "DisableEverything-DTLS",
1366 flags: []string{"-no-tls12", "-no-tls1"},
1367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
Adam Langley7c803a62015-06-15 15:35:05 -07001371 protocol: dtls,
1372 testType: serverTest,
1373 name: "MTU",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 MaxPacketLength: 256,
1377 },
1378 },
1379 flags: []string{"-mtu", "256"},
1380 },
1381 {
1382 protocol: dtls,
1383 testType: serverTest,
1384 name: "MTUExceeded",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 MaxPacketLength: 255,
1388 },
1389 },
1390 flags: []string{"-mtu", "256"},
1391 shouldFail: true,
1392 expectedLocalError: "dtls: exceeded maximum packet length",
1393 },
1394 {
1395 name: "CertMismatchRSA",
1396 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001397 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001398 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001399 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001400 Bugs: ProtocolBugs{
1401 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1402 },
1403 },
1404 shouldFail: true,
1405 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1406 },
1407 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001408 name: "CertMismatchRSA-TLS13",
1409 config: Config{
1410 MaxVersion: VersionTLS13,
1411 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1412 Certificates: []Certificate{ecdsaP256Certificate},
1413 Bugs: ProtocolBugs{
1414 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1419 },
1420 {
Adam Langley7c803a62015-06-15 15:35:05 -07001421 name: "CertMismatchECDSA",
1422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001423 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001425 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001426 Bugs: ProtocolBugs{
1427 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1428 },
1429 },
1430 shouldFail: true,
1431 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1432 },
1433 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001434 name: "CertMismatchECDSA-TLS13",
1435 config: Config{
1436 MaxVersion: VersionTLS13,
1437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1438 Certificates: []Certificate{rsaCertificate},
1439 Bugs: ProtocolBugs{
1440 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1441 },
1442 },
1443 shouldFail: true,
1444 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1445 },
1446 {
Adam Langley7c803a62015-06-15 15:35:05 -07001447 name: "EmptyCertificateList",
1448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001449 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1451 Bugs: ProtocolBugs{
1452 EmptyCertificateList: true,
1453 },
1454 },
1455 shouldFail: true,
1456 expectedError: ":DECODE_ERROR:",
1457 },
1458 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001459 name: "EmptyCertificateList-TLS13",
1460 config: Config{
1461 MaxVersion: VersionTLS13,
1462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1463 Bugs: ProtocolBugs{
1464 EmptyCertificateList: true,
1465 },
1466 },
1467 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001468 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001469 },
1470 {
Adam Langley7c803a62015-06-15 15:35:05 -07001471 name: "TLSFatalBadPackets",
1472 damageFirstWrite: true,
1473 shouldFail: true,
1474 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1475 },
1476 {
1477 protocol: dtls,
1478 name: "DTLSIgnoreBadPackets",
1479 damageFirstWrite: true,
1480 },
1481 {
1482 protocol: dtls,
1483 name: "DTLSIgnoreBadPackets-Async",
1484 damageFirstWrite: true,
1485 flags: []string{"-async"},
1486 },
1487 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001488 name: "AppDataBeforeHandshake",
1489 config: Config{
1490 Bugs: ProtocolBugs{
1491 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":UNEXPECTED_RECORD:",
1496 },
1497 {
1498 name: "AppDataBeforeHandshake-Empty",
1499 config: Config{
1500 Bugs: ProtocolBugs{
1501 AppDataBeforeHandshake: []byte{},
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":UNEXPECTED_RECORD:",
1506 },
1507 {
1508 protocol: dtls,
1509 name: "AppDataBeforeHandshake-DTLS",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 protocol: dtls,
1520 name: "AppDataBeforeHandshake-DTLS-Empty",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 AppDataBeforeHandshake: []byte{},
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
Adam Langley7c803a62015-06-15 15:35:05 -07001530 name: "AppDataAfterChangeCipherSpec",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001538 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001539 },
1540 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001541 name: "AppDataAfterChangeCipherSpec-Empty",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte{},
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001550 },
1551 {
Adam Langley7c803a62015-06-15 15:35:05 -07001552 protocol: dtls,
1553 name: "AppDataAfterChangeCipherSpec-DTLS",
1554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001555 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001556 Bugs: ProtocolBugs{
1557 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1558 },
1559 },
1560 // BoringSSL's DTLS implementation will drop the out-of-order
1561 // application data.
1562 },
1563 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001564 protocol: dtls,
1565 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001568 Bugs: ProtocolBugs{
1569 AppDataAfterChangeCipherSpec: []byte{},
1570 },
1571 },
1572 // BoringSSL's DTLS implementation will drop the out-of-order
1573 // application data.
1574 },
1575 {
Adam Langley7c803a62015-06-15 15:35:05 -07001576 name: "AlertAfterChangeCipherSpec",
1577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001578 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001579 Bugs: ProtocolBugs{
1580 AlertAfterChangeCipherSpec: alertRecordOverflow,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1585 },
1586 {
1587 protocol: dtls,
1588 name: "AlertAfterChangeCipherSpec-DTLS",
1589 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001590 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001591 Bugs: ProtocolBugs{
1592 AlertAfterChangeCipherSpec: alertRecordOverflow,
1593 },
1594 },
1595 shouldFail: true,
1596 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1597 },
1598 {
1599 protocol: dtls,
1600 name: "ReorderHandshakeFragments-Small-DTLS",
1601 config: Config{
1602 Bugs: ProtocolBugs{
1603 ReorderHandshakeFragments: true,
1604 // Small enough that every handshake message is
1605 // fragmented.
1606 MaxHandshakeRecordLength: 2,
1607 },
1608 },
1609 },
1610 {
1611 protocol: dtls,
1612 name: "ReorderHandshakeFragments-Large-DTLS",
1613 config: Config{
1614 Bugs: ProtocolBugs{
1615 ReorderHandshakeFragments: true,
1616 // Large enough that no handshake message is
1617 // fragmented.
1618 MaxHandshakeRecordLength: 2048,
1619 },
1620 },
1621 },
1622 {
1623 protocol: dtls,
1624 name: "MixCompleteMessageWithFragments-DTLS",
1625 config: Config{
1626 Bugs: ProtocolBugs{
1627 ReorderHandshakeFragments: true,
1628 MixCompleteMessageWithFragments: true,
1629 MaxHandshakeRecordLength: 2,
1630 },
1631 },
1632 },
1633 {
1634 name: "SendInvalidRecordType",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SendInvalidRecordType: true,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":UNEXPECTED_RECORD:",
1642 },
1643 {
1644 protocol: dtls,
1645 name: "SendInvalidRecordType-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendInvalidRecordType: true,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":UNEXPECTED_RECORD:",
1653 },
1654 {
1655 name: "FalseStart-SkipServerSecondLeg",
1656 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001657 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001658 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1659 NextProtos: []string{"foo"},
1660 Bugs: ProtocolBugs{
1661 SkipNewSessionTicket: true,
1662 SkipChangeCipherSpec: true,
1663 SkipFinished: true,
1664 ExpectFalseStart: true,
1665 },
1666 },
1667 flags: []string{
1668 "-false-start",
1669 "-handshake-never-done",
1670 "-advertise-alpn", "\x03foo",
1671 },
1672 shimWritesFirst: true,
1673 shouldFail: true,
1674 expectedError: ":UNEXPECTED_RECORD:",
1675 },
1676 {
1677 name: "FalseStart-SkipServerSecondLeg-Implicit",
1678 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001679 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1681 NextProtos: []string{"foo"},
1682 Bugs: ProtocolBugs{
1683 SkipNewSessionTicket: true,
1684 SkipChangeCipherSpec: true,
1685 SkipFinished: true,
1686 },
1687 },
1688 flags: []string{
1689 "-implicit-handshake",
1690 "-false-start",
1691 "-handshake-never-done",
1692 "-advertise-alpn", "\x03foo",
1693 },
1694 shouldFail: true,
1695 expectedError: ":UNEXPECTED_RECORD:",
1696 },
1697 {
1698 testType: serverTest,
1699 name: "FailEarlyCallback",
1700 flags: []string{"-fail-early-callback"},
1701 shouldFail: true,
1702 expectedError: ":CONNECTION_REJECTED:",
1703 expectedLocalError: "remote error: access denied",
1704 },
1705 {
Adam Langley7c803a62015-06-15 15:35:05 -07001706 protocol: dtls,
1707 name: "FragmentMessageTypeMismatch-DTLS",
1708 config: Config{
1709 Bugs: ProtocolBugs{
1710 MaxHandshakeRecordLength: 2,
1711 FragmentMessageTypeMismatch: true,
1712 },
1713 },
1714 shouldFail: true,
1715 expectedError: ":FRAGMENT_MISMATCH:",
1716 },
1717 {
1718 protocol: dtls,
1719 name: "FragmentMessageLengthMismatch-DTLS",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 MaxHandshakeRecordLength: 2,
1723 FragmentMessageLengthMismatch: true,
1724 },
1725 },
1726 shouldFail: true,
1727 expectedError: ":FRAGMENT_MISMATCH:",
1728 },
1729 {
1730 protocol: dtls,
1731 name: "SplitFragments-Header-DTLS",
1732 config: Config{
1733 Bugs: ProtocolBugs{
1734 SplitFragments: 2,
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-Boundary-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: dtlsRecordHeaderLen,
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: "SplitFragments-Body-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SplitFragments: dtlsRecordHeaderLen + 1,
1757 },
1758 },
1759 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001760 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 protocol: dtls,
1764 name: "SendEmptyFragments-DTLS",
1765 config: Config{
1766 Bugs: ProtocolBugs{
1767 SendEmptyFragments: true,
1768 },
1769 },
1770 },
1771 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001772 name: "BadFinished-Client",
1773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001783 name: "BadFinished-Client-TLS13",
1784 config: Config{
1785 MaxVersion: VersionTLS13,
1786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001794 testType: serverTest,
1795 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001797 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001798 Bugs: ProtocolBugs{
1799 BadFinished: true,
1800 },
1801 },
1802 shouldFail: true,
1803 expectedError: ":DIGEST_CHECK_FAILED:",
1804 },
1805 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001806 testType: serverTest,
1807 name: "BadFinished-Server-TLS13",
1808 config: Config{
1809 MaxVersion: VersionTLS13,
1810 Bugs: ProtocolBugs{
1811 BadFinished: true,
1812 },
1813 },
1814 shouldFail: true,
1815 expectedError: ":DIGEST_CHECK_FAILED:",
1816 },
1817 {
Adam Langley7c803a62015-06-15 15:35:05 -07001818 name: "FalseStart-BadFinished",
1819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001820 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1822 NextProtos: []string{"foo"},
1823 Bugs: ProtocolBugs{
1824 BadFinished: true,
1825 ExpectFalseStart: true,
1826 },
1827 },
1828 flags: []string{
1829 "-false-start",
1830 "-handshake-never-done",
1831 "-advertise-alpn", "\x03foo",
1832 },
1833 shimWritesFirst: true,
1834 shouldFail: true,
1835 expectedError: ":DIGEST_CHECK_FAILED:",
1836 },
1837 {
1838 name: "NoFalseStart-NoALPN",
1839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001840 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001841 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1842 Bugs: ProtocolBugs{
1843 ExpectFalseStart: true,
1844 AlertBeforeFalseStartTest: alertAccessDenied,
1845 },
1846 },
1847 flags: []string{
1848 "-false-start",
1849 },
1850 shimWritesFirst: true,
1851 shouldFail: true,
1852 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1853 expectedLocalError: "tls: peer did not false start: EOF",
1854 },
1855 {
1856 name: "NoFalseStart-NoAEAD",
1857 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001858 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001859 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1860 NextProtos: []string{"foo"},
1861 Bugs: ProtocolBugs{
1862 ExpectFalseStart: true,
1863 AlertBeforeFalseStartTest: alertAccessDenied,
1864 },
1865 },
1866 flags: []string{
1867 "-false-start",
1868 "-advertise-alpn", "\x03foo",
1869 },
1870 shimWritesFirst: true,
1871 shouldFail: true,
1872 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1873 expectedLocalError: "tls: peer did not false start: EOF",
1874 },
1875 {
1876 name: "NoFalseStart-RSA",
1877 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001878 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001879 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1880 NextProtos: []string{"foo"},
1881 Bugs: ProtocolBugs{
1882 ExpectFalseStart: true,
1883 AlertBeforeFalseStartTest: alertAccessDenied,
1884 },
1885 },
1886 flags: []string{
1887 "-false-start",
1888 "-advertise-alpn", "\x03foo",
1889 },
1890 shimWritesFirst: true,
1891 shouldFail: true,
1892 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1893 expectedLocalError: "tls: peer did not false start: EOF",
1894 },
1895 {
1896 name: "NoFalseStart-DHE_RSA",
1897 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001898 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001899 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1900 NextProtos: []string{"foo"},
1901 Bugs: ProtocolBugs{
1902 ExpectFalseStart: true,
1903 AlertBeforeFalseStartTest: alertAccessDenied,
1904 },
1905 },
1906 flags: []string{
1907 "-false-start",
1908 "-advertise-alpn", "\x03foo",
1909 },
1910 shimWritesFirst: true,
1911 shouldFail: true,
1912 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1913 expectedLocalError: "tls: peer did not false start: EOF",
1914 },
1915 {
Adam Langley7c803a62015-06-15 15:35:05 -07001916 protocol: dtls,
1917 name: "SendSplitAlert-Sync",
1918 config: Config{
1919 Bugs: ProtocolBugs{
1920 SendSplitAlert: true,
1921 },
1922 },
1923 },
1924 {
1925 protocol: dtls,
1926 name: "SendSplitAlert-Async",
1927 config: Config{
1928 Bugs: ProtocolBugs{
1929 SendSplitAlert: true,
1930 },
1931 },
1932 flags: []string{"-async"},
1933 },
1934 {
1935 protocol: dtls,
1936 name: "PackDTLSHandshake",
1937 config: Config{
1938 Bugs: ProtocolBugs{
1939 MaxHandshakeRecordLength: 2,
1940 PackHandshakeFragments: 20,
1941 PackHandshakeRecords: 200,
1942 },
1943 },
1944 },
1945 {
Adam Langley7c803a62015-06-15 15:35:05 -07001946 name: "SendEmptyRecords-Pass",
1947 sendEmptyRecords: 32,
1948 },
1949 {
1950 name: "SendEmptyRecords",
1951 sendEmptyRecords: 33,
1952 shouldFail: true,
1953 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1954 },
1955 {
1956 name: "SendEmptyRecords-Async",
1957 sendEmptyRecords: 33,
1958 flags: []string{"-async"},
1959 shouldFail: true,
1960 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1961 },
1962 {
David Benjamine8e84b92016-08-03 15:39:47 -04001963 name: "SendWarningAlerts-Pass",
1964 config: Config{
1965 MaxVersion: VersionTLS12,
1966 },
Adam Langley7c803a62015-06-15 15:35:05 -07001967 sendWarningAlerts: 4,
1968 },
1969 {
David Benjamine8e84b92016-08-03 15:39:47 -04001970 protocol: dtls,
1971 name: "SendWarningAlerts-DTLS-Pass",
1972 config: Config{
1973 MaxVersion: VersionTLS12,
1974 },
Adam Langley7c803a62015-06-15 15:35:05 -07001975 sendWarningAlerts: 4,
1976 },
1977 {
David Benjamine8e84b92016-08-03 15:39:47 -04001978 name: "SendWarningAlerts-TLS13",
1979 config: Config{
1980 MaxVersion: VersionTLS13,
1981 },
1982 sendWarningAlerts: 4,
1983 shouldFail: true,
1984 expectedError: ":BAD_ALERT:",
1985 expectedLocalError: "remote error: error decoding message",
1986 },
1987 {
1988 name: "SendWarningAlerts",
1989 config: Config{
1990 MaxVersion: VersionTLS12,
1991 },
Adam Langley7c803a62015-06-15 15:35:05 -07001992 sendWarningAlerts: 5,
1993 shouldFail: true,
1994 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1995 },
1996 {
David Benjamine8e84b92016-08-03 15:39:47 -04001997 name: "SendWarningAlerts-Async",
1998 config: Config{
1999 MaxVersion: VersionTLS12,
2000 },
Adam Langley7c803a62015-06-15 15:35:05 -07002001 sendWarningAlerts: 5,
2002 flags: []string{"-async"},
2003 shouldFail: true,
2004 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2005 },
David Benjaminba4594a2015-06-18 18:36:15 -04002006 {
Steven Valdez32635b82016-08-16 11:25:03 -04002007 name: "SendKeyUpdates",
2008 config: Config{
2009 MaxVersion: VersionTLS13,
2010 },
2011 sendKeyUpdates: 33,
2012 shouldFail: true,
2013 expectedError: ":TOO_MANY_KEY_UPDATES:",
2014 },
2015 {
David Benjaminba4594a2015-06-18 18:36:15 -04002016 name: "EmptySessionID",
2017 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002018 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002019 SessionTicketsDisabled: true,
2020 },
2021 noSessionCache: true,
2022 flags: []string{"-expect-no-session"},
2023 },
David Benjamin30789da2015-08-29 22:56:45 -04002024 {
2025 name: "Unclean-Shutdown",
2026 config: Config{
2027 Bugs: ProtocolBugs{
2028 NoCloseNotify: true,
2029 ExpectCloseNotify: true,
2030 },
2031 },
2032 shimShutsDown: true,
2033 flags: []string{"-check-close-notify"},
2034 shouldFail: true,
2035 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2036 },
2037 {
2038 name: "Unclean-Shutdown-Ignored",
2039 config: Config{
2040 Bugs: ProtocolBugs{
2041 NoCloseNotify: true,
2042 },
2043 },
2044 shimShutsDown: true,
2045 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002046 {
David Benjaminfa214e42016-05-10 17:03:10 -04002047 name: "Unclean-Shutdown-Alert",
2048 config: Config{
2049 Bugs: ProtocolBugs{
2050 SendAlertOnShutdown: alertDecompressionFailure,
2051 ExpectCloseNotify: true,
2052 },
2053 },
2054 shimShutsDown: true,
2055 flags: []string{"-check-close-notify"},
2056 shouldFail: true,
2057 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2058 },
2059 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 name: "LargePlaintext",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 SendLargeRecords: true,
2064 },
2065 },
2066 messageLen: maxPlaintext + 1,
2067 shouldFail: true,
2068 expectedError: ":DATA_LENGTH_TOO_LONG:",
2069 },
2070 {
2071 protocol: dtls,
2072 name: "LargePlaintext-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SendLargeRecords: true,
2076 },
2077 },
2078 messageLen: maxPlaintext + 1,
2079 shouldFail: true,
2080 expectedError: ":DATA_LENGTH_TOO_LONG:",
2081 },
2082 {
2083 name: "LargeCiphertext",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SendLargeRecords: true,
2087 },
2088 },
2089 messageLen: maxPlaintext * 2,
2090 shouldFail: true,
2091 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2092 },
2093 {
2094 protocol: dtls,
2095 name: "LargeCiphertext-DTLS",
2096 config: Config{
2097 Bugs: ProtocolBugs{
2098 SendLargeRecords: true,
2099 },
2100 },
2101 messageLen: maxPlaintext * 2,
2102 // Unlike the other four cases, DTLS drops records which
2103 // are invalid before authentication, so the connection
2104 // does not fail.
2105 expectMessageDropped: true,
2106 },
David Benjamindd6fed92015-10-23 17:41:12 -04002107 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002108 // In TLS 1.2 and below, empty NewSessionTicket messages
2109 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002110 name: "SendEmptySessionTicket",
2111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002112 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002113 Bugs: ProtocolBugs{
2114 SendEmptySessionTicket: true,
2115 FailIfSessionOffered: true,
2116 },
2117 },
2118 flags: []string{"-expect-no-session"},
2119 resumeSession: true,
2120 expectResumeRejected: true,
2121 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002122 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002123 name: "BadHelloRequest-1",
2124 renegotiate: 1,
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002127 Bugs: ProtocolBugs{
2128 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2129 },
2130 },
2131 flags: []string{
2132 "-renegotiate-freely",
2133 "-expect-total-renegotiations", "1",
2134 },
2135 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002136 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002137 },
2138 {
2139 name: "BadHelloRequest-2",
2140 renegotiate: 1,
2141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002142 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002143 Bugs: ProtocolBugs{
2144 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2145 },
2146 },
2147 flags: []string{
2148 "-renegotiate-freely",
2149 "-expect-total-renegotiations", "1",
2150 },
2151 shouldFail: true,
2152 expectedError: ":BAD_HELLO_REQUEST:",
2153 },
David Benjaminef1b0092015-11-21 14:05:44 -05002154 {
2155 testType: serverTest,
2156 name: "SupportTicketsWithSessionID",
2157 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002158 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002159 SessionTicketsDisabled: true,
2160 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002161 resumeConfig: &Config{
2162 MaxVersion: VersionTLS12,
2163 },
David Benjaminef1b0092015-11-21 14:05:44 -05002164 resumeSession: true,
2165 },
David Benjamin02edcd02016-07-27 17:40:37 -04002166 {
2167 protocol: dtls,
2168 name: "DTLS-SendExtraFinished",
2169 config: Config{
2170 Bugs: ProtocolBugs{
2171 SendExtraFinished: true,
2172 },
2173 },
2174 shouldFail: true,
2175 expectedError: ":UNEXPECTED_RECORD:",
2176 },
2177 {
2178 protocol: dtls,
2179 name: "DTLS-SendExtraFinished-Reordered",
2180 config: Config{
2181 Bugs: ProtocolBugs{
2182 MaxHandshakeRecordLength: 2,
2183 ReorderHandshakeFragments: true,
2184 SendExtraFinished: true,
2185 },
2186 },
2187 shouldFail: true,
2188 expectedError: ":UNEXPECTED_RECORD:",
2189 },
David Benjamine97fb482016-07-29 09:23:07 -04002190 {
2191 testType: serverTest,
2192 name: "V2ClientHello-EmptyRecordPrefix",
2193 config: Config{
2194 // Choose a cipher suite that does not involve
2195 // elliptic curves, so no extensions are
2196 // involved.
2197 MaxVersion: VersionTLS12,
2198 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2199 Bugs: ProtocolBugs{
2200 SendV2ClientHello: true,
2201 },
2202 },
2203 sendPrefix: string([]byte{
2204 byte(recordTypeHandshake),
2205 3, 1, // version
2206 0, 0, // length
2207 }),
2208 // A no-op empty record may not be sent before V2ClientHello.
2209 shouldFail: true,
2210 expectedError: ":WRONG_VERSION_NUMBER:",
2211 },
2212 {
2213 testType: serverTest,
2214 name: "V2ClientHello-WarningAlertPrefix",
2215 config: Config{
2216 // Choose a cipher suite that does not involve
2217 // elliptic curves, so no extensions are
2218 // involved.
2219 MaxVersion: VersionTLS12,
2220 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2221 Bugs: ProtocolBugs{
2222 SendV2ClientHello: true,
2223 },
2224 },
2225 sendPrefix: string([]byte{
2226 byte(recordTypeAlert),
2227 3, 1, // version
2228 0, 2, // length
2229 alertLevelWarning, byte(alertDecompressionFailure),
2230 }),
2231 // A no-op warning alert may not be sent before V2ClientHello.
2232 shouldFail: true,
2233 expectedError: ":WRONG_VERSION_NUMBER:",
2234 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002235 {
2236 testType: clientTest,
2237 name: "KeyUpdate",
2238 config: Config{
2239 MaxVersion: VersionTLS13,
2240 Bugs: ProtocolBugs{
2241 SendKeyUpdateBeforeEveryAppDataRecord: true,
2242 },
2243 },
2244 },
Adam Langley7c803a62015-06-15 15:35:05 -07002245 }
Adam Langley7c803a62015-06-15 15:35:05 -07002246 testCases = append(testCases, basicTests...)
2247}
2248
Adam Langley95c29f32014-06-20 12:00:00 -07002249func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002250 const bogusCipher = 0xfe00
2251
Adam Langley95c29f32014-06-20 12:00:00 -07002252 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002253 const psk = "12345"
2254 const pskIdentity = "luggage combo"
2255
Adam Langley95c29f32014-06-20 12:00:00 -07002256 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002257 var certFile string
2258 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002259 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002260 cert = ecdsaP256Certificate
2261 certFile = ecdsaP256CertificateFile
2262 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002263 } else {
David Benjamin33863262016-07-08 17:20:12 -07002264 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002265 certFile = rsaCertificateFile
2266 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002267 }
2268
David Benjamin48cae082014-10-27 01:06:24 -04002269 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002270 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002271 flags = append(flags,
2272 "-psk", psk,
2273 "-psk-identity", pskIdentity)
2274 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002275 if hasComponent(suite.name, "NULL") {
2276 // NULL ciphers must be explicitly enabled.
2277 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2278 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002279 if hasComponent(suite.name, "CECPQ1") {
2280 // CECPQ1 ciphers must be explicitly enabled.
2281 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2282 }
David Benjamin881f1962016-08-10 18:29:12 -04002283 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2284 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2285 // for now.
2286 flags = append(flags, "-cipher", suite.name)
2287 }
David Benjamin48cae082014-10-27 01:06:24 -04002288
Adam Langley95c29f32014-06-20 12:00:00 -07002289 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002290 for _, protocol := range []protocol{tls, dtls} {
2291 var prefix string
2292 if protocol == dtls {
2293 if !ver.hasDTLS {
2294 continue
2295 }
2296 prefix = "D"
2297 }
Adam Langley95c29f32014-06-20 12:00:00 -07002298
David Benjamin0407e762016-06-17 16:41:18 -04002299 var shouldServerFail, shouldClientFail bool
2300 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2301 // BoringSSL clients accept ECDHE on SSLv3, but
2302 // a BoringSSL server will never select it
2303 // because the extension is missing.
2304 shouldServerFail = true
2305 }
2306 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2307 shouldClientFail = true
2308 shouldServerFail = true
2309 }
David Benjamin54c217c2016-07-13 12:35:25 -04002310 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002311 shouldClientFail = true
2312 shouldServerFail = true
2313 }
David Benjamin0407e762016-06-17 16:41:18 -04002314 if !isDTLSCipher(suite.name) && protocol == dtls {
2315 shouldClientFail = true
2316 shouldServerFail = true
2317 }
David Benjamin4298d772015-12-19 00:18:25 -05002318
David Benjamin0407e762016-06-17 16:41:18 -04002319 var expectedServerError, expectedClientError string
2320 if shouldServerFail {
2321 expectedServerError = ":NO_SHARED_CIPHER:"
2322 }
2323 if shouldClientFail {
2324 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2325 }
David Benjamin025b3d32014-07-01 19:53:04 -04002326
David Benjamin6fd297b2014-08-11 18:43:38 -04002327 testCases = append(testCases, testCase{
2328 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002329 protocol: protocol,
2330
2331 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002332 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002333 MinVersion: ver.version,
2334 MaxVersion: ver.version,
2335 CipherSuites: []uint16{suite.id},
2336 Certificates: []Certificate{cert},
2337 PreSharedKey: []byte(psk),
2338 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002339 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002340 EnableAllCiphers: shouldServerFail,
2341 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002342 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002343 },
2344 certFile: certFile,
2345 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002346 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002347 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002348 shouldFail: shouldServerFail,
2349 expectedError: expectedServerError,
2350 })
2351
2352 testCases = append(testCases, testCase{
2353 testType: clientTest,
2354 protocol: protocol,
2355 name: prefix + ver.name + "-" + suite.name + "-client",
2356 config: Config{
2357 MinVersion: ver.version,
2358 MaxVersion: ver.version,
2359 CipherSuites: []uint16{suite.id},
2360 Certificates: []Certificate{cert},
2361 PreSharedKey: []byte(psk),
2362 PreSharedKeyIdentity: pskIdentity,
2363 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002364 EnableAllCiphers: shouldClientFail,
2365 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002366 },
2367 },
2368 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002369 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002370 shouldFail: shouldClientFail,
2371 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002372 })
David Benjamin2c99d282015-09-01 10:23:00 -04002373
Nick Harper1fd39d82016-06-14 18:14:35 -07002374 if !shouldClientFail {
2375 // Ensure the maximum record size is accepted.
2376 testCases = append(testCases, testCase{
2377 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2378 config: Config{
2379 MinVersion: ver.version,
2380 MaxVersion: ver.version,
2381 CipherSuites: []uint16{suite.id},
2382 Certificates: []Certificate{cert},
2383 PreSharedKey: []byte(psk),
2384 PreSharedKeyIdentity: pskIdentity,
2385 },
2386 flags: flags,
2387 messageLen: maxPlaintext,
2388 })
2389 }
2390 }
David Benjamin2c99d282015-09-01 10:23:00 -04002391 }
Adam Langley95c29f32014-06-20 12:00:00 -07002392 }
Adam Langleya7997f12015-05-14 17:38:50 -07002393
2394 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002395 name: "NoSharedCipher",
2396 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002397 MaxVersion: VersionTLS12,
2398 CipherSuites: []uint16{},
2399 },
2400 shouldFail: true,
2401 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2402 })
2403
2404 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002405 name: "NoSharedCipher-TLS13",
2406 config: Config{
2407 MaxVersion: VersionTLS13,
2408 CipherSuites: []uint16{},
2409 },
2410 shouldFail: true,
2411 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2412 })
2413
2414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002415 name: "UnsupportedCipherSuite",
2416 config: Config{
2417 MaxVersion: VersionTLS12,
2418 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2419 Bugs: ProtocolBugs{
2420 IgnorePeerCipherPreferences: true,
2421 },
2422 },
2423 flags: []string{"-cipher", "DEFAULT:!RC4"},
2424 shouldFail: true,
2425 expectedError: ":WRONG_CIPHER_RETURNED:",
2426 })
2427
2428 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002429 name: "ServerHelloBogusCipher",
2430 config: Config{
2431 MaxVersion: VersionTLS12,
2432 Bugs: ProtocolBugs{
2433 SendCipherSuite: bogusCipher,
2434 },
2435 },
2436 shouldFail: true,
2437 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2438 })
2439 testCases = append(testCases, testCase{
2440 name: "ServerHelloBogusCipher-TLS13",
2441 config: Config{
2442 MaxVersion: VersionTLS13,
2443 Bugs: ProtocolBugs{
2444 SendCipherSuite: bogusCipher,
2445 },
2446 },
2447 shouldFail: true,
2448 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2449 })
2450
2451 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002452 name: "WeakDH",
2453 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002454 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002455 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2456 Bugs: ProtocolBugs{
2457 // This is a 1023-bit prime number, generated
2458 // with:
2459 // openssl gendh 1023 | openssl asn1parse -i
2460 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2461 },
2462 },
2463 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002464 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002465 })
Adam Langleycef75832015-09-03 14:51:12 -07002466
David Benjamincd24a392015-11-11 13:23:05 -08002467 testCases = append(testCases, testCase{
2468 name: "SillyDH",
2469 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002470 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002471 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2472 Bugs: ProtocolBugs{
2473 // This is a 4097-bit prime number, generated
2474 // with:
2475 // openssl gendh 4097 | openssl asn1parse -i
2476 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2477 },
2478 },
2479 shouldFail: true,
2480 expectedError: ":DH_P_TOO_LONG:",
2481 })
2482
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002483 // This test ensures that Diffie-Hellman public values are padded with
2484 // zeros so that they're the same length as the prime. This is to avoid
2485 // hitting a bug in yaSSL.
2486 testCases = append(testCases, testCase{
2487 testType: serverTest,
2488 name: "DHPublicValuePadded",
2489 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002490 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002491 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2492 Bugs: ProtocolBugs{
2493 RequireDHPublicValueLen: (1025 + 7) / 8,
2494 },
2495 },
2496 flags: []string{"-use-sparse-dh-prime"},
2497 })
David Benjamincd24a392015-11-11 13:23:05 -08002498
David Benjamin241ae832016-01-15 03:04:54 -05002499 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002500 testCases = append(testCases, testCase{
2501 testType: serverTest,
2502 name: "UnknownCipher",
2503 config: Config{
2504 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2505 },
2506 })
2507
Adam Langleycef75832015-09-03 14:51:12 -07002508 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2509 // 1.1 specific cipher suite settings. A server is setup with the given
2510 // cipher lists and then a connection is made for each member of
2511 // expectations. The cipher suite that the server selects must match
2512 // the specified one.
2513 var versionSpecificCiphersTest = []struct {
2514 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2515 // expectations is a map from TLS version to cipher suite id.
2516 expectations map[uint16]uint16
2517 }{
2518 {
2519 // Test that the null case (where no version-specific ciphers are set)
2520 // works as expected.
2521 "RC4-SHA:AES128-SHA", // default ciphers
2522 "", // no ciphers specifically for TLS ≥ 1.0
2523 "", // no ciphers specifically for TLS ≥ 1.1
2524 map[uint16]uint16{
2525 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2526 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2527 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2528 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2529 },
2530 },
2531 {
2532 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2533 // cipher.
2534 "RC4-SHA:AES128-SHA", // default
2535 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2536 "", // no ciphers specifically for TLS ≥ 1.1
2537 map[uint16]uint16{
2538 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2539 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2540 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2541 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2542 },
2543 },
2544 {
2545 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2546 // cipher.
2547 "RC4-SHA:AES128-SHA", // default
2548 "", // no ciphers specifically for TLS ≥ 1.0
2549 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2550 map[uint16]uint16{
2551 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2552 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2553 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2554 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2555 },
2556 },
2557 {
2558 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2559 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2560 "RC4-SHA:AES128-SHA", // default
2561 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2562 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2563 map[uint16]uint16{
2564 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2565 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2566 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2567 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2568 },
2569 },
2570 }
2571
2572 for i, test := range versionSpecificCiphersTest {
2573 for version, expectedCipherSuite := range test.expectations {
2574 flags := []string{"-cipher", test.ciphersDefault}
2575 if len(test.ciphersTLS10) > 0 {
2576 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2577 }
2578 if len(test.ciphersTLS11) > 0 {
2579 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2580 }
2581
2582 testCases = append(testCases, testCase{
2583 testType: serverTest,
2584 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2585 config: Config{
2586 MaxVersion: version,
2587 MinVersion: version,
2588 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2589 },
2590 flags: flags,
2591 expectedCipher: expectedCipherSuite,
2592 })
2593 }
2594 }
Adam Langley95c29f32014-06-20 12:00:00 -07002595}
2596
2597func addBadECDSASignatureTests() {
2598 for badR := BadValue(1); badR < NumBadValues; badR++ {
2599 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002600 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002601 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2602 config: Config{
2603 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002604 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002605 Bugs: ProtocolBugs{
2606 BadECDSAR: badR,
2607 BadECDSAS: badS,
2608 },
2609 },
2610 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002611 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002612 })
2613 }
2614 }
2615}
2616
Adam Langley80842bd2014-06-20 12:00:00 -07002617func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002618 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002619 name: "MaxCBCPadding",
2620 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002621 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002622 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2623 Bugs: ProtocolBugs{
2624 MaxPadding: true,
2625 },
2626 },
2627 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2628 })
David Benjamin025b3d32014-07-01 19:53:04 -04002629 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002630 name: "BadCBCPadding",
2631 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002632 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002633 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2634 Bugs: ProtocolBugs{
2635 PaddingFirstByteBad: true,
2636 },
2637 },
2638 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002639 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002640 })
2641 // OpenSSL previously had an issue where the first byte of padding in
2642 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002643 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002644 name: "BadCBCPadding255",
2645 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002646 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002647 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2648 Bugs: ProtocolBugs{
2649 MaxPadding: true,
2650 PaddingFirstByteBadIf255: true,
2651 },
2652 },
2653 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2654 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002655 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002656 })
2657}
2658
Kenny Root7fdeaf12014-08-05 15:23:37 -07002659func addCBCSplittingTests() {
2660 testCases = append(testCases, testCase{
2661 name: "CBCRecordSplitting",
2662 config: Config{
2663 MaxVersion: VersionTLS10,
2664 MinVersion: VersionTLS10,
2665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2666 },
David Benjaminac8302a2015-09-01 17:18:15 -04002667 messageLen: -1, // read until EOF
2668 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002669 flags: []string{
2670 "-async",
2671 "-write-different-record-sizes",
2672 "-cbc-record-splitting",
2673 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002674 })
2675 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002676 name: "CBCRecordSplittingPartialWrite",
2677 config: Config{
2678 MaxVersion: VersionTLS10,
2679 MinVersion: VersionTLS10,
2680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2681 },
2682 messageLen: -1, // read until EOF
2683 flags: []string{
2684 "-async",
2685 "-write-different-record-sizes",
2686 "-cbc-record-splitting",
2687 "-partial-write",
2688 },
2689 })
2690}
2691
David Benjamin636293b2014-07-08 17:59:18 -04002692func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002693 // Add a dummy cert pool to stress certificate authority parsing.
2694 // TODO(davidben): Add tests that those values parse out correctly.
2695 certPool := x509.NewCertPool()
2696 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2697 if err != nil {
2698 panic(err)
2699 }
2700 certPool.AddCert(cert)
2701
David Benjamin636293b2014-07-08 17:59:18 -04002702 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002703 testCases = append(testCases, testCase{
2704 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002705 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002706 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002707 MinVersion: ver.version,
2708 MaxVersion: ver.version,
2709 ClientAuth: RequireAnyClientCert,
2710 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002711 },
2712 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002713 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2714 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002715 },
2716 })
2717 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002718 testType: serverTest,
2719 name: ver.name + "-Server-ClientAuth-RSA",
2720 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002721 MinVersion: ver.version,
2722 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002723 Certificates: []Certificate{rsaCertificate},
2724 },
2725 flags: []string{"-require-any-client-certificate"},
2726 })
David Benjamine098ec22014-08-27 23:13:20 -04002727 if ver.version != VersionSSL30 {
2728 testCases = append(testCases, testCase{
2729 testType: serverTest,
2730 name: ver.name + "-Server-ClientAuth-ECDSA",
2731 config: Config{
2732 MinVersion: ver.version,
2733 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002734 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002735 },
2736 flags: []string{"-require-any-client-certificate"},
2737 })
2738 testCases = append(testCases, testCase{
2739 testType: clientTest,
2740 name: ver.name + "-Client-ClientAuth-ECDSA",
2741 config: Config{
2742 MinVersion: ver.version,
2743 MaxVersion: ver.version,
2744 ClientAuth: RequireAnyClientCert,
2745 ClientCAs: certPool,
2746 },
2747 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002748 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2749 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002750 },
2751 })
2752 }
Adam Langley37646832016-08-01 16:16:46 -07002753
2754 testCases = append(testCases, testCase{
2755 name: "NoClientCertificate-" + ver.name,
2756 config: Config{
2757 MinVersion: ver.version,
2758 MaxVersion: ver.version,
2759 ClientAuth: RequireAnyClientCert,
2760 },
2761 shouldFail: true,
2762 expectedLocalError: "client didn't provide a certificate",
2763 })
2764
2765 testCases = append(testCases, testCase{
2766 // Even if not configured to expect a certificate, OpenSSL will
2767 // return X509_V_OK as the verify_result.
2768 testType: serverTest,
2769 name: "NoClientCertificateRequested-Server-" + ver.name,
2770 config: Config{
2771 MinVersion: ver.version,
2772 MaxVersion: ver.version,
2773 },
2774 flags: []string{
2775 "-expect-verify-result",
2776 },
2777 // TODO(davidben): Switch this to true when TLS 1.3
2778 // supports session resumption.
2779 resumeSession: ver.version < VersionTLS13,
2780 })
2781
2782 testCases = append(testCases, testCase{
2783 // If a client certificate is not provided, OpenSSL will still
2784 // return X509_V_OK as the verify_result.
2785 testType: serverTest,
2786 name: "NoClientCertificate-Server-" + ver.name,
2787 config: Config{
2788 MinVersion: ver.version,
2789 MaxVersion: ver.version,
2790 },
2791 flags: []string{
2792 "-expect-verify-result",
2793 "-verify-peer",
2794 },
2795 // TODO(davidben): Switch this to true when TLS 1.3
2796 // supports session resumption.
2797 resumeSession: ver.version < VersionTLS13,
2798 })
2799
2800 testCases = append(testCases, testCase{
2801 testType: serverTest,
2802 name: "RequireAnyClientCertificate-" + ver.name,
2803 config: Config{
2804 MinVersion: ver.version,
2805 MaxVersion: ver.version,
2806 },
2807 flags: []string{"-require-any-client-certificate"},
2808 shouldFail: true,
2809 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2810 })
2811
2812 if ver.version != VersionSSL30 {
2813 testCases = append(testCases, testCase{
2814 testType: serverTest,
2815 name: "SkipClientCertificate-" + ver.name,
2816 config: Config{
2817 MinVersion: ver.version,
2818 MaxVersion: ver.version,
2819 Bugs: ProtocolBugs{
2820 SkipClientCertificate: true,
2821 },
2822 },
2823 // Setting SSL_VERIFY_PEER allows anonymous clients.
2824 flags: []string{"-verify-peer"},
2825 shouldFail: true,
2826 expectedError: ":UNEXPECTED_MESSAGE:",
2827 })
2828 }
David Benjamin636293b2014-07-08 17:59:18 -04002829 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002830
David Benjaminc032dfa2016-05-12 14:54:57 -04002831 // Client auth is only legal in certificate-based ciphers.
2832 testCases = append(testCases, testCase{
2833 testType: clientTest,
2834 name: "ClientAuth-PSK",
2835 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002836 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002837 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2838 PreSharedKey: []byte("secret"),
2839 ClientAuth: RequireAnyClientCert,
2840 },
2841 flags: []string{
2842 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2843 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2844 "-psk", "secret",
2845 },
2846 shouldFail: true,
2847 expectedError: ":UNEXPECTED_MESSAGE:",
2848 })
2849 testCases = append(testCases, testCase{
2850 testType: clientTest,
2851 name: "ClientAuth-ECDHE_PSK",
2852 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002853 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002854 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2855 PreSharedKey: []byte("secret"),
2856 ClientAuth: RequireAnyClientCert,
2857 },
2858 flags: []string{
2859 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2860 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2861 "-psk", "secret",
2862 },
2863 shouldFail: true,
2864 expectedError: ":UNEXPECTED_MESSAGE:",
2865 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002866
2867 // Regression test for a bug where the client CA list, if explicitly
2868 // set to NULL, was mis-encoded.
2869 testCases = append(testCases, testCase{
2870 testType: serverTest,
2871 name: "Null-Client-CA-List",
2872 config: Config{
2873 MaxVersion: VersionTLS12,
2874 Certificates: []Certificate{rsaCertificate},
2875 },
2876 flags: []string{
2877 "-require-any-client-certificate",
2878 "-use-null-client-ca-list",
2879 },
2880 })
David Benjamin636293b2014-07-08 17:59:18 -04002881}
2882
Adam Langley75712922014-10-10 16:23:43 -07002883func addExtendedMasterSecretTests() {
2884 const expectEMSFlag = "-expect-extended-master-secret"
2885
2886 for _, with := range []bool{false, true} {
2887 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002888 if with {
2889 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002890 }
2891
2892 for _, isClient := range []bool{false, true} {
2893 suffix := "-Server"
2894 testType := serverTest
2895 if isClient {
2896 suffix = "-Client"
2897 testType = clientTest
2898 }
2899
2900 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002901 // In TLS 1.3, the extension is irrelevant and
2902 // always reports as enabled.
2903 var flags []string
2904 if with || ver.version >= VersionTLS13 {
2905 flags = []string{expectEMSFlag}
2906 }
2907
Adam Langley75712922014-10-10 16:23:43 -07002908 test := testCase{
2909 testType: testType,
2910 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2911 config: Config{
2912 MinVersion: ver.version,
2913 MaxVersion: ver.version,
2914 Bugs: ProtocolBugs{
2915 NoExtendedMasterSecret: !with,
2916 RequireExtendedMasterSecret: with,
2917 },
2918 },
David Benjamin48cae082014-10-27 01:06:24 -04002919 flags: flags,
2920 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002921 }
2922 if test.shouldFail {
2923 test.expectedLocalError = "extended master secret required but not supported by peer"
2924 }
2925 testCases = append(testCases, test)
2926 }
2927 }
2928 }
2929
Adam Langleyba5934b2015-06-02 10:50:35 -07002930 for _, isClient := range []bool{false, true} {
2931 for _, supportedInFirstConnection := range []bool{false, true} {
2932 for _, supportedInResumeConnection := range []bool{false, true} {
2933 boolToWord := func(b bool) string {
2934 if b {
2935 return "Yes"
2936 }
2937 return "No"
2938 }
2939 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2940 if isClient {
2941 suffix += "Client"
2942 } else {
2943 suffix += "Server"
2944 }
2945
2946 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002947 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002948 Bugs: ProtocolBugs{
2949 RequireExtendedMasterSecret: true,
2950 },
2951 }
2952
2953 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002954 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002955 Bugs: ProtocolBugs{
2956 NoExtendedMasterSecret: true,
2957 },
2958 }
2959
2960 test := testCase{
2961 name: "ExtendedMasterSecret-" + suffix,
2962 resumeSession: true,
2963 }
2964
2965 if !isClient {
2966 test.testType = serverTest
2967 }
2968
2969 if supportedInFirstConnection {
2970 test.config = supportedConfig
2971 } else {
2972 test.config = noSupportConfig
2973 }
2974
2975 if supportedInResumeConnection {
2976 test.resumeConfig = &supportedConfig
2977 } else {
2978 test.resumeConfig = &noSupportConfig
2979 }
2980
2981 switch suffix {
2982 case "YesToYes-Client", "YesToYes-Server":
2983 // When a session is resumed, it should
2984 // still be aware that its master
2985 // secret was generated via EMS and
2986 // thus it's safe to use tls-unique.
2987 test.flags = []string{expectEMSFlag}
2988 case "NoToYes-Server":
2989 // If an original connection did not
2990 // contain EMS, but a resumption
2991 // handshake does, then a server should
2992 // not resume the session.
2993 test.expectResumeRejected = true
2994 case "YesToNo-Server":
2995 // Resuming an EMS session without the
2996 // EMS extension should cause the
2997 // server to abort the connection.
2998 test.shouldFail = true
2999 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3000 case "NoToYes-Client":
3001 // A client should abort a connection
3002 // where the server resumed a non-EMS
3003 // session but echoed the EMS
3004 // extension.
3005 test.shouldFail = true
3006 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3007 case "YesToNo-Client":
3008 // A client should abort a connection
3009 // where the server didn't echo EMS
3010 // when the session used it.
3011 test.shouldFail = true
3012 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3013 }
3014
3015 testCases = append(testCases, test)
3016 }
3017 }
3018 }
Adam Langley75712922014-10-10 16:23:43 -07003019}
3020
David Benjamin582ba042016-07-07 12:33:25 -07003021type stateMachineTestConfig struct {
3022 protocol protocol
3023 async bool
3024 splitHandshake, packHandshakeFlight bool
3025}
3026
David Benjamin43ec06f2014-08-05 02:28:57 -04003027// Adds tests that try to cover the range of the handshake state machine, under
3028// various conditions. Some of these are redundant with other tests, but they
3029// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003030func addAllStateMachineCoverageTests() {
3031 for _, async := range []bool{false, true} {
3032 for _, protocol := range []protocol{tls, dtls} {
3033 addStateMachineCoverageTests(stateMachineTestConfig{
3034 protocol: protocol,
3035 async: async,
3036 })
3037 addStateMachineCoverageTests(stateMachineTestConfig{
3038 protocol: protocol,
3039 async: async,
3040 splitHandshake: true,
3041 })
3042 if protocol == tls {
3043 addStateMachineCoverageTests(stateMachineTestConfig{
3044 protocol: protocol,
3045 async: async,
3046 packHandshakeFlight: true,
3047 })
3048 }
3049 }
3050 }
3051}
3052
3053func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003054 var tests []testCase
3055
3056 // Basic handshake, with resumption. Client and server,
3057 // session ID and session ticket.
3058 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003059 name: "Basic-Client",
3060 config: Config{
3061 MaxVersion: VersionTLS12,
3062 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003063 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003064 // Ensure session tickets are used, not session IDs.
3065 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003066 })
3067 tests = append(tests, testCase{
3068 name: "Basic-Client-RenewTicket",
3069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003070 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003071 Bugs: ProtocolBugs{
3072 RenewTicketOnResume: true,
3073 },
3074 },
David Benjaminba4594a2015-06-18 18:36:15 -04003075 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003076 resumeSession: true,
3077 })
3078 tests = append(tests, testCase{
3079 name: "Basic-Client-NoTicket",
3080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003081 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003082 SessionTicketsDisabled: true,
3083 },
3084 resumeSession: true,
3085 })
3086 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003087 name: "Basic-Client-Implicit",
3088 config: Config{
3089 MaxVersion: VersionTLS12,
3090 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003091 flags: []string{"-implicit-handshake"},
3092 resumeSession: true,
3093 })
3094 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003095 testType: serverTest,
3096 name: "Basic-Server",
3097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003098 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003099 Bugs: ProtocolBugs{
3100 RequireSessionTickets: true,
3101 },
3102 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003103 resumeSession: true,
3104 })
3105 tests = append(tests, testCase{
3106 testType: serverTest,
3107 name: "Basic-Server-NoTickets",
3108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003110 SessionTicketsDisabled: true,
3111 },
3112 resumeSession: true,
3113 })
3114 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003115 testType: serverTest,
3116 name: "Basic-Server-Implicit",
3117 config: Config{
3118 MaxVersion: VersionTLS12,
3119 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003120 flags: []string{"-implicit-handshake"},
3121 resumeSession: true,
3122 })
3123 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003124 testType: serverTest,
3125 name: "Basic-Server-EarlyCallback",
3126 config: Config{
3127 MaxVersion: VersionTLS12,
3128 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003129 flags: []string{"-use-early-callback"},
3130 resumeSession: true,
3131 })
3132
Steven Valdez143e8b32016-07-11 13:19:03 -04003133 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003134 if config.protocol == tls {
3135 tests = append(tests, testCase{
3136 name: "TLS13-1RTT-Client",
3137 config: Config{
3138 MaxVersion: VersionTLS13,
3139 MinVersion: VersionTLS13,
3140 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003141 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003142 })
3143
3144 tests = append(tests, testCase{
3145 testType: serverTest,
3146 name: "TLS13-1RTT-Server",
3147 config: Config{
3148 MaxVersion: VersionTLS13,
3149 MinVersion: VersionTLS13,
3150 },
David Benjamin8a8349b2016-08-18 02:32:23 -04003151 resumeSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003152 })
3153
3154 tests = append(tests, testCase{
3155 name: "TLS13-HelloRetryRequest-Client",
3156 config: Config{
3157 MaxVersion: VersionTLS13,
3158 MinVersion: VersionTLS13,
3159 // P-384 requires a HelloRetryRequest against
3160 // BoringSSL's default configuration. Assert
3161 // that we do indeed test this with
3162 // ExpectMissingKeyShare.
3163 CurvePreferences: []CurveID{CurveP384},
3164 Bugs: ProtocolBugs{
3165 ExpectMissingKeyShare: true,
3166 },
3167 },
3168 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3169 resumeSession: true,
3170 })
3171
3172 tests = append(tests, testCase{
3173 testType: serverTest,
3174 name: "TLS13-HelloRetryRequest-Server",
3175 config: Config{
3176 MaxVersion: VersionTLS13,
3177 MinVersion: VersionTLS13,
3178 // Require a HelloRetryRequest for every curve.
3179 DefaultCurves: []CurveID{},
3180 },
3181 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3182 resumeSession: true,
3183 })
3184 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003185
David Benjamin760b1dd2015-05-15 23:33:48 -04003186 // TLS client auth.
3187 tests = append(tests, testCase{
3188 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003189 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003191 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003192 ClientAuth: RequestClientCert,
3193 },
3194 })
3195 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003196 testType: serverTest,
3197 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003198 config: Config{
3199 MaxVersion: VersionTLS12,
3200 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003201 // Setting SSL_VERIFY_PEER allows anonymous clients.
3202 flags: []string{"-verify-peer"},
3203 })
David Benjamin582ba042016-07-07 12:33:25 -07003204 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003205 tests = append(tests, testCase{
3206 testType: clientTest,
3207 name: "ClientAuth-NoCertificate-Client-SSL3",
3208 config: Config{
3209 MaxVersion: VersionSSL30,
3210 ClientAuth: RequestClientCert,
3211 },
3212 })
3213 tests = append(tests, testCase{
3214 testType: serverTest,
3215 name: "ClientAuth-NoCertificate-Server-SSL3",
3216 config: Config{
3217 MaxVersion: VersionSSL30,
3218 },
3219 // Setting SSL_VERIFY_PEER allows anonymous clients.
3220 flags: []string{"-verify-peer"},
3221 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003222 tests = append(tests, testCase{
3223 testType: clientTest,
3224 name: "ClientAuth-NoCertificate-Client-TLS13",
3225 config: Config{
3226 MaxVersion: VersionTLS13,
3227 ClientAuth: RequestClientCert,
3228 },
3229 })
3230 tests = append(tests, testCase{
3231 testType: serverTest,
3232 name: "ClientAuth-NoCertificate-Server-TLS13",
3233 config: Config{
3234 MaxVersion: VersionTLS13,
3235 },
3236 // Setting SSL_VERIFY_PEER allows anonymous clients.
3237 flags: []string{"-verify-peer"},
3238 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003239 }
3240 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003241 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003242 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003244 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003245 ClientAuth: RequireAnyClientCert,
3246 },
3247 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003248 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3249 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003250 },
3251 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003252 tests = append(tests, testCase{
3253 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003254 name: "ClientAuth-RSA-Client-TLS13",
3255 config: Config{
3256 MaxVersion: VersionTLS13,
3257 ClientAuth: RequireAnyClientCert,
3258 },
3259 flags: []string{
3260 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3261 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3262 },
3263 })
3264 tests = append(tests, testCase{
3265 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003266 name: "ClientAuth-ECDSA-Client",
3267 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003268 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003269 ClientAuth: RequireAnyClientCert,
3270 },
3271 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003272 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3273 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003274 },
3275 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003276 tests = append(tests, testCase{
3277 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003278 name: "ClientAuth-ECDSA-Client-TLS13",
3279 config: Config{
3280 MaxVersion: VersionTLS13,
3281 ClientAuth: RequireAnyClientCert,
3282 },
3283 flags: []string{
3284 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3285 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3286 },
3287 })
3288 tests = append(tests, testCase{
3289 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290 name: "ClientAuth-NoCertificate-OldCallback",
3291 config: Config{
3292 MaxVersion: VersionTLS12,
3293 ClientAuth: RequestClientCert,
3294 },
3295 flags: []string{"-use-old-client-cert-callback"},
3296 })
3297 tests = append(tests, testCase{
3298 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003299 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3300 config: Config{
3301 MaxVersion: VersionTLS13,
3302 ClientAuth: RequestClientCert,
3303 },
3304 flags: []string{"-use-old-client-cert-callback"},
3305 })
3306 tests = append(tests, testCase{
3307 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003308 name: "ClientAuth-OldCallback",
3309 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003310 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003311 ClientAuth: RequireAnyClientCert,
3312 },
3313 flags: []string{
3314 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3315 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3316 "-use-old-client-cert-callback",
3317 },
3318 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003319 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003320 testType: clientTest,
3321 name: "ClientAuth-OldCallback-TLS13",
3322 config: Config{
3323 MaxVersion: VersionTLS13,
3324 ClientAuth: RequireAnyClientCert,
3325 },
3326 flags: []string{
3327 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3328 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3329 "-use-old-client-cert-callback",
3330 },
3331 })
3332 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003333 testType: serverTest,
3334 name: "ClientAuth-Server",
3335 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003336 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003337 Certificates: []Certificate{rsaCertificate},
3338 },
3339 flags: []string{"-require-any-client-certificate"},
3340 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003341 tests = append(tests, testCase{
3342 testType: serverTest,
3343 name: "ClientAuth-Server-TLS13",
3344 config: Config{
3345 MaxVersion: VersionTLS13,
3346 Certificates: []Certificate{rsaCertificate},
3347 },
3348 flags: []string{"-require-any-client-certificate"},
3349 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003350
David Benjamin4c3ddf72016-06-29 18:13:53 -04003351 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003352 tests = append(tests, testCase{
3353 testType: serverTest,
3354 name: "Basic-Server-RSA",
3355 config: Config{
3356 MaxVersion: VersionTLS12,
3357 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3358 },
3359 flags: []string{
3360 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3361 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3362 },
3363 })
3364 tests = append(tests, testCase{
3365 testType: serverTest,
3366 name: "Basic-Server-ECDHE-RSA",
3367 config: Config{
3368 MaxVersion: VersionTLS12,
3369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3370 },
3371 flags: []string{
3372 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3373 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3374 },
3375 })
3376 tests = append(tests, testCase{
3377 testType: serverTest,
3378 name: "Basic-Server-ECDHE-ECDSA",
3379 config: Config{
3380 MaxVersion: VersionTLS12,
3381 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3382 },
3383 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003384 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3385 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003386 },
3387 })
3388
David Benjamin760b1dd2015-05-15 23:33:48 -04003389 // No session ticket support; server doesn't send NewSessionTicket.
3390 tests = append(tests, testCase{
3391 name: "SessionTicketsDisabled-Client",
3392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003393 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003394 SessionTicketsDisabled: true,
3395 },
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "SessionTicketsDisabled-Server",
3400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003401 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 SessionTicketsDisabled: true,
3403 },
3404 })
3405
3406 // Skip ServerKeyExchange in PSK key exchange if there's no
3407 // identity hint.
3408 tests = append(tests, testCase{
3409 name: "EmptyPSKHint-Client",
3410 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3413 PreSharedKey: []byte("secret"),
3414 },
3415 flags: []string{"-psk", "secret"},
3416 })
3417 tests = append(tests, testCase{
3418 testType: serverTest,
3419 name: "EmptyPSKHint-Server",
3420 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003421 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003422 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3423 PreSharedKey: []byte("secret"),
3424 },
3425 flags: []string{"-psk", "secret"},
3426 })
3427
David Benjamin4c3ddf72016-06-29 18:13:53 -04003428 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003429 tests = append(tests, testCase{
3430 testType: clientTest,
3431 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003432 config: Config{
3433 MaxVersion: VersionTLS12,
3434 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003435 flags: []string{
3436 "-enable-ocsp-stapling",
3437 "-expect-ocsp-response",
3438 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003439 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003440 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003441 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003442 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003443 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 testType: serverTest,
3445 name: "OCSPStapling-Server",
3446 config: Config{
3447 MaxVersion: VersionTLS12,
3448 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003449 expectedOCSPResponse: testOCSPResponse,
3450 flags: []string{
3451 "-ocsp-response",
3452 base64.StdEncoding.EncodeToString(testOCSPResponse),
3453 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003454 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003455 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003456 tests = append(tests, testCase{
3457 testType: clientTest,
3458 name: "OCSPStapling-Client-TLS13",
3459 config: Config{
3460 MaxVersion: VersionTLS13,
3461 },
3462 flags: []string{
3463 "-enable-ocsp-stapling",
3464 "-expect-ocsp-response",
3465 base64.StdEncoding.EncodeToString(testOCSPResponse),
3466 "-verify-peer",
3467 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003468 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003469 })
3470 tests = append(tests, testCase{
3471 testType: serverTest,
3472 name: "OCSPStapling-Server-TLS13",
3473 config: Config{
3474 MaxVersion: VersionTLS13,
3475 },
3476 expectedOCSPResponse: testOCSPResponse,
3477 flags: []string{
3478 "-ocsp-response",
3479 base64.StdEncoding.EncodeToString(testOCSPResponse),
3480 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003481 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003482 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003483
David Benjamin4c3ddf72016-06-29 18:13:53 -04003484 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003485 for _, vers := range tlsVersions {
3486 if config.protocol == dtls && !vers.hasDTLS {
3487 continue
3488 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003489 for _, testType := range []testType{clientTest, serverTest} {
3490 suffix := "-Client"
3491 if testType == serverTest {
3492 suffix = "-Server"
3493 }
3494 suffix += "-" + vers.name
3495
3496 flag := "-verify-peer"
3497 if testType == serverTest {
3498 flag = "-require-any-client-certificate"
3499 }
3500
3501 tests = append(tests, testCase{
3502 testType: testType,
3503 name: "CertificateVerificationSucceed" + suffix,
3504 config: Config{
3505 MaxVersion: vers.version,
3506 Certificates: []Certificate{rsaCertificate},
3507 },
3508 flags: []string{
3509 flag,
3510 "-expect-verify-result",
3511 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003512 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003513 })
3514 tests = append(tests, testCase{
3515 testType: testType,
3516 name: "CertificateVerificationFail" + suffix,
3517 config: Config{
3518 MaxVersion: vers.version,
3519 Certificates: []Certificate{rsaCertificate},
3520 },
3521 flags: []string{
3522 flag,
3523 "-verify-fail",
3524 },
3525 shouldFail: true,
3526 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3527 })
3528 }
3529
3530 // By default, the client is in a soft fail mode where the peer
3531 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003532 tests = append(tests, testCase{
3533 testType: clientTest,
3534 name: "CertificateVerificationSoftFail-" + vers.name,
3535 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003536 MaxVersion: vers.version,
3537 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003538 },
3539 flags: []string{
3540 "-verify-fail",
3541 "-expect-verify-result",
3542 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003543 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003544 })
3545 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003546
David Benjamin1d4f4c02016-07-26 18:03:08 -04003547 tests = append(tests, testCase{
3548 name: "ShimSendAlert",
3549 flags: []string{"-send-alert"},
3550 shimWritesFirst: true,
3551 shouldFail: true,
3552 expectedLocalError: "remote error: decompression failure",
3553 })
3554
David Benjamin582ba042016-07-07 12:33:25 -07003555 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003557 name: "Renegotiate-Client",
3558 config: Config{
3559 MaxVersion: VersionTLS12,
3560 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003561 renegotiate: 1,
3562 flags: []string{
3563 "-renegotiate-freely",
3564 "-expect-total-renegotiations", "1",
3565 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003566 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003567
David Benjamin47921102016-07-28 11:29:18 -04003568 tests = append(tests, testCase{
3569 name: "SendHalfHelloRequest",
3570 config: Config{
3571 MaxVersion: VersionTLS12,
3572 Bugs: ProtocolBugs{
3573 PackHelloRequestWithFinished: config.packHandshakeFlight,
3574 },
3575 },
3576 sendHalfHelloRequest: true,
3577 flags: []string{"-renegotiate-ignore"},
3578 shouldFail: true,
3579 expectedError: ":UNEXPECTED_RECORD:",
3580 })
3581
David Benjamin760b1dd2015-05-15 23:33:48 -04003582 // NPN on client and server; results in post-handshake message.
3583 tests = append(tests, testCase{
3584 name: "NPN-Client",
3585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003586 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 NextProtos: []string{"foo"},
3588 },
3589 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003590 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003591 expectedNextProto: "foo",
3592 expectedNextProtoType: npn,
3593 })
3594 tests = append(tests, testCase{
3595 testType: serverTest,
3596 name: "NPN-Server",
3597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003598 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003599 NextProtos: []string{"bar"},
3600 },
3601 flags: []string{
3602 "-advertise-npn", "\x03foo\x03bar\x03baz",
3603 "-expect-next-proto", "bar",
3604 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003605 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003606 expectedNextProto: "bar",
3607 expectedNextProtoType: npn,
3608 })
3609
3610 // TODO(davidben): Add tests for when False Start doesn't trigger.
3611
3612 // Client does False Start and negotiates NPN.
3613 tests = append(tests, testCase{
3614 name: "FalseStart",
3615 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003616 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003617 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3618 NextProtos: []string{"foo"},
3619 Bugs: ProtocolBugs{
3620 ExpectFalseStart: true,
3621 },
3622 },
3623 flags: []string{
3624 "-false-start",
3625 "-select-next-proto", "foo",
3626 },
3627 shimWritesFirst: true,
3628 resumeSession: true,
3629 })
3630
3631 // Client does False Start and negotiates ALPN.
3632 tests = append(tests, testCase{
3633 name: "FalseStart-ALPN",
3634 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003635 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003636 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3637 NextProtos: []string{"foo"},
3638 Bugs: ProtocolBugs{
3639 ExpectFalseStart: true,
3640 },
3641 },
3642 flags: []string{
3643 "-false-start",
3644 "-advertise-alpn", "\x03foo",
3645 },
3646 shimWritesFirst: true,
3647 resumeSession: true,
3648 })
3649
3650 // Client does False Start but doesn't explicitly call
3651 // SSL_connect.
3652 tests = append(tests, testCase{
3653 name: "FalseStart-Implicit",
3654 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003655 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003656 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3657 NextProtos: []string{"foo"},
3658 },
3659 flags: []string{
3660 "-implicit-handshake",
3661 "-false-start",
3662 "-advertise-alpn", "\x03foo",
3663 },
3664 })
3665
3666 // False Start without session tickets.
3667 tests = append(tests, testCase{
3668 name: "FalseStart-SessionTicketsDisabled",
3669 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3672 NextProtos: []string{"foo"},
3673 SessionTicketsDisabled: true,
3674 Bugs: ProtocolBugs{
3675 ExpectFalseStart: true,
3676 },
3677 },
3678 flags: []string{
3679 "-false-start",
3680 "-select-next-proto", "foo",
3681 },
3682 shimWritesFirst: true,
3683 })
3684
Adam Langleydf759b52016-07-11 15:24:37 -07003685 tests = append(tests, testCase{
3686 name: "FalseStart-CECPQ1",
3687 config: Config{
3688 MaxVersion: VersionTLS12,
3689 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3690 NextProtos: []string{"foo"},
3691 Bugs: ProtocolBugs{
3692 ExpectFalseStart: true,
3693 },
3694 },
3695 flags: []string{
3696 "-false-start",
3697 "-cipher", "DEFAULT:kCECPQ1",
3698 "-select-next-proto", "foo",
3699 },
3700 shimWritesFirst: true,
3701 resumeSession: true,
3702 })
3703
David Benjamin760b1dd2015-05-15 23:33:48 -04003704 // Server parses a V2ClientHello.
3705 tests = append(tests, testCase{
3706 testType: serverTest,
3707 name: "SendV2ClientHello",
3708 config: Config{
3709 // Choose a cipher suite that does not involve
3710 // elliptic curves, so no extensions are
3711 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003712 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003713 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3714 Bugs: ProtocolBugs{
3715 SendV2ClientHello: true,
3716 },
3717 },
3718 })
3719
3720 // Client sends a Channel ID.
3721 tests = append(tests, testCase{
3722 name: "ChannelID-Client",
3723 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003725 RequestChannelID: true,
3726 },
Adam Langley7c803a62015-06-15 15:35:05 -07003727 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 resumeSession: true,
3729 expectChannelID: true,
3730 })
3731
3732 // Server accepts a Channel ID.
3733 tests = append(tests, testCase{
3734 testType: serverTest,
3735 name: "ChannelID-Server",
3736 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003737 MaxVersion: VersionTLS12,
3738 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003739 },
3740 flags: []string{
3741 "-expect-channel-id",
3742 base64.StdEncoding.EncodeToString(channelIDBytes),
3743 },
3744 resumeSession: true,
3745 expectChannelID: true,
3746 })
David Benjamin30789da2015-08-29 22:56:45 -04003747
David Benjaminf8fcdf32016-06-08 15:56:13 -04003748 // Channel ID and NPN at the same time, to ensure their relative
3749 // ordering is correct.
3750 tests = append(tests, testCase{
3751 name: "ChannelID-NPN-Client",
3752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003754 RequestChannelID: true,
3755 NextProtos: []string{"foo"},
3756 },
3757 flags: []string{
3758 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3759 "-select-next-proto", "foo",
3760 },
3761 resumeSession: true,
3762 expectChannelID: true,
3763 expectedNextProto: "foo",
3764 expectedNextProtoType: npn,
3765 })
3766 tests = append(tests, testCase{
3767 testType: serverTest,
3768 name: "ChannelID-NPN-Server",
3769 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003770 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003771 ChannelID: channelIDKey,
3772 NextProtos: []string{"bar"},
3773 },
3774 flags: []string{
3775 "-expect-channel-id",
3776 base64.StdEncoding.EncodeToString(channelIDBytes),
3777 "-advertise-npn", "\x03foo\x03bar\x03baz",
3778 "-expect-next-proto", "bar",
3779 },
3780 resumeSession: true,
3781 expectChannelID: true,
3782 expectedNextProto: "bar",
3783 expectedNextProtoType: npn,
3784 })
3785
David Benjamin30789da2015-08-29 22:56:45 -04003786 // Bidirectional shutdown with the runner initiating.
3787 tests = append(tests, testCase{
3788 name: "Shutdown-Runner",
3789 config: Config{
3790 Bugs: ProtocolBugs{
3791 ExpectCloseNotify: true,
3792 },
3793 },
3794 flags: []string{"-check-close-notify"},
3795 })
3796
3797 // Bidirectional shutdown with the shim initiating. The runner,
3798 // in the meantime, sends garbage before the close_notify which
3799 // the shim must ignore.
3800 tests = append(tests, testCase{
3801 name: "Shutdown-Shim",
3802 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003803 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003804 Bugs: ProtocolBugs{
3805 ExpectCloseNotify: true,
3806 },
3807 },
3808 shimShutsDown: true,
3809 sendEmptyRecords: 1,
3810 sendWarningAlerts: 1,
3811 flags: []string{"-check-close-notify"},
3812 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003813 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003814 // TODO(davidben): DTLS 1.3 will want a similar thing for
3815 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003816 tests = append(tests, testCase{
3817 name: "SkipHelloVerifyRequest",
3818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003819 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003820 Bugs: ProtocolBugs{
3821 SkipHelloVerifyRequest: true,
3822 },
3823 },
3824 })
3825 }
3826
David Benjamin760b1dd2015-05-15 23:33:48 -04003827 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003828 test.protocol = config.protocol
3829 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003830 test.name += "-DTLS"
3831 }
David Benjamin582ba042016-07-07 12:33:25 -07003832 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003833 test.name += "-Async"
3834 test.flags = append(test.flags, "-async")
3835 } else {
3836 test.name += "-Sync"
3837 }
David Benjamin582ba042016-07-07 12:33:25 -07003838 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003839 test.name += "-SplitHandshakeRecords"
3840 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003841 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003842 test.config.Bugs.MaxPacketLength = 256
3843 test.flags = append(test.flags, "-mtu", "256")
3844 }
3845 }
David Benjamin582ba042016-07-07 12:33:25 -07003846 if config.packHandshakeFlight {
3847 test.name += "-PackHandshakeFlight"
3848 test.config.Bugs.PackHandshakeFlight = true
3849 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003850 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003851 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003852}
3853
Adam Langley524e7172015-02-20 16:04:00 -08003854func addDDoSCallbackTests() {
3855 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003856 for _, resume := range []bool{false, true} {
3857 suffix := "Resume"
3858 if resume {
3859 suffix = "No" + suffix
3860 }
3861
3862 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003863 testType: serverTest,
3864 name: "Server-DDoS-OK-" + suffix,
3865 config: Config{
3866 MaxVersion: VersionTLS12,
3867 },
Adam Langley524e7172015-02-20 16:04:00 -08003868 flags: []string{"-install-ddos-callback"},
3869 resumeSession: resume,
3870 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003871 testCases = append(testCases, testCase{
3872 testType: serverTest,
3873 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3874 config: Config{
3875 MaxVersion: VersionTLS13,
3876 },
3877 flags: []string{"-install-ddos-callback"},
3878 resumeSession: resume,
3879 })
Adam Langley524e7172015-02-20 16:04:00 -08003880
3881 failFlag := "-fail-ddos-callback"
3882 if resume {
3883 failFlag = "-fail-second-ddos-callback"
3884 }
3885 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003886 testType: serverTest,
3887 name: "Server-DDoS-Reject-" + suffix,
3888 config: Config{
3889 MaxVersion: VersionTLS12,
3890 },
Adam Langley524e7172015-02-20 16:04:00 -08003891 flags: []string{"-install-ddos-callback", failFlag},
3892 resumeSession: resume,
3893 shouldFail: true,
3894 expectedError: ":CONNECTION_REJECTED:",
3895 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003896 testCases = append(testCases, testCase{
3897 testType: serverTest,
3898 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3899 config: Config{
3900 MaxVersion: VersionTLS13,
3901 },
3902 flags: []string{"-install-ddos-callback", failFlag},
3903 resumeSession: resume,
3904 shouldFail: true,
3905 expectedError: ":CONNECTION_REJECTED:",
3906 })
Adam Langley524e7172015-02-20 16:04:00 -08003907 }
3908}
3909
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003910func addVersionNegotiationTests() {
3911 for i, shimVers := range tlsVersions {
3912 // Assemble flags to disable all newer versions on the shim.
3913 var flags []string
3914 for _, vers := range tlsVersions[i+1:] {
3915 flags = append(flags, vers.flag)
3916 }
3917
3918 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003919 protocols := []protocol{tls}
3920 if runnerVers.hasDTLS && shimVers.hasDTLS {
3921 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003922 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003923 for _, protocol := range protocols {
3924 expectedVersion := shimVers.version
3925 if runnerVers.version < shimVers.version {
3926 expectedVersion = runnerVers.version
3927 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003928
David Benjamin8b8c0062014-11-23 02:47:52 -05003929 suffix := shimVers.name + "-" + runnerVers.name
3930 if protocol == dtls {
3931 suffix += "-DTLS"
3932 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003933
David Benjamin1eb367c2014-12-12 18:17:51 -05003934 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3935
David Benjamin1e29a6b2014-12-10 02:27:24 -05003936 clientVers := shimVers.version
3937 if clientVers > VersionTLS10 {
3938 clientVers = VersionTLS10
3939 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003940 serverVers := expectedVersion
3941 if expectedVersion >= VersionTLS13 {
3942 serverVers = VersionTLS10
3943 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003944 testCases = append(testCases, testCase{
3945 protocol: protocol,
3946 testType: clientTest,
3947 name: "VersionNegotiation-Client-" + suffix,
3948 config: Config{
3949 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003950 Bugs: ProtocolBugs{
3951 ExpectInitialRecordVersion: clientVers,
3952 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003953 },
3954 flags: flags,
3955 expectedVersion: expectedVersion,
3956 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003957 testCases = append(testCases, testCase{
3958 protocol: protocol,
3959 testType: clientTest,
3960 name: "VersionNegotiation-Client2-" + suffix,
3961 config: Config{
3962 MaxVersion: runnerVers.version,
3963 Bugs: ProtocolBugs{
3964 ExpectInitialRecordVersion: clientVers,
3965 },
3966 },
3967 flags: []string{"-max-version", shimVersFlag},
3968 expectedVersion: expectedVersion,
3969 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003970
3971 testCases = append(testCases, testCase{
3972 protocol: protocol,
3973 testType: serverTest,
3974 name: "VersionNegotiation-Server-" + suffix,
3975 config: Config{
3976 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003977 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003978 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003979 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003980 },
3981 flags: flags,
3982 expectedVersion: expectedVersion,
3983 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003984 testCases = append(testCases, testCase{
3985 protocol: protocol,
3986 testType: serverTest,
3987 name: "VersionNegotiation-Server2-" + suffix,
3988 config: Config{
3989 MaxVersion: runnerVers.version,
3990 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003991 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003992 },
3993 },
3994 flags: []string{"-max-version", shimVersFlag},
3995 expectedVersion: expectedVersion,
3996 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003997 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003998 }
3999 }
David Benjamin95c69562016-06-29 18:15:03 -04004000
4001 // Test for version tolerance.
4002 testCases = append(testCases, testCase{
4003 testType: serverTest,
4004 name: "MinorVersionTolerance",
4005 config: Config{
4006 Bugs: ProtocolBugs{
4007 SendClientVersion: 0x03ff,
4008 },
4009 },
4010 expectedVersion: VersionTLS13,
4011 })
4012 testCases = append(testCases, testCase{
4013 testType: serverTest,
4014 name: "MajorVersionTolerance",
4015 config: Config{
4016 Bugs: ProtocolBugs{
4017 SendClientVersion: 0x0400,
4018 },
4019 },
4020 expectedVersion: VersionTLS13,
4021 })
4022 testCases = append(testCases, testCase{
4023 protocol: dtls,
4024 testType: serverTest,
4025 name: "MinorVersionTolerance-DTLS",
4026 config: Config{
4027 Bugs: ProtocolBugs{
4028 SendClientVersion: 0x03ff,
4029 },
4030 },
4031 expectedVersion: VersionTLS12,
4032 })
4033 testCases = append(testCases, testCase{
4034 protocol: dtls,
4035 testType: serverTest,
4036 name: "MajorVersionTolerance-DTLS",
4037 config: Config{
4038 Bugs: ProtocolBugs{
4039 SendClientVersion: 0x0400,
4040 },
4041 },
4042 expectedVersion: VersionTLS12,
4043 })
4044
4045 // Test that versions below 3.0 are rejected.
4046 testCases = append(testCases, testCase{
4047 testType: serverTest,
4048 name: "VersionTooLow",
4049 config: Config{
4050 Bugs: ProtocolBugs{
4051 SendClientVersion: 0x0200,
4052 },
4053 },
4054 shouldFail: true,
4055 expectedError: ":UNSUPPORTED_PROTOCOL:",
4056 })
4057 testCases = append(testCases, testCase{
4058 protocol: dtls,
4059 testType: serverTest,
4060 name: "VersionTooLow-DTLS",
4061 config: Config{
4062 Bugs: ProtocolBugs{
4063 // 0x0201 is the lowest version expressable in
4064 // DTLS.
4065 SendClientVersion: 0x0201,
4066 },
4067 },
4068 shouldFail: true,
4069 expectedError: ":UNSUPPORTED_PROTOCOL:",
4070 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004071
4072 // Test TLS 1.3's downgrade signal.
4073 testCases = append(testCases, testCase{
4074 name: "Downgrade-TLS12-Client",
4075 config: Config{
4076 Bugs: ProtocolBugs{
4077 NegotiateVersion: VersionTLS12,
4078 },
4079 },
4080 shouldFail: true,
4081 expectedError: ":DOWNGRADE_DETECTED:",
4082 })
4083 testCases = append(testCases, testCase{
4084 testType: serverTest,
4085 name: "Downgrade-TLS12-Server",
4086 config: Config{
4087 Bugs: ProtocolBugs{
4088 SendClientVersion: VersionTLS12,
4089 },
4090 },
4091 shouldFail: true,
4092 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4093 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004094
4095 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4096 // behave correctly when both real maximum and fallback versions are
4097 // set.
4098 testCases = append(testCases, testCase{
4099 name: "Downgrade-TLS12-Client-Fallback",
4100 config: Config{
4101 Bugs: ProtocolBugs{
4102 FailIfNotFallbackSCSV: true,
4103 },
4104 },
4105 flags: []string{
4106 "-max-version", strconv.Itoa(VersionTLS13),
4107 "-fallback-version", strconv.Itoa(VersionTLS12),
4108 },
4109 shouldFail: true,
4110 expectedError: ":DOWNGRADE_DETECTED:",
4111 })
4112 testCases = append(testCases, testCase{
4113 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4114 flags: []string{
4115 "-max-version", strconv.Itoa(VersionTLS12),
4116 "-fallback-version", strconv.Itoa(VersionTLS12),
4117 },
4118 })
4119
4120 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4121 // just have such connections fail than risk getting confused because we
4122 // didn't sent the 1.3 ClientHello.)
4123 testCases = append(testCases, testCase{
4124 name: "Downgrade-TLS12-Fallback-CheckVersion",
4125 config: Config{
4126 Bugs: ProtocolBugs{
4127 NegotiateVersion: VersionTLS13,
4128 FailIfNotFallbackSCSV: true,
4129 },
4130 },
4131 flags: []string{
4132 "-max-version", strconv.Itoa(VersionTLS13),
4133 "-fallback-version", strconv.Itoa(VersionTLS12),
4134 },
4135 shouldFail: true,
4136 expectedError: ":UNSUPPORTED_PROTOCOL:",
4137 })
4138
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004139}
4140
David Benjaminaccb4542014-12-12 23:44:33 -05004141func addMinimumVersionTests() {
4142 for i, shimVers := range tlsVersions {
4143 // Assemble flags to disable all older versions on the shim.
4144 var flags []string
4145 for _, vers := range tlsVersions[:i] {
4146 flags = append(flags, vers.flag)
4147 }
4148
4149 for _, runnerVers := range tlsVersions {
4150 protocols := []protocol{tls}
4151 if runnerVers.hasDTLS && shimVers.hasDTLS {
4152 protocols = append(protocols, dtls)
4153 }
4154 for _, protocol := range protocols {
4155 suffix := shimVers.name + "-" + runnerVers.name
4156 if protocol == dtls {
4157 suffix += "-DTLS"
4158 }
4159 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4160
David Benjaminaccb4542014-12-12 23:44:33 -05004161 var expectedVersion uint16
4162 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004163 var expectedClientError, expectedServerError string
4164 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004165 if runnerVers.version >= shimVers.version {
4166 expectedVersion = runnerVers.version
4167 } else {
4168 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004169 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4170 expectedServerLocalError = "remote error: protocol version not supported"
4171 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4172 // If the client's minimum version is TLS 1.3 and the runner's
4173 // maximum is below TLS 1.2, the runner will fail to select a
4174 // cipher before the shim rejects the selected version.
4175 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4176 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4177 } else {
4178 expectedClientError = expectedServerError
4179 expectedClientLocalError = expectedServerLocalError
4180 }
David Benjaminaccb4542014-12-12 23:44:33 -05004181 }
4182
4183 testCases = append(testCases, testCase{
4184 protocol: protocol,
4185 testType: clientTest,
4186 name: "MinimumVersion-Client-" + suffix,
4187 config: Config{
4188 MaxVersion: runnerVers.version,
4189 },
David Benjamin87909c02014-12-13 01:55:01 -05004190 flags: flags,
4191 expectedVersion: expectedVersion,
4192 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004193 expectedError: expectedClientError,
4194 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004195 })
4196 testCases = append(testCases, testCase{
4197 protocol: protocol,
4198 testType: clientTest,
4199 name: "MinimumVersion-Client2-" + suffix,
4200 config: Config{
4201 MaxVersion: runnerVers.version,
4202 },
David Benjamin87909c02014-12-13 01:55:01 -05004203 flags: []string{"-min-version", shimVersFlag},
4204 expectedVersion: expectedVersion,
4205 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004206 expectedError: expectedClientError,
4207 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004208 })
4209
4210 testCases = append(testCases, testCase{
4211 protocol: protocol,
4212 testType: serverTest,
4213 name: "MinimumVersion-Server-" + suffix,
4214 config: Config{
4215 MaxVersion: runnerVers.version,
4216 },
David Benjamin87909c02014-12-13 01:55:01 -05004217 flags: flags,
4218 expectedVersion: expectedVersion,
4219 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004220 expectedError: expectedServerError,
4221 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004222 })
4223 testCases = append(testCases, testCase{
4224 protocol: protocol,
4225 testType: serverTest,
4226 name: "MinimumVersion-Server2-" + suffix,
4227 config: Config{
4228 MaxVersion: runnerVers.version,
4229 },
David Benjamin87909c02014-12-13 01:55:01 -05004230 flags: []string{"-min-version", shimVersFlag},
4231 expectedVersion: expectedVersion,
4232 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004233 expectedError: expectedServerError,
4234 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004235 })
4236 }
4237 }
4238 }
4239}
4240
David Benjamine78bfde2014-09-06 12:45:15 -04004241func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004242 // TODO(davidben): Extensions, where applicable, all move their server
4243 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4244 // tests for both. Also test interaction with 0-RTT when implemented.
4245
David Benjamin97d17d92016-07-14 16:12:00 -04004246 // Repeat extensions tests all versions except SSL 3.0.
4247 for _, ver := range tlsVersions {
4248 if ver.version == VersionSSL30 {
4249 continue
4250 }
4251
David Benjamin97d17d92016-07-14 16:12:00 -04004252 // Test that duplicate extensions are rejected.
4253 testCases = append(testCases, testCase{
4254 testType: clientTest,
4255 name: "DuplicateExtensionClient-" + ver.name,
4256 config: Config{
4257 MaxVersion: ver.version,
4258 Bugs: ProtocolBugs{
4259 DuplicateExtension: true,
4260 },
David Benjamine78bfde2014-09-06 12:45:15 -04004261 },
David Benjamin97d17d92016-07-14 16:12:00 -04004262 shouldFail: true,
4263 expectedLocalError: "remote error: error decoding message",
4264 })
4265 testCases = append(testCases, testCase{
4266 testType: serverTest,
4267 name: "DuplicateExtensionServer-" + ver.name,
4268 config: Config{
4269 MaxVersion: ver.version,
4270 Bugs: ProtocolBugs{
4271 DuplicateExtension: true,
4272 },
David Benjamine78bfde2014-09-06 12:45:15 -04004273 },
David Benjamin97d17d92016-07-14 16:12:00 -04004274 shouldFail: true,
4275 expectedLocalError: "remote error: error decoding message",
4276 })
4277
4278 // Test SNI.
4279 testCases = append(testCases, testCase{
4280 testType: clientTest,
4281 name: "ServerNameExtensionClient-" + ver.name,
4282 config: Config{
4283 MaxVersion: ver.version,
4284 Bugs: ProtocolBugs{
4285 ExpectServerName: "example.com",
4286 },
David Benjamine78bfde2014-09-06 12:45:15 -04004287 },
David Benjamin97d17d92016-07-14 16:12:00 -04004288 flags: []string{"-host-name", "example.com"},
4289 })
4290 testCases = append(testCases, testCase{
4291 testType: clientTest,
4292 name: "ServerNameExtensionClientMismatch-" + ver.name,
4293 config: Config{
4294 MaxVersion: ver.version,
4295 Bugs: ProtocolBugs{
4296 ExpectServerName: "mismatch.com",
4297 },
David Benjamine78bfde2014-09-06 12:45:15 -04004298 },
David Benjamin97d17d92016-07-14 16:12:00 -04004299 flags: []string{"-host-name", "example.com"},
4300 shouldFail: true,
4301 expectedLocalError: "tls: unexpected server name",
4302 })
4303 testCases = append(testCases, testCase{
4304 testType: clientTest,
4305 name: "ServerNameExtensionClientMissing-" + ver.name,
4306 config: Config{
4307 MaxVersion: ver.version,
4308 Bugs: ProtocolBugs{
4309 ExpectServerName: "missing.com",
4310 },
David Benjamine78bfde2014-09-06 12:45:15 -04004311 },
David Benjamin97d17d92016-07-14 16:12:00 -04004312 shouldFail: true,
4313 expectedLocalError: "tls: unexpected server name",
4314 })
4315 testCases = append(testCases, testCase{
4316 testType: serverTest,
4317 name: "ServerNameExtensionServer-" + ver.name,
4318 config: Config{
4319 MaxVersion: ver.version,
4320 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004321 },
David Benjamin97d17d92016-07-14 16:12:00 -04004322 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004323 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004324 })
4325
4326 // Test ALPN.
4327 testCases = append(testCases, testCase{
4328 testType: clientTest,
4329 name: "ALPNClient-" + ver.name,
4330 config: Config{
4331 MaxVersion: ver.version,
4332 NextProtos: []string{"foo"},
4333 },
4334 flags: []string{
4335 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4336 "-expect-alpn", "foo",
4337 },
4338 expectedNextProto: "foo",
4339 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004340 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004341 })
4342 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004343 testType: clientTest,
4344 name: "ALPNClient-Mismatch-" + ver.name,
4345 config: Config{
4346 MaxVersion: ver.version,
4347 Bugs: ProtocolBugs{
4348 SendALPN: "baz",
4349 },
4350 },
4351 flags: []string{
4352 "-advertise-alpn", "\x03foo\x03bar",
4353 },
4354 shouldFail: true,
4355 expectedError: ":INVALID_ALPN_PROTOCOL:",
4356 expectedLocalError: "remote error: illegal parameter",
4357 })
4358 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004359 testType: serverTest,
4360 name: "ALPNServer-" + ver.name,
4361 config: Config{
4362 MaxVersion: ver.version,
4363 NextProtos: []string{"foo", "bar", "baz"},
4364 },
4365 flags: []string{
4366 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4367 "-select-alpn", "foo",
4368 },
4369 expectedNextProto: "foo",
4370 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004371 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004372 })
4373 testCases = append(testCases, testCase{
4374 testType: serverTest,
4375 name: "ALPNServer-Decline-" + ver.name,
4376 config: Config{
4377 MaxVersion: ver.version,
4378 NextProtos: []string{"foo", "bar", "baz"},
4379 },
4380 flags: []string{"-decline-alpn"},
4381 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004382 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004383 })
4384
David Benjamin25fe85b2016-08-09 20:00:32 -04004385 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4386 // called once.
4387 testCases = append(testCases, testCase{
4388 testType: serverTest,
4389 name: "ALPNServer-Async-" + ver.name,
4390 config: Config{
4391 MaxVersion: ver.version,
4392 NextProtos: []string{"foo", "bar", "baz"},
4393 },
4394 flags: []string{
4395 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4396 "-select-alpn", "foo",
4397 "-async",
4398 },
4399 expectedNextProto: "foo",
4400 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004401 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004402 })
4403
David Benjamin97d17d92016-07-14 16:12:00 -04004404 var emptyString string
4405 testCases = append(testCases, testCase{
4406 testType: clientTest,
4407 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4408 config: Config{
4409 MaxVersion: ver.version,
4410 NextProtos: []string{""},
4411 Bugs: ProtocolBugs{
4412 // A server returning an empty ALPN protocol
4413 // should be rejected.
4414 ALPNProtocol: &emptyString,
4415 },
4416 },
4417 flags: []string{
4418 "-advertise-alpn", "\x03foo",
4419 },
4420 shouldFail: true,
4421 expectedError: ":PARSE_TLSEXT:",
4422 })
4423 testCases = append(testCases, testCase{
4424 testType: serverTest,
4425 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4426 config: Config{
4427 MaxVersion: ver.version,
4428 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004429 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004430 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004431 },
David Benjamin97d17d92016-07-14 16:12:00 -04004432 flags: []string{
4433 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004434 },
David Benjamin97d17d92016-07-14 16:12:00 -04004435 shouldFail: true,
4436 expectedError: ":PARSE_TLSEXT:",
4437 })
4438
4439 // Test NPN and the interaction with ALPN.
4440 if ver.version < VersionTLS13 {
4441 // Test that the server prefers ALPN over NPN.
4442 testCases = append(testCases, testCase{
4443 testType: serverTest,
4444 name: "ALPNServer-Preferred-" + ver.name,
4445 config: Config{
4446 MaxVersion: ver.version,
4447 NextProtos: []string{"foo", "bar", "baz"},
4448 },
4449 flags: []string{
4450 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4451 "-select-alpn", "foo",
4452 "-advertise-npn", "\x03foo\x03bar\x03baz",
4453 },
4454 expectedNextProto: "foo",
4455 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004456 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004457 })
4458 testCases = append(testCases, testCase{
4459 testType: serverTest,
4460 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4461 config: Config{
4462 MaxVersion: ver.version,
4463 NextProtos: []string{"foo", "bar", "baz"},
4464 Bugs: ProtocolBugs{
4465 SwapNPNAndALPN: true,
4466 },
4467 },
4468 flags: []string{
4469 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4470 "-select-alpn", "foo",
4471 "-advertise-npn", "\x03foo\x03bar\x03baz",
4472 },
4473 expectedNextProto: "foo",
4474 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004475 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004476 })
4477
4478 // Test that negotiating both NPN and ALPN is forbidden.
4479 testCases = append(testCases, testCase{
4480 name: "NegotiateALPNAndNPN-" + ver.name,
4481 config: Config{
4482 MaxVersion: ver.version,
4483 NextProtos: []string{"foo", "bar", "baz"},
4484 Bugs: ProtocolBugs{
4485 NegotiateALPNAndNPN: true,
4486 },
4487 },
4488 flags: []string{
4489 "-advertise-alpn", "\x03foo",
4490 "-select-next-proto", "foo",
4491 },
4492 shouldFail: true,
4493 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4494 })
4495 testCases = append(testCases, testCase{
4496 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4497 config: Config{
4498 MaxVersion: ver.version,
4499 NextProtos: []string{"foo", "bar", "baz"},
4500 Bugs: ProtocolBugs{
4501 NegotiateALPNAndNPN: true,
4502 SwapNPNAndALPN: true,
4503 },
4504 },
4505 flags: []string{
4506 "-advertise-alpn", "\x03foo",
4507 "-select-next-proto", "foo",
4508 },
4509 shouldFail: true,
4510 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4511 })
4512
4513 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4514 testCases = append(testCases, testCase{
4515 name: "DisableNPN-" + ver.name,
4516 config: Config{
4517 MaxVersion: ver.version,
4518 NextProtos: []string{"foo"},
4519 },
4520 flags: []string{
4521 "-select-next-proto", "foo",
4522 "-disable-npn",
4523 },
4524 expectNoNextProto: true,
4525 })
4526 }
4527
4528 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004529
4530 // Resume with a corrupt ticket.
4531 testCases = append(testCases, testCase{
4532 testType: serverTest,
4533 name: "CorruptTicket-" + ver.name,
4534 config: Config{
4535 MaxVersion: ver.version,
4536 Bugs: ProtocolBugs{
4537 CorruptTicket: true,
4538 },
4539 },
4540 resumeSession: true,
4541 expectResumeRejected: true,
4542 })
4543 // Test the ticket callback, with and without renewal.
4544 testCases = append(testCases, testCase{
4545 testType: serverTest,
4546 name: "TicketCallback-" + ver.name,
4547 config: Config{
4548 MaxVersion: ver.version,
4549 },
4550 resumeSession: true,
4551 flags: []string{"-use-ticket-callback"},
4552 })
4553 testCases = append(testCases, testCase{
4554 testType: serverTest,
4555 name: "TicketCallback-Renew-" + ver.name,
4556 config: Config{
4557 MaxVersion: ver.version,
4558 Bugs: ProtocolBugs{
4559 ExpectNewTicket: true,
4560 },
4561 },
4562 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4563 resumeSession: true,
4564 })
4565
4566 // Test that the ticket callback is only called once when everything before
4567 // it in the ClientHello is asynchronous. This corrupts the ticket so
4568 // certificate selection callbacks run.
4569 testCases = append(testCases, testCase{
4570 testType: serverTest,
4571 name: "TicketCallback-SingleCall-" + ver.name,
4572 config: Config{
4573 MaxVersion: ver.version,
4574 Bugs: ProtocolBugs{
4575 CorruptTicket: true,
4576 },
4577 },
4578 resumeSession: true,
4579 expectResumeRejected: true,
4580 flags: []string{
4581 "-use-ticket-callback",
4582 "-async",
4583 },
4584 })
4585
4586 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004587 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004588 testCases = append(testCases, testCase{
4589 testType: serverTest,
4590 name: "OversizedSessionId-" + ver.name,
4591 config: Config{
4592 MaxVersion: ver.version,
4593 Bugs: ProtocolBugs{
4594 OversizedSessionId: true,
4595 },
4596 },
4597 resumeSession: true,
4598 shouldFail: true,
4599 expectedError: ":DECODE_ERROR:",
4600 })
4601 }
4602
4603 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4604 // are ignored.
4605 if ver.hasDTLS {
4606 testCases = append(testCases, testCase{
4607 protocol: dtls,
4608 name: "SRTP-Client-" + ver.name,
4609 config: Config{
4610 MaxVersion: ver.version,
4611 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4612 },
4613 flags: []string{
4614 "-srtp-profiles",
4615 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4616 },
4617 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4618 })
4619 testCases = append(testCases, testCase{
4620 protocol: dtls,
4621 testType: serverTest,
4622 name: "SRTP-Server-" + ver.name,
4623 config: Config{
4624 MaxVersion: ver.version,
4625 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4626 },
4627 flags: []string{
4628 "-srtp-profiles",
4629 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4630 },
4631 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4632 })
4633 // Test that the MKI is ignored.
4634 testCases = append(testCases, testCase{
4635 protocol: dtls,
4636 testType: serverTest,
4637 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4638 config: Config{
4639 MaxVersion: ver.version,
4640 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4641 Bugs: ProtocolBugs{
4642 SRTPMasterKeyIdentifer: "bogus",
4643 },
4644 },
4645 flags: []string{
4646 "-srtp-profiles",
4647 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4648 },
4649 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4650 })
4651 // Test that SRTP isn't negotiated on the server if there were
4652 // no matching profiles.
4653 testCases = append(testCases, testCase{
4654 protocol: dtls,
4655 testType: serverTest,
4656 name: "SRTP-Server-NoMatch-" + ver.name,
4657 config: Config{
4658 MaxVersion: ver.version,
4659 SRTPProtectionProfiles: []uint16{100, 101, 102},
4660 },
4661 flags: []string{
4662 "-srtp-profiles",
4663 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4664 },
4665 expectedSRTPProtectionProfile: 0,
4666 })
4667 // Test that the server returning an invalid SRTP profile is
4668 // flagged as an error by the client.
4669 testCases = append(testCases, testCase{
4670 protocol: dtls,
4671 name: "SRTP-Client-NoMatch-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 Bugs: ProtocolBugs{
4675 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4676 },
4677 },
4678 flags: []string{
4679 "-srtp-profiles",
4680 "SRTP_AES128_CM_SHA1_80",
4681 },
4682 shouldFail: true,
4683 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4684 })
4685 }
4686
4687 // Test SCT list.
4688 testCases = append(testCases, testCase{
4689 name: "SignedCertificateTimestampList-Client-" + ver.name,
4690 testType: clientTest,
4691 config: Config{
4692 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004693 },
David Benjamin97d17d92016-07-14 16:12:00 -04004694 flags: []string{
4695 "-enable-signed-cert-timestamps",
4696 "-expect-signed-cert-timestamps",
4697 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004698 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004699 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004700 })
4701 testCases = append(testCases, testCase{
4702 name: "SendSCTListOnResume-" + ver.name,
4703 config: Config{
4704 MaxVersion: ver.version,
4705 Bugs: ProtocolBugs{
4706 SendSCTListOnResume: []byte("bogus"),
4707 },
David Benjamind98452d2015-06-16 14:16:23 -04004708 },
David Benjamin97d17d92016-07-14 16:12:00 -04004709 flags: []string{
4710 "-enable-signed-cert-timestamps",
4711 "-expect-signed-cert-timestamps",
4712 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004713 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004714 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004715 })
4716 testCases = append(testCases, testCase{
4717 name: "SignedCertificateTimestampList-Server-" + ver.name,
4718 testType: serverTest,
4719 config: Config{
4720 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004721 },
David Benjamin97d17d92016-07-14 16:12:00 -04004722 flags: []string{
4723 "-signed-cert-timestamps",
4724 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004725 },
David Benjamin97d17d92016-07-14 16:12:00 -04004726 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004727 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004728 })
4729 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004730
Paul Lietar4fac72e2015-09-09 13:44:55 +01004731 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004732 testType: clientTest,
4733 name: "ClientHelloPadding",
4734 config: Config{
4735 Bugs: ProtocolBugs{
4736 RequireClientHelloSize: 512,
4737 },
4738 },
4739 // This hostname just needs to be long enough to push the
4740 // ClientHello into F5's danger zone between 256 and 511 bytes
4741 // long.
4742 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4743 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004744
4745 // Extensions should not function in SSL 3.0.
4746 testCases = append(testCases, testCase{
4747 testType: serverTest,
4748 name: "SSLv3Extensions-NoALPN",
4749 config: Config{
4750 MaxVersion: VersionSSL30,
4751 NextProtos: []string{"foo", "bar", "baz"},
4752 },
4753 flags: []string{
4754 "-select-alpn", "foo",
4755 },
4756 expectNoNextProto: true,
4757 })
4758
4759 // Test session tickets separately as they follow a different codepath.
4760 testCases = append(testCases, testCase{
4761 testType: serverTest,
4762 name: "SSLv3Extensions-NoTickets",
4763 config: Config{
4764 MaxVersion: VersionSSL30,
4765 Bugs: ProtocolBugs{
4766 // Historically, session tickets in SSL 3.0
4767 // failed in different ways depending on whether
4768 // the client supported renegotiation_info.
4769 NoRenegotiationInfo: true,
4770 },
4771 },
4772 resumeSession: true,
4773 })
4774 testCases = append(testCases, testCase{
4775 testType: serverTest,
4776 name: "SSLv3Extensions-NoTickets2",
4777 config: Config{
4778 MaxVersion: VersionSSL30,
4779 },
4780 resumeSession: true,
4781 })
4782
4783 // But SSL 3.0 does send and process renegotiation_info.
4784 testCases = append(testCases, testCase{
4785 testType: serverTest,
4786 name: "SSLv3Extensions-RenegotiationInfo",
4787 config: Config{
4788 MaxVersion: VersionSSL30,
4789 Bugs: ProtocolBugs{
4790 RequireRenegotiationInfo: true,
4791 },
4792 },
4793 })
4794 testCases = append(testCases, testCase{
4795 testType: serverTest,
4796 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4797 config: Config{
4798 MaxVersion: VersionSSL30,
4799 Bugs: ProtocolBugs{
4800 NoRenegotiationInfo: true,
4801 SendRenegotiationSCSV: true,
4802 RequireRenegotiationInfo: true,
4803 },
4804 },
4805 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004806
4807 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4808 // in ServerHello.
4809 testCases = append(testCases, testCase{
4810 name: "NPN-Forbidden-TLS13",
4811 config: Config{
4812 MaxVersion: VersionTLS13,
4813 NextProtos: []string{"foo"},
4814 Bugs: ProtocolBugs{
4815 NegotiateNPNAtAllVersions: true,
4816 },
4817 },
4818 flags: []string{"-select-next-proto", "foo"},
4819 shouldFail: true,
4820 expectedError: ":ERROR_PARSING_EXTENSION:",
4821 })
4822 testCases = append(testCases, testCase{
4823 name: "EMS-Forbidden-TLS13",
4824 config: Config{
4825 MaxVersion: VersionTLS13,
4826 Bugs: ProtocolBugs{
4827 NegotiateEMSAtAllVersions: true,
4828 },
4829 },
4830 shouldFail: true,
4831 expectedError: ":ERROR_PARSING_EXTENSION:",
4832 })
4833 testCases = append(testCases, testCase{
4834 name: "RenegotiationInfo-Forbidden-TLS13",
4835 config: Config{
4836 MaxVersion: VersionTLS13,
4837 Bugs: ProtocolBugs{
4838 NegotiateRenegotiationInfoAtAllVersions: true,
4839 },
4840 },
4841 shouldFail: true,
4842 expectedError: ":ERROR_PARSING_EXTENSION:",
4843 })
4844 testCases = append(testCases, testCase{
4845 name: "ChannelID-Forbidden-TLS13",
4846 config: Config{
4847 MaxVersion: VersionTLS13,
4848 RequestChannelID: true,
4849 Bugs: ProtocolBugs{
4850 NegotiateChannelIDAtAllVersions: true,
4851 },
4852 },
4853 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4854 shouldFail: true,
4855 expectedError: ":ERROR_PARSING_EXTENSION:",
4856 })
4857 testCases = append(testCases, testCase{
4858 name: "Ticket-Forbidden-TLS13",
4859 config: Config{
4860 MaxVersion: VersionTLS12,
4861 },
4862 resumeConfig: &Config{
4863 MaxVersion: VersionTLS13,
4864 Bugs: ProtocolBugs{
4865 AdvertiseTicketExtension: true,
4866 },
4867 },
4868 resumeSession: true,
4869 shouldFail: true,
4870 expectedError: ":ERROR_PARSING_EXTENSION:",
4871 })
4872
4873 // Test that illegal extensions in TLS 1.3 are declined by the server if
4874 // offered in ClientHello. The runner's server will fail if this occurs,
4875 // so we exercise the offering path. (EMS and Renegotiation Info are
4876 // implicit in every test.)
4877 testCases = append(testCases, testCase{
4878 testType: serverTest,
4879 name: "ChannelID-Declined-TLS13",
4880 config: Config{
4881 MaxVersion: VersionTLS13,
4882 ChannelID: channelIDKey,
4883 },
4884 flags: []string{"-enable-channel-id"},
4885 })
4886 testCases = append(testCases, testCase{
4887 testType: serverTest,
4888 name: "NPN-Server",
4889 config: Config{
4890 MaxVersion: VersionTLS13,
4891 NextProtos: []string{"bar"},
4892 },
4893 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4894 })
David Benjamine78bfde2014-09-06 12:45:15 -04004895}
4896
David Benjamin01fe8202014-09-24 15:21:44 -04004897func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004898 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004899 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004900 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4901 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4902 // TLS 1.3 only shares ciphers with TLS 1.2, so
4903 // we skip certain combinations and use a
4904 // different cipher to test with.
4905 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4906 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4907 continue
4908 }
4909 }
4910
David Benjamin8b8c0062014-11-23 02:47:52 -05004911 protocols := []protocol{tls}
4912 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4913 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004914 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004915 for _, protocol := range protocols {
4916 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4917 if protocol == dtls {
4918 suffix += "-DTLS"
4919 }
4920
David Benjaminece3de92015-03-16 18:02:20 -04004921 if sessionVers.version == resumeVers.version {
4922 testCases = append(testCases, testCase{
4923 protocol: protocol,
4924 name: "Resume-Client" + suffix,
4925 resumeSession: true,
4926 config: Config{
4927 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004928 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004929 Bugs: ProtocolBugs{
4930 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4931 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4932 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004933 },
David Benjaminece3de92015-03-16 18:02:20 -04004934 expectedVersion: sessionVers.version,
4935 expectedResumeVersion: resumeVers.version,
4936 })
4937 } else {
David Benjamin405da482016-08-08 17:25:07 -04004938 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4939
4940 // Offering a TLS 1.3 session sends an empty session ID, so
4941 // there is no way to convince a non-lookahead client the
4942 // session was resumed. It will appear to the client that a
4943 // stray ChangeCipherSpec was sent.
4944 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4945 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004946 }
4947
David Benjaminece3de92015-03-16 18:02:20 -04004948 testCases = append(testCases, testCase{
4949 protocol: protocol,
4950 name: "Resume-Client-Mismatch" + suffix,
4951 resumeSession: true,
4952 config: Config{
4953 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004954 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004955 },
David Benjaminece3de92015-03-16 18:02:20 -04004956 expectedVersion: sessionVers.version,
4957 resumeConfig: &Config{
4958 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004959 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004960 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004961 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004962 },
4963 },
4964 expectedResumeVersion: resumeVers.version,
4965 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004966 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004967 })
4968 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004969
4970 testCases = append(testCases, testCase{
4971 protocol: protocol,
4972 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004973 resumeSession: true,
4974 config: Config{
4975 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004976 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004977 },
4978 expectedVersion: sessionVers.version,
4979 resumeConfig: &Config{
4980 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004981 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004982 },
4983 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004984 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004985 expectedResumeVersion: resumeVers.version,
4986 })
4987
David Benjamin8b8c0062014-11-23 02:47:52 -05004988 testCases = append(testCases, testCase{
4989 protocol: protocol,
4990 testType: serverTest,
4991 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004992 resumeSession: true,
4993 config: Config{
4994 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004995 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004996 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004997 expectedVersion: sessionVers.version,
4998 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004999 resumeConfig: &Config{
5000 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005001 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005002 Bugs: ProtocolBugs{
5003 SendBothTickets: true,
5004 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005005 },
5006 expectedResumeVersion: resumeVers.version,
5007 })
5008 }
David Benjamin01fe8202014-09-24 15:21:44 -04005009 }
5010 }
David Benjaminece3de92015-03-16 18:02:20 -04005011
5012 testCases = append(testCases, testCase{
5013 name: "Resume-Client-CipherMismatch",
5014 resumeSession: true,
5015 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005016 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005017 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5018 },
5019 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005020 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005021 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5022 Bugs: ProtocolBugs{
5023 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5024 },
5025 },
5026 shouldFail: true,
5027 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5028 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005029
5030 testCases = append(testCases, testCase{
5031 name: "Resume-Client-CipherMismatch-TLS13",
5032 resumeSession: true,
5033 config: Config{
5034 MaxVersion: VersionTLS13,
5035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5036 },
5037 resumeConfig: &Config{
5038 MaxVersion: VersionTLS13,
5039 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5040 Bugs: ProtocolBugs{
5041 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5042 },
5043 },
5044 shouldFail: true,
5045 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5046 })
David Benjamin01fe8202014-09-24 15:21:44 -04005047}
5048
Adam Langley2ae77d22014-10-28 17:29:33 -07005049func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005050 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005051 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005052 testType: serverTest,
5053 name: "Renegotiate-Server-Forbidden",
5054 config: Config{
5055 MaxVersion: VersionTLS12,
5056 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005057 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005058 shouldFail: true,
5059 expectedError: ":NO_RENEGOTIATION:",
5060 expectedLocalError: "remote error: no renegotiation",
5061 })
Adam Langley5021b222015-06-12 18:27:58 -07005062 // The server shouldn't echo the renegotiation extension unless
5063 // requested by the client.
5064 testCases = append(testCases, testCase{
5065 testType: serverTest,
5066 name: "Renegotiate-Server-NoExt",
5067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005068 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005069 Bugs: ProtocolBugs{
5070 NoRenegotiationInfo: true,
5071 RequireRenegotiationInfo: true,
5072 },
5073 },
5074 shouldFail: true,
5075 expectedLocalError: "renegotiation extension missing",
5076 })
5077 // The renegotiation SCSV should be sufficient for the server to echo
5078 // the extension.
5079 testCases = append(testCases, testCase{
5080 testType: serverTest,
5081 name: "Renegotiate-Server-NoExt-SCSV",
5082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005083 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005084 Bugs: ProtocolBugs{
5085 NoRenegotiationInfo: true,
5086 SendRenegotiationSCSV: true,
5087 RequireRenegotiationInfo: true,
5088 },
5089 },
5090 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005091 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005092 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005094 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005095 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005096 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005097 },
5098 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005099 renegotiate: 1,
5100 flags: []string{
5101 "-renegotiate-freely",
5102 "-expect-total-renegotiations", "1",
5103 },
David Benjamincdea40c2015-03-19 14:09:43 -04005104 })
5105 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005106 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005107 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005109 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005110 Bugs: ProtocolBugs{
5111 EmptyRenegotiationInfo: true,
5112 },
5113 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005114 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005115 shouldFail: true,
5116 expectedError: ":RENEGOTIATION_MISMATCH:",
5117 })
5118 testCases = append(testCases, testCase{
5119 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005120 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005122 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005123 Bugs: ProtocolBugs{
5124 BadRenegotiationInfo: true,
5125 },
5126 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005127 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005128 shouldFail: true,
5129 expectedError: ":RENEGOTIATION_MISMATCH:",
5130 })
5131 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005132 name: "Renegotiate-Client-Downgrade",
5133 renegotiate: 1,
5134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005135 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005136 Bugs: ProtocolBugs{
5137 NoRenegotiationInfoAfterInitial: true,
5138 },
5139 },
5140 flags: []string{"-renegotiate-freely"},
5141 shouldFail: true,
5142 expectedError: ":RENEGOTIATION_MISMATCH:",
5143 })
5144 testCases = append(testCases, testCase{
5145 name: "Renegotiate-Client-Upgrade",
5146 renegotiate: 1,
5147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005148 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005149 Bugs: ProtocolBugs{
5150 NoRenegotiationInfoInInitial: true,
5151 },
5152 },
5153 flags: []string{"-renegotiate-freely"},
5154 shouldFail: true,
5155 expectedError: ":RENEGOTIATION_MISMATCH:",
5156 })
5157 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005158 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005159 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005161 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005162 Bugs: ProtocolBugs{
5163 NoRenegotiationInfo: true,
5164 },
5165 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005166 flags: []string{
5167 "-renegotiate-freely",
5168 "-expect-total-renegotiations", "1",
5169 },
David Benjamincff0b902015-05-15 23:09:47 -04005170 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005171
5172 // Test that the server may switch ciphers on renegotiation without
5173 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005174 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005175 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005176 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005177 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005178 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005179 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5180 },
5181 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005182 flags: []string{
5183 "-renegotiate-freely",
5184 "-expect-total-renegotiations", "1",
5185 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005186 })
5187 testCases = append(testCases, testCase{
5188 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005189 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005190 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005191 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5193 },
5194 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005195 flags: []string{
5196 "-renegotiate-freely",
5197 "-expect-total-renegotiations", "1",
5198 },
David Benjaminb16346b2015-04-08 19:16:58 -04005199 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005200
5201 // Test that the server may not switch versions on renegotiation.
5202 testCases = append(testCases, testCase{
5203 name: "Renegotiate-Client-SwitchVersion",
5204 config: Config{
5205 MaxVersion: VersionTLS12,
5206 // Pick a cipher which exists at both versions.
5207 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5208 Bugs: ProtocolBugs{
5209 NegotiateVersionOnRenego: VersionTLS11,
5210 },
5211 },
5212 renegotiate: 1,
5213 flags: []string{
5214 "-renegotiate-freely",
5215 "-expect-total-renegotiations", "1",
5216 },
5217 shouldFail: true,
5218 expectedError: ":WRONG_SSL_VERSION:",
5219 })
5220
David Benjaminb16346b2015-04-08 19:16:58 -04005221 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005222 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005223 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005224 config: Config{
5225 MaxVersion: VersionTLS10,
5226 Bugs: ProtocolBugs{
5227 RequireSameRenegoClientVersion: true,
5228 },
5229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005230 flags: []string{
5231 "-renegotiate-freely",
5232 "-expect-total-renegotiations", "1",
5233 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005234 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005235 testCases = append(testCases, testCase{
5236 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005237 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005238 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005239 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005240 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5241 NextProtos: []string{"foo"},
5242 },
5243 flags: []string{
5244 "-false-start",
5245 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005246 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005247 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005248 },
5249 shimWritesFirst: true,
5250 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005251
5252 // Client-side renegotiation controls.
5253 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005254 name: "Renegotiate-Client-Forbidden-1",
5255 config: Config{
5256 MaxVersion: VersionTLS12,
5257 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005258 renegotiate: 1,
5259 shouldFail: true,
5260 expectedError: ":NO_RENEGOTIATION:",
5261 expectedLocalError: "remote error: no renegotiation",
5262 })
5263 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005264 name: "Renegotiate-Client-Once-1",
5265 config: Config{
5266 MaxVersion: VersionTLS12,
5267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005268 renegotiate: 1,
5269 flags: []string{
5270 "-renegotiate-once",
5271 "-expect-total-renegotiations", "1",
5272 },
5273 })
5274 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005275 name: "Renegotiate-Client-Freely-1",
5276 config: Config{
5277 MaxVersion: VersionTLS12,
5278 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005279 renegotiate: 1,
5280 flags: []string{
5281 "-renegotiate-freely",
5282 "-expect-total-renegotiations", "1",
5283 },
5284 })
5285 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005286 name: "Renegotiate-Client-Once-2",
5287 config: Config{
5288 MaxVersion: VersionTLS12,
5289 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005290 renegotiate: 2,
5291 flags: []string{"-renegotiate-once"},
5292 shouldFail: true,
5293 expectedError: ":NO_RENEGOTIATION:",
5294 expectedLocalError: "remote error: no renegotiation",
5295 })
5296 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005297 name: "Renegotiate-Client-Freely-2",
5298 config: Config{
5299 MaxVersion: VersionTLS12,
5300 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005301 renegotiate: 2,
5302 flags: []string{
5303 "-renegotiate-freely",
5304 "-expect-total-renegotiations", "2",
5305 },
5306 })
Adam Langley27a0d082015-11-03 13:34:10 -08005307 testCases = append(testCases, testCase{
5308 name: "Renegotiate-Client-NoIgnore",
5309 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005310 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005311 Bugs: ProtocolBugs{
5312 SendHelloRequestBeforeEveryAppDataRecord: true,
5313 },
5314 },
5315 shouldFail: true,
5316 expectedError: ":NO_RENEGOTIATION:",
5317 })
5318 testCases = append(testCases, testCase{
5319 name: "Renegotiate-Client-Ignore",
5320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005321 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005322 Bugs: ProtocolBugs{
5323 SendHelloRequestBeforeEveryAppDataRecord: true,
5324 },
5325 },
5326 flags: []string{
5327 "-renegotiate-ignore",
5328 "-expect-total-renegotiations", "0",
5329 },
5330 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005331
David Benjamin397c8e62016-07-08 14:14:36 -07005332 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005333 testCases = append(testCases, testCase{
5334 name: "StrayHelloRequest",
5335 config: Config{
5336 MaxVersion: VersionTLS12,
5337 Bugs: ProtocolBugs{
5338 SendHelloRequestBeforeEveryHandshakeMessage: true,
5339 },
5340 },
5341 })
5342 testCases = append(testCases, testCase{
5343 name: "StrayHelloRequest-Packed",
5344 config: Config{
5345 MaxVersion: VersionTLS12,
5346 Bugs: ProtocolBugs{
5347 PackHandshakeFlight: true,
5348 SendHelloRequestBeforeEveryHandshakeMessage: true,
5349 },
5350 },
5351 })
5352
David Benjamin12d2c482016-07-24 10:56:51 -04005353 // Test renegotiation works if HelloRequest and server Finished come in
5354 // the same record.
5355 testCases = append(testCases, testCase{
5356 name: "Renegotiate-Client-Packed",
5357 config: Config{
5358 MaxVersion: VersionTLS12,
5359 Bugs: ProtocolBugs{
5360 PackHandshakeFlight: true,
5361 PackHelloRequestWithFinished: true,
5362 },
5363 },
5364 renegotiate: 1,
5365 flags: []string{
5366 "-renegotiate-freely",
5367 "-expect-total-renegotiations", "1",
5368 },
5369 })
5370
David Benjamin397c8e62016-07-08 14:14:36 -07005371 // Renegotiation is forbidden in TLS 1.3.
5372 testCases = append(testCases, testCase{
5373 name: "Renegotiate-Client-TLS13",
5374 config: Config{
5375 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005376 Bugs: ProtocolBugs{
5377 SendHelloRequestBeforeEveryAppDataRecord: true,
5378 },
David Benjamin397c8e62016-07-08 14:14:36 -07005379 },
David Benjamin397c8e62016-07-08 14:14:36 -07005380 flags: []string{
5381 "-renegotiate-freely",
5382 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005383 shouldFail: true,
5384 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005385 })
5386
5387 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5388 testCases = append(testCases, testCase{
5389 name: "StrayHelloRequest-TLS13",
5390 config: Config{
5391 MaxVersion: VersionTLS13,
5392 Bugs: ProtocolBugs{
5393 SendHelloRequestBeforeEveryHandshakeMessage: true,
5394 },
5395 },
5396 shouldFail: true,
5397 expectedError: ":UNEXPECTED_MESSAGE:",
5398 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005399}
5400
David Benjamin5e961c12014-11-07 01:48:35 -05005401func addDTLSReplayTests() {
5402 // Test that sequence number replays are detected.
5403 testCases = append(testCases, testCase{
5404 protocol: dtls,
5405 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005406 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005407 replayWrites: true,
5408 })
5409
David Benjamin8e6db492015-07-25 18:29:23 -04005410 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005411 // than the retransmit window.
5412 testCases = append(testCases, testCase{
5413 protocol: dtls,
5414 name: "DTLS-Replay-LargeGaps",
5415 config: Config{
5416 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005417 SequenceNumberMapping: func(in uint64) uint64 {
5418 return in * 127
5419 },
David Benjamin5e961c12014-11-07 01:48:35 -05005420 },
5421 },
David Benjamin8e6db492015-07-25 18:29:23 -04005422 messageCount: 200,
5423 replayWrites: true,
5424 })
5425
5426 // Test the incoming sequence number changing non-monotonically.
5427 testCases = append(testCases, testCase{
5428 protocol: dtls,
5429 name: "DTLS-Replay-NonMonotonic",
5430 config: Config{
5431 Bugs: ProtocolBugs{
5432 SequenceNumberMapping: func(in uint64) uint64 {
5433 return in ^ 31
5434 },
5435 },
5436 },
5437 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005438 replayWrites: true,
5439 })
5440}
5441
Nick Harper60edffd2016-06-21 15:19:24 -07005442var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005443 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005444 id signatureAlgorithm
5445 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005446}{
Nick Harper60edffd2016-06-21 15:19:24 -07005447 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5448 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5449 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5450 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005451 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005452 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5453 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5454 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005455 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5456 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5457 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005458 // Tests for key types prior to TLS 1.2.
5459 {"RSA", 0, testCertRSA},
5460 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005461}
5462
Nick Harper60edffd2016-06-21 15:19:24 -07005463const fakeSigAlg1 signatureAlgorithm = 0x2a01
5464const fakeSigAlg2 signatureAlgorithm = 0xff01
5465
5466func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005467 // Not all ciphers involve a signature. Advertise a list which gives all
5468 // versions a signing cipher.
5469 signingCiphers := []uint16{
5470 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5471 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5472 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5473 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5474 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5475 }
5476
David Benjaminca3d5452016-07-14 12:51:01 -04005477 var allAlgorithms []signatureAlgorithm
5478 for _, alg := range testSignatureAlgorithms {
5479 if alg.id != 0 {
5480 allAlgorithms = append(allAlgorithms, alg.id)
5481 }
5482 }
5483
Nick Harper60edffd2016-06-21 15:19:24 -07005484 // Make sure each signature algorithm works. Include some fake values in
5485 // the list and ensure they're ignored.
5486 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005487 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005488 if (ver.version < VersionTLS12) != (alg.id == 0) {
5489 continue
5490 }
5491
5492 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5493 // or remove it in C.
5494 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005495 continue
5496 }
Nick Harper60edffd2016-06-21 15:19:24 -07005497
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005498 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005499 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005500 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5501 shouldFail = true
5502 }
5503 // RSA-PSS does not exist in TLS 1.2.
5504 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5505 shouldFail = true
5506 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005507 // RSA-PKCS1 does not exist in TLS 1.3.
5508 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5509 shouldFail = true
5510 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005511
5512 var signError, verifyError string
5513 if shouldFail {
5514 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5515 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005516 }
David Benjamin000800a2014-11-14 01:43:59 -05005517
David Benjamin1fb125c2016-07-08 18:52:12 -07005518 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005519
David Benjamin7a41d372016-07-09 11:21:54 -07005520 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005521 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005522 config: Config{
5523 MaxVersion: ver.version,
5524 ClientAuth: RequireAnyClientCert,
5525 VerifySignatureAlgorithms: []signatureAlgorithm{
5526 fakeSigAlg1,
5527 alg.id,
5528 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005529 },
David Benjamin7a41d372016-07-09 11:21:54 -07005530 },
5531 flags: []string{
5532 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5533 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5534 "-enable-all-curves",
5535 },
5536 shouldFail: shouldFail,
5537 expectedError: signError,
5538 expectedPeerSignatureAlgorithm: alg.id,
5539 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005540
David Benjamin7a41d372016-07-09 11:21:54 -07005541 testCases = append(testCases, testCase{
5542 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005543 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005544 config: Config{
5545 MaxVersion: ver.version,
5546 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5547 SignSignatureAlgorithms: []signatureAlgorithm{
5548 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005549 },
David Benjamin7a41d372016-07-09 11:21:54 -07005550 Bugs: ProtocolBugs{
5551 SkipECDSACurveCheck: shouldFail,
5552 IgnoreSignatureVersionChecks: shouldFail,
5553 // The client won't advertise 1.3-only algorithms after
5554 // version negotiation.
5555 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005556 },
David Benjamin7a41d372016-07-09 11:21:54 -07005557 },
5558 flags: []string{
5559 "-require-any-client-certificate",
5560 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5561 "-enable-all-curves",
5562 },
5563 shouldFail: shouldFail,
5564 expectedError: verifyError,
5565 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005566
5567 testCases = append(testCases, testCase{
5568 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005569 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005570 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005571 MaxVersion: ver.version,
5572 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005573 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005574 fakeSigAlg1,
5575 alg.id,
5576 fakeSigAlg2,
5577 },
5578 },
5579 flags: []string{
5580 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5581 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5582 "-enable-all-curves",
5583 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005584 shouldFail: shouldFail,
5585 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005586 expectedPeerSignatureAlgorithm: alg.id,
5587 })
5588
5589 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005590 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005591 config: Config{
5592 MaxVersion: ver.version,
5593 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005594 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005595 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005596 alg.id,
5597 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005598 Bugs: ProtocolBugs{
5599 SkipECDSACurveCheck: shouldFail,
5600 IgnoreSignatureVersionChecks: shouldFail,
5601 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005602 },
5603 flags: []string{
5604 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5605 "-enable-all-curves",
5606 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005607 shouldFail: shouldFail,
5608 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005609 })
David Benjamin5208fd42016-07-13 21:43:25 -04005610
5611 if !shouldFail {
5612 testCases = append(testCases, testCase{
5613 testType: serverTest,
5614 name: "ClientAuth-InvalidSignature" + suffix,
5615 config: Config{
5616 MaxVersion: ver.version,
5617 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5618 SignSignatureAlgorithms: []signatureAlgorithm{
5619 alg.id,
5620 },
5621 Bugs: ProtocolBugs{
5622 InvalidSignature: true,
5623 },
5624 },
5625 flags: []string{
5626 "-require-any-client-certificate",
5627 "-enable-all-curves",
5628 },
5629 shouldFail: true,
5630 expectedError: ":BAD_SIGNATURE:",
5631 })
5632
5633 testCases = append(testCases, testCase{
5634 name: "ServerAuth-InvalidSignature" + suffix,
5635 config: Config{
5636 MaxVersion: ver.version,
5637 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5638 CipherSuites: signingCiphers,
5639 SignSignatureAlgorithms: []signatureAlgorithm{
5640 alg.id,
5641 },
5642 Bugs: ProtocolBugs{
5643 InvalidSignature: true,
5644 },
5645 },
5646 flags: []string{"-enable-all-curves"},
5647 shouldFail: true,
5648 expectedError: ":BAD_SIGNATURE:",
5649 })
5650 }
David Benjaminca3d5452016-07-14 12:51:01 -04005651
5652 if ver.version >= VersionTLS12 && !shouldFail {
5653 testCases = append(testCases, testCase{
5654 name: "ClientAuth-Sign-Negotiate" + suffix,
5655 config: Config{
5656 MaxVersion: ver.version,
5657 ClientAuth: RequireAnyClientCert,
5658 VerifySignatureAlgorithms: allAlgorithms,
5659 },
5660 flags: []string{
5661 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5662 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5663 "-enable-all-curves",
5664 "-signing-prefs", strconv.Itoa(int(alg.id)),
5665 },
5666 expectedPeerSignatureAlgorithm: alg.id,
5667 })
5668
5669 testCases = append(testCases, testCase{
5670 testType: serverTest,
5671 name: "ServerAuth-Sign-Negotiate" + suffix,
5672 config: Config{
5673 MaxVersion: ver.version,
5674 CipherSuites: signingCiphers,
5675 VerifySignatureAlgorithms: allAlgorithms,
5676 },
5677 flags: []string{
5678 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5679 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5680 "-enable-all-curves",
5681 "-signing-prefs", strconv.Itoa(int(alg.id)),
5682 },
5683 expectedPeerSignatureAlgorithm: alg.id,
5684 })
5685 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005686 }
David Benjamin000800a2014-11-14 01:43:59 -05005687 }
5688
Nick Harper60edffd2016-06-21 15:19:24 -07005689 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005690 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005691 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005692 config: Config{
5693 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005694 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005695 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005696 signatureECDSAWithP521AndSHA512,
5697 signatureRSAPKCS1WithSHA384,
5698 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005699 },
5700 },
5701 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005702 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5703 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005704 },
Nick Harper60edffd2016-06-21 15:19:24 -07005705 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005706 })
5707
5708 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005709 name: "ClientAuth-SignatureType-TLS13",
5710 config: Config{
5711 ClientAuth: RequireAnyClientCert,
5712 MaxVersion: VersionTLS13,
5713 VerifySignatureAlgorithms: []signatureAlgorithm{
5714 signatureECDSAWithP521AndSHA512,
5715 signatureRSAPKCS1WithSHA384,
5716 signatureRSAPSSWithSHA384,
5717 signatureECDSAWithSHA1,
5718 },
5719 },
5720 flags: []string{
5721 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5722 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5723 },
5724 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5725 })
5726
5727 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005728 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005729 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005731 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005732 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005733 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005734 signatureECDSAWithP521AndSHA512,
5735 signatureRSAPKCS1WithSHA384,
5736 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005737 },
5738 },
Nick Harper60edffd2016-06-21 15:19:24 -07005739 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005740 })
5741
Steven Valdez143e8b32016-07-11 13:19:03 -04005742 testCases = append(testCases, testCase{
5743 testType: serverTest,
5744 name: "ServerAuth-SignatureType-TLS13",
5745 config: Config{
5746 MaxVersion: VersionTLS13,
5747 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5748 VerifySignatureAlgorithms: []signatureAlgorithm{
5749 signatureECDSAWithP521AndSHA512,
5750 signatureRSAPKCS1WithSHA384,
5751 signatureRSAPSSWithSHA384,
5752 signatureECDSAWithSHA1,
5753 },
5754 },
5755 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5756 })
5757
David Benjamina95e9f32016-07-08 16:28:04 -07005758 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005759 testCases = append(testCases, testCase{
5760 testType: serverTest,
5761 name: "Verify-ClientAuth-SignatureType",
5762 config: Config{
5763 MaxVersion: VersionTLS12,
5764 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005765 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005766 signatureRSAPKCS1WithSHA256,
5767 },
5768 Bugs: ProtocolBugs{
5769 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5770 },
5771 },
5772 flags: []string{
5773 "-require-any-client-certificate",
5774 },
5775 shouldFail: true,
5776 expectedError: ":WRONG_SIGNATURE_TYPE:",
5777 })
5778
5779 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005780 testType: serverTest,
5781 name: "Verify-ClientAuth-SignatureType-TLS13",
5782 config: Config{
5783 MaxVersion: VersionTLS13,
5784 Certificates: []Certificate{rsaCertificate},
5785 SignSignatureAlgorithms: []signatureAlgorithm{
5786 signatureRSAPSSWithSHA256,
5787 },
5788 Bugs: ProtocolBugs{
5789 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5790 },
5791 },
5792 flags: []string{
5793 "-require-any-client-certificate",
5794 },
5795 shouldFail: true,
5796 expectedError: ":WRONG_SIGNATURE_TYPE:",
5797 })
5798
5799 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005800 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005801 config: Config{
5802 MaxVersion: VersionTLS12,
5803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005804 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005805 signatureRSAPKCS1WithSHA256,
5806 },
5807 Bugs: ProtocolBugs{
5808 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5809 },
5810 },
5811 shouldFail: true,
5812 expectedError: ":WRONG_SIGNATURE_TYPE:",
5813 })
5814
Steven Valdez143e8b32016-07-11 13:19:03 -04005815 testCases = append(testCases, testCase{
5816 name: "Verify-ServerAuth-SignatureType-TLS13",
5817 config: Config{
5818 MaxVersion: VersionTLS13,
5819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5820 SignSignatureAlgorithms: []signatureAlgorithm{
5821 signatureRSAPSSWithSHA256,
5822 },
5823 Bugs: ProtocolBugs{
5824 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5825 },
5826 },
5827 shouldFail: true,
5828 expectedError: ":WRONG_SIGNATURE_TYPE:",
5829 })
5830
David Benjamin51dd7d62016-07-08 16:07:01 -07005831 // Test that, if the list is missing, the peer falls back to SHA-1 in
5832 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005833 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005834 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005835 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005836 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005837 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005838 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005839 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005840 },
5841 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005842 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005843 },
5844 },
5845 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005846 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5847 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005848 },
5849 })
5850
5851 testCases = append(testCases, testCase{
5852 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005853 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005854 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005855 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005856 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005857 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005858 },
5859 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005860 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005861 },
5862 },
David Benjaminee32bea2016-08-17 13:36:44 -04005863 flags: []string{
5864 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5865 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5866 },
5867 })
5868
5869 testCases = append(testCases, testCase{
5870 name: "ClientAuth-SHA1-Fallback-ECDSA",
5871 config: Config{
5872 MaxVersion: VersionTLS12,
5873 ClientAuth: RequireAnyClientCert,
5874 VerifySignatureAlgorithms: []signatureAlgorithm{
5875 signatureECDSAWithSHA1,
5876 },
5877 Bugs: ProtocolBugs{
5878 NoSignatureAlgorithms: true,
5879 },
5880 },
5881 flags: []string{
5882 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5883 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5884 },
5885 })
5886
5887 testCases = append(testCases, testCase{
5888 testType: serverTest,
5889 name: "ServerAuth-SHA1-Fallback-ECDSA",
5890 config: Config{
5891 MaxVersion: VersionTLS12,
5892 VerifySignatureAlgorithms: []signatureAlgorithm{
5893 signatureECDSAWithSHA1,
5894 },
5895 Bugs: ProtocolBugs{
5896 NoSignatureAlgorithms: true,
5897 },
5898 },
5899 flags: []string{
5900 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5901 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5902 },
David Benjamin000800a2014-11-14 01:43:59 -05005903 })
David Benjamin72dc7832015-03-16 17:49:43 -04005904
David Benjamin51dd7d62016-07-08 16:07:01 -07005905 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005906 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005907 config: Config{
5908 MaxVersion: VersionTLS13,
5909 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005910 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005911 signatureRSAPKCS1WithSHA1,
5912 },
5913 Bugs: ProtocolBugs{
5914 NoSignatureAlgorithms: true,
5915 },
5916 },
5917 flags: []string{
5918 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5919 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5920 },
David Benjamin48901652016-08-01 12:12:47 -04005921 shouldFail: true,
5922 // An empty CertificateRequest signature algorithm list is a
5923 // syntax error in TLS 1.3.
5924 expectedError: ":DECODE_ERROR:",
5925 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005926 })
5927
5928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005930 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005934 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005935 signatureRSAPKCS1WithSHA1,
5936 },
5937 Bugs: ProtocolBugs{
5938 NoSignatureAlgorithms: true,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5943 })
5944
David Benjaminb62d2872016-07-18 14:55:02 +02005945 // Test that hash preferences are enforced. BoringSSL does not implement
5946 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005947 testCases = append(testCases, testCase{
5948 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005949 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005951 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005952 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005953 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005954 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005955 },
5956 Bugs: ProtocolBugs{
5957 IgnorePeerSignatureAlgorithmPreferences: true,
5958 },
5959 },
5960 flags: []string{"-require-any-client-certificate"},
5961 shouldFail: true,
5962 expectedError: ":WRONG_SIGNATURE_TYPE:",
5963 })
5964
5965 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005966 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005968 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005969 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005970 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005971 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005972 },
5973 Bugs: ProtocolBugs{
5974 IgnorePeerSignatureAlgorithmPreferences: true,
5975 },
5976 },
5977 shouldFail: true,
5978 expectedError: ":WRONG_SIGNATURE_TYPE:",
5979 })
David Benjaminb62d2872016-07-18 14:55:02 +02005980 testCases = append(testCases, testCase{
5981 testType: serverTest,
5982 name: "ClientAuth-Enforced-TLS13",
5983 config: Config{
5984 MaxVersion: VersionTLS13,
5985 Certificates: []Certificate{rsaCertificate},
5986 SignSignatureAlgorithms: []signatureAlgorithm{
5987 signatureRSAPKCS1WithMD5,
5988 },
5989 Bugs: ProtocolBugs{
5990 IgnorePeerSignatureAlgorithmPreferences: true,
5991 IgnoreSignatureVersionChecks: true,
5992 },
5993 },
5994 flags: []string{"-require-any-client-certificate"},
5995 shouldFail: true,
5996 expectedError: ":WRONG_SIGNATURE_TYPE:",
5997 })
5998
5999 testCases = append(testCases, testCase{
6000 name: "ServerAuth-Enforced-TLS13",
6001 config: Config{
6002 MaxVersion: VersionTLS13,
6003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6004 SignSignatureAlgorithms: []signatureAlgorithm{
6005 signatureRSAPKCS1WithMD5,
6006 },
6007 Bugs: ProtocolBugs{
6008 IgnorePeerSignatureAlgorithmPreferences: true,
6009 IgnoreSignatureVersionChecks: true,
6010 },
6011 },
6012 shouldFail: true,
6013 expectedError: ":WRONG_SIGNATURE_TYPE:",
6014 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006015
6016 // Test that the agreed upon digest respects the client preferences and
6017 // the server digests.
6018 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006019 name: "NoCommonAlgorithms-Digests",
6020 config: Config{
6021 MaxVersion: VersionTLS12,
6022 ClientAuth: RequireAnyClientCert,
6023 VerifySignatureAlgorithms: []signatureAlgorithm{
6024 signatureRSAPKCS1WithSHA512,
6025 signatureRSAPKCS1WithSHA1,
6026 },
6027 },
6028 flags: []string{
6029 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6030 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6031 "-digest-prefs", "SHA256",
6032 },
6033 shouldFail: true,
6034 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6035 })
6036 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006037 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006039 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006040 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006041 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006042 signatureRSAPKCS1WithSHA512,
6043 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006044 },
6045 },
6046 flags: []string{
6047 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6048 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006049 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006050 },
David Benjaminca3d5452016-07-14 12:51:01 -04006051 shouldFail: true,
6052 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6053 })
6054 testCases = append(testCases, testCase{
6055 name: "NoCommonAlgorithms-TLS13",
6056 config: Config{
6057 MaxVersion: VersionTLS13,
6058 ClientAuth: RequireAnyClientCert,
6059 VerifySignatureAlgorithms: []signatureAlgorithm{
6060 signatureRSAPSSWithSHA512,
6061 signatureRSAPSSWithSHA384,
6062 },
6063 },
6064 flags: []string{
6065 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6066 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6067 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6068 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006069 shouldFail: true,
6070 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006071 })
6072 testCases = append(testCases, testCase{
6073 name: "Agree-Digest-SHA256",
6074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006075 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006076 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006077 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006078 signatureRSAPKCS1WithSHA1,
6079 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006080 },
6081 },
6082 flags: []string{
6083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006085 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006086 },
Nick Harper60edffd2016-06-21 15:19:24 -07006087 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006088 })
6089 testCases = append(testCases, testCase{
6090 name: "Agree-Digest-SHA1",
6091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006092 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006093 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006094 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006095 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006096 },
6097 },
6098 flags: []string{
6099 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6100 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006101 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006102 },
Nick Harper60edffd2016-06-21 15:19:24 -07006103 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006104 })
6105 testCases = append(testCases, testCase{
6106 name: "Agree-Digest-Default",
6107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006108 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006109 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006110 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006111 signatureRSAPKCS1WithSHA256,
6112 signatureECDSAWithP256AndSHA256,
6113 signatureRSAPKCS1WithSHA1,
6114 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006115 },
6116 },
6117 flags: []string{
6118 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6119 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6120 },
Nick Harper60edffd2016-06-21 15:19:24 -07006121 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006122 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006123
David Benjaminca3d5452016-07-14 12:51:01 -04006124 // Test that the signing preference list may include extra algorithms
6125 // without negotiation problems.
6126 testCases = append(testCases, testCase{
6127 testType: serverTest,
6128 name: "FilterExtraAlgorithms",
6129 config: Config{
6130 MaxVersion: VersionTLS12,
6131 VerifySignatureAlgorithms: []signatureAlgorithm{
6132 signatureRSAPKCS1WithSHA256,
6133 },
6134 },
6135 flags: []string{
6136 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6137 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6138 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6139 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6140 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6141 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6142 },
6143 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6144 })
6145
David Benjamin4c3ddf72016-06-29 18:13:53 -04006146 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6147 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006148 testCases = append(testCases, testCase{
6149 name: "CheckLeafCurve",
6150 config: Config{
6151 MaxVersion: VersionTLS12,
6152 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006153 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006154 },
6155 flags: []string{"-p384-only"},
6156 shouldFail: true,
6157 expectedError: ":BAD_ECC_CERT:",
6158 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006159
6160 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6161 testCases = append(testCases, testCase{
6162 name: "CheckLeafCurve-TLS13",
6163 config: Config{
6164 MaxVersion: VersionTLS13,
6165 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6166 Certificates: []Certificate{ecdsaP256Certificate},
6167 },
6168 flags: []string{"-p384-only"},
6169 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006170
6171 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6172 testCases = append(testCases, testCase{
6173 name: "ECDSACurveMismatch-Verify-TLS12",
6174 config: Config{
6175 MaxVersion: VersionTLS12,
6176 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6177 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006178 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006179 signatureECDSAWithP384AndSHA384,
6180 },
6181 },
6182 })
6183
6184 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6185 testCases = append(testCases, testCase{
6186 name: "ECDSACurveMismatch-Verify-TLS13",
6187 config: Config{
6188 MaxVersion: VersionTLS13,
6189 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6190 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006191 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006192 signatureECDSAWithP384AndSHA384,
6193 },
6194 Bugs: ProtocolBugs{
6195 SkipECDSACurveCheck: true,
6196 },
6197 },
6198 shouldFail: true,
6199 expectedError: ":WRONG_SIGNATURE_TYPE:",
6200 })
6201
6202 // Signature algorithm selection in TLS 1.3 should take the curve into
6203 // account.
6204 testCases = append(testCases, testCase{
6205 testType: serverTest,
6206 name: "ECDSACurveMismatch-Sign-TLS13",
6207 config: Config{
6208 MaxVersion: VersionTLS13,
6209 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006210 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006211 signatureECDSAWithP384AndSHA384,
6212 signatureECDSAWithP256AndSHA256,
6213 },
6214 },
6215 flags: []string{
6216 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6217 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6218 },
6219 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6220 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006221
6222 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6223 // server does not attempt to sign in that case.
6224 testCases = append(testCases, testCase{
6225 testType: serverTest,
6226 name: "RSA-PSS-Large",
6227 config: Config{
6228 MaxVersion: VersionTLS13,
6229 VerifySignatureAlgorithms: []signatureAlgorithm{
6230 signatureRSAPSSWithSHA512,
6231 },
6232 },
6233 flags: []string{
6234 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6235 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6236 },
6237 shouldFail: true,
6238 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6239 })
David Benjamin000800a2014-11-14 01:43:59 -05006240}
6241
David Benjamin83f90402015-01-27 01:09:43 -05006242// timeouts is the retransmit schedule for BoringSSL. It doubles and
6243// caps at 60 seconds. On the 13th timeout, it gives up.
6244var timeouts = []time.Duration{
6245 1 * time.Second,
6246 2 * time.Second,
6247 4 * time.Second,
6248 8 * time.Second,
6249 16 * time.Second,
6250 32 * time.Second,
6251 60 * time.Second,
6252 60 * time.Second,
6253 60 * time.Second,
6254 60 * time.Second,
6255 60 * time.Second,
6256 60 * time.Second,
6257 60 * time.Second,
6258}
6259
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006260// shortTimeouts is an alternate set of timeouts which would occur if the
6261// initial timeout duration was set to 250ms.
6262var shortTimeouts = []time.Duration{
6263 250 * time.Millisecond,
6264 500 * time.Millisecond,
6265 1 * time.Second,
6266 2 * time.Second,
6267 4 * time.Second,
6268 8 * time.Second,
6269 16 * time.Second,
6270 32 * time.Second,
6271 60 * time.Second,
6272 60 * time.Second,
6273 60 * time.Second,
6274 60 * time.Second,
6275 60 * time.Second,
6276}
6277
David Benjamin83f90402015-01-27 01:09:43 -05006278func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006279 // These tests work by coordinating some behavior on both the shim and
6280 // the runner.
6281 //
6282 // TimeoutSchedule configures the runner to send a series of timeout
6283 // opcodes to the shim (see packetAdaptor) immediately before reading
6284 // each peer handshake flight N. The timeout opcode both simulates a
6285 // timeout in the shim and acts as a synchronization point to help the
6286 // runner bracket each handshake flight.
6287 //
6288 // We assume the shim does not read from the channel eagerly. It must
6289 // first wait until it has sent flight N and is ready to receive
6290 // handshake flight N+1. At this point, it will process the timeout
6291 // opcode. It must then immediately respond with a timeout ACK and act
6292 // as if the shim was idle for the specified amount of time.
6293 //
6294 // The runner then drops all packets received before the ACK and
6295 // continues waiting for flight N. This ordering results in one attempt
6296 // at sending flight N to be dropped. For the test to complete, the
6297 // shim must send flight N again, testing that the shim implements DTLS
6298 // retransmit on a timeout.
6299
Steven Valdez143e8b32016-07-11 13:19:03 -04006300 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006301 // likely be more epochs to cross and the final message's retransmit may
6302 // be more complex.
6303
David Benjamin585d7a42016-06-02 14:58:00 -04006304 for _, async := range []bool{true, false} {
6305 var tests []testCase
6306
6307 // Test that this is indeed the timeout schedule. Stress all
6308 // four patterns of handshake.
6309 for i := 1; i < len(timeouts); i++ {
6310 number := strconv.Itoa(i)
6311 tests = append(tests, testCase{
6312 protocol: dtls,
6313 name: "DTLS-Retransmit-Client-" + number,
6314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006315 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006316 Bugs: ProtocolBugs{
6317 TimeoutSchedule: timeouts[:i],
6318 },
6319 },
6320 resumeSession: true,
6321 })
6322 tests = append(tests, testCase{
6323 protocol: dtls,
6324 testType: serverTest,
6325 name: "DTLS-Retransmit-Server-" + number,
6326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006327 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006328 Bugs: ProtocolBugs{
6329 TimeoutSchedule: timeouts[:i],
6330 },
6331 },
6332 resumeSession: true,
6333 })
6334 }
6335
6336 // Test that exceeding the timeout schedule hits a read
6337 // timeout.
6338 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006339 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006340 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006342 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006343 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006344 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006345 },
6346 },
6347 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006348 shouldFail: true,
6349 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006350 })
David Benjamin585d7a42016-06-02 14:58:00 -04006351
6352 if async {
6353 // Test that timeout handling has a fudge factor, due to API
6354 // problems.
6355 tests = append(tests, testCase{
6356 protocol: dtls,
6357 name: "DTLS-Retransmit-Fudge",
6358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006359 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006360 Bugs: ProtocolBugs{
6361 TimeoutSchedule: []time.Duration{
6362 timeouts[0] - 10*time.Millisecond,
6363 },
6364 },
6365 },
6366 resumeSession: true,
6367 })
6368 }
6369
6370 // Test that the final Finished retransmitting isn't
6371 // duplicated if the peer badly fragments everything.
6372 tests = append(tests, testCase{
6373 testType: serverTest,
6374 protocol: dtls,
6375 name: "DTLS-Retransmit-Fragmented",
6376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006377 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006378 Bugs: ProtocolBugs{
6379 TimeoutSchedule: []time.Duration{timeouts[0]},
6380 MaxHandshakeRecordLength: 2,
6381 },
6382 },
6383 })
6384
6385 // Test the timeout schedule when a shorter initial timeout duration is set.
6386 tests = append(tests, testCase{
6387 protocol: dtls,
6388 name: "DTLS-Retransmit-Short-Client",
6389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006390 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006391 Bugs: ProtocolBugs{
6392 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6393 },
6394 },
6395 resumeSession: true,
6396 flags: []string{"-initial-timeout-duration-ms", "250"},
6397 })
6398 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006399 protocol: dtls,
6400 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006401 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006403 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006404 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006405 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006406 },
6407 },
6408 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006409 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006410 })
David Benjamin585d7a42016-06-02 14:58:00 -04006411
6412 for _, test := range tests {
6413 if async {
6414 test.name += "-Async"
6415 test.flags = append(test.flags, "-async")
6416 }
6417
6418 testCases = append(testCases, test)
6419 }
David Benjamin83f90402015-01-27 01:09:43 -05006420 }
David Benjamin83f90402015-01-27 01:09:43 -05006421}
6422
David Benjaminc565ebb2015-04-03 04:06:36 -04006423func addExportKeyingMaterialTests() {
6424 for _, vers := range tlsVersions {
6425 if vers.version == VersionSSL30 {
6426 continue
6427 }
6428 testCases = append(testCases, testCase{
6429 name: "ExportKeyingMaterial-" + vers.name,
6430 config: Config{
6431 MaxVersion: vers.version,
6432 },
6433 exportKeyingMaterial: 1024,
6434 exportLabel: "label",
6435 exportContext: "context",
6436 useExportContext: true,
6437 })
6438 testCases = append(testCases, testCase{
6439 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6440 config: Config{
6441 MaxVersion: vers.version,
6442 },
6443 exportKeyingMaterial: 1024,
6444 })
6445 testCases = append(testCases, testCase{
6446 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6447 config: Config{
6448 MaxVersion: vers.version,
6449 },
6450 exportKeyingMaterial: 1024,
6451 useExportContext: true,
6452 })
6453 testCases = append(testCases, testCase{
6454 name: "ExportKeyingMaterial-Small-" + vers.name,
6455 config: Config{
6456 MaxVersion: vers.version,
6457 },
6458 exportKeyingMaterial: 1,
6459 exportLabel: "label",
6460 exportContext: "context",
6461 useExportContext: true,
6462 })
6463 }
6464 testCases = append(testCases, testCase{
6465 name: "ExportKeyingMaterial-SSL3",
6466 config: Config{
6467 MaxVersion: VersionSSL30,
6468 },
6469 exportKeyingMaterial: 1024,
6470 exportLabel: "label",
6471 exportContext: "context",
6472 useExportContext: true,
6473 shouldFail: true,
6474 expectedError: "failed to export keying material",
6475 })
6476}
6477
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006478func addTLSUniqueTests() {
6479 for _, isClient := range []bool{false, true} {
6480 for _, isResumption := range []bool{false, true} {
6481 for _, hasEMS := range []bool{false, true} {
6482 var suffix string
6483 if isResumption {
6484 suffix = "Resume-"
6485 } else {
6486 suffix = "Full-"
6487 }
6488
6489 if hasEMS {
6490 suffix += "EMS-"
6491 } else {
6492 suffix += "NoEMS-"
6493 }
6494
6495 if isClient {
6496 suffix += "Client"
6497 } else {
6498 suffix += "Server"
6499 }
6500
6501 test := testCase{
6502 name: "TLSUnique-" + suffix,
6503 testTLSUnique: true,
6504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006505 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006506 Bugs: ProtocolBugs{
6507 NoExtendedMasterSecret: !hasEMS,
6508 },
6509 },
6510 }
6511
6512 if isResumption {
6513 test.resumeSession = true
6514 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006515 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006516 Bugs: ProtocolBugs{
6517 NoExtendedMasterSecret: !hasEMS,
6518 },
6519 }
6520 }
6521
6522 if isResumption && !hasEMS {
6523 test.shouldFail = true
6524 test.expectedError = "failed to get tls-unique"
6525 }
6526
6527 testCases = append(testCases, test)
6528 }
6529 }
6530 }
6531}
6532
Adam Langley09505632015-07-30 18:10:13 -07006533func addCustomExtensionTests() {
6534 expectedContents := "custom extension"
6535 emptyString := ""
6536
6537 for _, isClient := range []bool{false, true} {
6538 suffix := "Server"
6539 flag := "-enable-server-custom-extension"
6540 testType := serverTest
6541 if isClient {
6542 suffix = "Client"
6543 flag = "-enable-client-custom-extension"
6544 testType = clientTest
6545 }
6546
6547 testCases = append(testCases, testCase{
6548 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006549 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006551 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006552 Bugs: ProtocolBugs{
6553 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006554 ExpectedCustomExtension: &expectedContents,
6555 },
6556 },
6557 flags: []string{flag},
6558 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006559 testCases = append(testCases, testCase{
6560 testType: testType,
6561 name: "CustomExtensions-" + suffix + "-TLS13",
6562 config: Config{
6563 MaxVersion: VersionTLS13,
6564 Bugs: ProtocolBugs{
6565 CustomExtension: expectedContents,
6566 ExpectedCustomExtension: &expectedContents,
6567 },
6568 },
6569 flags: []string{flag},
6570 })
Adam Langley09505632015-07-30 18:10:13 -07006571
6572 // If the parse callback fails, the handshake should also fail.
6573 testCases = append(testCases, testCase{
6574 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006575 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006576 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006577 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006578 Bugs: ProtocolBugs{
6579 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006580 ExpectedCustomExtension: &expectedContents,
6581 },
6582 },
David Benjamin399e7c92015-07-30 23:01:27 -04006583 flags: []string{flag},
6584 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006585 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6586 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006587 testCases = append(testCases, testCase{
6588 testType: testType,
6589 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6590 config: Config{
6591 MaxVersion: VersionTLS13,
6592 Bugs: ProtocolBugs{
6593 CustomExtension: expectedContents + "foo",
6594 ExpectedCustomExtension: &expectedContents,
6595 },
6596 },
6597 flags: []string{flag},
6598 shouldFail: true,
6599 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6600 })
Adam Langley09505632015-07-30 18:10:13 -07006601
6602 // If the add callback fails, the handshake should also fail.
6603 testCases = append(testCases, testCase{
6604 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006605 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006607 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006608 Bugs: ProtocolBugs{
6609 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006610 ExpectedCustomExtension: &expectedContents,
6611 },
6612 },
David Benjamin399e7c92015-07-30 23:01:27 -04006613 flags: []string{flag, "-custom-extension-fail-add"},
6614 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006615 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6616 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006617 testCases = append(testCases, testCase{
6618 testType: testType,
6619 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6620 config: Config{
6621 MaxVersion: VersionTLS13,
6622 Bugs: ProtocolBugs{
6623 CustomExtension: expectedContents,
6624 ExpectedCustomExtension: &expectedContents,
6625 },
6626 },
6627 flags: []string{flag, "-custom-extension-fail-add"},
6628 shouldFail: true,
6629 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6630 })
Adam Langley09505632015-07-30 18:10:13 -07006631
6632 // If the add callback returns zero, no extension should be
6633 // added.
6634 skipCustomExtension := expectedContents
6635 if isClient {
6636 // For the case where the client skips sending the
6637 // custom extension, the server must not “echo” it.
6638 skipCustomExtension = ""
6639 }
6640 testCases = append(testCases, testCase{
6641 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006642 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006645 Bugs: ProtocolBugs{
6646 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006647 ExpectedCustomExtension: &emptyString,
6648 },
6649 },
6650 flags: []string{flag, "-custom-extension-skip"},
6651 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006652 testCases = append(testCases, testCase{
6653 testType: testType,
6654 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6655 config: Config{
6656 MaxVersion: VersionTLS13,
6657 Bugs: ProtocolBugs{
6658 CustomExtension: skipCustomExtension,
6659 ExpectedCustomExtension: &emptyString,
6660 },
6661 },
6662 flags: []string{flag, "-custom-extension-skip"},
6663 })
Adam Langley09505632015-07-30 18:10:13 -07006664 }
6665
6666 // The custom extension add callback should not be called if the client
6667 // doesn't send the extension.
6668 testCases = append(testCases, testCase{
6669 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006670 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006671 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006672 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006673 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006674 ExpectedCustomExtension: &emptyString,
6675 },
6676 },
6677 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6678 })
Adam Langley2deb9842015-08-07 11:15:37 -07006679
Steven Valdez143e8b32016-07-11 13:19:03 -04006680 testCases = append(testCases, testCase{
6681 testType: serverTest,
6682 name: "CustomExtensions-NotCalled-Server-TLS13",
6683 config: Config{
6684 MaxVersion: VersionTLS13,
6685 Bugs: ProtocolBugs{
6686 ExpectedCustomExtension: &emptyString,
6687 },
6688 },
6689 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6690 })
6691
Adam Langley2deb9842015-08-07 11:15:37 -07006692 // Test an unknown extension from the server.
6693 testCases = append(testCases, testCase{
6694 testType: clientTest,
6695 name: "UnknownExtension-Client",
6696 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006697 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006698 Bugs: ProtocolBugs{
6699 CustomExtension: expectedContents,
6700 },
6701 },
David Benjamin0c40a962016-08-01 12:05:50 -04006702 shouldFail: true,
6703 expectedError: ":UNEXPECTED_EXTENSION:",
6704 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006705 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006706 testCases = append(testCases, testCase{
6707 testType: clientTest,
6708 name: "UnknownExtension-Client-TLS13",
6709 config: Config{
6710 MaxVersion: VersionTLS13,
6711 Bugs: ProtocolBugs{
6712 CustomExtension: expectedContents,
6713 },
6714 },
David Benjamin0c40a962016-08-01 12:05:50 -04006715 shouldFail: true,
6716 expectedError: ":UNEXPECTED_EXTENSION:",
6717 expectedLocalError: "remote error: unsupported extension",
6718 })
6719
6720 // Test a known but unoffered extension from the server.
6721 testCases = append(testCases, testCase{
6722 testType: clientTest,
6723 name: "UnofferedExtension-Client",
6724 config: Config{
6725 MaxVersion: VersionTLS12,
6726 Bugs: ProtocolBugs{
6727 SendALPN: "alpn",
6728 },
6729 },
6730 shouldFail: true,
6731 expectedError: ":UNEXPECTED_EXTENSION:",
6732 expectedLocalError: "remote error: unsupported extension",
6733 })
6734 testCases = append(testCases, testCase{
6735 testType: clientTest,
6736 name: "UnofferedExtension-Client-TLS13",
6737 config: Config{
6738 MaxVersion: VersionTLS13,
6739 Bugs: ProtocolBugs{
6740 SendALPN: "alpn",
6741 },
6742 },
6743 shouldFail: true,
6744 expectedError: ":UNEXPECTED_EXTENSION:",
6745 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006746 })
Adam Langley09505632015-07-30 18:10:13 -07006747}
6748
David Benjaminb36a3952015-12-01 18:53:13 -05006749func addRSAClientKeyExchangeTests() {
6750 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6751 testCases = append(testCases, testCase{
6752 testType: serverTest,
6753 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6754 config: Config{
6755 // Ensure the ClientHello version and final
6756 // version are different, to detect if the
6757 // server uses the wrong one.
6758 MaxVersion: VersionTLS11,
6759 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6760 Bugs: ProtocolBugs{
6761 BadRSAClientKeyExchange: bad,
6762 },
6763 },
6764 shouldFail: true,
6765 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6766 })
6767 }
6768}
6769
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006770var testCurves = []struct {
6771 name string
6772 id CurveID
6773}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006774 {"P-256", CurveP256},
6775 {"P-384", CurveP384},
6776 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006777 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006778}
6779
Steven Valdez5440fe02016-07-18 12:40:30 -04006780const bogusCurve = 0x1234
6781
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006782func addCurveTests() {
6783 for _, curve := range testCurves {
6784 testCases = append(testCases, testCase{
6785 name: "CurveTest-Client-" + curve.name,
6786 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006787 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006788 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6789 CurvePreferences: []CurveID{curve.id},
6790 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006791 flags: []string{"-enable-all-curves"},
6792 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006793 })
6794 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006795 name: "CurveTest-Client-" + curve.name + "-TLS13",
6796 config: Config{
6797 MaxVersion: VersionTLS13,
6798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6799 CurvePreferences: []CurveID{curve.id},
6800 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006801 flags: []string{"-enable-all-curves"},
6802 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006803 })
6804 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006805 testType: serverTest,
6806 name: "CurveTest-Server-" + curve.name,
6807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006808 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006809 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6810 CurvePreferences: []CurveID{curve.id},
6811 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006812 flags: []string{"-enable-all-curves"},
6813 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006814 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006815 testCases = append(testCases, testCase{
6816 testType: serverTest,
6817 name: "CurveTest-Server-" + curve.name + "-TLS13",
6818 config: Config{
6819 MaxVersion: VersionTLS13,
6820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6821 CurvePreferences: []CurveID{curve.id},
6822 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006823 flags: []string{"-enable-all-curves"},
6824 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006825 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006826 }
David Benjamin241ae832016-01-15 03:04:54 -05006827
6828 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006829 testCases = append(testCases, testCase{
6830 testType: serverTest,
6831 name: "UnknownCurve",
6832 config: Config{
6833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6834 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6835 },
6836 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006837
6838 // The server must not consider ECDHE ciphers when there are no
6839 // supported curves.
6840 testCases = append(testCases, testCase{
6841 testType: serverTest,
6842 name: "NoSupportedCurves",
6843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006844 MaxVersion: VersionTLS12,
6845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6846 Bugs: ProtocolBugs{
6847 NoSupportedCurves: true,
6848 },
6849 },
6850 shouldFail: true,
6851 expectedError: ":NO_SHARED_CIPHER:",
6852 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006853 testCases = append(testCases, testCase{
6854 testType: serverTest,
6855 name: "NoSupportedCurves-TLS13",
6856 config: Config{
6857 MaxVersion: VersionTLS13,
6858 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6859 Bugs: ProtocolBugs{
6860 NoSupportedCurves: true,
6861 },
6862 },
6863 shouldFail: true,
6864 expectedError: ":NO_SHARED_CIPHER:",
6865 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006866
6867 // The server must fall back to another cipher when there are no
6868 // supported curves.
6869 testCases = append(testCases, testCase{
6870 testType: serverTest,
6871 name: "NoCommonCurves",
6872 config: Config{
6873 MaxVersion: VersionTLS12,
6874 CipherSuites: []uint16{
6875 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6876 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6877 },
6878 CurvePreferences: []CurveID{CurveP224},
6879 },
6880 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6881 })
6882
6883 // The client must reject bogus curves and disabled curves.
6884 testCases = append(testCases, testCase{
6885 name: "BadECDHECurve",
6886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006887 MaxVersion: VersionTLS12,
6888 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6889 Bugs: ProtocolBugs{
6890 SendCurve: bogusCurve,
6891 },
6892 },
6893 shouldFail: true,
6894 expectedError: ":WRONG_CURVE:",
6895 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006896 testCases = append(testCases, testCase{
6897 name: "BadECDHECurve-TLS13",
6898 config: Config{
6899 MaxVersion: VersionTLS13,
6900 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6901 Bugs: ProtocolBugs{
6902 SendCurve: bogusCurve,
6903 },
6904 },
6905 shouldFail: true,
6906 expectedError: ":WRONG_CURVE:",
6907 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006908
6909 testCases = append(testCases, testCase{
6910 name: "UnsupportedCurve",
6911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006912 MaxVersion: VersionTLS12,
6913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6914 CurvePreferences: []CurveID{CurveP256},
6915 Bugs: ProtocolBugs{
6916 IgnorePeerCurvePreferences: true,
6917 },
6918 },
6919 flags: []string{"-p384-only"},
6920 shouldFail: true,
6921 expectedError: ":WRONG_CURVE:",
6922 })
6923
David Benjamin4f921572016-07-17 14:20:10 +02006924 testCases = append(testCases, testCase{
6925 // TODO(davidben): Add a TLS 1.3 version where
6926 // HelloRetryRequest requests an unsupported curve.
6927 name: "UnsupportedCurve-ServerHello-TLS13",
6928 config: Config{
6929 MaxVersion: VersionTLS12,
6930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6931 CurvePreferences: []CurveID{CurveP384},
6932 Bugs: ProtocolBugs{
6933 SendCurve: CurveP256,
6934 },
6935 },
6936 flags: []string{"-p384-only"},
6937 shouldFail: true,
6938 expectedError: ":WRONG_CURVE:",
6939 })
6940
David Benjamin4c3ddf72016-06-29 18:13:53 -04006941 // Test invalid curve points.
6942 testCases = append(testCases, testCase{
6943 name: "InvalidECDHPoint-Client",
6944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006945 MaxVersion: VersionTLS12,
6946 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6947 CurvePreferences: []CurveID{CurveP256},
6948 Bugs: ProtocolBugs{
6949 InvalidECDHPoint: true,
6950 },
6951 },
6952 shouldFail: true,
6953 expectedError: ":INVALID_ENCODING:",
6954 })
6955 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006956 name: "InvalidECDHPoint-Client-TLS13",
6957 config: Config{
6958 MaxVersion: VersionTLS13,
6959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6960 CurvePreferences: []CurveID{CurveP256},
6961 Bugs: ProtocolBugs{
6962 InvalidECDHPoint: true,
6963 },
6964 },
6965 shouldFail: true,
6966 expectedError: ":INVALID_ENCODING:",
6967 })
6968 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006969 testType: serverTest,
6970 name: "InvalidECDHPoint-Server",
6971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006972 MaxVersion: VersionTLS12,
6973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6974 CurvePreferences: []CurveID{CurveP256},
6975 Bugs: ProtocolBugs{
6976 InvalidECDHPoint: true,
6977 },
6978 },
6979 shouldFail: true,
6980 expectedError: ":INVALID_ENCODING:",
6981 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006982 testCases = append(testCases, testCase{
6983 testType: serverTest,
6984 name: "InvalidECDHPoint-Server-TLS13",
6985 config: Config{
6986 MaxVersion: VersionTLS13,
6987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6988 CurvePreferences: []CurveID{CurveP256},
6989 Bugs: ProtocolBugs{
6990 InvalidECDHPoint: true,
6991 },
6992 },
6993 shouldFail: true,
6994 expectedError: ":INVALID_ENCODING:",
6995 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006996}
6997
Matt Braithwaite54217e42016-06-13 13:03:47 -07006998func addCECPQ1Tests() {
6999 testCases = append(testCases, testCase{
7000 testType: clientTest,
7001 name: "CECPQ1-Client-BadX25519Part",
7002 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007003 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007004 MinVersion: VersionTLS12,
7005 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7006 Bugs: ProtocolBugs{
7007 CECPQ1BadX25519Part: true,
7008 },
7009 },
7010 flags: []string{"-cipher", "kCECPQ1"},
7011 shouldFail: true,
7012 expectedLocalError: "local error: bad record MAC",
7013 })
7014 testCases = append(testCases, testCase{
7015 testType: clientTest,
7016 name: "CECPQ1-Client-BadNewhopePart",
7017 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007018 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007019 MinVersion: VersionTLS12,
7020 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7021 Bugs: ProtocolBugs{
7022 CECPQ1BadNewhopePart: true,
7023 },
7024 },
7025 flags: []string{"-cipher", "kCECPQ1"},
7026 shouldFail: true,
7027 expectedLocalError: "local error: bad record MAC",
7028 })
7029 testCases = append(testCases, testCase{
7030 testType: serverTest,
7031 name: "CECPQ1-Server-BadX25519Part",
7032 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007033 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007034 MinVersion: VersionTLS12,
7035 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7036 Bugs: ProtocolBugs{
7037 CECPQ1BadX25519Part: true,
7038 },
7039 },
7040 flags: []string{"-cipher", "kCECPQ1"},
7041 shouldFail: true,
7042 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7043 })
7044 testCases = append(testCases, testCase{
7045 testType: serverTest,
7046 name: "CECPQ1-Server-BadNewhopePart",
7047 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007048 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007049 MinVersion: VersionTLS12,
7050 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7051 Bugs: ProtocolBugs{
7052 CECPQ1BadNewhopePart: true,
7053 },
7054 },
7055 flags: []string{"-cipher", "kCECPQ1"},
7056 shouldFail: true,
7057 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7058 })
7059}
7060
David Benjamin4cc36ad2015-12-19 14:23:26 -05007061func addKeyExchangeInfoTests() {
7062 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05007063 name: "KeyExchangeInfo-DHE-Client",
7064 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007065 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007066 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7067 Bugs: ProtocolBugs{
7068 // This is a 1234-bit prime number, generated
7069 // with:
7070 // openssl gendh 1234 | openssl asn1parse -i
7071 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7072 },
7073 },
David Benjamin9e68f192016-06-30 14:55:33 -04007074 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007075 })
7076 testCases = append(testCases, testCase{
7077 testType: serverTest,
7078 name: "KeyExchangeInfo-DHE-Server",
7079 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007080 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007081 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7082 },
7083 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007084 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007085 })
7086
7087 testCases = append(testCases, testCase{
7088 name: "KeyExchangeInfo-ECDHE-Client",
7089 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007090 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007091 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7092 CurvePreferences: []CurveID{CurveX25519},
7093 },
David Benjamin9e68f192016-06-30 14:55:33 -04007094 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007095 })
7096 testCases = append(testCases, testCase{
7097 testType: serverTest,
7098 name: "KeyExchangeInfo-ECDHE-Server",
7099 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007100 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7102 CurvePreferences: []CurveID{CurveX25519},
7103 },
David Benjamin9e68f192016-06-30 14:55:33 -04007104 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007105 })
7106}
7107
David Benjaminc9ae27c2016-06-24 22:56:37 -04007108func addTLS13RecordTests() {
7109 testCases = append(testCases, testCase{
7110 name: "TLS13-RecordPadding",
7111 config: Config{
7112 MaxVersion: VersionTLS13,
7113 MinVersion: VersionTLS13,
7114 Bugs: ProtocolBugs{
7115 RecordPadding: 10,
7116 },
7117 },
7118 })
7119
7120 testCases = append(testCases, testCase{
7121 name: "TLS13-EmptyRecords",
7122 config: Config{
7123 MaxVersion: VersionTLS13,
7124 MinVersion: VersionTLS13,
7125 Bugs: ProtocolBugs{
7126 OmitRecordContents: true,
7127 },
7128 },
7129 shouldFail: true,
7130 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7131 })
7132
7133 testCases = append(testCases, testCase{
7134 name: "TLS13-OnlyPadding",
7135 config: Config{
7136 MaxVersion: VersionTLS13,
7137 MinVersion: VersionTLS13,
7138 Bugs: ProtocolBugs{
7139 OmitRecordContents: true,
7140 RecordPadding: 10,
7141 },
7142 },
7143 shouldFail: true,
7144 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7145 })
7146
7147 testCases = append(testCases, testCase{
7148 name: "TLS13-WrongOuterRecord",
7149 config: Config{
7150 MaxVersion: VersionTLS13,
7151 MinVersion: VersionTLS13,
7152 Bugs: ProtocolBugs{
7153 OuterRecordType: recordTypeHandshake,
7154 },
7155 },
7156 shouldFail: true,
7157 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7158 })
7159}
7160
David Benjamin82261be2016-07-07 14:32:50 -07007161func addChangeCipherSpecTests() {
7162 // Test missing ChangeCipherSpecs.
7163 testCases = append(testCases, testCase{
7164 name: "SkipChangeCipherSpec-Client",
7165 config: Config{
7166 MaxVersion: VersionTLS12,
7167 Bugs: ProtocolBugs{
7168 SkipChangeCipherSpec: true,
7169 },
7170 },
7171 shouldFail: true,
7172 expectedError: ":UNEXPECTED_RECORD:",
7173 })
7174 testCases = append(testCases, testCase{
7175 testType: serverTest,
7176 name: "SkipChangeCipherSpec-Server",
7177 config: Config{
7178 MaxVersion: VersionTLS12,
7179 Bugs: ProtocolBugs{
7180 SkipChangeCipherSpec: true,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_RECORD:",
7185 })
7186 testCases = append(testCases, testCase{
7187 testType: serverTest,
7188 name: "SkipChangeCipherSpec-Server-NPN",
7189 config: Config{
7190 MaxVersion: VersionTLS12,
7191 NextProtos: []string{"bar"},
7192 Bugs: ProtocolBugs{
7193 SkipChangeCipherSpec: true,
7194 },
7195 },
7196 flags: []string{
7197 "-advertise-npn", "\x03foo\x03bar\x03baz",
7198 },
7199 shouldFail: true,
7200 expectedError: ":UNEXPECTED_RECORD:",
7201 })
7202
7203 // Test synchronization between the handshake and ChangeCipherSpec.
7204 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7205 // rejected. Test both with and without handshake packing to handle both
7206 // when the partial post-CCS message is in its own record and when it is
7207 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007208 for _, packed := range []bool{false, true} {
7209 var suffix string
7210 if packed {
7211 suffix = "-Packed"
7212 }
7213
7214 testCases = append(testCases, testCase{
7215 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7216 config: Config{
7217 MaxVersion: VersionTLS12,
7218 Bugs: ProtocolBugs{
7219 FragmentAcrossChangeCipherSpec: true,
7220 PackHandshakeFlight: packed,
7221 },
7222 },
7223 shouldFail: true,
7224 expectedError: ":UNEXPECTED_RECORD:",
7225 })
7226 testCases = append(testCases, testCase{
7227 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7228 config: Config{
7229 MaxVersion: VersionTLS12,
7230 },
7231 resumeSession: true,
7232 resumeConfig: &Config{
7233 MaxVersion: VersionTLS12,
7234 Bugs: ProtocolBugs{
7235 FragmentAcrossChangeCipherSpec: true,
7236 PackHandshakeFlight: packed,
7237 },
7238 },
7239 shouldFail: true,
7240 expectedError: ":UNEXPECTED_RECORD:",
7241 })
7242 testCases = append(testCases, testCase{
7243 testType: serverTest,
7244 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7245 config: Config{
7246 MaxVersion: VersionTLS12,
7247 Bugs: ProtocolBugs{
7248 FragmentAcrossChangeCipherSpec: true,
7249 PackHandshakeFlight: packed,
7250 },
7251 },
7252 shouldFail: true,
7253 expectedError: ":UNEXPECTED_RECORD:",
7254 })
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7258 config: Config{
7259 MaxVersion: VersionTLS12,
7260 },
7261 resumeSession: true,
7262 resumeConfig: &Config{
7263 MaxVersion: VersionTLS12,
7264 Bugs: ProtocolBugs{
7265 FragmentAcrossChangeCipherSpec: true,
7266 PackHandshakeFlight: packed,
7267 },
7268 },
7269 shouldFail: true,
7270 expectedError: ":UNEXPECTED_RECORD:",
7271 })
7272 testCases = append(testCases, testCase{
7273 testType: serverTest,
7274 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7275 config: Config{
7276 MaxVersion: VersionTLS12,
7277 NextProtos: []string{"bar"},
7278 Bugs: ProtocolBugs{
7279 FragmentAcrossChangeCipherSpec: true,
7280 PackHandshakeFlight: packed,
7281 },
7282 },
7283 flags: []string{
7284 "-advertise-npn", "\x03foo\x03bar\x03baz",
7285 },
7286 shouldFail: true,
7287 expectedError: ":UNEXPECTED_RECORD:",
7288 })
7289 }
7290
David Benjamin61672812016-07-14 23:10:43 -04007291 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7292 // messages in the handshake queue. Do this by testing the server
7293 // reading the client Finished, reversing the flight so Finished comes
7294 // first.
7295 testCases = append(testCases, testCase{
7296 protocol: dtls,
7297 testType: serverTest,
7298 name: "SendUnencryptedFinished-DTLS",
7299 config: Config{
7300 MaxVersion: VersionTLS12,
7301 Bugs: ProtocolBugs{
7302 SendUnencryptedFinished: true,
7303 ReverseHandshakeFragments: true,
7304 },
7305 },
7306 shouldFail: true,
7307 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7308 })
7309
Steven Valdez143e8b32016-07-11 13:19:03 -04007310 // Test synchronization between encryption changes and the handshake in
7311 // TLS 1.3, where ChangeCipherSpec is implicit.
7312 testCases = append(testCases, testCase{
7313 name: "PartialEncryptedExtensionsWithServerHello",
7314 config: Config{
7315 MaxVersion: VersionTLS13,
7316 Bugs: ProtocolBugs{
7317 PartialEncryptedExtensionsWithServerHello: true,
7318 },
7319 },
7320 shouldFail: true,
7321 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7322 })
7323 testCases = append(testCases, testCase{
7324 testType: serverTest,
7325 name: "PartialClientFinishedWithClientHello",
7326 config: Config{
7327 MaxVersion: VersionTLS13,
7328 Bugs: ProtocolBugs{
7329 PartialClientFinishedWithClientHello: true,
7330 },
7331 },
7332 shouldFail: true,
7333 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7334 })
7335
David Benjamin82261be2016-07-07 14:32:50 -07007336 // Test that early ChangeCipherSpecs are handled correctly.
7337 testCases = append(testCases, testCase{
7338 testType: serverTest,
7339 name: "EarlyChangeCipherSpec-server-1",
7340 config: Config{
7341 MaxVersion: VersionTLS12,
7342 Bugs: ProtocolBugs{
7343 EarlyChangeCipherSpec: 1,
7344 },
7345 },
7346 shouldFail: true,
7347 expectedError: ":UNEXPECTED_RECORD:",
7348 })
7349 testCases = append(testCases, testCase{
7350 testType: serverTest,
7351 name: "EarlyChangeCipherSpec-server-2",
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 Bugs: ProtocolBugs{
7355 EarlyChangeCipherSpec: 2,
7356 },
7357 },
7358 shouldFail: true,
7359 expectedError: ":UNEXPECTED_RECORD:",
7360 })
7361 testCases = append(testCases, testCase{
7362 protocol: dtls,
7363 name: "StrayChangeCipherSpec",
7364 config: Config{
7365 // TODO(davidben): Once DTLS 1.3 exists, test
7366 // that stray ChangeCipherSpec messages are
7367 // rejected.
7368 MaxVersion: VersionTLS12,
7369 Bugs: ProtocolBugs{
7370 StrayChangeCipherSpec: true,
7371 },
7372 },
7373 })
7374
7375 // Test that the contents of ChangeCipherSpec are checked.
7376 testCases = append(testCases, testCase{
7377 name: "BadChangeCipherSpec-1",
7378 config: Config{
7379 MaxVersion: VersionTLS12,
7380 Bugs: ProtocolBugs{
7381 BadChangeCipherSpec: []byte{2},
7382 },
7383 },
7384 shouldFail: true,
7385 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7386 })
7387 testCases = append(testCases, testCase{
7388 name: "BadChangeCipherSpec-2",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 Bugs: ProtocolBugs{
7392 BadChangeCipherSpec: []byte{1, 1},
7393 },
7394 },
7395 shouldFail: true,
7396 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7397 })
7398 testCases = append(testCases, testCase{
7399 protocol: dtls,
7400 name: "BadChangeCipherSpec-DTLS-1",
7401 config: Config{
7402 MaxVersion: VersionTLS12,
7403 Bugs: ProtocolBugs{
7404 BadChangeCipherSpec: []byte{2},
7405 },
7406 },
7407 shouldFail: true,
7408 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7409 })
7410 testCases = append(testCases, testCase{
7411 protocol: dtls,
7412 name: "BadChangeCipherSpec-DTLS-2",
7413 config: Config{
7414 MaxVersion: VersionTLS12,
7415 Bugs: ProtocolBugs{
7416 BadChangeCipherSpec: []byte{1, 1},
7417 },
7418 },
7419 shouldFail: true,
7420 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7421 })
7422}
7423
David Benjamin0b8d5da2016-07-15 00:39:56 -04007424func addWrongMessageTypeTests() {
7425 for _, protocol := range []protocol{tls, dtls} {
7426 var suffix string
7427 if protocol == dtls {
7428 suffix = "-DTLS"
7429 }
7430
7431 testCases = append(testCases, testCase{
7432 protocol: protocol,
7433 testType: serverTest,
7434 name: "WrongMessageType-ClientHello" + suffix,
7435 config: Config{
7436 MaxVersion: VersionTLS12,
7437 Bugs: ProtocolBugs{
7438 SendWrongMessageType: typeClientHello,
7439 },
7440 },
7441 shouldFail: true,
7442 expectedError: ":UNEXPECTED_MESSAGE:",
7443 expectedLocalError: "remote error: unexpected message",
7444 })
7445
7446 if protocol == dtls {
7447 testCases = append(testCases, testCase{
7448 protocol: protocol,
7449 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7450 config: Config{
7451 MaxVersion: VersionTLS12,
7452 Bugs: ProtocolBugs{
7453 SendWrongMessageType: typeHelloVerifyRequest,
7454 },
7455 },
7456 shouldFail: true,
7457 expectedError: ":UNEXPECTED_MESSAGE:",
7458 expectedLocalError: "remote error: unexpected message",
7459 })
7460 }
7461
7462 testCases = append(testCases, testCase{
7463 protocol: protocol,
7464 name: "WrongMessageType-ServerHello" + suffix,
7465 config: Config{
7466 MaxVersion: VersionTLS12,
7467 Bugs: ProtocolBugs{
7468 SendWrongMessageType: typeServerHello,
7469 },
7470 },
7471 shouldFail: true,
7472 expectedError: ":UNEXPECTED_MESSAGE:",
7473 expectedLocalError: "remote error: unexpected message",
7474 })
7475
7476 testCases = append(testCases, testCase{
7477 protocol: protocol,
7478 name: "WrongMessageType-ServerCertificate" + suffix,
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 Bugs: ProtocolBugs{
7482 SendWrongMessageType: typeCertificate,
7483 },
7484 },
7485 shouldFail: true,
7486 expectedError: ":UNEXPECTED_MESSAGE:",
7487 expectedLocalError: "remote error: unexpected message",
7488 })
7489
7490 testCases = append(testCases, testCase{
7491 protocol: protocol,
7492 name: "WrongMessageType-CertificateStatus" + suffix,
7493 config: Config{
7494 MaxVersion: VersionTLS12,
7495 Bugs: ProtocolBugs{
7496 SendWrongMessageType: typeCertificateStatus,
7497 },
7498 },
7499 flags: []string{"-enable-ocsp-stapling"},
7500 shouldFail: true,
7501 expectedError: ":UNEXPECTED_MESSAGE:",
7502 expectedLocalError: "remote error: unexpected message",
7503 })
7504
7505 testCases = append(testCases, testCase{
7506 protocol: protocol,
7507 name: "WrongMessageType-ServerKeyExchange" + suffix,
7508 config: Config{
7509 MaxVersion: VersionTLS12,
7510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7511 Bugs: ProtocolBugs{
7512 SendWrongMessageType: typeServerKeyExchange,
7513 },
7514 },
7515 shouldFail: true,
7516 expectedError: ":UNEXPECTED_MESSAGE:",
7517 expectedLocalError: "remote error: unexpected message",
7518 })
7519
7520 testCases = append(testCases, testCase{
7521 protocol: protocol,
7522 name: "WrongMessageType-CertificateRequest" + suffix,
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 ClientAuth: RequireAnyClientCert,
7526 Bugs: ProtocolBugs{
7527 SendWrongMessageType: typeCertificateRequest,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":UNEXPECTED_MESSAGE:",
7532 expectedLocalError: "remote error: unexpected message",
7533 })
7534
7535 testCases = append(testCases, testCase{
7536 protocol: protocol,
7537 name: "WrongMessageType-ServerHelloDone" + suffix,
7538 config: Config{
7539 MaxVersion: VersionTLS12,
7540 Bugs: ProtocolBugs{
7541 SendWrongMessageType: typeServerHelloDone,
7542 },
7543 },
7544 shouldFail: true,
7545 expectedError: ":UNEXPECTED_MESSAGE:",
7546 expectedLocalError: "remote error: unexpected message",
7547 })
7548
7549 testCases = append(testCases, testCase{
7550 testType: serverTest,
7551 protocol: protocol,
7552 name: "WrongMessageType-ClientCertificate" + suffix,
7553 config: Config{
7554 Certificates: []Certificate{rsaCertificate},
7555 MaxVersion: VersionTLS12,
7556 Bugs: ProtocolBugs{
7557 SendWrongMessageType: typeCertificate,
7558 },
7559 },
7560 flags: []string{"-require-any-client-certificate"},
7561 shouldFail: true,
7562 expectedError: ":UNEXPECTED_MESSAGE:",
7563 expectedLocalError: "remote error: unexpected message",
7564 })
7565
7566 testCases = append(testCases, testCase{
7567 testType: serverTest,
7568 protocol: protocol,
7569 name: "WrongMessageType-CertificateVerify" + suffix,
7570 config: Config{
7571 Certificates: []Certificate{rsaCertificate},
7572 MaxVersion: VersionTLS12,
7573 Bugs: ProtocolBugs{
7574 SendWrongMessageType: typeCertificateVerify,
7575 },
7576 },
7577 flags: []string{"-require-any-client-certificate"},
7578 shouldFail: true,
7579 expectedError: ":UNEXPECTED_MESSAGE:",
7580 expectedLocalError: "remote error: unexpected message",
7581 })
7582
7583 testCases = append(testCases, testCase{
7584 testType: serverTest,
7585 protocol: protocol,
7586 name: "WrongMessageType-ClientKeyExchange" + suffix,
7587 config: Config{
7588 MaxVersion: VersionTLS12,
7589 Bugs: ProtocolBugs{
7590 SendWrongMessageType: typeClientKeyExchange,
7591 },
7592 },
7593 shouldFail: true,
7594 expectedError: ":UNEXPECTED_MESSAGE:",
7595 expectedLocalError: "remote error: unexpected message",
7596 })
7597
7598 if protocol != dtls {
7599 testCases = append(testCases, testCase{
7600 testType: serverTest,
7601 protocol: protocol,
7602 name: "WrongMessageType-NextProtocol" + suffix,
7603 config: Config{
7604 MaxVersion: VersionTLS12,
7605 NextProtos: []string{"bar"},
7606 Bugs: ProtocolBugs{
7607 SendWrongMessageType: typeNextProtocol,
7608 },
7609 },
7610 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7611 shouldFail: true,
7612 expectedError: ":UNEXPECTED_MESSAGE:",
7613 expectedLocalError: "remote error: unexpected message",
7614 })
7615
7616 testCases = append(testCases, testCase{
7617 testType: serverTest,
7618 protocol: protocol,
7619 name: "WrongMessageType-ChannelID" + suffix,
7620 config: Config{
7621 MaxVersion: VersionTLS12,
7622 ChannelID: channelIDKey,
7623 Bugs: ProtocolBugs{
7624 SendWrongMessageType: typeChannelID,
7625 },
7626 },
7627 flags: []string{
7628 "-expect-channel-id",
7629 base64.StdEncoding.EncodeToString(channelIDBytes),
7630 },
7631 shouldFail: true,
7632 expectedError: ":UNEXPECTED_MESSAGE:",
7633 expectedLocalError: "remote error: unexpected message",
7634 })
7635 }
7636
7637 testCases = append(testCases, testCase{
7638 testType: serverTest,
7639 protocol: protocol,
7640 name: "WrongMessageType-ClientFinished" + suffix,
7641 config: Config{
7642 MaxVersion: VersionTLS12,
7643 Bugs: ProtocolBugs{
7644 SendWrongMessageType: typeFinished,
7645 },
7646 },
7647 shouldFail: true,
7648 expectedError: ":UNEXPECTED_MESSAGE:",
7649 expectedLocalError: "remote error: unexpected message",
7650 })
7651
7652 testCases = append(testCases, testCase{
7653 protocol: protocol,
7654 name: "WrongMessageType-NewSessionTicket" + suffix,
7655 config: Config{
7656 MaxVersion: VersionTLS12,
7657 Bugs: ProtocolBugs{
7658 SendWrongMessageType: typeNewSessionTicket,
7659 },
7660 },
7661 shouldFail: true,
7662 expectedError: ":UNEXPECTED_MESSAGE:",
7663 expectedLocalError: "remote error: unexpected message",
7664 })
7665
7666 testCases = append(testCases, testCase{
7667 protocol: protocol,
7668 name: "WrongMessageType-ServerFinished" + suffix,
7669 config: Config{
7670 MaxVersion: VersionTLS12,
7671 Bugs: ProtocolBugs{
7672 SendWrongMessageType: typeFinished,
7673 },
7674 },
7675 shouldFail: true,
7676 expectedError: ":UNEXPECTED_MESSAGE:",
7677 expectedLocalError: "remote error: unexpected message",
7678 })
7679
7680 }
7681}
7682
Steven Valdez143e8b32016-07-11 13:19:03 -04007683func addTLS13WrongMessageTypeTests() {
7684 testCases = append(testCases, testCase{
7685 testType: serverTest,
7686 name: "WrongMessageType-TLS13-ClientHello",
7687 config: Config{
7688 MaxVersion: VersionTLS13,
7689 Bugs: ProtocolBugs{
7690 SendWrongMessageType: typeClientHello,
7691 },
7692 },
7693 shouldFail: true,
7694 expectedError: ":UNEXPECTED_MESSAGE:",
7695 expectedLocalError: "remote error: unexpected message",
7696 })
7697
7698 testCases = append(testCases, testCase{
7699 name: "WrongMessageType-TLS13-ServerHello",
7700 config: Config{
7701 MaxVersion: VersionTLS13,
7702 Bugs: ProtocolBugs{
7703 SendWrongMessageType: typeServerHello,
7704 },
7705 },
7706 shouldFail: true,
7707 expectedError: ":UNEXPECTED_MESSAGE:",
7708 // The alert comes in with the wrong encryption.
7709 expectedLocalError: "local error: bad record MAC",
7710 })
7711
7712 testCases = append(testCases, testCase{
7713 name: "WrongMessageType-TLS13-EncryptedExtensions",
7714 config: Config{
7715 MaxVersion: VersionTLS13,
7716 Bugs: ProtocolBugs{
7717 SendWrongMessageType: typeEncryptedExtensions,
7718 },
7719 },
7720 shouldFail: true,
7721 expectedError: ":UNEXPECTED_MESSAGE:",
7722 expectedLocalError: "remote error: unexpected message",
7723 })
7724
7725 testCases = append(testCases, testCase{
7726 name: "WrongMessageType-TLS13-CertificateRequest",
7727 config: Config{
7728 MaxVersion: VersionTLS13,
7729 ClientAuth: RequireAnyClientCert,
7730 Bugs: ProtocolBugs{
7731 SendWrongMessageType: typeCertificateRequest,
7732 },
7733 },
7734 shouldFail: true,
7735 expectedError: ":UNEXPECTED_MESSAGE:",
7736 expectedLocalError: "remote error: unexpected message",
7737 })
7738
7739 testCases = append(testCases, testCase{
7740 name: "WrongMessageType-TLS13-ServerCertificate",
7741 config: Config{
7742 MaxVersion: VersionTLS13,
7743 Bugs: ProtocolBugs{
7744 SendWrongMessageType: typeCertificate,
7745 },
7746 },
7747 shouldFail: true,
7748 expectedError: ":UNEXPECTED_MESSAGE:",
7749 expectedLocalError: "remote error: unexpected message",
7750 })
7751
7752 testCases = append(testCases, testCase{
7753 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7754 config: Config{
7755 MaxVersion: VersionTLS13,
7756 Bugs: ProtocolBugs{
7757 SendWrongMessageType: typeCertificateVerify,
7758 },
7759 },
7760 shouldFail: true,
7761 expectedError: ":UNEXPECTED_MESSAGE:",
7762 expectedLocalError: "remote error: unexpected message",
7763 })
7764
7765 testCases = append(testCases, testCase{
7766 name: "WrongMessageType-TLS13-ServerFinished",
7767 config: Config{
7768 MaxVersion: VersionTLS13,
7769 Bugs: ProtocolBugs{
7770 SendWrongMessageType: typeFinished,
7771 },
7772 },
7773 shouldFail: true,
7774 expectedError: ":UNEXPECTED_MESSAGE:",
7775 expectedLocalError: "remote error: unexpected message",
7776 })
7777
7778 testCases = append(testCases, testCase{
7779 testType: serverTest,
7780 name: "WrongMessageType-TLS13-ClientCertificate",
7781 config: Config{
7782 Certificates: []Certificate{rsaCertificate},
7783 MaxVersion: VersionTLS13,
7784 Bugs: ProtocolBugs{
7785 SendWrongMessageType: typeCertificate,
7786 },
7787 },
7788 flags: []string{"-require-any-client-certificate"},
7789 shouldFail: true,
7790 expectedError: ":UNEXPECTED_MESSAGE:",
7791 expectedLocalError: "remote error: unexpected message",
7792 })
7793
7794 testCases = append(testCases, testCase{
7795 testType: serverTest,
7796 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7797 config: Config{
7798 Certificates: []Certificate{rsaCertificate},
7799 MaxVersion: VersionTLS13,
7800 Bugs: ProtocolBugs{
7801 SendWrongMessageType: typeCertificateVerify,
7802 },
7803 },
7804 flags: []string{"-require-any-client-certificate"},
7805 shouldFail: true,
7806 expectedError: ":UNEXPECTED_MESSAGE:",
7807 expectedLocalError: "remote error: unexpected message",
7808 })
7809
7810 testCases = append(testCases, testCase{
7811 testType: serverTest,
7812 name: "WrongMessageType-TLS13-ClientFinished",
7813 config: Config{
7814 MaxVersion: VersionTLS13,
7815 Bugs: ProtocolBugs{
7816 SendWrongMessageType: typeFinished,
7817 },
7818 },
7819 shouldFail: true,
7820 expectedError: ":UNEXPECTED_MESSAGE:",
7821 expectedLocalError: "remote error: unexpected message",
7822 })
7823}
7824
7825func addTLS13HandshakeTests() {
7826 testCases = append(testCases, testCase{
7827 testType: clientTest,
7828 name: "MissingKeyShare-Client",
7829 config: Config{
7830 MaxVersion: VersionTLS13,
7831 Bugs: ProtocolBugs{
7832 MissingKeyShare: true,
7833 },
7834 },
7835 shouldFail: true,
7836 expectedError: ":MISSING_KEY_SHARE:",
7837 })
7838
7839 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007840 testType: serverTest,
7841 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007842 config: Config{
7843 MaxVersion: VersionTLS13,
7844 Bugs: ProtocolBugs{
7845 MissingKeyShare: true,
7846 },
7847 },
7848 shouldFail: true,
7849 expectedError: ":MISSING_KEY_SHARE:",
7850 })
7851
7852 testCases = append(testCases, testCase{
7853 testType: clientTest,
7854 name: "ClientHelloMissingKeyShare",
7855 config: Config{
7856 MaxVersion: VersionTLS13,
7857 Bugs: ProtocolBugs{
7858 MissingKeyShare: true,
7859 },
7860 },
7861 shouldFail: true,
7862 expectedError: ":MISSING_KEY_SHARE:",
7863 })
7864
7865 testCases = append(testCases, testCase{
7866 testType: clientTest,
7867 name: "MissingKeyShare",
7868 config: Config{
7869 MaxVersion: VersionTLS13,
7870 Bugs: ProtocolBugs{
7871 MissingKeyShare: true,
7872 },
7873 },
7874 shouldFail: true,
7875 expectedError: ":MISSING_KEY_SHARE:",
7876 })
7877
7878 testCases = append(testCases, testCase{
7879 testType: serverTest,
7880 name: "DuplicateKeyShares",
7881 config: Config{
7882 MaxVersion: VersionTLS13,
7883 Bugs: ProtocolBugs{
7884 DuplicateKeyShares: true,
7885 },
7886 },
7887 })
7888
7889 testCases = append(testCases, testCase{
7890 testType: clientTest,
7891 name: "EmptyEncryptedExtensions",
7892 config: Config{
7893 MaxVersion: VersionTLS13,
7894 Bugs: ProtocolBugs{
7895 EmptyEncryptedExtensions: true,
7896 },
7897 },
7898 shouldFail: true,
7899 expectedLocalError: "remote error: error decoding message",
7900 })
7901
7902 testCases = append(testCases, testCase{
7903 testType: clientTest,
7904 name: "EncryptedExtensionsWithKeyShare",
7905 config: Config{
7906 MaxVersion: VersionTLS13,
7907 Bugs: ProtocolBugs{
7908 EncryptedExtensionsWithKeyShare: true,
7909 },
7910 },
7911 shouldFail: true,
7912 expectedLocalError: "remote error: unsupported extension",
7913 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007914
7915 testCases = append(testCases, testCase{
7916 testType: serverTest,
7917 name: "SendHelloRetryRequest",
7918 config: Config{
7919 MaxVersion: VersionTLS13,
7920 // Require a HelloRetryRequest for every curve.
7921 DefaultCurves: []CurveID{},
7922 },
7923 expectedCurveID: CurveX25519,
7924 })
7925
7926 testCases = append(testCases, testCase{
7927 testType: serverTest,
7928 name: "SendHelloRetryRequest-2",
7929 config: Config{
7930 MaxVersion: VersionTLS13,
7931 DefaultCurves: []CurveID{CurveP384},
7932 },
7933 // Although the ClientHello did not predict our preferred curve,
7934 // we always select it whether it is predicted or not.
7935 expectedCurveID: CurveX25519,
7936 })
7937
7938 testCases = append(testCases, testCase{
7939 name: "UnknownCurve-HelloRetryRequest",
7940 config: Config{
7941 MaxVersion: VersionTLS13,
7942 // P-384 requires HelloRetryRequest in BoringSSL.
7943 CurvePreferences: []CurveID{CurveP384},
7944 Bugs: ProtocolBugs{
7945 SendHelloRetryRequestCurve: bogusCurve,
7946 },
7947 },
7948 shouldFail: true,
7949 expectedError: ":WRONG_CURVE:",
7950 })
7951
7952 testCases = append(testCases, testCase{
7953 name: "DisabledCurve-HelloRetryRequest",
7954 config: Config{
7955 MaxVersion: VersionTLS13,
7956 CurvePreferences: []CurveID{CurveP256},
7957 Bugs: ProtocolBugs{
7958 IgnorePeerCurvePreferences: true,
7959 },
7960 },
7961 flags: []string{"-p384-only"},
7962 shouldFail: true,
7963 expectedError: ":WRONG_CURVE:",
7964 })
7965
7966 testCases = append(testCases, testCase{
7967 name: "UnnecessaryHelloRetryRequest",
7968 config: Config{
7969 MaxVersion: VersionTLS13,
7970 Bugs: ProtocolBugs{
7971 UnnecessaryHelloRetryRequest: true,
7972 },
7973 },
7974 shouldFail: true,
7975 expectedError: ":WRONG_CURVE:",
7976 })
7977
7978 testCases = append(testCases, testCase{
7979 name: "SecondHelloRetryRequest",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 // P-384 requires HelloRetryRequest in BoringSSL.
7983 CurvePreferences: []CurveID{CurveP384},
7984 Bugs: ProtocolBugs{
7985 SecondHelloRetryRequest: true,
7986 },
7987 },
7988 shouldFail: true,
7989 expectedError: ":UNEXPECTED_MESSAGE:",
7990 })
7991
7992 testCases = append(testCases, testCase{
7993 testType: serverTest,
7994 name: "SecondClientHelloMissingKeyShare",
7995 config: Config{
7996 MaxVersion: VersionTLS13,
7997 DefaultCurves: []CurveID{},
7998 Bugs: ProtocolBugs{
7999 SecondClientHelloMissingKeyShare: true,
8000 },
8001 },
8002 shouldFail: true,
8003 expectedError: ":MISSING_KEY_SHARE:",
8004 })
8005
8006 testCases = append(testCases, testCase{
8007 testType: serverTest,
8008 name: "SecondClientHelloWrongCurve",
8009 config: Config{
8010 MaxVersion: VersionTLS13,
8011 DefaultCurves: []CurveID{},
8012 Bugs: ProtocolBugs{
8013 MisinterpretHelloRetryRequestCurve: CurveP521,
8014 },
8015 },
8016 shouldFail: true,
8017 expectedError: ":WRONG_CURVE:",
8018 })
8019
8020 testCases = append(testCases, testCase{
8021 name: "HelloRetryRequestVersionMismatch",
8022 config: Config{
8023 MaxVersion: VersionTLS13,
8024 // P-384 requires HelloRetryRequest in BoringSSL.
8025 CurvePreferences: []CurveID{CurveP384},
8026 Bugs: ProtocolBugs{
8027 SendServerHelloVersion: 0x0305,
8028 },
8029 },
8030 shouldFail: true,
8031 expectedError: ":WRONG_VERSION_NUMBER:",
8032 })
8033
8034 testCases = append(testCases, testCase{
8035 name: "HelloRetryRequestCurveMismatch",
8036 config: Config{
8037 MaxVersion: VersionTLS13,
8038 // P-384 requires HelloRetryRequest in BoringSSL.
8039 CurvePreferences: []CurveID{CurveP384},
8040 Bugs: ProtocolBugs{
8041 // Send P-384 (correct) in the HelloRetryRequest.
8042 SendHelloRetryRequestCurve: CurveP384,
8043 // But send P-256 in the ServerHello.
8044 SendCurve: CurveP256,
8045 },
8046 },
8047 shouldFail: true,
8048 expectedError: ":WRONG_CURVE:",
8049 })
8050
8051 // Test the server selecting a curve that requires a HelloRetryRequest
8052 // without sending it.
8053 testCases = append(testCases, testCase{
8054 name: "SkipHelloRetryRequest",
8055 config: Config{
8056 MaxVersion: VersionTLS13,
8057 // P-384 requires HelloRetryRequest in BoringSSL.
8058 CurvePreferences: []CurveID{CurveP384},
8059 Bugs: ProtocolBugs{
8060 SkipHelloRetryRequest: true,
8061 },
8062 },
8063 shouldFail: true,
8064 expectedError: ":WRONG_CURVE:",
8065 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008066
8067 testCases = append(testCases, testCase{
8068 name: "TLS13-RequestContextInHandshake",
8069 config: Config{
8070 MaxVersion: VersionTLS13,
8071 MinVersion: VersionTLS13,
8072 ClientAuth: RequireAnyClientCert,
8073 Bugs: ProtocolBugs{
8074 SendRequestContext: []byte("request context"),
8075 },
8076 },
8077 flags: []string{
8078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8080 },
8081 shouldFail: true,
8082 expectedError: ":DECODE_ERROR:",
8083 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008084}
8085
Adam Langley7c803a62015-06-15 15:35:05 -07008086func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008087 defer wg.Done()
8088
8089 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008090 var err error
8091
8092 if *mallocTest < 0 {
8093 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008094 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008095 } else {
8096 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8097 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008098 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008099 if err != nil {
8100 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8101 }
8102 break
8103 }
8104 }
8105 }
Adam Langley95c29f32014-06-20 12:00:00 -07008106 statusChan <- statusMsg{test: test, err: err}
8107 }
8108}
8109
8110type statusMsg struct {
8111 test *testCase
8112 started bool
8113 err error
8114}
8115
David Benjamin5f237bc2015-02-11 17:14:15 -05008116func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008117 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008118
David Benjamin5f237bc2015-02-11 17:14:15 -05008119 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008120 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008121 if !*pipe {
8122 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008123 var erase string
8124 for i := 0; i < lineLen; i++ {
8125 erase += "\b \b"
8126 }
8127 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008128 }
8129
Adam Langley95c29f32014-06-20 12:00:00 -07008130 if msg.started {
8131 started++
8132 } else {
8133 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008134
8135 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008136 if msg.err == errUnimplemented {
8137 if *pipe {
8138 // Print each test instead of a status line.
8139 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8140 }
8141 unimplemented++
8142 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8143 } else {
8144 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8145 failed++
8146 testOutput.addResult(msg.test.name, "FAIL")
8147 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008148 } else {
8149 if *pipe {
8150 // Print each test instead of a status line.
8151 fmt.Printf("PASSED (%s)\n", msg.test.name)
8152 }
8153 testOutput.addResult(msg.test.name, "PASS")
8154 }
Adam Langley95c29f32014-06-20 12:00:00 -07008155 }
8156
David Benjamin5f237bc2015-02-11 17:14:15 -05008157 if !*pipe {
8158 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008159 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008160 lineLen = len(line)
8161 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008162 }
Adam Langley95c29f32014-06-20 12:00:00 -07008163 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008164
8165 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008166}
8167
8168func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008169 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008170 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008171 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008172
Adam Langley7c803a62015-06-15 15:35:05 -07008173 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008174 addCipherSuiteTests()
8175 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008176 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008177 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008178 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008179 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008180 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008181 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008182 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008183 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008184 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008185 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008186 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008187 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008188 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008189 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008190 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008191 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008192 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008193 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008194 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008195 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008196 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008197 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008198 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008199 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008200 addTLS13WrongMessageTypeTests()
8201 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008202
8203 var wg sync.WaitGroup
8204
Adam Langley7c803a62015-06-15 15:35:05 -07008205 statusChan := make(chan statusMsg, *numWorkers)
8206 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008207 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008208
EKRf71d7ed2016-08-06 13:25:12 -07008209 if len(*shimConfigFile) != 0 {
8210 encoded, err := ioutil.ReadFile(*shimConfigFile)
8211 if err != nil {
8212 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8213 os.Exit(1)
8214 }
8215
8216 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8217 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8218 os.Exit(1)
8219 }
8220 }
8221
David Benjamin025b3d32014-07-01 19:53:04 -04008222 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008223
Adam Langley7c803a62015-06-15 15:35:05 -07008224 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008225 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008226 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008227 }
8228
David Benjamin270f0a72016-03-17 14:41:36 -04008229 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008230 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008231 matched := true
8232 if len(*testToRun) != 0 {
8233 var err error
8234 matched, err = filepath.Match(*testToRun, testCases[i].name)
8235 if err != nil {
8236 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8237 os.Exit(1)
8238 }
8239 }
8240
EKRf71d7ed2016-08-06 13:25:12 -07008241 if !*includeDisabled {
8242 for pattern := range shimConfig.DisabledTests {
8243 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8244 if err != nil {
8245 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8246 os.Exit(1)
8247 }
8248
8249 if isDisabled {
8250 matched = false
8251 break
8252 }
8253 }
8254 }
8255
David Benjamin17e12922016-07-28 18:04:43 -04008256 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008257 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008258 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008259 }
8260 }
David Benjamin17e12922016-07-28 18:04:43 -04008261
David Benjamin270f0a72016-03-17 14:41:36 -04008262 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008263 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008264 os.Exit(1)
8265 }
Adam Langley95c29f32014-06-20 12:00:00 -07008266
8267 close(testChan)
8268 wg.Wait()
8269 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008270 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008271
8272 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008273
8274 if *jsonOutput != "" {
8275 if err := testOutput.writeTo(*jsonOutput); err != nil {
8276 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8277 }
8278 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008279
EKR842ae6c2016-07-27 09:22:05 +02008280 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8281 os.Exit(1)
8282 }
8283
8284 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008285 os.Exit(1)
8286 }
Adam Langley95c29f32014-06-20 12:00:00 -07008287}