blob: ea660abe98372876f4831972b6cef4a9b86dcb5e [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{
4197 SendClientVersion: 0x03ff,
4198 },
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{
4208 SendClientVersion: 0x0400,
4209 },
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{
4232 // 0x0201 is the lowest version expressable in
4233 // DTLS.
4234 SendClientVersion: 0x0201,
4235 },
4236 },
4237 shouldFail: true,
4238 expectedError: ":UNSUPPORTED_PROTOCOL:",
4239 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004240
David Benjamin2dc02042016-09-19 19:57:37 -04004241 testCases = append(testCases, testCase{
4242 name: "ServerBogusVersion",
4243 config: Config{
4244 Bugs: ProtocolBugs{
4245 SendServerHelloVersion: 0x1234,
4246 },
4247 },
4248 shouldFail: true,
4249 expectedError: ":UNSUPPORTED_PROTOCOL:",
4250 })
4251
David Benjamin1f61f0d2016-07-10 12:20:35 -04004252 // Test TLS 1.3's downgrade signal.
4253 testCases = append(testCases, testCase{
4254 name: "Downgrade-TLS12-Client",
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 NegotiateVersion: VersionTLS12,
4258 },
4259 },
David Benjamin55108632016-08-11 22:01:18 -04004260 // TODO(davidben): This test should fail once TLS 1.3 is final
4261 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004262 })
4263 testCases = append(testCases, testCase{
4264 testType: serverTest,
4265 name: "Downgrade-TLS12-Server",
4266 config: Config{
4267 Bugs: ProtocolBugs{
4268 SendClientVersion: VersionTLS12,
4269 },
4270 },
David Benjamin55108632016-08-11 22:01:18 -04004271 // TODO(davidben): This test should fail once TLS 1.3 is final
4272 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004273 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004274}
4275
David Benjaminaccb4542014-12-12 23:44:33 -05004276func addMinimumVersionTests() {
4277 for i, shimVers := range tlsVersions {
4278 // Assemble flags to disable all older versions on the shim.
4279 var flags []string
4280 for _, vers := range tlsVersions[:i] {
4281 flags = append(flags, vers.flag)
4282 }
4283
4284 for _, runnerVers := range tlsVersions {
4285 protocols := []protocol{tls}
4286 if runnerVers.hasDTLS && shimVers.hasDTLS {
4287 protocols = append(protocols, dtls)
4288 }
4289 for _, protocol := range protocols {
4290 suffix := shimVers.name + "-" + runnerVers.name
4291 if protocol == dtls {
4292 suffix += "-DTLS"
4293 }
4294 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4295
David Benjaminaccb4542014-12-12 23:44:33 -05004296 var expectedVersion uint16
4297 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004298 var expectedClientError, expectedServerError string
4299 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004300 if runnerVers.version >= shimVers.version {
4301 expectedVersion = runnerVers.version
4302 } else {
4303 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004304 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4305 expectedServerLocalError = "remote error: protocol version not supported"
4306 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4307 // If the client's minimum version is TLS 1.3 and the runner's
4308 // maximum is below TLS 1.2, the runner will fail to select a
4309 // cipher before the shim rejects the selected version.
4310 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4311 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4312 } else {
4313 expectedClientError = expectedServerError
4314 expectedClientLocalError = expectedServerLocalError
4315 }
David Benjaminaccb4542014-12-12 23:44:33 -05004316 }
4317
4318 testCases = append(testCases, testCase{
4319 protocol: protocol,
4320 testType: clientTest,
4321 name: "MinimumVersion-Client-" + suffix,
4322 config: Config{
4323 MaxVersion: runnerVers.version,
4324 },
David Benjamin87909c02014-12-13 01:55:01 -05004325 flags: flags,
4326 expectedVersion: expectedVersion,
4327 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004328 expectedError: expectedClientError,
4329 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004330 })
4331 testCases = append(testCases, testCase{
4332 protocol: protocol,
4333 testType: clientTest,
4334 name: "MinimumVersion-Client2-" + suffix,
4335 config: Config{
4336 MaxVersion: runnerVers.version,
4337 },
David Benjamin87909c02014-12-13 01:55:01 -05004338 flags: []string{"-min-version", shimVersFlag},
4339 expectedVersion: expectedVersion,
4340 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004341 expectedError: expectedClientError,
4342 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004343 })
4344
4345 testCases = append(testCases, testCase{
4346 protocol: protocol,
4347 testType: serverTest,
4348 name: "MinimumVersion-Server-" + suffix,
4349 config: Config{
4350 MaxVersion: runnerVers.version,
4351 },
David Benjamin87909c02014-12-13 01:55:01 -05004352 flags: flags,
4353 expectedVersion: expectedVersion,
4354 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004355 expectedError: expectedServerError,
4356 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004357 })
4358 testCases = append(testCases, testCase{
4359 protocol: protocol,
4360 testType: serverTest,
4361 name: "MinimumVersion-Server2-" + suffix,
4362 config: Config{
4363 MaxVersion: runnerVers.version,
4364 },
David Benjamin87909c02014-12-13 01:55:01 -05004365 flags: []string{"-min-version", shimVersFlag},
4366 expectedVersion: expectedVersion,
4367 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004368 expectedError: expectedServerError,
4369 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004370 })
4371 }
4372 }
4373 }
4374}
4375
David Benjamine78bfde2014-09-06 12:45:15 -04004376func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004377 // TODO(davidben): Extensions, where applicable, all move their server
4378 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4379 // tests for both. Also test interaction with 0-RTT when implemented.
4380
David Benjamin97d17d92016-07-14 16:12:00 -04004381 // Repeat extensions tests all versions except SSL 3.0.
4382 for _, ver := range tlsVersions {
4383 if ver.version == VersionSSL30 {
4384 continue
4385 }
4386
David Benjamin97d17d92016-07-14 16:12:00 -04004387 // Test that duplicate extensions are rejected.
4388 testCases = append(testCases, testCase{
4389 testType: clientTest,
4390 name: "DuplicateExtensionClient-" + ver.name,
4391 config: Config{
4392 MaxVersion: ver.version,
4393 Bugs: ProtocolBugs{
4394 DuplicateExtension: true,
4395 },
David Benjamine78bfde2014-09-06 12:45:15 -04004396 },
David Benjamin97d17d92016-07-14 16:12:00 -04004397 shouldFail: true,
4398 expectedLocalError: "remote error: error decoding message",
4399 })
4400 testCases = append(testCases, testCase{
4401 testType: serverTest,
4402 name: "DuplicateExtensionServer-" + ver.name,
4403 config: Config{
4404 MaxVersion: ver.version,
4405 Bugs: ProtocolBugs{
4406 DuplicateExtension: true,
4407 },
David Benjamine78bfde2014-09-06 12:45:15 -04004408 },
David Benjamin97d17d92016-07-14 16:12:00 -04004409 shouldFail: true,
4410 expectedLocalError: "remote error: error decoding message",
4411 })
4412
4413 // Test SNI.
4414 testCases = append(testCases, testCase{
4415 testType: clientTest,
4416 name: "ServerNameExtensionClient-" + ver.name,
4417 config: Config{
4418 MaxVersion: ver.version,
4419 Bugs: ProtocolBugs{
4420 ExpectServerName: "example.com",
4421 },
David Benjamine78bfde2014-09-06 12:45:15 -04004422 },
David Benjamin97d17d92016-07-14 16:12:00 -04004423 flags: []string{"-host-name", "example.com"},
4424 })
4425 testCases = append(testCases, testCase{
4426 testType: clientTest,
4427 name: "ServerNameExtensionClientMismatch-" + ver.name,
4428 config: Config{
4429 MaxVersion: ver.version,
4430 Bugs: ProtocolBugs{
4431 ExpectServerName: "mismatch.com",
4432 },
David Benjamine78bfde2014-09-06 12:45:15 -04004433 },
David Benjamin97d17d92016-07-14 16:12:00 -04004434 flags: []string{"-host-name", "example.com"},
4435 shouldFail: true,
4436 expectedLocalError: "tls: unexpected server name",
4437 })
4438 testCases = append(testCases, testCase{
4439 testType: clientTest,
4440 name: "ServerNameExtensionClientMissing-" + ver.name,
4441 config: Config{
4442 MaxVersion: ver.version,
4443 Bugs: ProtocolBugs{
4444 ExpectServerName: "missing.com",
4445 },
David Benjamine78bfde2014-09-06 12:45:15 -04004446 },
David Benjamin97d17d92016-07-14 16:12:00 -04004447 shouldFail: true,
4448 expectedLocalError: "tls: unexpected server name",
4449 })
4450 testCases = append(testCases, testCase{
4451 testType: serverTest,
4452 name: "ServerNameExtensionServer-" + ver.name,
4453 config: Config{
4454 MaxVersion: ver.version,
4455 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004456 },
David Benjamin97d17d92016-07-14 16:12:00 -04004457 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004458 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004459 })
4460
4461 // Test ALPN.
4462 testCases = append(testCases, testCase{
4463 testType: clientTest,
4464 name: "ALPNClient-" + ver.name,
4465 config: Config{
4466 MaxVersion: ver.version,
4467 NextProtos: []string{"foo"},
4468 },
4469 flags: []string{
4470 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4471 "-expect-alpn", "foo",
4472 },
4473 expectedNextProto: "foo",
4474 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004475 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004476 })
4477 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004478 testType: clientTest,
4479 name: "ALPNClient-Mismatch-" + ver.name,
4480 config: Config{
4481 MaxVersion: ver.version,
4482 Bugs: ProtocolBugs{
4483 SendALPN: "baz",
4484 },
4485 },
4486 flags: []string{
4487 "-advertise-alpn", "\x03foo\x03bar",
4488 },
4489 shouldFail: true,
4490 expectedError: ":INVALID_ALPN_PROTOCOL:",
4491 expectedLocalError: "remote error: illegal parameter",
4492 })
4493 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004494 testType: serverTest,
4495 name: "ALPNServer-" + ver.name,
4496 config: Config{
4497 MaxVersion: ver.version,
4498 NextProtos: []string{"foo", "bar", "baz"},
4499 },
4500 flags: []string{
4501 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4502 "-select-alpn", "foo",
4503 },
4504 expectedNextProto: "foo",
4505 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004506 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004507 })
4508 testCases = append(testCases, testCase{
4509 testType: serverTest,
4510 name: "ALPNServer-Decline-" + ver.name,
4511 config: Config{
4512 MaxVersion: ver.version,
4513 NextProtos: []string{"foo", "bar", "baz"},
4514 },
4515 flags: []string{"-decline-alpn"},
4516 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004517 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004518 })
4519
David Benjamin25fe85b2016-08-09 20:00:32 -04004520 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4521 // called once.
4522 testCases = append(testCases, testCase{
4523 testType: serverTest,
4524 name: "ALPNServer-Async-" + ver.name,
4525 config: Config{
4526 MaxVersion: ver.version,
4527 NextProtos: []string{"foo", "bar", "baz"},
4528 },
4529 flags: []string{
4530 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4531 "-select-alpn", "foo",
4532 "-async",
4533 },
4534 expectedNextProto: "foo",
4535 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004536 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004537 })
4538
David Benjamin97d17d92016-07-14 16:12:00 -04004539 var emptyString string
4540 testCases = append(testCases, testCase{
4541 testType: clientTest,
4542 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4543 config: Config{
4544 MaxVersion: ver.version,
4545 NextProtos: []string{""},
4546 Bugs: ProtocolBugs{
4547 // A server returning an empty ALPN protocol
4548 // should be rejected.
4549 ALPNProtocol: &emptyString,
4550 },
4551 },
4552 flags: []string{
4553 "-advertise-alpn", "\x03foo",
4554 },
4555 shouldFail: true,
4556 expectedError: ":PARSE_TLSEXT:",
4557 })
4558 testCases = append(testCases, testCase{
4559 testType: serverTest,
4560 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4561 config: Config{
4562 MaxVersion: ver.version,
4563 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004564 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004565 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004566 },
David Benjamin97d17d92016-07-14 16:12:00 -04004567 flags: []string{
4568 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004569 },
David Benjamin97d17d92016-07-14 16:12:00 -04004570 shouldFail: true,
4571 expectedError: ":PARSE_TLSEXT:",
4572 })
4573
4574 // Test NPN and the interaction with ALPN.
4575 if ver.version < VersionTLS13 {
4576 // Test that the server prefers ALPN over NPN.
4577 testCases = append(testCases, testCase{
4578 testType: serverTest,
4579 name: "ALPNServer-Preferred-" + ver.name,
4580 config: Config{
4581 MaxVersion: ver.version,
4582 NextProtos: []string{"foo", "bar", "baz"},
4583 },
4584 flags: []string{
4585 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4586 "-select-alpn", "foo",
4587 "-advertise-npn", "\x03foo\x03bar\x03baz",
4588 },
4589 expectedNextProto: "foo",
4590 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004591 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004592 })
4593 testCases = append(testCases, testCase{
4594 testType: serverTest,
4595 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4596 config: Config{
4597 MaxVersion: ver.version,
4598 NextProtos: []string{"foo", "bar", "baz"},
4599 Bugs: ProtocolBugs{
4600 SwapNPNAndALPN: true,
4601 },
4602 },
4603 flags: []string{
4604 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4605 "-select-alpn", "foo",
4606 "-advertise-npn", "\x03foo\x03bar\x03baz",
4607 },
4608 expectedNextProto: "foo",
4609 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004610 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004611 })
4612
4613 // Test that negotiating both NPN and ALPN is forbidden.
4614 testCases = append(testCases, testCase{
4615 name: "NegotiateALPNAndNPN-" + ver.name,
4616 config: Config{
4617 MaxVersion: ver.version,
4618 NextProtos: []string{"foo", "bar", "baz"},
4619 Bugs: ProtocolBugs{
4620 NegotiateALPNAndNPN: true,
4621 },
4622 },
4623 flags: []string{
4624 "-advertise-alpn", "\x03foo",
4625 "-select-next-proto", "foo",
4626 },
4627 shouldFail: true,
4628 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4629 })
4630 testCases = append(testCases, testCase{
4631 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4632 config: Config{
4633 MaxVersion: ver.version,
4634 NextProtos: []string{"foo", "bar", "baz"},
4635 Bugs: ProtocolBugs{
4636 NegotiateALPNAndNPN: true,
4637 SwapNPNAndALPN: true,
4638 },
4639 },
4640 flags: []string{
4641 "-advertise-alpn", "\x03foo",
4642 "-select-next-proto", "foo",
4643 },
4644 shouldFail: true,
4645 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4646 })
4647
4648 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4649 testCases = append(testCases, testCase{
4650 name: "DisableNPN-" + ver.name,
4651 config: Config{
4652 MaxVersion: ver.version,
4653 NextProtos: []string{"foo"},
4654 },
4655 flags: []string{
4656 "-select-next-proto", "foo",
4657 "-disable-npn",
4658 },
4659 expectNoNextProto: true,
4660 })
4661 }
4662
4663 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004664
4665 // Resume with a corrupt ticket.
4666 testCases = append(testCases, testCase{
4667 testType: serverTest,
4668 name: "CorruptTicket-" + ver.name,
4669 config: Config{
4670 MaxVersion: ver.version,
4671 Bugs: ProtocolBugs{
4672 CorruptTicket: true,
4673 },
4674 },
4675 resumeSession: true,
4676 expectResumeRejected: true,
4677 })
4678 // Test the ticket callback, with and without renewal.
4679 testCases = append(testCases, testCase{
4680 testType: serverTest,
4681 name: "TicketCallback-" + ver.name,
4682 config: Config{
4683 MaxVersion: ver.version,
4684 },
4685 resumeSession: true,
4686 flags: []string{"-use-ticket-callback"},
4687 })
4688 testCases = append(testCases, testCase{
4689 testType: serverTest,
4690 name: "TicketCallback-Renew-" + ver.name,
4691 config: Config{
4692 MaxVersion: ver.version,
4693 Bugs: ProtocolBugs{
4694 ExpectNewTicket: true,
4695 },
4696 },
4697 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4698 resumeSession: true,
4699 })
4700
4701 // Test that the ticket callback is only called once when everything before
4702 // it in the ClientHello is asynchronous. This corrupts the ticket so
4703 // certificate selection callbacks run.
4704 testCases = append(testCases, testCase{
4705 testType: serverTest,
4706 name: "TicketCallback-SingleCall-" + ver.name,
4707 config: Config{
4708 MaxVersion: ver.version,
4709 Bugs: ProtocolBugs{
4710 CorruptTicket: true,
4711 },
4712 },
4713 resumeSession: true,
4714 expectResumeRejected: true,
4715 flags: []string{
4716 "-use-ticket-callback",
4717 "-async",
4718 },
4719 })
4720
4721 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004722 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004723 testCases = append(testCases, testCase{
4724 testType: serverTest,
4725 name: "OversizedSessionId-" + ver.name,
4726 config: Config{
4727 MaxVersion: ver.version,
4728 Bugs: ProtocolBugs{
4729 OversizedSessionId: true,
4730 },
4731 },
4732 resumeSession: true,
4733 shouldFail: true,
4734 expectedError: ":DECODE_ERROR:",
4735 })
4736 }
4737
4738 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4739 // are ignored.
4740 if ver.hasDTLS {
4741 testCases = append(testCases, testCase{
4742 protocol: dtls,
4743 name: "SRTP-Client-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4747 },
4748 flags: []string{
4749 "-srtp-profiles",
4750 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4751 },
4752 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4753 })
4754 testCases = append(testCases, testCase{
4755 protocol: dtls,
4756 testType: serverTest,
4757 name: "SRTP-Server-" + ver.name,
4758 config: Config{
4759 MaxVersion: ver.version,
4760 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4761 },
4762 flags: []string{
4763 "-srtp-profiles",
4764 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4765 },
4766 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4767 })
4768 // Test that the MKI is ignored.
4769 testCases = append(testCases, testCase{
4770 protocol: dtls,
4771 testType: serverTest,
4772 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4773 config: Config{
4774 MaxVersion: ver.version,
4775 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4776 Bugs: ProtocolBugs{
4777 SRTPMasterKeyIdentifer: "bogus",
4778 },
4779 },
4780 flags: []string{
4781 "-srtp-profiles",
4782 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4783 },
4784 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4785 })
4786 // Test that SRTP isn't negotiated on the server if there were
4787 // no matching profiles.
4788 testCases = append(testCases, testCase{
4789 protocol: dtls,
4790 testType: serverTest,
4791 name: "SRTP-Server-NoMatch-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 SRTPProtectionProfiles: []uint16{100, 101, 102},
4795 },
4796 flags: []string{
4797 "-srtp-profiles",
4798 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4799 },
4800 expectedSRTPProtectionProfile: 0,
4801 })
4802 // Test that the server returning an invalid SRTP profile is
4803 // flagged as an error by the client.
4804 testCases = append(testCases, testCase{
4805 protocol: dtls,
4806 name: "SRTP-Client-NoMatch-" + ver.name,
4807 config: Config{
4808 MaxVersion: ver.version,
4809 Bugs: ProtocolBugs{
4810 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4811 },
4812 },
4813 flags: []string{
4814 "-srtp-profiles",
4815 "SRTP_AES128_CM_SHA1_80",
4816 },
4817 shouldFail: true,
4818 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4819 })
4820 }
4821
4822 // Test SCT list.
4823 testCases = append(testCases, testCase{
4824 name: "SignedCertificateTimestampList-Client-" + ver.name,
4825 testType: clientTest,
4826 config: Config{
4827 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004828 },
David Benjamin97d17d92016-07-14 16:12:00 -04004829 flags: []string{
4830 "-enable-signed-cert-timestamps",
4831 "-expect-signed-cert-timestamps",
4832 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004833 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004834 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004835 })
4836 testCases = append(testCases, testCase{
4837 name: "SendSCTListOnResume-" + ver.name,
4838 config: Config{
4839 MaxVersion: ver.version,
4840 Bugs: ProtocolBugs{
4841 SendSCTListOnResume: []byte("bogus"),
4842 },
David Benjamind98452d2015-06-16 14:16:23 -04004843 },
David Benjamin97d17d92016-07-14 16:12:00 -04004844 flags: []string{
4845 "-enable-signed-cert-timestamps",
4846 "-expect-signed-cert-timestamps",
4847 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004848 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004849 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004850 })
4851 testCases = append(testCases, testCase{
4852 name: "SignedCertificateTimestampList-Server-" + ver.name,
4853 testType: serverTest,
4854 config: Config{
4855 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004856 },
David Benjamin97d17d92016-07-14 16:12:00 -04004857 flags: []string{
4858 "-signed-cert-timestamps",
4859 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004860 },
David Benjamin97d17d92016-07-14 16:12:00 -04004861 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004862 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004863 })
4864 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004865
Paul Lietar4fac72e2015-09-09 13:44:55 +01004866 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004867 testType: clientTest,
4868 name: "ClientHelloPadding",
4869 config: Config{
4870 Bugs: ProtocolBugs{
4871 RequireClientHelloSize: 512,
4872 },
4873 },
4874 // This hostname just needs to be long enough to push the
4875 // ClientHello into F5's danger zone between 256 and 511 bytes
4876 // long.
4877 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4878 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004879
4880 // Extensions should not function in SSL 3.0.
4881 testCases = append(testCases, testCase{
4882 testType: serverTest,
4883 name: "SSLv3Extensions-NoALPN",
4884 config: Config{
4885 MaxVersion: VersionSSL30,
4886 NextProtos: []string{"foo", "bar", "baz"},
4887 },
4888 flags: []string{
4889 "-select-alpn", "foo",
4890 },
4891 expectNoNextProto: true,
4892 })
4893
4894 // Test session tickets separately as they follow a different codepath.
4895 testCases = append(testCases, testCase{
4896 testType: serverTest,
4897 name: "SSLv3Extensions-NoTickets",
4898 config: Config{
4899 MaxVersion: VersionSSL30,
4900 Bugs: ProtocolBugs{
4901 // Historically, session tickets in SSL 3.0
4902 // failed in different ways depending on whether
4903 // the client supported renegotiation_info.
4904 NoRenegotiationInfo: true,
4905 },
4906 },
4907 resumeSession: true,
4908 })
4909 testCases = append(testCases, testCase{
4910 testType: serverTest,
4911 name: "SSLv3Extensions-NoTickets2",
4912 config: Config{
4913 MaxVersion: VersionSSL30,
4914 },
4915 resumeSession: true,
4916 })
4917
4918 // But SSL 3.0 does send and process renegotiation_info.
4919 testCases = append(testCases, testCase{
4920 testType: serverTest,
4921 name: "SSLv3Extensions-RenegotiationInfo",
4922 config: Config{
4923 MaxVersion: VersionSSL30,
4924 Bugs: ProtocolBugs{
4925 RequireRenegotiationInfo: true,
4926 },
4927 },
4928 })
4929 testCases = append(testCases, testCase{
4930 testType: serverTest,
4931 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4932 config: Config{
4933 MaxVersion: VersionSSL30,
4934 Bugs: ProtocolBugs{
4935 NoRenegotiationInfo: true,
4936 SendRenegotiationSCSV: true,
4937 RequireRenegotiationInfo: true,
4938 },
4939 },
4940 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004941
4942 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4943 // in ServerHello.
4944 testCases = append(testCases, testCase{
4945 name: "NPN-Forbidden-TLS13",
4946 config: Config{
4947 MaxVersion: VersionTLS13,
4948 NextProtos: []string{"foo"},
4949 Bugs: ProtocolBugs{
4950 NegotiateNPNAtAllVersions: true,
4951 },
4952 },
4953 flags: []string{"-select-next-proto", "foo"},
4954 shouldFail: true,
4955 expectedError: ":ERROR_PARSING_EXTENSION:",
4956 })
4957 testCases = append(testCases, testCase{
4958 name: "EMS-Forbidden-TLS13",
4959 config: Config{
4960 MaxVersion: VersionTLS13,
4961 Bugs: ProtocolBugs{
4962 NegotiateEMSAtAllVersions: true,
4963 },
4964 },
4965 shouldFail: true,
4966 expectedError: ":ERROR_PARSING_EXTENSION:",
4967 })
4968 testCases = append(testCases, testCase{
4969 name: "RenegotiationInfo-Forbidden-TLS13",
4970 config: Config{
4971 MaxVersion: VersionTLS13,
4972 Bugs: ProtocolBugs{
4973 NegotiateRenegotiationInfoAtAllVersions: true,
4974 },
4975 },
4976 shouldFail: true,
4977 expectedError: ":ERROR_PARSING_EXTENSION:",
4978 })
4979 testCases = append(testCases, testCase{
4980 name: "ChannelID-Forbidden-TLS13",
4981 config: Config{
4982 MaxVersion: VersionTLS13,
4983 RequestChannelID: true,
4984 Bugs: ProtocolBugs{
4985 NegotiateChannelIDAtAllVersions: true,
4986 },
4987 },
4988 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4989 shouldFail: true,
4990 expectedError: ":ERROR_PARSING_EXTENSION:",
4991 })
4992 testCases = append(testCases, testCase{
4993 name: "Ticket-Forbidden-TLS13",
4994 config: Config{
4995 MaxVersion: VersionTLS12,
4996 },
4997 resumeConfig: &Config{
4998 MaxVersion: VersionTLS13,
4999 Bugs: ProtocolBugs{
5000 AdvertiseTicketExtension: true,
5001 },
5002 },
5003 resumeSession: true,
5004 shouldFail: true,
5005 expectedError: ":ERROR_PARSING_EXTENSION:",
5006 })
5007
5008 // Test that illegal extensions in TLS 1.3 are declined by the server if
5009 // offered in ClientHello. The runner's server will fail if this occurs,
5010 // so we exercise the offering path. (EMS and Renegotiation Info are
5011 // implicit in every test.)
5012 testCases = append(testCases, testCase{
5013 testType: serverTest,
5014 name: "ChannelID-Declined-TLS13",
5015 config: Config{
5016 MaxVersion: VersionTLS13,
5017 ChannelID: channelIDKey,
5018 },
5019 flags: []string{"-enable-channel-id"},
5020 })
5021 testCases = append(testCases, testCase{
5022 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005023 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005024 config: Config{
5025 MaxVersion: VersionTLS13,
5026 NextProtos: []string{"bar"},
5027 },
5028 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5029 })
David Benjamin196df5b2016-09-21 16:23:27 -04005030
5031 testCases = append(testCases, testCase{
5032 testType: serverTest,
5033 name: "InvalidChannelIDSignature",
5034 config: Config{
5035 MaxVersion: VersionTLS12,
5036 ChannelID: channelIDKey,
5037 Bugs: ProtocolBugs{
5038 InvalidChannelIDSignature: true,
5039 },
5040 },
5041 flags: []string{"-enable-channel-id"},
5042 shouldFail: true,
5043 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5044 expectedLocalError: "remote error: error decrypting message",
5045 })
David Benjamine78bfde2014-09-06 12:45:15 -04005046}
5047
David Benjamin01fe8202014-09-24 15:21:44 -04005048func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005049 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005050 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005051 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5052 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5053 // TLS 1.3 only shares ciphers with TLS 1.2, so
5054 // we skip certain combinations and use a
5055 // different cipher to test with.
5056 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5057 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5058 continue
5059 }
5060 }
5061
David Benjamin8b8c0062014-11-23 02:47:52 -05005062 protocols := []protocol{tls}
5063 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5064 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005065 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005066 for _, protocol := range protocols {
5067 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5068 if protocol == dtls {
5069 suffix += "-DTLS"
5070 }
5071
David Benjaminece3de92015-03-16 18:02:20 -04005072 if sessionVers.version == resumeVers.version {
5073 testCases = append(testCases, testCase{
5074 protocol: protocol,
5075 name: "Resume-Client" + suffix,
5076 resumeSession: true,
5077 config: Config{
5078 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005079 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005080 Bugs: ProtocolBugs{
5081 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5082 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5083 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005084 },
David Benjaminece3de92015-03-16 18:02:20 -04005085 expectedVersion: sessionVers.version,
5086 expectedResumeVersion: resumeVers.version,
5087 })
5088 } else {
David Benjamin405da482016-08-08 17:25:07 -04005089 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5090
5091 // Offering a TLS 1.3 session sends an empty session ID, so
5092 // there is no way to convince a non-lookahead client the
5093 // session was resumed. It will appear to the client that a
5094 // stray ChangeCipherSpec was sent.
5095 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5096 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005097 }
5098
David Benjaminece3de92015-03-16 18:02:20 -04005099 testCases = append(testCases, testCase{
5100 protocol: protocol,
5101 name: "Resume-Client-Mismatch" + suffix,
5102 resumeSession: true,
5103 config: Config{
5104 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005105 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 },
David Benjaminece3de92015-03-16 18:02:20 -04005107 expectedVersion: sessionVers.version,
5108 resumeConfig: &Config{
5109 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005110 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005111 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005112 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005113 },
5114 },
5115 expectedResumeVersion: resumeVers.version,
5116 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005117 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005118 })
5119 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005120
5121 testCases = append(testCases, testCase{
5122 protocol: protocol,
5123 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005124 resumeSession: true,
5125 config: Config{
5126 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005127 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005128 },
5129 expectedVersion: sessionVers.version,
5130 resumeConfig: &Config{
5131 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005132 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005133 },
5134 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005135 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005136 expectedResumeVersion: resumeVers.version,
5137 })
5138
David Benjamin8b8c0062014-11-23 02:47:52 -05005139 testCases = append(testCases, testCase{
5140 protocol: protocol,
5141 testType: serverTest,
5142 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005143 resumeSession: true,
5144 config: Config{
5145 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005146 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005147 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005148 expectedVersion: sessionVers.version,
5149 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005150 resumeConfig: &Config{
5151 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005152 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005153 Bugs: ProtocolBugs{
5154 SendBothTickets: true,
5155 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005156 },
5157 expectedResumeVersion: resumeVers.version,
5158 })
5159 }
David Benjamin01fe8202014-09-24 15:21:44 -04005160 }
5161 }
David Benjaminece3de92015-03-16 18:02:20 -04005162
5163 testCases = append(testCases, testCase{
5164 name: "Resume-Client-CipherMismatch",
5165 resumeSession: true,
5166 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005167 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005168 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5169 },
5170 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005171 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005172 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5173 Bugs: ProtocolBugs{
5174 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5175 },
5176 },
5177 shouldFail: true,
5178 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5179 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005180
5181 testCases = append(testCases, testCase{
5182 name: "Resume-Client-CipherMismatch-TLS13",
5183 resumeSession: true,
5184 config: Config{
5185 MaxVersion: VersionTLS13,
5186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5187 },
5188 resumeConfig: &Config{
5189 MaxVersion: VersionTLS13,
5190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5191 Bugs: ProtocolBugs{
5192 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5193 },
5194 },
5195 shouldFail: true,
5196 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5197 })
David Benjamin01fe8202014-09-24 15:21:44 -04005198}
5199
Adam Langley2ae77d22014-10-28 17:29:33 -07005200func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005201 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005202 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005203 testType: serverTest,
5204 name: "Renegotiate-Server-Forbidden",
5205 config: Config{
5206 MaxVersion: VersionTLS12,
5207 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005208 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005209 shouldFail: true,
5210 expectedError: ":NO_RENEGOTIATION:",
5211 expectedLocalError: "remote error: no renegotiation",
5212 })
Adam Langley5021b222015-06-12 18:27:58 -07005213 // The server shouldn't echo the renegotiation extension unless
5214 // requested by the client.
5215 testCases = append(testCases, testCase{
5216 testType: serverTest,
5217 name: "Renegotiate-Server-NoExt",
5218 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005219 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005220 Bugs: ProtocolBugs{
5221 NoRenegotiationInfo: true,
5222 RequireRenegotiationInfo: true,
5223 },
5224 },
5225 shouldFail: true,
5226 expectedLocalError: "renegotiation extension missing",
5227 })
5228 // The renegotiation SCSV should be sufficient for the server to echo
5229 // the extension.
5230 testCases = append(testCases, testCase{
5231 testType: serverTest,
5232 name: "Renegotiate-Server-NoExt-SCSV",
5233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005234 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005235 Bugs: ProtocolBugs{
5236 NoRenegotiationInfo: true,
5237 SendRenegotiationSCSV: true,
5238 RequireRenegotiationInfo: true,
5239 },
5240 },
5241 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005242 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005243 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005244 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005245 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005246 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005247 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005248 },
5249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005250 renegotiate: 1,
5251 flags: []string{
5252 "-renegotiate-freely",
5253 "-expect-total-renegotiations", "1",
5254 },
David Benjamincdea40c2015-03-19 14:09:43 -04005255 })
5256 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005257 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005258 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005259 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005260 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005261 Bugs: ProtocolBugs{
5262 EmptyRenegotiationInfo: true,
5263 },
5264 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005265 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005266 shouldFail: true,
5267 expectedError: ":RENEGOTIATION_MISMATCH:",
5268 })
5269 testCases = append(testCases, testCase{
5270 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005271 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005272 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005273 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005274 Bugs: ProtocolBugs{
5275 BadRenegotiationInfo: true,
5276 },
5277 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005278 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005279 shouldFail: true,
5280 expectedError: ":RENEGOTIATION_MISMATCH:",
5281 })
5282 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005283 name: "Renegotiate-Client-Downgrade",
5284 renegotiate: 1,
5285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005286 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005287 Bugs: ProtocolBugs{
5288 NoRenegotiationInfoAfterInitial: true,
5289 },
5290 },
5291 flags: []string{"-renegotiate-freely"},
5292 shouldFail: true,
5293 expectedError: ":RENEGOTIATION_MISMATCH:",
5294 })
5295 testCases = append(testCases, testCase{
5296 name: "Renegotiate-Client-Upgrade",
5297 renegotiate: 1,
5298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005299 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005300 Bugs: ProtocolBugs{
5301 NoRenegotiationInfoInInitial: true,
5302 },
5303 },
5304 flags: []string{"-renegotiate-freely"},
5305 shouldFail: true,
5306 expectedError: ":RENEGOTIATION_MISMATCH:",
5307 })
5308 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005309 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005310 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005311 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005312 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005313 Bugs: ProtocolBugs{
5314 NoRenegotiationInfo: true,
5315 },
5316 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005317 flags: []string{
5318 "-renegotiate-freely",
5319 "-expect-total-renegotiations", "1",
5320 },
David Benjamincff0b902015-05-15 23:09:47 -04005321 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005322
5323 // Test that the server may switch ciphers on renegotiation without
5324 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005325 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005326 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005327 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005328 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005329 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005330 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005331 },
5332 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005333 flags: []string{
5334 "-renegotiate-freely",
5335 "-expect-total-renegotiations", "1",
5336 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005337 })
5338 testCases = append(testCases, testCase{
5339 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005340 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005341 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005342 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005343 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5344 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005345 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005346 flags: []string{
5347 "-renegotiate-freely",
5348 "-expect-total-renegotiations", "1",
5349 },
David Benjaminb16346b2015-04-08 19:16:58 -04005350 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005351
5352 // Test that the server may not switch versions on renegotiation.
5353 testCases = append(testCases, testCase{
5354 name: "Renegotiate-Client-SwitchVersion",
5355 config: Config{
5356 MaxVersion: VersionTLS12,
5357 // Pick a cipher which exists at both versions.
5358 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5359 Bugs: ProtocolBugs{
5360 NegotiateVersionOnRenego: VersionTLS11,
5361 },
5362 },
5363 renegotiate: 1,
5364 flags: []string{
5365 "-renegotiate-freely",
5366 "-expect-total-renegotiations", "1",
5367 },
5368 shouldFail: true,
5369 expectedError: ":WRONG_SSL_VERSION:",
5370 })
5371
David Benjaminb16346b2015-04-08 19:16:58 -04005372 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005373 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005374 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005375 config: Config{
5376 MaxVersion: VersionTLS10,
5377 Bugs: ProtocolBugs{
5378 RequireSameRenegoClientVersion: true,
5379 },
5380 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005381 flags: []string{
5382 "-renegotiate-freely",
5383 "-expect-total-renegotiations", "1",
5384 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005385 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005386 testCases = append(testCases, testCase{
5387 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005388 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005389 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005390 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5392 NextProtos: []string{"foo"},
5393 },
5394 flags: []string{
5395 "-false-start",
5396 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005397 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005398 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005399 },
5400 shimWritesFirst: true,
5401 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005402
5403 // Client-side renegotiation controls.
5404 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005405 name: "Renegotiate-Client-Forbidden-1",
5406 config: Config{
5407 MaxVersion: VersionTLS12,
5408 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005409 renegotiate: 1,
5410 shouldFail: true,
5411 expectedError: ":NO_RENEGOTIATION:",
5412 expectedLocalError: "remote error: no renegotiation",
5413 })
5414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005415 name: "Renegotiate-Client-Once-1",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005419 renegotiate: 1,
5420 flags: []string{
5421 "-renegotiate-once",
5422 "-expect-total-renegotiations", "1",
5423 },
5424 })
5425 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005426 name: "Renegotiate-Client-Freely-1",
5427 config: Config{
5428 MaxVersion: VersionTLS12,
5429 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005430 renegotiate: 1,
5431 flags: []string{
5432 "-renegotiate-freely",
5433 "-expect-total-renegotiations", "1",
5434 },
5435 })
5436 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005437 name: "Renegotiate-Client-Once-2",
5438 config: Config{
5439 MaxVersion: VersionTLS12,
5440 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005441 renegotiate: 2,
5442 flags: []string{"-renegotiate-once"},
5443 shouldFail: true,
5444 expectedError: ":NO_RENEGOTIATION:",
5445 expectedLocalError: "remote error: no renegotiation",
5446 })
5447 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005448 name: "Renegotiate-Client-Freely-2",
5449 config: Config{
5450 MaxVersion: VersionTLS12,
5451 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005452 renegotiate: 2,
5453 flags: []string{
5454 "-renegotiate-freely",
5455 "-expect-total-renegotiations", "2",
5456 },
5457 })
Adam Langley27a0d082015-11-03 13:34:10 -08005458 testCases = append(testCases, testCase{
5459 name: "Renegotiate-Client-NoIgnore",
5460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005461 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005462 Bugs: ProtocolBugs{
5463 SendHelloRequestBeforeEveryAppDataRecord: true,
5464 },
5465 },
5466 shouldFail: true,
5467 expectedError: ":NO_RENEGOTIATION:",
5468 })
5469 testCases = append(testCases, testCase{
5470 name: "Renegotiate-Client-Ignore",
5471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005472 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005473 Bugs: ProtocolBugs{
5474 SendHelloRequestBeforeEveryAppDataRecord: true,
5475 },
5476 },
5477 flags: []string{
5478 "-renegotiate-ignore",
5479 "-expect-total-renegotiations", "0",
5480 },
5481 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005482
David Benjamin397c8e62016-07-08 14:14:36 -07005483 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005484 testCases = append(testCases, testCase{
5485 name: "StrayHelloRequest",
5486 config: Config{
5487 MaxVersion: VersionTLS12,
5488 Bugs: ProtocolBugs{
5489 SendHelloRequestBeforeEveryHandshakeMessage: true,
5490 },
5491 },
5492 })
5493 testCases = append(testCases, testCase{
5494 name: "StrayHelloRequest-Packed",
5495 config: Config{
5496 MaxVersion: VersionTLS12,
5497 Bugs: ProtocolBugs{
5498 PackHandshakeFlight: true,
5499 SendHelloRequestBeforeEveryHandshakeMessage: true,
5500 },
5501 },
5502 })
5503
David Benjamin12d2c482016-07-24 10:56:51 -04005504 // Test renegotiation works if HelloRequest and server Finished come in
5505 // the same record.
5506 testCases = append(testCases, testCase{
5507 name: "Renegotiate-Client-Packed",
5508 config: Config{
5509 MaxVersion: VersionTLS12,
5510 Bugs: ProtocolBugs{
5511 PackHandshakeFlight: true,
5512 PackHelloRequestWithFinished: true,
5513 },
5514 },
5515 renegotiate: 1,
5516 flags: []string{
5517 "-renegotiate-freely",
5518 "-expect-total-renegotiations", "1",
5519 },
5520 })
5521
David Benjamin397c8e62016-07-08 14:14:36 -07005522 // Renegotiation is forbidden in TLS 1.3.
5523 testCases = append(testCases, testCase{
5524 name: "Renegotiate-Client-TLS13",
5525 config: Config{
5526 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005527 Bugs: ProtocolBugs{
5528 SendHelloRequestBeforeEveryAppDataRecord: true,
5529 },
David Benjamin397c8e62016-07-08 14:14:36 -07005530 },
David Benjamin397c8e62016-07-08 14:14:36 -07005531 flags: []string{
5532 "-renegotiate-freely",
5533 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005534 shouldFail: true,
5535 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005536 })
5537
5538 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5539 testCases = append(testCases, testCase{
5540 name: "StrayHelloRequest-TLS13",
5541 config: Config{
5542 MaxVersion: VersionTLS13,
5543 Bugs: ProtocolBugs{
5544 SendHelloRequestBeforeEveryHandshakeMessage: true,
5545 },
5546 },
5547 shouldFail: true,
5548 expectedError: ":UNEXPECTED_MESSAGE:",
5549 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005550}
5551
David Benjamin5e961c12014-11-07 01:48:35 -05005552func addDTLSReplayTests() {
5553 // Test that sequence number replays are detected.
5554 testCases = append(testCases, testCase{
5555 protocol: dtls,
5556 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005557 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005558 replayWrites: true,
5559 })
5560
David Benjamin8e6db492015-07-25 18:29:23 -04005561 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005562 // than the retransmit window.
5563 testCases = append(testCases, testCase{
5564 protocol: dtls,
5565 name: "DTLS-Replay-LargeGaps",
5566 config: Config{
5567 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005568 SequenceNumberMapping: func(in uint64) uint64 {
5569 return in * 127
5570 },
David Benjamin5e961c12014-11-07 01:48:35 -05005571 },
5572 },
David Benjamin8e6db492015-07-25 18:29:23 -04005573 messageCount: 200,
5574 replayWrites: true,
5575 })
5576
5577 // Test the incoming sequence number changing non-monotonically.
5578 testCases = append(testCases, testCase{
5579 protocol: dtls,
5580 name: "DTLS-Replay-NonMonotonic",
5581 config: Config{
5582 Bugs: ProtocolBugs{
5583 SequenceNumberMapping: func(in uint64) uint64 {
5584 return in ^ 31
5585 },
5586 },
5587 },
5588 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005589 replayWrites: true,
5590 })
5591}
5592
Nick Harper60edffd2016-06-21 15:19:24 -07005593var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005594 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005595 id signatureAlgorithm
5596 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005597}{
Nick Harper60edffd2016-06-21 15:19:24 -07005598 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5599 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5600 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5601 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005602 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005603 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5604 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5605 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005606 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5607 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5608 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005609 // Tests for key types prior to TLS 1.2.
5610 {"RSA", 0, testCertRSA},
5611 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005612}
5613
Nick Harper60edffd2016-06-21 15:19:24 -07005614const fakeSigAlg1 signatureAlgorithm = 0x2a01
5615const fakeSigAlg2 signatureAlgorithm = 0xff01
5616
5617func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005618 // Not all ciphers involve a signature. Advertise a list which gives all
5619 // versions a signing cipher.
5620 signingCiphers := []uint16{
5621 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5622 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5623 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5624 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5625 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5626 }
5627
David Benjaminca3d5452016-07-14 12:51:01 -04005628 var allAlgorithms []signatureAlgorithm
5629 for _, alg := range testSignatureAlgorithms {
5630 if alg.id != 0 {
5631 allAlgorithms = append(allAlgorithms, alg.id)
5632 }
5633 }
5634
Nick Harper60edffd2016-06-21 15:19:24 -07005635 // Make sure each signature algorithm works. Include some fake values in
5636 // the list and ensure they're ignored.
5637 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005638 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005639 if (ver.version < VersionTLS12) != (alg.id == 0) {
5640 continue
5641 }
5642
5643 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5644 // or remove it in C.
5645 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005646 continue
5647 }
Nick Harper60edffd2016-06-21 15:19:24 -07005648
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005649 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005650 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005651 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5652 shouldFail = true
5653 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005654 // RSA-PKCS1 does not exist in TLS 1.3.
5655 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5656 shouldFail = true
5657 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005658
5659 var signError, verifyError string
5660 if shouldFail {
5661 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5662 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005663 }
David Benjamin000800a2014-11-14 01:43:59 -05005664
David Benjamin1fb125c2016-07-08 18:52:12 -07005665 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005666
David Benjamin7a41d372016-07-09 11:21:54 -07005667 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005668 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005669 config: Config{
5670 MaxVersion: ver.version,
5671 ClientAuth: RequireAnyClientCert,
5672 VerifySignatureAlgorithms: []signatureAlgorithm{
5673 fakeSigAlg1,
5674 alg.id,
5675 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005676 },
David Benjamin7a41d372016-07-09 11:21:54 -07005677 },
5678 flags: []string{
5679 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5680 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5681 "-enable-all-curves",
5682 },
5683 shouldFail: shouldFail,
5684 expectedError: signError,
5685 expectedPeerSignatureAlgorithm: alg.id,
5686 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005687
David Benjamin7a41d372016-07-09 11:21:54 -07005688 testCases = append(testCases, testCase{
5689 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005690 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005691 config: Config{
5692 MaxVersion: ver.version,
5693 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5694 SignSignatureAlgorithms: []signatureAlgorithm{
5695 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005696 },
David Benjamin7a41d372016-07-09 11:21:54 -07005697 Bugs: ProtocolBugs{
5698 SkipECDSACurveCheck: shouldFail,
5699 IgnoreSignatureVersionChecks: shouldFail,
5700 // The client won't advertise 1.3-only algorithms after
5701 // version negotiation.
5702 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005703 },
David Benjamin7a41d372016-07-09 11:21:54 -07005704 },
5705 flags: []string{
5706 "-require-any-client-certificate",
5707 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5708 "-enable-all-curves",
5709 },
5710 shouldFail: shouldFail,
5711 expectedError: verifyError,
5712 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005713
5714 testCases = append(testCases, testCase{
5715 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005716 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005717 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005718 MaxVersion: ver.version,
5719 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005720 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005721 fakeSigAlg1,
5722 alg.id,
5723 fakeSigAlg2,
5724 },
5725 },
5726 flags: []string{
5727 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5728 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5729 "-enable-all-curves",
5730 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005731 shouldFail: shouldFail,
5732 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005733 expectedPeerSignatureAlgorithm: alg.id,
5734 })
5735
5736 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005737 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005738 config: Config{
5739 MaxVersion: ver.version,
5740 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005741 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005742 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005743 alg.id,
5744 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005745 Bugs: ProtocolBugs{
5746 SkipECDSACurveCheck: shouldFail,
5747 IgnoreSignatureVersionChecks: shouldFail,
5748 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005749 },
5750 flags: []string{
5751 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5752 "-enable-all-curves",
5753 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005754 shouldFail: shouldFail,
5755 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005756 })
David Benjamin5208fd42016-07-13 21:43:25 -04005757
5758 if !shouldFail {
5759 testCases = append(testCases, testCase{
5760 testType: serverTest,
5761 name: "ClientAuth-InvalidSignature" + suffix,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5765 SignSignatureAlgorithms: []signatureAlgorithm{
5766 alg.id,
5767 },
5768 Bugs: ProtocolBugs{
5769 InvalidSignature: true,
5770 },
5771 },
5772 flags: []string{
5773 "-require-any-client-certificate",
5774 "-enable-all-curves",
5775 },
5776 shouldFail: true,
5777 expectedError: ":BAD_SIGNATURE:",
5778 })
5779
5780 testCases = append(testCases, testCase{
5781 name: "ServerAuth-InvalidSignature" + suffix,
5782 config: Config{
5783 MaxVersion: ver.version,
5784 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5785 CipherSuites: signingCiphers,
5786 SignSignatureAlgorithms: []signatureAlgorithm{
5787 alg.id,
5788 },
5789 Bugs: ProtocolBugs{
5790 InvalidSignature: true,
5791 },
5792 },
5793 flags: []string{"-enable-all-curves"},
5794 shouldFail: true,
5795 expectedError: ":BAD_SIGNATURE:",
5796 })
5797 }
David Benjaminca3d5452016-07-14 12:51:01 -04005798
5799 if ver.version >= VersionTLS12 && !shouldFail {
5800 testCases = append(testCases, testCase{
5801 name: "ClientAuth-Sign-Negotiate" + suffix,
5802 config: Config{
5803 MaxVersion: ver.version,
5804 ClientAuth: RequireAnyClientCert,
5805 VerifySignatureAlgorithms: allAlgorithms,
5806 },
5807 flags: []string{
5808 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5809 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5810 "-enable-all-curves",
5811 "-signing-prefs", strconv.Itoa(int(alg.id)),
5812 },
5813 expectedPeerSignatureAlgorithm: alg.id,
5814 })
5815
5816 testCases = append(testCases, testCase{
5817 testType: serverTest,
5818 name: "ServerAuth-Sign-Negotiate" + suffix,
5819 config: Config{
5820 MaxVersion: ver.version,
5821 CipherSuites: signingCiphers,
5822 VerifySignatureAlgorithms: allAlgorithms,
5823 },
5824 flags: []string{
5825 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5826 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5827 "-enable-all-curves",
5828 "-signing-prefs", strconv.Itoa(int(alg.id)),
5829 },
5830 expectedPeerSignatureAlgorithm: alg.id,
5831 })
5832 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005833 }
David Benjamin000800a2014-11-14 01:43:59 -05005834 }
5835
Nick Harper60edffd2016-06-21 15:19:24 -07005836 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005837 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005838 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005839 config: Config{
5840 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005841 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005842 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005843 signatureECDSAWithP521AndSHA512,
5844 signatureRSAPKCS1WithSHA384,
5845 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005846 },
5847 },
5848 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005849 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5850 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005851 },
Nick Harper60edffd2016-06-21 15:19:24 -07005852 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005853 })
5854
5855 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005856 name: "ClientAuth-SignatureType-TLS13",
5857 config: Config{
5858 ClientAuth: RequireAnyClientCert,
5859 MaxVersion: VersionTLS13,
5860 VerifySignatureAlgorithms: []signatureAlgorithm{
5861 signatureECDSAWithP521AndSHA512,
5862 signatureRSAPKCS1WithSHA384,
5863 signatureRSAPSSWithSHA384,
5864 signatureECDSAWithSHA1,
5865 },
5866 },
5867 flags: []string{
5868 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5869 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5870 },
5871 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5872 })
5873
5874 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005875 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005876 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005878 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005880 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005881 signatureECDSAWithP521AndSHA512,
5882 signatureRSAPKCS1WithSHA384,
5883 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005884 },
5885 },
Nick Harper60edffd2016-06-21 15:19:24 -07005886 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005887 })
5888
Steven Valdez143e8b32016-07-11 13:19:03 -04005889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "ServerAuth-SignatureType-TLS13",
5892 config: Config{
5893 MaxVersion: VersionTLS13,
5894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5895 VerifySignatureAlgorithms: []signatureAlgorithm{
5896 signatureECDSAWithP521AndSHA512,
5897 signatureRSAPKCS1WithSHA384,
5898 signatureRSAPSSWithSHA384,
5899 signatureECDSAWithSHA1,
5900 },
5901 },
5902 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5903 })
5904
David Benjamina95e9f32016-07-08 16:28:04 -07005905 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005906 testCases = append(testCases, testCase{
5907 testType: serverTest,
5908 name: "Verify-ClientAuth-SignatureType",
5909 config: Config{
5910 MaxVersion: VersionTLS12,
5911 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005912 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005913 signatureRSAPKCS1WithSHA256,
5914 },
5915 Bugs: ProtocolBugs{
5916 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5917 },
5918 },
5919 flags: []string{
5920 "-require-any-client-certificate",
5921 },
5922 shouldFail: true,
5923 expectedError: ":WRONG_SIGNATURE_TYPE:",
5924 })
5925
5926 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005927 testType: serverTest,
5928 name: "Verify-ClientAuth-SignatureType-TLS13",
5929 config: Config{
5930 MaxVersion: VersionTLS13,
5931 Certificates: []Certificate{rsaCertificate},
5932 SignSignatureAlgorithms: []signatureAlgorithm{
5933 signatureRSAPSSWithSHA256,
5934 },
5935 Bugs: ProtocolBugs{
5936 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5937 },
5938 },
5939 flags: []string{
5940 "-require-any-client-certificate",
5941 },
5942 shouldFail: true,
5943 expectedError: ":WRONG_SIGNATURE_TYPE:",
5944 })
5945
5946 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005947 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005948 config: Config{
5949 MaxVersion: VersionTLS12,
5950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005951 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005952 signatureRSAPKCS1WithSHA256,
5953 },
5954 Bugs: ProtocolBugs{
5955 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5956 },
5957 },
5958 shouldFail: true,
5959 expectedError: ":WRONG_SIGNATURE_TYPE:",
5960 })
5961
Steven Valdez143e8b32016-07-11 13:19:03 -04005962 testCases = append(testCases, testCase{
5963 name: "Verify-ServerAuth-SignatureType-TLS13",
5964 config: Config{
5965 MaxVersion: VersionTLS13,
5966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5967 SignSignatureAlgorithms: []signatureAlgorithm{
5968 signatureRSAPSSWithSHA256,
5969 },
5970 Bugs: ProtocolBugs{
5971 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5972 },
5973 },
5974 shouldFail: true,
5975 expectedError: ":WRONG_SIGNATURE_TYPE:",
5976 })
5977
David Benjamin51dd7d62016-07-08 16:07:01 -07005978 // Test that, if the list is missing, the peer falls back to SHA-1 in
5979 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005980 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005981 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005983 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005984 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005985 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005986 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005987 },
5988 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005989 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005990 },
5991 },
5992 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005993 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5994 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005995 },
5996 })
5997
5998 testCases = append(testCases, testCase{
5999 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006000 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006001 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006002 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006003 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006004 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006005 },
6006 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006007 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006008 },
6009 },
David Benjaminee32bea2016-08-17 13:36:44 -04006010 flags: []string{
6011 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6012 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6013 },
6014 })
6015
6016 testCases = append(testCases, testCase{
6017 name: "ClientAuth-SHA1-Fallback-ECDSA",
6018 config: Config{
6019 MaxVersion: VersionTLS12,
6020 ClientAuth: RequireAnyClientCert,
6021 VerifySignatureAlgorithms: []signatureAlgorithm{
6022 signatureECDSAWithSHA1,
6023 },
6024 Bugs: ProtocolBugs{
6025 NoSignatureAlgorithms: true,
6026 },
6027 },
6028 flags: []string{
6029 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6030 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6031 },
6032 })
6033
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "ServerAuth-SHA1-Fallback-ECDSA",
6037 config: Config{
6038 MaxVersion: VersionTLS12,
6039 VerifySignatureAlgorithms: []signatureAlgorithm{
6040 signatureECDSAWithSHA1,
6041 },
6042 Bugs: ProtocolBugs{
6043 NoSignatureAlgorithms: true,
6044 },
6045 },
6046 flags: []string{
6047 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6048 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6049 },
David Benjamin000800a2014-11-14 01:43:59 -05006050 })
David Benjamin72dc7832015-03-16 17:49:43 -04006051
David Benjamin51dd7d62016-07-08 16:07:01 -07006052 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006053 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006054 config: Config{
6055 MaxVersion: VersionTLS13,
6056 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006057 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006058 signatureRSAPKCS1WithSHA1,
6059 },
6060 Bugs: ProtocolBugs{
6061 NoSignatureAlgorithms: true,
6062 },
6063 },
6064 flags: []string{
6065 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6066 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6067 },
David Benjamin48901652016-08-01 12:12:47 -04006068 shouldFail: true,
6069 // An empty CertificateRequest signature algorithm list is a
6070 // syntax error in TLS 1.3.
6071 expectedError: ":DECODE_ERROR:",
6072 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006073 })
6074
6075 testCases = append(testCases, testCase{
6076 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006077 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006078 config: Config{
6079 MaxVersion: VersionTLS13,
6080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006081 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006082 signatureRSAPKCS1WithSHA1,
6083 },
6084 Bugs: ProtocolBugs{
6085 NoSignatureAlgorithms: true,
6086 },
6087 },
6088 shouldFail: true,
6089 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6090 })
6091
David Benjaminb62d2872016-07-18 14:55:02 +02006092 // Test that hash preferences are enforced. BoringSSL does not implement
6093 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006094 testCases = append(testCases, testCase{
6095 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006096 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006099 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006100 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006101 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 },
6106 },
6107 flags: []string{"-require-any-client-certificate"},
6108 shouldFail: true,
6109 expectedError: ":WRONG_SIGNATURE_TYPE:",
6110 })
6111
6112 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006113 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006115 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006117 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006118 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006119 },
6120 Bugs: ProtocolBugs{
6121 IgnorePeerSignatureAlgorithmPreferences: true,
6122 },
6123 },
6124 shouldFail: true,
6125 expectedError: ":WRONG_SIGNATURE_TYPE:",
6126 })
David Benjaminb62d2872016-07-18 14:55:02 +02006127 testCases = append(testCases, testCase{
6128 testType: serverTest,
6129 name: "ClientAuth-Enforced-TLS13",
6130 config: Config{
6131 MaxVersion: VersionTLS13,
6132 Certificates: []Certificate{rsaCertificate},
6133 SignSignatureAlgorithms: []signatureAlgorithm{
6134 signatureRSAPKCS1WithMD5,
6135 },
6136 Bugs: ProtocolBugs{
6137 IgnorePeerSignatureAlgorithmPreferences: true,
6138 IgnoreSignatureVersionChecks: true,
6139 },
6140 },
6141 flags: []string{"-require-any-client-certificate"},
6142 shouldFail: true,
6143 expectedError: ":WRONG_SIGNATURE_TYPE:",
6144 })
6145
6146 testCases = append(testCases, testCase{
6147 name: "ServerAuth-Enforced-TLS13",
6148 config: Config{
6149 MaxVersion: VersionTLS13,
6150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6151 SignSignatureAlgorithms: []signatureAlgorithm{
6152 signatureRSAPKCS1WithMD5,
6153 },
6154 Bugs: ProtocolBugs{
6155 IgnorePeerSignatureAlgorithmPreferences: true,
6156 IgnoreSignatureVersionChecks: true,
6157 },
6158 },
6159 shouldFail: true,
6160 expectedError: ":WRONG_SIGNATURE_TYPE:",
6161 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006162
6163 // Test that the agreed upon digest respects the client preferences and
6164 // the server digests.
6165 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006166 name: "NoCommonAlgorithms-Digests",
6167 config: Config{
6168 MaxVersion: VersionTLS12,
6169 ClientAuth: RequireAnyClientCert,
6170 VerifySignatureAlgorithms: []signatureAlgorithm{
6171 signatureRSAPKCS1WithSHA512,
6172 signatureRSAPKCS1WithSHA1,
6173 },
6174 },
6175 flags: []string{
6176 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6177 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6178 "-digest-prefs", "SHA256",
6179 },
6180 shouldFail: true,
6181 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6182 })
6183 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006184 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006186 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006187 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006188 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006189 signatureRSAPKCS1WithSHA512,
6190 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006191 },
6192 },
6193 flags: []string{
6194 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6195 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006196 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006197 },
David Benjaminca3d5452016-07-14 12:51:01 -04006198 shouldFail: true,
6199 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6200 })
6201 testCases = append(testCases, testCase{
6202 name: "NoCommonAlgorithms-TLS13",
6203 config: Config{
6204 MaxVersion: VersionTLS13,
6205 ClientAuth: RequireAnyClientCert,
6206 VerifySignatureAlgorithms: []signatureAlgorithm{
6207 signatureRSAPSSWithSHA512,
6208 signatureRSAPSSWithSHA384,
6209 },
6210 },
6211 flags: []string{
6212 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6213 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6214 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6215 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006216 shouldFail: true,
6217 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 })
6219 testCases = append(testCases, testCase{
6220 name: "Agree-Digest-SHA256",
6221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006222 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006223 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006225 signatureRSAPKCS1WithSHA1,
6226 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006227 },
6228 },
6229 flags: []string{
6230 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6231 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006232 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006233 },
Nick Harper60edffd2016-06-21 15:19:24 -07006234 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006235 })
6236 testCases = append(testCases, testCase{
6237 name: "Agree-Digest-SHA1",
6238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006239 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006240 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006241 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006242 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006243 },
6244 },
6245 flags: []string{
6246 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6247 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006248 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006249 },
Nick Harper60edffd2016-06-21 15:19:24 -07006250 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006251 })
6252 testCases = append(testCases, testCase{
6253 name: "Agree-Digest-Default",
6254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006255 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006256 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006257 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006258 signatureRSAPKCS1WithSHA256,
6259 signatureECDSAWithP256AndSHA256,
6260 signatureRSAPKCS1WithSHA1,
6261 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006262 },
6263 },
6264 flags: []string{
6265 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6266 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6267 },
Nick Harper60edffd2016-06-21 15:19:24 -07006268 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006269 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006270
David Benjaminca3d5452016-07-14 12:51:01 -04006271 // Test that the signing preference list may include extra algorithms
6272 // without negotiation problems.
6273 testCases = append(testCases, testCase{
6274 testType: serverTest,
6275 name: "FilterExtraAlgorithms",
6276 config: Config{
6277 MaxVersion: VersionTLS12,
6278 VerifySignatureAlgorithms: []signatureAlgorithm{
6279 signatureRSAPKCS1WithSHA256,
6280 },
6281 },
6282 flags: []string{
6283 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6284 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6285 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6286 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6287 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6288 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6289 },
6290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6291 })
6292
David Benjamin4c3ddf72016-06-29 18:13:53 -04006293 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6294 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295 testCases = append(testCases, testCase{
6296 name: "CheckLeafCurve",
6297 config: Config{
6298 MaxVersion: VersionTLS12,
6299 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006300 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006301 },
6302 flags: []string{"-p384-only"},
6303 shouldFail: true,
6304 expectedError: ":BAD_ECC_CERT:",
6305 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006306
6307 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6308 testCases = append(testCases, testCase{
6309 name: "CheckLeafCurve-TLS13",
6310 config: Config{
6311 MaxVersion: VersionTLS13,
6312 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6313 Certificates: []Certificate{ecdsaP256Certificate},
6314 },
6315 flags: []string{"-p384-only"},
6316 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006317
6318 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6319 testCases = append(testCases, testCase{
6320 name: "ECDSACurveMismatch-Verify-TLS12",
6321 config: Config{
6322 MaxVersion: VersionTLS12,
6323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6324 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006325 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006326 signatureECDSAWithP384AndSHA384,
6327 },
6328 },
6329 })
6330
6331 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6332 testCases = append(testCases, testCase{
6333 name: "ECDSACurveMismatch-Verify-TLS13",
6334 config: Config{
6335 MaxVersion: VersionTLS13,
6336 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6337 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006338 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006339 signatureECDSAWithP384AndSHA384,
6340 },
6341 Bugs: ProtocolBugs{
6342 SkipECDSACurveCheck: true,
6343 },
6344 },
6345 shouldFail: true,
6346 expectedError: ":WRONG_SIGNATURE_TYPE:",
6347 })
6348
6349 // Signature algorithm selection in TLS 1.3 should take the curve into
6350 // account.
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "ECDSACurveMismatch-Sign-TLS13",
6354 config: Config{
6355 MaxVersion: VersionTLS13,
6356 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006357 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006358 signatureECDSAWithP384AndSHA384,
6359 signatureECDSAWithP256AndSHA256,
6360 },
6361 },
6362 flags: []string{
6363 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6364 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6365 },
6366 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6367 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006368
6369 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6370 // server does not attempt to sign in that case.
6371 testCases = append(testCases, testCase{
6372 testType: serverTest,
6373 name: "RSA-PSS-Large",
6374 config: Config{
6375 MaxVersion: VersionTLS13,
6376 VerifySignatureAlgorithms: []signatureAlgorithm{
6377 signatureRSAPSSWithSHA512,
6378 },
6379 },
6380 flags: []string{
6381 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6382 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6383 },
6384 shouldFail: true,
6385 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6386 })
David Benjamin57e929f2016-08-30 00:30:38 -04006387
6388 // Test that RSA-PSS is enabled by default for TLS 1.2.
6389 testCases = append(testCases, testCase{
6390 testType: clientTest,
6391 name: "RSA-PSS-Default-Verify",
6392 config: Config{
6393 MaxVersion: VersionTLS12,
6394 SignSignatureAlgorithms: []signatureAlgorithm{
6395 signatureRSAPSSWithSHA256,
6396 },
6397 },
6398 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6399 })
6400
6401 testCases = append(testCases, testCase{
6402 testType: serverTest,
6403 name: "RSA-PSS-Default-Sign",
6404 config: Config{
6405 MaxVersion: VersionTLS12,
6406 VerifySignatureAlgorithms: []signatureAlgorithm{
6407 signatureRSAPSSWithSHA256,
6408 },
6409 },
6410 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6411 })
David Benjamin000800a2014-11-14 01:43:59 -05006412}
6413
David Benjamin83f90402015-01-27 01:09:43 -05006414// timeouts is the retransmit schedule for BoringSSL. It doubles and
6415// caps at 60 seconds. On the 13th timeout, it gives up.
6416var timeouts = []time.Duration{
6417 1 * time.Second,
6418 2 * time.Second,
6419 4 * time.Second,
6420 8 * time.Second,
6421 16 * time.Second,
6422 32 * time.Second,
6423 60 * time.Second,
6424 60 * time.Second,
6425 60 * time.Second,
6426 60 * time.Second,
6427 60 * time.Second,
6428 60 * time.Second,
6429 60 * time.Second,
6430}
6431
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006432// shortTimeouts is an alternate set of timeouts which would occur if the
6433// initial timeout duration was set to 250ms.
6434var shortTimeouts = []time.Duration{
6435 250 * time.Millisecond,
6436 500 * time.Millisecond,
6437 1 * time.Second,
6438 2 * time.Second,
6439 4 * time.Second,
6440 8 * time.Second,
6441 16 * time.Second,
6442 32 * time.Second,
6443 60 * time.Second,
6444 60 * time.Second,
6445 60 * time.Second,
6446 60 * time.Second,
6447 60 * time.Second,
6448}
6449
David Benjamin83f90402015-01-27 01:09:43 -05006450func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006451 // These tests work by coordinating some behavior on both the shim and
6452 // the runner.
6453 //
6454 // TimeoutSchedule configures the runner to send a series of timeout
6455 // opcodes to the shim (see packetAdaptor) immediately before reading
6456 // each peer handshake flight N. The timeout opcode both simulates a
6457 // timeout in the shim and acts as a synchronization point to help the
6458 // runner bracket each handshake flight.
6459 //
6460 // We assume the shim does not read from the channel eagerly. It must
6461 // first wait until it has sent flight N and is ready to receive
6462 // handshake flight N+1. At this point, it will process the timeout
6463 // opcode. It must then immediately respond with a timeout ACK and act
6464 // as if the shim was idle for the specified amount of time.
6465 //
6466 // The runner then drops all packets received before the ACK and
6467 // continues waiting for flight N. This ordering results in one attempt
6468 // at sending flight N to be dropped. For the test to complete, the
6469 // shim must send flight N again, testing that the shim implements DTLS
6470 // retransmit on a timeout.
6471
Steven Valdez143e8b32016-07-11 13:19:03 -04006472 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006473 // likely be more epochs to cross and the final message's retransmit may
6474 // be more complex.
6475
David Benjamin585d7a42016-06-02 14:58:00 -04006476 for _, async := range []bool{true, false} {
6477 var tests []testCase
6478
6479 // Test that this is indeed the timeout schedule. Stress all
6480 // four patterns of handshake.
6481 for i := 1; i < len(timeouts); i++ {
6482 number := strconv.Itoa(i)
6483 tests = append(tests, testCase{
6484 protocol: dtls,
6485 name: "DTLS-Retransmit-Client-" + number,
6486 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006487 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006488 Bugs: ProtocolBugs{
6489 TimeoutSchedule: timeouts[:i],
6490 },
6491 },
6492 resumeSession: true,
6493 })
6494 tests = append(tests, testCase{
6495 protocol: dtls,
6496 testType: serverTest,
6497 name: "DTLS-Retransmit-Server-" + number,
6498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006499 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006500 Bugs: ProtocolBugs{
6501 TimeoutSchedule: timeouts[:i],
6502 },
6503 },
6504 resumeSession: true,
6505 })
6506 }
6507
6508 // Test that exceeding the timeout schedule hits a read
6509 // timeout.
6510 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006511 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006512 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006514 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006515 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006516 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006517 },
6518 },
6519 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006520 shouldFail: true,
6521 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006522 })
David Benjamin585d7a42016-06-02 14:58:00 -04006523
6524 if async {
6525 // Test that timeout handling has a fudge factor, due to API
6526 // problems.
6527 tests = append(tests, testCase{
6528 protocol: dtls,
6529 name: "DTLS-Retransmit-Fudge",
6530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006532 Bugs: ProtocolBugs{
6533 TimeoutSchedule: []time.Duration{
6534 timeouts[0] - 10*time.Millisecond,
6535 },
6536 },
6537 },
6538 resumeSession: true,
6539 })
6540 }
6541
6542 // Test that the final Finished retransmitting isn't
6543 // duplicated if the peer badly fragments everything.
6544 tests = append(tests, testCase{
6545 testType: serverTest,
6546 protocol: dtls,
6547 name: "DTLS-Retransmit-Fragmented",
6548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006549 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006550 Bugs: ProtocolBugs{
6551 TimeoutSchedule: []time.Duration{timeouts[0]},
6552 MaxHandshakeRecordLength: 2,
6553 },
6554 },
6555 })
6556
6557 // Test the timeout schedule when a shorter initial timeout duration is set.
6558 tests = append(tests, testCase{
6559 protocol: dtls,
6560 name: "DTLS-Retransmit-Short-Client",
6561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006562 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006563 Bugs: ProtocolBugs{
6564 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6565 },
6566 },
6567 resumeSession: true,
6568 flags: []string{"-initial-timeout-duration-ms", "250"},
6569 })
6570 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006571 protocol: dtls,
6572 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006573 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006575 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006576 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006577 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006578 },
6579 },
6580 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006581 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006582 })
David Benjamin585d7a42016-06-02 14:58:00 -04006583
6584 for _, test := range tests {
6585 if async {
6586 test.name += "-Async"
6587 test.flags = append(test.flags, "-async")
6588 }
6589
6590 testCases = append(testCases, test)
6591 }
David Benjamin83f90402015-01-27 01:09:43 -05006592 }
David Benjamin83f90402015-01-27 01:09:43 -05006593}
6594
David Benjaminc565ebb2015-04-03 04:06:36 -04006595func addExportKeyingMaterialTests() {
6596 for _, vers := range tlsVersions {
6597 if vers.version == VersionSSL30 {
6598 continue
6599 }
6600 testCases = append(testCases, testCase{
6601 name: "ExportKeyingMaterial-" + vers.name,
6602 config: Config{
6603 MaxVersion: vers.version,
6604 },
6605 exportKeyingMaterial: 1024,
6606 exportLabel: "label",
6607 exportContext: "context",
6608 useExportContext: true,
6609 })
6610 testCases = append(testCases, testCase{
6611 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6612 config: Config{
6613 MaxVersion: vers.version,
6614 },
6615 exportKeyingMaterial: 1024,
6616 })
6617 testCases = append(testCases, testCase{
6618 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6619 config: Config{
6620 MaxVersion: vers.version,
6621 },
6622 exportKeyingMaterial: 1024,
6623 useExportContext: true,
6624 })
6625 testCases = append(testCases, testCase{
6626 name: "ExportKeyingMaterial-Small-" + vers.name,
6627 config: Config{
6628 MaxVersion: vers.version,
6629 },
6630 exportKeyingMaterial: 1,
6631 exportLabel: "label",
6632 exportContext: "context",
6633 useExportContext: true,
6634 })
6635 }
6636 testCases = append(testCases, testCase{
6637 name: "ExportKeyingMaterial-SSL3",
6638 config: Config{
6639 MaxVersion: VersionSSL30,
6640 },
6641 exportKeyingMaterial: 1024,
6642 exportLabel: "label",
6643 exportContext: "context",
6644 useExportContext: true,
6645 shouldFail: true,
6646 expectedError: "failed to export keying material",
6647 })
6648}
6649
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006650func addTLSUniqueTests() {
6651 for _, isClient := range []bool{false, true} {
6652 for _, isResumption := range []bool{false, true} {
6653 for _, hasEMS := range []bool{false, true} {
6654 var suffix string
6655 if isResumption {
6656 suffix = "Resume-"
6657 } else {
6658 suffix = "Full-"
6659 }
6660
6661 if hasEMS {
6662 suffix += "EMS-"
6663 } else {
6664 suffix += "NoEMS-"
6665 }
6666
6667 if isClient {
6668 suffix += "Client"
6669 } else {
6670 suffix += "Server"
6671 }
6672
6673 test := testCase{
6674 name: "TLSUnique-" + suffix,
6675 testTLSUnique: true,
6676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006677 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006678 Bugs: ProtocolBugs{
6679 NoExtendedMasterSecret: !hasEMS,
6680 },
6681 },
6682 }
6683
6684 if isResumption {
6685 test.resumeSession = true
6686 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006687 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006688 Bugs: ProtocolBugs{
6689 NoExtendedMasterSecret: !hasEMS,
6690 },
6691 }
6692 }
6693
6694 if isResumption && !hasEMS {
6695 test.shouldFail = true
6696 test.expectedError = "failed to get tls-unique"
6697 }
6698
6699 testCases = append(testCases, test)
6700 }
6701 }
6702 }
6703}
6704
Adam Langley09505632015-07-30 18:10:13 -07006705func addCustomExtensionTests() {
6706 expectedContents := "custom extension"
6707 emptyString := ""
6708
6709 for _, isClient := range []bool{false, true} {
6710 suffix := "Server"
6711 flag := "-enable-server-custom-extension"
6712 testType := serverTest
6713 if isClient {
6714 suffix = "Client"
6715 flag = "-enable-client-custom-extension"
6716 testType = clientTest
6717 }
6718
6719 testCases = append(testCases, testCase{
6720 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006721 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006722 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006723 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006724 Bugs: ProtocolBugs{
6725 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006726 ExpectedCustomExtension: &expectedContents,
6727 },
6728 },
6729 flags: []string{flag},
6730 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006731 testCases = append(testCases, testCase{
6732 testType: testType,
6733 name: "CustomExtensions-" + suffix + "-TLS13",
6734 config: Config{
6735 MaxVersion: VersionTLS13,
6736 Bugs: ProtocolBugs{
6737 CustomExtension: expectedContents,
6738 ExpectedCustomExtension: &expectedContents,
6739 },
6740 },
6741 flags: []string{flag},
6742 })
Adam Langley09505632015-07-30 18:10:13 -07006743
6744 // If the parse callback fails, the handshake should also fail.
6745 testCases = append(testCases, testCase{
6746 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006747 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006749 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006750 Bugs: ProtocolBugs{
6751 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006752 ExpectedCustomExtension: &expectedContents,
6753 },
6754 },
David Benjamin399e7c92015-07-30 23:01:27 -04006755 flags: []string{flag},
6756 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006757 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6758 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006759 testCases = append(testCases, testCase{
6760 testType: testType,
6761 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6762 config: Config{
6763 MaxVersion: VersionTLS13,
6764 Bugs: ProtocolBugs{
6765 CustomExtension: expectedContents + "foo",
6766 ExpectedCustomExtension: &expectedContents,
6767 },
6768 },
6769 flags: []string{flag},
6770 shouldFail: true,
6771 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6772 })
Adam Langley09505632015-07-30 18:10:13 -07006773
6774 // If the add callback fails, the handshake should also fail.
6775 testCases = append(testCases, testCase{
6776 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006777 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006778 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006779 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006780 Bugs: ProtocolBugs{
6781 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006782 ExpectedCustomExtension: &expectedContents,
6783 },
6784 },
David Benjamin399e7c92015-07-30 23:01:27 -04006785 flags: []string{flag, "-custom-extension-fail-add"},
6786 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006787 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6788 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006789 testCases = append(testCases, testCase{
6790 testType: testType,
6791 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6792 config: Config{
6793 MaxVersion: VersionTLS13,
6794 Bugs: ProtocolBugs{
6795 CustomExtension: expectedContents,
6796 ExpectedCustomExtension: &expectedContents,
6797 },
6798 },
6799 flags: []string{flag, "-custom-extension-fail-add"},
6800 shouldFail: true,
6801 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6802 })
Adam Langley09505632015-07-30 18:10:13 -07006803
6804 // If the add callback returns zero, no extension should be
6805 // added.
6806 skipCustomExtension := expectedContents
6807 if isClient {
6808 // For the case where the client skips sending the
6809 // custom extension, the server must not “echo” it.
6810 skipCustomExtension = ""
6811 }
6812 testCases = append(testCases, testCase{
6813 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006814 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006816 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006817 Bugs: ProtocolBugs{
6818 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006819 ExpectedCustomExtension: &emptyString,
6820 },
6821 },
6822 flags: []string{flag, "-custom-extension-skip"},
6823 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006824 testCases = append(testCases, testCase{
6825 testType: testType,
6826 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6827 config: Config{
6828 MaxVersion: VersionTLS13,
6829 Bugs: ProtocolBugs{
6830 CustomExtension: skipCustomExtension,
6831 ExpectedCustomExtension: &emptyString,
6832 },
6833 },
6834 flags: []string{flag, "-custom-extension-skip"},
6835 })
Adam Langley09505632015-07-30 18:10:13 -07006836 }
6837
6838 // The custom extension add callback should not be called if the client
6839 // doesn't send the extension.
6840 testCases = append(testCases, testCase{
6841 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006842 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006844 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006845 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006846 ExpectedCustomExtension: &emptyString,
6847 },
6848 },
6849 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6850 })
Adam Langley2deb9842015-08-07 11:15:37 -07006851
Steven Valdez143e8b32016-07-11 13:19:03 -04006852 testCases = append(testCases, testCase{
6853 testType: serverTest,
6854 name: "CustomExtensions-NotCalled-Server-TLS13",
6855 config: Config{
6856 MaxVersion: VersionTLS13,
6857 Bugs: ProtocolBugs{
6858 ExpectedCustomExtension: &emptyString,
6859 },
6860 },
6861 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6862 })
6863
Adam Langley2deb9842015-08-07 11:15:37 -07006864 // Test an unknown extension from the server.
6865 testCases = append(testCases, testCase{
6866 testType: clientTest,
6867 name: "UnknownExtension-Client",
6868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006869 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006870 Bugs: ProtocolBugs{
6871 CustomExtension: expectedContents,
6872 },
6873 },
David Benjamin0c40a962016-08-01 12:05:50 -04006874 shouldFail: true,
6875 expectedError: ":UNEXPECTED_EXTENSION:",
6876 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006877 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006878 testCases = append(testCases, testCase{
6879 testType: clientTest,
6880 name: "UnknownExtension-Client-TLS13",
6881 config: Config{
6882 MaxVersion: VersionTLS13,
6883 Bugs: ProtocolBugs{
6884 CustomExtension: expectedContents,
6885 },
6886 },
David Benjamin0c40a962016-08-01 12:05:50 -04006887 shouldFail: true,
6888 expectedError: ":UNEXPECTED_EXTENSION:",
6889 expectedLocalError: "remote error: unsupported extension",
6890 })
6891
6892 // Test a known but unoffered extension from the server.
6893 testCases = append(testCases, testCase{
6894 testType: clientTest,
6895 name: "UnofferedExtension-Client",
6896 config: Config{
6897 MaxVersion: VersionTLS12,
6898 Bugs: ProtocolBugs{
6899 SendALPN: "alpn",
6900 },
6901 },
6902 shouldFail: true,
6903 expectedError: ":UNEXPECTED_EXTENSION:",
6904 expectedLocalError: "remote error: unsupported extension",
6905 })
6906 testCases = append(testCases, testCase{
6907 testType: clientTest,
6908 name: "UnofferedExtension-Client-TLS13",
6909 config: Config{
6910 MaxVersion: VersionTLS13,
6911 Bugs: ProtocolBugs{
6912 SendALPN: "alpn",
6913 },
6914 },
6915 shouldFail: true,
6916 expectedError: ":UNEXPECTED_EXTENSION:",
6917 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006918 })
Adam Langley09505632015-07-30 18:10:13 -07006919}
6920
David Benjaminb36a3952015-12-01 18:53:13 -05006921func addRSAClientKeyExchangeTests() {
6922 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6923 testCases = append(testCases, testCase{
6924 testType: serverTest,
6925 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6926 config: Config{
6927 // Ensure the ClientHello version and final
6928 // version are different, to detect if the
6929 // server uses the wrong one.
6930 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006931 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006932 Bugs: ProtocolBugs{
6933 BadRSAClientKeyExchange: bad,
6934 },
6935 },
6936 shouldFail: true,
6937 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6938 })
6939 }
David Benjamine63d9d72016-09-19 18:27:34 -04006940
6941 // The server must compare whatever was in ClientHello.version for the
6942 // RSA premaster.
6943 testCases = append(testCases, testCase{
6944 testType: serverTest,
6945 name: "SendClientVersion-RSA",
6946 config: Config{
6947 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6948 Bugs: ProtocolBugs{
6949 SendClientVersion: 0x1234,
6950 },
6951 },
6952 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6953 })
David Benjaminb36a3952015-12-01 18:53:13 -05006954}
6955
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006956var testCurves = []struct {
6957 name string
6958 id CurveID
6959}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006960 {"P-256", CurveP256},
6961 {"P-384", CurveP384},
6962 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006963 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006964}
6965
Steven Valdez5440fe02016-07-18 12:40:30 -04006966const bogusCurve = 0x1234
6967
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006968func addCurveTests() {
6969 for _, curve := range testCurves {
6970 testCases = append(testCases, testCase{
6971 name: "CurveTest-Client-" + curve.name,
6972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006973 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6975 CurvePreferences: []CurveID{curve.id},
6976 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006977 flags: []string{
6978 "-enable-all-curves",
6979 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6980 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006981 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006982 })
6983 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006984 name: "CurveTest-Client-" + curve.name + "-TLS13",
6985 config: Config{
6986 MaxVersion: VersionTLS13,
6987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6988 CurvePreferences: []CurveID{curve.id},
6989 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006990 flags: []string{
6991 "-enable-all-curves",
6992 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6993 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006994 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006995 })
6996 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006997 testType: serverTest,
6998 name: "CurveTest-Server-" + curve.name,
6999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7002 CurvePreferences: []CurveID{curve.id},
7003 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007004 flags: []string{
7005 "-enable-all-curves",
7006 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7007 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007008 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007009 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007010 testCases = append(testCases, testCase{
7011 testType: serverTest,
7012 name: "CurveTest-Server-" + curve.name + "-TLS13",
7013 config: Config{
7014 MaxVersion: VersionTLS13,
7015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7016 CurvePreferences: []CurveID{curve.id},
7017 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007018 flags: []string{
7019 "-enable-all-curves",
7020 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7021 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007022 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007023 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007024 }
David Benjamin241ae832016-01-15 03:04:54 -05007025
7026 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007027 testCases = append(testCases, testCase{
7028 testType: serverTest,
7029 name: "UnknownCurve",
7030 config: Config{
7031 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7032 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7033 },
7034 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007035
7036 // The server must not consider ECDHE ciphers when there are no
7037 // supported curves.
7038 testCases = append(testCases, testCase{
7039 testType: serverTest,
7040 name: "NoSupportedCurves",
7041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007042 MaxVersion: VersionTLS12,
7043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7044 Bugs: ProtocolBugs{
7045 NoSupportedCurves: true,
7046 },
7047 },
7048 shouldFail: true,
7049 expectedError: ":NO_SHARED_CIPHER:",
7050 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007051 testCases = append(testCases, testCase{
7052 testType: serverTest,
7053 name: "NoSupportedCurves-TLS13",
7054 config: Config{
7055 MaxVersion: VersionTLS13,
7056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7057 Bugs: ProtocolBugs{
7058 NoSupportedCurves: true,
7059 },
7060 },
7061 shouldFail: true,
7062 expectedError: ":NO_SHARED_CIPHER:",
7063 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007064
7065 // The server must fall back to another cipher when there are no
7066 // supported curves.
7067 testCases = append(testCases, testCase{
7068 testType: serverTest,
7069 name: "NoCommonCurves",
7070 config: Config{
7071 MaxVersion: VersionTLS12,
7072 CipherSuites: []uint16{
7073 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7074 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7075 },
7076 CurvePreferences: []CurveID{CurveP224},
7077 },
7078 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7079 })
7080
7081 // The client must reject bogus curves and disabled curves.
7082 testCases = append(testCases, testCase{
7083 name: "BadECDHECurve",
7084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007085 MaxVersion: VersionTLS12,
7086 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7087 Bugs: ProtocolBugs{
7088 SendCurve: bogusCurve,
7089 },
7090 },
7091 shouldFail: true,
7092 expectedError: ":WRONG_CURVE:",
7093 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007094 testCases = append(testCases, testCase{
7095 name: "BadECDHECurve-TLS13",
7096 config: Config{
7097 MaxVersion: VersionTLS13,
7098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7099 Bugs: ProtocolBugs{
7100 SendCurve: bogusCurve,
7101 },
7102 },
7103 shouldFail: true,
7104 expectedError: ":WRONG_CURVE:",
7105 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007106
7107 testCases = append(testCases, testCase{
7108 name: "UnsupportedCurve",
7109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
7111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7112 CurvePreferences: []CurveID{CurveP256},
7113 Bugs: ProtocolBugs{
7114 IgnorePeerCurvePreferences: true,
7115 },
7116 },
7117 flags: []string{"-p384-only"},
7118 shouldFail: true,
7119 expectedError: ":WRONG_CURVE:",
7120 })
7121
David Benjamin4f921572016-07-17 14:20:10 +02007122 testCases = append(testCases, testCase{
7123 // TODO(davidben): Add a TLS 1.3 version where
7124 // HelloRetryRequest requests an unsupported curve.
7125 name: "UnsupportedCurve-ServerHello-TLS13",
7126 config: Config{
7127 MaxVersion: VersionTLS12,
7128 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7129 CurvePreferences: []CurveID{CurveP384},
7130 Bugs: ProtocolBugs{
7131 SendCurve: CurveP256,
7132 },
7133 },
7134 flags: []string{"-p384-only"},
7135 shouldFail: true,
7136 expectedError: ":WRONG_CURVE:",
7137 })
7138
David Benjamin4c3ddf72016-06-29 18:13:53 -04007139 // Test invalid curve points.
7140 testCases = append(testCases, testCase{
7141 name: "InvalidECDHPoint-Client",
7142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007143 MaxVersion: VersionTLS12,
7144 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7145 CurvePreferences: []CurveID{CurveP256},
7146 Bugs: ProtocolBugs{
7147 InvalidECDHPoint: true,
7148 },
7149 },
7150 shouldFail: true,
7151 expectedError: ":INVALID_ENCODING:",
7152 })
7153 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007154 name: "InvalidECDHPoint-Client-TLS13",
7155 config: Config{
7156 MaxVersion: VersionTLS13,
7157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7158 CurvePreferences: []CurveID{CurveP256},
7159 Bugs: ProtocolBugs{
7160 InvalidECDHPoint: true,
7161 },
7162 },
7163 shouldFail: true,
7164 expectedError: ":INVALID_ENCODING:",
7165 })
7166 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007167 testType: serverTest,
7168 name: "InvalidECDHPoint-Server",
7169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007170 MaxVersion: VersionTLS12,
7171 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7172 CurvePreferences: []CurveID{CurveP256},
7173 Bugs: ProtocolBugs{
7174 InvalidECDHPoint: true,
7175 },
7176 },
7177 shouldFail: true,
7178 expectedError: ":INVALID_ENCODING:",
7179 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007180 testCases = append(testCases, testCase{
7181 testType: serverTest,
7182 name: "InvalidECDHPoint-Server-TLS13",
7183 config: Config{
7184 MaxVersion: VersionTLS13,
7185 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7186 CurvePreferences: []CurveID{CurveP256},
7187 Bugs: ProtocolBugs{
7188 InvalidECDHPoint: true,
7189 },
7190 },
7191 shouldFail: true,
7192 expectedError: ":INVALID_ENCODING:",
7193 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007194}
7195
Matt Braithwaite54217e42016-06-13 13:03:47 -07007196func addCECPQ1Tests() {
7197 testCases = append(testCases, testCase{
7198 testType: clientTest,
7199 name: "CECPQ1-Client-BadX25519Part",
7200 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007201 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007202 MinVersion: VersionTLS12,
7203 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7204 Bugs: ProtocolBugs{
7205 CECPQ1BadX25519Part: true,
7206 },
7207 },
7208 flags: []string{"-cipher", "kCECPQ1"},
7209 shouldFail: true,
7210 expectedLocalError: "local error: bad record MAC",
7211 })
7212 testCases = append(testCases, testCase{
7213 testType: clientTest,
7214 name: "CECPQ1-Client-BadNewhopePart",
7215 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007216 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007217 MinVersion: VersionTLS12,
7218 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7219 Bugs: ProtocolBugs{
7220 CECPQ1BadNewhopePart: true,
7221 },
7222 },
7223 flags: []string{"-cipher", "kCECPQ1"},
7224 shouldFail: true,
7225 expectedLocalError: "local error: bad record MAC",
7226 })
7227 testCases = append(testCases, testCase{
7228 testType: serverTest,
7229 name: "CECPQ1-Server-BadX25519Part",
7230 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007231 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007232 MinVersion: VersionTLS12,
7233 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7234 Bugs: ProtocolBugs{
7235 CECPQ1BadX25519Part: true,
7236 },
7237 },
7238 flags: []string{"-cipher", "kCECPQ1"},
7239 shouldFail: true,
7240 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7241 })
7242 testCases = append(testCases, testCase{
7243 testType: serverTest,
7244 name: "CECPQ1-Server-BadNewhopePart",
7245 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007246 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007247 MinVersion: VersionTLS12,
7248 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7249 Bugs: ProtocolBugs{
7250 CECPQ1BadNewhopePart: true,
7251 },
7252 },
7253 flags: []string{"-cipher", "kCECPQ1"},
7254 shouldFail: true,
7255 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7256 })
7257}
7258
David Benjamin5c4e8572016-08-19 17:44:53 -04007259func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007260 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007261 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007262 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007263 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007264 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7265 Bugs: ProtocolBugs{
7266 // This is a 1234-bit prime number, generated
7267 // with:
7268 // openssl gendh 1234 | openssl asn1parse -i
7269 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7270 },
7271 },
David Benjamin9e68f192016-06-30 14:55:33 -04007272 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007273 })
7274 testCases = append(testCases, testCase{
7275 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007276 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007277 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007278 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007279 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7280 },
7281 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007282 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007283 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007284}
7285
David Benjaminc9ae27c2016-06-24 22:56:37 -04007286func addTLS13RecordTests() {
7287 testCases = append(testCases, testCase{
7288 name: "TLS13-RecordPadding",
7289 config: Config{
7290 MaxVersion: VersionTLS13,
7291 MinVersion: VersionTLS13,
7292 Bugs: ProtocolBugs{
7293 RecordPadding: 10,
7294 },
7295 },
7296 })
7297
7298 testCases = append(testCases, testCase{
7299 name: "TLS13-EmptyRecords",
7300 config: Config{
7301 MaxVersion: VersionTLS13,
7302 MinVersion: VersionTLS13,
7303 Bugs: ProtocolBugs{
7304 OmitRecordContents: true,
7305 },
7306 },
7307 shouldFail: true,
7308 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7309 })
7310
7311 testCases = append(testCases, testCase{
7312 name: "TLS13-OnlyPadding",
7313 config: Config{
7314 MaxVersion: VersionTLS13,
7315 MinVersion: VersionTLS13,
7316 Bugs: ProtocolBugs{
7317 OmitRecordContents: true,
7318 RecordPadding: 10,
7319 },
7320 },
7321 shouldFail: true,
7322 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7323 })
7324
7325 testCases = append(testCases, testCase{
7326 name: "TLS13-WrongOuterRecord",
7327 config: Config{
7328 MaxVersion: VersionTLS13,
7329 MinVersion: VersionTLS13,
7330 Bugs: ProtocolBugs{
7331 OuterRecordType: recordTypeHandshake,
7332 },
7333 },
7334 shouldFail: true,
7335 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7336 })
7337}
7338
David Benjamin82261be2016-07-07 14:32:50 -07007339func addChangeCipherSpecTests() {
7340 // Test missing ChangeCipherSpecs.
7341 testCases = append(testCases, testCase{
7342 name: "SkipChangeCipherSpec-Client",
7343 config: Config{
7344 MaxVersion: VersionTLS12,
7345 Bugs: ProtocolBugs{
7346 SkipChangeCipherSpec: true,
7347 },
7348 },
7349 shouldFail: true,
7350 expectedError: ":UNEXPECTED_RECORD:",
7351 })
7352 testCases = append(testCases, testCase{
7353 testType: serverTest,
7354 name: "SkipChangeCipherSpec-Server",
7355 config: Config{
7356 MaxVersion: VersionTLS12,
7357 Bugs: ProtocolBugs{
7358 SkipChangeCipherSpec: true,
7359 },
7360 },
7361 shouldFail: true,
7362 expectedError: ":UNEXPECTED_RECORD:",
7363 })
7364 testCases = append(testCases, testCase{
7365 testType: serverTest,
7366 name: "SkipChangeCipherSpec-Server-NPN",
7367 config: Config{
7368 MaxVersion: VersionTLS12,
7369 NextProtos: []string{"bar"},
7370 Bugs: ProtocolBugs{
7371 SkipChangeCipherSpec: true,
7372 },
7373 },
7374 flags: []string{
7375 "-advertise-npn", "\x03foo\x03bar\x03baz",
7376 },
7377 shouldFail: true,
7378 expectedError: ":UNEXPECTED_RECORD:",
7379 })
7380
7381 // Test synchronization between the handshake and ChangeCipherSpec.
7382 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7383 // rejected. Test both with and without handshake packing to handle both
7384 // when the partial post-CCS message is in its own record and when it is
7385 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007386 for _, packed := range []bool{false, true} {
7387 var suffix string
7388 if packed {
7389 suffix = "-Packed"
7390 }
7391
7392 testCases = append(testCases, testCase{
7393 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7394 config: Config{
7395 MaxVersion: VersionTLS12,
7396 Bugs: ProtocolBugs{
7397 FragmentAcrossChangeCipherSpec: true,
7398 PackHandshakeFlight: packed,
7399 },
7400 },
7401 shouldFail: true,
7402 expectedError: ":UNEXPECTED_RECORD:",
7403 })
7404 testCases = append(testCases, testCase{
7405 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7406 config: Config{
7407 MaxVersion: VersionTLS12,
7408 },
7409 resumeSession: true,
7410 resumeConfig: &Config{
7411 MaxVersion: VersionTLS12,
7412 Bugs: ProtocolBugs{
7413 FragmentAcrossChangeCipherSpec: true,
7414 PackHandshakeFlight: packed,
7415 },
7416 },
7417 shouldFail: true,
7418 expectedError: ":UNEXPECTED_RECORD:",
7419 })
7420 testCases = append(testCases, testCase{
7421 testType: serverTest,
7422 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7423 config: Config{
7424 MaxVersion: VersionTLS12,
7425 Bugs: ProtocolBugs{
7426 FragmentAcrossChangeCipherSpec: true,
7427 PackHandshakeFlight: packed,
7428 },
7429 },
7430 shouldFail: true,
7431 expectedError: ":UNEXPECTED_RECORD:",
7432 })
7433 testCases = append(testCases, testCase{
7434 testType: serverTest,
7435 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7436 config: Config{
7437 MaxVersion: VersionTLS12,
7438 },
7439 resumeSession: true,
7440 resumeConfig: &Config{
7441 MaxVersion: VersionTLS12,
7442 Bugs: ProtocolBugs{
7443 FragmentAcrossChangeCipherSpec: true,
7444 PackHandshakeFlight: packed,
7445 },
7446 },
7447 shouldFail: true,
7448 expectedError: ":UNEXPECTED_RECORD:",
7449 })
7450 testCases = append(testCases, testCase{
7451 testType: serverTest,
7452 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7453 config: Config{
7454 MaxVersion: VersionTLS12,
7455 NextProtos: []string{"bar"},
7456 Bugs: ProtocolBugs{
7457 FragmentAcrossChangeCipherSpec: true,
7458 PackHandshakeFlight: packed,
7459 },
7460 },
7461 flags: []string{
7462 "-advertise-npn", "\x03foo\x03bar\x03baz",
7463 },
7464 shouldFail: true,
7465 expectedError: ":UNEXPECTED_RECORD:",
7466 })
7467 }
7468
David Benjamin61672812016-07-14 23:10:43 -04007469 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7470 // messages in the handshake queue. Do this by testing the server
7471 // reading the client Finished, reversing the flight so Finished comes
7472 // first.
7473 testCases = append(testCases, testCase{
7474 protocol: dtls,
7475 testType: serverTest,
7476 name: "SendUnencryptedFinished-DTLS",
7477 config: Config{
7478 MaxVersion: VersionTLS12,
7479 Bugs: ProtocolBugs{
7480 SendUnencryptedFinished: true,
7481 ReverseHandshakeFragments: true,
7482 },
7483 },
7484 shouldFail: true,
7485 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7486 })
7487
Steven Valdez143e8b32016-07-11 13:19:03 -04007488 // Test synchronization between encryption changes and the handshake in
7489 // TLS 1.3, where ChangeCipherSpec is implicit.
7490 testCases = append(testCases, testCase{
7491 name: "PartialEncryptedExtensionsWithServerHello",
7492 config: Config{
7493 MaxVersion: VersionTLS13,
7494 Bugs: ProtocolBugs{
7495 PartialEncryptedExtensionsWithServerHello: true,
7496 },
7497 },
7498 shouldFail: true,
7499 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7500 })
7501 testCases = append(testCases, testCase{
7502 testType: serverTest,
7503 name: "PartialClientFinishedWithClientHello",
7504 config: Config{
7505 MaxVersion: VersionTLS13,
7506 Bugs: ProtocolBugs{
7507 PartialClientFinishedWithClientHello: true,
7508 },
7509 },
7510 shouldFail: true,
7511 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7512 })
7513
David Benjamin82261be2016-07-07 14:32:50 -07007514 // Test that early ChangeCipherSpecs are handled correctly.
7515 testCases = append(testCases, testCase{
7516 testType: serverTest,
7517 name: "EarlyChangeCipherSpec-server-1",
7518 config: Config{
7519 MaxVersion: VersionTLS12,
7520 Bugs: ProtocolBugs{
7521 EarlyChangeCipherSpec: 1,
7522 },
7523 },
7524 shouldFail: true,
7525 expectedError: ":UNEXPECTED_RECORD:",
7526 })
7527 testCases = append(testCases, testCase{
7528 testType: serverTest,
7529 name: "EarlyChangeCipherSpec-server-2",
7530 config: Config{
7531 MaxVersion: VersionTLS12,
7532 Bugs: ProtocolBugs{
7533 EarlyChangeCipherSpec: 2,
7534 },
7535 },
7536 shouldFail: true,
7537 expectedError: ":UNEXPECTED_RECORD:",
7538 })
7539 testCases = append(testCases, testCase{
7540 protocol: dtls,
7541 name: "StrayChangeCipherSpec",
7542 config: Config{
7543 // TODO(davidben): Once DTLS 1.3 exists, test
7544 // that stray ChangeCipherSpec messages are
7545 // rejected.
7546 MaxVersion: VersionTLS12,
7547 Bugs: ProtocolBugs{
7548 StrayChangeCipherSpec: true,
7549 },
7550 },
7551 })
7552
7553 // Test that the contents of ChangeCipherSpec are checked.
7554 testCases = append(testCases, testCase{
7555 name: "BadChangeCipherSpec-1",
7556 config: Config{
7557 MaxVersion: VersionTLS12,
7558 Bugs: ProtocolBugs{
7559 BadChangeCipherSpec: []byte{2},
7560 },
7561 },
7562 shouldFail: true,
7563 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7564 })
7565 testCases = append(testCases, testCase{
7566 name: "BadChangeCipherSpec-2",
7567 config: Config{
7568 MaxVersion: VersionTLS12,
7569 Bugs: ProtocolBugs{
7570 BadChangeCipherSpec: []byte{1, 1},
7571 },
7572 },
7573 shouldFail: true,
7574 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7575 })
7576 testCases = append(testCases, testCase{
7577 protocol: dtls,
7578 name: "BadChangeCipherSpec-DTLS-1",
7579 config: Config{
7580 MaxVersion: VersionTLS12,
7581 Bugs: ProtocolBugs{
7582 BadChangeCipherSpec: []byte{2},
7583 },
7584 },
7585 shouldFail: true,
7586 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7587 })
7588 testCases = append(testCases, testCase{
7589 protocol: dtls,
7590 name: "BadChangeCipherSpec-DTLS-2",
7591 config: Config{
7592 MaxVersion: VersionTLS12,
7593 Bugs: ProtocolBugs{
7594 BadChangeCipherSpec: []byte{1, 1},
7595 },
7596 },
7597 shouldFail: true,
7598 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7599 })
7600}
7601
David Benjamincd2c8062016-09-09 11:28:16 -04007602type perMessageTest struct {
7603 messageType uint8
7604 test testCase
7605}
7606
7607// makePerMessageTests returns a series of test templates which cover each
7608// message in the TLS handshake. These may be used with bugs like
7609// WrongMessageType to fully test a per-message bug.
7610func makePerMessageTests() []perMessageTest {
7611 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007612 for _, protocol := range []protocol{tls, dtls} {
7613 var suffix string
7614 if protocol == dtls {
7615 suffix = "-DTLS"
7616 }
7617
David Benjamincd2c8062016-09-09 11:28:16 -04007618 ret = append(ret, perMessageTest{
7619 messageType: typeClientHello,
7620 test: testCase{
7621 protocol: protocol,
7622 testType: serverTest,
7623 name: "ClientHello" + suffix,
7624 config: Config{
7625 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007626 },
7627 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007628 })
7629
7630 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007631 ret = append(ret, perMessageTest{
7632 messageType: typeHelloVerifyRequest,
7633 test: testCase{
7634 protocol: protocol,
7635 name: "HelloVerifyRequest" + suffix,
7636 config: Config{
7637 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007638 },
7639 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007640 })
7641 }
7642
David Benjamincd2c8062016-09-09 11:28:16 -04007643 ret = append(ret, perMessageTest{
7644 messageType: typeServerHello,
7645 test: testCase{
7646 protocol: protocol,
7647 name: "ServerHello" + suffix,
7648 config: Config{
7649 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007650 },
7651 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007652 })
7653
David Benjamincd2c8062016-09-09 11:28:16 -04007654 ret = append(ret, perMessageTest{
7655 messageType: typeCertificate,
7656 test: testCase{
7657 protocol: protocol,
7658 name: "ServerCertificate" + suffix,
7659 config: Config{
7660 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007661 },
7662 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007663 })
7664
David Benjamincd2c8062016-09-09 11:28:16 -04007665 ret = append(ret, perMessageTest{
7666 messageType: typeCertificateStatus,
7667 test: testCase{
7668 protocol: protocol,
7669 name: "CertificateStatus" + suffix,
7670 config: Config{
7671 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007672 },
David Benjamincd2c8062016-09-09 11:28:16 -04007673 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007674 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007675 })
7676
David Benjamincd2c8062016-09-09 11:28:16 -04007677 ret = append(ret, perMessageTest{
7678 messageType: typeServerKeyExchange,
7679 test: testCase{
7680 protocol: protocol,
7681 name: "ServerKeyExchange" + suffix,
7682 config: Config{
7683 MaxVersion: VersionTLS12,
7684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007685 },
7686 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007687 })
7688
David Benjamincd2c8062016-09-09 11:28:16 -04007689 ret = append(ret, perMessageTest{
7690 messageType: typeCertificateRequest,
7691 test: testCase{
7692 protocol: protocol,
7693 name: "CertificateRequest" + suffix,
7694 config: Config{
7695 MaxVersion: VersionTLS12,
7696 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007697 },
7698 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007699 })
7700
David Benjamincd2c8062016-09-09 11:28:16 -04007701 ret = append(ret, perMessageTest{
7702 messageType: typeServerHelloDone,
7703 test: testCase{
7704 protocol: protocol,
7705 name: "ServerHelloDone" + suffix,
7706 config: Config{
7707 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007708 },
7709 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007710 })
7711
David Benjamincd2c8062016-09-09 11:28:16 -04007712 ret = append(ret, perMessageTest{
7713 messageType: typeCertificate,
7714 test: testCase{
7715 testType: serverTest,
7716 protocol: protocol,
7717 name: "ClientCertificate" + suffix,
7718 config: Config{
7719 Certificates: []Certificate{rsaCertificate},
7720 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007721 },
David Benjamincd2c8062016-09-09 11:28:16 -04007722 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007723 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007724 })
7725
David Benjamincd2c8062016-09-09 11:28:16 -04007726 ret = append(ret, perMessageTest{
7727 messageType: typeCertificateVerify,
7728 test: testCase{
7729 testType: serverTest,
7730 protocol: protocol,
7731 name: "CertificateVerify" + suffix,
7732 config: Config{
7733 Certificates: []Certificate{rsaCertificate},
7734 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007735 },
David Benjamincd2c8062016-09-09 11:28:16 -04007736 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007737 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007738 })
7739
David Benjamincd2c8062016-09-09 11:28:16 -04007740 ret = append(ret, perMessageTest{
7741 messageType: typeClientKeyExchange,
7742 test: testCase{
7743 testType: serverTest,
7744 protocol: protocol,
7745 name: "ClientKeyExchange" + suffix,
7746 config: Config{
7747 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007748 },
7749 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007750 })
7751
7752 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007753 ret = append(ret, perMessageTest{
7754 messageType: typeNextProtocol,
7755 test: testCase{
7756 testType: serverTest,
7757 protocol: protocol,
7758 name: "NextProtocol" + suffix,
7759 config: Config{
7760 MaxVersion: VersionTLS12,
7761 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 },
David Benjamincd2c8062016-09-09 11:28:16 -04007763 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007764 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007765 })
7766
David Benjamincd2c8062016-09-09 11:28:16 -04007767 ret = append(ret, perMessageTest{
7768 messageType: typeChannelID,
7769 test: testCase{
7770 testType: serverTest,
7771 protocol: protocol,
7772 name: "ChannelID" + suffix,
7773 config: Config{
7774 MaxVersion: VersionTLS12,
7775 ChannelID: channelIDKey,
7776 },
7777 flags: []string{
7778 "-expect-channel-id",
7779 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007780 },
7781 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007782 })
7783 }
7784
David Benjamincd2c8062016-09-09 11:28:16 -04007785 ret = append(ret, perMessageTest{
7786 messageType: typeFinished,
7787 test: testCase{
7788 testType: serverTest,
7789 protocol: protocol,
7790 name: "ClientFinished" + suffix,
7791 config: Config{
7792 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007793 },
7794 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007795 })
7796
David Benjamincd2c8062016-09-09 11:28:16 -04007797 ret = append(ret, perMessageTest{
7798 messageType: typeNewSessionTicket,
7799 test: testCase{
7800 protocol: protocol,
7801 name: "NewSessionTicket" + suffix,
7802 config: Config{
7803 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007804 },
7805 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007806 })
7807
David Benjamincd2c8062016-09-09 11:28:16 -04007808 ret = append(ret, perMessageTest{
7809 messageType: typeFinished,
7810 test: testCase{
7811 protocol: protocol,
7812 name: "ServerFinished" + suffix,
7813 config: Config{
7814 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007815 },
7816 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007817 })
7818
7819 }
David Benjamincd2c8062016-09-09 11:28:16 -04007820
7821 ret = append(ret, perMessageTest{
7822 messageType: typeClientHello,
7823 test: testCase{
7824 testType: serverTest,
7825 name: "TLS13-ClientHello",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 },
7829 },
7830 })
7831
7832 ret = append(ret, perMessageTest{
7833 messageType: typeServerHello,
7834 test: testCase{
7835 name: "TLS13-ServerHello",
7836 config: Config{
7837 MaxVersion: VersionTLS13,
7838 },
7839 },
7840 })
7841
7842 ret = append(ret, perMessageTest{
7843 messageType: typeEncryptedExtensions,
7844 test: testCase{
7845 name: "TLS13-EncryptedExtensions",
7846 config: Config{
7847 MaxVersion: VersionTLS13,
7848 },
7849 },
7850 })
7851
7852 ret = append(ret, perMessageTest{
7853 messageType: typeCertificateRequest,
7854 test: testCase{
7855 name: "TLS13-CertificateRequest",
7856 config: Config{
7857 MaxVersion: VersionTLS13,
7858 ClientAuth: RequireAnyClientCert,
7859 },
7860 },
7861 })
7862
7863 ret = append(ret, perMessageTest{
7864 messageType: typeCertificate,
7865 test: testCase{
7866 name: "TLS13-ServerCertificate",
7867 config: Config{
7868 MaxVersion: VersionTLS13,
7869 },
7870 },
7871 })
7872
7873 ret = append(ret, perMessageTest{
7874 messageType: typeCertificateVerify,
7875 test: testCase{
7876 name: "TLS13-ServerCertificateVerify",
7877 config: Config{
7878 MaxVersion: VersionTLS13,
7879 },
7880 },
7881 })
7882
7883 ret = append(ret, perMessageTest{
7884 messageType: typeFinished,
7885 test: testCase{
7886 name: "TLS13-ServerFinished",
7887 config: Config{
7888 MaxVersion: VersionTLS13,
7889 },
7890 },
7891 })
7892
7893 ret = append(ret, perMessageTest{
7894 messageType: typeCertificate,
7895 test: testCase{
7896 testType: serverTest,
7897 name: "TLS13-ClientCertificate",
7898 config: Config{
7899 Certificates: []Certificate{rsaCertificate},
7900 MaxVersion: VersionTLS13,
7901 },
7902 flags: []string{"-require-any-client-certificate"},
7903 },
7904 })
7905
7906 ret = append(ret, perMessageTest{
7907 messageType: typeCertificateVerify,
7908 test: testCase{
7909 testType: serverTest,
7910 name: "TLS13-ClientCertificateVerify",
7911 config: Config{
7912 Certificates: []Certificate{rsaCertificate},
7913 MaxVersion: VersionTLS13,
7914 },
7915 flags: []string{"-require-any-client-certificate"},
7916 },
7917 })
7918
7919 ret = append(ret, perMessageTest{
7920 messageType: typeFinished,
7921 test: testCase{
7922 testType: serverTest,
7923 name: "TLS13-ClientFinished",
7924 config: Config{
7925 MaxVersion: VersionTLS13,
7926 },
7927 },
7928 })
7929
7930 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007931}
7932
David Benjamincd2c8062016-09-09 11:28:16 -04007933func addWrongMessageTypeTests() {
7934 for _, t := range makePerMessageTests() {
7935 t.test.name = "WrongMessageType-" + t.test.name
7936 t.test.config.Bugs.SendWrongMessageType = t.messageType
7937 t.test.shouldFail = true
7938 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7939 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007940
David Benjamincd2c8062016-09-09 11:28:16 -04007941 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7942 // In TLS 1.3, a bad ServerHello means the client sends
7943 // an unencrypted alert while the server expects
7944 // encryption, so the alert is not readable by runner.
7945 t.test.expectedLocalError = "local error: bad record MAC"
7946 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007947
David Benjamincd2c8062016-09-09 11:28:16 -04007948 testCases = append(testCases, t.test)
7949 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007950}
7951
David Benjamin639846e2016-09-09 11:41:18 -04007952func addTrailingMessageDataTests() {
7953 for _, t := range makePerMessageTests() {
7954 t.test.name = "TrailingMessageData-" + t.test.name
7955 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7956 t.test.shouldFail = true
7957 t.test.expectedError = ":DECODE_ERROR:"
7958 t.test.expectedLocalError = "remote error: error decoding message"
7959
7960 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7961 // In TLS 1.3, a bad ServerHello means the client sends
7962 // an unencrypted alert while the server expects
7963 // encryption, so the alert is not readable by runner.
7964 t.test.expectedLocalError = "local error: bad record MAC"
7965 }
7966
7967 if t.messageType == typeFinished {
7968 // Bad Finished messages read as the verify data having
7969 // the wrong length.
7970 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7971 t.test.expectedLocalError = "remote error: error decrypting message"
7972 }
7973
7974 testCases = append(testCases, t.test)
7975 }
7976}
7977
Steven Valdez143e8b32016-07-11 13:19:03 -04007978func addTLS13HandshakeTests() {
7979 testCases = append(testCases, testCase{
7980 testType: clientTest,
7981 name: "MissingKeyShare-Client",
7982 config: Config{
7983 MaxVersion: VersionTLS13,
7984 Bugs: ProtocolBugs{
7985 MissingKeyShare: true,
7986 },
7987 },
7988 shouldFail: true,
7989 expectedError: ":MISSING_KEY_SHARE:",
7990 })
7991
7992 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007993 testType: serverTest,
7994 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007995 config: Config{
7996 MaxVersion: VersionTLS13,
7997 Bugs: ProtocolBugs{
7998 MissingKeyShare: true,
7999 },
8000 },
8001 shouldFail: true,
8002 expectedError: ":MISSING_KEY_SHARE:",
8003 })
8004
8005 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008006 testType: serverTest,
8007 name: "DuplicateKeyShares",
8008 config: Config{
8009 MaxVersion: VersionTLS13,
8010 Bugs: ProtocolBugs{
8011 DuplicateKeyShares: true,
8012 },
8013 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008014 shouldFail: true,
8015 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008016 })
8017
8018 testCases = append(testCases, testCase{
8019 testType: clientTest,
8020 name: "EmptyEncryptedExtensions",
8021 config: Config{
8022 MaxVersion: VersionTLS13,
8023 Bugs: ProtocolBugs{
8024 EmptyEncryptedExtensions: true,
8025 },
8026 },
8027 shouldFail: true,
8028 expectedLocalError: "remote error: error decoding message",
8029 })
8030
8031 testCases = append(testCases, testCase{
8032 testType: clientTest,
8033 name: "EncryptedExtensionsWithKeyShare",
8034 config: Config{
8035 MaxVersion: VersionTLS13,
8036 Bugs: ProtocolBugs{
8037 EncryptedExtensionsWithKeyShare: true,
8038 },
8039 },
8040 shouldFail: true,
8041 expectedLocalError: "remote error: unsupported extension",
8042 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008043
8044 testCases = append(testCases, testCase{
8045 testType: serverTest,
8046 name: "SendHelloRetryRequest",
8047 config: Config{
8048 MaxVersion: VersionTLS13,
8049 // Require a HelloRetryRequest for every curve.
8050 DefaultCurves: []CurveID{},
8051 },
8052 expectedCurveID: CurveX25519,
8053 })
8054
8055 testCases = append(testCases, testCase{
8056 testType: serverTest,
8057 name: "SendHelloRetryRequest-2",
8058 config: Config{
8059 MaxVersion: VersionTLS13,
8060 DefaultCurves: []CurveID{CurveP384},
8061 },
8062 // Although the ClientHello did not predict our preferred curve,
8063 // we always select it whether it is predicted or not.
8064 expectedCurveID: CurveX25519,
8065 })
8066
8067 testCases = append(testCases, testCase{
8068 name: "UnknownCurve-HelloRetryRequest",
8069 config: Config{
8070 MaxVersion: VersionTLS13,
8071 // P-384 requires HelloRetryRequest in BoringSSL.
8072 CurvePreferences: []CurveID{CurveP384},
8073 Bugs: ProtocolBugs{
8074 SendHelloRetryRequestCurve: bogusCurve,
8075 },
8076 },
8077 shouldFail: true,
8078 expectedError: ":WRONG_CURVE:",
8079 })
8080
8081 testCases = append(testCases, testCase{
8082 name: "DisabledCurve-HelloRetryRequest",
8083 config: Config{
8084 MaxVersion: VersionTLS13,
8085 CurvePreferences: []CurveID{CurveP256},
8086 Bugs: ProtocolBugs{
8087 IgnorePeerCurvePreferences: true,
8088 },
8089 },
8090 flags: []string{"-p384-only"},
8091 shouldFail: true,
8092 expectedError: ":WRONG_CURVE:",
8093 })
8094
8095 testCases = append(testCases, testCase{
8096 name: "UnnecessaryHelloRetryRequest",
8097 config: Config{
8098 MaxVersion: VersionTLS13,
8099 Bugs: ProtocolBugs{
8100 UnnecessaryHelloRetryRequest: true,
8101 },
8102 },
8103 shouldFail: true,
8104 expectedError: ":WRONG_CURVE:",
8105 })
8106
8107 testCases = append(testCases, testCase{
8108 name: "SecondHelloRetryRequest",
8109 config: Config{
8110 MaxVersion: VersionTLS13,
8111 // P-384 requires HelloRetryRequest in BoringSSL.
8112 CurvePreferences: []CurveID{CurveP384},
8113 Bugs: ProtocolBugs{
8114 SecondHelloRetryRequest: true,
8115 },
8116 },
8117 shouldFail: true,
8118 expectedError: ":UNEXPECTED_MESSAGE:",
8119 })
8120
8121 testCases = append(testCases, testCase{
8122 testType: serverTest,
8123 name: "SecondClientHelloMissingKeyShare",
8124 config: Config{
8125 MaxVersion: VersionTLS13,
8126 DefaultCurves: []CurveID{},
8127 Bugs: ProtocolBugs{
8128 SecondClientHelloMissingKeyShare: true,
8129 },
8130 },
8131 shouldFail: true,
8132 expectedError: ":MISSING_KEY_SHARE:",
8133 })
8134
8135 testCases = append(testCases, testCase{
8136 testType: serverTest,
8137 name: "SecondClientHelloWrongCurve",
8138 config: Config{
8139 MaxVersion: VersionTLS13,
8140 DefaultCurves: []CurveID{},
8141 Bugs: ProtocolBugs{
8142 MisinterpretHelloRetryRequestCurve: CurveP521,
8143 },
8144 },
8145 shouldFail: true,
8146 expectedError: ":WRONG_CURVE:",
8147 })
8148
8149 testCases = append(testCases, testCase{
8150 name: "HelloRetryRequestVersionMismatch",
8151 config: Config{
8152 MaxVersion: VersionTLS13,
8153 // P-384 requires HelloRetryRequest in BoringSSL.
8154 CurvePreferences: []CurveID{CurveP384},
8155 Bugs: ProtocolBugs{
8156 SendServerHelloVersion: 0x0305,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":WRONG_VERSION_NUMBER:",
8161 })
8162
8163 testCases = append(testCases, testCase{
8164 name: "HelloRetryRequestCurveMismatch",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 // P-384 requires HelloRetryRequest in BoringSSL.
8168 CurvePreferences: []CurveID{CurveP384},
8169 Bugs: ProtocolBugs{
8170 // Send P-384 (correct) in the HelloRetryRequest.
8171 SendHelloRetryRequestCurve: CurveP384,
8172 // But send P-256 in the ServerHello.
8173 SendCurve: CurveP256,
8174 },
8175 },
8176 shouldFail: true,
8177 expectedError: ":WRONG_CURVE:",
8178 })
8179
8180 // Test the server selecting a curve that requires a HelloRetryRequest
8181 // without sending it.
8182 testCases = append(testCases, testCase{
8183 name: "SkipHelloRetryRequest",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 // P-384 requires HelloRetryRequest in BoringSSL.
8187 CurvePreferences: []CurveID{CurveP384},
8188 Bugs: ProtocolBugs{
8189 SkipHelloRetryRequest: true,
8190 },
8191 },
8192 shouldFail: true,
8193 expectedError: ":WRONG_CURVE:",
8194 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008195
8196 testCases = append(testCases, testCase{
8197 name: "TLS13-RequestContextInHandshake",
8198 config: Config{
8199 MaxVersion: VersionTLS13,
8200 MinVersion: VersionTLS13,
8201 ClientAuth: RequireAnyClientCert,
8202 Bugs: ProtocolBugs{
8203 SendRequestContext: []byte("request context"),
8204 },
8205 },
8206 flags: []string{
8207 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8208 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8209 },
8210 shouldFail: true,
8211 expectedError: ":DECODE_ERROR:",
8212 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008213
8214 testCases = append(testCases, testCase{
8215 testType: serverTest,
8216 name: "TLS13-TrailingKeyShareData",
8217 config: Config{
8218 MaxVersion: VersionTLS13,
8219 Bugs: ProtocolBugs{
8220 TrailingKeyShareData: true,
8221 },
8222 },
8223 shouldFail: true,
8224 expectedError: ":DECODE_ERROR:",
8225 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008226}
8227
David Benjaminf3fbade2016-09-19 13:08:16 -04008228func addPeekTests() {
8229 // Test SSL_peek works, including on empty records.
8230 testCases = append(testCases, testCase{
8231 name: "Peek-Basic",
8232 sendEmptyRecords: 1,
8233 flags: []string{"-peek-then-read"},
8234 })
8235
8236 // Test SSL_peek can drive the initial handshake.
8237 testCases = append(testCases, testCase{
8238 name: "Peek-ImplicitHandshake",
8239 flags: []string{
8240 "-peek-then-read",
8241 "-implicit-handshake",
8242 },
8243 })
8244
8245 // Test SSL_peek can discover and drive a renegotiation.
8246 testCases = append(testCases, testCase{
8247 name: "Peek-Renegotiate",
8248 config: Config{
8249 MaxVersion: VersionTLS12,
8250 },
8251 renegotiate: 1,
8252 flags: []string{
8253 "-peek-then-read",
8254 "-renegotiate-freely",
8255 "-expect-total-renegotiations", "1",
8256 },
8257 })
8258
8259 // Test SSL_peek can discover a close_notify.
8260 testCases = append(testCases, testCase{
8261 name: "Peek-Shutdown",
8262 config: Config{
8263 Bugs: ProtocolBugs{
8264 ExpectCloseNotify: true,
8265 },
8266 },
8267 flags: []string{
8268 "-peek-then-read",
8269 "-check-close-notify",
8270 },
8271 })
8272
8273 // Test SSL_peek can discover an alert.
8274 testCases = append(testCases, testCase{
8275 name: "Peek-Alert",
8276 config: Config{
8277 Bugs: ProtocolBugs{
8278 SendSpuriousAlert: alertRecordOverflow,
8279 },
8280 },
8281 flags: []string{"-peek-then-read"},
8282 shouldFail: true,
8283 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8284 })
8285
8286 // Test SSL_peek can handle KeyUpdate.
8287 testCases = append(testCases, testCase{
8288 name: "Peek-KeyUpdate",
8289 config: Config{
8290 MaxVersion: VersionTLS13,
8291 Bugs: ProtocolBugs{
8292 SendKeyUpdateBeforeEveryAppDataRecord: true,
8293 },
8294 },
8295 flags: []string{"-peek-then-read"},
8296 })
8297}
8298
Adam Langley7c803a62015-06-15 15:35:05 -07008299func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008300 defer wg.Done()
8301
8302 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008303 var err error
8304
8305 if *mallocTest < 0 {
8306 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008307 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008308 } else {
8309 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8310 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008311 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008312 if err != nil {
8313 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8314 }
8315 break
8316 }
8317 }
8318 }
Adam Langley95c29f32014-06-20 12:00:00 -07008319 statusChan <- statusMsg{test: test, err: err}
8320 }
8321}
8322
8323type statusMsg struct {
8324 test *testCase
8325 started bool
8326 err error
8327}
8328
David Benjamin5f237bc2015-02-11 17:14:15 -05008329func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008330 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008331
David Benjamin5f237bc2015-02-11 17:14:15 -05008332 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008333 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008334 if !*pipe {
8335 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008336 var erase string
8337 for i := 0; i < lineLen; i++ {
8338 erase += "\b \b"
8339 }
8340 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008341 }
8342
Adam Langley95c29f32014-06-20 12:00:00 -07008343 if msg.started {
8344 started++
8345 } else {
8346 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008347
8348 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008349 if msg.err == errUnimplemented {
8350 if *pipe {
8351 // Print each test instead of a status line.
8352 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8353 }
8354 unimplemented++
8355 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8356 } else {
8357 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8358 failed++
8359 testOutput.addResult(msg.test.name, "FAIL")
8360 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008361 } else {
8362 if *pipe {
8363 // Print each test instead of a status line.
8364 fmt.Printf("PASSED (%s)\n", msg.test.name)
8365 }
8366 testOutput.addResult(msg.test.name, "PASS")
8367 }
Adam Langley95c29f32014-06-20 12:00:00 -07008368 }
8369
David Benjamin5f237bc2015-02-11 17:14:15 -05008370 if !*pipe {
8371 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008372 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008373 lineLen = len(line)
8374 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008375 }
Adam Langley95c29f32014-06-20 12:00:00 -07008376 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008377
8378 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008379}
8380
8381func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008382 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008383 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008384 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008385
Adam Langley7c803a62015-06-15 15:35:05 -07008386 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008387 addCipherSuiteTests()
8388 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008389 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008390 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008391 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008392 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008393 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008394 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008395 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008396 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008397 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008398 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008399 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008400 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008401 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008402 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008403 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008404 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008405 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008406 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008407 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008408 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008409 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008410 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008411 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008412 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008413 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008414 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008415 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008416
8417 var wg sync.WaitGroup
8418
Adam Langley7c803a62015-06-15 15:35:05 -07008419 statusChan := make(chan statusMsg, *numWorkers)
8420 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008421 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008422
EKRf71d7ed2016-08-06 13:25:12 -07008423 if len(*shimConfigFile) != 0 {
8424 encoded, err := ioutil.ReadFile(*shimConfigFile)
8425 if err != nil {
8426 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8427 os.Exit(1)
8428 }
8429
8430 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8431 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8432 os.Exit(1)
8433 }
8434 }
8435
David Benjamin025b3d32014-07-01 19:53:04 -04008436 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008437
Adam Langley7c803a62015-06-15 15:35:05 -07008438 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008439 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008440 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008441 }
8442
David Benjamin270f0a72016-03-17 14:41:36 -04008443 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008444 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008445 matched := true
8446 if len(*testToRun) != 0 {
8447 var err error
8448 matched, err = filepath.Match(*testToRun, testCases[i].name)
8449 if err != nil {
8450 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8451 os.Exit(1)
8452 }
8453 }
8454
EKRf71d7ed2016-08-06 13:25:12 -07008455 if !*includeDisabled {
8456 for pattern := range shimConfig.DisabledTests {
8457 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8458 if err != nil {
8459 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8460 os.Exit(1)
8461 }
8462
8463 if isDisabled {
8464 matched = false
8465 break
8466 }
8467 }
8468 }
8469
David Benjamin17e12922016-07-28 18:04:43 -04008470 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008471 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008472 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008473 }
8474 }
David Benjamin17e12922016-07-28 18:04:43 -04008475
David Benjamin270f0a72016-03-17 14:41:36 -04008476 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008477 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008478 os.Exit(1)
8479 }
Adam Langley95c29f32014-06-20 12:00:00 -07008480
8481 close(testChan)
8482 wg.Wait()
8483 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008484 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008485
8486 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008487
8488 if *jsonOutput != "" {
8489 if err := testOutput.writeTo(*jsonOutput); err != nil {
8490 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8491 }
8492 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008493
EKR842ae6c2016-07-27 09:22:05 +02008494 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8495 os.Exit(1)
8496 }
8497
8498 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008499 os.Exit(1)
8500 }
Adam Langley95c29f32014-06-20 12:00:00 -07008501}