blob: 039cd5c497f28273eff129449a1245ccc27e3381 [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
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjamin9867b7d2016-03-01 23:25:48 -0500369func writeTranscript(test *testCase, isResume bool, data []byte) {
370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
390 name := test.name
391 if isResume {
392 name += "-Resume"
393 } else {
394 name += "-Normal"
395 }
396
397 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
398 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
399 }
400}
401
David Benjamin3ed59772016-03-08 12:50:21 -0500402// A timeoutConn implements an idle timeout on each Read and Write operation.
403type timeoutConn struct {
404 net.Conn
405 timeout time.Duration
406}
407
408func (t *timeoutConn) Read(b []byte) (int, error) {
409 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
410 return 0, err
411 }
412 return t.Conn.Read(b)
413}
414
415func (t *timeoutConn) Write(b []byte) (int, error) {
416 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
417 return 0, err
418 }
419 return t.Conn.Write(b)
420}
421
David Benjamin8e6db492015-07-25 18:29:23 -0400422func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400423 if !test.noSessionCache {
424 if config.ClientSessionCache == nil {
425 config.ClientSessionCache = NewLRUClientSessionCache(1)
426 }
427 if config.ServerSessionCache == nil {
428 config.ServerSessionCache = NewLRUServerSessionCache(1)
429 }
430 }
431 if test.testType == clientTest {
432 if len(config.Certificates) == 0 {
433 config.Certificates = []Certificate{rsaCertificate}
434 }
435 } else {
436 // Supply a ServerName to ensure a constant session cache key,
437 // rather than falling back to net.Conn.RemoteAddr.
438 if len(config.ServerName) == 0 {
439 config.ServerName = "test"
440 }
441 }
442 if *fuzzer {
443 config.Bugs.NullAllCiphers = true
444 }
David Benjamine54af062016-08-08 19:21:18 -0400445
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 {
David Benjamind2ba8892016-09-20 19:41:04 -0400727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
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 Benjamin46662482016-08-17 00:51:00 -0400834 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400835 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400836 resumeCount++
837 if test.resumeRenewedSession {
838 resumeCount++
839 }
840 }
841
842 if resumeCount > 0 {
843 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400844 }
845
David Benjamine58c4f52014-08-24 03:47:07 -0400846 if test.shimWritesFirst {
847 flags = append(flags, "-shim-writes-first")
848 }
849
David Benjamin30789da2015-08-29 22:56:45 -0400850 if test.shimShutsDown {
851 flags = append(flags, "-shim-shuts-down")
852 }
853
David Benjaminc565ebb2015-04-03 04:06:36 -0400854 if test.exportKeyingMaterial > 0 {
855 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
856 flags = append(flags, "-export-label", test.exportLabel)
857 flags = append(flags, "-export-context", test.exportContext)
858 if test.useExportContext {
859 flags = append(flags, "-use-export-context")
860 }
861 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700862 if test.expectResumeRejected {
863 flags = append(flags, "-expect-session-miss")
864 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400865
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700866 if test.testTLSUnique {
867 flags = append(flags, "-tls-unique")
868 }
869
David Benjamin025b3d32014-07-01 19:53:04 -0400870 flags = append(flags, test.flags...)
871
872 var shim *exec.Cmd
873 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700874 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700875 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700876 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500877 } else if *useLLDB {
878 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400879 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400881 }
David Benjamin025b3d32014-07-01 19:53:04 -0400882 shim.Stdin = os.Stdin
883 var stdoutBuf, stderrBuf bytes.Buffer
884 shim.Stdout = &stdoutBuf
885 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800886 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500887 shim.Env = os.Environ()
888 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800889 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400890 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800891 }
892 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
893 }
David Benjamin025b3d32014-07-01 19:53:04 -0400894
895 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700896 panic(err)
897 }
David Benjamin87c8a642015-02-21 01:54:29 -0500898 waitChan := make(chan error, 1)
899 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700900
901 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700902
David Benjamin7a4aaa42016-09-20 17:58:14 -0400903 if *deterministic {
904 config.Rand = &deterministicRand{}
905 }
906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400940 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800941 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200942 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
943 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800944 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200945 case 89:
946 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400947 case 99:
948 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800949 }
950 }
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin9bea3492016-03-02 10:59:16 -0500952 // Account for Windows line endings.
953 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
954 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500955
956 // Separate the errors from the shim and those from tools like
957 // AddressSanitizer.
958 var extraStderr string
959 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
960 stderr = stderrParts[0]
961 extraStderr = stderrParts[1]
962 }
963
Adam Langley95c29f32014-06-20 12:00:00 -0700964 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700965 expectedError := translateExpectedError(test.expectedError)
966 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200967
Adam Langleyac61fa32014-06-23 12:03:11 -0700968 localError := "none"
969 if err != nil {
970 localError = err.Error()
971 }
972 if len(test.expectedLocalError) != 0 {
973 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
974 }
Adam Langley95c29f32014-06-20 12:00:00 -0700975
976 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700977 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700978 if childErr != nil {
979 childError = childErr.Error()
980 }
981
982 var msg string
983 switch {
984 case failed && !test.shouldFail:
985 msg = "unexpected failure"
986 case !failed && test.shouldFail:
987 msg = "unexpected success"
988 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700989 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700990 default:
991 panic("internal error")
992 }
993
David Benjamin9aafb642016-09-20 19:36:53 -0400994 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700995 }
996
David Benjamind2ba8892016-09-20 19:41:04 -0400997 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500998 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700999 }
1000
David Benjamind2ba8892016-09-20 19:41:04 -04001001 if *useValgrind && isValgrindError {
1002 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1003 }
1004
Adam Langley95c29f32014-06-20 12:00:00 -07001005 return nil
1006}
1007
1008var tlsVersions = []struct {
1009 name string
1010 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001011 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001012 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001013}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001014 {"SSL3", VersionSSL30, "-no-ssl3", false},
1015 {"TLS1", VersionTLS10, "-no-tls1", true},
1016 {"TLS11", VersionTLS11, "-no-tls11", false},
1017 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001018 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001019}
1020
1021var testCipherSuites = []struct {
1022 name string
1023 id uint16
1024}{
1025 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1033 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001035 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1036 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1039 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1041 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001042 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001043 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001044 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001045 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001046 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001049 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001050 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001051 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001052 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001053 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001054 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1055 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1056 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1057 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001058 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1059 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001060 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1061 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001062 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001063 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1064 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001065 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001066}
1067
David Benjamin8b8c0062014-11-23 02:47:52 -05001068func hasComponent(suiteName, component string) bool {
1069 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1070}
1071
David Benjaminf7768e42014-08-31 02:06:47 -04001072func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001073 return hasComponent(suiteName, "GCM") ||
1074 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001075 hasComponent(suiteName, "SHA384") ||
1076 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001077}
1078
Nick Harper1fd39d82016-06-14 18:14:35 -07001079func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001080 // Only AEADs.
1081 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1082 return false
1083 }
1084 // No old CHACHA20_POLY1305.
1085 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1086 return false
1087 }
1088 // Must have ECDHE.
1089 // TODO(davidben,svaldez): Add pure PSK support.
1090 if !hasComponent(suiteName, "ECDHE") {
1091 return false
1092 }
1093 // TODO(davidben,svaldez): Add PSK support.
1094 if hasComponent(suiteName, "PSK") {
1095 return false
1096 }
1097 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001098}
1099
David Benjamin8b8c0062014-11-23 02:47:52 -05001100func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001101 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001102}
1103
Adam Langleya7997f12015-05-14 17:38:50 -07001104func bigFromHex(hex string) *big.Int {
1105 ret, ok := new(big.Int).SetString(hex, 16)
1106 if !ok {
1107 panic("failed to parse hex number 0x" + hex)
1108 }
1109 return ret
1110}
1111
Adam Langley7c803a62015-06-15 15:35:05 -07001112func addBasicTests() {
1113 basicTests := []testCase{
1114 {
Adam Langley7c803a62015-06-15 15:35:05 -07001115 name: "NoFallbackSCSV",
1116 config: Config{
1117 Bugs: ProtocolBugs{
1118 FailIfNotFallbackSCSV: true,
1119 },
1120 },
1121 shouldFail: true,
1122 expectedLocalError: "no fallback SCSV found",
1123 },
1124 {
1125 name: "SendFallbackSCSV",
1126 config: Config{
1127 Bugs: ProtocolBugs{
1128 FailIfNotFallbackSCSV: true,
1129 },
1130 },
1131 flags: []string{"-fallback-scsv"},
1132 },
1133 {
1134 name: "ClientCertificateTypes",
1135 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001136 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001137 ClientAuth: RequestClientCert,
1138 ClientCertificateTypes: []byte{
1139 CertTypeDSSSign,
1140 CertTypeRSASign,
1141 CertTypeECDSASign,
1142 },
1143 },
1144 flags: []string{
1145 "-expect-certificate-types",
1146 base64.StdEncoding.EncodeToString([]byte{
1147 CertTypeDSSSign,
1148 CertTypeRSASign,
1149 CertTypeECDSASign,
1150 }),
1151 },
1152 },
1153 {
Adam Langley7c803a62015-06-15 15:35:05 -07001154 name: "UnauthenticatedECDH",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 UnauthenticatedECDH: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
1166 name: "SkipCertificateStatus",
1167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1170 Bugs: ProtocolBugs{
1171 SkipCertificateStatus: true,
1172 },
1173 },
1174 flags: []string{
1175 "-enable-ocsp-stapling",
1176 },
1177 },
1178 {
1179 name: "SkipServerKeyExchange",
1180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001181 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001182 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1183 Bugs: ProtocolBugs{
1184 SkipServerKeyExchange: true,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":UNEXPECTED_MESSAGE:",
1189 },
1190 {
Adam Langley7c803a62015-06-15 15:35:05 -07001191 testType: serverTest,
1192 name: "Alert",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1200 },
1201 {
1202 protocol: dtls,
1203 testType: serverTest,
1204 name: "Alert-DTLS",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1212 },
1213 {
1214 testType: serverTest,
1215 name: "FragmentAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 FragmentAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "FragmentAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 FragmentAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
1239 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001240 name: "DoubleAlert",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 DoubleAlert: true,
1244 SendSpuriousAlert: alertRecordOverflow,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":BAD_ALERT:",
1249 },
1250 {
1251 protocol: dtls,
1252 testType: serverTest,
1253 name: "DoubleAlert-DTLS",
1254 config: Config{
1255 Bugs: ProtocolBugs{
1256 DoubleAlert: true,
1257 SendSpuriousAlert: alertRecordOverflow,
1258 },
1259 },
1260 shouldFail: true,
1261 expectedError: ":BAD_ALERT:",
1262 },
1263 {
Adam Langley7c803a62015-06-15 15:35:05 -07001264 name: "SkipNewSessionTicket",
1265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001266 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001267 Bugs: ProtocolBugs{
1268 SkipNewSessionTicket: true,
1269 },
1270 },
1271 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001272 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001273 },
1274 {
1275 testType: serverTest,
1276 name: "FallbackSCSV",
1277 config: Config{
1278 MaxVersion: VersionTLS11,
1279 Bugs: ProtocolBugs{
1280 SendFallbackSCSV: true,
1281 },
1282 },
1283 shouldFail: true,
1284 expectedError: ":INAPPROPRIATE_FALLBACK:",
1285 },
1286 {
1287 testType: serverTest,
1288 name: "FallbackSCSV-VersionMatch",
1289 config: Config{
1290 Bugs: ProtocolBugs{
1291 SendFallbackSCSV: true,
1292 },
1293 },
1294 },
1295 {
1296 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001297 name: "FallbackSCSV-VersionMatch-TLS12",
1298 config: Config{
1299 MaxVersion: VersionTLS12,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1305 },
1306 {
1307 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001308 name: "FragmentedClientVersion",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 MaxHandshakeRecordLength: 1,
1312 FragmentClientVersion: true,
1313 },
1314 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001315 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001316 },
1317 {
Adam Langley7c803a62015-06-15 15:35:05 -07001318 testType: serverTest,
1319 name: "HttpGET",
1320 sendPrefix: "GET / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpPOST",
1327 sendPrefix: "POST / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpHEAD",
1334 sendPrefix: "HEAD / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpPUT",
1341 sendPrefix: "PUT / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpCONNECT",
1348 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTPS_PROXY_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "Garbage",
1355 sendPrefix: "blah",
1356 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001357 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001358 },
1359 {
Adam Langley7c803a62015-06-15 15:35:05 -07001360 name: "RSAEphemeralKey",
1361 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001362 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001363 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1364 Bugs: ProtocolBugs{
1365 RSAEphemeralKey: true,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":UNEXPECTED_MESSAGE:",
1370 },
1371 {
1372 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001373 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
1378 protocol: dtls,
1379 name: "DisableEverything-DTLS",
1380 flags: []string{"-no-tls12", "-no-tls1"},
1381 shouldFail: true,
1382 expectedError: ":WRONG_SSL_VERSION:",
1383 },
1384 {
Adam Langley7c803a62015-06-15 15:35:05 -07001385 protocol: dtls,
1386 testType: serverTest,
1387 name: "MTU",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 MaxPacketLength: 256,
1391 },
1392 },
1393 flags: []string{"-mtu", "256"},
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "MTUExceeded",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 MaxPacketLength: 255,
1402 },
1403 },
1404 flags: []string{"-mtu", "256"},
1405 shouldFail: true,
1406 expectedLocalError: "dtls: exceeded maximum packet length",
1407 },
1408 {
1409 name: "CertMismatchRSA",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001413 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001414 Bugs: ProtocolBugs{
1415 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1420 },
1421 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001422 name: "CertMismatchRSA-TLS13",
1423 config: Config{
1424 MaxVersion: VersionTLS13,
1425 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1426 Certificates: []Certificate{ecdsaP256Certificate},
1427 Bugs: ProtocolBugs{
1428 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1433 },
1434 {
Adam Langley7c803a62015-06-15 15:35:05 -07001435 name: "CertMismatchECDSA",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001439 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001440 Bugs: ProtocolBugs{
1441 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1446 },
1447 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001448 name: "CertMismatchECDSA-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Certificates: []Certificate{rsaCertificate},
1453 Bugs: ProtocolBugs{
1454 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1459 },
1460 {
Adam Langley7c803a62015-06-15 15:35:05 -07001461 name: "EmptyCertificateList",
1462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001463 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 EmptyCertificateList: true,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":DECODE_ERROR:",
1471 },
1472 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001473 name: "EmptyCertificateList-TLS13",
1474 config: Config{
1475 MaxVersion: VersionTLS13,
1476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1477 Bugs: ProtocolBugs{
1478 EmptyCertificateList: true,
1479 },
1480 },
1481 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001482 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001483 },
1484 {
Adam Langley7c803a62015-06-15 15:35:05 -07001485 name: "TLSFatalBadPackets",
1486 damageFirstWrite: true,
1487 shouldFail: true,
1488 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1489 },
1490 {
1491 protocol: dtls,
1492 name: "DTLSIgnoreBadPackets",
1493 damageFirstWrite: true,
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets-Async",
1498 damageFirstWrite: true,
1499 flags: []string{"-async"},
1500 },
1501 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001502 name: "AppDataBeforeHandshake",
1503 config: Config{
1504 Bugs: ProtocolBugs{
1505 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1506 },
1507 },
1508 shouldFail: true,
1509 expectedError: ":UNEXPECTED_RECORD:",
1510 },
1511 {
1512 name: "AppDataBeforeHandshake-Empty",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 AppDataBeforeHandshake: []byte{},
1516 },
1517 },
1518 shouldFail: true,
1519 expectedError: ":UNEXPECTED_RECORD:",
1520 },
1521 {
1522 protocol: dtls,
1523 name: "AppDataBeforeHandshake-DTLS",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_RECORD:",
1531 },
1532 {
1533 protocol: dtls,
1534 name: "AppDataBeforeHandshake-DTLS-Empty",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 AppDataBeforeHandshake: []byte{},
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 },
1543 {
Adam Langley7c803a62015-06-15 15:35:05 -07001544 name: "AppDataAfterChangeCipherSpec",
1545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001546 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1549 },
1550 },
1551 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001552 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001553 },
1554 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 name: "AppDataAfterChangeCipherSpec-Empty",
1556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001557 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001558 Bugs: ProtocolBugs{
1559 AppDataAfterChangeCipherSpec: []byte{},
1560 },
1561 },
1562 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001563 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001564 },
1565 {
Adam Langley7c803a62015-06-15 15:35:05 -07001566 protocol: dtls,
1567 name: "AppDataAfterChangeCipherSpec-DTLS",
1568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001569 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001570 Bugs: ProtocolBugs{
1571 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1572 },
1573 },
1574 // BoringSSL's DTLS implementation will drop the out-of-order
1575 // application data.
1576 },
1577 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001578 protocol: dtls,
1579 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001581 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001582 Bugs: ProtocolBugs{
1583 AppDataAfterChangeCipherSpec: []byte{},
1584 },
1585 },
1586 // BoringSSL's DTLS implementation will drop the out-of-order
1587 // application data.
1588 },
1589 {
Adam Langley7c803a62015-06-15 15:35:05 -07001590 name: "AlertAfterChangeCipherSpec",
1591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001592 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001593 Bugs: ProtocolBugs{
1594 AlertAfterChangeCipherSpec: alertRecordOverflow,
1595 },
1596 },
1597 shouldFail: true,
1598 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1599 },
1600 {
1601 protocol: dtls,
1602 name: "AlertAfterChangeCipherSpec-DTLS",
1603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001604 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001605 Bugs: ProtocolBugs{
1606 AlertAfterChangeCipherSpec: alertRecordOverflow,
1607 },
1608 },
1609 shouldFail: true,
1610 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1611 },
1612 {
1613 protocol: dtls,
1614 name: "ReorderHandshakeFragments-Small-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 ReorderHandshakeFragments: true,
1618 // Small enough that every handshake message is
1619 // fragmented.
1620 MaxHandshakeRecordLength: 2,
1621 },
1622 },
1623 },
1624 {
1625 protocol: dtls,
1626 name: "ReorderHandshakeFragments-Large-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 ReorderHandshakeFragments: true,
1630 // Large enough that no handshake message is
1631 // fragmented.
1632 MaxHandshakeRecordLength: 2048,
1633 },
1634 },
1635 },
1636 {
1637 protocol: dtls,
1638 name: "MixCompleteMessageWithFragments-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 ReorderHandshakeFragments: true,
1642 MixCompleteMessageWithFragments: true,
1643 MaxHandshakeRecordLength: 2,
1644 },
1645 },
1646 },
1647 {
1648 name: "SendInvalidRecordType",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SendInvalidRecordType-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SendInvalidRecordType: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":UNEXPECTED_RECORD:",
1667 },
1668 {
1669 name: "FalseStart-SkipServerSecondLeg",
1670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001671 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1673 NextProtos: []string{"foo"},
1674 Bugs: ProtocolBugs{
1675 SkipNewSessionTicket: true,
1676 SkipChangeCipherSpec: true,
1677 SkipFinished: true,
1678 ExpectFalseStart: true,
1679 },
1680 },
1681 flags: []string{
1682 "-false-start",
1683 "-handshake-never-done",
1684 "-advertise-alpn", "\x03foo",
1685 },
1686 shimWritesFirst: true,
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_RECORD:",
1689 },
1690 {
1691 name: "FalseStart-SkipServerSecondLeg-Implicit",
1692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001693 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1695 NextProtos: []string{"foo"},
1696 Bugs: ProtocolBugs{
1697 SkipNewSessionTicket: true,
1698 SkipChangeCipherSpec: true,
1699 SkipFinished: true,
1700 },
1701 },
1702 flags: []string{
1703 "-implicit-handshake",
1704 "-false-start",
1705 "-handshake-never-done",
1706 "-advertise-alpn", "\x03foo",
1707 },
1708 shouldFail: true,
1709 expectedError: ":UNEXPECTED_RECORD:",
1710 },
1711 {
1712 testType: serverTest,
1713 name: "FailEarlyCallback",
1714 flags: []string{"-fail-early-callback"},
1715 shouldFail: true,
1716 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001717 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001718 },
1719 {
Adam Langley7c803a62015-06-15 15:35:05 -07001720 protocol: dtls,
1721 name: "FragmentMessageTypeMismatch-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 MaxHandshakeRecordLength: 2,
1725 FragmentMessageTypeMismatch: true,
1726 },
1727 },
1728 shouldFail: true,
1729 expectedError: ":FRAGMENT_MISMATCH:",
1730 },
1731 {
1732 protocol: dtls,
1733 name: "FragmentMessageLengthMismatch-DTLS",
1734 config: Config{
1735 Bugs: ProtocolBugs{
1736 MaxHandshakeRecordLength: 2,
1737 FragmentMessageLengthMismatch: true,
1738 },
1739 },
1740 shouldFail: true,
1741 expectedError: ":FRAGMENT_MISMATCH:",
1742 },
1743 {
1744 protocol: dtls,
1745 name: "SplitFragments-Header-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 SplitFragments: 2,
1749 },
1750 },
1751 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001752 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001753 },
1754 {
1755 protocol: dtls,
1756 name: "SplitFragments-Boundary-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 SplitFragments: dtlsRecordHeaderLen,
1760 },
1761 },
1762 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001763 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001764 },
1765 {
1766 protocol: dtls,
1767 name: "SplitFragments-Body-DTLS",
1768 config: Config{
1769 Bugs: ProtocolBugs{
1770 SplitFragments: dtlsRecordHeaderLen + 1,
1771 },
1772 },
1773 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001774 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001775 },
1776 {
1777 protocol: dtls,
1778 name: "SendEmptyFragments-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 SendEmptyFragments: true,
1782 },
1783 },
1784 },
1785 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 name: "BadFinished-Client",
1787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001788 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001797 name: "BadFinished-Client-TLS13",
1798 config: Config{
1799 MaxVersion: VersionTLS13,
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 },
1803 },
1804 shouldFail: true,
1805 expectedError: ":DIGEST_CHECK_FAILED:",
1806 },
1807 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001808 testType: serverTest,
1809 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001811 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 },
1815 },
1816 shouldFail: true,
1817 expectedError: ":DIGEST_CHECK_FAILED:",
1818 },
1819 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001820 testType: serverTest,
1821 name: "BadFinished-Server-TLS13",
1822 config: Config{
1823 MaxVersion: VersionTLS13,
1824 Bugs: ProtocolBugs{
1825 BadFinished: true,
1826 },
1827 },
1828 shouldFail: true,
1829 expectedError: ":DIGEST_CHECK_FAILED:",
1830 },
1831 {
Adam Langley7c803a62015-06-15 15:35:05 -07001832 name: "FalseStart-BadFinished",
1833 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001834 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1836 NextProtos: []string{"foo"},
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 ExpectFalseStart: true,
1840 },
1841 },
1842 flags: []string{
1843 "-false-start",
1844 "-handshake-never-done",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":DIGEST_CHECK_FAILED:",
1850 },
1851 {
1852 name: "NoFalseStart-NoALPN",
1853 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1856 Bugs: ProtocolBugs{
1857 ExpectFalseStart: true,
1858 AlertBeforeFalseStartTest: alertAccessDenied,
1859 },
1860 },
1861 flags: []string{
1862 "-false-start",
1863 },
1864 shimWritesFirst: true,
1865 shouldFail: true,
1866 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1867 expectedLocalError: "tls: peer did not false start: EOF",
1868 },
1869 {
1870 name: "NoFalseStart-NoAEAD",
1871 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001872 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 NextProtos: []string{"foo"},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1887 expectedLocalError: "tls: peer did not false start: EOF",
1888 },
1889 {
1890 name: "NoFalseStart-RSA",
1891 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001892 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001893 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1894 NextProtos: []string{"foo"},
1895 Bugs: ProtocolBugs{
1896 ExpectFalseStart: true,
1897 AlertBeforeFalseStartTest: alertAccessDenied,
1898 },
1899 },
1900 flags: []string{
1901 "-false-start",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1907 expectedLocalError: "tls: peer did not false start: EOF",
1908 },
1909 {
1910 name: "NoFalseStart-DHE_RSA",
1911 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001912 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001913 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1914 NextProtos: []string{"foo"},
1915 Bugs: ProtocolBugs{
1916 ExpectFalseStart: true,
1917 AlertBeforeFalseStartTest: alertAccessDenied,
1918 },
1919 },
1920 flags: []string{
1921 "-false-start",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shimWritesFirst: true,
1925 shouldFail: true,
1926 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1927 expectedLocalError: "tls: peer did not false start: EOF",
1928 },
1929 {
Adam Langley7c803a62015-06-15 15:35:05 -07001930 protocol: dtls,
1931 name: "SendSplitAlert-Sync",
1932 config: Config{
1933 Bugs: ProtocolBugs{
1934 SendSplitAlert: true,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "SendSplitAlert-Async",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 SendSplitAlert: true,
1944 },
1945 },
1946 flags: []string{"-async"},
1947 },
1948 {
1949 protocol: dtls,
1950 name: "PackDTLSHandshake",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 MaxHandshakeRecordLength: 2,
1954 PackHandshakeFragments: 20,
1955 PackHandshakeRecords: 200,
1956 },
1957 },
1958 },
1959 {
Adam Langley7c803a62015-06-15 15:35:05 -07001960 name: "SendEmptyRecords-Pass",
1961 sendEmptyRecords: 32,
1962 },
1963 {
1964 name: "SendEmptyRecords",
1965 sendEmptyRecords: 33,
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
1970 name: "SendEmptyRecords-Async",
1971 sendEmptyRecords: 33,
1972 flags: []string{"-async"},
1973 shouldFail: true,
1974 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 name: "SendWarningAlerts-Pass",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 4,
1982 },
1983 {
David Benjamine8e84b92016-08-03 15:39:47 -04001984 protocol: dtls,
1985 name: "SendWarningAlerts-DTLS-Pass",
1986 config: Config{
1987 MaxVersion: VersionTLS12,
1988 },
Adam Langley7c803a62015-06-15 15:35:05 -07001989 sendWarningAlerts: 4,
1990 },
1991 {
David Benjamine8e84b92016-08-03 15:39:47 -04001992 name: "SendWarningAlerts-TLS13",
1993 config: Config{
1994 MaxVersion: VersionTLS13,
1995 },
1996 sendWarningAlerts: 4,
1997 shouldFail: true,
1998 expectedError: ":BAD_ALERT:",
1999 expectedLocalError: "remote error: error decoding message",
2000 },
2001 {
2002 name: "SendWarningAlerts",
2003 config: Config{
2004 MaxVersion: VersionTLS12,
2005 },
Adam Langley7c803a62015-06-15 15:35:05 -07002006 sendWarningAlerts: 5,
2007 shouldFail: true,
2008 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2009 },
2010 {
David Benjamine8e84b92016-08-03 15:39:47 -04002011 name: "SendWarningAlerts-Async",
2012 config: Config{
2013 MaxVersion: VersionTLS12,
2014 },
Adam Langley7c803a62015-06-15 15:35:05 -07002015 sendWarningAlerts: 5,
2016 flags: []string{"-async"},
2017 shouldFail: true,
2018 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2019 },
David Benjaminba4594a2015-06-18 18:36:15 -04002020 {
Steven Valdez32635b82016-08-16 11:25:03 -04002021 name: "SendKeyUpdates",
2022 config: Config{
2023 MaxVersion: VersionTLS13,
2024 },
2025 sendKeyUpdates: 33,
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_KEY_UPDATES:",
2028 },
2029 {
David Benjaminba4594a2015-06-18 18:36:15 -04002030 name: "EmptySessionID",
2031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002032 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
David Benjamin30789da2015-08-29 22:56:45 -04002038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 {
David Benjaminfa214e42016-05-10 17:03:10 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
David Benjamindd6fed92015-10-23 17:41:12 -04002121 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
David Benjamin46662482016-08-17 00:51:00 -04002132 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002133 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002134 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002135 name: "BadHelloRequest-1",
2136 renegotiate: 1,
2137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002138 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002139 Bugs: ProtocolBugs{
2140 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2141 },
2142 },
2143 flags: []string{
2144 "-renegotiate-freely",
2145 "-expect-total-renegotiations", "1",
2146 },
2147 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002148 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002149 },
2150 {
2151 name: "BadHelloRequest-2",
2152 renegotiate: 1,
2153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002154 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002155 Bugs: ProtocolBugs{
2156 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2157 },
2158 },
2159 flags: []string{
2160 "-renegotiate-freely",
2161 "-expect-total-renegotiations", "1",
2162 },
2163 shouldFail: true,
2164 expectedError: ":BAD_HELLO_REQUEST:",
2165 },
David Benjaminef1b0092015-11-21 14:05:44 -05002166 {
2167 testType: serverTest,
2168 name: "SupportTicketsWithSessionID",
2169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002171 SessionTicketsDisabled: true,
2172 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002173 resumeConfig: &Config{
2174 MaxVersion: VersionTLS12,
2175 },
David Benjaminef1b0092015-11-21 14:05:44 -05002176 resumeSession: true,
2177 },
David Benjamin02edcd02016-07-27 17:40:37 -04002178 {
2179 protocol: dtls,
2180 name: "DTLS-SendExtraFinished",
2181 config: Config{
2182 Bugs: ProtocolBugs{
2183 SendExtraFinished: true,
2184 },
2185 },
2186 shouldFail: true,
2187 expectedError: ":UNEXPECTED_RECORD:",
2188 },
2189 {
2190 protocol: dtls,
2191 name: "DTLS-SendExtraFinished-Reordered",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 MaxHandshakeRecordLength: 2,
2195 ReorderHandshakeFragments: true,
2196 SendExtraFinished: true,
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":UNEXPECTED_RECORD:",
2201 },
David Benjamine97fb482016-07-29 09:23:07 -04002202 {
2203 testType: serverTest,
2204 name: "V2ClientHello-EmptyRecordPrefix",
2205 config: Config{
2206 // Choose a cipher suite that does not involve
2207 // elliptic curves, so no extensions are
2208 // involved.
2209 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002210 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002211 Bugs: ProtocolBugs{
2212 SendV2ClientHello: true,
2213 },
2214 },
2215 sendPrefix: string([]byte{
2216 byte(recordTypeHandshake),
2217 3, 1, // version
2218 0, 0, // length
2219 }),
2220 // A no-op empty record may not be sent before V2ClientHello.
2221 shouldFail: true,
2222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
2224 {
2225 testType: serverTest,
2226 name: "V2ClientHello-WarningAlertPrefix",
2227 config: Config{
2228 // Choose a cipher suite that does not involve
2229 // elliptic curves, so no extensions are
2230 // involved.
2231 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002232 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002233 Bugs: ProtocolBugs{
2234 SendV2ClientHello: true,
2235 },
2236 },
2237 sendPrefix: string([]byte{
2238 byte(recordTypeAlert),
2239 3, 1, // version
2240 0, 2, // length
2241 alertLevelWarning, byte(alertDecompressionFailure),
2242 }),
2243 // A no-op warning alert may not be sent before V2ClientHello.
2244 shouldFail: true,
2245 expectedError: ":WRONG_VERSION_NUMBER:",
2246 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002247 {
2248 testType: clientTest,
2249 name: "KeyUpdate",
2250 config: Config{
2251 MaxVersion: VersionTLS13,
2252 Bugs: ProtocolBugs{
2253 SendKeyUpdateBeforeEveryAppDataRecord: true,
2254 },
2255 },
2256 },
David Benjaminabe94e32016-09-04 14:18:58 -04002257 {
2258 name: "SendSNIWarningAlert",
2259 config: Config{
2260 MaxVersion: VersionTLS12,
2261 Bugs: ProtocolBugs{
2262 SendSNIWarningAlert: true,
2263 },
2264 },
2265 },
David Benjaminc241d792016-09-09 10:34:20 -04002266 {
2267 testType: serverTest,
2268 name: "ExtraCompressionMethods-TLS12",
2269 config: Config{
2270 MaxVersion: VersionTLS12,
2271 Bugs: ProtocolBugs{
2272 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2273 },
2274 },
2275 },
2276 {
2277 testType: serverTest,
2278 name: "ExtraCompressionMethods-TLS13",
2279 config: Config{
2280 MaxVersion: VersionTLS13,
2281 Bugs: ProtocolBugs{
2282 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2283 },
2284 },
2285 shouldFail: true,
2286 expectedError: ":INVALID_COMPRESSION_LIST:",
2287 expectedLocalError: "remote error: illegal parameter",
2288 },
2289 {
2290 testType: serverTest,
2291 name: "NoNullCompression-TLS12",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2296 },
2297 },
2298 shouldFail: true,
2299 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2300 expectedLocalError: "remote error: illegal parameter",
2301 },
2302 {
2303 testType: serverTest,
2304 name: "NoNullCompression-TLS13",
2305 config: Config{
2306 MaxVersion: VersionTLS13,
2307 Bugs: ProtocolBugs{
2308 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2309 },
2310 },
2311 shouldFail: true,
2312 expectedError: ":INVALID_COMPRESSION_LIST:",
2313 expectedLocalError: "remote error: illegal parameter",
2314 },
Adam Langley7c803a62015-06-15 15:35:05 -07002315 }
Adam Langley7c803a62015-06-15 15:35:05 -07002316 testCases = append(testCases, basicTests...)
2317}
2318
Adam Langley95c29f32014-06-20 12:00:00 -07002319func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002320 const bogusCipher = 0xfe00
2321
Adam Langley95c29f32014-06-20 12:00:00 -07002322 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002323 const psk = "12345"
2324 const pskIdentity = "luggage combo"
2325
Adam Langley95c29f32014-06-20 12:00:00 -07002326 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002327 var certFile string
2328 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002329 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002330 cert = ecdsaP256Certificate
2331 certFile = ecdsaP256CertificateFile
2332 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002333 } else {
David Benjamin33863262016-07-08 17:20:12 -07002334 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002335 certFile = rsaCertificateFile
2336 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002337 }
2338
David Benjamin48cae082014-10-27 01:06:24 -04002339 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002340 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002341 flags = append(flags,
2342 "-psk", psk,
2343 "-psk-identity", pskIdentity)
2344 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002345 if hasComponent(suite.name, "NULL") {
2346 // NULL ciphers must be explicitly enabled.
2347 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2348 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002349 if hasComponent(suite.name, "CECPQ1") {
2350 // CECPQ1 ciphers must be explicitly enabled.
2351 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2352 }
David Benjamin881f1962016-08-10 18:29:12 -04002353 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2354 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2355 // for now.
2356 flags = append(flags, "-cipher", suite.name)
2357 }
David Benjamin48cae082014-10-27 01:06:24 -04002358
Adam Langley95c29f32014-06-20 12:00:00 -07002359 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002360 for _, protocol := range []protocol{tls, dtls} {
2361 var prefix string
2362 if protocol == dtls {
2363 if !ver.hasDTLS {
2364 continue
2365 }
2366 prefix = "D"
2367 }
Adam Langley95c29f32014-06-20 12:00:00 -07002368
David Benjamin0407e762016-06-17 16:41:18 -04002369 var shouldServerFail, shouldClientFail bool
2370 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2371 // BoringSSL clients accept ECDHE on SSLv3, but
2372 // a BoringSSL server will never select it
2373 // because the extension is missing.
2374 shouldServerFail = true
2375 }
2376 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2377 shouldClientFail = true
2378 shouldServerFail = true
2379 }
David Benjamin54c217c2016-07-13 12:35:25 -04002380 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002381 shouldClientFail = true
2382 shouldServerFail = true
2383 }
David Benjamin0407e762016-06-17 16:41:18 -04002384 if !isDTLSCipher(suite.name) && protocol == dtls {
2385 shouldClientFail = true
2386 shouldServerFail = true
2387 }
David Benjamin4298d772015-12-19 00:18:25 -05002388
David Benjamin0407e762016-06-17 16:41:18 -04002389 var expectedServerError, expectedClientError string
2390 if shouldServerFail {
2391 expectedServerError = ":NO_SHARED_CIPHER:"
2392 }
2393 if shouldClientFail {
2394 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2395 }
David Benjamin025b3d32014-07-01 19:53:04 -04002396
David Benjamin6fd297b2014-08-11 18:43:38 -04002397 testCases = append(testCases, testCase{
2398 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002399 protocol: protocol,
2400
2401 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002402 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002403 MinVersion: ver.version,
2404 MaxVersion: ver.version,
2405 CipherSuites: []uint16{suite.id},
2406 Certificates: []Certificate{cert},
2407 PreSharedKey: []byte(psk),
2408 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002409 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002410 EnableAllCiphers: shouldServerFail,
2411 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002412 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002413 },
2414 certFile: certFile,
2415 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002416 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002417 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002418 shouldFail: shouldServerFail,
2419 expectedError: expectedServerError,
2420 })
2421
2422 testCases = append(testCases, testCase{
2423 testType: clientTest,
2424 protocol: protocol,
2425 name: prefix + ver.name + "-" + suite.name + "-client",
2426 config: Config{
2427 MinVersion: ver.version,
2428 MaxVersion: ver.version,
2429 CipherSuites: []uint16{suite.id},
2430 Certificates: []Certificate{cert},
2431 PreSharedKey: []byte(psk),
2432 PreSharedKeyIdentity: pskIdentity,
2433 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002434 EnableAllCiphers: shouldClientFail,
2435 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002436 },
2437 },
2438 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002439 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002440 shouldFail: shouldClientFail,
2441 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002442 })
David Benjamin2c99d282015-09-01 10:23:00 -04002443
Nick Harper1fd39d82016-06-14 18:14:35 -07002444 if !shouldClientFail {
2445 // Ensure the maximum record size is accepted.
2446 testCases = append(testCases, testCase{
2447 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2448 config: Config{
2449 MinVersion: ver.version,
2450 MaxVersion: ver.version,
2451 CipherSuites: []uint16{suite.id},
2452 Certificates: []Certificate{cert},
2453 PreSharedKey: []byte(psk),
2454 PreSharedKeyIdentity: pskIdentity,
2455 },
2456 flags: flags,
2457 messageLen: maxPlaintext,
2458 })
2459 }
2460 }
David Benjamin2c99d282015-09-01 10:23:00 -04002461 }
Adam Langley95c29f32014-06-20 12:00:00 -07002462 }
Adam Langleya7997f12015-05-14 17:38:50 -07002463
2464 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002465 name: "NoSharedCipher",
2466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002467 MaxVersion: VersionTLS12,
2468 CipherSuites: []uint16{},
2469 },
2470 shouldFail: true,
2471 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2472 })
2473
2474 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002475 name: "NoSharedCipher-TLS13",
2476 config: Config{
2477 MaxVersion: VersionTLS13,
2478 CipherSuites: []uint16{},
2479 },
2480 shouldFail: true,
2481 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2482 })
2483
2484 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002485 name: "UnsupportedCipherSuite",
2486 config: Config{
2487 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002488 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002489 Bugs: ProtocolBugs{
2490 IgnorePeerCipherPreferences: true,
2491 },
2492 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002493 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002494 shouldFail: true,
2495 expectedError: ":WRONG_CIPHER_RETURNED:",
2496 })
2497
2498 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002499 name: "ServerHelloBogusCipher",
2500 config: Config{
2501 MaxVersion: VersionTLS12,
2502 Bugs: ProtocolBugs{
2503 SendCipherSuite: bogusCipher,
2504 },
2505 },
2506 shouldFail: true,
2507 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2508 })
2509 testCases = append(testCases, testCase{
2510 name: "ServerHelloBogusCipher-TLS13",
2511 config: Config{
2512 MaxVersion: VersionTLS13,
2513 Bugs: ProtocolBugs{
2514 SendCipherSuite: bogusCipher,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2519 })
2520
2521 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002522 name: "WeakDH",
2523 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002524 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002525 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2526 Bugs: ProtocolBugs{
2527 // This is a 1023-bit prime number, generated
2528 // with:
2529 // openssl gendh 1023 | openssl asn1parse -i
2530 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2531 },
2532 },
2533 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002534 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002535 })
Adam Langleycef75832015-09-03 14:51:12 -07002536
David Benjamincd24a392015-11-11 13:23:05 -08002537 testCases = append(testCases, testCase{
2538 name: "SillyDH",
2539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002540 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002541 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2542 Bugs: ProtocolBugs{
2543 // This is a 4097-bit prime number, generated
2544 // with:
2545 // openssl gendh 4097 | openssl asn1parse -i
2546 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2547 },
2548 },
2549 shouldFail: true,
2550 expectedError: ":DH_P_TOO_LONG:",
2551 })
2552
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002553 // This test ensures that Diffie-Hellman public values are padded with
2554 // zeros so that they're the same length as the prime. This is to avoid
2555 // hitting a bug in yaSSL.
2556 testCases = append(testCases, testCase{
2557 testType: serverTest,
2558 name: "DHPublicValuePadded",
2559 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002560 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002561 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2562 Bugs: ProtocolBugs{
2563 RequireDHPublicValueLen: (1025 + 7) / 8,
2564 },
2565 },
2566 flags: []string{"-use-sparse-dh-prime"},
2567 })
David Benjamincd24a392015-11-11 13:23:05 -08002568
David Benjamin241ae832016-01-15 03:04:54 -05002569 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002570 testCases = append(testCases, testCase{
2571 testType: serverTest,
2572 name: "UnknownCipher",
2573 config: Config{
2574 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2575 },
2576 })
2577
David Benjamin78679342016-09-16 19:42:05 -04002578 // Test empty ECDHE_PSK identity hints work as expected.
2579 testCases = append(testCases, testCase{
2580 name: "EmptyECDHEPSKHint",
2581 config: Config{
2582 MaxVersion: VersionTLS12,
2583 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2584 PreSharedKey: []byte("secret"),
2585 },
2586 flags: []string{"-psk", "secret"},
2587 })
2588
2589 // Test empty PSK identity hints work as expected, even if an explicit
2590 // ServerKeyExchange is sent.
2591 testCases = append(testCases, testCase{
2592 name: "ExplicitEmptyPSKHint",
2593 config: Config{
2594 MaxVersion: VersionTLS12,
2595 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2596 PreSharedKey: []byte("secret"),
2597 Bugs: ProtocolBugs{
2598 AlwaysSendPreSharedKeyIdentityHint: true,
2599 },
2600 },
2601 flags: []string{"-psk", "secret"},
2602 })
2603
Adam Langleycef75832015-09-03 14:51:12 -07002604 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2605 // 1.1 specific cipher suite settings. A server is setup with the given
2606 // cipher lists and then a connection is made for each member of
2607 // expectations. The cipher suite that the server selects must match
2608 // the specified one.
2609 var versionSpecificCiphersTest = []struct {
2610 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2611 // expectations is a map from TLS version to cipher suite id.
2612 expectations map[uint16]uint16
2613 }{
2614 {
2615 // Test that the null case (where no version-specific ciphers are set)
2616 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002617 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2618 "", // no ciphers specifically for TLS ≥ 1.0
2619 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002620 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002621 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2622 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2623 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2624 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002625 },
2626 },
2627 {
2628 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2629 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002630 "DES-CBC3-SHA:AES128-SHA", // default
2631 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2632 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002633 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002635 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2636 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2637 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2638 },
2639 },
2640 {
2641 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2642 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002643 "DES-CBC3-SHA:AES128-SHA", // default
2644 "", // no ciphers specifically for TLS ≥ 1.0
2645 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002646 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2648 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002649 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2650 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2651 },
2652 },
2653 {
2654 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2655 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002656 "DES-CBC3-SHA:AES128-SHA", // default
2657 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2658 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002659 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002661 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2662 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2663 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2664 },
2665 },
2666 }
2667
2668 for i, test := range versionSpecificCiphersTest {
2669 for version, expectedCipherSuite := range test.expectations {
2670 flags := []string{"-cipher", test.ciphersDefault}
2671 if len(test.ciphersTLS10) > 0 {
2672 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2673 }
2674 if len(test.ciphersTLS11) > 0 {
2675 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2676 }
2677
2678 testCases = append(testCases, testCase{
2679 testType: serverTest,
2680 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2681 config: Config{
2682 MaxVersion: version,
2683 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002684 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002685 },
2686 flags: flags,
2687 expectedCipher: expectedCipherSuite,
2688 })
2689 }
2690 }
Adam Langley95c29f32014-06-20 12:00:00 -07002691}
2692
2693func addBadECDSASignatureTests() {
2694 for badR := BadValue(1); badR < NumBadValues; badR++ {
2695 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002696 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002697 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2698 config: Config{
2699 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002700 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002701 Bugs: ProtocolBugs{
2702 BadECDSAR: badR,
2703 BadECDSAS: badS,
2704 },
2705 },
2706 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002707 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002708 })
2709 }
2710 }
2711}
2712
Adam Langley80842bd2014-06-20 12:00:00 -07002713func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002714 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002715 name: "MaxCBCPadding",
2716 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002717 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002718 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2719 Bugs: ProtocolBugs{
2720 MaxPadding: true,
2721 },
2722 },
2723 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2724 })
David Benjamin025b3d32014-07-01 19:53:04 -04002725 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002726 name: "BadCBCPadding",
2727 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002728 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2730 Bugs: ProtocolBugs{
2731 PaddingFirstByteBad: true,
2732 },
2733 },
2734 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002735 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002736 })
2737 // OpenSSL previously had an issue where the first byte of padding in
2738 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002739 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002740 name: "BadCBCPadding255",
2741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002742 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2744 Bugs: ProtocolBugs{
2745 MaxPadding: true,
2746 PaddingFirstByteBadIf255: true,
2747 },
2748 },
2749 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2750 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002751 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002752 })
2753}
2754
Kenny Root7fdeaf12014-08-05 15:23:37 -07002755func addCBCSplittingTests() {
2756 testCases = append(testCases, testCase{
2757 name: "CBCRecordSplitting",
2758 config: Config{
2759 MaxVersion: VersionTLS10,
2760 MinVersion: VersionTLS10,
2761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2762 },
David Benjaminac8302a2015-09-01 17:18:15 -04002763 messageLen: -1, // read until EOF
2764 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002765 flags: []string{
2766 "-async",
2767 "-write-different-record-sizes",
2768 "-cbc-record-splitting",
2769 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002770 })
2771 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772 name: "CBCRecordSplittingPartialWrite",
2773 config: Config{
2774 MaxVersion: VersionTLS10,
2775 MinVersion: VersionTLS10,
2776 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2777 },
2778 messageLen: -1, // read until EOF
2779 flags: []string{
2780 "-async",
2781 "-write-different-record-sizes",
2782 "-cbc-record-splitting",
2783 "-partial-write",
2784 },
2785 })
2786}
2787
David Benjamin636293b2014-07-08 17:59:18 -04002788func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002789 // Add a dummy cert pool to stress certificate authority parsing.
2790 // TODO(davidben): Add tests that those values parse out correctly.
2791 certPool := x509.NewCertPool()
2792 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2793 if err != nil {
2794 panic(err)
2795 }
2796 certPool.AddCert(cert)
2797
David Benjamin636293b2014-07-08 17:59:18 -04002798 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002799 testCases = append(testCases, testCase{
2800 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002801 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002802 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 ClientAuth: RequireAnyClientCert,
2806 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002807 },
2808 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002809 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2810 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002811 },
2812 })
2813 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002814 testType: serverTest,
2815 name: ver.name + "-Server-ClientAuth-RSA",
2816 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002817 MinVersion: ver.version,
2818 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002819 Certificates: []Certificate{rsaCertificate},
2820 },
2821 flags: []string{"-require-any-client-certificate"},
2822 })
David Benjamine098ec22014-08-27 23:13:20 -04002823 if ver.version != VersionSSL30 {
2824 testCases = append(testCases, testCase{
2825 testType: serverTest,
2826 name: ver.name + "-Server-ClientAuth-ECDSA",
2827 config: Config{
2828 MinVersion: ver.version,
2829 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002830 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002831 },
2832 flags: []string{"-require-any-client-certificate"},
2833 })
2834 testCases = append(testCases, testCase{
2835 testType: clientTest,
2836 name: ver.name + "-Client-ClientAuth-ECDSA",
2837 config: Config{
2838 MinVersion: ver.version,
2839 MaxVersion: ver.version,
2840 ClientAuth: RequireAnyClientCert,
2841 ClientCAs: certPool,
2842 },
2843 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002846 },
2847 })
2848 }
Adam Langley37646832016-08-01 16:16:46 -07002849
2850 testCases = append(testCases, testCase{
2851 name: "NoClientCertificate-" + ver.name,
2852 config: Config{
2853 MinVersion: ver.version,
2854 MaxVersion: ver.version,
2855 ClientAuth: RequireAnyClientCert,
2856 },
2857 shouldFail: true,
2858 expectedLocalError: "client didn't provide a certificate",
2859 })
2860
2861 testCases = append(testCases, testCase{
2862 // Even if not configured to expect a certificate, OpenSSL will
2863 // return X509_V_OK as the verify_result.
2864 testType: serverTest,
2865 name: "NoClientCertificateRequested-Server-" + ver.name,
2866 config: Config{
2867 MinVersion: ver.version,
2868 MaxVersion: ver.version,
2869 },
2870 flags: []string{
2871 "-expect-verify-result",
2872 },
2873 // TODO(davidben): Switch this to true when TLS 1.3
2874 // supports session resumption.
2875 resumeSession: ver.version < VersionTLS13,
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // If a client certificate is not provided, OpenSSL will still
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificate-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 "-verify-peer",
2890 },
2891 // TODO(davidben): Switch this to true when TLS 1.3
2892 // supports session resumption.
2893 resumeSession: ver.version < VersionTLS13,
2894 })
2895
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: "RequireAnyClientCertificate-" + ver.name,
2899 config: Config{
2900 MinVersion: ver.version,
2901 MaxVersion: ver.version,
2902 },
2903 flags: []string{"-require-any-client-certificate"},
2904 shouldFail: true,
2905 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2906 })
2907
2908 if ver.version != VersionSSL30 {
2909 testCases = append(testCases, testCase{
2910 testType: serverTest,
2911 name: "SkipClientCertificate-" + ver.name,
2912 config: Config{
2913 MinVersion: ver.version,
2914 MaxVersion: ver.version,
2915 Bugs: ProtocolBugs{
2916 SkipClientCertificate: true,
2917 },
2918 },
2919 // Setting SSL_VERIFY_PEER allows anonymous clients.
2920 flags: []string{"-verify-peer"},
2921 shouldFail: true,
2922 expectedError: ":UNEXPECTED_MESSAGE:",
2923 })
2924 }
David Benjamin636293b2014-07-08 17:59:18 -04002925 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002926
David Benjaminc032dfa2016-05-12 14:54:57 -04002927 // Client auth is only legal in certificate-based ciphers.
2928 testCases = append(testCases, testCase{
2929 testType: clientTest,
2930 name: "ClientAuth-PSK",
2931 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002932 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002933 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2934 PreSharedKey: []byte("secret"),
2935 ClientAuth: RequireAnyClientCert,
2936 },
2937 flags: []string{
2938 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2939 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2940 "-psk", "secret",
2941 },
2942 shouldFail: true,
2943 expectedError: ":UNEXPECTED_MESSAGE:",
2944 })
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-ECDHE_PSK",
2948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002949 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002950 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002962
2963 // Regression test for a bug where the client CA list, if explicitly
2964 // set to NULL, was mis-encoded.
2965 testCases = append(testCases, testCase{
2966 testType: serverTest,
2967 name: "Null-Client-CA-List",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 Certificates: []Certificate{rsaCertificate},
2971 },
2972 flags: []string{
2973 "-require-any-client-certificate",
2974 "-use-null-client-ca-list",
2975 },
2976 })
David Benjamin636293b2014-07-08 17:59:18 -04002977}
2978
Adam Langley75712922014-10-10 16:23:43 -07002979func addExtendedMasterSecretTests() {
2980 const expectEMSFlag = "-expect-extended-master-secret"
2981
2982 for _, with := range []bool{false, true} {
2983 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002984 if with {
2985 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002986 }
2987
2988 for _, isClient := range []bool{false, true} {
2989 suffix := "-Server"
2990 testType := serverTest
2991 if isClient {
2992 suffix = "-Client"
2993 testType = clientTest
2994 }
2995
2996 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002997 // In TLS 1.3, the extension is irrelevant and
2998 // always reports as enabled.
2999 var flags []string
3000 if with || ver.version >= VersionTLS13 {
3001 flags = []string{expectEMSFlag}
3002 }
3003
Adam Langley75712922014-10-10 16:23:43 -07003004 test := testCase{
3005 testType: testType,
3006 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3007 config: Config{
3008 MinVersion: ver.version,
3009 MaxVersion: ver.version,
3010 Bugs: ProtocolBugs{
3011 NoExtendedMasterSecret: !with,
3012 RequireExtendedMasterSecret: with,
3013 },
3014 },
David Benjamin48cae082014-10-27 01:06:24 -04003015 flags: flags,
3016 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003017 }
3018 if test.shouldFail {
3019 test.expectedLocalError = "extended master secret required but not supported by peer"
3020 }
3021 testCases = append(testCases, test)
3022 }
3023 }
3024 }
3025
Adam Langleyba5934b2015-06-02 10:50:35 -07003026 for _, isClient := range []bool{false, true} {
3027 for _, supportedInFirstConnection := range []bool{false, true} {
3028 for _, supportedInResumeConnection := range []bool{false, true} {
3029 boolToWord := func(b bool) string {
3030 if b {
3031 return "Yes"
3032 }
3033 return "No"
3034 }
3035 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3036 if isClient {
3037 suffix += "Client"
3038 } else {
3039 suffix += "Server"
3040 }
3041
3042 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003043 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003044 Bugs: ProtocolBugs{
3045 RequireExtendedMasterSecret: true,
3046 },
3047 }
3048
3049 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003051 Bugs: ProtocolBugs{
3052 NoExtendedMasterSecret: true,
3053 },
3054 }
3055
3056 test := testCase{
3057 name: "ExtendedMasterSecret-" + suffix,
3058 resumeSession: true,
3059 }
3060
3061 if !isClient {
3062 test.testType = serverTest
3063 }
3064
3065 if supportedInFirstConnection {
3066 test.config = supportedConfig
3067 } else {
3068 test.config = noSupportConfig
3069 }
3070
3071 if supportedInResumeConnection {
3072 test.resumeConfig = &supportedConfig
3073 } else {
3074 test.resumeConfig = &noSupportConfig
3075 }
3076
3077 switch suffix {
3078 case "YesToYes-Client", "YesToYes-Server":
3079 // When a session is resumed, it should
3080 // still be aware that its master
3081 // secret was generated via EMS and
3082 // thus it's safe to use tls-unique.
3083 test.flags = []string{expectEMSFlag}
3084 case "NoToYes-Server":
3085 // If an original connection did not
3086 // contain EMS, but a resumption
3087 // handshake does, then a server should
3088 // not resume the session.
3089 test.expectResumeRejected = true
3090 case "YesToNo-Server":
3091 // Resuming an EMS session without the
3092 // EMS extension should cause the
3093 // server to abort the connection.
3094 test.shouldFail = true
3095 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3096 case "NoToYes-Client":
3097 // A client should abort a connection
3098 // where the server resumed a non-EMS
3099 // session but echoed the EMS
3100 // extension.
3101 test.shouldFail = true
3102 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3103 case "YesToNo-Client":
3104 // A client should abort a connection
3105 // where the server didn't echo EMS
3106 // when the session used it.
3107 test.shouldFail = true
3108 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3109 }
3110
3111 testCases = append(testCases, test)
3112 }
3113 }
3114 }
David Benjamin163c9562016-08-29 23:14:17 -04003115
3116 // Switching EMS on renegotiation is forbidden.
3117 testCases = append(testCases, testCase{
3118 name: "ExtendedMasterSecret-Renego-NoEMS",
3119 config: Config{
3120 MaxVersion: VersionTLS12,
3121 Bugs: ProtocolBugs{
3122 NoExtendedMasterSecret: true,
3123 NoExtendedMasterSecretOnRenegotiation: true,
3124 },
3125 },
3126 renegotiate: 1,
3127 flags: []string{
3128 "-renegotiate-freely",
3129 "-expect-total-renegotiations", "1",
3130 },
3131 })
3132
3133 testCases = append(testCases, testCase{
3134 name: "ExtendedMasterSecret-Renego-Upgrade",
3135 config: Config{
3136 MaxVersion: VersionTLS12,
3137 Bugs: ProtocolBugs{
3138 NoExtendedMasterSecret: true,
3139 },
3140 },
3141 renegotiate: 1,
3142 flags: []string{
3143 "-renegotiate-freely",
3144 "-expect-total-renegotiations", "1",
3145 },
3146 shouldFail: true,
3147 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Downgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecretOnRenegotiation: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
Adam Langley75712922014-10-10 16:23:43 -07003166}
3167
David Benjamin582ba042016-07-07 12:33:25 -07003168type stateMachineTestConfig struct {
3169 protocol protocol
3170 async bool
3171 splitHandshake, packHandshakeFlight bool
3172}
3173
David Benjamin43ec06f2014-08-05 02:28:57 -04003174// Adds tests that try to cover the range of the handshake state machine, under
3175// various conditions. Some of these are redundant with other tests, but they
3176// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003177func addAllStateMachineCoverageTests() {
3178 for _, async := range []bool{false, true} {
3179 for _, protocol := range []protocol{tls, dtls} {
3180 addStateMachineCoverageTests(stateMachineTestConfig{
3181 protocol: protocol,
3182 async: async,
3183 })
3184 addStateMachineCoverageTests(stateMachineTestConfig{
3185 protocol: protocol,
3186 async: async,
3187 splitHandshake: true,
3188 })
3189 if protocol == tls {
3190 addStateMachineCoverageTests(stateMachineTestConfig{
3191 protocol: protocol,
3192 async: async,
3193 packHandshakeFlight: true,
3194 })
3195 }
3196 }
3197 }
3198}
3199
3200func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003201 var tests []testCase
3202
3203 // Basic handshake, with resumption. Client and server,
3204 // session ID and session ticket.
3205 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 name: "Basic-Client",
3207 config: Config{
3208 MaxVersion: VersionTLS12,
3209 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003211 // Ensure session tickets are used, not session IDs.
3212 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 })
3214 tests = append(tests, testCase{
3215 name: "Basic-Client-RenewTicket",
3216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003217 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 Bugs: ProtocolBugs{
3219 RenewTicketOnResume: true,
3220 },
3221 },
David Benjamin46662482016-08-17 00:51:00 -04003222 flags: []string{"-expect-ticket-renewal"},
3223 resumeSession: true,
3224 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 })
3226 tests = append(tests, testCase{
3227 name: "Basic-Client-NoTicket",
3228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 SessionTicketsDisabled: true,
3231 },
3232 resumeSession: true,
3233 })
3234 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003235 name: "Basic-Client-Implicit",
3236 config: Config{
3237 MaxVersion: VersionTLS12,
3238 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003239 flags: []string{"-implicit-handshake"},
3240 resumeSession: true,
3241 })
3242 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003243 testType: serverTest,
3244 name: "Basic-Server",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003247 Bugs: ProtocolBugs{
3248 RequireSessionTickets: true,
3249 },
3250 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003251 resumeSession: true,
3252 })
3253 tests = append(tests, testCase{
3254 testType: serverTest,
3255 name: "Basic-Server-NoTickets",
3256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003257 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 SessionTicketsDisabled: true,
3259 },
3260 resumeSession: true,
3261 })
3262 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 testType: serverTest,
3264 name: "Basic-Server-Implicit",
3265 config: Config{
3266 MaxVersion: VersionTLS12,
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 flags: []string{"-implicit-handshake"},
3269 resumeSession: true,
3270 })
3271 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003272 testType: serverTest,
3273 name: "Basic-Server-EarlyCallback",
3274 config: Config{
3275 MaxVersion: VersionTLS12,
3276 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 flags: []string{"-use-early-callback"},
3278 resumeSession: true,
3279 })
3280
Steven Valdez143e8b32016-07-11 13:19:03 -04003281 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003282 if config.protocol == tls {
3283 tests = append(tests, testCase{
3284 name: "TLS13-1RTT-Client",
3285 config: Config{
3286 MaxVersion: VersionTLS13,
3287 MinVersion: VersionTLS13,
3288 },
David Benjamin46662482016-08-17 00:51:00 -04003289 resumeSession: true,
3290 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003291 })
3292
3293 tests = append(tests, testCase{
3294 testType: serverTest,
3295 name: "TLS13-1RTT-Server",
3296 config: Config{
3297 MaxVersion: VersionTLS13,
3298 MinVersion: VersionTLS13,
3299 },
David Benjamin46662482016-08-17 00:51:00 -04003300 resumeSession: true,
3301 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003302 })
3303
3304 tests = append(tests, testCase{
3305 name: "TLS13-HelloRetryRequest-Client",
3306 config: Config{
3307 MaxVersion: VersionTLS13,
3308 MinVersion: VersionTLS13,
3309 // P-384 requires a HelloRetryRequest against
3310 // BoringSSL's default configuration. Assert
3311 // that we do indeed test this with
3312 // ExpectMissingKeyShare.
3313 CurvePreferences: []CurveID{CurveP384},
3314 Bugs: ProtocolBugs{
3315 ExpectMissingKeyShare: true,
3316 },
3317 },
3318 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3319 resumeSession: true,
3320 })
3321
3322 tests = append(tests, testCase{
3323 testType: serverTest,
3324 name: "TLS13-HelloRetryRequest-Server",
3325 config: Config{
3326 MaxVersion: VersionTLS13,
3327 MinVersion: VersionTLS13,
3328 // Require a HelloRetryRequest for every curve.
3329 DefaultCurves: []CurveID{},
3330 },
3331 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3332 resumeSession: true,
3333 })
3334 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003335
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 // TLS client auth.
3337 tests = append(tests, testCase{
3338 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003339 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003341 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003342 ClientAuth: RequestClientCert,
3343 },
3344 })
3345 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003346 testType: serverTest,
3347 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 config: Config{
3349 MaxVersion: VersionTLS12,
3350 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003351 // Setting SSL_VERIFY_PEER allows anonymous clients.
3352 flags: []string{"-verify-peer"},
3353 })
David Benjamin582ba042016-07-07 12:33:25 -07003354 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003355 tests = append(tests, testCase{
3356 testType: clientTest,
3357 name: "ClientAuth-NoCertificate-Client-SSL3",
3358 config: Config{
3359 MaxVersion: VersionSSL30,
3360 ClientAuth: RequestClientCert,
3361 },
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "ClientAuth-NoCertificate-Server-SSL3",
3366 config: Config{
3367 MaxVersion: VersionSSL30,
3368 },
3369 // Setting SSL_VERIFY_PEER allows anonymous clients.
3370 flags: []string{"-verify-peer"},
3371 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-TLS13",
3375 config: Config{
3376 MaxVersion: VersionTLS13,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-TLS13",
3383 config: Config{
3384 MaxVersion: VersionTLS13,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003389 }
3390 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003391 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003392 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003394 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 ClientAuth: RequireAnyClientCert,
3396 },
3397 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 },
3401 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003402 tests = append(tests, testCase{
3403 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003404 name: "ClientAuth-RSA-Client-TLS13",
3405 config: Config{
3406 MaxVersion: VersionTLS13,
3407 ClientAuth: RequireAnyClientCert,
3408 },
3409 flags: []string{
3410 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3411 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3412 },
3413 })
3414 tests = append(tests, testCase{
3415 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003416 name: "ClientAuth-ECDSA-Client",
3417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003418 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 ClientAuth: RequireAnyClientCert,
3420 },
3421 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003424 },
3425 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003426 tests = append(tests, testCase{
3427 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003428 name: "ClientAuth-ECDSA-Client-TLS13",
3429 config: Config{
3430 MaxVersion: VersionTLS13,
3431 ClientAuth: RequireAnyClientCert,
3432 },
3433 flags: []string{
3434 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3435 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3436 },
3437 })
3438 tests = append(tests, testCase{
3439 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 name: "ClientAuth-NoCertificate-OldCallback",
3441 config: Config{
3442 MaxVersion: VersionTLS12,
3443 ClientAuth: RequestClientCert,
3444 },
3445 flags: []string{"-use-old-client-cert-callback"},
3446 })
3447 tests = append(tests, testCase{
3448 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003449 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3450 config: Config{
3451 MaxVersion: VersionTLS13,
3452 ClientAuth: RequestClientCert,
3453 },
3454 flags: []string{"-use-old-client-cert-callback"},
3455 })
3456 tests = append(tests, testCase{
3457 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003458 name: "ClientAuth-OldCallback",
3459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003460 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003461 ClientAuth: RequireAnyClientCert,
3462 },
3463 flags: []string{
3464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3466 "-use-old-client-cert-callback",
3467 },
3468 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003469 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003470 testType: clientTest,
3471 name: "ClientAuth-OldCallback-TLS13",
3472 config: Config{
3473 MaxVersion: VersionTLS13,
3474 ClientAuth: RequireAnyClientCert,
3475 },
3476 flags: []string{
3477 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3478 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3479 "-use-old-client-cert-callback",
3480 },
3481 })
3482 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 testType: serverTest,
3484 name: "ClientAuth-Server",
3485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 Certificates: []Certificate{rsaCertificate},
3488 },
3489 flags: []string{"-require-any-client-certificate"},
3490 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "ClientAuth-Server-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 Certificates: []Certificate{rsaCertificate},
3497 },
3498 flags: []string{"-require-any-client-certificate"},
3499 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003500
David Benjamin4c3ddf72016-06-29 18:13:53 -04003501 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 tests = append(tests, testCase{
3503 testType: serverTest,
3504 name: "Basic-Server-RSA",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3508 },
3509 flags: []string{
3510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3512 },
3513 })
3514 tests = append(tests, testCase{
3515 testType: serverTest,
3516 name: "Basic-Server-ECDHE-RSA",
3517 config: Config{
3518 MaxVersion: VersionTLS12,
3519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3520 },
3521 flags: []string{
3522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3524 },
3525 })
3526 tests = append(tests, testCase{
3527 testType: serverTest,
3528 name: "Basic-Server-ECDHE-ECDSA",
3529 config: Config{
3530 MaxVersion: VersionTLS12,
3531 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3532 },
3533 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003534 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3535 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 },
3537 })
3538
David Benjamin760b1dd2015-05-15 23:33:48 -04003539 // No session ticket support; server doesn't send NewSessionTicket.
3540 tests = append(tests, testCase{
3541 name: "SessionTicketsDisabled-Client",
3542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003543 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 SessionTicketsDisabled: true,
3545 },
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "SessionTicketsDisabled-Server",
3550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003552 SessionTicketsDisabled: true,
3553 },
3554 })
3555
3556 // Skip ServerKeyExchange in PSK key exchange if there's no
3557 // identity hint.
3558 tests = append(tests, testCase{
3559 name: "EmptyPSKHint-Client",
3560 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003561 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3563 PreSharedKey: []byte("secret"),
3564 },
3565 flags: []string{"-psk", "secret"},
3566 })
3567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "EmptyPSKHint-Server",
3570 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003571 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003572 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3573 PreSharedKey: []byte("secret"),
3574 },
3575 flags: []string{"-psk", "secret"},
3576 })
3577
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003579 tests = append(tests, testCase{
3580 testType: clientTest,
3581 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003585 flags: []string{
3586 "-enable-ocsp-stapling",
3587 "-expect-ocsp-response",
3588 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003589 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003592 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003593 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003594 testType: serverTest,
3595 name: "OCSPStapling-Server",
3596 config: Config{
3597 MaxVersion: VersionTLS12,
3598 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003599 expectedOCSPResponse: testOCSPResponse,
3600 flags: []string{
3601 "-ocsp-response",
3602 base64.StdEncoding.EncodeToString(testOCSPResponse),
3603 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003604 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003605 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003606 tests = append(tests, testCase{
3607 testType: clientTest,
3608 name: "OCSPStapling-Client-TLS13",
3609 config: Config{
3610 MaxVersion: VersionTLS13,
3611 },
3612 flags: []string{
3613 "-enable-ocsp-stapling",
3614 "-expect-ocsp-response",
3615 base64.StdEncoding.EncodeToString(testOCSPResponse),
3616 "-verify-peer",
3617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003619 })
3620 tests = append(tests, testCase{
3621 testType: serverTest,
3622 name: "OCSPStapling-Server-TLS13",
3623 config: Config{
3624 MaxVersion: VersionTLS13,
3625 },
3626 expectedOCSPResponse: testOCSPResponse,
3627 flags: []string{
3628 "-ocsp-response",
3629 base64.StdEncoding.EncodeToString(testOCSPResponse),
3630 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003631 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003632 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003633
David Benjamin4c3ddf72016-06-29 18:13:53 -04003634 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003635 for _, vers := range tlsVersions {
3636 if config.protocol == dtls && !vers.hasDTLS {
3637 continue
3638 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003639 for _, testType := range []testType{clientTest, serverTest} {
3640 suffix := "-Client"
3641 if testType == serverTest {
3642 suffix = "-Server"
3643 }
3644 suffix += "-" + vers.name
3645
3646 flag := "-verify-peer"
3647 if testType == serverTest {
3648 flag = "-require-any-client-certificate"
3649 }
3650
3651 tests = append(tests, testCase{
3652 testType: testType,
3653 name: "CertificateVerificationSucceed" + suffix,
3654 config: Config{
3655 MaxVersion: vers.version,
3656 Certificates: []Certificate{rsaCertificate},
3657 },
3658 flags: []string{
3659 flag,
3660 "-expect-verify-result",
3661 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003662 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003663 })
3664 tests = append(tests, testCase{
3665 testType: testType,
3666 name: "CertificateVerificationFail" + suffix,
3667 config: Config{
3668 MaxVersion: vers.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 },
3671 flags: []string{
3672 flag,
3673 "-verify-fail",
3674 },
3675 shouldFail: true,
3676 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3677 })
3678 }
3679
3680 // By default, the client is in a soft fail mode where the peer
3681 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003682 tests = append(tests, testCase{
3683 testType: clientTest,
3684 name: "CertificateVerificationSoftFail-" + vers.name,
3685 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003686 MaxVersion: vers.version,
3687 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003688 },
3689 flags: []string{
3690 "-verify-fail",
3691 "-expect-verify-result",
3692 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003693 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003694 })
3695 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003696
David Benjamin1d4f4c02016-07-26 18:03:08 -04003697 tests = append(tests, testCase{
3698 name: "ShimSendAlert",
3699 flags: []string{"-send-alert"},
3700 shimWritesFirst: true,
3701 shouldFail: true,
3702 expectedLocalError: "remote error: decompression failure",
3703 })
3704
David Benjamin582ba042016-07-07 12:33:25 -07003705 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003706 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003707 name: "Renegotiate-Client",
3708 config: Config{
3709 MaxVersion: VersionTLS12,
3710 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003711 renegotiate: 1,
3712 flags: []string{
3713 "-renegotiate-freely",
3714 "-expect-total-renegotiations", "1",
3715 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003716 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717
David Benjamin47921102016-07-28 11:29:18 -04003718 tests = append(tests, testCase{
3719 name: "SendHalfHelloRequest",
3720 config: Config{
3721 MaxVersion: VersionTLS12,
3722 Bugs: ProtocolBugs{
3723 PackHelloRequestWithFinished: config.packHandshakeFlight,
3724 },
3725 },
3726 sendHalfHelloRequest: true,
3727 flags: []string{"-renegotiate-ignore"},
3728 shouldFail: true,
3729 expectedError: ":UNEXPECTED_RECORD:",
3730 })
3731
David Benjamin760b1dd2015-05-15 23:33:48 -04003732 // NPN on client and server; results in post-handshake message.
3733 tests = append(tests, testCase{
3734 name: "NPN-Client",
3735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 NextProtos: []string{"foo"},
3738 },
3739 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003740 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003741 expectedNextProto: "foo",
3742 expectedNextProtoType: npn,
3743 })
3744 tests = append(tests, testCase{
3745 testType: serverTest,
3746 name: "NPN-Server",
3747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 NextProtos: []string{"bar"},
3750 },
3751 flags: []string{
3752 "-advertise-npn", "\x03foo\x03bar\x03baz",
3753 "-expect-next-proto", "bar",
3754 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003755 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003756 expectedNextProto: "bar",
3757 expectedNextProtoType: npn,
3758 })
3759
3760 // TODO(davidben): Add tests for when False Start doesn't trigger.
3761
3762 // Client does False Start and negotiates NPN.
3763 tests = append(tests, testCase{
3764 name: "FalseStart",
3765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003766 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3768 NextProtos: []string{"foo"},
3769 Bugs: ProtocolBugs{
3770 ExpectFalseStart: true,
3771 },
3772 },
3773 flags: []string{
3774 "-false-start",
3775 "-select-next-proto", "foo",
3776 },
3777 shimWritesFirst: true,
3778 resumeSession: true,
3779 })
3780
3781 // Client does False Start and negotiates ALPN.
3782 tests = append(tests, testCase{
3783 name: "FalseStart-ALPN",
3784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3787 NextProtos: []string{"foo"},
3788 Bugs: ProtocolBugs{
3789 ExpectFalseStart: true,
3790 },
3791 },
3792 flags: []string{
3793 "-false-start",
3794 "-advertise-alpn", "\x03foo",
3795 },
3796 shimWritesFirst: true,
3797 resumeSession: true,
3798 })
3799
3800 // Client does False Start but doesn't explicitly call
3801 // SSL_connect.
3802 tests = append(tests, testCase{
3803 name: "FalseStart-Implicit",
3804 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003805 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3807 NextProtos: []string{"foo"},
3808 },
3809 flags: []string{
3810 "-implicit-handshake",
3811 "-false-start",
3812 "-advertise-alpn", "\x03foo",
3813 },
3814 })
3815
3816 // False Start without session tickets.
3817 tests = append(tests, testCase{
3818 name: "FalseStart-SessionTicketsDisabled",
3819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003820 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3822 NextProtos: []string{"foo"},
3823 SessionTicketsDisabled: true,
3824 Bugs: ProtocolBugs{
3825 ExpectFalseStart: true,
3826 },
3827 },
3828 flags: []string{
3829 "-false-start",
3830 "-select-next-proto", "foo",
3831 },
3832 shimWritesFirst: true,
3833 })
3834
Adam Langleydf759b52016-07-11 15:24:37 -07003835 tests = append(tests, testCase{
3836 name: "FalseStart-CECPQ1",
3837 config: Config{
3838 MaxVersion: VersionTLS12,
3839 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3840 NextProtos: []string{"foo"},
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-cipher", "DEFAULT:kCECPQ1",
3848 "-select-next-proto", "foo",
3849 },
3850 shimWritesFirst: true,
3851 resumeSession: true,
3852 })
3853
David Benjamin760b1dd2015-05-15 23:33:48 -04003854 // Server parses a V2ClientHello.
3855 tests = append(tests, testCase{
3856 testType: serverTest,
3857 name: "SendV2ClientHello",
3858 config: Config{
3859 // Choose a cipher suite that does not involve
3860 // elliptic curves, so no extensions are
3861 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003862 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003863 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003864 Bugs: ProtocolBugs{
3865 SendV2ClientHello: true,
3866 },
3867 },
3868 })
3869
3870 // Client sends a Channel ID.
3871 tests = append(tests, testCase{
3872 name: "ChannelID-Client",
3873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 RequestChannelID: true,
3876 },
Adam Langley7c803a62015-06-15 15:35:05 -07003877 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003878 resumeSession: true,
3879 expectChannelID: true,
3880 })
3881
3882 // Server accepts a Channel ID.
3883 tests = append(tests, testCase{
3884 testType: serverTest,
3885 name: "ChannelID-Server",
3886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003887 MaxVersion: VersionTLS12,
3888 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003889 },
3890 flags: []string{
3891 "-expect-channel-id",
3892 base64.StdEncoding.EncodeToString(channelIDBytes),
3893 },
3894 resumeSession: true,
3895 expectChannelID: true,
3896 })
David Benjamin30789da2015-08-29 22:56:45 -04003897
David Benjaminf8fcdf32016-06-08 15:56:13 -04003898 // Channel ID and NPN at the same time, to ensure their relative
3899 // ordering is correct.
3900 tests = append(tests, testCase{
3901 name: "ChannelID-NPN-Client",
3902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003904 RequestChannelID: true,
3905 NextProtos: []string{"foo"},
3906 },
3907 flags: []string{
3908 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3909 "-select-next-proto", "foo",
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 expectedNextProto: "foo",
3914 expectedNextProtoType: npn,
3915 })
3916 tests = append(tests, testCase{
3917 testType: serverTest,
3918 name: "ChannelID-NPN-Server",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 ChannelID: channelIDKey,
3922 NextProtos: []string{"bar"},
3923 },
3924 flags: []string{
3925 "-expect-channel-id",
3926 base64.StdEncoding.EncodeToString(channelIDBytes),
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
3930 resumeSession: true,
3931 expectChannelID: true,
3932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
David Benjamin30789da2015-08-29 22:56:45 -04003936 // Bidirectional shutdown with the runner initiating.
3937 tests = append(tests, testCase{
3938 name: "Shutdown-Runner",
3939 config: Config{
3940 Bugs: ProtocolBugs{
3941 ExpectCloseNotify: true,
3942 },
3943 },
3944 flags: []string{"-check-close-notify"},
3945 })
3946
3947 // Bidirectional shutdown with the shim initiating. The runner,
3948 // in the meantime, sends garbage before the close_notify which
3949 // the shim must ignore.
3950 tests = append(tests, testCase{
3951 name: "Shutdown-Shim",
3952 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003953 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003954 Bugs: ProtocolBugs{
3955 ExpectCloseNotify: true,
3956 },
3957 },
3958 shimShutsDown: true,
3959 sendEmptyRecords: 1,
3960 sendWarningAlerts: 1,
3961 flags: []string{"-check-close-notify"},
3962 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 // TODO(davidben): DTLS 1.3 will want a similar thing for
3965 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003966 tests = append(tests, testCase{
3967 name: "SkipHelloVerifyRequest",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 Bugs: ProtocolBugs{
3971 SkipHelloVerifyRequest: true,
3972 },
3973 },
3974 })
3975 }
3976
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003978 test.protocol = config.protocol
3979 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003980 test.name += "-DTLS"
3981 }
David Benjamin582ba042016-07-07 12:33:25 -07003982 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003983 test.name += "-Async"
3984 test.flags = append(test.flags, "-async")
3985 } else {
3986 test.name += "-Sync"
3987 }
David Benjamin582ba042016-07-07 12:33:25 -07003988 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003989 test.name += "-SplitHandshakeRecords"
3990 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003991 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003992 test.config.Bugs.MaxPacketLength = 256
3993 test.flags = append(test.flags, "-mtu", "256")
3994 }
3995 }
David Benjamin582ba042016-07-07 12:33:25 -07003996 if config.packHandshakeFlight {
3997 test.name += "-PackHandshakeFlight"
3998 test.config.Bugs.PackHandshakeFlight = true
3999 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004000 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004001 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004002}
4003
Adam Langley524e7172015-02-20 16:04:00 -08004004func addDDoSCallbackTests() {
4005 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004006 for _, resume := range []bool{false, true} {
4007 suffix := "Resume"
4008 if resume {
4009 suffix = "No" + suffix
4010 }
4011
4012 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 testType: serverTest,
4014 name: "Server-DDoS-OK-" + suffix,
4015 config: Config{
4016 MaxVersion: VersionTLS12,
4017 },
Adam Langley524e7172015-02-20 16:04:00 -08004018 flags: []string{"-install-ddos-callback"},
4019 resumeSession: resume,
4020 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004021 testCases = append(testCases, testCase{
4022 testType: serverTest,
4023 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4024 config: Config{
4025 MaxVersion: VersionTLS13,
4026 },
4027 flags: []string{"-install-ddos-callback"},
4028 resumeSession: resume,
4029 })
Adam Langley524e7172015-02-20 16:04:00 -08004030
4031 failFlag := "-fail-ddos-callback"
4032 if resume {
4033 failFlag = "-fail-second-ddos-callback"
4034 }
4035 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 testType: serverTest,
4037 name: "Server-DDoS-Reject-" + suffix,
4038 config: Config{
4039 MaxVersion: VersionTLS12,
4040 },
David Benjamin2c66e072016-09-16 15:58:00 -04004041 flags: []string{"-install-ddos-callback", failFlag},
4042 resumeSession: resume,
4043 shouldFail: true,
4044 expectedError: ":CONNECTION_REJECTED:",
4045 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004046 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004047 testCases = append(testCases, testCase{
4048 testType: serverTest,
4049 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4050 config: Config{
4051 MaxVersion: VersionTLS13,
4052 },
David Benjamin2c66e072016-09-16 15:58:00 -04004053 flags: []string{"-install-ddos-callback", failFlag},
4054 resumeSession: resume,
4055 shouldFail: true,
4056 expectedError: ":CONNECTION_REJECTED:",
4057 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004058 })
Adam Langley524e7172015-02-20 16:04:00 -08004059 }
4060}
4061
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004062func addVersionNegotiationTests() {
4063 for i, shimVers := range tlsVersions {
4064 // Assemble flags to disable all newer versions on the shim.
4065 var flags []string
4066 for _, vers := range tlsVersions[i+1:] {
4067 flags = append(flags, vers.flag)
4068 }
4069
4070 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004071 protocols := []protocol{tls}
4072 if runnerVers.hasDTLS && shimVers.hasDTLS {
4073 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004074 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004075 for _, protocol := range protocols {
4076 expectedVersion := shimVers.version
4077 if runnerVers.version < shimVers.version {
4078 expectedVersion = runnerVers.version
4079 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004080
David Benjamin8b8c0062014-11-23 02:47:52 -05004081 suffix := shimVers.name + "-" + runnerVers.name
4082 if protocol == dtls {
4083 suffix += "-DTLS"
4084 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004085
David Benjamin1eb367c2014-12-12 18:17:51 -05004086 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4087
David Benjamin1e29a6b2014-12-10 02:27:24 -05004088 clientVers := shimVers.version
4089 if clientVers > VersionTLS10 {
4090 clientVers = VersionTLS10
4091 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004092 serverVers := expectedVersion
4093 if expectedVersion >= VersionTLS13 {
4094 serverVers = VersionTLS10
4095 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004096 testCases = append(testCases, testCase{
4097 protocol: protocol,
4098 testType: clientTest,
4099 name: "VersionNegotiation-Client-" + suffix,
4100 config: Config{
4101 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004102 Bugs: ProtocolBugs{
4103 ExpectInitialRecordVersion: clientVers,
4104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004105 },
4106 flags: flags,
4107 expectedVersion: expectedVersion,
4108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004109 testCases = append(testCases, testCase{
4110 protocol: protocol,
4111 testType: clientTest,
4112 name: "VersionNegotiation-Client2-" + suffix,
4113 config: Config{
4114 MaxVersion: runnerVers.version,
4115 Bugs: ProtocolBugs{
4116 ExpectInitialRecordVersion: clientVers,
4117 },
4118 },
4119 flags: []string{"-max-version", shimVersFlag},
4120 expectedVersion: expectedVersion,
4121 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004122
4123 testCases = append(testCases, testCase{
4124 protocol: protocol,
4125 testType: serverTest,
4126 name: "VersionNegotiation-Server-" + suffix,
4127 config: Config{
4128 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004129 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004130 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004131 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004132 },
4133 flags: flags,
4134 expectedVersion: expectedVersion,
4135 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004136 testCases = append(testCases, testCase{
4137 protocol: protocol,
4138 testType: serverTest,
4139 name: "VersionNegotiation-Server2-" + suffix,
4140 config: Config{
4141 MaxVersion: runnerVers.version,
4142 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004143 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004144 },
4145 },
4146 flags: []string{"-max-version", shimVersFlag},
4147 expectedVersion: expectedVersion,
4148 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004149 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004150 }
4151 }
David Benjamin95c69562016-06-29 18:15:03 -04004152
4153 // Test for version tolerance.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "MinorVersionTolerance",
4157 config: Config{
4158 Bugs: ProtocolBugs{
4159 SendClientVersion: 0x03ff,
4160 },
4161 },
4162 expectedVersion: VersionTLS13,
4163 })
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "MajorVersionTolerance",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0400,
4170 },
4171 },
4172 expectedVersion: VersionTLS13,
4173 })
4174 testCases = append(testCases, testCase{
4175 protocol: dtls,
4176 testType: serverTest,
4177 name: "MinorVersionTolerance-DTLS",
4178 config: Config{
4179 Bugs: ProtocolBugs{
4180 SendClientVersion: 0x03ff,
4181 },
4182 },
4183 expectedVersion: VersionTLS12,
4184 })
4185 testCases = append(testCases, testCase{
4186 protocol: dtls,
4187 testType: serverTest,
4188 name: "MajorVersionTolerance-DTLS",
4189 config: Config{
4190 Bugs: ProtocolBugs{
4191 SendClientVersion: 0x0400,
4192 },
4193 },
4194 expectedVersion: VersionTLS12,
4195 })
4196
4197 // Test that versions below 3.0 are rejected.
4198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "VersionTooLow",
4201 config: Config{
4202 Bugs: ProtocolBugs{
4203 SendClientVersion: 0x0200,
4204 },
4205 },
4206 shouldFail: true,
4207 expectedError: ":UNSUPPORTED_PROTOCOL:",
4208 })
4209 testCases = append(testCases, testCase{
4210 protocol: dtls,
4211 testType: serverTest,
4212 name: "VersionTooLow-DTLS",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 // 0x0201 is the lowest version expressable in
4216 // DTLS.
4217 SendClientVersion: 0x0201,
4218 },
4219 },
4220 shouldFail: true,
4221 expectedError: ":UNSUPPORTED_PROTOCOL:",
4222 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004223
4224 // Test TLS 1.3's downgrade signal.
4225 testCases = append(testCases, testCase{
4226 name: "Downgrade-TLS12-Client",
4227 config: Config{
4228 Bugs: ProtocolBugs{
4229 NegotiateVersion: VersionTLS12,
4230 },
4231 },
David Benjamin55108632016-08-11 22:01:18 -04004232 // TODO(davidben): This test should fail once TLS 1.3 is final
4233 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004234 })
4235 testCases = append(testCases, testCase{
4236 testType: serverTest,
4237 name: "Downgrade-TLS12-Server",
4238 config: Config{
4239 Bugs: ProtocolBugs{
4240 SendClientVersion: VersionTLS12,
4241 },
4242 },
David Benjamin55108632016-08-11 22:01:18 -04004243 // TODO(davidben): This test should fail once TLS 1.3 is final
4244 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004245 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004246}
4247
David Benjaminaccb4542014-12-12 23:44:33 -05004248func addMinimumVersionTests() {
4249 for i, shimVers := range tlsVersions {
4250 // Assemble flags to disable all older versions on the shim.
4251 var flags []string
4252 for _, vers := range tlsVersions[:i] {
4253 flags = append(flags, vers.flag)
4254 }
4255
4256 for _, runnerVers := range tlsVersions {
4257 protocols := []protocol{tls}
4258 if runnerVers.hasDTLS && shimVers.hasDTLS {
4259 protocols = append(protocols, dtls)
4260 }
4261 for _, protocol := range protocols {
4262 suffix := shimVers.name + "-" + runnerVers.name
4263 if protocol == dtls {
4264 suffix += "-DTLS"
4265 }
4266 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4267
David Benjaminaccb4542014-12-12 23:44:33 -05004268 var expectedVersion uint16
4269 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004270 var expectedClientError, expectedServerError string
4271 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004272 if runnerVers.version >= shimVers.version {
4273 expectedVersion = runnerVers.version
4274 } else {
4275 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004276 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4277 expectedServerLocalError = "remote error: protocol version not supported"
4278 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4279 // If the client's minimum version is TLS 1.3 and the runner's
4280 // maximum is below TLS 1.2, the runner will fail to select a
4281 // cipher before the shim rejects the selected version.
4282 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4283 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4284 } else {
4285 expectedClientError = expectedServerError
4286 expectedClientLocalError = expectedServerLocalError
4287 }
David Benjaminaccb4542014-12-12 23:44:33 -05004288 }
4289
4290 testCases = append(testCases, testCase{
4291 protocol: protocol,
4292 testType: clientTest,
4293 name: "MinimumVersion-Client-" + suffix,
4294 config: Config{
4295 MaxVersion: runnerVers.version,
4296 },
David Benjamin87909c02014-12-13 01:55:01 -05004297 flags: flags,
4298 expectedVersion: expectedVersion,
4299 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004300 expectedError: expectedClientError,
4301 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004302 })
4303 testCases = append(testCases, testCase{
4304 protocol: protocol,
4305 testType: clientTest,
4306 name: "MinimumVersion-Client2-" + suffix,
4307 config: Config{
4308 MaxVersion: runnerVers.version,
4309 },
David Benjamin87909c02014-12-13 01:55:01 -05004310 flags: []string{"-min-version", shimVersFlag},
4311 expectedVersion: expectedVersion,
4312 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004313 expectedError: expectedClientError,
4314 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004315 })
4316
4317 testCases = append(testCases, testCase{
4318 protocol: protocol,
4319 testType: serverTest,
4320 name: "MinimumVersion-Server-" + suffix,
4321 config: Config{
4322 MaxVersion: runnerVers.version,
4323 },
David Benjamin87909c02014-12-13 01:55:01 -05004324 flags: flags,
4325 expectedVersion: expectedVersion,
4326 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004327 expectedError: expectedServerError,
4328 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004329 })
4330 testCases = append(testCases, testCase{
4331 protocol: protocol,
4332 testType: serverTest,
4333 name: "MinimumVersion-Server2-" + suffix,
4334 config: Config{
4335 MaxVersion: runnerVers.version,
4336 },
David Benjamin87909c02014-12-13 01:55:01 -05004337 flags: []string{"-min-version", shimVersFlag},
4338 expectedVersion: expectedVersion,
4339 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004340 expectedError: expectedServerError,
4341 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004342 })
4343 }
4344 }
4345 }
4346}
4347
David Benjamine78bfde2014-09-06 12:45:15 -04004348func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004349 // TODO(davidben): Extensions, where applicable, all move their server
4350 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4351 // tests for both. Also test interaction with 0-RTT when implemented.
4352
David Benjamin97d17d92016-07-14 16:12:00 -04004353 // Repeat extensions tests all versions except SSL 3.0.
4354 for _, ver := range tlsVersions {
4355 if ver.version == VersionSSL30 {
4356 continue
4357 }
4358
David Benjamin97d17d92016-07-14 16:12:00 -04004359 // Test that duplicate extensions are rejected.
4360 testCases = append(testCases, testCase{
4361 testType: clientTest,
4362 name: "DuplicateExtensionClient-" + ver.name,
4363 config: Config{
4364 MaxVersion: ver.version,
4365 Bugs: ProtocolBugs{
4366 DuplicateExtension: true,
4367 },
David Benjamine78bfde2014-09-06 12:45:15 -04004368 },
David Benjamin97d17d92016-07-14 16:12:00 -04004369 shouldFail: true,
4370 expectedLocalError: "remote error: error decoding message",
4371 })
4372 testCases = append(testCases, testCase{
4373 testType: serverTest,
4374 name: "DuplicateExtensionServer-" + ver.name,
4375 config: Config{
4376 MaxVersion: ver.version,
4377 Bugs: ProtocolBugs{
4378 DuplicateExtension: true,
4379 },
David Benjamine78bfde2014-09-06 12:45:15 -04004380 },
David Benjamin97d17d92016-07-14 16:12:00 -04004381 shouldFail: true,
4382 expectedLocalError: "remote error: error decoding message",
4383 })
4384
4385 // Test SNI.
4386 testCases = append(testCases, testCase{
4387 testType: clientTest,
4388 name: "ServerNameExtensionClient-" + ver.name,
4389 config: Config{
4390 MaxVersion: ver.version,
4391 Bugs: ProtocolBugs{
4392 ExpectServerName: "example.com",
4393 },
David Benjamine78bfde2014-09-06 12:45:15 -04004394 },
David Benjamin97d17d92016-07-14 16:12:00 -04004395 flags: []string{"-host-name", "example.com"},
4396 })
4397 testCases = append(testCases, testCase{
4398 testType: clientTest,
4399 name: "ServerNameExtensionClientMismatch-" + ver.name,
4400 config: Config{
4401 MaxVersion: ver.version,
4402 Bugs: ProtocolBugs{
4403 ExpectServerName: "mismatch.com",
4404 },
David Benjamine78bfde2014-09-06 12:45:15 -04004405 },
David Benjamin97d17d92016-07-14 16:12:00 -04004406 flags: []string{"-host-name", "example.com"},
4407 shouldFail: true,
4408 expectedLocalError: "tls: unexpected server name",
4409 })
4410 testCases = append(testCases, testCase{
4411 testType: clientTest,
4412 name: "ServerNameExtensionClientMissing-" + ver.name,
4413 config: Config{
4414 MaxVersion: ver.version,
4415 Bugs: ProtocolBugs{
4416 ExpectServerName: "missing.com",
4417 },
David Benjamine78bfde2014-09-06 12:45:15 -04004418 },
David Benjamin97d17d92016-07-14 16:12:00 -04004419 shouldFail: true,
4420 expectedLocalError: "tls: unexpected server name",
4421 })
4422 testCases = append(testCases, testCase{
4423 testType: serverTest,
4424 name: "ServerNameExtensionServer-" + ver.name,
4425 config: Config{
4426 MaxVersion: ver.version,
4427 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004428 },
David Benjamin97d17d92016-07-14 16:12:00 -04004429 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004430 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004431 })
4432
4433 // Test ALPN.
4434 testCases = append(testCases, testCase{
4435 testType: clientTest,
4436 name: "ALPNClient-" + ver.name,
4437 config: Config{
4438 MaxVersion: ver.version,
4439 NextProtos: []string{"foo"},
4440 },
4441 flags: []string{
4442 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4443 "-expect-alpn", "foo",
4444 },
4445 expectedNextProto: "foo",
4446 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004447 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004448 })
4449 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004450 testType: clientTest,
4451 name: "ALPNClient-Mismatch-" + ver.name,
4452 config: Config{
4453 MaxVersion: ver.version,
4454 Bugs: ProtocolBugs{
4455 SendALPN: "baz",
4456 },
4457 },
4458 flags: []string{
4459 "-advertise-alpn", "\x03foo\x03bar",
4460 },
4461 shouldFail: true,
4462 expectedError: ":INVALID_ALPN_PROTOCOL:",
4463 expectedLocalError: "remote error: illegal parameter",
4464 })
4465 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004466 testType: serverTest,
4467 name: "ALPNServer-" + ver.name,
4468 config: Config{
4469 MaxVersion: ver.version,
4470 NextProtos: []string{"foo", "bar", "baz"},
4471 },
4472 flags: []string{
4473 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4474 "-select-alpn", "foo",
4475 },
4476 expectedNextProto: "foo",
4477 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004478 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004479 })
4480 testCases = append(testCases, testCase{
4481 testType: serverTest,
4482 name: "ALPNServer-Decline-" + ver.name,
4483 config: Config{
4484 MaxVersion: ver.version,
4485 NextProtos: []string{"foo", "bar", "baz"},
4486 },
4487 flags: []string{"-decline-alpn"},
4488 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004489 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004490 })
4491
David Benjamin25fe85b2016-08-09 20:00:32 -04004492 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4493 // called once.
4494 testCases = append(testCases, testCase{
4495 testType: serverTest,
4496 name: "ALPNServer-Async-" + ver.name,
4497 config: Config{
4498 MaxVersion: ver.version,
4499 NextProtos: []string{"foo", "bar", "baz"},
4500 },
4501 flags: []string{
4502 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4503 "-select-alpn", "foo",
4504 "-async",
4505 },
4506 expectedNextProto: "foo",
4507 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004508 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004509 })
4510
David Benjamin97d17d92016-07-14 16:12:00 -04004511 var emptyString string
4512 testCases = append(testCases, testCase{
4513 testType: clientTest,
4514 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4515 config: Config{
4516 MaxVersion: ver.version,
4517 NextProtos: []string{""},
4518 Bugs: ProtocolBugs{
4519 // A server returning an empty ALPN protocol
4520 // should be rejected.
4521 ALPNProtocol: &emptyString,
4522 },
4523 },
4524 flags: []string{
4525 "-advertise-alpn", "\x03foo",
4526 },
4527 shouldFail: true,
4528 expectedError: ":PARSE_TLSEXT:",
4529 })
4530 testCases = append(testCases, testCase{
4531 testType: serverTest,
4532 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4533 config: Config{
4534 MaxVersion: ver.version,
4535 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004536 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004537 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004538 },
David Benjamin97d17d92016-07-14 16:12:00 -04004539 flags: []string{
4540 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004541 },
David Benjamin97d17d92016-07-14 16:12:00 -04004542 shouldFail: true,
4543 expectedError: ":PARSE_TLSEXT:",
4544 })
4545
4546 // Test NPN and the interaction with ALPN.
4547 if ver.version < VersionTLS13 {
4548 // Test that the server prefers ALPN over NPN.
4549 testCases = append(testCases, testCase{
4550 testType: serverTest,
4551 name: "ALPNServer-Preferred-" + ver.name,
4552 config: Config{
4553 MaxVersion: ver.version,
4554 NextProtos: []string{"foo", "bar", "baz"},
4555 },
4556 flags: []string{
4557 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4558 "-select-alpn", "foo",
4559 "-advertise-npn", "\x03foo\x03bar\x03baz",
4560 },
4561 expectedNextProto: "foo",
4562 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004563 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004564 })
4565 testCases = append(testCases, testCase{
4566 testType: serverTest,
4567 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4568 config: Config{
4569 MaxVersion: ver.version,
4570 NextProtos: []string{"foo", "bar", "baz"},
4571 Bugs: ProtocolBugs{
4572 SwapNPNAndALPN: true,
4573 },
4574 },
4575 flags: []string{
4576 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4577 "-select-alpn", "foo",
4578 "-advertise-npn", "\x03foo\x03bar\x03baz",
4579 },
4580 expectedNextProto: "foo",
4581 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004582 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004583 })
4584
4585 // Test that negotiating both NPN and ALPN is forbidden.
4586 testCases = append(testCases, testCase{
4587 name: "NegotiateALPNAndNPN-" + ver.name,
4588 config: Config{
4589 MaxVersion: ver.version,
4590 NextProtos: []string{"foo", "bar", "baz"},
4591 Bugs: ProtocolBugs{
4592 NegotiateALPNAndNPN: true,
4593 },
4594 },
4595 flags: []string{
4596 "-advertise-alpn", "\x03foo",
4597 "-select-next-proto", "foo",
4598 },
4599 shouldFail: true,
4600 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4601 })
4602 testCases = append(testCases, testCase{
4603 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4604 config: Config{
4605 MaxVersion: ver.version,
4606 NextProtos: []string{"foo", "bar", "baz"},
4607 Bugs: ProtocolBugs{
4608 NegotiateALPNAndNPN: true,
4609 SwapNPNAndALPN: true,
4610 },
4611 },
4612 flags: []string{
4613 "-advertise-alpn", "\x03foo",
4614 "-select-next-proto", "foo",
4615 },
4616 shouldFail: true,
4617 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4618 })
4619
4620 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4621 testCases = append(testCases, testCase{
4622 name: "DisableNPN-" + ver.name,
4623 config: Config{
4624 MaxVersion: ver.version,
4625 NextProtos: []string{"foo"},
4626 },
4627 flags: []string{
4628 "-select-next-proto", "foo",
4629 "-disable-npn",
4630 },
4631 expectNoNextProto: true,
4632 })
4633 }
4634
4635 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004636
4637 // Resume with a corrupt ticket.
4638 testCases = append(testCases, testCase{
4639 testType: serverTest,
4640 name: "CorruptTicket-" + ver.name,
4641 config: Config{
4642 MaxVersion: ver.version,
4643 Bugs: ProtocolBugs{
4644 CorruptTicket: true,
4645 },
4646 },
4647 resumeSession: true,
4648 expectResumeRejected: true,
4649 })
4650 // Test the ticket callback, with and without renewal.
4651 testCases = append(testCases, testCase{
4652 testType: serverTest,
4653 name: "TicketCallback-" + ver.name,
4654 config: Config{
4655 MaxVersion: ver.version,
4656 },
4657 resumeSession: true,
4658 flags: []string{"-use-ticket-callback"},
4659 })
4660 testCases = append(testCases, testCase{
4661 testType: serverTest,
4662 name: "TicketCallback-Renew-" + ver.name,
4663 config: Config{
4664 MaxVersion: ver.version,
4665 Bugs: ProtocolBugs{
4666 ExpectNewTicket: true,
4667 },
4668 },
4669 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4670 resumeSession: true,
4671 })
4672
4673 // Test that the ticket callback is only called once when everything before
4674 // it in the ClientHello is asynchronous. This corrupts the ticket so
4675 // certificate selection callbacks run.
4676 testCases = append(testCases, testCase{
4677 testType: serverTest,
4678 name: "TicketCallback-SingleCall-" + ver.name,
4679 config: Config{
4680 MaxVersion: ver.version,
4681 Bugs: ProtocolBugs{
4682 CorruptTicket: true,
4683 },
4684 },
4685 resumeSession: true,
4686 expectResumeRejected: true,
4687 flags: []string{
4688 "-use-ticket-callback",
4689 "-async",
4690 },
4691 })
4692
4693 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004694 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004695 testCases = append(testCases, testCase{
4696 testType: serverTest,
4697 name: "OversizedSessionId-" + ver.name,
4698 config: Config{
4699 MaxVersion: ver.version,
4700 Bugs: ProtocolBugs{
4701 OversizedSessionId: true,
4702 },
4703 },
4704 resumeSession: true,
4705 shouldFail: true,
4706 expectedError: ":DECODE_ERROR:",
4707 })
4708 }
4709
4710 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4711 // are ignored.
4712 if ver.hasDTLS {
4713 testCases = append(testCases, testCase{
4714 protocol: dtls,
4715 name: "SRTP-Client-" + ver.name,
4716 config: Config{
4717 MaxVersion: ver.version,
4718 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4719 },
4720 flags: []string{
4721 "-srtp-profiles",
4722 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4723 },
4724 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4725 })
4726 testCases = append(testCases, testCase{
4727 protocol: dtls,
4728 testType: serverTest,
4729 name: "SRTP-Server-" + ver.name,
4730 config: Config{
4731 MaxVersion: ver.version,
4732 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4733 },
4734 flags: []string{
4735 "-srtp-profiles",
4736 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4737 },
4738 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4739 })
4740 // Test that the MKI is ignored.
4741 testCases = append(testCases, testCase{
4742 protocol: dtls,
4743 testType: serverTest,
4744 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4745 config: Config{
4746 MaxVersion: ver.version,
4747 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4748 Bugs: ProtocolBugs{
4749 SRTPMasterKeyIdentifer: "bogus",
4750 },
4751 },
4752 flags: []string{
4753 "-srtp-profiles",
4754 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4755 },
4756 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4757 })
4758 // Test that SRTP isn't negotiated on the server if there were
4759 // no matching profiles.
4760 testCases = append(testCases, testCase{
4761 protocol: dtls,
4762 testType: serverTest,
4763 name: "SRTP-Server-NoMatch-" + ver.name,
4764 config: Config{
4765 MaxVersion: ver.version,
4766 SRTPProtectionProfiles: []uint16{100, 101, 102},
4767 },
4768 flags: []string{
4769 "-srtp-profiles",
4770 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4771 },
4772 expectedSRTPProtectionProfile: 0,
4773 })
4774 // Test that the server returning an invalid SRTP profile is
4775 // flagged as an error by the client.
4776 testCases = append(testCases, testCase{
4777 protocol: dtls,
4778 name: "SRTP-Client-NoMatch-" + ver.name,
4779 config: Config{
4780 MaxVersion: ver.version,
4781 Bugs: ProtocolBugs{
4782 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4783 },
4784 },
4785 flags: []string{
4786 "-srtp-profiles",
4787 "SRTP_AES128_CM_SHA1_80",
4788 },
4789 shouldFail: true,
4790 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4791 })
4792 }
4793
4794 // Test SCT list.
4795 testCases = append(testCases, testCase{
4796 name: "SignedCertificateTimestampList-Client-" + ver.name,
4797 testType: clientTest,
4798 config: Config{
4799 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004800 },
David Benjamin97d17d92016-07-14 16:12:00 -04004801 flags: []string{
4802 "-enable-signed-cert-timestamps",
4803 "-expect-signed-cert-timestamps",
4804 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004805 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004806 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004807 })
4808 testCases = append(testCases, testCase{
4809 name: "SendSCTListOnResume-" + ver.name,
4810 config: Config{
4811 MaxVersion: ver.version,
4812 Bugs: ProtocolBugs{
4813 SendSCTListOnResume: []byte("bogus"),
4814 },
David Benjamind98452d2015-06-16 14:16:23 -04004815 },
David Benjamin97d17d92016-07-14 16:12:00 -04004816 flags: []string{
4817 "-enable-signed-cert-timestamps",
4818 "-expect-signed-cert-timestamps",
4819 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004820 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004821 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004822 })
4823 testCases = append(testCases, testCase{
4824 name: "SignedCertificateTimestampList-Server-" + ver.name,
4825 testType: serverTest,
4826 config: Config{
4827 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004828 },
David Benjamin97d17d92016-07-14 16:12:00 -04004829 flags: []string{
4830 "-signed-cert-timestamps",
4831 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004832 },
David Benjamin97d17d92016-07-14 16:12:00 -04004833 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004834 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004835 })
4836 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004837
Paul Lietar4fac72e2015-09-09 13:44:55 +01004838 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004839 testType: clientTest,
4840 name: "ClientHelloPadding",
4841 config: Config{
4842 Bugs: ProtocolBugs{
4843 RequireClientHelloSize: 512,
4844 },
4845 },
4846 // This hostname just needs to be long enough to push the
4847 // ClientHello into F5's danger zone between 256 and 511 bytes
4848 // long.
4849 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4850 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004851
4852 // Extensions should not function in SSL 3.0.
4853 testCases = append(testCases, testCase{
4854 testType: serverTest,
4855 name: "SSLv3Extensions-NoALPN",
4856 config: Config{
4857 MaxVersion: VersionSSL30,
4858 NextProtos: []string{"foo", "bar", "baz"},
4859 },
4860 flags: []string{
4861 "-select-alpn", "foo",
4862 },
4863 expectNoNextProto: true,
4864 })
4865
4866 // Test session tickets separately as they follow a different codepath.
4867 testCases = append(testCases, testCase{
4868 testType: serverTest,
4869 name: "SSLv3Extensions-NoTickets",
4870 config: Config{
4871 MaxVersion: VersionSSL30,
4872 Bugs: ProtocolBugs{
4873 // Historically, session tickets in SSL 3.0
4874 // failed in different ways depending on whether
4875 // the client supported renegotiation_info.
4876 NoRenegotiationInfo: true,
4877 },
4878 },
4879 resumeSession: true,
4880 })
4881 testCases = append(testCases, testCase{
4882 testType: serverTest,
4883 name: "SSLv3Extensions-NoTickets2",
4884 config: Config{
4885 MaxVersion: VersionSSL30,
4886 },
4887 resumeSession: true,
4888 })
4889
4890 // But SSL 3.0 does send and process renegotiation_info.
4891 testCases = append(testCases, testCase{
4892 testType: serverTest,
4893 name: "SSLv3Extensions-RenegotiationInfo",
4894 config: Config{
4895 MaxVersion: VersionSSL30,
4896 Bugs: ProtocolBugs{
4897 RequireRenegotiationInfo: true,
4898 },
4899 },
4900 })
4901 testCases = append(testCases, testCase{
4902 testType: serverTest,
4903 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4904 config: Config{
4905 MaxVersion: VersionSSL30,
4906 Bugs: ProtocolBugs{
4907 NoRenegotiationInfo: true,
4908 SendRenegotiationSCSV: true,
4909 RequireRenegotiationInfo: true,
4910 },
4911 },
4912 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004913
4914 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4915 // in ServerHello.
4916 testCases = append(testCases, testCase{
4917 name: "NPN-Forbidden-TLS13",
4918 config: Config{
4919 MaxVersion: VersionTLS13,
4920 NextProtos: []string{"foo"},
4921 Bugs: ProtocolBugs{
4922 NegotiateNPNAtAllVersions: true,
4923 },
4924 },
4925 flags: []string{"-select-next-proto", "foo"},
4926 shouldFail: true,
4927 expectedError: ":ERROR_PARSING_EXTENSION:",
4928 })
4929 testCases = append(testCases, testCase{
4930 name: "EMS-Forbidden-TLS13",
4931 config: Config{
4932 MaxVersion: VersionTLS13,
4933 Bugs: ProtocolBugs{
4934 NegotiateEMSAtAllVersions: true,
4935 },
4936 },
4937 shouldFail: true,
4938 expectedError: ":ERROR_PARSING_EXTENSION:",
4939 })
4940 testCases = append(testCases, testCase{
4941 name: "RenegotiationInfo-Forbidden-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 Bugs: ProtocolBugs{
4945 NegotiateRenegotiationInfoAtAllVersions: true,
4946 },
4947 },
4948 shouldFail: true,
4949 expectedError: ":ERROR_PARSING_EXTENSION:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "ChannelID-Forbidden-TLS13",
4953 config: Config{
4954 MaxVersion: VersionTLS13,
4955 RequestChannelID: true,
4956 Bugs: ProtocolBugs{
4957 NegotiateChannelIDAtAllVersions: true,
4958 },
4959 },
4960 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4961 shouldFail: true,
4962 expectedError: ":ERROR_PARSING_EXTENSION:",
4963 })
4964 testCases = append(testCases, testCase{
4965 name: "Ticket-Forbidden-TLS13",
4966 config: Config{
4967 MaxVersion: VersionTLS12,
4968 },
4969 resumeConfig: &Config{
4970 MaxVersion: VersionTLS13,
4971 Bugs: ProtocolBugs{
4972 AdvertiseTicketExtension: true,
4973 },
4974 },
4975 resumeSession: true,
4976 shouldFail: true,
4977 expectedError: ":ERROR_PARSING_EXTENSION:",
4978 })
4979
4980 // Test that illegal extensions in TLS 1.3 are declined by the server if
4981 // offered in ClientHello. The runner's server will fail if this occurs,
4982 // so we exercise the offering path. (EMS and Renegotiation Info are
4983 // implicit in every test.)
4984 testCases = append(testCases, testCase{
4985 testType: serverTest,
4986 name: "ChannelID-Declined-TLS13",
4987 config: Config{
4988 MaxVersion: VersionTLS13,
4989 ChannelID: channelIDKey,
4990 },
4991 flags: []string{"-enable-channel-id"},
4992 })
4993 testCases = append(testCases, testCase{
4994 testType: serverTest,
4995 name: "NPN-Server",
4996 config: Config{
4997 MaxVersion: VersionTLS13,
4998 NextProtos: []string{"bar"},
4999 },
5000 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5001 })
David Benjamine78bfde2014-09-06 12:45:15 -04005002}
5003
David Benjamin01fe8202014-09-24 15:21:44 -04005004func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005005 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005006 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005007 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5008 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5009 // TLS 1.3 only shares ciphers with TLS 1.2, so
5010 // we skip certain combinations and use a
5011 // different cipher to test with.
5012 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5013 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5014 continue
5015 }
5016 }
5017
David Benjamin8b8c0062014-11-23 02:47:52 -05005018 protocols := []protocol{tls}
5019 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5020 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005021 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005022 for _, protocol := range protocols {
5023 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5024 if protocol == dtls {
5025 suffix += "-DTLS"
5026 }
5027
David Benjaminece3de92015-03-16 18:02:20 -04005028 if sessionVers.version == resumeVers.version {
5029 testCases = append(testCases, testCase{
5030 protocol: protocol,
5031 name: "Resume-Client" + suffix,
5032 resumeSession: true,
5033 config: Config{
5034 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005035 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005036 Bugs: ProtocolBugs{
5037 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5038 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5039 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005040 },
David Benjaminece3de92015-03-16 18:02:20 -04005041 expectedVersion: sessionVers.version,
5042 expectedResumeVersion: resumeVers.version,
5043 })
5044 } else {
David Benjamin405da482016-08-08 17:25:07 -04005045 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5046
5047 // Offering a TLS 1.3 session sends an empty session ID, so
5048 // there is no way to convince a non-lookahead client the
5049 // session was resumed. It will appear to the client that a
5050 // stray ChangeCipherSpec was sent.
5051 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5052 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005053 }
5054
David Benjaminece3de92015-03-16 18:02:20 -04005055 testCases = append(testCases, testCase{
5056 protocol: protocol,
5057 name: "Resume-Client-Mismatch" + suffix,
5058 resumeSession: true,
5059 config: Config{
5060 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005061 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005062 },
David Benjaminece3de92015-03-16 18:02:20 -04005063 expectedVersion: sessionVers.version,
5064 resumeConfig: &Config{
5065 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005066 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005067 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005068 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005069 },
5070 },
5071 expectedResumeVersion: resumeVers.version,
5072 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005073 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005074 })
5075 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005076
5077 testCases = append(testCases, testCase{
5078 protocol: protocol,
5079 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005080 resumeSession: true,
5081 config: Config{
5082 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005083 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005084 },
5085 expectedVersion: sessionVers.version,
5086 resumeConfig: &Config{
5087 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005088 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005089 },
5090 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005091 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005092 expectedResumeVersion: resumeVers.version,
5093 })
5094
David Benjamin8b8c0062014-11-23 02:47:52 -05005095 testCases = append(testCases, testCase{
5096 protocol: protocol,
5097 testType: serverTest,
5098 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005099 resumeSession: true,
5100 config: Config{
5101 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005102 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005104 expectedVersion: sessionVers.version,
5105 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 resumeConfig: &Config{
5107 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005108 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005109 Bugs: ProtocolBugs{
5110 SendBothTickets: true,
5111 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005112 },
5113 expectedResumeVersion: resumeVers.version,
5114 })
5115 }
David Benjamin01fe8202014-09-24 15:21:44 -04005116 }
5117 }
David Benjaminece3de92015-03-16 18:02:20 -04005118
5119 testCases = append(testCases, testCase{
5120 name: "Resume-Client-CipherMismatch",
5121 resumeSession: true,
5122 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005123 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005124 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5125 },
5126 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005127 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005128 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5129 Bugs: ProtocolBugs{
5130 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5131 },
5132 },
5133 shouldFail: true,
5134 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5135 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005136
5137 testCases = append(testCases, testCase{
5138 name: "Resume-Client-CipherMismatch-TLS13",
5139 resumeSession: true,
5140 config: Config{
5141 MaxVersion: VersionTLS13,
5142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5143 },
5144 resumeConfig: &Config{
5145 MaxVersion: VersionTLS13,
5146 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5147 Bugs: ProtocolBugs{
5148 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5149 },
5150 },
5151 shouldFail: true,
5152 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5153 })
David Benjamin01fe8202014-09-24 15:21:44 -04005154}
5155
Adam Langley2ae77d22014-10-28 17:29:33 -07005156func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005157 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005158 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005159 testType: serverTest,
5160 name: "Renegotiate-Server-Forbidden",
5161 config: Config{
5162 MaxVersion: VersionTLS12,
5163 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005164 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005165 shouldFail: true,
5166 expectedError: ":NO_RENEGOTIATION:",
5167 expectedLocalError: "remote error: no renegotiation",
5168 })
Adam Langley5021b222015-06-12 18:27:58 -07005169 // The server shouldn't echo the renegotiation extension unless
5170 // requested by the client.
5171 testCases = append(testCases, testCase{
5172 testType: serverTest,
5173 name: "Renegotiate-Server-NoExt",
5174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005175 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005176 Bugs: ProtocolBugs{
5177 NoRenegotiationInfo: true,
5178 RequireRenegotiationInfo: true,
5179 },
5180 },
5181 shouldFail: true,
5182 expectedLocalError: "renegotiation extension missing",
5183 })
5184 // The renegotiation SCSV should be sufficient for the server to echo
5185 // the extension.
5186 testCases = append(testCases, testCase{
5187 testType: serverTest,
5188 name: "Renegotiate-Server-NoExt-SCSV",
5189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005190 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005191 Bugs: ProtocolBugs{
5192 NoRenegotiationInfo: true,
5193 SendRenegotiationSCSV: true,
5194 RequireRenegotiationInfo: true,
5195 },
5196 },
5197 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005198 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005199 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005201 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005202 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005203 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005204 },
5205 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005206 renegotiate: 1,
5207 flags: []string{
5208 "-renegotiate-freely",
5209 "-expect-total-renegotiations", "1",
5210 },
David Benjamincdea40c2015-03-19 14:09:43 -04005211 })
5212 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005213 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005214 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005216 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005217 Bugs: ProtocolBugs{
5218 EmptyRenegotiationInfo: true,
5219 },
5220 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005221 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005222 shouldFail: true,
5223 expectedError: ":RENEGOTIATION_MISMATCH:",
5224 })
5225 testCases = append(testCases, testCase{
5226 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005227 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005229 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005230 Bugs: ProtocolBugs{
5231 BadRenegotiationInfo: true,
5232 },
5233 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005234 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005235 shouldFail: true,
5236 expectedError: ":RENEGOTIATION_MISMATCH:",
5237 })
5238 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005239 name: "Renegotiate-Client-Downgrade",
5240 renegotiate: 1,
5241 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005242 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005243 Bugs: ProtocolBugs{
5244 NoRenegotiationInfoAfterInitial: true,
5245 },
5246 },
5247 flags: []string{"-renegotiate-freely"},
5248 shouldFail: true,
5249 expectedError: ":RENEGOTIATION_MISMATCH:",
5250 })
5251 testCases = append(testCases, testCase{
5252 name: "Renegotiate-Client-Upgrade",
5253 renegotiate: 1,
5254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005255 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005256 Bugs: ProtocolBugs{
5257 NoRenegotiationInfoInInitial: true,
5258 },
5259 },
5260 flags: []string{"-renegotiate-freely"},
5261 shouldFail: true,
5262 expectedError: ":RENEGOTIATION_MISMATCH:",
5263 })
5264 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005265 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005266 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005267 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005268 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005269 Bugs: ProtocolBugs{
5270 NoRenegotiationInfo: true,
5271 },
5272 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005273 flags: []string{
5274 "-renegotiate-freely",
5275 "-expect-total-renegotiations", "1",
5276 },
David Benjamincff0b902015-05-15 23:09:47 -04005277 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005278
5279 // Test that the server may switch ciphers on renegotiation without
5280 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005281 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005282 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005283 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005284 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005285 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005286 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005287 },
5288 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005289 flags: []string{
5290 "-renegotiate-freely",
5291 "-expect-total-renegotiations", "1",
5292 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005293 })
5294 testCases = append(testCases, testCase{
5295 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005296 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005297 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005298 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005299 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5300 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005301 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005302 flags: []string{
5303 "-renegotiate-freely",
5304 "-expect-total-renegotiations", "1",
5305 },
David Benjaminb16346b2015-04-08 19:16:58 -04005306 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005307
5308 // Test that the server may not switch versions on renegotiation.
5309 testCases = append(testCases, testCase{
5310 name: "Renegotiate-Client-SwitchVersion",
5311 config: Config{
5312 MaxVersion: VersionTLS12,
5313 // Pick a cipher which exists at both versions.
5314 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5315 Bugs: ProtocolBugs{
5316 NegotiateVersionOnRenego: VersionTLS11,
5317 },
5318 },
5319 renegotiate: 1,
5320 flags: []string{
5321 "-renegotiate-freely",
5322 "-expect-total-renegotiations", "1",
5323 },
5324 shouldFail: true,
5325 expectedError: ":WRONG_SSL_VERSION:",
5326 })
5327
David Benjaminb16346b2015-04-08 19:16:58 -04005328 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005329 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005330 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005331 config: Config{
5332 MaxVersion: VersionTLS10,
5333 Bugs: ProtocolBugs{
5334 RequireSameRenegoClientVersion: true,
5335 },
5336 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005337 flags: []string{
5338 "-renegotiate-freely",
5339 "-expect-total-renegotiations", "1",
5340 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005341 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005342 testCases = append(testCases, testCase{
5343 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005344 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005345 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005346 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005347 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5348 NextProtos: []string{"foo"},
5349 },
5350 flags: []string{
5351 "-false-start",
5352 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005353 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005354 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005355 },
5356 shimWritesFirst: true,
5357 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005358
5359 // Client-side renegotiation controls.
5360 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005361 name: "Renegotiate-Client-Forbidden-1",
5362 config: Config{
5363 MaxVersion: VersionTLS12,
5364 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005365 renegotiate: 1,
5366 shouldFail: true,
5367 expectedError: ":NO_RENEGOTIATION:",
5368 expectedLocalError: "remote error: no renegotiation",
5369 })
5370 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005371 name: "Renegotiate-Client-Once-1",
5372 config: Config{
5373 MaxVersion: VersionTLS12,
5374 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005375 renegotiate: 1,
5376 flags: []string{
5377 "-renegotiate-once",
5378 "-expect-total-renegotiations", "1",
5379 },
5380 })
5381 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005382 name: "Renegotiate-Client-Freely-1",
5383 config: Config{
5384 MaxVersion: VersionTLS12,
5385 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005386 renegotiate: 1,
5387 flags: []string{
5388 "-renegotiate-freely",
5389 "-expect-total-renegotiations", "1",
5390 },
5391 })
5392 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005393 name: "Renegotiate-Client-Once-2",
5394 config: Config{
5395 MaxVersion: VersionTLS12,
5396 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005397 renegotiate: 2,
5398 flags: []string{"-renegotiate-once"},
5399 shouldFail: true,
5400 expectedError: ":NO_RENEGOTIATION:",
5401 expectedLocalError: "remote error: no renegotiation",
5402 })
5403 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005404 name: "Renegotiate-Client-Freely-2",
5405 config: Config{
5406 MaxVersion: VersionTLS12,
5407 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005408 renegotiate: 2,
5409 flags: []string{
5410 "-renegotiate-freely",
5411 "-expect-total-renegotiations", "2",
5412 },
5413 })
Adam Langley27a0d082015-11-03 13:34:10 -08005414 testCases = append(testCases, testCase{
5415 name: "Renegotiate-Client-NoIgnore",
5416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005417 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005418 Bugs: ProtocolBugs{
5419 SendHelloRequestBeforeEveryAppDataRecord: true,
5420 },
5421 },
5422 shouldFail: true,
5423 expectedError: ":NO_RENEGOTIATION:",
5424 })
5425 testCases = append(testCases, testCase{
5426 name: "Renegotiate-Client-Ignore",
5427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005429 Bugs: ProtocolBugs{
5430 SendHelloRequestBeforeEveryAppDataRecord: true,
5431 },
5432 },
5433 flags: []string{
5434 "-renegotiate-ignore",
5435 "-expect-total-renegotiations", "0",
5436 },
5437 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005438
David Benjamin397c8e62016-07-08 14:14:36 -07005439 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005440 testCases = append(testCases, testCase{
5441 name: "StrayHelloRequest",
5442 config: Config{
5443 MaxVersion: VersionTLS12,
5444 Bugs: ProtocolBugs{
5445 SendHelloRequestBeforeEveryHandshakeMessage: true,
5446 },
5447 },
5448 })
5449 testCases = append(testCases, testCase{
5450 name: "StrayHelloRequest-Packed",
5451 config: Config{
5452 MaxVersion: VersionTLS12,
5453 Bugs: ProtocolBugs{
5454 PackHandshakeFlight: true,
5455 SendHelloRequestBeforeEveryHandshakeMessage: true,
5456 },
5457 },
5458 })
5459
David Benjamin12d2c482016-07-24 10:56:51 -04005460 // Test renegotiation works if HelloRequest and server Finished come in
5461 // the same record.
5462 testCases = append(testCases, testCase{
5463 name: "Renegotiate-Client-Packed",
5464 config: Config{
5465 MaxVersion: VersionTLS12,
5466 Bugs: ProtocolBugs{
5467 PackHandshakeFlight: true,
5468 PackHelloRequestWithFinished: true,
5469 },
5470 },
5471 renegotiate: 1,
5472 flags: []string{
5473 "-renegotiate-freely",
5474 "-expect-total-renegotiations", "1",
5475 },
5476 })
5477
David Benjamin397c8e62016-07-08 14:14:36 -07005478 // Renegotiation is forbidden in TLS 1.3.
5479 testCases = append(testCases, testCase{
5480 name: "Renegotiate-Client-TLS13",
5481 config: Config{
5482 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005483 Bugs: ProtocolBugs{
5484 SendHelloRequestBeforeEveryAppDataRecord: true,
5485 },
David Benjamin397c8e62016-07-08 14:14:36 -07005486 },
David Benjamin397c8e62016-07-08 14:14:36 -07005487 flags: []string{
5488 "-renegotiate-freely",
5489 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005490 shouldFail: true,
5491 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005492 })
5493
5494 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5495 testCases = append(testCases, testCase{
5496 name: "StrayHelloRequest-TLS13",
5497 config: Config{
5498 MaxVersion: VersionTLS13,
5499 Bugs: ProtocolBugs{
5500 SendHelloRequestBeforeEveryHandshakeMessage: true,
5501 },
5502 },
5503 shouldFail: true,
5504 expectedError: ":UNEXPECTED_MESSAGE:",
5505 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005506}
5507
David Benjamin5e961c12014-11-07 01:48:35 -05005508func addDTLSReplayTests() {
5509 // Test that sequence number replays are detected.
5510 testCases = append(testCases, testCase{
5511 protocol: dtls,
5512 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005513 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005514 replayWrites: true,
5515 })
5516
David Benjamin8e6db492015-07-25 18:29:23 -04005517 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005518 // than the retransmit window.
5519 testCases = append(testCases, testCase{
5520 protocol: dtls,
5521 name: "DTLS-Replay-LargeGaps",
5522 config: Config{
5523 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005524 SequenceNumberMapping: func(in uint64) uint64 {
5525 return in * 127
5526 },
David Benjamin5e961c12014-11-07 01:48:35 -05005527 },
5528 },
David Benjamin8e6db492015-07-25 18:29:23 -04005529 messageCount: 200,
5530 replayWrites: true,
5531 })
5532
5533 // Test the incoming sequence number changing non-monotonically.
5534 testCases = append(testCases, testCase{
5535 protocol: dtls,
5536 name: "DTLS-Replay-NonMonotonic",
5537 config: Config{
5538 Bugs: ProtocolBugs{
5539 SequenceNumberMapping: func(in uint64) uint64 {
5540 return in ^ 31
5541 },
5542 },
5543 },
5544 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005545 replayWrites: true,
5546 })
5547}
5548
Nick Harper60edffd2016-06-21 15:19:24 -07005549var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005550 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005551 id signatureAlgorithm
5552 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005553}{
Nick Harper60edffd2016-06-21 15:19:24 -07005554 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5555 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5556 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5557 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005558 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005559 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5560 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5561 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005562 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5563 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5564 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005565 // Tests for key types prior to TLS 1.2.
5566 {"RSA", 0, testCertRSA},
5567 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005568}
5569
Nick Harper60edffd2016-06-21 15:19:24 -07005570const fakeSigAlg1 signatureAlgorithm = 0x2a01
5571const fakeSigAlg2 signatureAlgorithm = 0xff01
5572
5573func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005574 // Not all ciphers involve a signature. Advertise a list which gives all
5575 // versions a signing cipher.
5576 signingCiphers := []uint16{
5577 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5578 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5579 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5580 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5581 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5582 }
5583
David Benjaminca3d5452016-07-14 12:51:01 -04005584 var allAlgorithms []signatureAlgorithm
5585 for _, alg := range testSignatureAlgorithms {
5586 if alg.id != 0 {
5587 allAlgorithms = append(allAlgorithms, alg.id)
5588 }
5589 }
5590
Nick Harper60edffd2016-06-21 15:19:24 -07005591 // Make sure each signature algorithm works. Include some fake values in
5592 // the list and ensure they're ignored.
5593 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005594 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005595 if (ver.version < VersionTLS12) != (alg.id == 0) {
5596 continue
5597 }
5598
5599 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5600 // or remove it in C.
5601 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005602 continue
5603 }
Nick Harper60edffd2016-06-21 15:19:24 -07005604
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005605 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005606 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005607 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5608 shouldFail = true
5609 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005610 // RSA-PKCS1 does not exist in TLS 1.3.
5611 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5612 shouldFail = true
5613 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005614
5615 var signError, verifyError string
5616 if shouldFail {
5617 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5618 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005619 }
David Benjamin000800a2014-11-14 01:43:59 -05005620
David Benjamin1fb125c2016-07-08 18:52:12 -07005621 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005622
David Benjamin7a41d372016-07-09 11:21:54 -07005623 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005624 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005625 config: Config{
5626 MaxVersion: ver.version,
5627 ClientAuth: RequireAnyClientCert,
5628 VerifySignatureAlgorithms: []signatureAlgorithm{
5629 fakeSigAlg1,
5630 alg.id,
5631 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005632 },
David Benjamin7a41d372016-07-09 11:21:54 -07005633 },
5634 flags: []string{
5635 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5636 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5637 "-enable-all-curves",
5638 },
5639 shouldFail: shouldFail,
5640 expectedError: signError,
5641 expectedPeerSignatureAlgorithm: alg.id,
5642 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005643
David Benjamin7a41d372016-07-09 11:21:54 -07005644 testCases = append(testCases, testCase{
5645 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005646 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005647 config: Config{
5648 MaxVersion: ver.version,
5649 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5650 SignSignatureAlgorithms: []signatureAlgorithm{
5651 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005652 },
David Benjamin7a41d372016-07-09 11:21:54 -07005653 Bugs: ProtocolBugs{
5654 SkipECDSACurveCheck: shouldFail,
5655 IgnoreSignatureVersionChecks: shouldFail,
5656 // The client won't advertise 1.3-only algorithms after
5657 // version negotiation.
5658 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005659 },
David Benjamin7a41d372016-07-09 11:21:54 -07005660 },
5661 flags: []string{
5662 "-require-any-client-certificate",
5663 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5664 "-enable-all-curves",
5665 },
5666 shouldFail: shouldFail,
5667 expectedError: verifyError,
5668 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005669
5670 testCases = append(testCases, testCase{
5671 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005672 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005673 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005674 MaxVersion: ver.version,
5675 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005676 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005677 fakeSigAlg1,
5678 alg.id,
5679 fakeSigAlg2,
5680 },
5681 },
5682 flags: []string{
5683 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5684 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5685 "-enable-all-curves",
5686 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005687 shouldFail: shouldFail,
5688 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005689 expectedPeerSignatureAlgorithm: alg.id,
5690 })
5691
5692 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005693 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005694 config: Config{
5695 MaxVersion: ver.version,
5696 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005697 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005698 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005699 alg.id,
5700 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005701 Bugs: ProtocolBugs{
5702 SkipECDSACurveCheck: shouldFail,
5703 IgnoreSignatureVersionChecks: shouldFail,
5704 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005705 },
5706 flags: []string{
5707 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5708 "-enable-all-curves",
5709 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005710 shouldFail: shouldFail,
5711 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005712 })
David Benjamin5208fd42016-07-13 21:43:25 -04005713
5714 if !shouldFail {
5715 testCases = append(testCases, testCase{
5716 testType: serverTest,
5717 name: "ClientAuth-InvalidSignature" + suffix,
5718 config: Config{
5719 MaxVersion: ver.version,
5720 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5721 SignSignatureAlgorithms: []signatureAlgorithm{
5722 alg.id,
5723 },
5724 Bugs: ProtocolBugs{
5725 InvalidSignature: true,
5726 },
5727 },
5728 flags: []string{
5729 "-require-any-client-certificate",
5730 "-enable-all-curves",
5731 },
5732 shouldFail: true,
5733 expectedError: ":BAD_SIGNATURE:",
5734 })
5735
5736 testCases = append(testCases, testCase{
5737 name: "ServerAuth-InvalidSignature" + suffix,
5738 config: Config{
5739 MaxVersion: ver.version,
5740 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5741 CipherSuites: signingCiphers,
5742 SignSignatureAlgorithms: []signatureAlgorithm{
5743 alg.id,
5744 },
5745 Bugs: ProtocolBugs{
5746 InvalidSignature: true,
5747 },
5748 },
5749 flags: []string{"-enable-all-curves"},
5750 shouldFail: true,
5751 expectedError: ":BAD_SIGNATURE:",
5752 })
5753 }
David Benjaminca3d5452016-07-14 12:51:01 -04005754
5755 if ver.version >= VersionTLS12 && !shouldFail {
5756 testCases = append(testCases, testCase{
5757 name: "ClientAuth-Sign-Negotiate" + suffix,
5758 config: Config{
5759 MaxVersion: ver.version,
5760 ClientAuth: RequireAnyClientCert,
5761 VerifySignatureAlgorithms: allAlgorithms,
5762 },
5763 flags: []string{
5764 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5765 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5766 "-enable-all-curves",
5767 "-signing-prefs", strconv.Itoa(int(alg.id)),
5768 },
5769 expectedPeerSignatureAlgorithm: alg.id,
5770 })
5771
5772 testCases = append(testCases, testCase{
5773 testType: serverTest,
5774 name: "ServerAuth-Sign-Negotiate" + suffix,
5775 config: Config{
5776 MaxVersion: ver.version,
5777 CipherSuites: signingCiphers,
5778 VerifySignatureAlgorithms: allAlgorithms,
5779 },
5780 flags: []string{
5781 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5782 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5783 "-enable-all-curves",
5784 "-signing-prefs", strconv.Itoa(int(alg.id)),
5785 },
5786 expectedPeerSignatureAlgorithm: alg.id,
5787 })
5788 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005789 }
David Benjamin000800a2014-11-14 01:43:59 -05005790 }
5791
Nick Harper60edffd2016-06-21 15:19:24 -07005792 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005793 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005794 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005795 config: Config{
5796 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005797 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005798 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005799 signatureECDSAWithP521AndSHA512,
5800 signatureRSAPKCS1WithSHA384,
5801 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005802 },
5803 },
5804 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005805 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5806 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005807 },
Nick Harper60edffd2016-06-21 15:19:24 -07005808 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005809 })
5810
5811 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005812 name: "ClientAuth-SignatureType-TLS13",
5813 config: Config{
5814 ClientAuth: RequireAnyClientCert,
5815 MaxVersion: VersionTLS13,
5816 VerifySignatureAlgorithms: []signatureAlgorithm{
5817 signatureECDSAWithP521AndSHA512,
5818 signatureRSAPKCS1WithSHA384,
5819 signatureRSAPSSWithSHA384,
5820 signatureECDSAWithSHA1,
5821 },
5822 },
5823 flags: []string{
5824 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5825 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5826 },
5827 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5828 })
5829
5830 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005831 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005832 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005834 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005836 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005837 signatureECDSAWithP521AndSHA512,
5838 signatureRSAPKCS1WithSHA384,
5839 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005840 },
5841 },
Nick Harper60edffd2016-06-21 15:19:24 -07005842 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005843 })
5844
Steven Valdez143e8b32016-07-11 13:19:03 -04005845 testCases = append(testCases, testCase{
5846 testType: serverTest,
5847 name: "ServerAuth-SignatureType-TLS13",
5848 config: Config{
5849 MaxVersion: VersionTLS13,
5850 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5851 VerifySignatureAlgorithms: []signatureAlgorithm{
5852 signatureECDSAWithP521AndSHA512,
5853 signatureRSAPKCS1WithSHA384,
5854 signatureRSAPSSWithSHA384,
5855 signatureECDSAWithSHA1,
5856 },
5857 },
5858 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5859 })
5860
David Benjamina95e9f32016-07-08 16:28:04 -07005861 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005862 testCases = append(testCases, testCase{
5863 testType: serverTest,
5864 name: "Verify-ClientAuth-SignatureType",
5865 config: Config{
5866 MaxVersion: VersionTLS12,
5867 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005868 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005869 signatureRSAPKCS1WithSHA256,
5870 },
5871 Bugs: ProtocolBugs{
5872 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5873 },
5874 },
5875 flags: []string{
5876 "-require-any-client-certificate",
5877 },
5878 shouldFail: true,
5879 expectedError: ":WRONG_SIGNATURE_TYPE:",
5880 })
5881
5882 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005883 testType: serverTest,
5884 name: "Verify-ClientAuth-SignatureType-TLS13",
5885 config: Config{
5886 MaxVersion: VersionTLS13,
5887 Certificates: []Certificate{rsaCertificate},
5888 SignSignatureAlgorithms: []signatureAlgorithm{
5889 signatureRSAPSSWithSHA256,
5890 },
5891 Bugs: ProtocolBugs{
5892 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5893 },
5894 },
5895 flags: []string{
5896 "-require-any-client-certificate",
5897 },
5898 shouldFail: true,
5899 expectedError: ":WRONG_SIGNATURE_TYPE:",
5900 })
5901
5902 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005903 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005904 config: Config{
5905 MaxVersion: VersionTLS12,
5906 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005907 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005908 signatureRSAPKCS1WithSHA256,
5909 },
5910 Bugs: ProtocolBugs{
5911 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5912 },
5913 },
5914 shouldFail: true,
5915 expectedError: ":WRONG_SIGNATURE_TYPE:",
5916 })
5917
Steven Valdez143e8b32016-07-11 13:19:03 -04005918 testCases = append(testCases, testCase{
5919 name: "Verify-ServerAuth-SignatureType-TLS13",
5920 config: Config{
5921 MaxVersion: VersionTLS13,
5922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5923 SignSignatureAlgorithms: []signatureAlgorithm{
5924 signatureRSAPSSWithSHA256,
5925 },
5926 Bugs: ProtocolBugs{
5927 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5928 },
5929 },
5930 shouldFail: true,
5931 expectedError: ":WRONG_SIGNATURE_TYPE:",
5932 })
5933
David Benjamin51dd7d62016-07-08 16:07:01 -07005934 // Test that, if the list is missing, the peer falls back to SHA-1 in
5935 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005936 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005937 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005939 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005940 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005941 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005942 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005943 },
5944 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005945 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005946 },
5947 },
5948 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005949 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5950 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005951 },
5952 })
5953
5954 testCases = append(testCases, testCase{
5955 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005956 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005957 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005958 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005959 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005960 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005961 },
5962 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005963 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005964 },
5965 },
David Benjaminee32bea2016-08-17 13:36:44 -04005966 flags: []string{
5967 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5968 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5969 },
5970 })
5971
5972 testCases = append(testCases, testCase{
5973 name: "ClientAuth-SHA1-Fallback-ECDSA",
5974 config: Config{
5975 MaxVersion: VersionTLS12,
5976 ClientAuth: RequireAnyClientCert,
5977 VerifySignatureAlgorithms: []signatureAlgorithm{
5978 signatureECDSAWithSHA1,
5979 },
5980 Bugs: ProtocolBugs{
5981 NoSignatureAlgorithms: true,
5982 },
5983 },
5984 flags: []string{
5985 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5986 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5987 },
5988 })
5989
5990 testCases = append(testCases, testCase{
5991 testType: serverTest,
5992 name: "ServerAuth-SHA1-Fallback-ECDSA",
5993 config: Config{
5994 MaxVersion: VersionTLS12,
5995 VerifySignatureAlgorithms: []signatureAlgorithm{
5996 signatureECDSAWithSHA1,
5997 },
5998 Bugs: ProtocolBugs{
5999 NoSignatureAlgorithms: true,
6000 },
6001 },
6002 flags: []string{
6003 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6004 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6005 },
David Benjamin000800a2014-11-14 01:43:59 -05006006 })
David Benjamin72dc7832015-03-16 17:49:43 -04006007
David Benjamin51dd7d62016-07-08 16:07:01 -07006008 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006009 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006010 config: Config{
6011 MaxVersion: VersionTLS13,
6012 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006013 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006014 signatureRSAPKCS1WithSHA1,
6015 },
6016 Bugs: ProtocolBugs{
6017 NoSignatureAlgorithms: true,
6018 },
6019 },
6020 flags: []string{
6021 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6022 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6023 },
David Benjamin48901652016-08-01 12:12:47 -04006024 shouldFail: true,
6025 // An empty CertificateRequest signature algorithm list is a
6026 // syntax error in TLS 1.3.
6027 expectedError: ":DECODE_ERROR:",
6028 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006029 })
6030
6031 testCases = append(testCases, testCase{
6032 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006033 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006034 config: Config{
6035 MaxVersion: VersionTLS13,
6036 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006037 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006038 signatureRSAPKCS1WithSHA1,
6039 },
6040 Bugs: ProtocolBugs{
6041 NoSignatureAlgorithms: true,
6042 },
6043 },
6044 shouldFail: true,
6045 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6046 })
6047
David Benjaminb62d2872016-07-18 14:55:02 +02006048 // Test that hash preferences are enforced. BoringSSL does not implement
6049 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006050 testCases = append(testCases, testCase{
6051 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006052 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006053 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006054 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006055 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006056 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006057 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006058 },
6059 Bugs: ProtocolBugs{
6060 IgnorePeerSignatureAlgorithmPreferences: true,
6061 },
6062 },
6063 flags: []string{"-require-any-client-certificate"},
6064 shouldFail: true,
6065 expectedError: ":WRONG_SIGNATURE_TYPE:",
6066 })
6067
6068 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006069 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006071 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006072 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006073 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006074 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006075 },
6076 Bugs: ProtocolBugs{
6077 IgnorePeerSignatureAlgorithmPreferences: true,
6078 },
6079 },
6080 shouldFail: true,
6081 expectedError: ":WRONG_SIGNATURE_TYPE:",
6082 })
David Benjaminb62d2872016-07-18 14:55:02 +02006083 testCases = append(testCases, testCase{
6084 testType: serverTest,
6085 name: "ClientAuth-Enforced-TLS13",
6086 config: Config{
6087 MaxVersion: VersionTLS13,
6088 Certificates: []Certificate{rsaCertificate},
6089 SignSignatureAlgorithms: []signatureAlgorithm{
6090 signatureRSAPKCS1WithMD5,
6091 },
6092 Bugs: ProtocolBugs{
6093 IgnorePeerSignatureAlgorithmPreferences: true,
6094 IgnoreSignatureVersionChecks: true,
6095 },
6096 },
6097 flags: []string{"-require-any-client-certificate"},
6098 shouldFail: true,
6099 expectedError: ":WRONG_SIGNATURE_TYPE:",
6100 })
6101
6102 testCases = append(testCases, testCase{
6103 name: "ServerAuth-Enforced-TLS13",
6104 config: Config{
6105 MaxVersion: VersionTLS13,
6106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6107 SignSignatureAlgorithms: []signatureAlgorithm{
6108 signatureRSAPKCS1WithMD5,
6109 },
6110 Bugs: ProtocolBugs{
6111 IgnorePeerSignatureAlgorithmPreferences: true,
6112 IgnoreSignatureVersionChecks: true,
6113 },
6114 },
6115 shouldFail: true,
6116 expectedError: ":WRONG_SIGNATURE_TYPE:",
6117 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006118
6119 // Test that the agreed upon digest respects the client preferences and
6120 // the server digests.
6121 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006122 name: "NoCommonAlgorithms-Digests",
6123 config: Config{
6124 MaxVersion: VersionTLS12,
6125 ClientAuth: RequireAnyClientCert,
6126 VerifySignatureAlgorithms: []signatureAlgorithm{
6127 signatureRSAPKCS1WithSHA512,
6128 signatureRSAPKCS1WithSHA1,
6129 },
6130 },
6131 flags: []string{
6132 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6133 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6134 "-digest-prefs", "SHA256",
6135 },
6136 shouldFail: true,
6137 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6138 })
6139 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006140 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006142 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006143 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006144 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006145 signatureRSAPKCS1WithSHA512,
6146 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006147 },
6148 },
6149 flags: []string{
6150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006152 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006153 },
David Benjaminca3d5452016-07-14 12:51:01 -04006154 shouldFail: true,
6155 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6156 })
6157 testCases = append(testCases, testCase{
6158 name: "NoCommonAlgorithms-TLS13",
6159 config: Config{
6160 MaxVersion: VersionTLS13,
6161 ClientAuth: RequireAnyClientCert,
6162 VerifySignatureAlgorithms: []signatureAlgorithm{
6163 signatureRSAPSSWithSHA512,
6164 signatureRSAPSSWithSHA384,
6165 },
6166 },
6167 flags: []string{
6168 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6169 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6170 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6171 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006172 shouldFail: true,
6173 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006174 })
6175 testCases = append(testCases, testCase{
6176 name: "Agree-Digest-SHA256",
6177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006178 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006179 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006180 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006181 signatureRSAPKCS1WithSHA1,
6182 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006183 },
6184 },
6185 flags: []string{
6186 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6187 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006188 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006189 },
Nick Harper60edffd2016-06-21 15:19:24 -07006190 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006191 })
6192 testCases = append(testCases, testCase{
6193 name: "Agree-Digest-SHA1",
6194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006195 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006196 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006197 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006198 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006199 },
6200 },
6201 flags: []string{
6202 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6203 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006204 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006205 },
Nick Harper60edffd2016-06-21 15:19:24 -07006206 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006207 })
6208 testCases = append(testCases, testCase{
6209 name: "Agree-Digest-Default",
6210 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006211 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006212 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006213 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006214 signatureRSAPKCS1WithSHA256,
6215 signatureECDSAWithP256AndSHA256,
6216 signatureRSAPKCS1WithSHA1,
6217 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 },
6219 },
6220 flags: []string{
6221 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6222 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6223 },
Nick Harper60edffd2016-06-21 15:19:24 -07006224 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006225 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006226
David Benjaminca3d5452016-07-14 12:51:01 -04006227 // Test that the signing preference list may include extra algorithms
6228 // without negotiation problems.
6229 testCases = append(testCases, testCase{
6230 testType: serverTest,
6231 name: "FilterExtraAlgorithms",
6232 config: Config{
6233 MaxVersion: VersionTLS12,
6234 VerifySignatureAlgorithms: []signatureAlgorithm{
6235 signatureRSAPKCS1WithSHA256,
6236 },
6237 },
6238 flags: []string{
6239 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6240 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6241 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6242 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6243 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6244 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6245 },
6246 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6247 })
6248
David Benjamin4c3ddf72016-06-29 18:13:53 -04006249 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6250 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006251 testCases = append(testCases, testCase{
6252 name: "CheckLeafCurve",
6253 config: Config{
6254 MaxVersion: VersionTLS12,
6255 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006256 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006257 },
6258 flags: []string{"-p384-only"},
6259 shouldFail: true,
6260 expectedError: ":BAD_ECC_CERT:",
6261 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006262
6263 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6264 testCases = append(testCases, testCase{
6265 name: "CheckLeafCurve-TLS13",
6266 config: Config{
6267 MaxVersion: VersionTLS13,
6268 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6269 Certificates: []Certificate{ecdsaP256Certificate},
6270 },
6271 flags: []string{"-p384-only"},
6272 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006273
6274 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6275 testCases = append(testCases, testCase{
6276 name: "ECDSACurveMismatch-Verify-TLS12",
6277 config: Config{
6278 MaxVersion: VersionTLS12,
6279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6280 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006281 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006282 signatureECDSAWithP384AndSHA384,
6283 },
6284 },
6285 })
6286
6287 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6288 testCases = append(testCases, testCase{
6289 name: "ECDSACurveMismatch-Verify-TLS13",
6290 config: Config{
6291 MaxVersion: VersionTLS13,
6292 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6293 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006294 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006295 signatureECDSAWithP384AndSHA384,
6296 },
6297 Bugs: ProtocolBugs{
6298 SkipECDSACurveCheck: true,
6299 },
6300 },
6301 shouldFail: true,
6302 expectedError: ":WRONG_SIGNATURE_TYPE:",
6303 })
6304
6305 // Signature algorithm selection in TLS 1.3 should take the curve into
6306 // account.
6307 testCases = append(testCases, testCase{
6308 testType: serverTest,
6309 name: "ECDSACurveMismatch-Sign-TLS13",
6310 config: Config{
6311 MaxVersion: VersionTLS13,
6312 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006313 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006314 signatureECDSAWithP384AndSHA384,
6315 signatureECDSAWithP256AndSHA256,
6316 },
6317 },
6318 flags: []string{
6319 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6320 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6321 },
6322 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6323 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006324
6325 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6326 // server does not attempt to sign in that case.
6327 testCases = append(testCases, testCase{
6328 testType: serverTest,
6329 name: "RSA-PSS-Large",
6330 config: Config{
6331 MaxVersion: VersionTLS13,
6332 VerifySignatureAlgorithms: []signatureAlgorithm{
6333 signatureRSAPSSWithSHA512,
6334 },
6335 },
6336 flags: []string{
6337 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6338 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6339 },
6340 shouldFail: true,
6341 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6342 })
David Benjamin57e929f2016-08-30 00:30:38 -04006343
6344 // Test that RSA-PSS is enabled by default for TLS 1.2.
6345 testCases = append(testCases, testCase{
6346 testType: clientTest,
6347 name: "RSA-PSS-Default-Verify",
6348 config: Config{
6349 MaxVersion: VersionTLS12,
6350 SignSignatureAlgorithms: []signatureAlgorithm{
6351 signatureRSAPSSWithSHA256,
6352 },
6353 },
6354 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6355 })
6356
6357 testCases = append(testCases, testCase{
6358 testType: serverTest,
6359 name: "RSA-PSS-Default-Sign",
6360 config: Config{
6361 MaxVersion: VersionTLS12,
6362 VerifySignatureAlgorithms: []signatureAlgorithm{
6363 signatureRSAPSSWithSHA256,
6364 },
6365 },
6366 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6367 })
David Benjamin000800a2014-11-14 01:43:59 -05006368}
6369
David Benjamin83f90402015-01-27 01:09:43 -05006370// timeouts is the retransmit schedule for BoringSSL. It doubles and
6371// caps at 60 seconds. On the 13th timeout, it gives up.
6372var timeouts = []time.Duration{
6373 1 * time.Second,
6374 2 * time.Second,
6375 4 * time.Second,
6376 8 * time.Second,
6377 16 * time.Second,
6378 32 * time.Second,
6379 60 * time.Second,
6380 60 * time.Second,
6381 60 * time.Second,
6382 60 * time.Second,
6383 60 * time.Second,
6384 60 * time.Second,
6385 60 * time.Second,
6386}
6387
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006388// shortTimeouts is an alternate set of timeouts which would occur if the
6389// initial timeout duration was set to 250ms.
6390var shortTimeouts = []time.Duration{
6391 250 * time.Millisecond,
6392 500 * time.Millisecond,
6393 1 * time.Second,
6394 2 * time.Second,
6395 4 * time.Second,
6396 8 * time.Second,
6397 16 * time.Second,
6398 32 * time.Second,
6399 60 * time.Second,
6400 60 * time.Second,
6401 60 * time.Second,
6402 60 * time.Second,
6403 60 * time.Second,
6404}
6405
David Benjamin83f90402015-01-27 01:09:43 -05006406func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006407 // These tests work by coordinating some behavior on both the shim and
6408 // the runner.
6409 //
6410 // TimeoutSchedule configures the runner to send a series of timeout
6411 // opcodes to the shim (see packetAdaptor) immediately before reading
6412 // each peer handshake flight N. The timeout opcode both simulates a
6413 // timeout in the shim and acts as a synchronization point to help the
6414 // runner bracket each handshake flight.
6415 //
6416 // We assume the shim does not read from the channel eagerly. It must
6417 // first wait until it has sent flight N and is ready to receive
6418 // handshake flight N+1. At this point, it will process the timeout
6419 // opcode. It must then immediately respond with a timeout ACK and act
6420 // as if the shim was idle for the specified amount of time.
6421 //
6422 // The runner then drops all packets received before the ACK and
6423 // continues waiting for flight N. This ordering results in one attempt
6424 // at sending flight N to be dropped. For the test to complete, the
6425 // shim must send flight N again, testing that the shim implements DTLS
6426 // retransmit on a timeout.
6427
Steven Valdez143e8b32016-07-11 13:19:03 -04006428 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006429 // likely be more epochs to cross and the final message's retransmit may
6430 // be more complex.
6431
David Benjamin585d7a42016-06-02 14:58:00 -04006432 for _, async := range []bool{true, false} {
6433 var tests []testCase
6434
6435 // Test that this is indeed the timeout schedule. Stress all
6436 // four patterns of handshake.
6437 for i := 1; i < len(timeouts); i++ {
6438 number := strconv.Itoa(i)
6439 tests = append(tests, testCase{
6440 protocol: dtls,
6441 name: "DTLS-Retransmit-Client-" + number,
6442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006443 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006444 Bugs: ProtocolBugs{
6445 TimeoutSchedule: timeouts[:i],
6446 },
6447 },
6448 resumeSession: true,
6449 })
6450 tests = append(tests, testCase{
6451 protocol: dtls,
6452 testType: serverTest,
6453 name: "DTLS-Retransmit-Server-" + number,
6454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006455 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006456 Bugs: ProtocolBugs{
6457 TimeoutSchedule: timeouts[:i],
6458 },
6459 },
6460 resumeSession: true,
6461 })
6462 }
6463
6464 // Test that exceeding the timeout schedule hits a read
6465 // timeout.
6466 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006467 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006468 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006470 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006471 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006472 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006473 },
6474 },
6475 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006476 shouldFail: true,
6477 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006478 })
David Benjamin585d7a42016-06-02 14:58:00 -04006479
6480 if async {
6481 // Test that timeout handling has a fudge factor, due to API
6482 // problems.
6483 tests = append(tests, testCase{
6484 protocol: dtls,
6485 name: "DTLS-Retransmit-Fudge",
6486 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006487 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006488 Bugs: ProtocolBugs{
6489 TimeoutSchedule: []time.Duration{
6490 timeouts[0] - 10*time.Millisecond,
6491 },
6492 },
6493 },
6494 resumeSession: true,
6495 })
6496 }
6497
6498 // Test that the final Finished retransmitting isn't
6499 // duplicated if the peer badly fragments everything.
6500 tests = append(tests, testCase{
6501 testType: serverTest,
6502 protocol: dtls,
6503 name: "DTLS-Retransmit-Fragmented",
6504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006505 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006506 Bugs: ProtocolBugs{
6507 TimeoutSchedule: []time.Duration{timeouts[0]},
6508 MaxHandshakeRecordLength: 2,
6509 },
6510 },
6511 })
6512
6513 // Test the timeout schedule when a shorter initial timeout duration is set.
6514 tests = append(tests, testCase{
6515 protocol: dtls,
6516 name: "DTLS-Retransmit-Short-Client",
6517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006518 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006519 Bugs: ProtocolBugs{
6520 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6521 },
6522 },
6523 resumeSession: true,
6524 flags: []string{"-initial-timeout-duration-ms", "250"},
6525 })
6526 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006527 protocol: dtls,
6528 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006529 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006532 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006533 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006534 },
6535 },
6536 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006537 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006538 })
David Benjamin585d7a42016-06-02 14:58:00 -04006539
6540 for _, test := range tests {
6541 if async {
6542 test.name += "-Async"
6543 test.flags = append(test.flags, "-async")
6544 }
6545
6546 testCases = append(testCases, test)
6547 }
David Benjamin83f90402015-01-27 01:09:43 -05006548 }
David Benjamin83f90402015-01-27 01:09:43 -05006549}
6550
David Benjaminc565ebb2015-04-03 04:06:36 -04006551func addExportKeyingMaterialTests() {
6552 for _, vers := range tlsVersions {
6553 if vers.version == VersionSSL30 {
6554 continue
6555 }
6556 testCases = append(testCases, testCase{
6557 name: "ExportKeyingMaterial-" + vers.name,
6558 config: Config{
6559 MaxVersion: vers.version,
6560 },
6561 exportKeyingMaterial: 1024,
6562 exportLabel: "label",
6563 exportContext: "context",
6564 useExportContext: true,
6565 })
6566 testCases = append(testCases, testCase{
6567 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6568 config: Config{
6569 MaxVersion: vers.version,
6570 },
6571 exportKeyingMaterial: 1024,
6572 })
6573 testCases = append(testCases, testCase{
6574 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6575 config: Config{
6576 MaxVersion: vers.version,
6577 },
6578 exportKeyingMaterial: 1024,
6579 useExportContext: true,
6580 })
6581 testCases = append(testCases, testCase{
6582 name: "ExportKeyingMaterial-Small-" + vers.name,
6583 config: Config{
6584 MaxVersion: vers.version,
6585 },
6586 exportKeyingMaterial: 1,
6587 exportLabel: "label",
6588 exportContext: "context",
6589 useExportContext: true,
6590 })
6591 }
6592 testCases = append(testCases, testCase{
6593 name: "ExportKeyingMaterial-SSL3",
6594 config: Config{
6595 MaxVersion: VersionSSL30,
6596 },
6597 exportKeyingMaterial: 1024,
6598 exportLabel: "label",
6599 exportContext: "context",
6600 useExportContext: true,
6601 shouldFail: true,
6602 expectedError: "failed to export keying material",
6603 })
6604}
6605
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006606func addTLSUniqueTests() {
6607 for _, isClient := range []bool{false, true} {
6608 for _, isResumption := range []bool{false, true} {
6609 for _, hasEMS := range []bool{false, true} {
6610 var suffix string
6611 if isResumption {
6612 suffix = "Resume-"
6613 } else {
6614 suffix = "Full-"
6615 }
6616
6617 if hasEMS {
6618 suffix += "EMS-"
6619 } else {
6620 suffix += "NoEMS-"
6621 }
6622
6623 if isClient {
6624 suffix += "Client"
6625 } else {
6626 suffix += "Server"
6627 }
6628
6629 test := testCase{
6630 name: "TLSUnique-" + suffix,
6631 testTLSUnique: true,
6632 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006633 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006634 Bugs: ProtocolBugs{
6635 NoExtendedMasterSecret: !hasEMS,
6636 },
6637 },
6638 }
6639
6640 if isResumption {
6641 test.resumeSession = true
6642 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006643 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006644 Bugs: ProtocolBugs{
6645 NoExtendedMasterSecret: !hasEMS,
6646 },
6647 }
6648 }
6649
6650 if isResumption && !hasEMS {
6651 test.shouldFail = true
6652 test.expectedError = "failed to get tls-unique"
6653 }
6654
6655 testCases = append(testCases, test)
6656 }
6657 }
6658 }
6659}
6660
Adam Langley09505632015-07-30 18:10:13 -07006661func addCustomExtensionTests() {
6662 expectedContents := "custom extension"
6663 emptyString := ""
6664
6665 for _, isClient := range []bool{false, true} {
6666 suffix := "Server"
6667 flag := "-enable-server-custom-extension"
6668 testType := serverTest
6669 if isClient {
6670 suffix = "Client"
6671 flag = "-enable-client-custom-extension"
6672 testType = clientTest
6673 }
6674
6675 testCases = append(testCases, testCase{
6676 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006677 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006679 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006680 Bugs: ProtocolBugs{
6681 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006682 ExpectedCustomExtension: &expectedContents,
6683 },
6684 },
6685 flags: []string{flag},
6686 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006687 testCases = append(testCases, testCase{
6688 testType: testType,
6689 name: "CustomExtensions-" + suffix + "-TLS13",
6690 config: Config{
6691 MaxVersion: VersionTLS13,
6692 Bugs: ProtocolBugs{
6693 CustomExtension: expectedContents,
6694 ExpectedCustomExtension: &expectedContents,
6695 },
6696 },
6697 flags: []string{flag},
6698 })
Adam Langley09505632015-07-30 18:10:13 -07006699
6700 // If the parse callback fails, the handshake should also fail.
6701 testCases = append(testCases, testCase{
6702 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006703 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006704 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006705 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006706 Bugs: ProtocolBugs{
6707 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006708 ExpectedCustomExtension: &expectedContents,
6709 },
6710 },
David Benjamin399e7c92015-07-30 23:01:27 -04006711 flags: []string{flag},
6712 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006713 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6714 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006715 testCases = append(testCases, testCase{
6716 testType: testType,
6717 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6718 config: Config{
6719 MaxVersion: VersionTLS13,
6720 Bugs: ProtocolBugs{
6721 CustomExtension: expectedContents + "foo",
6722 ExpectedCustomExtension: &expectedContents,
6723 },
6724 },
6725 flags: []string{flag},
6726 shouldFail: true,
6727 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6728 })
Adam Langley09505632015-07-30 18:10:13 -07006729
6730 // If the add callback fails, the handshake should also fail.
6731 testCases = append(testCases, testCase{
6732 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006733 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006734 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006735 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006736 Bugs: ProtocolBugs{
6737 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006738 ExpectedCustomExtension: &expectedContents,
6739 },
6740 },
David Benjamin399e7c92015-07-30 23:01:27 -04006741 flags: []string{flag, "-custom-extension-fail-add"},
6742 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006743 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6744 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006745 testCases = append(testCases, testCase{
6746 testType: testType,
6747 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6748 config: Config{
6749 MaxVersion: VersionTLS13,
6750 Bugs: ProtocolBugs{
6751 CustomExtension: expectedContents,
6752 ExpectedCustomExtension: &expectedContents,
6753 },
6754 },
6755 flags: []string{flag, "-custom-extension-fail-add"},
6756 shouldFail: true,
6757 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6758 })
Adam Langley09505632015-07-30 18:10:13 -07006759
6760 // If the add callback returns zero, no extension should be
6761 // added.
6762 skipCustomExtension := expectedContents
6763 if isClient {
6764 // For the case where the client skips sending the
6765 // custom extension, the server must not “echo” it.
6766 skipCustomExtension = ""
6767 }
6768 testCases = append(testCases, testCase{
6769 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006770 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006772 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006773 Bugs: ProtocolBugs{
6774 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006775 ExpectedCustomExtension: &emptyString,
6776 },
6777 },
6778 flags: []string{flag, "-custom-extension-skip"},
6779 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006780 testCases = append(testCases, testCase{
6781 testType: testType,
6782 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6783 config: Config{
6784 MaxVersion: VersionTLS13,
6785 Bugs: ProtocolBugs{
6786 CustomExtension: skipCustomExtension,
6787 ExpectedCustomExtension: &emptyString,
6788 },
6789 },
6790 flags: []string{flag, "-custom-extension-skip"},
6791 })
Adam Langley09505632015-07-30 18:10:13 -07006792 }
6793
6794 // The custom extension add callback should not be called if the client
6795 // doesn't send the extension.
6796 testCases = append(testCases, testCase{
6797 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006798 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006800 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006801 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006802 ExpectedCustomExtension: &emptyString,
6803 },
6804 },
6805 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6806 })
Adam Langley2deb9842015-08-07 11:15:37 -07006807
Steven Valdez143e8b32016-07-11 13:19:03 -04006808 testCases = append(testCases, testCase{
6809 testType: serverTest,
6810 name: "CustomExtensions-NotCalled-Server-TLS13",
6811 config: Config{
6812 MaxVersion: VersionTLS13,
6813 Bugs: ProtocolBugs{
6814 ExpectedCustomExtension: &emptyString,
6815 },
6816 },
6817 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6818 })
6819
Adam Langley2deb9842015-08-07 11:15:37 -07006820 // Test an unknown extension from the server.
6821 testCases = append(testCases, testCase{
6822 testType: clientTest,
6823 name: "UnknownExtension-Client",
6824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006825 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006826 Bugs: ProtocolBugs{
6827 CustomExtension: expectedContents,
6828 },
6829 },
David Benjamin0c40a962016-08-01 12:05:50 -04006830 shouldFail: true,
6831 expectedError: ":UNEXPECTED_EXTENSION:",
6832 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006833 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006834 testCases = append(testCases, testCase{
6835 testType: clientTest,
6836 name: "UnknownExtension-Client-TLS13",
6837 config: Config{
6838 MaxVersion: VersionTLS13,
6839 Bugs: ProtocolBugs{
6840 CustomExtension: expectedContents,
6841 },
6842 },
David Benjamin0c40a962016-08-01 12:05:50 -04006843 shouldFail: true,
6844 expectedError: ":UNEXPECTED_EXTENSION:",
6845 expectedLocalError: "remote error: unsupported extension",
6846 })
6847
6848 // Test a known but unoffered extension from the server.
6849 testCases = append(testCases, testCase{
6850 testType: clientTest,
6851 name: "UnofferedExtension-Client",
6852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 Bugs: ProtocolBugs{
6855 SendALPN: "alpn",
6856 },
6857 },
6858 shouldFail: true,
6859 expectedError: ":UNEXPECTED_EXTENSION:",
6860 expectedLocalError: "remote error: unsupported extension",
6861 })
6862 testCases = append(testCases, testCase{
6863 testType: clientTest,
6864 name: "UnofferedExtension-Client-TLS13",
6865 config: Config{
6866 MaxVersion: VersionTLS13,
6867 Bugs: ProtocolBugs{
6868 SendALPN: "alpn",
6869 },
6870 },
6871 shouldFail: true,
6872 expectedError: ":UNEXPECTED_EXTENSION:",
6873 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006874 })
Adam Langley09505632015-07-30 18:10:13 -07006875}
6876
David Benjaminb36a3952015-12-01 18:53:13 -05006877func addRSAClientKeyExchangeTests() {
6878 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6879 testCases = append(testCases, testCase{
6880 testType: serverTest,
6881 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6882 config: Config{
6883 // Ensure the ClientHello version and final
6884 // version are different, to detect if the
6885 // server uses the wrong one.
6886 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006887 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006888 Bugs: ProtocolBugs{
6889 BadRSAClientKeyExchange: bad,
6890 },
6891 },
6892 shouldFail: true,
6893 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6894 })
6895 }
David Benjamine63d9d72016-09-19 18:27:34 -04006896
6897 // The server must compare whatever was in ClientHello.version for the
6898 // RSA premaster.
6899 testCases = append(testCases, testCase{
6900 testType: serverTest,
6901 name: "SendClientVersion-RSA",
6902 config: Config{
6903 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6904 Bugs: ProtocolBugs{
6905 SendClientVersion: 0x1234,
6906 },
6907 },
6908 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6909 })
David Benjaminb36a3952015-12-01 18:53:13 -05006910}
6911
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006912var testCurves = []struct {
6913 name string
6914 id CurveID
6915}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006916 {"P-256", CurveP256},
6917 {"P-384", CurveP384},
6918 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006919 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006920}
6921
Steven Valdez5440fe02016-07-18 12:40:30 -04006922const bogusCurve = 0x1234
6923
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006924func addCurveTests() {
6925 for _, curve := range testCurves {
6926 testCases = append(testCases, testCase{
6927 name: "CurveTest-Client-" + curve.name,
6928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006929 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6931 CurvePreferences: []CurveID{curve.id},
6932 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006933 flags: []string{
6934 "-enable-all-curves",
6935 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6936 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006937 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006938 })
6939 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006940 name: "CurveTest-Client-" + curve.name + "-TLS13",
6941 config: Config{
6942 MaxVersion: VersionTLS13,
6943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6944 CurvePreferences: []CurveID{curve.id},
6945 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006946 flags: []string{
6947 "-enable-all-curves",
6948 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6949 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006950 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006951 })
6952 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006953 testType: serverTest,
6954 name: "CurveTest-Server-" + curve.name,
6955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006956 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006957 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6958 CurvePreferences: []CurveID{curve.id},
6959 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006960 flags: []string{
6961 "-enable-all-curves",
6962 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6963 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006964 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006965 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006966 testCases = append(testCases, testCase{
6967 testType: serverTest,
6968 name: "CurveTest-Server-" + curve.name + "-TLS13",
6969 config: Config{
6970 MaxVersion: VersionTLS13,
6971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6972 CurvePreferences: []CurveID{curve.id},
6973 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006974 flags: []string{
6975 "-enable-all-curves",
6976 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6977 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006978 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006979 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006980 }
David Benjamin241ae832016-01-15 03:04:54 -05006981
6982 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006983 testCases = append(testCases, testCase{
6984 testType: serverTest,
6985 name: "UnknownCurve",
6986 config: Config{
6987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6988 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6989 },
6990 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006991
6992 // The server must not consider ECDHE ciphers when there are no
6993 // supported curves.
6994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "NoSupportedCurves",
6997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 MaxVersion: VersionTLS12,
6999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7000 Bugs: ProtocolBugs{
7001 NoSupportedCurves: true,
7002 },
7003 },
7004 shouldFail: true,
7005 expectedError: ":NO_SHARED_CIPHER:",
7006 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007007 testCases = append(testCases, testCase{
7008 testType: serverTest,
7009 name: "NoSupportedCurves-TLS13",
7010 config: Config{
7011 MaxVersion: VersionTLS13,
7012 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7013 Bugs: ProtocolBugs{
7014 NoSupportedCurves: true,
7015 },
7016 },
7017 shouldFail: true,
7018 expectedError: ":NO_SHARED_CIPHER:",
7019 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007020
7021 // The server must fall back to another cipher when there are no
7022 // supported curves.
7023 testCases = append(testCases, testCase{
7024 testType: serverTest,
7025 name: "NoCommonCurves",
7026 config: Config{
7027 MaxVersion: VersionTLS12,
7028 CipherSuites: []uint16{
7029 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7030 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7031 },
7032 CurvePreferences: []CurveID{CurveP224},
7033 },
7034 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7035 })
7036
7037 // The client must reject bogus curves and disabled curves.
7038 testCases = append(testCases, testCase{
7039 name: "BadECDHECurve",
7040 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007041 MaxVersion: VersionTLS12,
7042 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7043 Bugs: ProtocolBugs{
7044 SendCurve: bogusCurve,
7045 },
7046 },
7047 shouldFail: true,
7048 expectedError: ":WRONG_CURVE:",
7049 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007050 testCases = append(testCases, testCase{
7051 name: "BadECDHECurve-TLS13",
7052 config: Config{
7053 MaxVersion: VersionTLS13,
7054 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7055 Bugs: ProtocolBugs{
7056 SendCurve: bogusCurve,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedError: ":WRONG_CURVE:",
7061 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007062
7063 testCases = append(testCases, testCase{
7064 name: "UnsupportedCurve",
7065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007066 MaxVersion: VersionTLS12,
7067 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7068 CurvePreferences: []CurveID{CurveP256},
7069 Bugs: ProtocolBugs{
7070 IgnorePeerCurvePreferences: true,
7071 },
7072 },
7073 flags: []string{"-p384-only"},
7074 shouldFail: true,
7075 expectedError: ":WRONG_CURVE:",
7076 })
7077
David Benjamin4f921572016-07-17 14:20:10 +02007078 testCases = append(testCases, testCase{
7079 // TODO(davidben): Add a TLS 1.3 version where
7080 // HelloRetryRequest requests an unsupported curve.
7081 name: "UnsupportedCurve-ServerHello-TLS13",
7082 config: Config{
7083 MaxVersion: VersionTLS12,
7084 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7085 CurvePreferences: []CurveID{CurveP384},
7086 Bugs: ProtocolBugs{
7087 SendCurve: CurveP256,
7088 },
7089 },
7090 flags: []string{"-p384-only"},
7091 shouldFail: true,
7092 expectedError: ":WRONG_CURVE:",
7093 })
7094
David Benjamin4c3ddf72016-06-29 18:13:53 -04007095 // Test invalid curve points.
7096 testCases = append(testCases, testCase{
7097 name: "InvalidECDHPoint-Client",
7098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007099 MaxVersion: VersionTLS12,
7100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7101 CurvePreferences: []CurveID{CurveP256},
7102 Bugs: ProtocolBugs{
7103 InvalidECDHPoint: true,
7104 },
7105 },
7106 shouldFail: true,
7107 expectedError: ":INVALID_ENCODING:",
7108 })
7109 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007110 name: "InvalidECDHPoint-Client-TLS13",
7111 config: Config{
7112 MaxVersion: VersionTLS13,
7113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7114 CurvePreferences: []CurveID{CurveP256},
7115 Bugs: ProtocolBugs{
7116 InvalidECDHPoint: true,
7117 },
7118 },
7119 shouldFail: true,
7120 expectedError: ":INVALID_ENCODING:",
7121 })
7122 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007123 testType: serverTest,
7124 name: "InvalidECDHPoint-Server",
7125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
7127 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7128 CurvePreferences: []CurveID{CurveP256},
7129 Bugs: ProtocolBugs{
7130 InvalidECDHPoint: true,
7131 },
7132 },
7133 shouldFail: true,
7134 expectedError: ":INVALID_ENCODING:",
7135 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007136 testCases = append(testCases, testCase{
7137 testType: serverTest,
7138 name: "InvalidECDHPoint-Server-TLS13",
7139 config: Config{
7140 MaxVersion: VersionTLS13,
7141 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7142 CurvePreferences: []CurveID{CurveP256},
7143 Bugs: ProtocolBugs{
7144 InvalidECDHPoint: true,
7145 },
7146 },
7147 shouldFail: true,
7148 expectedError: ":INVALID_ENCODING:",
7149 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007150}
7151
Matt Braithwaite54217e42016-06-13 13:03:47 -07007152func addCECPQ1Tests() {
7153 testCases = append(testCases, testCase{
7154 testType: clientTest,
7155 name: "CECPQ1-Client-BadX25519Part",
7156 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007157 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007158 MinVersion: VersionTLS12,
7159 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7160 Bugs: ProtocolBugs{
7161 CECPQ1BadX25519Part: true,
7162 },
7163 },
7164 flags: []string{"-cipher", "kCECPQ1"},
7165 shouldFail: true,
7166 expectedLocalError: "local error: bad record MAC",
7167 })
7168 testCases = append(testCases, testCase{
7169 testType: clientTest,
7170 name: "CECPQ1-Client-BadNewhopePart",
7171 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007172 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007173 MinVersion: VersionTLS12,
7174 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7175 Bugs: ProtocolBugs{
7176 CECPQ1BadNewhopePart: true,
7177 },
7178 },
7179 flags: []string{"-cipher", "kCECPQ1"},
7180 shouldFail: true,
7181 expectedLocalError: "local error: bad record MAC",
7182 })
7183 testCases = append(testCases, testCase{
7184 testType: serverTest,
7185 name: "CECPQ1-Server-BadX25519Part",
7186 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007187 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007188 MinVersion: VersionTLS12,
7189 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7190 Bugs: ProtocolBugs{
7191 CECPQ1BadX25519Part: true,
7192 },
7193 },
7194 flags: []string{"-cipher", "kCECPQ1"},
7195 shouldFail: true,
7196 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7197 })
7198 testCases = append(testCases, testCase{
7199 testType: serverTest,
7200 name: "CECPQ1-Server-BadNewhopePart",
7201 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007202 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007203 MinVersion: VersionTLS12,
7204 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7205 Bugs: ProtocolBugs{
7206 CECPQ1BadNewhopePart: true,
7207 },
7208 },
7209 flags: []string{"-cipher", "kCECPQ1"},
7210 shouldFail: true,
7211 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7212 })
7213}
7214
David Benjamin5c4e8572016-08-19 17:44:53 -04007215func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007216 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007217 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007218 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007219 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007220 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7221 Bugs: ProtocolBugs{
7222 // This is a 1234-bit prime number, generated
7223 // with:
7224 // openssl gendh 1234 | openssl asn1parse -i
7225 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7226 },
7227 },
David Benjamin9e68f192016-06-30 14:55:33 -04007228 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007229 })
7230 testCases = append(testCases, testCase{
7231 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007232 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007233 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007234 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007235 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7236 },
7237 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007238 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007239 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007240}
7241
David Benjaminc9ae27c2016-06-24 22:56:37 -04007242func addTLS13RecordTests() {
7243 testCases = append(testCases, testCase{
7244 name: "TLS13-RecordPadding",
7245 config: Config{
7246 MaxVersion: VersionTLS13,
7247 MinVersion: VersionTLS13,
7248 Bugs: ProtocolBugs{
7249 RecordPadding: 10,
7250 },
7251 },
7252 })
7253
7254 testCases = append(testCases, testCase{
7255 name: "TLS13-EmptyRecords",
7256 config: Config{
7257 MaxVersion: VersionTLS13,
7258 MinVersion: VersionTLS13,
7259 Bugs: ProtocolBugs{
7260 OmitRecordContents: true,
7261 },
7262 },
7263 shouldFail: true,
7264 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7265 })
7266
7267 testCases = append(testCases, testCase{
7268 name: "TLS13-OnlyPadding",
7269 config: Config{
7270 MaxVersion: VersionTLS13,
7271 MinVersion: VersionTLS13,
7272 Bugs: ProtocolBugs{
7273 OmitRecordContents: true,
7274 RecordPadding: 10,
7275 },
7276 },
7277 shouldFail: true,
7278 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7279 })
7280
7281 testCases = append(testCases, testCase{
7282 name: "TLS13-WrongOuterRecord",
7283 config: Config{
7284 MaxVersion: VersionTLS13,
7285 MinVersion: VersionTLS13,
7286 Bugs: ProtocolBugs{
7287 OuterRecordType: recordTypeHandshake,
7288 },
7289 },
7290 shouldFail: true,
7291 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7292 })
7293}
7294
David Benjamin82261be2016-07-07 14:32:50 -07007295func addChangeCipherSpecTests() {
7296 // Test missing ChangeCipherSpecs.
7297 testCases = append(testCases, testCase{
7298 name: "SkipChangeCipherSpec-Client",
7299 config: Config{
7300 MaxVersion: VersionTLS12,
7301 Bugs: ProtocolBugs{
7302 SkipChangeCipherSpec: true,
7303 },
7304 },
7305 shouldFail: true,
7306 expectedError: ":UNEXPECTED_RECORD:",
7307 })
7308 testCases = append(testCases, testCase{
7309 testType: serverTest,
7310 name: "SkipChangeCipherSpec-Server",
7311 config: Config{
7312 MaxVersion: VersionTLS12,
7313 Bugs: ProtocolBugs{
7314 SkipChangeCipherSpec: true,
7315 },
7316 },
7317 shouldFail: true,
7318 expectedError: ":UNEXPECTED_RECORD:",
7319 })
7320 testCases = append(testCases, testCase{
7321 testType: serverTest,
7322 name: "SkipChangeCipherSpec-Server-NPN",
7323 config: Config{
7324 MaxVersion: VersionTLS12,
7325 NextProtos: []string{"bar"},
7326 Bugs: ProtocolBugs{
7327 SkipChangeCipherSpec: true,
7328 },
7329 },
7330 flags: []string{
7331 "-advertise-npn", "\x03foo\x03bar\x03baz",
7332 },
7333 shouldFail: true,
7334 expectedError: ":UNEXPECTED_RECORD:",
7335 })
7336
7337 // Test synchronization between the handshake and ChangeCipherSpec.
7338 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7339 // rejected. Test both with and without handshake packing to handle both
7340 // when the partial post-CCS message is in its own record and when it is
7341 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007342 for _, packed := range []bool{false, true} {
7343 var suffix string
7344 if packed {
7345 suffix = "-Packed"
7346 }
7347
7348 testCases = append(testCases, testCase{
7349 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7350 config: Config{
7351 MaxVersion: VersionTLS12,
7352 Bugs: ProtocolBugs{
7353 FragmentAcrossChangeCipherSpec: true,
7354 PackHandshakeFlight: packed,
7355 },
7356 },
7357 shouldFail: true,
7358 expectedError: ":UNEXPECTED_RECORD:",
7359 })
7360 testCases = append(testCases, testCase{
7361 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7362 config: Config{
7363 MaxVersion: VersionTLS12,
7364 },
7365 resumeSession: true,
7366 resumeConfig: &Config{
7367 MaxVersion: VersionTLS12,
7368 Bugs: ProtocolBugs{
7369 FragmentAcrossChangeCipherSpec: true,
7370 PackHandshakeFlight: packed,
7371 },
7372 },
7373 shouldFail: true,
7374 expectedError: ":UNEXPECTED_RECORD:",
7375 })
7376 testCases = append(testCases, testCase{
7377 testType: serverTest,
7378 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7379 config: Config{
7380 MaxVersion: VersionTLS12,
7381 Bugs: ProtocolBugs{
7382 FragmentAcrossChangeCipherSpec: true,
7383 PackHandshakeFlight: packed,
7384 },
7385 },
7386 shouldFail: true,
7387 expectedError: ":UNEXPECTED_RECORD:",
7388 })
7389 testCases = append(testCases, testCase{
7390 testType: serverTest,
7391 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7392 config: Config{
7393 MaxVersion: VersionTLS12,
7394 },
7395 resumeSession: true,
7396 resumeConfig: &Config{
7397 MaxVersion: VersionTLS12,
7398 Bugs: ProtocolBugs{
7399 FragmentAcrossChangeCipherSpec: true,
7400 PackHandshakeFlight: packed,
7401 },
7402 },
7403 shouldFail: true,
7404 expectedError: ":UNEXPECTED_RECORD:",
7405 })
7406 testCases = append(testCases, testCase{
7407 testType: serverTest,
7408 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7409 config: Config{
7410 MaxVersion: VersionTLS12,
7411 NextProtos: []string{"bar"},
7412 Bugs: ProtocolBugs{
7413 FragmentAcrossChangeCipherSpec: true,
7414 PackHandshakeFlight: packed,
7415 },
7416 },
7417 flags: []string{
7418 "-advertise-npn", "\x03foo\x03bar\x03baz",
7419 },
7420 shouldFail: true,
7421 expectedError: ":UNEXPECTED_RECORD:",
7422 })
7423 }
7424
David Benjamin61672812016-07-14 23:10:43 -04007425 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7426 // messages in the handshake queue. Do this by testing the server
7427 // reading the client Finished, reversing the flight so Finished comes
7428 // first.
7429 testCases = append(testCases, testCase{
7430 protocol: dtls,
7431 testType: serverTest,
7432 name: "SendUnencryptedFinished-DTLS",
7433 config: Config{
7434 MaxVersion: VersionTLS12,
7435 Bugs: ProtocolBugs{
7436 SendUnencryptedFinished: true,
7437 ReverseHandshakeFragments: true,
7438 },
7439 },
7440 shouldFail: true,
7441 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7442 })
7443
Steven Valdez143e8b32016-07-11 13:19:03 -04007444 // Test synchronization between encryption changes and the handshake in
7445 // TLS 1.3, where ChangeCipherSpec is implicit.
7446 testCases = append(testCases, testCase{
7447 name: "PartialEncryptedExtensionsWithServerHello",
7448 config: Config{
7449 MaxVersion: VersionTLS13,
7450 Bugs: ProtocolBugs{
7451 PartialEncryptedExtensionsWithServerHello: true,
7452 },
7453 },
7454 shouldFail: true,
7455 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7456 })
7457 testCases = append(testCases, testCase{
7458 testType: serverTest,
7459 name: "PartialClientFinishedWithClientHello",
7460 config: Config{
7461 MaxVersion: VersionTLS13,
7462 Bugs: ProtocolBugs{
7463 PartialClientFinishedWithClientHello: true,
7464 },
7465 },
7466 shouldFail: true,
7467 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7468 })
7469
David Benjamin82261be2016-07-07 14:32:50 -07007470 // Test that early ChangeCipherSpecs are handled correctly.
7471 testCases = append(testCases, testCase{
7472 testType: serverTest,
7473 name: "EarlyChangeCipherSpec-server-1",
7474 config: Config{
7475 MaxVersion: VersionTLS12,
7476 Bugs: ProtocolBugs{
7477 EarlyChangeCipherSpec: 1,
7478 },
7479 },
7480 shouldFail: true,
7481 expectedError: ":UNEXPECTED_RECORD:",
7482 })
7483 testCases = append(testCases, testCase{
7484 testType: serverTest,
7485 name: "EarlyChangeCipherSpec-server-2",
7486 config: Config{
7487 MaxVersion: VersionTLS12,
7488 Bugs: ProtocolBugs{
7489 EarlyChangeCipherSpec: 2,
7490 },
7491 },
7492 shouldFail: true,
7493 expectedError: ":UNEXPECTED_RECORD:",
7494 })
7495 testCases = append(testCases, testCase{
7496 protocol: dtls,
7497 name: "StrayChangeCipherSpec",
7498 config: Config{
7499 // TODO(davidben): Once DTLS 1.3 exists, test
7500 // that stray ChangeCipherSpec messages are
7501 // rejected.
7502 MaxVersion: VersionTLS12,
7503 Bugs: ProtocolBugs{
7504 StrayChangeCipherSpec: true,
7505 },
7506 },
7507 })
7508
7509 // Test that the contents of ChangeCipherSpec are checked.
7510 testCases = append(testCases, testCase{
7511 name: "BadChangeCipherSpec-1",
7512 config: Config{
7513 MaxVersion: VersionTLS12,
7514 Bugs: ProtocolBugs{
7515 BadChangeCipherSpec: []byte{2},
7516 },
7517 },
7518 shouldFail: true,
7519 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7520 })
7521 testCases = append(testCases, testCase{
7522 name: "BadChangeCipherSpec-2",
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 Bugs: ProtocolBugs{
7526 BadChangeCipherSpec: []byte{1, 1},
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7531 })
7532 testCases = append(testCases, testCase{
7533 protocol: dtls,
7534 name: "BadChangeCipherSpec-DTLS-1",
7535 config: Config{
7536 MaxVersion: VersionTLS12,
7537 Bugs: ProtocolBugs{
7538 BadChangeCipherSpec: []byte{2},
7539 },
7540 },
7541 shouldFail: true,
7542 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7543 })
7544 testCases = append(testCases, testCase{
7545 protocol: dtls,
7546 name: "BadChangeCipherSpec-DTLS-2",
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 Bugs: ProtocolBugs{
7550 BadChangeCipherSpec: []byte{1, 1},
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7555 })
7556}
7557
David Benjamincd2c8062016-09-09 11:28:16 -04007558type perMessageTest struct {
7559 messageType uint8
7560 test testCase
7561}
7562
7563// makePerMessageTests returns a series of test templates which cover each
7564// message in the TLS handshake. These may be used with bugs like
7565// WrongMessageType to fully test a per-message bug.
7566func makePerMessageTests() []perMessageTest {
7567 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007568 for _, protocol := range []protocol{tls, dtls} {
7569 var suffix string
7570 if protocol == dtls {
7571 suffix = "-DTLS"
7572 }
7573
David Benjamincd2c8062016-09-09 11:28:16 -04007574 ret = append(ret, perMessageTest{
7575 messageType: typeClientHello,
7576 test: testCase{
7577 protocol: protocol,
7578 testType: serverTest,
7579 name: "ClientHello" + suffix,
7580 config: Config{
7581 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007582 },
7583 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007584 })
7585
7586 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007587 ret = append(ret, perMessageTest{
7588 messageType: typeHelloVerifyRequest,
7589 test: testCase{
7590 protocol: protocol,
7591 name: "HelloVerifyRequest" + suffix,
7592 config: Config{
7593 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007594 },
7595 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007596 })
7597 }
7598
David Benjamincd2c8062016-09-09 11:28:16 -04007599 ret = append(ret, perMessageTest{
7600 messageType: typeServerHello,
7601 test: testCase{
7602 protocol: protocol,
7603 name: "ServerHello" + suffix,
7604 config: Config{
7605 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007606 },
7607 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007608 })
7609
David Benjamincd2c8062016-09-09 11:28:16 -04007610 ret = append(ret, perMessageTest{
7611 messageType: typeCertificate,
7612 test: testCase{
7613 protocol: protocol,
7614 name: "ServerCertificate" + suffix,
7615 config: Config{
7616 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007617 },
7618 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007619 })
7620
David Benjamincd2c8062016-09-09 11:28:16 -04007621 ret = append(ret, perMessageTest{
7622 messageType: typeCertificateStatus,
7623 test: testCase{
7624 protocol: protocol,
7625 name: "CertificateStatus" + suffix,
7626 config: Config{
7627 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007628 },
David Benjamincd2c8062016-09-09 11:28:16 -04007629 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007630 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007631 })
7632
David Benjamincd2c8062016-09-09 11:28:16 -04007633 ret = append(ret, perMessageTest{
7634 messageType: typeServerKeyExchange,
7635 test: testCase{
7636 protocol: protocol,
7637 name: "ServerKeyExchange" + suffix,
7638 config: Config{
7639 MaxVersion: VersionTLS12,
7640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007641 },
7642 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007643 })
7644
David Benjamincd2c8062016-09-09 11:28:16 -04007645 ret = append(ret, perMessageTest{
7646 messageType: typeCertificateRequest,
7647 test: testCase{
7648 protocol: protocol,
7649 name: "CertificateRequest" + suffix,
7650 config: Config{
7651 MaxVersion: VersionTLS12,
7652 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007653 },
7654 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007655 })
7656
David Benjamincd2c8062016-09-09 11:28:16 -04007657 ret = append(ret, perMessageTest{
7658 messageType: typeServerHelloDone,
7659 test: testCase{
7660 protocol: protocol,
7661 name: "ServerHelloDone" + suffix,
7662 config: Config{
7663 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007664 },
7665 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007666 })
7667
David Benjamincd2c8062016-09-09 11:28:16 -04007668 ret = append(ret, perMessageTest{
7669 messageType: typeCertificate,
7670 test: testCase{
7671 testType: serverTest,
7672 protocol: protocol,
7673 name: "ClientCertificate" + suffix,
7674 config: Config{
7675 Certificates: []Certificate{rsaCertificate},
7676 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007677 },
David Benjamincd2c8062016-09-09 11:28:16 -04007678 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007679 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007680 })
7681
David Benjamincd2c8062016-09-09 11:28:16 -04007682 ret = append(ret, perMessageTest{
7683 messageType: typeCertificateVerify,
7684 test: testCase{
7685 testType: serverTest,
7686 protocol: protocol,
7687 name: "CertificateVerify" + suffix,
7688 config: Config{
7689 Certificates: []Certificate{rsaCertificate},
7690 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007691 },
David Benjamincd2c8062016-09-09 11:28:16 -04007692 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007693 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007694 })
7695
David Benjamincd2c8062016-09-09 11:28:16 -04007696 ret = append(ret, perMessageTest{
7697 messageType: typeClientKeyExchange,
7698 test: testCase{
7699 testType: serverTest,
7700 protocol: protocol,
7701 name: "ClientKeyExchange" + suffix,
7702 config: Config{
7703 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007704 },
7705 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007706 })
7707
7708 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007709 ret = append(ret, perMessageTest{
7710 messageType: typeNextProtocol,
7711 test: testCase{
7712 testType: serverTest,
7713 protocol: protocol,
7714 name: "NextProtocol" + suffix,
7715 config: Config{
7716 MaxVersion: VersionTLS12,
7717 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007718 },
David Benjamincd2c8062016-09-09 11:28:16 -04007719 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007720 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007721 })
7722
David Benjamincd2c8062016-09-09 11:28:16 -04007723 ret = append(ret, perMessageTest{
7724 messageType: typeChannelID,
7725 test: testCase{
7726 testType: serverTest,
7727 protocol: protocol,
7728 name: "ChannelID" + suffix,
7729 config: Config{
7730 MaxVersion: VersionTLS12,
7731 ChannelID: channelIDKey,
7732 },
7733 flags: []string{
7734 "-expect-channel-id",
7735 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007736 },
7737 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007738 })
7739 }
7740
David Benjamincd2c8062016-09-09 11:28:16 -04007741 ret = append(ret, perMessageTest{
7742 messageType: typeFinished,
7743 test: testCase{
7744 testType: serverTest,
7745 protocol: protocol,
7746 name: "ClientFinished" + suffix,
7747 config: Config{
7748 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007749 },
7750 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007751 })
7752
David Benjamincd2c8062016-09-09 11:28:16 -04007753 ret = append(ret, perMessageTest{
7754 messageType: typeNewSessionTicket,
7755 test: testCase{
7756 protocol: protocol,
7757 name: "NewSessionTicket" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007760 },
7761 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 })
7763
David Benjamincd2c8062016-09-09 11:28:16 -04007764 ret = append(ret, perMessageTest{
7765 messageType: typeFinished,
7766 test: testCase{
7767 protocol: protocol,
7768 name: "ServerFinished" + suffix,
7769 config: Config{
7770 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007771 },
7772 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007773 })
7774
7775 }
David Benjamincd2c8062016-09-09 11:28:16 -04007776
7777 ret = append(ret, perMessageTest{
7778 messageType: typeClientHello,
7779 test: testCase{
7780 testType: serverTest,
7781 name: "TLS13-ClientHello",
7782 config: Config{
7783 MaxVersion: VersionTLS13,
7784 },
7785 },
7786 })
7787
7788 ret = append(ret, perMessageTest{
7789 messageType: typeServerHello,
7790 test: testCase{
7791 name: "TLS13-ServerHello",
7792 config: Config{
7793 MaxVersion: VersionTLS13,
7794 },
7795 },
7796 })
7797
7798 ret = append(ret, perMessageTest{
7799 messageType: typeEncryptedExtensions,
7800 test: testCase{
7801 name: "TLS13-EncryptedExtensions",
7802 config: Config{
7803 MaxVersion: VersionTLS13,
7804 },
7805 },
7806 })
7807
7808 ret = append(ret, perMessageTest{
7809 messageType: typeCertificateRequest,
7810 test: testCase{
7811 name: "TLS13-CertificateRequest",
7812 config: Config{
7813 MaxVersion: VersionTLS13,
7814 ClientAuth: RequireAnyClientCert,
7815 },
7816 },
7817 })
7818
7819 ret = append(ret, perMessageTest{
7820 messageType: typeCertificate,
7821 test: testCase{
7822 name: "TLS13-ServerCertificate",
7823 config: Config{
7824 MaxVersion: VersionTLS13,
7825 },
7826 },
7827 })
7828
7829 ret = append(ret, perMessageTest{
7830 messageType: typeCertificateVerify,
7831 test: testCase{
7832 name: "TLS13-ServerCertificateVerify",
7833 config: Config{
7834 MaxVersion: VersionTLS13,
7835 },
7836 },
7837 })
7838
7839 ret = append(ret, perMessageTest{
7840 messageType: typeFinished,
7841 test: testCase{
7842 name: "TLS13-ServerFinished",
7843 config: Config{
7844 MaxVersion: VersionTLS13,
7845 },
7846 },
7847 })
7848
7849 ret = append(ret, perMessageTest{
7850 messageType: typeCertificate,
7851 test: testCase{
7852 testType: serverTest,
7853 name: "TLS13-ClientCertificate",
7854 config: Config{
7855 Certificates: []Certificate{rsaCertificate},
7856 MaxVersion: VersionTLS13,
7857 },
7858 flags: []string{"-require-any-client-certificate"},
7859 },
7860 })
7861
7862 ret = append(ret, perMessageTest{
7863 messageType: typeCertificateVerify,
7864 test: testCase{
7865 testType: serverTest,
7866 name: "TLS13-ClientCertificateVerify",
7867 config: Config{
7868 Certificates: []Certificate{rsaCertificate},
7869 MaxVersion: VersionTLS13,
7870 },
7871 flags: []string{"-require-any-client-certificate"},
7872 },
7873 })
7874
7875 ret = append(ret, perMessageTest{
7876 messageType: typeFinished,
7877 test: testCase{
7878 testType: serverTest,
7879 name: "TLS13-ClientFinished",
7880 config: Config{
7881 MaxVersion: VersionTLS13,
7882 },
7883 },
7884 })
7885
7886 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007887}
7888
David Benjamincd2c8062016-09-09 11:28:16 -04007889func addWrongMessageTypeTests() {
7890 for _, t := range makePerMessageTests() {
7891 t.test.name = "WrongMessageType-" + t.test.name
7892 t.test.config.Bugs.SendWrongMessageType = t.messageType
7893 t.test.shouldFail = true
7894 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7895 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007896
David Benjamincd2c8062016-09-09 11:28:16 -04007897 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7898 // In TLS 1.3, a bad ServerHello means the client sends
7899 // an unencrypted alert while the server expects
7900 // encryption, so the alert is not readable by runner.
7901 t.test.expectedLocalError = "local error: bad record MAC"
7902 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007903
David Benjamincd2c8062016-09-09 11:28:16 -04007904 testCases = append(testCases, t.test)
7905 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007906}
7907
David Benjamin639846e2016-09-09 11:41:18 -04007908func addTrailingMessageDataTests() {
7909 for _, t := range makePerMessageTests() {
7910 t.test.name = "TrailingMessageData-" + t.test.name
7911 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7912 t.test.shouldFail = true
7913 t.test.expectedError = ":DECODE_ERROR:"
7914 t.test.expectedLocalError = "remote error: error decoding message"
7915
7916 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7917 // In TLS 1.3, a bad ServerHello means the client sends
7918 // an unencrypted alert while the server expects
7919 // encryption, so the alert is not readable by runner.
7920 t.test.expectedLocalError = "local error: bad record MAC"
7921 }
7922
7923 if t.messageType == typeFinished {
7924 // Bad Finished messages read as the verify data having
7925 // the wrong length.
7926 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7927 t.test.expectedLocalError = "remote error: error decrypting message"
7928 }
7929
7930 testCases = append(testCases, t.test)
7931 }
7932}
7933
Steven Valdez143e8b32016-07-11 13:19:03 -04007934func addTLS13HandshakeTests() {
7935 testCases = append(testCases, testCase{
7936 testType: clientTest,
7937 name: "MissingKeyShare-Client",
7938 config: Config{
7939 MaxVersion: VersionTLS13,
7940 Bugs: ProtocolBugs{
7941 MissingKeyShare: true,
7942 },
7943 },
7944 shouldFail: true,
7945 expectedError: ":MISSING_KEY_SHARE:",
7946 })
7947
7948 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007949 testType: serverTest,
7950 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007951 config: Config{
7952 MaxVersion: VersionTLS13,
7953 Bugs: ProtocolBugs{
7954 MissingKeyShare: true,
7955 },
7956 },
7957 shouldFail: true,
7958 expectedError: ":MISSING_KEY_SHARE:",
7959 })
7960
7961 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007962 testType: serverTest,
7963 name: "DuplicateKeyShares",
7964 config: Config{
7965 MaxVersion: VersionTLS13,
7966 Bugs: ProtocolBugs{
7967 DuplicateKeyShares: true,
7968 },
7969 },
7970 })
7971
7972 testCases = append(testCases, testCase{
7973 testType: clientTest,
7974 name: "EmptyEncryptedExtensions",
7975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 Bugs: ProtocolBugs{
7978 EmptyEncryptedExtensions: true,
7979 },
7980 },
7981 shouldFail: true,
7982 expectedLocalError: "remote error: error decoding message",
7983 })
7984
7985 testCases = append(testCases, testCase{
7986 testType: clientTest,
7987 name: "EncryptedExtensionsWithKeyShare",
7988 config: Config{
7989 MaxVersion: VersionTLS13,
7990 Bugs: ProtocolBugs{
7991 EncryptedExtensionsWithKeyShare: true,
7992 },
7993 },
7994 shouldFail: true,
7995 expectedLocalError: "remote error: unsupported extension",
7996 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007997
7998 testCases = append(testCases, testCase{
7999 testType: serverTest,
8000 name: "SendHelloRetryRequest",
8001 config: Config{
8002 MaxVersion: VersionTLS13,
8003 // Require a HelloRetryRequest for every curve.
8004 DefaultCurves: []CurveID{},
8005 },
8006 expectedCurveID: CurveX25519,
8007 })
8008
8009 testCases = append(testCases, testCase{
8010 testType: serverTest,
8011 name: "SendHelloRetryRequest-2",
8012 config: Config{
8013 MaxVersion: VersionTLS13,
8014 DefaultCurves: []CurveID{CurveP384},
8015 },
8016 // Although the ClientHello did not predict our preferred curve,
8017 // we always select it whether it is predicted or not.
8018 expectedCurveID: CurveX25519,
8019 })
8020
8021 testCases = append(testCases, testCase{
8022 name: "UnknownCurve-HelloRetryRequest",
8023 config: Config{
8024 MaxVersion: VersionTLS13,
8025 // P-384 requires HelloRetryRequest in BoringSSL.
8026 CurvePreferences: []CurveID{CurveP384},
8027 Bugs: ProtocolBugs{
8028 SendHelloRetryRequestCurve: bogusCurve,
8029 },
8030 },
8031 shouldFail: true,
8032 expectedError: ":WRONG_CURVE:",
8033 })
8034
8035 testCases = append(testCases, testCase{
8036 name: "DisabledCurve-HelloRetryRequest",
8037 config: Config{
8038 MaxVersion: VersionTLS13,
8039 CurvePreferences: []CurveID{CurveP256},
8040 Bugs: ProtocolBugs{
8041 IgnorePeerCurvePreferences: true,
8042 },
8043 },
8044 flags: []string{"-p384-only"},
8045 shouldFail: true,
8046 expectedError: ":WRONG_CURVE:",
8047 })
8048
8049 testCases = append(testCases, testCase{
8050 name: "UnnecessaryHelloRetryRequest",
8051 config: Config{
8052 MaxVersion: VersionTLS13,
8053 Bugs: ProtocolBugs{
8054 UnnecessaryHelloRetryRequest: true,
8055 },
8056 },
8057 shouldFail: true,
8058 expectedError: ":WRONG_CURVE:",
8059 })
8060
8061 testCases = append(testCases, testCase{
8062 name: "SecondHelloRetryRequest",
8063 config: Config{
8064 MaxVersion: VersionTLS13,
8065 // P-384 requires HelloRetryRequest in BoringSSL.
8066 CurvePreferences: []CurveID{CurveP384},
8067 Bugs: ProtocolBugs{
8068 SecondHelloRetryRequest: true,
8069 },
8070 },
8071 shouldFail: true,
8072 expectedError: ":UNEXPECTED_MESSAGE:",
8073 })
8074
8075 testCases = append(testCases, testCase{
8076 testType: serverTest,
8077 name: "SecondClientHelloMissingKeyShare",
8078 config: Config{
8079 MaxVersion: VersionTLS13,
8080 DefaultCurves: []CurveID{},
8081 Bugs: ProtocolBugs{
8082 SecondClientHelloMissingKeyShare: true,
8083 },
8084 },
8085 shouldFail: true,
8086 expectedError: ":MISSING_KEY_SHARE:",
8087 })
8088
8089 testCases = append(testCases, testCase{
8090 testType: serverTest,
8091 name: "SecondClientHelloWrongCurve",
8092 config: Config{
8093 MaxVersion: VersionTLS13,
8094 DefaultCurves: []CurveID{},
8095 Bugs: ProtocolBugs{
8096 MisinterpretHelloRetryRequestCurve: CurveP521,
8097 },
8098 },
8099 shouldFail: true,
8100 expectedError: ":WRONG_CURVE:",
8101 })
8102
8103 testCases = append(testCases, testCase{
8104 name: "HelloRetryRequestVersionMismatch",
8105 config: Config{
8106 MaxVersion: VersionTLS13,
8107 // P-384 requires HelloRetryRequest in BoringSSL.
8108 CurvePreferences: []CurveID{CurveP384},
8109 Bugs: ProtocolBugs{
8110 SendServerHelloVersion: 0x0305,
8111 },
8112 },
8113 shouldFail: true,
8114 expectedError: ":WRONG_VERSION_NUMBER:",
8115 })
8116
8117 testCases = append(testCases, testCase{
8118 name: "HelloRetryRequestCurveMismatch",
8119 config: Config{
8120 MaxVersion: VersionTLS13,
8121 // P-384 requires HelloRetryRequest in BoringSSL.
8122 CurvePreferences: []CurveID{CurveP384},
8123 Bugs: ProtocolBugs{
8124 // Send P-384 (correct) in the HelloRetryRequest.
8125 SendHelloRetryRequestCurve: CurveP384,
8126 // But send P-256 in the ServerHello.
8127 SendCurve: CurveP256,
8128 },
8129 },
8130 shouldFail: true,
8131 expectedError: ":WRONG_CURVE:",
8132 })
8133
8134 // Test the server selecting a curve that requires a HelloRetryRequest
8135 // without sending it.
8136 testCases = append(testCases, testCase{
8137 name: "SkipHelloRetryRequest",
8138 config: Config{
8139 MaxVersion: VersionTLS13,
8140 // P-384 requires HelloRetryRequest in BoringSSL.
8141 CurvePreferences: []CurveID{CurveP384},
8142 Bugs: ProtocolBugs{
8143 SkipHelloRetryRequest: true,
8144 },
8145 },
8146 shouldFail: true,
8147 expectedError: ":WRONG_CURVE:",
8148 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008149
8150 testCases = append(testCases, testCase{
8151 name: "TLS13-RequestContextInHandshake",
8152 config: Config{
8153 MaxVersion: VersionTLS13,
8154 MinVersion: VersionTLS13,
8155 ClientAuth: RequireAnyClientCert,
8156 Bugs: ProtocolBugs{
8157 SendRequestContext: []byte("request context"),
8158 },
8159 },
8160 flags: []string{
8161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8163 },
8164 shouldFail: true,
8165 expectedError: ":DECODE_ERROR:",
8166 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008167}
8168
Adam Langley7c803a62015-06-15 15:35:05 -07008169func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008170 defer wg.Done()
8171
8172 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008173 var err error
8174
8175 if *mallocTest < 0 {
8176 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008177 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008178 } else {
8179 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8180 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008181 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008182 if err != nil {
8183 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8184 }
8185 break
8186 }
8187 }
8188 }
Adam Langley95c29f32014-06-20 12:00:00 -07008189 statusChan <- statusMsg{test: test, err: err}
8190 }
8191}
8192
8193type statusMsg struct {
8194 test *testCase
8195 started bool
8196 err error
8197}
8198
David Benjamin5f237bc2015-02-11 17:14:15 -05008199func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008200 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008201
David Benjamin5f237bc2015-02-11 17:14:15 -05008202 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008203 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008204 if !*pipe {
8205 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008206 var erase string
8207 for i := 0; i < lineLen; i++ {
8208 erase += "\b \b"
8209 }
8210 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008211 }
8212
Adam Langley95c29f32014-06-20 12:00:00 -07008213 if msg.started {
8214 started++
8215 } else {
8216 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008217
8218 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008219 if msg.err == errUnimplemented {
8220 if *pipe {
8221 // Print each test instead of a status line.
8222 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8223 }
8224 unimplemented++
8225 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8226 } else {
8227 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8228 failed++
8229 testOutput.addResult(msg.test.name, "FAIL")
8230 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008231 } else {
8232 if *pipe {
8233 // Print each test instead of a status line.
8234 fmt.Printf("PASSED (%s)\n", msg.test.name)
8235 }
8236 testOutput.addResult(msg.test.name, "PASS")
8237 }
Adam Langley95c29f32014-06-20 12:00:00 -07008238 }
8239
David Benjamin5f237bc2015-02-11 17:14:15 -05008240 if !*pipe {
8241 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008242 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008243 lineLen = len(line)
8244 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008245 }
Adam Langley95c29f32014-06-20 12:00:00 -07008246 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008247
8248 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008249}
8250
8251func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008252 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008253 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008254 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008255
Adam Langley7c803a62015-06-15 15:35:05 -07008256 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008257 addCipherSuiteTests()
8258 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008259 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008260 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008261 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008262 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008263 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008264 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008265 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008266 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008267 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008268 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008269 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008270 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008271 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008272 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008273 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008274 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008275 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008276 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008277 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008278 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008279 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008280 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008281 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008282 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008283 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008284 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008285
8286 var wg sync.WaitGroup
8287
Adam Langley7c803a62015-06-15 15:35:05 -07008288 statusChan := make(chan statusMsg, *numWorkers)
8289 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008290 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008291
EKRf71d7ed2016-08-06 13:25:12 -07008292 if len(*shimConfigFile) != 0 {
8293 encoded, err := ioutil.ReadFile(*shimConfigFile)
8294 if err != nil {
8295 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8296 os.Exit(1)
8297 }
8298
8299 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8300 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8301 os.Exit(1)
8302 }
8303 }
8304
David Benjamin025b3d32014-07-01 19:53:04 -04008305 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008306
Adam Langley7c803a62015-06-15 15:35:05 -07008307 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008308 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008309 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008310 }
8311
David Benjamin270f0a72016-03-17 14:41:36 -04008312 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008313 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008314 matched := true
8315 if len(*testToRun) != 0 {
8316 var err error
8317 matched, err = filepath.Match(*testToRun, testCases[i].name)
8318 if err != nil {
8319 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8320 os.Exit(1)
8321 }
8322 }
8323
EKRf71d7ed2016-08-06 13:25:12 -07008324 if !*includeDisabled {
8325 for pattern := range shimConfig.DisabledTests {
8326 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8327 if err != nil {
8328 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8329 os.Exit(1)
8330 }
8331
8332 if isDisabled {
8333 matched = false
8334 break
8335 }
8336 }
8337 }
8338
David Benjamin17e12922016-07-28 18:04:43 -04008339 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008340 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008341 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008342 }
8343 }
David Benjamin17e12922016-07-28 18:04:43 -04008344
David Benjamin270f0a72016-03-17 14:41:36 -04008345 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008346 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008347 os.Exit(1)
8348 }
Adam Langley95c29f32014-06-20 12:00:00 -07008349
8350 close(testChan)
8351 wg.Wait()
8352 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008353 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008354
8355 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008356
8357 if *jsonOutput != "" {
8358 if err := testOutput.writeTo(*jsonOutput); err != nil {
8359 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8360 }
8361 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008362
EKR842ae6c2016-07-27 09:22:05 +02008363 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8364 os.Exit(1)
8365 }
8366
8367 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008368 os.Exit(1)
8369 }
Adam Langley95c29f32014-06-20 12:00:00 -07008370}