blob: 0523042dc9b578c6eebb7c414cafa70e30a64f86 [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 {
727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400729 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700730 }
David Benjamin325b5c32014-07-01 19:40:31 -0400731 valgrindArgs = append(valgrindArgs, path)
732 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700733
David Benjamin325b5c32014-07-01 19:40:31 -0400734 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700735}
736
David Benjamin325b5c32014-07-01 19:40:31 -0400737func gdbOf(path string, args ...string) *exec.Cmd {
738 xtermArgs := []string{"-e", "gdb", "--args"}
739 xtermArgs = append(xtermArgs, path)
740 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700741
David Benjamin325b5c32014-07-01 19:40:31 -0400742 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700743}
744
David Benjamind16bf342015-12-18 00:53:12 -0500745func lldbOf(path string, args ...string) *exec.Cmd {
746 xtermArgs := []string{"-e", "lldb", "--"}
747 xtermArgs = append(xtermArgs, path)
748 xtermArgs = append(xtermArgs, args...)
749
750 return exec.Command("xterm", xtermArgs...)
751}
752
EKR842ae6c2016-07-27 09:22:05 +0200753var (
754 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
755 errUnimplemented = errors.New("child process does not implement needed flags")
756)
Adam Langley69a01602014-11-17 17:26:55 -0800757
David Benjamin87c8a642015-02-21 01:54:29 -0500758// accept accepts a connection from listener, unless waitChan signals a process
759// exit first.
760func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
761 type connOrError struct {
762 conn net.Conn
763 err error
764 }
765 connChan := make(chan connOrError, 1)
766 go func() {
767 conn, err := listener.Accept()
768 connChan <- connOrError{conn, err}
769 close(connChan)
770 }()
771 select {
772 case result := <-connChan:
773 return result.conn, result.err
774 case childErr := <-waitChan:
775 waitChan <- childErr
776 return nil, fmt.Errorf("child exited early: %s", childErr)
777 }
778}
779
EKRf71d7ed2016-08-06 13:25:12 -0700780func translateExpectedError(errorStr string) string {
781 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
782 return translated
783 }
784
785 if *looseErrors {
786 return ""
787 }
788
789 return errorStr
790}
791
Adam Langley7c803a62015-06-15 15:35:05 -0700792func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700793 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
794 panic("Error expected without shouldFail in " + test.name)
795 }
796
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700797 if test.expectResumeRejected && !test.resumeSession {
798 panic("expectResumeRejected without resumeSession in " + test.name)
799 }
800
David Benjamin87c8a642015-02-21 01:54:29 -0500801 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
802 if err != nil {
803 panic(err)
804 }
805 defer func() {
806 if listener != nil {
807 listener.Close()
808 }
809 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700810
David Benjamin87c8a642015-02-21 01:54:29 -0500811 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400812 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400813 flags = append(flags, "-server")
814
David Benjamin025b3d32014-07-01 19:53:04 -0400815 flags = append(flags, "-key-file")
816 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700817 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400818 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700819 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400820 }
821
822 flags = append(flags, "-cert-file")
823 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828 }
David Benjamin5a593af2014-08-11 19:51:50 -0400829
David Benjamin6fd297b2014-08-11 18:43:38 -0400830 if test.protocol == dtls {
831 flags = append(flags, "-dtls")
832 }
833
David 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
Adam Langley69a01602014-11-17 17:26:55 -0800940 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200941 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
942 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800943 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200944 case 89:
945 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjaminc565ebb2015-04-03 04:06:36 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjaminff3a1492016-03-02 10:12:06 -0500994 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
998 return nil
999}
1000
1001var tlsVersions = []struct {
1002 name string
1003 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001004 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001005 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001006}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001007 {"SSL3", VersionSSL30, "-no-ssl3", false},
1008 {"TLS1", VersionTLS10, "-no-tls1", true},
1009 {"TLS11", VersionTLS11, "-no-tls11", false},
1010 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001011 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001012}
1013
1014var testCipherSuites = []struct {
1015 name string
1016 id uint16
1017}{
1018 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001019 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001020 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001021 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001022 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001023 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001024 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001025 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1026 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001027 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001028 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1029 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001031 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1032 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1034 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001036 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001038 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001040 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001046 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001047 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1048 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1049 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1050 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001051 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1052 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001053 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1054 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001055 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001056 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1057 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001058 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001059}
1060
David Benjamin8b8c0062014-11-23 02:47:52 -05001061func hasComponent(suiteName, component string) bool {
1062 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1063}
1064
David Benjaminf7768e42014-08-31 02:06:47 -04001065func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001066 return hasComponent(suiteName, "GCM") ||
1067 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001068 hasComponent(suiteName, "SHA384") ||
1069 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001070}
1071
Nick Harper1fd39d82016-06-14 18:14:35 -07001072func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001073 // Only AEADs.
1074 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1075 return false
1076 }
1077 // No old CHACHA20_POLY1305.
1078 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1079 return false
1080 }
1081 // Must have ECDHE.
1082 // TODO(davidben,svaldez): Add pure PSK support.
1083 if !hasComponent(suiteName, "ECDHE") {
1084 return false
1085 }
1086 // TODO(davidben,svaldez): Add PSK support.
1087 if hasComponent(suiteName, "PSK") {
1088 return false
1089 }
1090 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001091}
1092
David Benjamin8b8c0062014-11-23 02:47:52 -05001093func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001094 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001095}
1096
Adam Langleya7997f12015-05-14 17:38:50 -07001097func bigFromHex(hex string) *big.Int {
1098 ret, ok := new(big.Int).SetString(hex, 16)
1099 if !ok {
1100 panic("failed to parse hex number 0x" + hex)
1101 }
1102 return ret
1103}
1104
Adam Langley7c803a62015-06-15 15:35:05 -07001105func addBasicTests() {
1106 basicTests := []testCase{
1107 {
Adam Langley7c803a62015-06-15 15:35:05 -07001108 name: "NoFallbackSCSV",
1109 config: Config{
1110 Bugs: ProtocolBugs{
1111 FailIfNotFallbackSCSV: true,
1112 },
1113 },
1114 shouldFail: true,
1115 expectedLocalError: "no fallback SCSV found",
1116 },
1117 {
1118 name: "SendFallbackSCSV",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 FailIfNotFallbackSCSV: true,
1122 },
1123 },
1124 flags: []string{"-fallback-scsv"},
1125 },
1126 {
1127 name: "ClientCertificateTypes",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 ClientAuth: RequestClientCert,
1131 ClientCertificateTypes: []byte{
1132 CertTypeDSSSign,
1133 CertTypeRSASign,
1134 CertTypeECDSASign,
1135 },
1136 },
1137 flags: []string{
1138 "-expect-certificate-types",
1139 base64.StdEncoding.EncodeToString([]byte{
1140 CertTypeDSSSign,
1141 CertTypeRSASign,
1142 CertTypeECDSASign,
1143 }),
1144 },
1145 },
1146 {
Adam Langley7c803a62015-06-15 15:35:05 -07001147 name: "UnauthenticatedECDH",
1148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001149 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1151 Bugs: ProtocolBugs{
1152 UnauthenticatedECDH: true,
1153 },
1154 },
1155 shouldFail: true,
1156 expectedError: ":UNEXPECTED_MESSAGE:",
1157 },
1158 {
1159 name: "SkipCertificateStatus",
1160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1163 Bugs: ProtocolBugs{
1164 SkipCertificateStatus: true,
1165 },
1166 },
1167 flags: []string{
1168 "-enable-ocsp-stapling",
1169 },
1170 },
1171 {
1172 name: "SkipServerKeyExchange",
1173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1176 Bugs: ProtocolBugs{
1177 SkipServerKeyExchange: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedError: ":UNEXPECTED_MESSAGE:",
1182 },
1183 {
Adam Langley7c803a62015-06-15 15:35:05 -07001184 testType: serverTest,
1185 name: "Alert",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "Alert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendSpuriousAlert: alertRecordOverflow,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1205 },
1206 {
1207 testType: serverTest,
1208 name: "FragmentAlert",
1209 config: Config{
1210 Bugs: ProtocolBugs{
1211 FragmentAlert: true,
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":BAD_ALERT:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "FragmentAlert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 FragmentAlert: true,
1225 SendSpuriousAlert: alertRecordOverflow,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":BAD_ALERT:",
1230 },
1231 {
1232 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001233 name: "DoubleAlert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 DoubleAlert: true,
1237 SendSpuriousAlert: alertRecordOverflow,
1238 },
1239 },
1240 shouldFail: true,
1241 expectedError: ":BAD_ALERT:",
1242 },
1243 {
1244 protocol: dtls,
1245 testType: serverTest,
1246 name: "DoubleAlert-DTLS",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 DoubleAlert: true,
1250 SendSpuriousAlert: alertRecordOverflow,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":BAD_ALERT:",
1255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "SkipNewSessionTicket",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 Bugs: ProtocolBugs{
1261 SkipNewSessionTicket: true,
1262 },
1263 },
1264 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001265 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001266 },
1267 {
1268 testType: serverTest,
1269 name: "FallbackSCSV",
1270 config: Config{
1271 MaxVersion: VersionTLS11,
1272 Bugs: ProtocolBugs{
1273 SendFallbackSCSV: true,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":INAPPROPRIATE_FALLBACK:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "FallbackSCSV-VersionMatch",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 },
1288 {
1289 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 name: "FallbackSCSV-VersionMatch-TLS12",
1291 config: Config{
1292 MaxVersion: VersionTLS12,
1293 Bugs: ProtocolBugs{
1294 SendFallbackSCSV: true,
1295 },
1296 },
1297 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1298 },
1299 {
1300 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001308 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 testType: serverTest,
1312 name: "HttpGET",
1313 sendPrefix: "GET / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpPOST",
1320 sendPrefix: "POST / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpHEAD",
1327 sendPrefix: "HEAD / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpPUT",
1334 sendPrefix: "PUT / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpCONNECT",
1341 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTPS_PROXY_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "Garbage",
1348 sendPrefix: "blah",
1349 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001350 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 name: "RSAEphemeralKey",
1354 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001355 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1357 Bugs: ProtocolBugs{
1358 RSAEphemeralKey: true,
1359 },
1360 },
1361 shouldFail: true,
1362 expectedError: ":UNEXPECTED_MESSAGE:",
1363 },
1364 {
1365 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001366 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
1371 protocol: dtls,
1372 name: "DisableEverything-DTLS",
1373 flags: []string{"-no-tls12", "-no-tls1"},
1374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
Adam Langley7c803a62015-06-15 15:35:05 -07001378 protocol: dtls,
1379 testType: serverTest,
1380 name: "MTU",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 MaxPacketLength: 256,
1384 },
1385 },
1386 flags: []string{"-mtu", "256"},
1387 },
1388 {
1389 protocol: dtls,
1390 testType: serverTest,
1391 name: "MTUExceeded",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 MaxPacketLength: 255,
1395 },
1396 },
1397 flags: []string{"-mtu", "256"},
1398 shouldFail: true,
1399 expectedLocalError: "dtls: exceeded maximum packet length",
1400 },
1401 {
1402 name: "CertMismatchRSA",
1403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001406 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 Bugs: ProtocolBugs{
1408 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1413 },
1414 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001415 name: "CertMismatchRSA-TLS13",
1416 config: Config{
1417 MaxVersion: VersionTLS13,
1418 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1419 Certificates: []Certificate{ecdsaP256Certificate},
1420 Bugs: ProtocolBugs{
1421 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1422 },
1423 },
1424 shouldFail: true,
1425 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1426 },
1427 {
Adam Langley7c803a62015-06-15 15:35:05 -07001428 name: "CertMismatchECDSA",
1429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001432 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001433 Bugs: ProtocolBugs{
1434 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1439 },
1440 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001441 name: "CertMismatchECDSA-TLS13",
1442 config: Config{
1443 MaxVersion: VersionTLS13,
1444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Certificates: []Certificate{rsaCertificate},
1446 Bugs: ProtocolBugs{
1447 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1452 },
1453 {
Adam Langley7c803a62015-06-15 15:35:05 -07001454 name: "EmptyCertificateList",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 EmptyCertificateList: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":DECODE_ERROR:",
1464 },
1465 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 name: "EmptyCertificateList-TLS13",
1467 config: Config{
1468 MaxVersion: VersionTLS13,
1469 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1470 Bugs: ProtocolBugs{
1471 EmptyCertificateList: true,
1472 },
1473 },
1474 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001476 },
1477 {
Adam Langley7c803a62015-06-15 15:35:05 -07001478 name: "TLSFatalBadPackets",
1479 damageFirstWrite: true,
1480 shouldFail: true,
1481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets",
1486 damageFirstWrite: true,
1487 },
1488 {
1489 protocol: dtls,
1490 name: "DTLSIgnoreBadPackets-Async",
1491 damageFirstWrite: true,
1492 flags: []string{"-async"},
1493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataBeforeHandshake",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
1505 name: "AppDataBeforeHandshake-Empty",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 AppDataBeforeHandshake: []byte{},
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AppDataBeforeHandshake-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 protocol: dtls,
1527 name: "AppDataBeforeHandshake-DTLS-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
Adam Langley7c803a62015-06-15 15:35:05 -07001537 name: "AppDataAfterChangeCipherSpec",
1538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001539 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001540 Bugs: ProtocolBugs{
1541 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001545 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001546 },
1547 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 name: "AppDataAfterChangeCipherSpec-Empty",
1549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001550 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001551 Bugs: ProtocolBugs{
1552 AppDataAfterChangeCipherSpec: []byte{},
1553 },
1554 },
1555 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001556 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 name: "AppDataAfterChangeCipherSpec-DTLS",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1565 },
1566 },
1567 // BoringSSL's DTLS implementation will drop the out-of-order
1568 // application data.
1569 },
1570 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte{},
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "AlertAfterChangeCipherSpec",
1584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 AlertAfterChangeCipherSpec: alertRecordOverflow,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1592 },
1593 {
1594 protocol: dtls,
1595 name: "AlertAfterChangeCipherSpec-DTLS",
1596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 Bugs: ProtocolBugs{
1599 AlertAfterChangeCipherSpec: alertRecordOverflow,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "ReorderHandshakeFragments-Small-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 ReorderHandshakeFragments: true,
1611 // Small enough that every handshake message is
1612 // fragmented.
1613 MaxHandshakeRecordLength: 2,
1614 },
1615 },
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Large-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Large enough that no handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2048,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "MixCompleteMessageWithFragments-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 MixCompleteMessageWithFragments: true,
1636 MaxHandshakeRecordLength: 2,
1637 },
1638 },
1639 },
1640 {
1641 name: "SendInvalidRecordType",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "SendInvalidRecordType-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 SendInvalidRecordType: true,
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
1662 name: "FalseStart-SkipServerSecondLeg",
1663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 SkipNewSessionTicket: true,
1669 SkipChangeCipherSpec: true,
1670 SkipFinished: true,
1671 ExpectFalseStart: true,
1672 },
1673 },
1674 flags: []string{
1675 "-false-start",
1676 "-handshake-never-done",
1677 "-advertise-alpn", "\x03foo",
1678 },
1679 shimWritesFirst: true,
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg-Implicit",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 },
1694 },
1695 flags: []string{
1696 "-implicit-handshake",
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shouldFail: true,
1702 expectedError: ":UNEXPECTED_RECORD:",
1703 },
1704 {
1705 testType: serverTest,
1706 name: "FailEarlyCallback",
1707 flags: []string{"-fail-early-callback"},
1708 shouldFail: true,
1709 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001710 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001711 },
1712 {
Adam Langley7c803a62015-06-15 15:35:05 -07001713 protocol: dtls,
1714 name: "FragmentMessageTypeMismatch-DTLS",
1715 config: Config{
1716 Bugs: ProtocolBugs{
1717 MaxHandshakeRecordLength: 2,
1718 FragmentMessageTypeMismatch: true,
1719 },
1720 },
1721 shouldFail: true,
1722 expectedError: ":FRAGMENT_MISMATCH:",
1723 },
1724 {
1725 protocol: dtls,
1726 name: "FragmentMessageLengthMismatch-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 MaxHandshakeRecordLength: 2,
1730 FragmentMessageLengthMismatch: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":FRAGMENT_MISMATCH:",
1735 },
1736 {
1737 protocol: dtls,
1738 name: "SplitFragments-Header-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 SplitFragments: 2,
1742 },
1743 },
1744 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001745 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001746 },
1747 {
1748 protocol: dtls,
1749 name: "SplitFragments-Boundary-DTLS",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 SplitFragments: dtlsRecordHeaderLen,
1753 },
1754 },
1755 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001756 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001757 },
1758 {
1759 protocol: dtls,
1760 name: "SplitFragments-Body-DTLS",
1761 config: Config{
1762 Bugs: ProtocolBugs{
1763 SplitFragments: dtlsRecordHeaderLen + 1,
1764 },
1765 },
1766 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001767 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 {
1770 protocol: dtls,
1771 name: "SendEmptyFragments-DTLS",
1772 config: Config{
1773 Bugs: ProtocolBugs{
1774 SendEmptyFragments: true,
1775 },
1776 },
1777 },
1778 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001779 name: "BadFinished-Client",
1780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001781 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 Bugs: ProtocolBugs{
1783 BadFinished: true,
1784 },
1785 },
1786 shouldFail: true,
1787 expectedError: ":DIGEST_CHECK_FAILED:",
1788 },
1789 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001790 name: "BadFinished-Client-TLS13",
1791 config: Config{
1792 MaxVersion: VersionTLS13,
1793 Bugs: ProtocolBugs{
1794 BadFinished: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":DIGEST_CHECK_FAILED:",
1799 },
1800 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001801 testType: serverTest,
1802 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 BadFinished: true,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":DIGEST_CHECK_FAILED:",
1811 },
1812 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001813 testType: serverTest,
1814 name: "BadFinished-Server-TLS13",
1815 config: Config{
1816 MaxVersion: VersionTLS13,
1817 Bugs: ProtocolBugs{
1818 BadFinished: true,
1819 },
1820 },
1821 shouldFail: true,
1822 expectedError: ":DIGEST_CHECK_FAILED:",
1823 },
1824 {
Adam Langley7c803a62015-06-15 15:35:05 -07001825 name: "FalseStart-BadFinished",
1826 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001827 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1829 NextProtos: []string{"foo"},
1830 Bugs: ProtocolBugs{
1831 BadFinished: true,
1832 ExpectFalseStart: true,
1833 },
1834 },
1835 flags: []string{
1836 "-false-start",
1837 "-handshake-never-done",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
1845 name: "NoFalseStart-NoALPN",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1849 Bugs: ProtocolBugs{
1850 ExpectFalseStart: true,
1851 AlertBeforeFalseStartTest: alertAccessDenied,
1852 },
1853 },
1854 flags: []string{
1855 "-false-start",
1856 },
1857 shimWritesFirst: true,
1858 shouldFail: true,
1859 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1860 expectedLocalError: "tls: peer did not false start: EOF",
1861 },
1862 {
1863 name: "NoFalseStart-NoAEAD",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 ExpectFalseStart: true,
1870 AlertBeforeFalseStartTest: alertAccessDenied,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-advertise-alpn", "\x03foo",
1876 },
1877 shimWritesFirst: true,
1878 shouldFail: true,
1879 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1880 expectedLocalError: "tls: peer did not false start: EOF",
1881 },
1882 {
1883 name: "NoFalseStart-RSA",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1887 NextProtos: []string{"foo"},
1888 Bugs: ProtocolBugs{
1889 ExpectFalseStart: true,
1890 AlertBeforeFalseStartTest: alertAccessDenied,
1891 },
1892 },
1893 flags: []string{
1894 "-false-start",
1895 "-advertise-alpn", "\x03foo",
1896 },
1897 shimWritesFirst: true,
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1900 expectedLocalError: "tls: peer did not false start: EOF",
1901 },
1902 {
1903 name: "NoFalseStart-DHE_RSA",
1904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001905 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001906 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1907 NextProtos: []string{"foo"},
1908 Bugs: ProtocolBugs{
1909 ExpectFalseStart: true,
1910 AlertBeforeFalseStartTest: alertAccessDenied,
1911 },
1912 },
1913 flags: []string{
1914 "-false-start",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1920 expectedLocalError: "tls: peer did not false start: EOF",
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 protocol: dtls,
1924 name: "SendSplitAlert-Sync",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 SendSplitAlert: true,
1928 },
1929 },
1930 },
1931 {
1932 protocol: dtls,
1933 name: "SendSplitAlert-Async",
1934 config: Config{
1935 Bugs: ProtocolBugs{
1936 SendSplitAlert: true,
1937 },
1938 },
1939 flags: []string{"-async"},
1940 },
1941 {
1942 protocol: dtls,
1943 name: "PackDTLSHandshake",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 MaxHandshakeRecordLength: 2,
1947 PackHandshakeFragments: 20,
1948 PackHandshakeRecords: 200,
1949 },
1950 },
1951 },
1952 {
Adam Langley7c803a62015-06-15 15:35:05 -07001953 name: "SendEmptyRecords-Pass",
1954 sendEmptyRecords: 32,
1955 },
1956 {
1957 name: "SendEmptyRecords",
1958 sendEmptyRecords: 33,
1959 shouldFail: true,
1960 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1961 },
1962 {
1963 name: "SendEmptyRecords-Async",
1964 sendEmptyRecords: 33,
1965 flags: []string{"-async"},
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
David Benjamine8e84b92016-08-03 15:39:47 -04001970 name: "SendWarningAlerts-Pass",
1971 config: Config{
1972 MaxVersion: VersionTLS12,
1973 },
Adam Langley7c803a62015-06-15 15:35:05 -07001974 sendWarningAlerts: 4,
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 protocol: dtls,
1978 name: "SendWarningAlerts-DTLS-Pass",
1979 config: Config{
1980 MaxVersion: VersionTLS12,
1981 },
Adam Langley7c803a62015-06-15 15:35:05 -07001982 sendWarningAlerts: 4,
1983 },
1984 {
David Benjamine8e84b92016-08-03 15:39:47 -04001985 name: "SendWarningAlerts-TLS13",
1986 config: Config{
1987 MaxVersion: VersionTLS13,
1988 },
1989 sendWarningAlerts: 4,
1990 shouldFail: true,
1991 expectedError: ":BAD_ALERT:",
1992 expectedLocalError: "remote error: error decoding message",
1993 },
1994 {
1995 name: "SendWarningAlerts",
1996 config: Config{
1997 MaxVersion: VersionTLS12,
1998 },
Adam Langley7c803a62015-06-15 15:35:05 -07001999 sendWarningAlerts: 5,
2000 shouldFail: true,
2001 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2002 },
2003 {
David Benjamine8e84b92016-08-03 15:39:47 -04002004 name: "SendWarningAlerts-Async",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
Adam Langley7c803a62015-06-15 15:35:05 -07002008 sendWarningAlerts: 5,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2012 },
David Benjaminba4594a2015-06-18 18:36:15 -04002013 {
Steven Valdez32635b82016-08-16 11:25:03 -04002014 name: "SendKeyUpdates",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 },
2018 sendKeyUpdates: 33,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_KEY_UPDATES:",
2021 },
2022 {
David Benjaminba4594a2015-06-18 18:36:15 -04002023 name: "EmptySessionID",
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002026 SessionTicketsDisabled: true,
2027 },
2028 noSessionCache: true,
2029 flags: []string{"-expect-no-session"},
2030 },
David Benjamin30789da2015-08-29 22:56:45 -04002031 {
2032 name: "Unclean-Shutdown",
2033 config: Config{
2034 Bugs: ProtocolBugs{
2035 NoCloseNotify: true,
2036 ExpectCloseNotify: true,
2037 },
2038 },
2039 shimShutsDown: true,
2040 flags: []string{"-check-close-notify"},
2041 shouldFail: true,
2042 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2043 },
2044 {
2045 name: "Unclean-Shutdown-Ignored",
2046 config: Config{
2047 Bugs: ProtocolBugs{
2048 NoCloseNotify: true,
2049 },
2050 },
2051 shimShutsDown: true,
2052 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002053 {
David Benjaminfa214e42016-05-10 17:03:10 -04002054 name: "Unclean-Shutdown-Alert",
2055 config: Config{
2056 Bugs: ProtocolBugs{
2057 SendAlertOnShutdown: alertDecompressionFailure,
2058 ExpectCloseNotify: true,
2059 },
2060 },
2061 shimShutsDown: true,
2062 flags: []string{"-check-close-notify"},
2063 shouldFail: true,
2064 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2065 },
2066 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002067 name: "LargePlaintext",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 SendLargeRecords: true,
2071 },
2072 },
2073 messageLen: maxPlaintext + 1,
2074 shouldFail: true,
2075 expectedError: ":DATA_LENGTH_TOO_LONG:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "LargePlaintext-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SendLargeRecords: true,
2083 },
2084 },
2085 messageLen: maxPlaintext + 1,
2086 shouldFail: true,
2087 expectedError: ":DATA_LENGTH_TOO_LONG:",
2088 },
2089 {
2090 name: "LargeCiphertext",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SendLargeRecords: true,
2094 },
2095 },
2096 messageLen: maxPlaintext * 2,
2097 shouldFail: true,
2098 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2099 },
2100 {
2101 protocol: dtls,
2102 name: "LargeCiphertext-DTLS",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendLargeRecords: true,
2106 },
2107 },
2108 messageLen: maxPlaintext * 2,
2109 // Unlike the other four cases, DTLS drops records which
2110 // are invalid before authentication, so the connection
2111 // does not fail.
2112 expectMessageDropped: true,
2113 },
David Benjamindd6fed92015-10-23 17:41:12 -04002114 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 // In TLS 1.2 and below, empty NewSessionTicket messages
2116 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002117 name: "SendEmptySessionTicket",
2118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002120 Bugs: ProtocolBugs{
2121 SendEmptySessionTicket: true,
2122 FailIfSessionOffered: true,
2123 },
2124 },
David Benjamin46662482016-08-17 00:51:00 -04002125 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002126 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002127 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002128 name: "BadHelloRequest-1",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002141 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002142 },
2143 {
2144 name: "BadHelloRequest-2",
2145 renegotiate: 1,
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002148 Bugs: ProtocolBugs{
2149 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2150 },
2151 },
2152 flags: []string{
2153 "-renegotiate-freely",
2154 "-expect-total-renegotiations", "1",
2155 },
2156 shouldFail: true,
2157 expectedError: ":BAD_HELLO_REQUEST:",
2158 },
David Benjaminef1b0092015-11-21 14:05:44 -05002159 {
2160 testType: serverTest,
2161 name: "SupportTicketsWithSessionID",
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002164 SessionTicketsDisabled: true,
2165 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002166 resumeConfig: &Config{
2167 MaxVersion: VersionTLS12,
2168 },
David Benjaminef1b0092015-11-21 14:05:44 -05002169 resumeSession: true,
2170 },
David Benjamin02edcd02016-07-27 17:40:37 -04002171 {
2172 protocol: dtls,
2173 name: "DTLS-SendExtraFinished",
2174 config: Config{
2175 Bugs: ProtocolBugs{
2176 SendExtraFinished: true,
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":UNEXPECTED_RECORD:",
2181 },
2182 {
2183 protocol: dtls,
2184 name: "DTLS-SendExtraFinished-Reordered",
2185 config: Config{
2186 Bugs: ProtocolBugs{
2187 MaxHandshakeRecordLength: 2,
2188 ReorderHandshakeFragments: true,
2189 SendExtraFinished: true,
2190 },
2191 },
2192 shouldFail: true,
2193 expectedError: ":UNEXPECTED_RECORD:",
2194 },
David Benjamine97fb482016-07-29 09:23:07 -04002195 {
2196 testType: serverTest,
2197 name: "V2ClientHello-EmptyRecordPrefix",
2198 config: Config{
2199 // Choose a cipher suite that does not involve
2200 // elliptic curves, so no extensions are
2201 // involved.
2202 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002203 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002204 Bugs: ProtocolBugs{
2205 SendV2ClientHello: true,
2206 },
2207 },
2208 sendPrefix: string([]byte{
2209 byte(recordTypeHandshake),
2210 3, 1, // version
2211 0, 0, // length
2212 }),
2213 // A no-op empty record may not be sent before V2ClientHello.
2214 shouldFail: true,
2215 expectedError: ":WRONG_VERSION_NUMBER:",
2216 },
2217 {
2218 testType: serverTest,
2219 name: "V2ClientHello-WarningAlertPrefix",
2220 config: Config{
2221 // Choose a cipher suite that does not involve
2222 // elliptic curves, so no extensions are
2223 // involved.
2224 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002225 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002226 Bugs: ProtocolBugs{
2227 SendV2ClientHello: true,
2228 },
2229 },
2230 sendPrefix: string([]byte{
2231 byte(recordTypeAlert),
2232 3, 1, // version
2233 0, 2, // length
2234 alertLevelWarning, byte(alertDecompressionFailure),
2235 }),
2236 // A no-op warning alert may not be sent before V2ClientHello.
2237 shouldFail: true,
2238 expectedError: ":WRONG_VERSION_NUMBER:",
2239 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002240 {
2241 testType: clientTest,
2242 name: "KeyUpdate",
2243 config: Config{
2244 MaxVersion: VersionTLS13,
2245 Bugs: ProtocolBugs{
2246 SendKeyUpdateBeforeEveryAppDataRecord: true,
2247 },
2248 },
2249 },
David Benjaminabe94e32016-09-04 14:18:58 -04002250 {
2251 name: "SendSNIWarningAlert",
2252 config: Config{
2253 MaxVersion: VersionTLS12,
2254 Bugs: ProtocolBugs{
2255 SendSNIWarningAlert: true,
2256 },
2257 },
2258 },
David Benjaminc241d792016-09-09 10:34:20 -04002259 {
2260 testType: serverTest,
2261 name: "ExtraCompressionMethods-TLS12",
2262 config: Config{
2263 MaxVersion: VersionTLS12,
2264 Bugs: ProtocolBugs{
2265 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2266 },
2267 },
2268 },
2269 {
2270 testType: serverTest,
2271 name: "ExtraCompressionMethods-TLS13",
2272 config: Config{
2273 MaxVersion: VersionTLS13,
2274 Bugs: ProtocolBugs{
2275 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2276 },
2277 },
2278 shouldFail: true,
2279 expectedError: ":INVALID_COMPRESSION_LIST:",
2280 expectedLocalError: "remote error: illegal parameter",
2281 },
2282 {
2283 testType: serverTest,
2284 name: "NoNullCompression-TLS12",
2285 config: Config{
2286 MaxVersion: VersionTLS12,
2287 Bugs: ProtocolBugs{
2288 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2289 },
2290 },
2291 shouldFail: true,
2292 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2293 expectedLocalError: "remote error: illegal parameter",
2294 },
2295 {
2296 testType: serverTest,
2297 name: "NoNullCompression-TLS13",
2298 config: Config{
2299 MaxVersion: VersionTLS13,
2300 Bugs: ProtocolBugs{
2301 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2302 },
2303 },
2304 shouldFail: true,
2305 expectedError: ":INVALID_COMPRESSION_LIST:",
2306 expectedLocalError: "remote error: illegal parameter",
2307 },
Adam Langley7c803a62015-06-15 15:35:05 -07002308 }
Adam Langley7c803a62015-06-15 15:35:05 -07002309 testCases = append(testCases, basicTests...)
2310}
2311
Adam Langley95c29f32014-06-20 12:00:00 -07002312func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002313 const bogusCipher = 0xfe00
2314
Adam Langley95c29f32014-06-20 12:00:00 -07002315 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002316 const psk = "12345"
2317 const pskIdentity = "luggage combo"
2318
Adam Langley95c29f32014-06-20 12:00:00 -07002319 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002320 var certFile string
2321 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002322 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002323 cert = ecdsaP256Certificate
2324 certFile = ecdsaP256CertificateFile
2325 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002326 } else {
David Benjamin33863262016-07-08 17:20:12 -07002327 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002328 certFile = rsaCertificateFile
2329 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002330 }
2331
David Benjamin48cae082014-10-27 01:06:24 -04002332 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002333 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002334 flags = append(flags,
2335 "-psk", psk,
2336 "-psk-identity", pskIdentity)
2337 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002338 if hasComponent(suite.name, "NULL") {
2339 // NULL ciphers must be explicitly enabled.
2340 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2341 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002342 if hasComponent(suite.name, "CECPQ1") {
2343 // CECPQ1 ciphers must be explicitly enabled.
2344 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2345 }
David Benjamin881f1962016-08-10 18:29:12 -04002346 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2347 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2348 // for now.
2349 flags = append(flags, "-cipher", suite.name)
2350 }
David Benjamin48cae082014-10-27 01:06:24 -04002351
Adam Langley95c29f32014-06-20 12:00:00 -07002352 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002353 for _, protocol := range []protocol{tls, dtls} {
2354 var prefix string
2355 if protocol == dtls {
2356 if !ver.hasDTLS {
2357 continue
2358 }
2359 prefix = "D"
2360 }
Adam Langley95c29f32014-06-20 12:00:00 -07002361
David Benjamin0407e762016-06-17 16:41:18 -04002362 var shouldServerFail, shouldClientFail bool
2363 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2364 // BoringSSL clients accept ECDHE on SSLv3, but
2365 // a BoringSSL server will never select it
2366 // because the extension is missing.
2367 shouldServerFail = true
2368 }
2369 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2370 shouldClientFail = true
2371 shouldServerFail = true
2372 }
David Benjamin54c217c2016-07-13 12:35:25 -04002373 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002374 shouldClientFail = true
2375 shouldServerFail = true
2376 }
David Benjamin0407e762016-06-17 16:41:18 -04002377 if !isDTLSCipher(suite.name) && protocol == dtls {
2378 shouldClientFail = true
2379 shouldServerFail = true
2380 }
David Benjamin4298d772015-12-19 00:18:25 -05002381
David Benjamin0407e762016-06-17 16:41:18 -04002382 var expectedServerError, expectedClientError string
2383 if shouldServerFail {
2384 expectedServerError = ":NO_SHARED_CIPHER:"
2385 }
2386 if shouldClientFail {
2387 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2388 }
David Benjamin025b3d32014-07-01 19:53:04 -04002389
David Benjamin6fd297b2014-08-11 18:43:38 -04002390 testCases = append(testCases, testCase{
2391 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002392 protocol: protocol,
2393
2394 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002395 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002396 MinVersion: ver.version,
2397 MaxVersion: ver.version,
2398 CipherSuites: []uint16{suite.id},
2399 Certificates: []Certificate{cert},
2400 PreSharedKey: []byte(psk),
2401 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002402 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002403 EnableAllCiphers: shouldServerFail,
2404 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002405 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002406 },
2407 certFile: certFile,
2408 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002409 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002410 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002411 shouldFail: shouldServerFail,
2412 expectedError: expectedServerError,
2413 })
2414
2415 testCases = append(testCases, testCase{
2416 testType: clientTest,
2417 protocol: protocol,
2418 name: prefix + ver.name + "-" + suite.name + "-client",
2419 config: Config{
2420 MinVersion: ver.version,
2421 MaxVersion: ver.version,
2422 CipherSuites: []uint16{suite.id},
2423 Certificates: []Certificate{cert},
2424 PreSharedKey: []byte(psk),
2425 PreSharedKeyIdentity: pskIdentity,
2426 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002427 EnableAllCiphers: shouldClientFail,
2428 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002429 },
2430 },
2431 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002432 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002433 shouldFail: shouldClientFail,
2434 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002435 })
David Benjamin2c99d282015-09-01 10:23:00 -04002436
Nick Harper1fd39d82016-06-14 18:14:35 -07002437 if !shouldClientFail {
2438 // Ensure the maximum record size is accepted.
2439 testCases = append(testCases, testCase{
2440 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2441 config: Config{
2442 MinVersion: ver.version,
2443 MaxVersion: ver.version,
2444 CipherSuites: []uint16{suite.id},
2445 Certificates: []Certificate{cert},
2446 PreSharedKey: []byte(psk),
2447 PreSharedKeyIdentity: pskIdentity,
2448 },
2449 flags: flags,
2450 messageLen: maxPlaintext,
2451 })
2452 }
2453 }
David Benjamin2c99d282015-09-01 10:23:00 -04002454 }
Adam Langley95c29f32014-06-20 12:00:00 -07002455 }
Adam Langleya7997f12015-05-14 17:38:50 -07002456
2457 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002458 name: "NoSharedCipher",
2459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002460 MaxVersion: VersionTLS12,
2461 CipherSuites: []uint16{},
2462 },
2463 shouldFail: true,
2464 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2465 })
2466
2467 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002468 name: "NoSharedCipher-TLS13",
2469 config: Config{
2470 MaxVersion: VersionTLS13,
2471 CipherSuites: []uint16{},
2472 },
2473 shouldFail: true,
2474 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2475 })
2476
2477 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002478 name: "UnsupportedCipherSuite",
2479 config: Config{
2480 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002481 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 Bugs: ProtocolBugs{
2483 IgnorePeerCipherPreferences: true,
2484 },
2485 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002486 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002487 shouldFail: true,
2488 expectedError: ":WRONG_CIPHER_RETURNED:",
2489 })
2490
2491 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002492 name: "ServerHelloBogusCipher",
2493 config: Config{
2494 MaxVersion: VersionTLS12,
2495 Bugs: ProtocolBugs{
2496 SendCipherSuite: bogusCipher,
2497 },
2498 },
2499 shouldFail: true,
2500 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2501 })
2502 testCases = append(testCases, testCase{
2503 name: "ServerHelloBogusCipher-TLS13",
2504 config: Config{
2505 MaxVersion: VersionTLS13,
2506 Bugs: ProtocolBugs{
2507 SendCipherSuite: bogusCipher,
2508 },
2509 },
2510 shouldFail: true,
2511 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2512 })
2513
2514 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002515 name: "WeakDH",
2516 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002517 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002518 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2519 Bugs: ProtocolBugs{
2520 // This is a 1023-bit prime number, generated
2521 // with:
2522 // openssl gendh 1023 | openssl asn1parse -i
2523 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2524 },
2525 },
2526 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002527 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002528 })
Adam Langleycef75832015-09-03 14:51:12 -07002529
David Benjamincd24a392015-11-11 13:23:05 -08002530 testCases = append(testCases, testCase{
2531 name: "SillyDH",
2532 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002533 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002534 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2535 Bugs: ProtocolBugs{
2536 // This is a 4097-bit prime number, generated
2537 // with:
2538 // openssl gendh 4097 | openssl asn1parse -i
2539 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2540 },
2541 },
2542 shouldFail: true,
2543 expectedError: ":DH_P_TOO_LONG:",
2544 })
2545
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002546 // This test ensures that Diffie-Hellman public values are padded with
2547 // zeros so that they're the same length as the prime. This is to avoid
2548 // hitting a bug in yaSSL.
2549 testCases = append(testCases, testCase{
2550 testType: serverTest,
2551 name: "DHPublicValuePadded",
2552 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002553 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002554 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2555 Bugs: ProtocolBugs{
2556 RequireDHPublicValueLen: (1025 + 7) / 8,
2557 },
2558 },
2559 flags: []string{"-use-sparse-dh-prime"},
2560 })
David Benjamincd24a392015-11-11 13:23:05 -08002561
David Benjamin241ae832016-01-15 03:04:54 -05002562 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002563 testCases = append(testCases, testCase{
2564 testType: serverTest,
2565 name: "UnknownCipher",
2566 config: Config{
2567 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2568 },
2569 })
2570
David Benjamin78679342016-09-16 19:42:05 -04002571 // Test empty ECDHE_PSK identity hints work as expected.
2572 testCases = append(testCases, testCase{
2573 name: "EmptyECDHEPSKHint",
2574 config: Config{
2575 MaxVersion: VersionTLS12,
2576 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2577 PreSharedKey: []byte("secret"),
2578 },
2579 flags: []string{"-psk", "secret"},
2580 })
2581
2582 // Test empty PSK identity hints work as expected, even if an explicit
2583 // ServerKeyExchange is sent.
2584 testCases = append(testCases, testCase{
2585 name: "ExplicitEmptyPSKHint",
2586 config: Config{
2587 MaxVersion: VersionTLS12,
2588 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2589 PreSharedKey: []byte("secret"),
2590 Bugs: ProtocolBugs{
2591 AlwaysSendPreSharedKeyIdentityHint: true,
2592 },
2593 },
2594 flags: []string{"-psk", "secret"},
2595 })
2596
Adam Langleycef75832015-09-03 14:51:12 -07002597 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2598 // 1.1 specific cipher suite settings. A server is setup with the given
2599 // cipher lists and then a connection is made for each member of
2600 // expectations. The cipher suite that the server selects must match
2601 // the specified one.
2602 var versionSpecificCiphersTest = []struct {
2603 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2604 // expectations is a map from TLS version to cipher suite id.
2605 expectations map[uint16]uint16
2606 }{
2607 {
2608 // Test that the null case (where no version-specific ciphers are set)
2609 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002610 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2611 "", // no ciphers specifically for TLS ≥ 1.0
2612 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002613 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002614 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2615 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2616 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2617 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002618 },
2619 },
2620 {
2621 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2622 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002623 "DES-CBC3-SHA:AES128-SHA", // default
2624 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2625 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002626 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002627 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002628 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2629 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2630 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2631 },
2632 },
2633 {
2634 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2635 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002636 "DES-CBC3-SHA:AES128-SHA", // default
2637 "", // no ciphers specifically for TLS ≥ 1.0
2638 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002639 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002640 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2641 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002642 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2643 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2644 },
2645 },
2646 {
2647 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2648 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002649 "DES-CBC3-SHA:AES128-SHA", // default
2650 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2651 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002652 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002653 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002654 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2655 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2656 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2657 },
2658 },
2659 }
2660
2661 for i, test := range versionSpecificCiphersTest {
2662 for version, expectedCipherSuite := range test.expectations {
2663 flags := []string{"-cipher", test.ciphersDefault}
2664 if len(test.ciphersTLS10) > 0 {
2665 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2666 }
2667 if len(test.ciphersTLS11) > 0 {
2668 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2669 }
2670
2671 testCases = append(testCases, testCase{
2672 testType: serverTest,
2673 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2674 config: Config{
2675 MaxVersion: version,
2676 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 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 -07002678 },
2679 flags: flags,
2680 expectedCipher: expectedCipherSuite,
2681 })
2682 }
2683 }
Adam Langley95c29f32014-06-20 12:00:00 -07002684}
2685
2686func addBadECDSASignatureTests() {
2687 for badR := BadValue(1); badR < NumBadValues; badR++ {
2688 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002689 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002690 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2691 config: Config{
2692 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002693 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002694 Bugs: ProtocolBugs{
2695 BadECDSAR: badR,
2696 BadECDSAS: badS,
2697 },
2698 },
2699 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002700 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002701 })
2702 }
2703 }
2704}
2705
Adam Langley80842bd2014-06-20 12:00:00 -07002706func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002707 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002708 name: "MaxCBCPadding",
2709 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002710 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002711 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2712 Bugs: ProtocolBugs{
2713 MaxPadding: true,
2714 },
2715 },
2716 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2717 })
David Benjamin025b3d32014-07-01 19:53:04 -04002718 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002719 name: "BadCBCPadding",
2720 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002721 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002722 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2723 Bugs: ProtocolBugs{
2724 PaddingFirstByteBad: true,
2725 },
2726 },
2727 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002728 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002729 })
2730 // OpenSSL previously had an issue where the first byte of padding in
2731 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002732 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002733 name: "BadCBCPadding255",
2734 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002735 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2737 Bugs: ProtocolBugs{
2738 MaxPadding: true,
2739 PaddingFirstByteBadIf255: true,
2740 },
2741 },
2742 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2743 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002744 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002745 })
2746}
2747
Kenny Root7fdeaf12014-08-05 15:23:37 -07002748func addCBCSplittingTests() {
2749 testCases = append(testCases, testCase{
2750 name: "CBCRecordSplitting",
2751 config: Config{
2752 MaxVersion: VersionTLS10,
2753 MinVersion: VersionTLS10,
2754 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2755 },
David Benjaminac8302a2015-09-01 17:18:15 -04002756 messageLen: -1, // read until EOF
2757 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002758 flags: []string{
2759 "-async",
2760 "-write-different-record-sizes",
2761 "-cbc-record-splitting",
2762 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002763 })
2764 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002765 name: "CBCRecordSplittingPartialWrite",
2766 config: Config{
2767 MaxVersion: VersionTLS10,
2768 MinVersion: VersionTLS10,
2769 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2770 },
2771 messageLen: -1, // read until EOF
2772 flags: []string{
2773 "-async",
2774 "-write-different-record-sizes",
2775 "-cbc-record-splitting",
2776 "-partial-write",
2777 },
2778 })
2779}
2780
David Benjamin636293b2014-07-08 17:59:18 -04002781func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002782 // Add a dummy cert pool to stress certificate authority parsing.
2783 // TODO(davidben): Add tests that those values parse out correctly.
2784 certPool := x509.NewCertPool()
2785 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2786 if err != nil {
2787 panic(err)
2788 }
2789 certPool.AddCert(cert)
2790
David Benjamin636293b2014-07-08 17:59:18 -04002791 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002792 testCases = append(testCases, testCase{
2793 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002794 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002795 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002796 MinVersion: ver.version,
2797 MaxVersion: ver.version,
2798 ClientAuth: RequireAnyClientCert,
2799 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002800 },
2801 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002802 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2803 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002804 },
2805 })
2806 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002807 testType: serverTest,
2808 name: ver.name + "-Server-ClientAuth-RSA",
2809 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002810 MinVersion: ver.version,
2811 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002812 Certificates: []Certificate{rsaCertificate},
2813 },
2814 flags: []string{"-require-any-client-certificate"},
2815 })
David Benjamine098ec22014-08-27 23:13:20 -04002816 if ver.version != VersionSSL30 {
2817 testCases = append(testCases, testCase{
2818 testType: serverTest,
2819 name: ver.name + "-Server-ClientAuth-ECDSA",
2820 config: Config{
2821 MinVersion: ver.version,
2822 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002823 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002824 },
2825 flags: []string{"-require-any-client-certificate"},
2826 })
2827 testCases = append(testCases, testCase{
2828 testType: clientTest,
2829 name: ver.name + "-Client-ClientAuth-ECDSA",
2830 config: Config{
2831 MinVersion: ver.version,
2832 MaxVersion: ver.version,
2833 ClientAuth: RequireAnyClientCert,
2834 ClientCAs: certPool,
2835 },
2836 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002837 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2838 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002839 },
2840 })
2841 }
Adam Langley37646832016-08-01 16:16:46 -07002842
2843 testCases = append(testCases, testCase{
2844 name: "NoClientCertificate-" + ver.name,
2845 config: Config{
2846 MinVersion: ver.version,
2847 MaxVersion: ver.version,
2848 ClientAuth: RequireAnyClientCert,
2849 },
2850 shouldFail: true,
2851 expectedLocalError: "client didn't provide a certificate",
2852 })
2853
2854 testCases = append(testCases, testCase{
2855 // Even if not configured to expect a certificate, OpenSSL will
2856 // return X509_V_OK as the verify_result.
2857 testType: serverTest,
2858 name: "NoClientCertificateRequested-Server-" + ver.name,
2859 config: Config{
2860 MinVersion: ver.version,
2861 MaxVersion: ver.version,
2862 },
2863 flags: []string{
2864 "-expect-verify-result",
2865 },
2866 // TODO(davidben): Switch this to true when TLS 1.3
2867 // supports session resumption.
2868 resumeSession: ver.version < VersionTLS13,
2869 })
2870
2871 testCases = append(testCases, testCase{
2872 // If a client certificate is not provided, OpenSSL will still
2873 // return X509_V_OK as the verify_result.
2874 testType: serverTest,
2875 name: "NoClientCertificate-Server-" + ver.name,
2876 config: Config{
2877 MinVersion: ver.version,
2878 MaxVersion: ver.version,
2879 },
2880 flags: []string{
2881 "-expect-verify-result",
2882 "-verify-peer",
2883 },
2884 // TODO(davidben): Switch this to true when TLS 1.3
2885 // supports session resumption.
2886 resumeSession: ver.version < VersionTLS13,
2887 })
2888
2889 testCases = append(testCases, testCase{
2890 testType: serverTest,
2891 name: "RequireAnyClientCertificate-" + ver.name,
2892 config: Config{
2893 MinVersion: ver.version,
2894 MaxVersion: ver.version,
2895 },
2896 flags: []string{"-require-any-client-certificate"},
2897 shouldFail: true,
2898 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2899 })
2900
2901 if ver.version != VersionSSL30 {
2902 testCases = append(testCases, testCase{
2903 testType: serverTest,
2904 name: "SkipClientCertificate-" + ver.name,
2905 config: Config{
2906 MinVersion: ver.version,
2907 MaxVersion: ver.version,
2908 Bugs: ProtocolBugs{
2909 SkipClientCertificate: true,
2910 },
2911 },
2912 // Setting SSL_VERIFY_PEER allows anonymous clients.
2913 flags: []string{"-verify-peer"},
2914 shouldFail: true,
2915 expectedError: ":UNEXPECTED_MESSAGE:",
2916 })
2917 }
David Benjamin636293b2014-07-08 17:59:18 -04002918 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002919
David Benjaminc032dfa2016-05-12 14:54:57 -04002920 // Client auth is only legal in certificate-based ciphers.
2921 testCases = append(testCases, testCase{
2922 testType: clientTest,
2923 name: "ClientAuth-PSK",
2924 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002925 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002926 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2927 PreSharedKey: []byte("secret"),
2928 ClientAuth: RequireAnyClientCert,
2929 },
2930 flags: []string{
2931 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2932 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2933 "-psk", "secret",
2934 },
2935 shouldFail: true,
2936 expectedError: ":UNEXPECTED_MESSAGE:",
2937 })
2938 testCases = append(testCases, testCase{
2939 testType: clientTest,
2940 name: "ClientAuth-ECDHE_PSK",
2941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002942 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002943 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2944 PreSharedKey: []byte("secret"),
2945 ClientAuth: RequireAnyClientCert,
2946 },
2947 flags: []string{
2948 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2949 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2950 "-psk", "secret",
2951 },
2952 shouldFail: true,
2953 expectedError: ":UNEXPECTED_MESSAGE:",
2954 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002955
2956 // Regression test for a bug where the client CA list, if explicitly
2957 // set to NULL, was mis-encoded.
2958 testCases = append(testCases, testCase{
2959 testType: serverTest,
2960 name: "Null-Client-CA-List",
2961 config: Config{
2962 MaxVersion: VersionTLS12,
2963 Certificates: []Certificate{rsaCertificate},
2964 },
2965 flags: []string{
2966 "-require-any-client-certificate",
2967 "-use-null-client-ca-list",
2968 },
2969 })
David Benjamin636293b2014-07-08 17:59:18 -04002970}
2971
Adam Langley75712922014-10-10 16:23:43 -07002972func addExtendedMasterSecretTests() {
2973 const expectEMSFlag = "-expect-extended-master-secret"
2974
2975 for _, with := range []bool{false, true} {
2976 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002977 if with {
2978 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002979 }
2980
2981 for _, isClient := range []bool{false, true} {
2982 suffix := "-Server"
2983 testType := serverTest
2984 if isClient {
2985 suffix = "-Client"
2986 testType = clientTest
2987 }
2988
2989 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002990 // In TLS 1.3, the extension is irrelevant and
2991 // always reports as enabled.
2992 var flags []string
2993 if with || ver.version >= VersionTLS13 {
2994 flags = []string{expectEMSFlag}
2995 }
2996
Adam Langley75712922014-10-10 16:23:43 -07002997 test := testCase{
2998 testType: testType,
2999 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3000 config: Config{
3001 MinVersion: ver.version,
3002 MaxVersion: ver.version,
3003 Bugs: ProtocolBugs{
3004 NoExtendedMasterSecret: !with,
3005 RequireExtendedMasterSecret: with,
3006 },
3007 },
David Benjamin48cae082014-10-27 01:06:24 -04003008 flags: flags,
3009 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003010 }
3011 if test.shouldFail {
3012 test.expectedLocalError = "extended master secret required but not supported by peer"
3013 }
3014 testCases = append(testCases, test)
3015 }
3016 }
3017 }
3018
Adam Langleyba5934b2015-06-02 10:50:35 -07003019 for _, isClient := range []bool{false, true} {
3020 for _, supportedInFirstConnection := range []bool{false, true} {
3021 for _, supportedInResumeConnection := range []bool{false, true} {
3022 boolToWord := func(b bool) string {
3023 if b {
3024 return "Yes"
3025 }
3026 return "No"
3027 }
3028 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3029 if isClient {
3030 suffix += "Client"
3031 } else {
3032 suffix += "Server"
3033 }
3034
3035 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003036 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003037 Bugs: ProtocolBugs{
3038 RequireExtendedMasterSecret: true,
3039 },
3040 }
3041
3042 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003043 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003044 Bugs: ProtocolBugs{
3045 NoExtendedMasterSecret: true,
3046 },
3047 }
3048
3049 test := testCase{
3050 name: "ExtendedMasterSecret-" + suffix,
3051 resumeSession: true,
3052 }
3053
3054 if !isClient {
3055 test.testType = serverTest
3056 }
3057
3058 if supportedInFirstConnection {
3059 test.config = supportedConfig
3060 } else {
3061 test.config = noSupportConfig
3062 }
3063
3064 if supportedInResumeConnection {
3065 test.resumeConfig = &supportedConfig
3066 } else {
3067 test.resumeConfig = &noSupportConfig
3068 }
3069
3070 switch suffix {
3071 case "YesToYes-Client", "YesToYes-Server":
3072 // When a session is resumed, it should
3073 // still be aware that its master
3074 // secret was generated via EMS and
3075 // thus it's safe to use tls-unique.
3076 test.flags = []string{expectEMSFlag}
3077 case "NoToYes-Server":
3078 // If an original connection did not
3079 // contain EMS, but a resumption
3080 // handshake does, then a server should
3081 // not resume the session.
3082 test.expectResumeRejected = true
3083 case "YesToNo-Server":
3084 // Resuming an EMS session without the
3085 // EMS extension should cause the
3086 // server to abort the connection.
3087 test.shouldFail = true
3088 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3089 case "NoToYes-Client":
3090 // A client should abort a connection
3091 // where the server resumed a non-EMS
3092 // session but echoed the EMS
3093 // extension.
3094 test.shouldFail = true
3095 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3096 case "YesToNo-Client":
3097 // A client should abort a connection
3098 // where the server didn't echo EMS
3099 // when the session used it.
3100 test.shouldFail = true
3101 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3102 }
3103
3104 testCases = append(testCases, test)
3105 }
3106 }
3107 }
David Benjamin163c9562016-08-29 23:14:17 -04003108
3109 // Switching EMS on renegotiation is forbidden.
3110 testCases = append(testCases, testCase{
3111 name: "ExtendedMasterSecret-Renego-NoEMS",
3112 config: Config{
3113 MaxVersion: VersionTLS12,
3114 Bugs: ProtocolBugs{
3115 NoExtendedMasterSecret: true,
3116 NoExtendedMasterSecretOnRenegotiation: true,
3117 },
3118 },
3119 renegotiate: 1,
3120 flags: []string{
3121 "-renegotiate-freely",
3122 "-expect-total-renegotiations", "1",
3123 },
3124 })
3125
3126 testCases = append(testCases, testCase{
3127 name: "ExtendedMasterSecret-Renego-Upgrade",
3128 config: Config{
3129 MaxVersion: VersionTLS12,
3130 Bugs: ProtocolBugs{
3131 NoExtendedMasterSecret: true,
3132 },
3133 },
3134 renegotiate: 1,
3135 flags: []string{
3136 "-renegotiate-freely",
3137 "-expect-total-renegotiations", "1",
3138 },
3139 shouldFail: true,
3140 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3141 })
3142
3143 testCases = append(testCases, testCase{
3144 name: "ExtendedMasterSecret-Renego-Downgrade",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 Bugs: ProtocolBugs{
3148 NoExtendedMasterSecretOnRenegotiation: true,
3149 },
3150 },
3151 renegotiate: 1,
3152 flags: []string{
3153 "-renegotiate-freely",
3154 "-expect-total-renegotiations", "1",
3155 },
3156 shouldFail: true,
3157 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3158 })
Adam Langley75712922014-10-10 16:23:43 -07003159}
3160
David Benjamin582ba042016-07-07 12:33:25 -07003161type stateMachineTestConfig struct {
3162 protocol protocol
3163 async bool
3164 splitHandshake, packHandshakeFlight bool
3165}
3166
David Benjamin43ec06f2014-08-05 02:28:57 -04003167// Adds tests that try to cover the range of the handshake state machine, under
3168// various conditions. Some of these are redundant with other tests, but they
3169// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003170func addAllStateMachineCoverageTests() {
3171 for _, async := range []bool{false, true} {
3172 for _, protocol := range []protocol{tls, dtls} {
3173 addStateMachineCoverageTests(stateMachineTestConfig{
3174 protocol: protocol,
3175 async: async,
3176 })
3177 addStateMachineCoverageTests(stateMachineTestConfig{
3178 protocol: protocol,
3179 async: async,
3180 splitHandshake: true,
3181 })
3182 if protocol == tls {
3183 addStateMachineCoverageTests(stateMachineTestConfig{
3184 protocol: protocol,
3185 async: async,
3186 packHandshakeFlight: true,
3187 })
3188 }
3189 }
3190 }
3191}
3192
3193func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003194 var tests []testCase
3195
3196 // Basic handshake, with resumption. Client and server,
3197 // session ID and session ticket.
3198 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003199 name: "Basic-Client",
3200 config: Config{
3201 MaxVersion: VersionTLS12,
3202 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003203 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003204 // Ensure session tickets are used, not session IDs.
3205 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003206 })
3207 tests = append(tests, testCase{
3208 name: "Basic-Client-RenewTicket",
3209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003210 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003211 Bugs: ProtocolBugs{
3212 RenewTicketOnResume: true,
3213 },
3214 },
David Benjamin46662482016-08-17 00:51:00 -04003215 flags: []string{"-expect-ticket-renewal"},
3216 resumeSession: true,
3217 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 })
3219 tests = append(tests, testCase{
3220 name: "Basic-Client-NoTicket",
3221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003222 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003223 SessionTicketsDisabled: true,
3224 },
3225 resumeSession: true,
3226 })
3227 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003228 name: "Basic-Client-Implicit",
3229 config: Config{
3230 MaxVersion: VersionTLS12,
3231 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003232 flags: []string{"-implicit-handshake"},
3233 resumeSession: true,
3234 })
3235 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003236 testType: serverTest,
3237 name: "Basic-Server",
3238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003239 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003240 Bugs: ProtocolBugs{
3241 RequireSessionTickets: true,
3242 },
3243 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003244 resumeSession: true,
3245 })
3246 tests = append(tests, testCase{
3247 testType: serverTest,
3248 name: "Basic-Server-NoTickets",
3249 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003250 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003251 SessionTicketsDisabled: true,
3252 },
3253 resumeSession: true,
3254 })
3255 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003256 testType: serverTest,
3257 name: "Basic-Server-Implicit",
3258 config: Config{
3259 MaxVersion: VersionTLS12,
3260 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003261 flags: []string{"-implicit-handshake"},
3262 resumeSession: true,
3263 })
3264 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003265 testType: serverTest,
3266 name: "Basic-Server-EarlyCallback",
3267 config: Config{
3268 MaxVersion: VersionTLS12,
3269 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003270 flags: []string{"-use-early-callback"},
3271 resumeSession: true,
3272 })
3273
Steven Valdez143e8b32016-07-11 13:19:03 -04003274 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003275 if config.protocol == tls {
3276 tests = append(tests, testCase{
3277 name: "TLS13-1RTT-Client",
3278 config: Config{
3279 MaxVersion: VersionTLS13,
3280 MinVersion: VersionTLS13,
3281 },
David Benjamin46662482016-08-17 00:51:00 -04003282 resumeSession: true,
3283 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003284 })
3285
3286 tests = append(tests, testCase{
3287 testType: serverTest,
3288 name: "TLS13-1RTT-Server",
3289 config: Config{
3290 MaxVersion: VersionTLS13,
3291 MinVersion: VersionTLS13,
3292 },
David Benjamin46662482016-08-17 00:51:00 -04003293 resumeSession: true,
3294 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003295 })
3296
3297 tests = append(tests, testCase{
3298 name: "TLS13-HelloRetryRequest-Client",
3299 config: Config{
3300 MaxVersion: VersionTLS13,
3301 MinVersion: VersionTLS13,
3302 // P-384 requires a HelloRetryRequest against
3303 // BoringSSL's default configuration. Assert
3304 // that we do indeed test this with
3305 // ExpectMissingKeyShare.
3306 CurvePreferences: []CurveID{CurveP384},
3307 Bugs: ProtocolBugs{
3308 ExpectMissingKeyShare: true,
3309 },
3310 },
3311 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3312 resumeSession: true,
3313 })
3314
3315 tests = append(tests, testCase{
3316 testType: serverTest,
3317 name: "TLS13-HelloRetryRequest-Server",
3318 config: Config{
3319 MaxVersion: VersionTLS13,
3320 MinVersion: VersionTLS13,
3321 // Require a HelloRetryRequest for every curve.
3322 DefaultCurves: []CurveID{},
3323 },
3324 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3325 resumeSession: true,
3326 })
3327 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003328
David Benjamin760b1dd2015-05-15 23:33:48 -04003329 // TLS client auth.
3330 tests = append(tests, testCase{
3331 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003332 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003334 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003335 ClientAuth: RequestClientCert,
3336 },
3337 })
3338 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003339 testType: serverTest,
3340 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003341 config: Config{
3342 MaxVersion: VersionTLS12,
3343 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003344 // Setting SSL_VERIFY_PEER allows anonymous clients.
3345 flags: []string{"-verify-peer"},
3346 })
David Benjamin582ba042016-07-07 12:33:25 -07003347 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003348 tests = append(tests, testCase{
3349 testType: clientTest,
3350 name: "ClientAuth-NoCertificate-Client-SSL3",
3351 config: Config{
3352 MaxVersion: VersionSSL30,
3353 ClientAuth: RequestClientCert,
3354 },
3355 })
3356 tests = append(tests, testCase{
3357 testType: serverTest,
3358 name: "ClientAuth-NoCertificate-Server-SSL3",
3359 config: Config{
3360 MaxVersion: VersionSSL30,
3361 },
3362 // Setting SSL_VERIFY_PEER allows anonymous clients.
3363 flags: []string{"-verify-peer"},
3364 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003365 tests = append(tests, testCase{
3366 testType: clientTest,
3367 name: "ClientAuth-NoCertificate-Client-TLS13",
3368 config: Config{
3369 MaxVersion: VersionTLS13,
3370 ClientAuth: RequestClientCert,
3371 },
3372 })
3373 tests = append(tests, testCase{
3374 testType: serverTest,
3375 name: "ClientAuth-NoCertificate-Server-TLS13",
3376 config: Config{
3377 MaxVersion: VersionTLS13,
3378 },
3379 // Setting SSL_VERIFY_PEER allows anonymous clients.
3380 flags: []string{"-verify-peer"},
3381 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003382 }
3383 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003384 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003385 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003387 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 ClientAuth: RequireAnyClientCert,
3389 },
3390 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003391 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3392 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003393 },
3394 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003395 tests = append(tests, testCase{
3396 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003397 name: "ClientAuth-RSA-Client-TLS13",
3398 config: Config{
3399 MaxVersion: VersionTLS13,
3400 ClientAuth: RequireAnyClientCert,
3401 },
3402 flags: []string{
3403 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3404 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3405 },
3406 })
3407 tests = append(tests, testCase{
3408 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003409 name: "ClientAuth-ECDSA-Client",
3410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003412 ClientAuth: RequireAnyClientCert,
3413 },
3414 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003415 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3416 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003417 },
3418 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003419 tests = append(tests, testCase{
3420 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003421 name: "ClientAuth-ECDSA-Client-TLS13",
3422 config: Config{
3423 MaxVersion: VersionTLS13,
3424 ClientAuth: RequireAnyClientCert,
3425 },
3426 flags: []string{
3427 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3428 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3429 },
3430 })
3431 tests = append(tests, testCase{
3432 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003433 name: "ClientAuth-NoCertificate-OldCallback",
3434 config: Config{
3435 MaxVersion: VersionTLS12,
3436 ClientAuth: RequestClientCert,
3437 },
3438 flags: []string{"-use-old-client-cert-callback"},
3439 })
3440 tests = append(tests, testCase{
3441 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003442 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3443 config: Config{
3444 MaxVersion: VersionTLS13,
3445 ClientAuth: RequestClientCert,
3446 },
3447 flags: []string{"-use-old-client-cert-callback"},
3448 })
3449 tests = append(tests, testCase{
3450 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003451 name: "ClientAuth-OldCallback",
3452 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003453 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003454 ClientAuth: RequireAnyClientCert,
3455 },
3456 flags: []string{
3457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3459 "-use-old-client-cert-callback",
3460 },
3461 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003462 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003463 testType: clientTest,
3464 name: "ClientAuth-OldCallback-TLS13",
3465 config: Config{
3466 MaxVersion: VersionTLS13,
3467 ClientAuth: RequireAnyClientCert,
3468 },
3469 flags: []string{
3470 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3471 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3472 "-use-old-client-cert-callback",
3473 },
3474 })
3475 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003476 testType: serverTest,
3477 name: "ClientAuth-Server",
3478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003479 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003480 Certificates: []Certificate{rsaCertificate},
3481 },
3482 flags: []string{"-require-any-client-certificate"},
3483 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003484 tests = append(tests, testCase{
3485 testType: serverTest,
3486 name: "ClientAuth-Server-TLS13",
3487 config: Config{
3488 MaxVersion: VersionTLS13,
3489 Certificates: []Certificate{rsaCertificate},
3490 },
3491 flags: []string{"-require-any-client-certificate"},
3492 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003493
David Benjamin4c3ddf72016-06-29 18:13:53 -04003494 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003495 tests = append(tests, testCase{
3496 testType: serverTest,
3497 name: "Basic-Server-RSA",
3498 config: Config{
3499 MaxVersion: VersionTLS12,
3500 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3501 },
3502 flags: []string{
3503 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3504 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3505 },
3506 })
3507 tests = append(tests, testCase{
3508 testType: serverTest,
3509 name: "Basic-Server-ECDHE-RSA",
3510 config: Config{
3511 MaxVersion: VersionTLS12,
3512 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3513 },
3514 flags: []string{
3515 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3516 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3517 },
3518 })
3519 tests = append(tests, testCase{
3520 testType: serverTest,
3521 name: "Basic-Server-ECDHE-ECDSA",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3525 },
3526 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003527 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3528 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003529 },
3530 })
3531
David Benjamin760b1dd2015-05-15 23:33:48 -04003532 // No session ticket support; server doesn't send NewSessionTicket.
3533 tests = append(tests, testCase{
3534 name: "SessionTicketsDisabled-Client",
3535 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003537 SessionTicketsDisabled: true,
3538 },
3539 })
3540 tests = append(tests, testCase{
3541 testType: serverTest,
3542 name: "SessionTicketsDisabled-Server",
3543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003544 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003545 SessionTicketsDisabled: true,
3546 },
3547 })
3548
3549 // Skip ServerKeyExchange in PSK key exchange if there's no
3550 // identity hint.
3551 tests = append(tests, testCase{
3552 name: "EmptyPSKHint-Client",
3553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003554 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003555 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3556 PreSharedKey: []byte("secret"),
3557 },
3558 flags: []string{"-psk", "secret"},
3559 })
3560 tests = append(tests, testCase{
3561 testType: serverTest,
3562 name: "EmptyPSKHint-Server",
3563 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003564 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003565 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3566 PreSharedKey: []byte("secret"),
3567 },
3568 flags: []string{"-psk", "secret"},
3569 })
3570
David Benjamin4c3ddf72016-06-29 18:13:53 -04003571 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003572 tests = append(tests, testCase{
3573 testType: clientTest,
3574 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003575 config: Config{
3576 MaxVersion: VersionTLS12,
3577 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003578 flags: []string{
3579 "-enable-ocsp-stapling",
3580 "-expect-ocsp-response",
3581 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003582 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003583 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003584 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003585 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003586 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003587 testType: serverTest,
3588 name: "OCSPStapling-Server",
3589 config: Config{
3590 MaxVersion: VersionTLS12,
3591 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003592 expectedOCSPResponse: testOCSPResponse,
3593 flags: []string{
3594 "-ocsp-response",
3595 base64.StdEncoding.EncodeToString(testOCSPResponse),
3596 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003597 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003598 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003599 tests = append(tests, testCase{
3600 testType: clientTest,
3601 name: "OCSPStapling-Client-TLS13",
3602 config: Config{
3603 MaxVersion: VersionTLS13,
3604 },
3605 flags: []string{
3606 "-enable-ocsp-stapling",
3607 "-expect-ocsp-response",
3608 base64.StdEncoding.EncodeToString(testOCSPResponse),
3609 "-verify-peer",
3610 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003611 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003612 })
3613 tests = append(tests, testCase{
3614 testType: serverTest,
3615 name: "OCSPStapling-Server-TLS13",
3616 config: Config{
3617 MaxVersion: VersionTLS13,
3618 },
3619 expectedOCSPResponse: testOCSPResponse,
3620 flags: []string{
3621 "-ocsp-response",
3622 base64.StdEncoding.EncodeToString(testOCSPResponse),
3623 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003624 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003625 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003626
David Benjamin4c3ddf72016-06-29 18:13:53 -04003627 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003628 for _, vers := range tlsVersions {
3629 if config.protocol == dtls && !vers.hasDTLS {
3630 continue
3631 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003632 for _, testType := range []testType{clientTest, serverTest} {
3633 suffix := "-Client"
3634 if testType == serverTest {
3635 suffix = "-Server"
3636 }
3637 suffix += "-" + vers.name
3638
3639 flag := "-verify-peer"
3640 if testType == serverTest {
3641 flag = "-require-any-client-certificate"
3642 }
3643
3644 tests = append(tests, testCase{
3645 testType: testType,
3646 name: "CertificateVerificationSucceed" + suffix,
3647 config: Config{
3648 MaxVersion: vers.version,
3649 Certificates: []Certificate{rsaCertificate},
3650 },
3651 flags: []string{
3652 flag,
3653 "-expect-verify-result",
3654 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003655 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003656 })
3657 tests = append(tests, testCase{
3658 testType: testType,
3659 name: "CertificateVerificationFail" + suffix,
3660 config: Config{
3661 MaxVersion: vers.version,
3662 Certificates: []Certificate{rsaCertificate},
3663 },
3664 flags: []string{
3665 flag,
3666 "-verify-fail",
3667 },
3668 shouldFail: true,
3669 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3670 })
3671 }
3672
3673 // By default, the client is in a soft fail mode where the peer
3674 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003675 tests = append(tests, testCase{
3676 testType: clientTest,
3677 name: "CertificateVerificationSoftFail-" + vers.name,
3678 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003679 MaxVersion: vers.version,
3680 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003681 },
3682 flags: []string{
3683 "-verify-fail",
3684 "-expect-verify-result",
3685 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003686 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003687 })
3688 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003689
David Benjamin1d4f4c02016-07-26 18:03:08 -04003690 tests = append(tests, testCase{
3691 name: "ShimSendAlert",
3692 flags: []string{"-send-alert"},
3693 shimWritesFirst: true,
3694 shouldFail: true,
3695 expectedLocalError: "remote error: decompression failure",
3696 })
3697
David Benjamin582ba042016-07-07 12:33:25 -07003698 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003699 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003700 name: "Renegotiate-Client",
3701 config: Config{
3702 MaxVersion: VersionTLS12,
3703 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003704 renegotiate: 1,
3705 flags: []string{
3706 "-renegotiate-freely",
3707 "-expect-total-renegotiations", "1",
3708 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003709 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003710
David Benjamin47921102016-07-28 11:29:18 -04003711 tests = append(tests, testCase{
3712 name: "SendHalfHelloRequest",
3713 config: Config{
3714 MaxVersion: VersionTLS12,
3715 Bugs: ProtocolBugs{
3716 PackHelloRequestWithFinished: config.packHandshakeFlight,
3717 },
3718 },
3719 sendHalfHelloRequest: true,
3720 flags: []string{"-renegotiate-ignore"},
3721 shouldFail: true,
3722 expectedError: ":UNEXPECTED_RECORD:",
3723 })
3724
David Benjamin760b1dd2015-05-15 23:33:48 -04003725 // NPN on client and server; results in post-handshake message.
3726 tests = append(tests, testCase{
3727 name: "NPN-Client",
3728 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003729 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003730 NextProtos: []string{"foo"},
3731 },
3732 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003733 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 expectedNextProto: "foo",
3735 expectedNextProtoType: npn,
3736 })
3737 tests = append(tests, testCase{
3738 testType: serverTest,
3739 name: "NPN-Server",
3740 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003741 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003742 NextProtos: []string{"bar"},
3743 },
3744 flags: []string{
3745 "-advertise-npn", "\x03foo\x03bar\x03baz",
3746 "-expect-next-proto", "bar",
3747 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003748 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 expectedNextProto: "bar",
3750 expectedNextProtoType: npn,
3751 })
3752
3753 // TODO(davidben): Add tests for when False Start doesn't trigger.
3754
3755 // Client does False Start and negotiates NPN.
3756 tests = append(tests, testCase{
3757 name: "FalseStart",
3758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003759 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3761 NextProtos: []string{"foo"},
3762 Bugs: ProtocolBugs{
3763 ExpectFalseStart: true,
3764 },
3765 },
3766 flags: []string{
3767 "-false-start",
3768 "-select-next-proto", "foo",
3769 },
3770 shimWritesFirst: true,
3771 resumeSession: true,
3772 })
3773
3774 // Client does False Start and negotiates ALPN.
3775 tests = append(tests, testCase{
3776 name: "FalseStart-ALPN",
3777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003778 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3780 NextProtos: []string{"foo"},
3781 Bugs: ProtocolBugs{
3782 ExpectFalseStart: true,
3783 },
3784 },
3785 flags: []string{
3786 "-false-start",
3787 "-advertise-alpn", "\x03foo",
3788 },
3789 shimWritesFirst: true,
3790 resumeSession: true,
3791 })
3792
3793 // Client does False Start but doesn't explicitly call
3794 // SSL_connect.
3795 tests = append(tests, testCase{
3796 name: "FalseStart-Implicit",
3797 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003798 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003799 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3800 NextProtos: []string{"foo"},
3801 },
3802 flags: []string{
3803 "-implicit-handshake",
3804 "-false-start",
3805 "-advertise-alpn", "\x03foo",
3806 },
3807 })
3808
3809 // False Start without session tickets.
3810 tests = append(tests, testCase{
3811 name: "FalseStart-SessionTicketsDisabled",
3812 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003813 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003814 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3815 NextProtos: []string{"foo"},
3816 SessionTicketsDisabled: true,
3817 Bugs: ProtocolBugs{
3818 ExpectFalseStart: true,
3819 },
3820 },
3821 flags: []string{
3822 "-false-start",
3823 "-select-next-proto", "foo",
3824 },
3825 shimWritesFirst: true,
3826 })
3827
Adam Langleydf759b52016-07-11 15:24:37 -07003828 tests = append(tests, testCase{
3829 name: "FalseStart-CECPQ1",
3830 config: Config{
3831 MaxVersion: VersionTLS12,
3832 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3833 NextProtos: []string{"foo"},
3834 Bugs: ProtocolBugs{
3835 ExpectFalseStart: true,
3836 },
3837 },
3838 flags: []string{
3839 "-false-start",
3840 "-cipher", "DEFAULT:kCECPQ1",
3841 "-select-next-proto", "foo",
3842 },
3843 shimWritesFirst: true,
3844 resumeSession: true,
3845 })
3846
David Benjamin760b1dd2015-05-15 23:33:48 -04003847 // Server parses a V2ClientHello.
3848 tests = append(tests, testCase{
3849 testType: serverTest,
3850 name: "SendV2ClientHello",
3851 config: Config{
3852 // Choose a cipher suite that does not involve
3853 // elliptic curves, so no extensions are
3854 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003855 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003856 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003857 Bugs: ProtocolBugs{
3858 SendV2ClientHello: true,
3859 },
3860 },
3861 })
3862
3863 // Client sends a Channel ID.
3864 tests = append(tests, testCase{
3865 name: "ChannelID-Client",
3866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003867 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003868 RequestChannelID: true,
3869 },
Adam Langley7c803a62015-06-15 15:35:05 -07003870 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 resumeSession: true,
3872 expectChannelID: true,
3873 })
3874
3875 // Server accepts a Channel ID.
3876 tests = append(tests, testCase{
3877 testType: serverTest,
3878 name: "ChannelID-Server",
3879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003880 MaxVersion: VersionTLS12,
3881 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003882 },
3883 flags: []string{
3884 "-expect-channel-id",
3885 base64.StdEncoding.EncodeToString(channelIDBytes),
3886 },
3887 resumeSession: true,
3888 expectChannelID: true,
3889 })
David Benjamin30789da2015-08-29 22:56:45 -04003890
David Benjaminf8fcdf32016-06-08 15:56:13 -04003891 // Channel ID and NPN at the same time, to ensure their relative
3892 // ordering is correct.
3893 tests = append(tests, testCase{
3894 name: "ChannelID-NPN-Client",
3895 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003896 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003897 RequestChannelID: true,
3898 NextProtos: []string{"foo"},
3899 },
3900 flags: []string{
3901 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3902 "-select-next-proto", "foo",
3903 },
3904 resumeSession: true,
3905 expectChannelID: true,
3906 expectedNextProto: "foo",
3907 expectedNextProtoType: npn,
3908 })
3909 tests = append(tests, testCase{
3910 testType: serverTest,
3911 name: "ChannelID-NPN-Server",
3912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003913 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003914 ChannelID: channelIDKey,
3915 NextProtos: []string{"bar"},
3916 },
3917 flags: []string{
3918 "-expect-channel-id",
3919 base64.StdEncoding.EncodeToString(channelIDBytes),
3920 "-advertise-npn", "\x03foo\x03bar\x03baz",
3921 "-expect-next-proto", "bar",
3922 },
3923 resumeSession: true,
3924 expectChannelID: true,
3925 expectedNextProto: "bar",
3926 expectedNextProtoType: npn,
3927 })
3928
David Benjamin30789da2015-08-29 22:56:45 -04003929 // Bidirectional shutdown with the runner initiating.
3930 tests = append(tests, testCase{
3931 name: "Shutdown-Runner",
3932 config: Config{
3933 Bugs: ProtocolBugs{
3934 ExpectCloseNotify: true,
3935 },
3936 },
3937 flags: []string{"-check-close-notify"},
3938 })
3939
3940 // Bidirectional shutdown with the shim initiating. The runner,
3941 // in the meantime, sends garbage before the close_notify which
3942 // the shim must ignore.
3943 tests = append(tests, testCase{
3944 name: "Shutdown-Shim",
3945 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003946 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003947 Bugs: ProtocolBugs{
3948 ExpectCloseNotify: true,
3949 },
3950 },
3951 shimShutsDown: true,
3952 sendEmptyRecords: 1,
3953 sendWarningAlerts: 1,
3954 flags: []string{"-check-close-notify"},
3955 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003956 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 // TODO(davidben): DTLS 1.3 will want a similar thing for
3958 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003959 tests = append(tests, testCase{
3960 name: "SkipHelloVerifyRequest",
3961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003962 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 Bugs: ProtocolBugs{
3964 SkipHelloVerifyRequest: true,
3965 },
3966 },
3967 })
3968 }
3969
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003971 test.protocol = config.protocol
3972 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003973 test.name += "-DTLS"
3974 }
David Benjamin582ba042016-07-07 12:33:25 -07003975 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003976 test.name += "-Async"
3977 test.flags = append(test.flags, "-async")
3978 } else {
3979 test.name += "-Sync"
3980 }
David Benjamin582ba042016-07-07 12:33:25 -07003981 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003982 test.name += "-SplitHandshakeRecords"
3983 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003984 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003985 test.config.Bugs.MaxPacketLength = 256
3986 test.flags = append(test.flags, "-mtu", "256")
3987 }
3988 }
David Benjamin582ba042016-07-07 12:33:25 -07003989 if config.packHandshakeFlight {
3990 test.name += "-PackHandshakeFlight"
3991 test.config.Bugs.PackHandshakeFlight = true
3992 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003993 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003994 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003995}
3996
Adam Langley524e7172015-02-20 16:04:00 -08003997func addDDoSCallbackTests() {
3998 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003999 for _, resume := range []bool{false, true} {
4000 suffix := "Resume"
4001 if resume {
4002 suffix = "No" + suffix
4003 }
4004
4005 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004006 testType: serverTest,
4007 name: "Server-DDoS-OK-" + suffix,
4008 config: Config{
4009 MaxVersion: VersionTLS12,
4010 },
Adam Langley524e7172015-02-20 16:04:00 -08004011 flags: []string{"-install-ddos-callback"},
4012 resumeSession: resume,
4013 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004014 testCases = append(testCases, testCase{
4015 testType: serverTest,
4016 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4017 config: Config{
4018 MaxVersion: VersionTLS13,
4019 },
4020 flags: []string{"-install-ddos-callback"},
4021 resumeSession: resume,
4022 })
Adam Langley524e7172015-02-20 16:04:00 -08004023
4024 failFlag := "-fail-ddos-callback"
4025 if resume {
4026 failFlag = "-fail-second-ddos-callback"
4027 }
4028 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004029 testType: serverTest,
4030 name: "Server-DDoS-Reject-" + suffix,
4031 config: Config{
4032 MaxVersion: VersionTLS12,
4033 },
David Benjamin2c66e072016-09-16 15:58:00 -04004034 flags: []string{"-install-ddos-callback", failFlag},
4035 resumeSession: resume,
4036 shouldFail: true,
4037 expectedError: ":CONNECTION_REJECTED:",
4038 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004039 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004040 testCases = append(testCases, testCase{
4041 testType: serverTest,
4042 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4043 config: Config{
4044 MaxVersion: VersionTLS13,
4045 },
David Benjamin2c66e072016-09-16 15:58:00 -04004046 flags: []string{"-install-ddos-callback", failFlag},
4047 resumeSession: resume,
4048 shouldFail: true,
4049 expectedError: ":CONNECTION_REJECTED:",
4050 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004051 })
Adam Langley524e7172015-02-20 16:04:00 -08004052 }
4053}
4054
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004055func addVersionNegotiationTests() {
4056 for i, shimVers := range tlsVersions {
4057 // Assemble flags to disable all newer versions on the shim.
4058 var flags []string
4059 for _, vers := range tlsVersions[i+1:] {
4060 flags = append(flags, vers.flag)
4061 }
4062
4063 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004064 protocols := []protocol{tls}
4065 if runnerVers.hasDTLS && shimVers.hasDTLS {
4066 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004067 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004068 for _, protocol := range protocols {
4069 expectedVersion := shimVers.version
4070 if runnerVers.version < shimVers.version {
4071 expectedVersion = runnerVers.version
4072 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004073
David Benjamin8b8c0062014-11-23 02:47:52 -05004074 suffix := shimVers.name + "-" + runnerVers.name
4075 if protocol == dtls {
4076 suffix += "-DTLS"
4077 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004078
David Benjamin1eb367c2014-12-12 18:17:51 -05004079 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4080
David Benjamin1e29a6b2014-12-10 02:27:24 -05004081 clientVers := shimVers.version
4082 if clientVers > VersionTLS10 {
4083 clientVers = VersionTLS10
4084 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004085 serverVers := expectedVersion
4086 if expectedVersion >= VersionTLS13 {
4087 serverVers = VersionTLS10
4088 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004089 testCases = append(testCases, testCase{
4090 protocol: protocol,
4091 testType: clientTest,
4092 name: "VersionNegotiation-Client-" + suffix,
4093 config: Config{
4094 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004095 Bugs: ProtocolBugs{
4096 ExpectInitialRecordVersion: clientVers,
4097 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004098 },
4099 flags: flags,
4100 expectedVersion: expectedVersion,
4101 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004102 testCases = append(testCases, testCase{
4103 protocol: protocol,
4104 testType: clientTest,
4105 name: "VersionNegotiation-Client2-" + suffix,
4106 config: Config{
4107 MaxVersion: runnerVers.version,
4108 Bugs: ProtocolBugs{
4109 ExpectInitialRecordVersion: clientVers,
4110 },
4111 },
4112 flags: []string{"-max-version", shimVersFlag},
4113 expectedVersion: expectedVersion,
4114 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004115
4116 testCases = append(testCases, testCase{
4117 protocol: protocol,
4118 testType: serverTest,
4119 name: "VersionNegotiation-Server-" + suffix,
4120 config: Config{
4121 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004122 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004123 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004124 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004125 },
4126 flags: flags,
4127 expectedVersion: expectedVersion,
4128 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004129 testCases = append(testCases, testCase{
4130 protocol: protocol,
4131 testType: serverTest,
4132 name: "VersionNegotiation-Server2-" + suffix,
4133 config: Config{
4134 MaxVersion: runnerVers.version,
4135 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004136 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004137 },
4138 },
4139 flags: []string{"-max-version", shimVersFlag},
4140 expectedVersion: expectedVersion,
4141 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004142 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004143 }
4144 }
David Benjamin95c69562016-06-29 18:15:03 -04004145
4146 // Test for version tolerance.
4147 testCases = append(testCases, testCase{
4148 testType: serverTest,
4149 name: "MinorVersionTolerance",
4150 config: Config{
4151 Bugs: ProtocolBugs{
4152 SendClientVersion: 0x03ff,
4153 },
4154 },
4155 expectedVersion: VersionTLS13,
4156 })
4157 testCases = append(testCases, testCase{
4158 testType: serverTest,
4159 name: "MajorVersionTolerance",
4160 config: Config{
4161 Bugs: ProtocolBugs{
4162 SendClientVersion: 0x0400,
4163 },
4164 },
4165 expectedVersion: VersionTLS13,
4166 })
4167 testCases = append(testCases, testCase{
4168 protocol: dtls,
4169 testType: serverTest,
4170 name: "MinorVersionTolerance-DTLS",
4171 config: Config{
4172 Bugs: ProtocolBugs{
4173 SendClientVersion: 0x03ff,
4174 },
4175 },
4176 expectedVersion: VersionTLS12,
4177 })
4178 testCases = append(testCases, testCase{
4179 protocol: dtls,
4180 testType: serverTest,
4181 name: "MajorVersionTolerance-DTLS",
4182 config: Config{
4183 Bugs: ProtocolBugs{
4184 SendClientVersion: 0x0400,
4185 },
4186 },
4187 expectedVersion: VersionTLS12,
4188 })
4189
4190 // Test that versions below 3.0 are rejected.
4191 testCases = append(testCases, testCase{
4192 testType: serverTest,
4193 name: "VersionTooLow",
4194 config: Config{
4195 Bugs: ProtocolBugs{
4196 SendClientVersion: 0x0200,
4197 },
4198 },
4199 shouldFail: true,
4200 expectedError: ":UNSUPPORTED_PROTOCOL:",
4201 })
4202 testCases = append(testCases, testCase{
4203 protocol: dtls,
4204 testType: serverTest,
4205 name: "VersionTooLow-DTLS",
4206 config: Config{
4207 Bugs: ProtocolBugs{
4208 // 0x0201 is the lowest version expressable in
4209 // DTLS.
4210 SendClientVersion: 0x0201,
4211 },
4212 },
4213 shouldFail: true,
4214 expectedError: ":UNSUPPORTED_PROTOCOL:",
4215 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004216
4217 // Test TLS 1.3's downgrade signal.
4218 testCases = append(testCases, testCase{
4219 name: "Downgrade-TLS12-Client",
4220 config: Config{
4221 Bugs: ProtocolBugs{
4222 NegotiateVersion: VersionTLS12,
4223 },
4224 },
David Benjamin55108632016-08-11 22:01:18 -04004225 // TODO(davidben): This test should fail once TLS 1.3 is final
4226 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004227 })
4228 testCases = append(testCases, testCase{
4229 testType: serverTest,
4230 name: "Downgrade-TLS12-Server",
4231 config: Config{
4232 Bugs: ProtocolBugs{
4233 SendClientVersion: VersionTLS12,
4234 },
4235 },
David Benjamin55108632016-08-11 22:01:18 -04004236 // TODO(davidben): This test should fail once TLS 1.3 is final
4237 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004238 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004239}
4240
David Benjaminaccb4542014-12-12 23:44:33 -05004241func addMinimumVersionTests() {
4242 for i, shimVers := range tlsVersions {
4243 // Assemble flags to disable all older versions on the shim.
4244 var flags []string
4245 for _, vers := range tlsVersions[:i] {
4246 flags = append(flags, vers.flag)
4247 }
4248
4249 for _, runnerVers := range tlsVersions {
4250 protocols := []protocol{tls}
4251 if runnerVers.hasDTLS && shimVers.hasDTLS {
4252 protocols = append(protocols, dtls)
4253 }
4254 for _, protocol := range protocols {
4255 suffix := shimVers.name + "-" + runnerVers.name
4256 if protocol == dtls {
4257 suffix += "-DTLS"
4258 }
4259 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4260
David Benjaminaccb4542014-12-12 23:44:33 -05004261 var expectedVersion uint16
4262 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004263 var expectedClientError, expectedServerError string
4264 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004265 if runnerVers.version >= shimVers.version {
4266 expectedVersion = runnerVers.version
4267 } else {
4268 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004269 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4270 expectedServerLocalError = "remote error: protocol version not supported"
4271 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4272 // If the client's minimum version is TLS 1.3 and the runner's
4273 // maximum is below TLS 1.2, the runner will fail to select a
4274 // cipher before the shim rejects the selected version.
4275 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4276 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4277 } else {
4278 expectedClientError = expectedServerError
4279 expectedClientLocalError = expectedServerLocalError
4280 }
David Benjaminaccb4542014-12-12 23:44:33 -05004281 }
4282
4283 testCases = append(testCases, testCase{
4284 protocol: protocol,
4285 testType: clientTest,
4286 name: "MinimumVersion-Client-" + suffix,
4287 config: Config{
4288 MaxVersion: runnerVers.version,
4289 },
David Benjamin87909c02014-12-13 01:55:01 -05004290 flags: flags,
4291 expectedVersion: expectedVersion,
4292 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004293 expectedError: expectedClientError,
4294 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004295 })
4296 testCases = append(testCases, testCase{
4297 protocol: protocol,
4298 testType: clientTest,
4299 name: "MinimumVersion-Client2-" + suffix,
4300 config: Config{
4301 MaxVersion: runnerVers.version,
4302 },
David Benjamin87909c02014-12-13 01:55:01 -05004303 flags: []string{"-min-version", shimVersFlag},
4304 expectedVersion: expectedVersion,
4305 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004306 expectedError: expectedClientError,
4307 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004308 })
4309
4310 testCases = append(testCases, testCase{
4311 protocol: protocol,
4312 testType: serverTest,
4313 name: "MinimumVersion-Server-" + suffix,
4314 config: Config{
4315 MaxVersion: runnerVers.version,
4316 },
David Benjamin87909c02014-12-13 01:55:01 -05004317 flags: flags,
4318 expectedVersion: expectedVersion,
4319 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004320 expectedError: expectedServerError,
4321 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004322 })
4323 testCases = append(testCases, testCase{
4324 protocol: protocol,
4325 testType: serverTest,
4326 name: "MinimumVersion-Server2-" + suffix,
4327 config: Config{
4328 MaxVersion: runnerVers.version,
4329 },
David Benjamin87909c02014-12-13 01:55:01 -05004330 flags: []string{"-min-version", shimVersFlag},
4331 expectedVersion: expectedVersion,
4332 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004333 expectedError: expectedServerError,
4334 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004335 })
4336 }
4337 }
4338 }
4339}
4340
David Benjamine78bfde2014-09-06 12:45:15 -04004341func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004342 // TODO(davidben): Extensions, where applicable, all move their server
4343 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4344 // tests for both. Also test interaction with 0-RTT when implemented.
4345
David Benjamin97d17d92016-07-14 16:12:00 -04004346 // Repeat extensions tests all versions except SSL 3.0.
4347 for _, ver := range tlsVersions {
4348 if ver.version == VersionSSL30 {
4349 continue
4350 }
4351
David Benjamin97d17d92016-07-14 16:12:00 -04004352 // Test that duplicate extensions are rejected.
4353 testCases = append(testCases, testCase{
4354 testType: clientTest,
4355 name: "DuplicateExtensionClient-" + ver.name,
4356 config: Config{
4357 MaxVersion: ver.version,
4358 Bugs: ProtocolBugs{
4359 DuplicateExtension: true,
4360 },
David Benjamine78bfde2014-09-06 12:45:15 -04004361 },
David Benjamin97d17d92016-07-14 16:12:00 -04004362 shouldFail: true,
4363 expectedLocalError: "remote error: error decoding message",
4364 })
4365 testCases = append(testCases, testCase{
4366 testType: serverTest,
4367 name: "DuplicateExtensionServer-" + ver.name,
4368 config: Config{
4369 MaxVersion: ver.version,
4370 Bugs: ProtocolBugs{
4371 DuplicateExtension: true,
4372 },
David Benjamine78bfde2014-09-06 12:45:15 -04004373 },
David Benjamin97d17d92016-07-14 16:12:00 -04004374 shouldFail: true,
4375 expectedLocalError: "remote error: error decoding message",
4376 })
4377
4378 // Test SNI.
4379 testCases = append(testCases, testCase{
4380 testType: clientTest,
4381 name: "ServerNameExtensionClient-" + ver.name,
4382 config: Config{
4383 MaxVersion: ver.version,
4384 Bugs: ProtocolBugs{
4385 ExpectServerName: "example.com",
4386 },
David Benjamine78bfde2014-09-06 12:45:15 -04004387 },
David Benjamin97d17d92016-07-14 16:12:00 -04004388 flags: []string{"-host-name", "example.com"},
4389 })
4390 testCases = append(testCases, testCase{
4391 testType: clientTest,
4392 name: "ServerNameExtensionClientMismatch-" + ver.name,
4393 config: Config{
4394 MaxVersion: ver.version,
4395 Bugs: ProtocolBugs{
4396 ExpectServerName: "mismatch.com",
4397 },
David Benjamine78bfde2014-09-06 12:45:15 -04004398 },
David Benjamin97d17d92016-07-14 16:12:00 -04004399 flags: []string{"-host-name", "example.com"},
4400 shouldFail: true,
4401 expectedLocalError: "tls: unexpected server name",
4402 })
4403 testCases = append(testCases, testCase{
4404 testType: clientTest,
4405 name: "ServerNameExtensionClientMissing-" + ver.name,
4406 config: Config{
4407 MaxVersion: ver.version,
4408 Bugs: ProtocolBugs{
4409 ExpectServerName: "missing.com",
4410 },
David Benjamine78bfde2014-09-06 12:45:15 -04004411 },
David Benjamin97d17d92016-07-14 16:12:00 -04004412 shouldFail: true,
4413 expectedLocalError: "tls: unexpected server name",
4414 })
4415 testCases = append(testCases, testCase{
4416 testType: serverTest,
4417 name: "ServerNameExtensionServer-" + ver.name,
4418 config: Config{
4419 MaxVersion: ver.version,
4420 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004421 },
David Benjamin97d17d92016-07-14 16:12:00 -04004422 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004423 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004424 })
4425
4426 // Test ALPN.
4427 testCases = append(testCases, testCase{
4428 testType: clientTest,
4429 name: "ALPNClient-" + ver.name,
4430 config: Config{
4431 MaxVersion: ver.version,
4432 NextProtos: []string{"foo"},
4433 },
4434 flags: []string{
4435 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4436 "-expect-alpn", "foo",
4437 },
4438 expectedNextProto: "foo",
4439 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004440 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004441 })
4442 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004443 testType: clientTest,
4444 name: "ALPNClient-Mismatch-" + ver.name,
4445 config: Config{
4446 MaxVersion: ver.version,
4447 Bugs: ProtocolBugs{
4448 SendALPN: "baz",
4449 },
4450 },
4451 flags: []string{
4452 "-advertise-alpn", "\x03foo\x03bar",
4453 },
4454 shouldFail: true,
4455 expectedError: ":INVALID_ALPN_PROTOCOL:",
4456 expectedLocalError: "remote error: illegal parameter",
4457 })
4458 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004459 testType: serverTest,
4460 name: "ALPNServer-" + ver.name,
4461 config: Config{
4462 MaxVersion: ver.version,
4463 NextProtos: []string{"foo", "bar", "baz"},
4464 },
4465 flags: []string{
4466 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4467 "-select-alpn", "foo",
4468 },
4469 expectedNextProto: "foo",
4470 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004471 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004472 })
4473 testCases = append(testCases, testCase{
4474 testType: serverTest,
4475 name: "ALPNServer-Decline-" + ver.name,
4476 config: Config{
4477 MaxVersion: ver.version,
4478 NextProtos: []string{"foo", "bar", "baz"},
4479 },
4480 flags: []string{"-decline-alpn"},
4481 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004482 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004483 })
4484
David Benjamin25fe85b2016-08-09 20:00:32 -04004485 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4486 // called once.
4487 testCases = append(testCases, testCase{
4488 testType: serverTest,
4489 name: "ALPNServer-Async-" + ver.name,
4490 config: Config{
4491 MaxVersion: ver.version,
4492 NextProtos: []string{"foo", "bar", "baz"},
4493 },
4494 flags: []string{
4495 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4496 "-select-alpn", "foo",
4497 "-async",
4498 },
4499 expectedNextProto: "foo",
4500 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004501 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004502 })
4503
David Benjamin97d17d92016-07-14 16:12:00 -04004504 var emptyString string
4505 testCases = append(testCases, testCase{
4506 testType: clientTest,
4507 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4508 config: Config{
4509 MaxVersion: ver.version,
4510 NextProtos: []string{""},
4511 Bugs: ProtocolBugs{
4512 // A server returning an empty ALPN protocol
4513 // should be rejected.
4514 ALPNProtocol: &emptyString,
4515 },
4516 },
4517 flags: []string{
4518 "-advertise-alpn", "\x03foo",
4519 },
4520 shouldFail: true,
4521 expectedError: ":PARSE_TLSEXT:",
4522 })
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004529 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004530 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004531 },
David Benjamin97d17d92016-07-14 16:12:00 -04004532 flags: []string{
4533 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004534 },
David Benjamin97d17d92016-07-14 16:12:00 -04004535 shouldFail: true,
4536 expectedError: ":PARSE_TLSEXT:",
4537 })
4538
4539 // Test NPN and the interaction with ALPN.
4540 if ver.version < VersionTLS13 {
4541 // Test that the server prefers ALPN over NPN.
4542 testCases = append(testCases, testCase{
4543 testType: serverTest,
4544 name: "ALPNServer-Preferred-" + ver.name,
4545 config: Config{
4546 MaxVersion: ver.version,
4547 NextProtos: []string{"foo", "bar", "baz"},
4548 },
4549 flags: []string{
4550 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4551 "-select-alpn", "foo",
4552 "-advertise-npn", "\x03foo\x03bar\x03baz",
4553 },
4554 expectedNextProto: "foo",
4555 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004556 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004557 })
4558 testCases = append(testCases, testCase{
4559 testType: serverTest,
4560 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4561 config: Config{
4562 MaxVersion: ver.version,
4563 NextProtos: []string{"foo", "bar", "baz"},
4564 Bugs: ProtocolBugs{
4565 SwapNPNAndALPN: true,
4566 },
4567 },
4568 flags: []string{
4569 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4570 "-select-alpn", "foo",
4571 "-advertise-npn", "\x03foo\x03bar\x03baz",
4572 },
4573 expectedNextProto: "foo",
4574 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004575 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004576 })
4577
4578 // Test that negotiating both NPN and ALPN is forbidden.
4579 testCases = append(testCases, testCase{
4580 name: "NegotiateALPNAndNPN-" + ver.name,
4581 config: Config{
4582 MaxVersion: ver.version,
4583 NextProtos: []string{"foo", "bar", "baz"},
4584 Bugs: ProtocolBugs{
4585 NegotiateALPNAndNPN: true,
4586 },
4587 },
4588 flags: []string{
4589 "-advertise-alpn", "\x03foo",
4590 "-select-next-proto", "foo",
4591 },
4592 shouldFail: true,
4593 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4594 })
4595 testCases = append(testCases, testCase{
4596 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4597 config: Config{
4598 MaxVersion: ver.version,
4599 NextProtos: []string{"foo", "bar", "baz"},
4600 Bugs: ProtocolBugs{
4601 NegotiateALPNAndNPN: true,
4602 SwapNPNAndALPN: true,
4603 },
4604 },
4605 flags: []string{
4606 "-advertise-alpn", "\x03foo",
4607 "-select-next-proto", "foo",
4608 },
4609 shouldFail: true,
4610 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4611 })
4612
4613 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4614 testCases = append(testCases, testCase{
4615 name: "DisableNPN-" + ver.name,
4616 config: Config{
4617 MaxVersion: ver.version,
4618 NextProtos: []string{"foo"},
4619 },
4620 flags: []string{
4621 "-select-next-proto", "foo",
4622 "-disable-npn",
4623 },
4624 expectNoNextProto: true,
4625 })
4626 }
4627
4628 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004629
4630 // Resume with a corrupt ticket.
4631 testCases = append(testCases, testCase{
4632 testType: serverTest,
4633 name: "CorruptTicket-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 Bugs: ProtocolBugs{
4637 CorruptTicket: true,
4638 },
4639 },
4640 resumeSession: true,
4641 expectResumeRejected: true,
4642 })
4643 // Test the ticket callback, with and without renewal.
4644 testCases = append(testCases, testCase{
4645 testType: serverTest,
4646 name: "TicketCallback-" + ver.name,
4647 config: Config{
4648 MaxVersion: ver.version,
4649 },
4650 resumeSession: true,
4651 flags: []string{"-use-ticket-callback"},
4652 })
4653 testCases = append(testCases, testCase{
4654 testType: serverTest,
4655 name: "TicketCallback-Renew-" + ver.name,
4656 config: Config{
4657 MaxVersion: ver.version,
4658 Bugs: ProtocolBugs{
4659 ExpectNewTicket: true,
4660 },
4661 },
4662 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4663 resumeSession: true,
4664 })
4665
4666 // Test that the ticket callback is only called once when everything before
4667 // it in the ClientHello is asynchronous. This corrupts the ticket so
4668 // certificate selection callbacks run.
4669 testCases = append(testCases, testCase{
4670 testType: serverTest,
4671 name: "TicketCallback-SingleCall-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 Bugs: ProtocolBugs{
4675 CorruptTicket: true,
4676 },
4677 },
4678 resumeSession: true,
4679 expectResumeRejected: true,
4680 flags: []string{
4681 "-use-ticket-callback",
4682 "-async",
4683 },
4684 })
4685
4686 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004687 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004688 testCases = append(testCases, testCase{
4689 testType: serverTest,
4690 name: "OversizedSessionId-" + ver.name,
4691 config: Config{
4692 MaxVersion: ver.version,
4693 Bugs: ProtocolBugs{
4694 OversizedSessionId: true,
4695 },
4696 },
4697 resumeSession: true,
4698 shouldFail: true,
4699 expectedError: ":DECODE_ERROR:",
4700 })
4701 }
4702
4703 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4704 // are ignored.
4705 if ver.hasDTLS {
4706 testCases = append(testCases, testCase{
4707 protocol: dtls,
4708 name: "SRTP-Client-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4712 },
4713 flags: []string{
4714 "-srtp-profiles",
4715 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4716 },
4717 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4718 })
4719 testCases = append(testCases, testCase{
4720 protocol: dtls,
4721 testType: serverTest,
4722 name: "SRTP-Server-" + ver.name,
4723 config: Config{
4724 MaxVersion: ver.version,
4725 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4726 },
4727 flags: []string{
4728 "-srtp-profiles",
4729 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4730 },
4731 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4732 })
4733 // Test that the MKI is ignored.
4734 testCases = append(testCases, testCase{
4735 protocol: dtls,
4736 testType: serverTest,
4737 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4738 config: Config{
4739 MaxVersion: ver.version,
4740 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4741 Bugs: ProtocolBugs{
4742 SRTPMasterKeyIdentifer: "bogus",
4743 },
4744 },
4745 flags: []string{
4746 "-srtp-profiles",
4747 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4748 },
4749 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4750 })
4751 // Test that SRTP isn't negotiated on the server if there were
4752 // no matching profiles.
4753 testCases = append(testCases, testCase{
4754 protocol: dtls,
4755 testType: serverTest,
4756 name: "SRTP-Server-NoMatch-" + ver.name,
4757 config: Config{
4758 MaxVersion: ver.version,
4759 SRTPProtectionProfiles: []uint16{100, 101, 102},
4760 },
4761 flags: []string{
4762 "-srtp-profiles",
4763 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4764 },
4765 expectedSRTPProtectionProfile: 0,
4766 })
4767 // Test that the server returning an invalid SRTP profile is
4768 // flagged as an error by the client.
4769 testCases = append(testCases, testCase{
4770 protocol: dtls,
4771 name: "SRTP-Client-NoMatch-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 Bugs: ProtocolBugs{
4775 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4776 },
4777 },
4778 flags: []string{
4779 "-srtp-profiles",
4780 "SRTP_AES128_CM_SHA1_80",
4781 },
4782 shouldFail: true,
4783 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4784 })
4785 }
4786
4787 // Test SCT list.
4788 testCases = append(testCases, testCase{
4789 name: "SignedCertificateTimestampList-Client-" + ver.name,
4790 testType: clientTest,
4791 config: Config{
4792 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004793 },
David Benjamin97d17d92016-07-14 16:12:00 -04004794 flags: []string{
4795 "-enable-signed-cert-timestamps",
4796 "-expect-signed-cert-timestamps",
4797 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004798 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004799 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004800 })
4801 testCases = append(testCases, testCase{
4802 name: "SendSCTListOnResume-" + ver.name,
4803 config: Config{
4804 MaxVersion: ver.version,
4805 Bugs: ProtocolBugs{
4806 SendSCTListOnResume: []byte("bogus"),
4807 },
David Benjamind98452d2015-06-16 14:16:23 -04004808 },
David Benjamin97d17d92016-07-14 16:12:00 -04004809 flags: []string{
4810 "-enable-signed-cert-timestamps",
4811 "-expect-signed-cert-timestamps",
4812 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004813 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004814 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004815 })
4816 testCases = append(testCases, testCase{
4817 name: "SignedCertificateTimestampList-Server-" + ver.name,
4818 testType: serverTest,
4819 config: Config{
4820 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004821 },
David Benjamin97d17d92016-07-14 16:12:00 -04004822 flags: []string{
4823 "-signed-cert-timestamps",
4824 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004825 },
David Benjamin97d17d92016-07-14 16:12:00 -04004826 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004827 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004828 })
4829 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004830
Paul Lietar4fac72e2015-09-09 13:44:55 +01004831 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004832 testType: clientTest,
4833 name: "ClientHelloPadding",
4834 config: Config{
4835 Bugs: ProtocolBugs{
4836 RequireClientHelloSize: 512,
4837 },
4838 },
4839 // This hostname just needs to be long enough to push the
4840 // ClientHello into F5's danger zone between 256 and 511 bytes
4841 // long.
4842 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4843 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004844
4845 // Extensions should not function in SSL 3.0.
4846 testCases = append(testCases, testCase{
4847 testType: serverTest,
4848 name: "SSLv3Extensions-NoALPN",
4849 config: Config{
4850 MaxVersion: VersionSSL30,
4851 NextProtos: []string{"foo", "bar", "baz"},
4852 },
4853 flags: []string{
4854 "-select-alpn", "foo",
4855 },
4856 expectNoNextProto: true,
4857 })
4858
4859 // Test session tickets separately as they follow a different codepath.
4860 testCases = append(testCases, testCase{
4861 testType: serverTest,
4862 name: "SSLv3Extensions-NoTickets",
4863 config: Config{
4864 MaxVersion: VersionSSL30,
4865 Bugs: ProtocolBugs{
4866 // Historically, session tickets in SSL 3.0
4867 // failed in different ways depending on whether
4868 // the client supported renegotiation_info.
4869 NoRenegotiationInfo: true,
4870 },
4871 },
4872 resumeSession: true,
4873 })
4874 testCases = append(testCases, testCase{
4875 testType: serverTest,
4876 name: "SSLv3Extensions-NoTickets2",
4877 config: Config{
4878 MaxVersion: VersionSSL30,
4879 },
4880 resumeSession: true,
4881 })
4882
4883 // But SSL 3.0 does send and process renegotiation_info.
4884 testCases = append(testCases, testCase{
4885 testType: serverTest,
4886 name: "SSLv3Extensions-RenegotiationInfo",
4887 config: Config{
4888 MaxVersion: VersionSSL30,
4889 Bugs: ProtocolBugs{
4890 RequireRenegotiationInfo: true,
4891 },
4892 },
4893 })
4894 testCases = append(testCases, testCase{
4895 testType: serverTest,
4896 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4897 config: Config{
4898 MaxVersion: VersionSSL30,
4899 Bugs: ProtocolBugs{
4900 NoRenegotiationInfo: true,
4901 SendRenegotiationSCSV: true,
4902 RequireRenegotiationInfo: true,
4903 },
4904 },
4905 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004906
4907 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4908 // in ServerHello.
4909 testCases = append(testCases, testCase{
4910 name: "NPN-Forbidden-TLS13",
4911 config: Config{
4912 MaxVersion: VersionTLS13,
4913 NextProtos: []string{"foo"},
4914 Bugs: ProtocolBugs{
4915 NegotiateNPNAtAllVersions: true,
4916 },
4917 },
4918 flags: []string{"-select-next-proto", "foo"},
4919 shouldFail: true,
4920 expectedError: ":ERROR_PARSING_EXTENSION:",
4921 })
4922 testCases = append(testCases, testCase{
4923 name: "EMS-Forbidden-TLS13",
4924 config: Config{
4925 MaxVersion: VersionTLS13,
4926 Bugs: ProtocolBugs{
4927 NegotiateEMSAtAllVersions: true,
4928 },
4929 },
4930 shouldFail: true,
4931 expectedError: ":ERROR_PARSING_EXTENSION:",
4932 })
4933 testCases = append(testCases, testCase{
4934 name: "RenegotiationInfo-Forbidden-TLS13",
4935 config: Config{
4936 MaxVersion: VersionTLS13,
4937 Bugs: ProtocolBugs{
4938 NegotiateRenegotiationInfoAtAllVersions: true,
4939 },
4940 },
4941 shouldFail: true,
4942 expectedError: ":ERROR_PARSING_EXTENSION:",
4943 })
4944 testCases = append(testCases, testCase{
4945 name: "ChannelID-Forbidden-TLS13",
4946 config: Config{
4947 MaxVersion: VersionTLS13,
4948 RequestChannelID: true,
4949 Bugs: ProtocolBugs{
4950 NegotiateChannelIDAtAllVersions: true,
4951 },
4952 },
4953 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4954 shouldFail: true,
4955 expectedError: ":ERROR_PARSING_EXTENSION:",
4956 })
4957 testCases = append(testCases, testCase{
4958 name: "Ticket-Forbidden-TLS13",
4959 config: Config{
4960 MaxVersion: VersionTLS12,
4961 },
4962 resumeConfig: &Config{
4963 MaxVersion: VersionTLS13,
4964 Bugs: ProtocolBugs{
4965 AdvertiseTicketExtension: true,
4966 },
4967 },
4968 resumeSession: true,
4969 shouldFail: true,
4970 expectedError: ":ERROR_PARSING_EXTENSION:",
4971 })
4972
4973 // Test that illegal extensions in TLS 1.3 are declined by the server if
4974 // offered in ClientHello. The runner's server will fail if this occurs,
4975 // so we exercise the offering path. (EMS and Renegotiation Info are
4976 // implicit in every test.)
4977 testCases = append(testCases, testCase{
4978 testType: serverTest,
4979 name: "ChannelID-Declined-TLS13",
4980 config: Config{
4981 MaxVersion: VersionTLS13,
4982 ChannelID: channelIDKey,
4983 },
4984 flags: []string{"-enable-channel-id"},
4985 })
4986 testCases = append(testCases, testCase{
4987 testType: serverTest,
4988 name: "NPN-Server",
4989 config: Config{
4990 MaxVersion: VersionTLS13,
4991 NextProtos: []string{"bar"},
4992 },
4993 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4994 })
David Benjamine78bfde2014-09-06 12:45:15 -04004995}
4996
David Benjamin01fe8202014-09-24 15:21:44 -04004997func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004998 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004999 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005000 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5001 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5002 // TLS 1.3 only shares ciphers with TLS 1.2, so
5003 // we skip certain combinations and use a
5004 // different cipher to test with.
5005 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5006 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5007 continue
5008 }
5009 }
5010
David Benjamin8b8c0062014-11-23 02:47:52 -05005011 protocols := []protocol{tls}
5012 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5013 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005014 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005015 for _, protocol := range protocols {
5016 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5017 if protocol == dtls {
5018 suffix += "-DTLS"
5019 }
5020
David Benjaminece3de92015-03-16 18:02:20 -04005021 if sessionVers.version == resumeVers.version {
5022 testCases = append(testCases, testCase{
5023 protocol: protocol,
5024 name: "Resume-Client" + suffix,
5025 resumeSession: true,
5026 config: Config{
5027 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005028 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005029 Bugs: ProtocolBugs{
5030 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5031 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5032 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005033 },
David Benjaminece3de92015-03-16 18:02:20 -04005034 expectedVersion: sessionVers.version,
5035 expectedResumeVersion: resumeVers.version,
5036 })
5037 } else {
David Benjamin405da482016-08-08 17:25:07 -04005038 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5039
5040 // Offering a TLS 1.3 session sends an empty session ID, so
5041 // there is no way to convince a non-lookahead client the
5042 // session was resumed. It will appear to the client that a
5043 // stray ChangeCipherSpec was sent.
5044 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5045 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005046 }
5047
David Benjaminece3de92015-03-16 18:02:20 -04005048 testCases = append(testCases, testCase{
5049 protocol: protocol,
5050 name: "Resume-Client-Mismatch" + suffix,
5051 resumeSession: true,
5052 config: Config{
5053 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005054 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005055 },
David Benjaminece3de92015-03-16 18:02:20 -04005056 expectedVersion: sessionVers.version,
5057 resumeConfig: &Config{
5058 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005059 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005060 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005061 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005062 },
5063 },
5064 expectedResumeVersion: resumeVers.version,
5065 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005066 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005067 })
5068 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005069
5070 testCases = append(testCases, testCase{
5071 protocol: protocol,
5072 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005073 resumeSession: true,
5074 config: Config{
5075 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005076 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 },
5078 expectedVersion: sessionVers.version,
5079 resumeConfig: &Config{
5080 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005081 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005082 },
5083 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005084 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005085 expectedResumeVersion: resumeVers.version,
5086 })
5087
David Benjamin8b8c0062014-11-23 02:47:52 -05005088 testCases = append(testCases, testCase{
5089 protocol: protocol,
5090 testType: serverTest,
5091 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005092 resumeSession: true,
5093 config: Config{
5094 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005095 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005096 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005097 expectedVersion: sessionVers.version,
5098 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005099 resumeConfig: &Config{
5100 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005101 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005102 Bugs: ProtocolBugs{
5103 SendBothTickets: true,
5104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005105 },
5106 expectedResumeVersion: resumeVers.version,
5107 })
5108 }
David Benjamin01fe8202014-09-24 15:21:44 -04005109 }
5110 }
David Benjaminece3de92015-03-16 18:02:20 -04005111
5112 testCases = append(testCases, testCase{
5113 name: "Resume-Client-CipherMismatch",
5114 resumeSession: true,
5115 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005116 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005117 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5118 },
5119 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005120 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005121 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5122 Bugs: ProtocolBugs{
5123 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5124 },
5125 },
5126 shouldFail: true,
5127 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5128 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005129
5130 testCases = append(testCases, testCase{
5131 name: "Resume-Client-CipherMismatch-TLS13",
5132 resumeSession: true,
5133 config: Config{
5134 MaxVersion: VersionTLS13,
5135 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5136 },
5137 resumeConfig: &Config{
5138 MaxVersion: VersionTLS13,
5139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5140 Bugs: ProtocolBugs{
5141 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5142 },
5143 },
5144 shouldFail: true,
5145 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5146 })
David Benjamin01fe8202014-09-24 15:21:44 -04005147}
5148
Adam Langley2ae77d22014-10-28 17:29:33 -07005149func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005150 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005151 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005152 testType: serverTest,
5153 name: "Renegotiate-Server-Forbidden",
5154 config: Config{
5155 MaxVersion: VersionTLS12,
5156 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005157 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005158 shouldFail: true,
5159 expectedError: ":NO_RENEGOTIATION:",
5160 expectedLocalError: "remote error: no renegotiation",
5161 })
Adam Langley5021b222015-06-12 18:27:58 -07005162 // The server shouldn't echo the renegotiation extension unless
5163 // requested by the client.
5164 testCases = append(testCases, testCase{
5165 testType: serverTest,
5166 name: "Renegotiate-Server-NoExt",
5167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005168 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005169 Bugs: ProtocolBugs{
5170 NoRenegotiationInfo: true,
5171 RequireRenegotiationInfo: true,
5172 },
5173 },
5174 shouldFail: true,
5175 expectedLocalError: "renegotiation extension missing",
5176 })
5177 // The renegotiation SCSV should be sufficient for the server to echo
5178 // the extension.
5179 testCases = append(testCases, testCase{
5180 testType: serverTest,
5181 name: "Renegotiate-Server-NoExt-SCSV",
5182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005183 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005184 Bugs: ProtocolBugs{
5185 NoRenegotiationInfo: true,
5186 SendRenegotiationSCSV: true,
5187 RequireRenegotiationInfo: true,
5188 },
5189 },
5190 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005191 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005192 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005194 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005195 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005196 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005197 },
5198 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005199 renegotiate: 1,
5200 flags: []string{
5201 "-renegotiate-freely",
5202 "-expect-total-renegotiations", "1",
5203 },
David Benjamincdea40c2015-03-19 14:09:43 -04005204 })
5205 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005206 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005207 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005209 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005210 Bugs: ProtocolBugs{
5211 EmptyRenegotiationInfo: true,
5212 },
5213 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005214 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005215 shouldFail: true,
5216 expectedError: ":RENEGOTIATION_MISMATCH:",
5217 })
5218 testCases = append(testCases, testCase{
5219 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005220 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005222 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005223 Bugs: ProtocolBugs{
5224 BadRenegotiationInfo: true,
5225 },
5226 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005227 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005228 shouldFail: true,
5229 expectedError: ":RENEGOTIATION_MISMATCH:",
5230 })
5231 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005232 name: "Renegotiate-Client-Downgrade",
5233 renegotiate: 1,
5234 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005235 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005236 Bugs: ProtocolBugs{
5237 NoRenegotiationInfoAfterInitial: true,
5238 },
5239 },
5240 flags: []string{"-renegotiate-freely"},
5241 shouldFail: true,
5242 expectedError: ":RENEGOTIATION_MISMATCH:",
5243 })
5244 testCases = append(testCases, testCase{
5245 name: "Renegotiate-Client-Upgrade",
5246 renegotiate: 1,
5247 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005248 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005249 Bugs: ProtocolBugs{
5250 NoRenegotiationInfoInInitial: true,
5251 },
5252 },
5253 flags: []string{"-renegotiate-freely"},
5254 shouldFail: true,
5255 expectedError: ":RENEGOTIATION_MISMATCH:",
5256 })
5257 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005258 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005259 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005260 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005261 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005262 Bugs: ProtocolBugs{
5263 NoRenegotiationInfo: true,
5264 },
5265 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005266 flags: []string{
5267 "-renegotiate-freely",
5268 "-expect-total-renegotiations", "1",
5269 },
David Benjamincff0b902015-05-15 23:09:47 -04005270 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005271
5272 // Test that the server may switch ciphers on renegotiation without
5273 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005274 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005275 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005276 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005277 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005278 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005279 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005280 },
5281 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005282 flags: []string{
5283 "-renegotiate-freely",
5284 "-expect-total-renegotiations", "1",
5285 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005286 })
5287 testCases = append(testCases, testCase{
5288 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005289 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005290 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005291 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005292 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5293 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005294 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005295 flags: []string{
5296 "-renegotiate-freely",
5297 "-expect-total-renegotiations", "1",
5298 },
David Benjaminb16346b2015-04-08 19:16:58 -04005299 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005300
5301 // Test that the server may not switch versions on renegotiation.
5302 testCases = append(testCases, testCase{
5303 name: "Renegotiate-Client-SwitchVersion",
5304 config: Config{
5305 MaxVersion: VersionTLS12,
5306 // Pick a cipher which exists at both versions.
5307 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5308 Bugs: ProtocolBugs{
5309 NegotiateVersionOnRenego: VersionTLS11,
5310 },
5311 },
5312 renegotiate: 1,
5313 flags: []string{
5314 "-renegotiate-freely",
5315 "-expect-total-renegotiations", "1",
5316 },
5317 shouldFail: true,
5318 expectedError: ":WRONG_SSL_VERSION:",
5319 })
5320
David Benjaminb16346b2015-04-08 19:16:58 -04005321 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005322 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005323 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005324 config: Config{
5325 MaxVersion: VersionTLS10,
5326 Bugs: ProtocolBugs{
5327 RequireSameRenegoClientVersion: true,
5328 },
5329 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005330 flags: []string{
5331 "-renegotiate-freely",
5332 "-expect-total-renegotiations", "1",
5333 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005334 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005335 testCases = append(testCases, testCase{
5336 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005337 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005338 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005339 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005340 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5341 NextProtos: []string{"foo"},
5342 },
5343 flags: []string{
5344 "-false-start",
5345 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005346 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005347 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005348 },
5349 shimWritesFirst: true,
5350 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005351
5352 // Client-side renegotiation controls.
5353 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005354 name: "Renegotiate-Client-Forbidden-1",
5355 config: Config{
5356 MaxVersion: VersionTLS12,
5357 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005358 renegotiate: 1,
5359 shouldFail: true,
5360 expectedError: ":NO_RENEGOTIATION:",
5361 expectedLocalError: "remote error: no renegotiation",
5362 })
5363 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005364 name: "Renegotiate-Client-Once-1",
5365 config: Config{
5366 MaxVersion: VersionTLS12,
5367 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005368 renegotiate: 1,
5369 flags: []string{
5370 "-renegotiate-once",
5371 "-expect-total-renegotiations", "1",
5372 },
5373 })
5374 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005375 name: "Renegotiate-Client-Freely-1",
5376 config: Config{
5377 MaxVersion: VersionTLS12,
5378 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005379 renegotiate: 1,
5380 flags: []string{
5381 "-renegotiate-freely",
5382 "-expect-total-renegotiations", "1",
5383 },
5384 })
5385 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005386 name: "Renegotiate-Client-Once-2",
5387 config: Config{
5388 MaxVersion: VersionTLS12,
5389 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005390 renegotiate: 2,
5391 flags: []string{"-renegotiate-once"},
5392 shouldFail: true,
5393 expectedError: ":NO_RENEGOTIATION:",
5394 expectedLocalError: "remote error: no renegotiation",
5395 })
5396 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005397 name: "Renegotiate-Client-Freely-2",
5398 config: Config{
5399 MaxVersion: VersionTLS12,
5400 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005401 renegotiate: 2,
5402 flags: []string{
5403 "-renegotiate-freely",
5404 "-expect-total-renegotiations", "2",
5405 },
5406 })
Adam Langley27a0d082015-11-03 13:34:10 -08005407 testCases = append(testCases, testCase{
5408 name: "Renegotiate-Client-NoIgnore",
5409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005410 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005411 Bugs: ProtocolBugs{
5412 SendHelloRequestBeforeEveryAppDataRecord: true,
5413 },
5414 },
5415 shouldFail: true,
5416 expectedError: ":NO_RENEGOTIATION:",
5417 })
5418 testCases = append(testCases, testCase{
5419 name: "Renegotiate-Client-Ignore",
5420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005421 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005422 Bugs: ProtocolBugs{
5423 SendHelloRequestBeforeEveryAppDataRecord: true,
5424 },
5425 },
5426 flags: []string{
5427 "-renegotiate-ignore",
5428 "-expect-total-renegotiations", "0",
5429 },
5430 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005431
David Benjamin397c8e62016-07-08 14:14:36 -07005432 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005433 testCases = append(testCases, testCase{
5434 name: "StrayHelloRequest",
5435 config: Config{
5436 MaxVersion: VersionTLS12,
5437 Bugs: ProtocolBugs{
5438 SendHelloRequestBeforeEveryHandshakeMessage: true,
5439 },
5440 },
5441 })
5442 testCases = append(testCases, testCase{
5443 name: "StrayHelloRequest-Packed",
5444 config: Config{
5445 MaxVersion: VersionTLS12,
5446 Bugs: ProtocolBugs{
5447 PackHandshakeFlight: true,
5448 SendHelloRequestBeforeEveryHandshakeMessage: true,
5449 },
5450 },
5451 })
5452
David Benjamin12d2c482016-07-24 10:56:51 -04005453 // Test renegotiation works if HelloRequest and server Finished come in
5454 // the same record.
5455 testCases = append(testCases, testCase{
5456 name: "Renegotiate-Client-Packed",
5457 config: Config{
5458 MaxVersion: VersionTLS12,
5459 Bugs: ProtocolBugs{
5460 PackHandshakeFlight: true,
5461 PackHelloRequestWithFinished: true,
5462 },
5463 },
5464 renegotiate: 1,
5465 flags: []string{
5466 "-renegotiate-freely",
5467 "-expect-total-renegotiations", "1",
5468 },
5469 })
5470
David Benjamin397c8e62016-07-08 14:14:36 -07005471 // Renegotiation is forbidden in TLS 1.3.
5472 testCases = append(testCases, testCase{
5473 name: "Renegotiate-Client-TLS13",
5474 config: Config{
5475 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005476 Bugs: ProtocolBugs{
5477 SendHelloRequestBeforeEveryAppDataRecord: true,
5478 },
David Benjamin397c8e62016-07-08 14:14:36 -07005479 },
David Benjamin397c8e62016-07-08 14:14:36 -07005480 flags: []string{
5481 "-renegotiate-freely",
5482 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005483 shouldFail: true,
5484 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005485 })
5486
5487 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5488 testCases = append(testCases, testCase{
5489 name: "StrayHelloRequest-TLS13",
5490 config: Config{
5491 MaxVersion: VersionTLS13,
5492 Bugs: ProtocolBugs{
5493 SendHelloRequestBeforeEveryHandshakeMessage: true,
5494 },
5495 },
5496 shouldFail: true,
5497 expectedError: ":UNEXPECTED_MESSAGE:",
5498 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005499}
5500
David Benjamin5e961c12014-11-07 01:48:35 -05005501func addDTLSReplayTests() {
5502 // Test that sequence number replays are detected.
5503 testCases = append(testCases, testCase{
5504 protocol: dtls,
5505 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005506 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005507 replayWrites: true,
5508 })
5509
David Benjamin8e6db492015-07-25 18:29:23 -04005510 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005511 // than the retransmit window.
5512 testCases = append(testCases, testCase{
5513 protocol: dtls,
5514 name: "DTLS-Replay-LargeGaps",
5515 config: Config{
5516 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005517 SequenceNumberMapping: func(in uint64) uint64 {
5518 return in * 127
5519 },
David Benjamin5e961c12014-11-07 01:48:35 -05005520 },
5521 },
David Benjamin8e6db492015-07-25 18:29:23 -04005522 messageCount: 200,
5523 replayWrites: true,
5524 })
5525
5526 // Test the incoming sequence number changing non-monotonically.
5527 testCases = append(testCases, testCase{
5528 protocol: dtls,
5529 name: "DTLS-Replay-NonMonotonic",
5530 config: Config{
5531 Bugs: ProtocolBugs{
5532 SequenceNumberMapping: func(in uint64) uint64 {
5533 return in ^ 31
5534 },
5535 },
5536 },
5537 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005538 replayWrites: true,
5539 })
5540}
5541
Nick Harper60edffd2016-06-21 15:19:24 -07005542var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005543 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005544 id signatureAlgorithm
5545 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005546}{
Nick Harper60edffd2016-06-21 15:19:24 -07005547 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5548 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5549 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5550 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005551 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005552 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5553 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5554 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005555 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5556 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5557 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005558 // Tests for key types prior to TLS 1.2.
5559 {"RSA", 0, testCertRSA},
5560 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005561}
5562
Nick Harper60edffd2016-06-21 15:19:24 -07005563const fakeSigAlg1 signatureAlgorithm = 0x2a01
5564const fakeSigAlg2 signatureAlgorithm = 0xff01
5565
5566func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005567 // Not all ciphers involve a signature. Advertise a list which gives all
5568 // versions a signing cipher.
5569 signingCiphers := []uint16{
5570 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5571 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5572 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5573 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5574 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5575 }
5576
David Benjaminca3d5452016-07-14 12:51:01 -04005577 var allAlgorithms []signatureAlgorithm
5578 for _, alg := range testSignatureAlgorithms {
5579 if alg.id != 0 {
5580 allAlgorithms = append(allAlgorithms, alg.id)
5581 }
5582 }
5583
Nick Harper60edffd2016-06-21 15:19:24 -07005584 // Make sure each signature algorithm works. Include some fake values in
5585 // the list and ensure they're ignored.
5586 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005587 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005588 if (ver.version < VersionTLS12) != (alg.id == 0) {
5589 continue
5590 }
5591
5592 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5593 // or remove it in C.
5594 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005595 continue
5596 }
Nick Harper60edffd2016-06-21 15:19:24 -07005597
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005598 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005599 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005600 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5601 shouldFail = true
5602 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005603 // RSA-PKCS1 does not exist in TLS 1.3.
5604 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5605 shouldFail = true
5606 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005607
5608 var signError, verifyError string
5609 if shouldFail {
5610 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5611 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005612 }
David Benjamin000800a2014-11-14 01:43:59 -05005613
David Benjamin1fb125c2016-07-08 18:52:12 -07005614 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005615
David Benjamin7a41d372016-07-09 11:21:54 -07005616 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005617 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005618 config: Config{
5619 MaxVersion: ver.version,
5620 ClientAuth: RequireAnyClientCert,
5621 VerifySignatureAlgorithms: []signatureAlgorithm{
5622 fakeSigAlg1,
5623 alg.id,
5624 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005625 },
David Benjamin7a41d372016-07-09 11:21:54 -07005626 },
5627 flags: []string{
5628 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5629 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5630 "-enable-all-curves",
5631 },
5632 shouldFail: shouldFail,
5633 expectedError: signError,
5634 expectedPeerSignatureAlgorithm: alg.id,
5635 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005636
David Benjamin7a41d372016-07-09 11:21:54 -07005637 testCases = append(testCases, testCase{
5638 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005639 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005640 config: Config{
5641 MaxVersion: ver.version,
5642 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5643 SignSignatureAlgorithms: []signatureAlgorithm{
5644 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005645 },
David Benjamin7a41d372016-07-09 11:21:54 -07005646 Bugs: ProtocolBugs{
5647 SkipECDSACurveCheck: shouldFail,
5648 IgnoreSignatureVersionChecks: shouldFail,
5649 // The client won't advertise 1.3-only algorithms after
5650 // version negotiation.
5651 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005652 },
David Benjamin7a41d372016-07-09 11:21:54 -07005653 },
5654 flags: []string{
5655 "-require-any-client-certificate",
5656 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5657 "-enable-all-curves",
5658 },
5659 shouldFail: shouldFail,
5660 expectedError: verifyError,
5661 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005662
5663 testCases = append(testCases, testCase{
5664 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005665 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005666 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005667 MaxVersion: ver.version,
5668 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005669 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005670 fakeSigAlg1,
5671 alg.id,
5672 fakeSigAlg2,
5673 },
5674 },
5675 flags: []string{
5676 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5677 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5678 "-enable-all-curves",
5679 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005680 shouldFail: shouldFail,
5681 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005682 expectedPeerSignatureAlgorithm: alg.id,
5683 })
5684
5685 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005686 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005687 config: Config{
5688 MaxVersion: ver.version,
5689 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005690 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005691 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005692 alg.id,
5693 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005694 Bugs: ProtocolBugs{
5695 SkipECDSACurveCheck: shouldFail,
5696 IgnoreSignatureVersionChecks: shouldFail,
5697 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005698 },
5699 flags: []string{
5700 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5701 "-enable-all-curves",
5702 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005703 shouldFail: shouldFail,
5704 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005705 })
David Benjamin5208fd42016-07-13 21:43:25 -04005706
5707 if !shouldFail {
5708 testCases = append(testCases, testCase{
5709 testType: serverTest,
5710 name: "ClientAuth-InvalidSignature" + suffix,
5711 config: Config{
5712 MaxVersion: ver.version,
5713 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5714 SignSignatureAlgorithms: []signatureAlgorithm{
5715 alg.id,
5716 },
5717 Bugs: ProtocolBugs{
5718 InvalidSignature: true,
5719 },
5720 },
5721 flags: []string{
5722 "-require-any-client-certificate",
5723 "-enable-all-curves",
5724 },
5725 shouldFail: true,
5726 expectedError: ":BAD_SIGNATURE:",
5727 })
5728
5729 testCases = append(testCases, testCase{
5730 name: "ServerAuth-InvalidSignature" + suffix,
5731 config: Config{
5732 MaxVersion: ver.version,
5733 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5734 CipherSuites: signingCiphers,
5735 SignSignatureAlgorithms: []signatureAlgorithm{
5736 alg.id,
5737 },
5738 Bugs: ProtocolBugs{
5739 InvalidSignature: true,
5740 },
5741 },
5742 flags: []string{"-enable-all-curves"},
5743 shouldFail: true,
5744 expectedError: ":BAD_SIGNATURE:",
5745 })
5746 }
David Benjaminca3d5452016-07-14 12:51:01 -04005747
5748 if ver.version >= VersionTLS12 && !shouldFail {
5749 testCases = append(testCases, testCase{
5750 name: "ClientAuth-Sign-Negotiate" + suffix,
5751 config: Config{
5752 MaxVersion: ver.version,
5753 ClientAuth: RequireAnyClientCert,
5754 VerifySignatureAlgorithms: allAlgorithms,
5755 },
5756 flags: []string{
5757 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5758 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5759 "-enable-all-curves",
5760 "-signing-prefs", strconv.Itoa(int(alg.id)),
5761 },
5762 expectedPeerSignatureAlgorithm: alg.id,
5763 })
5764
5765 testCases = append(testCases, testCase{
5766 testType: serverTest,
5767 name: "ServerAuth-Sign-Negotiate" + suffix,
5768 config: Config{
5769 MaxVersion: ver.version,
5770 CipherSuites: signingCiphers,
5771 VerifySignatureAlgorithms: allAlgorithms,
5772 },
5773 flags: []string{
5774 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5775 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5776 "-enable-all-curves",
5777 "-signing-prefs", strconv.Itoa(int(alg.id)),
5778 },
5779 expectedPeerSignatureAlgorithm: alg.id,
5780 })
5781 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005782 }
David Benjamin000800a2014-11-14 01:43:59 -05005783 }
5784
Nick Harper60edffd2016-06-21 15:19:24 -07005785 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005786 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005787 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005788 config: Config{
5789 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005790 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005791 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005792 signatureECDSAWithP521AndSHA512,
5793 signatureRSAPKCS1WithSHA384,
5794 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005795 },
5796 },
5797 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005798 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5799 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005800 },
Nick Harper60edffd2016-06-21 15:19:24 -07005801 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005802 })
5803
5804 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005805 name: "ClientAuth-SignatureType-TLS13",
5806 config: Config{
5807 ClientAuth: RequireAnyClientCert,
5808 MaxVersion: VersionTLS13,
5809 VerifySignatureAlgorithms: []signatureAlgorithm{
5810 signatureECDSAWithP521AndSHA512,
5811 signatureRSAPKCS1WithSHA384,
5812 signatureRSAPSSWithSHA384,
5813 signatureECDSAWithSHA1,
5814 },
5815 },
5816 flags: []string{
5817 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5818 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5819 },
5820 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5821 })
5822
5823 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005824 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005825 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005827 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005829 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005830 signatureECDSAWithP521AndSHA512,
5831 signatureRSAPKCS1WithSHA384,
5832 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005833 },
5834 },
Nick Harper60edffd2016-06-21 15:19:24 -07005835 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005836 })
5837
Steven Valdez143e8b32016-07-11 13:19:03 -04005838 testCases = append(testCases, testCase{
5839 testType: serverTest,
5840 name: "ServerAuth-SignatureType-TLS13",
5841 config: Config{
5842 MaxVersion: VersionTLS13,
5843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5844 VerifySignatureAlgorithms: []signatureAlgorithm{
5845 signatureECDSAWithP521AndSHA512,
5846 signatureRSAPKCS1WithSHA384,
5847 signatureRSAPSSWithSHA384,
5848 signatureECDSAWithSHA1,
5849 },
5850 },
5851 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5852 })
5853
David Benjamina95e9f32016-07-08 16:28:04 -07005854 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005855 testCases = append(testCases, testCase{
5856 testType: serverTest,
5857 name: "Verify-ClientAuth-SignatureType",
5858 config: Config{
5859 MaxVersion: VersionTLS12,
5860 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005861 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005862 signatureRSAPKCS1WithSHA256,
5863 },
5864 Bugs: ProtocolBugs{
5865 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5866 },
5867 },
5868 flags: []string{
5869 "-require-any-client-certificate",
5870 },
5871 shouldFail: true,
5872 expectedError: ":WRONG_SIGNATURE_TYPE:",
5873 })
5874
5875 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005876 testType: serverTest,
5877 name: "Verify-ClientAuth-SignatureType-TLS13",
5878 config: Config{
5879 MaxVersion: VersionTLS13,
5880 Certificates: []Certificate{rsaCertificate},
5881 SignSignatureAlgorithms: []signatureAlgorithm{
5882 signatureRSAPSSWithSHA256,
5883 },
5884 Bugs: ProtocolBugs{
5885 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5886 },
5887 },
5888 flags: []string{
5889 "-require-any-client-certificate",
5890 },
5891 shouldFail: true,
5892 expectedError: ":WRONG_SIGNATURE_TYPE:",
5893 })
5894
5895 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005896 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005897 config: Config{
5898 MaxVersion: VersionTLS12,
5899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005900 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005901 signatureRSAPKCS1WithSHA256,
5902 },
5903 Bugs: ProtocolBugs{
5904 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5905 },
5906 },
5907 shouldFail: true,
5908 expectedError: ":WRONG_SIGNATURE_TYPE:",
5909 })
5910
Steven Valdez143e8b32016-07-11 13:19:03 -04005911 testCases = append(testCases, testCase{
5912 name: "Verify-ServerAuth-SignatureType-TLS13",
5913 config: Config{
5914 MaxVersion: VersionTLS13,
5915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5916 SignSignatureAlgorithms: []signatureAlgorithm{
5917 signatureRSAPSSWithSHA256,
5918 },
5919 Bugs: ProtocolBugs{
5920 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5921 },
5922 },
5923 shouldFail: true,
5924 expectedError: ":WRONG_SIGNATURE_TYPE:",
5925 })
5926
David Benjamin51dd7d62016-07-08 16:07:01 -07005927 // Test that, if the list is missing, the peer falls back to SHA-1 in
5928 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005929 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005930 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005932 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005933 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005934 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005935 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005936 },
5937 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005938 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005939 },
5940 },
5941 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005942 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5943 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005944 },
5945 })
5946
5947 testCases = append(testCases, testCase{
5948 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005949 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005950 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005951 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005952 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005953 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005954 },
5955 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005956 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005957 },
5958 },
David Benjaminee32bea2016-08-17 13:36:44 -04005959 flags: []string{
5960 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5961 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5962 },
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 name: "ClientAuth-SHA1-Fallback-ECDSA",
5967 config: Config{
5968 MaxVersion: VersionTLS12,
5969 ClientAuth: RequireAnyClientCert,
5970 VerifySignatureAlgorithms: []signatureAlgorithm{
5971 signatureECDSAWithSHA1,
5972 },
5973 Bugs: ProtocolBugs{
5974 NoSignatureAlgorithms: true,
5975 },
5976 },
5977 flags: []string{
5978 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5979 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5980 },
5981 })
5982
5983 testCases = append(testCases, testCase{
5984 testType: serverTest,
5985 name: "ServerAuth-SHA1-Fallback-ECDSA",
5986 config: Config{
5987 MaxVersion: VersionTLS12,
5988 VerifySignatureAlgorithms: []signatureAlgorithm{
5989 signatureECDSAWithSHA1,
5990 },
5991 Bugs: ProtocolBugs{
5992 NoSignatureAlgorithms: true,
5993 },
5994 },
5995 flags: []string{
5996 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5997 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5998 },
David Benjamin000800a2014-11-14 01:43:59 -05005999 })
David Benjamin72dc7832015-03-16 17:49:43 -04006000
David Benjamin51dd7d62016-07-08 16:07:01 -07006001 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006002 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006003 config: Config{
6004 MaxVersion: VersionTLS13,
6005 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006006 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006007 signatureRSAPKCS1WithSHA1,
6008 },
6009 Bugs: ProtocolBugs{
6010 NoSignatureAlgorithms: true,
6011 },
6012 },
6013 flags: []string{
6014 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6015 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6016 },
David Benjamin48901652016-08-01 12:12:47 -04006017 shouldFail: true,
6018 // An empty CertificateRequest signature algorithm list is a
6019 // syntax error in TLS 1.3.
6020 expectedError: ":DECODE_ERROR:",
6021 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006022 })
6023
6024 testCases = append(testCases, testCase{
6025 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006026 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006027 config: Config{
6028 MaxVersion: VersionTLS13,
6029 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006030 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006031 signatureRSAPKCS1WithSHA1,
6032 },
6033 Bugs: ProtocolBugs{
6034 NoSignatureAlgorithms: true,
6035 },
6036 },
6037 shouldFail: true,
6038 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6039 })
6040
David Benjaminb62d2872016-07-18 14:55:02 +02006041 // Test that hash preferences are enforced. BoringSSL does not implement
6042 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006043 testCases = append(testCases, testCase{
6044 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006045 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006046 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006047 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006048 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006049 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006050 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006051 },
6052 Bugs: ProtocolBugs{
6053 IgnorePeerSignatureAlgorithmPreferences: true,
6054 },
6055 },
6056 flags: []string{"-require-any-client-certificate"},
6057 shouldFail: true,
6058 expectedError: ":WRONG_SIGNATURE_TYPE:",
6059 })
6060
6061 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006062 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006064 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006066 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006067 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006068 },
6069 Bugs: ProtocolBugs{
6070 IgnorePeerSignatureAlgorithmPreferences: true,
6071 },
6072 },
6073 shouldFail: true,
6074 expectedError: ":WRONG_SIGNATURE_TYPE:",
6075 })
David Benjaminb62d2872016-07-18 14:55:02 +02006076 testCases = append(testCases, testCase{
6077 testType: serverTest,
6078 name: "ClientAuth-Enforced-TLS13",
6079 config: Config{
6080 MaxVersion: VersionTLS13,
6081 Certificates: []Certificate{rsaCertificate},
6082 SignSignatureAlgorithms: []signatureAlgorithm{
6083 signatureRSAPKCS1WithMD5,
6084 },
6085 Bugs: ProtocolBugs{
6086 IgnorePeerSignatureAlgorithmPreferences: true,
6087 IgnoreSignatureVersionChecks: true,
6088 },
6089 },
6090 flags: []string{"-require-any-client-certificate"},
6091 shouldFail: true,
6092 expectedError: ":WRONG_SIGNATURE_TYPE:",
6093 })
6094
6095 testCases = append(testCases, testCase{
6096 name: "ServerAuth-Enforced-TLS13",
6097 config: Config{
6098 MaxVersion: VersionTLS13,
6099 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6100 SignSignatureAlgorithms: []signatureAlgorithm{
6101 signatureRSAPKCS1WithMD5,
6102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 IgnoreSignatureVersionChecks: true,
6106 },
6107 },
6108 shouldFail: true,
6109 expectedError: ":WRONG_SIGNATURE_TYPE:",
6110 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006111
6112 // Test that the agreed upon digest respects the client preferences and
6113 // the server digests.
6114 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006115 name: "NoCommonAlgorithms-Digests",
6116 config: Config{
6117 MaxVersion: VersionTLS12,
6118 ClientAuth: RequireAnyClientCert,
6119 VerifySignatureAlgorithms: []signatureAlgorithm{
6120 signatureRSAPKCS1WithSHA512,
6121 signatureRSAPKCS1WithSHA1,
6122 },
6123 },
6124 flags: []string{
6125 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6126 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6127 "-digest-prefs", "SHA256",
6128 },
6129 shouldFail: true,
6130 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6131 })
6132 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006133 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006135 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006136 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006137 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006138 signatureRSAPKCS1WithSHA512,
6139 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006140 },
6141 },
6142 flags: []string{
6143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006145 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006146 },
David Benjaminca3d5452016-07-14 12:51:01 -04006147 shouldFail: true,
6148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6149 })
6150 testCases = append(testCases, testCase{
6151 name: "NoCommonAlgorithms-TLS13",
6152 config: Config{
6153 MaxVersion: VersionTLS13,
6154 ClientAuth: RequireAnyClientCert,
6155 VerifySignatureAlgorithms: []signatureAlgorithm{
6156 signatureRSAPSSWithSHA512,
6157 signatureRSAPSSWithSHA384,
6158 },
6159 },
6160 flags: []string{
6161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6163 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6164 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006165 shouldFail: true,
6166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006167 })
6168 testCases = append(testCases, testCase{
6169 name: "Agree-Digest-SHA256",
6170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006172 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006173 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006174 signatureRSAPKCS1WithSHA1,
6175 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006176 },
6177 },
6178 flags: []string{
6179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006181 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006182 },
Nick Harper60edffd2016-06-21 15:19:24 -07006183 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006184 })
6185 testCases = append(testCases, testCase{
6186 name: "Agree-Digest-SHA1",
6187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006188 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006189 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006190 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006191 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006192 },
6193 },
6194 flags: []string{
6195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006197 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006198 },
Nick Harper60edffd2016-06-21 15:19:24 -07006199 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006200 })
6201 testCases = append(testCases, testCase{
6202 name: "Agree-Digest-Default",
6203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006204 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006205 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006206 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006207 signatureRSAPKCS1WithSHA256,
6208 signatureECDSAWithP256AndSHA256,
6209 signatureRSAPKCS1WithSHA1,
6210 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006211 },
6212 },
6213 flags: []string{
6214 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6215 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6216 },
Nick Harper60edffd2016-06-21 15:19:24 -07006217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006219
David Benjaminca3d5452016-07-14 12:51:01 -04006220 // Test that the signing preference list may include extra algorithms
6221 // without negotiation problems.
6222 testCases = append(testCases, testCase{
6223 testType: serverTest,
6224 name: "FilterExtraAlgorithms",
6225 config: Config{
6226 MaxVersion: VersionTLS12,
6227 VerifySignatureAlgorithms: []signatureAlgorithm{
6228 signatureRSAPKCS1WithSHA256,
6229 },
6230 },
6231 flags: []string{
6232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6234 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6235 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6236 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6237 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6238 },
6239 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6240 })
6241
David Benjamin4c3ddf72016-06-29 18:13:53 -04006242 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6243 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006244 testCases = append(testCases, testCase{
6245 name: "CheckLeafCurve",
6246 config: Config{
6247 MaxVersion: VersionTLS12,
6248 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006249 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006250 },
6251 flags: []string{"-p384-only"},
6252 shouldFail: true,
6253 expectedError: ":BAD_ECC_CERT:",
6254 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006255
6256 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6257 testCases = append(testCases, testCase{
6258 name: "CheckLeafCurve-TLS13",
6259 config: Config{
6260 MaxVersion: VersionTLS13,
6261 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6262 Certificates: []Certificate{ecdsaP256Certificate},
6263 },
6264 flags: []string{"-p384-only"},
6265 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006266
6267 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6268 testCases = append(testCases, testCase{
6269 name: "ECDSACurveMismatch-Verify-TLS12",
6270 config: Config{
6271 MaxVersion: VersionTLS12,
6272 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6273 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006274 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006275 signatureECDSAWithP384AndSHA384,
6276 },
6277 },
6278 })
6279
6280 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6281 testCases = append(testCases, testCase{
6282 name: "ECDSACurveMismatch-Verify-TLS13",
6283 config: Config{
6284 MaxVersion: VersionTLS13,
6285 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6286 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006287 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006288 signatureECDSAWithP384AndSHA384,
6289 },
6290 Bugs: ProtocolBugs{
6291 SkipECDSACurveCheck: true,
6292 },
6293 },
6294 shouldFail: true,
6295 expectedError: ":WRONG_SIGNATURE_TYPE:",
6296 })
6297
6298 // Signature algorithm selection in TLS 1.3 should take the curve into
6299 // account.
6300 testCases = append(testCases, testCase{
6301 testType: serverTest,
6302 name: "ECDSACurveMismatch-Sign-TLS13",
6303 config: Config{
6304 MaxVersion: VersionTLS13,
6305 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006306 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006307 signatureECDSAWithP384AndSHA384,
6308 signatureECDSAWithP256AndSHA256,
6309 },
6310 },
6311 flags: []string{
6312 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6313 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6314 },
6315 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6316 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006317
6318 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6319 // server does not attempt to sign in that case.
6320 testCases = append(testCases, testCase{
6321 testType: serverTest,
6322 name: "RSA-PSS-Large",
6323 config: Config{
6324 MaxVersion: VersionTLS13,
6325 VerifySignatureAlgorithms: []signatureAlgorithm{
6326 signatureRSAPSSWithSHA512,
6327 },
6328 },
6329 flags: []string{
6330 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6331 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6332 },
6333 shouldFail: true,
6334 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6335 })
David Benjamin57e929f2016-08-30 00:30:38 -04006336
6337 // Test that RSA-PSS is enabled by default for TLS 1.2.
6338 testCases = append(testCases, testCase{
6339 testType: clientTest,
6340 name: "RSA-PSS-Default-Verify",
6341 config: Config{
6342 MaxVersion: VersionTLS12,
6343 SignSignatureAlgorithms: []signatureAlgorithm{
6344 signatureRSAPSSWithSHA256,
6345 },
6346 },
6347 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6348 })
6349
6350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "RSA-PSS-Default-Sign",
6353 config: Config{
6354 MaxVersion: VersionTLS12,
6355 VerifySignatureAlgorithms: []signatureAlgorithm{
6356 signatureRSAPSSWithSHA256,
6357 },
6358 },
6359 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6360 })
David Benjamin000800a2014-11-14 01:43:59 -05006361}
6362
David Benjamin83f90402015-01-27 01:09:43 -05006363// timeouts is the retransmit schedule for BoringSSL. It doubles and
6364// caps at 60 seconds. On the 13th timeout, it gives up.
6365var timeouts = []time.Duration{
6366 1 * time.Second,
6367 2 * time.Second,
6368 4 * time.Second,
6369 8 * time.Second,
6370 16 * time.Second,
6371 32 * time.Second,
6372 60 * time.Second,
6373 60 * time.Second,
6374 60 * time.Second,
6375 60 * time.Second,
6376 60 * time.Second,
6377 60 * time.Second,
6378 60 * time.Second,
6379}
6380
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006381// shortTimeouts is an alternate set of timeouts which would occur if the
6382// initial timeout duration was set to 250ms.
6383var shortTimeouts = []time.Duration{
6384 250 * time.Millisecond,
6385 500 * time.Millisecond,
6386 1 * time.Second,
6387 2 * time.Second,
6388 4 * time.Second,
6389 8 * time.Second,
6390 16 * time.Second,
6391 32 * time.Second,
6392 60 * time.Second,
6393 60 * time.Second,
6394 60 * time.Second,
6395 60 * time.Second,
6396 60 * time.Second,
6397}
6398
David Benjamin83f90402015-01-27 01:09:43 -05006399func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006400 // These tests work by coordinating some behavior on both the shim and
6401 // the runner.
6402 //
6403 // TimeoutSchedule configures the runner to send a series of timeout
6404 // opcodes to the shim (see packetAdaptor) immediately before reading
6405 // each peer handshake flight N. The timeout opcode both simulates a
6406 // timeout in the shim and acts as a synchronization point to help the
6407 // runner bracket each handshake flight.
6408 //
6409 // We assume the shim does not read from the channel eagerly. It must
6410 // first wait until it has sent flight N and is ready to receive
6411 // handshake flight N+1. At this point, it will process the timeout
6412 // opcode. It must then immediately respond with a timeout ACK and act
6413 // as if the shim was idle for the specified amount of time.
6414 //
6415 // The runner then drops all packets received before the ACK and
6416 // continues waiting for flight N. This ordering results in one attempt
6417 // at sending flight N to be dropped. For the test to complete, the
6418 // shim must send flight N again, testing that the shim implements DTLS
6419 // retransmit on a timeout.
6420
Steven Valdez143e8b32016-07-11 13:19:03 -04006421 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006422 // likely be more epochs to cross and the final message's retransmit may
6423 // be more complex.
6424
David Benjamin585d7a42016-06-02 14:58:00 -04006425 for _, async := range []bool{true, false} {
6426 var tests []testCase
6427
6428 // Test that this is indeed the timeout schedule. Stress all
6429 // four patterns of handshake.
6430 for i := 1; i < len(timeouts); i++ {
6431 number := strconv.Itoa(i)
6432 tests = append(tests, testCase{
6433 protocol: dtls,
6434 name: "DTLS-Retransmit-Client-" + number,
6435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006436 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006437 Bugs: ProtocolBugs{
6438 TimeoutSchedule: timeouts[:i],
6439 },
6440 },
6441 resumeSession: true,
6442 })
6443 tests = append(tests, testCase{
6444 protocol: dtls,
6445 testType: serverTest,
6446 name: "DTLS-Retransmit-Server-" + number,
6447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006448 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006449 Bugs: ProtocolBugs{
6450 TimeoutSchedule: timeouts[:i],
6451 },
6452 },
6453 resumeSession: true,
6454 })
6455 }
6456
6457 // Test that exceeding the timeout schedule hits a read
6458 // timeout.
6459 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006460 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006461 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006463 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006464 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006465 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006466 },
6467 },
6468 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006469 shouldFail: true,
6470 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006471 })
David Benjamin585d7a42016-06-02 14:58:00 -04006472
6473 if async {
6474 // Test that timeout handling has a fudge factor, due to API
6475 // problems.
6476 tests = append(tests, testCase{
6477 protocol: dtls,
6478 name: "DTLS-Retransmit-Fudge",
6479 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006480 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006481 Bugs: ProtocolBugs{
6482 TimeoutSchedule: []time.Duration{
6483 timeouts[0] - 10*time.Millisecond,
6484 },
6485 },
6486 },
6487 resumeSession: true,
6488 })
6489 }
6490
6491 // Test that the final Finished retransmitting isn't
6492 // duplicated if the peer badly fragments everything.
6493 tests = append(tests, testCase{
6494 testType: serverTest,
6495 protocol: dtls,
6496 name: "DTLS-Retransmit-Fragmented",
6497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006498 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006499 Bugs: ProtocolBugs{
6500 TimeoutSchedule: []time.Duration{timeouts[0]},
6501 MaxHandshakeRecordLength: 2,
6502 },
6503 },
6504 })
6505
6506 // Test the timeout schedule when a shorter initial timeout duration is set.
6507 tests = append(tests, testCase{
6508 protocol: dtls,
6509 name: "DTLS-Retransmit-Short-Client",
6510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006511 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006512 Bugs: ProtocolBugs{
6513 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6514 },
6515 },
6516 resumeSession: true,
6517 flags: []string{"-initial-timeout-duration-ms", "250"},
6518 })
6519 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006520 protocol: dtls,
6521 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006522 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006523 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006524 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006525 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006526 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006527 },
6528 },
6529 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006530 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006531 })
David Benjamin585d7a42016-06-02 14:58:00 -04006532
6533 for _, test := range tests {
6534 if async {
6535 test.name += "-Async"
6536 test.flags = append(test.flags, "-async")
6537 }
6538
6539 testCases = append(testCases, test)
6540 }
David Benjamin83f90402015-01-27 01:09:43 -05006541 }
David Benjamin83f90402015-01-27 01:09:43 -05006542}
6543
David Benjaminc565ebb2015-04-03 04:06:36 -04006544func addExportKeyingMaterialTests() {
6545 for _, vers := range tlsVersions {
6546 if vers.version == VersionSSL30 {
6547 continue
6548 }
6549 testCases = append(testCases, testCase{
6550 name: "ExportKeyingMaterial-" + vers.name,
6551 config: Config{
6552 MaxVersion: vers.version,
6553 },
6554 exportKeyingMaterial: 1024,
6555 exportLabel: "label",
6556 exportContext: "context",
6557 useExportContext: true,
6558 })
6559 testCases = append(testCases, testCase{
6560 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6561 config: Config{
6562 MaxVersion: vers.version,
6563 },
6564 exportKeyingMaterial: 1024,
6565 })
6566 testCases = append(testCases, testCase{
6567 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6568 config: Config{
6569 MaxVersion: vers.version,
6570 },
6571 exportKeyingMaterial: 1024,
6572 useExportContext: true,
6573 })
6574 testCases = append(testCases, testCase{
6575 name: "ExportKeyingMaterial-Small-" + vers.name,
6576 config: Config{
6577 MaxVersion: vers.version,
6578 },
6579 exportKeyingMaterial: 1,
6580 exportLabel: "label",
6581 exportContext: "context",
6582 useExportContext: true,
6583 })
6584 }
6585 testCases = append(testCases, testCase{
6586 name: "ExportKeyingMaterial-SSL3",
6587 config: Config{
6588 MaxVersion: VersionSSL30,
6589 },
6590 exportKeyingMaterial: 1024,
6591 exportLabel: "label",
6592 exportContext: "context",
6593 useExportContext: true,
6594 shouldFail: true,
6595 expectedError: "failed to export keying material",
6596 })
6597}
6598
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006599func addTLSUniqueTests() {
6600 for _, isClient := range []bool{false, true} {
6601 for _, isResumption := range []bool{false, true} {
6602 for _, hasEMS := range []bool{false, true} {
6603 var suffix string
6604 if isResumption {
6605 suffix = "Resume-"
6606 } else {
6607 suffix = "Full-"
6608 }
6609
6610 if hasEMS {
6611 suffix += "EMS-"
6612 } else {
6613 suffix += "NoEMS-"
6614 }
6615
6616 if isClient {
6617 suffix += "Client"
6618 } else {
6619 suffix += "Server"
6620 }
6621
6622 test := testCase{
6623 name: "TLSUnique-" + suffix,
6624 testTLSUnique: true,
6625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006626 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006627 Bugs: ProtocolBugs{
6628 NoExtendedMasterSecret: !hasEMS,
6629 },
6630 },
6631 }
6632
6633 if isResumption {
6634 test.resumeSession = true
6635 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006636 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006637 Bugs: ProtocolBugs{
6638 NoExtendedMasterSecret: !hasEMS,
6639 },
6640 }
6641 }
6642
6643 if isResumption && !hasEMS {
6644 test.shouldFail = true
6645 test.expectedError = "failed to get tls-unique"
6646 }
6647
6648 testCases = append(testCases, test)
6649 }
6650 }
6651 }
6652}
6653
Adam Langley09505632015-07-30 18:10:13 -07006654func addCustomExtensionTests() {
6655 expectedContents := "custom extension"
6656 emptyString := ""
6657
6658 for _, isClient := range []bool{false, true} {
6659 suffix := "Server"
6660 flag := "-enable-server-custom-extension"
6661 testType := serverTest
6662 if isClient {
6663 suffix = "Client"
6664 flag = "-enable-client-custom-extension"
6665 testType = clientTest
6666 }
6667
6668 testCases = append(testCases, testCase{
6669 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006670 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006671 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006672 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006673 Bugs: ProtocolBugs{
6674 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006675 ExpectedCustomExtension: &expectedContents,
6676 },
6677 },
6678 flags: []string{flag},
6679 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006680 testCases = append(testCases, testCase{
6681 testType: testType,
6682 name: "CustomExtensions-" + suffix + "-TLS13",
6683 config: Config{
6684 MaxVersion: VersionTLS13,
6685 Bugs: ProtocolBugs{
6686 CustomExtension: expectedContents,
6687 ExpectedCustomExtension: &expectedContents,
6688 },
6689 },
6690 flags: []string{flag},
6691 })
Adam Langley09505632015-07-30 18:10:13 -07006692
6693 // If the parse callback fails, the handshake should also fail.
6694 testCases = append(testCases, testCase{
6695 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006696 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006697 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006698 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006699 Bugs: ProtocolBugs{
6700 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006701 ExpectedCustomExtension: &expectedContents,
6702 },
6703 },
David Benjamin399e7c92015-07-30 23:01:27 -04006704 flags: []string{flag},
6705 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006706 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6707 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006708 testCases = append(testCases, testCase{
6709 testType: testType,
6710 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6711 config: Config{
6712 MaxVersion: VersionTLS13,
6713 Bugs: ProtocolBugs{
6714 CustomExtension: expectedContents + "foo",
6715 ExpectedCustomExtension: &expectedContents,
6716 },
6717 },
6718 flags: []string{flag},
6719 shouldFail: true,
6720 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6721 })
Adam Langley09505632015-07-30 18:10:13 -07006722
6723 // If the add callback fails, the handshake should also fail.
6724 testCases = append(testCases, testCase{
6725 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006726 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006728 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006729 Bugs: ProtocolBugs{
6730 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006731 ExpectedCustomExtension: &expectedContents,
6732 },
6733 },
David Benjamin399e7c92015-07-30 23:01:27 -04006734 flags: []string{flag, "-custom-extension-fail-add"},
6735 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006736 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6737 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006738 testCases = append(testCases, testCase{
6739 testType: testType,
6740 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6741 config: Config{
6742 MaxVersion: VersionTLS13,
6743 Bugs: ProtocolBugs{
6744 CustomExtension: expectedContents,
6745 ExpectedCustomExtension: &expectedContents,
6746 },
6747 },
6748 flags: []string{flag, "-custom-extension-fail-add"},
6749 shouldFail: true,
6750 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6751 })
Adam Langley09505632015-07-30 18:10:13 -07006752
6753 // If the add callback returns zero, no extension should be
6754 // added.
6755 skipCustomExtension := expectedContents
6756 if isClient {
6757 // For the case where the client skips sending the
6758 // custom extension, the server must not “echo” it.
6759 skipCustomExtension = ""
6760 }
6761 testCases = append(testCases, testCase{
6762 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006763 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006765 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006766 Bugs: ProtocolBugs{
6767 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006768 ExpectedCustomExtension: &emptyString,
6769 },
6770 },
6771 flags: []string{flag, "-custom-extension-skip"},
6772 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006773 testCases = append(testCases, testCase{
6774 testType: testType,
6775 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6776 config: Config{
6777 MaxVersion: VersionTLS13,
6778 Bugs: ProtocolBugs{
6779 CustomExtension: skipCustomExtension,
6780 ExpectedCustomExtension: &emptyString,
6781 },
6782 },
6783 flags: []string{flag, "-custom-extension-skip"},
6784 })
Adam Langley09505632015-07-30 18:10:13 -07006785 }
6786
6787 // The custom extension add callback should not be called if the client
6788 // doesn't send the extension.
6789 testCases = append(testCases, testCase{
6790 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006791 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006792 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006793 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006794 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006795 ExpectedCustomExtension: &emptyString,
6796 },
6797 },
6798 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6799 })
Adam Langley2deb9842015-08-07 11:15:37 -07006800
Steven Valdez143e8b32016-07-11 13:19:03 -04006801 testCases = append(testCases, testCase{
6802 testType: serverTest,
6803 name: "CustomExtensions-NotCalled-Server-TLS13",
6804 config: Config{
6805 MaxVersion: VersionTLS13,
6806 Bugs: ProtocolBugs{
6807 ExpectedCustomExtension: &emptyString,
6808 },
6809 },
6810 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6811 })
6812
Adam Langley2deb9842015-08-07 11:15:37 -07006813 // Test an unknown extension from the server.
6814 testCases = append(testCases, testCase{
6815 testType: clientTest,
6816 name: "UnknownExtension-Client",
6817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006818 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006819 Bugs: ProtocolBugs{
6820 CustomExtension: expectedContents,
6821 },
6822 },
David Benjamin0c40a962016-08-01 12:05:50 -04006823 shouldFail: true,
6824 expectedError: ":UNEXPECTED_EXTENSION:",
6825 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006826 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006827 testCases = append(testCases, testCase{
6828 testType: clientTest,
6829 name: "UnknownExtension-Client-TLS13",
6830 config: Config{
6831 MaxVersion: VersionTLS13,
6832 Bugs: ProtocolBugs{
6833 CustomExtension: expectedContents,
6834 },
6835 },
David Benjamin0c40a962016-08-01 12:05:50 -04006836 shouldFail: true,
6837 expectedError: ":UNEXPECTED_EXTENSION:",
6838 expectedLocalError: "remote error: unsupported extension",
6839 })
6840
6841 // Test a known but unoffered extension from the server.
6842 testCases = append(testCases, testCase{
6843 testType: clientTest,
6844 name: "UnofferedExtension-Client",
6845 config: Config{
6846 MaxVersion: VersionTLS12,
6847 Bugs: ProtocolBugs{
6848 SendALPN: "alpn",
6849 },
6850 },
6851 shouldFail: true,
6852 expectedError: ":UNEXPECTED_EXTENSION:",
6853 expectedLocalError: "remote error: unsupported extension",
6854 })
6855 testCases = append(testCases, testCase{
6856 testType: clientTest,
6857 name: "UnofferedExtension-Client-TLS13",
6858 config: Config{
6859 MaxVersion: VersionTLS13,
6860 Bugs: ProtocolBugs{
6861 SendALPN: "alpn",
6862 },
6863 },
6864 shouldFail: true,
6865 expectedError: ":UNEXPECTED_EXTENSION:",
6866 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006867 })
Adam Langley09505632015-07-30 18:10:13 -07006868}
6869
David Benjaminb36a3952015-12-01 18:53:13 -05006870func addRSAClientKeyExchangeTests() {
6871 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6872 testCases = append(testCases, testCase{
6873 testType: serverTest,
6874 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6875 config: Config{
6876 // Ensure the ClientHello version and final
6877 // version are different, to detect if the
6878 // server uses the wrong one.
6879 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006880 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006881 Bugs: ProtocolBugs{
6882 BadRSAClientKeyExchange: bad,
6883 },
6884 },
6885 shouldFail: true,
6886 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6887 })
6888 }
David Benjamine63d9d72016-09-19 18:27:34 -04006889
6890 // The server must compare whatever was in ClientHello.version for the
6891 // RSA premaster.
6892 testCases = append(testCases, testCase{
6893 testType: serverTest,
6894 name: "SendClientVersion-RSA",
6895 config: Config{
6896 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6897 Bugs: ProtocolBugs{
6898 SendClientVersion: 0x1234,
6899 },
6900 },
6901 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6902 })
David Benjaminb36a3952015-12-01 18:53:13 -05006903}
6904
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006905var testCurves = []struct {
6906 name string
6907 id CurveID
6908}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006909 {"P-256", CurveP256},
6910 {"P-384", CurveP384},
6911 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006912 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006913}
6914
Steven Valdez5440fe02016-07-18 12:40:30 -04006915const bogusCurve = 0x1234
6916
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006917func addCurveTests() {
6918 for _, curve := range testCurves {
6919 testCases = append(testCases, testCase{
6920 name: "CurveTest-Client-" + curve.name,
6921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006922 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006923 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6924 CurvePreferences: []CurveID{curve.id},
6925 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006926 flags: []string{
6927 "-enable-all-curves",
6928 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6929 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006930 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006931 })
6932 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006933 name: "CurveTest-Client-" + curve.name + "-TLS13",
6934 config: Config{
6935 MaxVersion: VersionTLS13,
6936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6937 CurvePreferences: []CurveID{curve.id},
6938 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006939 flags: []string{
6940 "-enable-all-curves",
6941 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6942 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006943 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006944 })
6945 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006946 testType: serverTest,
6947 name: "CurveTest-Server-" + curve.name,
6948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006949 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6951 CurvePreferences: []CurveID{curve.id},
6952 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006953 flags: []string{
6954 "-enable-all-curves",
6955 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6956 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006957 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006958 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006959 testCases = append(testCases, testCase{
6960 testType: serverTest,
6961 name: "CurveTest-Server-" + curve.name + "-TLS13",
6962 config: Config{
6963 MaxVersion: VersionTLS13,
6964 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6965 CurvePreferences: []CurveID{curve.id},
6966 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006967 flags: []string{
6968 "-enable-all-curves",
6969 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6970 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006971 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006972 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006973 }
David Benjamin241ae832016-01-15 03:04:54 -05006974
6975 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006976 testCases = append(testCases, testCase{
6977 testType: serverTest,
6978 name: "UnknownCurve",
6979 config: Config{
6980 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6981 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6982 },
6983 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984
6985 // The server must not consider ECDHE ciphers when there are no
6986 // supported curves.
6987 testCases = append(testCases, testCase{
6988 testType: serverTest,
6989 name: "NoSupportedCurves",
6990 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006991 MaxVersion: VersionTLS12,
6992 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6993 Bugs: ProtocolBugs{
6994 NoSupportedCurves: true,
6995 },
6996 },
6997 shouldFail: true,
6998 expectedError: ":NO_SHARED_CIPHER:",
6999 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007000 testCases = append(testCases, testCase{
7001 testType: serverTest,
7002 name: "NoSupportedCurves-TLS13",
7003 config: Config{
7004 MaxVersion: VersionTLS13,
7005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7006 Bugs: ProtocolBugs{
7007 NoSupportedCurves: true,
7008 },
7009 },
7010 shouldFail: true,
7011 expectedError: ":NO_SHARED_CIPHER:",
7012 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013
7014 // The server must fall back to another cipher when there are no
7015 // supported curves.
7016 testCases = append(testCases, testCase{
7017 testType: serverTest,
7018 name: "NoCommonCurves",
7019 config: Config{
7020 MaxVersion: VersionTLS12,
7021 CipherSuites: []uint16{
7022 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7023 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7024 },
7025 CurvePreferences: []CurveID{CurveP224},
7026 },
7027 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7028 })
7029
7030 // The client must reject bogus curves and disabled curves.
7031 testCases = append(testCases, testCase{
7032 name: "BadECDHECurve",
7033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007034 MaxVersion: VersionTLS12,
7035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7036 Bugs: ProtocolBugs{
7037 SendCurve: bogusCurve,
7038 },
7039 },
7040 shouldFail: true,
7041 expectedError: ":WRONG_CURVE:",
7042 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007043 testCases = append(testCases, testCase{
7044 name: "BadECDHECurve-TLS13",
7045 config: Config{
7046 MaxVersion: VersionTLS13,
7047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7048 Bugs: ProtocolBugs{
7049 SendCurve: bogusCurve,
7050 },
7051 },
7052 shouldFail: true,
7053 expectedError: ":WRONG_CURVE:",
7054 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055
7056 testCases = append(testCases, testCase{
7057 name: "UnsupportedCurve",
7058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007059 MaxVersion: VersionTLS12,
7060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7061 CurvePreferences: []CurveID{CurveP256},
7062 Bugs: ProtocolBugs{
7063 IgnorePeerCurvePreferences: true,
7064 },
7065 },
7066 flags: []string{"-p384-only"},
7067 shouldFail: true,
7068 expectedError: ":WRONG_CURVE:",
7069 })
7070
David Benjamin4f921572016-07-17 14:20:10 +02007071 testCases = append(testCases, testCase{
7072 // TODO(davidben): Add a TLS 1.3 version where
7073 // HelloRetryRequest requests an unsupported curve.
7074 name: "UnsupportedCurve-ServerHello-TLS13",
7075 config: Config{
7076 MaxVersion: VersionTLS12,
7077 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7078 CurvePreferences: []CurveID{CurveP384},
7079 Bugs: ProtocolBugs{
7080 SendCurve: CurveP256,
7081 },
7082 },
7083 flags: []string{"-p384-only"},
7084 shouldFail: true,
7085 expectedError: ":WRONG_CURVE:",
7086 })
7087
David Benjamin4c3ddf72016-06-29 18:13:53 -04007088 // Test invalid curve points.
7089 testCases = append(testCases, testCase{
7090 name: "InvalidECDHPoint-Client",
7091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 MaxVersion: VersionTLS12,
7093 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7094 CurvePreferences: []CurveID{CurveP256},
7095 Bugs: ProtocolBugs{
7096 InvalidECDHPoint: true,
7097 },
7098 },
7099 shouldFail: true,
7100 expectedError: ":INVALID_ENCODING:",
7101 })
7102 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007103 name: "InvalidECDHPoint-Client-TLS13",
7104 config: Config{
7105 MaxVersion: VersionTLS13,
7106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7107 CurvePreferences: []CurveID{CurveP256},
7108 Bugs: ProtocolBugs{
7109 InvalidECDHPoint: true,
7110 },
7111 },
7112 shouldFail: true,
7113 expectedError: ":INVALID_ENCODING:",
7114 })
7115 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007116 testType: serverTest,
7117 name: "InvalidECDHPoint-Server",
7118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007119 MaxVersion: VersionTLS12,
7120 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7121 CurvePreferences: []CurveID{CurveP256},
7122 Bugs: ProtocolBugs{
7123 InvalidECDHPoint: true,
7124 },
7125 },
7126 shouldFail: true,
7127 expectedError: ":INVALID_ENCODING:",
7128 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007129 testCases = append(testCases, testCase{
7130 testType: serverTest,
7131 name: "InvalidECDHPoint-Server-TLS13",
7132 config: Config{
7133 MaxVersion: VersionTLS13,
7134 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7135 CurvePreferences: []CurveID{CurveP256},
7136 Bugs: ProtocolBugs{
7137 InvalidECDHPoint: true,
7138 },
7139 },
7140 shouldFail: true,
7141 expectedError: ":INVALID_ENCODING:",
7142 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007143}
7144
Matt Braithwaite54217e42016-06-13 13:03:47 -07007145func addCECPQ1Tests() {
7146 testCases = append(testCases, testCase{
7147 testType: clientTest,
7148 name: "CECPQ1-Client-BadX25519Part",
7149 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007150 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007151 MinVersion: VersionTLS12,
7152 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7153 Bugs: ProtocolBugs{
7154 CECPQ1BadX25519Part: true,
7155 },
7156 },
7157 flags: []string{"-cipher", "kCECPQ1"},
7158 shouldFail: true,
7159 expectedLocalError: "local error: bad record MAC",
7160 })
7161 testCases = append(testCases, testCase{
7162 testType: clientTest,
7163 name: "CECPQ1-Client-BadNewhopePart",
7164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007165 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007166 MinVersion: VersionTLS12,
7167 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7168 Bugs: ProtocolBugs{
7169 CECPQ1BadNewhopePart: true,
7170 },
7171 },
7172 flags: []string{"-cipher", "kCECPQ1"},
7173 shouldFail: true,
7174 expectedLocalError: "local error: bad record MAC",
7175 })
7176 testCases = append(testCases, testCase{
7177 testType: serverTest,
7178 name: "CECPQ1-Server-BadX25519Part",
7179 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007180 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007181 MinVersion: VersionTLS12,
7182 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7183 Bugs: ProtocolBugs{
7184 CECPQ1BadX25519Part: true,
7185 },
7186 },
7187 flags: []string{"-cipher", "kCECPQ1"},
7188 shouldFail: true,
7189 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7190 })
7191 testCases = append(testCases, testCase{
7192 testType: serverTest,
7193 name: "CECPQ1-Server-BadNewhopePart",
7194 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007195 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007196 MinVersion: VersionTLS12,
7197 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7198 Bugs: ProtocolBugs{
7199 CECPQ1BadNewhopePart: true,
7200 },
7201 },
7202 flags: []string{"-cipher", "kCECPQ1"},
7203 shouldFail: true,
7204 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7205 })
7206}
7207
David Benjamin5c4e8572016-08-19 17:44:53 -04007208func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007209 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007210 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007211 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007212 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007213 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7214 Bugs: ProtocolBugs{
7215 // This is a 1234-bit prime number, generated
7216 // with:
7217 // openssl gendh 1234 | openssl asn1parse -i
7218 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7219 },
7220 },
David Benjamin9e68f192016-06-30 14:55:33 -04007221 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007222 })
7223 testCases = append(testCases, testCase{
7224 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007225 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007227 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007228 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7229 },
7230 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007231 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007232 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007233}
7234
David Benjaminc9ae27c2016-06-24 22:56:37 -04007235func addTLS13RecordTests() {
7236 testCases = append(testCases, testCase{
7237 name: "TLS13-RecordPadding",
7238 config: Config{
7239 MaxVersion: VersionTLS13,
7240 MinVersion: VersionTLS13,
7241 Bugs: ProtocolBugs{
7242 RecordPadding: 10,
7243 },
7244 },
7245 })
7246
7247 testCases = append(testCases, testCase{
7248 name: "TLS13-EmptyRecords",
7249 config: Config{
7250 MaxVersion: VersionTLS13,
7251 MinVersion: VersionTLS13,
7252 Bugs: ProtocolBugs{
7253 OmitRecordContents: true,
7254 },
7255 },
7256 shouldFail: true,
7257 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7258 })
7259
7260 testCases = append(testCases, testCase{
7261 name: "TLS13-OnlyPadding",
7262 config: Config{
7263 MaxVersion: VersionTLS13,
7264 MinVersion: VersionTLS13,
7265 Bugs: ProtocolBugs{
7266 OmitRecordContents: true,
7267 RecordPadding: 10,
7268 },
7269 },
7270 shouldFail: true,
7271 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7272 })
7273
7274 testCases = append(testCases, testCase{
7275 name: "TLS13-WrongOuterRecord",
7276 config: Config{
7277 MaxVersion: VersionTLS13,
7278 MinVersion: VersionTLS13,
7279 Bugs: ProtocolBugs{
7280 OuterRecordType: recordTypeHandshake,
7281 },
7282 },
7283 shouldFail: true,
7284 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7285 })
7286}
7287
David Benjamin82261be2016-07-07 14:32:50 -07007288func addChangeCipherSpecTests() {
7289 // Test missing ChangeCipherSpecs.
7290 testCases = append(testCases, testCase{
7291 name: "SkipChangeCipherSpec-Client",
7292 config: Config{
7293 MaxVersion: VersionTLS12,
7294 Bugs: ProtocolBugs{
7295 SkipChangeCipherSpec: true,
7296 },
7297 },
7298 shouldFail: true,
7299 expectedError: ":UNEXPECTED_RECORD:",
7300 })
7301 testCases = append(testCases, testCase{
7302 testType: serverTest,
7303 name: "SkipChangeCipherSpec-Server",
7304 config: Config{
7305 MaxVersion: VersionTLS12,
7306 Bugs: ProtocolBugs{
7307 SkipChangeCipherSpec: true,
7308 },
7309 },
7310 shouldFail: true,
7311 expectedError: ":UNEXPECTED_RECORD:",
7312 })
7313 testCases = append(testCases, testCase{
7314 testType: serverTest,
7315 name: "SkipChangeCipherSpec-Server-NPN",
7316 config: Config{
7317 MaxVersion: VersionTLS12,
7318 NextProtos: []string{"bar"},
7319 Bugs: ProtocolBugs{
7320 SkipChangeCipherSpec: true,
7321 },
7322 },
7323 flags: []string{
7324 "-advertise-npn", "\x03foo\x03bar\x03baz",
7325 },
7326 shouldFail: true,
7327 expectedError: ":UNEXPECTED_RECORD:",
7328 })
7329
7330 // Test synchronization between the handshake and ChangeCipherSpec.
7331 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7332 // rejected. Test both with and without handshake packing to handle both
7333 // when the partial post-CCS message is in its own record and when it is
7334 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007335 for _, packed := range []bool{false, true} {
7336 var suffix string
7337 if packed {
7338 suffix = "-Packed"
7339 }
7340
7341 testCases = append(testCases, testCase{
7342 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7343 config: Config{
7344 MaxVersion: VersionTLS12,
7345 Bugs: ProtocolBugs{
7346 FragmentAcrossChangeCipherSpec: true,
7347 PackHandshakeFlight: packed,
7348 },
7349 },
7350 shouldFail: true,
7351 expectedError: ":UNEXPECTED_RECORD:",
7352 })
7353 testCases = append(testCases, testCase{
7354 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7355 config: Config{
7356 MaxVersion: VersionTLS12,
7357 },
7358 resumeSession: true,
7359 resumeConfig: &Config{
7360 MaxVersion: VersionTLS12,
7361 Bugs: ProtocolBugs{
7362 FragmentAcrossChangeCipherSpec: true,
7363 PackHandshakeFlight: packed,
7364 },
7365 },
7366 shouldFail: true,
7367 expectedError: ":UNEXPECTED_RECORD:",
7368 })
7369 testCases = append(testCases, testCase{
7370 testType: serverTest,
7371 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7372 config: Config{
7373 MaxVersion: VersionTLS12,
7374 Bugs: ProtocolBugs{
7375 FragmentAcrossChangeCipherSpec: true,
7376 PackHandshakeFlight: packed,
7377 },
7378 },
7379 shouldFail: true,
7380 expectedError: ":UNEXPECTED_RECORD:",
7381 })
7382 testCases = append(testCases, testCase{
7383 testType: serverTest,
7384 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7385 config: Config{
7386 MaxVersion: VersionTLS12,
7387 },
7388 resumeSession: true,
7389 resumeConfig: &Config{
7390 MaxVersion: VersionTLS12,
7391 Bugs: ProtocolBugs{
7392 FragmentAcrossChangeCipherSpec: true,
7393 PackHandshakeFlight: packed,
7394 },
7395 },
7396 shouldFail: true,
7397 expectedError: ":UNEXPECTED_RECORD:",
7398 })
7399 testCases = append(testCases, testCase{
7400 testType: serverTest,
7401 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7402 config: Config{
7403 MaxVersion: VersionTLS12,
7404 NextProtos: []string{"bar"},
7405 Bugs: ProtocolBugs{
7406 FragmentAcrossChangeCipherSpec: true,
7407 PackHandshakeFlight: packed,
7408 },
7409 },
7410 flags: []string{
7411 "-advertise-npn", "\x03foo\x03bar\x03baz",
7412 },
7413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_RECORD:",
7415 })
7416 }
7417
David Benjamin61672812016-07-14 23:10:43 -04007418 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7419 // messages in the handshake queue. Do this by testing the server
7420 // reading the client Finished, reversing the flight so Finished comes
7421 // first.
7422 testCases = append(testCases, testCase{
7423 protocol: dtls,
7424 testType: serverTest,
7425 name: "SendUnencryptedFinished-DTLS",
7426 config: Config{
7427 MaxVersion: VersionTLS12,
7428 Bugs: ProtocolBugs{
7429 SendUnencryptedFinished: true,
7430 ReverseHandshakeFragments: true,
7431 },
7432 },
7433 shouldFail: true,
7434 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7435 })
7436
Steven Valdez143e8b32016-07-11 13:19:03 -04007437 // Test synchronization between encryption changes and the handshake in
7438 // TLS 1.3, where ChangeCipherSpec is implicit.
7439 testCases = append(testCases, testCase{
7440 name: "PartialEncryptedExtensionsWithServerHello",
7441 config: Config{
7442 MaxVersion: VersionTLS13,
7443 Bugs: ProtocolBugs{
7444 PartialEncryptedExtensionsWithServerHello: true,
7445 },
7446 },
7447 shouldFail: true,
7448 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7449 })
7450 testCases = append(testCases, testCase{
7451 testType: serverTest,
7452 name: "PartialClientFinishedWithClientHello",
7453 config: Config{
7454 MaxVersion: VersionTLS13,
7455 Bugs: ProtocolBugs{
7456 PartialClientFinishedWithClientHello: true,
7457 },
7458 },
7459 shouldFail: true,
7460 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7461 })
7462
David Benjamin82261be2016-07-07 14:32:50 -07007463 // Test that early ChangeCipherSpecs are handled correctly.
7464 testCases = append(testCases, testCase{
7465 testType: serverTest,
7466 name: "EarlyChangeCipherSpec-server-1",
7467 config: Config{
7468 MaxVersion: VersionTLS12,
7469 Bugs: ProtocolBugs{
7470 EarlyChangeCipherSpec: 1,
7471 },
7472 },
7473 shouldFail: true,
7474 expectedError: ":UNEXPECTED_RECORD:",
7475 })
7476 testCases = append(testCases, testCase{
7477 testType: serverTest,
7478 name: "EarlyChangeCipherSpec-server-2",
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 Bugs: ProtocolBugs{
7482 EarlyChangeCipherSpec: 2,
7483 },
7484 },
7485 shouldFail: true,
7486 expectedError: ":UNEXPECTED_RECORD:",
7487 })
7488 testCases = append(testCases, testCase{
7489 protocol: dtls,
7490 name: "StrayChangeCipherSpec",
7491 config: Config{
7492 // TODO(davidben): Once DTLS 1.3 exists, test
7493 // that stray ChangeCipherSpec messages are
7494 // rejected.
7495 MaxVersion: VersionTLS12,
7496 Bugs: ProtocolBugs{
7497 StrayChangeCipherSpec: true,
7498 },
7499 },
7500 })
7501
7502 // Test that the contents of ChangeCipherSpec are checked.
7503 testCases = append(testCases, testCase{
7504 name: "BadChangeCipherSpec-1",
7505 config: Config{
7506 MaxVersion: VersionTLS12,
7507 Bugs: ProtocolBugs{
7508 BadChangeCipherSpec: []byte{2},
7509 },
7510 },
7511 shouldFail: true,
7512 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7513 })
7514 testCases = append(testCases, testCase{
7515 name: "BadChangeCipherSpec-2",
7516 config: Config{
7517 MaxVersion: VersionTLS12,
7518 Bugs: ProtocolBugs{
7519 BadChangeCipherSpec: []byte{1, 1},
7520 },
7521 },
7522 shouldFail: true,
7523 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7524 })
7525 testCases = append(testCases, testCase{
7526 protocol: dtls,
7527 name: "BadChangeCipherSpec-DTLS-1",
7528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 Bugs: ProtocolBugs{
7531 BadChangeCipherSpec: []byte{2},
7532 },
7533 },
7534 shouldFail: true,
7535 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7536 })
7537 testCases = append(testCases, testCase{
7538 protocol: dtls,
7539 name: "BadChangeCipherSpec-DTLS-2",
7540 config: Config{
7541 MaxVersion: VersionTLS12,
7542 Bugs: ProtocolBugs{
7543 BadChangeCipherSpec: []byte{1, 1},
7544 },
7545 },
7546 shouldFail: true,
7547 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7548 })
7549}
7550
David Benjamincd2c8062016-09-09 11:28:16 -04007551type perMessageTest struct {
7552 messageType uint8
7553 test testCase
7554}
7555
7556// makePerMessageTests returns a series of test templates which cover each
7557// message in the TLS handshake. These may be used with bugs like
7558// WrongMessageType to fully test a per-message bug.
7559func makePerMessageTests() []perMessageTest {
7560 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007561 for _, protocol := range []protocol{tls, dtls} {
7562 var suffix string
7563 if protocol == dtls {
7564 suffix = "-DTLS"
7565 }
7566
David Benjamincd2c8062016-09-09 11:28:16 -04007567 ret = append(ret, perMessageTest{
7568 messageType: typeClientHello,
7569 test: testCase{
7570 protocol: protocol,
7571 testType: serverTest,
7572 name: "ClientHello" + suffix,
7573 config: Config{
7574 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007575 },
7576 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007577 })
7578
7579 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007580 ret = append(ret, perMessageTest{
7581 messageType: typeHelloVerifyRequest,
7582 test: testCase{
7583 protocol: protocol,
7584 name: "HelloVerifyRequest" + suffix,
7585 config: Config{
7586 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007587 },
7588 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007589 })
7590 }
7591
David Benjamincd2c8062016-09-09 11:28:16 -04007592 ret = append(ret, perMessageTest{
7593 messageType: typeServerHello,
7594 test: testCase{
7595 protocol: protocol,
7596 name: "ServerHello" + suffix,
7597 config: Config{
7598 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007599 },
7600 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007601 })
7602
David Benjamincd2c8062016-09-09 11:28:16 -04007603 ret = append(ret, perMessageTest{
7604 messageType: typeCertificate,
7605 test: testCase{
7606 protocol: protocol,
7607 name: "ServerCertificate" + suffix,
7608 config: Config{
7609 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007610 },
7611 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007612 })
7613
David Benjamincd2c8062016-09-09 11:28:16 -04007614 ret = append(ret, perMessageTest{
7615 messageType: typeCertificateStatus,
7616 test: testCase{
7617 protocol: protocol,
7618 name: "CertificateStatus" + suffix,
7619 config: Config{
7620 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007621 },
David Benjamincd2c8062016-09-09 11:28:16 -04007622 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007623 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007624 })
7625
David Benjamincd2c8062016-09-09 11:28:16 -04007626 ret = append(ret, perMessageTest{
7627 messageType: typeServerKeyExchange,
7628 test: testCase{
7629 protocol: protocol,
7630 name: "ServerKeyExchange" + suffix,
7631 config: Config{
7632 MaxVersion: VersionTLS12,
7633 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007634 },
7635 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007636 })
7637
David Benjamincd2c8062016-09-09 11:28:16 -04007638 ret = append(ret, perMessageTest{
7639 messageType: typeCertificateRequest,
7640 test: testCase{
7641 protocol: protocol,
7642 name: "CertificateRequest" + suffix,
7643 config: Config{
7644 MaxVersion: VersionTLS12,
7645 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007646 },
7647 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007648 })
7649
David Benjamincd2c8062016-09-09 11:28:16 -04007650 ret = append(ret, perMessageTest{
7651 messageType: typeServerHelloDone,
7652 test: testCase{
7653 protocol: protocol,
7654 name: "ServerHelloDone" + suffix,
7655 config: Config{
7656 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007657 },
7658 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007659 })
7660
David Benjamincd2c8062016-09-09 11:28:16 -04007661 ret = append(ret, perMessageTest{
7662 messageType: typeCertificate,
7663 test: testCase{
7664 testType: serverTest,
7665 protocol: protocol,
7666 name: "ClientCertificate" + suffix,
7667 config: Config{
7668 Certificates: []Certificate{rsaCertificate},
7669 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007670 },
David Benjamincd2c8062016-09-09 11:28:16 -04007671 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007673 })
7674
David Benjamincd2c8062016-09-09 11:28:16 -04007675 ret = append(ret, perMessageTest{
7676 messageType: typeCertificateVerify,
7677 test: testCase{
7678 testType: serverTest,
7679 protocol: protocol,
7680 name: "CertificateVerify" + suffix,
7681 config: Config{
7682 Certificates: []Certificate{rsaCertificate},
7683 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007684 },
David Benjamincd2c8062016-09-09 11:28:16 -04007685 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007686 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007687 })
7688
David Benjamincd2c8062016-09-09 11:28:16 -04007689 ret = append(ret, perMessageTest{
7690 messageType: typeClientKeyExchange,
7691 test: testCase{
7692 testType: serverTest,
7693 protocol: protocol,
7694 name: "ClientKeyExchange" + suffix,
7695 config: Config{
7696 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007697 },
7698 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007699 })
7700
7701 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007702 ret = append(ret, perMessageTest{
7703 messageType: typeNextProtocol,
7704 test: testCase{
7705 testType: serverTest,
7706 protocol: protocol,
7707 name: "NextProtocol" + suffix,
7708 config: Config{
7709 MaxVersion: VersionTLS12,
7710 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007711 },
David Benjamincd2c8062016-09-09 11:28:16 -04007712 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007713 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007714 })
7715
David Benjamincd2c8062016-09-09 11:28:16 -04007716 ret = append(ret, perMessageTest{
7717 messageType: typeChannelID,
7718 test: testCase{
7719 testType: serverTest,
7720 protocol: protocol,
7721 name: "ChannelID" + suffix,
7722 config: Config{
7723 MaxVersion: VersionTLS12,
7724 ChannelID: channelIDKey,
7725 },
7726 flags: []string{
7727 "-expect-channel-id",
7728 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007729 },
7730 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007731 })
7732 }
7733
David Benjamincd2c8062016-09-09 11:28:16 -04007734 ret = append(ret, perMessageTest{
7735 messageType: typeFinished,
7736 test: testCase{
7737 testType: serverTest,
7738 protocol: protocol,
7739 name: "ClientFinished" + suffix,
7740 config: Config{
7741 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007742 },
7743 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007744 })
7745
David Benjamincd2c8062016-09-09 11:28:16 -04007746 ret = append(ret, perMessageTest{
7747 messageType: typeNewSessionTicket,
7748 test: testCase{
7749 protocol: protocol,
7750 name: "NewSessionTicket" + suffix,
7751 config: Config{
7752 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007753 },
7754 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007755 })
7756
David Benjamincd2c8062016-09-09 11:28:16 -04007757 ret = append(ret, perMessageTest{
7758 messageType: typeFinished,
7759 test: testCase{
7760 protocol: protocol,
7761 name: "ServerFinished" + suffix,
7762 config: Config{
7763 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007764 },
7765 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007766 })
7767
7768 }
David Benjamincd2c8062016-09-09 11:28:16 -04007769
7770 ret = append(ret, perMessageTest{
7771 messageType: typeClientHello,
7772 test: testCase{
7773 testType: serverTest,
7774 name: "TLS13-ClientHello",
7775 config: Config{
7776 MaxVersion: VersionTLS13,
7777 },
7778 },
7779 })
7780
7781 ret = append(ret, perMessageTest{
7782 messageType: typeServerHello,
7783 test: testCase{
7784 name: "TLS13-ServerHello",
7785 config: Config{
7786 MaxVersion: VersionTLS13,
7787 },
7788 },
7789 })
7790
7791 ret = append(ret, perMessageTest{
7792 messageType: typeEncryptedExtensions,
7793 test: testCase{
7794 name: "TLS13-EncryptedExtensions",
7795 config: Config{
7796 MaxVersion: VersionTLS13,
7797 },
7798 },
7799 })
7800
7801 ret = append(ret, perMessageTest{
7802 messageType: typeCertificateRequest,
7803 test: testCase{
7804 name: "TLS13-CertificateRequest",
7805 config: Config{
7806 MaxVersion: VersionTLS13,
7807 ClientAuth: RequireAnyClientCert,
7808 },
7809 },
7810 })
7811
7812 ret = append(ret, perMessageTest{
7813 messageType: typeCertificate,
7814 test: testCase{
7815 name: "TLS13-ServerCertificate",
7816 config: Config{
7817 MaxVersion: VersionTLS13,
7818 },
7819 },
7820 })
7821
7822 ret = append(ret, perMessageTest{
7823 messageType: typeCertificateVerify,
7824 test: testCase{
7825 name: "TLS13-ServerCertificateVerify",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 },
7829 },
7830 })
7831
7832 ret = append(ret, perMessageTest{
7833 messageType: typeFinished,
7834 test: testCase{
7835 name: "TLS13-ServerFinished",
7836 config: Config{
7837 MaxVersion: VersionTLS13,
7838 },
7839 },
7840 })
7841
7842 ret = append(ret, perMessageTest{
7843 messageType: typeCertificate,
7844 test: testCase{
7845 testType: serverTest,
7846 name: "TLS13-ClientCertificate",
7847 config: Config{
7848 Certificates: []Certificate{rsaCertificate},
7849 MaxVersion: VersionTLS13,
7850 },
7851 flags: []string{"-require-any-client-certificate"},
7852 },
7853 })
7854
7855 ret = append(ret, perMessageTest{
7856 messageType: typeCertificateVerify,
7857 test: testCase{
7858 testType: serverTest,
7859 name: "TLS13-ClientCertificateVerify",
7860 config: Config{
7861 Certificates: []Certificate{rsaCertificate},
7862 MaxVersion: VersionTLS13,
7863 },
7864 flags: []string{"-require-any-client-certificate"},
7865 },
7866 })
7867
7868 ret = append(ret, perMessageTest{
7869 messageType: typeFinished,
7870 test: testCase{
7871 testType: serverTest,
7872 name: "TLS13-ClientFinished",
7873 config: Config{
7874 MaxVersion: VersionTLS13,
7875 },
7876 },
7877 })
7878
7879 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007880}
7881
David Benjamincd2c8062016-09-09 11:28:16 -04007882func addWrongMessageTypeTests() {
7883 for _, t := range makePerMessageTests() {
7884 t.test.name = "WrongMessageType-" + t.test.name
7885 t.test.config.Bugs.SendWrongMessageType = t.messageType
7886 t.test.shouldFail = true
7887 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7888 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007889
David Benjamincd2c8062016-09-09 11:28:16 -04007890 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7891 // In TLS 1.3, a bad ServerHello means the client sends
7892 // an unencrypted alert while the server expects
7893 // encryption, so the alert is not readable by runner.
7894 t.test.expectedLocalError = "local error: bad record MAC"
7895 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007896
David Benjamincd2c8062016-09-09 11:28:16 -04007897 testCases = append(testCases, t.test)
7898 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007899}
7900
David Benjamin639846e2016-09-09 11:41:18 -04007901func addTrailingMessageDataTests() {
7902 for _, t := range makePerMessageTests() {
7903 t.test.name = "TrailingMessageData-" + t.test.name
7904 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7905 t.test.shouldFail = true
7906 t.test.expectedError = ":DECODE_ERROR:"
7907 t.test.expectedLocalError = "remote error: error decoding message"
7908
7909 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7910 // In TLS 1.3, a bad ServerHello means the client sends
7911 // an unencrypted alert while the server expects
7912 // encryption, so the alert is not readable by runner.
7913 t.test.expectedLocalError = "local error: bad record MAC"
7914 }
7915
7916 if t.messageType == typeFinished {
7917 // Bad Finished messages read as the verify data having
7918 // the wrong length.
7919 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7920 t.test.expectedLocalError = "remote error: error decrypting message"
7921 }
7922
7923 testCases = append(testCases, t.test)
7924 }
7925}
7926
Steven Valdez143e8b32016-07-11 13:19:03 -04007927func addTLS13HandshakeTests() {
7928 testCases = append(testCases, testCase{
7929 testType: clientTest,
7930 name: "MissingKeyShare-Client",
7931 config: Config{
7932 MaxVersion: VersionTLS13,
7933 Bugs: ProtocolBugs{
7934 MissingKeyShare: true,
7935 },
7936 },
7937 shouldFail: true,
7938 expectedError: ":MISSING_KEY_SHARE:",
7939 })
7940
7941 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007942 testType: serverTest,
7943 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007944 config: Config{
7945 MaxVersion: VersionTLS13,
7946 Bugs: ProtocolBugs{
7947 MissingKeyShare: true,
7948 },
7949 },
7950 shouldFail: true,
7951 expectedError: ":MISSING_KEY_SHARE:",
7952 })
7953
7954 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007955 testType: serverTest,
7956 name: "DuplicateKeyShares",
7957 config: Config{
7958 MaxVersion: VersionTLS13,
7959 Bugs: ProtocolBugs{
7960 DuplicateKeyShares: true,
7961 },
7962 },
7963 })
7964
7965 testCases = append(testCases, testCase{
7966 testType: clientTest,
7967 name: "EmptyEncryptedExtensions",
7968 config: Config{
7969 MaxVersion: VersionTLS13,
7970 Bugs: ProtocolBugs{
7971 EmptyEncryptedExtensions: true,
7972 },
7973 },
7974 shouldFail: true,
7975 expectedLocalError: "remote error: error decoding message",
7976 })
7977
7978 testCases = append(testCases, testCase{
7979 testType: clientTest,
7980 name: "EncryptedExtensionsWithKeyShare",
7981 config: Config{
7982 MaxVersion: VersionTLS13,
7983 Bugs: ProtocolBugs{
7984 EncryptedExtensionsWithKeyShare: true,
7985 },
7986 },
7987 shouldFail: true,
7988 expectedLocalError: "remote error: unsupported extension",
7989 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007990
7991 testCases = append(testCases, testCase{
7992 testType: serverTest,
7993 name: "SendHelloRetryRequest",
7994 config: Config{
7995 MaxVersion: VersionTLS13,
7996 // Require a HelloRetryRequest for every curve.
7997 DefaultCurves: []CurveID{},
7998 },
7999 expectedCurveID: CurveX25519,
8000 })
8001
8002 testCases = append(testCases, testCase{
8003 testType: serverTest,
8004 name: "SendHelloRetryRequest-2",
8005 config: Config{
8006 MaxVersion: VersionTLS13,
8007 DefaultCurves: []CurveID{CurveP384},
8008 },
8009 // Although the ClientHello did not predict our preferred curve,
8010 // we always select it whether it is predicted or not.
8011 expectedCurveID: CurveX25519,
8012 })
8013
8014 testCases = append(testCases, testCase{
8015 name: "UnknownCurve-HelloRetryRequest",
8016 config: Config{
8017 MaxVersion: VersionTLS13,
8018 // P-384 requires HelloRetryRequest in BoringSSL.
8019 CurvePreferences: []CurveID{CurveP384},
8020 Bugs: ProtocolBugs{
8021 SendHelloRetryRequestCurve: bogusCurve,
8022 },
8023 },
8024 shouldFail: true,
8025 expectedError: ":WRONG_CURVE:",
8026 })
8027
8028 testCases = append(testCases, testCase{
8029 name: "DisabledCurve-HelloRetryRequest",
8030 config: Config{
8031 MaxVersion: VersionTLS13,
8032 CurvePreferences: []CurveID{CurveP256},
8033 Bugs: ProtocolBugs{
8034 IgnorePeerCurvePreferences: true,
8035 },
8036 },
8037 flags: []string{"-p384-only"},
8038 shouldFail: true,
8039 expectedError: ":WRONG_CURVE:",
8040 })
8041
8042 testCases = append(testCases, testCase{
8043 name: "UnnecessaryHelloRetryRequest",
8044 config: Config{
8045 MaxVersion: VersionTLS13,
8046 Bugs: ProtocolBugs{
8047 UnnecessaryHelloRetryRequest: true,
8048 },
8049 },
8050 shouldFail: true,
8051 expectedError: ":WRONG_CURVE:",
8052 })
8053
8054 testCases = append(testCases, testCase{
8055 name: "SecondHelloRetryRequest",
8056 config: Config{
8057 MaxVersion: VersionTLS13,
8058 // P-384 requires HelloRetryRequest in BoringSSL.
8059 CurvePreferences: []CurveID{CurveP384},
8060 Bugs: ProtocolBugs{
8061 SecondHelloRetryRequest: true,
8062 },
8063 },
8064 shouldFail: true,
8065 expectedError: ":UNEXPECTED_MESSAGE:",
8066 })
8067
8068 testCases = append(testCases, testCase{
8069 testType: serverTest,
8070 name: "SecondClientHelloMissingKeyShare",
8071 config: Config{
8072 MaxVersion: VersionTLS13,
8073 DefaultCurves: []CurveID{},
8074 Bugs: ProtocolBugs{
8075 SecondClientHelloMissingKeyShare: true,
8076 },
8077 },
8078 shouldFail: true,
8079 expectedError: ":MISSING_KEY_SHARE:",
8080 })
8081
8082 testCases = append(testCases, testCase{
8083 testType: serverTest,
8084 name: "SecondClientHelloWrongCurve",
8085 config: Config{
8086 MaxVersion: VersionTLS13,
8087 DefaultCurves: []CurveID{},
8088 Bugs: ProtocolBugs{
8089 MisinterpretHelloRetryRequestCurve: CurveP521,
8090 },
8091 },
8092 shouldFail: true,
8093 expectedError: ":WRONG_CURVE:",
8094 })
8095
8096 testCases = append(testCases, testCase{
8097 name: "HelloRetryRequestVersionMismatch",
8098 config: Config{
8099 MaxVersion: VersionTLS13,
8100 // P-384 requires HelloRetryRequest in BoringSSL.
8101 CurvePreferences: []CurveID{CurveP384},
8102 Bugs: ProtocolBugs{
8103 SendServerHelloVersion: 0x0305,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":WRONG_VERSION_NUMBER:",
8108 })
8109
8110 testCases = append(testCases, testCase{
8111 name: "HelloRetryRequestCurveMismatch",
8112 config: Config{
8113 MaxVersion: VersionTLS13,
8114 // P-384 requires HelloRetryRequest in BoringSSL.
8115 CurvePreferences: []CurveID{CurveP384},
8116 Bugs: ProtocolBugs{
8117 // Send P-384 (correct) in the HelloRetryRequest.
8118 SendHelloRetryRequestCurve: CurveP384,
8119 // But send P-256 in the ServerHello.
8120 SendCurve: CurveP256,
8121 },
8122 },
8123 shouldFail: true,
8124 expectedError: ":WRONG_CURVE:",
8125 })
8126
8127 // Test the server selecting a curve that requires a HelloRetryRequest
8128 // without sending it.
8129 testCases = append(testCases, testCase{
8130 name: "SkipHelloRetryRequest",
8131 config: Config{
8132 MaxVersion: VersionTLS13,
8133 // P-384 requires HelloRetryRequest in BoringSSL.
8134 CurvePreferences: []CurveID{CurveP384},
8135 Bugs: ProtocolBugs{
8136 SkipHelloRetryRequest: true,
8137 },
8138 },
8139 shouldFail: true,
8140 expectedError: ":WRONG_CURVE:",
8141 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008142
8143 testCases = append(testCases, testCase{
8144 name: "TLS13-RequestContextInHandshake",
8145 config: Config{
8146 MaxVersion: VersionTLS13,
8147 MinVersion: VersionTLS13,
8148 ClientAuth: RequireAnyClientCert,
8149 Bugs: ProtocolBugs{
8150 SendRequestContext: []byte("request context"),
8151 },
8152 },
8153 flags: []string{
8154 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8155 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8156 },
8157 shouldFail: true,
8158 expectedError: ":DECODE_ERROR:",
8159 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008160}
8161
Adam Langley7c803a62015-06-15 15:35:05 -07008162func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008163 defer wg.Done()
8164
8165 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008166 var err error
8167
8168 if *mallocTest < 0 {
8169 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008170 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008171 } else {
8172 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8173 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008174 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008175 if err != nil {
8176 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8177 }
8178 break
8179 }
8180 }
8181 }
Adam Langley95c29f32014-06-20 12:00:00 -07008182 statusChan <- statusMsg{test: test, err: err}
8183 }
8184}
8185
8186type statusMsg struct {
8187 test *testCase
8188 started bool
8189 err error
8190}
8191
David Benjamin5f237bc2015-02-11 17:14:15 -05008192func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008193 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008194
David Benjamin5f237bc2015-02-11 17:14:15 -05008195 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008196 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008197 if !*pipe {
8198 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008199 var erase string
8200 for i := 0; i < lineLen; i++ {
8201 erase += "\b \b"
8202 }
8203 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008204 }
8205
Adam Langley95c29f32014-06-20 12:00:00 -07008206 if msg.started {
8207 started++
8208 } else {
8209 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008210
8211 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008212 if msg.err == errUnimplemented {
8213 if *pipe {
8214 // Print each test instead of a status line.
8215 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8216 }
8217 unimplemented++
8218 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8219 } else {
8220 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8221 failed++
8222 testOutput.addResult(msg.test.name, "FAIL")
8223 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008224 } else {
8225 if *pipe {
8226 // Print each test instead of a status line.
8227 fmt.Printf("PASSED (%s)\n", msg.test.name)
8228 }
8229 testOutput.addResult(msg.test.name, "PASS")
8230 }
Adam Langley95c29f32014-06-20 12:00:00 -07008231 }
8232
David Benjamin5f237bc2015-02-11 17:14:15 -05008233 if !*pipe {
8234 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008235 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008236 lineLen = len(line)
8237 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008238 }
Adam Langley95c29f32014-06-20 12:00:00 -07008239 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008240
8241 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008242}
8243
8244func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008245 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008246 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008247 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008248
Adam Langley7c803a62015-06-15 15:35:05 -07008249 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008250 addCipherSuiteTests()
8251 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008252 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008253 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008254 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008255 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008256 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008257 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008258 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008259 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008260 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008261 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008262 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008263 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008264 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008265 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008266 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008267 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008268 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008269 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008270 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008271 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008272 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008273 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008274 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008275 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008276 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008277 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008278
8279 var wg sync.WaitGroup
8280
Adam Langley7c803a62015-06-15 15:35:05 -07008281 statusChan := make(chan statusMsg, *numWorkers)
8282 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008283 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008284
EKRf71d7ed2016-08-06 13:25:12 -07008285 if len(*shimConfigFile) != 0 {
8286 encoded, err := ioutil.ReadFile(*shimConfigFile)
8287 if err != nil {
8288 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8289 os.Exit(1)
8290 }
8291
8292 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8293 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8294 os.Exit(1)
8295 }
8296 }
8297
David Benjamin025b3d32014-07-01 19:53:04 -04008298 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008299
Adam Langley7c803a62015-06-15 15:35:05 -07008300 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008301 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008302 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008303 }
8304
David Benjamin270f0a72016-03-17 14:41:36 -04008305 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008306 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008307 matched := true
8308 if len(*testToRun) != 0 {
8309 var err error
8310 matched, err = filepath.Match(*testToRun, testCases[i].name)
8311 if err != nil {
8312 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8313 os.Exit(1)
8314 }
8315 }
8316
EKRf71d7ed2016-08-06 13:25:12 -07008317 if !*includeDisabled {
8318 for pattern := range shimConfig.DisabledTests {
8319 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8320 if err != nil {
8321 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8322 os.Exit(1)
8323 }
8324
8325 if isDisabled {
8326 matched = false
8327 break
8328 }
8329 }
8330 }
8331
David Benjamin17e12922016-07-28 18:04:43 -04008332 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008333 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008334 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008335 }
8336 }
David Benjamin17e12922016-07-28 18:04:43 -04008337
David Benjamin270f0a72016-03-17 14:41:36 -04008338 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008339 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008340 os.Exit(1)
8341 }
Adam Langley95c29f32014-06-20 12:00:00 -07008342
8343 close(testChan)
8344 wg.Wait()
8345 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008346 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008347
8348 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008349
8350 if *jsonOutput != "" {
8351 if err := testOutput.writeTo(*jsonOutput); err != nil {
8352 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8353 }
8354 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008355
EKR842ae6c2016-07-27 09:22:05 +02008356 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8357 os.Exit(1)
8358 }
8359
8360 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008361 os.Exit(1)
8362 }
Adam Langley95c29f32014-06-20 12:00:00 -07008363}