blob: 8e107aaadf559fc19fec40acc2028b4920f98674 [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 }
445 if *deterministic {
446 config.Rand = &deterministicRand{}
447 }
448
David Benjamin01784b42016-06-07 18:00:52 -0400449 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500450
David Benjamin6fd297b2014-08-11 18:43:38 -0400451 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500452 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
453 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500454 }
455
David Benjamin9867b7d2016-03-01 23:25:48 -0500456 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500457 local, peer := "client", "server"
458 if test.testType == clientTest {
459 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500460 }
David Benjaminebda9b32015-11-02 15:33:18 -0500461 connDebug := &recordingConn{
462 Conn: conn,
463 isDatagram: test.protocol == dtls,
464 local: local,
465 peer: peer,
466 }
467 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if *flagDebug {
469 defer connDebug.WriteTo(os.Stdout)
470 }
471 if len(*transcriptDir) != 0 {
472 defer func() {
473 writeTranscript(test, isResume, connDebug.Transcript())
474 }()
475 }
David Benjaminebda9b32015-11-02 15:33:18 -0500476
477 if config.Bugs.PacketAdaptor != nil {
478 config.Bugs.PacketAdaptor.debug = connDebug
479 }
480 }
481
482 if test.replayWrites {
483 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400484 }
485
David Benjamin3ed59772016-03-08 12:50:21 -0500486 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500487 if test.damageFirstWrite {
488 connDamage = newDamageAdaptor(conn)
489 conn = connDamage
490 }
491
David Benjamin6fd297b2014-08-11 18:43:38 -0400492 if test.sendPrefix != "" {
493 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
494 return err
495 }
David Benjamin98e882e2014-08-08 13:24:34 -0400496 }
497
David Benjamin1d5c83e2014-07-22 19:20:02 -0400498 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400499 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400500 if test.protocol == dtls {
501 tlsConn = DTLSServer(conn, config)
502 } else {
503 tlsConn = Server(conn, config)
504 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400505 } else {
506 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400507 if test.protocol == dtls {
508 tlsConn = DTLSClient(conn, config)
509 } else {
510 tlsConn = Client(conn, config)
511 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400512 }
David Benjamin30789da2015-08-29 22:56:45 -0400513 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400514
Adam Langley95c29f32014-06-20 12:00:00 -0700515 if err := tlsConn.Handshake(); err != nil {
516 return err
517 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700518
David Benjamin01fe8202014-09-24 15:21:44 -0400519 // TODO(davidben): move all per-connection expectations into a dedicated
520 // expectations struct that can be specified separately for the two
521 // legs.
522 expectedVersion := test.expectedVersion
523 if isResume && test.expectedResumeVersion != 0 {
524 expectedVersion = test.expectedResumeVersion
525 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700526 connState := tlsConn.ConnectionState()
527 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400528 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400529 }
530
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400532 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
533 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700534 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
535 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
536 }
David Benjamin90da8c82015-04-20 14:57:57 -0400537
David Benjamina08e49d2014-08-24 01:46:07 -0400538 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400540 if channelID == nil {
541 return fmt.Errorf("no channel ID negotiated")
542 }
543 if channelID.Curve != channelIDKey.Curve ||
544 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
545 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
546 return fmt.Errorf("incorrect channel ID")
547 }
548 }
549
David Benjaminae2888f2014-09-06 12:58:58 -0400550 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700551 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400552 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
553 }
554 }
555
David Benjaminc7ce9772015-10-09 19:32:41 -0400556 if test.expectNoNextProto {
557 if actual := connState.NegotiatedProtocol; actual != "" {
558 return fmt.Errorf("got unexpected next proto %s", actual)
559 }
560 }
561
David Benjaminfc7b0862014-09-06 13:21:53 -0400562 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700563 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400564 return fmt.Errorf("next proto type mismatch")
565 }
566 }
567
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700568 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500569 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
570 }
571
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100572 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300573 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100574 }
575
Paul Lietar4fac72e2015-09-09 13:44:55 +0100576 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
577 return fmt.Errorf("SCT list mismatch")
578 }
579
Nick Harper60edffd2016-06-21 15:19:24 -0700580 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
581 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400582 }
583
Steven Valdez5440fe02016-07-18 12:40:30 -0400584 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
585 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
586 }
587
David Benjaminc565ebb2015-04-03 04:06:36 -0400588 if test.exportKeyingMaterial > 0 {
589 actual := make([]byte, test.exportKeyingMaterial)
590 if _, err := io.ReadFull(tlsConn, actual); err != nil {
591 return err
592 }
593 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
594 if err != nil {
595 return err
596 }
597 if !bytes.Equal(actual, expected) {
598 return fmt.Errorf("keying material mismatch")
599 }
600 }
601
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700602 if test.testTLSUnique {
603 var peersValue [12]byte
604 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
605 return err
606 }
607 expected := tlsConn.ConnectionState().TLSUnique
608 if !bytes.Equal(peersValue[:], expected) {
609 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
610 }
611 }
612
David Benjamine58c4f52014-08-24 03:47:07 -0400613 if test.shimWritesFirst {
614 var buf [5]byte
615 _, err := io.ReadFull(tlsConn, buf[:])
616 if err != nil {
617 return err
618 }
619 if string(buf[:]) != "hello" {
620 return fmt.Errorf("bad initial message")
621 }
622 }
623
Steven Valdez32635b82016-08-16 11:25:03 -0400624 for i := 0; i < test.sendKeyUpdates; i++ {
625 tlsConn.SendKeyUpdate()
626 }
627
David Benjamina8ebe222015-06-06 03:04:39 -0400628 for i := 0; i < test.sendEmptyRecords; i++ {
629 tlsConn.Write(nil)
630 }
631
David Benjamin24f346d2015-06-06 03:28:08 -0400632 for i := 0; i < test.sendWarningAlerts; i++ {
633 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
634 }
635
David Benjamin47921102016-07-28 11:29:18 -0400636 if test.sendHalfHelloRequest {
637 tlsConn.SendHalfHelloRequest()
638 }
639
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400640 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700641 if test.renegotiateCiphers != nil {
642 config.CipherSuites = test.renegotiateCiphers
643 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400644 for i := 0; i < test.renegotiate; i++ {
645 if err := tlsConn.Renegotiate(); err != nil {
646 return err
647 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700648 }
649 } else if test.renegotiateCiphers != nil {
650 panic("renegotiateCiphers without renegotiate")
651 }
652
David Benjamin5fa3eba2015-01-22 16:35:40 -0500653 if test.damageFirstWrite {
654 connDamage.setDamage(true)
655 tlsConn.Write([]byte("DAMAGED WRITE"))
656 connDamage.setDamage(false)
657 }
658
David Benjamin8e6db492015-07-25 18:29:23 -0400659 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700660 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400661 if test.protocol == dtls {
662 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
663 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700664 // Read until EOF.
665 _, err := io.Copy(ioutil.Discard, tlsConn)
666 return err
667 }
David Benjamin4417d052015-04-05 04:17:25 -0400668 if messageLen == 0 {
669 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700670 }
Adam Langley95c29f32014-06-20 12:00:00 -0700671
David Benjamin8e6db492015-07-25 18:29:23 -0400672 messageCount := test.messageCount
673 if messageCount == 0 {
674 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400675 }
676
David Benjamin8e6db492015-07-25 18:29:23 -0400677 for j := 0; j < messageCount; j++ {
678 testMessage := make([]byte, messageLen)
679 for i := range testMessage {
680 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400681 }
David Benjamin8e6db492015-07-25 18:29:23 -0400682 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700683
Steven Valdez32635b82016-08-16 11:25:03 -0400684 for i := 0; i < test.sendKeyUpdates; i++ {
685 tlsConn.SendKeyUpdate()
686 }
687
David Benjamin8e6db492015-07-25 18:29:23 -0400688 for i := 0; i < test.sendEmptyRecords; i++ {
689 tlsConn.Write(nil)
690 }
691
692 for i := 0; i < test.sendWarningAlerts; i++ {
693 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
694 }
695
David Benjamin4f75aaf2015-09-01 16:53:10 -0400696 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400697 // The shim will not respond.
698 continue
699 }
700
David Benjamin8e6db492015-07-25 18:29:23 -0400701 buf := make([]byte, len(testMessage))
702 if test.protocol == dtls {
703 bufTmp := make([]byte, len(buf)+1)
704 n, err := tlsConn.Read(bufTmp)
705 if err != nil {
706 return err
707 }
708 if n != len(buf) {
709 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
710 }
711 copy(buf, bufTmp)
712 } else {
713 _, err := io.ReadFull(tlsConn, buf)
714 if err != nil {
715 return err
716 }
717 }
718
719 for i, v := range buf {
720 if v != testMessage[i]^0xff {
721 return fmt.Errorf("bad reply contents at byte %d", i)
722 }
Adam Langley95c29f32014-06-20 12:00:00 -0700723 }
724 }
725
726 return nil
727}
728
David Benjamin325b5c32014-07-01 19:40:31 -0400729func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
730 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700731 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400732 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700733 }
David Benjamin325b5c32014-07-01 19:40:31 -0400734 valgrindArgs = append(valgrindArgs, path)
735 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700736
David Benjamin325b5c32014-07-01 19:40:31 -0400737 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700738}
739
David Benjamin325b5c32014-07-01 19:40:31 -0400740func gdbOf(path string, args ...string) *exec.Cmd {
741 xtermArgs := []string{"-e", "gdb", "--args"}
742 xtermArgs = append(xtermArgs, path)
743 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700744
David Benjamin325b5c32014-07-01 19:40:31 -0400745 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700746}
747
David Benjamind16bf342015-12-18 00:53:12 -0500748func lldbOf(path string, args ...string) *exec.Cmd {
749 xtermArgs := []string{"-e", "lldb", "--"}
750 xtermArgs = append(xtermArgs, path)
751 xtermArgs = append(xtermArgs, args...)
752
753 return exec.Command("xterm", xtermArgs...)
754}
755
EKR842ae6c2016-07-27 09:22:05 +0200756var (
757 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
758 errUnimplemented = errors.New("child process does not implement needed flags")
759)
Adam Langley69a01602014-11-17 17:26:55 -0800760
David Benjamin87c8a642015-02-21 01:54:29 -0500761// accept accepts a connection from listener, unless waitChan signals a process
762// exit first.
763func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
764 type connOrError struct {
765 conn net.Conn
766 err error
767 }
768 connChan := make(chan connOrError, 1)
769 go func() {
770 conn, err := listener.Accept()
771 connChan <- connOrError{conn, err}
772 close(connChan)
773 }()
774 select {
775 case result := <-connChan:
776 return result.conn, result.err
777 case childErr := <-waitChan:
778 waitChan <- childErr
779 return nil, fmt.Errorf("child exited early: %s", childErr)
780 }
781}
782
EKRf71d7ed2016-08-06 13:25:12 -0700783func translateExpectedError(errorStr string) string {
784 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
785 return translated
786 }
787
788 if *looseErrors {
789 return ""
790 }
791
792 return errorStr
793}
794
Adam Langley7c803a62015-06-15 15:35:05 -0700795func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700796 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
797 panic("Error expected without shouldFail in " + test.name)
798 }
799
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700800 if test.expectResumeRejected && !test.resumeSession {
801 panic("expectResumeRejected without resumeSession in " + test.name)
802 }
803
David Benjamin87c8a642015-02-21 01:54:29 -0500804 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
805 if err != nil {
806 panic(err)
807 }
808 defer func() {
809 if listener != nil {
810 listener.Close()
811 }
812 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700813
David Benjamin87c8a642015-02-21 01:54:29 -0500814 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400815 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400816 flags = append(flags, "-server")
817
David Benjamin025b3d32014-07-01 19:53:04 -0400818 flags = append(flags, "-key-file")
819 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700820 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400821 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700822 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
824
825 flags = append(flags, "-cert-file")
826 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700827 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400828 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700829 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400830 }
831 }
David Benjamin5a593af2014-08-11 19:51:50 -0400832
David Benjamin6fd297b2014-08-11 18:43:38 -0400833 if test.protocol == dtls {
834 flags = append(flags, "-dtls")
835 }
836
David Benjamin46662482016-08-17 00:51:00 -0400837 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400838 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400839 resumeCount++
840 if test.resumeRenewedSession {
841 resumeCount++
842 }
843 }
844
845 if resumeCount > 0 {
846 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400847 }
848
David Benjamine58c4f52014-08-24 03:47:07 -0400849 if test.shimWritesFirst {
850 flags = append(flags, "-shim-writes-first")
851 }
852
David Benjamin30789da2015-08-29 22:56:45 -0400853 if test.shimShutsDown {
854 flags = append(flags, "-shim-shuts-down")
855 }
856
David Benjaminc565ebb2015-04-03 04:06:36 -0400857 if test.exportKeyingMaterial > 0 {
858 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
859 flags = append(flags, "-export-label", test.exportLabel)
860 flags = append(flags, "-export-context", test.exportContext)
861 if test.useExportContext {
862 flags = append(flags, "-use-export-context")
863 }
864 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700865 if test.expectResumeRejected {
866 flags = append(flags, "-expect-session-miss")
867 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400868
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700869 if test.testTLSUnique {
870 flags = append(flags, "-tls-unique")
871 }
872
David Benjamin025b3d32014-07-01 19:53:04 -0400873 flags = append(flags, test.flags...)
874
875 var shim *exec.Cmd
876 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700878 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700879 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500880 } else if *useLLDB {
881 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400882 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400884 }
David Benjamin025b3d32014-07-01 19:53:04 -0400885 shim.Stdin = os.Stdin
886 var stdoutBuf, stderrBuf bytes.Buffer
887 shim.Stdout = &stdoutBuf
888 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800889 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500890 shim.Env = os.Environ()
891 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800892 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400893 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800894 }
895 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
896 }
David Benjamin025b3d32014-07-01 19:53:04 -0400897
898 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700899 panic(err)
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 waitChan := make(chan error, 1)
902 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700903
904 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700905
David Benjamin87c8a642015-02-21 01:54:29 -0500906 conn, err := acceptOrWait(listener, waitChan)
907 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400908 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500909 conn.Close()
910 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500911
David Benjamin46662482016-08-17 00:51:00 -0400912 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400913 var resumeConfig Config
914 if test.resumeConfig != nil {
915 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400916 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500917 resumeConfig.SessionTicketKey = config.SessionTicketKey
918 resumeConfig.ClientSessionCache = config.ClientSessionCache
919 resumeConfig.ServerSessionCache = config.ServerSessionCache
920 }
David Benjamin2e045a92016-06-08 13:09:56 -0400921 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400922 } else {
923 resumeConfig = config
924 }
David Benjamin87c8a642015-02-21 01:54:29 -0500925 var connResume net.Conn
926 connResume, err = acceptOrWait(listener, waitChan)
927 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400928 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500929 connResume.Close()
930 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400931 }
932
David Benjamin87c8a642015-02-21 01:54:29 -0500933 // Close the listener now. This is to avoid hangs should the shim try to
934 // open more connections than expected.
935 listener.Close()
936 listener = nil
937
938 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800939 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200940 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
941 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800942 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200943 case 89:
944 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800945 }
946 }
Adam Langley95c29f32014-06-20 12:00:00 -0700947
David Benjamin9bea3492016-03-02 10:59:16 -0500948 // Account for Windows line endings.
949 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
950 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500951
952 // Separate the errors from the shim and those from tools like
953 // AddressSanitizer.
954 var extraStderr string
955 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
956 stderr = stderrParts[0]
957 extraStderr = stderrParts[1]
958 }
959
Adam Langley95c29f32014-06-20 12:00:00 -0700960 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700961 expectedError := translateExpectedError(test.expectedError)
962 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200963
Adam Langleyac61fa32014-06-23 12:03:11 -0700964 localError := "none"
965 if err != nil {
966 localError = err.Error()
967 }
968 if len(test.expectedLocalError) != 0 {
969 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
970 }
Adam Langley95c29f32014-06-20 12:00:00 -0700971
972 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700973 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700974 if childErr != nil {
975 childError = childErr.Error()
976 }
977
978 var msg string
979 switch {
980 case failed && !test.shouldFail:
981 msg = "unexpected failure"
982 case !failed && test.shouldFail:
983 msg = "unexpected success"
984 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700985 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700986 default:
987 panic("internal error")
988 }
989
David Benjaminc565ebb2015-04-03 04:06:36 -0400990 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 -0700991 }
992
David Benjaminff3a1492016-03-02 10:12:06 -0500993 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
994 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700995 }
996
997 return nil
998}
999
1000var tlsVersions = []struct {
1001 name string
1002 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001003 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001004 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001005}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001006 {"SSL3", VersionSSL30, "-no-ssl3", false},
1007 {"TLS1", VersionTLS10, "-no-tls1", true},
1008 {"TLS11", VersionTLS11, "-no-tls11", false},
1009 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001010 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001011}
1012
1013var testCipherSuites = []struct {
1014 name string
1015 id uint16
1016}{
1017 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001018 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001019 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001020 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001021 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001022 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001023 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001024 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1025 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001026 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001027 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1028 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001029 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1031 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001032 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1033 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001035 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001036 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001041 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001042 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001043 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001044 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001046 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1047 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1048 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1049 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001050 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1051 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001052 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1053 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001054 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001055 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1056 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001057 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001058}
1059
David Benjamin8b8c0062014-11-23 02:47:52 -05001060func hasComponent(suiteName, component string) bool {
1061 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1062}
1063
David Benjaminf7768e42014-08-31 02:06:47 -04001064func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001065 return hasComponent(suiteName, "GCM") ||
1066 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001067 hasComponent(suiteName, "SHA384") ||
1068 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001069}
1070
Nick Harper1fd39d82016-06-14 18:14:35 -07001071func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001072 // Only AEADs.
1073 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1074 return false
1075 }
1076 // No old CHACHA20_POLY1305.
1077 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1078 return false
1079 }
1080 // Must have ECDHE.
1081 // TODO(davidben,svaldez): Add pure PSK support.
1082 if !hasComponent(suiteName, "ECDHE") {
1083 return false
1084 }
1085 // TODO(davidben,svaldez): Add PSK support.
1086 if hasComponent(suiteName, "PSK") {
1087 return false
1088 }
1089 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001090}
1091
David Benjamin8b8c0062014-11-23 02:47:52 -05001092func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001093 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001094}
1095
Adam Langleya7997f12015-05-14 17:38:50 -07001096func bigFromHex(hex string) *big.Int {
1097 ret, ok := new(big.Int).SetString(hex, 16)
1098 if !ok {
1099 panic("failed to parse hex number 0x" + hex)
1100 }
1101 return ret
1102}
1103
Adam Langley7c803a62015-06-15 15:35:05 -07001104func addBasicTests() {
1105 basicTests := []testCase{
1106 {
Adam Langley7c803a62015-06-15 15:35:05 -07001107 name: "NoFallbackSCSV",
1108 config: Config{
1109 Bugs: ProtocolBugs{
1110 FailIfNotFallbackSCSV: true,
1111 },
1112 },
1113 shouldFail: true,
1114 expectedLocalError: "no fallback SCSV found",
1115 },
1116 {
1117 name: "SendFallbackSCSV",
1118 config: Config{
1119 Bugs: ProtocolBugs{
1120 FailIfNotFallbackSCSV: true,
1121 },
1122 },
1123 flags: []string{"-fallback-scsv"},
1124 },
1125 {
1126 name: "ClientCertificateTypes",
1127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001128 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001129 ClientAuth: RequestClientCert,
1130 ClientCertificateTypes: []byte{
1131 CertTypeDSSSign,
1132 CertTypeRSASign,
1133 CertTypeECDSASign,
1134 },
1135 },
1136 flags: []string{
1137 "-expect-certificate-types",
1138 base64.StdEncoding.EncodeToString([]byte{
1139 CertTypeDSSSign,
1140 CertTypeRSASign,
1141 CertTypeECDSASign,
1142 }),
1143 },
1144 },
1145 {
Adam Langley7c803a62015-06-15 15:35:05 -07001146 name: "UnauthenticatedECDH",
1147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001148 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001149 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1150 Bugs: ProtocolBugs{
1151 UnauthenticatedECDH: true,
1152 },
1153 },
1154 shouldFail: true,
1155 expectedError: ":UNEXPECTED_MESSAGE:",
1156 },
1157 {
1158 name: "SkipCertificateStatus",
1159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001160 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001161 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1162 Bugs: ProtocolBugs{
1163 SkipCertificateStatus: true,
1164 },
1165 },
1166 flags: []string{
1167 "-enable-ocsp-stapling",
1168 },
1169 },
1170 {
1171 name: "SkipServerKeyExchange",
1172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001173 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1175 Bugs: ProtocolBugs{
1176 SkipServerKeyExchange: true,
1177 },
1178 },
1179 shouldFail: true,
1180 expectedError: ":UNEXPECTED_MESSAGE:",
1181 },
1182 {
Adam Langley7c803a62015-06-15 15:35:05 -07001183 testType: serverTest,
1184 name: "Alert",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 SendSpuriousAlert: alertRecordOverflow,
1188 },
1189 },
1190 shouldFail: true,
1191 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1192 },
1193 {
1194 protocol: dtls,
1195 testType: serverTest,
1196 name: "Alert-DTLS",
1197 config: Config{
1198 Bugs: ProtocolBugs{
1199 SendSpuriousAlert: alertRecordOverflow,
1200 },
1201 },
1202 shouldFail: true,
1203 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1204 },
1205 {
1206 testType: serverTest,
1207 name: "FragmentAlert",
1208 config: Config{
1209 Bugs: ProtocolBugs{
1210 FragmentAlert: true,
1211 SendSpuriousAlert: alertRecordOverflow,
1212 },
1213 },
1214 shouldFail: true,
1215 expectedError: ":BAD_ALERT:",
1216 },
1217 {
1218 protocol: dtls,
1219 testType: serverTest,
1220 name: "FragmentAlert-DTLS",
1221 config: Config{
1222 Bugs: ProtocolBugs{
1223 FragmentAlert: true,
1224 SendSpuriousAlert: alertRecordOverflow,
1225 },
1226 },
1227 shouldFail: true,
1228 expectedError: ":BAD_ALERT:",
1229 },
1230 {
1231 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001232 name: "DoubleAlert",
1233 config: Config{
1234 Bugs: ProtocolBugs{
1235 DoubleAlert: true,
1236 SendSpuriousAlert: alertRecordOverflow,
1237 },
1238 },
1239 shouldFail: true,
1240 expectedError: ":BAD_ALERT:",
1241 },
1242 {
1243 protocol: dtls,
1244 testType: serverTest,
1245 name: "DoubleAlert-DTLS",
1246 config: Config{
1247 Bugs: ProtocolBugs{
1248 DoubleAlert: true,
1249 SendSpuriousAlert: alertRecordOverflow,
1250 },
1251 },
1252 shouldFail: true,
1253 expectedError: ":BAD_ALERT:",
1254 },
1255 {
Adam Langley7c803a62015-06-15 15:35:05 -07001256 name: "SkipNewSessionTicket",
1257 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001258 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001259 Bugs: ProtocolBugs{
1260 SkipNewSessionTicket: true,
1261 },
1262 },
1263 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001264 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001265 },
1266 {
1267 testType: serverTest,
1268 name: "FallbackSCSV",
1269 config: Config{
1270 MaxVersion: VersionTLS11,
1271 Bugs: ProtocolBugs{
1272 SendFallbackSCSV: true,
1273 },
1274 },
1275 shouldFail: true,
1276 expectedError: ":INAPPROPRIATE_FALLBACK:",
1277 },
1278 {
1279 testType: serverTest,
1280 name: "FallbackSCSV-VersionMatch",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 SendFallbackSCSV: true,
1284 },
1285 },
1286 },
1287 {
1288 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001289 name: "FallbackSCSV-VersionMatch-TLS12",
1290 config: Config{
1291 MaxVersion: VersionTLS12,
1292 Bugs: ProtocolBugs{
1293 SendFallbackSCSV: true,
1294 },
1295 },
1296 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1297 },
1298 {
1299 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001300 name: "FragmentedClientVersion",
1301 config: Config{
1302 Bugs: ProtocolBugs{
1303 MaxHandshakeRecordLength: 1,
1304 FragmentClientVersion: true,
1305 },
1306 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001307 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001308 },
1309 {
Adam Langley7c803a62015-06-15 15:35:05 -07001310 testType: serverTest,
1311 name: "HttpGET",
1312 sendPrefix: "GET / HTTP/1.0\n",
1313 shouldFail: true,
1314 expectedError: ":HTTP_REQUEST:",
1315 },
1316 {
1317 testType: serverTest,
1318 name: "HttpPOST",
1319 sendPrefix: "POST / HTTP/1.0\n",
1320 shouldFail: true,
1321 expectedError: ":HTTP_REQUEST:",
1322 },
1323 {
1324 testType: serverTest,
1325 name: "HttpHEAD",
1326 sendPrefix: "HEAD / HTTP/1.0\n",
1327 shouldFail: true,
1328 expectedError: ":HTTP_REQUEST:",
1329 },
1330 {
1331 testType: serverTest,
1332 name: "HttpPUT",
1333 sendPrefix: "PUT / HTTP/1.0\n",
1334 shouldFail: true,
1335 expectedError: ":HTTP_REQUEST:",
1336 },
1337 {
1338 testType: serverTest,
1339 name: "HttpCONNECT",
1340 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1341 shouldFail: true,
1342 expectedError: ":HTTPS_PROXY_REQUEST:",
1343 },
1344 {
1345 testType: serverTest,
1346 name: "Garbage",
1347 sendPrefix: "blah",
1348 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001349 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001350 },
1351 {
Adam Langley7c803a62015-06-15 15:35:05 -07001352 name: "RSAEphemeralKey",
1353 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001354 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001355 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1356 Bugs: ProtocolBugs{
1357 RSAEphemeralKey: true,
1358 },
1359 },
1360 shouldFail: true,
1361 expectedError: ":UNEXPECTED_MESSAGE:",
1362 },
1363 {
1364 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001365 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001366 shouldFail: true,
1367 expectedError: ":WRONG_SSL_VERSION:",
1368 },
1369 {
1370 protocol: dtls,
1371 name: "DisableEverything-DTLS",
1372 flags: []string{"-no-tls12", "-no-tls1"},
1373 shouldFail: true,
1374 expectedError: ":WRONG_SSL_VERSION:",
1375 },
1376 {
Adam Langley7c803a62015-06-15 15:35:05 -07001377 protocol: dtls,
1378 testType: serverTest,
1379 name: "MTU",
1380 config: Config{
1381 Bugs: ProtocolBugs{
1382 MaxPacketLength: 256,
1383 },
1384 },
1385 flags: []string{"-mtu", "256"},
1386 },
1387 {
1388 protocol: dtls,
1389 testType: serverTest,
1390 name: "MTUExceeded",
1391 config: Config{
1392 Bugs: ProtocolBugs{
1393 MaxPacketLength: 255,
1394 },
1395 },
1396 flags: []string{"-mtu", "256"},
1397 shouldFail: true,
1398 expectedLocalError: "dtls: exceeded maximum packet length",
1399 },
1400 {
1401 name: "CertMismatchRSA",
1402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001403 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001404 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001405 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001406 Bugs: ProtocolBugs{
1407 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1408 },
1409 },
1410 shouldFail: true,
1411 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1412 },
1413 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001414 name: "CertMismatchRSA-TLS13",
1415 config: Config{
1416 MaxVersion: VersionTLS13,
1417 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1418 Certificates: []Certificate{ecdsaP256Certificate},
1419 Bugs: ProtocolBugs{
1420 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1421 },
1422 },
1423 shouldFail: true,
1424 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1425 },
1426 {
Adam Langley7c803a62015-06-15 15:35:05 -07001427 name: "CertMismatchECDSA",
1428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001429 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001430 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001431 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001432 Bugs: ProtocolBugs{
1433 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1434 },
1435 },
1436 shouldFail: true,
1437 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1438 },
1439 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001440 name: "CertMismatchECDSA-TLS13",
1441 config: Config{
1442 MaxVersion: VersionTLS13,
1443 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1444 Certificates: []Certificate{rsaCertificate},
1445 Bugs: ProtocolBugs{
1446 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1447 },
1448 },
1449 shouldFail: true,
1450 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1451 },
1452 {
Adam Langley7c803a62015-06-15 15:35:05 -07001453 name: "EmptyCertificateList",
1454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001455 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001456 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1457 Bugs: ProtocolBugs{
1458 EmptyCertificateList: true,
1459 },
1460 },
1461 shouldFail: true,
1462 expectedError: ":DECODE_ERROR:",
1463 },
1464 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001465 name: "EmptyCertificateList-TLS13",
1466 config: Config{
1467 MaxVersion: VersionTLS13,
1468 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1469 Bugs: ProtocolBugs{
1470 EmptyCertificateList: true,
1471 },
1472 },
1473 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001474 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001475 },
1476 {
Adam Langley7c803a62015-06-15 15:35:05 -07001477 name: "TLSFatalBadPackets",
1478 damageFirstWrite: true,
1479 shouldFail: true,
1480 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1481 },
1482 {
1483 protocol: dtls,
1484 name: "DTLSIgnoreBadPackets",
1485 damageFirstWrite: true,
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets-Async",
1490 damageFirstWrite: true,
1491 flags: []string{"-async"},
1492 },
1493 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001494 name: "AppDataBeforeHandshake",
1495 config: Config{
1496 Bugs: ProtocolBugs{
1497 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1498 },
1499 },
1500 shouldFail: true,
1501 expectedError: ":UNEXPECTED_RECORD:",
1502 },
1503 {
1504 name: "AppDataBeforeHandshake-Empty",
1505 config: Config{
1506 Bugs: ProtocolBugs{
1507 AppDataBeforeHandshake: []byte{},
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_RECORD:",
1512 },
1513 {
1514 protocol: dtls,
1515 name: "AppDataBeforeHandshake-DTLS",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":UNEXPECTED_RECORD:",
1523 },
1524 {
1525 protocol: dtls,
1526 name: "AppDataBeforeHandshake-DTLS-Empty",
1527 config: Config{
1528 Bugs: ProtocolBugs{
1529 AppDataBeforeHandshake: []byte{},
1530 },
1531 },
1532 shouldFail: true,
1533 expectedError: ":UNEXPECTED_RECORD:",
1534 },
1535 {
Adam Langley7c803a62015-06-15 15:35:05 -07001536 name: "AppDataAfterChangeCipherSpec",
1537 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001538 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001539 Bugs: ProtocolBugs{
1540 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1541 },
1542 },
1543 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001544 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001545 },
1546 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001547 name: "AppDataAfterChangeCipherSpec-Empty",
1548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001549 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001550 Bugs: ProtocolBugs{
1551 AppDataAfterChangeCipherSpec: []byte{},
1552 },
1553 },
1554 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001555 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001556 },
1557 {
Adam Langley7c803a62015-06-15 15:35:05 -07001558 protocol: dtls,
1559 name: "AppDataAfterChangeCipherSpec-DTLS",
1560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001561 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001562 Bugs: ProtocolBugs{
1563 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1564 },
1565 },
1566 // BoringSSL's DTLS implementation will drop the out-of-order
1567 // application data.
1568 },
1569 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001570 protocol: dtls,
1571 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1572 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001573 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001574 Bugs: ProtocolBugs{
1575 AppDataAfterChangeCipherSpec: []byte{},
1576 },
1577 },
1578 // BoringSSL's DTLS implementation will drop the out-of-order
1579 // application data.
1580 },
1581 {
Adam Langley7c803a62015-06-15 15:35:05 -07001582 name: "AlertAfterChangeCipherSpec",
1583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001584 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001585 Bugs: ProtocolBugs{
1586 AlertAfterChangeCipherSpec: alertRecordOverflow,
1587 },
1588 },
1589 shouldFail: true,
1590 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1591 },
1592 {
1593 protocol: dtls,
1594 name: "AlertAfterChangeCipherSpec-DTLS",
1595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001596 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001597 Bugs: ProtocolBugs{
1598 AlertAfterChangeCipherSpec: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1603 },
1604 {
1605 protocol: dtls,
1606 name: "ReorderHandshakeFragments-Small-DTLS",
1607 config: Config{
1608 Bugs: ProtocolBugs{
1609 ReorderHandshakeFragments: true,
1610 // Small enough that every handshake message is
1611 // fragmented.
1612 MaxHandshakeRecordLength: 2,
1613 },
1614 },
1615 },
1616 {
1617 protocol: dtls,
1618 name: "ReorderHandshakeFragments-Large-DTLS",
1619 config: Config{
1620 Bugs: ProtocolBugs{
1621 ReorderHandshakeFragments: true,
1622 // Large enough that no handshake message is
1623 // fragmented.
1624 MaxHandshakeRecordLength: 2048,
1625 },
1626 },
1627 },
1628 {
1629 protocol: dtls,
1630 name: "MixCompleteMessageWithFragments-DTLS",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 ReorderHandshakeFragments: true,
1634 MixCompleteMessageWithFragments: true,
1635 MaxHandshakeRecordLength: 2,
1636 },
1637 },
1638 },
1639 {
1640 name: "SendInvalidRecordType",
1641 config: Config{
1642 Bugs: ProtocolBugs{
1643 SendInvalidRecordType: true,
1644 },
1645 },
1646 shouldFail: true,
1647 expectedError: ":UNEXPECTED_RECORD:",
1648 },
1649 {
1650 protocol: dtls,
1651 name: "SendInvalidRecordType-DTLS",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 SendInvalidRecordType: true,
1655 },
1656 },
1657 shouldFail: true,
1658 expectedError: ":UNEXPECTED_RECORD:",
1659 },
1660 {
1661 name: "FalseStart-SkipServerSecondLeg",
1662 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001663 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1665 NextProtos: []string{"foo"},
1666 Bugs: ProtocolBugs{
1667 SkipNewSessionTicket: true,
1668 SkipChangeCipherSpec: true,
1669 SkipFinished: true,
1670 ExpectFalseStart: true,
1671 },
1672 },
1673 flags: []string{
1674 "-false-start",
1675 "-handshake-never-done",
1676 "-advertise-alpn", "\x03foo",
1677 },
1678 shimWritesFirst: true,
1679 shouldFail: true,
1680 expectedError: ":UNEXPECTED_RECORD:",
1681 },
1682 {
1683 name: "FalseStart-SkipServerSecondLeg-Implicit",
1684 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001685 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001686 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1687 NextProtos: []string{"foo"},
1688 Bugs: ProtocolBugs{
1689 SkipNewSessionTicket: true,
1690 SkipChangeCipherSpec: true,
1691 SkipFinished: true,
1692 },
1693 },
1694 flags: []string{
1695 "-implicit-handshake",
1696 "-false-start",
1697 "-handshake-never-done",
1698 "-advertise-alpn", "\x03foo",
1699 },
1700 shouldFail: true,
1701 expectedError: ":UNEXPECTED_RECORD:",
1702 },
1703 {
1704 testType: serverTest,
1705 name: "FailEarlyCallback",
1706 flags: []string{"-fail-early-callback"},
1707 shouldFail: true,
1708 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001709 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001710 },
1711 {
Adam Langley7c803a62015-06-15 15:35:05 -07001712 protocol: dtls,
1713 name: "FragmentMessageTypeMismatch-DTLS",
1714 config: Config{
1715 Bugs: ProtocolBugs{
1716 MaxHandshakeRecordLength: 2,
1717 FragmentMessageTypeMismatch: true,
1718 },
1719 },
1720 shouldFail: true,
1721 expectedError: ":FRAGMENT_MISMATCH:",
1722 },
1723 {
1724 protocol: dtls,
1725 name: "FragmentMessageLengthMismatch-DTLS",
1726 config: Config{
1727 Bugs: ProtocolBugs{
1728 MaxHandshakeRecordLength: 2,
1729 FragmentMessageLengthMismatch: true,
1730 },
1731 },
1732 shouldFail: true,
1733 expectedError: ":FRAGMENT_MISMATCH:",
1734 },
1735 {
1736 protocol: dtls,
1737 name: "SplitFragments-Header-DTLS",
1738 config: Config{
1739 Bugs: ProtocolBugs{
1740 SplitFragments: 2,
1741 },
1742 },
1743 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001744 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001745 },
1746 {
1747 protocol: dtls,
1748 name: "SplitFragments-Boundary-DTLS",
1749 config: Config{
1750 Bugs: ProtocolBugs{
1751 SplitFragments: dtlsRecordHeaderLen,
1752 },
1753 },
1754 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001755 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001756 },
1757 {
1758 protocol: dtls,
1759 name: "SplitFragments-Body-DTLS",
1760 config: Config{
1761 Bugs: ProtocolBugs{
1762 SplitFragments: dtlsRecordHeaderLen + 1,
1763 },
1764 },
1765 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001766 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001767 },
1768 {
1769 protocol: dtls,
1770 name: "SendEmptyFragments-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 SendEmptyFragments: true,
1774 },
1775 },
1776 },
1777 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001778 name: "BadFinished-Client",
1779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001780 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001781 Bugs: ProtocolBugs{
1782 BadFinished: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":DIGEST_CHECK_FAILED:",
1787 },
1788 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001789 name: "BadFinished-Client-TLS13",
1790 config: Config{
1791 MaxVersion: VersionTLS13,
1792 Bugs: ProtocolBugs{
1793 BadFinished: true,
1794 },
1795 },
1796 shouldFail: true,
1797 expectedError: ":DIGEST_CHECK_FAILED:",
1798 },
1799 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001800 testType: serverTest,
1801 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001802 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 Bugs: ProtocolBugs{
1805 BadFinished: true,
1806 },
1807 },
1808 shouldFail: true,
1809 expectedError: ":DIGEST_CHECK_FAILED:",
1810 },
1811 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001812 testType: serverTest,
1813 name: "BadFinished-Server-TLS13",
1814 config: Config{
1815 MaxVersion: VersionTLS13,
1816 Bugs: ProtocolBugs{
1817 BadFinished: true,
1818 },
1819 },
1820 shouldFail: true,
1821 expectedError: ":DIGEST_CHECK_FAILED:",
1822 },
1823 {
Adam Langley7c803a62015-06-15 15:35:05 -07001824 name: "FalseStart-BadFinished",
1825 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001826 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001827 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1828 NextProtos: []string{"foo"},
1829 Bugs: ProtocolBugs{
1830 BadFinished: true,
1831 ExpectFalseStart: true,
1832 },
1833 },
1834 flags: []string{
1835 "-false-start",
1836 "-handshake-never-done",
1837 "-advertise-alpn", "\x03foo",
1838 },
1839 shimWritesFirst: true,
1840 shouldFail: true,
1841 expectedError: ":DIGEST_CHECK_FAILED:",
1842 },
1843 {
1844 name: "NoFalseStart-NoALPN",
1845 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001846 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001847 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1848 Bugs: ProtocolBugs{
1849 ExpectFalseStart: true,
1850 AlertBeforeFalseStartTest: alertAccessDenied,
1851 },
1852 },
1853 flags: []string{
1854 "-false-start",
1855 },
1856 shimWritesFirst: true,
1857 shouldFail: true,
1858 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1859 expectedLocalError: "tls: peer did not false start: EOF",
1860 },
1861 {
1862 name: "NoFalseStart-NoAEAD",
1863 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001864 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001865 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1866 NextProtos: []string{"foo"},
1867 Bugs: ProtocolBugs{
1868 ExpectFalseStart: true,
1869 AlertBeforeFalseStartTest: alertAccessDenied,
1870 },
1871 },
1872 flags: []string{
1873 "-false-start",
1874 "-advertise-alpn", "\x03foo",
1875 },
1876 shimWritesFirst: true,
1877 shouldFail: true,
1878 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1879 expectedLocalError: "tls: peer did not false start: EOF",
1880 },
1881 {
1882 name: "NoFalseStart-RSA",
1883 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001884 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001885 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1886 NextProtos: []string{"foo"},
1887 Bugs: ProtocolBugs{
1888 ExpectFalseStart: true,
1889 AlertBeforeFalseStartTest: alertAccessDenied,
1890 },
1891 },
1892 flags: []string{
1893 "-false-start",
1894 "-advertise-alpn", "\x03foo",
1895 },
1896 shimWritesFirst: true,
1897 shouldFail: true,
1898 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1899 expectedLocalError: "tls: peer did not false start: EOF",
1900 },
1901 {
1902 name: "NoFalseStart-DHE_RSA",
1903 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001904 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001905 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1906 NextProtos: []string{"foo"},
1907 Bugs: ProtocolBugs{
1908 ExpectFalseStart: true,
1909 AlertBeforeFalseStartTest: alertAccessDenied,
1910 },
1911 },
1912 flags: []string{
1913 "-false-start",
1914 "-advertise-alpn", "\x03foo",
1915 },
1916 shimWritesFirst: true,
1917 shouldFail: true,
1918 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1919 expectedLocalError: "tls: peer did not false start: EOF",
1920 },
1921 {
Adam Langley7c803a62015-06-15 15:35:05 -07001922 protocol: dtls,
1923 name: "SendSplitAlert-Sync",
1924 config: Config{
1925 Bugs: ProtocolBugs{
1926 SendSplitAlert: true,
1927 },
1928 },
1929 },
1930 {
1931 protocol: dtls,
1932 name: "SendSplitAlert-Async",
1933 config: Config{
1934 Bugs: ProtocolBugs{
1935 SendSplitAlert: true,
1936 },
1937 },
1938 flags: []string{"-async"},
1939 },
1940 {
1941 protocol: dtls,
1942 name: "PackDTLSHandshake",
1943 config: Config{
1944 Bugs: ProtocolBugs{
1945 MaxHandshakeRecordLength: 2,
1946 PackHandshakeFragments: 20,
1947 PackHandshakeRecords: 200,
1948 },
1949 },
1950 },
1951 {
Adam Langley7c803a62015-06-15 15:35:05 -07001952 name: "SendEmptyRecords-Pass",
1953 sendEmptyRecords: 32,
1954 },
1955 {
1956 name: "SendEmptyRecords",
1957 sendEmptyRecords: 33,
1958 shouldFail: true,
1959 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1960 },
1961 {
1962 name: "SendEmptyRecords-Async",
1963 sendEmptyRecords: 33,
1964 flags: []string{"-async"},
1965 shouldFail: true,
1966 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1967 },
1968 {
David Benjamine8e84b92016-08-03 15:39:47 -04001969 name: "SendWarningAlerts-Pass",
1970 config: Config{
1971 MaxVersion: VersionTLS12,
1972 },
Adam Langley7c803a62015-06-15 15:35:05 -07001973 sendWarningAlerts: 4,
1974 },
1975 {
David Benjamine8e84b92016-08-03 15:39:47 -04001976 protocol: dtls,
1977 name: "SendWarningAlerts-DTLS-Pass",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 4,
1982 },
1983 {
David Benjamine8e84b92016-08-03 15:39:47 -04001984 name: "SendWarningAlerts-TLS13",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 },
1988 sendWarningAlerts: 4,
1989 shouldFail: true,
1990 expectedError: ":BAD_ALERT:",
1991 expectedLocalError: "remote error: error decoding message",
1992 },
1993 {
1994 name: "SendWarningAlerts",
1995 config: Config{
1996 MaxVersion: VersionTLS12,
1997 },
Adam Langley7c803a62015-06-15 15:35:05 -07001998 sendWarningAlerts: 5,
1999 shouldFail: true,
2000 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2001 },
2002 {
David Benjamine8e84b92016-08-03 15:39:47 -04002003 name: "SendWarningAlerts-Async",
2004 config: Config{
2005 MaxVersion: VersionTLS12,
2006 },
Adam Langley7c803a62015-06-15 15:35:05 -07002007 sendWarningAlerts: 5,
2008 flags: []string{"-async"},
2009 shouldFail: true,
2010 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2011 },
David Benjaminba4594a2015-06-18 18:36:15 -04002012 {
Steven Valdez32635b82016-08-16 11:25:03 -04002013 name: "SendKeyUpdates",
2014 config: Config{
2015 MaxVersion: VersionTLS13,
2016 },
2017 sendKeyUpdates: 33,
2018 shouldFail: true,
2019 expectedError: ":TOO_MANY_KEY_UPDATES:",
2020 },
2021 {
David Benjaminba4594a2015-06-18 18:36:15 -04002022 name: "EmptySessionID",
2023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002024 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002025 SessionTicketsDisabled: true,
2026 },
2027 noSessionCache: true,
2028 flags: []string{"-expect-no-session"},
2029 },
David Benjamin30789da2015-08-29 22:56:45 -04002030 {
2031 name: "Unclean-Shutdown",
2032 config: Config{
2033 Bugs: ProtocolBugs{
2034 NoCloseNotify: true,
2035 ExpectCloseNotify: true,
2036 },
2037 },
2038 shimShutsDown: true,
2039 flags: []string{"-check-close-notify"},
2040 shouldFail: true,
2041 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2042 },
2043 {
2044 name: "Unclean-Shutdown-Ignored",
2045 config: Config{
2046 Bugs: ProtocolBugs{
2047 NoCloseNotify: true,
2048 },
2049 },
2050 shimShutsDown: true,
2051 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002052 {
David Benjaminfa214e42016-05-10 17:03:10 -04002053 name: "Unclean-Shutdown-Alert",
2054 config: Config{
2055 Bugs: ProtocolBugs{
2056 SendAlertOnShutdown: alertDecompressionFailure,
2057 ExpectCloseNotify: true,
2058 },
2059 },
2060 shimShutsDown: true,
2061 flags: []string{"-check-close-notify"},
2062 shouldFail: true,
2063 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2064 },
2065 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002066 name: "LargePlaintext",
2067 config: Config{
2068 Bugs: ProtocolBugs{
2069 SendLargeRecords: true,
2070 },
2071 },
2072 messageLen: maxPlaintext + 1,
2073 shouldFail: true,
2074 expectedError: ":DATA_LENGTH_TOO_LONG:",
2075 },
2076 {
2077 protocol: dtls,
2078 name: "LargePlaintext-DTLS",
2079 config: Config{
2080 Bugs: ProtocolBugs{
2081 SendLargeRecords: true,
2082 },
2083 },
2084 messageLen: maxPlaintext + 1,
2085 shouldFail: true,
2086 expectedError: ":DATA_LENGTH_TOO_LONG:",
2087 },
2088 {
2089 name: "LargeCiphertext",
2090 config: Config{
2091 Bugs: ProtocolBugs{
2092 SendLargeRecords: true,
2093 },
2094 },
2095 messageLen: maxPlaintext * 2,
2096 shouldFail: true,
2097 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2098 },
2099 {
2100 protocol: dtls,
2101 name: "LargeCiphertext-DTLS",
2102 config: Config{
2103 Bugs: ProtocolBugs{
2104 SendLargeRecords: true,
2105 },
2106 },
2107 messageLen: maxPlaintext * 2,
2108 // Unlike the other four cases, DTLS drops records which
2109 // are invalid before authentication, so the connection
2110 // does not fail.
2111 expectMessageDropped: true,
2112 },
David Benjamindd6fed92015-10-23 17:41:12 -04002113 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002114 // In TLS 1.2 and below, empty NewSessionTicket messages
2115 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002116 name: "SendEmptySessionTicket",
2117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002118 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002119 Bugs: ProtocolBugs{
2120 SendEmptySessionTicket: true,
2121 FailIfSessionOffered: true,
2122 },
2123 },
David Benjamin46662482016-08-17 00:51:00 -04002124 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002125 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002126 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002127 name: "BadHelloRequest-1",
2128 renegotiate: 1,
2129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002130 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002131 Bugs: ProtocolBugs{
2132 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2133 },
2134 },
2135 flags: []string{
2136 "-renegotiate-freely",
2137 "-expect-total-renegotiations", "1",
2138 },
2139 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002140 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002141 },
2142 {
2143 name: "BadHelloRequest-2",
2144 renegotiate: 1,
2145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002146 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002147 Bugs: ProtocolBugs{
2148 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2149 },
2150 },
2151 flags: []string{
2152 "-renegotiate-freely",
2153 "-expect-total-renegotiations", "1",
2154 },
2155 shouldFail: true,
2156 expectedError: ":BAD_HELLO_REQUEST:",
2157 },
David Benjaminef1b0092015-11-21 14:05:44 -05002158 {
2159 testType: serverTest,
2160 name: "SupportTicketsWithSessionID",
2161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002162 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002163 SessionTicketsDisabled: true,
2164 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002165 resumeConfig: &Config{
2166 MaxVersion: VersionTLS12,
2167 },
David Benjaminef1b0092015-11-21 14:05:44 -05002168 resumeSession: true,
2169 },
David Benjamin02edcd02016-07-27 17:40:37 -04002170 {
2171 protocol: dtls,
2172 name: "DTLS-SendExtraFinished",
2173 config: Config{
2174 Bugs: ProtocolBugs{
2175 SendExtraFinished: true,
2176 },
2177 },
2178 shouldFail: true,
2179 expectedError: ":UNEXPECTED_RECORD:",
2180 },
2181 {
2182 protocol: dtls,
2183 name: "DTLS-SendExtraFinished-Reordered",
2184 config: Config{
2185 Bugs: ProtocolBugs{
2186 MaxHandshakeRecordLength: 2,
2187 ReorderHandshakeFragments: true,
2188 SendExtraFinished: true,
2189 },
2190 },
2191 shouldFail: true,
2192 expectedError: ":UNEXPECTED_RECORD:",
2193 },
David Benjamine97fb482016-07-29 09:23:07 -04002194 {
2195 testType: serverTest,
2196 name: "V2ClientHello-EmptyRecordPrefix",
2197 config: Config{
2198 // Choose a cipher suite that does not involve
2199 // elliptic curves, so no extensions are
2200 // involved.
2201 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002202 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002203 Bugs: ProtocolBugs{
2204 SendV2ClientHello: true,
2205 },
2206 },
2207 sendPrefix: string([]byte{
2208 byte(recordTypeHandshake),
2209 3, 1, // version
2210 0, 0, // length
2211 }),
2212 // A no-op empty record may not be sent before V2ClientHello.
2213 shouldFail: true,
2214 expectedError: ":WRONG_VERSION_NUMBER:",
2215 },
2216 {
2217 testType: serverTest,
2218 name: "V2ClientHello-WarningAlertPrefix",
2219 config: Config{
2220 // Choose a cipher suite that does not involve
2221 // elliptic curves, so no extensions are
2222 // involved.
2223 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002224 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002225 Bugs: ProtocolBugs{
2226 SendV2ClientHello: true,
2227 },
2228 },
2229 sendPrefix: string([]byte{
2230 byte(recordTypeAlert),
2231 3, 1, // version
2232 0, 2, // length
2233 alertLevelWarning, byte(alertDecompressionFailure),
2234 }),
2235 // A no-op warning alert may not be sent before V2ClientHello.
2236 shouldFail: true,
2237 expectedError: ":WRONG_VERSION_NUMBER:",
2238 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002239 {
2240 testType: clientTest,
2241 name: "KeyUpdate",
2242 config: Config{
2243 MaxVersion: VersionTLS13,
2244 Bugs: ProtocolBugs{
2245 SendKeyUpdateBeforeEveryAppDataRecord: true,
2246 },
2247 },
2248 },
David Benjaminabe94e32016-09-04 14:18:58 -04002249 {
2250 name: "SendSNIWarningAlert",
2251 config: Config{
2252 MaxVersion: VersionTLS12,
2253 Bugs: ProtocolBugs{
2254 SendSNIWarningAlert: true,
2255 },
2256 },
2257 },
David Benjaminc241d792016-09-09 10:34:20 -04002258 {
2259 testType: serverTest,
2260 name: "ExtraCompressionMethods-TLS12",
2261 config: Config{
2262 MaxVersion: VersionTLS12,
2263 Bugs: ProtocolBugs{
2264 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2265 },
2266 },
2267 },
2268 {
2269 testType: serverTest,
2270 name: "ExtraCompressionMethods-TLS13",
2271 config: Config{
2272 MaxVersion: VersionTLS13,
2273 Bugs: ProtocolBugs{
2274 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2275 },
2276 },
2277 shouldFail: true,
2278 expectedError: ":INVALID_COMPRESSION_LIST:",
2279 expectedLocalError: "remote error: illegal parameter",
2280 },
2281 {
2282 testType: serverTest,
2283 name: "NoNullCompression-TLS12",
2284 config: Config{
2285 MaxVersion: VersionTLS12,
2286 Bugs: ProtocolBugs{
2287 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2288 },
2289 },
2290 shouldFail: true,
2291 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2292 expectedLocalError: "remote error: illegal parameter",
2293 },
2294 {
2295 testType: serverTest,
2296 name: "NoNullCompression-TLS13",
2297 config: Config{
2298 MaxVersion: VersionTLS13,
2299 Bugs: ProtocolBugs{
2300 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2301 },
2302 },
2303 shouldFail: true,
2304 expectedError: ":INVALID_COMPRESSION_LIST:",
2305 expectedLocalError: "remote error: illegal parameter",
2306 },
Adam Langley7c803a62015-06-15 15:35:05 -07002307 }
Adam Langley7c803a62015-06-15 15:35:05 -07002308 testCases = append(testCases, basicTests...)
2309}
2310
Adam Langley95c29f32014-06-20 12:00:00 -07002311func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002312 const bogusCipher = 0xfe00
2313
Adam Langley95c29f32014-06-20 12:00:00 -07002314 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002315 const psk = "12345"
2316 const pskIdentity = "luggage combo"
2317
Adam Langley95c29f32014-06-20 12:00:00 -07002318 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002319 var certFile string
2320 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002321 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002322 cert = ecdsaP256Certificate
2323 certFile = ecdsaP256CertificateFile
2324 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002325 } else {
David Benjamin33863262016-07-08 17:20:12 -07002326 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002327 certFile = rsaCertificateFile
2328 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002329 }
2330
David Benjamin48cae082014-10-27 01:06:24 -04002331 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002332 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002333 flags = append(flags,
2334 "-psk", psk,
2335 "-psk-identity", pskIdentity)
2336 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002337 if hasComponent(suite.name, "NULL") {
2338 // NULL ciphers must be explicitly enabled.
2339 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2340 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002341 if hasComponent(suite.name, "CECPQ1") {
2342 // CECPQ1 ciphers must be explicitly enabled.
2343 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2344 }
David Benjamin881f1962016-08-10 18:29:12 -04002345 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2346 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2347 // for now.
2348 flags = append(flags, "-cipher", suite.name)
2349 }
David Benjamin48cae082014-10-27 01:06:24 -04002350
Adam Langley95c29f32014-06-20 12:00:00 -07002351 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002352 for _, protocol := range []protocol{tls, dtls} {
2353 var prefix string
2354 if protocol == dtls {
2355 if !ver.hasDTLS {
2356 continue
2357 }
2358 prefix = "D"
2359 }
Adam Langley95c29f32014-06-20 12:00:00 -07002360
David Benjamin0407e762016-06-17 16:41:18 -04002361 var shouldServerFail, shouldClientFail bool
2362 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2363 // BoringSSL clients accept ECDHE on SSLv3, but
2364 // a BoringSSL server will never select it
2365 // because the extension is missing.
2366 shouldServerFail = true
2367 }
2368 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2369 shouldClientFail = true
2370 shouldServerFail = true
2371 }
David Benjamin54c217c2016-07-13 12:35:25 -04002372 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002373 shouldClientFail = true
2374 shouldServerFail = true
2375 }
David Benjamin0407e762016-06-17 16:41:18 -04002376 if !isDTLSCipher(suite.name) && protocol == dtls {
2377 shouldClientFail = true
2378 shouldServerFail = true
2379 }
David Benjamin4298d772015-12-19 00:18:25 -05002380
David Benjamin0407e762016-06-17 16:41:18 -04002381 var expectedServerError, expectedClientError string
2382 if shouldServerFail {
2383 expectedServerError = ":NO_SHARED_CIPHER:"
2384 }
2385 if shouldClientFail {
2386 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2387 }
David Benjamin025b3d32014-07-01 19:53:04 -04002388
David Benjamin6fd297b2014-08-11 18:43:38 -04002389 testCases = append(testCases, testCase{
2390 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002391 protocol: protocol,
2392
2393 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002394 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002395 MinVersion: ver.version,
2396 MaxVersion: ver.version,
2397 CipherSuites: []uint16{suite.id},
2398 Certificates: []Certificate{cert},
2399 PreSharedKey: []byte(psk),
2400 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002401 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002402 EnableAllCiphers: shouldServerFail,
2403 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002404 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002405 },
2406 certFile: certFile,
2407 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002408 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002409 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002410 shouldFail: shouldServerFail,
2411 expectedError: expectedServerError,
2412 })
2413
2414 testCases = append(testCases, testCase{
2415 testType: clientTest,
2416 protocol: protocol,
2417 name: prefix + ver.name + "-" + suite.name + "-client",
2418 config: Config{
2419 MinVersion: ver.version,
2420 MaxVersion: ver.version,
2421 CipherSuites: []uint16{suite.id},
2422 Certificates: []Certificate{cert},
2423 PreSharedKey: []byte(psk),
2424 PreSharedKeyIdentity: pskIdentity,
2425 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002426 EnableAllCiphers: shouldClientFail,
2427 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002428 },
2429 },
2430 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002431 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002432 shouldFail: shouldClientFail,
2433 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002434 })
David Benjamin2c99d282015-09-01 10:23:00 -04002435
Nick Harper1fd39d82016-06-14 18:14:35 -07002436 if !shouldClientFail {
2437 // Ensure the maximum record size is accepted.
2438 testCases = append(testCases, testCase{
2439 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2440 config: Config{
2441 MinVersion: ver.version,
2442 MaxVersion: ver.version,
2443 CipherSuites: []uint16{suite.id},
2444 Certificates: []Certificate{cert},
2445 PreSharedKey: []byte(psk),
2446 PreSharedKeyIdentity: pskIdentity,
2447 },
2448 flags: flags,
2449 messageLen: maxPlaintext,
2450 })
2451 }
2452 }
David Benjamin2c99d282015-09-01 10:23:00 -04002453 }
Adam Langley95c29f32014-06-20 12:00:00 -07002454 }
Adam Langleya7997f12015-05-14 17:38:50 -07002455
2456 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002457 name: "NoSharedCipher",
2458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002459 MaxVersion: VersionTLS12,
2460 CipherSuites: []uint16{},
2461 },
2462 shouldFail: true,
2463 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2464 })
2465
2466 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002467 name: "NoSharedCipher-TLS13",
2468 config: Config{
2469 MaxVersion: VersionTLS13,
2470 CipherSuites: []uint16{},
2471 },
2472 shouldFail: true,
2473 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2474 })
2475
2476 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002477 name: "UnsupportedCipherSuite",
2478 config: Config{
2479 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002480 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002481 Bugs: ProtocolBugs{
2482 IgnorePeerCipherPreferences: true,
2483 },
2484 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002485 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002486 shouldFail: true,
2487 expectedError: ":WRONG_CIPHER_RETURNED:",
2488 })
2489
2490 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002491 name: "ServerHelloBogusCipher",
2492 config: Config{
2493 MaxVersion: VersionTLS12,
2494 Bugs: ProtocolBugs{
2495 SendCipherSuite: bogusCipher,
2496 },
2497 },
2498 shouldFail: true,
2499 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2500 })
2501 testCases = append(testCases, testCase{
2502 name: "ServerHelloBogusCipher-TLS13",
2503 config: Config{
2504 MaxVersion: VersionTLS13,
2505 Bugs: ProtocolBugs{
2506 SendCipherSuite: bogusCipher,
2507 },
2508 },
2509 shouldFail: true,
2510 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2511 })
2512
2513 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002514 name: "WeakDH",
2515 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002516 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002517 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2518 Bugs: ProtocolBugs{
2519 // This is a 1023-bit prime number, generated
2520 // with:
2521 // openssl gendh 1023 | openssl asn1parse -i
2522 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2523 },
2524 },
2525 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002526 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002527 })
Adam Langleycef75832015-09-03 14:51:12 -07002528
David Benjamincd24a392015-11-11 13:23:05 -08002529 testCases = append(testCases, testCase{
2530 name: "SillyDH",
2531 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002532 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002533 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2534 Bugs: ProtocolBugs{
2535 // This is a 4097-bit prime number, generated
2536 // with:
2537 // openssl gendh 4097 | openssl asn1parse -i
2538 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2539 },
2540 },
2541 shouldFail: true,
2542 expectedError: ":DH_P_TOO_LONG:",
2543 })
2544
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002545 // This test ensures that Diffie-Hellman public values are padded with
2546 // zeros so that they're the same length as the prime. This is to avoid
2547 // hitting a bug in yaSSL.
2548 testCases = append(testCases, testCase{
2549 testType: serverTest,
2550 name: "DHPublicValuePadded",
2551 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002552 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002553 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2554 Bugs: ProtocolBugs{
2555 RequireDHPublicValueLen: (1025 + 7) / 8,
2556 },
2557 },
2558 flags: []string{"-use-sparse-dh-prime"},
2559 })
David Benjamincd24a392015-11-11 13:23:05 -08002560
David Benjamin241ae832016-01-15 03:04:54 -05002561 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002562 testCases = append(testCases, testCase{
2563 testType: serverTest,
2564 name: "UnknownCipher",
2565 config: Config{
2566 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2567 },
2568 })
2569
Adam Langleycef75832015-09-03 14:51:12 -07002570 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2571 // 1.1 specific cipher suite settings. A server is setup with the given
2572 // cipher lists and then a connection is made for each member of
2573 // expectations. The cipher suite that the server selects must match
2574 // the specified one.
2575 var versionSpecificCiphersTest = []struct {
2576 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2577 // expectations is a map from TLS version to cipher suite id.
2578 expectations map[uint16]uint16
2579 }{
2580 {
2581 // Test that the null case (where no version-specific ciphers are set)
2582 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002583 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2584 "", // no ciphers specifically for TLS ≥ 1.0
2585 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002586 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002587 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2588 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2589 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2590 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002591 },
2592 },
2593 {
2594 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2595 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002596 "DES-CBC3-SHA:AES128-SHA", // default
2597 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2598 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002599 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002600 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002601 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2602 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2603 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2604 },
2605 },
2606 {
2607 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2608 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002609 "DES-CBC3-SHA:AES128-SHA", // default
2610 "", // no ciphers specifically for TLS ≥ 1.0
2611 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002612 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002613 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2614 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002615 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2616 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2617 },
2618 },
2619 {
2620 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2621 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002622 "DES-CBC3-SHA:AES128-SHA", // default
2623 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2624 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002625 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002626 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002627 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2628 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2629 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2630 },
2631 },
2632 }
2633
2634 for i, test := range versionSpecificCiphersTest {
2635 for version, expectedCipherSuite := range test.expectations {
2636 flags := []string{"-cipher", test.ciphersDefault}
2637 if len(test.ciphersTLS10) > 0 {
2638 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2639 }
2640 if len(test.ciphersTLS11) > 0 {
2641 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2642 }
2643
2644 testCases = append(testCases, testCase{
2645 testType: serverTest,
2646 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2647 config: Config{
2648 MaxVersion: version,
2649 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002650 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 -07002651 },
2652 flags: flags,
2653 expectedCipher: expectedCipherSuite,
2654 })
2655 }
2656 }
Adam Langley95c29f32014-06-20 12:00:00 -07002657}
2658
2659func addBadECDSASignatureTests() {
2660 for badR := BadValue(1); badR < NumBadValues; badR++ {
2661 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002662 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002663 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2664 config: Config{
2665 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002666 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002667 Bugs: ProtocolBugs{
2668 BadECDSAR: badR,
2669 BadECDSAS: badS,
2670 },
2671 },
2672 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002673 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002674 })
2675 }
2676 }
2677}
2678
Adam Langley80842bd2014-06-20 12:00:00 -07002679func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002680 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002681 name: "MaxCBCPadding",
2682 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002683 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2685 Bugs: ProtocolBugs{
2686 MaxPadding: true,
2687 },
2688 },
2689 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2690 })
David Benjamin025b3d32014-07-01 19:53:04 -04002691 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002692 name: "BadCBCPadding",
2693 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002694 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2696 Bugs: ProtocolBugs{
2697 PaddingFirstByteBad: true,
2698 },
2699 },
2700 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002701 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002702 })
2703 // OpenSSL previously had an issue where the first byte of padding in
2704 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002705 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002706 name: "BadCBCPadding255",
2707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002708 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2710 Bugs: ProtocolBugs{
2711 MaxPadding: true,
2712 PaddingFirstByteBadIf255: true,
2713 },
2714 },
2715 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2716 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002717 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002718 })
2719}
2720
Kenny Root7fdeaf12014-08-05 15:23:37 -07002721func addCBCSplittingTests() {
2722 testCases = append(testCases, testCase{
2723 name: "CBCRecordSplitting",
2724 config: Config{
2725 MaxVersion: VersionTLS10,
2726 MinVersion: VersionTLS10,
2727 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2728 },
David Benjaminac8302a2015-09-01 17:18:15 -04002729 messageLen: -1, // read until EOF
2730 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002731 flags: []string{
2732 "-async",
2733 "-write-different-record-sizes",
2734 "-cbc-record-splitting",
2735 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002736 })
2737 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002738 name: "CBCRecordSplittingPartialWrite",
2739 config: Config{
2740 MaxVersion: VersionTLS10,
2741 MinVersion: VersionTLS10,
2742 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2743 },
2744 messageLen: -1, // read until EOF
2745 flags: []string{
2746 "-async",
2747 "-write-different-record-sizes",
2748 "-cbc-record-splitting",
2749 "-partial-write",
2750 },
2751 })
2752}
2753
David Benjamin636293b2014-07-08 17:59:18 -04002754func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002755 // Add a dummy cert pool to stress certificate authority parsing.
2756 // TODO(davidben): Add tests that those values parse out correctly.
2757 certPool := x509.NewCertPool()
2758 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2759 if err != nil {
2760 panic(err)
2761 }
2762 certPool.AddCert(cert)
2763
David Benjamin636293b2014-07-08 17:59:18 -04002764 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002765 testCases = append(testCases, testCase{
2766 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002767 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002768 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002769 MinVersion: ver.version,
2770 MaxVersion: ver.version,
2771 ClientAuth: RequireAnyClientCert,
2772 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002773 },
2774 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002775 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2776 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002777 },
2778 })
2779 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002780 testType: serverTest,
2781 name: ver.name + "-Server-ClientAuth-RSA",
2782 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002783 MinVersion: ver.version,
2784 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002785 Certificates: []Certificate{rsaCertificate},
2786 },
2787 flags: []string{"-require-any-client-certificate"},
2788 })
David Benjamine098ec22014-08-27 23:13:20 -04002789 if ver.version != VersionSSL30 {
2790 testCases = append(testCases, testCase{
2791 testType: serverTest,
2792 name: ver.name + "-Server-ClientAuth-ECDSA",
2793 config: Config{
2794 MinVersion: ver.version,
2795 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002796 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002797 },
2798 flags: []string{"-require-any-client-certificate"},
2799 })
2800 testCases = append(testCases, testCase{
2801 testType: clientTest,
2802 name: ver.name + "-Client-ClientAuth-ECDSA",
2803 config: Config{
2804 MinVersion: ver.version,
2805 MaxVersion: ver.version,
2806 ClientAuth: RequireAnyClientCert,
2807 ClientCAs: certPool,
2808 },
2809 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002810 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2811 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002812 },
2813 })
2814 }
Adam Langley37646832016-08-01 16:16:46 -07002815
2816 testCases = append(testCases, testCase{
2817 name: "NoClientCertificate-" + ver.name,
2818 config: Config{
2819 MinVersion: ver.version,
2820 MaxVersion: ver.version,
2821 ClientAuth: RequireAnyClientCert,
2822 },
2823 shouldFail: true,
2824 expectedLocalError: "client didn't provide a certificate",
2825 })
2826
2827 testCases = append(testCases, testCase{
2828 // Even if not configured to expect a certificate, OpenSSL will
2829 // return X509_V_OK as the verify_result.
2830 testType: serverTest,
2831 name: "NoClientCertificateRequested-Server-" + ver.name,
2832 config: Config{
2833 MinVersion: ver.version,
2834 MaxVersion: ver.version,
2835 },
2836 flags: []string{
2837 "-expect-verify-result",
2838 },
2839 // TODO(davidben): Switch this to true when TLS 1.3
2840 // supports session resumption.
2841 resumeSession: ver.version < VersionTLS13,
2842 })
2843
2844 testCases = append(testCases, testCase{
2845 // If a client certificate is not provided, OpenSSL will still
2846 // return X509_V_OK as the verify_result.
2847 testType: serverTest,
2848 name: "NoClientCertificate-Server-" + ver.name,
2849 config: Config{
2850 MinVersion: ver.version,
2851 MaxVersion: ver.version,
2852 },
2853 flags: []string{
2854 "-expect-verify-result",
2855 "-verify-peer",
2856 },
2857 // TODO(davidben): Switch this to true when TLS 1.3
2858 // supports session resumption.
2859 resumeSession: ver.version < VersionTLS13,
2860 })
2861
2862 testCases = append(testCases, testCase{
2863 testType: serverTest,
2864 name: "RequireAnyClientCertificate-" + ver.name,
2865 config: Config{
2866 MinVersion: ver.version,
2867 MaxVersion: ver.version,
2868 },
2869 flags: []string{"-require-any-client-certificate"},
2870 shouldFail: true,
2871 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2872 })
2873
2874 if ver.version != VersionSSL30 {
2875 testCases = append(testCases, testCase{
2876 testType: serverTest,
2877 name: "SkipClientCertificate-" + ver.name,
2878 config: Config{
2879 MinVersion: ver.version,
2880 MaxVersion: ver.version,
2881 Bugs: ProtocolBugs{
2882 SkipClientCertificate: true,
2883 },
2884 },
2885 // Setting SSL_VERIFY_PEER allows anonymous clients.
2886 flags: []string{"-verify-peer"},
2887 shouldFail: true,
2888 expectedError: ":UNEXPECTED_MESSAGE:",
2889 })
2890 }
David Benjamin636293b2014-07-08 17:59:18 -04002891 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002892
David Benjaminc032dfa2016-05-12 14:54:57 -04002893 // Client auth is only legal in certificate-based ciphers.
2894 testCases = append(testCases, testCase{
2895 testType: clientTest,
2896 name: "ClientAuth-PSK",
2897 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002898 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002899 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2900 PreSharedKey: []byte("secret"),
2901 ClientAuth: RequireAnyClientCert,
2902 },
2903 flags: []string{
2904 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2905 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2906 "-psk", "secret",
2907 },
2908 shouldFail: true,
2909 expectedError: ":UNEXPECTED_MESSAGE:",
2910 })
2911 testCases = append(testCases, testCase{
2912 testType: clientTest,
2913 name: "ClientAuth-ECDHE_PSK",
2914 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002915 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002916 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2917 PreSharedKey: []byte("secret"),
2918 ClientAuth: RequireAnyClientCert,
2919 },
2920 flags: []string{
2921 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2922 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2923 "-psk", "secret",
2924 },
2925 shouldFail: true,
2926 expectedError: ":UNEXPECTED_MESSAGE:",
2927 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002928
2929 // Regression test for a bug where the client CA list, if explicitly
2930 // set to NULL, was mis-encoded.
2931 testCases = append(testCases, testCase{
2932 testType: serverTest,
2933 name: "Null-Client-CA-List",
2934 config: Config{
2935 MaxVersion: VersionTLS12,
2936 Certificates: []Certificate{rsaCertificate},
2937 },
2938 flags: []string{
2939 "-require-any-client-certificate",
2940 "-use-null-client-ca-list",
2941 },
2942 })
David Benjamin636293b2014-07-08 17:59:18 -04002943}
2944
Adam Langley75712922014-10-10 16:23:43 -07002945func addExtendedMasterSecretTests() {
2946 const expectEMSFlag = "-expect-extended-master-secret"
2947
2948 for _, with := range []bool{false, true} {
2949 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002950 if with {
2951 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002952 }
2953
2954 for _, isClient := range []bool{false, true} {
2955 suffix := "-Server"
2956 testType := serverTest
2957 if isClient {
2958 suffix = "-Client"
2959 testType = clientTest
2960 }
2961
2962 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002963 // In TLS 1.3, the extension is irrelevant and
2964 // always reports as enabled.
2965 var flags []string
2966 if with || ver.version >= VersionTLS13 {
2967 flags = []string{expectEMSFlag}
2968 }
2969
Adam Langley75712922014-10-10 16:23:43 -07002970 test := testCase{
2971 testType: testType,
2972 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2973 config: Config{
2974 MinVersion: ver.version,
2975 MaxVersion: ver.version,
2976 Bugs: ProtocolBugs{
2977 NoExtendedMasterSecret: !with,
2978 RequireExtendedMasterSecret: with,
2979 },
2980 },
David Benjamin48cae082014-10-27 01:06:24 -04002981 flags: flags,
2982 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002983 }
2984 if test.shouldFail {
2985 test.expectedLocalError = "extended master secret required but not supported by peer"
2986 }
2987 testCases = append(testCases, test)
2988 }
2989 }
2990 }
2991
Adam Langleyba5934b2015-06-02 10:50:35 -07002992 for _, isClient := range []bool{false, true} {
2993 for _, supportedInFirstConnection := range []bool{false, true} {
2994 for _, supportedInResumeConnection := range []bool{false, true} {
2995 boolToWord := func(b bool) string {
2996 if b {
2997 return "Yes"
2998 }
2999 return "No"
3000 }
3001 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3002 if isClient {
3003 suffix += "Client"
3004 } else {
3005 suffix += "Server"
3006 }
3007
3008 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003009 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003010 Bugs: ProtocolBugs{
3011 RequireExtendedMasterSecret: true,
3012 },
3013 }
3014
3015 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003016 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003017 Bugs: ProtocolBugs{
3018 NoExtendedMasterSecret: true,
3019 },
3020 }
3021
3022 test := testCase{
3023 name: "ExtendedMasterSecret-" + suffix,
3024 resumeSession: true,
3025 }
3026
3027 if !isClient {
3028 test.testType = serverTest
3029 }
3030
3031 if supportedInFirstConnection {
3032 test.config = supportedConfig
3033 } else {
3034 test.config = noSupportConfig
3035 }
3036
3037 if supportedInResumeConnection {
3038 test.resumeConfig = &supportedConfig
3039 } else {
3040 test.resumeConfig = &noSupportConfig
3041 }
3042
3043 switch suffix {
3044 case "YesToYes-Client", "YesToYes-Server":
3045 // When a session is resumed, it should
3046 // still be aware that its master
3047 // secret was generated via EMS and
3048 // thus it's safe to use tls-unique.
3049 test.flags = []string{expectEMSFlag}
3050 case "NoToYes-Server":
3051 // If an original connection did not
3052 // contain EMS, but a resumption
3053 // handshake does, then a server should
3054 // not resume the session.
3055 test.expectResumeRejected = true
3056 case "YesToNo-Server":
3057 // Resuming an EMS session without the
3058 // EMS extension should cause the
3059 // server to abort the connection.
3060 test.shouldFail = true
3061 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3062 case "NoToYes-Client":
3063 // A client should abort a connection
3064 // where the server resumed a non-EMS
3065 // session but echoed the EMS
3066 // extension.
3067 test.shouldFail = true
3068 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3069 case "YesToNo-Client":
3070 // A client should abort a connection
3071 // where the server didn't echo EMS
3072 // when the session used it.
3073 test.shouldFail = true
3074 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3075 }
3076
3077 testCases = append(testCases, test)
3078 }
3079 }
3080 }
David Benjamin163c9562016-08-29 23:14:17 -04003081
3082 // Switching EMS on renegotiation is forbidden.
3083 testCases = append(testCases, testCase{
3084 name: "ExtendedMasterSecret-Renego-NoEMS",
3085 config: Config{
3086 MaxVersion: VersionTLS12,
3087 Bugs: ProtocolBugs{
3088 NoExtendedMasterSecret: true,
3089 NoExtendedMasterSecretOnRenegotiation: true,
3090 },
3091 },
3092 renegotiate: 1,
3093 flags: []string{
3094 "-renegotiate-freely",
3095 "-expect-total-renegotiations", "1",
3096 },
3097 })
3098
3099 testCases = append(testCases, testCase{
3100 name: "ExtendedMasterSecret-Renego-Upgrade",
3101 config: Config{
3102 MaxVersion: VersionTLS12,
3103 Bugs: ProtocolBugs{
3104 NoExtendedMasterSecret: true,
3105 },
3106 },
3107 renegotiate: 1,
3108 flags: []string{
3109 "-renegotiate-freely",
3110 "-expect-total-renegotiations", "1",
3111 },
3112 shouldFail: true,
3113 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3114 })
3115
3116 testCases = append(testCases, testCase{
3117 name: "ExtendedMasterSecret-Renego-Downgrade",
3118 config: Config{
3119 MaxVersion: VersionTLS12,
3120 Bugs: ProtocolBugs{
3121 NoExtendedMasterSecretOnRenegotiation: true,
3122 },
3123 },
3124 renegotiate: 1,
3125 flags: []string{
3126 "-renegotiate-freely",
3127 "-expect-total-renegotiations", "1",
3128 },
3129 shouldFail: true,
3130 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3131 })
Adam Langley75712922014-10-10 16:23:43 -07003132}
3133
David Benjamin582ba042016-07-07 12:33:25 -07003134type stateMachineTestConfig struct {
3135 protocol protocol
3136 async bool
3137 splitHandshake, packHandshakeFlight bool
3138}
3139
David Benjamin43ec06f2014-08-05 02:28:57 -04003140// Adds tests that try to cover the range of the handshake state machine, under
3141// various conditions. Some of these are redundant with other tests, but they
3142// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003143func addAllStateMachineCoverageTests() {
3144 for _, async := range []bool{false, true} {
3145 for _, protocol := range []protocol{tls, dtls} {
3146 addStateMachineCoverageTests(stateMachineTestConfig{
3147 protocol: protocol,
3148 async: async,
3149 })
3150 addStateMachineCoverageTests(stateMachineTestConfig{
3151 protocol: protocol,
3152 async: async,
3153 splitHandshake: true,
3154 })
3155 if protocol == tls {
3156 addStateMachineCoverageTests(stateMachineTestConfig{
3157 protocol: protocol,
3158 async: async,
3159 packHandshakeFlight: true,
3160 })
3161 }
3162 }
3163 }
3164}
3165
3166func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003167 var tests []testCase
3168
3169 // Basic handshake, with resumption. Client and server,
3170 // session ID and session ticket.
3171 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003172 name: "Basic-Client",
3173 config: Config{
3174 MaxVersion: VersionTLS12,
3175 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003176 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003177 // Ensure session tickets are used, not session IDs.
3178 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003179 })
3180 tests = append(tests, testCase{
3181 name: "Basic-Client-RenewTicket",
3182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003183 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003184 Bugs: ProtocolBugs{
3185 RenewTicketOnResume: true,
3186 },
3187 },
David Benjamin46662482016-08-17 00:51:00 -04003188 flags: []string{"-expect-ticket-renewal"},
3189 resumeSession: true,
3190 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003191 })
3192 tests = append(tests, testCase{
3193 name: "Basic-Client-NoTicket",
3194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003195 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003196 SessionTicketsDisabled: true,
3197 },
3198 resumeSession: true,
3199 })
3200 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003201 name: "Basic-Client-Implicit",
3202 config: Config{
3203 MaxVersion: VersionTLS12,
3204 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 flags: []string{"-implicit-handshake"},
3206 resumeSession: true,
3207 })
3208 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003209 testType: serverTest,
3210 name: "Basic-Server",
3211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003213 Bugs: ProtocolBugs{
3214 RequireSessionTickets: true,
3215 },
3216 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003217 resumeSession: true,
3218 })
3219 tests = append(tests, testCase{
3220 testType: serverTest,
3221 name: "Basic-Server-NoTickets",
3222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003223 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003224 SessionTicketsDisabled: true,
3225 },
3226 resumeSession: true,
3227 })
3228 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 testType: serverTest,
3230 name: "Basic-Server-Implicit",
3231 config: Config{
3232 MaxVersion: VersionTLS12,
3233 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003234 flags: []string{"-implicit-handshake"},
3235 resumeSession: true,
3236 })
3237 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003238 testType: serverTest,
3239 name: "Basic-Server-EarlyCallback",
3240 config: Config{
3241 MaxVersion: VersionTLS12,
3242 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003243 flags: []string{"-use-early-callback"},
3244 resumeSession: true,
3245 })
3246
Steven Valdez143e8b32016-07-11 13:19:03 -04003247 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003248 if config.protocol == tls {
3249 tests = append(tests, testCase{
3250 name: "TLS13-1RTT-Client",
3251 config: Config{
3252 MaxVersion: VersionTLS13,
3253 MinVersion: VersionTLS13,
3254 },
David Benjamin46662482016-08-17 00:51:00 -04003255 resumeSession: true,
3256 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003257 })
3258
3259 tests = append(tests, testCase{
3260 testType: serverTest,
3261 name: "TLS13-1RTT-Server",
3262 config: Config{
3263 MaxVersion: VersionTLS13,
3264 MinVersion: VersionTLS13,
3265 },
David Benjamin46662482016-08-17 00:51:00 -04003266 resumeSession: true,
3267 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003268 })
3269
3270 tests = append(tests, testCase{
3271 name: "TLS13-HelloRetryRequest-Client",
3272 config: Config{
3273 MaxVersion: VersionTLS13,
3274 MinVersion: VersionTLS13,
3275 // P-384 requires a HelloRetryRequest against
3276 // BoringSSL's default configuration. Assert
3277 // that we do indeed test this with
3278 // ExpectMissingKeyShare.
3279 CurvePreferences: []CurveID{CurveP384},
3280 Bugs: ProtocolBugs{
3281 ExpectMissingKeyShare: true,
3282 },
3283 },
3284 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3285 resumeSession: true,
3286 })
3287
3288 tests = append(tests, testCase{
3289 testType: serverTest,
3290 name: "TLS13-HelloRetryRequest-Server",
3291 config: Config{
3292 MaxVersion: VersionTLS13,
3293 MinVersion: VersionTLS13,
3294 // Require a HelloRetryRequest for every curve.
3295 DefaultCurves: []CurveID{},
3296 },
3297 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3298 resumeSession: true,
3299 })
3300 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003301
David Benjamin760b1dd2015-05-15 23:33:48 -04003302 // TLS client auth.
3303 tests = append(tests, testCase{
3304 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003305 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003307 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003308 ClientAuth: RequestClientCert,
3309 },
3310 })
3311 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003312 testType: serverTest,
3313 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003314 config: Config{
3315 MaxVersion: VersionTLS12,
3316 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003317 // Setting SSL_VERIFY_PEER allows anonymous clients.
3318 flags: []string{"-verify-peer"},
3319 })
David Benjamin582ba042016-07-07 12:33:25 -07003320 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003321 tests = append(tests, testCase{
3322 testType: clientTest,
3323 name: "ClientAuth-NoCertificate-Client-SSL3",
3324 config: Config{
3325 MaxVersion: VersionSSL30,
3326 ClientAuth: RequestClientCert,
3327 },
3328 })
3329 tests = append(tests, testCase{
3330 testType: serverTest,
3331 name: "ClientAuth-NoCertificate-Server-SSL3",
3332 config: Config{
3333 MaxVersion: VersionSSL30,
3334 },
3335 // Setting SSL_VERIFY_PEER allows anonymous clients.
3336 flags: []string{"-verify-peer"},
3337 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003338 tests = append(tests, testCase{
3339 testType: clientTest,
3340 name: "ClientAuth-NoCertificate-Client-TLS13",
3341 config: Config{
3342 MaxVersion: VersionTLS13,
3343 ClientAuth: RequestClientCert,
3344 },
3345 })
3346 tests = append(tests, testCase{
3347 testType: serverTest,
3348 name: "ClientAuth-NoCertificate-Server-TLS13",
3349 config: Config{
3350 MaxVersion: VersionTLS13,
3351 },
3352 // Setting SSL_VERIFY_PEER allows anonymous clients.
3353 flags: []string{"-verify-peer"},
3354 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003355 }
3356 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003357 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003358 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003360 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003361 ClientAuth: RequireAnyClientCert,
3362 },
3363 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003364 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3365 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003366 },
3367 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003368 tests = append(tests, testCase{
3369 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003370 name: "ClientAuth-RSA-Client-TLS13",
3371 config: Config{
3372 MaxVersion: VersionTLS13,
3373 ClientAuth: RequireAnyClientCert,
3374 },
3375 flags: []string{
3376 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3377 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003382 name: "ClientAuth-ECDSA-Client",
3383 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003384 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003385 ClientAuth: RequireAnyClientCert,
3386 },
3387 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003388 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3389 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003390 },
3391 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003392 tests = append(tests, testCase{
3393 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003394 name: "ClientAuth-ECDSA-Client-TLS13",
3395 config: Config{
3396 MaxVersion: VersionTLS13,
3397 ClientAuth: RequireAnyClientCert,
3398 },
3399 flags: []string{
3400 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3401 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3402 },
3403 })
3404 tests = append(tests, testCase{
3405 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003406 name: "ClientAuth-NoCertificate-OldCallback",
3407 config: Config{
3408 MaxVersion: VersionTLS12,
3409 ClientAuth: RequestClientCert,
3410 },
3411 flags: []string{"-use-old-client-cert-callback"},
3412 })
3413 tests = append(tests, testCase{
3414 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003415 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3416 config: Config{
3417 MaxVersion: VersionTLS13,
3418 ClientAuth: RequestClientCert,
3419 },
3420 flags: []string{"-use-old-client-cert-callback"},
3421 })
3422 tests = append(tests, testCase{
3423 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003424 name: "ClientAuth-OldCallback",
3425 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003427 ClientAuth: RequireAnyClientCert,
3428 },
3429 flags: []string{
3430 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3431 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3432 "-use-old-client-cert-callback",
3433 },
3434 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003435 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003436 testType: clientTest,
3437 name: "ClientAuth-OldCallback-TLS13",
3438 config: Config{
3439 MaxVersion: VersionTLS13,
3440 ClientAuth: RequireAnyClientCert,
3441 },
3442 flags: []string{
3443 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3444 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3445 "-use-old-client-cert-callback",
3446 },
3447 })
3448 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003449 testType: serverTest,
3450 name: "ClientAuth-Server",
3451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003452 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003453 Certificates: []Certificate{rsaCertificate},
3454 },
3455 flags: []string{"-require-any-client-certificate"},
3456 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003457 tests = append(tests, testCase{
3458 testType: serverTest,
3459 name: "ClientAuth-Server-TLS13",
3460 config: Config{
3461 MaxVersion: VersionTLS13,
3462 Certificates: []Certificate{rsaCertificate},
3463 },
3464 flags: []string{"-require-any-client-certificate"},
3465 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003466
David Benjamin4c3ddf72016-06-29 18:13:53 -04003467 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003468 tests = append(tests, testCase{
3469 testType: serverTest,
3470 name: "Basic-Server-RSA",
3471 config: Config{
3472 MaxVersion: VersionTLS12,
3473 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3474 },
3475 flags: []string{
3476 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3477 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3478 },
3479 })
3480 tests = append(tests, testCase{
3481 testType: serverTest,
3482 name: "Basic-Server-ECDHE-RSA",
3483 config: Config{
3484 MaxVersion: VersionTLS12,
3485 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3486 },
3487 flags: []string{
3488 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3489 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3490 },
3491 })
3492 tests = append(tests, testCase{
3493 testType: serverTest,
3494 name: "Basic-Server-ECDHE-ECDSA",
3495 config: Config{
3496 MaxVersion: VersionTLS12,
3497 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3498 },
3499 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003500 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3501 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 },
3503 })
3504
David Benjamin760b1dd2015-05-15 23:33:48 -04003505 // No session ticket support; server doesn't send NewSessionTicket.
3506 tests = append(tests, testCase{
3507 name: "SessionTicketsDisabled-Client",
3508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003509 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003510 SessionTicketsDisabled: true,
3511 },
3512 })
3513 tests = append(tests, testCase{
3514 testType: serverTest,
3515 name: "SessionTicketsDisabled-Server",
3516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003517 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003518 SessionTicketsDisabled: true,
3519 },
3520 })
3521
3522 // Skip ServerKeyExchange in PSK key exchange if there's no
3523 // identity hint.
3524 tests = append(tests, testCase{
3525 name: "EmptyPSKHint-Client",
3526 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003527 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003528 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3529 PreSharedKey: []byte("secret"),
3530 },
3531 flags: []string{"-psk", "secret"},
3532 })
3533 tests = append(tests, testCase{
3534 testType: serverTest,
3535 name: "EmptyPSKHint-Server",
3536 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003537 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003538 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3539 PreSharedKey: []byte("secret"),
3540 },
3541 flags: []string{"-psk", "secret"},
3542 })
3543
David Benjamin4c3ddf72016-06-29 18:13:53 -04003544 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003545 tests = append(tests, testCase{
3546 testType: clientTest,
3547 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003548 config: Config{
3549 MaxVersion: VersionTLS12,
3550 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003551 flags: []string{
3552 "-enable-ocsp-stapling",
3553 "-expect-ocsp-response",
3554 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003555 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003556 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003557 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003558 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003559 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 testType: serverTest,
3561 name: "OCSPStapling-Server",
3562 config: Config{
3563 MaxVersion: VersionTLS12,
3564 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003565 expectedOCSPResponse: testOCSPResponse,
3566 flags: []string{
3567 "-ocsp-response",
3568 base64.StdEncoding.EncodeToString(testOCSPResponse),
3569 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003570 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003571 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003572 tests = append(tests, testCase{
3573 testType: clientTest,
3574 name: "OCSPStapling-Client-TLS13",
3575 config: Config{
3576 MaxVersion: VersionTLS13,
3577 },
3578 flags: []string{
3579 "-enable-ocsp-stapling",
3580 "-expect-ocsp-response",
3581 base64.StdEncoding.EncodeToString(testOCSPResponse),
3582 "-verify-peer",
3583 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003584 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003585 })
3586 tests = append(tests, testCase{
3587 testType: serverTest,
3588 name: "OCSPStapling-Server-TLS13",
3589 config: Config{
3590 MaxVersion: VersionTLS13,
3591 },
3592 expectedOCSPResponse: testOCSPResponse,
3593 flags: []string{
3594 "-ocsp-response",
3595 base64.StdEncoding.EncodeToString(testOCSPResponse),
3596 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003597 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003598 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003599
David Benjamin4c3ddf72016-06-29 18:13:53 -04003600 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003601 for _, vers := range tlsVersions {
3602 if config.protocol == dtls && !vers.hasDTLS {
3603 continue
3604 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003605 for _, testType := range []testType{clientTest, serverTest} {
3606 suffix := "-Client"
3607 if testType == serverTest {
3608 suffix = "-Server"
3609 }
3610 suffix += "-" + vers.name
3611
3612 flag := "-verify-peer"
3613 if testType == serverTest {
3614 flag = "-require-any-client-certificate"
3615 }
3616
3617 tests = append(tests, testCase{
3618 testType: testType,
3619 name: "CertificateVerificationSucceed" + suffix,
3620 config: Config{
3621 MaxVersion: vers.version,
3622 Certificates: []Certificate{rsaCertificate},
3623 },
3624 flags: []string{
3625 flag,
3626 "-expect-verify-result",
3627 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003628 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003629 })
3630 tests = append(tests, testCase{
3631 testType: testType,
3632 name: "CertificateVerificationFail" + suffix,
3633 config: Config{
3634 MaxVersion: vers.version,
3635 Certificates: []Certificate{rsaCertificate},
3636 },
3637 flags: []string{
3638 flag,
3639 "-verify-fail",
3640 },
3641 shouldFail: true,
3642 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3643 })
3644 }
3645
3646 // By default, the client is in a soft fail mode where the peer
3647 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003648 tests = append(tests, testCase{
3649 testType: clientTest,
3650 name: "CertificateVerificationSoftFail-" + vers.name,
3651 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003652 MaxVersion: vers.version,
3653 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003654 },
3655 flags: []string{
3656 "-verify-fail",
3657 "-expect-verify-result",
3658 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003659 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003660 })
3661 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003662
David Benjamin1d4f4c02016-07-26 18:03:08 -04003663 tests = append(tests, testCase{
3664 name: "ShimSendAlert",
3665 flags: []string{"-send-alert"},
3666 shimWritesFirst: true,
3667 shouldFail: true,
3668 expectedLocalError: "remote error: decompression failure",
3669 })
3670
David Benjamin582ba042016-07-07 12:33:25 -07003671 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003672 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003673 name: "Renegotiate-Client",
3674 config: Config{
3675 MaxVersion: VersionTLS12,
3676 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003677 renegotiate: 1,
3678 flags: []string{
3679 "-renegotiate-freely",
3680 "-expect-total-renegotiations", "1",
3681 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003682 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003683
David Benjamin47921102016-07-28 11:29:18 -04003684 tests = append(tests, testCase{
3685 name: "SendHalfHelloRequest",
3686 config: Config{
3687 MaxVersion: VersionTLS12,
3688 Bugs: ProtocolBugs{
3689 PackHelloRequestWithFinished: config.packHandshakeFlight,
3690 },
3691 },
3692 sendHalfHelloRequest: true,
3693 flags: []string{"-renegotiate-ignore"},
3694 shouldFail: true,
3695 expectedError: ":UNEXPECTED_RECORD:",
3696 })
3697
David Benjamin760b1dd2015-05-15 23:33:48 -04003698 // NPN on client and server; results in post-handshake message.
3699 tests = append(tests, testCase{
3700 name: "NPN-Client",
3701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003702 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003703 NextProtos: []string{"foo"},
3704 },
3705 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003706 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003707 expectedNextProto: "foo",
3708 expectedNextProtoType: npn,
3709 })
3710 tests = append(tests, testCase{
3711 testType: serverTest,
3712 name: "NPN-Server",
3713 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003714 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003715 NextProtos: []string{"bar"},
3716 },
3717 flags: []string{
3718 "-advertise-npn", "\x03foo\x03bar\x03baz",
3719 "-expect-next-proto", "bar",
3720 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003721 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003722 expectedNextProto: "bar",
3723 expectedNextProtoType: npn,
3724 })
3725
3726 // TODO(davidben): Add tests for when False Start doesn't trigger.
3727
3728 // Client does False Start and negotiates NPN.
3729 tests = append(tests, testCase{
3730 name: "FalseStart",
3731 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003732 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3734 NextProtos: []string{"foo"},
3735 Bugs: ProtocolBugs{
3736 ExpectFalseStart: true,
3737 },
3738 },
3739 flags: []string{
3740 "-false-start",
3741 "-select-next-proto", "foo",
3742 },
3743 shimWritesFirst: true,
3744 resumeSession: true,
3745 })
3746
3747 // Client does False Start and negotiates ALPN.
3748 tests = append(tests, testCase{
3749 name: "FalseStart-ALPN",
3750 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003751 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003752 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3753 NextProtos: []string{"foo"},
3754 Bugs: ProtocolBugs{
3755 ExpectFalseStart: true,
3756 },
3757 },
3758 flags: []string{
3759 "-false-start",
3760 "-advertise-alpn", "\x03foo",
3761 },
3762 shimWritesFirst: true,
3763 resumeSession: true,
3764 })
3765
3766 // Client does False Start but doesn't explicitly call
3767 // SSL_connect.
3768 tests = append(tests, testCase{
3769 name: "FalseStart-Implicit",
3770 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003771 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003772 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3773 NextProtos: []string{"foo"},
3774 },
3775 flags: []string{
3776 "-implicit-handshake",
3777 "-false-start",
3778 "-advertise-alpn", "\x03foo",
3779 },
3780 })
3781
3782 // False Start without session tickets.
3783 tests = append(tests, testCase{
3784 name: "FalseStart-SessionTicketsDisabled",
3785 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003786 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3788 NextProtos: []string{"foo"},
3789 SessionTicketsDisabled: true,
3790 Bugs: ProtocolBugs{
3791 ExpectFalseStart: true,
3792 },
3793 },
3794 flags: []string{
3795 "-false-start",
3796 "-select-next-proto", "foo",
3797 },
3798 shimWritesFirst: true,
3799 })
3800
Adam Langleydf759b52016-07-11 15:24:37 -07003801 tests = append(tests, testCase{
3802 name: "FalseStart-CECPQ1",
3803 config: Config{
3804 MaxVersion: VersionTLS12,
3805 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3806 NextProtos: []string{"foo"},
3807 Bugs: ProtocolBugs{
3808 ExpectFalseStart: true,
3809 },
3810 },
3811 flags: []string{
3812 "-false-start",
3813 "-cipher", "DEFAULT:kCECPQ1",
3814 "-select-next-proto", "foo",
3815 },
3816 shimWritesFirst: true,
3817 resumeSession: true,
3818 })
3819
David Benjamin760b1dd2015-05-15 23:33:48 -04003820 // Server parses a V2ClientHello.
3821 tests = append(tests, testCase{
3822 testType: serverTest,
3823 name: "SendV2ClientHello",
3824 config: Config{
3825 // Choose a cipher suite that does not involve
3826 // elliptic curves, so no extensions are
3827 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003828 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003829 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003830 Bugs: ProtocolBugs{
3831 SendV2ClientHello: true,
3832 },
3833 },
3834 })
3835
3836 // Client sends a Channel ID.
3837 tests = append(tests, testCase{
3838 name: "ChannelID-Client",
3839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003840 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003841 RequestChannelID: true,
3842 },
Adam Langley7c803a62015-06-15 15:35:05 -07003843 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003844 resumeSession: true,
3845 expectChannelID: true,
3846 })
3847
3848 // Server accepts a Channel ID.
3849 tests = append(tests, testCase{
3850 testType: serverTest,
3851 name: "ChannelID-Server",
3852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003853 MaxVersion: VersionTLS12,
3854 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003855 },
3856 flags: []string{
3857 "-expect-channel-id",
3858 base64.StdEncoding.EncodeToString(channelIDBytes),
3859 },
3860 resumeSession: true,
3861 expectChannelID: true,
3862 })
David Benjamin30789da2015-08-29 22:56:45 -04003863
David Benjaminf8fcdf32016-06-08 15:56:13 -04003864 // Channel ID and NPN at the same time, to ensure their relative
3865 // ordering is correct.
3866 tests = append(tests, testCase{
3867 name: "ChannelID-NPN-Client",
3868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003869 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003870 RequestChannelID: true,
3871 NextProtos: []string{"foo"},
3872 },
3873 flags: []string{
3874 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3875 "-select-next-proto", "foo",
3876 },
3877 resumeSession: true,
3878 expectChannelID: true,
3879 expectedNextProto: "foo",
3880 expectedNextProtoType: npn,
3881 })
3882 tests = append(tests, testCase{
3883 testType: serverTest,
3884 name: "ChannelID-NPN-Server",
3885 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003886 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003887 ChannelID: channelIDKey,
3888 NextProtos: []string{"bar"},
3889 },
3890 flags: []string{
3891 "-expect-channel-id",
3892 base64.StdEncoding.EncodeToString(channelIDBytes),
3893 "-advertise-npn", "\x03foo\x03bar\x03baz",
3894 "-expect-next-proto", "bar",
3895 },
3896 resumeSession: true,
3897 expectChannelID: true,
3898 expectedNextProto: "bar",
3899 expectedNextProtoType: npn,
3900 })
3901
David Benjamin30789da2015-08-29 22:56:45 -04003902 // Bidirectional shutdown with the runner initiating.
3903 tests = append(tests, testCase{
3904 name: "Shutdown-Runner",
3905 config: Config{
3906 Bugs: ProtocolBugs{
3907 ExpectCloseNotify: true,
3908 },
3909 },
3910 flags: []string{"-check-close-notify"},
3911 })
3912
3913 // Bidirectional shutdown with the shim initiating. The runner,
3914 // in the meantime, sends garbage before the close_notify which
3915 // the shim must ignore.
3916 tests = append(tests, testCase{
3917 name: "Shutdown-Shim",
3918 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003919 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003920 Bugs: ProtocolBugs{
3921 ExpectCloseNotify: true,
3922 },
3923 },
3924 shimShutsDown: true,
3925 sendEmptyRecords: 1,
3926 sendWarningAlerts: 1,
3927 flags: []string{"-check-close-notify"},
3928 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003930 // TODO(davidben): DTLS 1.3 will want a similar thing for
3931 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 tests = append(tests, testCase{
3933 name: "SkipHelloVerifyRequest",
3934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003935 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003936 Bugs: ProtocolBugs{
3937 SkipHelloVerifyRequest: true,
3938 },
3939 },
3940 })
3941 }
3942
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003944 test.protocol = config.protocol
3945 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003946 test.name += "-DTLS"
3947 }
David Benjamin582ba042016-07-07 12:33:25 -07003948 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003949 test.name += "-Async"
3950 test.flags = append(test.flags, "-async")
3951 } else {
3952 test.name += "-Sync"
3953 }
David Benjamin582ba042016-07-07 12:33:25 -07003954 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003955 test.name += "-SplitHandshakeRecords"
3956 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003957 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003958 test.config.Bugs.MaxPacketLength = 256
3959 test.flags = append(test.flags, "-mtu", "256")
3960 }
3961 }
David Benjamin582ba042016-07-07 12:33:25 -07003962 if config.packHandshakeFlight {
3963 test.name += "-PackHandshakeFlight"
3964 test.config.Bugs.PackHandshakeFlight = true
3965 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003966 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003967 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003968}
3969
Adam Langley524e7172015-02-20 16:04:00 -08003970func addDDoSCallbackTests() {
3971 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003972 for _, resume := range []bool{false, true} {
3973 suffix := "Resume"
3974 if resume {
3975 suffix = "No" + suffix
3976 }
3977
3978 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 testType: serverTest,
3980 name: "Server-DDoS-OK-" + suffix,
3981 config: Config{
3982 MaxVersion: VersionTLS12,
3983 },
Adam Langley524e7172015-02-20 16:04:00 -08003984 flags: []string{"-install-ddos-callback"},
3985 resumeSession: resume,
3986 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003987 testCases = append(testCases, testCase{
3988 testType: serverTest,
3989 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3990 config: Config{
3991 MaxVersion: VersionTLS13,
3992 },
3993 flags: []string{"-install-ddos-callback"},
3994 resumeSession: resume,
3995 })
Adam Langley524e7172015-02-20 16:04:00 -08003996
3997 failFlag := "-fail-ddos-callback"
3998 if resume {
3999 failFlag = "-fail-second-ddos-callback"
4000 }
4001 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004002 testType: serverTest,
4003 name: "Server-DDoS-Reject-" + suffix,
4004 config: Config{
4005 MaxVersion: VersionTLS12,
4006 },
David Benjamin2c66e072016-09-16 15:58:00 -04004007 flags: []string{"-install-ddos-callback", failFlag},
4008 resumeSession: resume,
4009 shouldFail: true,
4010 expectedError: ":CONNECTION_REJECTED:",
4011 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004012 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004013 testCases = append(testCases, testCase{
4014 testType: serverTest,
4015 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4016 config: Config{
4017 MaxVersion: VersionTLS13,
4018 },
David Benjamin2c66e072016-09-16 15:58:00 -04004019 flags: []string{"-install-ddos-callback", failFlag},
4020 resumeSession: resume,
4021 shouldFail: true,
4022 expectedError: ":CONNECTION_REJECTED:",
4023 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004024 })
Adam Langley524e7172015-02-20 16:04:00 -08004025 }
4026}
4027
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004028func addVersionNegotiationTests() {
4029 for i, shimVers := range tlsVersions {
4030 // Assemble flags to disable all newer versions on the shim.
4031 var flags []string
4032 for _, vers := range tlsVersions[i+1:] {
4033 flags = append(flags, vers.flag)
4034 }
4035
4036 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004037 protocols := []protocol{tls}
4038 if runnerVers.hasDTLS && shimVers.hasDTLS {
4039 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004040 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004041 for _, protocol := range protocols {
4042 expectedVersion := shimVers.version
4043 if runnerVers.version < shimVers.version {
4044 expectedVersion = runnerVers.version
4045 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004046
David Benjamin8b8c0062014-11-23 02:47:52 -05004047 suffix := shimVers.name + "-" + runnerVers.name
4048 if protocol == dtls {
4049 suffix += "-DTLS"
4050 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004051
David Benjamin1eb367c2014-12-12 18:17:51 -05004052 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4053
David Benjamin1e29a6b2014-12-10 02:27:24 -05004054 clientVers := shimVers.version
4055 if clientVers > VersionTLS10 {
4056 clientVers = VersionTLS10
4057 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004058 serverVers := expectedVersion
4059 if expectedVersion >= VersionTLS13 {
4060 serverVers = VersionTLS10
4061 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004062 testCases = append(testCases, testCase{
4063 protocol: protocol,
4064 testType: clientTest,
4065 name: "VersionNegotiation-Client-" + suffix,
4066 config: Config{
4067 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004068 Bugs: ProtocolBugs{
4069 ExpectInitialRecordVersion: clientVers,
4070 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004071 },
4072 flags: flags,
4073 expectedVersion: expectedVersion,
4074 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004075 testCases = append(testCases, testCase{
4076 protocol: protocol,
4077 testType: clientTest,
4078 name: "VersionNegotiation-Client2-" + suffix,
4079 config: Config{
4080 MaxVersion: runnerVers.version,
4081 Bugs: ProtocolBugs{
4082 ExpectInitialRecordVersion: clientVers,
4083 },
4084 },
4085 flags: []string{"-max-version", shimVersFlag},
4086 expectedVersion: expectedVersion,
4087 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004088
4089 testCases = append(testCases, testCase{
4090 protocol: protocol,
4091 testType: serverTest,
4092 name: "VersionNegotiation-Server-" + suffix,
4093 config: Config{
4094 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004095 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004096 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004097 },
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: serverTest,
4105 name: "VersionNegotiation-Server2-" + suffix,
4106 config: Config{
4107 MaxVersion: runnerVers.version,
4108 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004109 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004110 },
4111 },
4112 flags: []string{"-max-version", shimVersFlag},
4113 expectedVersion: expectedVersion,
4114 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004115 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004116 }
4117 }
David Benjamin95c69562016-06-29 18:15:03 -04004118
4119 // Test for version tolerance.
4120 testCases = append(testCases, testCase{
4121 testType: serverTest,
4122 name: "MinorVersionTolerance",
4123 config: Config{
4124 Bugs: ProtocolBugs{
4125 SendClientVersion: 0x03ff,
4126 },
4127 },
4128 expectedVersion: VersionTLS13,
4129 })
4130 testCases = append(testCases, testCase{
4131 testType: serverTest,
4132 name: "MajorVersionTolerance",
4133 config: Config{
4134 Bugs: ProtocolBugs{
4135 SendClientVersion: 0x0400,
4136 },
4137 },
4138 expectedVersion: VersionTLS13,
4139 })
4140 testCases = append(testCases, testCase{
4141 protocol: dtls,
4142 testType: serverTest,
4143 name: "MinorVersionTolerance-DTLS",
4144 config: Config{
4145 Bugs: ProtocolBugs{
4146 SendClientVersion: 0x03ff,
4147 },
4148 },
4149 expectedVersion: VersionTLS12,
4150 })
4151 testCases = append(testCases, testCase{
4152 protocol: dtls,
4153 testType: serverTest,
4154 name: "MajorVersionTolerance-DTLS",
4155 config: Config{
4156 Bugs: ProtocolBugs{
4157 SendClientVersion: 0x0400,
4158 },
4159 },
4160 expectedVersion: VersionTLS12,
4161 })
4162
4163 // Test that versions below 3.0 are rejected.
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "VersionTooLow",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0200,
4170 },
4171 },
4172 shouldFail: true,
4173 expectedError: ":UNSUPPORTED_PROTOCOL:",
4174 })
4175 testCases = append(testCases, testCase{
4176 protocol: dtls,
4177 testType: serverTest,
4178 name: "VersionTooLow-DTLS",
4179 config: Config{
4180 Bugs: ProtocolBugs{
4181 // 0x0201 is the lowest version expressable in
4182 // DTLS.
4183 SendClientVersion: 0x0201,
4184 },
4185 },
4186 shouldFail: true,
4187 expectedError: ":UNSUPPORTED_PROTOCOL:",
4188 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004189
4190 // Test TLS 1.3's downgrade signal.
4191 testCases = append(testCases, testCase{
4192 name: "Downgrade-TLS12-Client",
4193 config: Config{
4194 Bugs: ProtocolBugs{
4195 NegotiateVersion: VersionTLS12,
4196 },
4197 },
David Benjamin55108632016-08-11 22:01:18 -04004198 // TODO(davidben): This test should fail once TLS 1.3 is final
4199 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004200 })
4201 testCases = append(testCases, testCase{
4202 testType: serverTest,
4203 name: "Downgrade-TLS12-Server",
4204 config: Config{
4205 Bugs: ProtocolBugs{
4206 SendClientVersion: VersionTLS12,
4207 },
4208 },
David Benjamin55108632016-08-11 22:01:18 -04004209 // TODO(davidben): This test should fail once TLS 1.3 is final
4210 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004211 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004212
4213 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4214 // behave correctly when both real maximum and fallback versions are
4215 // set.
4216 testCases = append(testCases, testCase{
4217 name: "Downgrade-TLS12-Client-Fallback",
4218 config: Config{
4219 Bugs: ProtocolBugs{
4220 FailIfNotFallbackSCSV: true,
4221 },
4222 },
4223 flags: []string{
4224 "-max-version", strconv.Itoa(VersionTLS13),
4225 "-fallback-version", strconv.Itoa(VersionTLS12),
4226 },
David Benjamin55108632016-08-11 22:01:18 -04004227 // TODO(davidben): This test should fail once TLS 1.3 is final
4228 // and the fallback signal restored.
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004229 })
4230 testCases = append(testCases, testCase{
4231 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4232 flags: []string{
4233 "-max-version", strconv.Itoa(VersionTLS12),
4234 "-fallback-version", strconv.Itoa(VersionTLS12),
4235 },
4236 })
4237
4238 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4239 // just have such connections fail than risk getting confused because we
4240 // didn't sent the 1.3 ClientHello.)
4241 testCases = append(testCases, testCase{
4242 name: "Downgrade-TLS12-Fallback-CheckVersion",
4243 config: Config{
4244 Bugs: ProtocolBugs{
4245 NegotiateVersion: VersionTLS13,
4246 FailIfNotFallbackSCSV: true,
4247 },
4248 },
4249 flags: []string{
4250 "-max-version", strconv.Itoa(VersionTLS13),
4251 "-fallback-version", strconv.Itoa(VersionTLS12),
4252 },
4253 shouldFail: true,
4254 expectedError: ":UNSUPPORTED_PROTOCOL:",
4255 })
4256
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004257}
4258
David Benjaminaccb4542014-12-12 23:44:33 -05004259func addMinimumVersionTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all older versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[:i] {
4264 flags = append(flags, vers.flag)
4265 }
4266
4267 for _, runnerVers := range tlsVersions {
4268 protocols := []protocol{tls}
4269 if runnerVers.hasDTLS && shimVers.hasDTLS {
4270 protocols = append(protocols, dtls)
4271 }
4272 for _, protocol := range protocols {
4273 suffix := shimVers.name + "-" + runnerVers.name
4274 if protocol == dtls {
4275 suffix += "-DTLS"
4276 }
4277 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4278
David Benjaminaccb4542014-12-12 23:44:33 -05004279 var expectedVersion uint16
4280 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004281 var expectedClientError, expectedServerError string
4282 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004283 if runnerVers.version >= shimVers.version {
4284 expectedVersion = runnerVers.version
4285 } else {
4286 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004287 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4288 expectedServerLocalError = "remote error: protocol version not supported"
4289 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4290 // If the client's minimum version is TLS 1.3 and the runner's
4291 // maximum is below TLS 1.2, the runner will fail to select a
4292 // cipher before the shim rejects the selected version.
4293 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4294 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4295 } else {
4296 expectedClientError = expectedServerError
4297 expectedClientLocalError = expectedServerLocalError
4298 }
David Benjaminaccb4542014-12-12 23:44:33 -05004299 }
4300
4301 testCases = append(testCases, testCase{
4302 protocol: protocol,
4303 testType: clientTest,
4304 name: "MinimumVersion-Client-" + suffix,
4305 config: Config{
4306 MaxVersion: runnerVers.version,
4307 },
David Benjamin87909c02014-12-13 01:55:01 -05004308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004311 expectedError: expectedClientError,
4312 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004313 })
4314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: clientTest,
4317 name: "MinimumVersion-Client2-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
4320 },
David Benjamin87909c02014-12-13 01:55:01 -05004321 flags: []string{"-min-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004324 expectedError: expectedClientError,
4325 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004326 })
4327
4328 testCases = append(testCases, testCase{
4329 protocol: protocol,
4330 testType: serverTest,
4331 name: "MinimumVersion-Server-" + suffix,
4332 config: Config{
4333 MaxVersion: runnerVers.version,
4334 },
David Benjamin87909c02014-12-13 01:55:01 -05004335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004338 expectedError: expectedServerError,
4339 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004340 })
4341 testCases = append(testCases, testCase{
4342 protocol: protocol,
4343 testType: serverTest,
4344 name: "MinimumVersion-Server2-" + suffix,
4345 config: Config{
4346 MaxVersion: runnerVers.version,
4347 },
David Benjamin87909c02014-12-13 01:55:01 -05004348 flags: []string{"-min-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004351 expectedError: expectedServerError,
4352 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004353 })
4354 }
4355 }
4356 }
4357}
4358
David Benjamine78bfde2014-09-06 12:45:15 -04004359func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004360 // TODO(davidben): Extensions, where applicable, all move their server
4361 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4362 // tests for both. Also test interaction with 0-RTT when implemented.
4363
David Benjamin97d17d92016-07-14 16:12:00 -04004364 // Repeat extensions tests all versions except SSL 3.0.
4365 for _, ver := range tlsVersions {
4366 if ver.version == VersionSSL30 {
4367 continue
4368 }
4369
David Benjamin97d17d92016-07-14 16:12:00 -04004370 // Test that duplicate extensions are rejected.
4371 testCases = append(testCases, testCase{
4372 testType: clientTest,
4373 name: "DuplicateExtensionClient-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 Bugs: ProtocolBugs{
4377 DuplicateExtension: true,
4378 },
David Benjamine78bfde2014-09-06 12:45:15 -04004379 },
David Benjamin97d17d92016-07-14 16:12:00 -04004380 shouldFail: true,
4381 expectedLocalError: "remote error: error decoding message",
4382 })
4383 testCases = append(testCases, testCase{
4384 testType: serverTest,
4385 name: "DuplicateExtensionServer-" + ver.name,
4386 config: Config{
4387 MaxVersion: ver.version,
4388 Bugs: ProtocolBugs{
4389 DuplicateExtension: true,
4390 },
David Benjamine78bfde2014-09-06 12:45:15 -04004391 },
David Benjamin97d17d92016-07-14 16:12:00 -04004392 shouldFail: true,
4393 expectedLocalError: "remote error: error decoding message",
4394 })
4395
4396 // Test SNI.
4397 testCases = append(testCases, testCase{
4398 testType: clientTest,
4399 name: "ServerNameExtensionClient-" + ver.name,
4400 config: Config{
4401 MaxVersion: ver.version,
4402 Bugs: ProtocolBugs{
4403 ExpectServerName: "example.com",
4404 },
David Benjamine78bfde2014-09-06 12:45:15 -04004405 },
David Benjamin97d17d92016-07-14 16:12:00 -04004406 flags: []string{"-host-name", "example.com"},
4407 })
4408 testCases = append(testCases, testCase{
4409 testType: clientTest,
4410 name: "ServerNameExtensionClientMismatch-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 Bugs: ProtocolBugs{
4414 ExpectServerName: "mismatch.com",
4415 },
David Benjamine78bfde2014-09-06 12:45:15 -04004416 },
David Benjamin97d17d92016-07-14 16:12:00 -04004417 flags: []string{"-host-name", "example.com"},
4418 shouldFail: true,
4419 expectedLocalError: "tls: unexpected server name",
4420 })
4421 testCases = append(testCases, testCase{
4422 testType: clientTest,
4423 name: "ServerNameExtensionClientMissing-" + ver.name,
4424 config: Config{
4425 MaxVersion: ver.version,
4426 Bugs: ProtocolBugs{
4427 ExpectServerName: "missing.com",
4428 },
David Benjamine78bfde2014-09-06 12:45:15 -04004429 },
David Benjamin97d17d92016-07-14 16:12:00 -04004430 shouldFail: true,
4431 expectedLocalError: "tls: unexpected server name",
4432 })
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ServerNameExtensionServer-" + ver.name,
4436 config: Config{
4437 MaxVersion: ver.version,
4438 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004439 },
David Benjamin97d17d92016-07-14 16:12:00 -04004440 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004441 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004442 })
4443
4444 // Test ALPN.
4445 testCases = append(testCases, testCase{
4446 testType: clientTest,
4447 name: "ALPNClient-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo"},
4451 },
4452 flags: []string{
4453 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4454 "-expect-alpn", "foo",
4455 },
4456 expectedNextProto: "foo",
4457 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004458 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004459 })
4460 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004461 testType: clientTest,
4462 name: "ALPNClient-Mismatch-" + ver.name,
4463 config: Config{
4464 MaxVersion: ver.version,
4465 Bugs: ProtocolBugs{
4466 SendALPN: "baz",
4467 },
4468 },
4469 flags: []string{
4470 "-advertise-alpn", "\x03foo\x03bar",
4471 },
4472 shouldFail: true,
4473 expectedError: ":INVALID_ALPN_PROTOCOL:",
4474 expectedLocalError: "remote error: illegal parameter",
4475 })
4476 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004477 testType: serverTest,
4478 name: "ALPNServer-" + ver.name,
4479 config: Config{
4480 MaxVersion: ver.version,
4481 NextProtos: []string{"foo", "bar", "baz"},
4482 },
4483 flags: []string{
4484 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4485 "-select-alpn", "foo",
4486 },
4487 expectedNextProto: "foo",
4488 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004489 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004490 })
4491 testCases = append(testCases, testCase{
4492 testType: serverTest,
4493 name: "ALPNServer-Decline-" + ver.name,
4494 config: Config{
4495 MaxVersion: ver.version,
4496 NextProtos: []string{"foo", "bar", "baz"},
4497 },
4498 flags: []string{"-decline-alpn"},
4499 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004500 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004501 })
4502
David Benjamin25fe85b2016-08-09 20:00:32 -04004503 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4504 // called once.
4505 testCases = append(testCases, testCase{
4506 testType: serverTest,
4507 name: "ALPNServer-Async-" + ver.name,
4508 config: Config{
4509 MaxVersion: ver.version,
4510 NextProtos: []string{"foo", "bar", "baz"},
4511 },
4512 flags: []string{
4513 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4514 "-select-alpn", "foo",
4515 "-async",
4516 },
4517 expectedNextProto: "foo",
4518 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004519 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004520 })
4521
David Benjamin97d17d92016-07-14 16:12:00 -04004522 var emptyString string
4523 testCases = append(testCases, testCase{
4524 testType: clientTest,
4525 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 NextProtos: []string{""},
4529 Bugs: ProtocolBugs{
4530 // A server returning an empty ALPN protocol
4531 // should be rejected.
4532 ALPNProtocol: &emptyString,
4533 },
4534 },
4535 flags: []string{
4536 "-advertise-alpn", "\x03foo",
4537 },
4538 shouldFail: true,
4539 expectedError: ":PARSE_TLSEXT:",
4540 })
4541 testCases = append(testCases, testCase{
4542 testType: serverTest,
4543 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4544 config: Config{
4545 MaxVersion: ver.version,
4546 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004547 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004548 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004549 },
David Benjamin97d17d92016-07-14 16:12:00 -04004550 flags: []string{
4551 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004552 },
David Benjamin97d17d92016-07-14 16:12:00 -04004553 shouldFail: true,
4554 expectedError: ":PARSE_TLSEXT:",
4555 })
4556
4557 // Test NPN and the interaction with ALPN.
4558 if ver.version < VersionTLS13 {
4559 // Test that the server prefers ALPN over NPN.
4560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "ALPNServer-Preferred-" + ver.name,
4563 config: Config{
4564 MaxVersion: ver.version,
4565 NextProtos: []string{"foo", "bar", "baz"},
4566 },
4567 flags: []string{
4568 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4569 "-select-alpn", "foo",
4570 "-advertise-npn", "\x03foo\x03bar\x03baz",
4571 },
4572 expectedNextProto: "foo",
4573 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004574 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004575 })
4576 testCases = append(testCases, testCase{
4577 testType: serverTest,
4578 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 NextProtos: []string{"foo", "bar", "baz"},
4582 Bugs: ProtocolBugs{
4583 SwapNPNAndALPN: true,
4584 },
4585 },
4586 flags: []string{
4587 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4588 "-select-alpn", "foo",
4589 "-advertise-npn", "\x03foo\x03bar\x03baz",
4590 },
4591 expectedNextProto: "foo",
4592 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004593 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004594 })
4595
4596 // Test that negotiating both NPN and ALPN is forbidden.
4597 testCases = append(testCases, testCase{
4598 name: "NegotiateALPNAndNPN-" + ver.name,
4599 config: Config{
4600 MaxVersion: ver.version,
4601 NextProtos: []string{"foo", "bar", "baz"},
4602 Bugs: ProtocolBugs{
4603 NegotiateALPNAndNPN: true,
4604 },
4605 },
4606 flags: []string{
4607 "-advertise-alpn", "\x03foo",
4608 "-select-next-proto", "foo",
4609 },
4610 shouldFail: true,
4611 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4612 })
4613 testCases = append(testCases, testCase{
4614 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4615 config: Config{
4616 MaxVersion: ver.version,
4617 NextProtos: []string{"foo", "bar", "baz"},
4618 Bugs: ProtocolBugs{
4619 NegotiateALPNAndNPN: true,
4620 SwapNPNAndALPN: true,
4621 },
4622 },
4623 flags: []string{
4624 "-advertise-alpn", "\x03foo",
4625 "-select-next-proto", "foo",
4626 },
4627 shouldFail: true,
4628 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4629 })
4630
4631 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4632 testCases = append(testCases, testCase{
4633 name: "DisableNPN-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 NextProtos: []string{"foo"},
4637 },
4638 flags: []string{
4639 "-select-next-proto", "foo",
4640 "-disable-npn",
4641 },
4642 expectNoNextProto: true,
4643 })
4644 }
4645
4646 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004647
4648 // Resume with a corrupt ticket.
4649 testCases = append(testCases, testCase{
4650 testType: serverTest,
4651 name: "CorruptTicket-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 CorruptTicket: true,
4656 },
4657 },
4658 resumeSession: true,
4659 expectResumeRejected: true,
4660 })
4661 // Test the ticket callback, with and without renewal.
4662 testCases = append(testCases, testCase{
4663 testType: serverTest,
4664 name: "TicketCallback-" + ver.name,
4665 config: Config{
4666 MaxVersion: ver.version,
4667 },
4668 resumeSession: true,
4669 flags: []string{"-use-ticket-callback"},
4670 })
4671 testCases = append(testCases, testCase{
4672 testType: serverTest,
4673 name: "TicketCallback-Renew-" + ver.name,
4674 config: Config{
4675 MaxVersion: ver.version,
4676 Bugs: ProtocolBugs{
4677 ExpectNewTicket: true,
4678 },
4679 },
4680 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4681 resumeSession: true,
4682 })
4683
4684 // Test that the ticket callback is only called once when everything before
4685 // it in the ClientHello is asynchronous. This corrupts the ticket so
4686 // certificate selection callbacks run.
4687 testCases = append(testCases, testCase{
4688 testType: serverTest,
4689 name: "TicketCallback-SingleCall-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 Bugs: ProtocolBugs{
4693 CorruptTicket: true,
4694 },
4695 },
4696 resumeSession: true,
4697 expectResumeRejected: true,
4698 flags: []string{
4699 "-use-ticket-callback",
4700 "-async",
4701 },
4702 })
4703
4704 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004705 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004706 testCases = append(testCases, testCase{
4707 testType: serverTest,
4708 name: "OversizedSessionId-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 Bugs: ProtocolBugs{
4712 OversizedSessionId: true,
4713 },
4714 },
4715 resumeSession: true,
4716 shouldFail: true,
4717 expectedError: ":DECODE_ERROR:",
4718 })
4719 }
4720
4721 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4722 // are ignored.
4723 if ver.hasDTLS {
4724 testCases = append(testCases, testCase{
4725 protocol: dtls,
4726 name: "SRTP-Client-" + ver.name,
4727 config: Config{
4728 MaxVersion: ver.version,
4729 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4730 },
4731 flags: []string{
4732 "-srtp-profiles",
4733 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4734 },
4735 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4736 })
4737 testCases = append(testCases, testCase{
4738 protocol: dtls,
4739 testType: serverTest,
4740 name: "SRTP-Server-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
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 the MKI is ignored.
4752 testCases = append(testCases, testCase{
4753 protocol: dtls,
4754 testType: serverTest,
4755 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4759 Bugs: ProtocolBugs{
4760 SRTPMasterKeyIdentifer: "bogus",
4761 },
4762 },
4763 flags: []string{
4764 "-srtp-profiles",
4765 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4766 },
4767 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4768 })
4769 // Test that SRTP isn't negotiated on the server if there were
4770 // no matching profiles.
4771 testCases = append(testCases, testCase{
4772 protocol: dtls,
4773 testType: serverTest,
4774 name: "SRTP-Server-NoMatch-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 SRTPProtectionProfiles: []uint16{100, 101, 102},
4778 },
4779 flags: []string{
4780 "-srtp-profiles",
4781 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4782 },
4783 expectedSRTPProtectionProfile: 0,
4784 })
4785 // Test that the server returning an invalid SRTP profile is
4786 // flagged as an error by the client.
4787 testCases = append(testCases, testCase{
4788 protocol: dtls,
4789 name: "SRTP-Client-NoMatch-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 Bugs: ProtocolBugs{
4793 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4794 },
4795 },
4796 flags: []string{
4797 "-srtp-profiles",
4798 "SRTP_AES128_CM_SHA1_80",
4799 },
4800 shouldFail: true,
4801 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4802 })
4803 }
4804
4805 // Test SCT list.
4806 testCases = append(testCases, testCase{
4807 name: "SignedCertificateTimestampList-Client-" + ver.name,
4808 testType: clientTest,
4809 config: Config{
4810 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004811 },
David Benjamin97d17d92016-07-14 16:12:00 -04004812 flags: []string{
4813 "-enable-signed-cert-timestamps",
4814 "-expect-signed-cert-timestamps",
4815 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004816 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004818 })
4819 testCases = append(testCases, testCase{
4820 name: "SendSCTListOnResume-" + ver.name,
4821 config: Config{
4822 MaxVersion: ver.version,
4823 Bugs: ProtocolBugs{
4824 SendSCTListOnResume: []byte("bogus"),
4825 },
David Benjamind98452d2015-06-16 14:16:23 -04004826 },
David Benjamin97d17d92016-07-14 16:12:00 -04004827 flags: []string{
4828 "-enable-signed-cert-timestamps",
4829 "-expect-signed-cert-timestamps",
4830 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004831 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004832 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004833 })
4834 testCases = append(testCases, testCase{
4835 name: "SignedCertificateTimestampList-Server-" + ver.name,
4836 testType: serverTest,
4837 config: Config{
4838 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004839 },
David Benjamin97d17d92016-07-14 16:12:00 -04004840 flags: []string{
4841 "-signed-cert-timestamps",
4842 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004843 },
David Benjamin97d17d92016-07-14 16:12:00 -04004844 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004846 })
4847 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004848
Paul Lietar4fac72e2015-09-09 13:44:55 +01004849 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004850 testType: clientTest,
4851 name: "ClientHelloPadding",
4852 config: Config{
4853 Bugs: ProtocolBugs{
4854 RequireClientHelloSize: 512,
4855 },
4856 },
4857 // This hostname just needs to be long enough to push the
4858 // ClientHello into F5's danger zone between 256 and 511 bytes
4859 // long.
4860 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4861 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004862
4863 // Extensions should not function in SSL 3.0.
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "SSLv3Extensions-NoALPN",
4867 config: Config{
4868 MaxVersion: VersionSSL30,
4869 NextProtos: []string{"foo", "bar", "baz"},
4870 },
4871 flags: []string{
4872 "-select-alpn", "foo",
4873 },
4874 expectNoNextProto: true,
4875 })
4876
4877 // Test session tickets separately as they follow a different codepath.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "SSLv3Extensions-NoTickets",
4881 config: Config{
4882 MaxVersion: VersionSSL30,
4883 Bugs: ProtocolBugs{
4884 // Historically, session tickets in SSL 3.0
4885 // failed in different ways depending on whether
4886 // the client supported renegotiation_info.
4887 NoRenegotiationInfo: true,
4888 },
4889 },
4890 resumeSession: true,
4891 })
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "SSLv3Extensions-NoTickets2",
4895 config: Config{
4896 MaxVersion: VersionSSL30,
4897 },
4898 resumeSession: true,
4899 })
4900
4901 // But SSL 3.0 does send and process renegotiation_info.
4902 testCases = append(testCases, testCase{
4903 testType: serverTest,
4904 name: "SSLv3Extensions-RenegotiationInfo",
4905 config: Config{
4906 MaxVersion: VersionSSL30,
4907 Bugs: ProtocolBugs{
4908 RequireRenegotiationInfo: true,
4909 },
4910 },
4911 })
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4915 config: Config{
4916 MaxVersion: VersionSSL30,
4917 Bugs: ProtocolBugs{
4918 NoRenegotiationInfo: true,
4919 SendRenegotiationSCSV: true,
4920 RequireRenegotiationInfo: true,
4921 },
4922 },
4923 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004924
4925 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4926 // in ServerHello.
4927 testCases = append(testCases, testCase{
4928 name: "NPN-Forbidden-TLS13",
4929 config: Config{
4930 MaxVersion: VersionTLS13,
4931 NextProtos: []string{"foo"},
4932 Bugs: ProtocolBugs{
4933 NegotiateNPNAtAllVersions: true,
4934 },
4935 },
4936 flags: []string{"-select-next-proto", "foo"},
4937 shouldFail: true,
4938 expectedError: ":ERROR_PARSING_EXTENSION:",
4939 })
4940 testCases = append(testCases, testCase{
4941 name: "EMS-Forbidden-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 Bugs: ProtocolBugs{
4945 NegotiateEMSAtAllVersions: true,
4946 },
4947 },
4948 shouldFail: true,
4949 expectedError: ":ERROR_PARSING_EXTENSION:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "RenegotiationInfo-Forbidden-TLS13",
4953 config: Config{
4954 MaxVersion: VersionTLS13,
4955 Bugs: ProtocolBugs{
4956 NegotiateRenegotiationInfoAtAllVersions: true,
4957 },
4958 },
4959 shouldFail: true,
4960 expectedError: ":ERROR_PARSING_EXTENSION:",
4961 })
4962 testCases = append(testCases, testCase{
4963 name: "ChannelID-Forbidden-TLS13",
4964 config: Config{
4965 MaxVersion: VersionTLS13,
4966 RequestChannelID: true,
4967 Bugs: ProtocolBugs{
4968 NegotiateChannelIDAtAllVersions: true,
4969 },
4970 },
4971 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4972 shouldFail: true,
4973 expectedError: ":ERROR_PARSING_EXTENSION:",
4974 })
4975 testCases = append(testCases, testCase{
4976 name: "Ticket-Forbidden-TLS13",
4977 config: Config{
4978 MaxVersion: VersionTLS12,
4979 },
4980 resumeConfig: &Config{
4981 MaxVersion: VersionTLS13,
4982 Bugs: ProtocolBugs{
4983 AdvertiseTicketExtension: true,
4984 },
4985 },
4986 resumeSession: true,
4987 shouldFail: true,
4988 expectedError: ":ERROR_PARSING_EXTENSION:",
4989 })
4990
4991 // Test that illegal extensions in TLS 1.3 are declined by the server if
4992 // offered in ClientHello. The runner's server will fail if this occurs,
4993 // so we exercise the offering path. (EMS and Renegotiation Info are
4994 // implicit in every test.)
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "ChannelID-Declined-TLS13",
4998 config: Config{
4999 MaxVersion: VersionTLS13,
5000 ChannelID: channelIDKey,
5001 },
5002 flags: []string{"-enable-channel-id"},
5003 })
5004 testCases = append(testCases, testCase{
5005 testType: serverTest,
5006 name: "NPN-Server",
5007 config: Config{
5008 MaxVersion: VersionTLS13,
5009 NextProtos: []string{"bar"},
5010 },
5011 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5012 })
David Benjamine78bfde2014-09-06 12:45:15 -04005013}
5014
David Benjamin01fe8202014-09-24 15:21:44 -04005015func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005016 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005017 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005018 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5019 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5020 // TLS 1.3 only shares ciphers with TLS 1.2, so
5021 // we skip certain combinations and use a
5022 // different cipher to test with.
5023 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5024 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5025 continue
5026 }
5027 }
5028
David Benjamin8b8c0062014-11-23 02:47:52 -05005029 protocols := []protocol{tls}
5030 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5031 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005032 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005033 for _, protocol := range protocols {
5034 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5035 if protocol == dtls {
5036 suffix += "-DTLS"
5037 }
5038
David Benjaminece3de92015-03-16 18:02:20 -04005039 if sessionVers.version == resumeVers.version {
5040 testCases = append(testCases, testCase{
5041 protocol: protocol,
5042 name: "Resume-Client" + suffix,
5043 resumeSession: true,
5044 config: Config{
5045 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005046 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005047 Bugs: ProtocolBugs{
5048 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5049 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5050 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005051 },
David Benjaminece3de92015-03-16 18:02:20 -04005052 expectedVersion: sessionVers.version,
5053 expectedResumeVersion: resumeVers.version,
5054 })
5055 } else {
David Benjamin405da482016-08-08 17:25:07 -04005056 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5057
5058 // Offering a TLS 1.3 session sends an empty session ID, so
5059 // there is no way to convince a non-lookahead client the
5060 // session was resumed. It will appear to the client that a
5061 // stray ChangeCipherSpec was sent.
5062 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5063 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005064 }
5065
David Benjaminece3de92015-03-16 18:02:20 -04005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 name: "Resume-Client-Mismatch" + suffix,
5069 resumeSession: true,
5070 config: Config{
5071 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005072 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005073 },
David Benjaminece3de92015-03-16 18:02:20 -04005074 expectedVersion: sessionVers.version,
5075 resumeConfig: &Config{
5076 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005077 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005078 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005079 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005080 },
5081 },
5082 expectedResumeVersion: resumeVers.version,
5083 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005084 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005085 })
5086 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005087
5088 testCases = append(testCases, testCase{
5089 protocol: protocol,
5090 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005091 resumeSession: true,
5092 config: Config{
5093 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005094 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005095 },
5096 expectedVersion: sessionVers.version,
5097 resumeConfig: &Config{
5098 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005099 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005100 },
5101 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005102 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 expectedResumeVersion: resumeVers.version,
5104 })
5105
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 testCases = append(testCases, testCase{
5107 protocol: protocol,
5108 testType: serverTest,
5109 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005110 resumeSession: true,
5111 config: Config{
5112 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005113 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005114 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005115 expectedVersion: sessionVers.version,
5116 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005117 resumeConfig: &Config{
5118 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005119 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005120 Bugs: ProtocolBugs{
5121 SendBothTickets: true,
5122 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 },
5124 expectedResumeVersion: resumeVers.version,
5125 })
5126 }
David Benjamin01fe8202014-09-24 15:21:44 -04005127 }
5128 }
David Benjaminece3de92015-03-16 18:02:20 -04005129
5130 testCases = append(testCases, testCase{
5131 name: "Resume-Client-CipherMismatch",
5132 resumeSession: true,
5133 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005134 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005135 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5136 },
5137 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005138 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5140 Bugs: ProtocolBugs{
5141 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5142 },
5143 },
5144 shouldFail: true,
5145 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5146 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005147
5148 testCases = append(testCases, testCase{
5149 name: "Resume-Client-CipherMismatch-TLS13",
5150 resumeSession: true,
5151 config: Config{
5152 MaxVersion: VersionTLS13,
5153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5154 },
5155 resumeConfig: &Config{
5156 MaxVersion: VersionTLS13,
5157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5158 Bugs: ProtocolBugs{
5159 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5164 })
David Benjamin01fe8202014-09-24 15:21:44 -04005165}
5166
Adam Langley2ae77d22014-10-28 17:29:33 -07005167func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005168 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005169 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005170 testType: serverTest,
5171 name: "Renegotiate-Server-Forbidden",
5172 config: Config{
5173 MaxVersion: VersionTLS12,
5174 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005175 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005176 shouldFail: true,
5177 expectedError: ":NO_RENEGOTIATION:",
5178 expectedLocalError: "remote error: no renegotiation",
5179 })
Adam Langley5021b222015-06-12 18:27:58 -07005180 // The server shouldn't echo the renegotiation extension unless
5181 // requested by the client.
5182 testCases = append(testCases, testCase{
5183 testType: serverTest,
5184 name: "Renegotiate-Server-NoExt",
5185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005186 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005187 Bugs: ProtocolBugs{
5188 NoRenegotiationInfo: true,
5189 RequireRenegotiationInfo: true,
5190 },
5191 },
5192 shouldFail: true,
5193 expectedLocalError: "renegotiation extension missing",
5194 })
5195 // The renegotiation SCSV should be sufficient for the server to echo
5196 // the extension.
5197 testCases = append(testCases, testCase{
5198 testType: serverTest,
5199 name: "Renegotiate-Server-NoExt-SCSV",
5200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005201 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005202 Bugs: ProtocolBugs{
5203 NoRenegotiationInfo: true,
5204 SendRenegotiationSCSV: true,
5205 RequireRenegotiationInfo: true,
5206 },
5207 },
5208 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005209 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005210 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005212 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005213 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005214 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005215 },
5216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005217 renegotiate: 1,
5218 flags: []string{
5219 "-renegotiate-freely",
5220 "-expect-total-renegotiations", "1",
5221 },
David Benjamincdea40c2015-03-19 14:09:43 -04005222 })
5223 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005224 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005225 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005227 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005228 Bugs: ProtocolBugs{
5229 EmptyRenegotiationInfo: true,
5230 },
5231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005232 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005233 shouldFail: true,
5234 expectedError: ":RENEGOTIATION_MISMATCH:",
5235 })
5236 testCases = append(testCases, testCase{
5237 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005241 Bugs: ProtocolBugs{
5242 BadRenegotiationInfo: true,
5243 },
5244 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005245 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005246 shouldFail: true,
5247 expectedError: ":RENEGOTIATION_MISMATCH:",
5248 })
5249 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005250 name: "Renegotiate-Client-Downgrade",
5251 renegotiate: 1,
5252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005253 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005254 Bugs: ProtocolBugs{
5255 NoRenegotiationInfoAfterInitial: true,
5256 },
5257 },
5258 flags: []string{"-renegotiate-freely"},
5259 shouldFail: true,
5260 expectedError: ":RENEGOTIATION_MISMATCH:",
5261 })
5262 testCases = append(testCases, testCase{
5263 name: "Renegotiate-Client-Upgrade",
5264 renegotiate: 1,
5265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005266 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005267 Bugs: ProtocolBugs{
5268 NoRenegotiationInfoInInitial: true,
5269 },
5270 },
5271 flags: []string{"-renegotiate-freely"},
5272 shouldFail: true,
5273 expectedError: ":RENEGOTIATION_MISMATCH:",
5274 })
5275 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005276 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005277 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005279 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005280 Bugs: ProtocolBugs{
5281 NoRenegotiationInfo: true,
5282 },
5283 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005284 flags: []string{
5285 "-renegotiate-freely",
5286 "-expect-total-renegotiations", "1",
5287 },
David Benjamincff0b902015-05-15 23:09:47 -04005288 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005289
5290 // Test that the server may switch ciphers on renegotiation without
5291 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005292 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005293 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005294 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005295 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005296 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005297 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005298 },
5299 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005300 flags: []string{
5301 "-renegotiate-freely",
5302 "-expect-total-renegotiations", "1",
5303 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005304 })
5305 testCases = append(testCases, testCase{
5306 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005307 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005308 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005309 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005310 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5311 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005312 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005313 flags: []string{
5314 "-renegotiate-freely",
5315 "-expect-total-renegotiations", "1",
5316 },
David Benjaminb16346b2015-04-08 19:16:58 -04005317 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005318
5319 // Test that the server may not switch versions on renegotiation.
5320 testCases = append(testCases, testCase{
5321 name: "Renegotiate-Client-SwitchVersion",
5322 config: Config{
5323 MaxVersion: VersionTLS12,
5324 // Pick a cipher which exists at both versions.
5325 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5326 Bugs: ProtocolBugs{
5327 NegotiateVersionOnRenego: VersionTLS11,
5328 },
5329 },
5330 renegotiate: 1,
5331 flags: []string{
5332 "-renegotiate-freely",
5333 "-expect-total-renegotiations", "1",
5334 },
5335 shouldFail: true,
5336 expectedError: ":WRONG_SSL_VERSION:",
5337 })
5338
David Benjaminb16346b2015-04-08 19:16:58 -04005339 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005340 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005341 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005342 config: Config{
5343 MaxVersion: VersionTLS10,
5344 Bugs: ProtocolBugs{
5345 RequireSameRenegoClientVersion: true,
5346 },
5347 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005348 flags: []string{
5349 "-renegotiate-freely",
5350 "-expect-total-renegotiations", "1",
5351 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005352 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005353 testCases = append(testCases, testCase{
5354 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005355 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005356 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005357 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005358 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5359 NextProtos: []string{"foo"},
5360 },
5361 flags: []string{
5362 "-false-start",
5363 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005364 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005365 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005366 },
5367 shimWritesFirst: true,
5368 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005369
5370 // Client-side renegotiation controls.
5371 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005372 name: "Renegotiate-Client-Forbidden-1",
5373 config: Config{
5374 MaxVersion: VersionTLS12,
5375 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005376 renegotiate: 1,
5377 shouldFail: true,
5378 expectedError: ":NO_RENEGOTIATION:",
5379 expectedLocalError: "remote error: no renegotiation",
5380 })
5381 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005382 name: "Renegotiate-Client-Once-1",
5383 config: Config{
5384 MaxVersion: VersionTLS12,
5385 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005386 renegotiate: 1,
5387 flags: []string{
5388 "-renegotiate-once",
5389 "-expect-total-renegotiations", "1",
5390 },
5391 })
5392 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005393 name: "Renegotiate-Client-Freely-1",
5394 config: Config{
5395 MaxVersion: VersionTLS12,
5396 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005397 renegotiate: 1,
5398 flags: []string{
5399 "-renegotiate-freely",
5400 "-expect-total-renegotiations", "1",
5401 },
5402 })
5403 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005404 name: "Renegotiate-Client-Once-2",
5405 config: Config{
5406 MaxVersion: VersionTLS12,
5407 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005408 renegotiate: 2,
5409 flags: []string{"-renegotiate-once"},
5410 shouldFail: true,
5411 expectedError: ":NO_RENEGOTIATION:",
5412 expectedLocalError: "remote error: no renegotiation",
5413 })
5414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005415 name: "Renegotiate-Client-Freely-2",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005419 renegotiate: 2,
5420 flags: []string{
5421 "-renegotiate-freely",
5422 "-expect-total-renegotiations", "2",
5423 },
5424 })
Adam Langley27a0d082015-11-03 13:34:10 -08005425 testCases = append(testCases, testCase{
5426 name: "Renegotiate-Client-NoIgnore",
5427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005429 Bugs: ProtocolBugs{
5430 SendHelloRequestBeforeEveryAppDataRecord: true,
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":NO_RENEGOTIATION:",
5435 })
5436 testCases = append(testCases, testCase{
5437 name: "Renegotiate-Client-Ignore",
5438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005439 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005440 Bugs: ProtocolBugs{
5441 SendHelloRequestBeforeEveryAppDataRecord: true,
5442 },
5443 },
5444 flags: []string{
5445 "-renegotiate-ignore",
5446 "-expect-total-renegotiations", "0",
5447 },
5448 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005449
David Benjamin397c8e62016-07-08 14:14:36 -07005450 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005451 testCases = append(testCases, testCase{
5452 name: "StrayHelloRequest",
5453 config: Config{
5454 MaxVersion: VersionTLS12,
5455 Bugs: ProtocolBugs{
5456 SendHelloRequestBeforeEveryHandshakeMessage: true,
5457 },
5458 },
5459 })
5460 testCases = append(testCases, testCase{
5461 name: "StrayHelloRequest-Packed",
5462 config: Config{
5463 MaxVersion: VersionTLS12,
5464 Bugs: ProtocolBugs{
5465 PackHandshakeFlight: true,
5466 SendHelloRequestBeforeEveryHandshakeMessage: true,
5467 },
5468 },
5469 })
5470
David Benjamin12d2c482016-07-24 10:56:51 -04005471 // Test renegotiation works if HelloRequest and server Finished come in
5472 // the same record.
5473 testCases = append(testCases, testCase{
5474 name: "Renegotiate-Client-Packed",
5475 config: Config{
5476 MaxVersion: VersionTLS12,
5477 Bugs: ProtocolBugs{
5478 PackHandshakeFlight: true,
5479 PackHelloRequestWithFinished: true,
5480 },
5481 },
5482 renegotiate: 1,
5483 flags: []string{
5484 "-renegotiate-freely",
5485 "-expect-total-renegotiations", "1",
5486 },
5487 })
5488
David Benjamin397c8e62016-07-08 14:14:36 -07005489 // Renegotiation is forbidden in TLS 1.3.
5490 testCases = append(testCases, testCase{
5491 name: "Renegotiate-Client-TLS13",
5492 config: Config{
5493 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005494 Bugs: ProtocolBugs{
5495 SendHelloRequestBeforeEveryAppDataRecord: true,
5496 },
David Benjamin397c8e62016-07-08 14:14:36 -07005497 },
David Benjamin397c8e62016-07-08 14:14:36 -07005498 flags: []string{
5499 "-renegotiate-freely",
5500 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005501 shouldFail: true,
5502 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005503 })
5504
5505 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5506 testCases = append(testCases, testCase{
5507 name: "StrayHelloRequest-TLS13",
5508 config: Config{
5509 MaxVersion: VersionTLS13,
5510 Bugs: ProtocolBugs{
5511 SendHelloRequestBeforeEveryHandshakeMessage: true,
5512 },
5513 },
5514 shouldFail: true,
5515 expectedError: ":UNEXPECTED_MESSAGE:",
5516 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005517}
5518
David Benjamin5e961c12014-11-07 01:48:35 -05005519func addDTLSReplayTests() {
5520 // Test that sequence number replays are detected.
5521 testCases = append(testCases, testCase{
5522 protocol: dtls,
5523 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005524 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005525 replayWrites: true,
5526 })
5527
David Benjamin8e6db492015-07-25 18:29:23 -04005528 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005529 // than the retransmit window.
5530 testCases = append(testCases, testCase{
5531 protocol: dtls,
5532 name: "DTLS-Replay-LargeGaps",
5533 config: Config{
5534 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005535 SequenceNumberMapping: func(in uint64) uint64 {
5536 return in * 127
5537 },
David Benjamin5e961c12014-11-07 01:48:35 -05005538 },
5539 },
David Benjamin8e6db492015-07-25 18:29:23 -04005540 messageCount: 200,
5541 replayWrites: true,
5542 })
5543
5544 // Test the incoming sequence number changing non-monotonically.
5545 testCases = append(testCases, testCase{
5546 protocol: dtls,
5547 name: "DTLS-Replay-NonMonotonic",
5548 config: Config{
5549 Bugs: ProtocolBugs{
5550 SequenceNumberMapping: func(in uint64) uint64 {
5551 return in ^ 31
5552 },
5553 },
5554 },
5555 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005556 replayWrites: true,
5557 })
5558}
5559
Nick Harper60edffd2016-06-21 15:19:24 -07005560var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005561 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005562 id signatureAlgorithm
5563 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005564}{
Nick Harper60edffd2016-06-21 15:19:24 -07005565 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5566 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5567 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5568 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005569 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005570 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5571 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5572 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005573 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5574 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5575 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005576 // Tests for key types prior to TLS 1.2.
5577 {"RSA", 0, testCertRSA},
5578 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005579}
5580
Nick Harper60edffd2016-06-21 15:19:24 -07005581const fakeSigAlg1 signatureAlgorithm = 0x2a01
5582const fakeSigAlg2 signatureAlgorithm = 0xff01
5583
5584func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005585 // Not all ciphers involve a signature. Advertise a list which gives all
5586 // versions a signing cipher.
5587 signingCiphers := []uint16{
5588 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5589 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5590 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5591 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5592 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5593 }
5594
David Benjaminca3d5452016-07-14 12:51:01 -04005595 var allAlgorithms []signatureAlgorithm
5596 for _, alg := range testSignatureAlgorithms {
5597 if alg.id != 0 {
5598 allAlgorithms = append(allAlgorithms, alg.id)
5599 }
5600 }
5601
Nick Harper60edffd2016-06-21 15:19:24 -07005602 // Make sure each signature algorithm works. Include some fake values in
5603 // the list and ensure they're ignored.
5604 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005605 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005606 if (ver.version < VersionTLS12) != (alg.id == 0) {
5607 continue
5608 }
5609
5610 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5611 // or remove it in C.
5612 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005613 continue
5614 }
Nick Harper60edffd2016-06-21 15:19:24 -07005615
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005616 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005617 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005618 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5619 shouldFail = true
5620 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005621 // RSA-PKCS1 does not exist in TLS 1.3.
5622 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5623 shouldFail = true
5624 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005625
5626 var signError, verifyError string
5627 if shouldFail {
5628 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5629 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005630 }
David Benjamin000800a2014-11-14 01:43:59 -05005631
David Benjamin1fb125c2016-07-08 18:52:12 -07005632 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005633
David Benjamin7a41d372016-07-09 11:21:54 -07005634 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005635 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005636 config: Config{
5637 MaxVersion: ver.version,
5638 ClientAuth: RequireAnyClientCert,
5639 VerifySignatureAlgorithms: []signatureAlgorithm{
5640 fakeSigAlg1,
5641 alg.id,
5642 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005643 },
David Benjamin7a41d372016-07-09 11:21:54 -07005644 },
5645 flags: []string{
5646 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5647 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5648 "-enable-all-curves",
5649 },
5650 shouldFail: shouldFail,
5651 expectedError: signError,
5652 expectedPeerSignatureAlgorithm: alg.id,
5653 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005654
David Benjamin7a41d372016-07-09 11:21:54 -07005655 testCases = append(testCases, testCase{
5656 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005657 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005658 config: Config{
5659 MaxVersion: ver.version,
5660 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5661 SignSignatureAlgorithms: []signatureAlgorithm{
5662 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005663 },
David Benjamin7a41d372016-07-09 11:21:54 -07005664 Bugs: ProtocolBugs{
5665 SkipECDSACurveCheck: shouldFail,
5666 IgnoreSignatureVersionChecks: shouldFail,
5667 // The client won't advertise 1.3-only algorithms after
5668 // version negotiation.
5669 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005670 },
David Benjamin7a41d372016-07-09 11:21:54 -07005671 },
5672 flags: []string{
5673 "-require-any-client-certificate",
5674 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5675 "-enable-all-curves",
5676 },
5677 shouldFail: shouldFail,
5678 expectedError: verifyError,
5679 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005680
5681 testCases = append(testCases, testCase{
5682 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005683 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005684 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005685 MaxVersion: ver.version,
5686 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005687 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005688 fakeSigAlg1,
5689 alg.id,
5690 fakeSigAlg2,
5691 },
5692 },
5693 flags: []string{
5694 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5695 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5696 "-enable-all-curves",
5697 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005698 shouldFail: shouldFail,
5699 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005700 expectedPeerSignatureAlgorithm: alg.id,
5701 })
5702
5703 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005704 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005705 config: Config{
5706 MaxVersion: ver.version,
5707 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005708 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005709 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005710 alg.id,
5711 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005712 Bugs: ProtocolBugs{
5713 SkipECDSACurveCheck: shouldFail,
5714 IgnoreSignatureVersionChecks: shouldFail,
5715 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005716 },
5717 flags: []string{
5718 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5719 "-enable-all-curves",
5720 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005721 shouldFail: shouldFail,
5722 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005723 })
David Benjamin5208fd42016-07-13 21:43:25 -04005724
5725 if !shouldFail {
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "ClientAuth-InvalidSignature" + suffix,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5732 SignSignatureAlgorithms: []signatureAlgorithm{
5733 alg.id,
5734 },
5735 Bugs: ProtocolBugs{
5736 InvalidSignature: true,
5737 },
5738 },
5739 flags: []string{
5740 "-require-any-client-certificate",
5741 "-enable-all-curves",
5742 },
5743 shouldFail: true,
5744 expectedError: ":BAD_SIGNATURE:",
5745 })
5746
5747 testCases = append(testCases, testCase{
5748 name: "ServerAuth-InvalidSignature" + suffix,
5749 config: Config{
5750 MaxVersion: ver.version,
5751 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5752 CipherSuites: signingCiphers,
5753 SignSignatureAlgorithms: []signatureAlgorithm{
5754 alg.id,
5755 },
5756 Bugs: ProtocolBugs{
5757 InvalidSignature: true,
5758 },
5759 },
5760 flags: []string{"-enable-all-curves"},
5761 shouldFail: true,
5762 expectedError: ":BAD_SIGNATURE:",
5763 })
5764 }
David Benjaminca3d5452016-07-14 12:51:01 -04005765
5766 if ver.version >= VersionTLS12 && !shouldFail {
5767 testCases = append(testCases, testCase{
5768 name: "ClientAuth-Sign-Negotiate" + suffix,
5769 config: Config{
5770 MaxVersion: ver.version,
5771 ClientAuth: RequireAnyClientCert,
5772 VerifySignatureAlgorithms: allAlgorithms,
5773 },
5774 flags: []string{
5775 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5776 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5777 "-enable-all-curves",
5778 "-signing-prefs", strconv.Itoa(int(alg.id)),
5779 },
5780 expectedPeerSignatureAlgorithm: alg.id,
5781 })
5782
5783 testCases = append(testCases, testCase{
5784 testType: serverTest,
5785 name: "ServerAuth-Sign-Negotiate" + suffix,
5786 config: Config{
5787 MaxVersion: ver.version,
5788 CipherSuites: signingCiphers,
5789 VerifySignatureAlgorithms: allAlgorithms,
5790 },
5791 flags: []string{
5792 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5793 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5794 "-enable-all-curves",
5795 "-signing-prefs", strconv.Itoa(int(alg.id)),
5796 },
5797 expectedPeerSignatureAlgorithm: alg.id,
5798 })
5799 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005800 }
David Benjamin000800a2014-11-14 01:43:59 -05005801 }
5802
Nick Harper60edffd2016-06-21 15:19:24 -07005803 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005804 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005805 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005806 config: Config{
5807 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005808 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005809 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005810 signatureECDSAWithP521AndSHA512,
5811 signatureRSAPKCS1WithSHA384,
5812 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005813 },
5814 },
5815 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005816 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5817 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005818 },
Nick Harper60edffd2016-06-21 15:19:24 -07005819 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005820 })
5821
5822 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005823 name: "ClientAuth-SignatureType-TLS13",
5824 config: Config{
5825 ClientAuth: RequireAnyClientCert,
5826 MaxVersion: VersionTLS13,
5827 VerifySignatureAlgorithms: []signatureAlgorithm{
5828 signatureECDSAWithP521AndSHA512,
5829 signatureRSAPKCS1WithSHA384,
5830 signatureRSAPSSWithSHA384,
5831 signatureECDSAWithSHA1,
5832 },
5833 },
5834 flags: []string{
5835 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5836 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5837 },
5838 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5839 })
5840
5841 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005842 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005843 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005845 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005847 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005848 signatureECDSAWithP521AndSHA512,
5849 signatureRSAPKCS1WithSHA384,
5850 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005851 },
5852 },
Nick Harper60edffd2016-06-21 15:19:24 -07005853 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005854 })
5855
Steven Valdez143e8b32016-07-11 13:19:03 -04005856 testCases = append(testCases, testCase{
5857 testType: serverTest,
5858 name: "ServerAuth-SignatureType-TLS13",
5859 config: Config{
5860 MaxVersion: VersionTLS13,
5861 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5862 VerifySignatureAlgorithms: []signatureAlgorithm{
5863 signatureECDSAWithP521AndSHA512,
5864 signatureRSAPKCS1WithSHA384,
5865 signatureRSAPSSWithSHA384,
5866 signatureECDSAWithSHA1,
5867 },
5868 },
5869 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5870 })
5871
David Benjamina95e9f32016-07-08 16:28:04 -07005872 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005873 testCases = append(testCases, testCase{
5874 testType: serverTest,
5875 name: "Verify-ClientAuth-SignatureType",
5876 config: Config{
5877 MaxVersion: VersionTLS12,
5878 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005879 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005880 signatureRSAPKCS1WithSHA256,
5881 },
5882 Bugs: ProtocolBugs{
5883 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5884 },
5885 },
5886 flags: []string{
5887 "-require-any-client-certificate",
5888 },
5889 shouldFail: true,
5890 expectedError: ":WRONG_SIGNATURE_TYPE:",
5891 })
5892
5893 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005894 testType: serverTest,
5895 name: "Verify-ClientAuth-SignatureType-TLS13",
5896 config: Config{
5897 MaxVersion: VersionTLS13,
5898 Certificates: []Certificate{rsaCertificate},
5899 SignSignatureAlgorithms: []signatureAlgorithm{
5900 signatureRSAPSSWithSHA256,
5901 },
5902 Bugs: ProtocolBugs{
5903 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5904 },
5905 },
5906 flags: []string{
5907 "-require-any-client-certificate",
5908 },
5909 shouldFail: true,
5910 expectedError: ":WRONG_SIGNATURE_TYPE:",
5911 })
5912
5913 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005914 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005915 config: Config{
5916 MaxVersion: VersionTLS12,
5917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005918 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005919 signatureRSAPKCS1WithSHA256,
5920 },
5921 Bugs: ProtocolBugs{
5922 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5923 },
5924 },
5925 shouldFail: true,
5926 expectedError: ":WRONG_SIGNATURE_TYPE:",
5927 })
5928
Steven Valdez143e8b32016-07-11 13:19:03 -04005929 testCases = append(testCases, testCase{
5930 name: "Verify-ServerAuth-SignatureType-TLS13",
5931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5934 SignSignatureAlgorithms: []signatureAlgorithm{
5935 signatureRSAPSSWithSHA256,
5936 },
5937 Bugs: ProtocolBugs{
5938 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":WRONG_SIGNATURE_TYPE:",
5943 })
5944
David Benjamin51dd7d62016-07-08 16:07:01 -07005945 // Test that, if the list is missing, the peer falls back to SHA-1 in
5946 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005947 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005948 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005950 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005951 ClientAuth: RequireAnyClientCert,
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 },
5959 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005960 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5961 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005962 },
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005967 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005968 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005969 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005970 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005971 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005972 },
5973 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005974 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005975 },
5976 },
David Benjaminee32bea2016-08-17 13:36:44 -04005977 flags: []string{
5978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5980 },
5981 })
5982
5983 testCases = append(testCases, testCase{
5984 name: "ClientAuth-SHA1-Fallback-ECDSA",
5985 config: Config{
5986 MaxVersion: VersionTLS12,
5987 ClientAuth: RequireAnyClientCert,
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 },
5999 })
6000
6001 testCases = append(testCases, testCase{
6002 testType: serverTest,
6003 name: "ServerAuth-SHA1-Fallback-ECDSA",
6004 config: Config{
6005 MaxVersion: VersionTLS12,
6006 VerifySignatureAlgorithms: []signatureAlgorithm{
6007 signatureECDSAWithSHA1,
6008 },
6009 Bugs: ProtocolBugs{
6010 NoSignatureAlgorithms: true,
6011 },
6012 },
6013 flags: []string{
6014 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6015 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6016 },
David Benjamin000800a2014-11-14 01:43:59 -05006017 })
David Benjamin72dc7832015-03-16 17:49:43 -04006018
David Benjamin51dd7d62016-07-08 16:07:01 -07006019 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006020 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006021 config: Config{
6022 MaxVersion: VersionTLS13,
6023 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006024 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006025 signatureRSAPKCS1WithSHA1,
6026 },
6027 Bugs: ProtocolBugs{
6028 NoSignatureAlgorithms: true,
6029 },
6030 },
6031 flags: []string{
6032 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6033 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6034 },
David Benjamin48901652016-08-01 12:12:47 -04006035 shouldFail: true,
6036 // An empty CertificateRequest signature algorithm list is a
6037 // syntax error in TLS 1.3.
6038 expectedError: ":DECODE_ERROR:",
6039 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006040 })
6041
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006044 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006045 config: Config{
6046 MaxVersion: VersionTLS13,
6047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006048 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006049 signatureRSAPKCS1WithSHA1,
6050 },
6051 Bugs: ProtocolBugs{
6052 NoSignatureAlgorithms: true,
6053 },
6054 },
6055 shouldFail: true,
6056 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6057 })
6058
David Benjaminb62d2872016-07-18 14:55:02 +02006059 // Test that hash preferences are enforced. BoringSSL does not implement
6060 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006061 testCases = append(testCases, testCase{
6062 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006063 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006065 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006066 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006067 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006068 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006069 },
6070 Bugs: ProtocolBugs{
6071 IgnorePeerSignatureAlgorithmPreferences: true,
6072 },
6073 },
6074 flags: []string{"-require-any-client-certificate"},
6075 shouldFail: true,
6076 expectedError: ":WRONG_SIGNATURE_TYPE:",
6077 })
6078
6079 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006080 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006082 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006083 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006084 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006085 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006086 },
6087 Bugs: ProtocolBugs{
6088 IgnorePeerSignatureAlgorithmPreferences: true,
6089 },
6090 },
6091 shouldFail: true,
6092 expectedError: ":WRONG_SIGNATURE_TYPE:",
6093 })
David Benjaminb62d2872016-07-18 14:55:02 +02006094 testCases = append(testCases, testCase{
6095 testType: serverTest,
6096 name: "ClientAuth-Enforced-TLS13",
6097 config: Config{
6098 MaxVersion: VersionTLS13,
6099 Certificates: []Certificate{rsaCertificate},
6100 SignSignatureAlgorithms: []signatureAlgorithm{
6101 signatureRSAPKCS1WithMD5,
6102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 IgnoreSignatureVersionChecks: true,
6106 },
6107 },
6108 flags: []string{"-require-any-client-certificate"},
6109 shouldFail: true,
6110 expectedError: ":WRONG_SIGNATURE_TYPE:",
6111 })
6112
6113 testCases = append(testCases, testCase{
6114 name: "ServerAuth-Enforced-TLS13",
6115 config: Config{
6116 MaxVersion: VersionTLS13,
6117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6118 SignSignatureAlgorithms: []signatureAlgorithm{
6119 signatureRSAPKCS1WithMD5,
6120 },
6121 Bugs: ProtocolBugs{
6122 IgnorePeerSignatureAlgorithmPreferences: true,
6123 IgnoreSignatureVersionChecks: true,
6124 },
6125 },
6126 shouldFail: true,
6127 expectedError: ":WRONG_SIGNATURE_TYPE:",
6128 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006129
6130 // Test that the agreed upon digest respects the client preferences and
6131 // the server digests.
6132 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006133 name: "NoCommonAlgorithms-Digests",
6134 config: Config{
6135 MaxVersion: VersionTLS12,
6136 ClientAuth: RequireAnyClientCert,
6137 VerifySignatureAlgorithms: []signatureAlgorithm{
6138 signatureRSAPKCS1WithSHA512,
6139 signatureRSAPKCS1WithSHA1,
6140 },
6141 },
6142 flags: []string{
6143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6145 "-digest-prefs", "SHA256",
6146 },
6147 shouldFail: true,
6148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6149 })
6150 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006151 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006153 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006154 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006155 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006156 signatureRSAPKCS1WithSHA512,
6157 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006158 },
6159 },
6160 flags: []string{
6161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006163 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006164 },
David Benjaminca3d5452016-07-14 12:51:01 -04006165 shouldFail: true,
6166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6167 })
6168 testCases = append(testCases, testCase{
6169 name: "NoCommonAlgorithms-TLS13",
6170 config: Config{
6171 MaxVersion: VersionTLS13,
6172 ClientAuth: RequireAnyClientCert,
6173 VerifySignatureAlgorithms: []signatureAlgorithm{
6174 signatureRSAPSSWithSHA512,
6175 signatureRSAPSSWithSHA384,
6176 },
6177 },
6178 flags: []string{
6179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6181 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6182 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006183 shouldFail: true,
6184 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006185 })
6186 testCases = append(testCases, testCase{
6187 name: "Agree-Digest-SHA256",
6188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006189 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006190 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006191 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006192 signatureRSAPKCS1WithSHA1,
6193 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006194 },
6195 },
6196 flags: []string{
6197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006199 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006200 },
Nick Harper60edffd2016-06-21 15:19:24 -07006201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006202 })
6203 testCases = append(testCases, testCase{
6204 name: "Agree-Digest-SHA1",
6205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006206 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006209 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006210 },
6211 },
6212 flags: []string{
6213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006215 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006216 },
Nick Harper60edffd2016-06-21 15:19:24 -07006217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 })
6219 testCases = append(testCases, testCase{
6220 name: "Agree-Digest-Default",
6221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006222 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006223 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006225 signatureRSAPKCS1WithSHA256,
6226 signatureECDSAWithP256AndSHA256,
6227 signatureRSAPKCS1WithSHA1,
6228 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006229 },
6230 },
6231 flags: []string{
6232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6234 },
Nick Harper60edffd2016-06-21 15:19:24 -07006235 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006236 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006237
David Benjaminca3d5452016-07-14 12:51:01 -04006238 // Test that the signing preference list may include extra algorithms
6239 // without negotiation problems.
6240 testCases = append(testCases, testCase{
6241 testType: serverTest,
6242 name: "FilterExtraAlgorithms",
6243 config: Config{
6244 MaxVersion: VersionTLS12,
6245 VerifySignatureAlgorithms: []signatureAlgorithm{
6246 signatureRSAPKCS1WithSHA256,
6247 },
6248 },
6249 flags: []string{
6250 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6251 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6252 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6253 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6254 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6255 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6256 },
6257 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6258 })
6259
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6261 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006262 testCases = append(testCases, testCase{
6263 name: "CheckLeafCurve",
6264 config: Config{
6265 MaxVersion: VersionTLS12,
6266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006267 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006268 },
6269 flags: []string{"-p384-only"},
6270 shouldFail: true,
6271 expectedError: ":BAD_ECC_CERT:",
6272 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006273
6274 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6275 testCases = append(testCases, testCase{
6276 name: "CheckLeafCurve-TLS13",
6277 config: Config{
6278 MaxVersion: VersionTLS13,
6279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6280 Certificates: []Certificate{ecdsaP256Certificate},
6281 },
6282 flags: []string{"-p384-only"},
6283 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006284
6285 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6286 testCases = append(testCases, testCase{
6287 name: "ECDSACurveMismatch-Verify-TLS12",
6288 config: Config{
6289 MaxVersion: VersionTLS12,
6290 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6291 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006292 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006293 signatureECDSAWithP384AndSHA384,
6294 },
6295 },
6296 })
6297
6298 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6299 testCases = append(testCases, testCase{
6300 name: "ECDSACurveMismatch-Verify-TLS13",
6301 config: Config{
6302 MaxVersion: VersionTLS13,
6303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6304 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006305 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006306 signatureECDSAWithP384AndSHA384,
6307 },
6308 Bugs: ProtocolBugs{
6309 SkipECDSACurveCheck: true,
6310 },
6311 },
6312 shouldFail: true,
6313 expectedError: ":WRONG_SIGNATURE_TYPE:",
6314 })
6315
6316 // Signature algorithm selection in TLS 1.3 should take the curve into
6317 // account.
6318 testCases = append(testCases, testCase{
6319 testType: serverTest,
6320 name: "ECDSACurveMismatch-Sign-TLS13",
6321 config: Config{
6322 MaxVersion: VersionTLS13,
6323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006324 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006325 signatureECDSAWithP384AndSHA384,
6326 signatureECDSAWithP256AndSHA256,
6327 },
6328 },
6329 flags: []string{
6330 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6331 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6332 },
6333 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6334 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006335
6336 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6337 // server does not attempt to sign in that case.
6338 testCases = append(testCases, testCase{
6339 testType: serverTest,
6340 name: "RSA-PSS-Large",
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 VerifySignatureAlgorithms: []signatureAlgorithm{
6344 signatureRSAPSSWithSHA512,
6345 },
6346 },
6347 flags: []string{
6348 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6349 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6350 },
6351 shouldFail: true,
6352 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6353 })
David Benjamin57e929f2016-08-30 00:30:38 -04006354
6355 // Test that RSA-PSS is enabled by default for TLS 1.2.
6356 testCases = append(testCases, testCase{
6357 testType: clientTest,
6358 name: "RSA-PSS-Default-Verify",
6359 config: Config{
6360 MaxVersion: VersionTLS12,
6361 SignSignatureAlgorithms: []signatureAlgorithm{
6362 signatureRSAPSSWithSHA256,
6363 },
6364 },
6365 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6366 })
6367
6368 testCases = append(testCases, testCase{
6369 testType: serverTest,
6370 name: "RSA-PSS-Default-Sign",
6371 config: Config{
6372 MaxVersion: VersionTLS12,
6373 VerifySignatureAlgorithms: []signatureAlgorithm{
6374 signatureRSAPSSWithSHA256,
6375 },
6376 },
6377 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6378 })
David Benjamin000800a2014-11-14 01:43:59 -05006379}
6380
David Benjamin83f90402015-01-27 01:09:43 -05006381// timeouts is the retransmit schedule for BoringSSL. It doubles and
6382// caps at 60 seconds. On the 13th timeout, it gives up.
6383var timeouts = []time.Duration{
6384 1 * time.Second,
6385 2 * time.Second,
6386 4 * time.Second,
6387 8 * time.Second,
6388 16 * time.Second,
6389 32 * time.Second,
6390 60 * time.Second,
6391 60 * time.Second,
6392 60 * time.Second,
6393 60 * time.Second,
6394 60 * time.Second,
6395 60 * time.Second,
6396 60 * time.Second,
6397}
6398
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006399// shortTimeouts is an alternate set of timeouts which would occur if the
6400// initial timeout duration was set to 250ms.
6401var shortTimeouts = []time.Duration{
6402 250 * time.Millisecond,
6403 500 * time.Millisecond,
6404 1 * time.Second,
6405 2 * time.Second,
6406 4 * time.Second,
6407 8 * time.Second,
6408 16 * time.Second,
6409 32 * time.Second,
6410 60 * time.Second,
6411 60 * time.Second,
6412 60 * time.Second,
6413 60 * time.Second,
6414 60 * time.Second,
6415}
6416
David Benjamin83f90402015-01-27 01:09:43 -05006417func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006418 // These tests work by coordinating some behavior on both the shim and
6419 // the runner.
6420 //
6421 // TimeoutSchedule configures the runner to send a series of timeout
6422 // opcodes to the shim (see packetAdaptor) immediately before reading
6423 // each peer handshake flight N. The timeout opcode both simulates a
6424 // timeout in the shim and acts as a synchronization point to help the
6425 // runner bracket each handshake flight.
6426 //
6427 // We assume the shim does not read from the channel eagerly. It must
6428 // first wait until it has sent flight N and is ready to receive
6429 // handshake flight N+1. At this point, it will process the timeout
6430 // opcode. It must then immediately respond with a timeout ACK and act
6431 // as if the shim was idle for the specified amount of time.
6432 //
6433 // The runner then drops all packets received before the ACK and
6434 // continues waiting for flight N. This ordering results in one attempt
6435 // at sending flight N to be dropped. For the test to complete, the
6436 // shim must send flight N again, testing that the shim implements DTLS
6437 // retransmit on a timeout.
6438
Steven Valdez143e8b32016-07-11 13:19:03 -04006439 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006440 // likely be more epochs to cross and the final message's retransmit may
6441 // be more complex.
6442
David Benjamin585d7a42016-06-02 14:58:00 -04006443 for _, async := range []bool{true, false} {
6444 var tests []testCase
6445
6446 // Test that this is indeed the timeout schedule. Stress all
6447 // four patterns of handshake.
6448 for i := 1; i < len(timeouts); i++ {
6449 number := strconv.Itoa(i)
6450 tests = append(tests, testCase{
6451 protocol: dtls,
6452 name: "DTLS-Retransmit-Client-" + number,
6453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006454 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006455 Bugs: ProtocolBugs{
6456 TimeoutSchedule: timeouts[:i],
6457 },
6458 },
6459 resumeSession: true,
6460 })
6461 tests = append(tests, testCase{
6462 protocol: dtls,
6463 testType: serverTest,
6464 name: "DTLS-Retransmit-Server-" + number,
6465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006466 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006467 Bugs: ProtocolBugs{
6468 TimeoutSchedule: timeouts[:i],
6469 },
6470 },
6471 resumeSession: true,
6472 })
6473 }
6474
6475 // Test that exceeding the timeout schedule hits a read
6476 // timeout.
6477 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006478 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006479 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006481 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006482 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006483 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006484 },
6485 },
6486 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006487 shouldFail: true,
6488 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006489 })
David Benjamin585d7a42016-06-02 14:58:00 -04006490
6491 if async {
6492 // Test that timeout handling has a fudge factor, due to API
6493 // problems.
6494 tests = append(tests, testCase{
6495 protocol: dtls,
6496 name: "DTLS-Retransmit-Fudge",
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{
6501 timeouts[0] - 10*time.Millisecond,
6502 },
6503 },
6504 },
6505 resumeSession: true,
6506 })
6507 }
6508
6509 // Test that the final Finished retransmitting isn't
6510 // duplicated if the peer badly fragments everything.
6511 tests = append(tests, testCase{
6512 testType: serverTest,
6513 protocol: dtls,
6514 name: "DTLS-Retransmit-Fragmented",
6515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006517 Bugs: ProtocolBugs{
6518 TimeoutSchedule: []time.Duration{timeouts[0]},
6519 MaxHandshakeRecordLength: 2,
6520 },
6521 },
6522 })
6523
6524 // Test the timeout schedule when a shorter initial timeout duration is set.
6525 tests = append(tests, testCase{
6526 protocol: dtls,
6527 name: "DTLS-Retransmit-Short-Client",
6528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006529 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006530 Bugs: ProtocolBugs{
6531 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6532 },
6533 },
6534 resumeSession: true,
6535 flags: []string{"-initial-timeout-duration-ms", "250"},
6536 })
6537 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006538 protocol: dtls,
6539 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006540 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006542 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006543 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006544 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006545 },
6546 },
6547 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006548 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006549 })
David Benjamin585d7a42016-06-02 14:58:00 -04006550
6551 for _, test := range tests {
6552 if async {
6553 test.name += "-Async"
6554 test.flags = append(test.flags, "-async")
6555 }
6556
6557 testCases = append(testCases, test)
6558 }
David Benjamin83f90402015-01-27 01:09:43 -05006559 }
David Benjamin83f90402015-01-27 01:09:43 -05006560}
6561
David Benjaminc565ebb2015-04-03 04:06:36 -04006562func addExportKeyingMaterialTests() {
6563 for _, vers := range tlsVersions {
6564 if vers.version == VersionSSL30 {
6565 continue
6566 }
6567 testCases = append(testCases, testCase{
6568 name: "ExportKeyingMaterial-" + vers.name,
6569 config: Config{
6570 MaxVersion: vers.version,
6571 },
6572 exportKeyingMaterial: 1024,
6573 exportLabel: "label",
6574 exportContext: "context",
6575 useExportContext: true,
6576 })
6577 testCases = append(testCases, testCase{
6578 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6579 config: Config{
6580 MaxVersion: vers.version,
6581 },
6582 exportKeyingMaterial: 1024,
6583 })
6584 testCases = append(testCases, testCase{
6585 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6586 config: Config{
6587 MaxVersion: vers.version,
6588 },
6589 exportKeyingMaterial: 1024,
6590 useExportContext: true,
6591 })
6592 testCases = append(testCases, testCase{
6593 name: "ExportKeyingMaterial-Small-" + vers.name,
6594 config: Config{
6595 MaxVersion: vers.version,
6596 },
6597 exportKeyingMaterial: 1,
6598 exportLabel: "label",
6599 exportContext: "context",
6600 useExportContext: true,
6601 })
6602 }
6603 testCases = append(testCases, testCase{
6604 name: "ExportKeyingMaterial-SSL3",
6605 config: Config{
6606 MaxVersion: VersionSSL30,
6607 },
6608 exportKeyingMaterial: 1024,
6609 exportLabel: "label",
6610 exportContext: "context",
6611 useExportContext: true,
6612 shouldFail: true,
6613 expectedError: "failed to export keying material",
6614 })
6615}
6616
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006617func addTLSUniqueTests() {
6618 for _, isClient := range []bool{false, true} {
6619 for _, isResumption := range []bool{false, true} {
6620 for _, hasEMS := range []bool{false, true} {
6621 var suffix string
6622 if isResumption {
6623 suffix = "Resume-"
6624 } else {
6625 suffix = "Full-"
6626 }
6627
6628 if hasEMS {
6629 suffix += "EMS-"
6630 } else {
6631 suffix += "NoEMS-"
6632 }
6633
6634 if isClient {
6635 suffix += "Client"
6636 } else {
6637 suffix += "Server"
6638 }
6639
6640 test := testCase{
6641 name: "TLSUnique-" + suffix,
6642 testTLSUnique: true,
6643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006645 Bugs: ProtocolBugs{
6646 NoExtendedMasterSecret: !hasEMS,
6647 },
6648 },
6649 }
6650
6651 if isResumption {
6652 test.resumeSession = true
6653 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006654 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006655 Bugs: ProtocolBugs{
6656 NoExtendedMasterSecret: !hasEMS,
6657 },
6658 }
6659 }
6660
6661 if isResumption && !hasEMS {
6662 test.shouldFail = true
6663 test.expectedError = "failed to get tls-unique"
6664 }
6665
6666 testCases = append(testCases, test)
6667 }
6668 }
6669 }
6670}
6671
Adam Langley09505632015-07-30 18:10:13 -07006672func addCustomExtensionTests() {
6673 expectedContents := "custom extension"
6674 emptyString := ""
6675
6676 for _, isClient := range []bool{false, true} {
6677 suffix := "Server"
6678 flag := "-enable-server-custom-extension"
6679 testType := serverTest
6680 if isClient {
6681 suffix = "Client"
6682 flag = "-enable-client-custom-extension"
6683 testType = clientTest
6684 }
6685
6686 testCases = append(testCases, testCase{
6687 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006688 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006689 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006690 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006691 Bugs: ProtocolBugs{
6692 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006693 ExpectedCustomExtension: &expectedContents,
6694 },
6695 },
6696 flags: []string{flag},
6697 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006698 testCases = append(testCases, testCase{
6699 testType: testType,
6700 name: "CustomExtensions-" + suffix + "-TLS13",
6701 config: Config{
6702 MaxVersion: VersionTLS13,
6703 Bugs: ProtocolBugs{
6704 CustomExtension: expectedContents,
6705 ExpectedCustomExtension: &expectedContents,
6706 },
6707 },
6708 flags: []string{flag},
6709 })
Adam Langley09505632015-07-30 18:10:13 -07006710
6711 // If the parse callback fails, the handshake should also fail.
6712 testCases = append(testCases, testCase{
6713 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006714 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006716 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006717 Bugs: ProtocolBugs{
6718 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006719 ExpectedCustomExtension: &expectedContents,
6720 },
6721 },
David Benjamin399e7c92015-07-30 23:01:27 -04006722 flags: []string{flag},
6723 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006724 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6725 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006726 testCases = append(testCases, testCase{
6727 testType: testType,
6728 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6729 config: Config{
6730 MaxVersion: VersionTLS13,
6731 Bugs: ProtocolBugs{
6732 CustomExtension: expectedContents + "foo",
6733 ExpectedCustomExtension: &expectedContents,
6734 },
6735 },
6736 flags: []string{flag},
6737 shouldFail: true,
6738 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6739 })
Adam Langley09505632015-07-30 18:10:13 -07006740
6741 // If the add callback fails, the handshake should also fail.
6742 testCases = append(testCases, testCase{
6743 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006744 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006745 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006746 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006747 Bugs: ProtocolBugs{
6748 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006749 ExpectedCustomExtension: &expectedContents,
6750 },
6751 },
David Benjamin399e7c92015-07-30 23:01:27 -04006752 flags: []string{flag, "-custom-extension-fail-add"},
6753 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006754 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6755 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006756 testCases = append(testCases, testCase{
6757 testType: testType,
6758 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6759 config: Config{
6760 MaxVersion: VersionTLS13,
6761 Bugs: ProtocolBugs{
6762 CustomExtension: expectedContents,
6763 ExpectedCustomExtension: &expectedContents,
6764 },
6765 },
6766 flags: []string{flag, "-custom-extension-fail-add"},
6767 shouldFail: true,
6768 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6769 })
Adam Langley09505632015-07-30 18:10:13 -07006770
6771 // If the add callback returns zero, no extension should be
6772 // added.
6773 skipCustomExtension := expectedContents
6774 if isClient {
6775 // For the case where the client skips sending the
6776 // custom extension, the server must not “echo” it.
6777 skipCustomExtension = ""
6778 }
6779 testCases = append(testCases, testCase{
6780 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006781 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006783 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006784 Bugs: ProtocolBugs{
6785 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006786 ExpectedCustomExtension: &emptyString,
6787 },
6788 },
6789 flags: []string{flag, "-custom-extension-skip"},
6790 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006791 testCases = append(testCases, testCase{
6792 testType: testType,
6793 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6794 config: Config{
6795 MaxVersion: VersionTLS13,
6796 Bugs: ProtocolBugs{
6797 CustomExtension: skipCustomExtension,
6798 ExpectedCustomExtension: &emptyString,
6799 },
6800 },
6801 flags: []string{flag, "-custom-extension-skip"},
6802 })
Adam Langley09505632015-07-30 18:10:13 -07006803 }
6804
6805 // The custom extension add callback should not be called if the client
6806 // doesn't send the extension.
6807 testCases = append(testCases, testCase{
6808 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006809 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006811 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006812 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006813 ExpectedCustomExtension: &emptyString,
6814 },
6815 },
6816 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6817 })
Adam Langley2deb9842015-08-07 11:15:37 -07006818
Steven Valdez143e8b32016-07-11 13:19:03 -04006819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "CustomExtensions-NotCalled-Server-TLS13",
6822 config: Config{
6823 MaxVersion: VersionTLS13,
6824 Bugs: ProtocolBugs{
6825 ExpectedCustomExtension: &emptyString,
6826 },
6827 },
6828 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6829 })
6830
Adam Langley2deb9842015-08-07 11:15:37 -07006831 // Test an unknown extension from the server.
6832 testCases = append(testCases, testCase{
6833 testType: clientTest,
6834 name: "UnknownExtension-Client",
6835 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006836 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006837 Bugs: ProtocolBugs{
6838 CustomExtension: expectedContents,
6839 },
6840 },
David Benjamin0c40a962016-08-01 12:05:50 -04006841 shouldFail: true,
6842 expectedError: ":UNEXPECTED_EXTENSION:",
6843 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006844 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006845 testCases = append(testCases, testCase{
6846 testType: clientTest,
6847 name: "UnknownExtension-Client-TLS13",
6848 config: Config{
6849 MaxVersion: VersionTLS13,
6850 Bugs: ProtocolBugs{
6851 CustomExtension: expectedContents,
6852 },
6853 },
David Benjamin0c40a962016-08-01 12:05:50 -04006854 shouldFail: true,
6855 expectedError: ":UNEXPECTED_EXTENSION:",
6856 expectedLocalError: "remote error: unsupported extension",
6857 })
6858
6859 // Test a known but unoffered extension from the server.
6860 testCases = append(testCases, testCase{
6861 testType: clientTest,
6862 name: "UnofferedExtension-Client",
6863 config: Config{
6864 MaxVersion: VersionTLS12,
6865 Bugs: ProtocolBugs{
6866 SendALPN: "alpn",
6867 },
6868 },
6869 shouldFail: true,
6870 expectedError: ":UNEXPECTED_EXTENSION:",
6871 expectedLocalError: "remote error: unsupported extension",
6872 })
6873 testCases = append(testCases, testCase{
6874 testType: clientTest,
6875 name: "UnofferedExtension-Client-TLS13",
6876 config: Config{
6877 MaxVersion: VersionTLS13,
6878 Bugs: ProtocolBugs{
6879 SendALPN: "alpn",
6880 },
6881 },
6882 shouldFail: true,
6883 expectedError: ":UNEXPECTED_EXTENSION:",
6884 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006885 })
Adam Langley09505632015-07-30 18:10:13 -07006886}
6887
David Benjaminb36a3952015-12-01 18:53:13 -05006888func addRSAClientKeyExchangeTests() {
6889 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6893 config: Config{
6894 // Ensure the ClientHello version and final
6895 // version are different, to detect if the
6896 // server uses the wrong one.
6897 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006898 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006899 Bugs: ProtocolBugs{
6900 BadRSAClientKeyExchange: bad,
6901 },
6902 },
6903 shouldFail: true,
6904 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6905 })
6906 }
6907}
6908
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006909var testCurves = []struct {
6910 name string
6911 id CurveID
6912}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006913 {"P-256", CurveP256},
6914 {"P-384", CurveP384},
6915 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006916 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006917}
6918
Steven Valdez5440fe02016-07-18 12:40:30 -04006919const bogusCurve = 0x1234
6920
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006921func addCurveTests() {
6922 for _, curve := range testCurves {
6923 testCases = append(testCases, testCase{
6924 name: "CurveTest-Client-" + curve.name,
6925 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006926 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006927 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6928 CurvePreferences: []CurveID{curve.id},
6929 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006930 flags: []string{
6931 "-enable-all-curves",
6932 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6933 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006934 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006935 })
6936 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006937 name: "CurveTest-Client-" + curve.name + "-TLS13",
6938 config: Config{
6939 MaxVersion: VersionTLS13,
6940 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6941 CurvePreferences: []CurveID{curve.id},
6942 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006943 flags: []string{
6944 "-enable-all-curves",
6945 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6946 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006947 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006948 })
6949 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006950 testType: serverTest,
6951 name: "CurveTest-Server-" + curve.name,
6952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006953 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6955 CurvePreferences: []CurveID{curve.id},
6956 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006957 flags: []string{
6958 "-enable-all-curves",
6959 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6960 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006961 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006962 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006963 testCases = append(testCases, testCase{
6964 testType: serverTest,
6965 name: "CurveTest-Server-" + curve.name + "-TLS13",
6966 config: Config{
6967 MaxVersion: VersionTLS13,
6968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6969 CurvePreferences: []CurveID{curve.id},
6970 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006971 flags: []string{
6972 "-enable-all-curves",
6973 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6974 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006975 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006976 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006977 }
David Benjamin241ae832016-01-15 03:04:54 -05006978
6979 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006980 testCases = append(testCases, testCase{
6981 testType: serverTest,
6982 name: "UnknownCurve",
6983 config: Config{
6984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6985 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6986 },
6987 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006988
6989 // The server must not consider ECDHE ciphers when there are no
6990 // supported curves.
6991 testCases = append(testCases, testCase{
6992 testType: serverTest,
6993 name: "NoSupportedCurves",
6994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006995 MaxVersion: VersionTLS12,
6996 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6997 Bugs: ProtocolBugs{
6998 NoSupportedCurves: true,
6999 },
7000 },
7001 shouldFail: true,
7002 expectedError: ":NO_SHARED_CIPHER:",
7003 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007004 testCases = append(testCases, testCase{
7005 testType: serverTest,
7006 name: "NoSupportedCurves-TLS13",
7007 config: Config{
7008 MaxVersion: VersionTLS13,
7009 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7010 Bugs: ProtocolBugs{
7011 NoSupportedCurves: true,
7012 },
7013 },
7014 shouldFail: true,
7015 expectedError: ":NO_SHARED_CIPHER:",
7016 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007017
7018 // The server must fall back to another cipher when there are no
7019 // supported curves.
7020 testCases = append(testCases, testCase{
7021 testType: serverTest,
7022 name: "NoCommonCurves",
7023 config: Config{
7024 MaxVersion: VersionTLS12,
7025 CipherSuites: []uint16{
7026 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7027 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7028 },
7029 CurvePreferences: []CurveID{CurveP224},
7030 },
7031 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7032 })
7033
7034 // The client must reject bogus curves and disabled curves.
7035 testCases = append(testCases, testCase{
7036 name: "BadECDHECurve",
7037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007038 MaxVersion: VersionTLS12,
7039 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7040 Bugs: ProtocolBugs{
7041 SendCurve: bogusCurve,
7042 },
7043 },
7044 shouldFail: true,
7045 expectedError: ":WRONG_CURVE:",
7046 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007047 testCases = append(testCases, testCase{
7048 name: "BadECDHECurve-TLS13",
7049 config: Config{
7050 MaxVersion: VersionTLS13,
7051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7052 Bugs: ProtocolBugs{
7053 SendCurve: bogusCurve,
7054 },
7055 },
7056 shouldFail: true,
7057 expectedError: ":WRONG_CURVE:",
7058 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007059
7060 testCases = append(testCases, testCase{
7061 name: "UnsupportedCurve",
7062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007063 MaxVersion: VersionTLS12,
7064 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7065 CurvePreferences: []CurveID{CurveP256},
7066 Bugs: ProtocolBugs{
7067 IgnorePeerCurvePreferences: true,
7068 },
7069 },
7070 flags: []string{"-p384-only"},
7071 shouldFail: true,
7072 expectedError: ":WRONG_CURVE:",
7073 })
7074
David Benjamin4f921572016-07-17 14:20:10 +02007075 testCases = append(testCases, testCase{
7076 // TODO(davidben): Add a TLS 1.3 version where
7077 // HelloRetryRequest requests an unsupported curve.
7078 name: "UnsupportedCurve-ServerHello-TLS13",
7079 config: Config{
7080 MaxVersion: VersionTLS12,
7081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7082 CurvePreferences: []CurveID{CurveP384},
7083 Bugs: ProtocolBugs{
7084 SendCurve: CurveP256,
7085 },
7086 },
7087 flags: []string{"-p384-only"},
7088 shouldFail: true,
7089 expectedError: ":WRONG_CURVE:",
7090 })
7091
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 // Test invalid curve points.
7093 testCases = append(testCases, testCase{
7094 name: "InvalidECDHPoint-Client",
7095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007096 MaxVersion: VersionTLS12,
7097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7098 CurvePreferences: []CurveID{CurveP256},
7099 Bugs: ProtocolBugs{
7100 InvalidECDHPoint: true,
7101 },
7102 },
7103 shouldFail: true,
7104 expectedError: ":INVALID_ENCODING:",
7105 })
7106 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007107 name: "InvalidECDHPoint-Client-TLS13",
7108 config: Config{
7109 MaxVersion: VersionTLS13,
7110 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7111 CurvePreferences: []CurveID{CurveP256},
7112 Bugs: ProtocolBugs{
7113 InvalidECDHPoint: true,
7114 },
7115 },
7116 shouldFail: true,
7117 expectedError: ":INVALID_ENCODING:",
7118 })
7119 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007120 testType: serverTest,
7121 name: "InvalidECDHPoint-Server",
7122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007123 MaxVersion: VersionTLS12,
7124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7125 CurvePreferences: []CurveID{CurveP256},
7126 Bugs: ProtocolBugs{
7127 InvalidECDHPoint: true,
7128 },
7129 },
7130 shouldFail: true,
7131 expectedError: ":INVALID_ENCODING:",
7132 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007133 testCases = append(testCases, testCase{
7134 testType: serverTest,
7135 name: "InvalidECDHPoint-Server-TLS13",
7136 config: Config{
7137 MaxVersion: VersionTLS13,
7138 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7139 CurvePreferences: []CurveID{CurveP256},
7140 Bugs: ProtocolBugs{
7141 InvalidECDHPoint: true,
7142 },
7143 },
7144 shouldFail: true,
7145 expectedError: ":INVALID_ENCODING:",
7146 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007147}
7148
Matt Braithwaite54217e42016-06-13 13:03:47 -07007149func addCECPQ1Tests() {
7150 testCases = append(testCases, testCase{
7151 testType: clientTest,
7152 name: "CECPQ1-Client-BadX25519Part",
7153 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007154 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007155 MinVersion: VersionTLS12,
7156 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7157 Bugs: ProtocolBugs{
7158 CECPQ1BadX25519Part: true,
7159 },
7160 },
7161 flags: []string{"-cipher", "kCECPQ1"},
7162 shouldFail: true,
7163 expectedLocalError: "local error: bad record MAC",
7164 })
7165 testCases = append(testCases, testCase{
7166 testType: clientTest,
7167 name: "CECPQ1-Client-BadNewhopePart",
7168 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007169 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007170 MinVersion: VersionTLS12,
7171 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7172 Bugs: ProtocolBugs{
7173 CECPQ1BadNewhopePart: true,
7174 },
7175 },
7176 flags: []string{"-cipher", "kCECPQ1"},
7177 shouldFail: true,
7178 expectedLocalError: "local error: bad record MAC",
7179 })
7180 testCases = append(testCases, testCase{
7181 testType: serverTest,
7182 name: "CECPQ1-Server-BadX25519Part",
7183 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007184 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007185 MinVersion: VersionTLS12,
7186 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7187 Bugs: ProtocolBugs{
7188 CECPQ1BadX25519Part: true,
7189 },
7190 },
7191 flags: []string{"-cipher", "kCECPQ1"},
7192 shouldFail: true,
7193 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7194 })
7195 testCases = append(testCases, testCase{
7196 testType: serverTest,
7197 name: "CECPQ1-Server-BadNewhopePart",
7198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007199 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007200 MinVersion: VersionTLS12,
7201 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7202 Bugs: ProtocolBugs{
7203 CECPQ1BadNewhopePart: true,
7204 },
7205 },
7206 flags: []string{"-cipher", "kCECPQ1"},
7207 shouldFail: true,
7208 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7209 })
7210}
7211
David Benjamin5c4e8572016-08-19 17:44:53 -04007212func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007213 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007214 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007215 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007216 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007217 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7218 Bugs: ProtocolBugs{
7219 // This is a 1234-bit prime number, generated
7220 // with:
7221 // openssl gendh 1234 | openssl asn1parse -i
7222 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7223 },
7224 },
David Benjamin9e68f192016-06-30 14:55:33 -04007225 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007226 })
7227 testCases = append(testCases, testCase{
7228 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007229 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007230 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007231 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007232 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7233 },
7234 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007235 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007236 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007237}
7238
David Benjaminc9ae27c2016-06-24 22:56:37 -04007239func addTLS13RecordTests() {
7240 testCases = append(testCases, testCase{
7241 name: "TLS13-RecordPadding",
7242 config: Config{
7243 MaxVersion: VersionTLS13,
7244 MinVersion: VersionTLS13,
7245 Bugs: ProtocolBugs{
7246 RecordPadding: 10,
7247 },
7248 },
7249 })
7250
7251 testCases = append(testCases, testCase{
7252 name: "TLS13-EmptyRecords",
7253 config: Config{
7254 MaxVersion: VersionTLS13,
7255 MinVersion: VersionTLS13,
7256 Bugs: ProtocolBugs{
7257 OmitRecordContents: true,
7258 },
7259 },
7260 shouldFail: true,
7261 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7262 })
7263
7264 testCases = append(testCases, testCase{
7265 name: "TLS13-OnlyPadding",
7266 config: Config{
7267 MaxVersion: VersionTLS13,
7268 MinVersion: VersionTLS13,
7269 Bugs: ProtocolBugs{
7270 OmitRecordContents: true,
7271 RecordPadding: 10,
7272 },
7273 },
7274 shouldFail: true,
7275 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7276 })
7277
7278 testCases = append(testCases, testCase{
7279 name: "TLS13-WrongOuterRecord",
7280 config: Config{
7281 MaxVersion: VersionTLS13,
7282 MinVersion: VersionTLS13,
7283 Bugs: ProtocolBugs{
7284 OuterRecordType: recordTypeHandshake,
7285 },
7286 },
7287 shouldFail: true,
7288 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7289 })
7290}
7291
David Benjamin82261be2016-07-07 14:32:50 -07007292func addChangeCipherSpecTests() {
7293 // Test missing ChangeCipherSpecs.
7294 testCases = append(testCases, testCase{
7295 name: "SkipChangeCipherSpec-Client",
7296 config: Config{
7297 MaxVersion: VersionTLS12,
7298 Bugs: ProtocolBugs{
7299 SkipChangeCipherSpec: true,
7300 },
7301 },
7302 shouldFail: true,
7303 expectedError: ":UNEXPECTED_RECORD:",
7304 })
7305 testCases = append(testCases, testCase{
7306 testType: serverTest,
7307 name: "SkipChangeCipherSpec-Server",
7308 config: Config{
7309 MaxVersion: VersionTLS12,
7310 Bugs: ProtocolBugs{
7311 SkipChangeCipherSpec: true,
7312 },
7313 },
7314 shouldFail: true,
7315 expectedError: ":UNEXPECTED_RECORD:",
7316 })
7317 testCases = append(testCases, testCase{
7318 testType: serverTest,
7319 name: "SkipChangeCipherSpec-Server-NPN",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 NextProtos: []string{"bar"},
7323 Bugs: ProtocolBugs{
7324 SkipChangeCipherSpec: true,
7325 },
7326 },
7327 flags: []string{
7328 "-advertise-npn", "\x03foo\x03bar\x03baz",
7329 },
7330 shouldFail: true,
7331 expectedError: ":UNEXPECTED_RECORD:",
7332 })
7333
7334 // Test synchronization between the handshake and ChangeCipherSpec.
7335 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7336 // rejected. Test both with and without handshake packing to handle both
7337 // when the partial post-CCS message is in its own record and when it is
7338 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007339 for _, packed := range []bool{false, true} {
7340 var suffix string
7341 if packed {
7342 suffix = "-Packed"
7343 }
7344
7345 testCases = append(testCases, testCase{
7346 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7347 config: Config{
7348 MaxVersion: VersionTLS12,
7349 Bugs: ProtocolBugs{
7350 FragmentAcrossChangeCipherSpec: true,
7351 PackHandshakeFlight: packed,
7352 },
7353 },
7354 shouldFail: true,
7355 expectedError: ":UNEXPECTED_RECORD:",
7356 })
7357 testCases = append(testCases, testCase{
7358 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7359 config: Config{
7360 MaxVersion: VersionTLS12,
7361 },
7362 resumeSession: true,
7363 resumeConfig: &Config{
7364 MaxVersion: VersionTLS12,
7365 Bugs: ProtocolBugs{
7366 FragmentAcrossChangeCipherSpec: true,
7367 PackHandshakeFlight: packed,
7368 },
7369 },
7370 shouldFail: true,
7371 expectedError: ":UNEXPECTED_RECORD:",
7372 })
7373 testCases = append(testCases, testCase{
7374 testType: serverTest,
7375 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7376 config: Config{
7377 MaxVersion: VersionTLS12,
7378 Bugs: ProtocolBugs{
7379 FragmentAcrossChangeCipherSpec: true,
7380 PackHandshakeFlight: packed,
7381 },
7382 },
7383 shouldFail: true,
7384 expectedError: ":UNEXPECTED_RECORD:",
7385 })
7386 testCases = append(testCases, testCase{
7387 testType: serverTest,
7388 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 },
7392 resumeSession: true,
7393 resumeConfig: &Config{
7394 MaxVersion: VersionTLS12,
7395 Bugs: ProtocolBugs{
7396 FragmentAcrossChangeCipherSpec: true,
7397 PackHandshakeFlight: packed,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":UNEXPECTED_RECORD:",
7402 })
7403 testCases = append(testCases, testCase{
7404 testType: serverTest,
7405 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7406 config: Config{
7407 MaxVersion: VersionTLS12,
7408 NextProtos: []string{"bar"},
7409 Bugs: ProtocolBugs{
7410 FragmentAcrossChangeCipherSpec: true,
7411 PackHandshakeFlight: packed,
7412 },
7413 },
7414 flags: []string{
7415 "-advertise-npn", "\x03foo\x03bar\x03baz",
7416 },
7417 shouldFail: true,
7418 expectedError: ":UNEXPECTED_RECORD:",
7419 })
7420 }
7421
David Benjamin61672812016-07-14 23:10:43 -04007422 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7423 // messages in the handshake queue. Do this by testing the server
7424 // reading the client Finished, reversing the flight so Finished comes
7425 // first.
7426 testCases = append(testCases, testCase{
7427 protocol: dtls,
7428 testType: serverTest,
7429 name: "SendUnencryptedFinished-DTLS",
7430 config: Config{
7431 MaxVersion: VersionTLS12,
7432 Bugs: ProtocolBugs{
7433 SendUnencryptedFinished: true,
7434 ReverseHandshakeFragments: true,
7435 },
7436 },
7437 shouldFail: true,
7438 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7439 })
7440
Steven Valdez143e8b32016-07-11 13:19:03 -04007441 // Test synchronization between encryption changes and the handshake in
7442 // TLS 1.3, where ChangeCipherSpec is implicit.
7443 testCases = append(testCases, testCase{
7444 name: "PartialEncryptedExtensionsWithServerHello",
7445 config: Config{
7446 MaxVersion: VersionTLS13,
7447 Bugs: ProtocolBugs{
7448 PartialEncryptedExtensionsWithServerHello: true,
7449 },
7450 },
7451 shouldFail: true,
7452 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7453 })
7454 testCases = append(testCases, testCase{
7455 testType: serverTest,
7456 name: "PartialClientFinishedWithClientHello",
7457 config: Config{
7458 MaxVersion: VersionTLS13,
7459 Bugs: ProtocolBugs{
7460 PartialClientFinishedWithClientHello: true,
7461 },
7462 },
7463 shouldFail: true,
7464 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7465 })
7466
David Benjamin82261be2016-07-07 14:32:50 -07007467 // Test that early ChangeCipherSpecs are handled correctly.
7468 testCases = append(testCases, testCase{
7469 testType: serverTest,
7470 name: "EarlyChangeCipherSpec-server-1",
7471 config: Config{
7472 MaxVersion: VersionTLS12,
7473 Bugs: ProtocolBugs{
7474 EarlyChangeCipherSpec: 1,
7475 },
7476 },
7477 shouldFail: true,
7478 expectedError: ":UNEXPECTED_RECORD:",
7479 })
7480 testCases = append(testCases, testCase{
7481 testType: serverTest,
7482 name: "EarlyChangeCipherSpec-server-2",
7483 config: Config{
7484 MaxVersion: VersionTLS12,
7485 Bugs: ProtocolBugs{
7486 EarlyChangeCipherSpec: 2,
7487 },
7488 },
7489 shouldFail: true,
7490 expectedError: ":UNEXPECTED_RECORD:",
7491 })
7492 testCases = append(testCases, testCase{
7493 protocol: dtls,
7494 name: "StrayChangeCipherSpec",
7495 config: Config{
7496 // TODO(davidben): Once DTLS 1.3 exists, test
7497 // that stray ChangeCipherSpec messages are
7498 // rejected.
7499 MaxVersion: VersionTLS12,
7500 Bugs: ProtocolBugs{
7501 StrayChangeCipherSpec: true,
7502 },
7503 },
7504 })
7505
7506 // Test that the contents of ChangeCipherSpec are checked.
7507 testCases = append(testCases, testCase{
7508 name: "BadChangeCipherSpec-1",
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 Bugs: ProtocolBugs{
7512 BadChangeCipherSpec: []byte{2},
7513 },
7514 },
7515 shouldFail: true,
7516 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7517 })
7518 testCases = append(testCases, testCase{
7519 name: "BadChangeCipherSpec-2",
7520 config: Config{
7521 MaxVersion: VersionTLS12,
7522 Bugs: ProtocolBugs{
7523 BadChangeCipherSpec: []byte{1, 1},
7524 },
7525 },
7526 shouldFail: true,
7527 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7528 })
7529 testCases = append(testCases, testCase{
7530 protocol: dtls,
7531 name: "BadChangeCipherSpec-DTLS-1",
7532 config: Config{
7533 MaxVersion: VersionTLS12,
7534 Bugs: ProtocolBugs{
7535 BadChangeCipherSpec: []byte{2},
7536 },
7537 },
7538 shouldFail: true,
7539 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7540 })
7541 testCases = append(testCases, testCase{
7542 protocol: dtls,
7543 name: "BadChangeCipherSpec-DTLS-2",
7544 config: Config{
7545 MaxVersion: VersionTLS12,
7546 Bugs: ProtocolBugs{
7547 BadChangeCipherSpec: []byte{1, 1},
7548 },
7549 },
7550 shouldFail: true,
7551 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7552 })
7553}
7554
David Benjamincd2c8062016-09-09 11:28:16 -04007555type perMessageTest struct {
7556 messageType uint8
7557 test testCase
7558}
7559
7560// makePerMessageTests returns a series of test templates which cover each
7561// message in the TLS handshake. These may be used with bugs like
7562// WrongMessageType to fully test a per-message bug.
7563func makePerMessageTests() []perMessageTest {
7564 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007565 for _, protocol := range []protocol{tls, dtls} {
7566 var suffix string
7567 if protocol == dtls {
7568 suffix = "-DTLS"
7569 }
7570
David Benjamincd2c8062016-09-09 11:28:16 -04007571 ret = append(ret, perMessageTest{
7572 messageType: typeClientHello,
7573 test: testCase{
7574 protocol: protocol,
7575 testType: serverTest,
7576 name: "ClientHello" + suffix,
7577 config: Config{
7578 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007579 },
7580 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007581 })
7582
7583 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007584 ret = append(ret, perMessageTest{
7585 messageType: typeHelloVerifyRequest,
7586 test: testCase{
7587 protocol: protocol,
7588 name: "HelloVerifyRequest" + suffix,
7589 config: Config{
7590 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007591 },
7592 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007593 })
7594 }
7595
David Benjamincd2c8062016-09-09 11:28:16 -04007596 ret = append(ret, perMessageTest{
7597 messageType: typeServerHello,
7598 test: testCase{
7599 protocol: protocol,
7600 name: "ServerHello" + suffix,
7601 config: Config{
7602 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007603 },
7604 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007605 })
7606
David Benjamincd2c8062016-09-09 11:28:16 -04007607 ret = append(ret, perMessageTest{
7608 messageType: typeCertificate,
7609 test: testCase{
7610 protocol: protocol,
7611 name: "ServerCertificate" + suffix,
7612 config: Config{
7613 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007614 },
7615 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007616 })
7617
David Benjamincd2c8062016-09-09 11:28:16 -04007618 ret = append(ret, perMessageTest{
7619 messageType: typeCertificateStatus,
7620 test: testCase{
7621 protocol: protocol,
7622 name: "CertificateStatus" + suffix,
7623 config: Config{
7624 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007625 },
David Benjamincd2c8062016-09-09 11:28:16 -04007626 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007627 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007628 })
7629
David Benjamincd2c8062016-09-09 11:28:16 -04007630 ret = append(ret, perMessageTest{
7631 messageType: typeServerKeyExchange,
7632 test: testCase{
7633 protocol: protocol,
7634 name: "ServerKeyExchange" + suffix,
7635 config: Config{
7636 MaxVersion: VersionTLS12,
7637 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007638 },
7639 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007640 })
7641
David Benjamincd2c8062016-09-09 11:28:16 -04007642 ret = append(ret, perMessageTest{
7643 messageType: typeCertificateRequest,
7644 test: testCase{
7645 protocol: protocol,
7646 name: "CertificateRequest" + suffix,
7647 config: Config{
7648 MaxVersion: VersionTLS12,
7649 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007650 },
7651 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007652 })
7653
David Benjamincd2c8062016-09-09 11:28:16 -04007654 ret = append(ret, perMessageTest{
7655 messageType: typeServerHelloDone,
7656 test: testCase{
7657 protocol: protocol,
7658 name: "ServerHelloDone" + suffix,
7659 config: Config{
7660 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007661 },
7662 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007663 })
7664
David Benjamincd2c8062016-09-09 11:28:16 -04007665 ret = append(ret, perMessageTest{
7666 messageType: typeCertificate,
7667 test: testCase{
7668 testType: serverTest,
7669 protocol: protocol,
7670 name: "ClientCertificate" + suffix,
7671 config: Config{
7672 Certificates: []Certificate{rsaCertificate},
7673 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007674 },
David Benjamincd2c8062016-09-09 11:28:16 -04007675 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007676 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007677 })
7678
David Benjamincd2c8062016-09-09 11:28:16 -04007679 ret = append(ret, perMessageTest{
7680 messageType: typeCertificateVerify,
7681 test: testCase{
7682 testType: serverTest,
7683 protocol: protocol,
7684 name: "CertificateVerify" + suffix,
7685 config: Config{
7686 Certificates: []Certificate{rsaCertificate},
7687 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007688 },
David Benjamincd2c8062016-09-09 11:28:16 -04007689 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007690 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007691 })
7692
David Benjamincd2c8062016-09-09 11:28:16 -04007693 ret = append(ret, perMessageTest{
7694 messageType: typeClientKeyExchange,
7695 test: testCase{
7696 testType: serverTest,
7697 protocol: protocol,
7698 name: "ClientKeyExchange" + suffix,
7699 config: Config{
7700 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007701 },
7702 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007703 })
7704
7705 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007706 ret = append(ret, perMessageTest{
7707 messageType: typeNextProtocol,
7708 test: testCase{
7709 testType: serverTest,
7710 protocol: protocol,
7711 name: "NextProtocol" + suffix,
7712 config: Config{
7713 MaxVersion: VersionTLS12,
7714 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007715 },
David Benjamincd2c8062016-09-09 11:28:16 -04007716 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007717 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007718 })
7719
David Benjamincd2c8062016-09-09 11:28:16 -04007720 ret = append(ret, perMessageTest{
7721 messageType: typeChannelID,
7722 test: testCase{
7723 testType: serverTest,
7724 protocol: protocol,
7725 name: "ChannelID" + suffix,
7726 config: Config{
7727 MaxVersion: VersionTLS12,
7728 ChannelID: channelIDKey,
7729 },
7730 flags: []string{
7731 "-expect-channel-id",
7732 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007733 },
7734 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007735 })
7736 }
7737
David Benjamincd2c8062016-09-09 11:28:16 -04007738 ret = append(ret, perMessageTest{
7739 messageType: typeFinished,
7740 test: testCase{
7741 testType: serverTest,
7742 protocol: protocol,
7743 name: "ClientFinished" + suffix,
7744 config: Config{
7745 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007746 },
7747 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007748 })
7749
David Benjamincd2c8062016-09-09 11:28:16 -04007750 ret = append(ret, perMessageTest{
7751 messageType: typeNewSessionTicket,
7752 test: testCase{
7753 protocol: protocol,
7754 name: "NewSessionTicket" + suffix,
7755 config: Config{
7756 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007757 },
7758 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007759 })
7760
David Benjamincd2c8062016-09-09 11:28:16 -04007761 ret = append(ret, perMessageTest{
7762 messageType: typeFinished,
7763 test: testCase{
7764 protocol: protocol,
7765 name: "ServerFinished" + suffix,
7766 config: Config{
7767 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007768 },
7769 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007770 })
7771
7772 }
David Benjamincd2c8062016-09-09 11:28:16 -04007773
7774 ret = append(ret, perMessageTest{
7775 messageType: typeClientHello,
7776 test: testCase{
7777 testType: serverTest,
7778 name: "TLS13-ClientHello",
7779 config: Config{
7780 MaxVersion: VersionTLS13,
7781 },
7782 },
7783 })
7784
7785 ret = append(ret, perMessageTest{
7786 messageType: typeServerHello,
7787 test: testCase{
7788 name: "TLS13-ServerHello",
7789 config: Config{
7790 MaxVersion: VersionTLS13,
7791 },
7792 },
7793 })
7794
7795 ret = append(ret, perMessageTest{
7796 messageType: typeEncryptedExtensions,
7797 test: testCase{
7798 name: "TLS13-EncryptedExtensions",
7799 config: Config{
7800 MaxVersion: VersionTLS13,
7801 },
7802 },
7803 })
7804
7805 ret = append(ret, perMessageTest{
7806 messageType: typeCertificateRequest,
7807 test: testCase{
7808 name: "TLS13-CertificateRequest",
7809 config: Config{
7810 MaxVersion: VersionTLS13,
7811 ClientAuth: RequireAnyClientCert,
7812 },
7813 },
7814 })
7815
7816 ret = append(ret, perMessageTest{
7817 messageType: typeCertificate,
7818 test: testCase{
7819 name: "TLS13-ServerCertificate",
7820 config: Config{
7821 MaxVersion: VersionTLS13,
7822 },
7823 },
7824 })
7825
7826 ret = append(ret, perMessageTest{
7827 messageType: typeCertificateVerify,
7828 test: testCase{
7829 name: "TLS13-ServerCertificateVerify",
7830 config: Config{
7831 MaxVersion: VersionTLS13,
7832 },
7833 },
7834 })
7835
7836 ret = append(ret, perMessageTest{
7837 messageType: typeFinished,
7838 test: testCase{
7839 name: "TLS13-ServerFinished",
7840 config: Config{
7841 MaxVersion: VersionTLS13,
7842 },
7843 },
7844 })
7845
7846 ret = append(ret, perMessageTest{
7847 messageType: typeCertificate,
7848 test: testCase{
7849 testType: serverTest,
7850 name: "TLS13-ClientCertificate",
7851 config: Config{
7852 Certificates: []Certificate{rsaCertificate},
7853 MaxVersion: VersionTLS13,
7854 },
7855 flags: []string{"-require-any-client-certificate"},
7856 },
7857 })
7858
7859 ret = append(ret, perMessageTest{
7860 messageType: typeCertificateVerify,
7861 test: testCase{
7862 testType: serverTest,
7863 name: "TLS13-ClientCertificateVerify",
7864 config: Config{
7865 Certificates: []Certificate{rsaCertificate},
7866 MaxVersion: VersionTLS13,
7867 },
7868 flags: []string{"-require-any-client-certificate"},
7869 },
7870 })
7871
7872 ret = append(ret, perMessageTest{
7873 messageType: typeFinished,
7874 test: testCase{
7875 testType: serverTest,
7876 name: "TLS13-ClientFinished",
7877 config: Config{
7878 MaxVersion: VersionTLS13,
7879 },
7880 },
7881 })
7882
7883 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007884}
7885
David Benjamincd2c8062016-09-09 11:28:16 -04007886func addWrongMessageTypeTests() {
7887 for _, t := range makePerMessageTests() {
7888 t.test.name = "WrongMessageType-" + t.test.name
7889 t.test.config.Bugs.SendWrongMessageType = t.messageType
7890 t.test.shouldFail = true
7891 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7892 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007893
David Benjamincd2c8062016-09-09 11:28:16 -04007894 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7895 // In TLS 1.3, a bad ServerHello means the client sends
7896 // an unencrypted alert while the server expects
7897 // encryption, so the alert is not readable by runner.
7898 t.test.expectedLocalError = "local error: bad record MAC"
7899 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007900
David Benjamincd2c8062016-09-09 11:28:16 -04007901 testCases = append(testCases, t.test)
7902 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007903}
7904
David Benjamin639846e2016-09-09 11:41:18 -04007905func addTrailingMessageDataTests() {
7906 for _, t := range makePerMessageTests() {
7907 t.test.name = "TrailingMessageData-" + t.test.name
7908 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7909 t.test.shouldFail = true
7910 t.test.expectedError = ":DECODE_ERROR:"
7911 t.test.expectedLocalError = "remote error: error decoding message"
7912
7913 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7914 // In TLS 1.3, a bad ServerHello means the client sends
7915 // an unencrypted alert while the server expects
7916 // encryption, so the alert is not readable by runner.
7917 t.test.expectedLocalError = "local error: bad record MAC"
7918 }
7919
7920 if t.messageType == typeFinished {
7921 // Bad Finished messages read as the verify data having
7922 // the wrong length.
7923 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7924 t.test.expectedLocalError = "remote error: error decrypting message"
7925 }
7926
7927 testCases = append(testCases, t.test)
7928 }
7929}
7930
Steven Valdez143e8b32016-07-11 13:19:03 -04007931func addTLS13HandshakeTests() {
7932 testCases = append(testCases, testCase{
7933 testType: clientTest,
7934 name: "MissingKeyShare-Client",
7935 config: Config{
7936 MaxVersion: VersionTLS13,
7937 Bugs: ProtocolBugs{
7938 MissingKeyShare: true,
7939 },
7940 },
7941 shouldFail: true,
7942 expectedError: ":MISSING_KEY_SHARE:",
7943 })
7944
7945 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007946 testType: serverTest,
7947 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007948 config: Config{
7949 MaxVersion: VersionTLS13,
7950 Bugs: ProtocolBugs{
7951 MissingKeyShare: true,
7952 },
7953 },
7954 shouldFail: true,
7955 expectedError: ":MISSING_KEY_SHARE:",
7956 })
7957
7958 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007959 testType: serverTest,
7960 name: "DuplicateKeyShares",
7961 config: Config{
7962 MaxVersion: VersionTLS13,
7963 Bugs: ProtocolBugs{
7964 DuplicateKeyShares: true,
7965 },
7966 },
7967 })
7968
7969 testCases = append(testCases, testCase{
7970 testType: clientTest,
7971 name: "EmptyEncryptedExtensions",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
7974 Bugs: ProtocolBugs{
7975 EmptyEncryptedExtensions: true,
7976 },
7977 },
7978 shouldFail: true,
7979 expectedLocalError: "remote error: error decoding message",
7980 })
7981
7982 testCases = append(testCases, testCase{
7983 testType: clientTest,
7984 name: "EncryptedExtensionsWithKeyShare",
7985 config: Config{
7986 MaxVersion: VersionTLS13,
7987 Bugs: ProtocolBugs{
7988 EncryptedExtensionsWithKeyShare: true,
7989 },
7990 },
7991 shouldFail: true,
7992 expectedLocalError: "remote error: unsupported extension",
7993 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007994
7995 testCases = append(testCases, testCase{
7996 testType: serverTest,
7997 name: "SendHelloRetryRequest",
7998 config: Config{
7999 MaxVersion: VersionTLS13,
8000 // Require a HelloRetryRequest for every curve.
8001 DefaultCurves: []CurveID{},
8002 },
8003 expectedCurveID: CurveX25519,
8004 })
8005
8006 testCases = append(testCases, testCase{
8007 testType: serverTest,
8008 name: "SendHelloRetryRequest-2",
8009 config: Config{
8010 MaxVersion: VersionTLS13,
8011 DefaultCurves: []CurveID{CurveP384},
8012 },
8013 // Although the ClientHello did not predict our preferred curve,
8014 // we always select it whether it is predicted or not.
8015 expectedCurveID: CurveX25519,
8016 })
8017
8018 testCases = append(testCases, testCase{
8019 name: "UnknownCurve-HelloRetryRequest",
8020 config: Config{
8021 MaxVersion: VersionTLS13,
8022 // P-384 requires HelloRetryRequest in BoringSSL.
8023 CurvePreferences: []CurveID{CurveP384},
8024 Bugs: ProtocolBugs{
8025 SendHelloRetryRequestCurve: bogusCurve,
8026 },
8027 },
8028 shouldFail: true,
8029 expectedError: ":WRONG_CURVE:",
8030 })
8031
8032 testCases = append(testCases, testCase{
8033 name: "DisabledCurve-HelloRetryRequest",
8034 config: Config{
8035 MaxVersion: VersionTLS13,
8036 CurvePreferences: []CurveID{CurveP256},
8037 Bugs: ProtocolBugs{
8038 IgnorePeerCurvePreferences: true,
8039 },
8040 },
8041 flags: []string{"-p384-only"},
8042 shouldFail: true,
8043 expectedError: ":WRONG_CURVE:",
8044 })
8045
8046 testCases = append(testCases, testCase{
8047 name: "UnnecessaryHelloRetryRequest",
8048 config: Config{
8049 MaxVersion: VersionTLS13,
8050 Bugs: ProtocolBugs{
8051 UnnecessaryHelloRetryRequest: true,
8052 },
8053 },
8054 shouldFail: true,
8055 expectedError: ":WRONG_CURVE:",
8056 })
8057
8058 testCases = append(testCases, testCase{
8059 name: "SecondHelloRetryRequest",
8060 config: Config{
8061 MaxVersion: VersionTLS13,
8062 // P-384 requires HelloRetryRequest in BoringSSL.
8063 CurvePreferences: []CurveID{CurveP384},
8064 Bugs: ProtocolBugs{
8065 SecondHelloRetryRequest: true,
8066 },
8067 },
8068 shouldFail: true,
8069 expectedError: ":UNEXPECTED_MESSAGE:",
8070 })
8071
8072 testCases = append(testCases, testCase{
8073 testType: serverTest,
8074 name: "SecondClientHelloMissingKeyShare",
8075 config: Config{
8076 MaxVersion: VersionTLS13,
8077 DefaultCurves: []CurveID{},
8078 Bugs: ProtocolBugs{
8079 SecondClientHelloMissingKeyShare: true,
8080 },
8081 },
8082 shouldFail: true,
8083 expectedError: ":MISSING_KEY_SHARE:",
8084 })
8085
8086 testCases = append(testCases, testCase{
8087 testType: serverTest,
8088 name: "SecondClientHelloWrongCurve",
8089 config: Config{
8090 MaxVersion: VersionTLS13,
8091 DefaultCurves: []CurveID{},
8092 Bugs: ProtocolBugs{
8093 MisinterpretHelloRetryRequestCurve: CurveP521,
8094 },
8095 },
8096 shouldFail: true,
8097 expectedError: ":WRONG_CURVE:",
8098 })
8099
8100 testCases = append(testCases, testCase{
8101 name: "HelloRetryRequestVersionMismatch",
8102 config: Config{
8103 MaxVersion: VersionTLS13,
8104 // P-384 requires HelloRetryRequest in BoringSSL.
8105 CurvePreferences: []CurveID{CurveP384},
8106 Bugs: ProtocolBugs{
8107 SendServerHelloVersion: 0x0305,
8108 },
8109 },
8110 shouldFail: true,
8111 expectedError: ":WRONG_VERSION_NUMBER:",
8112 })
8113
8114 testCases = append(testCases, testCase{
8115 name: "HelloRetryRequestCurveMismatch",
8116 config: Config{
8117 MaxVersion: VersionTLS13,
8118 // P-384 requires HelloRetryRequest in BoringSSL.
8119 CurvePreferences: []CurveID{CurveP384},
8120 Bugs: ProtocolBugs{
8121 // Send P-384 (correct) in the HelloRetryRequest.
8122 SendHelloRetryRequestCurve: CurveP384,
8123 // But send P-256 in the ServerHello.
8124 SendCurve: CurveP256,
8125 },
8126 },
8127 shouldFail: true,
8128 expectedError: ":WRONG_CURVE:",
8129 })
8130
8131 // Test the server selecting a curve that requires a HelloRetryRequest
8132 // without sending it.
8133 testCases = append(testCases, testCase{
8134 name: "SkipHelloRetryRequest",
8135 config: Config{
8136 MaxVersion: VersionTLS13,
8137 // P-384 requires HelloRetryRequest in BoringSSL.
8138 CurvePreferences: []CurveID{CurveP384},
8139 Bugs: ProtocolBugs{
8140 SkipHelloRetryRequest: true,
8141 },
8142 },
8143 shouldFail: true,
8144 expectedError: ":WRONG_CURVE:",
8145 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008146
8147 testCases = append(testCases, testCase{
8148 name: "TLS13-RequestContextInHandshake",
8149 config: Config{
8150 MaxVersion: VersionTLS13,
8151 MinVersion: VersionTLS13,
8152 ClientAuth: RequireAnyClientCert,
8153 Bugs: ProtocolBugs{
8154 SendRequestContext: []byte("request context"),
8155 },
8156 },
8157 flags: []string{
8158 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8159 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8160 },
8161 shouldFail: true,
8162 expectedError: ":DECODE_ERROR:",
8163 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008164}
8165
Adam Langley7c803a62015-06-15 15:35:05 -07008166func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008167 defer wg.Done()
8168
8169 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008170 var err error
8171
8172 if *mallocTest < 0 {
8173 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008174 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008175 } else {
8176 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8177 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008178 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008179 if err != nil {
8180 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8181 }
8182 break
8183 }
8184 }
8185 }
Adam Langley95c29f32014-06-20 12:00:00 -07008186 statusChan <- statusMsg{test: test, err: err}
8187 }
8188}
8189
8190type statusMsg struct {
8191 test *testCase
8192 started bool
8193 err error
8194}
8195
David Benjamin5f237bc2015-02-11 17:14:15 -05008196func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008197 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008198
David Benjamin5f237bc2015-02-11 17:14:15 -05008199 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008200 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008201 if !*pipe {
8202 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008203 var erase string
8204 for i := 0; i < lineLen; i++ {
8205 erase += "\b \b"
8206 }
8207 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008208 }
8209
Adam Langley95c29f32014-06-20 12:00:00 -07008210 if msg.started {
8211 started++
8212 } else {
8213 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008214
8215 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008216 if msg.err == errUnimplemented {
8217 if *pipe {
8218 // Print each test instead of a status line.
8219 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8220 }
8221 unimplemented++
8222 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8223 } else {
8224 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8225 failed++
8226 testOutput.addResult(msg.test.name, "FAIL")
8227 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008228 } else {
8229 if *pipe {
8230 // Print each test instead of a status line.
8231 fmt.Printf("PASSED (%s)\n", msg.test.name)
8232 }
8233 testOutput.addResult(msg.test.name, "PASS")
8234 }
Adam Langley95c29f32014-06-20 12:00:00 -07008235 }
8236
David Benjamin5f237bc2015-02-11 17:14:15 -05008237 if !*pipe {
8238 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008239 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008240 lineLen = len(line)
8241 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008242 }
Adam Langley95c29f32014-06-20 12:00:00 -07008243 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008244
8245 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008246}
8247
8248func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008249 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008250 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008251 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008252
Adam Langley7c803a62015-06-15 15:35:05 -07008253 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008254 addCipherSuiteTests()
8255 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008256 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008257 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008258 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008259 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008260 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008261 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008262 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008263 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008264 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008265 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008266 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008267 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008268 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008269 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008270 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008271 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008272 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008273 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008274 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008275 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008276 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008277 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008278 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008279 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008280 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008281 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008282
8283 var wg sync.WaitGroup
8284
Adam Langley7c803a62015-06-15 15:35:05 -07008285 statusChan := make(chan statusMsg, *numWorkers)
8286 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008287 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008288
EKRf71d7ed2016-08-06 13:25:12 -07008289 if len(*shimConfigFile) != 0 {
8290 encoded, err := ioutil.ReadFile(*shimConfigFile)
8291 if err != nil {
8292 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8293 os.Exit(1)
8294 }
8295
8296 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8297 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8298 os.Exit(1)
8299 }
8300 }
8301
David Benjamin025b3d32014-07-01 19:53:04 -04008302 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008303
Adam Langley7c803a62015-06-15 15:35:05 -07008304 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008305 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008306 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008307 }
8308
David Benjamin270f0a72016-03-17 14:41:36 -04008309 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008310 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008311 matched := true
8312 if len(*testToRun) != 0 {
8313 var err error
8314 matched, err = filepath.Match(*testToRun, testCases[i].name)
8315 if err != nil {
8316 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8317 os.Exit(1)
8318 }
8319 }
8320
EKRf71d7ed2016-08-06 13:25:12 -07008321 if !*includeDisabled {
8322 for pattern := range shimConfig.DisabledTests {
8323 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8324 if err != nil {
8325 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8326 os.Exit(1)
8327 }
8328
8329 if isDisabled {
8330 matched = false
8331 break
8332 }
8333 }
8334 }
8335
David Benjamin17e12922016-07-28 18:04:43 -04008336 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008337 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008338 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008339 }
8340 }
David Benjamin17e12922016-07-28 18:04:43 -04008341
David Benjamin270f0a72016-03-17 14:41:36 -04008342 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008343 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008344 os.Exit(1)
8345 }
Adam Langley95c29f32014-06-20 12:00:00 -07008346
8347 close(testChan)
8348 wg.Wait()
8349 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008350 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008351
8352 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008353
8354 if *jsonOutput != "" {
8355 if err := testOutput.writeTo(*jsonOutput); err != nil {
8356 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8357 }
8358 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008359
EKR842ae6c2016-07-27 09:22:05 +02008360 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8361 os.Exit(1)
8362 }
8363
8364 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008365 os.Exit(1)
8366 }
Adam Langley95c29f32014-06-20 12:00:00 -07008367}