blob: ea29ef5030b9bb5c5975b2dbdec0d5db76aa2489 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
619 tlsConn.SendKeyUpdate()
620 }
621
David Benjamina8ebe222015-06-06 03:04:39 -0400622 for i := 0; i < test.sendEmptyRecords; i++ {
623 tlsConn.Write(nil)
624 }
625
David Benjamin24f346d2015-06-06 03:28:08 -0400626 for i := 0; i < test.sendWarningAlerts; i++ {
627 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
628 }
629
David Benjamin47921102016-07-28 11:29:18 -0400630 if test.sendHalfHelloRequest {
631 tlsConn.SendHalfHelloRequest()
632 }
633
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400634 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700635 if test.renegotiateCiphers != nil {
636 config.CipherSuites = test.renegotiateCiphers
637 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400638 for i := 0; i < test.renegotiate; i++ {
639 if err := tlsConn.Renegotiate(); err != nil {
640 return err
641 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 }
643 } else if test.renegotiateCiphers != nil {
644 panic("renegotiateCiphers without renegotiate")
645 }
646
David Benjamin5fa3eba2015-01-22 16:35:40 -0500647 if test.damageFirstWrite {
648 connDamage.setDamage(true)
649 tlsConn.Write([]byte("DAMAGED WRITE"))
650 connDamage.setDamage(false)
651 }
652
David Benjamin8e6db492015-07-25 18:29:23 -0400653 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700654 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400655 if test.protocol == dtls {
656 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
657 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700658 // Read until EOF.
659 _, err := io.Copy(ioutil.Discard, tlsConn)
660 return err
661 }
David Benjamin4417d052015-04-05 04:17:25 -0400662 if messageLen == 0 {
663 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700664 }
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin8e6db492015-07-25 18:29:23 -0400666 messageCount := test.messageCount
667 if messageCount == 0 {
668 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400669 }
670
David Benjamin8e6db492015-07-25 18:29:23 -0400671 for j := 0; j < messageCount; j++ {
672 testMessage := make([]byte, messageLen)
673 for i := range testMessage {
674 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400675 }
David Benjamin8e6db492015-07-25 18:29:23 -0400676 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700677
Steven Valdez32635b82016-08-16 11:25:03 -0400678 for i := 0; i < test.sendKeyUpdates; i++ {
679 tlsConn.SendKeyUpdate()
680 }
681
David Benjamin8e6db492015-07-25 18:29:23 -0400682 for i := 0; i < test.sendEmptyRecords; i++ {
683 tlsConn.Write(nil)
684 }
685
686 for i := 0; i < test.sendWarningAlerts; i++ {
687 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
688 }
689
David Benjamin4f75aaf2015-09-01 16:53:10 -0400690 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400691 // The shim will not respond.
692 continue
693 }
694
David Benjamin8e6db492015-07-25 18:29:23 -0400695 buf := make([]byte, len(testMessage))
696 if test.protocol == dtls {
697 bufTmp := make([]byte, len(buf)+1)
698 n, err := tlsConn.Read(bufTmp)
699 if err != nil {
700 return err
701 }
702 if n != len(buf) {
703 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
704 }
705 copy(buf, bufTmp)
706 } else {
707 _, err := io.ReadFull(tlsConn, buf)
708 if err != nil {
709 return err
710 }
711 }
712
713 for i, v := range buf {
714 if v != testMessage[i]^0xff {
715 return fmt.Errorf("bad reply contents at byte %d", i)
716 }
Adam Langley95c29f32014-06-20 12:00:00 -0700717 }
718 }
719
720 return nil
721}
722
David Benjamin325b5c32014-07-01 19:40:31 -0400723func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400724 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700725 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400726 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700727 }
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, path)
729 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700730
David Benjamin325b5c32014-07-01 19:40:31 -0400731 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732}
733
David Benjamin325b5c32014-07-01 19:40:31 -0400734func gdbOf(path string, args ...string) *exec.Cmd {
735 xtermArgs := []string{"-e", "gdb", "--args"}
736 xtermArgs = append(xtermArgs, path)
737 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700738
David Benjamin325b5c32014-07-01 19:40:31 -0400739 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740}
741
David Benjamind16bf342015-12-18 00:53:12 -0500742func lldbOf(path string, args ...string) *exec.Cmd {
743 xtermArgs := []string{"-e", "lldb", "--"}
744 xtermArgs = append(xtermArgs, path)
745 xtermArgs = append(xtermArgs, args...)
746
747 return exec.Command("xterm", xtermArgs...)
748}
749
EKR842ae6c2016-07-27 09:22:05 +0200750var (
751 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
752 errUnimplemented = errors.New("child process does not implement needed flags")
753)
Adam Langley69a01602014-11-17 17:26:55 -0800754
David Benjamin87c8a642015-02-21 01:54:29 -0500755// accept accepts a connection from listener, unless waitChan signals a process
756// exit first.
757func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
758 type connOrError struct {
759 conn net.Conn
760 err error
761 }
762 connChan := make(chan connOrError, 1)
763 go func() {
764 conn, err := listener.Accept()
765 connChan <- connOrError{conn, err}
766 close(connChan)
767 }()
768 select {
769 case result := <-connChan:
770 return result.conn, result.err
771 case childErr := <-waitChan:
772 waitChan <- childErr
773 return nil, fmt.Errorf("child exited early: %s", childErr)
774 }
775}
776
EKRf71d7ed2016-08-06 13:25:12 -0700777func translateExpectedError(errorStr string) string {
778 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
779 return translated
780 }
781
782 if *looseErrors {
783 return ""
784 }
785
786 return errorStr
787}
788
Adam Langley7c803a62015-06-15 15:35:05 -0700789func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700790 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
791 panic("Error expected without shouldFail in " + test.name)
792 }
793
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700794 if test.expectResumeRejected && !test.resumeSession {
795 panic("expectResumeRejected without resumeSession in " + test.name)
796 }
797
David Benjamin87c8a642015-02-21 01:54:29 -0500798 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
799 if err != nil {
800 panic(err)
801 }
802 defer func() {
803 if listener != nil {
804 listener.Close()
805 }
806 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400809 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400810 flags = append(flags, "-server")
811
David Benjamin025b3d32014-07-01 19:53:04 -0400812 flags = append(flags, "-key-file")
813 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700814 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400815 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700816 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400817 }
818
819 flags = append(flags, "-cert-file")
820 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825 }
David Benjamin5a593af2014-08-11 19:51:50 -0400826
David Benjamin6fd297b2014-08-11 18:43:38 -0400827 if test.protocol == dtls {
828 flags = append(flags, "-dtls")
829 }
830
David Benjamin46662482016-08-17 00:51:00 -0400831 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400832 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400833 resumeCount++
834 if test.resumeRenewedSession {
835 resumeCount++
836 }
837 }
838
839 if resumeCount > 0 {
840 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400841 }
842
David Benjamine58c4f52014-08-24 03:47:07 -0400843 if test.shimWritesFirst {
844 flags = append(flags, "-shim-writes-first")
845 }
846
David Benjamin30789da2015-08-29 22:56:45 -0400847 if test.shimShutsDown {
848 flags = append(flags, "-shim-shuts-down")
849 }
850
David Benjaminc565ebb2015-04-03 04:06:36 -0400851 if test.exportKeyingMaterial > 0 {
852 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
853 flags = append(flags, "-export-label", test.exportLabel)
854 flags = append(flags, "-export-context", test.exportContext)
855 if test.useExportContext {
856 flags = append(flags, "-use-export-context")
857 }
858 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700859 if test.expectResumeRejected {
860 flags = append(flags, "-expect-session-miss")
861 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400862
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700863 if test.testTLSUnique {
864 flags = append(flags, "-tls-unique")
865 }
866
David Benjamin025b3d32014-07-01 19:53:04 -0400867 flags = append(flags, test.flags...)
868
869 var shim *exec.Cmd
870 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700871 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700872 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500874 } else if *useLLDB {
875 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400876 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400878 }
David Benjamin025b3d32014-07-01 19:53:04 -0400879 shim.Stdin = os.Stdin
880 var stdoutBuf, stderrBuf bytes.Buffer
881 shim.Stdout = &stdoutBuf
882 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800883 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500884 shim.Env = os.Environ()
885 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800886 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400887 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800888 }
889 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
890 }
David Benjamin025b3d32014-07-01 19:53:04 -0400891
892 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700893 panic(err)
894 }
David Benjamin87c8a642015-02-21 01:54:29 -0500895 waitChan := make(chan error, 1)
896 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700897
898 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700899
David Benjamin7a4aaa42016-09-20 17:58:14 -0400900 if *deterministic {
901 config.Rand = &deterministicRand{}
902 }
903
David Benjamin87c8a642015-02-21 01:54:29 -0500904 conn, err := acceptOrWait(listener, waitChan)
905 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400906 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn.Close()
908 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500909
David Benjamin46662482016-08-17 00:51:00 -0400910 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400911 var resumeConfig Config
912 if test.resumeConfig != nil {
913 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400914 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500915 resumeConfig.SessionTicketKey = config.SessionTicketKey
916 resumeConfig.ClientSessionCache = config.ClientSessionCache
917 resumeConfig.ServerSessionCache = config.ServerSessionCache
918 }
David Benjamin2e045a92016-06-08 13:09:56 -0400919 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400920 } else {
921 resumeConfig = config
922 }
David Benjamin87c8a642015-02-21 01:54:29 -0500923 var connResume net.Conn
924 connResume, err = acceptOrWait(listener, waitChan)
925 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400926 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500927 connResume.Close()
928 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400929 }
930
David Benjamin87c8a642015-02-21 01:54:29 -0500931 // Close the listener now. This is to avoid hangs should the shim try to
932 // open more connections than expected.
933 listener.Close()
934 listener = nil
935
936 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400937 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800938 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200939 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
940 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800941 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200942 case 89:
943 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400944 case 99:
945 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjamin9aafb642016-09-20 19:36:53 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjamind2ba8892016-09-20 19:41:04 -0400994 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
David Benjamind2ba8892016-09-20 19:41:04 -0400998 if *useValgrind && isValgrindError {
999 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1000 }
1001
Adam Langley95c29f32014-06-20 12:00:00 -07001002 return nil
1003}
1004
1005var tlsVersions = []struct {
1006 name string
1007 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001008 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001009 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001010}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001011 {"SSL3", VersionSSL30, "-no-ssl3", false},
1012 {"TLS1", VersionTLS10, "-no-tls1", true},
1013 {"TLS11", VersionTLS11, "-no-tls11", false},
1014 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001015 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001016}
1017
1018var testCipherSuites = []struct {
1019 name string
1020 id uint16
1021}{
1022 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001023 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001024 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001025 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1030 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1033 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1036 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1038 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001041 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001042 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001044 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001045 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001046 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001049 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001050 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001051 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1052 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1053 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1054 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001055 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1056 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001057 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1058 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001060 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1061 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001062 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001063}
1064
David Benjamin8b8c0062014-11-23 02:47:52 -05001065func hasComponent(suiteName, component string) bool {
1066 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1067}
1068
David Benjaminf7768e42014-08-31 02:06:47 -04001069func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001070 return hasComponent(suiteName, "GCM") ||
1071 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001072 hasComponent(suiteName, "SHA384") ||
1073 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001074}
1075
Nick Harper1fd39d82016-06-14 18:14:35 -07001076func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001077 // Only AEADs.
1078 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1079 return false
1080 }
1081 // No old CHACHA20_POLY1305.
1082 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1083 return false
1084 }
1085 // Must have ECDHE.
1086 // TODO(davidben,svaldez): Add pure PSK support.
1087 if !hasComponent(suiteName, "ECDHE") {
1088 return false
1089 }
1090 // TODO(davidben,svaldez): Add PSK support.
1091 if hasComponent(suiteName, "PSK") {
1092 return false
1093 }
1094 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001095}
1096
David Benjamin8b8c0062014-11-23 02:47:52 -05001097func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001098 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001099}
1100
Adam Langleya7997f12015-05-14 17:38:50 -07001101func bigFromHex(hex string) *big.Int {
1102 ret, ok := new(big.Int).SetString(hex, 16)
1103 if !ok {
1104 panic("failed to parse hex number 0x" + hex)
1105 }
1106 return ret
1107}
1108
Adam Langley7c803a62015-06-15 15:35:05 -07001109func addBasicTests() {
1110 basicTests := []testCase{
1111 {
Adam Langley7c803a62015-06-15 15:35:05 -07001112 name: "NoFallbackSCSV",
1113 config: Config{
1114 Bugs: ProtocolBugs{
1115 FailIfNotFallbackSCSV: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedLocalError: "no fallback SCSV found",
1120 },
1121 {
1122 name: "SendFallbackSCSV",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 FailIfNotFallbackSCSV: true,
1126 },
1127 },
1128 flags: []string{"-fallback-scsv"},
1129 },
1130 {
1131 name: "ClientCertificateTypes",
1132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001133 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001134 ClientAuth: RequestClientCert,
1135 ClientCertificateTypes: []byte{
1136 CertTypeDSSSign,
1137 CertTypeRSASign,
1138 CertTypeECDSASign,
1139 },
1140 },
1141 flags: []string{
1142 "-expect-certificate-types",
1143 base64.StdEncoding.EncodeToString([]byte{
1144 CertTypeDSSSign,
1145 CertTypeRSASign,
1146 CertTypeECDSASign,
1147 }),
1148 },
1149 },
1150 {
Adam Langley7c803a62015-06-15 15:35:05 -07001151 name: "UnauthenticatedECDH",
1152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1155 Bugs: ProtocolBugs{
1156 UnauthenticatedECDH: true,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":UNEXPECTED_MESSAGE:",
1161 },
1162 {
1163 name: "SkipCertificateStatus",
1164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001165 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1167 Bugs: ProtocolBugs{
1168 SkipCertificateStatus: true,
1169 },
1170 },
1171 flags: []string{
1172 "-enable-ocsp-stapling",
1173 },
1174 },
1175 {
1176 name: "SkipServerKeyExchange",
1177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001178 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1180 Bugs: ProtocolBugs{
1181 SkipServerKeyExchange: true,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":UNEXPECTED_MESSAGE:",
1186 },
1187 {
Adam Langley7c803a62015-06-15 15:35:05 -07001188 testType: serverTest,
1189 name: "Alert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 SendSpuriousAlert: alertRecordOverflow,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1197 },
1198 {
1199 protocol: dtls,
1200 testType: serverTest,
1201 name: "Alert-DTLS",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 SendSpuriousAlert: alertRecordOverflow,
1205 },
1206 },
1207 shouldFail: true,
1208 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1209 },
1210 {
1211 testType: serverTest,
1212 name: "FragmentAlert",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 FragmentAlert: true,
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":BAD_ALERT:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "FragmentAlert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 FragmentAlert: true,
1229 SendSpuriousAlert: alertRecordOverflow,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":BAD_ALERT:",
1234 },
1235 {
1236 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001237 name: "DoubleAlert",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 DoubleAlert: true,
1241 SendSpuriousAlert: alertRecordOverflow,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedError: ":BAD_ALERT:",
1246 },
1247 {
1248 protocol: dtls,
1249 testType: serverTest,
1250 name: "DoubleAlert-DTLS",
1251 config: Config{
1252 Bugs: ProtocolBugs{
1253 DoubleAlert: true,
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":BAD_ALERT:",
1259 },
1260 {
Adam Langley7c803a62015-06-15 15:35:05 -07001261 name: "SkipNewSessionTicket",
1262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001263 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001264 Bugs: ProtocolBugs{
1265 SkipNewSessionTicket: true,
1266 },
1267 },
1268 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001269 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001270 },
1271 {
1272 testType: serverTest,
1273 name: "FallbackSCSV",
1274 config: Config{
1275 MaxVersion: VersionTLS11,
1276 Bugs: ProtocolBugs{
1277 SendFallbackSCSV: true,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":INAPPROPRIATE_FALLBACK:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "FallbackSCSV-VersionMatch",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 SendFallbackSCSV: true,
1289 },
1290 },
1291 },
1292 {
1293 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 name: "FallbackSCSV-VersionMatch-TLS12",
1295 config: Config{
1296 MaxVersion: VersionTLS12,
1297 Bugs: ProtocolBugs{
1298 SendFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1302 },
1303 {
1304 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001305 name: "FragmentedClientVersion",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxHandshakeRecordLength: 1,
1309 FragmentClientVersion: true,
1310 },
1311 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001312 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
Adam Langley7c803a62015-06-15 15:35:05 -07001315 testType: serverTest,
1316 name: "HttpGET",
1317 sendPrefix: "GET / HTTP/1.0\n",
1318 shouldFail: true,
1319 expectedError: ":HTTP_REQUEST:",
1320 },
1321 {
1322 testType: serverTest,
1323 name: "HttpPOST",
1324 sendPrefix: "POST / HTTP/1.0\n",
1325 shouldFail: true,
1326 expectedError: ":HTTP_REQUEST:",
1327 },
1328 {
1329 testType: serverTest,
1330 name: "HttpHEAD",
1331 sendPrefix: "HEAD / HTTP/1.0\n",
1332 shouldFail: true,
1333 expectedError: ":HTTP_REQUEST:",
1334 },
1335 {
1336 testType: serverTest,
1337 name: "HttpPUT",
1338 sendPrefix: "PUT / HTTP/1.0\n",
1339 shouldFail: true,
1340 expectedError: ":HTTP_REQUEST:",
1341 },
1342 {
1343 testType: serverTest,
1344 name: "HttpCONNECT",
1345 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1346 shouldFail: true,
1347 expectedError: ":HTTPS_PROXY_REQUEST:",
1348 },
1349 {
1350 testType: serverTest,
1351 name: "Garbage",
1352 sendPrefix: "blah",
1353 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001354 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001355 },
1356 {
Adam Langley7c803a62015-06-15 15:35:05 -07001357 name: "RSAEphemeralKey",
1358 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001359 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001360 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1361 Bugs: ProtocolBugs{
1362 RSAEphemeralKey: true,
1363 },
1364 },
1365 shouldFail: true,
1366 expectedError: ":UNEXPECTED_MESSAGE:",
1367 },
1368 {
1369 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001370 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 shouldFail: true,
1372 expectedError: ":WRONG_SSL_VERSION:",
1373 },
1374 {
1375 protocol: dtls,
1376 name: "DisableEverything-DTLS",
1377 flags: []string{"-no-tls12", "-no-tls1"},
1378 shouldFail: true,
1379 expectedError: ":WRONG_SSL_VERSION:",
1380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 protocol: dtls,
1383 testType: serverTest,
1384 name: "MTU",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 MaxPacketLength: 256,
1388 },
1389 },
1390 flags: []string{"-mtu", "256"},
1391 },
1392 {
1393 protocol: dtls,
1394 testType: serverTest,
1395 name: "MTUExceeded",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 MaxPacketLength: 255,
1399 },
1400 },
1401 flags: []string{"-mtu", "256"},
1402 shouldFail: true,
1403 expectedLocalError: "dtls: exceeded maximum packet length",
1404 },
1405 {
1406 name: "CertMismatchRSA",
1407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001419 name: "CertMismatchRSA-TLS13",
1420 config: Config{
1421 MaxVersion: VersionTLS13,
1422 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1423 Certificates: []Certificate{ecdsaP256Certificate},
1424 Bugs: ProtocolBugs{
1425 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1426 },
1427 },
1428 shouldFail: true,
1429 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1430 },
1431 {
Adam Langley7c803a62015-06-15 15:35:05 -07001432 name: "CertMismatchECDSA",
1433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001434 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001436 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1443 },
1444 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001445 name: "CertMismatchECDSA-TLS13",
1446 config: Config{
1447 MaxVersion: VersionTLS13,
1448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1449 Certificates: []Certificate{rsaCertificate},
1450 Bugs: ProtocolBugs{
1451 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "EmptyCertificateList",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1462 Bugs: ProtocolBugs{
1463 EmptyCertificateList: true,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":DECODE_ERROR:",
1468 },
1469 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 name: "EmptyCertificateList-TLS13",
1471 config: Config{
1472 MaxVersion: VersionTLS13,
1473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1474 Bugs: ProtocolBugs{
1475 EmptyCertificateList: true,
1476 },
1477 },
1478 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001479 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001480 },
1481 {
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "TLSFatalBadPackets",
1483 damageFirstWrite: true,
1484 shouldFail: true,
1485 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets",
1490 damageFirstWrite: true,
1491 },
1492 {
1493 protocol: dtls,
1494 name: "DTLSIgnoreBadPackets-Async",
1495 damageFirstWrite: true,
1496 flags: []string{"-async"},
1497 },
1498 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001499 name: "AppDataBeforeHandshake",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":UNEXPECTED_RECORD:",
1507 },
1508 {
1509 name: "AppDataBeforeHandshake-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 protocol: dtls,
1520 name: "AppDataBeforeHandshake-DTLS",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
1530 protocol: dtls,
1531 name: "AppDataBeforeHandshake-DTLS-Empty",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte{},
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "AppDataAfterChangeCipherSpec",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001552 name: "AppDataAfterChangeCipherSpec-Empty",
1553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001554 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 Bugs: ProtocolBugs{
1556 AppDataAfterChangeCipherSpec: []byte{},
1557 },
1558 },
1559 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001560 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001561 },
1562 {
Adam Langley7c803a62015-06-15 15:35:05 -07001563 protocol: dtls,
1564 name: "AppDataAfterChangeCipherSpec-DTLS",
1565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001566 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001567 Bugs: ProtocolBugs{
1568 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1569 },
1570 },
1571 // BoringSSL's DTLS implementation will drop the out-of-order
1572 // application data.
1573 },
1574 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 protocol: dtls,
1576 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001578 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 Bugs: ProtocolBugs{
1580 AppDataAfterChangeCipherSpec: []byte{},
1581 },
1582 },
1583 // BoringSSL's DTLS implementation will drop the out-of-order
1584 // application data.
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "AlertAfterChangeCipherSpec",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 AlertAfterChangeCipherSpec: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "AlertAfterChangeCipherSpec-DTLS",
1600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001601 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001602 Bugs: ProtocolBugs{
1603 AlertAfterChangeCipherSpec: alertRecordOverflow,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "ReorderHandshakeFragments-Small-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 ReorderHandshakeFragments: true,
1615 // Small enough that every handshake message is
1616 // fragmented.
1617 MaxHandshakeRecordLength: 2,
1618 },
1619 },
1620 },
1621 {
1622 protocol: dtls,
1623 name: "ReorderHandshakeFragments-Large-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 ReorderHandshakeFragments: true,
1627 // Large enough that no handshake message is
1628 // fragmented.
1629 MaxHandshakeRecordLength: 2048,
1630 },
1631 },
1632 },
1633 {
1634 protocol: dtls,
1635 name: "MixCompleteMessageWithFragments-DTLS",
1636 config: Config{
1637 Bugs: ProtocolBugs{
1638 ReorderHandshakeFragments: true,
1639 MixCompleteMessageWithFragments: true,
1640 MaxHandshakeRecordLength: 2,
1641 },
1642 },
1643 },
1644 {
1645 name: "SendInvalidRecordType",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendInvalidRecordType: true,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":UNEXPECTED_RECORD:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendInvalidRecordType-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendInvalidRecordType: true,
1660 },
1661 },
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 ExpectFalseStart: true,
1676 },
1677 },
1678 flags: []string{
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shimWritesFirst: true,
1684 shouldFail: true,
1685 expectedError: ":UNEXPECTED_RECORD:",
1686 },
1687 {
1688 name: "FalseStart-SkipServerSecondLeg-Implicit",
1689 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001690 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1692 NextProtos: []string{"foo"},
1693 Bugs: ProtocolBugs{
1694 SkipNewSessionTicket: true,
1695 SkipChangeCipherSpec: true,
1696 SkipFinished: true,
1697 },
1698 },
1699 flags: []string{
1700 "-implicit-handshake",
1701 "-false-start",
1702 "-handshake-never-done",
1703 "-advertise-alpn", "\x03foo",
1704 },
1705 shouldFail: true,
1706 expectedError: ":UNEXPECTED_RECORD:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "FailEarlyCallback",
1711 flags: []string{"-fail-early-callback"},
1712 shouldFail: true,
1713 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001714 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001715 },
1716 {
Adam Langley7c803a62015-06-15 15:35:05 -07001717 protocol: dtls,
1718 name: "FragmentMessageTypeMismatch-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 MaxHandshakeRecordLength: 2,
1722 FragmentMessageTypeMismatch: true,
1723 },
1724 },
1725 shouldFail: true,
1726 expectedError: ":FRAGMENT_MISMATCH:",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "FragmentMessageLengthMismatch-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxHandshakeRecordLength: 2,
1734 FragmentMessageLengthMismatch: true,
1735 },
1736 },
1737 shouldFail: true,
1738 expectedError: ":FRAGMENT_MISMATCH:",
1739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Header-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: 2,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SplitFragments-Boundary-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SplitFragments: dtlsRecordHeaderLen,
1757 },
1758 },
1759 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001760 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 protocol: dtls,
1764 name: "SplitFragments-Body-DTLS",
1765 config: Config{
1766 Bugs: ProtocolBugs{
1767 SplitFragments: dtlsRecordHeaderLen + 1,
1768 },
1769 },
1770 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001771 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001772 },
1773 {
1774 protocol: dtls,
1775 name: "SendEmptyFragments-DTLS",
1776 config: Config{
1777 Bugs: ProtocolBugs{
1778 SendEmptyFragments: true,
1779 },
1780 },
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 name: "BadFinished-Client",
1784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001794 name: "BadFinished-Client-TLS13",
1795 config: Config{
1796 MaxVersion: VersionTLS13,
1797 Bugs: ProtocolBugs{
1798 BadFinished: true,
1799 },
1800 },
1801 shouldFail: true,
1802 expectedError: ":DIGEST_CHECK_FAILED:",
1803 },
1804 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001805 testType: serverTest,
1806 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 Bugs: ProtocolBugs{
1810 BadFinished: true,
1811 },
1812 },
1813 shouldFail: true,
1814 expectedError: ":DIGEST_CHECK_FAILED:",
1815 },
1816 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001817 testType: serverTest,
1818 name: "BadFinished-Server-TLS13",
1819 config: Config{
1820 MaxVersion: VersionTLS13,
1821 Bugs: ProtocolBugs{
1822 BadFinished: true,
1823 },
1824 },
1825 shouldFail: true,
1826 expectedError: ":DIGEST_CHECK_FAILED:",
1827 },
1828 {
Adam Langley7c803a62015-06-15 15:35:05 -07001829 name: "FalseStart-BadFinished",
1830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001831 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1833 NextProtos: []string{"foo"},
1834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 ExpectFalseStart: true,
1837 },
1838 },
1839 flags: []string{
1840 "-false-start",
1841 "-handshake-never-done",
1842 "-advertise-alpn", "\x03foo",
1843 },
1844 shimWritesFirst: true,
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 name: "NoFalseStart-NoALPN",
1850 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001851 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1853 Bugs: ProtocolBugs{
1854 ExpectFalseStart: true,
1855 AlertBeforeFalseStartTest: alertAccessDenied,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 },
1861 shimWritesFirst: true,
1862 shouldFail: true,
1863 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1864 expectedLocalError: "tls: peer did not false start: EOF",
1865 },
1866 {
1867 name: "NoFalseStart-NoAEAD",
1868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001869 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1871 NextProtos: []string{"foo"},
1872 Bugs: ProtocolBugs{
1873 ExpectFalseStart: true,
1874 AlertBeforeFalseStartTest: alertAccessDenied,
1875 },
1876 },
1877 flags: []string{
1878 "-false-start",
1879 "-advertise-alpn", "\x03foo",
1880 },
1881 shimWritesFirst: true,
1882 shouldFail: true,
1883 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1884 expectedLocalError: "tls: peer did not false start: EOF",
1885 },
1886 {
1887 name: "NoFalseStart-RSA",
1888 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001889 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001890 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1891 NextProtos: []string{"foo"},
1892 Bugs: ProtocolBugs{
1893 ExpectFalseStart: true,
1894 AlertBeforeFalseStartTest: alertAccessDenied,
1895 },
1896 },
1897 flags: []string{
1898 "-false-start",
1899 "-advertise-alpn", "\x03foo",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-DHE_RSA",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
Adam Langley7c803a62015-06-15 15:35:05 -07001927 protocol: dtls,
1928 name: "SendSplitAlert-Sync",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 SendSplitAlert: true,
1932 },
1933 },
1934 },
1935 {
1936 protocol: dtls,
1937 name: "SendSplitAlert-Async",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendSplitAlert: true,
1941 },
1942 },
1943 flags: []string{"-async"},
1944 },
1945 {
1946 protocol: dtls,
1947 name: "PackDTLSHandshake",
1948 config: Config{
1949 Bugs: ProtocolBugs{
1950 MaxHandshakeRecordLength: 2,
1951 PackHandshakeFragments: 20,
1952 PackHandshakeRecords: 200,
1953 },
1954 },
1955 },
1956 {
Adam Langley7c803a62015-06-15 15:35:05 -07001957 name: "SendEmptyRecords-Pass",
1958 sendEmptyRecords: 32,
1959 },
1960 {
1961 name: "SendEmptyRecords",
1962 sendEmptyRecords: 33,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1965 },
1966 {
1967 name: "SendEmptyRecords-Async",
1968 sendEmptyRecords: 33,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Pass",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 4,
1979 },
1980 {
David Benjamine8e84b92016-08-03 15:39:47 -04001981 protocol: dtls,
1982 name: "SendWarningAlerts-DTLS-Pass",
1983 config: Config{
1984 MaxVersion: VersionTLS12,
1985 },
Adam Langley7c803a62015-06-15 15:35:05 -07001986 sendWarningAlerts: 4,
1987 },
1988 {
David Benjamine8e84b92016-08-03 15:39:47 -04001989 name: "SendWarningAlerts-TLS13",
1990 config: Config{
1991 MaxVersion: VersionTLS13,
1992 },
1993 sendWarningAlerts: 4,
1994 shouldFail: true,
1995 expectedError: ":BAD_ALERT:",
1996 expectedLocalError: "remote error: error decoding message",
1997 },
1998 {
1999 name: "SendWarningAlerts",
2000 config: Config{
2001 MaxVersion: VersionTLS12,
2002 },
Adam Langley7c803a62015-06-15 15:35:05 -07002003 sendWarningAlerts: 5,
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2006 },
2007 {
David Benjamine8e84b92016-08-03 15:39:47 -04002008 name: "SendWarningAlerts-Async",
2009 config: Config{
2010 MaxVersion: VersionTLS12,
2011 },
Adam Langley7c803a62015-06-15 15:35:05 -07002012 sendWarningAlerts: 5,
2013 flags: []string{"-async"},
2014 shouldFail: true,
2015 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2016 },
David Benjaminba4594a2015-06-18 18:36:15 -04002017 {
Steven Valdez32635b82016-08-16 11:25:03 -04002018 name: "SendKeyUpdates",
2019 config: Config{
2020 MaxVersion: VersionTLS13,
2021 },
2022 sendKeyUpdates: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_KEY_UPDATES:",
2025 },
2026 {
David Benjaminba4594a2015-06-18 18:36:15 -04002027 name: "EmptySessionID",
2028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002029 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002030 SessionTicketsDisabled: true,
2031 },
2032 noSessionCache: true,
2033 flags: []string{"-expect-no-session"},
2034 },
David Benjamin30789da2015-08-29 22:56:45 -04002035 {
2036 name: "Unclean-Shutdown",
2037 config: Config{
2038 Bugs: ProtocolBugs{
2039 NoCloseNotify: true,
2040 ExpectCloseNotify: true,
2041 },
2042 },
2043 shimShutsDown: true,
2044 flags: []string{"-check-close-notify"},
2045 shouldFail: true,
2046 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2047 },
2048 {
2049 name: "Unclean-Shutdown-Ignored",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 NoCloseNotify: true,
2053 },
2054 },
2055 shimShutsDown: true,
2056 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002057 {
David Benjaminfa214e42016-05-10 17:03:10 -04002058 name: "Unclean-Shutdown-Alert",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 SendAlertOnShutdown: alertDecompressionFailure,
2062 ExpectCloseNotify: true,
2063 },
2064 },
2065 shimShutsDown: true,
2066 flags: []string{"-check-close-notify"},
2067 shouldFail: true,
2068 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2069 },
2070 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002071 name: "LargePlaintext",
2072 config: Config{
2073 Bugs: ProtocolBugs{
2074 SendLargeRecords: true,
2075 },
2076 },
2077 messageLen: maxPlaintext + 1,
2078 shouldFail: true,
2079 expectedError: ":DATA_LENGTH_TOO_LONG:",
2080 },
2081 {
2082 protocol: dtls,
2083 name: "LargePlaintext-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SendLargeRecords: true,
2087 },
2088 },
2089 messageLen: maxPlaintext + 1,
2090 shouldFail: true,
2091 expectedError: ":DATA_LENGTH_TOO_LONG:",
2092 },
2093 {
2094 name: "LargeCiphertext",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendLargeRecords: true,
2098 },
2099 },
2100 messageLen: maxPlaintext * 2,
2101 shouldFail: true,
2102 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2103 },
2104 {
2105 protocol: dtls,
2106 name: "LargeCiphertext-DTLS",
2107 config: Config{
2108 Bugs: ProtocolBugs{
2109 SendLargeRecords: true,
2110 },
2111 },
2112 messageLen: maxPlaintext * 2,
2113 // Unlike the other four cases, DTLS drops records which
2114 // are invalid before authentication, so the connection
2115 // does not fail.
2116 expectMessageDropped: true,
2117 },
David Benjamindd6fed92015-10-23 17:41:12 -04002118 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 // In TLS 1.2 and below, empty NewSessionTicket messages
2120 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002121 name: "SendEmptySessionTicket",
2122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002124 Bugs: ProtocolBugs{
2125 SendEmptySessionTicket: true,
2126 FailIfSessionOffered: true,
2127 },
2128 },
David Benjamin46662482016-08-17 00:51:00 -04002129 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002130 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002131 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 name: "BadHelloRequest-1",
2133 renegotiate: 1,
2134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002135 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002136 Bugs: ProtocolBugs{
2137 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2138 },
2139 },
2140 flags: []string{
2141 "-renegotiate-freely",
2142 "-expect-total-renegotiations", "1",
2143 },
2144 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002145 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002146 },
2147 {
2148 name: "BadHelloRequest-2",
2149 renegotiate: 1,
2150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002151 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002152 Bugs: ProtocolBugs{
2153 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2154 },
2155 },
2156 flags: []string{
2157 "-renegotiate-freely",
2158 "-expect-total-renegotiations", "1",
2159 },
2160 shouldFail: true,
2161 expectedError: ":BAD_HELLO_REQUEST:",
2162 },
David Benjaminef1b0092015-11-21 14:05:44 -05002163 {
2164 testType: serverTest,
2165 name: "SupportTicketsWithSessionID",
2166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002167 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002168 SessionTicketsDisabled: true,
2169 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 resumeConfig: &Config{
2171 MaxVersion: VersionTLS12,
2172 },
David Benjaminef1b0092015-11-21 14:05:44 -05002173 resumeSession: true,
2174 },
David Benjamin02edcd02016-07-27 17:40:37 -04002175 {
2176 protocol: dtls,
2177 name: "DTLS-SendExtraFinished",
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 SendExtraFinished: true,
2181 },
2182 },
2183 shouldFail: true,
2184 expectedError: ":UNEXPECTED_RECORD:",
2185 },
2186 {
2187 protocol: dtls,
2188 name: "DTLS-SendExtraFinished-Reordered",
2189 config: Config{
2190 Bugs: ProtocolBugs{
2191 MaxHandshakeRecordLength: 2,
2192 ReorderHandshakeFragments: true,
2193 SendExtraFinished: true,
2194 },
2195 },
2196 shouldFail: true,
2197 expectedError: ":UNEXPECTED_RECORD:",
2198 },
David Benjamine97fb482016-07-29 09:23:07 -04002199 {
2200 testType: serverTest,
2201 name: "V2ClientHello-EmptyRecordPrefix",
2202 config: Config{
2203 // Choose a cipher suite that does not involve
2204 // elliptic curves, so no extensions are
2205 // involved.
2206 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002207 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002208 Bugs: ProtocolBugs{
2209 SendV2ClientHello: true,
2210 },
2211 },
2212 sendPrefix: string([]byte{
2213 byte(recordTypeHandshake),
2214 3, 1, // version
2215 0, 0, // length
2216 }),
2217 // A no-op empty record may not be sent before V2ClientHello.
2218 shouldFail: true,
2219 expectedError: ":WRONG_VERSION_NUMBER:",
2220 },
2221 {
2222 testType: serverTest,
2223 name: "V2ClientHello-WarningAlertPrefix",
2224 config: Config{
2225 // Choose a cipher suite that does not involve
2226 // elliptic curves, so no extensions are
2227 // involved.
2228 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002229 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002230 Bugs: ProtocolBugs{
2231 SendV2ClientHello: true,
2232 },
2233 },
2234 sendPrefix: string([]byte{
2235 byte(recordTypeAlert),
2236 3, 1, // version
2237 0, 2, // length
2238 alertLevelWarning, byte(alertDecompressionFailure),
2239 }),
2240 // A no-op warning alert may not be sent before V2ClientHello.
2241 shouldFail: true,
2242 expectedError: ":WRONG_VERSION_NUMBER:",
2243 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002244 {
2245 testType: clientTest,
2246 name: "KeyUpdate",
2247 config: Config{
2248 MaxVersion: VersionTLS13,
2249 Bugs: ProtocolBugs{
2250 SendKeyUpdateBeforeEveryAppDataRecord: true,
2251 },
2252 },
2253 },
David Benjaminabe94e32016-09-04 14:18:58 -04002254 {
2255 name: "SendSNIWarningAlert",
2256 config: Config{
2257 MaxVersion: VersionTLS12,
2258 Bugs: ProtocolBugs{
2259 SendSNIWarningAlert: true,
2260 },
2261 },
2262 },
David Benjaminc241d792016-09-09 10:34:20 -04002263 {
2264 testType: serverTest,
2265 name: "ExtraCompressionMethods-TLS12",
2266 config: Config{
2267 MaxVersion: VersionTLS12,
2268 Bugs: ProtocolBugs{
2269 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2270 },
2271 },
2272 },
2273 {
2274 testType: serverTest,
2275 name: "ExtraCompressionMethods-TLS13",
2276 config: Config{
2277 MaxVersion: VersionTLS13,
2278 Bugs: ProtocolBugs{
2279 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2280 },
2281 },
2282 shouldFail: true,
2283 expectedError: ":INVALID_COMPRESSION_LIST:",
2284 expectedLocalError: "remote error: illegal parameter",
2285 },
2286 {
2287 testType: serverTest,
2288 name: "NoNullCompression-TLS12",
2289 config: Config{
2290 MaxVersion: VersionTLS12,
2291 Bugs: ProtocolBugs{
2292 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2293 },
2294 },
2295 shouldFail: true,
2296 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2297 expectedLocalError: "remote error: illegal parameter",
2298 },
2299 {
2300 testType: serverTest,
2301 name: "NoNullCompression-TLS13",
2302 config: Config{
2303 MaxVersion: VersionTLS13,
2304 Bugs: ProtocolBugs{
2305 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2306 },
2307 },
2308 shouldFail: true,
2309 expectedError: ":INVALID_COMPRESSION_LIST:",
2310 expectedLocalError: "remote error: illegal parameter",
2311 },
David Benjamin65ac9972016-09-02 21:35:25 -04002312 {
2313 name: "GREASE-TLS12",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 ExpectGREASE: true,
2318 },
2319 },
2320 flags: []string{"-enable-grease"},
2321 },
2322 {
2323 name: "GREASE-TLS13",
2324 config: Config{
2325 MaxVersion: VersionTLS13,
2326 Bugs: ProtocolBugs{
2327 ExpectGREASE: true,
2328 },
2329 },
2330 flags: []string{"-enable-grease"},
2331 },
Adam Langley7c803a62015-06-15 15:35:05 -07002332 }
Adam Langley7c803a62015-06-15 15:35:05 -07002333 testCases = append(testCases, basicTests...)
2334}
2335
Adam Langley95c29f32014-06-20 12:00:00 -07002336func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002337 const bogusCipher = 0xfe00
2338
Adam Langley95c29f32014-06-20 12:00:00 -07002339 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002340 const psk = "12345"
2341 const pskIdentity = "luggage combo"
2342
Adam Langley95c29f32014-06-20 12:00:00 -07002343 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002344 var certFile string
2345 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002346 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002347 cert = ecdsaP256Certificate
2348 certFile = ecdsaP256CertificateFile
2349 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002350 } else {
David Benjamin33863262016-07-08 17:20:12 -07002351 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002352 certFile = rsaCertificateFile
2353 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002354 }
2355
David Benjamin48cae082014-10-27 01:06:24 -04002356 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002357 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002358 flags = append(flags,
2359 "-psk", psk,
2360 "-psk-identity", pskIdentity)
2361 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002362 if hasComponent(suite.name, "NULL") {
2363 // NULL ciphers must be explicitly enabled.
2364 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2365 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002366 if hasComponent(suite.name, "CECPQ1") {
2367 // CECPQ1 ciphers must be explicitly enabled.
2368 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2369 }
David Benjamin881f1962016-08-10 18:29:12 -04002370 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2371 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2372 // for now.
2373 flags = append(flags, "-cipher", suite.name)
2374 }
David Benjamin48cae082014-10-27 01:06:24 -04002375
Adam Langley95c29f32014-06-20 12:00:00 -07002376 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002377 for _, protocol := range []protocol{tls, dtls} {
2378 var prefix string
2379 if protocol == dtls {
2380 if !ver.hasDTLS {
2381 continue
2382 }
2383 prefix = "D"
2384 }
Adam Langley95c29f32014-06-20 12:00:00 -07002385
David Benjamin0407e762016-06-17 16:41:18 -04002386 var shouldServerFail, shouldClientFail bool
2387 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2388 // BoringSSL clients accept ECDHE on SSLv3, but
2389 // a BoringSSL server will never select it
2390 // because the extension is missing.
2391 shouldServerFail = true
2392 }
2393 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2394 shouldClientFail = true
2395 shouldServerFail = true
2396 }
David Benjamin54c217c2016-07-13 12:35:25 -04002397 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002398 shouldClientFail = true
2399 shouldServerFail = true
2400 }
David Benjamin0407e762016-06-17 16:41:18 -04002401 if !isDTLSCipher(suite.name) && protocol == dtls {
2402 shouldClientFail = true
2403 shouldServerFail = true
2404 }
David Benjamin4298d772015-12-19 00:18:25 -05002405
David Benjamin0407e762016-06-17 16:41:18 -04002406 var expectedServerError, expectedClientError string
2407 if shouldServerFail {
2408 expectedServerError = ":NO_SHARED_CIPHER:"
2409 }
2410 if shouldClientFail {
2411 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2412 }
David Benjamin025b3d32014-07-01 19:53:04 -04002413
David Benjamin6fd297b2014-08-11 18:43:38 -04002414 testCases = append(testCases, testCase{
2415 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002416 protocol: protocol,
2417
2418 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002419 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002420 MinVersion: ver.version,
2421 MaxVersion: ver.version,
2422 CipherSuites: []uint16{suite.id},
2423 Certificates: []Certificate{cert},
2424 PreSharedKey: []byte(psk),
2425 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002426 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002427 EnableAllCiphers: shouldServerFail,
2428 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002429 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002430 },
2431 certFile: certFile,
2432 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002433 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002434 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002435 shouldFail: shouldServerFail,
2436 expectedError: expectedServerError,
2437 })
2438
2439 testCases = append(testCases, testCase{
2440 testType: clientTest,
2441 protocol: protocol,
2442 name: prefix + ver.name + "-" + suite.name + "-client",
2443 config: Config{
2444 MinVersion: ver.version,
2445 MaxVersion: ver.version,
2446 CipherSuites: []uint16{suite.id},
2447 Certificates: []Certificate{cert},
2448 PreSharedKey: []byte(psk),
2449 PreSharedKeyIdentity: pskIdentity,
2450 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002451 EnableAllCiphers: shouldClientFail,
2452 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002453 },
2454 },
2455 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002456 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002457 shouldFail: shouldClientFail,
2458 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002459 })
David Benjamin2c99d282015-09-01 10:23:00 -04002460
Nick Harper1fd39d82016-06-14 18:14:35 -07002461 if !shouldClientFail {
2462 // Ensure the maximum record size is accepted.
2463 testCases = append(testCases, testCase{
2464 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2465 config: Config{
2466 MinVersion: ver.version,
2467 MaxVersion: ver.version,
2468 CipherSuites: []uint16{suite.id},
2469 Certificates: []Certificate{cert},
2470 PreSharedKey: []byte(psk),
2471 PreSharedKeyIdentity: pskIdentity,
2472 },
2473 flags: flags,
2474 messageLen: maxPlaintext,
2475 })
2476 }
2477 }
David Benjamin2c99d282015-09-01 10:23:00 -04002478 }
Adam Langley95c29f32014-06-20 12:00:00 -07002479 }
Adam Langleya7997f12015-05-14 17:38:50 -07002480
2481 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 name: "NoSharedCipher",
2483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002484 MaxVersion: VersionTLS12,
2485 CipherSuites: []uint16{},
2486 },
2487 shouldFail: true,
2488 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2489 })
2490
2491 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002492 name: "NoSharedCipher-TLS13",
2493 config: Config{
2494 MaxVersion: VersionTLS13,
2495 CipherSuites: []uint16{},
2496 },
2497 shouldFail: true,
2498 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2499 })
2500
2501 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002502 name: "UnsupportedCipherSuite",
2503 config: Config{
2504 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002505 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002506 Bugs: ProtocolBugs{
2507 IgnorePeerCipherPreferences: true,
2508 },
2509 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002510 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002511 shouldFail: true,
2512 expectedError: ":WRONG_CIPHER_RETURNED:",
2513 })
2514
2515 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002516 name: "ServerHelloBogusCipher",
2517 config: Config{
2518 MaxVersion: VersionTLS12,
2519 Bugs: ProtocolBugs{
2520 SendCipherSuite: bogusCipher,
2521 },
2522 },
2523 shouldFail: true,
2524 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2525 })
2526 testCases = append(testCases, testCase{
2527 name: "ServerHelloBogusCipher-TLS13",
2528 config: Config{
2529 MaxVersion: VersionTLS13,
2530 Bugs: ProtocolBugs{
2531 SendCipherSuite: bogusCipher,
2532 },
2533 },
2534 shouldFail: true,
2535 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2536 })
2537
2538 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002539 name: "WeakDH",
2540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002541 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002542 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2543 Bugs: ProtocolBugs{
2544 // This is a 1023-bit prime number, generated
2545 // with:
2546 // openssl gendh 1023 | openssl asn1parse -i
2547 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2548 },
2549 },
2550 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002551 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002552 })
Adam Langleycef75832015-09-03 14:51:12 -07002553
David Benjamincd24a392015-11-11 13:23:05 -08002554 testCases = append(testCases, testCase{
2555 name: "SillyDH",
2556 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002557 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002558 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2559 Bugs: ProtocolBugs{
2560 // This is a 4097-bit prime number, generated
2561 // with:
2562 // openssl gendh 4097 | openssl asn1parse -i
2563 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2564 },
2565 },
2566 shouldFail: true,
2567 expectedError: ":DH_P_TOO_LONG:",
2568 })
2569
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002570 // This test ensures that Diffie-Hellman public values are padded with
2571 // zeros so that they're the same length as the prime. This is to avoid
2572 // hitting a bug in yaSSL.
2573 testCases = append(testCases, testCase{
2574 testType: serverTest,
2575 name: "DHPublicValuePadded",
2576 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002577 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002578 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2579 Bugs: ProtocolBugs{
2580 RequireDHPublicValueLen: (1025 + 7) / 8,
2581 },
2582 },
2583 flags: []string{"-use-sparse-dh-prime"},
2584 })
David Benjamincd24a392015-11-11 13:23:05 -08002585
David Benjamin241ae832016-01-15 03:04:54 -05002586 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002587 testCases = append(testCases, testCase{
2588 testType: serverTest,
2589 name: "UnknownCipher",
2590 config: Config{
2591 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2592 },
2593 })
2594
David Benjamin78679342016-09-16 19:42:05 -04002595 // Test empty ECDHE_PSK identity hints work as expected.
2596 testCases = append(testCases, testCase{
2597 name: "EmptyECDHEPSKHint",
2598 config: Config{
2599 MaxVersion: VersionTLS12,
2600 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2601 PreSharedKey: []byte("secret"),
2602 },
2603 flags: []string{"-psk", "secret"},
2604 })
2605
2606 // Test empty PSK identity hints work as expected, even if an explicit
2607 // ServerKeyExchange is sent.
2608 testCases = append(testCases, testCase{
2609 name: "ExplicitEmptyPSKHint",
2610 config: Config{
2611 MaxVersion: VersionTLS12,
2612 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2613 PreSharedKey: []byte("secret"),
2614 Bugs: ProtocolBugs{
2615 AlwaysSendPreSharedKeyIdentityHint: true,
2616 },
2617 },
2618 flags: []string{"-psk", "secret"},
2619 })
2620
Adam Langleycef75832015-09-03 14:51:12 -07002621 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2622 // 1.1 specific cipher suite settings. A server is setup with the given
2623 // cipher lists and then a connection is made for each member of
2624 // expectations. The cipher suite that the server selects must match
2625 // the specified one.
2626 var versionSpecificCiphersTest = []struct {
2627 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2628 // expectations is a map from TLS version to cipher suite id.
2629 expectations map[uint16]uint16
2630 }{
2631 {
2632 // Test that the null case (where no version-specific ciphers are set)
2633 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2635 "", // no ciphers specifically for TLS ≥ 1.0
2636 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002637 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002638 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2639 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2640 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2641 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002642 },
2643 },
2644 {
2645 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2646 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 "DES-CBC3-SHA:AES128-SHA", // default
2648 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2649 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002650 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002651 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002652 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2653 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2654 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2655 },
2656 },
2657 {
2658 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2659 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 "DES-CBC3-SHA:AES128-SHA", // default
2661 "", // no ciphers specifically for TLS ≥ 1.0
2662 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002663 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2665 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002666 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2667 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2668 },
2669 },
2670 {
2671 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2672 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002673 "DES-CBC3-SHA:AES128-SHA", // default
2674 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2675 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002676 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002678 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2679 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2680 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2681 },
2682 },
2683 }
2684
2685 for i, test := range versionSpecificCiphersTest {
2686 for version, expectedCipherSuite := range test.expectations {
2687 flags := []string{"-cipher", test.ciphersDefault}
2688 if len(test.ciphersTLS10) > 0 {
2689 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2690 }
2691 if len(test.ciphersTLS11) > 0 {
2692 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2693 }
2694
2695 testCases = append(testCases, testCase{
2696 testType: serverTest,
2697 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2698 config: Config{
2699 MaxVersion: version,
2700 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002701 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002702 },
2703 flags: flags,
2704 expectedCipher: expectedCipherSuite,
2705 })
2706 }
2707 }
Adam Langley95c29f32014-06-20 12:00:00 -07002708}
2709
2710func addBadECDSASignatureTests() {
2711 for badR := BadValue(1); badR < NumBadValues; badR++ {
2712 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002713 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002714 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2715 config: Config{
2716 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002717 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002718 Bugs: ProtocolBugs{
2719 BadECDSAR: badR,
2720 BadECDSAS: badS,
2721 },
2722 },
2723 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002724 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002725 })
2726 }
2727 }
2728}
2729
Adam Langley80842bd2014-06-20 12:00:00 -07002730func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002731 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002732 name: "MaxCBCPadding",
2733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002734 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2736 Bugs: ProtocolBugs{
2737 MaxPadding: true,
2738 },
2739 },
2740 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2741 })
David Benjamin025b3d32014-07-01 19:53:04 -04002742 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002743 name: "BadCBCPadding",
2744 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002745 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2747 Bugs: ProtocolBugs{
2748 PaddingFirstByteBad: true,
2749 },
2750 },
2751 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002752 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002753 })
2754 // OpenSSL previously had an issue where the first byte of padding in
2755 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002756 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002757 name: "BadCBCPadding255",
2758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002759 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2761 Bugs: ProtocolBugs{
2762 MaxPadding: true,
2763 PaddingFirstByteBadIf255: true,
2764 },
2765 },
2766 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2767 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002768 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002769 })
2770}
2771
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772func addCBCSplittingTests() {
2773 testCases = append(testCases, testCase{
2774 name: "CBCRecordSplitting",
2775 config: Config{
2776 MaxVersion: VersionTLS10,
2777 MinVersion: VersionTLS10,
2778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2779 },
David Benjaminac8302a2015-09-01 17:18:15 -04002780 messageLen: -1, // read until EOF
2781 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002782 flags: []string{
2783 "-async",
2784 "-write-different-record-sizes",
2785 "-cbc-record-splitting",
2786 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002787 })
2788 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002789 name: "CBCRecordSplittingPartialWrite",
2790 config: Config{
2791 MaxVersion: VersionTLS10,
2792 MinVersion: VersionTLS10,
2793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2794 },
2795 messageLen: -1, // read until EOF
2796 flags: []string{
2797 "-async",
2798 "-write-different-record-sizes",
2799 "-cbc-record-splitting",
2800 "-partial-write",
2801 },
2802 })
2803}
2804
David Benjamin636293b2014-07-08 17:59:18 -04002805func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002806 // Add a dummy cert pool to stress certificate authority parsing.
2807 // TODO(davidben): Add tests that those values parse out correctly.
2808 certPool := x509.NewCertPool()
2809 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2810 if err != nil {
2811 panic(err)
2812 }
2813 certPool.AddCert(cert)
2814
David Benjamin636293b2014-07-08 17:59:18 -04002815 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002816 testCases = append(testCases, testCase{
2817 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002818 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002819 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002820 MinVersion: ver.version,
2821 MaxVersion: ver.version,
2822 ClientAuth: RequireAnyClientCert,
2823 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002824 },
2825 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002828 },
2829 })
2830 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002831 testType: serverTest,
2832 name: ver.name + "-Server-ClientAuth-RSA",
2833 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002834 MinVersion: ver.version,
2835 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002836 Certificates: []Certificate{rsaCertificate},
2837 },
2838 flags: []string{"-require-any-client-certificate"},
2839 })
David Benjamine098ec22014-08-27 23:13:20 -04002840 if ver.version != VersionSSL30 {
2841 testCases = append(testCases, testCase{
2842 testType: serverTest,
2843 name: ver.name + "-Server-ClientAuth-ECDSA",
2844 config: Config{
2845 MinVersion: ver.version,
2846 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002847 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002848 },
2849 flags: []string{"-require-any-client-certificate"},
2850 })
2851 testCases = append(testCases, testCase{
2852 testType: clientTest,
2853 name: ver.name + "-Client-ClientAuth-ECDSA",
2854 config: Config{
2855 MinVersion: ver.version,
2856 MaxVersion: ver.version,
2857 ClientAuth: RequireAnyClientCert,
2858 ClientCAs: certPool,
2859 },
2860 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002861 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2862 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002863 },
2864 })
2865 }
Adam Langley37646832016-08-01 16:16:46 -07002866
2867 testCases = append(testCases, testCase{
2868 name: "NoClientCertificate-" + ver.name,
2869 config: Config{
2870 MinVersion: ver.version,
2871 MaxVersion: ver.version,
2872 ClientAuth: RequireAnyClientCert,
2873 },
2874 shouldFail: true,
2875 expectedLocalError: "client didn't provide a certificate",
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // Even if not configured to expect a certificate, OpenSSL will
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificateRequested-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 },
2890 // TODO(davidben): Switch this to true when TLS 1.3
2891 // supports session resumption.
2892 resumeSession: ver.version < VersionTLS13,
2893 })
2894
2895 testCases = append(testCases, testCase{
2896 // If a client certificate is not provided, OpenSSL will still
2897 // return X509_V_OK as the verify_result.
2898 testType: serverTest,
2899 name: "NoClientCertificate-Server-" + ver.name,
2900 config: Config{
2901 MinVersion: ver.version,
2902 MaxVersion: ver.version,
2903 },
2904 flags: []string{
2905 "-expect-verify-result",
2906 "-verify-peer",
2907 },
2908 // TODO(davidben): Switch this to true when TLS 1.3
2909 // supports session resumption.
2910 resumeSession: ver.version < VersionTLS13,
2911 })
2912
2913 testCases = append(testCases, testCase{
2914 testType: serverTest,
2915 name: "RequireAnyClientCertificate-" + ver.name,
2916 config: Config{
2917 MinVersion: ver.version,
2918 MaxVersion: ver.version,
2919 },
2920 flags: []string{"-require-any-client-certificate"},
2921 shouldFail: true,
2922 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2923 })
2924
2925 if ver.version != VersionSSL30 {
2926 testCases = append(testCases, testCase{
2927 testType: serverTest,
2928 name: "SkipClientCertificate-" + ver.name,
2929 config: Config{
2930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 Bugs: ProtocolBugs{
2933 SkipClientCertificate: true,
2934 },
2935 },
2936 // Setting SSL_VERIFY_PEER allows anonymous clients.
2937 flags: []string{"-verify-peer"},
2938 shouldFail: true,
2939 expectedError: ":UNEXPECTED_MESSAGE:",
2940 })
2941 }
David Benjamin636293b2014-07-08 17:59:18 -04002942 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002943
David Benjaminc032dfa2016-05-12 14:54:57 -04002944 // Client auth is only legal in certificate-based ciphers.
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-PSK",
2948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002949 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002950 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
2962 testCases = append(testCases, testCase{
2963 testType: clientTest,
2964 name: "ClientAuth-ECDHE_PSK",
2965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002966 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002967 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2968 PreSharedKey: []byte("secret"),
2969 ClientAuth: RequireAnyClientCert,
2970 },
2971 flags: []string{
2972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2974 "-psk", "secret",
2975 },
2976 shouldFail: true,
2977 expectedError: ":UNEXPECTED_MESSAGE:",
2978 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002979
2980 // Regression test for a bug where the client CA list, if explicitly
2981 // set to NULL, was mis-encoded.
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "Null-Client-CA-List",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 Certificates: []Certificate{rsaCertificate},
2988 },
2989 flags: []string{
2990 "-require-any-client-certificate",
2991 "-use-null-client-ca-list",
2992 },
2993 })
David Benjamin636293b2014-07-08 17:59:18 -04002994}
2995
Adam Langley75712922014-10-10 16:23:43 -07002996func addExtendedMasterSecretTests() {
2997 const expectEMSFlag = "-expect-extended-master-secret"
2998
2999 for _, with := range []bool{false, true} {
3000 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003001 if with {
3002 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003003 }
3004
3005 for _, isClient := range []bool{false, true} {
3006 suffix := "-Server"
3007 testType := serverTest
3008 if isClient {
3009 suffix = "-Client"
3010 testType = clientTest
3011 }
3012
3013 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003014 // In TLS 1.3, the extension is irrelevant and
3015 // always reports as enabled.
3016 var flags []string
3017 if with || ver.version >= VersionTLS13 {
3018 flags = []string{expectEMSFlag}
3019 }
3020
Adam Langley75712922014-10-10 16:23:43 -07003021 test := testCase{
3022 testType: testType,
3023 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3024 config: Config{
3025 MinVersion: ver.version,
3026 MaxVersion: ver.version,
3027 Bugs: ProtocolBugs{
3028 NoExtendedMasterSecret: !with,
3029 RequireExtendedMasterSecret: with,
3030 },
3031 },
David Benjamin48cae082014-10-27 01:06:24 -04003032 flags: flags,
3033 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003034 }
3035 if test.shouldFail {
3036 test.expectedLocalError = "extended master secret required but not supported by peer"
3037 }
3038 testCases = append(testCases, test)
3039 }
3040 }
3041 }
3042
Adam Langleyba5934b2015-06-02 10:50:35 -07003043 for _, isClient := range []bool{false, true} {
3044 for _, supportedInFirstConnection := range []bool{false, true} {
3045 for _, supportedInResumeConnection := range []bool{false, true} {
3046 boolToWord := func(b bool) string {
3047 if b {
3048 return "Yes"
3049 }
3050 return "No"
3051 }
3052 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3053 if isClient {
3054 suffix += "Client"
3055 } else {
3056 suffix += "Server"
3057 }
3058
3059 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003060 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003061 Bugs: ProtocolBugs{
3062 RequireExtendedMasterSecret: true,
3063 },
3064 }
3065
3066 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003068 Bugs: ProtocolBugs{
3069 NoExtendedMasterSecret: true,
3070 },
3071 }
3072
3073 test := testCase{
3074 name: "ExtendedMasterSecret-" + suffix,
3075 resumeSession: true,
3076 }
3077
3078 if !isClient {
3079 test.testType = serverTest
3080 }
3081
3082 if supportedInFirstConnection {
3083 test.config = supportedConfig
3084 } else {
3085 test.config = noSupportConfig
3086 }
3087
3088 if supportedInResumeConnection {
3089 test.resumeConfig = &supportedConfig
3090 } else {
3091 test.resumeConfig = &noSupportConfig
3092 }
3093
3094 switch suffix {
3095 case "YesToYes-Client", "YesToYes-Server":
3096 // When a session is resumed, it should
3097 // still be aware that its master
3098 // secret was generated via EMS and
3099 // thus it's safe to use tls-unique.
3100 test.flags = []string{expectEMSFlag}
3101 case "NoToYes-Server":
3102 // If an original connection did not
3103 // contain EMS, but a resumption
3104 // handshake does, then a server should
3105 // not resume the session.
3106 test.expectResumeRejected = true
3107 case "YesToNo-Server":
3108 // Resuming an EMS session without the
3109 // EMS extension should cause the
3110 // server to abort the connection.
3111 test.shouldFail = true
3112 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3113 case "NoToYes-Client":
3114 // A client should abort a connection
3115 // where the server resumed a non-EMS
3116 // session but echoed the EMS
3117 // extension.
3118 test.shouldFail = true
3119 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3120 case "YesToNo-Client":
3121 // A client should abort a connection
3122 // where the server didn't echo EMS
3123 // when the session used it.
3124 test.shouldFail = true
3125 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3126 }
3127
3128 testCases = append(testCases, test)
3129 }
3130 }
3131 }
David Benjamin163c9562016-08-29 23:14:17 -04003132
3133 // Switching EMS on renegotiation is forbidden.
3134 testCases = append(testCases, testCase{
3135 name: "ExtendedMasterSecret-Renego-NoEMS",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 Bugs: ProtocolBugs{
3139 NoExtendedMasterSecret: true,
3140 NoExtendedMasterSecretOnRenegotiation: true,
3141 },
3142 },
3143 renegotiate: 1,
3144 flags: []string{
3145 "-renegotiate-freely",
3146 "-expect-total-renegotiations", "1",
3147 },
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Upgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecret: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
3166
3167 testCases = append(testCases, testCase{
3168 name: "ExtendedMasterSecret-Renego-Downgrade",
3169 config: Config{
3170 MaxVersion: VersionTLS12,
3171 Bugs: ProtocolBugs{
3172 NoExtendedMasterSecretOnRenegotiation: true,
3173 },
3174 },
3175 renegotiate: 1,
3176 flags: []string{
3177 "-renegotiate-freely",
3178 "-expect-total-renegotiations", "1",
3179 },
3180 shouldFail: true,
3181 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3182 })
Adam Langley75712922014-10-10 16:23:43 -07003183}
3184
David Benjamin582ba042016-07-07 12:33:25 -07003185type stateMachineTestConfig struct {
3186 protocol protocol
3187 async bool
3188 splitHandshake, packHandshakeFlight bool
3189}
3190
David Benjamin43ec06f2014-08-05 02:28:57 -04003191// Adds tests that try to cover the range of the handshake state machine, under
3192// various conditions. Some of these are redundant with other tests, but they
3193// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003194func addAllStateMachineCoverageTests() {
3195 for _, async := range []bool{false, true} {
3196 for _, protocol := range []protocol{tls, dtls} {
3197 addStateMachineCoverageTests(stateMachineTestConfig{
3198 protocol: protocol,
3199 async: async,
3200 })
3201 addStateMachineCoverageTests(stateMachineTestConfig{
3202 protocol: protocol,
3203 async: async,
3204 splitHandshake: true,
3205 })
3206 if protocol == tls {
3207 addStateMachineCoverageTests(stateMachineTestConfig{
3208 protocol: protocol,
3209 async: async,
3210 packHandshakeFlight: true,
3211 })
3212 }
3213 }
3214 }
3215}
3216
3217func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 var tests []testCase
3219
3220 // Basic handshake, with resumption. Client and server,
3221 // session ID and session ticket.
3222 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003223 name: "Basic-Client",
3224 config: Config{
3225 MaxVersion: VersionTLS12,
3226 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003227 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003228 // Ensure session tickets are used, not session IDs.
3229 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 })
3231 tests = append(tests, testCase{
3232 name: "Basic-Client-RenewTicket",
3233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003234 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003235 Bugs: ProtocolBugs{
3236 RenewTicketOnResume: true,
3237 },
3238 },
David Benjamin46662482016-08-17 00:51:00 -04003239 flags: []string{"-expect-ticket-renewal"},
3240 resumeSession: true,
3241 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003242 })
3243 tests = append(tests, testCase{
3244 name: "Basic-Client-NoTicket",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003247 SessionTicketsDisabled: true,
3248 },
3249 resumeSession: true,
3250 })
3251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003252 name: "Basic-Client-Implicit",
3253 config: Config{
3254 MaxVersion: VersionTLS12,
3255 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003256 flags: []string{"-implicit-handshake"},
3257 resumeSession: true,
3258 })
3259 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003260 testType: serverTest,
3261 name: "Basic-Server",
3262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003264 Bugs: ProtocolBugs{
3265 RequireSessionTickets: true,
3266 },
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 resumeSession: true,
3269 })
3270 tests = append(tests, testCase{
3271 testType: serverTest,
3272 name: "Basic-Server-NoTickets",
3273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003274 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 SessionTicketsDisabled: true,
3276 },
3277 resumeSession: true,
3278 })
3279 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003280 testType: serverTest,
3281 name: "Basic-Server-Implicit",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003285 flags: []string{"-implicit-handshake"},
3286 resumeSession: true,
3287 })
3288 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003289 testType: serverTest,
3290 name: "Basic-Server-EarlyCallback",
3291 config: Config{
3292 MaxVersion: VersionTLS12,
3293 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 flags: []string{"-use-early-callback"},
3295 resumeSession: true,
3296 })
3297
Steven Valdez143e8b32016-07-11 13:19:03 -04003298 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003299 if config.protocol == tls {
3300 tests = append(tests, testCase{
3301 name: "TLS13-1RTT-Client",
3302 config: Config{
3303 MaxVersion: VersionTLS13,
3304 MinVersion: VersionTLS13,
3305 },
David Benjamin46662482016-08-17 00:51:00 -04003306 resumeSession: true,
3307 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003308 })
3309
3310 tests = append(tests, testCase{
3311 testType: serverTest,
3312 name: "TLS13-1RTT-Server",
3313 config: Config{
3314 MaxVersion: VersionTLS13,
3315 MinVersion: VersionTLS13,
3316 },
David Benjamin46662482016-08-17 00:51:00 -04003317 resumeSession: true,
3318 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003319 })
3320
3321 tests = append(tests, testCase{
3322 name: "TLS13-HelloRetryRequest-Client",
3323 config: Config{
3324 MaxVersion: VersionTLS13,
3325 MinVersion: VersionTLS13,
3326 // P-384 requires a HelloRetryRequest against
3327 // BoringSSL's default configuration. Assert
3328 // that we do indeed test this with
3329 // ExpectMissingKeyShare.
3330 CurvePreferences: []CurveID{CurveP384},
3331 Bugs: ProtocolBugs{
3332 ExpectMissingKeyShare: true,
3333 },
3334 },
3335 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3336 resumeSession: true,
3337 })
3338
3339 tests = append(tests, testCase{
3340 testType: serverTest,
3341 name: "TLS13-HelloRetryRequest-Server",
3342 config: Config{
3343 MaxVersion: VersionTLS13,
3344 MinVersion: VersionTLS13,
3345 // Require a HelloRetryRequest for every curve.
3346 DefaultCurves: []CurveID{},
3347 },
3348 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3349 resumeSession: true,
3350 })
3351 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003352
David Benjamin760b1dd2015-05-15 23:33:48 -04003353 // TLS client auth.
3354 tests = append(tests, testCase{
3355 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003356 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003358 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003359 ClientAuth: RequestClientCert,
3360 },
3361 })
3362 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003363 testType: serverTest,
3364 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003365 config: Config{
3366 MaxVersion: VersionTLS12,
3367 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003368 // Setting SSL_VERIFY_PEER allows anonymous clients.
3369 flags: []string{"-verify-peer"},
3370 })
David Benjamin582ba042016-07-07 12:33:25 -07003371 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-SSL3",
3375 config: Config{
3376 MaxVersion: VersionSSL30,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-SSL3",
3383 config: Config{
3384 MaxVersion: VersionSSL30,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003389 tests = append(tests, testCase{
3390 testType: clientTest,
3391 name: "ClientAuth-NoCertificate-Client-TLS13",
3392 config: Config{
3393 MaxVersion: VersionTLS13,
3394 ClientAuth: RequestClientCert,
3395 },
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "ClientAuth-NoCertificate-Server-TLS13",
3400 config: Config{
3401 MaxVersion: VersionTLS13,
3402 },
3403 // Setting SSL_VERIFY_PEER allows anonymous clients.
3404 flags: []string{"-verify-peer"},
3405 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003406 }
3407 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003408 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003409 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 ClientAuth: RequireAnyClientCert,
3413 },
3414 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003415 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3416 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003417 },
3418 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 tests = append(tests, testCase{
3420 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003421 name: "ClientAuth-RSA-Client-TLS13",
3422 config: Config{
3423 MaxVersion: VersionTLS13,
3424 ClientAuth: RequireAnyClientCert,
3425 },
3426 flags: []string{
3427 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3428 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3429 },
3430 })
3431 tests = append(tests, testCase{
3432 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003433 name: "ClientAuth-ECDSA-Client",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003436 ClientAuth: RequireAnyClientCert,
3437 },
3438 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003439 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3440 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003441 },
3442 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003443 tests = append(tests, testCase{
3444 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003445 name: "ClientAuth-ECDSA-Client-TLS13",
3446 config: Config{
3447 MaxVersion: VersionTLS13,
3448 ClientAuth: RequireAnyClientCert,
3449 },
3450 flags: []string{
3451 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3452 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3453 },
3454 })
3455 tests = append(tests, testCase{
3456 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003457 name: "ClientAuth-NoCertificate-OldCallback",
3458 config: Config{
3459 MaxVersion: VersionTLS12,
3460 ClientAuth: RequestClientCert,
3461 },
3462 flags: []string{"-use-old-client-cert-callback"},
3463 })
3464 tests = append(tests, testCase{
3465 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003466 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3467 config: Config{
3468 MaxVersion: VersionTLS13,
3469 ClientAuth: RequestClientCert,
3470 },
3471 flags: []string{"-use-old-client-cert-callback"},
3472 })
3473 tests = append(tests, testCase{
3474 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003475 name: "ClientAuth-OldCallback",
3476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003477 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003478 ClientAuth: RequireAnyClientCert,
3479 },
3480 flags: []string{
3481 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3482 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3483 "-use-old-client-cert-callback",
3484 },
3485 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003486 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003487 testType: clientTest,
3488 name: "ClientAuth-OldCallback-TLS13",
3489 config: Config{
3490 MaxVersion: VersionTLS13,
3491 ClientAuth: RequireAnyClientCert,
3492 },
3493 flags: []string{
3494 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3495 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3496 "-use-old-client-cert-callback",
3497 },
3498 })
3499 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003500 testType: serverTest,
3501 name: "ClientAuth-Server",
3502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003503 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 Certificates: []Certificate{rsaCertificate},
3505 },
3506 flags: []string{"-require-any-client-certificate"},
3507 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 tests = append(tests, testCase{
3509 testType: serverTest,
3510 name: "ClientAuth-Server-TLS13",
3511 config: Config{
3512 MaxVersion: VersionTLS13,
3513 Certificates: []Certificate{rsaCertificate},
3514 },
3515 flags: []string{"-require-any-client-certificate"},
3516 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003517
David Benjamin4c3ddf72016-06-29 18:13:53 -04003518 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003519 tests = append(tests, testCase{
3520 testType: serverTest,
3521 name: "Basic-Server-RSA",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3525 },
3526 flags: []string{
3527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3529 },
3530 })
3531 tests = append(tests, testCase{
3532 testType: serverTest,
3533 name: "Basic-Server-ECDHE-RSA",
3534 config: Config{
3535 MaxVersion: VersionTLS12,
3536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3537 },
3538 flags: []string{
3539 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3540 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3541 },
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "Basic-Server-ECDHE-ECDSA",
3546 config: Config{
3547 MaxVersion: VersionTLS12,
3548 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3549 },
3550 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003551 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3552 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003553 },
3554 })
3555
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 // No session ticket support; server doesn't send NewSessionTicket.
3557 tests = append(tests, testCase{
3558 name: "SessionTicketsDisabled-Client",
3559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003561 SessionTicketsDisabled: true,
3562 },
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "SessionTicketsDisabled-Server",
3567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003568 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 SessionTicketsDisabled: true,
3570 },
3571 })
3572
3573 // Skip ServerKeyExchange in PSK key exchange if there's no
3574 // identity hint.
3575 tests = append(tests, testCase{
3576 name: "EmptyPSKHint-Client",
3577 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003578 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003579 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3580 PreSharedKey: []byte("secret"),
3581 },
3582 flags: []string{"-psk", "secret"},
3583 })
3584 tests = append(tests, testCase{
3585 testType: serverTest,
3586 name: "EmptyPSKHint-Server",
3587 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003588 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3590 PreSharedKey: []byte("secret"),
3591 },
3592 flags: []string{"-psk", "secret"},
3593 })
3594
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003596 tests = append(tests, testCase{
3597 testType: clientTest,
3598 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003599 config: Config{
3600 MaxVersion: VersionTLS12,
3601 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003602 flags: []string{
3603 "-enable-ocsp-stapling",
3604 "-expect-ocsp-response",
3605 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003606 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003607 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003608 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003609 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003610 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 testType: serverTest,
3612 name: "OCSPStapling-Server",
3613 config: Config{
3614 MaxVersion: VersionTLS12,
3615 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003616 expectedOCSPResponse: testOCSPResponse,
3617 flags: []string{
3618 "-ocsp-response",
3619 base64.StdEncoding.EncodeToString(testOCSPResponse),
3620 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003621 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003622 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003623 tests = append(tests, testCase{
3624 testType: clientTest,
3625 name: "OCSPStapling-Client-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 },
3629 flags: []string{
3630 "-enable-ocsp-stapling",
3631 "-expect-ocsp-response",
3632 base64.StdEncoding.EncodeToString(testOCSPResponse),
3633 "-verify-peer",
3634 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003635 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003636 })
3637 tests = append(tests, testCase{
3638 testType: serverTest,
3639 name: "OCSPStapling-Server-TLS13",
3640 config: Config{
3641 MaxVersion: VersionTLS13,
3642 },
3643 expectedOCSPResponse: testOCSPResponse,
3644 flags: []string{
3645 "-ocsp-response",
3646 base64.StdEncoding.EncodeToString(testOCSPResponse),
3647 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003648 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003649 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003650
David Benjamin4c3ddf72016-06-29 18:13:53 -04003651 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003652 for _, vers := range tlsVersions {
3653 if config.protocol == dtls && !vers.hasDTLS {
3654 continue
3655 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003656 for _, testType := range []testType{clientTest, serverTest} {
3657 suffix := "-Client"
3658 if testType == serverTest {
3659 suffix = "-Server"
3660 }
3661 suffix += "-" + vers.name
3662
3663 flag := "-verify-peer"
3664 if testType == serverTest {
3665 flag = "-require-any-client-certificate"
3666 }
3667
3668 tests = append(tests, testCase{
3669 testType: testType,
3670 name: "CertificateVerificationSucceed" + suffix,
3671 config: Config{
3672 MaxVersion: vers.version,
3673 Certificates: []Certificate{rsaCertificate},
3674 },
3675 flags: []string{
3676 flag,
3677 "-expect-verify-result",
3678 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003679 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003680 })
3681 tests = append(tests, testCase{
3682 testType: testType,
3683 name: "CertificateVerificationFail" + suffix,
3684 config: Config{
3685 MaxVersion: vers.version,
3686 Certificates: []Certificate{rsaCertificate},
3687 },
3688 flags: []string{
3689 flag,
3690 "-verify-fail",
3691 },
3692 shouldFail: true,
3693 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3694 })
3695 }
3696
3697 // By default, the client is in a soft fail mode where the peer
3698 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003699 tests = append(tests, testCase{
3700 testType: clientTest,
3701 name: "CertificateVerificationSoftFail-" + vers.name,
3702 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003703 MaxVersion: vers.version,
3704 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003705 },
3706 flags: []string{
3707 "-verify-fail",
3708 "-expect-verify-result",
3709 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003710 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003711 })
3712 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003713
David Benjamin1d4f4c02016-07-26 18:03:08 -04003714 tests = append(tests, testCase{
3715 name: "ShimSendAlert",
3716 flags: []string{"-send-alert"},
3717 shimWritesFirst: true,
3718 shouldFail: true,
3719 expectedLocalError: "remote error: decompression failure",
3720 })
3721
David Benjamin582ba042016-07-07 12:33:25 -07003722 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 name: "Renegotiate-Client",
3725 config: Config{
3726 MaxVersion: VersionTLS12,
3727 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003728 renegotiate: 1,
3729 flags: []string{
3730 "-renegotiate-freely",
3731 "-expect-total-renegotiations", "1",
3732 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003734
David Benjamin47921102016-07-28 11:29:18 -04003735 tests = append(tests, testCase{
3736 name: "SendHalfHelloRequest",
3737 config: Config{
3738 MaxVersion: VersionTLS12,
3739 Bugs: ProtocolBugs{
3740 PackHelloRequestWithFinished: config.packHandshakeFlight,
3741 },
3742 },
3743 sendHalfHelloRequest: true,
3744 flags: []string{"-renegotiate-ignore"},
3745 shouldFail: true,
3746 expectedError: ":UNEXPECTED_RECORD:",
3747 })
3748
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 // NPN on client and server; results in post-handshake message.
3750 tests = append(tests, testCase{
3751 name: "NPN-Client",
3752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003754 NextProtos: []string{"foo"},
3755 },
3756 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003757 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003758 expectedNextProto: "foo",
3759 expectedNextProtoType: npn,
3760 })
3761 tests = append(tests, testCase{
3762 testType: serverTest,
3763 name: "NPN-Server",
3764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 NextProtos: []string{"bar"},
3767 },
3768 flags: []string{
3769 "-advertise-npn", "\x03foo\x03bar\x03baz",
3770 "-expect-next-proto", "bar",
3771 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003772 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003773 expectedNextProto: "bar",
3774 expectedNextProtoType: npn,
3775 })
3776
3777 // TODO(davidben): Add tests for when False Start doesn't trigger.
3778
3779 // Client does False Start and negotiates NPN.
3780 tests = append(tests, testCase{
3781 name: "FalseStart",
3782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003783 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3785 NextProtos: []string{"foo"},
3786 Bugs: ProtocolBugs{
3787 ExpectFalseStart: true,
3788 },
3789 },
3790 flags: []string{
3791 "-false-start",
3792 "-select-next-proto", "foo",
3793 },
3794 shimWritesFirst: true,
3795 resumeSession: true,
3796 })
3797
3798 // Client does False Start and negotiates ALPN.
3799 tests = append(tests, testCase{
3800 name: "FalseStart-ALPN",
3801 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003802 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3804 NextProtos: []string{"foo"},
3805 Bugs: ProtocolBugs{
3806 ExpectFalseStart: true,
3807 },
3808 },
3809 flags: []string{
3810 "-false-start",
3811 "-advertise-alpn", "\x03foo",
3812 },
3813 shimWritesFirst: true,
3814 resumeSession: true,
3815 })
3816
3817 // Client does False Start but doesn't explicitly call
3818 // SSL_connect.
3819 tests = append(tests, testCase{
3820 name: "FalseStart-Implicit",
3821 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003822 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3824 NextProtos: []string{"foo"},
3825 },
3826 flags: []string{
3827 "-implicit-handshake",
3828 "-false-start",
3829 "-advertise-alpn", "\x03foo",
3830 },
3831 })
3832
3833 // False Start without session tickets.
3834 tests = append(tests, testCase{
3835 name: "FalseStart-SessionTicketsDisabled",
3836 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003837 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3839 NextProtos: []string{"foo"},
3840 SessionTicketsDisabled: true,
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-select-next-proto", "foo",
3848 },
3849 shimWritesFirst: true,
3850 })
3851
Adam Langleydf759b52016-07-11 15:24:37 -07003852 tests = append(tests, testCase{
3853 name: "FalseStart-CECPQ1",
3854 config: Config{
3855 MaxVersion: VersionTLS12,
3856 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3857 NextProtos: []string{"foo"},
3858 Bugs: ProtocolBugs{
3859 ExpectFalseStart: true,
3860 },
3861 },
3862 flags: []string{
3863 "-false-start",
3864 "-cipher", "DEFAULT:kCECPQ1",
3865 "-select-next-proto", "foo",
3866 },
3867 shimWritesFirst: true,
3868 resumeSession: true,
3869 })
3870
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 // Server parses a V2ClientHello.
3872 tests = append(tests, testCase{
3873 testType: serverTest,
3874 name: "SendV2ClientHello",
3875 config: Config{
3876 // Choose a cipher suite that does not involve
3877 // elliptic curves, so no extensions are
3878 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003879 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003880 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 Bugs: ProtocolBugs{
3882 SendV2ClientHello: true,
3883 },
3884 },
3885 })
3886
3887 // Client sends a Channel ID.
3888 tests = append(tests, testCase{
3889 name: "ChannelID-Client",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 RequestChannelID: true,
3893 },
Adam Langley7c803a62015-06-15 15:35:05 -07003894 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 resumeSession: true,
3896 expectChannelID: true,
3897 })
3898
3899 // Server accepts a Channel ID.
3900 tests = append(tests, testCase{
3901 testType: serverTest,
3902 name: "ChannelID-Server",
3903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904 MaxVersion: VersionTLS12,
3905 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003906 },
3907 flags: []string{
3908 "-expect-channel-id",
3909 base64.StdEncoding.EncodeToString(channelIDBytes),
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 })
David Benjamin30789da2015-08-29 22:56:45 -04003914
David Benjaminf8fcdf32016-06-08 15:56:13 -04003915 // Channel ID and NPN at the same time, to ensure their relative
3916 // ordering is correct.
3917 tests = append(tests, testCase{
3918 name: "ChannelID-NPN-Client",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 RequestChannelID: true,
3922 NextProtos: []string{"foo"},
3923 },
3924 flags: []string{
3925 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3926 "-select-next-proto", "foo",
3927 },
3928 resumeSession: true,
3929 expectChannelID: true,
3930 expectedNextProto: "foo",
3931 expectedNextProtoType: npn,
3932 })
3933 tests = append(tests, testCase{
3934 testType: serverTest,
3935 name: "ChannelID-NPN-Server",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003938 ChannelID: channelIDKey,
3939 NextProtos: []string{"bar"},
3940 },
3941 flags: []string{
3942 "-expect-channel-id",
3943 base64.StdEncoding.EncodeToString(channelIDBytes),
3944 "-advertise-npn", "\x03foo\x03bar\x03baz",
3945 "-expect-next-proto", "bar",
3946 },
3947 resumeSession: true,
3948 expectChannelID: true,
3949 expectedNextProto: "bar",
3950 expectedNextProtoType: npn,
3951 })
3952
David Benjamin30789da2015-08-29 22:56:45 -04003953 // Bidirectional shutdown with the runner initiating.
3954 tests = append(tests, testCase{
3955 name: "Shutdown-Runner",
3956 config: Config{
3957 Bugs: ProtocolBugs{
3958 ExpectCloseNotify: true,
3959 },
3960 },
3961 flags: []string{"-check-close-notify"},
3962 })
3963
3964 // Bidirectional shutdown with the shim initiating. The runner,
3965 // in the meantime, sends garbage before the close_notify which
3966 // the shim must ignore.
3967 tests = append(tests, testCase{
3968 name: "Shutdown-Shim",
3969 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003970 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003971 Bugs: ProtocolBugs{
3972 ExpectCloseNotify: true,
3973 },
3974 },
3975 shimShutsDown: true,
3976 sendEmptyRecords: 1,
3977 sendWarningAlerts: 1,
3978 flags: []string{"-check-close-notify"},
3979 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003980 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003981 // TODO(davidben): DTLS 1.3 will want a similar thing for
3982 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 tests = append(tests, testCase{
3984 name: "SkipHelloVerifyRequest",
3985 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003986 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003987 Bugs: ProtocolBugs{
3988 SkipHelloVerifyRequest: true,
3989 },
3990 },
3991 })
3992 }
3993
David Benjamin760b1dd2015-05-15 23:33:48 -04003994 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003995 test.protocol = config.protocol
3996 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003997 test.name += "-DTLS"
3998 }
David Benjamin582ba042016-07-07 12:33:25 -07003999 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004000 test.name += "-Async"
4001 test.flags = append(test.flags, "-async")
4002 } else {
4003 test.name += "-Sync"
4004 }
David Benjamin582ba042016-07-07 12:33:25 -07004005 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004006 test.name += "-SplitHandshakeRecords"
4007 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004009 test.config.Bugs.MaxPacketLength = 256
4010 test.flags = append(test.flags, "-mtu", "256")
4011 }
4012 }
David Benjamin582ba042016-07-07 12:33:25 -07004013 if config.packHandshakeFlight {
4014 test.name += "-PackHandshakeFlight"
4015 test.config.Bugs.PackHandshakeFlight = true
4016 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004018 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004019}
4020
Adam Langley524e7172015-02-20 16:04:00 -08004021func addDDoSCallbackTests() {
4022 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004023 for _, resume := range []bool{false, true} {
4024 suffix := "Resume"
4025 if resume {
4026 suffix = "No" + suffix
4027 }
4028
4029 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 testType: serverTest,
4031 name: "Server-DDoS-OK-" + suffix,
4032 config: Config{
4033 MaxVersion: VersionTLS12,
4034 },
Adam Langley524e7172015-02-20 16:04:00 -08004035 flags: []string{"-install-ddos-callback"},
4036 resumeSession: resume,
4037 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004038 testCases = append(testCases, testCase{
4039 testType: serverTest,
4040 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4041 config: Config{
4042 MaxVersion: VersionTLS13,
4043 },
4044 flags: []string{"-install-ddos-callback"},
4045 resumeSession: resume,
4046 })
Adam Langley524e7172015-02-20 16:04:00 -08004047
4048 failFlag := "-fail-ddos-callback"
4049 if resume {
4050 failFlag = "-fail-second-ddos-callback"
4051 }
4052 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004053 testType: serverTest,
4054 name: "Server-DDoS-Reject-" + suffix,
4055 config: Config{
4056 MaxVersion: VersionTLS12,
4057 },
David Benjamin2c66e072016-09-16 15:58:00 -04004058 flags: []string{"-install-ddos-callback", failFlag},
4059 resumeSession: resume,
4060 shouldFail: true,
4061 expectedError: ":CONNECTION_REJECTED:",
4062 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004063 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004064 testCases = append(testCases, testCase{
4065 testType: serverTest,
4066 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4067 config: Config{
4068 MaxVersion: VersionTLS13,
4069 },
David Benjamin2c66e072016-09-16 15:58:00 -04004070 flags: []string{"-install-ddos-callback", failFlag},
4071 resumeSession: resume,
4072 shouldFail: true,
4073 expectedError: ":CONNECTION_REJECTED:",
4074 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004075 })
Adam Langley524e7172015-02-20 16:04:00 -08004076 }
4077}
4078
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004079func addVersionNegotiationTests() {
4080 for i, shimVers := range tlsVersions {
4081 // Assemble flags to disable all newer versions on the shim.
4082 var flags []string
4083 for _, vers := range tlsVersions[i+1:] {
4084 flags = append(flags, vers.flag)
4085 }
4086
4087 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004088 protocols := []protocol{tls}
4089 if runnerVers.hasDTLS && shimVers.hasDTLS {
4090 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004091 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004092 for _, protocol := range protocols {
4093 expectedVersion := shimVers.version
4094 if runnerVers.version < shimVers.version {
4095 expectedVersion = runnerVers.version
4096 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004097
David Benjamin8b8c0062014-11-23 02:47:52 -05004098 suffix := shimVers.name + "-" + runnerVers.name
4099 if protocol == dtls {
4100 suffix += "-DTLS"
4101 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004102
David Benjamin1eb367c2014-12-12 18:17:51 -05004103 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4104
David Benjamin1e29a6b2014-12-10 02:27:24 -05004105 clientVers := shimVers.version
4106 if clientVers > VersionTLS10 {
4107 clientVers = VersionTLS10
4108 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004109 serverVers := expectedVersion
4110 if expectedVersion >= VersionTLS13 {
4111 serverVers = VersionTLS10
4112 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004113 testCases = append(testCases, testCase{
4114 protocol: protocol,
4115 testType: clientTest,
4116 name: "VersionNegotiation-Client-" + suffix,
4117 config: Config{
4118 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004119 Bugs: ProtocolBugs{
4120 ExpectInitialRecordVersion: clientVers,
4121 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004122 },
4123 flags: flags,
4124 expectedVersion: expectedVersion,
4125 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004126 testCases = append(testCases, testCase{
4127 protocol: protocol,
4128 testType: clientTest,
4129 name: "VersionNegotiation-Client2-" + suffix,
4130 config: Config{
4131 MaxVersion: runnerVers.version,
4132 Bugs: ProtocolBugs{
4133 ExpectInitialRecordVersion: clientVers,
4134 },
4135 },
4136 flags: []string{"-max-version", shimVersFlag},
4137 expectedVersion: expectedVersion,
4138 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004139
4140 testCases = append(testCases, testCase{
4141 protocol: protocol,
4142 testType: serverTest,
4143 name: "VersionNegotiation-Server-" + suffix,
4144 config: Config{
4145 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004146 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004147 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004148 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004149 },
4150 flags: flags,
4151 expectedVersion: expectedVersion,
4152 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004153 testCases = append(testCases, testCase{
4154 protocol: protocol,
4155 testType: serverTest,
4156 name: "VersionNegotiation-Server2-" + suffix,
4157 config: Config{
4158 MaxVersion: runnerVers.version,
4159 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004160 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004161 },
4162 },
4163 flags: []string{"-max-version", shimVersFlag},
4164 expectedVersion: expectedVersion,
4165 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004166 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004167 }
4168 }
David Benjamin95c69562016-06-29 18:15:03 -04004169
4170 // Test for version tolerance.
4171 testCases = append(testCases, testCase{
4172 testType: serverTest,
4173 name: "MinorVersionTolerance",
4174 config: Config{
4175 Bugs: ProtocolBugs{
4176 SendClientVersion: 0x03ff,
4177 },
4178 },
4179 expectedVersion: VersionTLS13,
4180 })
4181 testCases = append(testCases, testCase{
4182 testType: serverTest,
4183 name: "MajorVersionTolerance",
4184 config: Config{
4185 Bugs: ProtocolBugs{
4186 SendClientVersion: 0x0400,
4187 },
4188 },
4189 expectedVersion: VersionTLS13,
4190 })
4191 testCases = append(testCases, testCase{
4192 protocol: dtls,
4193 testType: serverTest,
4194 name: "MinorVersionTolerance-DTLS",
4195 config: Config{
4196 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004197 SendClientVersion: 0xfe00,
David Benjamin95c69562016-06-29 18:15:03 -04004198 },
4199 },
4200 expectedVersion: VersionTLS12,
4201 })
4202 testCases = append(testCases, testCase{
4203 protocol: dtls,
4204 testType: serverTest,
4205 name: "MajorVersionTolerance-DTLS",
4206 config: Config{
4207 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004208 SendClientVersion: 0xfdff,
David Benjamin95c69562016-06-29 18:15:03 -04004209 },
4210 },
4211 expectedVersion: VersionTLS12,
4212 })
4213
4214 // Test that versions below 3.0 are rejected.
4215 testCases = append(testCases, testCase{
4216 testType: serverTest,
4217 name: "VersionTooLow",
4218 config: Config{
4219 Bugs: ProtocolBugs{
4220 SendClientVersion: 0x0200,
4221 },
4222 },
4223 shouldFail: true,
4224 expectedError: ":UNSUPPORTED_PROTOCOL:",
4225 })
4226 testCases = append(testCases, testCase{
4227 protocol: dtls,
4228 testType: serverTest,
4229 name: "VersionTooLow-DTLS",
4230 config: Config{
4231 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004232 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004233 },
4234 },
4235 shouldFail: true,
4236 expectedError: ":UNSUPPORTED_PROTOCOL:",
4237 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004238
David Benjamin2dc02042016-09-19 19:57:37 -04004239 testCases = append(testCases, testCase{
4240 name: "ServerBogusVersion",
4241 config: Config{
4242 Bugs: ProtocolBugs{
4243 SendServerHelloVersion: 0x1234,
4244 },
4245 },
4246 shouldFail: true,
4247 expectedError: ":UNSUPPORTED_PROTOCOL:",
4248 })
4249
David Benjamin1f61f0d2016-07-10 12:20:35 -04004250 // Test TLS 1.3's downgrade signal.
4251 testCases = append(testCases, testCase{
4252 name: "Downgrade-TLS12-Client",
4253 config: Config{
4254 Bugs: ProtocolBugs{
4255 NegotiateVersion: VersionTLS12,
4256 },
4257 },
David Benjamin55108632016-08-11 22:01:18 -04004258 // TODO(davidben): This test should fail once TLS 1.3 is final
4259 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004260 })
4261 testCases = append(testCases, testCase{
4262 testType: serverTest,
4263 name: "Downgrade-TLS12-Server",
4264 config: Config{
4265 Bugs: ProtocolBugs{
4266 SendClientVersion: VersionTLS12,
4267 },
4268 },
David Benjamin55108632016-08-11 22:01:18 -04004269 // TODO(davidben): This test should fail once TLS 1.3 is final
4270 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004271 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004272}
4273
David Benjaminaccb4542014-12-12 23:44:33 -05004274func addMinimumVersionTests() {
4275 for i, shimVers := range tlsVersions {
4276 // Assemble flags to disable all older versions on the shim.
4277 var flags []string
4278 for _, vers := range tlsVersions[:i] {
4279 flags = append(flags, vers.flag)
4280 }
4281
4282 for _, runnerVers := range tlsVersions {
4283 protocols := []protocol{tls}
4284 if runnerVers.hasDTLS && shimVers.hasDTLS {
4285 protocols = append(protocols, dtls)
4286 }
4287 for _, protocol := range protocols {
4288 suffix := shimVers.name + "-" + runnerVers.name
4289 if protocol == dtls {
4290 suffix += "-DTLS"
4291 }
4292 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4293
David Benjaminaccb4542014-12-12 23:44:33 -05004294 var expectedVersion uint16
4295 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004296 var expectedClientError, expectedServerError string
4297 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004298 if runnerVers.version >= shimVers.version {
4299 expectedVersion = runnerVers.version
4300 } else {
4301 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004302 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4303 expectedServerLocalError = "remote error: protocol version not supported"
4304 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4305 // If the client's minimum version is TLS 1.3 and the runner's
4306 // maximum is below TLS 1.2, the runner will fail to select a
4307 // cipher before the shim rejects the selected version.
4308 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4309 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4310 } else {
4311 expectedClientError = expectedServerError
4312 expectedClientLocalError = expectedServerLocalError
4313 }
David Benjaminaccb4542014-12-12 23:44:33 -05004314 }
4315
4316 testCases = append(testCases, testCase{
4317 protocol: protocol,
4318 testType: clientTest,
4319 name: "MinimumVersion-Client-" + suffix,
4320 config: Config{
4321 MaxVersion: runnerVers.version,
4322 },
David Benjamin87909c02014-12-13 01:55:01 -05004323 flags: flags,
4324 expectedVersion: expectedVersion,
4325 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004326 expectedError: expectedClientError,
4327 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004328 })
4329 testCases = append(testCases, testCase{
4330 protocol: protocol,
4331 testType: clientTest,
4332 name: "MinimumVersion-Client2-" + suffix,
4333 config: Config{
4334 MaxVersion: runnerVers.version,
4335 },
David Benjamin87909c02014-12-13 01:55:01 -05004336 flags: []string{"-min-version", shimVersFlag},
4337 expectedVersion: expectedVersion,
4338 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004339 expectedError: expectedClientError,
4340 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004341 })
4342
4343 testCases = append(testCases, testCase{
4344 protocol: protocol,
4345 testType: serverTest,
4346 name: "MinimumVersion-Server-" + suffix,
4347 config: Config{
4348 MaxVersion: runnerVers.version,
4349 },
David Benjamin87909c02014-12-13 01:55:01 -05004350 flags: flags,
4351 expectedVersion: expectedVersion,
4352 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004353 expectedError: expectedServerError,
4354 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004355 })
4356 testCases = append(testCases, testCase{
4357 protocol: protocol,
4358 testType: serverTest,
4359 name: "MinimumVersion-Server2-" + suffix,
4360 config: Config{
4361 MaxVersion: runnerVers.version,
4362 },
David Benjamin87909c02014-12-13 01:55:01 -05004363 flags: []string{"-min-version", shimVersFlag},
4364 expectedVersion: expectedVersion,
4365 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004366 expectedError: expectedServerError,
4367 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004368 })
4369 }
4370 }
4371 }
4372}
4373
David Benjamine78bfde2014-09-06 12:45:15 -04004374func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004375 // TODO(davidben): Extensions, where applicable, all move their server
4376 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4377 // tests for both. Also test interaction with 0-RTT when implemented.
4378
David Benjamin97d17d92016-07-14 16:12:00 -04004379 // Repeat extensions tests all versions except SSL 3.0.
4380 for _, ver := range tlsVersions {
4381 if ver.version == VersionSSL30 {
4382 continue
4383 }
4384
David Benjamin97d17d92016-07-14 16:12:00 -04004385 // Test that duplicate extensions are rejected.
4386 testCases = append(testCases, testCase{
4387 testType: clientTest,
4388 name: "DuplicateExtensionClient-" + ver.name,
4389 config: Config{
4390 MaxVersion: ver.version,
4391 Bugs: ProtocolBugs{
4392 DuplicateExtension: true,
4393 },
David Benjamine78bfde2014-09-06 12:45:15 -04004394 },
David Benjamin97d17d92016-07-14 16:12:00 -04004395 shouldFail: true,
4396 expectedLocalError: "remote error: error decoding message",
4397 })
4398 testCases = append(testCases, testCase{
4399 testType: serverTest,
4400 name: "DuplicateExtensionServer-" + ver.name,
4401 config: Config{
4402 MaxVersion: ver.version,
4403 Bugs: ProtocolBugs{
4404 DuplicateExtension: true,
4405 },
David Benjamine78bfde2014-09-06 12:45:15 -04004406 },
David Benjamin97d17d92016-07-14 16:12:00 -04004407 shouldFail: true,
4408 expectedLocalError: "remote error: error decoding message",
4409 })
4410
4411 // Test SNI.
4412 testCases = append(testCases, testCase{
4413 testType: clientTest,
4414 name: "ServerNameExtensionClient-" + ver.name,
4415 config: Config{
4416 MaxVersion: ver.version,
4417 Bugs: ProtocolBugs{
4418 ExpectServerName: "example.com",
4419 },
David Benjamine78bfde2014-09-06 12:45:15 -04004420 },
David Benjamin97d17d92016-07-14 16:12:00 -04004421 flags: []string{"-host-name", "example.com"},
4422 })
4423 testCases = append(testCases, testCase{
4424 testType: clientTest,
4425 name: "ServerNameExtensionClientMismatch-" + ver.name,
4426 config: Config{
4427 MaxVersion: ver.version,
4428 Bugs: ProtocolBugs{
4429 ExpectServerName: "mismatch.com",
4430 },
David Benjamine78bfde2014-09-06 12:45:15 -04004431 },
David Benjamin97d17d92016-07-14 16:12:00 -04004432 flags: []string{"-host-name", "example.com"},
4433 shouldFail: true,
4434 expectedLocalError: "tls: unexpected server name",
4435 })
4436 testCases = append(testCases, testCase{
4437 testType: clientTest,
4438 name: "ServerNameExtensionClientMissing-" + ver.name,
4439 config: Config{
4440 MaxVersion: ver.version,
4441 Bugs: ProtocolBugs{
4442 ExpectServerName: "missing.com",
4443 },
David Benjamine78bfde2014-09-06 12:45:15 -04004444 },
David Benjamin97d17d92016-07-14 16:12:00 -04004445 shouldFail: true,
4446 expectedLocalError: "tls: unexpected server name",
4447 })
4448 testCases = append(testCases, testCase{
4449 testType: serverTest,
4450 name: "ServerNameExtensionServer-" + ver.name,
4451 config: Config{
4452 MaxVersion: ver.version,
4453 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004454 },
David Benjamin97d17d92016-07-14 16:12:00 -04004455 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004456 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004457 })
4458
4459 // Test ALPN.
4460 testCases = append(testCases, testCase{
4461 testType: clientTest,
4462 name: "ALPNClient-" + ver.name,
4463 config: Config{
4464 MaxVersion: ver.version,
4465 NextProtos: []string{"foo"},
4466 },
4467 flags: []string{
4468 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4469 "-expect-alpn", "foo",
4470 },
4471 expectedNextProto: "foo",
4472 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004473 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004474 })
4475 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004476 testType: clientTest,
4477 name: "ALPNClient-Mismatch-" + ver.name,
4478 config: Config{
4479 MaxVersion: ver.version,
4480 Bugs: ProtocolBugs{
4481 SendALPN: "baz",
4482 },
4483 },
4484 flags: []string{
4485 "-advertise-alpn", "\x03foo\x03bar",
4486 },
4487 shouldFail: true,
4488 expectedError: ":INVALID_ALPN_PROTOCOL:",
4489 expectedLocalError: "remote error: illegal parameter",
4490 })
4491 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004492 testType: serverTest,
4493 name: "ALPNServer-" + ver.name,
4494 config: Config{
4495 MaxVersion: ver.version,
4496 NextProtos: []string{"foo", "bar", "baz"},
4497 },
4498 flags: []string{
4499 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4500 "-select-alpn", "foo",
4501 },
4502 expectedNextProto: "foo",
4503 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004504 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004505 })
4506 testCases = append(testCases, testCase{
4507 testType: serverTest,
4508 name: "ALPNServer-Decline-" + ver.name,
4509 config: Config{
4510 MaxVersion: ver.version,
4511 NextProtos: []string{"foo", "bar", "baz"},
4512 },
4513 flags: []string{"-decline-alpn"},
4514 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004515 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004516 })
4517
David Benjamin25fe85b2016-08-09 20:00:32 -04004518 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4519 // called once.
4520 testCases = append(testCases, testCase{
4521 testType: serverTest,
4522 name: "ALPNServer-Async-" + ver.name,
4523 config: Config{
4524 MaxVersion: ver.version,
4525 NextProtos: []string{"foo", "bar", "baz"},
4526 },
4527 flags: []string{
4528 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4529 "-select-alpn", "foo",
4530 "-async",
4531 },
4532 expectedNextProto: "foo",
4533 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004534 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004535 })
4536
David Benjamin97d17d92016-07-14 16:12:00 -04004537 var emptyString string
4538 testCases = append(testCases, testCase{
4539 testType: clientTest,
4540 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4541 config: Config{
4542 MaxVersion: ver.version,
4543 NextProtos: []string{""},
4544 Bugs: ProtocolBugs{
4545 // A server returning an empty ALPN protocol
4546 // should be rejected.
4547 ALPNProtocol: &emptyString,
4548 },
4549 },
4550 flags: []string{
4551 "-advertise-alpn", "\x03foo",
4552 },
4553 shouldFail: true,
4554 expectedError: ":PARSE_TLSEXT:",
4555 })
4556 testCases = append(testCases, testCase{
4557 testType: serverTest,
4558 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4559 config: Config{
4560 MaxVersion: ver.version,
4561 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004562 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004563 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004564 },
David Benjamin97d17d92016-07-14 16:12:00 -04004565 flags: []string{
4566 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004567 },
David Benjamin97d17d92016-07-14 16:12:00 -04004568 shouldFail: true,
4569 expectedError: ":PARSE_TLSEXT:",
4570 })
4571
4572 // Test NPN and the interaction with ALPN.
4573 if ver.version < VersionTLS13 {
4574 // Test that the server prefers ALPN over NPN.
4575 testCases = append(testCases, testCase{
4576 testType: serverTest,
4577 name: "ALPNServer-Preferred-" + ver.name,
4578 config: Config{
4579 MaxVersion: ver.version,
4580 NextProtos: []string{"foo", "bar", "baz"},
4581 },
4582 flags: []string{
4583 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4584 "-select-alpn", "foo",
4585 "-advertise-npn", "\x03foo\x03bar\x03baz",
4586 },
4587 expectedNextProto: "foo",
4588 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004589 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004590 })
4591 testCases = append(testCases, testCase{
4592 testType: serverTest,
4593 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4594 config: Config{
4595 MaxVersion: ver.version,
4596 NextProtos: []string{"foo", "bar", "baz"},
4597 Bugs: ProtocolBugs{
4598 SwapNPNAndALPN: true,
4599 },
4600 },
4601 flags: []string{
4602 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4603 "-select-alpn", "foo",
4604 "-advertise-npn", "\x03foo\x03bar\x03baz",
4605 },
4606 expectedNextProto: "foo",
4607 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004608 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004609 })
4610
4611 // Test that negotiating both NPN and ALPN is forbidden.
4612 testCases = append(testCases, testCase{
4613 name: "NegotiateALPNAndNPN-" + ver.name,
4614 config: Config{
4615 MaxVersion: ver.version,
4616 NextProtos: []string{"foo", "bar", "baz"},
4617 Bugs: ProtocolBugs{
4618 NegotiateALPNAndNPN: true,
4619 },
4620 },
4621 flags: []string{
4622 "-advertise-alpn", "\x03foo",
4623 "-select-next-proto", "foo",
4624 },
4625 shouldFail: true,
4626 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4627 })
4628 testCases = append(testCases, testCase{
4629 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4630 config: Config{
4631 MaxVersion: ver.version,
4632 NextProtos: []string{"foo", "bar", "baz"},
4633 Bugs: ProtocolBugs{
4634 NegotiateALPNAndNPN: true,
4635 SwapNPNAndALPN: true,
4636 },
4637 },
4638 flags: []string{
4639 "-advertise-alpn", "\x03foo",
4640 "-select-next-proto", "foo",
4641 },
4642 shouldFail: true,
4643 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4644 })
4645
4646 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4647 testCases = append(testCases, testCase{
4648 name: "DisableNPN-" + ver.name,
4649 config: Config{
4650 MaxVersion: ver.version,
4651 NextProtos: []string{"foo"},
4652 },
4653 flags: []string{
4654 "-select-next-proto", "foo",
4655 "-disable-npn",
4656 },
4657 expectNoNextProto: true,
4658 })
4659 }
4660
4661 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004662
4663 // Resume with a corrupt ticket.
4664 testCases = append(testCases, testCase{
4665 testType: serverTest,
4666 name: "CorruptTicket-" + ver.name,
4667 config: Config{
4668 MaxVersion: ver.version,
4669 Bugs: ProtocolBugs{
4670 CorruptTicket: true,
4671 },
4672 },
4673 resumeSession: true,
4674 expectResumeRejected: true,
4675 })
4676 // Test the ticket callback, with and without renewal.
4677 testCases = append(testCases, testCase{
4678 testType: serverTest,
4679 name: "TicketCallback-" + ver.name,
4680 config: Config{
4681 MaxVersion: ver.version,
4682 },
4683 resumeSession: true,
4684 flags: []string{"-use-ticket-callback"},
4685 })
4686 testCases = append(testCases, testCase{
4687 testType: serverTest,
4688 name: "TicketCallback-Renew-" + ver.name,
4689 config: Config{
4690 MaxVersion: ver.version,
4691 Bugs: ProtocolBugs{
4692 ExpectNewTicket: true,
4693 },
4694 },
4695 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4696 resumeSession: true,
4697 })
4698
4699 // Test that the ticket callback is only called once when everything before
4700 // it in the ClientHello is asynchronous. This corrupts the ticket so
4701 // certificate selection callbacks run.
4702 testCases = append(testCases, testCase{
4703 testType: serverTest,
4704 name: "TicketCallback-SingleCall-" + ver.name,
4705 config: Config{
4706 MaxVersion: ver.version,
4707 Bugs: ProtocolBugs{
4708 CorruptTicket: true,
4709 },
4710 },
4711 resumeSession: true,
4712 expectResumeRejected: true,
4713 flags: []string{
4714 "-use-ticket-callback",
4715 "-async",
4716 },
4717 })
4718
4719 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004720 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004721 testCases = append(testCases, testCase{
4722 testType: serverTest,
4723 name: "OversizedSessionId-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 Bugs: ProtocolBugs{
4727 OversizedSessionId: true,
4728 },
4729 },
4730 resumeSession: true,
4731 shouldFail: true,
4732 expectedError: ":DECODE_ERROR:",
4733 })
4734 }
4735
4736 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4737 // are ignored.
4738 if ver.hasDTLS {
4739 testCases = append(testCases, testCase{
4740 protocol: dtls,
4741 name: "SRTP-Client-" + ver.name,
4742 config: Config{
4743 MaxVersion: ver.version,
4744 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4745 },
4746 flags: []string{
4747 "-srtp-profiles",
4748 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4749 },
4750 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4751 })
4752 testCases = append(testCases, testCase{
4753 protocol: dtls,
4754 testType: serverTest,
4755 name: "SRTP-Server-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
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 the MKI is ignored.
4767 testCases = append(testCases, testCase{
4768 protocol: dtls,
4769 testType: serverTest,
4770 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4771 config: Config{
4772 MaxVersion: ver.version,
4773 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4774 Bugs: ProtocolBugs{
4775 SRTPMasterKeyIdentifer: "bogus",
4776 },
4777 },
4778 flags: []string{
4779 "-srtp-profiles",
4780 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4781 },
4782 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4783 })
4784 // Test that SRTP isn't negotiated on the server if there were
4785 // no matching profiles.
4786 testCases = append(testCases, testCase{
4787 protocol: dtls,
4788 testType: serverTest,
4789 name: "SRTP-Server-NoMatch-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 SRTPProtectionProfiles: []uint16{100, 101, 102},
4793 },
4794 flags: []string{
4795 "-srtp-profiles",
4796 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4797 },
4798 expectedSRTPProtectionProfile: 0,
4799 })
4800 // Test that the server returning an invalid SRTP profile is
4801 // flagged as an error by the client.
4802 testCases = append(testCases, testCase{
4803 protocol: dtls,
4804 name: "SRTP-Client-NoMatch-" + ver.name,
4805 config: Config{
4806 MaxVersion: ver.version,
4807 Bugs: ProtocolBugs{
4808 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4809 },
4810 },
4811 flags: []string{
4812 "-srtp-profiles",
4813 "SRTP_AES128_CM_SHA1_80",
4814 },
4815 shouldFail: true,
4816 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4817 })
4818 }
4819
4820 // Test SCT list.
4821 testCases = append(testCases, testCase{
4822 name: "SignedCertificateTimestampList-Client-" + ver.name,
4823 testType: clientTest,
4824 config: Config{
4825 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004826 },
David Benjamin97d17d92016-07-14 16:12:00 -04004827 flags: []string{
4828 "-enable-signed-cert-timestamps",
4829 "-expect-signed-cert-timestamps",
4830 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004831 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004832 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004833 })
4834 testCases = append(testCases, testCase{
4835 name: "SendSCTListOnResume-" + ver.name,
4836 config: Config{
4837 MaxVersion: ver.version,
4838 Bugs: ProtocolBugs{
4839 SendSCTListOnResume: []byte("bogus"),
4840 },
David Benjamind98452d2015-06-16 14:16:23 -04004841 },
David Benjamin97d17d92016-07-14 16:12:00 -04004842 flags: []string{
4843 "-enable-signed-cert-timestamps",
4844 "-expect-signed-cert-timestamps",
4845 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004846 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004847 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004848 })
4849 testCases = append(testCases, testCase{
4850 name: "SignedCertificateTimestampList-Server-" + ver.name,
4851 testType: serverTest,
4852 config: Config{
4853 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004854 },
David Benjamin97d17d92016-07-14 16:12:00 -04004855 flags: []string{
4856 "-signed-cert-timestamps",
4857 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004858 },
David Benjamin97d17d92016-07-14 16:12:00 -04004859 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004860 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004861 })
4862 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004863
Paul Lietar4fac72e2015-09-09 13:44:55 +01004864 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004865 testType: clientTest,
4866 name: "ClientHelloPadding",
4867 config: Config{
4868 Bugs: ProtocolBugs{
4869 RequireClientHelloSize: 512,
4870 },
4871 },
4872 // This hostname just needs to be long enough to push the
4873 // ClientHello into F5's danger zone between 256 and 511 bytes
4874 // long.
4875 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4876 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004877
4878 // Extensions should not function in SSL 3.0.
4879 testCases = append(testCases, testCase{
4880 testType: serverTest,
4881 name: "SSLv3Extensions-NoALPN",
4882 config: Config{
4883 MaxVersion: VersionSSL30,
4884 NextProtos: []string{"foo", "bar", "baz"},
4885 },
4886 flags: []string{
4887 "-select-alpn", "foo",
4888 },
4889 expectNoNextProto: true,
4890 })
4891
4892 // Test session tickets separately as they follow a different codepath.
4893 testCases = append(testCases, testCase{
4894 testType: serverTest,
4895 name: "SSLv3Extensions-NoTickets",
4896 config: Config{
4897 MaxVersion: VersionSSL30,
4898 Bugs: ProtocolBugs{
4899 // Historically, session tickets in SSL 3.0
4900 // failed in different ways depending on whether
4901 // the client supported renegotiation_info.
4902 NoRenegotiationInfo: true,
4903 },
4904 },
4905 resumeSession: true,
4906 })
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "SSLv3Extensions-NoTickets2",
4910 config: Config{
4911 MaxVersion: VersionSSL30,
4912 },
4913 resumeSession: true,
4914 })
4915
4916 // But SSL 3.0 does send and process renegotiation_info.
4917 testCases = append(testCases, testCase{
4918 testType: serverTest,
4919 name: "SSLv3Extensions-RenegotiationInfo",
4920 config: Config{
4921 MaxVersion: VersionSSL30,
4922 Bugs: ProtocolBugs{
4923 RequireRenegotiationInfo: true,
4924 },
4925 },
4926 })
4927 testCases = append(testCases, testCase{
4928 testType: serverTest,
4929 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4930 config: Config{
4931 MaxVersion: VersionSSL30,
4932 Bugs: ProtocolBugs{
4933 NoRenegotiationInfo: true,
4934 SendRenegotiationSCSV: true,
4935 RequireRenegotiationInfo: true,
4936 },
4937 },
4938 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004939
4940 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4941 // in ServerHello.
4942 testCases = append(testCases, testCase{
4943 name: "NPN-Forbidden-TLS13",
4944 config: Config{
4945 MaxVersion: VersionTLS13,
4946 NextProtos: []string{"foo"},
4947 Bugs: ProtocolBugs{
4948 NegotiateNPNAtAllVersions: true,
4949 },
4950 },
4951 flags: []string{"-select-next-proto", "foo"},
4952 shouldFail: true,
4953 expectedError: ":ERROR_PARSING_EXTENSION:",
4954 })
4955 testCases = append(testCases, testCase{
4956 name: "EMS-Forbidden-TLS13",
4957 config: Config{
4958 MaxVersion: VersionTLS13,
4959 Bugs: ProtocolBugs{
4960 NegotiateEMSAtAllVersions: true,
4961 },
4962 },
4963 shouldFail: true,
4964 expectedError: ":ERROR_PARSING_EXTENSION:",
4965 })
4966 testCases = append(testCases, testCase{
4967 name: "RenegotiationInfo-Forbidden-TLS13",
4968 config: Config{
4969 MaxVersion: VersionTLS13,
4970 Bugs: ProtocolBugs{
4971 NegotiateRenegotiationInfoAtAllVersions: true,
4972 },
4973 },
4974 shouldFail: true,
4975 expectedError: ":ERROR_PARSING_EXTENSION:",
4976 })
4977 testCases = append(testCases, testCase{
4978 name: "ChannelID-Forbidden-TLS13",
4979 config: Config{
4980 MaxVersion: VersionTLS13,
4981 RequestChannelID: true,
4982 Bugs: ProtocolBugs{
4983 NegotiateChannelIDAtAllVersions: true,
4984 },
4985 },
4986 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4987 shouldFail: true,
4988 expectedError: ":ERROR_PARSING_EXTENSION:",
4989 })
4990 testCases = append(testCases, testCase{
4991 name: "Ticket-Forbidden-TLS13",
4992 config: Config{
4993 MaxVersion: VersionTLS12,
4994 },
4995 resumeConfig: &Config{
4996 MaxVersion: VersionTLS13,
4997 Bugs: ProtocolBugs{
4998 AdvertiseTicketExtension: true,
4999 },
5000 },
5001 resumeSession: true,
5002 shouldFail: true,
5003 expectedError: ":ERROR_PARSING_EXTENSION:",
5004 })
5005
5006 // Test that illegal extensions in TLS 1.3 are declined by the server if
5007 // offered in ClientHello. The runner's server will fail if this occurs,
5008 // so we exercise the offering path. (EMS and Renegotiation Info are
5009 // implicit in every test.)
5010 testCases = append(testCases, testCase{
5011 testType: serverTest,
5012 name: "ChannelID-Declined-TLS13",
5013 config: Config{
5014 MaxVersion: VersionTLS13,
5015 ChannelID: channelIDKey,
5016 },
5017 flags: []string{"-enable-channel-id"},
5018 })
5019 testCases = append(testCases, testCase{
5020 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005021 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005022 config: Config{
5023 MaxVersion: VersionTLS13,
5024 NextProtos: []string{"bar"},
5025 },
5026 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5027 })
David Benjamin196df5b2016-09-21 16:23:27 -04005028
5029 testCases = append(testCases, testCase{
5030 testType: serverTest,
5031 name: "InvalidChannelIDSignature",
5032 config: Config{
5033 MaxVersion: VersionTLS12,
5034 ChannelID: channelIDKey,
5035 Bugs: ProtocolBugs{
5036 InvalidChannelIDSignature: true,
5037 },
5038 },
5039 flags: []string{"-enable-channel-id"},
5040 shouldFail: true,
5041 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5042 expectedLocalError: "remote error: error decrypting message",
5043 })
David Benjamine78bfde2014-09-06 12:45:15 -04005044}
5045
David Benjamin01fe8202014-09-24 15:21:44 -04005046func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005047 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005048 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005049 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5050 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5051 // TLS 1.3 only shares ciphers with TLS 1.2, so
5052 // we skip certain combinations and use a
5053 // different cipher to test with.
5054 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5055 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5056 continue
5057 }
5058 }
5059
David Benjamin8b8c0062014-11-23 02:47:52 -05005060 protocols := []protocol{tls}
5061 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5062 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005063 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 for _, protocol := range protocols {
5065 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5066 if protocol == dtls {
5067 suffix += "-DTLS"
5068 }
5069
David Benjaminece3de92015-03-16 18:02:20 -04005070 if sessionVers.version == resumeVers.version {
5071 testCases = append(testCases, testCase{
5072 protocol: protocol,
5073 name: "Resume-Client" + suffix,
5074 resumeSession: true,
5075 config: Config{
5076 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005077 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005078 Bugs: ProtocolBugs{
5079 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5080 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5081 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005082 },
David Benjaminece3de92015-03-16 18:02:20 -04005083 expectedVersion: sessionVers.version,
5084 expectedResumeVersion: resumeVers.version,
5085 })
5086 } else {
David Benjamin405da482016-08-08 17:25:07 -04005087 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5088
5089 // Offering a TLS 1.3 session sends an empty session ID, so
5090 // there is no way to convince a non-lookahead client the
5091 // session was resumed. It will appear to the client that a
5092 // stray ChangeCipherSpec was sent.
5093 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5094 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005095 }
5096
David Benjaminece3de92015-03-16 18:02:20 -04005097 testCases = append(testCases, testCase{
5098 protocol: protocol,
5099 name: "Resume-Client-Mismatch" + suffix,
5100 resumeSession: true,
5101 config: Config{
5102 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005103 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005104 },
David Benjaminece3de92015-03-16 18:02:20 -04005105 expectedVersion: sessionVers.version,
5106 resumeConfig: &Config{
5107 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005108 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005109 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005110 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005111 },
5112 },
5113 expectedResumeVersion: resumeVers.version,
5114 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005115 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005116 })
5117 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005118
5119 testCases = append(testCases, testCase{
5120 protocol: protocol,
5121 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005122 resumeSession: true,
5123 config: Config{
5124 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005125 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005126 },
5127 expectedVersion: sessionVers.version,
5128 resumeConfig: &Config{
5129 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005130 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005131 },
5132 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005133 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005134 expectedResumeVersion: resumeVers.version,
5135 })
5136
David Benjamin8b8c0062014-11-23 02:47:52 -05005137 testCases = append(testCases, testCase{
5138 protocol: protocol,
5139 testType: serverTest,
5140 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005141 resumeSession: true,
5142 config: Config{
5143 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005144 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005145 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005146 expectedVersion: sessionVers.version,
5147 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005148 resumeConfig: &Config{
5149 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005150 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005151 Bugs: ProtocolBugs{
5152 SendBothTickets: true,
5153 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005154 },
5155 expectedResumeVersion: resumeVers.version,
5156 })
5157 }
David Benjamin01fe8202014-09-24 15:21:44 -04005158 }
5159 }
David Benjaminece3de92015-03-16 18:02:20 -04005160
5161 testCases = append(testCases, testCase{
5162 name: "Resume-Client-CipherMismatch",
5163 resumeSession: true,
5164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005165 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005166 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5167 },
5168 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005169 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005170 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5171 Bugs: ProtocolBugs{
5172 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5173 },
5174 },
5175 shouldFail: true,
5176 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5177 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005178
5179 testCases = append(testCases, testCase{
5180 name: "Resume-Client-CipherMismatch-TLS13",
5181 resumeSession: true,
5182 config: Config{
5183 MaxVersion: VersionTLS13,
5184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5185 },
5186 resumeConfig: &Config{
5187 MaxVersion: VersionTLS13,
5188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5189 Bugs: ProtocolBugs{
5190 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5191 },
5192 },
5193 shouldFail: true,
5194 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5195 })
David Benjamin01fe8202014-09-24 15:21:44 -04005196}
5197
Adam Langley2ae77d22014-10-28 17:29:33 -07005198func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005199 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005200 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005201 testType: serverTest,
5202 name: "Renegotiate-Server-Forbidden",
5203 config: Config{
5204 MaxVersion: VersionTLS12,
5205 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005206 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005207 shouldFail: true,
5208 expectedError: ":NO_RENEGOTIATION:",
5209 expectedLocalError: "remote error: no renegotiation",
5210 })
Adam Langley5021b222015-06-12 18:27:58 -07005211 // The server shouldn't echo the renegotiation extension unless
5212 // requested by the client.
5213 testCases = append(testCases, testCase{
5214 testType: serverTest,
5215 name: "Renegotiate-Server-NoExt",
5216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005217 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005218 Bugs: ProtocolBugs{
5219 NoRenegotiationInfo: true,
5220 RequireRenegotiationInfo: true,
5221 },
5222 },
5223 shouldFail: true,
5224 expectedLocalError: "renegotiation extension missing",
5225 })
5226 // The renegotiation SCSV should be sufficient for the server to echo
5227 // the extension.
5228 testCases = append(testCases, testCase{
5229 testType: serverTest,
5230 name: "Renegotiate-Server-NoExt-SCSV",
5231 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005232 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005233 Bugs: ProtocolBugs{
5234 NoRenegotiationInfo: true,
5235 SendRenegotiationSCSV: true,
5236 RequireRenegotiationInfo: true,
5237 },
5238 },
5239 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005240 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005241 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005243 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005244 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005245 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005246 },
5247 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005248 renegotiate: 1,
5249 flags: []string{
5250 "-renegotiate-freely",
5251 "-expect-total-renegotiations", "1",
5252 },
David Benjamincdea40c2015-03-19 14:09:43 -04005253 })
5254 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005255 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005256 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005257 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005258 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005259 Bugs: ProtocolBugs{
5260 EmptyRenegotiationInfo: true,
5261 },
5262 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005263 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005264 shouldFail: true,
5265 expectedError: ":RENEGOTIATION_MISMATCH:",
5266 })
5267 testCases = append(testCases, testCase{
5268 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005269 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005271 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005272 Bugs: ProtocolBugs{
5273 BadRenegotiationInfo: true,
5274 },
5275 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005276 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005277 shouldFail: true,
5278 expectedError: ":RENEGOTIATION_MISMATCH:",
5279 })
5280 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005281 name: "Renegotiate-Client-Downgrade",
5282 renegotiate: 1,
5283 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005284 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005285 Bugs: ProtocolBugs{
5286 NoRenegotiationInfoAfterInitial: true,
5287 },
5288 },
5289 flags: []string{"-renegotiate-freely"},
5290 shouldFail: true,
5291 expectedError: ":RENEGOTIATION_MISMATCH:",
5292 })
5293 testCases = append(testCases, testCase{
5294 name: "Renegotiate-Client-Upgrade",
5295 renegotiate: 1,
5296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005297 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005298 Bugs: ProtocolBugs{
5299 NoRenegotiationInfoInInitial: true,
5300 },
5301 },
5302 flags: []string{"-renegotiate-freely"},
5303 shouldFail: true,
5304 expectedError: ":RENEGOTIATION_MISMATCH:",
5305 })
5306 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005307 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005308 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005309 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005310 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005311 Bugs: ProtocolBugs{
5312 NoRenegotiationInfo: true,
5313 },
5314 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005315 flags: []string{
5316 "-renegotiate-freely",
5317 "-expect-total-renegotiations", "1",
5318 },
David Benjamincff0b902015-05-15 23:09:47 -04005319 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005320
5321 // Test that the server may switch ciphers on renegotiation without
5322 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005323 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005324 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005325 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005326 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005327 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005328 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005329 },
5330 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005331 flags: []string{
5332 "-renegotiate-freely",
5333 "-expect-total-renegotiations", "1",
5334 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005335 })
5336 testCases = append(testCases, testCase{
5337 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005338 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005339 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005340 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5342 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005343 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005344 flags: []string{
5345 "-renegotiate-freely",
5346 "-expect-total-renegotiations", "1",
5347 },
David Benjaminb16346b2015-04-08 19:16:58 -04005348 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005349
5350 // Test that the server may not switch versions on renegotiation.
5351 testCases = append(testCases, testCase{
5352 name: "Renegotiate-Client-SwitchVersion",
5353 config: Config{
5354 MaxVersion: VersionTLS12,
5355 // Pick a cipher which exists at both versions.
5356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5357 Bugs: ProtocolBugs{
5358 NegotiateVersionOnRenego: VersionTLS11,
5359 },
5360 },
5361 renegotiate: 1,
5362 flags: []string{
5363 "-renegotiate-freely",
5364 "-expect-total-renegotiations", "1",
5365 },
5366 shouldFail: true,
5367 expectedError: ":WRONG_SSL_VERSION:",
5368 })
5369
David Benjaminb16346b2015-04-08 19:16:58 -04005370 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005371 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005372 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005373 config: Config{
5374 MaxVersion: VersionTLS10,
5375 Bugs: ProtocolBugs{
5376 RequireSameRenegoClientVersion: true,
5377 },
5378 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005379 flags: []string{
5380 "-renegotiate-freely",
5381 "-expect-total-renegotiations", "1",
5382 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005383 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005384 testCases = append(testCases, testCase{
5385 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005386 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005387 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005388 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005389 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5390 NextProtos: []string{"foo"},
5391 },
5392 flags: []string{
5393 "-false-start",
5394 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005395 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005396 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005397 },
5398 shimWritesFirst: true,
5399 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005400
5401 // Client-side renegotiation controls.
5402 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005403 name: "Renegotiate-Client-Forbidden-1",
5404 config: Config{
5405 MaxVersion: VersionTLS12,
5406 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005407 renegotiate: 1,
5408 shouldFail: true,
5409 expectedError: ":NO_RENEGOTIATION:",
5410 expectedLocalError: "remote error: no renegotiation",
5411 })
5412 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005413 name: "Renegotiate-Client-Once-1",
5414 config: Config{
5415 MaxVersion: VersionTLS12,
5416 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005417 renegotiate: 1,
5418 flags: []string{
5419 "-renegotiate-once",
5420 "-expect-total-renegotiations", "1",
5421 },
5422 })
5423 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005424 name: "Renegotiate-Client-Freely-1",
5425 config: Config{
5426 MaxVersion: VersionTLS12,
5427 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005428 renegotiate: 1,
5429 flags: []string{
5430 "-renegotiate-freely",
5431 "-expect-total-renegotiations", "1",
5432 },
5433 })
5434 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005435 name: "Renegotiate-Client-Once-2",
5436 config: Config{
5437 MaxVersion: VersionTLS12,
5438 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005439 renegotiate: 2,
5440 flags: []string{"-renegotiate-once"},
5441 shouldFail: true,
5442 expectedError: ":NO_RENEGOTIATION:",
5443 expectedLocalError: "remote error: no renegotiation",
5444 })
5445 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005446 name: "Renegotiate-Client-Freely-2",
5447 config: Config{
5448 MaxVersion: VersionTLS12,
5449 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005450 renegotiate: 2,
5451 flags: []string{
5452 "-renegotiate-freely",
5453 "-expect-total-renegotiations", "2",
5454 },
5455 })
Adam Langley27a0d082015-11-03 13:34:10 -08005456 testCases = append(testCases, testCase{
5457 name: "Renegotiate-Client-NoIgnore",
5458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005459 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005460 Bugs: ProtocolBugs{
5461 SendHelloRequestBeforeEveryAppDataRecord: true,
5462 },
5463 },
5464 shouldFail: true,
5465 expectedError: ":NO_RENEGOTIATION:",
5466 })
5467 testCases = append(testCases, testCase{
5468 name: "Renegotiate-Client-Ignore",
5469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005470 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005471 Bugs: ProtocolBugs{
5472 SendHelloRequestBeforeEveryAppDataRecord: true,
5473 },
5474 },
5475 flags: []string{
5476 "-renegotiate-ignore",
5477 "-expect-total-renegotiations", "0",
5478 },
5479 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005480
David Benjamin397c8e62016-07-08 14:14:36 -07005481 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005482 testCases = append(testCases, testCase{
5483 name: "StrayHelloRequest",
5484 config: Config{
5485 MaxVersion: VersionTLS12,
5486 Bugs: ProtocolBugs{
5487 SendHelloRequestBeforeEveryHandshakeMessage: true,
5488 },
5489 },
5490 })
5491 testCases = append(testCases, testCase{
5492 name: "StrayHelloRequest-Packed",
5493 config: Config{
5494 MaxVersion: VersionTLS12,
5495 Bugs: ProtocolBugs{
5496 PackHandshakeFlight: true,
5497 SendHelloRequestBeforeEveryHandshakeMessage: true,
5498 },
5499 },
5500 })
5501
David Benjamin12d2c482016-07-24 10:56:51 -04005502 // Test renegotiation works if HelloRequest and server Finished come in
5503 // the same record.
5504 testCases = append(testCases, testCase{
5505 name: "Renegotiate-Client-Packed",
5506 config: Config{
5507 MaxVersion: VersionTLS12,
5508 Bugs: ProtocolBugs{
5509 PackHandshakeFlight: true,
5510 PackHelloRequestWithFinished: true,
5511 },
5512 },
5513 renegotiate: 1,
5514 flags: []string{
5515 "-renegotiate-freely",
5516 "-expect-total-renegotiations", "1",
5517 },
5518 })
5519
David Benjamin397c8e62016-07-08 14:14:36 -07005520 // Renegotiation is forbidden in TLS 1.3.
5521 testCases = append(testCases, testCase{
5522 name: "Renegotiate-Client-TLS13",
5523 config: Config{
5524 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005525 Bugs: ProtocolBugs{
5526 SendHelloRequestBeforeEveryAppDataRecord: true,
5527 },
David Benjamin397c8e62016-07-08 14:14:36 -07005528 },
David Benjamin397c8e62016-07-08 14:14:36 -07005529 flags: []string{
5530 "-renegotiate-freely",
5531 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005532 shouldFail: true,
5533 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005534 })
5535
5536 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5537 testCases = append(testCases, testCase{
5538 name: "StrayHelloRequest-TLS13",
5539 config: Config{
5540 MaxVersion: VersionTLS13,
5541 Bugs: ProtocolBugs{
5542 SendHelloRequestBeforeEveryHandshakeMessage: true,
5543 },
5544 },
5545 shouldFail: true,
5546 expectedError: ":UNEXPECTED_MESSAGE:",
5547 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005548}
5549
David Benjamin5e961c12014-11-07 01:48:35 -05005550func addDTLSReplayTests() {
5551 // Test that sequence number replays are detected.
5552 testCases = append(testCases, testCase{
5553 protocol: dtls,
5554 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005555 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005556 replayWrites: true,
5557 })
5558
David Benjamin8e6db492015-07-25 18:29:23 -04005559 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005560 // than the retransmit window.
5561 testCases = append(testCases, testCase{
5562 protocol: dtls,
5563 name: "DTLS-Replay-LargeGaps",
5564 config: Config{
5565 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005566 SequenceNumberMapping: func(in uint64) uint64 {
5567 return in * 127
5568 },
David Benjamin5e961c12014-11-07 01:48:35 -05005569 },
5570 },
David Benjamin8e6db492015-07-25 18:29:23 -04005571 messageCount: 200,
5572 replayWrites: true,
5573 })
5574
5575 // Test the incoming sequence number changing non-monotonically.
5576 testCases = append(testCases, testCase{
5577 protocol: dtls,
5578 name: "DTLS-Replay-NonMonotonic",
5579 config: Config{
5580 Bugs: ProtocolBugs{
5581 SequenceNumberMapping: func(in uint64) uint64 {
5582 return in ^ 31
5583 },
5584 },
5585 },
5586 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005587 replayWrites: true,
5588 })
5589}
5590
Nick Harper60edffd2016-06-21 15:19:24 -07005591var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005592 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005593 id signatureAlgorithm
5594 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005595}{
Nick Harper60edffd2016-06-21 15:19:24 -07005596 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5597 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5598 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5599 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005600 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005601 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5602 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5603 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005604 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5605 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5606 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005607 // Tests for key types prior to TLS 1.2.
5608 {"RSA", 0, testCertRSA},
5609 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005610}
5611
Nick Harper60edffd2016-06-21 15:19:24 -07005612const fakeSigAlg1 signatureAlgorithm = 0x2a01
5613const fakeSigAlg2 signatureAlgorithm = 0xff01
5614
5615func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005616 // Not all ciphers involve a signature. Advertise a list which gives all
5617 // versions a signing cipher.
5618 signingCiphers := []uint16{
5619 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5620 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5621 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5622 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5623 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5624 }
5625
David Benjaminca3d5452016-07-14 12:51:01 -04005626 var allAlgorithms []signatureAlgorithm
5627 for _, alg := range testSignatureAlgorithms {
5628 if alg.id != 0 {
5629 allAlgorithms = append(allAlgorithms, alg.id)
5630 }
5631 }
5632
Nick Harper60edffd2016-06-21 15:19:24 -07005633 // Make sure each signature algorithm works. Include some fake values in
5634 // the list and ensure they're ignored.
5635 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005636 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005637 if (ver.version < VersionTLS12) != (alg.id == 0) {
5638 continue
5639 }
5640
5641 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5642 // or remove it in C.
5643 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005644 continue
5645 }
Nick Harper60edffd2016-06-21 15:19:24 -07005646
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005647 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005648 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005649 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5650 shouldFail = true
5651 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005652 // RSA-PKCS1 does not exist in TLS 1.3.
5653 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5654 shouldFail = true
5655 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005656
5657 var signError, verifyError string
5658 if shouldFail {
5659 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5660 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005661 }
David Benjamin000800a2014-11-14 01:43:59 -05005662
David Benjamin1fb125c2016-07-08 18:52:12 -07005663 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005664
David Benjamin7a41d372016-07-09 11:21:54 -07005665 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005666 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005667 config: Config{
5668 MaxVersion: ver.version,
5669 ClientAuth: RequireAnyClientCert,
5670 VerifySignatureAlgorithms: []signatureAlgorithm{
5671 fakeSigAlg1,
5672 alg.id,
5673 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005674 },
David Benjamin7a41d372016-07-09 11:21:54 -07005675 },
5676 flags: []string{
5677 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5678 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5679 "-enable-all-curves",
5680 },
5681 shouldFail: shouldFail,
5682 expectedError: signError,
5683 expectedPeerSignatureAlgorithm: alg.id,
5684 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005685
David Benjamin7a41d372016-07-09 11:21:54 -07005686 testCases = append(testCases, testCase{
5687 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005688 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005689 config: Config{
5690 MaxVersion: ver.version,
5691 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5692 SignSignatureAlgorithms: []signatureAlgorithm{
5693 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005694 },
David Benjamin7a41d372016-07-09 11:21:54 -07005695 Bugs: ProtocolBugs{
5696 SkipECDSACurveCheck: shouldFail,
5697 IgnoreSignatureVersionChecks: shouldFail,
5698 // The client won't advertise 1.3-only algorithms after
5699 // version negotiation.
5700 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005701 },
David Benjamin7a41d372016-07-09 11:21:54 -07005702 },
5703 flags: []string{
5704 "-require-any-client-certificate",
5705 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5706 "-enable-all-curves",
5707 },
5708 shouldFail: shouldFail,
5709 expectedError: verifyError,
5710 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005711
5712 testCases = append(testCases, testCase{
5713 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005714 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005715 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005716 MaxVersion: ver.version,
5717 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005718 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005719 fakeSigAlg1,
5720 alg.id,
5721 fakeSigAlg2,
5722 },
5723 },
5724 flags: []string{
5725 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5726 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5727 "-enable-all-curves",
5728 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005729 shouldFail: shouldFail,
5730 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005731 expectedPeerSignatureAlgorithm: alg.id,
5732 })
5733
5734 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005735 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005736 config: Config{
5737 MaxVersion: ver.version,
5738 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005739 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005740 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005741 alg.id,
5742 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005743 Bugs: ProtocolBugs{
5744 SkipECDSACurveCheck: shouldFail,
5745 IgnoreSignatureVersionChecks: shouldFail,
5746 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005747 },
5748 flags: []string{
5749 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5750 "-enable-all-curves",
5751 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005752 shouldFail: shouldFail,
5753 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005754 })
David Benjamin5208fd42016-07-13 21:43:25 -04005755
5756 if !shouldFail {
5757 testCases = append(testCases, testCase{
5758 testType: serverTest,
5759 name: "ClientAuth-InvalidSignature" + suffix,
5760 config: Config{
5761 MaxVersion: ver.version,
5762 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5763 SignSignatureAlgorithms: []signatureAlgorithm{
5764 alg.id,
5765 },
5766 Bugs: ProtocolBugs{
5767 InvalidSignature: true,
5768 },
5769 },
5770 flags: []string{
5771 "-require-any-client-certificate",
5772 "-enable-all-curves",
5773 },
5774 shouldFail: true,
5775 expectedError: ":BAD_SIGNATURE:",
5776 })
5777
5778 testCases = append(testCases, testCase{
5779 name: "ServerAuth-InvalidSignature" + suffix,
5780 config: Config{
5781 MaxVersion: ver.version,
5782 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5783 CipherSuites: signingCiphers,
5784 SignSignatureAlgorithms: []signatureAlgorithm{
5785 alg.id,
5786 },
5787 Bugs: ProtocolBugs{
5788 InvalidSignature: true,
5789 },
5790 },
5791 flags: []string{"-enable-all-curves"},
5792 shouldFail: true,
5793 expectedError: ":BAD_SIGNATURE:",
5794 })
5795 }
David Benjaminca3d5452016-07-14 12:51:01 -04005796
5797 if ver.version >= VersionTLS12 && !shouldFail {
5798 testCases = append(testCases, testCase{
5799 name: "ClientAuth-Sign-Negotiate" + suffix,
5800 config: Config{
5801 MaxVersion: ver.version,
5802 ClientAuth: RequireAnyClientCert,
5803 VerifySignatureAlgorithms: allAlgorithms,
5804 },
5805 flags: []string{
5806 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5807 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5808 "-enable-all-curves",
5809 "-signing-prefs", strconv.Itoa(int(alg.id)),
5810 },
5811 expectedPeerSignatureAlgorithm: alg.id,
5812 })
5813
5814 testCases = append(testCases, testCase{
5815 testType: serverTest,
5816 name: "ServerAuth-Sign-Negotiate" + suffix,
5817 config: Config{
5818 MaxVersion: ver.version,
5819 CipherSuites: signingCiphers,
5820 VerifySignatureAlgorithms: allAlgorithms,
5821 },
5822 flags: []string{
5823 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5824 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5825 "-enable-all-curves",
5826 "-signing-prefs", strconv.Itoa(int(alg.id)),
5827 },
5828 expectedPeerSignatureAlgorithm: alg.id,
5829 })
5830 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005831 }
David Benjamin000800a2014-11-14 01:43:59 -05005832 }
5833
Nick Harper60edffd2016-06-21 15:19:24 -07005834 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005835 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005836 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005837 config: Config{
5838 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005839 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005840 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005841 signatureECDSAWithP521AndSHA512,
5842 signatureRSAPKCS1WithSHA384,
5843 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005844 },
5845 },
5846 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005847 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5848 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005849 },
Nick Harper60edffd2016-06-21 15:19:24 -07005850 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005851 })
5852
5853 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005854 name: "ClientAuth-SignatureType-TLS13",
5855 config: Config{
5856 ClientAuth: RequireAnyClientCert,
5857 MaxVersion: VersionTLS13,
5858 VerifySignatureAlgorithms: []signatureAlgorithm{
5859 signatureECDSAWithP521AndSHA512,
5860 signatureRSAPKCS1WithSHA384,
5861 signatureRSAPSSWithSHA384,
5862 signatureECDSAWithSHA1,
5863 },
5864 },
5865 flags: []string{
5866 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5867 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5868 },
5869 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5870 })
5871
5872 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005873 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005874 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005876 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005878 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005879 signatureECDSAWithP521AndSHA512,
5880 signatureRSAPKCS1WithSHA384,
5881 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005882 },
5883 },
Nick Harper60edffd2016-06-21 15:19:24 -07005884 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005885 })
5886
Steven Valdez143e8b32016-07-11 13:19:03 -04005887 testCases = append(testCases, testCase{
5888 testType: serverTest,
5889 name: "ServerAuth-SignatureType-TLS13",
5890 config: Config{
5891 MaxVersion: VersionTLS13,
5892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5893 VerifySignatureAlgorithms: []signatureAlgorithm{
5894 signatureECDSAWithP521AndSHA512,
5895 signatureRSAPKCS1WithSHA384,
5896 signatureRSAPSSWithSHA384,
5897 signatureECDSAWithSHA1,
5898 },
5899 },
5900 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5901 })
5902
David Benjamina95e9f32016-07-08 16:28:04 -07005903 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005904 testCases = append(testCases, testCase{
5905 testType: serverTest,
5906 name: "Verify-ClientAuth-SignatureType",
5907 config: Config{
5908 MaxVersion: VersionTLS12,
5909 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005910 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005911 signatureRSAPKCS1WithSHA256,
5912 },
5913 Bugs: ProtocolBugs{
5914 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5915 },
5916 },
5917 flags: []string{
5918 "-require-any-client-certificate",
5919 },
5920 shouldFail: true,
5921 expectedError: ":WRONG_SIGNATURE_TYPE:",
5922 })
5923
5924 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005925 testType: serverTest,
5926 name: "Verify-ClientAuth-SignatureType-TLS13",
5927 config: Config{
5928 MaxVersion: VersionTLS13,
5929 Certificates: []Certificate{rsaCertificate},
5930 SignSignatureAlgorithms: []signatureAlgorithm{
5931 signatureRSAPSSWithSHA256,
5932 },
5933 Bugs: ProtocolBugs{
5934 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5935 },
5936 },
5937 flags: []string{
5938 "-require-any-client-certificate",
5939 },
5940 shouldFail: true,
5941 expectedError: ":WRONG_SIGNATURE_TYPE:",
5942 })
5943
5944 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005945 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005946 config: Config{
5947 MaxVersion: VersionTLS12,
5948 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005949 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005950 signatureRSAPKCS1WithSHA256,
5951 },
5952 Bugs: ProtocolBugs{
5953 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5954 },
5955 },
5956 shouldFail: true,
5957 expectedError: ":WRONG_SIGNATURE_TYPE:",
5958 })
5959
Steven Valdez143e8b32016-07-11 13:19:03 -04005960 testCases = append(testCases, testCase{
5961 name: "Verify-ServerAuth-SignatureType-TLS13",
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5965 SignSignatureAlgorithms: []signatureAlgorithm{
5966 signatureRSAPSSWithSHA256,
5967 },
5968 Bugs: ProtocolBugs{
5969 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5970 },
5971 },
5972 shouldFail: true,
5973 expectedError: ":WRONG_SIGNATURE_TYPE:",
5974 })
5975
David Benjamin51dd7d62016-07-08 16:07:01 -07005976 // Test that, if the list is missing, the peer falls back to SHA-1 in
5977 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005978 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005979 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005981 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005982 ClientAuth: RequireAnyClientCert,
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 },
5990 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005991 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5992 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005993 },
5994 })
5995
5996 testCases = append(testCases, testCase{
5997 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005998 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005999 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006000 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006001 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006002 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006003 },
6004 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006005 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006006 },
6007 },
David Benjaminee32bea2016-08-17 13:36:44 -04006008 flags: []string{
6009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6011 },
6012 })
6013
6014 testCases = append(testCases, testCase{
6015 name: "ClientAuth-SHA1-Fallback-ECDSA",
6016 config: Config{
6017 MaxVersion: VersionTLS12,
6018 ClientAuth: RequireAnyClientCert,
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 },
6030 })
6031
6032 testCases = append(testCases, testCase{
6033 testType: serverTest,
6034 name: "ServerAuth-SHA1-Fallback-ECDSA",
6035 config: Config{
6036 MaxVersion: VersionTLS12,
6037 VerifySignatureAlgorithms: []signatureAlgorithm{
6038 signatureECDSAWithSHA1,
6039 },
6040 Bugs: ProtocolBugs{
6041 NoSignatureAlgorithms: true,
6042 },
6043 },
6044 flags: []string{
6045 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6046 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6047 },
David Benjamin000800a2014-11-14 01:43:59 -05006048 })
David Benjamin72dc7832015-03-16 17:49:43 -04006049
David Benjamin51dd7d62016-07-08 16:07:01 -07006050 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006051 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006052 config: Config{
6053 MaxVersion: VersionTLS13,
6054 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006055 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006056 signatureRSAPKCS1WithSHA1,
6057 },
6058 Bugs: ProtocolBugs{
6059 NoSignatureAlgorithms: true,
6060 },
6061 },
6062 flags: []string{
6063 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6064 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6065 },
David Benjamin48901652016-08-01 12:12:47 -04006066 shouldFail: true,
6067 // An empty CertificateRequest signature algorithm list is a
6068 // syntax error in TLS 1.3.
6069 expectedError: ":DECODE_ERROR:",
6070 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006071 })
6072
6073 testCases = append(testCases, testCase{
6074 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006075 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006076 config: Config{
6077 MaxVersion: VersionTLS13,
6078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006079 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006080 signatureRSAPKCS1WithSHA1,
6081 },
6082 Bugs: ProtocolBugs{
6083 NoSignatureAlgorithms: true,
6084 },
6085 },
6086 shouldFail: true,
6087 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6088 })
6089
David Benjaminb62d2872016-07-18 14:55:02 +02006090 // Test that hash preferences are enforced. BoringSSL does not implement
6091 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006092 testCases = append(testCases, testCase{
6093 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006094 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006096 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006097 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006098 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006099 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006100 },
6101 Bugs: ProtocolBugs{
6102 IgnorePeerSignatureAlgorithmPreferences: true,
6103 },
6104 },
6105 flags: []string{"-require-any-client-certificate"},
6106 shouldFail: true,
6107 expectedError: ":WRONG_SIGNATURE_TYPE:",
6108 })
6109
6110 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006111 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006113 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006115 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006116 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006117 },
6118 Bugs: ProtocolBugs{
6119 IgnorePeerSignatureAlgorithmPreferences: true,
6120 },
6121 },
6122 shouldFail: true,
6123 expectedError: ":WRONG_SIGNATURE_TYPE:",
6124 })
David Benjaminb62d2872016-07-18 14:55:02 +02006125 testCases = append(testCases, testCase{
6126 testType: serverTest,
6127 name: "ClientAuth-Enforced-TLS13",
6128 config: Config{
6129 MaxVersion: VersionTLS13,
6130 Certificates: []Certificate{rsaCertificate},
6131 SignSignatureAlgorithms: []signatureAlgorithm{
6132 signatureRSAPKCS1WithMD5,
6133 },
6134 Bugs: ProtocolBugs{
6135 IgnorePeerSignatureAlgorithmPreferences: true,
6136 IgnoreSignatureVersionChecks: true,
6137 },
6138 },
6139 flags: []string{"-require-any-client-certificate"},
6140 shouldFail: true,
6141 expectedError: ":WRONG_SIGNATURE_TYPE:",
6142 })
6143
6144 testCases = append(testCases, testCase{
6145 name: "ServerAuth-Enforced-TLS13",
6146 config: Config{
6147 MaxVersion: VersionTLS13,
6148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6149 SignSignatureAlgorithms: []signatureAlgorithm{
6150 signatureRSAPKCS1WithMD5,
6151 },
6152 Bugs: ProtocolBugs{
6153 IgnorePeerSignatureAlgorithmPreferences: true,
6154 IgnoreSignatureVersionChecks: true,
6155 },
6156 },
6157 shouldFail: true,
6158 expectedError: ":WRONG_SIGNATURE_TYPE:",
6159 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006160
6161 // Test that the agreed upon digest respects the client preferences and
6162 // the server digests.
6163 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006164 name: "NoCommonAlgorithms-Digests",
6165 config: Config{
6166 MaxVersion: VersionTLS12,
6167 ClientAuth: RequireAnyClientCert,
6168 VerifySignatureAlgorithms: []signatureAlgorithm{
6169 signatureRSAPKCS1WithSHA512,
6170 signatureRSAPKCS1WithSHA1,
6171 },
6172 },
6173 flags: []string{
6174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6176 "-digest-prefs", "SHA256",
6177 },
6178 shouldFail: true,
6179 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6180 })
6181 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006182 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006184 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006185 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006186 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006187 signatureRSAPKCS1WithSHA512,
6188 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006189 },
6190 },
6191 flags: []string{
6192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006194 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006195 },
David Benjaminca3d5452016-07-14 12:51:01 -04006196 shouldFail: true,
6197 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6198 })
6199 testCases = append(testCases, testCase{
6200 name: "NoCommonAlgorithms-TLS13",
6201 config: Config{
6202 MaxVersion: VersionTLS13,
6203 ClientAuth: RequireAnyClientCert,
6204 VerifySignatureAlgorithms: []signatureAlgorithm{
6205 signatureRSAPSSWithSHA512,
6206 signatureRSAPSSWithSHA384,
6207 },
6208 },
6209 flags: []string{
6210 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6211 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6212 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6213 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006214 shouldFail: true,
6215 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006216 })
6217 testCases = append(testCases, testCase{
6218 name: "Agree-Digest-SHA256",
6219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006220 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006221 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006222 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006223 signatureRSAPKCS1WithSHA1,
6224 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006225 },
6226 },
6227 flags: []string{
6228 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6229 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006230 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006231 },
Nick Harper60edffd2016-06-21 15:19:24 -07006232 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006233 })
6234 testCases = append(testCases, testCase{
6235 name: "Agree-Digest-SHA1",
6236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006237 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006238 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006239 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006240 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006241 },
6242 },
6243 flags: []string{
6244 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6245 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006246 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006247 },
Nick Harper60edffd2016-06-21 15:19:24 -07006248 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006249 })
6250 testCases = append(testCases, testCase{
6251 name: "Agree-Digest-Default",
6252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006253 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006254 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006255 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006256 signatureRSAPKCS1WithSHA256,
6257 signatureECDSAWithP256AndSHA256,
6258 signatureRSAPKCS1WithSHA1,
6259 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006260 },
6261 },
6262 flags: []string{
6263 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6264 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6265 },
Nick Harper60edffd2016-06-21 15:19:24 -07006266 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006267 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006268
David Benjaminca3d5452016-07-14 12:51:01 -04006269 // Test that the signing preference list may include extra algorithms
6270 // without negotiation problems.
6271 testCases = append(testCases, testCase{
6272 testType: serverTest,
6273 name: "FilterExtraAlgorithms",
6274 config: Config{
6275 MaxVersion: VersionTLS12,
6276 VerifySignatureAlgorithms: []signatureAlgorithm{
6277 signatureRSAPKCS1WithSHA256,
6278 },
6279 },
6280 flags: []string{
6281 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6282 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6283 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6284 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6285 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6286 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6287 },
6288 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6289 })
6290
David Benjamin4c3ddf72016-06-29 18:13:53 -04006291 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6292 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006293 testCases = append(testCases, testCase{
6294 name: "CheckLeafCurve",
6295 config: Config{
6296 MaxVersion: VersionTLS12,
6297 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006298 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006299 },
6300 flags: []string{"-p384-only"},
6301 shouldFail: true,
6302 expectedError: ":BAD_ECC_CERT:",
6303 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006304
6305 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6306 testCases = append(testCases, testCase{
6307 name: "CheckLeafCurve-TLS13",
6308 config: Config{
6309 MaxVersion: VersionTLS13,
6310 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6311 Certificates: []Certificate{ecdsaP256Certificate},
6312 },
6313 flags: []string{"-p384-only"},
6314 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006315
6316 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6317 testCases = append(testCases, testCase{
6318 name: "ECDSACurveMismatch-Verify-TLS12",
6319 config: Config{
6320 MaxVersion: VersionTLS12,
6321 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6322 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006323 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006324 signatureECDSAWithP384AndSHA384,
6325 },
6326 },
6327 })
6328
6329 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6330 testCases = append(testCases, testCase{
6331 name: "ECDSACurveMismatch-Verify-TLS13",
6332 config: Config{
6333 MaxVersion: VersionTLS13,
6334 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6335 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006336 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006337 signatureECDSAWithP384AndSHA384,
6338 },
6339 Bugs: ProtocolBugs{
6340 SkipECDSACurveCheck: true,
6341 },
6342 },
6343 shouldFail: true,
6344 expectedError: ":WRONG_SIGNATURE_TYPE:",
6345 })
6346
6347 // Signature algorithm selection in TLS 1.3 should take the curve into
6348 // account.
6349 testCases = append(testCases, testCase{
6350 testType: serverTest,
6351 name: "ECDSACurveMismatch-Sign-TLS13",
6352 config: Config{
6353 MaxVersion: VersionTLS13,
6354 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006355 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006356 signatureECDSAWithP384AndSHA384,
6357 signatureECDSAWithP256AndSHA256,
6358 },
6359 },
6360 flags: []string{
6361 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6362 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6363 },
6364 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6365 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006366
6367 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6368 // server does not attempt to sign in that case.
6369 testCases = append(testCases, testCase{
6370 testType: serverTest,
6371 name: "RSA-PSS-Large",
6372 config: Config{
6373 MaxVersion: VersionTLS13,
6374 VerifySignatureAlgorithms: []signatureAlgorithm{
6375 signatureRSAPSSWithSHA512,
6376 },
6377 },
6378 flags: []string{
6379 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6380 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6381 },
6382 shouldFail: true,
6383 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6384 })
David Benjamin57e929f2016-08-30 00:30:38 -04006385
6386 // Test that RSA-PSS is enabled by default for TLS 1.2.
6387 testCases = append(testCases, testCase{
6388 testType: clientTest,
6389 name: "RSA-PSS-Default-Verify",
6390 config: Config{
6391 MaxVersion: VersionTLS12,
6392 SignSignatureAlgorithms: []signatureAlgorithm{
6393 signatureRSAPSSWithSHA256,
6394 },
6395 },
6396 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6397 })
6398
6399 testCases = append(testCases, testCase{
6400 testType: serverTest,
6401 name: "RSA-PSS-Default-Sign",
6402 config: Config{
6403 MaxVersion: VersionTLS12,
6404 VerifySignatureAlgorithms: []signatureAlgorithm{
6405 signatureRSAPSSWithSHA256,
6406 },
6407 },
6408 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6409 })
David Benjamin000800a2014-11-14 01:43:59 -05006410}
6411
David Benjamin83f90402015-01-27 01:09:43 -05006412// timeouts is the retransmit schedule for BoringSSL. It doubles and
6413// caps at 60 seconds. On the 13th timeout, it gives up.
6414var timeouts = []time.Duration{
6415 1 * time.Second,
6416 2 * time.Second,
6417 4 * time.Second,
6418 8 * time.Second,
6419 16 * time.Second,
6420 32 * time.Second,
6421 60 * time.Second,
6422 60 * time.Second,
6423 60 * time.Second,
6424 60 * time.Second,
6425 60 * time.Second,
6426 60 * time.Second,
6427 60 * time.Second,
6428}
6429
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006430// shortTimeouts is an alternate set of timeouts which would occur if the
6431// initial timeout duration was set to 250ms.
6432var shortTimeouts = []time.Duration{
6433 250 * time.Millisecond,
6434 500 * time.Millisecond,
6435 1 * time.Second,
6436 2 * time.Second,
6437 4 * time.Second,
6438 8 * time.Second,
6439 16 * time.Second,
6440 32 * time.Second,
6441 60 * time.Second,
6442 60 * time.Second,
6443 60 * time.Second,
6444 60 * time.Second,
6445 60 * time.Second,
6446}
6447
David Benjamin83f90402015-01-27 01:09:43 -05006448func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006449 // These tests work by coordinating some behavior on both the shim and
6450 // the runner.
6451 //
6452 // TimeoutSchedule configures the runner to send a series of timeout
6453 // opcodes to the shim (see packetAdaptor) immediately before reading
6454 // each peer handshake flight N. The timeout opcode both simulates a
6455 // timeout in the shim and acts as a synchronization point to help the
6456 // runner bracket each handshake flight.
6457 //
6458 // We assume the shim does not read from the channel eagerly. It must
6459 // first wait until it has sent flight N and is ready to receive
6460 // handshake flight N+1. At this point, it will process the timeout
6461 // opcode. It must then immediately respond with a timeout ACK and act
6462 // as if the shim was idle for the specified amount of time.
6463 //
6464 // The runner then drops all packets received before the ACK and
6465 // continues waiting for flight N. This ordering results in one attempt
6466 // at sending flight N to be dropped. For the test to complete, the
6467 // shim must send flight N again, testing that the shim implements DTLS
6468 // retransmit on a timeout.
6469
Steven Valdez143e8b32016-07-11 13:19:03 -04006470 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006471 // likely be more epochs to cross and the final message's retransmit may
6472 // be more complex.
6473
David Benjamin585d7a42016-06-02 14:58:00 -04006474 for _, async := range []bool{true, false} {
6475 var tests []testCase
6476
6477 // Test that this is indeed the timeout schedule. Stress all
6478 // four patterns of handshake.
6479 for i := 1; i < len(timeouts); i++ {
6480 number := strconv.Itoa(i)
6481 tests = append(tests, testCase{
6482 protocol: dtls,
6483 name: "DTLS-Retransmit-Client-" + number,
6484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006485 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006486 Bugs: ProtocolBugs{
6487 TimeoutSchedule: timeouts[:i],
6488 },
6489 },
6490 resumeSession: true,
6491 })
6492 tests = append(tests, testCase{
6493 protocol: dtls,
6494 testType: serverTest,
6495 name: "DTLS-Retransmit-Server-" + number,
6496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006497 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006498 Bugs: ProtocolBugs{
6499 TimeoutSchedule: timeouts[:i],
6500 },
6501 },
6502 resumeSession: true,
6503 })
6504 }
6505
6506 // Test that exceeding the timeout schedule hits a read
6507 // timeout.
6508 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006509 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006510 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006512 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006513 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006514 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006515 },
6516 },
6517 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006518 shouldFail: true,
6519 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006520 })
David Benjamin585d7a42016-06-02 14:58:00 -04006521
6522 if async {
6523 // Test that timeout handling has a fudge factor, due to API
6524 // problems.
6525 tests = append(tests, testCase{
6526 protocol: dtls,
6527 name: "DTLS-Retransmit-Fudge",
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{
6532 timeouts[0] - 10*time.Millisecond,
6533 },
6534 },
6535 },
6536 resumeSession: true,
6537 })
6538 }
6539
6540 // Test that the final Finished retransmitting isn't
6541 // duplicated if the peer badly fragments everything.
6542 tests = append(tests, testCase{
6543 testType: serverTest,
6544 protocol: dtls,
6545 name: "DTLS-Retransmit-Fragmented",
6546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006547 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006548 Bugs: ProtocolBugs{
6549 TimeoutSchedule: []time.Duration{timeouts[0]},
6550 MaxHandshakeRecordLength: 2,
6551 },
6552 },
6553 })
6554
6555 // Test the timeout schedule when a shorter initial timeout duration is set.
6556 tests = append(tests, testCase{
6557 protocol: dtls,
6558 name: "DTLS-Retransmit-Short-Client",
6559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006560 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006561 Bugs: ProtocolBugs{
6562 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6563 },
6564 },
6565 resumeSession: true,
6566 flags: []string{"-initial-timeout-duration-ms", "250"},
6567 })
6568 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006569 protocol: dtls,
6570 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006571 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006572 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006573 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006574 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006575 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006576 },
6577 },
6578 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006579 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006580 })
David Benjamin585d7a42016-06-02 14:58:00 -04006581
6582 for _, test := range tests {
6583 if async {
6584 test.name += "-Async"
6585 test.flags = append(test.flags, "-async")
6586 }
6587
6588 testCases = append(testCases, test)
6589 }
David Benjamin83f90402015-01-27 01:09:43 -05006590 }
David Benjamin83f90402015-01-27 01:09:43 -05006591}
6592
David Benjaminc565ebb2015-04-03 04:06:36 -04006593func addExportKeyingMaterialTests() {
6594 for _, vers := range tlsVersions {
6595 if vers.version == VersionSSL30 {
6596 continue
6597 }
6598 testCases = append(testCases, testCase{
6599 name: "ExportKeyingMaterial-" + vers.name,
6600 config: Config{
6601 MaxVersion: vers.version,
6602 },
6603 exportKeyingMaterial: 1024,
6604 exportLabel: "label",
6605 exportContext: "context",
6606 useExportContext: true,
6607 })
6608 testCases = append(testCases, testCase{
6609 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6610 config: Config{
6611 MaxVersion: vers.version,
6612 },
6613 exportKeyingMaterial: 1024,
6614 })
6615 testCases = append(testCases, testCase{
6616 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6617 config: Config{
6618 MaxVersion: vers.version,
6619 },
6620 exportKeyingMaterial: 1024,
6621 useExportContext: true,
6622 })
6623 testCases = append(testCases, testCase{
6624 name: "ExportKeyingMaterial-Small-" + vers.name,
6625 config: Config{
6626 MaxVersion: vers.version,
6627 },
6628 exportKeyingMaterial: 1,
6629 exportLabel: "label",
6630 exportContext: "context",
6631 useExportContext: true,
6632 })
6633 }
6634 testCases = append(testCases, testCase{
6635 name: "ExportKeyingMaterial-SSL3",
6636 config: Config{
6637 MaxVersion: VersionSSL30,
6638 },
6639 exportKeyingMaterial: 1024,
6640 exportLabel: "label",
6641 exportContext: "context",
6642 useExportContext: true,
6643 shouldFail: true,
6644 expectedError: "failed to export keying material",
6645 })
6646}
6647
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006648func addTLSUniqueTests() {
6649 for _, isClient := range []bool{false, true} {
6650 for _, isResumption := range []bool{false, true} {
6651 for _, hasEMS := range []bool{false, true} {
6652 var suffix string
6653 if isResumption {
6654 suffix = "Resume-"
6655 } else {
6656 suffix = "Full-"
6657 }
6658
6659 if hasEMS {
6660 suffix += "EMS-"
6661 } else {
6662 suffix += "NoEMS-"
6663 }
6664
6665 if isClient {
6666 suffix += "Client"
6667 } else {
6668 suffix += "Server"
6669 }
6670
6671 test := testCase{
6672 name: "TLSUnique-" + suffix,
6673 testTLSUnique: true,
6674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006675 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006676 Bugs: ProtocolBugs{
6677 NoExtendedMasterSecret: !hasEMS,
6678 },
6679 },
6680 }
6681
6682 if isResumption {
6683 test.resumeSession = true
6684 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006685 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006686 Bugs: ProtocolBugs{
6687 NoExtendedMasterSecret: !hasEMS,
6688 },
6689 }
6690 }
6691
6692 if isResumption && !hasEMS {
6693 test.shouldFail = true
6694 test.expectedError = "failed to get tls-unique"
6695 }
6696
6697 testCases = append(testCases, test)
6698 }
6699 }
6700 }
6701}
6702
Adam Langley09505632015-07-30 18:10:13 -07006703func addCustomExtensionTests() {
6704 expectedContents := "custom extension"
6705 emptyString := ""
6706
6707 for _, isClient := range []bool{false, true} {
6708 suffix := "Server"
6709 flag := "-enable-server-custom-extension"
6710 testType := serverTest
6711 if isClient {
6712 suffix = "Client"
6713 flag = "-enable-client-custom-extension"
6714 testType = clientTest
6715 }
6716
6717 testCases = append(testCases, testCase{
6718 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006719 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006721 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006722 Bugs: ProtocolBugs{
6723 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006724 ExpectedCustomExtension: &expectedContents,
6725 },
6726 },
6727 flags: []string{flag},
6728 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006729 testCases = append(testCases, testCase{
6730 testType: testType,
6731 name: "CustomExtensions-" + suffix + "-TLS13",
6732 config: Config{
6733 MaxVersion: VersionTLS13,
6734 Bugs: ProtocolBugs{
6735 CustomExtension: expectedContents,
6736 ExpectedCustomExtension: &expectedContents,
6737 },
6738 },
6739 flags: []string{flag},
6740 })
Adam Langley09505632015-07-30 18:10:13 -07006741
6742 // If the parse callback fails, the handshake should also fail.
6743 testCases = append(testCases, testCase{
6744 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006745 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006746 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006747 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006748 Bugs: ProtocolBugs{
6749 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006750 ExpectedCustomExtension: &expectedContents,
6751 },
6752 },
David Benjamin399e7c92015-07-30 23:01:27 -04006753 flags: []string{flag},
6754 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006755 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6756 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006757 testCases = append(testCases, testCase{
6758 testType: testType,
6759 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6760 config: Config{
6761 MaxVersion: VersionTLS13,
6762 Bugs: ProtocolBugs{
6763 CustomExtension: expectedContents + "foo",
6764 ExpectedCustomExtension: &expectedContents,
6765 },
6766 },
6767 flags: []string{flag},
6768 shouldFail: true,
6769 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6770 })
Adam Langley09505632015-07-30 18:10:13 -07006771
6772 // If the add callback fails, the handshake should also fail.
6773 testCases = append(testCases, testCase{
6774 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006775 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006776 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006777 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006778 Bugs: ProtocolBugs{
6779 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006780 ExpectedCustomExtension: &expectedContents,
6781 },
6782 },
David Benjamin399e7c92015-07-30 23:01:27 -04006783 flags: []string{flag, "-custom-extension-fail-add"},
6784 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006785 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6786 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006787 testCases = append(testCases, testCase{
6788 testType: testType,
6789 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6790 config: Config{
6791 MaxVersion: VersionTLS13,
6792 Bugs: ProtocolBugs{
6793 CustomExtension: expectedContents,
6794 ExpectedCustomExtension: &expectedContents,
6795 },
6796 },
6797 flags: []string{flag, "-custom-extension-fail-add"},
6798 shouldFail: true,
6799 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6800 })
Adam Langley09505632015-07-30 18:10:13 -07006801
6802 // If the add callback returns zero, no extension should be
6803 // added.
6804 skipCustomExtension := expectedContents
6805 if isClient {
6806 // For the case where the client skips sending the
6807 // custom extension, the server must not “echo” it.
6808 skipCustomExtension = ""
6809 }
6810 testCases = append(testCases, testCase{
6811 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006812 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006813 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006814 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006815 Bugs: ProtocolBugs{
6816 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006817 ExpectedCustomExtension: &emptyString,
6818 },
6819 },
6820 flags: []string{flag, "-custom-extension-skip"},
6821 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006822 testCases = append(testCases, testCase{
6823 testType: testType,
6824 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6825 config: Config{
6826 MaxVersion: VersionTLS13,
6827 Bugs: ProtocolBugs{
6828 CustomExtension: skipCustomExtension,
6829 ExpectedCustomExtension: &emptyString,
6830 },
6831 },
6832 flags: []string{flag, "-custom-extension-skip"},
6833 })
Adam Langley09505632015-07-30 18:10:13 -07006834 }
6835
6836 // The custom extension add callback should not be called if the client
6837 // doesn't send the extension.
6838 testCases = append(testCases, testCase{
6839 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006840 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006842 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006843 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006844 ExpectedCustomExtension: &emptyString,
6845 },
6846 },
6847 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6848 })
Adam Langley2deb9842015-08-07 11:15:37 -07006849
Steven Valdez143e8b32016-07-11 13:19:03 -04006850 testCases = append(testCases, testCase{
6851 testType: serverTest,
6852 name: "CustomExtensions-NotCalled-Server-TLS13",
6853 config: Config{
6854 MaxVersion: VersionTLS13,
6855 Bugs: ProtocolBugs{
6856 ExpectedCustomExtension: &emptyString,
6857 },
6858 },
6859 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6860 })
6861
Adam Langley2deb9842015-08-07 11:15:37 -07006862 // Test an unknown extension from the server.
6863 testCases = append(testCases, testCase{
6864 testType: clientTest,
6865 name: "UnknownExtension-Client",
6866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006867 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006868 Bugs: ProtocolBugs{
6869 CustomExtension: expectedContents,
6870 },
6871 },
David Benjamin0c40a962016-08-01 12:05:50 -04006872 shouldFail: true,
6873 expectedError: ":UNEXPECTED_EXTENSION:",
6874 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006875 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006876 testCases = append(testCases, testCase{
6877 testType: clientTest,
6878 name: "UnknownExtension-Client-TLS13",
6879 config: Config{
6880 MaxVersion: VersionTLS13,
6881 Bugs: ProtocolBugs{
6882 CustomExtension: expectedContents,
6883 },
6884 },
David Benjamin0c40a962016-08-01 12:05:50 -04006885 shouldFail: true,
6886 expectedError: ":UNEXPECTED_EXTENSION:",
6887 expectedLocalError: "remote error: unsupported extension",
6888 })
6889
6890 // Test a known but unoffered extension from the server.
6891 testCases = append(testCases, testCase{
6892 testType: clientTest,
6893 name: "UnofferedExtension-Client",
6894 config: Config{
6895 MaxVersion: VersionTLS12,
6896 Bugs: ProtocolBugs{
6897 SendALPN: "alpn",
6898 },
6899 },
6900 shouldFail: true,
6901 expectedError: ":UNEXPECTED_EXTENSION:",
6902 expectedLocalError: "remote error: unsupported extension",
6903 })
6904 testCases = append(testCases, testCase{
6905 testType: clientTest,
6906 name: "UnofferedExtension-Client-TLS13",
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 Bugs: ProtocolBugs{
6910 SendALPN: "alpn",
6911 },
6912 },
6913 shouldFail: true,
6914 expectedError: ":UNEXPECTED_EXTENSION:",
6915 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006916 })
Adam Langley09505632015-07-30 18:10:13 -07006917}
6918
David Benjaminb36a3952015-12-01 18:53:13 -05006919func addRSAClientKeyExchangeTests() {
6920 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6921 testCases = append(testCases, testCase{
6922 testType: serverTest,
6923 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6924 config: Config{
6925 // Ensure the ClientHello version and final
6926 // version are different, to detect if the
6927 // server uses the wrong one.
6928 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006929 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006930 Bugs: ProtocolBugs{
6931 BadRSAClientKeyExchange: bad,
6932 },
6933 },
6934 shouldFail: true,
6935 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6936 })
6937 }
David Benjamine63d9d72016-09-19 18:27:34 -04006938
6939 // The server must compare whatever was in ClientHello.version for the
6940 // RSA premaster.
6941 testCases = append(testCases, testCase{
6942 testType: serverTest,
6943 name: "SendClientVersion-RSA",
6944 config: Config{
6945 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6946 Bugs: ProtocolBugs{
6947 SendClientVersion: 0x1234,
6948 },
6949 },
6950 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6951 })
David Benjaminb36a3952015-12-01 18:53:13 -05006952}
6953
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006954var testCurves = []struct {
6955 name string
6956 id CurveID
6957}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006958 {"P-256", CurveP256},
6959 {"P-384", CurveP384},
6960 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006961 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006962}
6963
Steven Valdez5440fe02016-07-18 12:40:30 -04006964const bogusCurve = 0x1234
6965
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006966func addCurveTests() {
6967 for _, curve := range testCurves {
6968 testCases = append(testCases, testCase{
6969 name: "CurveTest-Client-" + curve.name,
6970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006971 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006972 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6973 CurvePreferences: []CurveID{curve.id},
6974 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006975 flags: []string{
6976 "-enable-all-curves",
6977 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6978 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006979 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006980 })
6981 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006982 name: "CurveTest-Client-" + curve.name + "-TLS13",
6983 config: Config{
6984 MaxVersion: VersionTLS13,
6985 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6986 CurvePreferences: []CurveID{curve.id},
6987 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006988 flags: []string{
6989 "-enable-all-curves",
6990 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6991 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006992 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006993 })
6994 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006995 testType: serverTest,
6996 name: "CurveTest-Server-" + curve.name,
6997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7000 CurvePreferences: []CurveID{curve.id},
7001 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007002 flags: []string{
7003 "-enable-all-curves",
7004 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7005 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007006 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007007 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007008 testCases = append(testCases, testCase{
7009 testType: serverTest,
7010 name: "CurveTest-Server-" + curve.name + "-TLS13",
7011 config: Config{
7012 MaxVersion: VersionTLS13,
7013 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7014 CurvePreferences: []CurveID{curve.id},
7015 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007016 flags: []string{
7017 "-enable-all-curves",
7018 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7019 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007020 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007021 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007022 }
David Benjamin241ae832016-01-15 03:04:54 -05007023
7024 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007025 testCases = append(testCases, testCase{
7026 testType: serverTest,
7027 name: "UnknownCurve",
7028 config: Config{
7029 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7030 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7031 },
7032 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007033
7034 // The server must not consider ECDHE ciphers when there are no
7035 // supported curves.
7036 testCases = append(testCases, testCase{
7037 testType: serverTest,
7038 name: "NoSupportedCurves",
7039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007040 MaxVersion: VersionTLS12,
7041 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7042 Bugs: ProtocolBugs{
7043 NoSupportedCurves: true,
7044 },
7045 },
7046 shouldFail: true,
7047 expectedError: ":NO_SHARED_CIPHER:",
7048 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007049 testCases = append(testCases, testCase{
7050 testType: serverTest,
7051 name: "NoSupportedCurves-TLS13",
7052 config: Config{
7053 MaxVersion: VersionTLS13,
7054 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7055 Bugs: ProtocolBugs{
7056 NoSupportedCurves: true,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedError: ":NO_SHARED_CIPHER:",
7061 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007062
7063 // The server must fall back to another cipher when there are no
7064 // supported curves.
7065 testCases = append(testCases, testCase{
7066 testType: serverTest,
7067 name: "NoCommonCurves",
7068 config: Config{
7069 MaxVersion: VersionTLS12,
7070 CipherSuites: []uint16{
7071 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7072 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7073 },
7074 CurvePreferences: []CurveID{CurveP224},
7075 },
7076 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7077 })
7078
7079 // The client must reject bogus curves and disabled curves.
7080 testCases = append(testCases, testCase{
7081 name: "BadECDHECurve",
7082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083 MaxVersion: VersionTLS12,
7084 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7085 Bugs: ProtocolBugs{
7086 SendCurve: bogusCurve,
7087 },
7088 },
7089 shouldFail: true,
7090 expectedError: ":WRONG_CURVE:",
7091 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007092 testCases = append(testCases, testCase{
7093 name: "BadECDHECurve-TLS13",
7094 config: Config{
7095 MaxVersion: VersionTLS13,
7096 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7097 Bugs: ProtocolBugs{
7098 SendCurve: bogusCurve,
7099 },
7100 },
7101 shouldFail: true,
7102 expectedError: ":WRONG_CURVE:",
7103 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007104
7105 testCases = append(testCases, testCase{
7106 name: "UnsupportedCurve",
7107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007108 MaxVersion: VersionTLS12,
7109 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7110 CurvePreferences: []CurveID{CurveP256},
7111 Bugs: ProtocolBugs{
7112 IgnorePeerCurvePreferences: true,
7113 },
7114 },
7115 flags: []string{"-p384-only"},
7116 shouldFail: true,
7117 expectedError: ":WRONG_CURVE:",
7118 })
7119
David Benjamin4f921572016-07-17 14:20:10 +02007120 testCases = append(testCases, testCase{
7121 // TODO(davidben): Add a TLS 1.3 version where
7122 // HelloRetryRequest requests an unsupported curve.
7123 name: "UnsupportedCurve-ServerHello-TLS13",
7124 config: Config{
7125 MaxVersion: VersionTLS12,
7126 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7127 CurvePreferences: []CurveID{CurveP384},
7128 Bugs: ProtocolBugs{
7129 SendCurve: CurveP256,
7130 },
7131 },
7132 flags: []string{"-p384-only"},
7133 shouldFail: true,
7134 expectedError: ":WRONG_CURVE:",
7135 })
7136
David Benjamin4c3ddf72016-06-29 18:13:53 -04007137 // Test invalid curve points.
7138 testCases = append(testCases, testCase{
7139 name: "InvalidECDHPoint-Client",
7140 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007141 MaxVersion: VersionTLS12,
7142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7143 CurvePreferences: []CurveID{CurveP256},
7144 Bugs: ProtocolBugs{
7145 InvalidECDHPoint: true,
7146 },
7147 },
7148 shouldFail: true,
7149 expectedError: ":INVALID_ENCODING:",
7150 })
7151 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007152 name: "InvalidECDHPoint-Client-TLS13",
7153 config: Config{
7154 MaxVersion: VersionTLS13,
7155 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7156 CurvePreferences: []CurveID{CurveP256},
7157 Bugs: ProtocolBugs{
7158 InvalidECDHPoint: true,
7159 },
7160 },
7161 shouldFail: true,
7162 expectedError: ":INVALID_ENCODING:",
7163 })
7164 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007165 testType: serverTest,
7166 name: "InvalidECDHPoint-Server",
7167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007168 MaxVersion: VersionTLS12,
7169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7170 CurvePreferences: []CurveID{CurveP256},
7171 Bugs: ProtocolBugs{
7172 InvalidECDHPoint: true,
7173 },
7174 },
7175 shouldFail: true,
7176 expectedError: ":INVALID_ENCODING:",
7177 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007178 testCases = append(testCases, testCase{
7179 testType: serverTest,
7180 name: "InvalidECDHPoint-Server-TLS13",
7181 config: Config{
7182 MaxVersion: VersionTLS13,
7183 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7184 CurvePreferences: []CurveID{CurveP256},
7185 Bugs: ProtocolBugs{
7186 InvalidECDHPoint: true,
7187 },
7188 },
7189 shouldFail: true,
7190 expectedError: ":INVALID_ENCODING:",
7191 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007192}
7193
Matt Braithwaite54217e42016-06-13 13:03:47 -07007194func addCECPQ1Tests() {
7195 testCases = append(testCases, testCase{
7196 testType: clientTest,
7197 name: "CECPQ1-Client-BadX25519Part",
7198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007199 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007200 MinVersion: VersionTLS12,
7201 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7202 Bugs: ProtocolBugs{
7203 CECPQ1BadX25519Part: true,
7204 },
7205 },
7206 flags: []string{"-cipher", "kCECPQ1"},
7207 shouldFail: true,
7208 expectedLocalError: "local error: bad record MAC",
7209 })
7210 testCases = append(testCases, testCase{
7211 testType: clientTest,
7212 name: "CECPQ1-Client-BadNewhopePart",
7213 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007214 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007215 MinVersion: VersionTLS12,
7216 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7217 Bugs: ProtocolBugs{
7218 CECPQ1BadNewhopePart: true,
7219 },
7220 },
7221 flags: []string{"-cipher", "kCECPQ1"},
7222 shouldFail: true,
7223 expectedLocalError: "local error: bad record MAC",
7224 })
7225 testCases = append(testCases, testCase{
7226 testType: serverTest,
7227 name: "CECPQ1-Server-BadX25519Part",
7228 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007229 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007230 MinVersion: VersionTLS12,
7231 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7232 Bugs: ProtocolBugs{
7233 CECPQ1BadX25519Part: true,
7234 },
7235 },
7236 flags: []string{"-cipher", "kCECPQ1"},
7237 shouldFail: true,
7238 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7239 })
7240 testCases = append(testCases, testCase{
7241 testType: serverTest,
7242 name: "CECPQ1-Server-BadNewhopePart",
7243 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007244 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007245 MinVersion: VersionTLS12,
7246 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7247 Bugs: ProtocolBugs{
7248 CECPQ1BadNewhopePart: true,
7249 },
7250 },
7251 flags: []string{"-cipher", "kCECPQ1"},
7252 shouldFail: true,
7253 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7254 })
7255}
7256
David Benjamin5c4e8572016-08-19 17:44:53 -04007257func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007258 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007259 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007260 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007261 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007262 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7263 Bugs: ProtocolBugs{
7264 // This is a 1234-bit prime number, generated
7265 // with:
7266 // openssl gendh 1234 | openssl asn1parse -i
7267 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7268 },
7269 },
David Benjamin9e68f192016-06-30 14:55:33 -04007270 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007271 })
7272 testCases = append(testCases, testCase{
7273 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007274 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007275 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007276 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007277 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7278 },
7279 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007280 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007281 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007282}
7283
David Benjaminc9ae27c2016-06-24 22:56:37 -04007284func addTLS13RecordTests() {
7285 testCases = append(testCases, testCase{
7286 name: "TLS13-RecordPadding",
7287 config: Config{
7288 MaxVersion: VersionTLS13,
7289 MinVersion: VersionTLS13,
7290 Bugs: ProtocolBugs{
7291 RecordPadding: 10,
7292 },
7293 },
7294 })
7295
7296 testCases = append(testCases, testCase{
7297 name: "TLS13-EmptyRecords",
7298 config: Config{
7299 MaxVersion: VersionTLS13,
7300 MinVersion: VersionTLS13,
7301 Bugs: ProtocolBugs{
7302 OmitRecordContents: true,
7303 },
7304 },
7305 shouldFail: true,
7306 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7307 })
7308
7309 testCases = append(testCases, testCase{
7310 name: "TLS13-OnlyPadding",
7311 config: Config{
7312 MaxVersion: VersionTLS13,
7313 MinVersion: VersionTLS13,
7314 Bugs: ProtocolBugs{
7315 OmitRecordContents: true,
7316 RecordPadding: 10,
7317 },
7318 },
7319 shouldFail: true,
7320 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7321 })
7322
7323 testCases = append(testCases, testCase{
7324 name: "TLS13-WrongOuterRecord",
7325 config: Config{
7326 MaxVersion: VersionTLS13,
7327 MinVersion: VersionTLS13,
7328 Bugs: ProtocolBugs{
7329 OuterRecordType: recordTypeHandshake,
7330 },
7331 },
7332 shouldFail: true,
7333 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7334 })
7335}
7336
David Benjamin82261be2016-07-07 14:32:50 -07007337func addChangeCipherSpecTests() {
7338 // Test missing ChangeCipherSpecs.
7339 testCases = append(testCases, testCase{
7340 name: "SkipChangeCipherSpec-Client",
7341 config: Config{
7342 MaxVersion: VersionTLS12,
7343 Bugs: ProtocolBugs{
7344 SkipChangeCipherSpec: true,
7345 },
7346 },
7347 shouldFail: true,
7348 expectedError: ":UNEXPECTED_RECORD:",
7349 })
7350 testCases = append(testCases, testCase{
7351 testType: serverTest,
7352 name: "SkipChangeCipherSpec-Server",
7353 config: Config{
7354 MaxVersion: VersionTLS12,
7355 Bugs: ProtocolBugs{
7356 SkipChangeCipherSpec: true,
7357 },
7358 },
7359 shouldFail: true,
7360 expectedError: ":UNEXPECTED_RECORD:",
7361 })
7362 testCases = append(testCases, testCase{
7363 testType: serverTest,
7364 name: "SkipChangeCipherSpec-Server-NPN",
7365 config: Config{
7366 MaxVersion: VersionTLS12,
7367 NextProtos: []string{"bar"},
7368 Bugs: ProtocolBugs{
7369 SkipChangeCipherSpec: true,
7370 },
7371 },
7372 flags: []string{
7373 "-advertise-npn", "\x03foo\x03bar\x03baz",
7374 },
7375 shouldFail: true,
7376 expectedError: ":UNEXPECTED_RECORD:",
7377 })
7378
7379 // Test synchronization between the handshake and ChangeCipherSpec.
7380 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7381 // rejected. Test both with and without handshake packing to handle both
7382 // when the partial post-CCS message is in its own record and when it is
7383 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007384 for _, packed := range []bool{false, true} {
7385 var suffix string
7386 if packed {
7387 suffix = "-Packed"
7388 }
7389
7390 testCases = append(testCases, testCase{
7391 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7392 config: Config{
7393 MaxVersion: VersionTLS12,
7394 Bugs: ProtocolBugs{
7395 FragmentAcrossChangeCipherSpec: true,
7396 PackHandshakeFlight: packed,
7397 },
7398 },
7399 shouldFail: true,
7400 expectedError: ":UNEXPECTED_RECORD:",
7401 })
7402 testCases = append(testCases, testCase{
7403 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7404 config: Config{
7405 MaxVersion: VersionTLS12,
7406 },
7407 resumeSession: true,
7408 resumeConfig: &Config{
7409 MaxVersion: VersionTLS12,
7410 Bugs: ProtocolBugs{
7411 FragmentAcrossChangeCipherSpec: true,
7412 PackHandshakeFlight: packed,
7413 },
7414 },
7415 shouldFail: true,
7416 expectedError: ":UNEXPECTED_RECORD:",
7417 })
7418 testCases = append(testCases, testCase{
7419 testType: serverTest,
7420 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7421 config: Config{
7422 MaxVersion: VersionTLS12,
7423 Bugs: ProtocolBugs{
7424 FragmentAcrossChangeCipherSpec: true,
7425 PackHandshakeFlight: packed,
7426 },
7427 },
7428 shouldFail: true,
7429 expectedError: ":UNEXPECTED_RECORD:",
7430 })
7431 testCases = append(testCases, testCase{
7432 testType: serverTest,
7433 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7434 config: Config{
7435 MaxVersion: VersionTLS12,
7436 },
7437 resumeSession: true,
7438 resumeConfig: &Config{
7439 MaxVersion: VersionTLS12,
7440 Bugs: ProtocolBugs{
7441 FragmentAcrossChangeCipherSpec: true,
7442 PackHandshakeFlight: packed,
7443 },
7444 },
7445 shouldFail: true,
7446 expectedError: ":UNEXPECTED_RECORD:",
7447 })
7448 testCases = append(testCases, testCase{
7449 testType: serverTest,
7450 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7451 config: Config{
7452 MaxVersion: VersionTLS12,
7453 NextProtos: []string{"bar"},
7454 Bugs: ProtocolBugs{
7455 FragmentAcrossChangeCipherSpec: true,
7456 PackHandshakeFlight: packed,
7457 },
7458 },
7459 flags: []string{
7460 "-advertise-npn", "\x03foo\x03bar\x03baz",
7461 },
7462 shouldFail: true,
7463 expectedError: ":UNEXPECTED_RECORD:",
7464 })
7465 }
7466
David Benjamin61672812016-07-14 23:10:43 -04007467 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7468 // messages in the handshake queue. Do this by testing the server
7469 // reading the client Finished, reversing the flight so Finished comes
7470 // first.
7471 testCases = append(testCases, testCase{
7472 protocol: dtls,
7473 testType: serverTest,
7474 name: "SendUnencryptedFinished-DTLS",
7475 config: Config{
7476 MaxVersion: VersionTLS12,
7477 Bugs: ProtocolBugs{
7478 SendUnencryptedFinished: true,
7479 ReverseHandshakeFragments: true,
7480 },
7481 },
7482 shouldFail: true,
7483 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7484 })
7485
Steven Valdez143e8b32016-07-11 13:19:03 -04007486 // Test synchronization between encryption changes and the handshake in
7487 // TLS 1.3, where ChangeCipherSpec is implicit.
7488 testCases = append(testCases, testCase{
7489 name: "PartialEncryptedExtensionsWithServerHello",
7490 config: Config{
7491 MaxVersion: VersionTLS13,
7492 Bugs: ProtocolBugs{
7493 PartialEncryptedExtensionsWithServerHello: true,
7494 },
7495 },
7496 shouldFail: true,
7497 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7498 })
7499 testCases = append(testCases, testCase{
7500 testType: serverTest,
7501 name: "PartialClientFinishedWithClientHello",
7502 config: Config{
7503 MaxVersion: VersionTLS13,
7504 Bugs: ProtocolBugs{
7505 PartialClientFinishedWithClientHello: true,
7506 },
7507 },
7508 shouldFail: true,
7509 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7510 })
7511
David Benjamin82261be2016-07-07 14:32:50 -07007512 // Test that early ChangeCipherSpecs are handled correctly.
7513 testCases = append(testCases, testCase{
7514 testType: serverTest,
7515 name: "EarlyChangeCipherSpec-server-1",
7516 config: Config{
7517 MaxVersion: VersionTLS12,
7518 Bugs: ProtocolBugs{
7519 EarlyChangeCipherSpec: 1,
7520 },
7521 },
7522 shouldFail: true,
7523 expectedError: ":UNEXPECTED_RECORD:",
7524 })
7525 testCases = append(testCases, testCase{
7526 testType: serverTest,
7527 name: "EarlyChangeCipherSpec-server-2",
7528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 Bugs: ProtocolBugs{
7531 EarlyChangeCipherSpec: 2,
7532 },
7533 },
7534 shouldFail: true,
7535 expectedError: ":UNEXPECTED_RECORD:",
7536 })
7537 testCases = append(testCases, testCase{
7538 protocol: dtls,
7539 name: "StrayChangeCipherSpec",
7540 config: Config{
7541 // TODO(davidben): Once DTLS 1.3 exists, test
7542 // that stray ChangeCipherSpec messages are
7543 // rejected.
7544 MaxVersion: VersionTLS12,
7545 Bugs: ProtocolBugs{
7546 StrayChangeCipherSpec: true,
7547 },
7548 },
7549 })
7550
7551 // Test that the contents of ChangeCipherSpec are checked.
7552 testCases = append(testCases, testCase{
7553 name: "BadChangeCipherSpec-1",
7554 config: Config{
7555 MaxVersion: VersionTLS12,
7556 Bugs: ProtocolBugs{
7557 BadChangeCipherSpec: []byte{2},
7558 },
7559 },
7560 shouldFail: true,
7561 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7562 })
7563 testCases = append(testCases, testCase{
7564 name: "BadChangeCipherSpec-2",
7565 config: Config{
7566 MaxVersion: VersionTLS12,
7567 Bugs: ProtocolBugs{
7568 BadChangeCipherSpec: []byte{1, 1},
7569 },
7570 },
7571 shouldFail: true,
7572 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7573 })
7574 testCases = append(testCases, testCase{
7575 protocol: dtls,
7576 name: "BadChangeCipherSpec-DTLS-1",
7577 config: Config{
7578 MaxVersion: VersionTLS12,
7579 Bugs: ProtocolBugs{
7580 BadChangeCipherSpec: []byte{2},
7581 },
7582 },
7583 shouldFail: true,
7584 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7585 })
7586 testCases = append(testCases, testCase{
7587 protocol: dtls,
7588 name: "BadChangeCipherSpec-DTLS-2",
7589 config: Config{
7590 MaxVersion: VersionTLS12,
7591 Bugs: ProtocolBugs{
7592 BadChangeCipherSpec: []byte{1, 1},
7593 },
7594 },
7595 shouldFail: true,
7596 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7597 })
7598}
7599
David Benjamincd2c8062016-09-09 11:28:16 -04007600type perMessageTest struct {
7601 messageType uint8
7602 test testCase
7603}
7604
7605// makePerMessageTests returns a series of test templates which cover each
7606// message in the TLS handshake. These may be used with bugs like
7607// WrongMessageType to fully test a per-message bug.
7608func makePerMessageTests() []perMessageTest {
7609 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007610 for _, protocol := range []protocol{tls, dtls} {
7611 var suffix string
7612 if protocol == dtls {
7613 suffix = "-DTLS"
7614 }
7615
David Benjamincd2c8062016-09-09 11:28:16 -04007616 ret = append(ret, perMessageTest{
7617 messageType: typeClientHello,
7618 test: testCase{
7619 protocol: protocol,
7620 testType: serverTest,
7621 name: "ClientHello" + suffix,
7622 config: Config{
7623 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007624 },
7625 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007626 })
7627
7628 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007629 ret = append(ret, perMessageTest{
7630 messageType: typeHelloVerifyRequest,
7631 test: testCase{
7632 protocol: protocol,
7633 name: "HelloVerifyRequest" + suffix,
7634 config: Config{
7635 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007636 },
7637 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007638 })
7639 }
7640
David Benjamincd2c8062016-09-09 11:28:16 -04007641 ret = append(ret, perMessageTest{
7642 messageType: typeServerHello,
7643 test: testCase{
7644 protocol: protocol,
7645 name: "ServerHello" + suffix,
7646 config: Config{
7647 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007648 },
7649 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007650 })
7651
David Benjamincd2c8062016-09-09 11:28:16 -04007652 ret = append(ret, perMessageTest{
7653 messageType: typeCertificate,
7654 test: testCase{
7655 protocol: protocol,
7656 name: "ServerCertificate" + suffix,
7657 config: Config{
7658 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007659 },
7660 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007661 })
7662
David Benjamincd2c8062016-09-09 11:28:16 -04007663 ret = append(ret, perMessageTest{
7664 messageType: typeCertificateStatus,
7665 test: testCase{
7666 protocol: protocol,
7667 name: "CertificateStatus" + suffix,
7668 config: Config{
7669 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007670 },
David Benjamincd2c8062016-09-09 11:28:16 -04007671 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007673 })
7674
David Benjamincd2c8062016-09-09 11:28:16 -04007675 ret = append(ret, perMessageTest{
7676 messageType: typeServerKeyExchange,
7677 test: testCase{
7678 protocol: protocol,
7679 name: "ServerKeyExchange" + suffix,
7680 config: Config{
7681 MaxVersion: VersionTLS12,
7682 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007683 },
7684 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007685 })
7686
David Benjamincd2c8062016-09-09 11:28:16 -04007687 ret = append(ret, perMessageTest{
7688 messageType: typeCertificateRequest,
7689 test: testCase{
7690 protocol: protocol,
7691 name: "CertificateRequest" + suffix,
7692 config: Config{
7693 MaxVersion: VersionTLS12,
7694 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007695 },
7696 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007697 })
7698
David Benjamincd2c8062016-09-09 11:28:16 -04007699 ret = append(ret, perMessageTest{
7700 messageType: typeServerHelloDone,
7701 test: testCase{
7702 protocol: protocol,
7703 name: "ServerHelloDone" + suffix,
7704 config: Config{
7705 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007706 },
7707 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007708 })
7709
David Benjamincd2c8062016-09-09 11:28:16 -04007710 ret = append(ret, perMessageTest{
7711 messageType: typeCertificate,
7712 test: testCase{
7713 testType: serverTest,
7714 protocol: protocol,
7715 name: "ClientCertificate" + suffix,
7716 config: Config{
7717 Certificates: []Certificate{rsaCertificate},
7718 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007719 },
David Benjamincd2c8062016-09-09 11:28:16 -04007720 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007721 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007722 })
7723
David Benjamincd2c8062016-09-09 11:28:16 -04007724 ret = append(ret, perMessageTest{
7725 messageType: typeCertificateVerify,
7726 test: testCase{
7727 testType: serverTest,
7728 protocol: protocol,
7729 name: "CertificateVerify" + suffix,
7730 config: Config{
7731 Certificates: []Certificate{rsaCertificate},
7732 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007733 },
David Benjamincd2c8062016-09-09 11:28:16 -04007734 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007735 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007736 })
7737
David Benjamincd2c8062016-09-09 11:28:16 -04007738 ret = append(ret, perMessageTest{
7739 messageType: typeClientKeyExchange,
7740 test: testCase{
7741 testType: serverTest,
7742 protocol: protocol,
7743 name: "ClientKeyExchange" + suffix,
7744 config: Config{
7745 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007746 },
7747 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007748 })
7749
7750 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007751 ret = append(ret, perMessageTest{
7752 messageType: typeNextProtocol,
7753 test: testCase{
7754 testType: serverTest,
7755 protocol: protocol,
7756 name: "NextProtocol" + suffix,
7757 config: Config{
7758 MaxVersion: VersionTLS12,
7759 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007760 },
David Benjamincd2c8062016-09-09 11:28:16 -04007761 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007763 })
7764
David Benjamincd2c8062016-09-09 11:28:16 -04007765 ret = append(ret, perMessageTest{
7766 messageType: typeChannelID,
7767 test: testCase{
7768 testType: serverTest,
7769 protocol: protocol,
7770 name: "ChannelID" + suffix,
7771 config: Config{
7772 MaxVersion: VersionTLS12,
7773 ChannelID: channelIDKey,
7774 },
7775 flags: []string{
7776 "-expect-channel-id",
7777 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007778 },
7779 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007780 })
7781 }
7782
David Benjamincd2c8062016-09-09 11:28:16 -04007783 ret = append(ret, perMessageTest{
7784 messageType: typeFinished,
7785 test: testCase{
7786 testType: serverTest,
7787 protocol: protocol,
7788 name: "ClientFinished" + suffix,
7789 config: Config{
7790 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007791 },
7792 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007793 })
7794
David Benjamincd2c8062016-09-09 11:28:16 -04007795 ret = append(ret, perMessageTest{
7796 messageType: typeNewSessionTicket,
7797 test: testCase{
7798 protocol: protocol,
7799 name: "NewSessionTicket" + suffix,
7800 config: Config{
7801 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007802 },
7803 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007804 })
7805
David Benjamincd2c8062016-09-09 11:28:16 -04007806 ret = append(ret, perMessageTest{
7807 messageType: typeFinished,
7808 test: testCase{
7809 protocol: protocol,
7810 name: "ServerFinished" + suffix,
7811 config: Config{
7812 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007813 },
7814 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007815 })
7816
7817 }
David Benjamincd2c8062016-09-09 11:28:16 -04007818
7819 ret = append(ret, perMessageTest{
7820 messageType: typeClientHello,
7821 test: testCase{
7822 testType: serverTest,
7823 name: "TLS13-ClientHello",
7824 config: Config{
7825 MaxVersion: VersionTLS13,
7826 },
7827 },
7828 })
7829
7830 ret = append(ret, perMessageTest{
7831 messageType: typeServerHello,
7832 test: testCase{
7833 name: "TLS13-ServerHello",
7834 config: Config{
7835 MaxVersion: VersionTLS13,
7836 },
7837 },
7838 })
7839
7840 ret = append(ret, perMessageTest{
7841 messageType: typeEncryptedExtensions,
7842 test: testCase{
7843 name: "TLS13-EncryptedExtensions",
7844 config: Config{
7845 MaxVersion: VersionTLS13,
7846 },
7847 },
7848 })
7849
7850 ret = append(ret, perMessageTest{
7851 messageType: typeCertificateRequest,
7852 test: testCase{
7853 name: "TLS13-CertificateRequest",
7854 config: Config{
7855 MaxVersion: VersionTLS13,
7856 ClientAuth: RequireAnyClientCert,
7857 },
7858 },
7859 })
7860
7861 ret = append(ret, perMessageTest{
7862 messageType: typeCertificate,
7863 test: testCase{
7864 name: "TLS13-ServerCertificate",
7865 config: Config{
7866 MaxVersion: VersionTLS13,
7867 },
7868 },
7869 })
7870
7871 ret = append(ret, perMessageTest{
7872 messageType: typeCertificateVerify,
7873 test: testCase{
7874 name: "TLS13-ServerCertificateVerify",
7875 config: Config{
7876 MaxVersion: VersionTLS13,
7877 },
7878 },
7879 })
7880
7881 ret = append(ret, perMessageTest{
7882 messageType: typeFinished,
7883 test: testCase{
7884 name: "TLS13-ServerFinished",
7885 config: Config{
7886 MaxVersion: VersionTLS13,
7887 },
7888 },
7889 })
7890
7891 ret = append(ret, perMessageTest{
7892 messageType: typeCertificate,
7893 test: testCase{
7894 testType: serverTest,
7895 name: "TLS13-ClientCertificate",
7896 config: Config{
7897 Certificates: []Certificate{rsaCertificate},
7898 MaxVersion: VersionTLS13,
7899 },
7900 flags: []string{"-require-any-client-certificate"},
7901 },
7902 })
7903
7904 ret = append(ret, perMessageTest{
7905 messageType: typeCertificateVerify,
7906 test: testCase{
7907 testType: serverTest,
7908 name: "TLS13-ClientCertificateVerify",
7909 config: Config{
7910 Certificates: []Certificate{rsaCertificate},
7911 MaxVersion: VersionTLS13,
7912 },
7913 flags: []string{"-require-any-client-certificate"},
7914 },
7915 })
7916
7917 ret = append(ret, perMessageTest{
7918 messageType: typeFinished,
7919 test: testCase{
7920 testType: serverTest,
7921 name: "TLS13-ClientFinished",
7922 config: Config{
7923 MaxVersion: VersionTLS13,
7924 },
7925 },
7926 })
7927
7928 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007929}
7930
David Benjamincd2c8062016-09-09 11:28:16 -04007931func addWrongMessageTypeTests() {
7932 for _, t := range makePerMessageTests() {
7933 t.test.name = "WrongMessageType-" + t.test.name
7934 t.test.config.Bugs.SendWrongMessageType = t.messageType
7935 t.test.shouldFail = true
7936 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7937 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007938
David Benjamincd2c8062016-09-09 11:28:16 -04007939 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7940 // In TLS 1.3, a bad ServerHello means the client sends
7941 // an unencrypted alert while the server expects
7942 // encryption, so the alert is not readable by runner.
7943 t.test.expectedLocalError = "local error: bad record MAC"
7944 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007945
David Benjamincd2c8062016-09-09 11:28:16 -04007946 testCases = append(testCases, t.test)
7947 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007948}
7949
David Benjamin639846e2016-09-09 11:41:18 -04007950func addTrailingMessageDataTests() {
7951 for _, t := range makePerMessageTests() {
7952 t.test.name = "TrailingMessageData-" + t.test.name
7953 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7954 t.test.shouldFail = true
7955 t.test.expectedError = ":DECODE_ERROR:"
7956 t.test.expectedLocalError = "remote error: error decoding message"
7957
7958 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7959 // In TLS 1.3, a bad ServerHello means the client sends
7960 // an unencrypted alert while the server expects
7961 // encryption, so the alert is not readable by runner.
7962 t.test.expectedLocalError = "local error: bad record MAC"
7963 }
7964
7965 if t.messageType == typeFinished {
7966 // Bad Finished messages read as the verify data having
7967 // the wrong length.
7968 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7969 t.test.expectedLocalError = "remote error: error decrypting message"
7970 }
7971
7972 testCases = append(testCases, t.test)
7973 }
7974}
7975
Steven Valdez143e8b32016-07-11 13:19:03 -04007976func addTLS13HandshakeTests() {
7977 testCases = append(testCases, testCase{
7978 testType: clientTest,
7979 name: "MissingKeyShare-Client",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 Bugs: ProtocolBugs{
7983 MissingKeyShare: true,
7984 },
7985 },
7986 shouldFail: true,
7987 expectedError: ":MISSING_KEY_SHARE:",
7988 })
7989
7990 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007991 testType: serverTest,
7992 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007993 config: Config{
7994 MaxVersion: VersionTLS13,
7995 Bugs: ProtocolBugs{
7996 MissingKeyShare: true,
7997 },
7998 },
7999 shouldFail: true,
8000 expectedError: ":MISSING_KEY_SHARE:",
8001 })
8002
8003 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008004 testType: serverTest,
8005 name: "DuplicateKeyShares",
8006 config: Config{
8007 MaxVersion: VersionTLS13,
8008 Bugs: ProtocolBugs{
8009 DuplicateKeyShares: true,
8010 },
8011 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008012 shouldFail: true,
8013 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008014 })
8015
8016 testCases = append(testCases, testCase{
8017 testType: clientTest,
8018 name: "EmptyEncryptedExtensions",
8019 config: Config{
8020 MaxVersion: VersionTLS13,
8021 Bugs: ProtocolBugs{
8022 EmptyEncryptedExtensions: true,
8023 },
8024 },
8025 shouldFail: true,
8026 expectedLocalError: "remote error: error decoding message",
8027 })
8028
8029 testCases = append(testCases, testCase{
8030 testType: clientTest,
8031 name: "EncryptedExtensionsWithKeyShare",
8032 config: Config{
8033 MaxVersion: VersionTLS13,
8034 Bugs: ProtocolBugs{
8035 EncryptedExtensionsWithKeyShare: true,
8036 },
8037 },
8038 shouldFail: true,
8039 expectedLocalError: "remote error: unsupported extension",
8040 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008041
8042 testCases = append(testCases, testCase{
8043 testType: serverTest,
8044 name: "SendHelloRetryRequest",
8045 config: Config{
8046 MaxVersion: VersionTLS13,
8047 // Require a HelloRetryRequest for every curve.
8048 DefaultCurves: []CurveID{},
8049 },
8050 expectedCurveID: CurveX25519,
8051 })
8052
8053 testCases = append(testCases, testCase{
8054 testType: serverTest,
8055 name: "SendHelloRetryRequest-2",
8056 config: Config{
8057 MaxVersion: VersionTLS13,
8058 DefaultCurves: []CurveID{CurveP384},
8059 },
8060 // Although the ClientHello did not predict our preferred curve,
8061 // we always select it whether it is predicted or not.
8062 expectedCurveID: CurveX25519,
8063 })
8064
8065 testCases = append(testCases, testCase{
8066 name: "UnknownCurve-HelloRetryRequest",
8067 config: Config{
8068 MaxVersion: VersionTLS13,
8069 // P-384 requires HelloRetryRequest in BoringSSL.
8070 CurvePreferences: []CurveID{CurveP384},
8071 Bugs: ProtocolBugs{
8072 SendHelloRetryRequestCurve: bogusCurve,
8073 },
8074 },
8075 shouldFail: true,
8076 expectedError: ":WRONG_CURVE:",
8077 })
8078
8079 testCases = append(testCases, testCase{
8080 name: "DisabledCurve-HelloRetryRequest",
8081 config: Config{
8082 MaxVersion: VersionTLS13,
8083 CurvePreferences: []CurveID{CurveP256},
8084 Bugs: ProtocolBugs{
8085 IgnorePeerCurvePreferences: true,
8086 },
8087 },
8088 flags: []string{"-p384-only"},
8089 shouldFail: true,
8090 expectedError: ":WRONG_CURVE:",
8091 })
8092
8093 testCases = append(testCases, testCase{
8094 name: "UnnecessaryHelloRetryRequest",
8095 config: Config{
8096 MaxVersion: VersionTLS13,
8097 Bugs: ProtocolBugs{
8098 UnnecessaryHelloRetryRequest: true,
8099 },
8100 },
8101 shouldFail: true,
8102 expectedError: ":WRONG_CURVE:",
8103 })
8104
8105 testCases = append(testCases, testCase{
8106 name: "SecondHelloRetryRequest",
8107 config: Config{
8108 MaxVersion: VersionTLS13,
8109 // P-384 requires HelloRetryRequest in BoringSSL.
8110 CurvePreferences: []CurveID{CurveP384},
8111 Bugs: ProtocolBugs{
8112 SecondHelloRetryRequest: true,
8113 },
8114 },
8115 shouldFail: true,
8116 expectedError: ":UNEXPECTED_MESSAGE:",
8117 })
8118
8119 testCases = append(testCases, testCase{
8120 testType: serverTest,
8121 name: "SecondClientHelloMissingKeyShare",
8122 config: Config{
8123 MaxVersion: VersionTLS13,
8124 DefaultCurves: []CurveID{},
8125 Bugs: ProtocolBugs{
8126 SecondClientHelloMissingKeyShare: true,
8127 },
8128 },
8129 shouldFail: true,
8130 expectedError: ":MISSING_KEY_SHARE:",
8131 })
8132
8133 testCases = append(testCases, testCase{
8134 testType: serverTest,
8135 name: "SecondClientHelloWrongCurve",
8136 config: Config{
8137 MaxVersion: VersionTLS13,
8138 DefaultCurves: []CurveID{},
8139 Bugs: ProtocolBugs{
8140 MisinterpretHelloRetryRequestCurve: CurveP521,
8141 },
8142 },
8143 shouldFail: true,
8144 expectedError: ":WRONG_CURVE:",
8145 })
8146
8147 testCases = append(testCases, testCase{
8148 name: "HelloRetryRequestVersionMismatch",
8149 config: Config{
8150 MaxVersion: VersionTLS13,
8151 // P-384 requires HelloRetryRequest in BoringSSL.
8152 CurvePreferences: []CurveID{CurveP384},
8153 Bugs: ProtocolBugs{
8154 SendServerHelloVersion: 0x0305,
8155 },
8156 },
8157 shouldFail: true,
8158 expectedError: ":WRONG_VERSION_NUMBER:",
8159 })
8160
8161 testCases = append(testCases, testCase{
8162 name: "HelloRetryRequestCurveMismatch",
8163 config: Config{
8164 MaxVersion: VersionTLS13,
8165 // P-384 requires HelloRetryRequest in BoringSSL.
8166 CurvePreferences: []CurveID{CurveP384},
8167 Bugs: ProtocolBugs{
8168 // Send P-384 (correct) in the HelloRetryRequest.
8169 SendHelloRetryRequestCurve: CurveP384,
8170 // But send P-256 in the ServerHello.
8171 SendCurve: CurveP256,
8172 },
8173 },
8174 shouldFail: true,
8175 expectedError: ":WRONG_CURVE:",
8176 })
8177
8178 // Test the server selecting a curve that requires a HelloRetryRequest
8179 // without sending it.
8180 testCases = append(testCases, testCase{
8181 name: "SkipHelloRetryRequest",
8182 config: Config{
8183 MaxVersion: VersionTLS13,
8184 // P-384 requires HelloRetryRequest in BoringSSL.
8185 CurvePreferences: []CurveID{CurveP384},
8186 Bugs: ProtocolBugs{
8187 SkipHelloRetryRequest: true,
8188 },
8189 },
8190 shouldFail: true,
8191 expectedError: ":WRONG_CURVE:",
8192 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008193
8194 testCases = append(testCases, testCase{
8195 name: "TLS13-RequestContextInHandshake",
8196 config: Config{
8197 MaxVersion: VersionTLS13,
8198 MinVersion: VersionTLS13,
8199 ClientAuth: RequireAnyClientCert,
8200 Bugs: ProtocolBugs{
8201 SendRequestContext: []byte("request context"),
8202 },
8203 },
8204 flags: []string{
8205 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8206 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8207 },
8208 shouldFail: true,
8209 expectedError: ":DECODE_ERROR:",
8210 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008211
8212 testCases = append(testCases, testCase{
8213 testType: serverTest,
8214 name: "TLS13-TrailingKeyShareData",
8215 config: Config{
8216 MaxVersion: VersionTLS13,
8217 Bugs: ProtocolBugs{
8218 TrailingKeyShareData: true,
8219 },
8220 },
8221 shouldFail: true,
8222 expectedError: ":DECODE_ERROR:",
8223 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008224}
8225
David Benjaminf3fbade2016-09-19 13:08:16 -04008226func addPeekTests() {
8227 // Test SSL_peek works, including on empty records.
8228 testCases = append(testCases, testCase{
8229 name: "Peek-Basic",
8230 sendEmptyRecords: 1,
8231 flags: []string{"-peek-then-read"},
8232 })
8233
8234 // Test SSL_peek can drive the initial handshake.
8235 testCases = append(testCases, testCase{
8236 name: "Peek-ImplicitHandshake",
8237 flags: []string{
8238 "-peek-then-read",
8239 "-implicit-handshake",
8240 },
8241 })
8242
8243 // Test SSL_peek can discover and drive a renegotiation.
8244 testCases = append(testCases, testCase{
8245 name: "Peek-Renegotiate",
8246 config: Config{
8247 MaxVersion: VersionTLS12,
8248 },
8249 renegotiate: 1,
8250 flags: []string{
8251 "-peek-then-read",
8252 "-renegotiate-freely",
8253 "-expect-total-renegotiations", "1",
8254 },
8255 })
8256
8257 // Test SSL_peek can discover a close_notify.
8258 testCases = append(testCases, testCase{
8259 name: "Peek-Shutdown",
8260 config: Config{
8261 Bugs: ProtocolBugs{
8262 ExpectCloseNotify: true,
8263 },
8264 },
8265 flags: []string{
8266 "-peek-then-read",
8267 "-check-close-notify",
8268 },
8269 })
8270
8271 // Test SSL_peek can discover an alert.
8272 testCases = append(testCases, testCase{
8273 name: "Peek-Alert",
8274 config: Config{
8275 Bugs: ProtocolBugs{
8276 SendSpuriousAlert: alertRecordOverflow,
8277 },
8278 },
8279 flags: []string{"-peek-then-read"},
8280 shouldFail: true,
8281 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8282 })
8283
8284 // Test SSL_peek can handle KeyUpdate.
8285 testCases = append(testCases, testCase{
8286 name: "Peek-KeyUpdate",
8287 config: Config{
8288 MaxVersion: VersionTLS13,
8289 Bugs: ProtocolBugs{
8290 SendKeyUpdateBeforeEveryAppDataRecord: true,
8291 },
8292 },
8293 flags: []string{"-peek-then-read"},
8294 })
8295}
8296
Adam Langley7c803a62015-06-15 15:35:05 -07008297func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008298 defer wg.Done()
8299
8300 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008301 var err error
8302
8303 if *mallocTest < 0 {
8304 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008305 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008306 } else {
8307 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8308 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008309 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008310 if err != nil {
8311 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8312 }
8313 break
8314 }
8315 }
8316 }
Adam Langley95c29f32014-06-20 12:00:00 -07008317 statusChan <- statusMsg{test: test, err: err}
8318 }
8319}
8320
8321type statusMsg struct {
8322 test *testCase
8323 started bool
8324 err error
8325}
8326
David Benjamin5f237bc2015-02-11 17:14:15 -05008327func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008328 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008329
David Benjamin5f237bc2015-02-11 17:14:15 -05008330 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008331 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008332 if !*pipe {
8333 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008334 var erase string
8335 for i := 0; i < lineLen; i++ {
8336 erase += "\b \b"
8337 }
8338 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008339 }
8340
Adam Langley95c29f32014-06-20 12:00:00 -07008341 if msg.started {
8342 started++
8343 } else {
8344 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008345
8346 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008347 if msg.err == errUnimplemented {
8348 if *pipe {
8349 // Print each test instead of a status line.
8350 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8351 }
8352 unimplemented++
8353 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8354 } else {
8355 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8356 failed++
8357 testOutput.addResult(msg.test.name, "FAIL")
8358 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008359 } else {
8360 if *pipe {
8361 // Print each test instead of a status line.
8362 fmt.Printf("PASSED (%s)\n", msg.test.name)
8363 }
8364 testOutput.addResult(msg.test.name, "PASS")
8365 }
Adam Langley95c29f32014-06-20 12:00:00 -07008366 }
8367
David Benjamin5f237bc2015-02-11 17:14:15 -05008368 if !*pipe {
8369 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008370 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008371 lineLen = len(line)
8372 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008373 }
Adam Langley95c29f32014-06-20 12:00:00 -07008374 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008375
8376 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008377}
8378
8379func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008380 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008381 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008382 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008383
Adam Langley7c803a62015-06-15 15:35:05 -07008384 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008385 addCipherSuiteTests()
8386 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008387 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008388 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008389 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008390 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008391 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008392 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008393 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008394 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008395 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008396 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008397 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008398 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008399 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008400 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008401 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008402 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008403 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008404 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008405 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008406 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008407 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008408 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008409 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008410 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008411 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008412 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008413 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008414
8415 var wg sync.WaitGroup
8416
Adam Langley7c803a62015-06-15 15:35:05 -07008417 statusChan := make(chan statusMsg, *numWorkers)
8418 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008419 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008420
EKRf71d7ed2016-08-06 13:25:12 -07008421 if len(*shimConfigFile) != 0 {
8422 encoded, err := ioutil.ReadFile(*shimConfigFile)
8423 if err != nil {
8424 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8425 os.Exit(1)
8426 }
8427
8428 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8429 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8430 os.Exit(1)
8431 }
8432 }
8433
David Benjamin025b3d32014-07-01 19:53:04 -04008434 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008435
Adam Langley7c803a62015-06-15 15:35:05 -07008436 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008437 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008438 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008439 }
8440
David Benjamin270f0a72016-03-17 14:41:36 -04008441 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008442 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008443 matched := true
8444 if len(*testToRun) != 0 {
8445 var err error
8446 matched, err = filepath.Match(*testToRun, testCases[i].name)
8447 if err != nil {
8448 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8449 os.Exit(1)
8450 }
8451 }
8452
EKRf71d7ed2016-08-06 13:25:12 -07008453 if !*includeDisabled {
8454 for pattern := range shimConfig.DisabledTests {
8455 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8456 if err != nil {
8457 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8458 os.Exit(1)
8459 }
8460
8461 if isDisabled {
8462 matched = false
8463 break
8464 }
8465 }
8466 }
8467
David Benjamin17e12922016-07-28 18:04:43 -04008468 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008469 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008470 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008471 }
8472 }
David Benjamin17e12922016-07-28 18:04:43 -04008473
David Benjamin270f0a72016-03-17 14:41:36 -04008474 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008475 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008476 os.Exit(1)
8477 }
Adam Langley95c29f32014-06-20 12:00:00 -07008478
8479 close(testChan)
8480 wg.Wait()
8481 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008482 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008483
8484 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008485
8486 if *jsonOutput != "" {
8487 if err := testOutput.writeTo(*jsonOutput); err != nil {
8488 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8489 }
8490 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008491
EKR842ae6c2016-07-27 09:22:05 +02008492 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8493 os.Exit(1)
8494 }
8495
8496 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008497 os.Exit(1)
8498 }
Adam Langley95c29f32014-06-20 12:00:00 -07008499}