blob: 19f67b1e690a8d05bc6cfea3c17ae95e4f69617c [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 Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 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
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
619 tlsConn.SendKeyUpdate()
620 }
621
David Benjamina8ebe222015-06-06 03:04:39 -0400622 for i := 0; i < test.sendEmptyRecords; i++ {
623 tlsConn.Write(nil)
624 }
625
David Benjamin24f346d2015-06-06 03:28:08 -0400626 for i := 0; i < test.sendWarningAlerts; i++ {
627 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
628 }
629
David Benjamin47921102016-07-28 11:29:18 -0400630 if test.sendHalfHelloRequest {
631 tlsConn.SendHalfHelloRequest()
632 }
633
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400634 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700635 if test.renegotiateCiphers != nil {
636 config.CipherSuites = test.renegotiateCiphers
637 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400638 for i := 0; i < test.renegotiate; i++ {
639 if err := tlsConn.Renegotiate(); err != nil {
640 return err
641 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 }
643 } else if test.renegotiateCiphers != nil {
644 panic("renegotiateCiphers without renegotiate")
645 }
646
David Benjamin5fa3eba2015-01-22 16:35:40 -0500647 if test.damageFirstWrite {
648 connDamage.setDamage(true)
649 tlsConn.Write([]byte("DAMAGED WRITE"))
650 connDamage.setDamage(false)
651 }
652
David Benjamin8e6db492015-07-25 18:29:23 -0400653 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700654 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400655 if test.protocol == dtls {
656 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
657 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700658 // Read until EOF.
659 _, err := io.Copy(ioutil.Discard, tlsConn)
660 return err
661 }
David Benjamin4417d052015-04-05 04:17:25 -0400662 if messageLen == 0 {
663 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700664 }
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin8e6db492015-07-25 18:29:23 -0400666 messageCount := test.messageCount
667 if messageCount == 0 {
668 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400669 }
670
David Benjamin8e6db492015-07-25 18:29:23 -0400671 for j := 0; j < messageCount; j++ {
672 testMessage := make([]byte, messageLen)
673 for i := range testMessage {
674 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400675 }
David Benjamin8e6db492015-07-25 18:29:23 -0400676 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700677
Steven Valdez32635b82016-08-16 11:25:03 -0400678 for i := 0; i < test.sendKeyUpdates; i++ {
679 tlsConn.SendKeyUpdate()
680 }
681
David Benjamin8e6db492015-07-25 18:29:23 -0400682 for i := 0; i < test.sendEmptyRecords; i++ {
683 tlsConn.Write(nil)
684 }
685
686 for i := 0; i < test.sendWarningAlerts; i++ {
687 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
688 }
689
David Benjamin4f75aaf2015-09-01 16:53:10 -0400690 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400691 // The shim will not respond.
692 continue
693 }
694
David Benjamin8e6db492015-07-25 18:29:23 -0400695 buf := make([]byte, len(testMessage))
696 if test.protocol == dtls {
697 bufTmp := make([]byte, len(buf)+1)
698 n, err := tlsConn.Read(bufTmp)
699 if err != nil {
700 return err
701 }
702 if n != len(buf) {
703 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
704 }
705 copy(buf, bufTmp)
706 } else {
707 _, err := io.ReadFull(tlsConn, buf)
708 if err != nil {
709 return err
710 }
711 }
712
713 for i, v := range buf {
714 if v != testMessage[i]^0xff {
715 return fmt.Errorf("bad reply contents at byte %d", i)
716 }
Adam Langley95c29f32014-06-20 12:00:00 -0700717 }
718 }
719
720 return nil
721}
722
David Benjamin325b5c32014-07-01 19:40:31 -0400723func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400724 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700725 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400726 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700727 }
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, path)
729 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700730
David Benjamin325b5c32014-07-01 19:40:31 -0400731 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732}
733
David Benjamin325b5c32014-07-01 19:40:31 -0400734func gdbOf(path string, args ...string) *exec.Cmd {
735 xtermArgs := []string{"-e", "gdb", "--args"}
736 xtermArgs = append(xtermArgs, path)
737 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700738
David Benjamin325b5c32014-07-01 19:40:31 -0400739 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740}
741
David Benjamind16bf342015-12-18 00:53:12 -0500742func lldbOf(path string, args ...string) *exec.Cmd {
743 xtermArgs := []string{"-e", "lldb", "--"}
744 xtermArgs = append(xtermArgs, path)
745 xtermArgs = append(xtermArgs, args...)
746
747 return exec.Command("xterm", xtermArgs...)
748}
749
EKR842ae6c2016-07-27 09:22:05 +0200750var (
751 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
752 errUnimplemented = errors.New("child process does not implement needed flags")
753)
Adam Langley69a01602014-11-17 17:26:55 -0800754
David Benjamin87c8a642015-02-21 01:54:29 -0500755// accept accepts a connection from listener, unless waitChan signals a process
756// exit first.
757func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
758 type connOrError struct {
759 conn net.Conn
760 err error
761 }
762 connChan := make(chan connOrError, 1)
763 go func() {
764 conn, err := listener.Accept()
765 connChan <- connOrError{conn, err}
766 close(connChan)
767 }()
768 select {
769 case result := <-connChan:
770 return result.conn, result.err
771 case childErr := <-waitChan:
772 waitChan <- childErr
773 return nil, fmt.Errorf("child exited early: %s", childErr)
774 }
775}
776
EKRf71d7ed2016-08-06 13:25:12 -0700777func translateExpectedError(errorStr string) string {
778 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
779 return translated
780 }
781
782 if *looseErrors {
783 return ""
784 }
785
786 return errorStr
787}
788
Adam Langley7c803a62015-06-15 15:35:05 -0700789func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700790 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
791 panic("Error expected without shouldFail in " + test.name)
792 }
793
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700794 if test.expectResumeRejected && !test.resumeSession {
795 panic("expectResumeRejected without resumeSession in " + test.name)
796 }
797
David Benjamin87c8a642015-02-21 01:54:29 -0500798 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
799 if err != nil {
800 panic(err)
801 }
802 defer func() {
803 if listener != nil {
804 listener.Close()
805 }
806 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400809 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400810 flags = append(flags, "-server")
811
David Benjamin025b3d32014-07-01 19:53:04 -0400812 flags = append(flags, "-key-file")
813 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700814 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400815 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700816 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400817 }
818
819 flags = append(flags, "-cert-file")
820 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825 }
David Benjamin5a593af2014-08-11 19:51:50 -0400826
David Benjamin6fd297b2014-08-11 18:43:38 -0400827 if test.protocol == dtls {
828 flags = append(flags, "-dtls")
829 }
830
David Benjamin46662482016-08-17 00:51:00 -0400831 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400832 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400833 resumeCount++
834 if test.resumeRenewedSession {
835 resumeCount++
836 }
837 }
838
839 if resumeCount > 0 {
840 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400841 }
842
David Benjamine58c4f52014-08-24 03:47:07 -0400843 if test.shimWritesFirst {
844 flags = append(flags, "-shim-writes-first")
845 }
846
David Benjamin30789da2015-08-29 22:56:45 -0400847 if test.shimShutsDown {
848 flags = append(flags, "-shim-shuts-down")
849 }
850
David Benjaminc565ebb2015-04-03 04:06:36 -0400851 if test.exportKeyingMaterial > 0 {
852 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
853 flags = append(flags, "-export-label", test.exportLabel)
854 flags = append(flags, "-export-context", test.exportContext)
855 if test.useExportContext {
856 flags = append(flags, "-use-export-context")
857 }
858 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700859 if test.expectResumeRejected {
860 flags = append(flags, "-expect-session-miss")
861 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400862
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700863 if test.testTLSUnique {
864 flags = append(flags, "-tls-unique")
865 }
866
David Benjamin025b3d32014-07-01 19:53:04 -0400867 flags = append(flags, test.flags...)
868
869 var shim *exec.Cmd
870 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700871 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700872 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500874 } else if *useLLDB {
875 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400876 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400878 }
David Benjamin025b3d32014-07-01 19:53:04 -0400879 shim.Stdin = os.Stdin
880 var stdoutBuf, stderrBuf bytes.Buffer
881 shim.Stdout = &stdoutBuf
882 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800883 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500884 shim.Env = os.Environ()
885 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800886 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400887 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800888 }
889 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
890 }
David Benjamin025b3d32014-07-01 19:53:04 -0400891
892 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700893 panic(err)
894 }
David Benjamin87c8a642015-02-21 01:54:29 -0500895 waitChan := make(chan error, 1)
896 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700897
898 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700899
David Benjamin7a4aaa42016-09-20 17:58:14 -0400900 if *deterministic {
901 config.Rand = &deterministicRand{}
902 }
903
David Benjamin87c8a642015-02-21 01:54:29 -0500904 conn, err := acceptOrWait(listener, waitChan)
905 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400906 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn.Close()
908 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500909
David Benjamin46662482016-08-17 00:51:00 -0400910 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400911 var resumeConfig Config
912 if test.resumeConfig != nil {
913 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400914 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500915 resumeConfig.SessionTicketKey = config.SessionTicketKey
916 resumeConfig.ClientSessionCache = config.ClientSessionCache
917 resumeConfig.ServerSessionCache = config.ServerSessionCache
918 }
David Benjamin2e045a92016-06-08 13:09:56 -0400919 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400920 } else {
921 resumeConfig = config
922 }
David Benjamin87c8a642015-02-21 01:54:29 -0500923 var connResume net.Conn
924 connResume, err = acceptOrWait(listener, waitChan)
925 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400926 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500927 connResume.Close()
928 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400929 }
930
David Benjamin87c8a642015-02-21 01:54:29 -0500931 // Close the listener now. This is to avoid hangs should the shim try to
932 // open more connections than expected.
933 listener.Close()
934 listener = nil
935
936 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400937 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800938 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200939 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
940 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800941 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200942 case 89:
943 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400944 case 99:
945 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjamin9aafb642016-09-20 19:36:53 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjamind2ba8892016-09-20 19:41:04 -0400994 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
David Benjamind2ba8892016-09-20 19:41:04 -0400998 if *useValgrind && isValgrindError {
999 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1000 }
1001
Adam Langley95c29f32014-06-20 12:00:00 -07001002 return nil
1003}
1004
1005var tlsVersions = []struct {
1006 name string
1007 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001008 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001009 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001010}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001011 {"SSL3", VersionSSL30, "-no-ssl3", false},
1012 {"TLS1", VersionTLS10, "-no-tls1", true},
1013 {"TLS11", VersionTLS11, "-no-tls11", false},
1014 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001015 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001016}
1017
1018var testCipherSuites = []struct {
1019 name string
1020 id uint16
1021}{
1022 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001023 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001024 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001025 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1030 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1033 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1036 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1038 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001041 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001042 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001044 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001045 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001046 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001049 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001050 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001051 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1052 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1053 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1054 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001055 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1056 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001057 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1058 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001060 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1061 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001062 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001063}
1064
David Benjamin8b8c0062014-11-23 02:47:52 -05001065func hasComponent(suiteName, component string) bool {
1066 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1067}
1068
David Benjaminf7768e42014-08-31 02:06:47 -04001069func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001070 return hasComponent(suiteName, "GCM") ||
1071 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001072 hasComponent(suiteName, "SHA384") ||
1073 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001074}
1075
Nick Harper1fd39d82016-06-14 18:14:35 -07001076func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001077 // Only AEADs.
1078 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1079 return false
1080 }
1081 // No old CHACHA20_POLY1305.
1082 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1083 return false
1084 }
1085 // Must have ECDHE.
1086 // TODO(davidben,svaldez): Add pure PSK support.
1087 if !hasComponent(suiteName, "ECDHE") {
1088 return false
1089 }
1090 // TODO(davidben,svaldez): Add PSK support.
1091 if hasComponent(suiteName, "PSK") {
1092 return false
1093 }
1094 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001095}
1096
David Benjamin8b8c0062014-11-23 02:47:52 -05001097func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001098 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001099}
1100
Adam Langleya7997f12015-05-14 17:38:50 -07001101func bigFromHex(hex string) *big.Int {
1102 ret, ok := new(big.Int).SetString(hex, 16)
1103 if !ok {
1104 panic("failed to parse hex number 0x" + hex)
1105 }
1106 return ret
1107}
1108
Adam Langley7c803a62015-06-15 15:35:05 -07001109func addBasicTests() {
1110 basicTests := []testCase{
1111 {
Adam Langley7c803a62015-06-15 15:35:05 -07001112 name: "NoFallbackSCSV",
1113 config: Config{
1114 Bugs: ProtocolBugs{
1115 FailIfNotFallbackSCSV: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedLocalError: "no fallback SCSV found",
1120 },
1121 {
1122 name: "SendFallbackSCSV",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 FailIfNotFallbackSCSV: true,
1126 },
1127 },
1128 flags: []string{"-fallback-scsv"},
1129 },
1130 {
1131 name: "ClientCertificateTypes",
1132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001133 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001134 ClientAuth: RequestClientCert,
1135 ClientCertificateTypes: []byte{
1136 CertTypeDSSSign,
1137 CertTypeRSASign,
1138 CertTypeECDSASign,
1139 },
1140 },
1141 flags: []string{
1142 "-expect-certificate-types",
1143 base64.StdEncoding.EncodeToString([]byte{
1144 CertTypeDSSSign,
1145 CertTypeRSASign,
1146 CertTypeECDSASign,
1147 }),
1148 },
1149 },
1150 {
Adam Langley7c803a62015-06-15 15:35:05 -07001151 name: "UnauthenticatedECDH",
1152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1155 Bugs: ProtocolBugs{
1156 UnauthenticatedECDH: true,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":UNEXPECTED_MESSAGE:",
1161 },
1162 {
1163 name: "SkipCertificateStatus",
1164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001165 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1167 Bugs: ProtocolBugs{
1168 SkipCertificateStatus: true,
1169 },
1170 },
1171 flags: []string{
1172 "-enable-ocsp-stapling",
1173 },
1174 },
1175 {
1176 name: "SkipServerKeyExchange",
1177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001178 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1180 Bugs: ProtocolBugs{
1181 SkipServerKeyExchange: true,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":UNEXPECTED_MESSAGE:",
1186 },
1187 {
Adam Langley7c803a62015-06-15 15:35:05 -07001188 testType: serverTest,
1189 name: "Alert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 SendSpuriousAlert: alertRecordOverflow,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1197 },
1198 {
1199 protocol: dtls,
1200 testType: serverTest,
1201 name: "Alert-DTLS",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 SendSpuriousAlert: alertRecordOverflow,
1205 },
1206 },
1207 shouldFail: true,
1208 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1209 },
1210 {
1211 testType: serverTest,
1212 name: "FragmentAlert",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 FragmentAlert: true,
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":BAD_ALERT:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "FragmentAlert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 FragmentAlert: true,
1229 SendSpuriousAlert: alertRecordOverflow,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":BAD_ALERT:",
1234 },
1235 {
1236 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001237 name: "DoubleAlert",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 DoubleAlert: true,
1241 SendSpuriousAlert: alertRecordOverflow,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedError: ":BAD_ALERT:",
1246 },
1247 {
1248 protocol: dtls,
1249 testType: serverTest,
1250 name: "DoubleAlert-DTLS",
1251 config: Config{
1252 Bugs: ProtocolBugs{
1253 DoubleAlert: true,
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":BAD_ALERT:",
1259 },
1260 {
Adam Langley7c803a62015-06-15 15:35:05 -07001261 name: "SkipNewSessionTicket",
1262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001263 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001264 Bugs: ProtocolBugs{
1265 SkipNewSessionTicket: true,
1266 },
1267 },
1268 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001269 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001270 },
1271 {
1272 testType: serverTest,
1273 name: "FallbackSCSV",
1274 config: Config{
1275 MaxVersion: VersionTLS11,
1276 Bugs: ProtocolBugs{
1277 SendFallbackSCSV: true,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":INAPPROPRIATE_FALLBACK:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "FallbackSCSV-VersionMatch",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 SendFallbackSCSV: true,
1289 },
1290 },
1291 },
1292 {
1293 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 name: "FallbackSCSV-VersionMatch-TLS12",
1295 config: Config{
1296 MaxVersion: VersionTLS12,
1297 Bugs: ProtocolBugs{
1298 SendFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1302 },
1303 {
1304 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001305 name: "FragmentedClientVersion",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxHandshakeRecordLength: 1,
1309 FragmentClientVersion: true,
1310 },
1311 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001312 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
Adam Langley7c803a62015-06-15 15:35:05 -07001315 testType: serverTest,
1316 name: "HttpGET",
1317 sendPrefix: "GET / HTTP/1.0\n",
1318 shouldFail: true,
1319 expectedError: ":HTTP_REQUEST:",
1320 },
1321 {
1322 testType: serverTest,
1323 name: "HttpPOST",
1324 sendPrefix: "POST / HTTP/1.0\n",
1325 shouldFail: true,
1326 expectedError: ":HTTP_REQUEST:",
1327 },
1328 {
1329 testType: serverTest,
1330 name: "HttpHEAD",
1331 sendPrefix: "HEAD / HTTP/1.0\n",
1332 shouldFail: true,
1333 expectedError: ":HTTP_REQUEST:",
1334 },
1335 {
1336 testType: serverTest,
1337 name: "HttpPUT",
1338 sendPrefix: "PUT / HTTP/1.0\n",
1339 shouldFail: true,
1340 expectedError: ":HTTP_REQUEST:",
1341 },
1342 {
1343 testType: serverTest,
1344 name: "HttpCONNECT",
1345 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1346 shouldFail: true,
1347 expectedError: ":HTTPS_PROXY_REQUEST:",
1348 },
1349 {
1350 testType: serverTest,
1351 name: "Garbage",
1352 sendPrefix: "blah",
1353 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001354 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001355 },
1356 {
Adam Langley7c803a62015-06-15 15:35:05 -07001357 name: "RSAEphemeralKey",
1358 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001359 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001360 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1361 Bugs: ProtocolBugs{
1362 RSAEphemeralKey: true,
1363 },
1364 },
1365 shouldFail: true,
1366 expectedError: ":UNEXPECTED_MESSAGE:",
1367 },
1368 {
1369 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001370 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 shouldFail: true,
1372 expectedError: ":WRONG_SSL_VERSION:",
1373 },
1374 {
1375 protocol: dtls,
1376 name: "DisableEverything-DTLS",
1377 flags: []string{"-no-tls12", "-no-tls1"},
1378 shouldFail: true,
1379 expectedError: ":WRONG_SSL_VERSION:",
1380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 protocol: dtls,
1383 testType: serverTest,
1384 name: "MTU",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 MaxPacketLength: 256,
1388 },
1389 },
1390 flags: []string{"-mtu", "256"},
1391 },
1392 {
1393 protocol: dtls,
1394 testType: serverTest,
1395 name: "MTUExceeded",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 MaxPacketLength: 255,
1399 },
1400 },
1401 flags: []string{"-mtu", "256"},
1402 shouldFail: true,
1403 expectedLocalError: "dtls: exceeded maximum packet length",
1404 },
1405 {
1406 name: "CertMismatchRSA",
1407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001419 name: "CertMismatchRSA-TLS13",
1420 config: Config{
1421 MaxVersion: VersionTLS13,
1422 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1423 Certificates: []Certificate{ecdsaP256Certificate},
1424 Bugs: ProtocolBugs{
1425 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1426 },
1427 },
1428 shouldFail: true,
1429 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1430 },
1431 {
Adam Langley7c803a62015-06-15 15:35:05 -07001432 name: "CertMismatchECDSA",
1433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001434 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001436 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1443 },
1444 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001445 name: "CertMismatchECDSA-TLS13",
1446 config: Config{
1447 MaxVersion: VersionTLS13,
1448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1449 Certificates: []Certificate{rsaCertificate},
1450 Bugs: ProtocolBugs{
1451 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "EmptyCertificateList",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1462 Bugs: ProtocolBugs{
1463 EmptyCertificateList: true,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":DECODE_ERROR:",
1468 },
1469 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 name: "EmptyCertificateList-TLS13",
1471 config: Config{
1472 MaxVersion: VersionTLS13,
1473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1474 Bugs: ProtocolBugs{
1475 EmptyCertificateList: true,
1476 },
1477 },
1478 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001479 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001480 },
1481 {
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "TLSFatalBadPackets",
1483 damageFirstWrite: true,
1484 shouldFail: true,
1485 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets",
1490 damageFirstWrite: true,
1491 },
1492 {
1493 protocol: dtls,
1494 name: "DTLSIgnoreBadPackets-Async",
1495 damageFirstWrite: true,
1496 flags: []string{"-async"},
1497 },
1498 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001499 name: "AppDataBeforeHandshake",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":UNEXPECTED_RECORD:",
1507 },
1508 {
1509 name: "AppDataBeforeHandshake-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 protocol: dtls,
1520 name: "AppDataBeforeHandshake-DTLS",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
1530 protocol: dtls,
1531 name: "AppDataBeforeHandshake-DTLS-Empty",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte{},
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "AppDataAfterChangeCipherSpec",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001552 name: "AppDataAfterChangeCipherSpec-Empty",
1553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001554 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 Bugs: ProtocolBugs{
1556 AppDataAfterChangeCipherSpec: []byte{},
1557 },
1558 },
1559 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001560 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001561 },
1562 {
Adam Langley7c803a62015-06-15 15:35:05 -07001563 protocol: dtls,
1564 name: "AppDataAfterChangeCipherSpec-DTLS",
1565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001566 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001567 Bugs: ProtocolBugs{
1568 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1569 },
1570 },
1571 // BoringSSL's DTLS implementation will drop the out-of-order
1572 // application data.
1573 },
1574 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 protocol: dtls,
1576 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001578 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 Bugs: ProtocolBugs{
1580 AppDataAfterChangeCipherSpec: []byte{},
1581 },
1582 },
1583 // BoringSSL's DTLS implementation will drop the out-of-order
1584 // application data.
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "AlertAfterChangeCipherSpec",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 AlertAfterChangeCipherSpec: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "AlertAfterChangeCipherSpec-DTLS",
1600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001601 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001602 Bugs: ProtocolBugs{
1603 AlertAfterChangeCipherSpec: alertRecordOverflow,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "ReorderHandshakeFragments-Small-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 ReorderHandshakeFragments: true,
1615 // Small enough that every handshake message is
1616 // fragmented.
1617 MaxHandshakeRecordLength: 2,
1618 },
1619 },
1620 },
1621 {
1622 protocol: dtls,
1623 name: "ReorderHandshakeFragments-Large-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 ReorderHandshakeFragments: true,
1627 // Large enough that no handshake message is
1628 // fragmented.
1629 MaxHandshakeRecordLength: 2048,
1630 },
1631 },
1632 },
1633 {
1634 protocol: dtls,
1635 name: "MixCompleteMessageWithFragments-DTLS",
1636 config: Config{
1637 Bugs: ProtocolBugs{
1638 ReorderHandshakeFragments: true,
1639 MixCompleteMessageWithFragments: true,
1640 MaxHandshakeRecordLength: 2,
1641 },
1642 },
1643 },
1644 {
1645 name: "SendInvalidRecordType",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendInvalidRecordType: true,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":UNEXPECTED_RECORD:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendInvalidRecordType-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendInvalidRecordType: true,
1660 },
1661 },
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 ExpectFalseStart: true,
1676 },
1677 },
1678 flags: []string{
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shimWritesFirst: true,
1684 shouldFail: true,
1685 expectedError: ":UNEXPECTED_RECORD:",
1686 },
1687 {
1688 name: "FalseStart-SkipServerSecondLeg-Implicit",
1689 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001690 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1692 NextProtos: []string{"foo"},
1693 Bugs: ProtocolBugs{
1694 SkipNewSessionTicket: true,
1695 SkipChangeCipherSpec: true,
1696 SkipFinished: true,
1697 },
1698 },
1699 flags: []string{
1700 "-implicit-handshake",
1701 "-false-start",
1702 "-handshake-never-done",
1703 "-advertise-alpn", "\x03foo",
1704 },
1705 shouldFail: true,
1706 expectedError: ":UNEXPECTED_RECORD:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "FailEarlyCallback",
1711 flags: []string{"-fail-early-callback"},
1712 shouldFail: true,
1713 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001714 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001715 },
1716 {
Adam Langley7c803a62015-06-15 15:35:05 -07001717 protocol: dtls,
1718 name: "FragmentMessageTypeMismatch-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 MaxHandshakeRecordLength: 2,
1722 FragmentMessageTypeMismatch: true,
1723 },
1724 },
1725 shouldFail: true,
1726 expectedError: ":FRAGMENT_MISMATCH:",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "FragmentMessageLengthMismatch-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxHandshakeRecordLength: 2,
1734 FragmentMessageLengthMismatch: true,
1735 },
1736 },
1737 shouldFail: true,
1738 expectedError: ":FRAGMENT_MISMATCH:",
1739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Header-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: 2,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SplitFragments-Boundary-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SplitFragments: dtlsRecordHeaderLen,
1757 },
1758 },
1759 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001760 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 protocol: dtls,
1764 name: "SplitFragments-Body-DTLS",
1765 config: Config{
1766 Bugs: ProtocolBugs{
1767 SplitFragments: dtlsRecordHeaderLen + 1,
1768 },
1769 },
1770 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001771 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001772 },
1773 {
1774 protocol: dtls,
1775 name: "SendEmptyFragments-DTLS",
1776 config: Config{
1777 Bugs: ProtocolBugs{
1778 SendEmptyFragments: true,
1779 },
1780 },
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 name: "BadFinished-Client",
1784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001794 name: "BadFinished-Client-TLS13",
1795 config: Config{
1796 MaxVersion: VersionTLS13,
1797 Bugs: ProtocolBugs{
1798 BadFinished: true,
1799 },
1800 },
1801 shouldFail: true,
1802 expectedError: ":DIGEST_CHECK_FAILED:",
1803 },
1804 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001805 testType: serverTest,
1806 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 Bugs: ProtocolBugs{
1810 BadFinished: true,
1811 },
1812 },
1813 shouldFail: true,
1814 expectedError: ":DIGEST_CHECK_FAILED:",
1815 },
1816 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001817 testType: serverTest,
1818 name: "BadFinished-Server-TLS13",
1819 config: Config{
1820 MaxVersion: VersionTLS13,
1821 Bugs: ProtocolBugs{
1822 BadFinished: true,
1823 },
1824 },
1825 shouldFail: true,
1826 expectedError: ":DIGEST_CHECK_FAILED:",
1827 },
1828 {
Adam Langley7c803a62015-06-15 15:35:05 -07001829 name: "FalseStart-BadFinished",
1830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001831 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1833 NextProtos: []string{"foo"},
1834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 ExpectFalseStart: true,
1837 },
1838 },
1839 flags: []string{
1840 "-false-start",
1841 "-handshake-never-done",
1842 "-advertise-alpn", "\x03foo",
1843 },
1844 shimWritesFirst: true,
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 name: "NoFalseStart-NoALPN",
1850 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001851 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1853 Bugs: ProtocolBugs{
1854 ExpectFalseStart: true,
1855 AlertBeforeFalseStartTest: alertAccessDenied,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 },
1861 shimWritesFirst: true,
1862 shouldFail: true,
1863 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1864 expectedLocalError: "tls: peer did not false start: EOF",
1865 },
1866 {
1867 name: "NoFalseStart-NoAEAD",
1868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001869 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1871 NextProtos: []string{"foo"},
1872 Bugs: ProtocolBugs{
1873 ExpectFalseStart: true,
1874 AlertBeforeFalseStartTest: alertAccessDenied,
1875 },
1876 },
1877 flags: []string{
1878 "-false-start",
1879 "-advertise-alpn", "\x03foo",
1880 },
1881 shimWritesFirst: true,
1882 shouldFail: true,
1883 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1884 expectedLocalError: "tls: peer did not false start: EOF",
1885 },
1886 {
1887 name: "NoFalseStart-RSA",
1888 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001889 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001890 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1891 NextProtos: []string{"foo"},
1892 Bugs: ProtocolBugs{
1893 ExpectFalseStart: true,
1894 AlertBeforeFalseStartTest: alertAccessDenied,
1895 },
1896 },
1897 flags: []string{
1898 "-false-start",
1899 "-advertise-alpn", "\x03foo",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-DHE_RSA",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
Adam Langley7c803a62015-06-15 15:35:05 -07001927 protocol: dtls,
1928 name: "SendSplitAlert-Sync",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 SendSplitAlert: true,
1932 },
1933 },
1934 },
1935 {
1936 protocol: dtls,
1937 name: "SendSplitAlert-Async",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendSplitAlert: true,
1941 },
1942 },
1943 flags: []string{"-async"},
1944 },
1945 {
1946 protocol: dtls,
1947 name: "PackDTLSHandshake",
1948 config: Config{
1949 Bugs: ProtocolBugs{
1950 MaxHandshakeRecordLength: 2,
1951 PackHandshakeFragments: 20,
1952 PackHandshakeRecords: 200,
1953 },
1954 },
1955 },
1956 {
Adam Langley7c803a62015-06-15 15:35:05 -07001957 name: "SendEmptyRecords-Pass",
1958 sendEmptyRecords: 32,
1959 },
1960 {
1961 name: "SendEmptyRecords",
1962 sendEmptyRecords: 33,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1965 },
1966 {
1967 name: "SendEmptyRecords-Async",
1968 sendEmptyRecords: 33,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Pass",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 4,
1979 },
1980 {
David Benjamine8e84b92016-08-03 15:39:47 -04001981 protocol: dtls,
1982 name: "SendWarningAlerts-DTLS-Pass",
1983 config: Config{
1984 MaxVersion: VersionTLS12,
1985 },
Adam Langley7c803a62015-06-15 15:35:05 -07001986 sendWarningAlerts: 4,
1987 },
1988 {
David Benjamine8e84b92016-08-03 15:39:47 -04001989 name: "SendWarningAlerts-TLS13",
1990 config: Config{
1991 MaxVersion: VersionTLS13,
1992 },
1993 sendWarningAlerts: 4,
1994 shouldFail: true,
1995 expectedError: ":BAD_ALERT:",
1996 expectedLocalError: "remote error: error decoding message",
1997 },
1998 {
1999 name: "SendWarningAlerts",
2000 config: Config{
2001 MaxVersion: VersionTLS12,
2002 },
Adam Langley7c803a62015-06-15 15:35:05 -07002003 sendWarningAlerts: 5,
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2006 },
2007 {
David Benjamine8e84b92016-08-03 15:39:47 -04002008 name: "SendWarningAlerts-Async",
2009 config: Config{
2010 MaxVersion: VersionTLS12,
2011 },
Adam Langley7c803a62015-06-15 15:35:05 -07002012 sendWarningAlerts: 5,
2013 flags: []string{"-async"},
2014 shouldFail: true,
2015 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2016 },
David Benjaminba4594a2015-06-18 18:36:15 -04002017 {
Steven Valdez32635b82016-08-16 11:25:03 -04002018 name: "SendKeyUpdates",
2019 config: Config{
2020 MaxVersion: VersionTLS13,
2021 },
2022 sendKeyUpdates: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_KEY_UPDATES:",
2025 },
2026 {
David Benjaminba4594a2015-06-18 18:36:15 -04002027 name: "EmptySessionID",
2028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002029 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002030 SessionTicketsDisabled: true,
2031 },
2032 noSessionCache: true,
2033 flags: []string{"-expect-no-session"},
2034 },
David Benjamin30789da2015-08-29 22:56:45 -04002035 {
2036 name: "Unclean-Shutdown",
2037 config: Config{
2038 Bugs: ProtocolBugs{
2039 NoCloseNotify: true,
2040 ExpectCloseNotify: true,
2041 },
2042 },
2043 shimShutsDown: true,
2044 flags: []string{"-check-close-notify"},
2045 shouldFail: true,
2046 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2047 },
2048 {
2049 name: "Unclean-Shutdown-Ignored",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 NoCloseNotify: true,
2053 },
2054 },
2055 shimShutsDown: true,
2056 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002057 {
David Benjaminfa214e42016-05-10 17:03:10 -04002058 name: "Unclean-Shutdown-Alert",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 SendAlertOnShutdown: alertDecompressionFailure,
2062 ExpectCloseNotify: true,
2063 },
2064 },
2065 shimShutsDown: true,
2066 flags: []string{"-check-close-notify"},
2067 shouldFail: true,
2068 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2069 },
2070 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002071 name: "LargePlaintext",
2072 config: Config{
2073 Bugs: ProtocolBugs{
2074 SendLargeRecords: true,
2075 },
2076 },
2077 messageLen: maxPlaintext + 1,
2078 shouldFail: true,
2079 expectedError: ":DATA_LENGTH_TOO_LONG:",
2080 },
2081 {
2082 protocol: dtls,
2083 name: "LargePlaintext-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SendLargeRecords: true,
2087 },
2088 },
2089 messageLen: maxPlaintext + 1,
2090 shouldFail: true,
2091 expectedError: ":DATA_LENGTH_TOO_LONG:",
2092 },
2093 {
2094 name: "LargeCiphertext",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendLargeRecords: true,
2098 },
2099 },
2100 messageLen: maxPlaintext * 2,
2101 shouldFail: true,
2102 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2103 },
2104 {
2105 protocol: dtls,
2106 name: "LargeCiphertext-DTLS",
2107 config: Config{
2108 Bugs: ProtocolBugs{
2109 SendLargeRecords: true,
2110 },
2111 },
2112 messageLen: maxPlaintext * 2,
2113 // Unlike the other four cases, DTLS drops records which
2114 // are invalid before authentication, so the connection
2115 // does not fail.
2116 expectMessageDropped: true,
2117 },
David Benjamindd6fed92015-10-23 17:41:12 -04002118 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 // In TLS 1.2 and below, empty NewSessionTicket messages
2120 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002121 name: "SendEmptySessionTicket",
2122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002124 Bugs: ProtocolBugs{
2125 SendEmptySessionTicket: true,
2126 FailIfSessionOffered: true,
2127 },
2128 },
David Benjamin46662482016-08-17 00:51:00 -04002129 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002130 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002131 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 name: "BadHelloRequest-1",
2133 renegotiate: 1,
2134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002135 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002136 Bugs: ProtocolBugs{
2137 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2138 },
2139 },
2140 flags: []string{
2141 "-renegotiate-freely",
2142 "-expect-total-renegotiations", "1",
2143 },
2144 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002145 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002146 },
2147 {
2148 name: "BadHelloRequest-2",
2149 renegotiate: 1,
2150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002151 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002152 Bugs: ProtocolBugs{
2153 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2154 },
2155 },
2156 flags: []string{
2157 "-renegotiate-freely",
2158 "-expect-total-renegotiations", "1",
2159 },
2160 shouldFail: true,
2161 expectedError: ":BAD_HELLO_REQUEST:",
2162 },
David Benjaminef1b0092015-11-21 14:05:44 -05002163 {
2164 testType: serverTest,
2165 name: "SupportTicketsWithSessionID",
2166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002167 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002168 SessionTicketsDisabled: true,
2169 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 resumeConfig: &Config{
2171 MaxVersion: VersionTLS12,
2172 },
David Benjaminef1b0092015-11-21 14:05:44 -05002173 resumeSession: true,
2174 },
David Benjamin02edcd02016-07-27 17:40:37 -04002175 {
2176 protocol: dtls,
2177 name: "DTLS-SendExtraFinished",
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 SendExtraFinished: true,
2181 },
2182 },
2183 shouldFail: true,
2184 expectedError: ":UNEXPECTED_RECORD:",
2185 },
2186 {
2187 protocol: dtls,
2188 name: "DTLS-SendExtraFinished-Reordered",
2189 config: Config{
2190 Bugs: ProtocolBugs{
2191 MaxHandshakeRecordLength: 2,
2192 ReorderHandshakeFragments: true,
2193 SendExtraFinished: true,
2194 },
2195 },
2196 shouldFail: true,
2197 expectedError: ":UNEXPECTED_RECORD:",
2198 },
David Benjamine97fb482016-07-29 09:23:07 -04002199 {
2200 testType: serverTest,
2201 name: "V2ClientHello-EmptyRecordPrefix",
2202 config: Config{
2203 // Choose a cipher suite that does not involve
2204 // elliptic curves, so no extensions are
2205 // involved.
2206 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002207 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002208 Bugs: ProtocolBugs{
2209 SendV2ClientHello: true,
2210 },
2211 },
2212 sendPrefix: string([]byte{
2213 byte(recordTypeHandshake),
2214 3, 1, // version
2215 0, 0, // length
2216 }),
2217 // A no-op empty record may not be sent before V2ClientHello.
2218 shouldFail: true,
2219 expectedError: ":WRONG_VERSION_NUMBER:",
2220 },
2221 {
2222 testType: serverTest,
2223 name: "V2ClientHello-WarningAlertPrefix",
2224 config: Config{
2225 // Choose a cipher suite that does not involve
2226 // elliptic curves, so no extensions are
2227 // involved.
2228 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002229 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002230 Bugs: ProtocolBugs{
2231 SendV2ClientHello: true,
2232 },
2233 },
2234 sendPrefix: string([]byte{
2235 byte(recordTypeAlert),
2236 3, 1, // version
2237 0, 2, // length
2238 alertLevelWarning, byte(alertDecompressionFailure),
2239 }),
2240 // A no-op warning alert may not be sent before V2ClientHello.
2241 shouldFail: true,
2242 expectedError: ":WRONG_VERSION_NUMBER:",
2243 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002244 {
2245 testType: clientTest,
2246 name: "KeyUpdate",
2247 config: Config{
2248 MaxVersion: VersionTLS13,
2249 Bugs: ProtocolBugs{
2250 SendKeyUpdateBeforeEveryAppDataRecord: true,
2251 },
2252 },
2253 },
David Benjaminabe94e32016-09-04 14:18:58 -04002254 {
2255 name: "SendSNIWarningAlert",
2256 config: Config{
2257 MaxVersion: VersionTLS12,
2258 Bugs: ProtocolBugs{
2259 SendSNIWarningAlert: true,
2260 },
2261 },
2262 },
David Benjaminc241d792016-09-09 10:34:20 -04002263 {
2264 testType: serverTest,
2265 name: "ExtraCompressionMethods-TLS12",
2266 config: Config{
2267 MaxVersion: VersionTLS12,
2268 Bugs: ProtocolBugs{
2269 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2270 },
2271 },
2272 },
2273 {
2274 testType: serverTest,
2275 name: "ExtraCompressionMethods-TLS13",
2276 config: Config{
2277 MaxVersion: VersionTLS13,
2278 Bugs: ProtocolBugs{
2279 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2280 },
2281 },
2282 shouldFail: true,
2283 expectedError: ":INVALID_COMPRESSION_LIST:",
2284 expectedLocalError: "remote error: illegal parameter",
2285 },
2286 {
2287 testType: serverTest,
2288 name: "NoNullCompression-TLS12",
2289 config: Config{
2290 MaxVersion: VersionTLS12,
2291 Bugs: ProtocolBugs{
2292 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2293 },
2294 },
2295 shouldFail: true,
2296 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2297 expectedLocalError: "remote error: illegal parameter",
2298 },
2299 {
2300 testType: serverTest,
2301 name: "NoNullCompression-TLS13",
2302 config: Config{
2303 MaxVersion: VersionTLS13,
2304 Bugs: ProtocolBugs{
2305 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2306 },
2307 },
2308 shouldFail: true,
2309 expectedError: ":INVALID_COMPRESSION_LIST:",
2310 expectedLocalError: "remote error: illegal parameter",
2311 },
David Benjamin65ac9972016-09-02 21:35:25 -04002312 {
2313 name: "GREASE-TLS12",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 ExpectGREASE: true,
2318 },
2319 },
2320 flags: []string{"-enable-grease"},
2321 },
2322 {
2323 name: "GREASE-TLS13",
2324 config: Config{
2325 MaxVersion: VersionTLS13,
2326 Bugs: ProtocolBugs{
2327 ExpectGREASE: true,
2328 },
2329 },
2330 flags: []string{"-enable-grease"},
2331 },
Adam Langley7c803a62015-06-15 15:35:05 -07002332 }
Adam Langley7c803a62015-06-15 15:35:05 -07002333 testCases = append(testCases, basicTests...)
2334}
2335
Adam Langley95c29f32014-06-20 12:00:00 -07002336func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002337 const bogusCipher = 0xfe00
2338
Adam Langley95c29f32014-06-20 12:00:00 -07002339 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002340 const psk = "12345"
2341 const pskIdentity = "luggage combo"
2342
Adam Langley95c29f32014-06-20 12:00:00 -07002343 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002344 var certFile string
2345 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002346 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002347 cert = ecdsaP256Certificate
2348 certFile = ecdsaP256CertificateFile
2349 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002350 } else {
David Benjamin33863262016-07-08 17:20:12 -07002351 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002352 certFile = rsaCertificateFile
2353 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002354 }
2355
David Benjamin48cae082014-10-27 01:06:24 -04002356 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002357 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002358 flags = append(flags,
2359 "-psk", psk,
2360 "-psk-identity", pskIdentity)
2361 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002362 if hasComponent(suite.name, "NULL") {
2363 // NULL ciphers must be explicitly enabled.
2364 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2365 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002366 if hasComponent(suite.name, "CECPQ1") {
2367 // CECPQ1 ciphers must be explicitly enabled.
2368 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2369 }
David Benjamin881f1962016-08-10 18:29:12 -04002370 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2371 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2372 // for now.
2373 flags = append(flags, "-cipher", suite.name)
2374 }
David Benjamin48cae082014-10-27 01:06:24 -04002375
Adam Langley95c29f32014-06-20 12:00:00 -07002376 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002377 for _, protocol := range []protocol{tls, dtls} {
2378 var prefix string
2379 if protocol == dtls {
2380 if !ver.hasDTLS {
2381 continue
2382 }
2383 prefix = "D"
2384 }
Adam Langley95c29f32014-06-20 12:00:00 -07002385
David Benjamin0407e762016-06-17 16:41:18 -04002386 var shouldServerFail, shouldClientFail bool
2387 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2388 // BoringSSL clients accept ECDHE on SSLv3, but
2389 // a BoringSSL server will never select it
2390 // because the extension is missing.
2391 shouldServerFail = true
2392 }
2393 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2394 shouldClientFail = true
2395 shouldServerFail = true
2396 }
David Benjamin54c217c2016-07-13 12:35:25 -04002397 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002398 shouldClientFail = true
2399 shouldServerFail = true
2400 }
David Benjamin0407e762016-06-17 16:41:18 -04002401 if !isDTLSCipher(suite.name) && protocol == dtls {
2402 shouldClientFail = true
2403 shouldServerFail = true
2404 }
David Benjamin4298d772015-12-19 00:18:25 -05002405
David Benjamin0407e762016-06-17 16:41:18 -04002406 var expectedServerError, expectedClientError string
2407 if shouldServerFail {
2408 expectedServerError = ":NO_SHARED_CIPHER:"
2409 }
2410 if shouldClientFail {
2411 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2412 }
David Benjamin025b3d32014-07-01 19:53:04 -04002413
David Benjamin6fd297b2014-08-11 18:43:38 -04002414 testCases = append(testCases, testCase{
2415 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002416 protocol: protocol,
2417
2418 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002419 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002420 MinVersion: ver.version,
2421 MaxVersion: ver.version,
2422 CipherSuites: []uint16{suite.id},
2423 Certificates: []Certificate{cert},
2424 PreSharedKey: []byte(psk),
2425 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002426 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002427 EnableAllCiphers: shouldServerFail,
2428 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002429 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002430 },
2431 certFile: certFile,
2432 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002433 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002434 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002435 shouldFail: shouldServerFail,
2436 expectedError: expectedServerError,
2437 })
2438
2439 testCases = append(testCases, testCase{
2440 testType: clientTest,
2441 protocol: protocol,
2442 name: prefix + ver.name + "-" + suite.name + "-client",
2443 config: Config{
2444 MinVersion: ver.version,
2445 MaxVersion: ver.version,
2446 CipherSuites: []uint16{suite.id},
2447 Certificates: []Certificate{cert},
2448 PreSharedKey: []byte(psk),
2449 PreSharedKeyIdentity: pskIdentity,
2450 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002451 EnableAllCiphers: shouldClientFail,
2452 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002453 },
2454 },
2455 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002456 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002457 shouldFail: shouldClientFail,
2458 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002459 })
David Benjamin2c99d282015-09-01 10:23:00 -04002460
Nick Harper1fd39d82016-06-14 18:14:35 -07002461 if !shouldClientFail {
2462 // Ensure the maximum record size is accepted.
2463 testCases = append(testCases, testCase{
2464 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2465 config: Config{
2466 MinVersion: ver.version,
2467 MaxVersion: ver.version,
2468 CipherSuites: []uint16{suite.id},
2469 Certificates: []Certificate{cert},
2470 PreSharedKey: []byte(psk),
2471 PreSharedKeyIdentity: pskIdentity,
2472 },
2473 flags: flags,
2474 messageLen: maxPlaintext,
2475 })
2476 }
2477 }
David Benjamin2c99d282015-09-01 10:23:00 -04002478 }
Adam Langley95c29f32014-06-20 12:00:00 -07002479 }
Adam Langleya7997f12015-05-14 17:38:50 -07002480
2481 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 name: "NoSharedCipher",
2483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002484 MaxVersion: VersionTLS12,
2485 CipherSuites: []uint16{},
2486 },
2487 shouldFail: true,
2488 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2489 })
2490
2491 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002492 name: "NoSharedCipher-TLS13",
2493 config: Config{
2494 MaxVersion: VersionTLS13,
2495 CipherSuites: []uint16{},
2496 },
2497 shouldFail: true,
2498 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2499 })
2500
2501 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002502 name: "UnsupportedCipherSuite",
2503 config: Config{
2504 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002505 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002506 Bugs: ProtocolBugs{
2507 IgnorePeerCipherPreferences: true,
2508 },
2509 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002510 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002511 shouldFail: true,
2512 expectedError: ":WRONG_CIPHER_RETURNED:",
2513 })
2514
2515 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002516 name: "ServerHelloBogusCipher",
2517 config: Config{
2518 MaxVersion: VersionTLS12,
2519 Bugs: ProtocolBugs{
2520 SendCipherSuite: bogusCipher,
2521 },
2522 },
2523 shouldFail: true,
2524 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2525 })
2526 testCases = append(testCases, testCase{
2527 name: "ServerHelloBogusCipher-TLS13",
2528 config: Config{
2529 MaxVersion: VersionTLS13,
2530 Bugs: ProtocolBugs{
2531 SendCipherSuite: bogusCipher,
2532 },
2533 },
2534 shouldFail: true,
2535 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2536 })
2537
2538 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002539 name: "WeakDH",
2540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002541 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002542 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2543 Bugs: ProtocolBugs{
2544 // This is a 1023-bit prime number, generated
2545 // with:
2546 // openssl gendh 1023 | openssl asn1parse -i
2547 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2548 },
2549 },
2550 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002551 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002552 })
Adam Langleycef75832015-09-03 14:51:12 -07002553
David Benjamincd24a392015-11-11 13:23:05 -08002554 testCases = append(testCases, testCase{
2555 name: "SillyDH",
2556 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002557 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002558 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2559 Bugs: ProtocolBugs{
2560 // This is a 4097-bit prime number, generated
2561 // with:
2562 // openssl gendh 4097 | openssl asn1parse -i
2563 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2564 },
2565 },
2566 shouldFail: true,
2567 expectedError: ":DH_P_TOO_LONG:",
2568 })
2569
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002570 // This test ensures that Diffie-Hellman public values are padded with
2571 // zeros so that they're the same length as the prime. This is to avoid
2572 // hitting a bug in yaSSL.
2573 testCases = append(testCases, testCase{
2574 testType: serverTest,
2575 name: "DHPublicValuePadded",
2576 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002577 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002578 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2579 Bugs: ProtocolBugs{
2580 RequireDHPublicValueLen: (1025 + 7) / 8,
2581 },
2582 },
2583 flags: []string{"-use-sparse-dh-prime"},
2584 })
David Benjamincd24a392015-11-11 13:23:05 -08002585
David Benjamin241ae832016-01-15 03:04:54 -05002586 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002587 testCases = append(testCases, testCase{
2588 testType: serverTest,
2589 name: "UnknownCipher",
2590 config: Config{
2591 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2592 },
2593 })
2594
David Benjamin78679342016-09-16 19:42:05 -04002595 // Test empty ECDHE_PSK identity hints work as expected.
2596 testCases = append(testCases, testCase{
2597 name: "EmptyECDHEPSKHint",
2598 config: Config{
2599 MaxVersion: VersionTLS12,
2600 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2601 PreSharedKey: []byte("secret"),
2602 },
2603 flags: []string{"-psk", "secret"},
2604 })
2605
2606 // Test empty PSK identity hints work as expected, even if an explicit
2607 // ServerKeyExchange is sent.
2608 testCases = append(testCases, testCase{
2609 name: "ExplicitEmptyPSKHint",
2610 config: Config{
2611 MaxVersion: VersionTLS12,
2612 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2613 PreSharedKey: []byte("secret"),
2614 Bugs: ProtocolBugs{
2615 AlwaysSendPreSharedKeyIdentityHint: true,
2616 },
2617 },
2618 flags: []string{"-psk", "secret"},
2619 })
2620
Adam Langleycef75832015-09-03 14:51:12 -07002621 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2622 // 1.1 specific cipher suite settings. A server is setup with the given
2623 // cipher lists and then a connection is made for each member of
2624 // expectations. The cipher suite that the server selects must match
2625 // the specified one.
2626 var versionSpecificCiphersTest = []struct {
2627 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2628 // expectations is a map from TLS version to cipher suite id.
2629 expectations map[uint16]uint16
2630 }{
2631 {
2632 // Test that the null case (where no version-specific ciphers are set)
2633 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2635 "", // no ciphers specifically for TLS ≥ 1.0
2636 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002637 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002638 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2639 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2640 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2641 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002642 },
2643 },
2644 {
2645 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2646 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 "DES-CBC3-SHA:AES128-SHA", // default
2648 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2649 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002650 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002651 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002652 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2653 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2654 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2655 },
2656 },
2657 {
2658 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2659 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 "DES-CBC3-SHA:AES128-SHA", // default
2661 "", // no ciphers specifically for TLS ≥ 1.0
2662 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002663 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2665 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002666 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2667 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2668 },
2669 },
2670 {
2671 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2672 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002673 "DES-CBC3-SHA:AES128-SHA", // default
2674 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2675 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002676 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002678 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2679 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2680 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2681 },
2682 },
2683 }
2684
2685 for i, test := range versionSpecificCiphersTest {
2686 for version, expectedCipherSuite := range test.expectations {
2687 flags := []string{"-cipher", test.ciphersDefault}
2688 if len(test.ciphersTLS10) > 0 {
2689 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2690 }
2691 if len(test.ciphersTLS11) > 0 {
2692 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2693 }
2694
2695 testCases = append(testCases, testCase{
2696 testType: serverTest,
2697 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2698 config: Config{
2699 MaxVersion: version,
2700 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002701 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 -07002702 },
2703 flags: flags,
2704 expectedCipher: expectedCipherSuite,
2705 })
2706 }
2707 }
Adam Langley95c29f32014-06-20 12:00:00 -07002708}
2709
2710func addBadECDSASignatureTests() {
2711 for badR := BadValue(1); badR < NumBadValues; badR++ {
2712 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002713 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002714 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2715 config: Config{
2716 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002717 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002718 Bugs: ProtocolBugs{
2719 BadECDSAR: badR,
2720 BadECDSAS: badS,
2721 },
2722 },
2723 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002724 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002725 })
2726 }
2727 }
2728}
2729
Adam Langley80842bd2014-06-20 12:00:00 -07002730func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002731 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002732 name: "MaxCBCPadding",
2733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002734 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2736 Bugs: ProtocolBugs{
2737 MaxPadding: true,
2738 },
2739 },
2740 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2741 })
David Benjamin025b3d32014-07-01 19:53:04 -04002742 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002743 name: "BadCBCPadding",
2744 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002745 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2747 Bugs: ProtocolBugs{
2748 PaddingFirstByteBad: true,
2749 },
2750 },
2751 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002752 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002753 })
2754 // OpenSSL previously had an issue where the first byte of padding in
2755 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002756 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002757 name: "BadCBCPadding255",
2758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002759 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2761 Bugs: ProtocolBugs{
2762 MaxPadding: true,
2763 PaddingFirstByteBadIf255: true,
2764 },
2765 },
2766 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2767 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002768 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002769 })
2770}
2771
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772func addCBCSplittingTests() {
2773 testCases = append(testCases, testCase{
2774 name: "CBCRecordSplitting",
2775 config: Config{
2776 MaxVersion: VersionTLS10,
2777 MinVersion: VersionTLS10,
2778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2779 },
David Benjaminac8302a2015-09-01 17:18:15 -04002780 messageLen: -1, // read until EOF
2781 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002782 flags: []string{
2783 "-async",
2784 "-write-different-record-sizes",
2785 "-cbc-record-splitting",
2786 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002787 })
2788 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002789 name: "CBCRecordSplittingPartialWrite",
2790 config: Config{
2791 MaxVersion: VersionTLS10,
2792 MinVersion: VersionTLS10,
2793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2794 },
2795 messageLen: -1, // read until EOF
2796 flags: []string{
2797 "-async",
2798 "-write-different-record-sizes",
2799 "-cbc-record-splitting",
2800 "-partial-write",
2801 },
2802 })
2803}
2804
David Benjamin636293b2014-07-08 17:59:18 -04002805func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002806 // Add a dummy cert pool to stress certificate authority parsing.
2807 // TODO(davidben): Add tests that those values parse out correctly.
2808 certPool := x509.NewCertPool()
2809 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2810 if err != nil {
2811 panic(err)
2812 }
2813 certPool.AddCert(cert)
2814
David Benjamin636293b2014-07-08 17:59:18 -04002815 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002816 testCases = append(testCases, testCase{
2817 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002818 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002819 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002820 MinVersion: ver.version,
2821 MaxVersion: ver.version,
2822 ClientAuth: RequireAnyClientCert,
2823 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002824 },
2825 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002828 },
2829 })
2830 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002831 testType: serverTest,
2832 name: ver.name + "-Server-ClientAuth-RSA",
2833 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002834 MinVersion: ver.version,
2835 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002836 Certificates: []Certificate{rsaCertificate},
2837 },
2838 flags: []string{"-require-any-client-certificate"},
2839 })
David Benjamine098ec22014-08-27 23:13:20 -04002840 if ver.version != VersionSSL30 {
2841 testCases = append(testCases, testCase{
2842 testType: serverTest,
2843 name: ver.name + "-Server-ClientAuth-ECDSA",
2844 config: Config{
2845 MinVersion: ver.version,
2846 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002847 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002848 },
2849 flags: []string{"-require-any-client-certificate"},
2850 })
2851 testCases = append(testCases, testCase{
2852 testType: clientTest,
2853 name: ver.name + "-Client-ClientAuth-ECDSA",
2854 config: Config{
2855 MinVersion: ver.version,
2856 MaxVersion: ver.version,
2857 ClientAuth: RequireAnyClientCert,
2858 ClientCAs: certPool,
2859 },
2860 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002861 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2862 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002863 },
2864 })
2865 }
Adam Langley37646832016-08-01 16:16:46 -07002866
2867 testCases = append(testCases, testCase{
2868 name: "NoClientCertificate-" + ver.name,
2869 config: Config{
2870 MinVersion: ver.version,
2871 MaxVersion: ver.version,
2872 ClientAuth: RequireAnyClientCert,
2873 },
2874 shouldFail: true,
2875 expectedLocalError: "client didn't provide a certificate",
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // Even if not configured to expect a certificate, OpenSSL will
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificateRequested-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 },
2890 // TODO(davidben): Switch this to true when TLS 1.3
2891 // supports session resumption.
2892 resumeSession: ver.version < VersionTLS13,
2893 })
2894
2895 testCases = append(testCases, testCase{
2896 // If a client certificate is not provided, OpenSSL will still
2897 // return X509_V_OK as the verify_result.
2898 testType: serverTest,
2899 name: "NoClientCertificate-Server-" + ver.name,
2900 config: Config{
2901 MinVersion: ver.version,
2902 MaxVersion: ver.version,
2903 },
2904 flags: []string{
2905 "-expect-verify-result",
2906 "-verify-peer",
2907 },
2908 // TODO(davidben): Switch this to true when TLS 1.3
2909 // supports session resumption.
2910 resumeSession: ver.version < VersionTLS13,
2911 })
2912
2913 testCases = append(testCases, testCase{
2914 testType: serverTest,
2915 name: "RequireAnyClientCertificate-" + ver.name,
2916 config: Config{
2917 MinVersion: ver.version,
2918 MaxVersion: ver.version,
2919 },
2920 flags: []string{"-require-any-client-certificate"},
2921 shouldFail: true,
2922 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2923 })
2924
2925 if ver.version != VersionSSL30 {
2926 testCases = append(testCases, testCase{
2927 testType: serverTest,
2928 name: "SkipClientCertificate-" + ver.name,
2929 config: Config{
2930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 Bugs: ProtocolBugs{
2933 SkipClientCertificate: true,
2934 },
2935 },
2936 // Setting SSL_VERIFY_PEER allows anonymous clients.
2937 flags: []string{"-verify-peer"},
2938 shouldFail: true,
2939 expectedError: ":UNEXPECTED_MESSAGE:",
2940 })
2941 }
David Benjamin636293b2014-07-08 17:59:18 -04002942 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002943
David Benjaminc032dfa2016-05-12 14:54:57 -04002944 // Client auth is only legal in certificate-based ciphers.
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-PSK",
2948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002949 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002950 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
2962 testCases = append(testCases, testCase{
2963 testType: clientTest,
2964 name: "ClientAuth-ECDHE_PSK",
2965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002966 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002967 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2968 PreSharedKey: []byte("secret"),
2969 ClientAuth: RequireAnyClientCert,
2970 },
2971 flags: []string{
2972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2974 "-psk", "secret",
2975 },
2976 shouldFail: true,
2977 expectedError: ":UNEXPECTED_MESSAGE:",
2978 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002979
2980 // Regression test for a bug where the client CA list, if explicitly
2981 // set to NULL, was mis-encoded.
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "Null-Client-CA-List",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 Certificates: []Certificate{rsaCertificate},
2988 },
2989 flags: []string{
2990 "-require-any-client-certificate",
2991 "-use-null-client-ca-list",
2992 },
2993 })
David Benjamin636293b2014-07-08 17:59:18 -04002994}
2995
Adam Langley75712922014-10-10 16:23:43 -07002996func addExtendedMasterSecretTests() {
2997 const expectEMSFlag = "-expect-extended-master-secret"
2998
2999 for _, with := range []bool{false, true} {
3000 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003001 if with {
3002 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003003 }
3004
3005 for _, isClient := range []bool{false, true} {
3006 suffix := "-Server"
3007 testType := serverTest
3008 if isClient {
3009 suffix = "-Client"
3010 testType = clientTest
3011 }
3012
3013 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003014 // In TLS 1.3, the extension is irrelevant and
3015 // always reports as enabled.
3016 var flags []string
3017 if with || ver.version >= VersionTLS13 {
3018 flags = []string{expectEMSFlag}
3019 }
3020
Adam Langley75712922014-10-10 16:23:43 -07003021 test := testCase{
3022 testType: testType,
3023 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3024 config: Config{
3025 MinVersion: ver.version,
3026 MaxVersion: ver.version,
3027 Bugs: ProtocolBugs{
3028 NoExtendedMasterSecret: !with,
3029 RequireExtendedMasterSecret: with,
3030 },
3031 },
David Benjamin48cae082014-10-27 01:06:24 -04003032 flags: flags,
3033 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003034 }
3035 if test.shouldFail {
3036 test.expectedLocalError = "extended master secret required but not supported by peer"
3037 }
3038 testCases = append(testCases, test)
3039 }
3040 }
3041 }
3042
Adam Langleyba5934b2015-06-02 10:50:35 -07003043 for _, isClient := range []bool{false, true} {
3044 for _, supportedInFirstConnection := range []bool{false, true} {
3045 for _, supportedInResumeConnection := range []bool{false, true} {
3046 boolToWord := func(b bool) string {
3047 if b {
3048 return "Yes"
3049 }
3050 return "No"
3051 }
3052 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3053 if isClient {
3054 suffix += "Client"
3055 } else {
3056 suffix += "Server"
3057 }
3058
3059 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003060 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003061 Bugs: ProtocolBugs{
3062 RequireExtendedMasterSecret: true,
3063 },
3064 }
3065
3066 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003068 Bugs: ProtocolBugs{
3069 NoExtendedMasterSecret: true,
3070 },
3071 }
3072
3073 test := testCase{
3074 name: "ExtendedMasterSecret-" + suffix,
3075 resumeSession: true,
3076 }
3077
3078 if !isClient {
3079 test.testType = serverTest
3080 }
3081
3082 if supportedInFirstConnection {
3083 test.config = supportedConfig
3084 } else {
3085 test.config = noSupportConfig
3086 }
3087
3088 if supportedInResumeConnection {
3089 test.resumeConfig = &supportedConfig
3090 } else {
3091 test.resumeConfig = &noSupportConfig
3092 }
3093
3094 switch suffix {
3095 case "YesToYes-Client", "YesToYes-Server":
3096 // When a session is resumed, it should
3097 // still be aware that its master
3098 // secret was generated via EMS and
3099 // thus it's safe to use tls-unique.
3100 test.flags = []string{expectEMSFlag}
3101 case "NoToYes-Server":
3102 // If an original connection did not
3103 // contain EMS, but a resumption
3104 // handshake does, then a server should
3105 // not resume the session.
3106 test.expectResumeRejected = true
3107 case "YesToNo-Server":
3108 // Resuming an EMS session without the
3109 // EMS extension should cause the
3110 // server to abort the connection.
3111 test.shouldFail = true
3112 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3113 case "NoToYes-Client":
3114 // A client should abort a connection
3115 // where the server resumed a non-EMS
3116 // session but echoed the EMS
3117 // extension.
3118 test.shouldFail = true
3119 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3120 case "YesToNo-Client":
3121 // A client should abort a connection
3122 // where the server didn't echo EMS
3123 // when the session used it.
3124 test.shouldFail = true
3125 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3126 }
3127
3128 testCases = append(testCases, test)
3129 }
3130 }
3131 }
David Benjamin163c9562016-08-29 23:14:17 -04003132
3133 // Switching EMS on renegotiation is forbidden.
3134 testCases = append(testCases, testCase{
3135 name: "ExtendedMasterSecret-Renego-NoEMS",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 Bugs: ProtocolBugs{
3139 NoExtendedMasterSecret: true,
3140 NoExtendedMasterSecretOnRenegotiation: true,
3141 },
3142 },
3143 renegotiate: 1,
3144 flags: []string{
3145 "-renegotiate-freely",
3146 "-expect-total-renegotiations", "1",
3147 },
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Upgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecret: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
3166
3167 testCases = append(testCases, testCase{
3168 name: "ExtendedMasterSecret-Renego-Downgrade",
3169 config: Config{
3170 MaxVersion: VersionTLS12,
3171 Bugs: ProtocolBugs{
3172 NoExtendedMasterSecretOnRenegotiation: true,
3173 },
3174 },
3175 renegotiate: 1,
3176 flags: []string{
3177 "-renegotiate-freely",
3178 "-expect-total-renegotiations", "1",
3179 },
3180 shouldFail: true,
3181 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3182 })
Adam Langley75712922014-10-10 16:23:43 -07003183}
3184
David Benjamin582ba042016-07-07 12:33:25 -07003185type stateMachineTestConfig struct {
3186 protocol protocol
3187 async bool
3188 splitHandshake, packHandshakeFlight bool
3189}
3190
David Benjamin43ec06f2014-08-05 02:28:57 -04003191// Adds tests that try to cover the range of the handshake state machine, under
3192// various conditions. Some of these are redundant with other tests, but they
3193// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003194func addAllStateMachineCoverageTests() {
3195 for _, async := range []bool{false, true} {
3196 for _, protocol := range []protocol{tls, dtls} {
3197 addStateMachineCoverageTests(stateMachineTestConfig{
3198 protocol: protocol,
3199 async: async,
3200 })
3201 addStateMachineCoverageTests(stateMachineTestConfig{
3202 protocol: protocol,
3203 async: async,
3204 splitHandshake: true,
3205 })
3206 if protocol == tls {
3207 addStateMachineCoverageTests(stateMachineTestConfig{
3208 protocol: protocol,
3209 async: async,
3210 packHandshakeFlight: true,
3211 })
3212 }
3213 }
3214 }
3215}
3216
3217func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 var tests []testCase
3219
3220 // Basic handshake, with resumption. Client and server,
3221 // session ID and session ticket.
3222 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003223 name: "Basic-Client",
3224 config: Config{
3225 MaxVersion: VersionTLS12,
3226 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003227 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003228 // Ensure session tickets are used, not session IDs.
3229 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 })
3231 tests = append(tests, testCase{
3232 name: "Basic-Client-RenewTicket",
3233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003234 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003235 Bugs: ProtocolBugs{
3236 RenewTicketOnResume: true,
3237 },
3238 },
David Benjamin46662482016-08-17 00:51:00 -04003239 flags: []string{"-expect-ticket-renewal"},
3240 resumeSession: true,
3241 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003242 })
3243 tests = append(tests, testCase{
3244 name: "Basic-Client-NoTicket",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003247 SessionTicketsDisabled: true,
3248 },
3249 resumeSession: true,
3250 })
3251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003252 name: "Basic-Client-Implicit",
3253 config: Config{
3254 MaxVersion: VersionTLS12,
3255 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003256 flags: []string{"-implicit-handshake"},
3257 resumeSession: true,
3258 })
3259 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003260 testType: serverTest,
3261 name: "Basic-Server",
3262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003264 Bugs: ProtocolBugs{
3265 RequireSessionTickets: true,
3266 },
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 resumeSession: true,
3269 })
3270 tests = append(tests, testCase{
3271 testType: serverTest,
3272 name: "Basic-Server-NoTickets",
3273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003274 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 SessionTicketsDisabled: true,
3276 },
3277 resumeSession: true,
3278 })
3279 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003280 testType: serverTest,
3281 name: "Basic-Server-Implicit",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003285 flags: []string{"-implicit-handshake"},
3286 resumeSession: true,
3287 })
3288 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003289 testType: serverTest,
3290 name: "Basic-Server-EarlyCallback",
3291 config: Config{
3292 MaxVersion: VersionTLS12,
3293 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 flags: []string{"-use-early-callback"},
3295 resumeSession: true,
3296 })
3297
Steven Valdez143e8b32016-07-11 13:19:03 -04003298 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003299 if config.protocol == tls {
3300 tests = append(tests, testCase{
3301 name: "TLS13-1RTT-Client",
3302 config: Config{
3303 MaxVersion: VersionTLS13,
3304 MinVersion: VersionTLS13,
3305 },
David Benjamin46662482016-08-17 00:51:00 -04003306 resumeSession: true,
3307 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003308 })
3309
3310 tests = append(tests, testCase{
3311 testType: serverTest,
3312 name: "TLS13-1RTT-Server",
3313 config: Config{
3314 MaxVersion: VersionTLS13,
3315 MinVersion: VersionTLS13,
3316 },
David Benjamin46662482016-08-17 00:51:00 -04003317 resumeSession: true,
3318 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003319 })
3320
3321 tests = append(tests, testCase{
3322 name: "TLS13-HelloRetryRequest-Client",
3323 config: Config{
3324 MaxVersion: VersionTLS13,
3325 MinVersion: VersionTLS13,
3326 // P-384 requires a HelloRetryRequest against
3327 // BoringSSL's default configuration. Assert
3328 // that we do indeed test this with
3329 // ExpectMissingKeyShare.
3330 CurvePreferences: []CurveID{CurveP384},
3331 Bugs: ProtocolBugs{
3332 ExpectMissingKeyShare: true,
3333 },
3334 },
3335 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3336 resumeSession: true,
3337 })
3338
3339 tests = append(tests, testCase{
3340 testType: serverTest,
3341 name: "TLS13-HelloRetryRequest-Server",
3342 config: Config{
3343 MaxVersion: VersionTLS13,
3344 MinVersion: VersionTLS13,
3345 // Require a HelloRetryRequest for every curve.
3346 DefaultCurves: []CurveID{},
3347 },
3348 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3349 resumeSession: true,
3350 })
3351 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003352
David Benjamin760b1dd2015-05-15 23:33:48 -04003353 // TLS client auth.
3354 tests = append(tests, testCase{
3355 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003356 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003358 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003359 ClientAuth: RequestClientCert,
3360 },
3361 })
3362 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003363 testType: serverTest,
3364 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003365 config: Config{
3366 MaxVersion: VersionTLS12,
3367 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003368 // Setting SSL_VERIFY_PEER allows anonymous clients.
3369 flags: []string{"-verify-peer"},
3370 })
David Benjamin582ba042016-07-07 12:33:25 -07003371 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-SSL3",
3375 config: Config{
3376 MaxVersion: VersionSSL30,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-SSL3",
3383 config: Config{
3384 MaxVersion: VersionSSL30,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003389 tests = append(tests, testCase{
3390 testType: clientTest,
3391 name: "ClientAuth-NoCertificate-Client-TLS13",
3392 config: Config{
3393 MaxVersion: VersionTLS13,
3394 ClientAuth: RequestClientCert,
3395 },
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "ClientAuth-NoCertificate-Server-TLS13",
3400 config: Config{
3401 MaxVersion: VersionTLS13,
3402 },
3403 // Setting SSL_VERIFY_PEER allows anonymous clients.
3404 flags: []string{"-verify-peer"},
3405 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003406 }
3407 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003408 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003409 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 ClientAuth: RequireAnyClientCert,
3413 },
3414 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003415 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3416 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003417 },
3418 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 tests = append(tests, testCase{
3420 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003421 name: "ClientAuth-RSA-Client-TLS13",
3422 config: Config{
3423 MaxVersion: VersionTLS13,
3424 ClientAuth: RequireAnyClientCert,
3425 },
3426 flags: []string{
3427 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3428 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3429 },
3430 })
3431 tests = append(tests, testCase{
3432 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003433 name: "ClientAuth-ECDSA-Client",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003436 ClientAuth: RequireAnyClientCert,
3437 },
3438 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003439 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3440 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003441 },
3442 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003443 tests = append(tests, testCase{
3444 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003445 name: "ClientAuth-ECDSA-Client-TLS13",
3446 config: Config{
3447 MaxVersion: VersionTLS13,
3448 ClientAuth: RequireAnyClientCert,
3449 },
3450 flags: []string{
3451 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3452 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3453 },
3454 })
3455 tests = append(tests, testCase{
3456 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003457 name: "ClientAuth-NoCertificate-OldCallback",
3458 config: Config{
3459 MaxVersion: VersionTLS12,
3460 ClientAuth: RequestClientCert,
3461 },
3462 flags: []string{"-use-old-client-cert-callback"},
3463 })
3464 tests = append(tests, testCase{
3465 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003466 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3467 config: Config{
3468 MaxVersion: VersionTLS13,
3469 ClientAuth: RequestClientCert,
3470 },
3471 flags: []string{"-use-old-client-cert-callback"},
3472 })
3473 tests = append(tests, testCase{
3474 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003475 name: "ClientAuth-OldCallback",
3476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003477 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003478 ClientAuth: RequireAnyClientCert,
3479 },
3480 flags: []string{
3481 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3482 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3483 "-use-old-client-cert-callback",
3484 },
3485 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003486 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003487 testType: clientTest,
3488 name: "ClientAuth-OldCallback-TLS13",
3489 config: Config{
3490 MaxVersion: VersionTLS13,
3491 ClientAuth: RequireAnyClientCert,
3492 },
3493 flags: []string{
3494 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3495 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3496 "-use-old-client-cert-callback",
3497 },
3498 })
3499 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003500 testType: serverTest,
3501 name: "ClientAuth-Server",
3502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003503 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 Certificates: []Certificate{rsaCertificate},
3505 },
3506 flags: []string{"-require-any-client-certificate"},
3507 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 tests = append(tests, testCase{
3509 testType: serverTest,
3510 name: "ClientAuth-Server-TLS13",
3511 config: Config{
3512 MaxVersion: VersionTLS13,
3513 Certificates: []Certificate{rsaCertificate},
3514 },
3515 flags: []string{"-require-any-client-certificate"},
3516 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003517
David Benjamin4c3ddf72016-06-29 18:13:53 -04003518 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003519 tests = append(tests, testCase{
3520 testType: serverTest,
3521 name: "Basic-Server-RSA",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3525 },
3526 flags: []string{
3527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3529 },
3530 })
3531 tests = append(tests, testCase{
3532 testType: serverTest,
3533 name: "Basic-Server-ECDHE-RSA",
3534 config: Config{
3535 MaxVersion: VersionTLS12,
3536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3537 },
3538 flags: []string{
3539 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3540 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3541 },
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "Basic-Server-ECDHE-ECDSA",
3546 config: Config{
3547 MaxVersion: VersionTLS12,
3548 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3549 },
3550 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003551 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3552 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003553 },
3554 })
3555
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 // No session ticket support; server doesn't send NewSessionTicket.
3557 tests = append(tests, testCase{
3558 name: "SessionTicketsDisabled-Client",
3559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003561 SessionTicketsDisabled: true,
3562 },
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "SessionTicketsDisabled-Server",
3567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003568 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 SessionTicketsDisabled: true,
3570 },
3571 })
3572
3573 // Skip ServerKeyExchange in PSK key exchange if there's no
3574 // identity hint.
3575 tests = append(tests, testCase{
3576 name: "EmptyPSKHint-Client",
3577 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003578 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003579 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3580 PreSharedKey: []byte("secret"),
3581 },
3582 flags: []string{"-psk", "secret"},
3583 })
3584 tests = append(tests, testCase{
3585 testType: serverTest,
3586 name: "EmptyPSKHint-Server",
3587 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003588 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3590 PreSharedKey: []byte("secret"),
3591 },
3592 flags: []string{"-psk", "secret"},
3593 })
3594
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003596 tests = append(tests, testCase{
3597 testType: clientTest,
3598 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003599 config: Config{
3600 MaxVersion: VersionTLS12,
3601 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003602 flags: []string{
3603 "-enable-ocsp-stapling",
3604 "-expect-ocsp-response",
3605 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003606 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003607 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003608 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003609 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003610 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 testType: serverTest,
3612 name: "OCSPStapling-Server",
3613 config: Config{
3614 MaxVersion: VersionTLS12,
3615 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003616 expectedOCSPResponse: testOCSPResponse,
3617 flags: []string{
3618 "-ocsp-response",
3619 base64.StdEncoding.EncodeToString(testOCSPResponse),
3620 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003621 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003622 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003623 tests = append(tests, testCase{
3624 testType: clientTest,
3625 name: "OCSPStapling-Client-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 },
3629 flags: []string{
3630 "-enable-ocsp-stapling",
3631 "-expect-ocsp-response",
3632 base64.StdEncoding.EncodeToString(testOCSPResponse),
3633 "-verify-peer",
3634 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003635 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003636 })
3637 tests = append(tests, testCase{
3638 testType: serverTest,
3639 name: "OCSPStapling-Server-TLS13",
3640 config: Config{
3641 MaxVersion: VersionTLS13,
3642 },
3643 expectedOCSPResponse: testOCSPResponse,
3644 flags: []string{
3645 "-ocsp-response",
3646 base64.StdEncoding.EncodeToString(testOCSPResponse),
3647 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003648 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003649 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003650
David Benjamin4c3ddf72016-06-29 18:13:53 -04003651 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003652 for _, vers := range tlsVersions {
3653 if config.protocol == dtls && !vers.hasDTLS {
3654 continue
3655 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003656 for _, testType := range []testType{clientTest, serverTest} {
3657 suffix := "-Client"
3658 if testType == serverTest {
3659 suffix = "-Server"
3660 }
3661 suffix += "-" + vers.name
3662
3663 flag := "-verify-peer"
3664 if testType == serverTest {
3665 flag = "-require-any-client-certificate"
3666 }
3667
3668 tests = append(tests, testCase{
3669 testType: testType,
3670 name: "CertificateVerificationSucceed" + suffix,
3671 config: Config{
3672 MaxVersion: vers.version,
3673 Certificates: []Certificate{rsaCertificate},
3674 },
3675 flags: []string{
3676 flag,
3677 "-expect-verify-result",
3678 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003679 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003680 })
3681 tests = append(tests, testCase{
3682 testType: testType,
3683 name: "CertificateVerificationFail" + suffix,
3684 config: Config{
3685 MaxVersion: vers.version,
3686 Certificates: []Certificate{rsaCertificate},
3687 },
3688 flags: []string{
3689 flag,
3690 "-verify-fail",
3691 },
3692 shouldFail: true,
3693 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3694 })
3695 }
3696
3697 // By default, the client is in a soft fail mode where the peer
3698 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003699 tests = append(tests, testCase{
3700 testType: clientTest,
3701 name: "CertificateVerificationSoftFail-" + vers.name,
3702 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003703 MaxVersion: vers.version,
3704 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003705 },
3706 flags: []string{
3707 "-verify-fail",
3708 "-expect-verify-result",
3709 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003710 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003711 })
3712 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003713
David Benjamin1d4f4c02016-07-26 18:03:08 -04003714 tests = append(tests, testCase{
3715 name: "ShimSendAlert",
3716 flags: []string{"-send-alert"},
3717 shimWritesFirst: true,
3718 shouldFail: true,
3719 expectedLocalError: "remote error: decompression failure",
3720 })
3721
David Benjamin582ba042016-07-07 12:33:25 -07003722 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 name: "Renegotiate-Client",
3725 config: Config{
3726 MaxVersion: VersionTLS12,
3727 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003728 renegotiate: 1,
3729 flags: []string{
3730 "-renegotiate-freely",
3731 "-expect-total-renegotiations", "1",
3732 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003734
David Benjamin47921102016-07-28 11:29:18 -04003735 tests = append(tests, testCase{
3736 name: "SendHalfHelloRequest",
3737 config: Config{
3738 MaxVersion: VersionTLS12,
3739 Bugs: ProtocolBugs{
3740 PackHelloRequestWithFinished: config.packHandshakeFlight,
3741 },
3742 },
3743 sendHalfHelloRequest: true,
3744 flags: []string{"-renegotiate-ignore"},
3745 shouldFail: true,
3746 expectedError: ":UNEXPECTED_RECORD:",
3747 })
3748
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 // NPN on client and server; results in post-handshake message.
3750 tests = append(tests, testCase{
3751 name: "NPN-Client",
3752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003754 NextProtos: []string{"foo"},
3755 },
3756 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003757 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003758 expectedNextProto: "foo",
3759 expectedNextProtoType: npn,
3760 })
3761 tests = append(tests, testCase{
3762 testType: serverTest,
3763 name: "NPN-Server",
3764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 NextProtos: []string{"bar"},
3767 },
3768 flags: []string{
3769 "-advertise-npn", "\x03foo\x03bar\x03baz",
3770 "-expect-next-proto", "bar",
3771 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003772 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003773 expectedNextProto: "bar",
3774 expectedNextProtoType: npn,
3775 })
3776
3777 // TODO(davidben): Add tests for when False Start doesn't trigger.
3778
3779 // Client does False Start and negotiates NPN.
3780 tests = append(tests, testCase{
3781 name: "FalseStart",
3782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003783 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3785 NextProtos: []string{"foo"},
3786 Bugs: ProtocolBugs{
3787 ExpectFalseStart: true,
3788 },
3789 },
3790 flags: []string{
3791 "-false-start",
3792 "-select-next-proto", "foo",
3793 },
3794 shimWritesFirst: true,
3795 resumeSession: true,
3796 })
3797
3798 // Client does False Start and negotiates ALPN.
3799 tests = append(tests, testCase{
3800 name: "FalseStart-ALPN",
3801 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003802 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3804 NextProtos: []string{"foo"},
3805 Bugs: ProtocolBugs{
3806 ExpectFalseStart: true,
3807 },
3808 },
3809 flags: []string{
3810 "-false-start",
3811 "-advertise-alpn", "\x03foo",
3812 },
3813 shimWritesFirst: true,
3814 resumeSession: true,
3815 })
3816
3817 // Client does False Start but doesn't explicitly call
3818 // SSL_connect.
3819 tests = append(tests, testCase{
3820 name: "FalseStart-Implicit",
3821 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003822 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3824 NextProtos: []string{"foo"},
3825 },
3826 flags: []string{
3827 "-implicit-handshake",
3828 "-false-start",
3829 "-advertise-alpn", "\x03foo",
3830 },
3831 })
3832
3833 // False Start without session tickets.
3834 tests = append(tests, testCase{
3835 name: "FalseStart-SessionTicketsDisabled",
3836 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003837 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3839 NextProtos: []string{"foo"},
3840 SessionTicketsDisabled: true,
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-select-next-proto", "foo",
3848 },
3849 shimWritesFirst: true,
3850 })
3851
Adam Langleydf759b52016-07-11 15:24:37 -07003852 tests = append(tests, testCase{
3853 name: "FalseStart-CECPQ1",
3854 config: Config{
3855 MaxVersion: VersionTLS12,
3856 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3857 NextProtos: []string{"foo"},
3858 Bugs: ProtocolBugs{
3859 ExpectFalseStart: true,
3860 },
3861 },
3862 flags: []string{
3863 "-false-start",
3864 "-cipher", "DEFAULT:kCECPQ1",
3865 "-select-next-proto", "foo",
3866 },
3867 shimWritesFirst: true,
3868 resumeSession: true,
3869 })
3870
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 // Server parses a V2ClientHello.
3872 tests = append(tests, testCase{
3873 testType: serverTest,
3874 name: "SendV2ClientHello",
3875 config: Config{
3876 // Choose a cipher suite that does not involve
3877 // elliptic curves, so no extensions are
3878 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003879 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003880 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 Bugs: ProtocolBugs{
3882 SendV2ClientHello: true,
3883 },
3884 },
3885 })
3886
3887 // Client sends a Channel ID.
3888 tests = append(tests, testCase{
3889 name: "ChannelID-Client",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 RequestChannelID: true,
3893 },
Adam Langley7c803a62015-06-15 15:35:05 -07003894 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 resumeSession: true,
3896 expectChannelID: true,
3897 })
3898
3899 // Server accepts a Channel ID.
3900 tests = append(tests, testCase{
3901 testType: serverTest,
3902 name: "ChannelID-Server",
3903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904 MaxVersion: VersionTLS12,
3905 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003906 },
3907 flags: []string{
3908 "-expect-channel-id",
3909 base64.StdEncoding.EncodeToString(channelIDBytes),
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 })
David Benjamin30789da2015-08-29 22:56:45 -04003914
David Benjaminf8fcdf32016-06-08 15:56:13 -04003915 // Channel ID and NPN at the same time, to ensure their relative
3916 // ordering is correct.
3917 tests = append(tests, testCase{
3918 name: "ChannelID-NPN-Client",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 RequestChannelID: true,
3922 NextProtos: []string{"foo"},
3923 },
3924 flags: []string{
3925 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3926 "-select-next-proto", "foo",
3927 },
3928 resumeSession: true,
3929 expectChannelID: true,
3930 expectedNextProto: "foo",
3931 expectedNextProtoType: npn,
3932 })
3933 tests = append(tests, testCase{
3934 testType: serverTest,
3935 name: "ChannelID-NPN-Server",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003938 ChannelID: channelIDKey,
3939 NextProtos: []string{"bar"},
3940 },
3941 flags: []string{
3942 "-expect-channel-id",
3943 base64.StdEncoding.EncodeToString(channelIDBytes),
3944 "-advertise-npn", "\x03foo\x03bar\x03baz",
3945 "-expect-next-proto", "bar",
3946 },
3947 resumeSession: true,
3948 expectChannelID: true,
3949 expectedNextProto: "bar",
3950 expectedNextProtoType: npn,
3951 })
3952
David Benjamin30789da2015-08-29 22:56:45 -04003953 // Bidirectional shutdown with the runner initiating.
3954 tests = append(tests, testCase{
3955 name: "Shutdown-Runner",
3956 config: Config{
3957 Bugs: ProtocolBugs{
3958 ExpectCloseNotify: true,
3959 },
3960 },
3961 flags: []string{"-check-close-notify"},
3962 })
3963
3964 // Bidirectional shutdown with the shim initiating. The runner,
3965 // in the meantime, sends garbage before the close_notify which
3966 // the shim must ignore.
3967 tests = append(tests, testCase{
3968 name: "Shutdown-Shim",
3969 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003970 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003971 Bugs: ProtocolBugs{
3972 ExpectCloseNotify: true,
3973 },
3974 },
3975 shimShutsDown: true,
3976 sendEmptyRecords: 1,
3977 sendWarningAlerts: 1,
3978 flags: []string{"-check-close-notify"},
3979 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003980 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003981 // TODO(davidben): DTLS 1.3 will want a similar thing for
3982 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 tests = append(tests, testCase{
3984 name: "SkipHelloVerifyRequest",
3985 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003986 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003987 Bugs: ProtocolBugs{
3988 SkipHelloVerifyRequest: true,
3989 },
3990 },
3991 })
3992 }
3993
David Benjamin760b1dd2015-05-15 23:33:48 -04003994 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003995 test.protocol = config.protocol
3996 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003997 test.name += "-DTLS"
3998 }
David Benjamin582ba042016-07-07 12:33:25 -07003999 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004000 test.name += "-Async"
4001 test.flags = append(test.flags, "-async")
4002 } else {
4003 test.name += "-Sync"
4004 }
David Benjamin582ba042016-07-07 12:33:25 -07004005 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004006 test.name += "-SplitHandshakeRecords"
4007 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004009 test.config.Bugs.MaxPacketLength = 256
4010 test.flags = append(test.flags, "-mtu", "256")
4011 }
4012 }
David Benjamin582ba042016-07-07 12:33:25 -07004013 if config.packHandshakeFlight {
4014 test.name += "-PackHandshakeFlight"
4015 test.config.Bugs.PackHandshakeFlight = true
4016 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004018 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004019}
4020
Adam Langley524e7172015-02-20 16:04:00 -08004021func addDDoSCallbackTests() {
4022 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004023 for _, resume := range []bool{false, true} {
4024 suffix := "Resume"
4025 if resume {
4026 suffix = "No" + suffix
4027 }
4028
4029 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 testType: serverTest,
4031 name: "Server-DDoS-OK-" + suffix,
4032 config: Config{
4033 MaxVersion: VersionTLS12,
4034 },
Adam Langley524e7172015-02-20 16:04:00 -08004035 flags: []string{"-install-ddos-callback"},
4036 resumeSession: resume,
4037 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004038 testCases = append(testCases, testCase{
4039 testType: serverTest,
4040 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4041 config: Config{
4042 MaxVersion: VersionTLS13,
4043 },
4044 flags: []string{"-install-ddos-callback"},
4045 resumeSession: resume,
4046 })
Adam Langley524e7172015-02-20 16:04:00 -08004047
4048 failFlag := "-fail-ddos-callback"
4049 if resume {
4050 failFlag = "-fail-second-ddos-callback"
4051 }
4052 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004053 testType: serverTest,
4054 name: "Server-DDoS-Reject-" + suffix,
4055 config: Config{
4056 MaxVersion: VersionTLS12,
4057 },
David Benjamin2c66e072016-09-16 15:58:00 -04004058 flags: []string{"-install-ddos-callback", failFlag},
4059 resumeSession: resume,
4060 shouldFail: true,
4061 expectedError: ":CONNECTION_REJECTED:",
4062 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004063 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004064 testCases = append(testCases, testCase{
4065 testType: serverTest,
4066 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4067 config: Config{
4068 MaxVersion: VersionTLS13,
4069 },
David Benjamin2c66e072016-09-16 15:58:00 -04004070 flags: []string{"-install-ddos-callback", failFlag},
4071 resumeSession: resume,
4072 shouldFail: true,
4073 expectedError: ":CONNECTION_REJECTED:",
4074 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004075 })
Adam Langley524e7172015-02-20 16:04:00 -08004076 }
4077}
4078
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004079func addVersionNegotiationTests() {
4080 for i, shimVers := range tlsVersions {
4081 // Assemble flags to disable all newer versions on the shim.
4082 var flags []string
4083 for _, vers := range tlsVersions[i+1:] {
4084 flags = append(flags, vers.flag)
4085 }
4086
4087 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004088 protocols := []protocol{tls}
4089 if runnerVers.hasDTLS && shimVers.hasDTLS {
4090 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004091 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004092 for _, protocol := range protocols {
4093 expectedVersion := shimVers.version
4094 if runnerVers.version < shimVers.version {
4095 expectedVersion = runnerVers.version
4096 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004097
David Benjamin8b8c0062014-11-23 02:47:52 -05004098 suffix := shimVers.name + "-" + runnerVers.name
4099 if protocol == dtls {
4100 suffix += "-DTLS"
4101 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004102
David Benjamin1eb367c2014-12-12 18:17:51 -05004103 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4104
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004105 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004106 clientVers := shimVers.version
4107 if clientVers > VersionTLS10 {
4108 clientVers = VersionTLS10
4109 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004110 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004111 serverVers := expectedVersion
4112 if expectedVersion >= VersionTLS13 {
4113 serverVers = VersionTLS10
4114 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004115 serverVers = versionToWire(serverVers, protocol == dtls)
4116
David Benjamin8b8c0062014-11-23 02:47:52 -05004117 testCases = append(testCases, testCase{
4118 protocol: protocol,
4119 testType: clientTest,
4120 name: "VersionNegotiation-Client-" + suffix,
4121 config: Config{
4122 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004123 Bugs: ProtocolBugs{
4124 ExpectInitialRecordVersion: clientVers,
4125 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004126 },
4127 flags: flags,
4128 expectedVersion: expectedVersion,
4129 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004130 testCases = append(testCases, testCase{
4131 protocol: protocol,
4132 testType: clientTest,
4133 name: "VersionNegotiation-Client2-" + suffix,
4134 config: Config{
4135 MaxVersion: runnerVers.version,
4136 Bugs: ProtocolBugs{
4137 ExpectInitialRecordVersion: clientVers,
4138 },
4139 },
4140 flags: []string{"-max-version", shimVersFlag},
4141 expectedVersion: expectedVersion,
4142 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004143
4144 testCases = append(testCases, testCase{
4145 protocol: protocol,
4146 testType: serverTest,
4147 name: "VersionNegotiation-Server-" + suffix,
4148 config: Config{
4149 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004150 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004151 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004152 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004153 },
4154 flags: flags,
4155 expectedVersion: expectedVersion,
4156 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004157 testCases = append(testCases, testCase{
4158 protocol: protocol,
4159 testType: serverTest,
4160 name: "VersionNegotiation-Server2-" + suffix,
4161 config: Config{
4162 MaxVersion: runnerVers.version,
4163 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004164 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004165 },
4166 },
4167 flags: []string{"-max-version", shimVersFlag},
4168 expectedVersion: expectedVersion,
4169 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004170 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004171 }
4172 }
David Benjamin95c69562016-06-29 18:15:03 -04004173
4174 // Test for version tolerance.
4175 testCases = append(testCases, testCase{
4176 testType: serverTest,
4177 name: "MinorVersionTolerance",
4178 config: Config{
4179 Bugs: ProtocolBugs{
4180 SendClientVersion: 0x03ff,
4181 },
4182 },
4183 expectedVersion: VersionTLS13,
4184 })
4185 testCases = append(testCases, testCase{
4186 testType: serverTest,
4187 name: "MajorVersionTolerance",
4188 config: Config{
4189 Bugs: ProtocolBugs{
4190 SendClientVersion: 0x0400,
4191 },
4192 },
4193 expectedVersion: VersionTLS13,
4194 })
4195 testCases = append(testCases, testCase{
4196 protocol: dtls,
4197 testType: serverTest,
4198 name: "MinorVersionTolerance-DTLS",
4199 config: Config{
4200 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004201 SendClientVersion: 0xfe00,
David Benjamin95c69562016-06-29 18:15:03 -04004202 },
4203 },
4204 expectedVersion: VersionTLS12,
4205 })
4206 testCases = append(testCases, testCase{
4207 protocol: dtls,
4208 testType: serverTest,
4209 name: "MajorVersionTolerance-DTLS",
4210 config: Config{
4211 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004212 SendClientVersion: 0xfdff,
David Benjamin95c69562016-06-29 18:15:03 -04004213 },
4214 },
4215 expectedVersion: VersionTLS12,
4216 })
4217
4218 // Test that versions below 3.0 are rejected.
4219 testCases = append(testCases, testCase{
4220 testType: serverTest,
4221 name: "VersionTooLow",
4222 config: Config{
4223 Bugs: ProtocolBugs{
4224 SendClientVersion: 0x0200,
4225 },
4226 },
4227 shouldFail: true,
4228 expectedError: ":UNSUPPORTED_PROTOCOL:",
4229 })
4230 testCases = append(testCases, testCase{
4231 protocol: dtls,
4232 testType: serverTest,
4233 name: "VersionTooLow-DTLS",
4234 config: Config{
4235 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004236 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004237 },
4238 },
4239 shouldFail: true,
4240 expectedError: ":UNSUPPORTED_PROTOCOL:",
4241 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004242
David Benjamin2dc02042016-09-19 19:57:37 -04004243 testCases = append(testCases, testCase{
4244 name: "ServerBogusVersion",
4245 config: Config{
4246 Bugs: ProtocolBugs{
4247 SendServerHelloVersion: 0x1234,
4248 },
4249 },
4250 shouldFail: true,
4251 expectedError: ":UNSUPPORTED_PROTOCOL:",
4252 })
4253
David Benjamin1f61f0d2016-07-10 12:20:35 -04004254 // Test TLS 1.3's downgrade signal.
4255 testCases = append(testCases, testCase{
4256 name: "Downgrade-TLS12-Client",
4257 config: Config{
4258 Bugs: ProtocolBugs{
4259 NegotiateVersion: VersionTLS12,
4260 },
4261 },
David Benjamin55108632016-08-11 22:01:18 -04004262 // TODO(davidben): This test should fail once TLS 1.3 is final
4263 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004264 })
4265 testCases = append(testCases, testCase{
4266 testType: serverTest,
4267 name: "Downgrade-TLS12-Server",
4268 config: Config{
4269 Bugs: ProtocolBugs{
4270 SendClientVersion: VersionTLS12,
4271 },
4272 },
David Benjamin55108632016-08-11 22:01:18 -04004273 // TODO(davidben): This test should fail once TLS 1.3 is final
4274 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004275 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004276}
4277
David Benjaminaccb4542014-12-12 23:44:33 -05004278func addMinimumVersionTests() {
4279 for i, shimVers := range tlsVersions {
4280 // Assemble flags to disable all older versions on the shim.
4281 var flags []string
4282 for _, vers := range tlsVersions[:i] {
4283 flags = append(flags, vers.flag)
4284 }
4285
4286 for _, runnerVers := range tlsVersions {
4287 protocols := []protocol{tls}
4288 if runnerVers.hasDTLS && shimVers.hasDTLS {
4289 protocols = append(protocols, dtls)
4290 }
4291 for _, protocol := range protocols {
4292 suffix := shimVers.name + "-" + runnerVers.name
4293 if protocol == dtls {
4294 suffix += "-DTLS"
4295 }
4296 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4297
David Benjaminaccb4542014-12-12 23:44:33 -05004298 var expectedVersion uint16
4299 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004300 var expectedClientError, expectedServerError string
4301 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004302 if runnerVers.version >= shimVers.version {
4303 expectedVersion = runnerVers.version
4304 } else {
4305 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004306 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4307 expectedServerLocalError = "remote error: protocol version not supported"
4308 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4309 // If the client's minimum version is TLS 1.3 and the runner's
4310 // maximum is below TLS 1.2, the runner will fail to select a
4311 // cipher before the shim rejects the selected version.
4312 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4313 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4314 } else {
4315 expectedClientError = expectedServerError
4316 expectedClientLocalError = expectedServerLocalError
4317 }
David Benjaminaccb4542014-12-12 23:44:33 -05004318 }
4319
4320 testCases = append(testCases, testCase{
4321 protocol: protocol,
4322 testType: clientTest,
4323 name: "MinimumVersion-Client-" + suffix,
4324 config: Config{
4325 MaxVersion: runnerVers.version,
4326 },
David Benjamin87909c02014-12-13 01:55:01 -05004327 flags: flags,
4328 expectedVersion: expectedVersion,
4329 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004330 expectedError: expectedClientError,
4331 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004332 })
4333 testCases = append(testCases, testCase{
4334 protocol: protocol,
4335 testType: clientTest,
4336 name: "MinimumVersion-Client2-" + suffix,
4337 config: Config{
4338 MaxVersion: runnerVers.version,
4339 },
David Benjamin87909c02014-12-13 01:55:01 -05004340 flags: []string{"-min-version", shimVersFlag},
4341 expectedVersion: expectedVersion,
4342 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004343 expectedError: expectedClientError,
4344 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004345 })
4346
4347 testCases = append(testCases, testCase{
4348 protocol: protocol,
4349 testType: serverTest,
4350 name: "MinimumVersion-Server-" + suffix,
4351 config: Config{
4352 MaxVersion: runnerVers.version,
4353 },
David Benjamin87909c02014-12-13 01:55:01 -05004354 flags: flags,
4355 expectedVersion: expectedVersion,
4356 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004357 expectedError: expectedServerError,
4358 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004359 })
4360 testCases = append(testCases, testCase{
4361 protocol: protocol,
4362 testType: serverTest,
4363 name: "MinimumVersion-Server2-" + suffix,
4364 config: Config{
4365 MaxVersion: runnerVers.version,
4366 },
David Benjamin87909c02014-12-13 01:55:01 -05004367 flags: []string{"-min-version", shimVersFlag},
4368 expectedVersion: expectedVersion,
4369 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004370 expectedError: expectedServerError,
4371 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004372 })
4373 }
4374 }
4375 }
4376}
4377
David Benjamine78bfde2014-09-06 12:45:15 -04004378func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004379 // TODO(davidben): Extensions, where applicable, all move their server
4380 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4381 // tests for both. Also test interaction with 0-RTT when implemented.
4382
David Benjamin97d17d92016-07-14 16:12:00 -04004383 // Repeat extensions tests all versions except SSL 3.0.
4384 for _, ver := range tlsVersions {
4385 if ver.version == VersionSSL30 {
4386 continue
4387 }
4388
David Benjamin97d17d92016-07-14 16:12:00 -04004389 // Test that duplicate extensions are rejected.
4390 testCases = append(testCases, testCase{
4391 testType: clientTest,
4392 name: "DuplicateExtensionClient-" + ver.name,
4393 config: Config{
4394 MaxVersion: ver.version,
4395 Bugs: ProtocolBugs{
4396 DuplicateExtension: true,
4397 },
David Benjamine78bfde2014-09-06 12:45:15 -04004398 },
David Benjamin97d17d92016-07-14 16:12:00 -04004399 shouldFail: true,
4400 expectedLocalError: "remote error: error decoding message",
4401 })
4402 testCases = append(testCases, testCase{
4403 testType: serverTest,
4404 name: "DuplicateExtensionServer-" + ver.name,
4405 config: Config{
4406 MaxVersion: ver.version,
4407 Bugs: ProtocolBugs{
4408 DuplicateExtension: true,
4409 },
David Benjamine78bfde2014-09-06 12:45:15 -04004410 },
David Benjamin97d17d92016-07-14 16:12:00 -04004411 shouldFail: true,
4412 expectedLocalError: "remote error: error decoding message",
4413 })
4414
4415 // Test SNI.
4416 testCases = append(testCases, testCase{
4417 testType: clientTest,
4418 name: "ServerNameExtensionClient-" + ver.name,
4419 config: Config{
4420 MaxVersion: ver.version,
4421 Bugs: ProtocolBugs{
4422 ExpectServerName: "example.com",
4423 },
David Benjamine78bfde2014-09-06 12:45:15 -04004424 },
David Benjamin97d17d92016-07-14 16:12:00 -04004425 flags: []string{"-host-name", "example.com"},
4426 })
4427 testCases = append(testCases, testCase{
4428 testType: clientTest,
4429 name: "ServerNameExtensionClientMismatch-" + ver.name,
4430 config: Config{
4431 MaxVersion: ver.version,
4432 Bugs: ProtocolBugs{
4433 ExpectServerName: "mismatch.com",
4434 },
David Benjamine78bfde2014-09-06 12:45:15 -04004435 },
David Benjamin97d17d92016-07-14 16:12:00 -04004436 flags: []string{"-host-name", "example.com"},
4437 shouldFail: true,
4438 expectedLocalError: "tls: unexpected server name",
4439 })
4440 testCases = append(testCases, testCase{
4441 testType: clientTest,
4442 name: "ServerNameExtensionClientMissing-" + ver.name,
4443 config: Config{
4444 MaxVersion: ver.version,
4445 Bugs: ProtocolBugs{
4446 ExpectServerName: "missing.com",
4447 },
David Benjamine78bfde2014-09-06 12:45:15 -04004448 },
David Benjamin97d17d92016-07-14 16:12:00 -04004449 shouldFail: true,
4450 expectedLocalError: "tls: unexpected server name",
4451 })
4452 testCases = append(testCases, testCase{
4453 testType: serverTest,
4454 name: "ServerNameExtensionServer-" + ver.name,
4455 config: Config{
4456 MaxVersion: ver.version,
4457 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004458 },
David Benjamin97d17d92016-07-14 16:12:00 -04004459 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004460 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004461 })
4462
4463 // Test ALPN.
4464 testCases = append(testCases, testCase{
4465 testType: clientTest,
4466 name: "ALPNClient-" + ver.name,
4467 config: Config{
4468 MaxVersion: ver.version,
4469 NextProtos: []string{"foo"},
4470 },
4471 flags: []string{
4472 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4473 "-expect-alpn", "foo",
4474 },
4475 expectedNextProto: "foo",
4476 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004477 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004478 })
4479 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004480 testType: clientTest,
4481 name: "ALPNClient-Mismatch-" + ver.name,
4482 config: Config{
4483 MaxVersion: ver.version,
4484 Bugs: ProtocolBugs{
4485 SendALPN: "baz",
4486 },
4487 },
4488 flags: []string{
4489 "-advertise-alpn", "\x03foo\x03bar",
4490 },
4491 shouldFail: true,
4492 expectedError: ":INVALID_ALPN_PROTOCOL:",
4493 expectedLocalError: "remote error: illegal parameter",
4494 })
4495 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004496 testType: serverTest,
4497 name: "ALPNServer-" + ver.name,
4498 config: Config{
4499 MaxVersion: ver.version,
4500 NextProtos: []string{"foo", "bar", "baz"},
4501 },
4502 flags: []string{
4503 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4504 "-select-alpn", "foo",
4505 },
4506 expectedNextProto: "foo",
4507 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004508 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004509 })
4510 testCases = append(testCases, testCase{
4511 testType: serverTest,
4512 name: "ALPNServer-Decline-" + ver.name,
4513 config: Config{
4514 MaxVersion: ver.version,
4515 NextProtos: []string{"foo", "bar", "baz"},
4516 },
4517 flags: []string{"-decline-alpn"},
4518 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004519 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004520 })
4521
David Benjamin25fe85b2016-08-09 20:00:32 -04004522 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4523 // called once.
4524 testCases = append(testCases, testCase{
4525 testType: serverTest,
4526 name: "ALPNServer-Async-" + ver.name,
4527 config: Config{
4528 MaxVersion: ver.version,
4529 NextProtos: []string{"foo", "bar", "baz"},
4530 },
4531 flags: []string{
4532 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4533 "-select-alpn", "foo",
4534 "-async",
4535 },
4536 expectedNextProto: "foo",
4537 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004538 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004539 })
4540
David Benjamin97d17d92016-07-14 16:12:00 -04004541 var emptyString string
4542 testCases = append(testCases, testCase{
4543 testType: clientTest,
4544 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4545 config: Config{
4546 MaxVersion: ver.version,
4547 NextProtos: []string{""},
4548 Bugs: ProtocolBugs{
4549 // A server returning an empty ALPN protocol
4550 // should be rejected.
4551 ALPNProtocol: &emptyString,
4552 },
4553 },
4554 flags: []string{
4555 "-advertise-alpn", "\x03foo",
4556 },
4557 shouldFail: true,
4558 expectedError: ":PARSE_TLSEXT:",
4559 })
4560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4563 config: Config{
4564 MaxVersion: ver.version,
4565 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004566 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004567 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004568 },
David Benjamin97d17d92016-07-14 16:12:00 -04004569 flags: []string{
4570 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004571 },
David Benjamin97d17d92016-07-14 16:12:00 -04004572 shouldFail: true,
4573 expectedError: ":PARSE_TLSEXT:",
4574 })
4575
4576 // Test NPN and the interaction with ALPN.
4577 if ver.version < VersionTLS13 {
4578 // Test that the server prefers ALPN over NPN.
4579 testCases = append(testCases, testCase{
4580 testType: serverTest,
4581 name: "ALPNServer-Preferred-" + ver.name,
4582 config: Config{
4583 MaxVersion: ver.version,
4584 NextProtos: []string{"foo", "bar", "baz"},
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 testCases = append(testCases, testCase{
4596 testType: serverTest,
4597 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4598 config: Config{
4599 MaxVersion: ver.version,
4600 NextProtos: []string{"foo", "bar", "baz"},
4601 Bugs: ProtocolBugs{
4602 SwapNPNAndALPN: true,
4603 },
4604 },
4605 flags: []string{
4606 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4607 "-select-alpn", "foo",
4608 "-advertise-npn", "\x03foo\x03bar\x03baz",
4609 },
4610 expectedNextProto: "foo",
4611 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004612 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004613 })
4614
4615 // Test that negotiating both NPN and ALPN is forbidden.
4616 testCases = append(testCases, testCase{
4617 name: "NegotiateALPNAndNPN-" + ver.name,
4618 config: Config{
4619 MaxVersion: ver.version,
4620 NextProtos: []string{"foo", "bar", "baz"},
4621 Bugs: ProtocolBugs{
4622 NegotiateALPNAndNPN: true,
4623 },
4624 },
4625 flags: []string{
4626 "-advertise-alpn", "\x03foo",
4627 "-select-next-proto", "foo",
4628 },
4629 shouldFail: true,
4630 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4631 })
4632 testCases = append(testCases, testCase{
4633 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 NextProtos: []string{"foo", "bar", "baz"},
4637 Bugs: ProtocolBugs{
4638 NegotiateALPNAndNPN: true,
4639 SwapNPNAndALPN: true,
4640 },
4641 },
4642 flags: []string{
4643 "-advertise-alpn", "\x03foo",
4644 "-select-next-proto", "foo",
4645 },
4646 shouldFail: true,
4647 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4648 })
4649
4650 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4651 testCases = append(testCases, testCase{
4652 name: "DisableNPN-" + ver.name,
4653 config: Config{
4654 MaxVersion: ver.version,
4655 NextProtos: []string{"foo"},
4656 },
4657 flags: []string{
4658 "-select-next-proto", "foo",
4659 "-disable-npn",
4660 },
4661 expectNoNextProto: true,
4662 })
4663 }
4664
4665 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004666
4667 // Resume with a corrupt ticket.
4668 testCases = append(testCases, testCase{
4669 testType: serverTest,
4670 name: "CorruptTicket-" + ver.name,
4671 config: Config{
4672 MaxVersion: ver.version,
4673 Bugs: ProtocolBugs{
4674 CorruptTicket: true,
4675 },
4676 },
4677 resumeSession: true,
4678 expectResumeRejected: true,
4679 })
4680 // Test the ticket callback, with and without renewal.
4681 testCases = append(testCases, testCase{
4682 testType: serverTest,
4683 name: "TicketCallback-" + ver.name,
4684 config: Config{
4685 MaxVersion: ver.version,
4686 },
4687 resumeSession: true,
4688 flags: []string{"-use-ticket-callback"},
4689 })
4690 testCases = append(testCases, testCase{
4691 testType: serverTest,
4692 name: "TicketCallback-Renew-" + ver.name,
4693 config: Config{
4694 MaxVersion: ver.version,
4695 Bugs: ProtocolBugs{
4696 ExpectNewTicket: true,
4697 },
4698 },
4699 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4700 resumeSession: true,
4701 })
4702
4703 // Test that the ticket callback is only called once when everything before
4704 // it in the ClientHello is asynchronous. This corrupts the ticket so
4705 // certificate selection callbacks run.
4706 testCases = append(testCases, testCase{
4707 testType: serverTest,
4708 name: "TicketCallback-SingleCall-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 Bugs: ProtocolBugs{
4712 CorruptTicket: true,
4713 },
4714 },
4715 resumeSession: true,
4716 expectResumeRejected: true,
4717 flags: []string{
4718 "-use-ticket-callback",
4719 "-async",
4720 },
4721 })
4722
4723 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004724 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004725 testCases = append(testCases, testCase{
4726 testType: serverTest,
4727 name: "OversizedSessionId-" + ver.name,
4728 config: Config{
4729 MaxVersion: ver.version,
4730 Bugs: ProtocolBugs{
4731 OversizedSessionId: true,
4732 },
4733 },
4734 resumeSession: true,
4735 shouldFail: true,
4736 expectedError: ":DECODE_ERROR:",
4737 })
4738 }
4739
4740 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4741 // are ignored.
4742 if ver.hasDTLS {
4743 testCases = append(testCases, testCase{
4744 protocol: dtls,
4745 name: "SRTP-Client-" + ver.name,
4746 config: Config{
4747 MaxVersion: ver.version,
4748 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4749 },
4750 flags: []string{
4751 "-srtp-profiles",
4752 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4753 },
4754 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4755 })
4756 testCases = append(testCases, testCase{
4757 protocol: dtls,
4758 testType: serverTest,
4759 name: "SRTP-Server-" + ver.name,
4760 config: Config{
4761 MaxVersion: ver.version,
4762 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4763 },
4764 flags: []string{
4765 "-srtp-profiles",
4766 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4767 },
4768 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4769 })
4770 // Test that the MKI is ignored.
4771 testCases = append(testCases, testCase{
4772 protocol: dtls,
4773 testType: serverTest,
4774 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4778 Bugs: ProtocolBugs{
4779 SRTPMasterKeyIdentifer: "bogus",
4780 },
4781 },
4782 flags: []string{
4783 "-srtp-profiles",
4784 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4785 },
4786 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4787 })
4788 // Test that SRTP isn't negotiated on the server if there were
4789 // no matching profiles.
4790 testCases = append(testCases, testCase{
4791 protocol: dtls,
4792 testType: serverTest,
4793 name: "SRTP-Server-NoMatch-" + ver.name,
4794 config: Config{
4795 MaxVersion: ver.version,
4796 SRTPProtectionProfiles: []uint16{100, 101, 102},
4797 },
4798 flags: []string{
4799 "-srtp-profiles",
4800 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4801 },
4802 expectedSRTPProtectionProfile: 0,
4803 })
4804 // Test that the server returning an invalid SRTP profile is
4805 // flagged as an error by the client.
4806 testCases = append(testCases, testCase{
4807 protocol: dtls,
4808 name: "SRTP-Client-NoMatch-" + ver.name,
4809 config: Config{
4810 MaxVersion: ver.version,
4811 Bugs: ProtocolBugs{
4812 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4813 },
4814 },
4815 flags: []string{
4816 "-srtp-profiles",
4817 "SRTP_AES128_CM_SHA1_80",
4818 },
4819 shouldFail: true,
4820 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4821 })
4822 }
4823
4824 // Test SCT list.
4825 testCases = append(testCases, testCase{
4826 name: "SignedCertificateTimestampList-Client-" + ver.name,
4827 testType: clientTest,
4828 config: Config{
4829 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004830 },
David Benjamin97d17d92016-07-14 16:12:00 -04004831 flags: []string{
4832 "-enable-signed-cert-timestamps",
4833 "-expect-signed-cert-timestamps",
4834 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004835 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004836 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004837 })
4838 testCases = append(testCases, testCase{
4839 name: "SendSCTListOnResume-" + ver.name,
4840 config: Config{
4841 MaxVersion: ver.version,
4842 Bugs: ProtocolBugs{
4843 SendSCTListOnResume: []byte("bogus"),
4844 },
David Benjamind98452d2015-06-16 14:16:23 -04004845 },
David Benjamin97d17d92016-07-14 16:12:00 -04004846 flags: []string{
4847 "-enable-signed-cert-timestamps",
4848 "-expect-signed-cert-timestamps",
4849 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004850 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004851 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004852 })
4853 testCases = append(testCases, testCase{
4854 name: "SignedCertificateTimestampList-Server-" + ver.name,
4855 testType: serverTest,
4856 config: Config{
4857 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004858 },
David Benjamin97d17d92016-07-14 16:12:00 -04004859 flags: []string{
4860 "-signed-cert-timestamps",
4861 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004862 },
David Benjamin97d17d92016-07-14 16:12:00 -04004863 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004864 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004865 })
4866 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004867
Paul Lietar4fac72e2015-09-09 13:44:55 +01004868 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004869 testType: clientTest,
4870 name: "ClientHelloPadding",
4871 config: Config{
4872 Bugs: ProtocolBugs{
4873 RequireClientHelloSize: 512,
4874 },
4875 },
4876 // This hostname just needs to be long enough to push the
4877 // ClientHello into F5's danger zone between 256 and 511 bytes
4878 // long.
4879 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4880 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004881
4882 // Extensions should not function in SSL 3.0.
4883 testCases = append(testCases, testCase{
4884 testType: serverTest,
4885 name: "SSLv3Extensions-NoALPN",
4886 config: Config{
4887 MaxVersion: VersionSSL30,
4888 NextProtos: []string{"foo", "bar", "baz"},
4889 },
4890 flags: []string{
4891 "-select-alpn", "foo",
4892 },
4893 expectNoNextProto: true,
4894 })
4895
4896 // Test session tickets separately as they follow a different codepath.
4897 testCases = append(testCases, testCase{
4898 testType: serverTest,
4899 name: "SSLv3Extensions-NoTickets",
4900 config: Config{
4901 MaxVersion: VersionSSL30,
4902 Bugs: ProtocolBugs{
4903 // Historically, session tickets in SSL 3.0
4904 // failed in different ways depending on whether
4905 // the client supported renegotiation_info.
4906 NoRenegotiationInfo: true,
4907 },
4908 },
4909 resumeSession: true,
4910 })
4911 testCases = append(testCases, testCase{
4912 testType: serverTest,
4913 name: "SSLv3Extensions-NoTickets2",
4914 config: Config{
4915 MaxVersion: VersionSSL30,
4916 },
4917 resumeSession: true,
4918 })
4919
4920 // But SSL 3.0 does send and process renegotiation_info.
4921 testCases = append(testCases, testCase{
4922 testType: serverTest,
4923 name: "SSLv3Extensions-RenegotiationInfo",
4924 config: Config{
4925 MaxVersion: VersionSSL30,
4926 Bugs: ProtocolBugs{
4927 RequireRenegotiationInfo: true,
4928 },
4929 },
4930 })
4931 testCases = append(testCases, testCase{
4932 testType: serverTest,
4933 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4934 config: Config{
4935 MaxVersion: VersionSSL30,
4936 Bugs: ProtocolBugs{
4937 NoRenegotiationInfo: true,
4938 SendRenegotiationSCSV: true,
4939 RequireRenegotiationInfo: true,
4940 },
4941 },
4942 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004943
4944 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4945 // in ServerHello.
4946 testCases = append(testCases, testCase{
4947 name: "NPN-Forbidden-TLS13",
4948 config: Config{
4949 MaxVersion: VersionTLS13,
4950 NextProtos: []string{"foo"},
4951 Bugs: ProtocolBugs{
4952 NegotiateNPNAtAllVersions: true,
4953 },
4954 },
4955 flags: []string{"-select-next-proto", "foo"},
4956 shouldFail: true,
4957 expectedError: ":ERROR_PARSING_EXTENSION:",
4958 })
4959 testCases = append(testCases, testCase{
4960 name: "EMS-Forbidden-TLS13",
4961 config: Config{
4962 MaxVersion: VersionTLS13,
4963 Bugs: ProtocolBugs{
4964 NegotiateEMSAtAllVersions: true,
4965 },
4966 },
4967 shouldFail: true,
4968 expectedError: ":ERROR_PARSING_EXTENSION:",
4969 })
4970 testCases = append(testCases, testCase{
4971 name: "RenegotiationInfo-Forbidden-TLS13",
4972 config: Config{
4973 MaxVersion: VersionTLS13,
4974 Bugs: ProtocolBugs{
4975 NegotiateRenegotiationInfoAtAllVersions: true,
4976 },
4977 },
4978 shouldFail: true,
4979 expectedError: ":ERROR_PARSING_EXTENSION:",
4980 })
4981 testCases = append(testCases, testCase{
4982 name: "ChannelID-Forbidden-TLS13",
4983 config: Config{
4984 MaxVersion: VersionTLS13,
4985 RequestChannelID: true,
4986 Bugs: ProtocolBugs{
4987 NegotiateChannelIDAtAllVersions: true,
4988 },
4989 },
4990 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4991 shouldFail: true,
4992 expectedError: ":ERROR_PARSING_EXTENSION:",
4993 })
4994 testCases = append(testCases, testCase{
4995 name: "Ticket-Forbidden-TLS13",
4996 config: Config{
4997 MaxVersion: VersionTLS12,
4998 },
4999 resumeConfig: &Config{
5000 MaxVersion: VersionTLS13,
5001 Bugs: ProtocolBugs{
5002 AdvertiseTicketExtension: true,
5003 },
5004 },
5005 resumeSession: true,
5006 shouldFail: true,
5007 expectedError: ":ERROR_PARSING_EXTENSION:",
5008 })
5009
5010 // Test that illegal extensions in TLS 1.3 are declined by the server if
5011 // offered in ClientHello. The runner's server will fail if this occurs,
5012 // so we exercise the offering path. (EMS and Renegotiation Info are
5013 // implicit in every test.)
5014 testCases = append(testCases, testCase{
5015 testType: serverTest,
5016 name: "ChannelID-Declined-TLS13",
5017 config: Config{
5018 MaxVersion: VersionTLS13,
5019 ChannelID: channelIDKey,
5020 },
5021 flags: []string{"-enable-channel-id"},
5022 })
5023 testCases = append(testCases, testCase{
5024 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005025 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005026 config: Config{
5027 MaxVersion: VersionTLS13,
5028 NextProtos: []string{"bar"},
5029 },
5030 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5031 })
David Benjamin196df5b2016-09-21 16:23:27 -04005032
5033 testCases = append(testCases, testCase{
5034 testType: serverTest,
5035 name: "InvalidChannelIDSignature",
5036 config: Config{
5037 MaxVersion: VersionTLS12,
5038 ChannelID: channelIDKey,
5039 Bugs: ProtocolBugs{
5040 InvalidChannelIDSignature: true,
5041 },
5042 },
5043 flags: []string{"-enable-channel-id"},
5044 shouldFail: true,
5045 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5046 expectedLocalError: "remote error: error decrypting message",
5047 })
David Benjamine78bfde2014-09-06 12:45:15 -04005048}
5049
David Benjamin01fe8202014-09-24 15:21:44 -04005050func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005051 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005052 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005053 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5054 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5055 // TLS 1.3 only shares ciphers with TLS 1.2, so
5056 // we skip certain combinations and use a
5057 // different cipher to test with.
5058 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5059 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5060 continue
5061 }
5062 }
5063
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 protocols := []protocol{tls}
5065 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5066 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005067 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005068 for _, protocol := range protocols {
5069 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5070 if protocol == dtls {
5071 suffix += "-DTLS"
5072 }
5073
David Benjaminece3de92015-03-16 18:02:20 -04005074 if sessionVers.version == resumeVers.version {
5075 testCases = append(testCases, testCase{
5076 protocol: protocol,
5077 name: "Resume-Client" + suffix,
5078 resumeSession: true,
5079 config: Config{
5080 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005081 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005082 Bugs: ProtocolBugs{
5083 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5084 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5085 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005086 },
David Benjaminece3de92015-03-16 18:02:20 -04005087 expectedVersion: sessionVers.version,
5088 expectedResumeVersion: resumeVers.version,
5089 })
5090 } else {
David Benjamin405da482016-08-08 17:25:07 -04005091 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5092
5093 // Offering a TLS 1.3 session sends an empty session ID, so
5094 // there is no way to convince a non-lookahead client the
5095 // session was resumed. It will appear to the client that a
5096 // stray ChangeCipherSpec was sent.
5097 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5098 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005099 }
5100
David Benjaminece3de92015-03-16 18:02:20 -04005101 testCases = append(testCases, testCase{
5102 protocol: protocol,
5103 name: "Resume-Client-Mismatch" + suffix,
5104 resumeSession: true,
5105 config: Config{
5106 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005107 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005108 },
David Benjaminece3de92015-03-16 18:02:20 -04005109 expectedVersion: sessionVers.version,
5110 resumeConfig: &Config{
5111 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005112 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005113 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005114 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005115 },
5116 },
5117 expectedResumeVersion: resumeVers.version,
5118 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005119 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005120 })
5121 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005122
5123 testCases = append(testCases, testCase{
5124 protocol: protocol,
5125 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005126 resumeSession: true,
5127 config: Config{
5128 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005129 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005130 },
5131 expectedVersion: sessionVers.version,
5132 resumeConfig: &Config{
5133 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005134 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005135 },
5136 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005137 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005138 expectedResumeVersion: resumeVers.version,
5139 })
5140
David Benjamin8b8c0062014-11-23 02:47:52 -05005141 testCases = append(testCases, testCase{
5142 protocol: protocol,
5143 testType: serverTest,
5144 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005145 resumeSession: true,
5146 config: Config{
5147 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005148 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005149 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005150 expectedVersion: sessionVers.version,
5151 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005152 resumeConfig: &Config{
5153 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005154 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005155 Bugs: ProtocolBugs{
5156 SendBothTickets: true,
5157 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005158 },
5159 expectedResumeVersion: resumeVers.version,
5160 })
5161 }
David Benjamin01fe8202014-09-24 15:21:44 -04005162 }
5163 }
David Benjaminece3de92015-03-16 18:02:20 -04005164
5165 testCases = append(testCases, testCase{
5166 name: "Resume-Client-CipherMismatch",
5167 resumeSession: true,
5168 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005169 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005170 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5171 },
5172 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005173 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005174 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5175 Bugs: ProtocolBugs{
5176 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5177 },
5178 },
5179 shouldFail: true,
5180 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5181 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005182
5183 testCases = append(testCases, testCase{
5184 name: "Resume-Client-CipherMismatch-TLS13",
5185 resumeSession: true,
5186 config: Config{
5187 MaxVersion: VersionTLS13,
5188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5189 },
5190 resumeConfig: &Config{
5191 MaxVersion: VersionTLS13,
5192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5193 Bugs: ProtocolBugs{
5194 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5195 },
5196 },
5197 shouldFail: true,
5198 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5199 })
David Benjamin01fe8202014-09-24 15:21:44 -04005200}
5201
Adam Langley2ae77d22014-10-28 17:29:33 -07005202func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005203 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005204 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005205 testType: serverTest,
5206 name: "Renegotiate-Server-Forbidden",
5207 config: Config{
5208 MaxVersion: VersionTLS12,
5209 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005210 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005211 shouldFail: true,
5212 expectedError: ":NO_RENEGOTIATION:",
5213 expectedLocalError: "remote error: no renegotiation",
5214 })
Adam Langley5021b222015-06-12 18:27:58 -07005215 // The server shouldn't echo the renegotiation extension unless
5216 // requested by the client.
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
5219 name: "Renegotiate-Server-NoExt",
5220 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005221 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005222 Bugs: ProtocolBugs{
5223 NoRenegotiationInfo: true,
5224 RequireRenegotiationInfo: true,
5225 },
5226 },
5227 shouldFail: true,
5228 expectedLocalError: "renegotiation extension missing",
5229 })
5230 // The renegotiation SCSV should be sufficient for the server to echo
5231 // the extension.
5232 testCases = append(testCases, testCase{
5233 testType: serverTest,
5234 name: "Renegotiate-Server-NoExt-SCSV",
5235 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005236 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005237 Bugs: ProtocolBugs{
5238 NoRenegotiationInfo: true,
5239 SendRenegotiationSCSV: true,
5240 RequireRenegotiationInfo: true,
5241 },
5242 },
5243 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005244 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005245 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005246 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005247 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005248 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005249 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005250 },
5251 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005252 renegotiate: 1,
5253 flags: []string{
5254 "-renegotiate-freely",
5255 "-expect-total-renegotiations", "1",
5256 },
David Benjamincdea40c2015-03-19 14:09:43 -04005257 })
5258 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005259 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005260 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005262 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005263 Bugs: ProtocolBugs{
5264 EmptyRenegotiationInfo: true,
5265 },
5266 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005267 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005268 shouldFail: true,
5269 expectedError: ":RENEGOTIATION_MISMATCH:",
5270 })
5271 testCases = append(testCases, testCase{
5272 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005273 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005274 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005275 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005276 Bugs: ProtocolBugs{
5277 BadRenegotiationInfo: true,
5278 },
5279 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005280 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005281 shouldFail: true,
5282 expectedError: ":RENEGOTIATION_MISMATCH:",
5283 })
5284 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005285 name: "Renegotiate-Client-Downgrade",
5286 renegotiate: 1,
5287 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005288 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005289 Bugs: ProtocolBugs{
5290 NoRenegotiationInfoAfterInitial: true,
5291 },
5292 },
5293 flags: []string{"-renegotiate-freely"},
5294 shouldFail: true,
5295 expectedError: ":RENEGOTIATION_MISMATCH:",
5296 })
5297 testCases = append(testCases, testCase{
5298 name: "Renegotiate-Client-Upgrade",
5299 renegotiate: 1,
5300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005301 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005302 Bugs: ProtocolBugs{
5303 NoRenegotiationInfoInInitial: true,
5304 },
5305 },
5306 flags: []string{"-renegotiate-freely"},
5307 shouldFail: true,
5308 expectedError: ":RENEGOTIATION_MISMATCH:",
5309 })
5310 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005311 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005312 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005313 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005314 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005315 Bugs: ProtocolBugs{
5316 NoRenegotiationInfo: true,
5317 },
5318 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005319 flags: []string{
5320 "-renegotiate-freely",
5321 "-expect-total-renegotiations", "1",
5322 },
David Benjamincff0b902015-05-15 23:09:47 -04005323 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005324
5325 // Test that the server may switch ciphers on renegotiation without
5326 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005327 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005328 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005329 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005330 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005331 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005332 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005333 },
5334 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005335 flags: []string{
5336 "-renegotiate-freely",
5337 "-expect-total-renegotiations", "1",
5338 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005339 })
5340 testCases = append(testCases, testCase{
5341 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005342 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005343 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005344 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005345 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5346 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005347 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005348 flags: []string{
5349 "-renegotiate-freely",
5350 "-expect-total-renegotiations", "1",
5351 },
David Benjaminb16346b2015-04-08 19:16:58 -04005352 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005353
5354 // Test that the server may not switch versions on renegotiation.
5355 testCases = append(testCases, testCase{
5356 name: "Renegotiate-Client-SwitchVersion",
5357 config: Config{
5358 MaxVersion: VersionTLS12,
5359 // Pick a cipher which exists at both versions.
5360 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5361 Bugs: ProtocolBugs{
5362 NegotiateVersionOnRenego: VersionTLS11,
5363 },
5364 },
5365 renegotiate: 1,
5366 flags: []string{
5367 "-renegotiate-freely",
5368 "-expect-total-renegotiations", "1",
5369 },
5370 shouldFail: true,
5371 expectedError: ":WRONG_SSL_VERSION:",
5372 })
5373
David Benjaminb16346b2015-04-08 19:16:58 -04005374 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005375 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005376 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005377 config: Config{
5378 MaxVersion: VersionTLS10,
5379 Bugs: ProtocolBugs{
5380 RequireSameRenegoClientVersion: true,
5381 },
5382 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005383 flags: []string{
5384 "-renegotiate-freely",
5385 "-expect-total-renegotiations", "1",
5386 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005387 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005388 testCases = append(testCases, testCase{
5389 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005390 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005391 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005392 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005393 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5394 NextProtos: []string{"foo"},
5395 },
5396 flags: []string{
5397 "-false-start",
5398 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005399 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005400 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005401 },
5402 shimWritesFirst: true,
5403 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005404
5405 // Client-side renegotiation controls.
5406 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005407 name: "Renegotiate-Client-Forbidden-1",
5408 config: Config{
5409 MaxVersion: VersionTLS12,
5410 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005411 renegotiate: 1,
5412 shouldFail: true,
5413 expectedError: ":NO_RENEGOTIATION:",
5414 expectedLocalError: "remote error: no renegotiation",
5415 })
5416 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005417 name: "Renegotiate-Client-Once-1",
5418 config: Config{
5419 MaxVersion: VersionTLS12,
5420 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005421 renegotiate: 1,
5422 flags: []string{
5423 "-renegotiate-once",
5424 "-expect-total-renegotiations", "1",
5425 },
5426 })
5427 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 name: "Renegotiate-Client-Freely-1",
5429 config: Config{
5430 MaxVersion: VersionTLS12,
5431 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005432 renegotiate: 1,
5433 flags: []string{
5434 "-renegotiate-freely",
5435 "-expect-total-renegotiations", "1",
5436 },
5437 })
5438 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005439 name: "Renegotiate-Client-Once-2",
5440 config: Config{
5441 MaxVersion: VersionTLS12,
5442 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005443 renegotiate: 2,
5444 flags: []string{"-renegotiate-once"},
5445 shouldFail: true,
5446 expectedError: ":NO_RENEGOTIATION:",
5447 expectedLocalError: "remote error: no renegotiation",
5448 })
5449 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005450 name: "Renegotiate-Client-Freely-2",
5451 config: Config{
5452 MaxVersion: VersionTLS12,
5453 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005454 renegotiate: 2,
5455 flags: []string{
5456 "-renegotiate-freely",
5457 "-expect-total-renegotiations", "2",
5458 },
5459 })
Adam Langley27a0d082015-11-03 13:34:10 -08005460 testCases = append(testCases, testCase{
5461 name: "Renegotiate-Client-NoIgnore",
5462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005463 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005464 Bugs: ProtocolBugs{
5465 SendHelloRequestBeforeEveryAppDataRecord: true,
5466 },
5467 },
5468 shouldFail: true,
5469 expectedError: ":NO_RENEGOTIATION:",
5470 })
5471 testCases = append(testCases, testCase{
5472 name: "Renegotiate-Client-Ignore",
5473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005474 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005475 Bugs: ProtocolBugs{
5476 SendHelloRequestBeforeEveryAppDataRecord: true,
5477 },
5478 },
5479 flags: []string{
5480 "-renegotiate-ignore",
5481 "-expect-total-renegotiations", "0",
5482 },
5483 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005484
David Benjamin397c8e62016-07-08 14:14:36 -07005485 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005486 testCases = append(testCases, testCase{
5487 name: "StrayHelloRequest",
5488 config: Config{
5489 MaxVersion: VersionTLS12,
5490 Bugs: ProtocolBugs{
5491 SendHelloRequestBeforeEveryHandshakeMessage: true,
5492 },
5493 },
5494 })
5495 testCases = append(testCases, testCase{
5496 name: "StrayHelloRequest-Packed",
5497 config: Config{
5498 MaxVersion: VersionTLS12,
5499 Bugs: ProtocolBugs{
5500 PackHandshakeFlight: true,
5501 SendHelloRequestBeforeEveryHandshakeMessage: true,
5502 },
5503 },
5504 })
5505
David Benjamin12d2c482016-07-24 10:56:51 -04005506 // Test renegotiation works if HelloRequest and server Finished come in
5507 // the same record.
5508 testCases = append(testCases, testCase{
5509 name: "Renegotiate-Client-Packed",
5510 config: Config{
5511 MaxVersion: VersionTLS12,
5512 Bugs: ProtocolBugs{
5513 PackHandshakeFlight: true,
5514 PackHelloRequestWithFinished: true,
5515 },
5516 },
5517 renegotiate: 1,
5518 flags: []string{
5519 "-renegotiate-freely",
5520 "-expect-total-renegotiations", "1",
5521 },
5522 })
5523
David Benjamin397c8e62016-07-08 14:14:36 -07005524 // Renegotiation is forbidden in TLS 1.3.
5525 testCases = append(testCases, testCase{
5526 name: "Renegotiate-Client-TLS13",
5527 config: Config{
5528 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005529 Bugs: ProtocolBugs{
5530 SendHelloRequestBeforeEveryAppDataRecord: true,
5531 },
David Benjamin397c8e62016-07-08 14:14:36 -07005532 },
David Benjamin397c8e62016-07-08 14:14:36 -07005533 flags: []string{
5534 "-renegotiate-freely",
5535 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005536 shouldFail: true,
5537 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005538 })
5539
5540 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5541 testCases = append(testCases, testCase{
5542 name: "StrayHelloRequest-TLS13",
5543 config: Config{
5544 MaxVersion: VersionTLS13,
5545 Bugs: ProtocolBugs{
5546 SendHelloRequestBeforeEveryHandshakeMessage: true,
5547 },
5548 },
5549 shouldFail: true,
5550 expectedError: ":UNEXPECTED_MESSAGE:",
5551 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005552}
5553
David Benjamin5e961c12014-11-07 01:48:35 -05005554func addDTLSReplayTests() {
5555 // Test that sequence number replays are detected.
5556 testCases = append(testCases, testCase{
5557 protocol: dtls,
5558 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005559 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005560 replayWrites: true,
5561 })
5562
David Benjamin8e6db492015-07-25 18:29:23 -04005563 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005564 // than the retransmit window.
5565 testCases = append(testCases, testCase{
5566 protocol: dtls,
5567 name: "DTLS-Replay-LargeGaps",
5568 config: Config{
5569 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005570 SequenceNumberMapping: func(in uint64) uint64 {
5571 return in * 127
5572 },
David Benjamin5e961c12014-11-07 01:48:35 -05005573 },
5574 },
David Benjamin8e6db492015-07-25 18:29:23 -04005575 messageCount: 200,
5576 replayWrites: true,
5577 })
5578
5579 // Test the incoming sequence number changing non-monotonically.
5580 testCases = append(testCases, testCase{
5581 protocol: dtls,
5582 name: "DTLS-Replay-NonMonotonic",
5583 config: Config{
5584 Bugs: ProtocolBugs{
5585 SequenceNumberMapping: func(in uint64) uint64 {
5586 return in ^ 31
5587 },
5588 },
5589 },
5590 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005591 replayWrites: true,
5592 })
5593}
5594
Nick Harper60edffd2016-06-21 15:19:24 -07005595var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005596 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005597 id signatureAlgorithm
5598 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005599}{
Nick Harper60edffd2016-06-21 15:19:24 -07005600 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5601 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5602 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5603 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005604 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005605 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5606 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5607 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005608 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5609 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5610 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005611 // Tests for key types prior to TLS 1.2.
5612 {"RSA", 0, testCertRSA},
5613 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005614}
5615
Nick Harper60edffd2016-06-21 15:19:24 -07005616const fakeSigAlg1 signatureAlgorithm = 0x2a01
5617const fakeSigAlg2 signatureAlgorithm = 0xff01
5618
5619func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005620 // Not all ciphers involve a signature. Advertise a list which gives all
5621 // versions a signing cipher.
5622 signingCiphers := []uint16{
5623 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5624 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5625 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5626 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5627 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5628 }
5629
David Benjaminca3d5452016-07-14 12:51:01 -04005630 var allAlgorithms []signatureAlgorithm
5631 for _, alg := range testSignatureAlgorithms {
5632 if alg.id != 0 {
5633 allAlgorithms = append(allAlgorithms, alg.id)
5634 }
5635 }
5636
Nick Harper60edffd2016-06-21 15:19:24 -07005637 // Make sure each signature algorithm works. Include some fake values in
5638 // the list and ensure they're ignored.
5639 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005640 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005641 if (ver.version < VersionTLS12) != (alg.id == 0) {
5642 continue
5643 }
5644
5645 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5646 // or remove it in C.
5647 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005648 continue
5649 }
Nick Harper60edffd2016-06-21 15:19:24 -07005650
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005651 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005652 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005653 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5654 shouldFail = true
5655 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005656 // RSA-PKCS1 does not exist in TLS 1.3.
5657 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5658 shouldFail = true
5659 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005660
5661 var signError, verifyError string
5662 if shouldFail {
5663 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5664 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005665 }
David Benjamin000800a2014-11-14 01:43:59 -05005666
David Benjamin1fb125c2016-07-08 18:52:12 -07005667 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005668
David Benjamin7a41d372016-07-09 11:21:54 -07005669 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005670 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005671 config: Config{
5672 MaxVersion: ver.version,
5673 ClientAuth: RequireAnyClientCert,
5674 VerifySignatureAlgorithms: []signatureAlgorithm{
5675 fakeSigAlg1,
5676 alg.id,
5677 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005678 },
David Benjamin7a41d372016-07-09 11:21:54 -07005679 },
5680 flags: []string{
5681 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5682 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5683 "-enable-all-curves",
5684 },
5685 shouldFail: shouldFail,
5686 expectedError: signError,
5687 expectedPeerSignatureAlgorithm: alg.id,
5688 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005689
David Benjamin7a41d372016-07-09 11:21:54 -07005690 testCases = append(testCases, testCase{
5691 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005692 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005693 config: Config{
5694 MaxVersion: ver.version,
5695 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5696 SignSignatureAlgorithms: []signatureAlgorithm{
5697 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005698 },
David Benjamin7a41d372016-07-09 11:21:54 -07005699 Bugs: ProtocolBugs{
5700 SkipECDSACurveCheck: shouldFail,
5701 IgnoreSignatureVersionChecks: shouldFail,
5702 // The client won't advertise 1.3-only algorithms after
5703 // version negotiation.
5704 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005705 },
David Benjamin7a41d372016-07-09 11:21:54 -07005706 },
5707 flags: []string{
5708 "-require-any-client-certificate",
5709 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5710 "-enable-all-curves",
5711 },
5712 shouldFail: shouldFail,
5713 expectedError: verifyError,
5714 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005715
5716 testCases = append(testCases, testCase{
5717 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005718 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005719 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005720 MaxVersion: ver.version,
5721 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005722 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005723 fakeSigAlg1,
5724 alg.id,
5725 fakeSigAlg2,
5726 },
5727 },
5728 flags: []string{
5729 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5730 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5731 "-enable-all-curves",
5732 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005733 shouldFail: shouldFail,
5734 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005735 expectedPeerSignatureAlgorithm: alg.id,
5736 })
5737
5738 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005739 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005740 config: Config{
5741 MaxVersion: ver.version,
5742 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005743 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005744 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005745 alg.id,
5746 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005747 Bugs: ProtocolBugs{
5748 SkipECDSACurveCheck: shouldFail,
5749 IgnoreSignatureVersionChecks: shouldFail,
5750 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005751 },
5752 flags: []string{
5753 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5754 "-enable-all-curves",
5755 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005756 shouldFail: shouldFail,
5757 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005758 })
David Benjamin5208fd42016-07-13 21:43:25 -04005759
5760 if !shouldFail {
5761 testCases = append(testCases, testCase{
5762 testType: serverTest,
5763 name: "ClientAuth-InvalidSignature" + suffix,
5764 config: Config{
5765 MaxVersion: ver.version,
5766 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5767 SignSignatureAlgorithms: []signatureAlgorithm{
5768 alg.id,
5769 },
5770 Bugs: ProtocolBugs{
5771 InvalidSignature: true,
5772 },
5773 },
5774 flags: []string{
5775 "-require-any-client-certificate",
5776 "-enable-all-curves",
5777 },
5778 shouldFail: true,
5779 expectedError: ":BAD_SIGNATURE:",
5780 })
5781
5782 testCases = append(testCases, testCase{
5783 name: "ServerAuth-InvalidSignature" + suffix,
5784 config: Config{
5785 MaxVersion: ver.version,
5786 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5787 CipherSuites: signingCiphers,
5788 SignSignatureAlgorithms: []signatureAlgorithm{
5789 alg.id,
5790 },
5791 Bugs: ProtocolBugs{
5792 InvalidSignature: true,
5793 },
5794 },
5795 flags: []string{"-enable-all-curves"},
5796 shouldFail: true,
5797 expectedError: ":BAD_SIGNATURE:",
5798 })
5799 }
David Benjaminca3d5452016-07-14 12:51:01 -04005800
5801 if ver.version >= VersionTLS12 && !shouldFail {
5802 testCases = append(testCases, testCase{
5803 name: "ClientAuth-Sign-Negotiate" + suffix,
5804 config: Config{
5805 MaxVersion: ver.version,
5806 ClientAuth: RequireAnyClientCert,
5807 VerifySignatureAlgorithms: allAlgorithms,
5808 },
5809 flags: []string{
5810 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5811 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5812 "-enable-all-curves",
5813 "-signing-prefs", strconv.Itoa(int(alg.id)),
5814 },
5815 expectedPeerSignatureAlgorithm: alg.id,
5816 })
5817
5818 testCases = append(testCases, testCase{
5819 testType: serverTest,
5820 name: "ServerAuth-Sign-Negotiate" + suffix,
5821 config: Config{
5822 MaxVersion: ver.version,
5823 CipherSuites: signingCiphers,
5824 VerifySignatureAlgorithms: allAlgorithms,
5825 },
5826 flags: []string{
5827 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5828 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5829 "-enable-all-curves",
5830 "-signing-prefs", strconv.Itoa(int(alg.id)),
5831 },
5832 expectedPeerSignatureAlgorithm: alg.id,
5833 })
5834 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005835 }
David Benjamin000800a2014-11-14 01:43:59 -05005836 }
5837
Nick Harper60edffd2016-06-21 15:19:24 -07005838 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005839 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005840 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005841 config: Config{
5842 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005843 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005844 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005845 signatureECDSAWithP521AndSHA512,
5846 signatureRSAPKCS1WithSHA384,
5847 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005848 },
5849 },
5850 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005851 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5852 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005853 },
Nick Harper60edffd2016-06-21 15:19:24 -07005854 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005855 })
5856
5857 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005858 name: "ClientAuth-SignatureType-TLS13",
5859 config: Config{
5860 ClientAuth: RequireAnyClientCert,
5861 MaxVersion: VersionTLS13,
5862 VerifySignatureAlgorithms: []signatureAlgorithm{
5863 signatureECDSAWithP521AndSHA512,
5864 signatureRSAPKCS1WithSHA384,
5865 signatureRSAPSSWithSHA384,
5866 signatureECDSAWithSHA1,
5867 },
5868 },
5869 flags: []string{
5870 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5871 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5872 },
5873 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5874 })
5875
5876 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005877 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005878 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005880 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005881 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005882 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005883 signatureECDSAWithP521AndSHA512,
5884 signatureRSAPKCS1WithSHA384,
5885 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005886 },
5887 },
Nick Harper60edffd2016-06-21 15:19:24 -07005888 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005889 })
5890
Steven Valdez143e8b32016-07-11 13:19:03 -04005891 testCases = append(testCases, testCase{
5892 testType: serverTest,
5893 name: "ServerAuth-SignatureType-TLS13",
5894 config: Config{
5895 MaxVersion: VersionTLS13,
5896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5897 VerifySignatureAlgorithms: []signatureAlgorithm{
5898 signatureECDSAWithP521AndSHA512,
5899 signatureRSAPKCS1WithSHA384,
5900 signatureRSAPSSWithSHA384,
5901 signatureECDSAWithSHA1,
5902 },
5903 },
5904 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5905 })
5906
David Benjamina95e9f32016-07-08 16:28:04 -07005907 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005908 testCases = append(testCases, testCase{
5909 testType: serverTest,
5910 name: "Verify-ClientAuth-SignatureType",
5911 config: Config{
5912 MaxVersion: VersionTLS12,
5913 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005914 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005915 signatureRSAPKCS1WithSHA256,
5916 },
5917 Bugs: ProtocolBugs{
5918 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5919 },
5920 },
5921 flags: []string{
5922 "-require-any-client-certificate",
5923 },
5924 shouldFail: true,
5925 expectedError: ":WRONG_SIGNATURE_TYPE:",
5926 })
5927
5928 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005929 testType: serverTest,
5930 name: "Verify-ClientAuth-SignatureType-TLS13",
5931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 Certificates: []Certificate{rsaCertificate},
5934 SignSignatureAlgorithms: []signatureAlgorithm{
5935 signatureRSAPSSWithSHA256,
5936 },
5937 Bugs: ProtocolBugs{
5938 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5939 },
5940 },
5941 flags: []string{
5942 "-require-any-client-certificate",
5943 },
5944 shouldFail: true,
5945 expectedError: ":WRONG_SIGNATURE_TYPE:",
5946 })
5947
5948 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005949 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005950 config: Config{
5951 MaxVersion: VersionTLS12,
5952 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005953 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005954 signatureRSAPKCS1WithSHA256,
5955 },
5956 Bugs: ProtocolBugs{
5957 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5958 },
5959 },
5960 shouldFail: true,
5961 expectedError: ":WRONG_SIGNATURE_TYPE:",
5962 })
5963
Steven Valdez143e8b32016-07-11 13:19:03 -04005964 testCases = append(testCases, testCase{
5965 name: "Verify-ServerAuth-SignatureType-TLS13",
5966 config: Config{
5967 MaxVersion: VersionTLS13,
5968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5969 SignSignatureAlgorithms: []signatureAlgorithm{
5970 signatureRSAPSSWithSHA256,
5971 },
5972 Bugs: ProtocolBugs{
5973 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5974 },
5975 },
5976 shouldFail: true,
5977 expectedError: ":WRONG_SIGNATURE_TYPE:",
5978 })
5979
David Benjamin51dd7d62016-07-08 16:07:01 -07005980 // Test that, if the list is missing, the peer falls back to SHA-1 in
5981 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005982 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005983 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005985 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005986 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005987 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005988 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005989 },
5990 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005991 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005992 },
5993 },
5994 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005995 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5996 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005997 },
5998 })
5999
6000 testCases = append(testCases, testCase{
6001 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006002 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006003 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006004 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006005 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006006 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006007 },
6008 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006009 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006010 },
6011 },
David Benjaminee32bea2016-08-17 13:36:44 -04006012 flags: []string{
6013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6015 },
6016 })
6017
6018 testCases = append(testCases, testCase{
6019 name: "ClientAuth-SHA1-Fallback-ECDSA",
6020 config: Config{
6021 MaxVersion: VersionTLS12,
6022 ClientAuth: RequireAnyClientCert,
6023 VerifySignatureAlgorithms: []signatureAlgorithm{
6024 signatureECDSAWithSHA1,
6025 },
6026 Bugs: ProtocolBugs{
6027 NoSignatureAlgorithms: true,
6028 },
6029 },
6030 flags: []string{
6031 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6032 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6033 },
6034 })
6035
6036 testCases = append(testCases, testCase{
6037 testType: serverTest,
6038 name: "ServerAuth-SHA1-Fallback-ECDSA",
6039 config: Config{
6040 MaxVersion: VersionTLS12,
6041 VerifySignatureAlgorithms: []signatureAlgorithm{
6042 signatureECDSAWithSHA1,
6043 },
6044 Bugs: ProtocolBugs{
6045 NoSignatureAlgorithms: true,
6046 },
6047 },
6048 flags: []string{
6049 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6050 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6051 },
David Benjamin000800a2014-11-14 01:43:59 -05006052 })
David Benjamin72dc7832015-03-16 17:49:43 -04006053
David Benjamin51dd7d62016-07-08 16:07:01 -07006054 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006055 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006056 config: Config{
6057 MaxVersion: VersionTLS13,
6058 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006059 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006060 signatureRSAPKCS1WithSHA1,
6061 },
6062 Bugs: ProtocolBugs{
6063 NoSignatureAlgorithms: true,
6064 },
6065 },
6066 flags: []string{
6067 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6068 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6069 },
David Benjamin48901652016-08-01 12:12:47 -04006070 shouldFail: true,
6071 // An empty CertificateRequest signature algorithm list is a
6072 // syntax error in TLS 1.3.
6073 expectedError: ":DECODE_ERROR:",
6074 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006075 })
6076
6077 testCases = append(testCases, testCase{
6078 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006079 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006080 config: Config{
6081 MaxVersion: VersionTLS13,
6082 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006083 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006084 signatureRSAPKCS1WithSHA1,
6085 },
6086 Bugs: ProtocolBugs{
6087 NoSignatureAlgorithms: true,
6088 },
6089 },
6090 shouldFail: true,
6091 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6092 })
6093
David Benjaminb62d2872016-07-18 14:55:02 +02006094 // Test that hash preferences are enforced. BoringSSL does not implement
6095 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006096 testCases = append(testCases, testCase{
6097 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006098 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006100 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006101 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006102 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006103 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006104 },
6105 Bugs: ProtocolBugs{
6106 IgnorePeerSignatureAlgorithmPreferences: true,
6107 },
6108 },
6109 flags: []string{"-require-any-client-certificate"},
6110 shouldFail: true,
6111 expectedError: ":WRONG_SIGNATURE_TYPE:",
6112 })
6113
6114 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006115 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006117 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006119 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006120 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006121 },
6122 Bugs: ProtocolBugs{
6123 IgnorePeerSignatureAlgorithmPreferences: true,
6124 },
6125 },
6126 shouldFail: true,
6127 expectedError: ":WRONG_SIGNATURE_TYPE:",
6128 })
David Benjaminb62d2872016-07-18 14:55:02 +02006129 testCases = append(testCases, testCase{
6130 testType: serverTest,
6131 name: "ClientAuth-Enforced-TLS13",
6132 config: Config{
6133 MaxVersion: VersionTLS13,
6134 Certificates: []Certificate{rsaCertificate},
6135 SignSignatureAlgorithms: []signatureAlgorithm{
6136 signatureRSAPKCS1WithMD5,
6137 },
6138 Bugs: ProtocolBugs{
6139 IgnorePeerSignatureAlgorithmPreferences: true,
6140 IgnoreSignatureVersionChecks: true,
6141 },
6142 },
6143 flags: []string{"-require-any-client-certificate"},
6144 shouldFail: true,
6145 expectedError: ":WRONG_SIGNATURE_TYPE:",
6146 })
6147
6148 testCases = append(testCases, testCase{
6149 name: "ServerAuth-Enforced-TLS13",
6150 config: Config{
6151 MaxVersion: VersionTLS13,
6152 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6153 SignSignatureAlgorithms: []signatureAlgorithm{
6154 signatureRSAPKCS1WithMD5,
6155 },
6156 Bugs: ProtocolBugs{
6157 IgnorePeerSignatureAlgorithmPreferences: true,
6158 IgnoreSignatureVersionChecks: true,
6159 },
6160 },
6161 shouldFail: true,
6162 expectedError: ":WRONG_SIGNATURE_TYPE:",
6163 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006164
6165 // Test that the agreed upon digest respects the client preferences and
6166 // the server digests.
6167 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006168 name: "NoCommonAlgorithms-Digests",
6169 config: Config{
6170 MaxVersion: VersionTLS12,
6171 ClientAuth: RequireAnyClientCert,
6172 VerifySignatureAlgorithms: []signatureAlgorithm{
6173 signatureRSAPKCS1WithSHA512,
6174 signatureRSAPKCS1WithSHA1,
6175 },
6176 },
6177 flags: []string{
6178 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6179 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6180 "-digest-prefs", "SHA256",
6181 },
6182 shouldFail: true,
6183 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6184 })
6185 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006186 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006188 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006189 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006190 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006191 signatureRSAPKCS1WithSHA512,
6192 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006193 },
6194 },
6195 flags: []string{
6196 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6197 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006198 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006199 },
David Benjaminca3d5452016-07-14 12:51:01 -04006200 shouldFail: true,
6201 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6202 })
6203 testCases = append(testCases, testCase{
6204 name: "NoCommonAlgorithms-TLS13",
6205 config: Config{
6206 MaxVersion: VersionTLS13,
6207 ClientAuth: RequireAnyClientCert,
6208 VerifySignatureAlgorithms: []signatureAlgorithm{
6209 signatureRSAPSSWithSHA512,
6210 signatureRSAPSSWithSHA384,
6211 },
6212 },
6213 flags: []string{
6214 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6215 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6216 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6217 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006218 shouldFail: true,
6219 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006220 })
6221 testCases = append(testCases, testCase{
6222 name: "Agree-Digest-SHA256",
6223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006224 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006225 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006226 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006227 signatureRSAPKCS1WithSHA1,
6228 signatureRSAPKCS1WithSHA256,
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),
David Benjaminca3d5452016-07-14 12:51:01 -04006234 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006235 },
Nick Harper60edffd2016-06-21 15:19:24 -07006236 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006237 })
6238 testCases = append(testCases, testCase{
6239 name: "Agree-Digest-SHA1",
6240 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006241 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006242 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006243 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006244 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006245 },
6246 },
6247 flags: []string{
6248 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6249 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006250 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006251 },
Nick Harper60edffd2016-06-21 15:19:24 -07006252 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006253 })
6254 testCases = append(testCases, testCase{
6255 name: "Agree-Digest-Default",
6256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006257 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006258 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006259 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006260 signatureRSAPKCS1WithSHA256,
6261 signatureECDSAWithP256AndSHA256,
6262 signatureRSAPKCS1WithSHA1,
6263 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006264 },
6265 },
6266 flags: []string{
6267 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6268 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6269 },
Nick Harper60edffd2016-06-21 15:19:24 -07006270 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006271 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006272
David Benjaminca3d5452016-07-14 12:51:01 -04006273 // Test that the signing preference list may include extra algorithms
6274 // without negotiation problems.
6275 testCases = append(testCases, testCase{
6276 testType: serverTest,
6277 name: "FilterExtraAlgorithms",
6278 config: Config{
6279 MaxVersion: VersionTLS12,
6280 VerifySignatureAlgorithms: []signatureAlgorithm{
6281 signatureRSAPKCS1WithSHA256,
6282 },
6283 },
6284 flags: []string{
6285 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6286 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6287 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6288 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6289 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6290 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6291 },
6292 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6293 })
6294
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6296 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006297 testCases = append(testCases, testCase{
6298 name: "CheckLeafCurve",
6299 config: Config{
6300 MaxVersion: VersionTLS12,
6301 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006302 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006303 },
6304 flags: []string{"-p384-only"},
6305 shouldFail: true,
6306 expectedError: ":BAD_ECC_CERT:",
6307 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006308
6309 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6310 testCases = append(testCases, testCase{
6311 name: "CheckLeafCurve-TLS13",
6312 config: Config{
6313 MaxVersion: VersionTLS13,
6314 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6315 Certificates: []Certificate{ecdsaP256Certificate},
6316 },
6317 flags: []string{"-p384-only"},
6318 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006319
6320 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6321 testCases = append(testCases, testCase{
6322 name: "ECDSACurveMismatch-Verify-TLS12",
6323 config: Config{
6324 MaxVersion: VersionTLS12,
6325 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6326 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006327 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006328 signatureECDSAWithP384AndSHA384,
6329 },
6330 },
6331 })
6332
6333 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6334 testCases = append(testCases, testCase{
6335 name: "ECDSACurveMismatch-Verify-TLS13",
6336 config: Config{
6337 MaxVersion: VersionTLS13,
6338 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6339 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006340 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006341 signatureECDSAWithP384AndSHA384,
6342 },
6343 Bugs: ProtocolBugs{
6344 SkipECDSACurveCheck: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedError: ":WRONG_SIGNATURE_TYPE:",
6349 })
6350
6351 // Signature algorithm selection in TLS 1.3 should take the curve into
6352 // account.
6353 testCases = append(testCases, testCase{
6354 testType: serverTest,
6355 name: "ECDSACurveMismatch-Sign-TLS13",
6356 config: Config{
6357 MaxVersion: VersionTLS13,
6358 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006359 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006360 signatureECDSAWithP384AndSHA384,
6361 signatureECDSAWithP256AndSHA256,
6362 },
6363 },
6364 flags: []string{
6365 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6366 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6367 },
6368 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6369 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006370
6371 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6372 // server does not attempt to sign in that case.
6373 testCases = append(testCases, testCase{
6374 testType: serverTest,
6375 name: "RSA-PSS-Large",
6376 config: Config{
6377 MaxVersion: VersionTLS13,
6378 VerifySignatureAlgorithms: []signatureAlgorithm{
6379 signatureRSAPSSWithSHA512,
6380 },
6381 },
6382 flags: []string{
6383 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6384 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6385 },
6386 shouldFail: true,
6387 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6388 })
David Benjamin57e929f2016-08-30 00:30:38 -04006389
6390 // Test that RSA-PSS is enabled by default for TLS 1.2.
6391 testCases = append(testCases, testCase{
6392 testType: clientTest,
6393 name: "RSA-PSS-Default-Verify",
6394 config: Config{
6395 MaxVersion: VersionTLS12,
6396 SignSignatureAlgorithms: []signatureAlgorithm{
6397 signatureRSAPSSWithSHA256,
6398 },
6399 },
6400 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6401 })
6402
6403 testCases = append(testCases, testCase{
6404 testType: serverTest,
6405 name: "RSA-PSS-Default-Sign",
6406 config: Config{
6407 MaxVersion: VersionTLS12,
6408 VerifySignatureAlgorithms: []signatureAlgorithm{
6409 signatureRSAPSSWithSHA256,
6410 },
6411 },
6412 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6413 })
David Benjamin000800a2014-11-14 01:43:59 -05006414}
6415
David Benjamin83f90402015-01-27 01:09:43 -05006416// timeouts is the retransmit schedule for BoringSSL. It doubles and
6417// caps at 60 seconds. On the 13th timeout, it gives up.
6418var timeouts = []time.Duration{
6419 1 * time.Second,
6420 2 * time.Second,
6421 4 * time.Second,
6422 8 * time.Second,
6423 16 * time.Second,
6424 32 * time.Second,
6425 60 * time.Second,
6426 60 * time.Second,
6427 60 * time.Second,
6428 60 * time.Second,
6429 60 * time.Second,
6430 60 * time.Second,
6431 60 * time.Second,
6432}
6433
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006434// shortTimeouts is an alternate set of timeouts which would occur if the
6435// initial timeout duration was set to 250ms.
6436var shortTimeouts = []time.Duration{
6437 250 * time.Millisecond,
6438 500 * time.Millisecond,
6439 1 * time.Second,
6440 2 * time.Second,
6441 4 * time.Second,
6442 8 * time.Second,
6443 16 * time.Second,
6444 32 * time.Second,
6445 60 * time.Second,
6446 60 * time.Second,
6447 60 * time.Second,
6448 60 * time.Second,
6449 60 * time.Second,
6450}
6451
David Benjamin83f90402015-01-27 01:09:43 -05006452func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006453 // These tests work by coordinating some behavior on both the shim and
6454 // the runner.
6455 //
6456 // TimeoutSchedule configures the runner to send a series of timeout
6457 // opcodes to the shim (see packetAdaptor) immediately before reading
6458 // each peer handshake flight N. The timeout opcode both simulates a
6459 // timeout in the shim and acts as a synchronization point to help the
6460 // runner bracket each handshake flight.
6461 //
6462 // We assume the shim does not read from the channel eagerly. It must
6463 // first wait until it has sent flight N and is ready to receive
6464 // handshake flight N+1. At this point, it will process the timeout
6465 // opcode. It must then immediately respond with a timeout ACK and act
6466 // as if the shim was idle for the specified amount of time.
6467 //
6468 // The runner then drops all packets received before the ACK and
6469 // continues waiting for flight N. This ordering results in one attempt
6470 // at sending flight N to be dropped. For the test to complete, the
6471 // shim must send flight N again, testing that the shim implements DTLS
6472 // retransmit on a timeout.
6473
Steven Valdez143e8b32016-07-11 13:19:03 -04006474 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006475 // likely be more epochs to cross and the final message's retransmit may
6476 // be more complex.
6477
David Benjamin585d7a42016-06-02 14:58:00 -04006478 for _, async := range []bool{true, false} {
6479 var tests []testCase
6480
6481 // Test that this is indeed the timeout schedule. Stress all
6482 // four patterns of handshake.
6483 for i := 1; i < len(timeouts); i++ {
6484 number := strconv.Itoa(i)
6485 tests = append(tests, testCase{
6486 protocol: dtls,
6487 name: "DTLS-Retransmit-Client-" + number,
6488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006489 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006490 Bugs: ProtocolBugs{
6491 TimeoutSchedule: timeouts[:i],
6492 },
6493 },
6494 resumeSession: true,
6495 })
6496 tests = append(tests, testCase{
6497 protocol: dtls,
6498 testType: serverTest,
6499 name: "DTLS-Retransmit-Server-" + number,
6500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006501 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006502 Bugs: ProtocolBugs{
6503 TimeoutSchedule: timeouts[:i],
6504 },
6505 },
6506 resumeSession: true,
6507 })
6508 }
6509
6510 // Test that exceeding the timeout schedule hits a read
6511 // timeout.
6512 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006513 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006514 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006517 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006518 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006519 },
6520 },
6521 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006522 shouldFail: true,
6523 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006524 })
David Benjamin585d7a42016-06-02 14:58:00 -04006525
6526 if async {
6527 // Test that timeout handling has a fudge factor, due to API
6528 // problems.
6529 tests = append(tests, testCase{
6530 protocol: dtls,
6531 name: "DTLS-Retransmit-Fudge",
6532 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006533 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006534 Bugs: ProtocolBugs{
6535 TimeoutSchedule: []time.Duration{
6536 timeouts[0] - 10*time.Millisecond,
6537 },
6538 },
6539 },
6540 resumeSession: true,
6541 })
6542 }
6543
6544 // Test that the final Finished retransmitting isn't
6545 // duplicated if the peer badly fragments everything.
6546 tests = append(tests, testCase{
6547 testType: serverTest,
6548 protocol: dtls,
6549 name: "DTLS-Retransmit-Fragmented",
6550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006551 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006552 Bugs: ProtocolBugs{
6553 TimeoutSchedule: []time.Duration{timeouts[0]},
6554 MaxHandshakeRecordLength: 2,
6555 },
6556 },
6557 })
6558
6559 // Test the timeout schedule when a shorter initial timeout duration is set.
6560 tests = append(tests, testCase{
6561 protocol: dtls,
6562 name: "DTLS-Retransmit-Short-Client",
6563 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006564 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006565 Bugs: ProtocolBugs{
6566 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6567 },
6568 },
6569 resumeSession: true,
6570 flags: []string{"-initial-timeout-duration-ms", "250"},
6571 })
6572 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006573 protocol: dtls,
6574 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006575 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006576 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006577 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006578 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006579 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006580 },
6581 },
6582 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006583 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006584 })
David Benjamin585d7a42016-06-02 14:58:00 -04006585
6586 for _, test := range tests {
6587 if async {
6588 test.name += "-Async"
6589 test.flags = append(test.flags, "-async")
6590 }
6591
6592 testCases = append(testCases, test)
6593 }
David Benjamin83f90402015-01-27 01:09:43 -05006594 }
David Benjamin83f90402015-01-27 01:09:43 -05006595}
6596
David Benjaminc565ebb2015-04-03 04:06:36 -04006597func addExportKeyingMaterialTests() {
6598 for _, vers := range tlsVersions {
6599 if vers.version == VersionSSL30 {
6600 continue
6601 }
6602 testCases = append(testCases, testCase{
6603 name: "ExportKeyingMaterial-" + vers.name,
6604 config: Config{
6605 MaxVersion: vers.version,
6606 },
6607 exportKeyingMaterial: 1024,
6608 exportLabel: "label",
6609 exportContext: "context",
6610 useExportContext: true,
6611 })
6612 testCases = append(testCases, testCase{
6613 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6614 config: Config{
6615 MaxVersion: vers.version,
6616 },
6617 exportKeyingMaterial: 1024,
6618 })
6619 testCases = append(testCases, testCase{
6620 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6621 config: Config{
6622 MaxVersion: vers.version,
6623 },
6624 exportKeyingMaterial: 1024,
6625 useExportContext: true,
6626 })
6627 testCases = append(testCases, testCase{
6628 name: "ExportKeyingMaterial-Small-" + vers.name,
6629 config: Config{
6630 MaxVersion: vers.version,
6631 },
6632 exportKeyingMaterial: 1,
6633 exportLabel: "label",
6634 exportContext: "context",
6635 useExportContext: true,
6636 })
6637 }
6638 testCases = append(testCases, testCase{
6639 name: "ExportKeyingMaterial-SSL3",
6640 config: Config{
6641 MaxVersion: VersionSSL30,
6642 },
6643 exportKeyingMaterial: 1024,
6644 exportLabel: "label",
6645 exportContext: "context",
6646 useExportContext: true,
6647 shouldFail: true,
6648 expectedError: "failed to export keying material",
6649 })
6650}
6651
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006652func addTLSUniqueTests() {
6653 for _, isClient := range []bool{false, true} {
6654 for _, isResumption := range []bool{false, true} {
6655 for _, hasEMS := range []bool{false, true} {
6656 var suffix string
6657 if isResumption {
6658 suffix = "Resume-"
6659 } else {
6660 suffix = "Full-"
6661 }
6662
6663 if hasEMS {
6664 suffix += "EMS-"
6665 } else {
6666 suffix += "NoEMS-"
6667 }
6668
6669 if isClient {
6670 suffix += "Client"
6671 } else {
6672 suffix += "Server"
6673 }
6674
6675 test := testCase{
6676 name: "TLSUnique-" + suffix,
6677 testTLSUnique: true,
6678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006679 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006680 Bugs: ProtocolBugs{
6681 NoExtendedMasterSecret: !hasEMS,
6682 },
6683 },
6684 }
6685
6686 if isResumption {
6687 test.resumeSession = true
6688 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006689 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006690 Bugs: ProtocolBugs{
6691 NoExtendedMasterSecret: !hasEMS,
6692 },
6693 }
6694 }
6695
6696 if isResumption && !hasEMS {
6697 test.shouldFail = true
6698 test.expectedError = "failed to get tls-unique"
6699 }
6700
6701 testCases = append(testCases, test)
6702 }
6703 }
6704 }
6705}
6706
Adam Langley09505632015-07-30 18:10:13 -07006707func addCustomExtensionTests() {
6708 expectedContents := "custom extension"
6709 emptyString := ""
6710
6711 for _, isClient := range []bool{false, true} {
6712 suffix := "Server"
6713 flag := "-enable-server-custom-extension"
6714 testType := serverTest
6715 if isClient {
6716 suffix = "Client"
6717 flag = "-enable-client-custom-extension"
6718 testType = clientTest
6719 }
6720
6721 testCases = append(testCases, testCase{
6722 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006723 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006725 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006726 Bugs: ProtocolBugs{
6727 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006728 ExpectedCustomExtension: &expectedContents,
6729 },
6730 },
6731 flags: []string{flag},
6732 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006733 testCases = append(testCases, testCase{
6734 testType: testType,
6735 name: "CustomExtensions-" + suffix + "-TLS13",
6736 config: Config{
6737 MaxVersion: VersionTLS13,
6738 Bugs: ProtocolBugs{
6739 CustomExtension: expectedContents,
6740 ExpectedCustomExtension: &expectedContents,
6741 },
6742 },
6743 flags: []string{flag},
6744 })
Adam Langley09505632015-07-30 18:10:13 -07006745
6746 // If the parse callback fails, the handshake should also fail.
6747 testCases = append(testCases, testCase{
6748 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006749 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006751 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006752 Bugs: ProtocolBugs{
6753 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006754 ExpectedCustomExtension: &expectedContents,
6755 },
6756 },
David Benjamin399e7c92015-07-30 23:01:27 -04006757 flags: []string{flag},
6758 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006759 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6760 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006761 testCases = append(testCases, testCase{
6762 testType: testType,
6763 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6764 config: Config{
6765 MaxVersion: VersionTLS13,
6766 Bugs: ProtocolBugs{
6767 CustomExtension: expectedContents + "foo",
6768 ExpectedCustomExtension: &expectedContents,
6769 },
6770 },
6771 flags: []string{flag},
6772 shouldFail: true,
6773 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6774 })
Adam Langley09505632015-07-30 18:10:13 -07006775
6776 // If the add callback fails, the handshake should also fail.
6777 testCases = append(testCases, testCase{
6778 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006779 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006781 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006782 Bugs: ProtocolBugs{
6783 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006784 ExpectedCustomExtension: &expectedContents,
6785 },
6786 },
David Benjamin399e7c92015-07-30 23:01:27 -04006787 flags: []string{flag, "-custom-extension-fail-add"},
6788 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006789 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6790 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006791 testCases = append(testCases, testCase{
6792 testType: testType,
6793 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6794 config: Config{
6795 MaxVersion: VersionTLS13,
6796 Bugs: ProtocolBugs{
6797 CustomExtension: expectedContents,
6798 ExpectedCustomExtension: &expectedContents,
6799 },
6800 },
6801 flags: []string{flag, "-custom-extension-fail-add"},
6802 shouldFail: true,
6803 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6804 })
Adam Langley09505632015-07-30 18:10:13 -07006805
6806 // If the add callback returns zero, no extension should be
6807 // added.
6808 skipCustomExtension := expectedContents
6809 if isClient {
6810 // For the case where the client skips sending the
6811 // custom extension, the server must not “echo” it.
6812 skipCustomExtension = ""
6813 }
6814 testCases = append(testCases, testCase{
6815 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006816 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006818 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006819 Bugs: ProtocolBugs{
6820 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006821 ExpectedCustomExtension: &emptyString,
6822 },
6823 },
6824 flags: []string{flag, "-custom-extension-skip"},
6825 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006826 testCases = append(testCases, testCase{
6827 testType: testType,
6828 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6829 config: Config{
6830 MaxVersion: VersionTLS13,
6831 Bugs: ProtocolBugs{
6832 CustomExtension: skipCustomExtension,
6833 ExpectedCustomExtension: &emptyString,
6834 },
6835 },
6836 flags: []string{flag, "-custom-extension-skip"},
6837 })
Adam Langley09505632015-07-30 18:10:13 -07006838 }
6839
6840 // The custom extension add callback should not be called if the client
6841 // doesn't send the extension.
6842 testCases = append(testCases, testCase{
6843 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006844 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006846 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006847 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006848 ExpectedCustomExtension: &emptyString,
6849 },
6850 },
6851 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6852 })
Adam Langley2deb9842015-08-07 11:15:37 -07006853
Steven Valdez143e8b32016-07-11 13:19:03 -04006854 testCases = append(testCases, testCase{
6855 testType: serverTest,
6856 name: "CustomExtensions-NotCalled-Server-TLS13",
6857 config: Config{
6858 MaxVersion: VersionTLS13,
6859 Bugs: ProtocolBugs{
6860 ExpectedCustomExtension: &emptyString,
6861 },
6862 },
6863 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6864 })
6865
Adam Langley2deb9842015-08-07 11:15:37 -07006866 // Test an unknown extension from the server.
6867 testCases = append(testCases, testCase{
6868 testType: clientTest,
6869 name: "UnknownExtension-Client",
6870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006871 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006872 Bugs: ProtocolBugs{
6873 CustomExtension: expectedContents,
6874 },
6875 },
David Benjamin0c40a962016-08-01 12:05:50 -04006876 shouldFail: true,
6877 expectedError: ":UNEXPECTED_EXTENSION:",
6878 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006879 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006880 testCases = append(testCases, testCase{
6881 testType: clientTest,
6882 name: "UnknownExtension-Client-TLS13",
6883 config: Config{
6884 MaxVersion: VersionTLS13,
6885 Bugs: ProtocolBugs{
6886 CustomExtension: expectedContents,
6887 },
6888 },
David Benjamin0c40a962016-08-01 12:05:50 -04006889 shouldFail: true,
6890 expectedError: ":UNEXPECTED_EXTENSION:",
6891 expectedLocalError: "remote error: unsupported extension",
6892 })
6893
6894 // Test a known but unoffered extension from the server.
6895 testCases = append(testCases, testCase{
6896 testType: clientTest,
6897 name: "UnofferedExtension-Client",
6898 config: Config{
6899 MaxVersion: VersionTLS12,
6900 Bugs: ProtocolBugs{
6901 SendALPN: "alpn",
6902 },
6903 },
6904 shouldFail: true,
6905 expectedError: ":UNEXPECTED_EXTENSION:",
6906 expectedLocalError: "remote error: unsupported extension",
6907 })
6908 testCases = append(testCases, testCase{
6909 testType: clientTest,
6910 name: "UnofferedExtension-Client-TLS13",
6911 config: Config{
6912 MaxVersion: VersionTLS13,
6913 Bugs: ProtocolBugs{
6914 SendALPN: "alpn",
6915 },
6916 },
6917 shouldFail: true,
6918 expectedError: ":UNEXPECTED_EXTENSION:",
6919 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006920 })
Adam Langley09505632015-07-30 18:10:13 -07006921}
6922
David Benjaminb36a3952015-12-01 18:53:13 -05006923func addRSAClientKeyExchangeTests() {
6924 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6925 testCases = append(testCases, testCase{
6926 testType: serverTest,
6927 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6928 config: Config{
6929 // Ensure the ClientHello version and final
6930 // version are different, to detect if the
6931 // server uses the wrong one.
6932 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006933 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006934 Bugs: ProtocolBugs{
6935 BadRSAClientKeyExchange: bad,
6936 },
6937 },
6938 shouldFail: true,
6939 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6940 })
6941 }
David Benjamine63d9d72016-09-19 18:27:34 -04006942
6943 // The server must compare whatever was in ClientHello.version for the
6944 // RSA premaster.
6945 testCases = append(testCases, testCase{
6946 testType: serverTest,
6947 name: "SendClientVersion-RSA",
6948 config: Config{
6949 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6950 Bugs: ProtocolBugs{
6951 SendClientVersion: 0x1234,
6952 },
6953 },
6954 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6955 })
David Benjaminb36a3952015-12-01 18:53:13 -05006956}
6957
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006958var testCurves = []struct {
6959 name string
6960 id CurveID
6961}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006962 {"P-256", CurveP256},
6963 {"P-384", CurveP384},
6964 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006965 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006966}
6967
Steven Valdez5440fe02016-07-18 12:40:30 -04006968const bogusCurve = 0x1234
6969
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006970func addCurveTests() {
6971 for _, curve := range testCurves {
6972 testCases = append(testCases, testCase{
6973 name: "CurveTest-Client-" + curve.name,
6974 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006975 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006976 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6977 CurvePreferences: []CurveID{curve.id},
6978 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006979 flags: []string{
6980 "-enable-all-curves",
6981 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6982 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006983 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006984 })
6985 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006986 name: "CurveTest-Client-" + curve.name + "-TLS13",
6987 config: Config{
6988 MaxVersion: VersionTLS13,
6989 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6990 CurvePreferences: []CurveID{curve.id},
6991 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006992 flags: []string{
6993 "-enable-all-curves",
6994 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6995 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006996 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006997 })
6998 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006999 testType: serverTest,
7000 name: "CurveTest-Server-" + curve.name,
7001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007002 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7004 CurvePreferences: []CurveID{curve.id},
7005 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007006 flags: []string{
7007 "-enable-all-curves",
7008 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7009 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007010 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007011 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007012 testCases = append(testCases, testCase{
7013 testType: serverTest,
7014 name: "CurveTest-Server-" + curve.name + "-TLS13",
7015 config: Config{
7016 MaxVersion: VersionTLS13,
7017 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7018 CurvePreferences: []CurveID{curve.id},
7019 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007020 flags: []string{
7021 "-enable-all-curves",
7022 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7023 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007024 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007025 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007026 }
David Benjamin241ae832016-01-15 03:04:54 -05007027
7028 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007029 testCases = append(testCases, testCase{
7030 testType: serverTest,
7031 name: "UnknownCurve",
7032 config: Config{
7033 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7034 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7035 },
7036 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007037
7038 // The server must not consider ECDHE ciphers when there are no
7039 // supported curves.
7040 testCases = append(testCases, testCase{
7041 testType: serverTest,
7042 name: "NoSupportedCurves",
7043 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007044 MaxVersion: VersionTLS12,
7045 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7046 Bugs: ProtocolBugs{
7047 NoSupportedCurves: true,
7048 },
7049 },
7050 shouldFail: true,
7051 expectedError: ":NO_SHARED_CIPHER:",
7052 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007053 testCases = append(testCases, testCase{
7054 testType: serverTest,
7055 name: "NoSupportedCurves-TLS13",
7056 config: Config{
7057 MaxVersion: VersionTLS13,
7058 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7059 Bugs: ProtocolBugs{
7060 NoSupportedCurves: true,
7061 },
7062 },
7063 shouldFail: true,
7064 expectedError: ":NO_SHARED_CIPHER:",
7065 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007066
7067 // The server must fall back to another cipher when there are no
7068 // supported curves.
7069 testCases = append(testCases, testCase{
7070 testType: serverTest,
7071 name: "NoCommonCurves",
7072 config: Config{
7073 MaxVersion: VersionTLS12,
7074 CipherSuites: []uint16{
7075 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7076 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7077 },
7078 CurvePreferences: []CurveID{CurveP224},
7079 },
7080 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7081 })
7082
7083 // The client must reject bogus curves and disabled curves.
7084 testCases = append(testCases, testCase{
7085 name: "BadECDHECurve",
7086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007087 MaxVersion: VersionTLS12,
7088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7089 Bugs: ProtocolBugs{
7090 SendCurve: bogusCurve,
7091 },
7092 },
7093 shouldFail: true,
7094 expectedError: ":WRONG_CURVE:",
7095 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007096 testCases = append(testCases, testCase{
7097 name: "BadECDHECurve-TLS13",
7098 config: Config{
7099 MaxVersion: VersionTLS13,
7100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7101 Bugs: ProtocolBugs{
7102 SendCurve: bogusCurve,
7103 },
7104 },
7105 shouldFail: true,
7106 expectedError: ":WRONG_CURVE:",
7107 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007108
7109 testCases = append(testCases, testCase{
7110 name: "UnsupportedCurve",
7111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007112 MaxVersion: VersionTLS12,
7113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7114 CurvePreferences: []CurveID{CurveP256},
7115 Bugs: ProtocolBugs{
7116 IgnorePeerCurvePreferences: true,
7117 },
7118 },
7119 flags: []string{"-p384-only"},
7120 shouldFail: true,
7121 expectedError: ":WRONG_CURVE:",
7122 })
7123
David Benjamin4f921572016-07-17 14:20:10 +02007124 testCases = append(testCases, testCase{
7125 // TODO(davidben): Add a TLS 1.3 version where
7126 // HelloRetryRequest requests an unsupported curve.
7127 name: "UnsupportedCurve-ServerHello-TLS13",
7128 config: Config{
7129 MaxVersion: VersionTLS12,
7130 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7131 CurvePreferences: []CurveID{CurveP384},
7132 Bugs: ProtocolBugs{
7133 SendCurve: CurveP256,
7134 },
7135 },
7136 flags: []string{"-p384-only"},
7137 shouldFail: true,
7138 expectedError: ":WRONG_CURVE:",
7139 })
7140
David Benjamin4c3ddf72016-06-29 18:13:53 -04007141 // Test invalid curve points.
7142 testCases = append(testCases, testCase{
7143 name: "InvalidECDHPoint-Client",
7144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007145 MaxVersion: VersionTLS12,
7146 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7147 CurvePreferences: []CurveID{CurveP256},
7148 Bugs: ProtocolBugs{
7149 InvalidECDHPoint: true,
7150 },
7151 },
7152 shouldFail: true,
7153 expectedError: ":INVALID_ENCODING:",
7154 })
7155 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007156 name: "InvalidECDHPoint-Client-TLS13",
7157 config: Config{
7158 MaxVersion: VersionTLS13,
7159 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7160 CurvePreferences: []CurveID{CurveP256},
7161 Bugs: ProtocolBugs{
7162 InvalidECDHPoint: true,
7163 },
7164 },
7165 shouldFail: true,
7166 expectedError: ":INVALID_ENCODING:",
7167 })
7168 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007169 testType: serverTest,
7170 name: "InvalidECDHPoint-Server",
7171 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007172 MaxVersion: VersionTLS12,
7173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7174 CurvePreferences: []CurveID{CurveP256},
7175 Bugs: ProtocolBugs{
7176 InvalidECDHPoint: true,
7177 },
7178 },
7179 shouldFail: true,
7180 expectedError: ":INVALID_ENCODING:",
7181 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007182 testCases = append(testCases, testCase{
7183 testType: serverTest,
7184 name: "InvalidECDHPoint-Server-TLS13",
7185 config: Config{
7186 MaxVersion: VersionTLS13,
7187 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7188 CurvePreferences: []CurveID{CurveP256},
7189 Bugs: ProtocolBugs{
7190 InvalidECDHPoint: true,
7191 },
7192 },
7193 shouldFail: true,
7194 expectedError: ":INVALID_ENCODING:",
7195 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007196}
7197
Matt Braithwaite54217e42016-06-13 13:03:47 -07007198func addCECPQ1Tests() {
7199 testCases = append(testCases, testCase{
7200 testType: clientTest,
7201 name: "CECPQ1-Client-BadX25519Part",
7202 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007203 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007204 MinVersion: VersionTLS12,
7205 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7206 Bugs: ProtocolBugs{
7207 CECPQ1BadX25519Part: true,
7208 },
7209 },
7210 flags: []string{"-cipher", "kCECPQ1"},
7211 shouldFail: true,
7212 expectedLocalError: "local error: bad record MAC",
7213 })
7214 testCases = append(testCases, testCase{
7215 testType: clientTest,
7216 name: "CECPQ1-Client-BadNewhopePart",
7217 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007218 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007219 MinVersion: VersionTLS12,
7220 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7221 Bugs: ProtocolBugs{
7222 CECPQ1BadNewhopePart: true,
7223 },
7224 },
7225 flags: []string{"-cipher", "kCECPQ1"},
7226 shouldFail: true,
7227 expectedLocalError: "local error: bad record MAC",
7228 })
7229 testCases = append(testCases, testCase{
7230 testType: serverTest,
7231 name: "CECPQ1-Server-BadX25519Part",
7232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007233 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007234 MinVersion: VersionTLS12,
7235 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7236 Bugs: ProtocolBugs{
7237 CECPQ1BadX25519Part: true,
7238 },
7239 },
7240 flags: []string{"-cipher", "kCECPQ1"},
7241 shouldFail: true,
7242 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7243 })
7244 testCases = append(testCases, testCase{
7245 testType: serverTest,
7246 name: "CECPQ1-Server-BadNewhopePart",
7247 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007248 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007249 MinVersion: VersionTLS12,
7250 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7251 Bugs: ProtocolBugs{
7252 CECPQ1BadNewhopePart: true,
7253 },
7254 },
7255 flags: []string{"-cipher", "kCECPQ1"},
7256 shouldFail: true,
7257 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7258 })
7259}
7260
David Benjamin5c4e8572016-08-19 17:44:53 -04007261func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007262 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007263 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007264 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007265 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007266 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7267 Bugs: ProtocolBugs{
7268 // This is a 1234-bit prime number, generated
7269 // with:
7270 // openssl gendh 1234 | openssl asn1parse -i
7271 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7272 },
7273 },
David Benjamin9e68f192016-06-30 14:55:33 -04007274 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007275 })
7276 testCases = append(testCases, testCase{
7277 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007278 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007279 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007280 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007281 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7282 },
7283 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007284 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007285 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007286}
7287
David Benjaminc9ae27c2016-06-24 22:56:37 -04007288func addTLS13RecordTests() {
7289 testCases = append(testCases, testCase{
7290 name: "TLS13-RecordPadding",
7291 config: Config{
7292 MaxVersion: VersionTLS13,
7293 MinVersion: VersionTLS13,
7294 Bugs: ProtocolBugs{
7295 RecordPadding: 10,
7296 },
7297 },
7298 })
7299
7300 testCases = append(testCases, testCase{
7301 name: "TLS13-EmptyRecords",
7302 config: Config{
7303 MaxVersion: VersionTLS13,
7304 MinVersion: VersionTLS13,
7305 Bugs: ProtocolBugs{
7306 OmitRecordContents: true,
7307 },
7308 },
7309 shouldFail: true,
7310 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7311 })
7312
7313 testCases = append(testCases, testCase{
7314 name: "TLS13-OnlyPadding",
7315 config: Config{
7316 MaxVersion: VersionTLS13,
7317 MinVersion: VersionTLS13,
7318 Bugs: ProtocolBugs{
7319 OmitRecordContents: true,
7320 RecordPadding: 10,
7321 },
7322 },
7323 shouldFail: true,
7324 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7325 })
7326
7327 testCases = append(testCases, testCase{
7328 name: "TLS13-WrongOuterRecord",
7329 config: Config{
7330 MaxVersion: VersionTLS13,
7331 MinVersion: VersionTLS13,
7332 Bugs: ProtocolBugs{
7333 OuterRecordType: recordTypeHandshake,
7334 },
7335 },
7336 shouldFail: true,
7337 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7338 })
7339}
7340
David Benjamin82261be2016-07-07 14:32:50 -07007341func addChangeCipherSpecTests() {
7342 // Test missing ChangeCipherSpecs.
7343 testCases = append(testCases, testCase{
7344 name: "SkipChangeCipherSpec-Client",
7345 config: Config{
7346 MaxVersion: VersionTLS12,
7347 Bugs: ProtocolBugs{
7348 SkipChangeCipherSpec: true,
7349 },
7350 },
7351 shouldFail: true,
7352 expectedError: ":UNEXPECTED_RECORD:",
7353 })
7354 testCases = append(testCases, testCase{
7355 testType: serverTest,
7356 name: "SkipChangeCipherSpec-Server",
7357 config: Config{
7358 MaxVersion: VersionTLS12,
7359 Bugs: ProtocolBugs{
7360 SkipChangeCipherSpec: true,
7361 },
7362 },
7363 shouldFail: true,
7364 expectedError: ":UNEXPECTED_RECORD:",
7365 })
7366 testCases = append(testCases, testCase{
7367 testType: serverTest,
7368 name: "SkipChangeCipherSpec-Server-NPN",
7369 config: Config{
7370 MaxVersion: VersionTLS12,
7371 NextProtos: []string{"bar"},
7372 Bugs: ProtocolBugs{
7373 SkipChangeCipherSpec: true,
7374 },
7375 },
7376 flags: []string{
7377 "-advertise-npn", "\x03foo\x03bar\x03baz",
7378 },
7379 shouldFail: true,
7380 expectedError: ":UNEXPECTED_RECORD:",
7381 })
7382
7383 // Test synchronization between the handshake and ChangeCipherSpec.
7384 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7385 // rejected. Test both with and without handshake packing to handle both
7386 // when the partial post-CCS message is in its own record and when it is
7387 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007388 for _, packed := range []bool{false, true} {
7389 var suffix string
7390 if packed {
7391 suffix = "-Packed"
7392 }
7393
7394 testCases = append(testCases, testCase{
7395 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7396 config: Config{
7397 MaxVersion: VersionTLS12,
7398 Bugs: ProtocolBugs{
7399 FragmentAcrossChangeCipherSpec: true,
7400 PackHandshakeFlight: packed,
7401 },
7402 },
7403 shouldFail: true,
7404 expectedError: ":UNEXPECTED_RECORD:",
7405 })
7406 testCases = append(testCases, testCase{
7407 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7408 config: Config{
7409 MaxVersion: VersionTLS12,
7410 },
7411 resumeSession: true,
7412 resumeConfig: &Config{
7413 MaxVersion: VersionTLS12,
7414 Bugs: ProtocolBugs{
7415 FragmentAcrossChangeCipherSpec: true,
7416 PackHandshakeFlight: packed,
7417 },
7418 },
7419 shouldFail: true,
7420 expectedError: ":UNEXPECTED_RECORD:",
7421 })
7422 testCases = append(testCases, testCase{
7423 testType: serverTest,
7424 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7425 config: Config{
7426 MaxVersion: VersionTLS12,
7427 Bugs: ProtocolBugs{
7428 FragmentAcrossChangeCipherSpec: true,
7429 PackHandshakeFlight: packed,
7430 },
7431 },
7432 shouldFail: true,
7433 expectedError: ":UNEXPECTED_RECORD:",
7434 })
7435 testCases = append(testCases, testCase{
7436 testType: serverTest,
7437 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7438 config: Config{
7439 MaxVersion: VersionTLS12,
7440 },
7441 resumeSession: true,
7442 resumeConfig: &Config{
7443 MaxVersion: VersionTLS12,
7444 Bugs: ProtocolBugs{
7445 FragmentAcrossChangeCipherSpec: true,
7446 PackHandshakeFlight: packed,
7447 },
7448 },
7449 shouldFail: true,
7450 expectedError: ":UNEXPECTED_RECORD:",
7451 })
7452 testCases = append(testCases, testCase{
7453 testType: serverTest,
7454 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7455 config: Config{
7456 MaxVersion: VersionTLS12,
7457 NextProtos: []string{"bar"},
7458 Bugs: ProtocolBugs{
7459 FragmentAcrossChangeCipherSpec: true,
7460 PackHandshakeFlight: packed,
7461 },
7462 },
7463 flags: []string{
7464 "-advertise-npn", "\x03foo\x03bar\x03baz",
7465 },
7466 shouldFail: true,
7467 expectedError: ":UNEXPECTED_RECORD:",
7468 })
7469 }
7470
David Benjamin61672812016-07-14 23:10:43 -04007471 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7472 // messages in the handshake queue. Do this by testing the server
7473 // reading the client Finished, reversing the flight so Finished comes
7474 // first.
7475 testCases = append(testCases, testCase{
7476 protocol: dtls,
7477 testType: serverTest,
7478 name: "SendUnencryptedFinished-DTLS",
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 Bugs: ProtocolBugs{
7482 SendUnencryptedFinished: true,
7483 ReverseHandshakeFragments: true,
7484 },
7485 },
7486 shouldFail: true,
7487 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7488 })
7489
Steven Valdez143e8b32016-07-11 13:19:03 -04007490 // Test synchronization between encryption changes and the handshake in
7491 // TLS 1.3, where ChangeCipherSpec is implicit.
7492 testCases = append(testCases, testCase{
7493 name: "PartialEncryptedExtensionsWithServerHello",
7494 config: Config{
7495 MaxVersion: VersionTLS13,
7496 Bugs: ProtocolBugs{
7497 PartialEncryptedExtensionsWithServerHello: true,
7498 },
7499 },
7500 shouldFail: true,
7501 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7502 })
7503 testCases = append(testCases, testCase{
7504 testType: serverTest,
7505 name: "PartialClientFinishedWithClientHello",
7506 config: Config{
7507 MaxVersion: VersionTLS13,
7508 Bugs: ProtocolBugs{
7509 PartialClientFinishedWithClientHello: true,
7510 },
7511 },
7512 shouldFail: true,
7513 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7514 })
7515
David Benjamin82261be2016-07-07 14:32:50 -07007516 // Test that early ChangeCipherSpecs are handled correctly.
7517 testCases = append(testCases, testCase{
7518 testType: serverTest,
7519 name: "EarlyChangeCipherSpec-server-1",
7520 config: Config{
7521 MaxVersion: VersionTLS12,
7522 Bugs: ProtocolBugs{
7523 EarlyChangeCipherSpec: 1,
7524 },
7525 },
7526 shouldFail: true,
7527 expectedError: ":UNEXPECTED_RECORD:",
7528 })
7529 testCases = append(testCases, testCase{
7530 testType: serverTest,
7531 name: "EarlyChangeCipherSpec-server-2",
7532 config: Config{
7533 MaxVersion: VersionTLS12,
7534 Bugs: ProtocolBugs{
7535 EarlyChangeCipherSpec: 2,
7536 },
7537 },
7538 shouldFail: true,
7539 expectedError: ":UNEXPECTED_RECORD:",
7540 })
7541 testCases = append(testCases, testCase{
7542 protocol: dtls,
7543 name: "StrayChangeCipherSpec",
7544 config: Config{
7545 // TODO(davidben): Once DTLS 1.3 exists, test
7546 // that stray ChangeCipherSpec messages are
7547 // rejected.
7548 MaxVersion: VersionTLS12,
7549 Bugs: ProtocolBugs{
7550 StrayChangeCipherSpec: true,
7551 },
7552 },
7553 })
7554
7555 // Test that the contents of ChangeCipherSpec are checked.
7556 testCases = append(testCases, testCase{
7557 name: "BadChangeCipherSpec-1",
7558 config: Config{
7559 MaxVersion: VersionTLS12,
7560 Bugs: ProtocolBugs{
7561 BadChangeCipherSpec: []byte{2},
7562 },
7563 },
7564 shouldFail: true,
7565 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7566 })
7567 testCases = append(testCases, testCase{
7568 name: "BadChangeCipherSpec-2",
7569 config: Config{
7570 MaxVersion: VersionTLS12,
7571 Bugs: ProtocolBugs{
7572 BadChangeCipherSpec: []byte{1, 1},
7573 },
7574 },
7575 shouldFail: true,
7576 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7577 })
7578 testCases = append(testCases, testCase{
7579 protocol: dtls,
7580 name: "BadChangeCipherSpec-DTLS-1",
7581 config: Config{
7582 MaxVersion: VersionTLS12,
7583 Bugs: ProtocolBugs{
7584 BadChangeCipherSpec: []byte{2},
7585 },
7586 },
7587 shouldFail: true,
7588 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7589 })
7590 testCases = append(testCases, testCase{
7591 protocol: dtls,
7592 name: "BadChangeCipherSpec-DTLS-2",
7593 config: Config{
7594 MaxVersion: VersionTLS12,
7595 Bugs: ProtocolBugs{
7596 BadChangeCipherSpec: []byte{1, 1},
7597 },
7598 },
7599 shouldFail: true,
7600 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7601 })
7602}
7603
David Benjamincd2c8062016-09-09 11:28:16 -04007604type perMessageTest struct {
7605 messageType uint8
7606 test testCase
7607}
7608
7609// makePerMessageTests returns a series of test templates which cover each
7610// message in the TLS handshake. These may be used with bugs like
7611// WrongMessageType to fully test a per-message bug.
7612func makePerMessageTests() []perMessageTest {
7613 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007614 for _, protocol := range []protocol{tls, dtls} {
7615 var suffix string
7616 if protocol == dtls {
7617 suffix = "-DTLS"
7618 }
7619
David Benjamincd2c8062016-09-09 11:28:16 -04007620 ret = append(ret, perMessageTest{
7621 messageType: typeClientHello,
7622 test: testCase{
7623 protocol: protocol,
7624 testType: serverTest,
7625 name: "ClientHello" + suffix,
7626 config: Config{
7627 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007628 },
7629 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007630 })
7631
7632 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007633 ret = append(ret, perMessageTest{
7634 messageType: typeHelloVerifyRequest,
7635 test: testCase{
7636 protocol: protocol,
7637 name: "HelloVerifyRequest" + suffix,
7638 config: Config{
7639 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007640 },
7641 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007642 })
7643 }
7644
David Benjamincd2c8062016-09-09 11:28:16 -04007645 ret = append(ret, perMessageTest{
7646 messageType: typeServerHello,
7647 test: testCase{
7648 protocol: protocol,
7649 name: "ServerHello" + suffix,
7650 config: Config{
7651 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007652 },
7653 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007654 })
7655
David Benjamincd2c8062016-09-09 11:28:16 -04007656 ret = append(ret, perMessageTest{
7657 messageType: typeCertificate,
7658 test: testCase{
7659 protocol: protocol,
7660 name: "ServerCertificate" + suffix,
7661 config: Config{
7662 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007663 },
7664 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007665 })
7666
David Benjamincd2c8062016-09-09 11:28:16 -04007667 ret = append(ret, perMessageTest{
7668 messageType: typeCertificateStatus,
7669 test: testCase{
7670 protocol: protocol,
7671 name: "CertificateStatus" + suffix,
7672 config: Config{
7673 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007674 },
David Benjamincd2c8062016-09-09 11:28:16 -04007675 flags: []string{"-enable-ocsp-stapling"},
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: typeServerKeyExchange,
7681 test: testCase{
7682 protocol: protocol,
7683 name: "ServerKeyExchange" + suffix,
7684 config: Config{
7685 MaxVersion: VersionTLS12,
7686 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007687 },
7688 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007689 })
7690
David Benjamincd2c8062016-09-09 11:28:16 -04007691 ret = append(ret, perMessageTest{
7692 messageType: typeCertificateRequest,
7693 test: testCase{
7694 protocol: protocol,
7695 name: "CertificateRequest" + suffix,
7696 config: Config{
7697 MaxVersion: VersionTLS12,
7698 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007699 },
7700 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007701 })
7702
David Benjamincd2c8062016-09-09 11:28:16 -04007703 ret = append(ret, perMessageTest{
7704 messageType: typeServerHelloDone,
7705 test: testCase{
7706 protocol: protocol,
7707 name: "ServerHelloDone" + suffix,
7708 config: Config{
7709 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007710 },
7711 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007712 })
7713
David Benjamincd2c8062016-09-09 11:28:16 -04007714 ret = append(ret, perMessageTest{
7715 messageType: typeCertificate,
7716 test: testCase{
7717 testType: serverTest,
7718 protocol: protocol,
7719 name: "ClientCertificate" + suffix,
7720 config: Config{
7721 Certificates: []Certificate{rsaCertificate},
7722 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007723 },
David Benjamincd2c8062016-09-09 11:28:16 -04007724 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007725 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007726 })
7727
David Benjamincd2c8062016-09-09 11:28:16 -04007728 ret = append(ret, perMessageTest{
7729 messageType: typeCertificateVerify,
7730 test: testCase{
7731 testType: serverTest,
7732 protocol: protocol,
7733 name: "CertificateVerify" + suffix,
7734 config: Config{
7735 Certificates: []Certificate{rsaCertificate},
7736 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007737 },
David Benjamincd2c8062016-09-09 11:28:16 -04007738 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007739 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007740 })
7741
David Benjamincd2c8062016-09-09 11:28:16 -04007742 ret = append(ret, perMessageTest{
7743 messageType: typeClientKeyExchange,
7744 test: testCase{
7745 testType: serverTest,
7746 protocol: protocol,
7747 name: "ClientKeyExchange" + suffix,
7748 config: Config{
7749 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007750 },
7751 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007752 })
7753
7754 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007755 ret = append(ret, perMessageTest{
7756 messageType: typeNextProtocol,
7757 test: testCase{
7758 testType: serverTest,
7759 protocol: protocol,
7760 name: "NextProtocol" + suffix,
7761 config: Config{
7762 MaxVersion: VersionTLS12,
7763 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007764 },
David Benjamincd2c8062016-09-09 11:28:16 -04007765 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007766 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007767 })
7768
David Benjamincd2c8062016-09-09 11:28:16 -04007769 ret = append(ret, perMessageTest{
7770 messageType: typeChannelID,
7771 test: testCase{
7772 testType: serverTest,
7773 protocol: protocol,
7774 name: "ChannelID" + suffix,
7775 config: Config{
7776 MaxVersion: VersionTLS12,
7777 ChannelID: channelIDKey,
7778 },
7779 flags: []string{
7780 "-expect-channel-id",
7781 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007782 },
7783 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007784 })
7785 }
7786
David Benjamincd2c8062016-09-09 11:28:16 -04007787 ret = append(ret, perMessageTest{
7788 messageType: typeFinished,
7789 test: testCase{
7790 testType: serverTest,
7791 protocol: protocol,
7792 name: "ClientFinished" + suffix,
7793 config: Config{
7794 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007795 },
7796 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007797 })
7798
David Benjamincd2c8062016-09-09 11:28:16 -04007799 ret = append(ret, perMessageTest{
7800 messageType: typeNewSessionTicket,
7801 test: testCase{
7802 protocol: protocol,
7803 name: "NewSessionTicket" + suffix,
7804 config: Config{
7805 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007806 },
7807 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007808 })
7809
David Benjamincd2c8062016-09-09 11:28:16 -04007810 ret = append(ret, perMessageTest{
7811 messageType: typeFinished,
7812 test: testCase{
7813 protocol: protocol,
7814 name: "ServerFinished" + suffix,
7815 config: Config{
7816 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007817 },
7818 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007819 })
7820
7821 }
David Benjamincd2c8062016-09-09 11:28:16 -04007822
7823 ret = append(ret, perMessageTest{
7824 messageType: typeClientHello,
7825 test: testCase{
7826 testType: serverTest,
7827 name: "TLS13-ClientHello",
7828 config: Config{
7829 MaxVersion: VersionTLS13,
7830 },
7831 },
7832 })
7833
7834 ret = append(ret, perMessageTest{
7835 messageType: typeServerHello,
7836 test: testCase{
7837 name: "TLS13-ServerHello",
7838 config: Config{
7839 MaxVersion: VersionTLS13,
7840 },
7841 },
7842 })
7843
7844 ret = append(ret, perMessageTest{
7845 messageType: typeEncryptedExtensions,
7846 test: testCase{
7847 name: "TLS13-EncryptedExtensions",
7848 config: Config{
7849 MaxVersion: VersionTLS13,
7850 },
7851 },
7852 })
7853
7854 ret = append(ret, perMessageTest{
7855 messageType: typeCertificateRequest,
7856 test: testCase{
7857 name: "TLS13-CertificateRequest",
7858 config: Config{
7859 MaxVersion: VersionTLS13,
7860 ClientAuth: RequireAnyClientCert,
7861 },
7862 },
7863 })
7864
7865 ret = append(ret, perMessageTest{
7866 messageType: typeCertificate,
7867 test: testCase{
7868 name: "TLS13-ServerCertificate",
7869 config: Config{
7870 MaxVersion: VersionTLS13,
7871 },
7872 },
7873 })
7874
7875 ret = append(ret, perMessageTest{
7876 messageType: typeCertificateVerify,
7877 test: testCase{
7878 name: "TLS13-ServerCertificateVerify",
7879 config: Config{
7880 MaxVersion: VersionTLS13,
7881 },
7882 },
7883 })
7884
7885 ret = append(ret, perMessageTest{
7886 messageType: typeFinished,
7887 test: testCase{
7888 name: "TLS13-ServerFinished",
7889 config: Config{
7890 MaxVersion: VersionTLS13,
7891 },
7892 },
7893 })
7894
7895 ret = append(ret, perMessageTest{
7896 messageType: typeCertificate,
7897 test: testCase{
7898 testType: serverTest,
7899 name: "TLS13-ClientCertificate",
7900 config: Config{
7901 Certificates: []Certificate{rsaCertificate},
7902 MaxVersion: VersionTLS13,
7903 },
7904 flags: []string{"-require-any-client-certificate"},
7905 },
7906 })
7907
7908 ret = append(ret, perMessageTest{
7909 messageType: typeCertificateVerify,
7910 test: testCase{
7911 testType: serverTest,
7912 name: "TLS13-ClientCertificateVerify",
7913 config: Config{
7914 Certificates: []Certificate{rsaCertificate},
7915 MaxVersion: VersionTLS13,
7916 },
7917 flags: []string{"-require-any-client-certificate"},
7918 },
7919 })
7920
7921 ret = append(ret, perMessageTest{
7922 messageType: typeFinished,
7923 test: testCase{
7924 testType: serverTest,
7925 name: "TLS13-ClientFinished",
7926 config: Config{
7927 MaxVersion: VersionTLS13,
7928 },
7929 },
7930 })
7931
7932 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007933}
7934
David Benjamincd2c8062016-09-09 11:28:16 -04007935func addWrongMessageTypeTests() {
7936 for _, t := range makePerMessageTests() {
7937 t.test.name = "WrongMessageType-" + t.test.name
7938 t.test.config.Bugs.SendWrongMessageType = t.messageType
7939 t.test.shouldFail = true
7940 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7941 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007942
David Benjamincd2c8062016-09-09 11:28:16 -04007943 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7944 // In TLS 1.3, a bad ServerHello means the client sends
7945 // an unencrypted alert while the server expects
7946 // encryption, so the alert is not readable by runner.
7947 t.test.expectedLocalError = "local error: bad record MAC"
7948 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007949
David Benjamincd2c8062016-09-09 11:28:16 -04007950 testCases = append(testCases, t.test)
7951 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007952}
7953
David Benjamin639846e2016-09-09 11:41:18 -04007954func addTrailingMessageDataTests() {
7955 for _, t := range makePerMessageTests() {
7956 t.test.name = "TrailingMessageData-" + t.test.name
7957 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7958 t.test.shouldFail = true
7959 t.test.expectedError = ":DECODE_ERROR:"
7960 t.test.expectedLocalError = "remote error: error decoding message"
7961
7962 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7963 // In TLS 1.3, a bad ServerHello means the client sends
7964 // an unencrypted alert while the server expects
7965 // encryption, so the alert is not readable by runner.
7966 t.test.expectedLocalError = "local error: bad record MAC"
7967 }
7968
7969 if t.messageType == typeFinished {
7970 // Bad Finished messages read as the verify data having
7971 // the wrong length.
7972 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7973 t.test.expectedLocalError = "remote error: error decrypting message"
7974 }
7975
7976 testCases = append(testCases, t.test)
7977 }
7978}
7979
Steven Valdez143e8b32016-07-11 13:19:03 -04007980func addTLS13HandshakeTests() {
7981 testCases = append(testCases, testCase{
7982 testType: clientTest,
7983 name: "MissingKeyShare-Client",
7984 config: Config{
7985 MaxVersion: VersionTLS13,
7986 Bugs: ProtocolBugs{
7987 MissingKeyShare: true,
7988 },
7989 },
7990 shouldFail: true,
7991 expectedError: ":MISSING_KEY_SHARE:",
7992 })
7993
7994 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007995 testType: serverTest,
7996 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007997 config: Config{
7998 MaxVersion: VersionTLS13,
7999 Bugs: ProtocolBugs{
8000 MissingKeyShare: true,
8001 },
8002 },
8003 shouldFail: true,
8004 expectedError: ":MISSING_KEY_SHARE:",
8005 })
8006
8007 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008008 testType: serverTest,
8009 name: "DuplicateKeyShares",
8010 config: Config{
8011 MaxVersion: VersionTLS13,
8012 Bugs: ProtocolBugs{
8013 DuplicateKeyShares: true,
8014 },
8015 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008016 shouldFail: true,
8017 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008018 })
8019
8020 testCases = append(testCases, testCase{
8021 testType: clientTest,
8022 name: "EmptyEncryptedExtensions",
8023 config: Config{
8024 MaxVersion: VersionTLS13,
8025 Bugs: ProtocolBugs{
8026 EmptyEncryptedExtensions: true,
8027 },
8028 },
8029 shouldFail: true,
8030 expectedLocalError: "remote error: error decoding message",
8031 })
8032
8033 testCases = append(testCases, testCase{
8034 testType: clientTest,
8035 name: "EncryptedExtensionsWithKeyShare",
8036 config: Config{
8037 MaxVersion: VersionTLS13,
8038 Bugs: ProtocolBugs{
8039 EncryptedExtensionsWithKeyShare: true,
8040 },
8041 },
8042 shouldFail: true,
8043 expectedLocalError: "remote error: unsupported extension",
8044 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008045
8046 testCases = append(testCases, testCase{
8047 testType: serverTest,
8048 name: "SendHelloRetryRequest",
8049 config: Config{
8050 MaxVersion: VersionTLS13,
8051 // Require a HelloRetryRequest for every curve.
8052 DefaultCurves: []CurveID{},
8053 },
8054 expectedCurveID: CurveX25519,
8055 })
8056
8057 testCases = append(testCases, testCase{
8058 testType: serverTest,
8059 name: "SendHelloRetryRequest-2",
8060 config: Config{
8061 MaxVersion: VersionTLS13,
8062 DefaultCurves: []CurveID{CurveP384},
8063 },
8064 // Although the ClientHello did not predict our preferred curve,
8065 // we always select it whether it is predicted or not.
8066 expectedCurveID: CurveX25519,
8067 })
8068
8069 testCases = append(testCases, testCase{
8070 name: "UnknownCurve-HelloRetryRequest",
8071 config: Config{
8072 MaxVersion: VersionTLS13,
8073 // P-384 requires HelloRetryRequest in BoringSSL.
8074 CurvePreferences: []CurveID{CurveP384},
8075 Bugs: ProtocolBugs{
8076 SendHelloRetryRequestCurve: bogusCurve,
8077 },
8078 },
8079 shouldFail: true,
8080 expectedError: ":WRONG_CURVE:",
8081 })
8082
8083 testCases = append(testCases, testCase{
8084 name: "DisabledCurve-HelloRetryRequest",
8085 config: Config{
8086 MaxVersion: VersionTLS13,
8087 CurvePreferences: []CurveID{CurveP256},
8088 Bugs: ProtocolBugs{
8089 IgnorePeerCurvePreferences: true,
8090 },
8091 },
8092 flags: []string{"-p384-only"},
8093 shouldFail: true,
8094 expectedError: ":WRONG_CURVE:",
8095 })
8096
8097 testCases = append(testCases, testCase{
8098 name: "UnnecessaryHelloRetryRequest",
8099 config: Config{
8100 MaxVersion: VersionTLS13,
8101 Bugs: ProtocolBugs{
8102 UnnecessaryHelloRetryRequest: true,
8103 },
8104 },
8105 shouldFail: true,
8106 expectedError: ":WRONG_CURVE:",
8107 })
8108
8109 testCases = append(testCases, testCase{
8110 name: "SecondHelloRetryRequest",
8111 config: Config{
8112 MaxVersion: VersionTLS13,
8113 // P-384 requires HelloRetryRequest in BoringSSL.
8114 CurvePreferences: []CurveID{CurveP384},
8115 Bugs: ProtocolBugs{
8116 SecondHelloRetryRequest: true,
8117 },
8118 },
8119 shouldFail: true,
8120 expectedError: ":UNEXPECTED_MESSAGE:",
8121 })
8122
8123 testCases = append(testCases, testCase{
8124 testType: serverTest,
8125 name: "SecondClientHelloMissingKeyShare",
8126 config: Config{
8127 MaxVersion: VersionTLS13,
8128 DefaultCurves: []CurveID{},
8129 Bugs: ProtocolBugs{
8130 SecondClientHelloMissingKeyShare: true,
8131 },
8132 },
8133 shouldFail: true,
8134 expectedError: ":MISSING_KEY_SHARE:",
8135 })
8136
8137 testCases = append(testCases, testCase{
8138 testType: serverTest,
8139 name: "SecondClientHelloWrongCurve",
8140 config: Config{
8141 MaxVersion: VersionTLS13,
8142 DefaultCurves: []CurveID{},
8143 Bugs: ProtocolBugs{
8144 MisinterpretHelloRetryRequestCurve: CurveP521,
8145 },
8146 },
8147 shouldFail: true,
8148 expectedError: ":WRONG_CURVE:",
8149 })
8150
8151 testCases = append(testCases, testCase{
8152 name: "HelloRetryRequestVersionMismatch",
8153 config: Config{
8154 MaxVersion: VersionTLS13,
8155 // P-384 requires HelloRetryRequest in BoringSSL.
8156 CurvePreferences: []CurveID{CurveP384},
8157 Bugs: ProtocolBugs{
8158 SendServerHelloVersion: 0x0305,
8159 },
8160 },
8161 shouldFail: true,
8162 expectedError: ":WRONG_VERSION_NUMBER:",
8163 })
8164
8165 testCases = append(testCases, testCase{
8166 name: "HelloRetryRequestCurveMismatch",
8167 config: Config{
8168 MaxVersion: VersionTLS13,
8169 // P-384 requires HelloRetryRequest in BoringSSL.
8170 CurvePreferences: []CurveID{CurveP384},
8171 Bugs: ProtocolBugs{
8172 // Send P-384 (correct) in the HelloRetryRequest.
8173 SendHelloRetryRequestCurve: CurveP384,
8174 // But send P-256 in the ServerHello.
8175 SendCurve: CurveP256,
8176 },
8177 },
8178 shouldFail: true,
8179 expectedError: ":WRONG_CURVE:",
8180 })
8181
8182 // Test the server selecting a curve that requires a HelloRetryRequest
8183 // without sending it.
8184 testCases = append(testCases, testCase{
8185 name: "SkipHelloRetryRequest",
8186 config: Config{
8187 MaxVersion: VersionTLS13,
8188 // P-384 requires HelloRetryRequest in BoringSSL.
8189 CurvePreferences: []CurveID{CurveP384},
8190 Bugs: ProtocolBugs{
8191 SkipHelloRetryRequest: true,
8192 },
8193 },
8194 shouldFail: true,
8195 expectedError: ":WRONG_CURVE:",
8196 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008197
8198 testCases = append(testCases, testCase{
8199 name: "TLS13-RequestContextInHandshake",
8200 config: Config{
8201 MaxVersion: VersionTLS13,
8202 MinVersion: VersionTLS13,
8203 ClientAuth: RequireAnyClientCert,
8204 Bugs: ProtocolBugs{
8205 SendRequestContext: []byte("request context"),
8206 },
8207 },
8208 flags: []string{
8209 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8210 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8211 },
8212 shouldFail: true,
8213 expectedError: ":DECODE_ERROR:",
8214 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008215
8216 testCases = append(testCases, testCase{
8217 testType: serverTest,
8218 name: "TLS13-TrailingKeyShareData",
8219 config: Config{
8220 MaxVersion: VersionTLS13,
8221 Bugs: ProtocolBugs{
8222 TrailingKeyShareData: true,
8223 },
8224 },
8225 shouldFail: true,
8226 expectedError: ":DECODE_ERROR:",
8227 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008228}
8229
David Benjaminf3fbade2016-09-19 13:08:16 -04008230func addPeekTests() {
8231 // Test SSL_peek works, including on empty records.
8232 testCases = append(testCases, testCase{
8233 name: "Peek-Basic",
8234 sendEmptyRecords: 1,
8235 flags: []string{"-peek-then-read"},
8236 })
8237
8238 // Test SSL_peek can drive the initial handshake.
8239 testCases = append(testCases, testCase{
8240 name: "Peek-ImplicitHandshake",
8241 flags: []string{
8242 "-peek-then-read",
8243 "-implicit-handshake",
8244 },
8245 })
8246
8247 // Test SSL_peek can discover and drive a renegotiation.
8248 testCases = append(testCases, testCase{
8249 name: "Peek-Renegotiate",
8250 config: Config{
8251 MaxVersion: VersionTLS12,
8252 },
8253 renegotiate: 1,
8254 flags: []string{
8255 "-peek-then-read",
8256 "-renegotiate-freely",
8257 "-expect-total-renegotiations", "1",
8258 },
8259 })
8260
8261 // Test SSL_peek can discover a close_notify.
8262 testCases = append(testCases, testCase{
8263 name: "Peek-Shutdown",
8264 config: Config{
8265 Bugs: ProtocolBugs{
8266 ExpectCloseNotify: true,
8267 },
8268 },
8269 flags: []string{
8270 "-peek-then-read",
8271 "-check-close-notify",
8272 },
8273 })
8274
8275 // Test SSL_peek can discover an alert.
8276 testCases = append(testCases, testCase{
8277 name: "Peek-Alert",
8278 config: Config{
8279 Bugs: ProtocolBugs{
8280 SendSpuriousAlert: alertRecordOverflow,
8281 },
8282 },
8283 flags: []string{"-peek-then-read"},
8284 shouldFail: true,
8285 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8286 })
8287
8288 // Test SSL_peek can handle KeyUpdate.
8289 testCases = append(testCases, testCase{
8290 name: "Peek-KeyUpdate",
8291 config: Config{
8292 MaxVersion: VersionTLS13,
8293 Bugs: ProtocolBugs{
8294 SendKeyUpdateBeforeEveryAppDataRecord: true,
8295 },
8296 },
8297 flags: []string{"-peek-then-read"},
8298 })
8299}
8300
Adam Langley7c803a62015-06-15 15:35:05 -07008301func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008302 defer wg.Done()
8303
8304 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008305 var err error
8306
8307 if *mallocTest < 0 {
8308 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008309 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008310 } else {
8311 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8312 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008313 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008314 if err != nil {
8315 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8316 }
8317 break
8318 }
8319 }
8320 }
Adam Langley95c29f32014-06-20 12:00:00 -07008321 statusChan <- statusMsg{test: test, err: err}
8322 }
8323}
8324
8325type statusMsg struct {
8326 test *testCase
8327 started bool
8328 err error
8329}
8330
David Benjamin5f237bc2015-02-11 17:14:15 -05008331func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008332 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008333
David Benjamin5f237bc2015-02-11 17:14:15 -05008334 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008335 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008336 if !*pipe {
8337 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008338 var erase string
8339 for i := 0; i < lineLen; i++ {
8340 erase += "\b \b"
8341 }
8342 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008343 }
8344
Adam Langley95c29f32014-06-20 12:00:00 -07008345 if msg.started {
8346 started++
8347 } else {
8348 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008349
8350 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008351 if msg.err == errUnimplemented {
8352 if *pipe {
8353 // Print each test instead of a status line.
8354 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8355 }
8356 unimplemented++
8357 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8358 } else {
8359 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8360 failed++
8361 testOutput.addResult(msg.test.name, "FAIL")
8362 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008363 } else {
8364 if *pipe {
8365 // Print each test instead of a status line.
8366 fmt.Printf("PASSED (%s)\n", msg.test.name)
8367 }
8368 testOutput.addResult(msg.test.name, "PASS")
8369 }
Adam Langley95c29f32014-06-20 12:00:00 -07008370 }
8371
David Benjamin5f237bc2015-02-11 17:14:15 -05008372 if !*pipe {
8373 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008374 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008375 lineLen = len(line)
8376 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008377 }
Adam Langley95c29f32014-06-20 12:00:00 -07008378 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008379
8380 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008381}
8382
8383func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008384 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008385 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008386 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008387
Adam Langley7c803a62015-06-15 15:35:05 -07008388 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008389 addCipherSuiteTests()
8390 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008391 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008392 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008393 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008394 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008395 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008396 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008397 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008398 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008399 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008400 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008401 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008402 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008403 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008404 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008405 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008406 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008407 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008408 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008409 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008410 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008411 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008412 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008413 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008414 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008415 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008416 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008417 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008418
8419 var wg sync.WaitGroup
8420
Adam Langley7c803a62015-06-15 15:35:05 -07008421 statusChan := make(chan statusMsg, *numWorkers)
8422 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008423 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008424
EKRf71d7ed2016-08-06 13:25:12 -07008425 if len(*shimConfigFile) != 0 {
8426 encoded, err := ioutil.ReadFile(*shimConfigFile)
8427 if err != nil {
8428 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8429 os.Exit(1)
8430 }
8431
8432 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8433 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8434 os.Exit(1)
8435 }
8436 }
8437
David Benjamin025b3d32014-07-01 19:53:04 -04008438 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008439
Adam Langley7c803a62015-06-15 15:35:05 -07008440 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008441 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008442 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008443 }
8444
David Benjamin270f0a72016-03-17 14:41:36 -04008445 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008446 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008447 matched := true
8448 if len(*testToRun) != 0 {
8449 var err error
8450 matched, err = filepath.Match(*testToRun, testCases[i].name)
8451 if err != nil {
8452 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8453 os.Exit(1)
8454 }
8455 }
8456
EKRf71d7ed2016-08-06 13:25:12 -07008457 if !*includeDisabled {
8458 for pattern := range shimConfig.DisabledTests {
8459 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8460 if err != nil {
8461 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8462 os.Exit(1)
8463 }
8464
8465 if isDisabled {
8466 matched = false
8467 break
8468 }
8469 }
8470 }
8471
David Benjamin17e12922016-07-28 18:04:43 -04008472 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008473 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008474 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008475 }
8476 }
David Benjamin17e12922016-07-28 18:04:43 -04008477
David Benjamin270f0a72016-03-17 14:41:36 -04008478 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008479 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008480 os.Exit(1)
8481 }
Adam Langley95c29f32014-06-20 12:00:00 -07008482
8483 close(testChan)
8484 wg.Wait()
8485 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008486 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008487
8488 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008489
8490 if *jsonOutput != "" {
8491 if err := testOutput.writeTo(*jsonOutput); err != nil {
8492 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8493 }
8494 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008495
EKR842ae6c2016-07-27 09:22:05 +02008496 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8497 os.Exit(1)
8498 }
8499
8500 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008501 os.Exit(1)
8502 }
Adam Langley95c29f32014-06-20 12:00:00 -07008503}