blob: 8943865d9aff262684c76d0db9795baf3bd5093f [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 },
Adam Langley7c803a62015-06-15 15:35:05 -07002312 }
Adam Langley7c803a62015-06-15 15:35:05 -07002313 testCases = append(testCases, basicTests...)
2314}
2315
Adam Langley95c29f32014-06-20 12:00:00 -07002316func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002317 const bogusCipher = 0xfe00
2318
Adam Langley95c29f32014-06-20 12:00:00 -07002319 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002320 const psk = "12345"
2321 const pskIdentity = "luggage combo"
2322
Adam Langley95c29f32014-06-20 12:00:00 -07002323 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002324 var certFile string
2325 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002326 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002327 cert = ecdsaP256Certificate
2328 certFile = ecdsaP256CertificateFile
2329 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002330 } else {
David Benjamin33863262016-07-08 17:20:12 -07002331 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002332 certFile = rsaCertificateFile
2333 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002334 }
2335
David Benjamin48cae082014-10-27 01:06:24 -04002336 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002337 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002338 flags = append(flags,
2339 "-psk", psk,
2340 "-psk-identity", pskIdentity)
2341 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002342 if hasComponent(suite.name, "NULL") {
2343 // NULL ciphers must be explicitly enabled.
2344 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2345 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002346 if hasComponent(suite.name, "CECPQ1") {
2347 // CECPQ1 ciphers must be explicitly enabled.
2348 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2349 }
David Benjamin881f1962016-08-10 18:29:12 -04002350 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2351 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2352 // for now.
2353 flags = append(flags, "-cipher", suite.name)
2354 }
David Benjamin48cae082014-10-27 01:06:24 -04002355
Adam Langley95c29f32014-06-20 12:00:00 -07002356 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002357 for _, protocol := range []protocol{tls, dtls} {
2358 var prefix string
2359 if protocol == dtls {
2360 if !ver.hasDTLS {
2361 continue
2362 }
2363 prefix = "D"
2364 }
Adam Langley95c29f32014-06-20 12:00:00 -07002365
David Benjamin0407e762016-06-17 16:41:18 -04002366 var shouldServerFail, shouldClientFail bool
2367 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2368 // BoringSSL clients accept ECDHE on SSLv3, but
2369 // a BoringSSL server will never select it
2370 // because the extension is missing.
2371 shouldServerFail = true
2372 }
2373 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2374 shouldClientFail = true
2375 shouldServerFail = true
2376 }
David Benjamin54c217c2016-07-13 12:35:25 -04002377 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002378 shouldClientFail = true
2379 shouldServerFail = true
2380 }
David Benjamin0407e762016-06-17 16:41:18 -04002381 if !isDTLSCipher(suite.name) && protocol == dtls {
2382 shouldClientFail = true
2383 shouldServerFail = true
2384 }
David Benjamin4298d772015-12-19 00:18:25 -05002385
David Benjamin0407e762016-06-17 16:41:18 -04002386 var expectedServerError, expectedClientError string
2387 if shouldServerFail {
2388 expectedServerError = ":NO_SHARED_CIPHER:"
2389 }
2390 if shouldClientFail {
2391 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2392 }
David Benjamin025b3d32014-07-01 19:53:04 -04002393
David Benjamin6fd297b2014-08-11 18:43:38 -04002394 testCases = append(testCases, testCase{
2395 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002396 protocol: protocol,
2397
2398 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002399 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002400 MinVersion: ver.version,
2401 MaxVersion: ver.version,
2402 CipherSuites: []uint16{suite.id},
2403 Certificates: []Certificate{cert},
2404 PreSharedKey: []byte(psk),
2405 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002406 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002407 EnableAllCiphers: shouldServerFail,
2408 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002409 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002410 },
2411 certFile: certFile,
2412 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002413 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002414 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002415 shouldFail: shouldServerFail,
2416 expectedError: expectedServerError,
2417 })
2418
2419 testCases = append(testCases, testCase{
2420 testType: clientTest,
2421 protocol: protocol,
2422 name: prefix + ver.name + "-" + suite.name + "-client",
2423 config: Config{
2424 MinVersion: ver.version,
2425 MaxVersion: ver.version,
2426 CipherSuites: []uint16{suite.id},
2427 Certificates: []Certificate{cert},
2428 PreSharedKey: []byte(psk),
2429 PreSharedKeyIdentity: pskIdentity,
2430 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002431 EnableAllCiphers: shouldClientFail,
2432 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002433 },
2434 },
2435 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002436 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002437 shouldFail: shouldClientFail,
2438 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002439 })
David Benjamin2c99d282015-09-01 10:23:00 -04002440
Nick Harper1fd39d82016-06-14 18:14:35 -07002441 if !shouldClientFail {
2442 // Ensure the maximum record size is accepted.
2443 testCases = append(testCases, testCase{
2444 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2445 config: Config{
2446 MinVersion: ver.version,
2447 MaxVersion: ver.version,
2448 CipherSuites: []uint16{suite.id},
2449 Certificates: []Certificate{cert},
2450 PreSharedKey: []byte(psk),
2451 PreSharedKeyIdentity: pskIdentity,
2452 },
2453 flags: flags,
2454 messageLen: maxPlaintext,
2455 })
2456 }
2457 }
David Benjamin2c99d282015-09-01 10:23:00 -04002458 }
Adam Langley95c29f32014-06-20 12:00:00 -07002459 }
Adam Langleya7997f12015-05-14 17:38:50 -07002460
2461 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002462 name: "NoSharedCipher",
2463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002464 MaxVersion: VersionTLS12,
2465 CipherSuites: []uint16{},
2466 },
2467 shouldFail: true,
2468 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2469 })
2470
2471 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002472 name: "NoSharedCipher-TLS13",
2473 config: Config{
2474 MaxVersion: VersionTLS13,
2475 CipherSuites: []uint16{},
2476 },
2477 shouldFail: true,
2478 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2479 })
2480
2481 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 name: "UnsupportedCipherSuite",
2483 config: Config{
2484 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002485 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002486 Bugs: ProtocolBugs{
2487 IgnorePeerCipherPreferences: true,
2488 },
2489 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002490 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002491 shouldFail: true,
2492 expectedError: ":WRONG_CIPHER_RETURNED:",
2493 })
2494
2495 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002496 name: "ServerHelloBogusCipher",
2497 config: Config{
2498 MaxVersion: VersionTLS12,
2499 Bugs: ProtocolBugs{
2500 SendCipherSuite: bogusCipher,
2501 },
2502 },
2503 shouldFail: true,
2504 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2505 })
2506 testCases = append(testCases, testCase{
2507 name: "ServerHelloBogusCipher-TLS13",
2508 config: Config{
2509 MaxVersion: VersionTLS13,
2510 Bugs: ProtocolBugs{
2511 SendCipherSuite: bogusCipher,
2512 },
2513 },
2514 shouldFail: true,
2515 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2516 })
2517
2518 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002519 name: "WeakDH",
2520 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002521 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002522 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2523 Bugs: ProtocolBugs{
2524 // This is a 1023-bit prime number, generated
2525 // with:
2526 // openssl gendh 1023 | openssl asn1parse -i
2527 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2528 },
2529 },
2530 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002531 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002532 })
Adam Langleycef75832015-09-03 14:51:12 -07002533
David Benjamincd24a392015-11-11 13:23:05 -08002534 testCases = append(testCases, testCase{
2535 name: "SillyDH",
2536 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002537 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002538 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2539 Bugs: ProtocolBugs{
2540 // This is a 4097-bit prime number, generated
2541 // with:
2542 // openssl gendh 4097 | openssl asn1parse -i
2543 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2544 },
2545 },
2546 shouldFail: true,
2547 expectedError: ":DH_P_TOO_LONG:",
2548 })
2549
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002550 // This test ensures that Diffie-Hellman public values are padded with
2551 // zeros so that they're the same length as the prime. This is to avoid
2552 // hitting a bug in yaSSL.
2553 testCases = append(testCases, testCase{
2554 testType: serverTest,
2555 name: "DHPublicValuePadded",
2556 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002557 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002558 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2559 Bugs: ProtocolBugs{
2560 RequireDHPublicValueLen: (1025 + 7) / 8,
2561 },
2562 },
2563 flags: []string{"-use-sparse-dh-prime"},
2564 })
David Benjamincd24a392015-11-11 13:23:05 -08002565
David Benjamin241ae832016-01-15 03:04:54 -05002566 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002567 testCases = append(testCases, testCase{
2568 testType: serverTest,
2569 name: "UnknownCipher",
2570 config: Config{
2571 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2572 },
2573 })
2574
David Benjamin78679342016-09-16 19:42:05 -04002575 // Test empty ECDHE_PSK identity hints work as expected.
2576 testCases = append(testCases, testCase{
2577 name: "EmptyECDHEPSKHint",
2578 config: Config{
2579 MaxVersion: VersionTLS12,
2580 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2581 PreSharedKey: []byte("secret"),
2582 },
2583 flags: []string{"-psk", "secret"},
2584 })
2585
2586 // Test empty PSK identity hints work as expected, even if an explicit
2587 // ServerKeyExchange is sent.
2588 testCases = append(testCases, testCase{
2589 name: "ExplicitEmptyPSKHint",
2590 config: Config{
2591 MaxVersion: VersionTLS12,
2592 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2593 PreSharedKey: []byte("secret"),
2594 Bugs: ProtocolBugs{
2595 AlwaysSendPreSharedKeyIdentityHint: true,
2596 },
2597 },
2598 flags: []string{"-psk", "secret"},
2599 })
2600
Adam Langleycef75832015-09-03 14:51:12 -07002601 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2602 // 1.1 specific cipher suite settings. A server is setup with the given
2603 // cipher lists and then a connection is made for each member of
2604 // expectations. The cipher suite that the server selects must match
2605 // the specified one.
2606 var versionSpecificCiphersTest = []struct {
2607 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2608 // expectations is a map from TLS version to cipher suite id.
2609 expectations map[uint16]uint16
2610 }{
2611 {
2612 // Test that the null case (where no version-specific ciphers are set)
2613 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002614 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2615 "", // no ciphers specifically for TLS ≥ 1.0
2616 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002617 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002618 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2619 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2620 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2621 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002622 },
2623 },
2624 {
2625 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2626 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002627 "DES-CBC3-SHA:AES128-SHA", // default
2628 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2629 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002630 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002631 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002632 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2633 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2634 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2635 },
2636 },
2637 {
2638 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2639 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002640 "DES-CBC3-SHA:AES128-SHA", // default
2641 "", // no ciphers specifically for TLS ≥ 1.0
2642 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002643 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002644 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2645 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002646 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2647 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2648 },
2649 },
2650 {
2651 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2652 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002653 "DES-CBC3-SHA:AES128-SHA", // default
2654 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2655 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002656 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002657 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002658 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2659 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2660 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2661 },
2662 },
2663 }
2664
2665 for i, test := range versionSpecificCiphersTest {
2666 for version, expectedCipherSuite := range test.expectations {
2667 flags := []string{"-cipher", test.ciphersDefault}
2668 if len(test.ciphersTLS10) > 0 {
2669 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2670 }
2671 if len(test.ciphersTLS11) > 0 {
2672 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2673 }
2674
2675 testCases = append(testCases, testCase{
2676 testType: serverTest,
2677 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2678 config: Config{
2679 MaxVersion: version,
2680 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002681 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 -07002682 },
2683 flags: flags,
2684 expectedCipher: expectedCipherSuite,
2685 })
2686 }
2687 }
Adam Langley95c29f32014-06-20 12:00:00 -07002688}
2689
2690func addBadECDSASignatureTests() {
2691 for badR := BadValue(1); badR < NumBadValues; badR++ {
2692 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002693 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002694 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2695 config: Config{
2696 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002697 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002698 Bugs: ProtocolBugs{
2699 BadECDSAR: badR,
2700 BadECDSAS: badS,
2701 },
2702 },
2703 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002704 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002705 })
2706 }
2707 }
2708}
2709
Adam Langley80842bd2014-06-20 12:00:00 -07002710func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002711 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002712 name: "MaxCBCPadding",
2713 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002714 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002715 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2716 Bugs: ProtocolBugs{
2717 MaxPadding: true,
2718 },
2719 },
2720 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2721 })
David Benjamin025b3d32014-07-01 19:53:04 -04002722 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002723 name: "BadCBCPadding",
2724 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002725 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002726 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2727 Bugs: ProtocolBugs{
2728 PaddingFirstByteBad: true,
2729 },
2730 },
2731 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002732 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002733 })
2734 // OpenSSL previously had an issue where the first byte of padding in
2735 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002736 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002737 name: "BadCBCPadding255",
2738 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002739 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002740 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2741 Bugs: ProtocolBugs{
2742 MaxPadding: true,
2743 PaddingFirstByteBadIf255: true,
2744 },
2745 },
2746 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2747 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002748 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002749 })
2750}
2751
Kenny Root7fdeaf12014-08-05 15:23:37 -07002752func addCBCSplittingTests() {
2753 testCases = append(testCases, testCase{
2754 name: "CBCRecordSplitting",
2755 config: Config{
2756 MaxVersion: VersionTLS10,
2757 MinVersion: VersionTLS10,
2758 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2759 },
David Benjaminac8302a2015-09-01 17:18:15 -04002760 messageLen: -1, // read until EOF
2761 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002762 flags: []string{
2763 "-async",
2764 "-write-different-record-sizes",
2765 "-cbc-record-splitting",
2766 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002767 })
2768 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002769 name: "CBCRecordSplittingPartialWrite",
2770 config: Config{
2771 MaxVersion: VersionTLS10,
2772 MinVersion: VersionTLS10,
2773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2774 },
2775 messageLen: -1, // read until EOF
2776 flags: []string{
2777 "-async",
2778 "-write-different-record-sizes",
2779 "-cbc-record-splitting",
2780 "-partial-write",
2781 },
2782 })
2783}
2784
David Benjamin636293b2014-07-08 17:59:18 -04002785func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002786 // Add a dummy cert pool to stress certificate authority parsing.
2787 // TODO(davidben): Add tests that those values parse out correctly.
2788 certPool := x509.NewCertPool()
2789 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2790 if err != nil {
2791 panic(err)
2792 }
2793 certPool.AddCert(cert)
2794
David Benjamin636293b2014-07-08 17:59:18 -04002795 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002796 testCases = append(testCases, testCase{
2797 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002798 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002799 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002800 MinVersion: ver.version,
2801 MaxVersion: ver.version,
2802 ClientAuth: RequireAnyClientCert,
2803 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002804 },
2805 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002806 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2807 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002808 },
2809 })
2810 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002811 testType: serverTest,
2812 name: ver.name + "-Server-ClientAuth-RSA",
2813 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002814 MinVersion: ver.version,
2815 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002816 Certificates: []Certificate{rsaCertificate},
2817 },
2818 flags: []string{"-require-any-client-certificate"},
2819 })
David Benjamine098ec22014-08-27 23:13:20 -04002820 if ver.version != VersionSSL30 {
2821 testCases = append(testCases, testCase{
2822 testType: serverTest,
2823 name: ver.name + "-Server-ClientAuth-ECDSA",
2824 config: Config{
2825 MinVersion: ver.version,
2826 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002827 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002828 },
2829 flags: []string{"-require-any-client-certificate"},
2830 })
2831 testCases = append(testCases, testCase{
2832 testType: clientTest,
2833 name: ver.name + "-Client-ClientAuth-ECDSA",
2834 config: Config{
2835 MinVersion: ver.version,
2836 MaxVersion: ver.version,
2837 ClientAuth: RequireAnyClientCert,
2838 ClientCAs: certPool,
2839 },
2840 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002841 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2842 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002843 },
2844 })
2845 }
Adam Langley37646832016-08-01 16:16:46 -07002846
2847 testCases = append(testCases, testCase{
2848 name: "NoClientCertificate-" + ver.name,
2849 config: Config{
2850 MinVersion: ver.version,
2851 MaxVersion: ver.version,
2852 ClientAuth: RequireAnyClientCert,
2853 },
2854 shouldFail: true,
2855 expectedLocalError: "client didn't provide a certificate",
2856 })
2857
2858 testCases = append(testCases, testCase{
2859 // Even if not configured to expect a certificate, OpenSSL will
2860 // return X509_V_OK as the verify_result.
2861 testType: serverTest,
2862 name: "NoClientCertificateRequested-Server-" + ver.name,
2863 config: Config{
2864 MinVersion: ver.version,
2865 MaxVersion: ver.version,
2866 },
2867 flags: []string{
2868 "-expect-verify-result",
2869 },
2870 // TODO(davidben): Switch this to true when TLS 1.3
2871 // supports session resumption.
2872 resumeSession: ver.version < VersionTLS13,
2873 })
2874
2875 testCases = append(testCases, testCase{
2876 // If a client certificate is not provided, OpenSSL will still
2877 // return X509_V_OK as the verify_result.
2878 testType: serverTest,
2879 name: "NoClientCertificate-Server-" + ver.name,
2880 config: Config{
2881 MinVersion: ver.version,
2882 MaxVersion: ver.version,
2883 },
2884 flags: []string{
2885 "-expect-verify-result",
2886 "-verify-peer",
2887 },
2888 // TODO(davidben): Switch this to true when TLS 1.3
2889 // supports session resumption.
2890 resumeSession: ver.version < VersionTLS13,
2891 })
2892
2893 testCases = append(testCases, testCase{
2894 testType: serverTest,
2895 name: "RequireAnyClientCertificate-" + ver.name,
2896 config: Config{
2897 MinVersion: ver.version,
2898 MaxVersion: ver.version,
2899 },
2900 flags: []string{"-require-any-client-certificate"},
2901 shouldFail: true,
2902 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2903 })
2904
2905 if ver.version != VersionSSL30 {
2906 testCases = append(testCases, testCase{
2907 testType: serverTest,
2908 name: "SkipClientCertificate-" + ver.name,
2909 config: Config{
2910 MinVersion: ver.version,
2911 MaxVersion: ver.version,
2912 Bugs: ProtocolBugs{
2913 SkipClientCertificate: true,
2914 },
2915 },
2916 // Setting SSL_VERIFY_PEER allows anonymous clients.
2917 flags: []string{"-verify-peer"},
2918 shouldFail: true,
2919 expectedError: ":UNEXPECTED_MESSAGE:",
2920 })
2921 }
David Benjamin636293b2014-07-08 17:59:18 -04002922 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002923
David Benjaminc032dfa2016-05-12 14:54:57 -04002924 // Client auth is only legal in certificate-based ciphers.
2925 testCases = append(testCases, testCase{
2926 testType: clientTest,
2927 name: "ClientAuth-PSK",
2928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002929 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002930 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2931 PreSharedKey: []byte("secret"),
2932 ClientAuth: RequireAnyClientCert,
2933 },
2934 flags: []string{
2935 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2936 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2937 "-psk", "secret",
2938 },
2939 shouldFail: true,
2940 expectedError: ":UNEXPECTED_MESSAGE:",
2941 })
2942 testCases = append(testCases, testCase{
2943 testType: clientTest,
2944 name: "ClientAuth-ECDHE_PSK",
2945 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002946 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002947 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2948 PreSharedKey: []byte("secret"),
2949 ClientAuth: RequireAnyClientCert,
2950 },
2951 flags: []string{
2952 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2953 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2954 "-psk", "secret",
2955 },
2956 shouldFail: true,
2957 expectedError: ":UNEXPECTED_MESSAGE:",
2958 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002959
2960 // Regression test for a bug where the client CA list, if explicitly
2961 // set to NULL, was mis-encoded.
2962 testCases = append(testCases, testCase{
2963 testType: serverTest,
2964 name: "Null-Client-CA-List",
2965 config: Config{
2966 MaxVersion: VersionTLS12,
2967 Certificates: []Certificate{rsaCertificate},
2968 },
2969 flags: []string{
2970 "-require-any-client-certificate",
2971 "-use-null-client-ca-list",
2972 },
2973 })
David Benjamin636293b2014-07-08 17:59:18 -04002974}
2975
Adam Langley75712922014-10-10 16:23:43 -07002976func addExtendedMasterSecretTests() {
2977 const expectEMSFlag = "-expect-extended-master-secret"
2978
2979 for _, with := range []bool{false, true} {
2980 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002981 if with {
2982 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002983 }
2984
2985 for _, isClient := range []bool{false, true} {
2986 suffix := "-Server"
2987 testType := serverTest
2988 if isClient {
2989 suffix = "-Client"
2990 testType = clientTest
2991 }
2992
2993 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002994 // In TLS 1.3, the extension is irrelevant and
2995 // always reports as enabled.
2996 var flags []string
2997 if with || ver.version >= VersionTLS13 {
2998 flags = []string{expectEMSFlag}
2999 }
3000
Adam Langley75712922014-10-10 16:23:43 -07003001 test := testCase{
3002 testType: testType,
3003 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3004 config: Config{
3005 MinVersion: ver.version,
3006 MaxVersion: ver.version,
3007 Bugs: ProtocolBugs{
3008 NoExtendedMasterSecret: !with,
3009 RequireExtendedMasterSecret: with,
3010 },
3011 },
David Benjamin48cae082014-10-27 01:06:24 -04003012 flags: flags,
3013 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003014 }
3015 if test.shouldFail {
3016 test.expectedLocalError = "extended master secret required but not supported by peer"
3017 }
3018 testCases = append(testCases, test)
3019 }
3020 }
3021 }
3022
Adam Langleyba5934b2015-06-02 10:50:35 -07003023 for _, isClient := range []bool{false, true} {
3024 for _, supportedInFirstConnection := range []bool{false, true} {
3025 for _, supportedInResumeConnection := range []bool{false, true} {
3026 boolToWord := func(b bool) string {
3027 if b {
3028 return "Yes"
3029 }
3030 return "No"
3031 }
3032 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3033 if isClient {
3034 suffix += "Client"
3035 } else {
3036 suffix += "Server"
3037 }
3038
3039 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003040 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003041 Bugs: ProtocolBugs{
3042 RequireExtendedMasterSecret: true,
3043 },
3044 }
3045
3046 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003047 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003048 Bugs: ProtocolBugs{
3049 NoExtendedMasterSecret: true,
3050 },
3051 }
3052
3053 test := testCase{
3054 name: "ExtendedMasterSecret-" + suffix,
3055 resumeSession: true,
3056 }
3057
3058 if !isClient {
3059 test.testType = serverTest
3060 }
3061
3062 if supportedInFirstConnection {
3063 test.config = supportedConfig
3064 } else {
3065 test.config = noSupportConfig
3066 }
3067
3068 if supportedInResumeConnection {
3069 test.resumeConfig = &supportedConfig
3070 } else {
3071 test.resumeConfig = &noSupportConfig
3072 }
3073
3074 switch suffix {
3075 case "YesToYes-Client", "YesToYes-Server":
3076 // When a session is resumed, it should
3077 // still be aware that its master
3078 // secret was generated via EMS and
3079 // thus it's safe to use tls-unique.
3080 test.flags = []string{expectEMSFlag}
3081 case "NoToYes-Server":
3082 // If an original connection did not
3083 // contain EMS, but a resumption
3084 // handshake does, then a server should
3085 // not resume the session.
3086 test.expectResumeRejected = true
3087 case "YesToNo-Server":
3088 // Resuming an EMS session without the
3089 // EMS extension should cause the
3090 // server to abort the connection.
3091 test.shouldFail = true
3092 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3093 case "NoToYes-Client":
3094 // A client should abort a connection
3095 // where the server resumed a non-EMS
3096 // session but echoed the EMS
3097 // extension.
3098 test.shouldFail = true
3099 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3100 case "YesToNo-Client":
3101 // A client should abort a connection
3102 // where the server didn't echo EMS
3103 // when the session used it.
3104 test.shouldFail = true
3105 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3106 }
3107
3108 testCases = append(testCases, test)
3109 }
3110 }
3111 }
David Benjamin163c9562016-08-29 23:14:17 -04003112
3113 // Switching EMS on renegotiation is forbidden.
3114 testCases = append(testCases, testCase{
3115 name: "ExtendedMasterSecret-Renego-NoEMS",
3116 config: Config{
3117 MaxVersion: VersionTLS12,
3118 Bugs: ProtocolBugs{
3119 NoExtendedMasterSecret: true,
3120 NoExtendedMasterSecretOnRenegotiation: true,
3121 },
3122 },
3123 renegotiate: 1,
3124 flags: []string{
3125 "-renegotiate-freely",
3126 "-expect-total-renegotiations", "1",
3127 },
3128 })
3129
3130 testCases = append(testCases, testCase{
3131 name: "ExtendedMasterSecret-Renego-Upgrade",
3132 config: Config{
3133 MaxVersion: VersionTLS12,
3134 Bugs: ProtocolBugs{
3135 NoExtendedMasterSecret: true,
3136 },
3137 },
3138 renegotiate: 1,
3139 flags: []string{
3140 "-renegotiate-freely",
3141 "-expect-total-renegotiations", "1",
3142 },
3143 shouldFail: true,
3144 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3145 })
3146
3147 testCases = append(testCases, testCase{
3148 name: "ExtendedMasterSecret-Renego-Downgrade",
3149 config: Config{
3150 MaxVersion: VersionTLS12,
3151 Bugs: ProtocolBugs{
3152 NoExtendedMasterSecretOnRenegotiation: true,
3153 },
3154 },
3155 renegotiate: 1,
3156 flags: []string{
3157 "-renegotiate-freely",
3158 "-expect-total-renegotiations", "1",
3159 },
3160 shouldFail: true,
3161 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3162 })
Adam Langley75712922014-10-10 16:23:43 -07003163}
3164
David Benjamin582ba042016-07-07 12:33:25 -07003165type stateMachineTestConfig struct {
3166 protocol protocol
3167 async bool
3168 splitHandshake, packHandshakeFlight bool
3169}
3170
David Benjamin43ec06f2014-08-05 02:28:57 -04003171// Adds tests that try to cover the range of the handshake state machine, under
3172// various conditions. Some of these are redundant with other tests, but they
3173// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003174func addAllStateMachineCoverageTests() {
3175 for _, async := range []bool{false, true} {
3176 for _, protocol := range []protocol{tls, dtls} {
3177 addStateMachineCoverageTests(stateMachineTestConfig{
3178 protocol: protocol,
3179 async: async,
3180 })
3181 addStateMachineCoverageTests(stateMachineTestConfig{
3182 protocol: protocol,
3183 async: async,
3184 splitHandshake: true,
3185 })
3186 if protocol == tls {
3187 addStateMachineCoverageTests(stateMachineTestConfig{
3188 protocol: protocol,
3189 async: async,
3190 packHandshakeFlight: true,
3191 })
3192 }
3193 }
3194 }
3195}
3196
3197func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 var tests []testCase
3199
3200 // Basic handshake, with resumption. Client and server,
3201 // session ID and session ticket.
3202 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003203 name: "Basic-Client",
3204 config: Config{
3205 MaxVersion: VersionTLS12,
3206 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003207 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003208 // Ensure session tickets are used, not session IDs.
3209 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 })
3211 tests = append(tests, testCase{
3212 name: "Basic-Client-RenewTicket",
3213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003214 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003215 Bugs: ProtocolBugs{
3216 RenewTicketOnResume: true,
3217 },
3218 },
David Benjamin46662482016-08-17 00:51:00 -04003219 flags: []string{"-expect-ticket-renewal"},
3220 resumeSession: true,
3221 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003222 })
3223 tests = append(tests, testCase{
3224 name: "Basic-Client-NoTicket",
3225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003226 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003227 SessionTicketsDisabled: true,
3228 },
3229 resumeSession: true,
3230 })
3231 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003232 name: "Basic-Client-Implicit",
3233 config: Config{
3234 MaxVersion: VersionTLS12,
3235 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003236 flags: []string{"-implicit-handshake"},
3237 resumeSession: true,
3238 })
3239 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003240 testType: serverTest,
3241 name: "Basic-Server",
3242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003243 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003244 Bugs: ProtocolBugs{
3245 RequireSessionTickets: true,
3246 },
3247 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003248 resumeSession: true,
3249 })
3250 tests = append(tests, testCase{
3251 testType: serverTest,
3252 name: "Basic-Server-NoTickets",
3253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003254 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003255 SessionTicketsDisabled: true,
3256 },
3257 resumeSession: true,
3258 })
3259 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003260 testType: serverTest,
3261 name: "Basic-Server-Implicit",
3262 config: Config{
3263 MaxVersion: VersionTLS12,
3264 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003265 flags: []string{"-implicit-handshake"},
3266 resumeSession: true,
3267 })
3268 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003269 testType: serverTest,
3270 name: "Basic-Server-EarlyCallback",
3271 config: Config{
3272 MaxVersion: VersionTLS12,
3273 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003274 flags: []string{"-use-early-callback"},
3275 resumeSession: true,
3276 })
3277
Steven Valdez143e8b32016-07-11 13:19:03 -04003278 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003279 if config.protocol == tls {
3280 tests = append(tests, testCase{
3281 name: "TLS13-1RTT-Client",
3282 config: Config{
3283 MaxVersion: VersionTLS13,
3284 MinVersion: VersionTLS13,
3285 },
David Benjamin46662482016-08-17 00:51:00 -04003286 resumeSession: true,
3287 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003288 })
3289
3290 tests = append(tests, testCase{
3291 testType: serverTest,
3292 name: "TLS13-1RTT-Server",
3293 config: Config{
3294 MaxVersion: VersionTLS13,
3295 MinVersion: VersionTLS13,
3296 },
David Benjamin46662482016-08-17 00:51:00 -04003297 resumeSession: true,
3298 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003299 })
3300
3301 tests = append(tests, testCase{
3302 name: "TLS13-HelloRetryRequest-Client",
3303 config: Config{
3304 MaxVersion: VersionTLS13,
3305 MinVersion: VersionTLS13,
3306 // P-384 requires a HelloRetryRequest against
3307 // BoringSSL's default configuration. Assert
3308 // that we do indeed test this with
3309 // ExpectMissingKeyShare.
3310 CurvePreferences: []CurveID{CurveP384},
3311 Bugs: ProtocolBugs{
3312 ExpectMissingKeyShare: true,
3313 },
3314 },
3315 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3316 resumeSession: true,
3317 })
3318
3319 tests = append(tests, testCase{
3320 testType: serverTest,
3321 name: "TLS13-HelloRetryRequest-Server",
3322 config: Config{
3323 MaxVersion: VersionTLS13,
3324 MinVersion: VersionTLS13,
3325 // Require a HelloRetryRequest for every curve.
3326 DefaultCurves: []CurveID{},
3327 },
3328 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3329 resumeSession: true,
3330 })
3331 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003332
David Benjamin760b1dd2015-05-15 23:33:48 -04003333 // TLS client auth.
3334 tests = append(tests, testCase{
3335 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003336 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003338 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003339 ClientAuth: RequestClientCert,
3340 },
3341 })
3342 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003343 testType: serverTest,
3344 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003345 config: Config{
3346 MaxVersion: VersionTLS12,
3347 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003348 // Setting SSL_VERIFY_PEER allows anonymous clients.
3349 flags: []string{"-verify-peer"},
3350 })
David Benjamin582ba042016-07-07 12:33:25 -07003351 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003352 tests = append(tests, testCase{
3353 testType: clientTest,
3354 name: "ClientAuth-NoCertificate-Client-SSL3",
3355 config: Config{
3356 MaxVersion: VersionSSL30,
3357 ClientAuth: RequestClientCert,
3358 },
3359 })
3360 tests = append(tests, testCase{
3361 testType: serverTest,
3362 name: "ClientAuth-NoCertificate-Server-SSL3",
3363 config: Config{
3364 MaxVersion: VersionSSL30,
3365 },
3366 // Setting SSL_VERIFY_PEER allows anonymous clients.
3367 flags: []string{"-verify-peer"},
3368 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003369 tests = append(tests, testCase{
3370 testType: clientTest,
3371 name: "ClientAuth-NoCertificate-Client-TLS13",
3372 config: Config{
3373 MaxVersion: VersionTLS13,
3374 ClientAuth: RequestClientCert,
3375 },
3376 })
3377 tests = append(tests, testCase{
3378 testType: serverTest,
3379 name: "ClientAuth-NoCertificate-Server-TLS13",
3380 config: Config{
3381 MaxVersion: VersionTLS13,
3382 },
3383 // Setting SSL_VERIFY_PEER allows anonymous clients.
3384 flags: []string{"-verify-peer"},
3385 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003386 }
3387 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003388 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003389 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003391 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003392 ClientAuth: RequireAnyClientCert,
3393 },
3394 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003395 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3396 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003397 },
3398 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003399 tests = append(tests, testCase{
3400 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003401 name: "ClientAuth-RSA-Client-TLS13",
3402 config: Config{
3403 MaxVersion: VersionTLS13,
3404 ClientAuth: RequireAnyClientCert,
3405 },
3406 flags: []string{
3407 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3408 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3409 },
3410 })
3411 tests = append(tests, testCase{
3412 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003413 name: "ClientAuth-ECDSA-Client",
3414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003415 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003416 ClientAuth: RequireAnyClientCert,
3417 },
3418 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003419 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3420 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003421 },
3422 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003423 tests = append(tests, testCase{
3424 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003425 name: "ClientAuth-ECDSA-Client-TLS13",
3426 config: Config{
3427 MaxVersion: VersionTLS13,
3428 ClientAuth: RequireAnyClientCert,
3429 },
3430 flags: []string{
3431 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3432 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3433 },
3434 })
3435 tests = append(tests, testCase{
3436 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003437 name: "ClientAuth-NoCertificate-OldCallback",
3438 config: Config{
3439 MaxVersion: VersionTLS12,
3440 ClientAuth: RequestClientCert,
3441 },
3442 flags: []string{"-use-old-client-cert-callback"},
3443 })
3444 tests = append(tests, testCase{
3445 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003446 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3447 config: Config{
3448 MaxVersion: VersionTLS13,
3449 ClientAuth: RequestClientCert,
3450 },
3451 flags: []string{"-use-old-client-cert-callback"},
3452 })
3453 tests = append(tests, testCase{
3454 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003455 name: "ClientAuth-OldCallback",
3456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003457 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003458 ClientAuth: RequireAnyClientCert,
3459 },
3460 flags: []string{
3461 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3462 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3463 "-use-old-client-cert-callback",
3464 },
3465 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003466 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003467 testType: clientTest,
3468 name: "ClientAuth-OldCallback-TLS13",
3469 config: Config{
3470 MaxVersion: VersionTLS13,
3471 ClientAuth: RequireAnyClientCert,
3472 },
3473 flags: []string{
3474 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3475 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3476 "-use-old-client-cert-callback",
3477 },
3478 })
3479 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003480 testType: serverTest,
3481 name: "ClientAuth-Server",
3482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003483 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003484 Certificates: []Certificate{rsaCertificate},
3485 },
3486 flags: []string{"-require-any-client-certificate"},
3487 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003488 tests = append(tests, testCase{
3489 testType: serverTest,
3490 name: "ClientAuth-Server-TLS13",
3491 config: Config{
3492 MaxVersion: VersionTLS13,
3493 Certificates: []Certificate{rsaCertificate},
3494 },
3495 flags: []string{"-require-any-client-certificate"},
3496 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003497
David Benjamin4c3ddf72016-06-29 18:13:53 -04003498 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003499 tests = append(tests, testCase{
3500 testType: serverTest,
3501 name: "Basic-Server-RSA",
3502 config: Config{
3503 MaxVersion: VersionTLS12,
3504 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3505 },
3506 flags: []string{
3507 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3508 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3509 },
3510 })
3511 tests = append(tests, testCase{
3512 testType: serverTest,
3513 name: "Basic-Server-ECDHE-RSA",
3514 config: Config{
3515 MaxVersion: VersionTLS12,
3516 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3517 },
3518 flags: []string{
3519 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3520 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3521 },
3522 })
3523 tests = append(tests, testCase{
3524 testType: serverTest,
3525 name: "Basic-Server-ECDHE-ECDSA",
3526 config: Config{
3527 MaxVersion: VersionTLS12,
3528 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3529 },
3530 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003531 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3532 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003533 },
3534 })
3535
David Benjamin760b1dd2015-05-15 23:33:48 -04003536 // No session ticket support; server doesn't send NewSessionTicket.
3537 tests = append(tests, testCase{
3538 name: "SessionTicketsDisabled-Client",
3539 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003540 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003541 SessionTicketsDisabled: true,
3542 },
3543 })
3544 tests = append(tests, testCase{
3545 testType: serverTest,
3546 name: "SessionTicketsDisabled-Server",
3547 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003548 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003549 SessionTicketsDisabled: true,
3550 },
3551 })
3552
3553 // Skip ServerKeyExchange in PSK key exchange if there's no
3554 // identity hint.
3555 tests = append(tests, testCase{
3556 name: "EmptyPSKHint-Client",
3557 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003558 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003559 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3560 PreSharedKey: []byte("secret"),
3561 },
3562 flags: []string{"-psk", "secret"},
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "EmptyPSKHint-Server",
3567 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003568 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3570 PreSharedKey: []byte("secret"),
3571 },
3572 flags: []string{"-psk", "secret"},
3573 })
3574
David Benjamin4c3ddf72016-06-29 18:13:53 -04003575 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003576 tests = append(tests, testCase{
3577 testType: clientTest,
3578 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003579 config: Config{
3580 MaxVersion: VersionTLS12,
3581 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003582 flags: []string{
3583 "-enable-ocsp-stapling",
3584 "-expect-ocsp-response",
3585 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003586 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003587 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003588 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003589 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003590 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003591 testType: serverTest,
3592 name: "OCSPStapling-Server",
3593 config: Config{
3594 MaxVersion: VersionTLS12,
3595 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003596 expectedOCSPResponse: testOCSPResponse,
3597 flags: []string{
3598 "-ocsp-response",
3599 base64.StdEncoding.EncodeToString(testOCSPResponse),
3600 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003601 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003602 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003603 tests = append(tests, testCase{
3604 testType: clientTest,
3605 name: "OCSPStapling-Client-TLS13",
3606 config: Config{
3607 MaxVersion: VersionTLS13,
3608 },
3609 flags: []string{
3610 "-enable-ocsp-stapling",
3611 "-expect-ocsp-response",
3612 base64.StdEncoding.EncodeToString(testOCSPResponse),
3613 "-verify-peer",
3614 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003615 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003616 })
3617 tests = append(tests, testCase{
3618 testType: serverTest,
3619 name: "OCSPStapling-Server-TLS13",
3620 config: Config{
3621 MaxVersion: VersionTLS13,
3622 },
3623 expectedOCSPResponse: testOCSPResponse,
3624 flags: []string{
3625 "-ocsp-response",
3626 base64.StdEncoding.EncodeToString(testOCSPResponse),
3627 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003628 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003629 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003630
David Benjamin4c3ddf72016-06-29 18:13:53 -04003631 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003632 for _, vers := range tlsVersions {
3633 if config.protocol == dtls && !vers.hasDTLS {
3634 continue
3635 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003636 for _, testType := range []testType{clientTest, serverTest} {
3637 suffix := "-Client"
3638 if testType == serverTest {
3639 suffix = "-Server"
3640 }
3641 suffix += "-" + vers.name
3642
3643 flag := "-verify-peer"
3644 if testType == serverTest {
3645 flag = "-require-any-client-certificate"
3646 }
3647
3648 tests = append(tests, testCase{
3649 testType: testType,
3650 name: "CertificateVerificationSucceed" + suffix,
3651 config: Config{
3652 MaxVersion: vers.version,
3653 Certificates: []Certificate{rsaCertificate},
3654 },
3655 flags: []string{
3656 flag,
3657 "-expect-verify-result",
3658 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003659 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003660 })
3661 tests = append(tests, testCase{
3662 testType: testType,
3663 name: "CertificateVerificationFail" + suffix,
3664 config: Config{
3665 MaxVersion: vers.version,
3666 Certificates: []Certificate{rsaCertificate},
3667 },
3668 flags: []string{
3669 flag,
3670 "-verify-fail",
3671 },
3672 shouldFail: true,
3673 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3674 })
3675 }
3676
3677 // By default, the client is in a soft fail mode where the peer
3678 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003679 tests = append(tests, testCase{
3680 testType: clientTest,
3681 name: "CertificateVerificationSoftFail-" + vers.name,
3682 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003683 MaxVersion: vers.version,
3684 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003685 },
3686 flags: []string{
3687 "-verify-fail",
3688 "-expect-verify-result",
3689 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003690 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003691 })
3692 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003693
David Benjamin1d4f4c02016-07-26 18:03:08 -04003694 tests = append(tests, testCase{
3695 name: "ShimSendAlert",
3696 flags: []string{"-send-alert"},
3697 shimWritesFirst: true,
3698 shouldFail: true,
3699 expectedLocalError: "remote error: decompression failure",
3700 })
3701
David Benjamin582ba042016-07-07 12:33:25 -07003702 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003703 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003704 name: "Renegotiate-Client",
3705 config: Config{
3706 MaxVersion: VersionTLS12,
3707 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003708 renegotiate: 1,
3709 flags: []string{
3710 "-renegotiate-freely",
3711 "-expect-total-renegotiations", "1",
3712 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003713 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003714
David Benjamin47921102016-07-28 11:29:18 -04003715 tests = append(tests, testCase{
3716 name: "SendHalfHelloRequest",
3717 config: Config{
3718 MaxVersion: VersionTLS12,
3719 Bugs: ProtocolBugs{
3720 PackHelloRequestWithFinished: config.packHandshakeFlight,
3721 },
3722 },
3723 sendHalfHelloRequest: true,
3724 flags: []string{"-renegotiate-ignore"},
3725 shouldFail: true,
3726 expectedError: ":UNEXPECTED_RECORD:",
3727 })
3728
David Benjamin760b1dd2015-05-15 23:33:48 -04003729 // NPN on client and server; results in post-handshake message.
3730 tests = append(tests, testCase{
3731 name: "NPN-Client",
3732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003733 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 NextProtos: []string{"foo"},
3735 },
3736 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003737 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003738 expectedNextProto: "foo",
3739 expectedNextProtoType: npn,
3740 })
3741 tests = append(tests, testCase{
3742 testType: serverTest,
3743 name: "NPN-Server",
3744 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003745 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003746 NextProtos: []string{"bar"},
3747 },
3748 flags: []string{
3749 "-advertise-npn", "\x03foo\x03bar\x03baz",
3750 "-expect-next-proto", "bar",
3751 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003752 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003753 expectedNextProto: "bar",
3754 expectedNextProtoType: npn,
3755 })
3756
3757 // TODO(davidben): Add tests for when False Start doesn't trigger.
3758
3759 // Client does False Start and negotiates NPN.
3760 tests = append(tests, testCase{
3761 name: "FalseStart",
3762 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003763 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3765 NextProtos: []string{"foo"},
3766 Bugs: ProtocolBugs{
3767 ExpectFalseStart: true,
3768 },
3769 },
3770 flags: []string{
3771 "-false-start",
3772 "-select-next-proto", "foo",
3773 },
3774 shimWritesFirst: true,
3775 resumeSession: true,
3776 })
3777
3778 // Client does False Start and negotiates ALPN.
3779 tests = append(tests, testCase{
3780 name: "FalseStart-ALPN",
3781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003782 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3784 NextProtos: []string{"foo"},
3785 Bugs: ProtocolBugs{
3786 ExpectFalseStart: true,
3787 },
3788 },
3789 flags: []string{
3790 "-false-start",
3791 "-advertise-alpn", "\x03foo",
3792 },
3793 shimWritesFirst: true,
3794 resumeSession: true,
3795 })
3796
3797 // Client does False Start but doesn't explicitly call
3798 // SSL_connect.
3799 tests = append(tests, testCase{
3800 name: "FalseStart-Implicit",
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 },
3806 flags: []string{
3807 "-implicit-handshake",
3808 "-false-start",
3809 "-advertise-alpn", "\x03foo",
3810 },
3811 })
3812
3813 // False Start without session tickets.
3814 tests = append(tests, testCase{
3815 name: "FalseStart-SessionTicketsDisabled",
3816 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003817 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3819 NextProtos: []string{"foo"},
3820 SessionTicketsDisabled: true,
3821 Bugs: ProtocolBugs{
3822 ExpectFalseStart: true,
3823 },
3824 },
3825 flags: []string{
3826 "-false-start",
3827 "-select-next-proto", "foo",
3828 },
3829 shimWritesFirst: true,
3830 })
3831
Adam Langleydf759b52016-07-11 15:24:37 -07003832 tests = append(tests, testCase{
3833 name: "FalseStart-CECPQ1",
3834 config: Config{
3835 MaxVersion: VersionTLS12,
3836 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3837 NextProtos: []string{"foo"},
3838 Bugs: ProtocolBugs{
3839 ExpectFalseStart: true,
3840 },
3841 },
3842 flags: []string{
3843 "-false-start",
3844 "-cipher", "DEFAULT:kCECPQ1",
3845 "-select-next-proto", "foo",
3846 },
3847 shimWritesFirst: true,
3848 resumeSession: true,
3849 })
3850
David Benjamin760b1dd2015-05-15 23:33:48 -04003851 // Server parses a V2ClientHello.
3852 tests = append(tests, testCase{
3853 testType: serverTest,
3854 name: "SendV2ClientHello",
3855 config: Config{
3856 // Choose a cipher suite that does not involve
3857 // elliptic curves, so no extensions are
3858 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003859 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003860 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003861 Bugs: ProtocolBugs{
3862 SendV2ClientHello: true,
3863 },
3864 },
3865 })
3866
3867 // Client sends a Channel ID.
3868 tests = append(tests, testCase{
3869 name: "ChannelID-Client",
3870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003871 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003872 RequestChannelID: true,
3873 },
Adam Langley7c803a62015-06-15 15:35:05 -07003874 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 resumeSession: true,
3876 expectChannelID: true,
3877 })
3878
3879 // Server accepts a Channel ID.
3880 tests = append(tests, testCase{
3881 testType: serverTest,
3882 name: "ChannelID-Server",
3883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003884 MaxVersion: VersionTLS12,
3885 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003886 },
3887 flags: []string{
3888 "-expect-channel-id",
3889 base64.StdEncoding.EncodeToString(channelIDBytes),
3890 },
3891 resumeSession: true,
3892 expectChannelID: true,
3893 })
David Benjamin30789da2015-08-29 22:56:45 -04003894
David Benjaminf8fcdf32016-06-08 15:56:13 -04003895 // Channel ID and NPN at the same time, to ensure their relative
3896 // ordering is correct.
3897 tests = append(tests, testCase{
3898 name: "ChannelID-NPN-Client",
3899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003900 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003901 RequestChannelID: true,
3902 NextProtos: []string{"foo"},
3903 },
3904 flags: []string{
3905 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3906 "-select-next-proto", "foo",
3907 },
3908 resumeSession: true,
3909 expectChannelID: true,
3910 expectedNextProto: "foo",
3911 expectedNextProtoType: npn,
3912 })
3913 tests = append(tests, testCase{
3914 testType: serverTest,
3915 name: "ChannelID-NPN-Server",
3916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003917 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003918 ChannelID: channelIDKey,
3919 NextProtos: []string{"bar"},
3920 },
3921 flags: []string{
3922 "-expect-channel-id",
3923 base64.StdEncoding.EncodeToString(channelIDBytes),
3924 "-advertise-npn", "\x03foo\x03bar\x03baz",
3925 "-expect-next-proto", "bar",
3926 },
3927 resumeSession: true,
3928 expectChannelID: true,
3929 expectedNextProto: "bar",
3930 expectedNextProtoType: npn,
3931 })
3932
David Benjamin30789da2015-08-29 22:56:45 -04003933 // Bidirectional shutdown with the runner initiating.
3934 tests = append(tests, testCase{
3935 name: "Shutdown-Runner",
3936 config: Config{
3937 Bugs: ProtocolBugs{
3938 ExpectCloseNotify: true,
3939 },
3940 },
3941 flags: []string{"-check-close-notify"},
3942 })
3943
3944 // Bidirectional shutdown with the shim initiating. The runner,
3945 // in the meantime, sends garbage before the close_notify which
3946 // the shim must ignore.
3947 tests = append(tests, testCase{
3948 name: "Shutdown-Shim",
3949 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003950 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003951 Bugs: ProtocolBugs{
3952 ExpectCloseNotify: true,
3953 },
3954 },
3955 shimShutsDown: true,
3956 sendEmptyRecords: 1,
3957 sendWarningAlerts: 1,
3958 flags: []string{"-check-close-notify"},
3959 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003960 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003961 // TODO(davidben): DTLS 1.3 will want a similar thing for
3962 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 tests = append(tests, testCase{
3964 name: "SkipHelloVerifyRequest",
3965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003966 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003967 Bugs: ProtocolBugs{
3968 SkipHelloVerifyRequest: true,
3969 },
3970 },
3971 })
3972 }
3973
David Benjamin760b1dd2015-05-15 23:33:48 -04003974 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003975 test.protocol = config.protocol
3976 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003977 test.name += "-DTLS"
3978 }
David Benjamin582ba042016-07-07 12:33:25 -07003979 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003980 test.name += "-Async"
3981 test.flags = append(test.flags, "-async")
3982 } else {
3983 test.name += "-Sync"
3984 }
David Benjamin582ba042016-07-07 12:33:25 -07003985 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003986 test.name += "-SplitHandshakeRecords"
3987 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003988 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003989 test.config.Bugs.MaxPacketLength = 256
3990 test.flags = append(test.flags, "-mtu", "256")
3991 }
3992 }
David Benjamin582ba042016-07-07 12:33:25 -07003993 if config.packHandshakeFlight {
3994 test.name += "-PackHandshakeFlight"
3995 test.config.Bugs.PackHandshakeFlight = true
3996 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003998 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003999}
4000
Adam Langley524e7172015-02-20 16:04:00 -08004001func addDDoSCallbackTests() {
4002 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004003 for _, resume := range []bool{false, true} {
4004 suffix := "Resume"
4005 if resume {
4006 suffix = "No" + suffix
4007 }
4008
4009 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004010 testType: serverTest,
4011 name: "Server-DDoS-OK-" + suffix,
4012 config: Config{
4013 MaxVersion: VersionTLS12,
4014 },
Adam Langley524e7172015-02-20 16:04:00 -08004015 flags: []string{"-install-ddos-callback"},
4016 resumeSession: resume,
4017 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004018 testCases = append(testCases, testCase{
4019 testType: serverTest,
4020 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4021 config: Config{
4022 MaxVersion: VersionTLS13,
4023 },
4024 flags: []string{"-install-ddos-callback"},
4025 resumeSession: resume,
4026 })
Adam Langley524e7172015-02-20 16:04:00 -08004027
4028 failFlag := "-fail-ddos-callback"
4029 if resume {
4030 failFlag = "-fail-second-ddos-callback"
4031 }
4032 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004033 testType: serverTest,
4034 name: "Server-DDoS-Reject-" + suffix,
4035 config: Config{
4036 MaxVersion: VersionTLS12,
4037 },
David Benjamin2c66e072016-09-16 15:58:00 -04004038 flags: []string{"-install-ddos-callback", failFlag},
4039 resumeSession: resume,
4040 shouldFail: true,
4041 expectedError: ":CONNECTION_REJECTED:",
4042 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004043 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004044 testCases = append(testCases, testCase{
4045 testType: serverTest,
4046 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4047 config: Config{
4048 MaxVersion: VersionTLS13,
4049 },
David Benjamin2c66e072016-09-16 15:58:00 -04004050 flags: []string{"-install-ddos-callback", failFlag},
4051 resumeSession: resume,
4052 shouldFail: true,
4053 expectedError: ":CONNECTION_REJECTED:",
4054 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004055 })
Adam Langley524e7172015-02-20 16:04:00 -08004056 }
4057}
4058
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004059func addVersionNegotiationTests() {
4060 for i, shimVers := range tlsVersions {
4061 // Assemble flags to disable all newer versions on the shim.
4062 var flags []string
4063 for _, vers := range tlsVersions[i+1:] {
4064 flags = append(flags, vers.flag)
4065 }
4066
4067 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004068 protocols := []protocol{tls}
4069 if runnerVers.hasDTLS && shimVers.hasDTLS {
4070 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004071 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004072 for _, protocol := range protocols {
4073 expectedVersion := shimVers.version
4074 if runnerVers.version < shimVers.version {
4075 expectedVersion = runnerVers.version
4076 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004077
David Benjamin8b8c0062014-11-23 02:47:52 -05004078 suffix := shimVers.name + "-" + runnerVers.name
4079 if protocol == dtls {
4080 suffix += "-DTLS"
4081 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004082
David Benjamin1eb367c2014-12-12 18:17:51 -05004083 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4084
David Benjamin1e29a6b2014-12-10 02:27:24 -05004085 clientVers := shimVers.version
4086 if clientVers > VersionTLS10 {
4087 clientVers = VersionTLS10
4088 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004089 serverVers := expectedVersion
4090 if expectedVersion >= VersionTLS13 {
4091 serverVers = VersionTLS10
4092 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004093 testCases = append(testCases, testCase{
4094 protocol: protocol,
4095 testType: clientTest,
4096 name: "VersionNegotiation-Client-" + suffix,
4097 config: Config{
4098 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004099 Bugs: ProtocolBugs{
4100 ExpectInitialRecordVersion: clientVers,
4101 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004102 },
4103 flags: flags,
4104 expectedVersion: expectedVersion,
4105 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004106 testCases = append(testCases, testCase{
4107 protocol: protocol,
4108 testType: clientTest,
4109 name: "VersionNegotiation-Client2-" + suffix,
4110 config: Config{
4111 MaxVersion: runnerVers.version,
4112 Bugs: ProtocolBugs{
4113 ExpectInitialRecordVersion: clientVers,
4114 },
4115 },
4116 flags: []string{"-max-version", shimVersFlag},
4117 expectedVersion: expectedVersion,
4118 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004119
4120 testCases = append(testCases, testCase{
4121 protocol: protocol,
4122 testType: serverTest,
4123 name: "VersionNegotiation-Server-" + suffix,
4124 config: Config{
4125 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004126 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004127 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004128 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004129 },
4130 flags: flags,
4131 expectedVersion: expectedVersion,
4132 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004133 testCases = append(testCases, testCase{
4134 protocol: protocol,
4135 testType: serverTest,
4136 name: "VersionNegotiation-Server2-" + suffix,
4137 config: Config{
4138 MaxVersion: runnerVers.version,
4139 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004140 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004141 },
4142 },
4143 flags: []string{"-max-version", shimVersFlag},
4144 expectedVersion: expectedVersion,
4145 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004146 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004147 }
4148 }
David Benjamin95c69562016-06-29 18:15:03 -04004149
4150 // Test for version tolerance.
4151 testCases = append(testCases, testCase{
4152 testType: serverTest,
4153 name: "MinorVersionTolerance",
4154 config: Config{
4155 Bugs: ProtocolBugs{
4156 SendClientVersion: 0x03ff,
4157 },
4158 },
4159 expectedVersion: VersionTLS13,
4160 })
4161 testCases = append(testCases, testCase{
4162 testType: serverTest,
4163 name: "MajorVersionTolerance",
4164 config: Config{
4165 Bugs: ProtocolBugs{
4166 SendClientVersion: 0x0400,
4167 },
4168 },
4169 expectedVersion: VersionTLS13,
4170 })
4171 testCases = append(testCases, testCase{
4172 protocol: dtls,
4173 testType: serverTest,
4174 name: "MinorVersionTolerance-DTLS",
4175 config: Config{
4176 Bugs: ProtocolBugs{
4177 SendClientVersion: 0x03ff,
4178 },
4179 },
4180 expectedVersion: VersionTLS12,
4181 })
4182 testCases = append(testCases, testCase{
4183 protocol: dtls,
4184 testType: serverTest,
4185 name: "MajorVersionTolerance-DTLS",
4186 config: Config{
4187 Bugs: ProtocolBugs{
4188 SendClientVersion: 0x0400,
4189 },
4190 },
4191 expectedVersion: VersionTLS12,
4192 })
4193
4194 // Test that versions below 3.0 are rejected.
4195 testCases = append(testCases, testCase{
4196 testType: serverTest,
4197 name: "VersionTooLow",
4198 config: Config{
4199 Bugs: ProtocolBugs{
4200 SendClientVersion: 0x0200,
4201 },
4202 },
4203 shouldFail: true,
4204 expectedError: ":UNSUPPORTED_PROTOCOL:",
4205 })
4206 testCases = append(testCases, testCase{
4207 protocol: dtls,
4208 testType: serverTest,
4209 name: "VersionTooLow-DTLS",
4210 config: Config{
4211 Bugs: ProtocolBugs{
4212 // 0x0201 is the lowest version expressable in
4213 // DTLS.
4214 SendClientVersion: 0x0201,
4215 },
4216 },
4217 shouldFail: true,
4218 expectedError: ":UNSUPPORTED_PROTOCOL:",
4219 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004220
David Benjamin2dc02042016-09-19 19:57:37 -04004221 testCases = append(testCases, testCase{
4222 name: "ServerBogusVersion",
4223 config: Config{
4224 Bugs: ProtocolBugs{
4225 SendServerHelloVersion: 0x1234,
4226 },
4227 },
4228 shouldFail: true,
4229 expectedError: ":UNSUPPORTED_PROTOCOL:",
4230 })
4231
David Benjamin1f61f0d2016-07-10 12:20:35 -04004232 // Test TLS 1.3's downgrade signal.
4233 testCases = append(testCases, testCase{
4234 name: "Downgrade-TLS12-Client",
4235 config: Config{
4236 Bugs: ProtocolBugs{
4237 NegotiateVersion: VersionTLS12,
4238 },
4239 },
David Benjamin55108632016-08-11 22:01:18 -04004240 // TODO(davidben): This test should fail once TLS 1.3 is final
4241 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004242 })
4243 testCases = append(testCases, testCase{
4244 testType: serverTest,
4245 name: "Downgrade-TLS12-Server",
4246 config: Config{
4247 Bugs: ProtocolBugs{
4248 SendClientVersion: VersionTLS12,
4249 },
4250 },
David Benjamin55108632016-08-11 22:01:18 -04004251 // TODO(davidben): This test should fail once TLS 1.3 is final
4252 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004253 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004254}
4255
David Benjaminaccb4542014-12-12 23:44:33 -05004256func addMinimumVersionTests() {
4257 for i, shimVers := range tlsVersions {
4258 // Assemble flags to disable all older versions on the shim.
4259 var flags []string
4260 for _, vers := range tlsVersions[:i] {
4261 flags = append(flags, vers.flag)
4262 }
4263
4264 for _, runnerVers := range tlsVersions {
4265 protocols := []protocol{tls}
4266 if runnerVers.hasDTLS && shimVers.hasDTLS {
4267 protocols = append(protocols, dtls)
4268 }
4269 for _, protocol := range protocols {
4270 suffix := shimVers.name + "-" + runnerVers.name
4271 if protocol == dtls {
4272 suffix += "-DTLS"
4273 }
4274 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4275
David Benjaminaccb4542014-12-12 23:44:33 -05004276 var expectedVersion uint16
4277 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004278 var expectedClientError, expectedServerError string
4279 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004280 if runnerVers.version >= shimVers.version {
4281 expectedVersion = runnerVers.version
4282 } else {
4283 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004284 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4285 expectedServerLocalError = "remote error: protocol version not supported"
4286 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4287 // If the client's minimum version is TLS 1.3 and the runner's
4288 // maximum is below TLS 1.2, the runner will fail to select a
4289 // cipher before the shim rejects the selected version.
4290 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4291 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4292 } else {
4293 expectedClientError = expectedServerError
4294 expectedClientLocalError = expectedServerLocalError
4295 }
David Benjaminaccb4542014-12-12 23:44:33 -05004296 }
4297
4298 testCases = append(testCases, testCase{
4299 protocol: protocol,
4300 testType: clientTest,
4301 name: "MinimumVersion-Client-" + suffix,
4302 config: Config{
4303 MaxVersion: runnerVers.version,
4304 },
David Benjamin87909c02014-12-13 01:55:01 -05004305 flags: flags,
4306 expectedVersion: expectedVersion,
4307 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004308 expectedError: expectedClientError,
4309 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004310 })
4311 testCases = append(testCases, testCase{
4312 protocol: protocol,
4313 testType: clientTest,
4314 name: "MinimumVersion-Client2-" + suffix,
4315 config: Config{
4316 MaxVersion: runnerVers.version,
4317 },
David Benjamin87909c02014-12-13 01:55:01 -05004318 flags: []string{"-min-version", shimVersFlag},
4319 expectedVersion: expectedVersion,
4320 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004321 expectedError: expectedClientError,
4322 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004323 })
4324
4325 testCases = append(testCases, testCase{
4326 protocol: protocol,
4327 testType: serverTest,
4328 name: "MinimumVersion-Server-" + suffix,
4329 config: Config{
4330 MaxVersion: runnerVers.version,
4331 },
David Benjamin87909c02014-12-13 01:55:01 -05004332 flags: flags,
4333 expectedVersion: expectedVersion,
4334 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004335 expectedError: expectedServerError,
4336 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004337 })
4338 testCases = append(testCases, testCase{
4339 protocol: protocol,
4340 testType: serverTest,
4341 name: "MinimumVersion-Server2-" + suffix,
4342 config: Config{
4343 MaxVersion: runnerVers.version,
4344 },
David Benjamin87909c02014-12-13 01:55:01 -05004345 flags: []string{"-min-version", shimVersFlag},
4346 expectedVersion: expectedVersion,
4347 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004348 expectedError: expectedServerError,
4349 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004350 })
4351 }
4352 }
4353 }
4354}
4355
David Benjamine78bfde2014-09-06 12:45:15 -04004356func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004357 // TODO(davidben): Extensions, where applicable, all move their server
4358 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4359 // tests for both. Also test interaction with 0-RTT when implemented.
4360
David Benjamin97d17d92016-07-14 16:12:00 -04004361 // Repeat extensions tests all versions except SSL 3.0.
4362 for _, ver := range tlsVersions {
4363 if ver.version == VersionSSL30 {
4364 continue
4365 }
4366
David Benjamin97d17d92016-07-14 16:12:00 -04004367 // Test that duplicate extensions are rejected.
4368 testCases = append(testCases, testCase{
4369 testType: clientTest,
4370 name: "DuplicateExtensionClient-" + ver.name,
4371 config: Config{
4372 MaxVersion: ver.version,
4373 Bugs: ProtocolBugs{
4374 DuplicateExtension: true,
4375 },
David Benjamine78bfde2014-09-06 12:45:15 -04004376 },
David Benjamin97d17d92016-07-14 16:12:00 -04004377 shouldFail: true,
4378 expectedLocalError: "remote error: error decoding message",
4379 })
4380 testCases = append(testCases, testCase{
4381 testType: serverTest,
4382 name: "DuplicateExtensionServer-" + ver.name,
4383 config: Config{
4384 MaxVersion: ver.version,
4385 Bugs: ProtocolBugs{
4386 DuplicateExtension: true,
4387 },
David Benjamine78bfde2014-09-06 12:45:15 -04004388 },
David Benjamin97d17d92016-07-14 16:12:00 -04004389 shouldFail: true,
4390 expectedLocalError: "remote error: error decoding message",
4391 })
4392
4393 // Test SNI.
4394 testCases = append(testCases, testCase{
4395 testType: clientTest,
4396 name: "ServerNameExtensionClient-" + ver.name,
4397 config: Config{
4398 MaxVersion: ver.version,
4399 Bugs: ProtocolBugs{
4400 ExpectServerName: "example.com",
4401 },
David Benjamine78bfde2014-09-06 12:45:15 -04004402 },
David Benjamin97d17d92016-07-14 16:12:00 -04004403 flags: []string{"-host-name", "example.com"},
4404 })
4405 testCases = append(testCases, testCase{
4406 testType: clientTest,
4407 name: "ServerNameExtensionClientMismatch-" + ver.name,
4408 config: Config{
4409 MaxVersion: ver.version,
4410 Bugs: ProtocolBugs{
4411 ExpectServerName: "mismatch.com",
4412 },
David Benjamine78bfde2014-09-06 12:45:15 -04004413 },
David Benjamin97d17d92016-07-14 16:12:00 -04004414 flags: []string{"-host-name", "example.com"},
4415 shouldFail: true,
4416 expectedLocalError: "tls: unexpected server name",
4417 })
4418 testCases = append(testCases, testCase{
4419 testType: clientTest,
4420 name: "ServerNameExtensionClientMissing-" + ver.name,
4421 config: Config{
4422 MaxVersion: ver.version,
4423 Bugs: ProtocolBugs{
4424 ExpectServerName: "missing.com",
4425 },
David Benjamine78bfde2014-09-06 12:45:15 -04004426 },
David Benjamin97d17d92016-07-14 16:12:00 -04004427 shouldFail: true,
4428 expectedLocalError: "tls: unexpected server name",
4429 })
4430 testCases = append(testCases, testCase{
4431 testType: serverTest,
4432 name: "ServerNameExtensionServer-" + ver.name,
4433 config: Config{
4434 MaxVersion: ver.version,
4435 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004436 },
David Benjamin97d17d92016-07-14 16:12:00 -04004437 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004438 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004439 })
4440
4441 // Test ALPN.
4442 testCases = append(testCases, testCase{
4443 testType: clientTest,
4444 name: "ALPNClient-" + ver.name,
4445 config: Config{
4446 MaxVersion: ver.version,
4447 NextProtos: []string{"foo"},
4448 },
4449 flags: []string{
4450 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4451 "-expect-alpn", "foo",
4452 },
4453 expectedNextProto: "foo",
4454 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004455 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004456 })
4457 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004458 testType: clientTest,
4459 name: "ALPNClient-Mismatch-" + ver.name,
4460 config: Config{
4461 MaxVersion: ver.version,
4462 Bugs: ProtocolBugs{
4463 SendALPN: "baz",
4464 },
4465 },
4466 flags: []string{
4467 "-advertise-alpn", "\x03foo\x03bar",
4468 },
4469 shouldFail: true,
4470 expectedError: ":INVALID_ALPN_PROTOCOL:",
4471 expectedLocalError: "remote error: illegal parameter",
4472 })
4473 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004474 testType: serverTest,
4475 name: "ALPNServer-" + ver.name,
4476 config: Config{
4477 MaxVersion: ver.version,
4478 NextProtos: []string{"foo", "bar", "baz"},
4479 },
4480 flags: []string{
4481 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4482 "-select-alpn", "foo",
4483 },
4484 expectedNextProto: "foo",
4485 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004486 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004487 })
4488 testCases = append(testCases, testCase{
4489 testType: serverTest,
4490 name: "ALPNServer-Decline-" + ver.name,
4491 config: Config{
4492 MaxVersion: ver.version,
4493 NextProtos: []string{"foo", "bar", "baz"},
4494 },
4495 flags: []string{"-decline-alpn"},
4496 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004497 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004498 })
4499
David Benjamin25fe85b2016-08-09 20:00:32 -04004500 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4501 // called once.
4502 testCases = append(testCases, testCase{
4503 testType: serverTest,
4504 name: "ALPNServer-Async-" + ver.name,
4505 config: Config{
4506 MaxVersion: ver.version,
4507 NextProtos: []string{"foo", "bar", "baz"},
4508 },
4509 flags: []string{
4510 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4511 "-select-alpn", "foo",
4512 "-async",
4513 },
4514 expectedNextProto: "foo",
4515 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004516 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004517 })
4518
David Benjamin97d17d92016-07-14 16:12:00 -04004519 var emptyString string
4520 testCases = append(testCases, testCase{
4521 testType: clientTest,
4522 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4523 config: Config{
4524 MaxVersion: ver.version,
4525 NextProtos: []string{""},
4526 Bugs: ProtocolBugs{
4527 // A server returning an empty ALPN protocol
4528 // should be rejected.
4529 ALPNProtocol: &emptyString,
4530 },
4531 },
4532 flags: []string{
4533 "-advertise-alpn", "\x03foo",
4534 },
4535 shouldFail: true,
4536 expectedError: ":PARSE_TLSEXT:",
4537 })
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4541 config: Config{
4542 MaxVersion: ver.version,
4543 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004544 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004545 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004546 },
David Benjamin97d17d92016-07-14 16:12:00 -04004547 flags: []string{
4548 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004549 },
David Benjamin97d17d92016-07-14 16:12:00 -04004550 shouldFail: true,
4551 expectedError: ":PARSE_TLSEXT:",
4552 })
4553
4554 // Test NPN and the interaction with ALPN.
4555 if ver.version < VersionTLS13 {
4556 // Test that the server prefers ALPN over NPN.
4557 testCases = append(testCases, testCase{
4558 testType: serverTest,
4559 name: "ALPNServer-Preferred-" + ver.name,
4560 config: Config{
4561 MaxVersion: ver.version,
4562 NextProtos: []string{"foo", "bar", "baz"},
4563 },
4564 flags: []string{
4565 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4566 "-select-alpn", "foo",
4567 "-advertise-npn", "\x03foo\x03bar\x03baz",
4568 },
4569 expectedNextProto: "foo",
4570 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004571 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004572 })
4573 testCases = append(testCases, testCase{
4574 testType: serverTest,
4575 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4576 config: Config{
4577 MaxVersion: ver.version,
4578 NextProtos: []string{"foo", "bar", "baz"},
4579 Bugs: ProtocolBugs{
4580 SwapNPNAndALPN: true,
4581 },
4582 },
4583 flags: []string{
4584 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4585 "-select-alpn", "foo",
4586 "-advertise-npn", "\x03foo\x03bar\x03baz",
4587 },
4588 expectedNextProto: "foo",
4589 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004590 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004591 })
4592
4593 // Test that negotiating both NPN and ALPN is forbidden.
4594 testCases = append(testCases, testCase{
4595 name: "NegotiateALPNAndNPN-" + ver.name,
4596 config: Config{
4597 MaxVersion: ver.version,
4598 NextProtos: []string{"foo", "bar", "baz"},
4599 Bugs: ProtocolBugs{
4600 NegotiateALPNAndNPN: true,
4601 },
4602 },
4603 flags: []string{
4604 "-advertise-alpn", "\x03foo",
4605 "-select-next-proto", "foo",
4606 },
4607 shouldFail: true,
4608 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4609 })
4610 testCases = append(testCases, testCase{
4611 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4612 config: Config{
4613 MaxVersion: ver.version,
4614 NextProtos: []string{"foo", "bar", "baz"},
4615 Bugs: ProtocolBugs{
4616 NegotiateALPNAndNPN: true,
4617 SwapNPNAndALPN: true,
4618 },
4619 },
4620 flags: []string{
4621 "-advertise-alpn", "\x03foo",
4622 "-select-next-proto", "foo",
4623 },
4624 shouldFail: true,
4625 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4626 })
4627
4628 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4629 testCases = append(testCases, testCase{
4630 name: "DisableNPN-" + ver.name,
4631 config: Config{
4632 MaxVersion: ver.version,
4633 NextProtos: []string{"foo"},
4634 },
4635 flags: []string{
4636 "-select-next-proto", "foo",
4637 "-disable-npn",
4638 },
4639 expectNoNextProto: true,
4640 })
4641 }
4642
4643 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004644
4645 // Resume with a corrupt ticket.
4646 testCases = append(testCases, testCase{
4647 testType: serverTest,
4648 name: "CorruptTicket-" + ver.name,
4649 config: Config{
4650 MaxVersion: ver.version,
4651 Bugs: ProtocolBugs{
4652 CorruptTicket: true,
4653 },
4654 },
4655 resumeSession: true,
4656 expectResumeRejected: true,
4657 })
4658 // Test the ticket callback, with and without renewal.
4659 testCases = append(testCases, testCase{
4660 testType: serverTest,
4661 name: "TicketCallback-" + ver.name,
4662 config: Config{
4663 MaxVersion: ver.version,
4664 },
4665 resumeSession: true,
4666 flags: []string{"-use-ticket-callback"},
4667 })
4668 testCases = append(testCases, testCase{
4669 testType: serverTest,
4670 name: "TicketCallback-Renew-" + ver.name,
4671 config: Config{
4672 MaxVersion: ver.version,
4673 Bugs: ProtocolBugs{
4674 ExpectNewTicket: true,
4675 },
4676 },
4677 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4678 resumeSession: true,
4679 })
4680
4681 // Test that the ticket callback is only called once when everything before
4682 // it in the ClientHello is asynchronous. This corrupts the ticket so
4683 // certificate selection callbacks run.
4684 testCases = append(testCases, testCase{
4685 testType: serverTest,
4686 name: "TicketCallback-SingleCall-" + ver.name,
4687 config: Config{
4688 MaxVersion: ver.version,
4689 Bugs: ProtocolBugs{
4690 CorruptTicket: true,
4691 },
4692 },
4693 resumeSession: true,
4694 expectResumeRejected: true,
4695 flags: []string{
4696 "-use-ticket-callback",
4697 "-async",
4698 },
4699 })
4700
4701 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004702 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004703 testCases = append(testCases, testCase{
4704 testType: serverTest,
4705 name: "OversizedSessionId-" + ver.name,
4706 config: Config{
4707 MaxVersion: ver.version,
4708 Bugs: ProtocolBugs{
4709 OversizedSessionId: true,
4710 },
4711 },
4712 resumeSession: true,
4713 shouldFail: true,
4714 expectedError: ":DECODE_ERROR:",
4715 })
4716 }
4717
4718 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4719 // are ignored.
4720 if ver.hasDTLS {
4721 testCases = append(testCases, testCase{
4722 protocol: dtls,
4723 name: "SRTP-Client-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4727 },
4728 flags: []string{
4729 "-srtp-profiles",
4730 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4731 },
4732 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4733 })
4734 testCases = append(testCases, testCase{
4735 protocol: dtls,
4736 testType: serverTest,
4737 name: "SRTP-Server-" + ver.name,
4738 config: Config{
4739 MaxVersion: ver.version,
4740 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4741 },
4742 flags: []string{
4743 "-srtp-profiles",
4744 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4745 },
4746 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4747 })
4748 // Test that the MKI is ignored.
4749 testCases = append(testCases, testCase{
4750 protocol: dtls,
4751 testType: serverTest,
4752 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4753 config: Config{
4754 MaxVersion: ver.version,
4755 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4756 Bugs: ProtocolBugs{
4757 SRTPMasterKeyIdentifer: "bogus",
4758 },
4759 },
4760 flags: []string{
4761 "-srtp-profiles",
4762 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4763 },
4764 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4765 })
4766 // Test that SRTP isn't negotiated on the server if there were
4767 // no matching profiles.
4768 testCases = append(testCases, testCase{
4769 protocol: dtls,
4770 testType: serverTest,
4771 name: "SRTP-Server-NoMatch-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 SRTPProtectionProfiles: []uint16{100, 101, 102},
4775 },
4776 flags: []string{
4777 "-srtp-profiles",
4778 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4779 },
4780 expectedSRTPProtectionProfile: 0,
4781 })
4782 // Test that the server returning an invalid SRTP profile is
4783 // flagged as an error by the client.
4784 testCases = append(testCases, testCase{
4785 protocol: dtls,
4786 name: "SRTP-Client-NoMatch-" + ver.name,
4787 config: Config{
4788 MaxVersion: ver.version,
4789 Bugs: ProtocolBugs{
4790 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4791 },
4792 },
4793 flags: []string{
4794 "-srtp-profiles",
4795 "SRTP_AES128_CM_SHA1_80",
4796 },
4797 shouldFail: true,
4798 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4799 })
4800 }
4801
4802 // Test SCT list.
4803 testCases = append(testCases, testCase{
4804 name: "SignedCertificateTimestampList-Client-" + ver.name,
4805 testType: clientTest,
4806 config: Config{
4807 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004808 },
David Benjamin97d17d92016-07-14 16:12:00 -04004809 flags: []string{
4810 "-enable-signed-cert-timestamps",
4811 "-expect-signed-cert-timestamps",
4812 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004813 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004814 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004815 })
4816 testCases = append(testCases, testCase{
4817 name: "SendSCTListOnResume-" + ver.name,
4818 config: Config{
4819 MaxVersion: ver.version,
4820 Bugs: ProtocolBugs{
4821 SendSCTListOnResume: []byte("bogus"),
4822 },
David Benjamind98452d2015-06-16 14:16:23 -04004823 },
David Benjamin97d17d92016-07-14 16:12:00 -04004824 flags: []string{
4825 "-enable-signed-cert-timestamps",
4826 "-expect-signed-cert-timestamps",
4827 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004828 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004829 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004830 })
4831 testCases = append(testCases, testCase{
4832 name: "SignedCertificateTimestampList-Server-" + ver.name,
4833 testType: serverTest,
4834 config: Config{
4835 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004836 },
David Benjamin97d17d92016-07-14 16:12:00 -04004837 flags: []string{
4838 "-signed-cert-timestamps",
4839 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004840 },
David Benjamin97d17d92016-07-14 16:12:00 -04004841 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004842 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004843 })
4844 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004845
Paul Lietar4fac72e2015-09-09 13:44:55 +01004846 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004847 testType: clientTest,
4848 name: "ClientHelloPadding",
4849 config: Config{
4850 Bugs: ProtocolBugs{
4851 RequireClientHelloSize: 512,
4852 },
4853 },
4854 // This hostname just needs to be long enough to push the
4855 // ClientHello into F5's danger zone between 256 and 511 bytes
4856 // long.
4857 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4858 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004859
4860 // Extensions should not function in SSL 3.0.
4861 testCases = append(testCases, testCase{
4862 testType: serverTest,
4863 name: "SSLv3Extensions-NoALPN",
4864 config: Config{
4865 MaxVersion: VersionSSL30,
4866 NextProtos: []string{"foo", "bar", "baz"},
4867 },
4868 flags: []string{
4869 "-select-alpn", "foo",
4870 },
4871 expectNoNextProto: true,
4872 })
4873
4874 // Test session tickets separately as they follow a different codepath.
4875 testCases = append(testCases, testCase{
4876 testType: serverTest,
4877 name: "SSLv3Extensions-NoTickets",
4878 config: Config{
4879 MaxVersion: VersionSSL30,
4880 Bugs: ProtocolBugs{
4881 // Historically, session tickets in SSL 3.0
4882 // failed in different ways depending on whether
4883 // the client supported renegotiation_info.
4884 NoRenegotiationInfo: true,
4885 },
4886 },
4887 resumeSession: true,
4888 })
4889 testCases = append(testCases, testCase{
4890 testType: serverTest,
4891 name: "SSLv3Extensions-NoTickets2",
4892 config: Config{
4893 MaxVersion: VersionSSL30,
4894 },
4895 resumeSession: true,
4896 })
4897
4898 // But SSL 3.0 does send and process renegotiation_info.
4899 testCases = append(testCases, testCase{
4900 testType: serverTest,
4901 name: "SSLv3Extensions-RenegotiationInfo",
4902 config: Config{
4903 MaxVersion: VersionSSL30,
4904 Bugs: ProtocolBugs{
4905 RequireRenegotiationInfo: true,
4906 },
4907 },
4908 })
4909 testCases = append(testCases, testCase{
4910 testType: serverTest,
4911 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4912 config: Config{
4913 MaxVersion: VersionSSL30,
4914 Bugs: ProtocolBugs{
4915 NoRenegotiationInfo: true,
4916 SendRenegotiationSCSV: true,
4917 RequireRenegotiationInfo: true,
4918 },
4919 },
4920 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004921
4922 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4923 // in ServerHello.
4924 testCases = append(testCases, testCase{
4925 name: "NPN-Forbidden-TLS13",
4926 config: Config{
4927 MaxVersion: VersionTLS13,
4928 NextProtos: []string{"foo"},
4929 Bugs: ProtocolBugs{
4930 NegotiateNPNAtAllVersions: true,
4931 },
4932 },
4933 flags: []string{"-select-next-proto", "foo"},
4934 shouldFail: true,
4935 expectedError: ":ERROR_PARSING_EXTENSION:",
4936 })
4937 testCases = append(testCases, testCase{
4938 name: "EMS-Forbidden-TLS13",
4939 config: Config{
4940 MaxVersion: VersionTLS13,
4941 Bugs: ProtocolBugs{
4942 NegotiateEMSAtAllVersions: true,
4943 },
4944 },
4945 shouldFail: true,
4946 expectedError: ":ERROR_PARSING_EXTENSION:",
4947 })
4948 testCases = append(testCases, testCase{
4949 name: "RenegotiationInfo-Forbidden-TLS13",
4950 config: Config{
4951 MaxVersion: VersionTLS13,
4952 Bugs: ProtocolBugs{
4953 NegotiateRenegotiationInfoAtAllVersions: true,
4954 },
4955 },
4956 shouldFail: true,
4957 expectedError: ":ERROR_PARSING_EXTENSION:",
4958 })
4959 testCases = append(testCases, testCase{
4960 name: "ChannelID-Forbidden-TLS13",
4961 config: Config{
4962 MaxVersion: VersionTLS13,
4963 RequestChannelID: true,
4964 Bugs: ProtocolBugs{
4965 NegotiateChannelIDAtAllVersions: true,
4966 },
4967 },
4968 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4969 shouldFail: true,
4970 expectedError: ":ERROR_PARSING_EXTENSION:",
4971 })
4972 testCases = append(testCases, testCase{
4973 name: "Ticket-Forbidden-TLS13",
4974 config: Config{
4975 MaxVersion: VersionTLS12,
4976 },
4977 resumeConfig: &Config{
4978 MaxVersion: VersionTLS13,
4979 Bugs: ProtocolBugs{
4980 AdvertiseTicketExtension: true,
4981 },
4982 },
4983 resumeSession: true,
4984 shouldFail: true,
4985 expectedError: ":ERROR_PARSING_EXTENSION:",
4986 })
4987
4988 // Test that illegal extensions in TLS 1.3 are declined by the server if
4989 // offered in ClientHello. The runner's server will fail if this occurs,
4990 // so we exercise the offering path. (EMS and Renegotiation Info are
4991 // implicit in every test.)
4992 testCases = append(testCases, testCase{
4993 testType: serverTest,
4994 name: "ChannelID-Declined-TLS13",
4995 config: Config{
4996 MaxVersion: VersionTLS13,
4997 ChannelID: channelIDKey,
4998 },
4999 flags: []string{"-enable-channel-id"},
5000 })
5001 testCases = append(testCases, testCase{
5002 testType: serverTest,
5003 name: "NPN-Server",
5004 config: Config{
5005 MaxVersion: VersionTLS13,
5006 NextProtos: []string{"bar"},
5007 },
5008 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5009 })
David Benjamin196df5b2016-09-21 16:23:27 -04005010
5011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "InvalidChannelIDSignature",
5014 config: Config{
5015 MaxVersion: VersionTLS12,
5016 ChannelID: channelIDKey,
5017 Bugs: ProtocolBugs{
5018 InvalidChannelIDSignature: true,
5019 },
5020 },
5021 flags: []string{"-enable-channel-id"},
5022 shouldFail: true,
5023 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5024 expectedLocalError: "remote error: error decrypting message",
5025 })
David Benjamine78bfde2014-09-06 12:45:15 -04005026}
5027
David Benjamin01fe8202014-09-24 15:21:44 -04005028func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005029 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005030 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005031 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5032 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5033 // TLS 1.3 only shares ciphers with TLS 1.2, so
5034 // we skip certain combinations and use a
5035 // different cipher to test with.
5036 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5037 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5038 continue
5039 }
5040 }
5041
David Benjamin8b8c0062014-11-23 02:47:52 -05005042 protocols := []protocol{tls}
5043 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5044 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005045 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005046 for _, protocol := range protocols {
5047 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5048 if protocol == dtls {
5049 suffix += "-DTLS"
5050 }
5051
David Benjaminece3de92015-03-16 18:02:20 -04005052 if sessionVers.version == resumeVers.version {
5053 testCases = append(testCases, testCase{
5054 protocol: protocol,
5055 name: "Resume-Client" + suffix,
5056 resumeSession: true,
5057 config: Config{
5058 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005059 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005060 Bugs: ProtocolBugs{
5061 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5062 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5063 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 },
David Benjaminece3de92015-03-16 18:02:20 -04005065 expectedVersion: sessionVers.version,
5066 expectedResumeVersion: resumeVers.version,
5067 })
5068 } else {
David Benjamin405da482016-08-08 17:25:07 -04005069 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5070
5071 // Offering a TLS 1.3 session sends an empty session ID, so
5072 // there is no way to convince a non-lookahead client the
5073 // session was resumed. It will appear to the client that a
5074 // stray ChangeCipherSpec was sent.
5075 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5076 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005077 }
5078
David Benjaminece3de92015-03-16 18:02:20 -04005079 testCases = append(testCases, testCase{
5080 protocol: protocol,
5081 name: "Resume-Client-Mismatch" + suffix,
5082 resumeSession: true,
5083 config: Config{
5084 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005085 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005086 },
David Benjaminece3de92015-03-16 18:02:20 -04005087 expectedVersion: sessionVers.version,
5088 resumeConfig: &Config{
5089 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005090 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005091 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005092 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005093 },
5094 },
5095 expectedResumeVersion: resumeVers.version,
5096 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005097 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005098 })
5099 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005100
5101 testCases = append(testCases, testCase{
5102 protocol: protocol,
5103 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005104 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 },
5109 expectedVersion: sessionVers.version,
5110 resumeConfig: &Config{
5111 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005112 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005113 },
5114 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005115 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005116 expectedResumeVersion: resumeVers.version,
5117 })
5118
David Benjamin8b8c0062014-11-23 02:47:52 -05005119 testCases = append(testCases, testCase{
5120 protocol: protocol,
5121 testType: serverTest,
5122 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 resumeSession: true,
5124 config: Config{
5125 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005126 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005127 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005128 expectedVersion: sessionVers.version,
5129 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005130 resumeConfig: &Config{
5131 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005132 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005133 Bugs: ProtocolBugs{
5134 SendBothTickets: true,
5135 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005136 },
5137 expectedResumeVersion: resumeVers.version,
5138 })
5139 }
David Benjamin01fe8202014-09-24 15:21:44 -04005140 }
5141 }
David Benjaminece3de92015-03-16 18:02:20 -04005142
5143 testCases = append(testCases, testCase{
5144 name: "Resume-Client-CipherMismatch",
5145 resumeSession: true,
5146 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005147 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005148 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5149 },
5150 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005151 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005152 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5153 Bugs: ProtocolBugs{
5154 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5155 },
5156 },
5157 shouldFail: true,
5158 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5159 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005160
5161 testCases = append(testCases, testCase{
5162 name: "Resume-Client-CipherMismatch-TLS13",
5163 resumeSession: true,
5164 config: Config{
5165 MaxVersion: VersionTLS13,
5166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5167 },
5168 resumeConfig: &Config{
5169 MaxVersion: VersionTLS13,
5170 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5171 Bugs: ProtocolBugs{
5172 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5173 },
5174 },
5175 shouldFail: true,
5176 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5177 })
David Benjamin01fe8202014-09-24 15:21:44 -04005178}
5179
Adam Langley2ae77d22014-10-28 17:29:33 -07005180func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005181 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005182 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005183 testType: serverTest,
5184 name: "Renegotiate-Server-Forbidden",
5185 config: Config{
5186 MaxVersion: VersionTLS12,
5187 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005188 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005189 shouldFail: true,
5190 expectedError: ":NO_RENEGOTIATION:",
5191 expectedLocalError: "remote error: no renegotiation",
5192 })
Adam Langley5021b222015-06-12 18:27:58 -07005193 // The server shouldn't echo the renegotiation extension unless
5194 // requested by the client.
5195 testCases = append(testCases, testCase{
5196 testType: serverTest,
5197 name: "Renegotiate-Server-NoExt",
5198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005199 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005200 Bugs: ProtocolBugs{
5201 NoRenegotiationInfo: true,
5202 RequireRenegotiationInfo: true,
5203 },
5204 },
5205 shouldFail: true,
5206 expectedLocalError: "renegotiation extension missing",
5207 })
5208 // The renegotiation SCSV should be sufficient for the server to echo
5209 // the extension.
5210 testCases = append(testCases, testCase{
5211 testType: serverTest,
5212 name: "Renegotiate-Server-NoExt-SCSV",
5213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005214 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005215 Bugs: ProtocolBugs{
5216 NoRenegotiationInfo: true,
5217 SendRenegotiationSCSV: true,
5218 RequireRenegotiationInfo: true,
5219 },
5220 },
5221 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005222 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005223 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005224 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005225 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005226 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005227 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005228 },
5229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005230 renegotiate: 1,
5231 flags: []string{
5232 "-renegotiate-freely",
5233 "-expect-total-renegotiations", "1",
5234 },
David Benjamincdea40c2015-03-19 14:09:43 -04005235 })
5236 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005237 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005241 Bugs: ProtocolBugs{
5242 EmptyRenegotiationInfo: true,
5243 },
5244 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005245 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005246 shouldFail: true,
5247 expectedError: ":RENEGOTIATION_MISMATCH:",
5248 })
5249 testCases = append(testCases, testCase{
5250 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005251 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005253 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005254 Bugs: ProtocolBugs{
5255 BadRenegotiationInfo: true,
5256 },
5257 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005258 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005259 shouldFail: true,
5260 expectedError: ":RENEGOTIATION_MISMATCH:",
5261 })
5262 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005263 name: "Renegotiate-Client-Downgrade",
5264 renegotiate: 1,
5265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005266 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005267 Bugs: ProtocolBugs{
5268 NoRenegotiationInfoAfterInitial: true,
5269 },
5270 },
5271 flags: []string{"-renegotiate-freely"},
5272 shouldFail: true,
5273 expectedError: ":RENEGOTIATION_MISMATCH:",
5274 })
5275 testCases = append(testCases, testCase{
5276 name: "Renegotiate-Client-Upgrade",
5277 renegotiate: 1,
5278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005279 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005280 Bugs: ProtocolBugs{
5281 NoRenegotiationInfoInInitial: true,
5282 },
5283 },
5284 flags: []string{"-renegotiate-freely"},
5285 shouldFail: true,
5286 expectedError: ":RENEGOTIATION_MISMATCH:",
5287 })
5288 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005289 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005290 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005292 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005293 Bugs: ProtocolBugs{
5294 NoRenegotiationInfo: true,
5295 },
5296 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005297 flags: []string{
5298 "-renegotiate-freely",
5299 "-expect-total-renegotiations", "1",
5300 },
David Benjamincff0b902015-05-15 23:09:47 -04005301 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005302
5303 // Test that the server may switch ciphers on renegotiation without
5304 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005305 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005306 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005307 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005308 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005309 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005310 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005311 },
5312 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005313 flags: []string{
5314 "-renegotiate-freely",
5315 "-expect-total-renegotiations", "1",
5316 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005317 })
5318 testCases = append(testCases, testCase{
5319 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005320 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005321 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005322 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005323 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5324 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005325 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005326 flags: []string{
5327 "-renegotiate-freely",
5328 "-expect-total-renegotiations", "1",
5329 },
David Benjaminb16346b2015-04-08 19:16:58 -04005330 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005331
5332 // Test that the server may not switch versions on renegotiation.
5333 testCases = append(testCases, testCase{
5334 name: "Renegotiate-Client-SwitchVersion",
5335 config: Config{
5336 MaxVersion: VersionTLS12,
5337 // Pick a cipher which exists at both versions.
5338 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5339 Bugs: ProtocolBugs{
5340 NegotiateVersionOnRenego: VersionTLS11,
5341 },
5342 },
5343 renegotiate: 1,
5344 flags: []string{
5345 "-renegotiate-freely",
5346 "-expect-total-renegotiations", "1",
5347 },
5348 shouldFail: true,
5349 expectedError: ":WRONG_SSL_VERSION:",
5350 })
5351
David Benjaminb16346b2015-04-08 19:16:58 -04005352 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005353 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005354 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005355 config: Config{
5356 MaxVersion: VersionTLS10,
5357 Bugs: ProtocolBugs{
5358 RequireSameRenegoClientVersion: true,
5359 },
5360 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005361 flags: []string{
5362 "-renegotiate-freely",
5363 "-expect-total-renegotiations", "1",
5364 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005365 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005366 testCases = append(testCases, testCase{
5367 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005368 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005369 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005370 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005371 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5372 NextProtos: []string{"foo"},
5373 },
5374 flags: []string{
5375 "-false-start",
5376 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005377 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005378 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005379 },
5380 shimWritesFirst: true,
5381 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005382
5383 // Client-side renegotiation controls.
5384 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005385 name: "Renegotiate-Client-Forbidden-1",
5386 config: Config{
5387 MaxVersion: VersionTLS12,
5388 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005389 renegotiate: 1,
5390 shouldFail: true,
5391 expectedError: ":NO_RENEGOTIATION:",
5392 expectedLocalError: "remote error: no renegotiation",
5393 })
5394 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005395 name: "Renegotiate-Client-Once-1",
5396 config: Config{
5397 MaxVersion: VersionTLS12,
5398 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005399 renegotiate: 1,
5400 flags: []string{
5401 "-renegotiate-once",
5402 "-expect-total-renegotiations", "1",
5403 },
5404 })
5405 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005406 name: "Renegotiate-Client-Freely-1",
5407 config: Config{
5408 MaxVersion: VersionTLS12,
5409 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005410 renegotiate: 1,
5411 flags: []string{
5412 "-renegotiate-freely",
5413 "-expect-total-renegotiations", "1",
5414 },
5415 })
5416 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005417 name: "Renegotiate-Client-Once-2",
5418 config: Config{
5419 MaxVersion: VersionTLS12,
5420 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005421 renegotiate: 2,
5422 flags: []string{"-renegotiate-once"},
5423 shouldFail: true,
5424 expectedError: ":NO_RENEGOTIATION:",
5425 expectedLocalError: "remote error: no renegotiation",
5426 })
5427 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 name: "Renegotiate-Client-Freely-2",
5429 config: Config{
5430 MaxVersion: VersionTLS12,
5431 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005432 renegotiate: 2,
5433 flags: []string{
5434 "-renegotiate-freely",
5435 "-expect-total-renegotiations", "2",
5436 },
5437 })
Adam Langley27a0d082015-11-03 13:34:10 -08005438 testCases = append(testCases, testCase{
5439 name: "Renegotiate-Client-NoIgnore",
5440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005441 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005442 Bugs: ProtocolBugs{
5443 SendHelloRequestBeforeEveryAppDataRecord: true,
5444 },
5445 },
5446 shouldFail: true,
5447 expectedError: ":NO_RENEGOTIATION:",
5448 })
5449 testCases = append(testCases, testCase{
5450 name: "Renegotiate-Client-Ignore",
5451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005452 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005453 Bugs: ProtocolBugs{
5454 SendHelloRequestBeforeEveryAppDataRecord: true,
5455 },
5456 },
5457 flags: []string{
5458 "-renegotiate-ignore",
5459 "-expect-total-renegotiations", "0",
5460 },
5461 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005462
David Benjamin397c8e62016-07-08 14:14:36 -07005463 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005464 testCases = append(testCases, testCase{
5465 name: "StrayHelloRequest",
5466 config: Config{
5467 MaxVersion: VersionTLS12,
5468 Bugs: ProtocolBugs{
5469 SendHelloRequestBeforeEveryHandshakeMessage: true,
5470 },
5471 },
5472 })
5473 testCases = append(testCases, testCase{
5474 name: "StrayHelloRequest-Packed",
5475 config: Config{
5476 MaxVersion: VersionTLS12,
5477 Bugs: ProtocolBugs{
5478 PackHandshakeFlight: true,
5479 SendHelloRequestBeforeEveryHandshakeMessage: true,
5480 },
5481 },
5482 })
5483
David Benjamin12d2c482016-07-24 10:56:51 -04005484 // Test renegotiation works if HelloRequest and server Finished come in
5485 // the same record.
5486 testCases = append(testCases, testCase{
5487 name: "Renegotiate-Client-Packed",
5488 config: Config{
5489 MaxVersion: VersionTLS12,
5490 Bugs: ProtocolBugs{
5491 PackHandshakeFlight: true,
5492 PackHelloRequestWithFinished: true,
5493 },
5494 },
5495 renegotiate: 1,
5496 flags: []string{
5497 "-renegotiate-freely",
5498 "-expect-total-renegotiations", "1",
5499 },
5500 })
5501
David Benjamin397c8e62016-07-08 14:14:36 -07005502 // Renegotiation is forbidden in TLS 1.3.
5503 testCases = append(testCases, testCase{
5504 name: "Renegotiate-Client-TLS13",
5505 config: Config{
5506 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005507 Bugs: ProtocolBugs{
5508 SendHelloRequestBeforeEveryAppDataRecord: true,
5509 },
David Benjamin397c8e62016-07-08 14:14:36 -07005510 },
David Benjamin397c8e62016-07-08 14:14:36 -07005511 flags: []string{
5512 "-renegotiate-freely",
5513 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005514 shouldFail: true,
5515 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005516 })
5517
5518 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5519 testCases = append(testCases, testCase{
5520 name: "StrayHelloRequest-TLS13",
5521 config: Config{
5522 MaxVersion: VersionTLS13,
5523 Bugs: ProtocolBugs{
5524 SendHelloRequestBeforeEveryHandshakeMessage: true,
5525 },
5526 },
5527 shouldFail: true,
5528 expectedError: ":UNEXPECTED_MESSAGE:",
5529 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005530}
5531
David Benjamin5e961c12014-11-07 01:48:35 -05005532func addDTLSReplayTests() {
5533 // Test that sequence number replays are detected.
5534 testCases = append(testCases, testCase{
5535 protocol: dtls,
5536 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005537 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005538 replayWrites: true,
5539 })
5540
David Benjamin8e6db492015-07-25 18:29:23 -04005541 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005542 // than the retransmit window.
5543 testCases = append(testCases, testCase{
5544 protocol: dtls,
5545 name: "DTLS-Replay-LargeGaps",
5546 config: Config{
5547 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005548 SequenceNumberMapping: func(in uint64) uint64 {
5549 return in * 127
5550 },
David Benjamin5e961c12014-11-07 01:48:35 -05005551 },
5552 },
David Benjamin8e6db492015-07-25 18:29:23 -04005553 messageCount: 200,
5554 replayWrites: true,
5555 })
5556
5557 // Test the incoming sequence number changing non-monotonically.
5558 testCases = append(testCases, testCase{
5559 protocol: dtls,
5560 name: "DTLS-Replay-NonMonotonic",
5561 config: Config{
5562 Bugs: ProtocolBugs{
5563 SequenceNumberMapping: func(in uint64) uint64 {
5564 return in ^ 31
5565 },
5566 },
5567 },
5568 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005569 replayWrites: true,
5570 })
5571}
5572
Nick Harper60edffd2016-06-21 15:19:24 -07005573var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005574 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005575 id signatureAlgorithm
5576 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005577}{
Nick Harper60edffd2016-06-21 15:19:24 -07005578 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5579 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5580 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5581 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005582 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005583 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5584 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5585 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005586 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5587 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5588 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005589 // Tests for key types prior to TLS 1.2.
5590 {"RSA", 0, testCertRSA},
5591 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005592}
5593
Nick Harper60edffd2016-06-21 15:19:24 -07005594const fakeSigAlg1 signatureAlgorithm = 0x2a01
5595const fakeSigAlg2 signatureAlgorithm = 0xff01
5596
5597func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005598 // Not all ciphers involve a signature. Advertise a list which gives all
5599 // versions a signing cipher.
5600 signingCiphers := []uint16{
5601 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5602 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5603 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5604 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5605 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5606 }
5607
David Benjaminca3d5452016-07-14 12:51:01 -04005608 var allAlgorithms []signatureAlgorithm
5609 for _, alg := range testSignatureAlgorithms {
5610 if alg.id != 0 {
5611 allAlgorithms = append(allAlgorithms, alg.id)
5612 }
5613 }
5614
Nick Harper60edffd2016-06-21 15:19:24 -07005615 // Make sure each signature algorithm works. Include some fake values in
5616 // the list and ensure they're ignored.
5617 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005618 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005619 if (ver.version < VersionTLS12) != (alg.id == 0) {
5620 continue
5621 }
5622
5623 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5624 // or remove it in C.
5625 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005626 continue
5627 }
Nick Harper60edffd2016-06-21 15:19:24 -07005628
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005629 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005630 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005631 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5632 shouldFail = true
5633 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005634 // RSA-PKCS1 does not exist in TLS 1.3.
5635 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5636 shouldFail = true
5637 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005638
5639 var signError, verifyError string
5640 if shouldFail {
5641 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5642 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005643 }
David Benjamin000800a2014-11-14 01:43:59 -05005644
David Benjamin1fb125c2016-07-08 18:52:12 -07005645 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005646
David Benjamin7a41d372016-07-09 11:21:54 -07005647 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005648 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005649 config: Config{
5650 MaxVersion: ver.version,
5651 ClientAuth: RequireAnyClientCert,
5652 VerifySignatureAlgorithms: []signatureAlgorithm{
5653 fakeSigAlg1,
5654 alg.id,
5655 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005656 },
David Benjamin7a41d372016-07-09 11:21:54 -07005657 },
5658 flags: []string{
5659 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5660 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5661 "-enable-all-curves",
5662 },
5663 shouldFail: shouldFail,
5664 expectedError: signError,
5665 expectedPeerSignatureAlgorithm: alg.id,
5666 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005667
David Benjamin7a41d372016-07-09 11:21:54 -07005668 testCases = append(testCases, testCase{
5669 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005670 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005671 config: Config{
5672 MaxVersion: ver.version,
5673 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5674 SignSignatureAlgorithms: []signatureAlgorithm{
5675 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005676 },
David Benjamin7a41d372016-07-09 11:21:54 -07005677 Bugs: ProtocolBugs{
5678 SkipECDSACurveCheck: shouldFail,
5679 IgnoreSignatureVersionChecks: shouldFail,
5680 // The client won't advertise 1.3-only algorithms after
5681 // version negotiation.
5682 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005683 },
David Benjamin7a41d372016-07-09 11:21:54 -07005684 },
5685 flags: []string{
5686 "-require-any-client-certificate",
5687 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5688 "-enable-all-curves",
5689 },
5690 shouldFail: shouldFail,
5691 expectedError: verifyError,
5692 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005693
5694 testCases = append(testCases, testCase{
5695 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005696 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005697 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005698 MaxVersion: ver.version,
5699 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005700 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005701 fakeSigAlg1,
5702 alg.id,
5703 fakeSigAlg2,
5704 },
5705 },
5706 flags: []string{
5707 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5708 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5709 "-enable-all-curves",
5710 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005711 shouldFail: shouldFail,
5712 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005713 expectedPeerSignatureAlgorithm: alg.id,
5714 })
5715
5716 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005717 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005718 config: Config{
5719 MaxVersion: ver.version,
5720 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005721 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005722 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005723 alg.id,
5724 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005725 Bugs: ProtocolBugs{
5726 SkipECDSACurveCheck: shouldFail,
5727 IgnoreSignatureVersionChecks: shouldFail,
5728 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005729 },
5730 flags: []string{
5731 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5732 "-enable-all-curves",
5733 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005734 shouldFail: shouldFail,
5735 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005736 })
David Benjamin5208fd42016-07-13 21:43:25 -04005737
5738 if !shouldFail {
5739 testCases = append(testCases, testCase{
5740 testType: serverTest,
5741 name: "ClientAuth-InvalidSignature" + suffix,
5742 config: Config{
5743 MaxVersion: ver.version,
5744 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5745 SignSignatureAlgorithms: []signatureAlgorithm{
5746 alg.id,
5747 },
5748 Bugs: ProtocolBugs{
5749 InvalidSignature: true,
5750 },
5751 },
5752 flags: []string{
5753 "-require-any-client-certificate",
5754 "-enable-all-curves",
5755 },
5756 shouldFail: true,
5757 expectedError: ":BAD_SIGNATURE:",
5758 })
5759
5760 testCases = append(testCases, testCase{
5761 name: "ServerAuth-InvalidSignature" + suffix,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5765 CipherSuites: signingCiphers,
5766 SignSignatureAlgorithms: []signatureAlgorithm{
5767 alg.id,
5768 },
5769 Bugs: ProtocolBugs{
5770 InvalidSignature: true,
5771 },
5772 },
5773 flags: []string{"-enable-all-curves"},
5774 shouldFail: true,
5775 expectedError: ":BAD_SIGNATURE:",
5776 })
5777 }
David Benjaminca3d5452016-07-14 12:51:01 -04005778
5779 if ver.version >= VersionTLS12 && !shouldFail {
5780 testCases = append(testCases, testCase{
5781 name: "ClientAuth-Sign-Negotiate" + suffix,
5782 config: Config{
5783 MaxVersion: ver.version,
5784 ClientAuth: RequireAnyClientCert,
5785 VerifySignatureAlgorithms: allAlgorithms,
5786 },
5787 flags: []string{
5788 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5789 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5790 "-enable-all-curves",
5791 "-signing-prefs", strconv.Itoa(int(alg.id)),
5792 },
5793 expectedPeerSignatureAlgorithm: alg.id,
5794 })
5795
5796 testCases = append(testCases, testCase{
5797 testType: serverTest,
5798 name: "ServerAuth-Sign-Negotiate" + suffix,
5799 config: Config{
5800 MaxVersion: ver.version,
5801 CipherSuites: signingCiphers,
5802 VerifySignatureAlgorithms: allAlgorithms,
5803 },
5804 flags: []string{
5805 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5806 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5807 "-enable-all-curves",
5808 "-signing-prefs", strconv.Itoa(int(alg.id)),
5809 },
5810 expectedPeerSignatureAlgorithm: alg.id,
5811 })
5812 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005813 }
David Benjamin000800a2014-11-14 01:43:59 -05005814 }
5815
Nick Harper60edffd2016-06-21 15:19:24 -07005816 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005817 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005818 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005819 config: Config{
5820 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005821 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005822 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005823 signatureECDSAWithP521AndSHA512,
5824 signatureRSAPKCS1WithSHA384,
5825 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005826 },
5827 },
5828 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005829 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5830 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005831 },
Nick Harper60edffd2016-06-21 15:19:24 -07005832 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005833 })
5834
5835 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005836 name: "ClientAuth-SignatureType-TLS13",
5837 config: Config{
5838 ClientAuth: RequireAnyClientCert,
5839 MaxVersion: VersionTLS13,
5840 VerifySignatureAlgorithms: []signatureAlgorithm{
5841 signatureECDSAWithP521AndSHA512,
5842 signatureRSAPKCS1WithSHA384,
5843 signatureRSAPSSWithSHA384,
5844 signatureECDSAWithSHA1,
5845 },
5846 },
5847 flags: []string{
5848 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5849 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5850 },
5851 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5852 })
5853
5854 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005855 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005856 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005858 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005859 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005860 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005861 signatureECDSAWithP521AndSHA512,
5862 signatureRSAPKCS1WithSHA384,
5863 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005864 },
5865 },
Nick Harper60edffd2016-06-21 15:19:24 -07005866 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005867 })
5868
Steven Valdez143e8b32016-07-11 13:19:03 -04005869 testCases = append(testCases, testCase{
5870 testType: serverTest,
5871 name: "ServerAuth-SignatureType-TLS13",
5872 config: Config{
5873 MaxVersion: VersionTLS13,
5874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5875 VerifySignatureAlgorithms: []signatureAlgorithm{
5876 signatureECDSAWithP521AndSHA512,
5877 signatureRSAPKCS1WithSHA384,
5878 signatureRSAPSSWithSHA384,
5879 signatureECDSAWithSHA1,
5880 },
5881 },
5882 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5883 })
5884
David Benjamina95e9f32016-07-08 16:28:04 -07005885 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "Verify-ClientAuth-SignatureType",
5889 config: Config{
5890 MaxVersion: VersionTLS12,
5891 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005892 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005893 signatureRSAPKCS1WithSHA256,
5894 },
5895 Bugs: ProtocolBugs{
5896 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5897 },
5898 },
5899 flags: []string{
5900 "-require-any-client-certificate",
5901 },
5902 shouldFail: true,
5903 expectedError: ":WRONG_SIGNATURE_TYPE:",
5904 })
5905
5906 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005907 testType: serverTest,
5908 name: "Verify-ClientAuth-SignatureType-TLS13",
5909 config: Config{
5910 MaxVersion: VersionTLS13,
5911 Certificates: []Certificate{rsaCertificate},
5912 SignSignatureAlgorithms: []signatureAlgorithm{
5913 signatureRSAPSSWithSHA256,
5914 },
5915 Bugs: ProtocolBugs{
5916 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5917 },
5918 },
5919 flags: []string{
5920 "-require-any-client-certificate",
5921 },
5922 shouldFail: true,
5923 expectedError: ":WRONG_SIGNATURE_TYPE:",
5924 })
5925
5926 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005927 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005928 config: Config{
5929 MaxVersion: VersionTLS12,
5930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005931 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005932 signatureRSAPKCS1WithSHA256,
5933 },
5934 Bugs: ProtocolBugs{
5935 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5936 },
5937 },
5938 shouldFail: true,
5939 expectedError: ":WRONG_SIGNATURE_TYPE:",
5940 })
5941
Steven Valdez143e8b32016-07-11 13:19:03 -04005942 testCases = append(testCases, testCase{
5943 name: "Verify-ServerAuth-SignatureType-TLS13",
5944 config: Config{
5945 MaxVersion: VersionTLS13,
5946 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5947 SignSignatureAlgorithms: []signatureAlgorithm{
5948 signatureRSAPSSWithSHA256,
5949 },
5950 Bugs: ProtocolBugs{
5951 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5952 },
5953 },
5954 shouldFail: true,
5955 expectedError: ":WRONG_SIGNATURE_TYPE:",
5956 })
5957
David Benjamin51dd7d62016-07-08 16:07:01 -07005958 // Test that, if the list is missing, the peer falls back to SHA-1 in
5959 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005960 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005961 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005963 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005964 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005965 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005966 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005967 },
5968 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005969 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005970 },
5971 },
5972 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005973 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5974 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005975 },
5976 })
5977
5978 testCases = append(testCases, testCase{
5979 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005980 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005981 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005982 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005983 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005984 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005985 },
5986 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005987 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005988 },
5989 },
David Benjaminee32bea2016-08-17 13:36:44 -04005990 flags: []string{
5991 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5992 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5993 },
5994 })
5995
5996 testCases = append(testCases, testCase{
5997 name: "ClientAuth-SHA1-Fallback-ECDSA",
5998 config: Config{
5999 MaxVersion: VersionTLS12,
6000 ClientAuth: RequireAnyClientCert,
6001 VerifySignatureAlgorithms: []signatureAlgorithm{
6002 signatureECDSAWithSHA1,
6003 },
6004 Bugs: ProtocolBugs{
6005 NoSignatureAlgorithms: true,
6006 },
6007 },
6008 flags: []string{
6009 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6010 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6011 },
6012 })
6013
6014 testCases = append(testCases, testCase{
6015 testType: serverTest,
6016 name: "ServerAuth-SHA1-Fallback-ECDSA",
6017 config: Config{
6018 MaxVersion: VersionTLS12,
6019 VerifySignatureAlgorithms: []signatureAlgorithm{
6020 signatureECDSAWithSHA1,
6021 },
6022 Bugs: ProtocolBugs{
6023 NoSignatureAlgorithms: true,
6024 },
6025 },
6026 flags: []string{
6027 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6028 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6029 },
David Benjamin000800a2014-11-14 01:43:59 -05006030 })
David Benjamin72dc7832015-03-16 17:49:43 -04006031
David Benjamin51dd7d62016-07-08 16:07:01 -07006032 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006033 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006034 config: Config{
6035 MaxVersion: VersionTLS13,
6036 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006037 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006038 signatureRSAPKCS1WithSHA1,
6039 },
6040 Bugs: ProtocolBugs{
6041 NoSignatureAlgorithms: true,
6042 },
6043 },
6044 flags: []string{
6045 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6046 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6047 },
David Benjamin48901652016-08-01 12:12:47 -04006048 shouldFail: true,
6049 // An empty CertificateRequest signature algorithm list is a
6050 // syntax error in TLS 1.3.
6051 expectedError: ":DECODE_ERROR:",
6052 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006053 })
6054
6055 testCases = append(testCases, testCase{
6056 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006057 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006058 config: Config{
6059 MaxVersion: VersionTLS13,
6060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006061 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006062 signatureRSAPKCS1WithSHA1,
6063 },
6064 Bugs: ProtocolBugs{
6065 NoSignatureAlgorithms: true,
6066 },
6067 },
6068 shouldFail: true,
6069 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6070 })
6071
David Benjaminb62d2872016-07-18 14:55:02 +02006072 // Test that hash preferences are enforced. BoringSSL does not implement
6073 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006074 testCases = append(testCases, testCase{
6075 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006076 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006078 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006079 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006080 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006081 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006082 },
6083 Bugs: ProtocolBugs{
6084 IgnorePeerSignatureAlgorithmPreferences: true,
6085 },
6086 },
6087 flags: []string{"-require-any-client-certificate"},
6088 shouldFail: true,
6089 expectedError: ":WRONG_SIGNATURE_TYPE:",
6090 })
6091
6092 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006093 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006095 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006096 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006097 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006098 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006099 },
6100 Bugs: ProtocolBugs{
6101 IgnorePeerSignatureAlgorithmPreferences: true,
6102 },
6103 },
6104 shouldFail: true,
6105 expectedError: ":WRONG_SIGNATURE_TYPE:",
6106 })
David Benjaminb62d2872016-07-18 14:55:02 +02006107 testCases = append(testCases, testCase{
6108 testType: serverTest,
6109 name: "ClientAuth-Enforced-TLS13",
6110 config: Config{
6111 MaxVersion: VersionTLS13,
6112 Certificates: []Certificate{rsaCertificate},
6113 SignSignatureAlgorithms: []signatureAlgorithm{
6114 signatureRSAPKCS1WithMD5,
6115 },
6116 Bugs: ProtocolBugs{
6117 IgnorePeerSignatureAlgorithmPreferences: true,
6118 IgnoreSignatureVersionChecks: true,
6119 },
6120 },
6121 flags: []string{"-require-any-client-certificate"},
6122 shouldFail: true,
6123 expectedError: ":WRONG_SIGNATURE_TYPE:",
6124 })
6125
6126 testCases = append(testCases, testCase{
6127 name: "ServerAuth-Enforced-TLS13",
6128 config: Config{
6129 MaxVersion: VersionTLS13,
6130 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6131 SignSignatureAlgorithms: []signatureAlgorithm{
6132 signatureRSAPKCS1WithMD5,
6133 },
6134 Bugs: ProtocolBugs{
6135 IgnorePeerSignatureAlgorithmPreferences: true,
6136 IgnoreSignatureVersionChecks: true,
6137 },
6138 },
6139 shouldFail: true,
6140 expectedError: ":WRONG_SIGNATURE_TYPE:",
6141 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006142
6143 // Test that the agreed upon digest respects the client preferences and
6144 // the server digests.
6145 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006146 name: "NoCommonAlgorithms-Digests",
6147 config: Config{
6148 MaxVersion: VersionTLS12,
6149 ClientAuth: RequireAnyClientCert,
6150 VerifySignatureAlgorithms: []signatureAlgorithm{
6151 signatureRSAPKCS1WithSHA512,
6152 signatureRSAPKCS1WithSHA1,
6153 },
6154 },
6155 flags: []string{
6156 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6157 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6158 "-digest-prefs", "SHA256",
6159 },
6160 shouldFail: true,
6161 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6162 })
6163 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006164 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006166 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006167 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006168 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006169 signatureRSAPKCS1WithSHA512,
6170 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006171 },
6172 },
6173 flags: []string{
6174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006176 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006177 },
David Benjaminca3d5452016-07-14 12:51:01 -04006178 shouldFail: true,
6179 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6180 })
6181 testCases = append(testCases, testCase{
6182 name: "NoCommonAlgorithms-TLS13",
6183 config: Config{
6184 MaxVersion: VersionTLS13,
6185 ClientAuth: RequireAnyClientCert,
6186 VerifySignatureAlgorithms: []signatureAlgorithm{
6187 signatureRSAPSSWithSHA512,
6188 signatureRSAPSSWithSHA384,
6189 },
6190 },
6191 flags: []string{
6192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6194 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6195 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006196 shouldFail: true,
6197 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006198 })
6199 testCases = append(testCases, testCase{
6200 name: "Agree-Digest-SHA256",
6201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006202 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006203 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006204 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006205 signatureRSAPKCS1WithSHA1,
6206 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006207 },
6208 },
6209 flags: []string{
6210 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6211 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006212 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006213 },
Nick Harper60edffd2016-06-21 15:19:24 -07006214 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006215 })
6216 testCases = append(testCases, testCase{
6217 name: "Agree-Digest-SHA1",
6218 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006219 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006220 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006221 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006222 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006223 },
6224 },
6225 flags: []string{
6226 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6227 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006228 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006229 },
Nick Harper60edffd2016-06-21 15:19:24 -07006230 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006231 })
6232 testCases = append(testCases, testCase{
6233 name: "Agree-Digest-Default",
6234 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006235 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006236 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006237 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006238 signatureRSAPKCS1WithSHA256,
6239 signatureECDSAWithP256AndSHA256,
6240 signatureRSAPKCS1WithSHA1,
6241 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006242 },
6243 },
6244 flags: []string{
6245 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6246 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6247 },
Nick Harper60edffd2016-06-21 15:19:24 -07006248 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006249 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006250
David Benjaminca3d5452016-07-14 12:51:01 -04006251 // Test that the signing preference list may include extra algorithms
6252 // without negotiation problems.
6253 testCases = append(testCases, testCase{
6254 testType: serverTest,
6255 name: "FilterExtraAlgorithms",
6256 config: Config{
6257 MaxVersion: VersionTLS12,
6258 VerifySignatureAlgorithms: []signatureAlgorithm{
6259 signatureRSAPKCS1WithSHA256,
6260 },
6261 },
6262 flags: []string{
6263 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6264 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6265 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6266 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6267 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6268 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6269 },
6270 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6271 })
6272
David Benjamin4c3ddf72016-06-29 18:13:53 -04006273 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6274 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006275 testCases = append(testCases, testCase{
6276 name: "CheckLeafCurve",
6277 config: Config{
6278 MaxVersion: VersionTLS12,
6279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006280 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006281 },
6282 flags: []string{"-p384-only"},
6283 shouldFail: true,
6284 expectedError: ":BAD_ECC_CERT:",
6285 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006286
6287 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6288 testCases = append(testCases, testCase{
6289 name: "CheckLeafCurve-TLS13",
6290 config: Config{
6291 MaxVersion: VersionTLS13,
6292 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6293 Certificates: []Certificate{ecdsaP256Certificate},
6294 },
6295 flags: []string{"-p384-only"},
6296 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006297
6298 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6299 testCases = append(testCases, testCase{
6300 name: "ECDSACurveMismatch-Verify-TLS12",
6301 config: Config{
6302 MaxVersion: VersionTLS12,
6303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6304 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006305 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006306 signatureECDSAWithP384AndSHA384,
6307 },
6308 },
6309 })
6310
6311 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6312 testCases = append(testCases, testCase{
6313 name: "ECDSACurveMismatch-Verify-TLS13",
6314 config: Config{
6315 MaxVersion: VersionTLS13,
6316 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6317 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006318 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006319 signatureECDSAWithP384AndSHA384,
6320 },
6321 Bugs: ProtocolBugs{
6322 SkipECDSACurveCheck: true,
6323 },
6324 },
6325 shouldFail: true,
6326 expectedError: ":WRONG_SIGNATURE_TYPE:",
6327 })
6328
6329 // Signature algorithm selection in TLS 1.3 should take the curve into
6330 // account.
6331 testCases = append(testCases, testCase{
6332 testType: serverTest,
6333 name: "ECDSACurveMismatch-Sign-TLS13",
6334 config: Config{
6335 MaxVersion: VersionTLS13,
6336 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006337 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006338 signatureECDSAWithP384AndSHA384,
6339 signatureECDSAWithP256AndSHA256,
6340 },
6341 },
6342 flags: []string{
6343 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6344 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6345 },
6346 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6347 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006348
6349 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6350 // server does not attempt to sign in that case.
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "RSA-PSS-Large",
6354 config: Config{
6355 MaxVersion: VersionTLS13,
6356 VerifySignatureAlgorithms: []signatureAlgorithm{
6357 signatureRSAPSSWithSHA512,
6358 },
6359 },
6360 flags: []string{
6361 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6362 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6363 },
6364 shouldFail: true,
6365 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6366 })
David Benjamin57e929f2016-08-30 00:30:38 -04006367
6368 // Test that RSA-PSS is enabled by default for TLS 1.2.
6369 testCases = append(testCases, testCase{
6370 testType: clientTest,
6371 name: "RSA-PSS-Default-Verify",
6372 config: Config{
6373 MaxVersion: VersionTLS12,
6374 SignSignatureAlgorithms: []signatureAlgorithm{
6375 signatureRSAPSSWithSHA256,
6376 },
6377 },
6378 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6379 })
6380
6381 testCases = append(testCases, testCase{
6382 testType: serverTest,
6383 name: "RSA-PSS-Default-Sign",
6384 config: Config{
6385 MaxVersion: VersionTLS12,
6386 VerifySignatureAlgorithms: []signatureAlgorithm{
6387 signatureRSAPSSWithSHA256,
6388 },
6389 },
6390 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6391 })
David Benjamin000800a2014-11-14 01:43:59 -05006392}
6393
David Benjamin83f90402015-01-27 01:09:43 -05006394// timeouts is the retransmit schedule for BoringSSL. It doubles and
6395// caps at 60 seconds. On the 13th timeout, it gives up.
6396var timeouts = []time.Duration{
6397 1 * time.Second,
6398 2 * time.Second,
6399 4 * time.Second,
6400 8 * time.Second,
6401 16 * time.Second,
6402 32 * time.Second,
6403 60 * time.Second,
6404 60 * time.Second,
6405 60 * time.Second,
6406 60 * time.Second,
6407 60 * time.Second,
6408 60 * time.Second,
6409 60 * time.Second,
6410}
6411
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006412// shortTimeouts is an alternate set of timeouts which would occur if the
6413// initial timeout duration was set to 250ms.
6414var shortTimeouts = []time.Duration{
6415 250 * time.Millisecond,
6416 500 * time.Millisecond,
6417 1 * time.Second,
6418 2 * time.Second,
6419 4 * time.Second,
6420 8 * time.Second,
6421 16 * time.Second,
6422 32 * time.Second,
6423 60 * time.Second,
6424 60 * time.Second,
6425 60 * time.Second,
6426 60 * time.Second,
6427 60 * time.Second,
6428}
6429
David Benjamin83f90402015-01-27 01:09:43 -05006430func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006431 // These tests work by coordinating some behavior on both the shim and
6432 // the runner.
6433 //
6434 // TimeoutSchedule configures the runner to send a series of timeout
6435 // opcodes to the shim (see packetAdaptor) immediately before reading
6436 // each peer handshake flight N. The timeout opcode both simulates a
6437 // timeout in the shim and acts as a synchronization point to help the
6438 // runner bracket each handshake flight.
6439 //
6440 // We assume the shim does not read from the channel eagerly. It must
6441 // first wait until it has sent flight N and is ready to receive
6442 // handshake flight N+1. At this point, it will process the timeout
6443 // opcode. It must then immediately respond with a timeout ACK and act
6444 // as if the shim was idle for the specified amount of time.
6445 //
6446 // The runner then drops all packets received before the ACK and
6447 // continues waiting for flight N. This ordering results in one attempt
6448 // at sending flight N to be dropped. For the test to complete, the
6449 // shim must send flight N again, testing that the shim implements DTLS
6450 // retransmit on a timeout.
6451
Steven Valdez143e8b32016-07-11 13:19:03 -04006452 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006453 // likely be more epochs to cross and the final message's retransmit may
6454 // be more complex.
6455
David Benjamin585d7a42016-06-02 14:58:00 -04006456 for _, async := range []bool{true, false} {
6457 var tests []testCase
6458
6459 // Test that this is indeed the timeout schedule. Stress all
6460 // four patterns of handshake.
6461 for i := 1; i < len(timeouts); i++ {
6462 number := strconv.Itoa(i)
6463 tests = append(tests, testCase{
6464 protocol: dtls,
6465 name: "DTLS-Retransmit-Client-" + number,
6466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006467 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006468 Bugs: ProtocolBugs{
6469 TimeoutSchedule: timeouts[:i],
6470 },
6471 },
6472 resumeSession: true,
6473 })
6474 tests = append(tests, testCase{
6475 protocol: dtls,
6476 testType: serverTest,
6477 name: "DTLS-Retransmit-Server-" + number,
6478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006479 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006480 Bugs: ProtocolBugs{
6481 TimeoutSchedule: timeouts[:i],
6482 },
6483 },
6484 resumeSession: true,
6485 })
6486 }
6487
6488 // Test that exceeding the timeout schedule hits a read
6489 // timeout.
6490 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006491 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006492 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006494 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006495 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006496 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006497 },
6498 },
6499 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006500 shouldFail: true,
6501 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006502 })
David Benjamin585d7a42016-06-02 14:58:00 -04006503
6504 if async {
6505 // Test that timeout handling has a fudge factor, due to API
6506 // problems.
6507 tests = append(tests, testCase{
6508 protocol: dtls,
6509 name: "DTLS-Retransmit-Fudge",
6510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006511 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006512 Bugs: ProtocolBugs{
6513 TimeoutSchedule: []time.Duration{
6514 timeouts[0] - 10*time.Millisecond,
6515 },
6516 },
6517 },
6518 resumeSession: true,
6519 })
6520 }
6521
6522 // Test that the final Finished retransmitting isn't
6523 // duplicated if the peer badly fragments everything.
6524 tests = append(tests, testCase{
6525 testType: serverTest,
6526 protocol: dtls,
6527 name: "DTLS-Retransmit-Fragmented",
6528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006529 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006530 Bugs: ProtocolBugs{
6531 TimeoutSchedule: []time.Duration{timeouts[0]},
6532 MaxHandshakeRecordLength: 2,
6533 },
6534 },
6535 })
6536
6537 // Test the timeout schedule when a shorter initial timeout duration is set.
6538 tests = append(tests, testCase{
6539 protocol: dtls,
6540 name: "DTLS-Retransmit-Short-Client",
6541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006542 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006543 Bugs: ProtocolBugs{
6544 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6545 },
6546 },
6547 resumeSession: true,
6548 flags: []string{"-initial-timeout-duration-ms", "250"},
6549 })
6550 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006551 protocol: dtls,
6552 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006553 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006555 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006556 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006557 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006558 },
6559 },
6560 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006561 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006562 })
David Benjamin585d7a42016-06-02 14:58:00 -04006563
6564 for _, test := range tests {
6565 if async {
6566 test.name += "-Async"
6567 test.flags = append(test.flags, "-async")
6568 }
6569
6570 testCases = append(testCases, test)
6571 }
David Benjamin83f90402015-01-27 01:09:43 -05006572 }
David Benjamin83f90402015-01-27 01:09:43 -05006573}
6574
David Benjaminc565ebb2015-04-03 04:06:36 -04006575func addExportKeyingMaterialTests() {
6576 for _, vers := range tlsVersions {
6577 if vers.version == VersionSSL30 {
6578 continue
6579 }
6580 testCases = append(testCases, testCase{
6581 name: "ExportKeyingMaterial-" + vers.name,
6582 config: Config{
6583 MaxVersion: vers.version,
6584 },
6585 exportKeyingMaterial: 1024,
6586 exportLabel: "label",
6587 exportContext: "context",
6588 useExportContext: true,
6589 })
6590 testCases = append(testCases, testCase{
6591 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6592 config: Config{
6593 MaxVersion: vers.version,
6594 },
6595 exportKeyingMaterial: 1024,
6596 })
6597 testCases = append(testCases, testCase{
6598 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6599 config: Config{
6600 MaxVersion: vers.version,
6601 },
6602 exportKeyingMaterial: 1024,
6603 useExportContext: true,
6604 })
6605 testCases = append(testCases, testCase{
6606 name: "ExportKeyingMaterial-Small-" + vers.name,
6607 config: Config{
6608 MaxVersion: vers.version,
6609 },
6610 exportKeyingMaterial: 1,
6611 exportLabel: "label",
6612 exportContext: "context",
6613 useExportContext: true,
6614 })
6615 }
6616 testCases = append(testCases, testCase{
6617 name: "ExportKeyingMaterial-SSL3",
6618 config: Config{
6619 MaxVersion: VersionSSL30,
6620 },
6621 exportKeyingMaterial: 1024,
6622 exportLabel: "label",
6623 exportContext: "context",
6624 useExportContext: true,
6625 shouldFail: true,
6626 expectedError: "failed to export keying material",
6627 })
6628}
6629
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006630func addTLSUniqueTests() {
6631 for _, isClient := range []bool{false, true} {
6632 for _, isResumption := range []bool{false, true} {
6633 for _, hasEMS := range []bool{false, true} {
6634 var suffix string
6635 if isResumption {
6636 suffix = "Resume-"
6637 } else {
6638 suffix = "Full-"
6639 }
6640
6641 if hasEMS {
6642 suffix += "EMS-"
6643 } else {
6644 suffix += "NoEMS-"
6645 }
6646
6647 if isClient {
6648 suffix += "Client"
6649 } else {
6650 suffix += "Server"
6651 }
6652
6653 test := testCase{
6654 name: "TLSUnique-" + suffix,
6655 testTLSUnique: true,
6656 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006657 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006658 Bugs: ProtocolBugs{
6659 NoExtendedMasterSecret: !hasEMS,
6660 },
6661 },
6662 }
6663
6664 if isResumption {
6665 test.resumeSession = true
6666 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006667 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006668 Bugs: ProtocolBugs{
6669 NoExtendedMasterSecret: !hasEMS,
6670 },
6671 }
6672 }
6673
6674 if isResumption && !hasEMS {
6675 test.shouldFail = true
6676 test.expectedError = "failed to get tls-unique"
6677 }
6678
6679 testCases = append(testCases, test)
6680 }
6681 }
6682 }
6683}
6684
Adam Langley09505632015-07-30 18:10:13 -07006685func addCustomExtensionTests() {
6686 expectedContents := "custom extension"
6687 emptyString := ""
6688
6689 for _, isClient := range []bool{false, true} {
6690 suffix := "Server"
6691 flag := "-enable-server-custom-extension"
6692 testType := serverTest
6693 if isClient {
6694 suffix = "Client"
6695 flag = "-enable-client-custom-extension"
6696 testType = clientTest
6697 }
6698
6699 testCases = append(testCases, testCase{
6700 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006701 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006702 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006703 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006704 Bugs: ProtocolBugs{
6705 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006706 ExpectedCustomExtension: &expectedContents,
6707 },
6708 },
6709 flags: []string{flag},
6710 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006711 testCases = append(testCases, testCase{
6712 testType: testType,
6713 name: "CustomExtensions-" + suffix + "-TLS13",
6714 config: Config{
6715 MaxVersion: VersionTLS13,
6716 Bugs: ProtocolBugs{
6717 CustomExtension: expectedContents,
6718 ExpectedCustomExtension: &expectedContents,
6719 },
6720 },
6721 flags: []string{flag},
6722 })
Adam Langley09505632015-07-30 18:10:13 -07006723
6724 // If the parse callback fails, the handshake should also fail.
6725 testCases = append(testCases, testCase{
6726 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006727 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006728 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006729 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006730 Bugs: ProtocolBugs{
6731 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006732 ExpectedCustomExtension: &expectedContents,
6733 },
6734 },
David Benjamin399e7c92015-07-30 23:01:27 -04006735 flags: []string{flag},
6736 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006737 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6738 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006739 testCases = append(testCases, testCase{
6740 testType: testType,
6741 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6742 config: Config{
6743 MaxVersion: VersionTLS13,
6744 Bugs: ProtocolBugs{
6745 CustomExtension: expectedContents + "foo",
6746 ExpectedCustomExtension: &expectedContents,
6747 },
6748 },
6749 flags: []string{flag},
6750 shouldFail: true,
6751 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6752 })
Adam Langley09505632015-07-30 18:10:13 -07006753
6754 // If the add callback fails, the handshake should also fail.
6755 testCases = append(testCases, testCase{
6756 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006757 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006758 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006759 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006760 Bugs: ProtocolBugs{
6761 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006762 ExpectedCustomExtension: &expectedContents,
6763 },
6764 },
David Benjamin399e7c92015-07-30 23:01:27 -04006765 flags: []string{flag, "-custom-extension-fail-add"},
6766 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006767 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6768 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006769 testCases = append(testCases, testCase{
6770 testType: testType,
6771 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6772 config: Config{
6773 MaxVersion: VersionTLS13,
6774 Bugs: ProtocolBugs{
6775 CustomExtension: expectedContents,
6776 ExpectedCustomExtension: &expectedContents,
6777 },
6778 },
6779 flags: []string{flag, "-custom-extension-fail-add"},
6780 shouldFail: true,
6781 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6782 })
Adam Langley09505632015-07-30 18:10:13 -07006783
6784 // If the add callback returns zero, no extension should be
6785 // added.
6786 skipCustomExtension := expectedContents
6787 if isClient {
6788 // For the case where the client skips sending the
6789 // custom extension, the server must not “echo” it.
6790 skipCustomExtension = ""
6791 }
6792 testCases = append(testCases, testCase{
6793 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006794 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006795 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006796 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006797 Bugs: ProtocolBugs{
6798 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006799 ExpectedCustomExtension: &emptyString,
6800 },
6801 },
6802 flags: []string{flag, "-custom-extension-skip"},
6803 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006804 testCases = append(testCases, testCase{
6805 testType: testType,
6806 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6807 config: Config{
6808 MaxVersion: VersionTLS13,
6809 Bugs: ProtocolBugs{
6810 CustomExtension: skipCustomExtension,
6811 ExpectedCustomExtension: &emptyString,
6812 },
6813 },
6814 flags: []string{flag, "-custom-extension-skip"},
6815 })
Adam Langley09505632015-07-30 18:10:13 -07006816 }
6817
6818 // The custom extension add callback should not be called if the client
6819 // doesn't send the extension.
6820 testCases = append(testCases, testCase{
6821 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006822 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006823 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006824 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006825 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006826 ExpectedCustomExtension: &emptyString,
6827 },
6828 },
6829 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6830 })
Adam Langley2deb9842015-08-07 11:15:37 -07006831
Steven Valdez143e8b32016-07-11 13:19:03 -04006832 testCases = append(testCases, testCase{
6833 testType: serverTest,
6834 name: "CustomExtensions-NotCalled-Server-TLS13",
6835 config: Config{
6836 MaxVersion: VersionTLS13,
6837 Bugs: ProtocolBugs{
6838 ExpectedCustomExtension: &emptyString,
6839 },
6840 },
6841 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6842 })
6843
Adam Langley2deb9842015-08-07 11:15:37 -07006844 // Test an unknown extension from the server.
6845 testCases = append(testCases, testCase{
6846 testType: clientTest,
6847 name: "UnknownExtension-Client",
6848 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006849 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006850 Bugs: ProtocolBugs{
6851 CustomExtension: expectedContents,
6852 },
6853 },
David Benjamin0c40a962016-08-01 12:05:50 -04006854 shouldFail: true,
6855 expectedError: ":UNEXPECTED_EXTENSION:",
6856 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006857 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006858 testCases = append(testCases, testCase{
6859 testType: clientTest,
6860 name: "UnknownExtension-Client-TLS13",
6861 config: Config{
6862 MaxVersion: VersionTLS13,
6863 Bugs: ProtocolBugs{
6864 CustomExtension: expectedContents,
6865 },
6866 },
David Benjamin0c40a962016-08-01 12:05:50 -04006867 shouldFail: true,
6868 expectedError: ":UNEXPECTED_EXTENSION:",
6869 expectedLocalError: "remote error: unsupported extension",
6870 })
6871
6872 // Test a known but unoffered extension from the server.
6873 testCases = append(testCases, testCase{
6874 testType: clientTest,
6875 name: "UnofferedExtension-Client",
6876 config: Config{
6877 MaxVersion: VersionTLS12,
6878 Bugs: ProtocolBugs{
6879 SendALPN: "alpn",
6880 },
6881 },
6882 shouldFail: true,
6883 expectedError: ":UNEXPECTED_EXTENSION:",
6884 expectedLocalError: "remote error: unsupported extension",
6885 })
6886 testCases = append(testCases, testCase{
6887 testType: clientTest,
6888 name: "UnofferedExtension-Client-TLS13",
6889 config: Config{
6890 MaxVersion: VersionTLS13,
6891 Bugs: ProtocolBugs{
6892 SendALPN: "alpn",
6893 },
6894 },
6895 shouldFail: true,
6896 expectedError: ":UNEXPECTED_EXTENSION:",
6897 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006898 })
Adam Langley09505632015-07-30 18:10:13 -07006899}
6900
David Benjaminb36a3952015-12-01 18:53:13 -05006901func addRSAClientKeyExchangeTests() {
6902 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6906 config: Config{
6907 // Ensure the ClientHello version and final
6908 // version are different, to detect if the
6909 // server uses the wrong one.
6910 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006911 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006912 Bugs: ProtocolBugs{
6913 BadRSAClientKeyExchange: bad,
6914 },
6915 },
6916 shouldFail: true,
6917 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6918 })
6919 }
David Benjamine63d9d72016-09-19 18:27:34 -04006920
6921 // The server must compare whatever was in ClientHello.version for the
6922 // RSA premaster.
6923 testCases = append(testCases, testCase{
6924 testType: serverTest,
6925 name: "SendClientVersion-RSA",
6926 config: Config{
6927 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6928 Bugs: ProtocolBugs{
6929 SendClientVersion: 0x1234,
6930 },
6931 },
6932 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6933 })
David Benjaminb36a3952015-12-01 18:53:13 -05006934}
6935
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006936var testCurves = []struct {
6937 name string
6938 id CurveID
6939}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006940 {"P-256", CurveP256},
6941 {"P-384", CurveP384},
6942 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006943 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006944}
6945
Steven Valdez5440fe02016-07-18 12:40:30 -04006946const bogusCurve = 0x1234
6947
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006948func addCurveTests() {
6949 for _, curve := range testCurves {
6950 testCases = append(testCases, testCase{
6951 name: "CurveTest-Client-" + curve.name,
6952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006953 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6955 CurvePreferences: []CurveID{curve.id},
6956 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006957 flags: []string{
6958 "-enable-all-curves",
6959 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6960 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006961 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006962 })
6963 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006964 name: "CurveTest-Client-" + curve.name + "-TLS13",
6965 config: Config{
6966 MaxVersion: VersionTLS13,
6967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6968 CurvePreferences: []CurveID{curve.id},
6969 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006970 flags: []string{
6971 "-enable-all-curves",
6972 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6973 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006974 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006975 })
6976 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006977 testType: serverTest,
6978 name: "CurveTest-Server-" + curve.name,
6979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006980 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6982 CurvePreferences: []CurveID{curve.id},
6983 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006984 flags: []string{
6985 "-enable-all-curves",
6986 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6987 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006988 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006989 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006990 testCases = append(testCases, testCase{
6991 testType: serverTest,
6992 name: "CurveTest-Server-" + curve.name + "-TLS13",
6993 config: Config{
6994 MaxVersion: VersionTLS13,
6995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6996 CurvePreferences: []CurveID{curve.id},
6997 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006998 flags: []string{
6999 "-enable-all-curves",
7000 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7001 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007002 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007003 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007004 }
David Benjamin241ae832016-01-15 03:04:54 -05007005
7006 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007007 testCases = append(testCases, testCase{
7008 testType: serverTest,
7009 name: "UnknownCurve",
7010 config: Config{
7011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7012 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7013 },
7014 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007015
7016 // The server must not consider ECDHE ciphers when there are no
7017 // supported curves.
7018 testCases = append(testCases, testCase{
7019 testType: serverTest,
7020 name: "NoSupportedCurves",
7021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007022 MaxVersion: VersionTLS12,
7023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7024 Bugs: ProtocolBugs{
7025 NoSupportedCurves: true,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedError: ":NO_SHARED_CIPHER:",
7030 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007031 testCases = append(testCases, testCase{
7032 testType: serverTest,
7033 name: "NoSupportedCurves-TLS13",
7034 config: Config{
7035 MaxVersion: VersionTLS13,
7036 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7037 Bugs: ProtocolBugs{
7038 NoSupportedCurves: true,
7039 },
7040 },
7041 shouldFail: true,
7042 expectedError: ":NO_SHARED_CIPHER:",
7043 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007044
7045 // The server must fall back to another cipher when there are no
7046 // supported curves.
7047 testCases = append(testCases, testCase{
7048 testType: serverTest,
7049 name: "NoCommonCurves",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 CipherSuites: []uint16{
7053 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7054 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7055 },
7056 CurvePreferences: []CurveID{CurveP224},
7057 },
7058 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7059 })
7060
7061 // The client must reject bogus curves and disabled curves.
7062 testCases = append(testCases, testCase{
7063 name: "BadECDHECurve",
7064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007065 MaxVersion: VersionTLS12,
7066 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7067 Bugs: ProtocolBugs{
7068 SendCurve: bogusCurve,
7069 },
7070 },
7071 shouldFail: true,
7072 expectedError: ":WRONG_CURVE:",
7073 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007074 testCases = append(testCases, testCase{
7075 name: "BadECDHECurve-TLS13",
7076 config: Config{
7077 MaxVersion: VersionTLS13,
7078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7079 Bugs: ProtocolBugs{
7080 SendCurve: bogusCurve,
7081 },
7082 },
7083 shouldFail: true,
7084 expectedError: ":WRONG_CURVE:",
7085 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007086
7087 testCases = append(testCases, testCase{
7088 name: "UnsupportedCurve",
7089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007090 MaxVersion: VersionTLS12,
7091 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7092 CurvePreferences: []CurveID{CurveP256},
7093 Bugs: ProtocolBugs{
7094 IgnorePeerCurvePreferences: true,
7095 },
7096 },
7097 flags: []string{"-p384-only"},
7098 shouldFail: true,
7099 expectedError: ":WRONG_CURVE:",
7100 })
7101
David Benjamin4f921572016-07-17 14:20:10 +02007102 testCases = append(testCases, testCase{
7103 // TODO(davidben): Add a TLS 1.3 version where
7104 // HelloRetryRequest requests an unsupported curve.
7105 name: "UnsupportedCurve-ServerHello-TLS13",
7106 config: Config{
7107 MaxVersion: VersionTLS12,
7108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7109 CurvePreferences: []CurveID{CurveP384},
7110 Bugs: ProtocolBugs{
7111 SendCurve: CurveP256,
7112 },
7113 },
7114 flags: []string{"-p384-only"},
7115 shouldFail: true,
7116 expectedError: ":WRONG_CURVE:",
7117 })
7118
David Benjamin4c3ddf72016-06-29 18:13:53 -04007119 // Test invalid curve points.
7120 testCases = append(testCases, testCase{
7121 name: "InvalidECDHPoint-Client",
7122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007123 MaxVersion: VersionTLS12,
7124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7125 CurvePreferences: []CurveID{CurveP256},
7126 Bugs: ProtocolBugs{
7127 InvalidECDHPoint: true,
7128 },
7129 },
7130 shouldFail: true,
7131 expectedError: ":INVALID_ENCODING:",
7132 })
7133 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007134 name: "InvalidECDHPoint-Client-TLS13",
7135 config: Config{
7136 MaxVersion: VersionTLS13,
7137 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7138 CurvePreferences: []CurveID{CurveP256},
7139 Bugs: ProtocolBugs{
7140 InvalidECDHPoint: true,
7141 },
7142 },
7143 shouldFail: true,
7144 expectedError: ":INVALID_ENCODING:",
7145 })
7146 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007147 testType: serverTest,
7148 name: "InvalidECDHPoint-Server",
7149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007150 MaxVersion: VersionTLS12,
7151 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7152 CurvePreferences: []CurveID{CurveP256},
7153 Bugs: ProtocolBugs{
7154 InvalidECDHPoint: true,
7155 },
7156 },
7157 shouldFail: true,
7158 expectedError: ":INVALID_ENCODING:",
7159 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007160 testCases = append(testCases, testCase{
7161 testType: serverTest,
7162 name: "InvalidECDHPoint-Server-TLS13",
7163 config: Config{
7164 MaxVersion: VersionTLS13,
7165 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7166 CurvePreferences: []CurveID{CurveP256},
7167 Bugs: ProtocolBugs{
7168 InvalidECDHPoint: true,
7169 },
7170 },
7171 shouldFail: true,
7172 expectedError: ":INVALID_ENCODING:",
7173 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007174}
7175
Matt Braithwaite54217e42016-06-13 13:03:47 -07007176func addCECPQ1Tests() {
7177 testCases = append(testCases, testCase{
7178 testType: clientTest,
7179 name: "CECPQ1-Client-BadX25519Part",
7180 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007181 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007182 MinVersion: VersionTLS12,
7183 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7184 Bugs: ProtocolBugs{
7185 CECPQ1BadX25519Part: true,
7186 },
7187 },
7188 flags: []string{"-cipher", "kCECPQ1"},
7189 shouldFail: true,
7190 expectedLocalError: "local error: bad record MAC",
7191 })
7192 testCases = append(testCases, testCase{
7193 testType: clientTest,
7194 name: "CECPQ1-Client-BadNewhopePart",
7195 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007196 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007197 MinVersion: VersionTLS12,
7198 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7199 Bugs: ProtocolBugs{
7200 CECPQ1BadNewhopePart: true,
7201 },
7202 },
7203 flags: []string{"-cipher", "kCECPQ1"},
7204 shouldFail: true,
7205 expectedLocalError: "local error: bad record MAC",
7206 })
7207 testCases = append(testCases, testCase{
7208 testType: serverTest,
7209 name: "CECPQ1-Server-BadX25519Part",
7210 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007211 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007212 MinVersion: VersionTLS12,
7213 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7214 Bugs: ProtocolBugs{
7215 CECPQ1BadX25519Part: true,
7216 },
7217 },
7218 flags: []string{"-cipher", "kCECPQ1"},
7219 shouldFail: true,
7220 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7221 })
7222 testCases = append(testCases, testCase{
7223 testType: serverTest,
7224 name: "CECPQ1-Server-BadNewhopePart",
7225 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007226 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007227 MinVersion: VersionTLS12,
7228 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7229 Bugs: ProtocolBugs{
7230 CECPQ1BadNewhopePart: true,
7231 },
7232 },
7233 flags: []string{"-cipher", "kCECPQ1"},
7234 shouldFail: true,
7235 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7236 })
7237}
7238
David Benjamin5c4e8572016-08-19 17:44:53 -04007239func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007240 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007241 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007242 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007243 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007244 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7245 Bugs: ProtocolBugs{
7246 // This is a 1234-bit prime number, generated
7247 // with:
7248 // openssl gendh 1234 | openssl asn1parse -i
7249 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7250 },
7251 },
David Benjamin9e68f192016-06-30 14:55:33 -04007252 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007253 })
7254 testCases = append(testCases, testCase{
7255 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007256 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007257 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007258 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007259 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7260 },
7261 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007262 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007263 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007264}
7265
David Benjaminc9ae27c2016-06-24 22:56:37 -04007266func addTLS13RecordTests() {
7267 testCases = append(testCases, testCase{
7268 name: "TLS13-RecordPadding",
7269 config: Config{
7270 MaxVersion: VersionTLS13,
7271 MinVersion: VersionTLS13,
7272 Bugs: ProtocolBugs{
7273 RecordPadding: 10,
7274 },
7275 },
7276 })
7277
7278 testCases = append(testCases, testCase{
7279 name: "TLS13-EmptyRecords",
7280 config: Config{
7281 MaxVersion: VersionTLS13,
7282 MinVersion: VersionTLS13,
7283 Bugs: ProtocolBugs{
7284 OmitRecordContents: true,
7285 },
7286 },
7287 shouldFail: true,
7288 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7289 })
7290
7291 testCases = append(testCases, testCase{
7292 name: "TLS13-OnlyPadding",
7293 config: Config{
7294 MaxVersion: VersionTLS13,
7295 MinVersion: VersionTLS13,
7296 Bugs: ProtocolBugs{
7297 OmitRecordContents: true,
7298 RecordPadding: 10,
7299 },
7300 },
7301 shouldFail: true,
7302 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7303 })
7304
7305 testCases = append(testCases, testCase{
7306 name: "TLS13-WrongOuterRecord",
7307 config: Config{
7308 MaxVersion: VersionTLS13,
7309 MinVersion: VersionTLS13,
7310 Bugs: ProtocolBugs{
7311 OuterRecordType: recordTypeHandshake,
7312 },
7313 },
7314 shouldFail: true,
7315 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7316 })
7317}
7318
David Benjamin82261be2016-07-07 14:32:50 -07007319func addChangeCipherSpecTests() {
7320 // Test missing ChangeCipherSpecs.
7321 testCases = append(testCases, testCase{
7322 name: "SkipChangeCipherSpec-Client",
7323 config: Config{
7324 MaxVersion: VersionTLS12,
7325 Bugs: ProtocolBugs{
7326 SkipChangeCipherSpec: true,
7327 },
7328 },
7329 shouldFail: true,
7330 expectedError: ":UNEXPECTED_RECORD:",
7331 })
7332 testCases = append(testCases, testCase{
7333 testType: serverTest,
7334 name: "SkipChangeCipherSpec-Server",
7335 config: Config{
7336 MaxVersion: VersionTLS12,
7337 Bugs: ProtocolBugs{
7338 SkipChangeCipherSpec: true,
7339 },
7340 },
7341 shouldFail: true,
7342 expectedError: ":UNEXPECTED_RECORD:",
7343 })
7344 testCases = append(testCases, testCase{
7345 testType: serverTest,
7346 name: "SkipChangeCipherSpec-Server-NPN",
7347 config: Config{
7348 MaxVersion: VersionTLS12,
7349 NextProtos: []string{"bar"},
7350 Bugs: ProtocolBugs{
7351 SkipChangeCipherSpec: true,
7352 },
7353 },
7354 flags: []string{
7355 "-advertise-npn", "\x03foo\x03bar\x03baz",
7356 },
7357 shouldFail: true,
7358 expectedError: ":UNEXPECTED_RECORD:",
7359 })
7360
7361 // Test synchronization between the handshake and ChangeCipherSpec.
7362 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7363 // rejected. Test both with and without handshake packing to handle both
7364 // when the partial post-CCS message is in its own record and when it is
7365 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007366 for _, packed := range []bool{false, true} {
7367 var suffix string
7368 if packed {
7369 suffix = "-Packed"
7370 }
7371
7372 testCases = append(testCases, testCase{
7373 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7374 config: Config{
7375 MaxVersion: VersionTLS12,
7376 Bugs: ProtocolBugs{
7377 FragmentAcrossChangeCipherSpec: true,
7378 PackHandshakeFlight: packed,
7379 },
7380 },
7381 shouldFail: true,
7382 expectedError: ":UNEXPECTED_RECORD:",
7383 })
7384 testCases = append(testCases, testCase{
7385 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7386 config: Config{
7387 MaxVersion: VersionTLS12,
7388 },
7389 resumeSession: true,
7390 resumeConfig: &Config{
7391 MaxVersion: VersionTLS12,
7392 Bugs: ProtocolBugs{
7393 FragmentAcrossChangeCipherSpec: true,
7394 PackHandshakeFlight: packed,
7395 },
7396 },
7397 shouldFail: true,
7398 expectedError: ":UNEXPECTED_RECORD:",
7399 })
7400 testCases = append(testCases, testCase{
7401 testType: serverTest,
7402 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7403 config: Config{
7404 MaxVersion: VersionTLS12,
7405 Bugs: ProtocolBugs{
7406 FragmentAcrossChangeCipherSpec: true,
7407 PackHandshakeFlight: packed,
7408 },
7409 },
7410 shouldFail: true,
7411 expectedError: ":UNEXPECTED_RECORD:",
7412 })
7413 testCases = append(testCases, testCase{
7414 testType: serverTest,
7415 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7416 config: Config{
7417 MaxVersion: VersionTLS12,
7418 },
7419 resumeSession: true,
7420 resumeConfig: &Config{
7421 MaxVersion: VersionTLS12,
7422 Bugs: ProtocolBugs{
7423 FragmentAcrossChangeCipherSpec: true,
7424 PackHandshakeFlight: packed,
7425 },
7426 },
7427 shouldFail: true,
7428 expectedError: ":UNEXPECTED_RECORD:",
7429 })
7430 testCases = append(testCases, testCase{
7431 testType: serverTest,
7432 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7433 config: Config{
7434 MaxVersion: VersionTLS12,
7435 NextProtos: []string{"bar"},
7436 Bugs: ProtocolBugs{
7437 FragmentAcrossChangeCipherSpec: true,
7438 PackHandshakeFlight: packed,
7439 },
7440 },
7441 flags: []string{
7442 "-advertise-npn", "\x03foo\x03bar\x03baz",
7443 },
7444 shouldFail: true,
7445 expectedError: ":UNEXPECTED_RECORD:",
7446 })
7447 }
7448
David Benjamin61672812016-07-14 23:10:43 -04007449 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7450 // messages in the handshake queue. Do this by testing the server
7451 // reading the client Finished, reversing the flight so Finished comes
7452 // first.
7453 testCases = append(testCases, testCase{
7454 protocol: dtls,
7455 testType: serverTest,
7456 name: "SendUnencryptedFinished-DTLS",
7457 config: Config{
7458 MaxVersion: VersionTLS12,
7459 Bugs: ProtocolBugs{
7460 SendUnencryptedFinished: true,
7461 ReverseHandshakeFragments: true,
7462 },
7463 },
7464 shouldFail: true,
7465 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7466 })
7467
Steven Valdez143e8b32016-07-11 13:19:03 -04007468 // Test synchronization between encryption changes and the handshake in
7469 // TLS 1.3, where ChangeCipherSpec is implicit.
7470 testCases = append(testCases, testCase{
7471 name: "PartialEncryptedExtensionsWithServerHello",
7472 config: Config{
7473 MaxVersion: VersionTLS13,
7474 Bugs: ProtocolBugs{
7475 PartialEncryptedExtensionsWithServerHello: true,
7476 },
7477 },
7478 shouldFail: true,
7479 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7480 })
7481 testCases = append(testCases, testCase{
7482 testType: serverTest,
7483 name: "PartialClientFinishedWithClientHello",
7484 config: Config{
7485 MaxVersion: VersionTLS13,
7486 Bugs: ProtocolBugs{
7487 PartialClientFinishedWithClientHello: true,
7488 },
7489 },
7490 shouldFail: true,
7491 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7492 })
7493
David Benjamin82261be2016-07-07 14:32:50 -07007494 // Test that early ChangeCipherSpecs are handled correctly.
7495 testCases = append(testCases, testCase{
7496 testType: serverTest,
7497 name: "EarlyChangeCipherSpec-server-1",
7498 config: Config{
7499 MaxVersion: VersionTLS12,
7500 Bugs: ProtocolBugs{
7501 EarlyChangeCipherSpec: 1,
7502 },
7503 },
7504 shouldFail: true,
7505 expectedError: ":UNEXPECTED_RECORD:",
7506 })
7507 testCases = append(testCases, testCase{
7508 testType: serverTest,
7509 name: "EarlyChangeCipherSpec-server-2",
7510 config: Config{
7511 MaxVersion: VersionTLS12,
7512 Bugs: ProtocolBugs{
7513 EarlyChangeCipherSpec: 2,
7514 },
7515 },
7516 shouldFail: true,
7517 expectedError: ":UNEXPECTED_RECORD:",
7518 })
7519 testCases = append(testCases, testCase{
7520 protocol: dtls,
7521 name: "StrayChangeCipherSpec",
7522 config: Config{
7523 // TODO(davidben): Once DTLS 1.3 exists, test
7524 // that stray ChangeCipherSpec messages are
7525 // rejected.
7526 MaxVersion: VersionTLS12,
7527 Bugs: ProtocolBugs{
7528 StrayChangeCipherSpec: true,
7529 },
7530 },
7531 })
7532
7533 // Test that the contents of ChangeCipherSpec are checked.
7534 testCases = append(testCases, testCase{
7535 name: "BadChangeCipherSpec-1",
7536 config: Config{
7537 MaxVersion: VersionTLS12,
7538 Bugs: ProtocolBugs{
7539 BadChangeCipherSpec: []byte{2},
7540 },
7541 },
7542 shouldFail: true,
7543 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7544 })
7545 testCases = append(testCases, testCase{
7546 name: "BadChangeCipherSpec-2",
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 Bugs: ProtocolBugs{
7550 BadChangeCipherSpec: []byte{1, 1},
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7555 })
7556 testCases = append(testCases, testCase{
7557 protocol: dtls,
7558 name: "BadChangeCipherSpec-DTLS-1",
7559 config: Config{
7560 MaxVersion: VersionTLS12,
7561 Bugs: ProtocolBugs{
7562 BadChangeCipherSpec: []byte{2},
7563 },
7564 },
7565 shouldFail: true,
7566 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7567 })
7568 testCases = append(testCases, testCase{
7569 protocol: dtls,
7570 name: "BadChangeCipherSpec-DTLS-2",
7571 config: Config{
7572 MaxVersion: VersionTLS12,
7573 Bugs: ProtocolBugs{
7574 BadChangeCipherSpec: []byte{1, 1},
7575 },
7576 },
7577 shouldFail: true,
7578 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7579 })
7580}
7581
David Benjamincd2c8062016-09-09 11:28:16 -04007582type perMessageTest struct {
7583 messageType uint8
7584 test testCase
7585}
7586
7587// makePerMessageTests returns a series of test templates which cover each
7588// message in the TLS handshake. These may be used with bugs like
7589// WrongMessageType to fully test a per-message bug.
7590func makePerMessageTests() []perMessageTest {
7591 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007592 for _, protocol := range []protocol{tls, dtls} {
7593 var suffix string
7594 if protocol == dtls {
7595 suffix = "-DTLS"
7596 }
7597
David Benjamincd2c8062016-09-09 11:28:16 -04007598 ret = append(ret, perMessageTest{
7599 messageType: typeClientHello,
7600 test: testCase{
7601 protocol: protocol,
7602 testType: serverTest,
7603 name: "ClientHello" + suffix,
7604 config: Config{
7605 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007606 },
7607 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007608 })
7609
7610 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007611 ret = append(ret, perMessageTest{
7612 messageType: typeHelloVerifyRequest,
7613 test: testCase{
7614 protocol: protocol,
7615 name: "HelloVerifyRequest" + suffix,
7616 config: Config{
7617 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007618 },
7619 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007620 })
7621 }
7622
David Benjamincd2c8062016-09-09 11:28:16 -04007623 ret = append(ret, perMessageTest{
7624 messageType: typeServerHello,
7625 test: testCase{
7626 protocol: protocol,
7627 name: "ServerHello" + suffix,
7628 config: Config{
7629 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007630 },
7631 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007632 })
7633
David Benjamincd2c8062016-09-09 11:28:16 -04007634 ret = append(ret, perMessageTest{
7635 messageType: typeCertificate,
7636 test: testCase{
7637 protocol: protocol,
7638 name: "ServerCertificate" + suffix,
7639 config: Config{
7640 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007641 },
7642 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007643 })
7644
David Benjamincd2c8062016-09-09 11:28:16 -04007645 ret = append(ret, perMessageTest{
7646 messageType: typeCertificateStatus,
7647 test: testCase{
7648 protocol: protocol,
7649 name: "CertificateStatus" + suffix,
7650 config: Config{
7651 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007652 },
David Benjamincd2c8062016-09-09 11:28:16 -04007653 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007654 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007655 })
7656
David Benjamincd2c8062016-09-09 11:28:16 -04007657 ret = append(ret, perMessageTest{
7658 messageType: typeServerKeyExchange,
7659 test: testCase{
7660 protocol: protocol,
7661 name: "ServerKeyExchange" + suffix,
7662 config: Config{
7663 MaxVersion: VersionTLS12,
7664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007665 },
7666 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007667 })
7668
David Benjamincd2c8062016-09-09 11:28:16 -04007669 ret = append(ret, perMessageTest{
7670 messageType: typeCertificateRequest,
7671 test: testCase{
7672 protocol: protocol,
7673 name: "CertificateRequest" + suffix,
7674 config: Config{
7675 MaxVersion: VersionTLS12,
7676 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007677 },
7678 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007679 })
7680
David Benjamincd2c8062016-09-09 11:28:16 -04007681 ret = append(ret, perMessageTest{
7682 messageType: typeServerHelloDone,
7683 test: testCase{
7684 protocol: protocol,
7685 name: "ServerHelloDone" + suffix,
7686 config: Config{
7687 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007688 },
7689 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007690 })
7691
David Benjamincd2c8062016-09-09 11:28:16 -04007692 ret = append(ret, perMessageTest{
7693 messageType: typeCertificate,
7694 test: testCase{
7695 testType: serverTest,
7696 protocol: protocol,
7697 name: "ClientCertificate" + suffix,
7698 config: Config{
7699 Certificates: []Certificate{rsaCertificate},
7700 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007701 },
David Benjamincd2c8062016-09-09 11:28:16 -04007702 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007703 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007704 })
7705
David Benjamincd2c8062016-09-09 11:28:16 -04007706 ret = append(ret, perMessageTest{
7707 messageType: typeCertificateVerify,
7708 test: testCase{
7709 testType: serverTest,
7710 protocol: protocol,
7711 name: "CertificateVerify" + suffix,
7712 config: Config{
7713 Certificates: []Certificate{rsaCertificate},
7714 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007715 },
David Benjamincd2c8062016-09-09 11:28:16 -04007716 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007717 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007718 })
7719
David Benjamincd2c8062016-09-09 11:28:16 -04007720 ret = append(ret, perMessageTest{
7721 messageType: typeClientKeyExchange,
7722 test: testCase{
7723 testType: serverTest,
7724 protocol: protocol,
7725 name: "ClientKeyExchange" + suffix,
7726 config: Config{
7727 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007728 },
7729 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007730 })
7731
7732 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007733 ret = append(ret, perMessageTest{
7734 messageType: typeNextProtocol,
7735 test: testCase{
7736 testType: serverTest,
7737 protocol: protocol,
7738 name: "NextProtocol" + suffix,
7739 config: Config{
7740 MaxVersion: VersionTLS12,
7741 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007742 },
David Benjamincd2c8062016-09-09 11:28:16 -04007743 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007744 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007745 })
7746
David Benjamincd2c8062016-09-09 11:28:16 -04007747 ret = append(ret, perMessageTest{
7748 messageType: typeChannelID,
7749 test: testCase{
7750 testType: serverTest,
7751 protocol: protocol,
7752 name: "ChannelID" + suffix,
7753 config: Config{
7754 MaxVersion: VersionTLS12,
7755 ChannelID: channelIDKey,
7756 },
7757 flags: []string{
7758 "-expect-channel-id",
7759 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007760 },
7761 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 })
7763 }
7764
David Benjamincd2c8062016-09-09 11:28:16 -04007765 ret = append(ret, perMessageTest{
7766 messageType: typeFinished,
7767 test: testCase{
7768 testType: serverTest,
7769 protocol: protocol,
7770 name: "ClientFinished" + suffix,
7771 config: Config{
7772 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007773 },
7774 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007775 })
7776
David Benjamincd2c8062016-09-09 11:28:16 -04007777 ret = append(ret, perMessageTest{
7778 messageType: typeNewSessionTicket,
7779 test: testCase{
7780 protocol: protocol,
7781 name: "NewSessionTicket" + suffix,
7782 config: Config{
7783 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007784 },
7785 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007786 })
7787
David Benjamincd2c8062016-09-09 11:28:16 -04007788 ret = append(ret, perMessageTest{
7789 messageType: typeFinished,
7790 test: testCase{
7791 protocol: protocol,
7792 name: "ServerFinished" + 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
7799 }
David Benjamincd2c8062016-09-09 11:28:16 -04007800
7801 ret = append(ret, perMessageTest{
7802 messageType: typeClientHello,
7803 test: testCase{
7804 testType: serverTest,
7805 name: "TLS13-ClientHello",
7806 config: Config{
7807 MaxVersion: VersionTLS13,
7808 },
7809 },
7810 })
7811
7812 ret = append(ret, perMessageTest{
7813 messageType: typeServerHello,
7814 test: testCase{
7815 name: "TLS13-ServerHello",
7816 config: Config{
7817 MaxVersion: VersionTLS13,
7818 },
7819 },
7820 })
7821
7822 ret = append(ret, perMessageTest{
7823 messageType: typeEncryptedExtensions,
7824 test: testCase{
7825 name: "TLS13-EncryptedExtensions",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 },
7829 },
7830 })
7831
7832 ret = append(ret, perMessageTest{
7833 messageType: typeCertificateRequest,
7834 test: testCase{
7835 name: "TLS13-CertificateRequest",
7836 config: Config{
7837 MaxVersion: VersionTLS13,
7838 ClientAuth: RequireAnyClientCert,
7839 },
7840 },
7841 })
7842
7843 ret = append(ret, perMessageTest{
7844 messageType: typeCertificate,
7845 test: testCase{
7846 name: "TLS13-ServerCertificate",
7847 config: Config{
7848 MaxVersion: VersionTLS13,
7849 },
7850 },
7851 })
7852
7853 ret = append(ret, perMessageTest{
7854 messageType: typeCertificateVerify,
7855 test: testCase{
7856 name: "TLS13-ServerCertificateVerify",
7857 config: Config{
7858 MaxVersion: VersionTLS13,
7859 },
7860 },
7861 })
7862
7863 ret = append(ret, perMessageTest{
7864 messageType: typeFinished,
7865 test: testCase{
7866 name: "TLS13-ServerFinished",
7867 config: Config{
7868 MaxVersion: VersionTLS13,
7869 },
7870 },
7871 })
7872
7873 ret = append(ret, perMessageTest{
7874 messageType: typeCertificate,
7875 test: testCase{
7876 testType: serverTest,
7877 name: "TLS13-ClientCertificate",
7878 config: Config{
7879 Certificates: []Certificate{rsaCertificate},
7880 MaxVersion: VersionTLS13,
7881 },
7882 flags: []string{"-require-any-client-certificate"},
7883 },
7884 })
7885
7886 ret = append(ret, perMessageTest{
7887 messageType: typeCertificateVerify,
7888 test: testCase{
7889 testType: serverTest,
7890 name: "TLS13-ClientCertificateVerify",
7891 config: Config{
7892 Certificates: []Certificate{rsaCertificate},
7893 MaxVersion: VersionTLS13,
7894 },
7895 flags: []string{"-require-any-client-certificate"},
7896 },
7897 })
7898
7899 ret = append(ret, perMessageTest{
7900 messageType: typeFinished,
7901 test: testCase{
7902 testType: serverTest,
7903 name: "TLS13-ClientFinished",
7904 config: Config{
7905 MaxVersion: VersionTLS13,
7906 },
7907 },
7908 })
7909
7910 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007911}
7912
David Benjamincd2c8062016-09-09 11:28:16 -04007913func addWrongMessageTypeTests() {
7914 for _, t := range makePerMessageTests() {
7915 t.test.name = "WrongMessageType-" + t.test.name
7916 t.test.config.Bugs.SendWrongMessageType = t.messageType
7917 t.test.shouldFail = true
7918 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7919 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007920
David Benjamincd2c8062016-09-09 11:28:16 -04007921 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7922 // In TLS 1.3, a bad ServerHello means the client sends
7923 // an unencrypted alert while the server expects
7924 // encryption, so the alert is not readable by runner.
7925 t.test.expectedLocalError = "local error: bad record MAC"
7926 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007927
David Benjamincd2c8062016-09-09 11:28:16 -04007928 testCases = append(testCases, t.test)
7929 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007930}
7931
David Benjamin639846e2016-09-09 11:41:18 -04007932func addTrailingMessageDataTests() {
7933 for _, t := range makePerMessageTests() {
7934 t.test.name = "TrailingMessageData-" + t.test.name
7935 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7936 t.test.shouldFail = true
7937 t.test.expectedError = ":DECODE_ERROR:"
7938 t.test.expectedLocalError = "remote error: error decoding message"
7939
7940 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7941 // In TLS 1.3, a bad ServerHello means the client sends
7942 // an unencrypted alert while the server expects
7943 // encryption, so the alert is not readable by runner.
7944 t.test.expectedLocalError = "local error: bad record MAC"
7945 }
7946
7947 if t.messageType == typeFinished {
7948 // Bad Finished messages read as the verify data having
7949 // the wrong length.
7950 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7951 t.test.expectedLocalError = "remote error: error decrypting message"
7952 }
7953
7954 testCases = append(testCases, t.test)
7955 }
7956}
7957
Steven Valdez143e8b32016-07-11 13:19:03 -04007958func addTLS13HandshakeTests() {
7959 testCases = append(testCases, testCase{
7960 testType: clientTest,
7961 name: "MissingKeyShare-Client",
7962 config: Config{
7963 MaxVersion: VersionTLS13,
7964 Bugs: ProtocolBugs{
7965 MissingKeyShare: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":MISSING_KEY_SHARE:",
7970 })
7971
7972 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007973 testType: serverTest,
7974 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 Bugs: ProtocolBugs{
7978 MissingKeyShare: true,
7979 },
7980 },
7981 shouldFail: true,
7982 expectedError: ":MISSING_KEY_SHARE:",
7983 })
7984
7985 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007986 testType: serverTest,
7987 name: "DuplicateKeyShares",
7988 config: Config{
7989 MaxVersion: VersionTLS13,
7990 Bugs: ProtocolBugs{
7991 DuplicateKeyShares: true,
7992 },
7993 },
David Benjamin7e1f9842016-09-20 19:24:40 -04007994 shouldFail: true,
7995 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007996 })
7997
7998 testCases = append(testCases, testCase{
7999 testType: clientTest,
8000 name: "EmptyEncryptedExtensions",
8001 config: Config{
8002 MaxVersion: VersionTLS13,
8003 Bugs: ProtocolBugs{
8004 EmptyEncryptedExtensions: true,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedLocalError: "remote error: error decoding message",
8009 })
8010
8011 testCases = append(testCases, testCase{
8012 testType: clientTest,
8013 name: "EncryptedExtensionsWithKeyShare",
8014 config: Config{
8015 MaxVersion: VersionTLS13,
8016 Bugs: ProtocolBugs{
8017 EncryptedExtensionsWithKeyShare: true,
8018 },
8019 },
8020 shouldFail: true,
8021 expectedLocalError: "remote error: unsupported extension",
8022 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008023
8024 testCases = append(testCases, testCase{
8025 testType: serverTest,
8026 name: "SendHelloRetryRequest",
8027 config: Config{
8028 MaxVersion: VersionTLS13,
8029 // Require a HelloRetryRequest for every curve.
8030 DefaultCurves: []CurveID{},
8031 },
8032 expectedCurveID: CurveX25519,
8033 })
8034
8035 testCases = append(testCases, testCase{
8036 testType: serverTest,
8037 name: "SendHelloRetryRequest-2",
8038 config: Config{
8039 MaxVersion: VersionTLS13,
8040 DefaultCurves: []CurveID{CurveP384},
8041 },
8042 // Although the ClientHello did not predict our preferred curve,
8043 // we always select it whether it is predicted or not.
8044 expectedCurveID: CurveX25519,
8045 })
8046
8047 testCases = append(testCases, testCase{
8048 name: "UnknownCurve-HelloRetryRequest",
8049 config: Config{
8050 MaxVersion: VersionTLS13,
8051 // P-384 requires HelloRetryRequest in BoringSSL.
8052 CurvePreferences: []CurveID{CurveP384},
8053 Bugs: ProtocolBugs{
8054 SendHelloRetryRequestCurve: bogusCurve,
8055 },
8056 },
8057 shouldFail: true,
8058 expectedError: ":WRONG_CURVE:",
8059 })
8060
8061 testCases = append(testCases, testCase{
8062 name: "DisabledCurve-HelloRetryRequest",
8063 config: Config{
8064 MaxVersion: VersionTLS13,
8065 CurvePreferences: []CurveID{CurveP256},
8066 Bugs: ProtocolBugs{
8067 IgnorePeerCurvePreferences: true,
8068 },
8069 },
8070 flags: []string{"-p384-only"},
8071 shouldFail: true,
8072 expectedError: ":WRONG_CURVE:",
8073 })
8074
8075 testCases = append(testCases, testCase{
8076 name: "UnnecessaryHelloRetryRequest",
8077 config: Config{
8078 MaxVersion: VersionTLS13,
8079 Bugs: ProtocolBugs{
8080 UnnecessaryHelloRetryRequest: true,
8081 },
8082 },
8083 shouldFail: true,
8084 expectedError: ":WRONG_CURVE:",
8085 })
8086
8087 testCases = append(testCases, testCase{
8088 name: "SecondHelloRetryRequest",
8089 config: Config{
8090 MaxVersion: VersionTLS13,
8091 // P-384 requires HelloRetryRequest in BoringSSL.
8092 CurvePreferences: []CurveID{CurveP384},
8093 Bugs: ProtocolBugs{
8094 SecondHelloRetryRequest: true,
8095 },
8096 },
8097 shouldFail: true,
8098 expectedError: ":UNEXPECTED_MESSAGE:",
8099 })
8100
8101 testCases = append(testCases, testCase{
8102 testType: serverTest,
8103 name: "SecondClientHelloMissingKeyShare",
8104 config: Config{
8105 MaxVersion: VersionTLS13,
8106 DefaultCurves: []CurveID{},
8107 Bugs: ProtocolBugs{
8108 SecondClientHelloMissingKeyShare: true,
8109 },
8110 },
8111 shouldFail: true,
8112 expectedError: ":MISSING_KEY_SHARE:",
8113 })
8114
8115 testCases = append(testCases, testCase{
8116 testType: serverTest,
8117 name: "SecondClientHelloWrongCurve",
8118 config: Config{
8119 MaxVersion: VersionTLS13,
8120 DefaultCurves: []CurveID{},
8121 Bugs: ProtocolBugs{
8122 MisinterpretHelloRetryRequestCurve: CurveP521,
8123 },
8124 },
8125 shouldFail: true,
8126 expectedError: ":WRONG_CURVE:",
8127 })
8128
8129 testCases = append(testCases, testCase{
8130 name: "HelloRetryRequestVersionMismatch",
8131 config: Config{
8132 MaxVersion: VersionTLS13,
8133 // P-384 requires HelloRetryRequest in BoringSSL.
8134 CurvePreferences: []CurveID{CurveP384},
8135 Bugs: ProtocolBugs{
8136 SendServerHelloVersion: 0x0305,
8137 },
8138 },
8139 shouldFail: true,
8140 expectedError: ":WRONG_VERSION_NUMBER:",
8141 })
8142
8143 testCases = append(testCases, testCase{
8144 name: "HelloRetryRequestCurveMismatch",
8145 config: Config{
8146 MaxVersion: VersionTLS13,
8147 // P-384 requires HelloRetryRequest in BoringSSL.
8148 CurvePreferences: []CurveID{CurveP384},
8149 Bugs: ProtocolBugs{
8150 // Send P-384 (correct) in the HelloRetryRequest.
8151 SendHelloRetryRequestCurve: CurveP384,
8152 // But send P-256 in the ServerHello.
8153 SendCurve: CurveP256,
8154 },
8155 },
8156 shouldFail: true,
8157 expectedError: ":WRONG_CURVE:",
8158 })
8159
8160 // Test the server selecting a curve that requires a HelloRetryRequest
8161 // without sending it.
8162 testCases = append(testCases, testCase{
8163 name: "SkipHelloRetryRequest",
8164 config: Config{
8165 MaxVersion: VersionTLS13,
8166 // P-384 requires HelloRetryRequest in BoringSSL.
8167 CurvePreferences: []CurveID{CurveP384},
8168 Bugs: ProtocolBugs{
8169 SkipHelloRetryRequest: true,
8170 },
8171 },
8172 shouldFail: true,
8173 expectedError: ":WRONG_CURVE:",
8174 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008175
8176 testCases = append(testCases, testCase{
8177 name: "TLS13-RequestContextInHandshake",
8178 config: Config{
8179 MaxVersion: VersionTLS13,
8180 MinVersion: VersionTLS13,
8181 ClientAuth: RequireAnyClientCert,
8182 Bugs: ProtocolBugs{
8183 SendRequestContext: []byte("request context"),
8184 },
8185 },
8186 flags: []string{
8187 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8188 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8189 },
8190 shouldFail: true,
8191 expectedError: ":DECODE_ERROR:",
8192 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008193
8194 testCases = append(testCases, testCase{
8195 testType: serverTest,
8196 name: "TLS13-TrailingKeyShareData",
8197 config: Config{
8198 MaxVersion: VersionTLS13,
8199 Bugs: ProtocolBugs{
8200 TrailingKeyShareData: true,
8201 },
8202 },
8203 shouldFail: true,
8204 expectedError: ":DECODE_ERROR:",
8205 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008206}
8207
David Benjaminf3fbade2016-09-19 13:08:16 -04008208func addPeekTests() {
8209 // Test SSL_peek works, including on empty records.
8210 testCases = append(testCases, testCase{
8211 name: "Peek-Basic",
8212 sendEmptyRecords: 1,
8213 flags: []string{"-peek-then-read"},
8214 })
8215
8216 // Test SSL_peek can drive the initial handshake.
8217 testCases = append(testCases, testCase{
8218 name: "Peek-ImplicitHandshake",
8219 flags: []string{
8220 "-peek-then-read",
8221 "-implicit-handshake",
8222 },
8223 })
8224
8225 // Test SSL_peek can discover and drive a renegotiation.
8226 testCases = append(testCases, testCase{
8227 name: "Peek-Renegotiate",
8228 config: Config{
8229 MaxVersion: VersionTLS12,
8230 },
8231 renegotiate: 1,
8232 flags: []string{
8233 "-peek-then-read",
8234 "-renegotiate-freely",
8235 "-expect-total-renegotiations", "1",
8236 },
8237 })
8238
8239 // Test SSL_peek can discover a close_notify.
8240 testCases = append(testCases, testCase{
8241 name: "Peek-Shutdown",
8242 config: Config{
8243 Bugs: ProtocolBugs{
8244 ExpectCloseNotify: true,
8245 },
8246 },
8247 flags: []string{
8248 "-peek-then-read",
8249 "-check-close-notify",
8250 },
8251 })
8252
8253 // Test SSL_peek can discover an alert.
8254 testCases = append(testCases, testCase{
8255 name: "Peek-Alert",
8256 config: Config{
8257 Bugs: ProtocolBugs{
8258 SendSpuriousAlert: alertRecordOverflow,
8259 },
8260 },
8261 flags: []string{"-peek-then-read"},
8262 shouldFail: true,
8263 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8264 })
8265
8266 // Test SSL_peek can handle KeyUpdate.
8267 testCases = append(testCases, testCase{
8268 name: "Peek-KeyUpdate",
8269 config: Config{
8270 MaxVersion: VersionTLS13,
8271 Bugs: ProtocolBugs{
8272 SendKeyUpdateBeforeEveryAppDataRecord: true,
8273 },
8274 },
8275 flags: []string{"-peek-then-read"},
8276 })
8277}
8278
Adam Langley7c803a62015-06-15 15:35:05 -07008279func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008280 defer wg.Done()
8281
8282 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008283 var err error
8284
8285 if *mallocTest < 0 {
8286 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008287 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008288 } else {
8289 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8290 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008291 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008292 if err != nil {
8293 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8294 }
8295 break
8296 }
8297 }
8298 }
Adam Langley95c29f32014-06-20 12:00:00 -07008299 statusChan <- statusMsg{test: test, err: err}
8300 }
8301}
8302
8303type statusMsg struct {
8304 test *testCase
8305 started bool
8306 err error
8307}
8308
David Benjamin5f237bc2015-02-11 17:14:15 -05008309func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008310 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008311
David Benjamin5f237bc2015-02-11 17:14:15 -05008312 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008313 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008314 if !*pipe {
8315 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008316 var erase string
8317 for i := 0; i < lineLen; i++ {
8318 erase += "\b \b"
8319 }
8320 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008321 }
8322
Adam Langley95c29f32014-06-20 12:00:00 -07008323 if msg.started {
8324 started++
8325 } else {
8326 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008327
8328 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008329 if msg.err == errUnimplemented {
8330 if *pipe {
8331 // Print each test instead of a status line.
8332 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8333 }
8334 unimplemented++
8335 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8336 } else {
8337 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8338 failed++
8339 testOutput.addResult(msg.test.name, "FAIL")
8340 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008341 } else {
8342 if *pipe {
8343 // Print each test instead of a status line.
8344 fmt.Printf("PASSED (%s)\n", msg.test.name)
8345 }
8346 testOutput.addResult(msg.test.name, "PASS")
8347 }
Adam Langley95c29f32014-06-20 12:00:00 -07008348 }
8349
David Benjamin5f237bc2015-02-11 17:14:15 -05008350 if !*pipe {
8351 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008352 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008353 lineLen = len(line)
8354 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008355 }
Adam Langley95c29f32014-06-20 12:00:00 -07008356 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008357
8358 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008359}
8360
8361func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008362 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008363 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008364 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008365
Adam Langley7c803a62015-06-15 15:35:05 -07008366 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008367 addCipherSuiteTests()
8368 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008369 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008370 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008371 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008372 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008373 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008374 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008375 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008376 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008377 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008378 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008379 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008380 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008381 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008382 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008383 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008384 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008385 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008386 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008387 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008388 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008389 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008390 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008391 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008392 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008393 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008394 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008395 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008396
8397 var wg sync.WaitGroup
8398
Adam Langley7c803a62015-06-15 15:35:05 -07008399 statusChan := make(chan statusMsg, *numWorkers)
8400 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008401 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008402
EKRf71d7ed2016-08-06 13:25:12 -07008403 if len(*shimConfigFile) != 0 {
8404 encoded, err := ioutil.ReadFile(*shimConfigFile)
8405 if err != nil {
8406 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8407 os.Exit(1)
8408 }
8409
8410 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8411 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8412 os.Exit(1)
8413 }
8414 }
8415
David Benjamin025b3d32014-07-01 19:53:04 -04008416 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008417
Adam Langley7c803a62015-06-15 15:35:05 -07008418 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008419 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008420 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008421 }
8422
David Benjamin270f0a72016-03-17 14:41:36 -04008423 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008424 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008425 matched := true
8426 if len(*testToRun) != 0 {
8427 var err error
8428 matched, err = filepath.Match(*testToRun, testCases[i].name)
8429 if err != nil {
8430 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8431 os.Exit(1)
8432 }
8433 }
8434
EKRf71d7ed2016-08-06 13:25:12 -07008435 if !*includeDisabled {
8436 for pattern := range shimConfig.DisabledTests {
8437 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8438 if err != nil {
8439 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8440 os.Exit(1)
8441 }
8442
8443 if isDisabled {
8444 matched = false
8445 break
8446 }
8447 }
8448 }
8449
David Benjamin17e12922016-07-28 18:04:43 -04008450 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008451 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008452 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008453 }
8454 }
David Benjamin17e12922016-07-28 18:04:43 -04008455
David Benjamin270f0a72016-03-17 14:41:36 -04008456 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008457 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008458 os.Exit(1)
8459 }
Adam Langley95c29f32014-06-20 12:00:00 -07008460
8461 close(testChan)
8462 wg.Wait()
8463 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008464 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008465
8466 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008467
8468 if *jsonOutput != "" {
8469 if err := testOutput.writeTo(*jsonOutput); err != nil {
8470 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8471 }
8472 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008473
EKR842ae6c2016-07-27 09:22:05 +02008474 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8475 os.Exit(1)
8476 }
8477
8478 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008479 os.Exit(1)
8480 }
Adam Langley95c29f32014-06-20 12:00:00 -07008481}