blob: c350ac5bbfac6892d2027291cc289f98d0109b31 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjamin9867b7d2016-03-01 23:25:48 -0500369func writeTranscript(test *testCase, isResume bool, data []byte) {
370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
390 name := test.name
391 if isResume {
392 name += "-Resume"
393 } else {
394 name += "-Normal"
395 }
396
397 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
398 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
399 }
400}
401
David Benjamin3ed59772016-03-08 12:50:21 -0500402// A timeoutConn implements an idle timeout on each Read and Write operation.
403type timeoutConn struct {
404 net.Conn
405 timeout time.Duration
406}
407
408func (t *timeoutConn) Read(b []byte) (int, error) {
409 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
410 return 0, err
411 }
412 return t.Conn.Read(b)
413}
414
415func (t *timeoutConn) Write(b []byte) (int, error) {
416 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
417 return 0, err
418 }
419 return t.Conn.Write(b)
420}
421
David Benjamin8e6db492015-07-25 18:29:23 -0400422func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400423 if !test.noSessionCache {
424 if config.ClientSessionCache == nil {
425 config.ClientSessionCache = NewLRUClientSessionCache(1)
426 }
427 if config.ServerSessionCache == nil {
428 config.ServerSessionCache = NewLRUServerSessionCache(1)
429 }
430 }
431 if test.testType == clientTest {
432 if len(config.Certificates) == 0 {
433 config.Certificates = []Certificate{rsaCertificate}
434 }
435 } else {
436 // Supply a ServerName to ensure a constant session cache key,
437 // rather than falling back to net.Conn.RemoteAddr.
438 if len(config.ServerName) == 0 {
439 config.ServerName = "test"
440 }
441 }
442 if *fuzzer {
443 config.Bugs.NullAllCiphers = true
444 }
David Benjamine54af062016-08-08 19:21:18 -0400445
David Benjamin01784b42016-06-07 18:00:52 -0400446 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500447
David Benjamin6fd297b2014-08-11 18:43:38 -0400448 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500449 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
450 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500451 }
452
David Benjamin9867b7d2016-03-01 23:25:48 -0500453 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500454 local, peer := "client", "server"
455 if test.testType == clientTest {
456 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500457 }
David Benjaminebda9b32015-11-02 15:33:18 -0500458 connDebug := &recordingConn{
459 Conn: conn,
460 isDatagram: test.protocol == dtls,
461 local: local,
462 peer: peer,
463 }
464 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500465 if *flagDebug {
466 defer connDebug.WriteTo(os.Stdout)
467 }
468 if len(*transcriptDir) != 0 {
469 defer func() {
470 writeTranscript(test, isResume, connDebug.Transcript())
471 }()
472 }
David Benjaminebda9b32015-11-02 15:33:18 -0500473
474 if config.Bugs.PacketAdaptor != nil {
475 config.Bugs.PacketAdaptor.debug = connDebug
476 }
477 }
478
479 if test.replayWrites {
480 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400481 }
482
David Benjamin3ed59772016-03-08 12:50:21 -0500483 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500484 if test.damageFirstWrite {
485 connDamage = newDamageAdaptor(conn)
486 conn = connDamage
487 }
488
David Benjamin6fd297b2014-08-11 18:43:38 -0400489 if test.sendPrefix != "" {
490 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
491 return err
492 }
David Benjamin98e882e2014-08-08 13:24:34 -0400493 }
494
David Benjamin1d5c83e2014-07-22 19:20:02 -0400495 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400496 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 if test.protocol == dtls {
498 tlsConn = DTLSServer(conn, config)
499 } else {
500 tlsConn = Server(conn, config)
501 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400502 } else {
503 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400504 if test.protocol == dtls {
505 tlsConn = DTLSClient(conn, config)
506 } else {
507 tlsConn = Client(conn, config)
508 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400509 }
David Benjamin30789da2015-08-29 22:56:45 -0400510 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511
Adam Langley95c29f32014-06-20 12:00:00 -0700512 if err := tlsConn.Handshake(); err != nil {
513 return err
514 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700515
David Benjamin01fe8202014-09-24 15:21:44 -0400516 // TODO(davidben): move all per-connection expectations into a dedicated
517 // expectations struct that can be specified separately for the two
518 // legs.
519 expectedVersion := test.expectedVersion
520 if isResume && test.expectedResumeVersion != 0 {
521 expectedVersion = test.expectedResumeVersion
522 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700523 connState := tlsConn.ConnectionState()
524 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400525 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400526 }
527
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400529 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
530 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
532 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
533 }
David Benjamin90da8c82015-04-20 14:57:57 -0400534
David Benjamina08e49d2014-08-24 01:46:07 -0400535 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700536 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400537 if channelID == nil {
538 return fmt.Errorf("no channel ID negotiated")
539 }
540 if channelID.Curve != channelIDKey.Curve ||
541 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
542 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
543 return fmt.Errorf("incorrect channel ID")
544 }
545 }
546
David Benjaminae2888f2014-09-06 12:58:58 -0400547 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400549 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
550 }
551 }
552
David Benjaminc7ce9772015-10-09 19:32:41 -0400553 if test.expectNoNextProto {
554 if actual := connState.NegotiatedProtocol; actual != "" {
555 return fmt.Errorf("got unexpected next proto %s", actual)
556 }
557 }
558
David Benjaminfc7b0862014-09-06 13:21:53 -0400559 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700560 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400561 return fmt.Errorf("next proto type mismatch")
562 }
563 }
564
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700565 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500566 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
567 }
568
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100569 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300570 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100571 }
572
Paul Lietar4fac72e2015-09-09 13:44:55 +0100573 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
574 return fmt.Errorf("SCT list mismatch")
575 }
576
Nick Harper60edffd2016-06-21 15:19:24 -0700577 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
578 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400579 }
580
Steven Valdez5440fe02016-07-18 12:40:30 -0400581 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
582 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
583 }
584
David Benjaminc565ebb2015-04-03 04:06:36 -0400585 if test.exportKeyingMaterial > 0 {
586 actual := make([]byte, test.exportKeyingMaterial)
587 if _, err := io.ReadFull(tlsConn, actual); err != nil {
588 return err
589 }
590 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
591 if err != nil {
592 return err
593 }
594 if !bytes.Equal(actual, expected) {
595 return fmt.Errorf("keying material mismatch")
596 }
597 }
598
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700599 if test.testTLSUnique {
600 var peersValue [12]byte
601 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
602 return err
603 }
604 expected := tlsConn.ConnectionState().TLSUnique
605 if !bytes.Equal(peersValue[:], expected) {
606 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
607 }
608 }
609
David Benjamine58c4f52014-08-24 03:47:07 -0400610 if test.shimWritesFirst {
611 var buf [5]byte
612 _, err := io.ReadFull(tlsConn, buf[:])
613 if err != nil {
614 return err
615 }
616 if string(buf[:]) != "hello" {
617 return fmt.Errorf("bad initial message")
618 }
619 }
620
Steven Valdez32635b82016-08-16 11:25:03 -0400621 for i := 0; i < test.sendKeyUpdates; i++ {
622 tlsConn.SendKeyUpdate()
623 }
624
David Benjamina8ebe222015-06-06 03:04:39 -0400625 for i := 0; i < test.sendEmptyRecords; i++ {
626 tlsConn.Write(nil)
627 }
628
David Benjamin24f346d2015-06-06 03:28:08 -0400629 for i := 0; i < test.sendWarningAlerts; i++ {
630 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
631 }
632
David Benjamin47921102016-07-28 11:29:18 -0400633 if test.sendHalfHelloRequest {
634 tlsConn.SendHalfHelloRequest()
635 }
636
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400637 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700638 if test.renegotiateCiphers != nil {
639 config.CipherSuites = test.renegotiateCiphers
640 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 for i := 0; i < test.renegotiate; i++ {
642 if err := tlsConn.Renegotiate(); err != nil {
643 return err
644 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700645 }
646 } else if test.renegotiateCiphers != nil {
647 panic("renegotiateCiphers without renegotiate")
648 }
649
David Benjamin5fa3eba2015-01-22 16:35:40 -0500650 if test.damageFirstWrite {
651 connDamage.setDamage(true)
652 tlsConn.Write([]byte("DAMAGED WRITE"))
653 connDamage.setDamage(false)
654 }
655
David Benjamin8e6db492015-07-25 18:29:23 -0400656 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700657 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400658 if test.protocol == dtls {
659 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
660 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 // Read until EOF.
662 _, err := io.Copy(ioutil.Discard, tlsConn)
663 return err
664 }
David Benjamin4417d052015-04-05 04:17:25 -0400665 if messageLen == 0 {
666 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700667 }
Adam Langley95c29f32014-06-20 12:00:00 -0700668
David Benjamin8e6db492015-07-25 18:29:23 -0400669 messageCount := test.messageCount
670 if messageCount == 0 {
671 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400672 }
673
David Benjamin8e6db492015-07-25 18:29:23 -0400674 for j := 0; j < messageCount; j++ {
675 testMessage := make([]byte, messageLen)
676 for i := range testMessage {
677 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400678 }
David Benjamin8e6db492015-07-25 18:29:23 -0400679 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700680
Steven Valdez32635b82016-08-16 11:25:03 -0400681 for i := 0; i < test.sendKeyUpdates; i++ {
682 tlsConn.SendKeyUpdate()
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 for i := 0; i < test.sendEmptyRecords; i++ {
686 tlsConn.Write(nil)
687 }
688
689 for i := 0; i < test.sendWarningAlerts; i++ {
690 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
691 }
692
David Benjamin4f75aaf2015-09-01 16:53:10 -0400693 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400694 // The shim will not respond.
695 continue
696 }
697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 buf := make([]byte, len(testMessage))
699 if test.protocol == dtls {
700 bufTmp := make([]byte, len(buf)+1)
701 n, err := tlsConn.Read(bufTmp)
702 if err != nil {
703 return err
704 }
705 if n != len(buf) {
706 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
707 }
708 copy(buf, bufTmp)
709 } else {
710 _, err := io.ReadFull(tlsConn, buf)
711 if err != nil {
712 return err
713 }
714 }
715
716 for i, v := range buf {
717 if v != testMessage[i]^0xff {
718 return fmt.Errorf("bad reply contents at byte %d", i)
719 }
Adam Langley95c29f32014-06-20 12:00:00 -0700720 }
721 }
722
723 return nil
724}
725
David Benjamin325b5c32014-07-01 19:40:31 -0400726func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400729 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700730 }
David Benjamin325b5c32014-07-01 19:40:31 -0400731 valgrindArgs = append(valgrindArgs, path)
732 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700733
David Benjamin325b5c32014-07-01 19:40:31 -0400734 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700735}
736
David Benjamin325b5c32014-07-01 19:40:31 -0400737func gdbOf(path string, args ...string) *exec.Cmd {
738 xtermArgs := []string{"-e", "gdb", "--args"}
739 xtermArgs = append(xtermArgs, path)
740 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700741
David Benjamin325b5c32014-07-01 19:40:31 -0400742 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700743}
744
David Benjamind16bf342015-12-18 00:53:12 -0500745func lldbOf(path string, args ...string) *exec.Cmd {
746 xtermArgs := []string{"-e", "lldb", "--"}
747 xtermArgs = append(xtermArgs, path)
748 xtermArgs = append(xtermArgs, args...)
749
750 return exec.Command("xterm", xtermArgs...)
751}
752
EKR842ae6c2016-07-27 09:22:05 +0200753var (
754 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
755 errUnimplemented = errors.New("child process does not implement needed flags")
756)
Adam Langley69a01602014-11-17 17:26:55 -0800757
David Benjamin87c8a642015-02-21 01:54:29 -0500758// accept accepts a connection from listener, unless waitChan signals a process
759// exit first.
760func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
761 type connOrError struct {
762 conn net.Conn
763 err error
764 }
765 connChan := make(chan connOrError, 1)
766 go func() {
767 conn, err := listener.Accept()
768 connChan <- connOrError{conn, err}
769 close(connChan)
770 }()
771 select {
772 case result := <-connChan:
773 return result.conn, result.err
774 case childErr := <-waitChan:
775 waitChan <- childErr
776 return nil, fmt.Errorf("child exited early: %s", childErr)
777 }
778}
779
EKRf71d7ed2016-08-06 13:25:12 -0700780func translateExpectedError(errorStr string) string {
781 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
782 return translated
783 }
784
785 if *looseErrors {
786 return ""
787 }
788
789 return errorStr
790}
791
Adam Langley7c803a62015-06-15 15:35:05 -0700792func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700793 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
794 panic("Error expected without shouldFail in " + test.name)
795 }
796
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700797 if test.expectResumeRejected && !test.resumeSession {
798 panic("expectResumeRejected without resumeSession in " + test.name)
799 }
800
David Benjamin87c8a642015-02-21 01:54:29 -0500801 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
802 if err != nil {
803 panic(err)
804 }
805 defer func() {
806 if listener != nil {
807 listener.Close()
808 }
809 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700810
David Benjamin87c8a642015-02-21 01:54:29 -0500811 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400812 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400813 flags = append(flags, "-server")
814
David Benjamin025b3d32014-07-01 19:53:04 -0400815 flags = append(flags, "-key-file")
816 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700817 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400818 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700819 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400820 }
821
822 flags = append(flags, "-cert-file")
823 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828 }
David Benjamin5a593af2014-08-11 19:51:50 -0400829
David Benjamin6fd297b2014-08-11 18:43:38 -0400830 if test.protocol == dtls {
831 flags = append(flags, "-dtls")
832 }
833
David Benjamin46662482016-08-17 00:51:00 -0400834 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400835 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400836 resumeCount++
837 if test.resumeRenewedSession {
838 resumeCount++
839 }
840 }
841
842 if resumeCount > 0 {
843 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400844 }
845
David Benjamine58c4f52014-08-24 03:47:07 -0400846 if test.shimWritesFirst {
847 flags = append(flags, "-shim-writes-first")
848 }
849
David Benjamin30789da2015-08-29 22:56:45 -0400850 if test.shimShutsDown {
851 flags = append(flags, "-shim-shuts-down")
852 }
853
David Benjaminc565ebb2015-04-03 04:06:36 -0400854 if test.exportKeyingMaterial > 0 {
855 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
856 flags = append(flags, "-export-label", test.exportLabel)
857 flags = append(flags, "-export-context", test.exportContext)
858 if test.useExportContext {
859 flags = append(flags, "-use-export-context")
860 }
861 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700862 if test.expectResumeRejected {
863 flags = append(flags, "-expect-session-miss")
864 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400865
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700866 if test.testTLSUnique {
867 flags = append(flags, "-tls-unique")
868 }
869
David Benjamin025b3d32014-07-01 19:53:04 -0400870 flags = append(flags, test.flags...)
871
872 var shim *exec.Cmd
873 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700874 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700875 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700876 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500877 } else if *useLLDB {
878 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400879 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400881 }
David Benjamin025b3d32014-07-01 19:53:04 -0400882 shim.Stdin = os.Stdin
883 var stdoutBuf, stderrBuf bytes.Buffer
884 shim.Stdout = &stdoutBuf
885 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800886 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500887 shim.Env = os.Environ()
888 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800889 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400890 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800891 }
892 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
893 }
David Benjamin025b3d32014-07-01 19:53:04 -0400894
895 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700896 panic(err)
897 }
David Benjamin87c8a642015-02-21 01:54:29 -0500898 waitChan := make(chan error, 1)
899 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700900
901 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700902
David Benjamin7a4aaa42016-09-20 17:58:14 -0400903 if *deterministic {
904 config.Rand = &deterministicRand{}
905 }
906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400940 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800941 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200942 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
943 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800944 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200945 case 89:
946 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400947 case 99:
948 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800949 }
950 }
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin9bea3492016-03-02 10:59:16 -0500952 // Account for Windows line endings.
953 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
954 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500955
956 // Separate the errors from the shim and those from tools like
957 // AddressSanitizer.
958 var extraStderr string
959 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
960 stderr = stderrParts[0]
961 extraStderr = stderrParts[1]
962 }
963
Adam Langley95c29f32014-06-20 12:00:00 -0700964 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700965 expectedError := translateExpectedError(test.expectedError)
966 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200967
Adam Langleyac61fa32014-06-23 12:03:11 -0700968 localError := "none"
969 if err != nil {
970 localError = err.Error()
971 }
972 if len(test.expectedLocalError) != 0 {
973 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
974 }
Adam Langley95c29f32014-06-20 12:00:00 -0700975
976 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700977 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700978 if childErr != nil {
979 childError = childErr.Error()
980 }
981
982 var msg string
983 switch {
984 case failed && !test.shouldFail:
985 msg = "unexpected failure"
986 case !failed && test.shouldFail:
987 msg = "unexpected success"
988 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700989 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700990 default:
991 panic("internal error")
992 }
993
David Benjamin9aafb642016-09-20 19:36:53 -0400994 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 -0700995 }
996
David Benjamind2ba8892016-09-20 19:41:04 -0400997 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500998 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700999 }
1000
David Benjamind2ba8892016-09-20 19:41:04 -04001001 if *useValgrind && isValgrindError {
1002 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1003 }
1004
Adam Langley95c29f32014-06-20 12:00:00 -07001005 return nil
1006}
1007
1008var tlsVersions = []struct {
1009 name string
1010 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001011 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001012 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001013}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001014 {"SSL3", VersionSSL30, "-no-ssl3", false},
1015 {"TLS1", VersionTLS10, "-no-tls1", true},
1016 {"TLS11", VersionTLS11, "-no-tls11", false},
1017 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001018 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001019}
1020
1021var testCipherSuites = []struct {
1022 name string
1023 id uint16
1024}{
1025 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1033 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001035 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1036 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1039 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1041 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001042 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001043 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001044 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001045 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001046 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001049 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001050 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001051 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001052 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001053 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001054 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1055 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1056 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1057 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001058 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1059 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001060 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1061 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001062 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001063 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1064 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001065 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001066}
1067
David Benjamin8b8c0062014-11-23 02:47:52 -05001068func hasComponent(suiteName, component string) bool {
1069 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1070}
1071
David Benjaminf7768e42014-08-31 02:06:47 -04001072func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001073 return hasComponent(suiteName, "GCM") ||
1074 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001075 hasComponent(suiteName, "SHA384") ||
1076 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001077}
1078
Nick Harper1fd39d82016-06-14 18:14:35 -07001079func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001080 // Only AEADs.
1081 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1082 return false
1083 }
1084 // No old CHACHA20_POLY1305.
1085 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1086 return false
1087 }
1088 // Must have ECDHE.
1089 // TODO(davidben,svaldez): Add pure PSK support.
1090 if !hasComponent(suiteName, "ECDHE") {
1091 return false
1092 }
1093 // TODO(davidben,svaldez): Add PSK support.
1094 if hasComponent(suiteName, "PSK") {
1095 return false
1096 }
1097 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001098}
1099
David Benjamin8b8c0062014-11-23 02:47:52 -05001100func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001101 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001102}
1103
Adam Langleya7997f12015-05-14 17:38:50 -07001104func bigFromHex(hex string) *big.Int {
1105 ret, ok := new(big.Int).SetString(hex, 16)
1106 if !ok {
1107 panic("failed to parse hex number 0x" + hex)
1108 }
1109 return ret
1110}
1111
Adam Langley7c803a62015-06-15 15:35:05 -07001112func addBasicTests() {
1113 basicTests := []testCase{
1114 {
Adam Langley7c803a62015-06-15 15:35:05 -07001115 name: "NoFallbackSCSV",
1116 config: Config{
1117 Bugs: ProtocolBugs{
1118 FailIfNotFallbackSCSV: true,
1119 },
1120 },
1121 shouldFail: true,
1122 expectedLocalError: "no fallback SCSV found",
1123 },
1124 {
1125 name: "SendFallbackSCSV",
1126 config: Config{
1127 Bugs: ProtocolBugs{
1128 FailIfNotFallbackSCSV: true,
1129 },
1130 },
1131 flags: []string{"-fallback-scsv"},
1132 },
1133 {
1134 name: "ClientCertificateTypes",
1135 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001136 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001137 ClientAuth: RequestClientCert,
1138 ClientCertificateTypes: []byte{
1139 CertTypeDSSSign,
1140 CertTypeRSASign,
1141 CertTypeECDSASign,
1142 },
1143 },
1144 flags: []string{
1145 "-expect-certificate-types",
1146 base64.StdEncoding.EncodeToString([]byte{
1147 CertTypeDSSSign,
1148 CertTypeRSASign,
1149 CertTypeECDSASign,
1150 }),
1151 },
1152 },
1153 {
Adam Langley7c803a62015-06-15 15:35:05 -07001154 name: "UnauthenticatedECDH",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 UnauthenticatedECDH: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
1166 name: "SkipCertificateStatus",
1167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1170 Bugs: ProtocolBugs{
1171 SkipCertificateStatus: true,
1172 },
1173 },
1174 flags: []string{
1175 "-enable-ocsp-stapling",
1176 },
1177 },
1178 {
1179 name: "SkipServerKeyExchange",
1180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001181 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001182 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1183 Bugs: ProtocolBugs{
1184 SkipServerKeyExchange: true,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":UNEXPECTED_MESSAGE:",
1189 },
1190 {
Adam Langley7c803a62015-06-15 15:35:05 -07001191 testType: serverTest,
1192 name: "Alert",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1200 },
1201 {
1202 protocol: dtls,
1203 testType: serverTest,
1204 name: "Alert-DTLS",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1212 },
1213 {
1214 testType: serverTest,
1215 name: "FragmentAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 FragmentAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "FragmentAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 FragmentAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
1239 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001240 name: "DoubleAlert",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 DoubleAlert: true,
1244 SendSpuriousAlert: alertRecordOverflow,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":BAD_ALERT:",
1249 },
1250 {
1251 protocol: dtls,
1252 testType: serverTest,
1253 name: "DoubleAlert-DTLS",
1254 config: Config{
1255 Bugs: ProtocolBugs{
1256 DoubleAlert: true,
1257 SendSpuriousAlert: alertRecordOverflow,
1258 },
1259 },
1260 shouldFail: true,
1261 expectedError: ":BAD_ALERT:",
1262 },
1263 {
Adam Langley7c803a62015-06-15 15:35:05 -07001264 name: "SkipNewSessionTicket",
1265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001266 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001267 Bugs: ProtocolBugs{
1268 SkipNewSessionTicket: true,
1269 },
1270 },
1271 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001272 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001273 },
1274 {
1275 testType: serverTest,
1276 name: "FallbackSCSV",
1277 config: Config{
1278 MaxVersion: VersionTLS11,
1279 Bugs: ProtocolBugs{
1280 SendFallbackSCSV: true,
1281 },
1282 },
1283 shouldFail: true,
1284 expectedError: ":INAPPROPRIATE_FALLBACK:",
1285 },
1286 {
1287 testType: serverTest,
1288 name: "FallbackSCSV-VersionMatch",
1289 config: Config{
1290 Bugs: ProtocolBugs{
1291 SendFallbackSCSV: true,
1292 },
1293 },
1294 },
1295 {
1296 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001297 name: "FallbackSCSV-VersionMatch-TLS12",
1298 config: Config{
1299 MaxVersion: VersionTLS12,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1305 },
1306 {
1307 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001308 name: "FragmentedClientVersion",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 MaxHandshakeRecordLength: 1,
1312 FragmentClientVersion: true,
1313 },
1314 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001315 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001316 },
1317 {
Adam Langley7c803a62015-06-15 15:35:05 -07001318 testType: serverTest,
1319 name: "HttpGET",
1320 sendPrefix: "GET / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpPOST",
1327 sendPrefix: "POST / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpHEAD",
1334 sendPrefix: "HEAD / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpPUT",
1341 sendPrefix: "PUT / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpCONNECT",
1348 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTPS_PROXY_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "Garbage",
1355 sendPrefix: "blah",
1356 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001357 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001358 },
1359 {
Adam Langley7c803a62015-06-15 15:35:05 -07001360 name: "RSAEphemeralKey",
1361 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001362 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001363 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1364 Bugs: ProtocolBugs{
1365 RSAEphemeralKey: true,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":UNEXPECTED_MESSAGE:",
1370 },
1371 {
1372 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001373 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
1378 protocol: dtls,
1379 name: "DisableEverything-DTLS",
1380 flags: []string{"-no-tls12", "-no-tls1"},
1381 shouldFail: true,
1382 expectedError: ":WRONG_SSL_VERSION:",
1383 },
1384 {
Adam Langley7c803a62015-06-15 15:35:05 -07001385 protocol: dtls,
1386 testType: serverTest,
1387 name: "MTU",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 MaxPacketLength: 256,
1391 },
1392 },
1393 flags: []string{"-mtu", "256"},
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "MTUExceeded",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 MaxPacketLength: 255,
1402 },
1403 },
1404 flags: []string{"-mtu", "256"},
1405 shouldFail: true,
1406 expectedLocalError: "dtls: exceeded maximum packet length",
1407 },
1408 {
1409 name: "CertMismatchRSA",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001413 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001414 Bugs: ProtocolBugs{
1415 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1420 },
1421 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001422 name: "CertMismatchRSA-TLS13",
1423 config: Config{
1424 MaxVersion: VersionTLS13,
1425 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1426 Certificates: []Certificate{ecdsaP256Certificate},
1427 Bugs: ProtocolBugs{
1428 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1433 },
1434 {
Adam Langley7c803a62015-06-15 15:35:05 -07001435 name: "CertMismatchECDSA",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001439 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001440 Bugs: ProtocolBugs{
1441 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1446 },
1447 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001448 name: "CertMismatchECDSA-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Certificates: []Certificate{rsaCertificate},
1453 Bugs: ProtocolBugs{
1454 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1459 },
1460 {
Adam Langley7c803a62015-06-15 15:35:05 -07001461 name: "EmptyCertificateList",
1462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001463 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 EmptyCertificateList: true,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":DECODE_ERROR:",
1471 },
1472 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001473 name: "EmptyCertificateList-TLS13",
1474 config: Config{
1475 MaxVersion: VersionTLS13,
1476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1477 Bugs: ProtocolBugs{
1478 EmptyCertificateList: true,
1479 },
1480 },
1481 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001482 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001483 },
1484 {
Adam Langley7c803a62015-06-15 15:35:05 -07001485 name: "TLSFatalBadPackets",
1486 damageFirstWrite: true,
1487 shouldFail: true,
1488 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1489 },
1490 {
1491 protocol: dtls,
1492 name: "DTLSIgnoreBadPackets",
1493 damageFirstWrite: true,
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets-Async",
1498 damageFirstWrite: true,
1499 flags: []string{"-async"},
1500 },
1501 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001502 name: "AppDataBeforeHandshake",
1503 config: Config{
1504 Bugs: ProtocolBugs{
1505 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1506 },
1507 },
1508 shouldFail: true,
1509 expectedError: ":UNEXPECTED_RECORD:",
1510 },
1511 {
1512 name: "AppDataBeforeHandshake-Empty",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 AppDataBeforeHandshake: []byte{},
1516 },
1517 },
1518 shouldFail: true,
1519 expectedError: ":UNEXPECTED_RECORD:",
1520 },
1521 {
1522 protocol: dtls,
1523 name: "AppDataBeforeHandshake-DTLS",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_RECORD:",
1531 },
1532 {
1533 protocol: dtls,
1534 name: "AppDataBeforeHandshake-DTLS-Empty",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 AppDataBeforeHandshake: []byte{},
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 },
1543 {
Adam Langley7c803a62015-06-15 15:35:05 -07001544 name: "AppDataAfterChangeCipherSpec",
1545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001546 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1549 },
1550 },
1551 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001552 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001553 },
1554 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 name: "AppDataAfterChangeCipherSpec-Empty",
1556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001557 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001558 Bugs: ProtocolBugs{
1559 AppDataAfterChangeCipherSpec: []byte{},
1560 },
1561 },
1562 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001563 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001564 },
1565 {
Adam Langley7c803a62015-06-15 15:35:05 -07001566 protocol: dtls,
1567 name: "AppDataAfterChangeCipherSpec-DTLS",
1568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001569 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001570 Bugs: ProtocolBugs{
1571 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1572 },
1573 },
1574 // BoringSSL's DTLS implementation will drop the out-of-order
1575 // application data.
1576 },
1577 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001578 protocol: dtls,
1579 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001581 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001582 Bugs: ProtocolBugs{
1583 AppDataAfterChangeCipherSpec: []byte{},
1584 },
1585 },
1586 // BoringSSL's DTLS implementation will drop the out-of-order
1587 // application data.
1588 },
1589 {
Adam Langley7c803a62015-06-15 15:35:05 -07001590 name: "AlertAfterChangeCipherSpec",
1591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001592 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001593 Bugs: ProtocolBugs{
1594 AlertAfterChangeCipherSpec: alertRecordOverflow,
1595 },
1596 },
1597 shouldFail: true,
1598 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1599 },
1600 {
1601 protocol: dtls,
1602 name: "AlertAfterChangeCipherSpec-DTLS",
1603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001604 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001605 Bugs: ProtocolBugs{
1606 AlertAfterChangeCipherSpec: alertRecordOverflow,
1607 },
1608 },
1609 shouldFail: true,
1610 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1611 },
1612 {
1613 protocol: dtls,
1614 name: "ReorderHandshakeFragments-Small-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 ReorderHandshakeFragments: true,
1618 // Small enough that every handshake message is
1619 // fragmented.
1620 MaxHandshakeRecordLength: 2,
1621 },
1622 },
1623 },
1624 {
1625 protocol: dtls,
1626 name: "ReorderHandshakeFragments-Large-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 ReorderHandshakeFragments: true,
1630 // Large enough that no handshake message is
1631 // fragmented.
1632 MaxHandshakeRecordLength: 2048,
1633 },
1634 },
1635 },
1636 {
1637 protocol: dtls,
1638 name: "MixCompleteMessageWithFragments-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 ReorderHandshakeFragments: true,
1642 MixCompleteMessageWithFragments: true,
1643 MaxHandshakeRecordLength: 2,
1644 },
1645 },
1646 },
1647 {
1648 name: "SendInvalidRecordType",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SendInvalidRecordType-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SendInvalidRecordType: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":UNEXPECTED_RECORD:",
1667 },
1668 {
1669 name: "FalseStart-SkipServerSecondLeg",
1670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001671 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1673 NextProtos: []string{"foo"},
1674 Bugs: ProtocolBugs{
1675 SkipNewSessionTicket: true,
1676 SkipChangeCipherSpec: true,
1677 SkipFinished: true,
1678 ExpectFalseStart: true,
1679 },
1680 },
1681 flags: []string{
1682 "-false-start",
1683 "-handshake-never-done",
1684 "-advertise-alpn", "\x03foo",
1685 },
1686 shimWritesFirst: true,
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_RECORD:",
1689 },
1690 {
1691 name: "FalseStart-SkipServerSecondLeg-Implicit",
1692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001693 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1695 NextProtos: []string{"foo"},
1696 Bugs: ProtocolBugs{
1697 SkipNewSessionTicket: true,
1698 SkipChangeCipherSpec: true,
1699 SkipFinished: true,
1700 },
1701 },
1702 flags: []string{
1703 "-implicit-handshake",
1704 "-false-start",
1705 "-handshake-never-done",
1706 "-advertise-alpn", "\x03foo",
1707 },
1708 shouldFail: true,
1709 expectedError: ":UNEXPECTED_RECORD:",
1710 },
1711 {
1712 testType: serverTest,
1713 name: "FailEarlyCallback",
1714 flags: []string{"-fail-early-callback"},
1715 shouldFail: true,
1716 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001717 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001718 },
1719 {
Adam Langley7c803a62015-06-15 15:35:05 -07001720 protocol: dtls,
1721 name: "FragmentMessageTypeMismatch-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 MaxHandshakeRecordLength: 2,
1725 FragmentMessageTypeMismatch: true,
1726 },
1727 },
1728 shouldFail: true,
1729 expectedError: ":FRAGMENT_MISMATCH:",
1730 },
1731 {
1732 protocol: dtls,
1733 name: "FragmentMessageLengthMismatch-DTLS",
1734 config: Config{
1735 Bugs: ProtocolBugs{
1736 MaxHandshakeRecordLength: 2,
1737 FragmentMessageLengthMismatch: true,
1738 },
1739 },
1740 shouldFail: true,
1741 expectedError: ":FRAGMENT_MISMATCH:",
1742 },
1743 {
1744 protocol: dtls,
1745 name: "SplitFragments-Header-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 SplitFragments: 2,
1749 },
1750 },
1751 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001752 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001753 },
1754 {
1755 protocol: dtls,
1756 name: "SplitFragments-Boundary-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 SplitFragments: dtlsRecordHeaderLen,
1760 },
1761 },
1762 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001763 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001764 },
1765 {
1766 protocol: dtls,
1767 name: "SplitFragments-Body-DTLS",
1768 config: Config{
1769 Bugs: ProtocolBugs{
1770 SplitFragments: dtlsRecordHeaderLen + 1,
1771 },
1772 },
1773 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001774 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001775 },
1776 {
1777 protocol: dtls,
1778 name: "SendEmptyFragments-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 SendEmptyFragments: true,
1782 },
1783 },
1784 },
1785 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 name: "BadFinished-Client",
1787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001788 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001797 name: "BadFinished-Client-TLS13",
1798 config: Config{
1799 MaxVersion: VersionTLS13,
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 },
1803 },
1804 shouldFail: true,
1805 expectedError: ":DIGEST_CHECK_FAILED:",
1806 },
1807 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001808 testType: serverTest,
1809 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001811 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 },
1815 },
1816 shouldFail: true,
1817 expectedError: ":DIGEST_CHECK_FAILED:",
1818 },
1819 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001820 testType: serverTest,
1821 name: "BadFinished-Server-TLS13",
1822 config: Config{
1823 MaxVersion: VersionTLS13,
1824 Bugs: ProtocolBugs{
1825 BadFinished: true,
1826 },
1827 },
1828 shouldFail: true,
1829 expectedError: ":DIGEST_CHECK_FAILED:",
1830 },
1831 {
Adam Langley7c803a62015-06-15 15:35:05 -07001832 name: "FalseStart-BadFinished",
1833 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001834 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1836 NextProtos: []string{"foo"},
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 ExpectFalseStart: true,
1840 },
1841 },
1842 flags: []string{
1843 "-false-start",
1844 "-handshake-never-done",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":DIGEST_CHECK_FAILED:",
1850 },
1851 {
1852 name: "NoFalseStart-NoALPN",
1853 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1856 Bugs: ProtocolBugs{
1857 ExpectFalseStart: true,
1858 AlertBeforeFalseStartTest: alertAccessDenied,
1859 },
1860 },
1861 flags: []string{
1862 "-false-start",
1863 },
1864 shimWritesFirst: true,
1865 shouldFail: true,
1866 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1867 expectedLocalError: "tls: peer did not false start: EOF",
1868 },
1869 {
1870 name: "NoFalseStart-NoAEAD",
1871 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001872 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 NextProtos: []string{"foo"},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1887 expectedLocalError: "tls: peer did not false start: EOF",
1888 },
1889 {
1890 name: "NoFalseStart-RSA",
1891 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001892 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001893 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1894 NextProtos: []string{"foo"},
1895 Bugs: ProtocolBugs{
1896 ExpectFalseStart: true,
1897 AlertBeforeFalseStartTest: alertAccessDenied,
1898 },
1899 },
1900 flags: []string{
1901 "-false-start",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1907 expectedLocalError: "tls: peer did not false start: EOF",
1908 },
1909 {
1910 name: "NoFalseStart-DHE_RSA",
1911 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001912 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001913 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1914 NextProtos: []string{"foo"},
1915 Bugs: ProtocolBugs{
1916 ExpectFalseStart: true,
1917 AlertBeforeFalseStartTest: alertAccessDenied,
1918 },
1919 },
1920 flags: []string{
1921 "-false-start",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shimWritesFirst: true,
1925 shouldFail: true,
1926 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1927 expectedLocalError: "tls: peer did not false start: EOF",
1928 },
1929 {
Adam Langley7c803a62015-06-15 15:35:05 -07001930 protocol: dtls,
1931 name: "SendSplitAlert-Sync",
1932 config: Config{
1933 Bugs: ProtocolBugs{
1934 SendSplitAlert: true,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "SendSplitAlert-Async",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 SendSplitAlert: true,
1944 },
1945 },
1946 flags: []string{"-async"},
1947 },
1948 {
1949 protocol: dtls,
1950 name: "PackDTLSHandshake",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 MaxHandshakeRecordLength: 2,
1954 PackHandshakeFragments: 20,
1955 PackHandshakeRecords: 200,
1956 },
1957 },
1958 },
1959 {
Adam Langley7c803a62015-06-15 15:35:05 -07001960 name: "SendEmptyRecords-Pass",
1961 sendEmptyRecords: 32,
1962 },
1963 {
1964 name: "SendEmptyRecords",
1965 sendEmptyRecords: 33,
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
1970 name: "SendEmptyRecords-Async",
1971 sendEmptyRecords: 33,
1972 flags: []string{"-async"},
1973 shouldFail: true,
1974 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 name: "SendWarningAlerts-Pass",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 4,
1982 },
1983 {
David Benjamine8e84b92016-08-03 15:39:47 -04001984 protocol: dtls,
1985 name: "SendWarningAlerts-DTLS-Pass",
1986 config: Config{
1987 MaxVersion: VersionTLS12,
1988 },
Adam Langley7c803a62015-06-15 15:35:05 -07001989 sendWarningAlerts: 4,
1990 },
1991 {
David Benjamine8e84b92016-08-03 15:39:47 -04001992 name: "SendWarningAlerts-TLS13",
1993 config: Config{
1994 MaxVersion: VersionTLS13,
1995 },
1996 sendWarningAlerts: 4,
1997 shouldFail: true,
1998 expectedError: ":BAD_ALERT:",
1999 expectedLocalError: "remote error: error decoding message",
2000 },
2001 {
2002 name: "SendWarningAlerts",
2003 config: Config{
2004 MaxVersion: VersionTLS12,
2005 },
Adam Langley7c803a62015-06-15 15:35:05 -07002006 sendWarningAlerts: 5,
2007 shouldFail: true,
2008 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2009 },
2010 {
David Benjamine8e84b92016-08-03 15:39:47 -04002011 name: "SendWarningAlerts-Async",
2012 config: Config{
2013 MaxVersion: VersionTLS12,
2014 },
Adam Langley7c803a62015-06-15 15:35:05 -07002015 sendWarningAlerts: 5,
2016 flags: []string{"-async"},
2017 shouldFail: true,
2018 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2019 },
David Benjaminba4594a2015-06-18 18:36:15 -04002020 {
Steven Valdez32635b82016-08-16 11:25:03 -04002021 name: "SendKeyUpdates",
2022 config: Config{
2023 MaxVersion: VersionTLS13,
2024 },
2025 sendKeyUpdates: 33,
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_KEY_UPDATES:",
2028 },
2029 {
David Benjaminba4594a2015-06-18 18:36:15 -04002030 name: "EmptySessionID",
2031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002032 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
David Benjamin30789da2015-08-29 22:56:45 -04002038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 {
David Benjaminfa214e42016-05-10 17:03:10 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
David Benjamindd6fed92015-10-23 17:41:12 -04002121 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
David Benjamin46662482016-08-17 00:51:00 -04002132 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002133 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002134 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002135 name: "BadHelloRequest-1",
2136 renegotiate: 1,
2137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002138 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002139 Bugs: ProtocolBugs{
2140 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2141 },
2142 },
2143 flags: []string{
2144 "-renegotiate-freely",
2145 "-expect-total-renegotiations", "1",
2146 },
2147 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002148 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002149 },
2150 {
2151 name: "BadHelloRequest-2",
2152 renegotiate: 1,
2153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002154 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002155 Bugs: ProtocolBugs{
2156 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2157 },
2158 },
2159 flags: []string{
2160 "-renegotiate-freely",
2161 "-expect-total-renegotiations", "1",
2162 },
2163 shouldFail: true,
2164 expectedError: ":BAD_HELLO_REQUEST:",
2165 },
David Benjaminef1b0092015-11-21 14:05:44 -05002166 {
2167 testType: serverTest,
2168 name: "SupportTicketsWithSessionID",
2169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002171 SessionTicketsDisabled: true,
2172 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002173 resumeConfig: &Config{
2174 MaxVersion: VersionTLS12,
2175 },
David Benjaminef1b0092015-11-21 14:05:44 -05002176 resumeSession: true,
2177 },
David Benjamin02edcd02016-07-27 17:40:37 -04002178 {
2179 protocol: dtls,
2180 name: "DTLS-SendExtraFinished",
2181 config: Config{
2182 Bugs: ProtocolBugs{
2183 SendExtraFinished: true,
2184 },
2185 },
2186 shouldFail: true,
2187 expectedError: ":UNEXPECTED_RECORD:",
2188 },
2189 {
2190 protocol: dtls,
2191 name: "DTLS-SendExtraFinished-Reordered",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 MaxHandshakeRecordLength: 2,
2195 ReorderHandshakeFragments: true,
2196 SendExtraFinished: true,
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":UNEXPECTED_RECORD:",
2201 },
David Benjamine97fb482016-07-29 09:23:07 -04002202 {
2203 testType: serverTest,
2204 name: "V2ClientHello-EmptyRecordPrefix",
2205 config: Config{
2206 // Choose a cipher suite that does not involve
2207 // elliptic curves, so no extensions are
2208 // involved.
2209 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002210 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002211 Bugs: ProtocolBugs{
2212 SendV2ClientHello: true,
2213 },
2214 },
2215 sendPrefix: string([]byte{
2216 byte(recordTypeHandshake),
2217 3, 1, // version
2218 0, 0, // length
2219 }),
2220 // A no-op empty record may not be sent before V2ClientHello.
2221 shouldFail: true,
2222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
2224 {
2225 testType: serverTest,
2226 name: "V2ClientHello-WarningAlertPrefix",
2227 config: Config{
2228 // Choose a cipher suite that does not involve
2229 // elliptic curves, so no extensions are
2230 // involved.
2231 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002232 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002233 Bugs: ProtocolBugs{
2234 SendV2ClientHello: true,
2235 },
2236 },
2237 sendPrefix: string([]byte{
2238 byte(recordTypeAlert),
2239 3, 1, // version
2240 0, 2, // length
2241 alertLevelWarning, byte(alertDecompressionFailure),
2242 }),
2243 // A no-op warning alert may not be sent before V2ClientHello.
2244 shouldFail: true,
2245 expectedError: ":WRONG_VERSION_NUMBER:",
2246 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002247 {
2248 testType: clientTest,
2249 name: "KeyUpdate",
2250 config: Config{
2251 MaxVersion: VersionTLS13,
2252 Bugs: ProtocolBugs{
2253 SendKeyUpdateBeforeEveryAppDataRecord: true,
2254 },
2255 },
2256 },
David Benjaminabe94e32016-09-04 14:18:58 -04002257 {
2258 name: "SendSNIWarningAlert",
2259 config: Config{
2260 MaxVersion: VersionTLS12,
2261 Bugs: ProtocolBugs{
2262 SendSNIWarningAlert: true,
2263 },
2264 },
2265 },
David Benjaminc241d792016-09-09 10:34:20 -04002266 {
2267 testType: serverTest,
2268 name: "ExtraCompressionMethods-TLS12",
2269 config: Config{
2270 MaxVersion: VersionTLS12,
2271 Bugs: ProtocolBugs{
2272 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2273 },
2274 },
2275 },
2276 {
2277 testType: serverTest,
2278 name: "ExtraCompressionMethods-TLS13",
2279 config: Config{
2280 MaxVersion: VersionTLS13,
2281 Bugs: ProtocolBugs{
2282 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2283 },
2284 },
2285 shouldFail: true,
2286 expectedError: ":INVALID_COMPRESSION_LIST:",
2287 expectedLocalError: "remote error: illegal parameter",
2288 },
2289 {
2290 testType: serverTest,
2291 name: "NoNullCompression-TLS12",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2296 },
2297 },
2298 shouldFail: true,
2299 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2300 expectedLocalError: "remote error: illegal parameter",
2301 },
2302 {
2303 testType: serverTest,
2304 name: "NoNullCompression-TLS13",
2305 config: Config{
2306 MaxVersion: VersionTLS13,
2307 Bugs: ProtocolBugs{
2308 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2309 },
2310 },
2311 shouldFail: true,
2312 expectedError: ":INVALID_COMPRESSION_LIST:",
2313 expectedLocalError: "remote error: illegal parameter",
2314 },
Adam Langley7c803a62015-06-15 15:35:05 -07002315 }
Adam Langley7c803a62015-06-15 15:35:05 -07002316 testCases = append(testCases, basicTests...)
2317}
2318
Adam Langley95c29f32014-06-20 12:00:00 -07002319func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002320 const bogusCipher = 0xfe00
2321
Adam Langley95c29f32014-06-20 12:00:00 -07002322 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002323 const psk = "12345"
2324 const pskIdentity = "luggage combo"
2325
Adam Langley95c29f32014-06-20 12:00:00 -07002326 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002327 var certFile string
2328 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002329 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002330 cert = ecdsaP256Certificate
2331 certFile = ecdsaP256CertificateFile
2332 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002333 } else {
David Benjamin33863262016-07-08 17:20:12 -07002334 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002335 certFile = rsaCertificateFile
2336 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002337 }
2338
David Benjamin48cae082014-10-27 01:06:24 -04002339 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002340 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002341 flags = append(flags,
2342 "-psk", psk,
2343 "-psk-identity", pskIdentity)
2344 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002345 if hasComponent(suite.name, "NULL") {
2346 // NULL ciphers must be explicitly enabled.
2347 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2348 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002349 if hasComponent(suite.name, "CECPQ1") {
2350 // CECPQ1 ciphers must be explicitly enabled.
2351 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2352 }
David Benjamin881f1962016-08-10 18:29:12 -04002353 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2354 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2355 // for now.
2356 flags = append(flags, "-cipher", suite.name)
2357 }
David Benjamin48cae082014-10-27 01:06:24 -04002358
Adam Langley95c29f32014-06-20 12:00:00 -07002359 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002360 for _, protocol := range []protocol{tls, dtls} {
2361 var prefix string
2362 if protocol == dtls {
2363 if !ver.hasDTLS {
2364 continue
2365 }
2366 prefix = "D"
2367 }
Adam Langley95c29f32014-06-20 12:00:00 -07002368
David Benjamin0407e762016-06-17 16:41:18 -04002369 var shouldServerFail, shouldClientFail bool
2370 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2371 // BoringSSL clients accept ECDHE on SSLv3, but
2372 // a BoringSSL server will never select it
2373 // because the extension is missing.
2374 shouldServerFail = true
2375 }
2376 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2377 shouldClientFail = true
2378 shouldServerFail = true
2379 }
David Benjamin54c217c2016-07-13 12:35:25 -04002380 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002381 shouldClientFail = true
2382 shouldServerFail = true
2383 }
David Benjamin0407e762016-06-17 16:41:18 -04002384 if !isDTLSCipher(suite.name) && protocol == dtls {
2385 shouldClientFail = true
2386 shouldServerFail = true
2387 }
David Benjamin4298d772015-12-19 00:18:25 -05002388
David Benjamin0407e762016-06-17 16:41:18 -04002389 var expectedServerError, expectedClientError string
2390 if shouldServerFail {
2391 expectedServerError = ":NO_SHARED_CIPHER:"
2392 }
2393 if shouldClientFail {
2394 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2395 }
David Benjamin025b3d32014-07-01 19:53:04 -04002396
David Benjamin6fd297b2014-08-11 18:43:38 -04002397 testCases = append(testCases, testCase{
2398 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002399 protocol: protocol,
2400
2401 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002402 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002403 MinVersion: ver.version,
2404 MaxVersion: ver.version,
2405 CipherSuites: []uint16{suite.id},
2406 Certificates: []Certificate{cert},
2407 PreSharedKey: []byte(psk),
2408 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002409 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002410 EnableAllCiphers: shouldServerFail,
2411 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002412 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002413 },
2414 certFile: certFile,
2415 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002416 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002417 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002418 shouldFail: shouldServerFail,
2419 expectedError: expectedServerError,
2420 })
2421
2422 testCases = append(testCases, testCase{
2423 testType: clientTest,
2424 protocol: protocol,
2425 name: prefix + ver.name + "-" + suite.name + "-client",
2426 config: Config{
2427 MinVersion: ver.version,
2428 MaxVersion: ver.version,
2429 CipherSuites: []uint16{suite.id},
2430 Certificates: []Certificate{cert},
2431 PreSharedKey: []byte(psk),
2432 PreSharedKeyIdentity: pskIdentity,
2433 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002434 EnableAllCiphers: shouldClientFail,
2435 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002436 },
2437 },
2438 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002439 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002440 shouldFail: shouldClientFail,
2441 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002442 })
David Benjamin2c99d282015-09-01 10:23:00 -04002443
Nick Harper1fd39d82016-06-14 18:14:35 -07002444 if !shouldClientFail {
2445 // Ensure the maximum record size is accepted.
2446 testCases = append(testCases, testCase{
2447 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2448 config: Config{
2449 MinVersion: ver.version,
2450 MaxVersion: ver.version,
2451 CipherSuites: []uint16{suite.id},
2452 Certificates: []Certificate{cert},
2453 PreSharedKey: []byte(psk),
2454 PreSharedKeyIdentity: pskIdentity,
2455 },
2456 flags: flags,
2457 messageLen: maxPlaintext,
2458 })
2459 }
2460 }
David Benjamin2c99d282015-09-01 10:23:00 -04002461 }
Adam Langley95c29f32014-06-20 12:00:00 -07002462 }
Adam Langleya7997f12015-05-14 17:38:50 -07002463
2464 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002465 name: "NoSharedCipher",
2466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002467 MaxVersion: VersionTLS12,
2468 CipherSuites: []uint16{},
2469 },
2470 shouldFail: true,
2471 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2472 })
2473
2474 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002475 name: "NoSharedCipher-TLS13",
2476 config: Config{
2477 MaxVersion: VersionTLS13,
2478 CipherSuites: []uint16{},
2479 },
2480 shouldFail: true,
2481 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2482 })
2483
2484 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002485 name: "UnsupportedCipherSuite",
2486 config: Config{
2487 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002488 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002489 Bugs: ProtocolBugs{
2490 IgnorePeerCipherPreferences: true,
2491 },
2492 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002493 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002494 shouldFail: true,
2495 expectedError: ":WRONG_CIPHER_RETURNED:",
2496 })
2497
2498 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002499 name: "ServerHelloBogusCipher",
2500 config: Config{
2501 MaxVersion: VersionTLS12,
2502 Bugs: ProtocolBugs{
2503 SendCipherSuite: bogusCipher,
2504 },
2505 },
2506 shouldFail: true,
2507 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2508 })
2509 testCases = append(testCases, testCase{
2510 name: "ServerHelloBogusCipher-TLS13",
2511 config: Config{
2512 MaxVersion: VersionTLS13,
2513 Bugs: ProtocolBugs{
2514 SendCipherSuite: bogusCipher,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2519 })
2520
2521 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002522 name: "WeakDH",
2523 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002524 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002525 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2526 Bugs: ProtocolBugs{
2527 // This is a 1023-bit prime number, generated
2528 // with:
2529 // openssl gendh 1023 | openssl asn1parse -i
2530 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2531 },
2532 },
2533 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002534 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002535 })
Adam Langleycef75832015-09-03 14:51:12 -07002536
David Benjamincd24a392015-11-11 13:23:05 -08002537 testCases = append(testCases, testCase{
2538 name: "SillyDH",
2539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002540 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002541 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2542 Bugs: ProtocolBugs{
2543 // This is a 4097-bit prime number, generated
2544 // with:
2545 // openssl gendh 4097 | openssl asn1parse -i
2546 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2547 },
2548 },
2549 shouldFail: true,
2550 expectedError: ":DH_P_TOO_LONG:",
2551 })
2552
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002553 // This test ensures that Diffie-Hellman public values are padded with
2554 // zeros so that they're the same length as the prime. This is to avoid
2555 // hitting a bug in yaSSL.
2556 testCases = append(testCases, testCase{
2557 testType: serverTest,
2558 name: "DHPublicValuePadded",
2559 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002560 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002561 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2562 Bugs: ProtocolBugs{
2563 RequireDHPublicValueLen: (1025 + 7) / 8,
2564 },
2565 },
2566 flags: []string{"-use-sparse-dh-prime"},
2567 })
David Benjamincd24a392015-11-11 13:23:05 -08002568
David Benjamin241ae832016-01-15 03:04:54 -05002569 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002570 testCases = append(testCases, testCase{
2571 testType: serverTest,
2572 name: "UnknownCipher",
2573 config: Config{
2574 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2575 },
2576 })
2577
David Benjamin78679342016-09-16 19:42:05 -04002578 // Test empty ECDHE_PSK identity hints work as expected.
2579 testCases = append(testCases, testCase{
2580 name: "EmptyECDHEPSKHint",
2581 config: Config{
2582 MaxVersion: VersionTLS12,
2583 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2584 PreSharedKey: []byte("secret"),
2585 },
2586 flags: []string{"-psk", "secret"},
2587 })
2588
2589 // Test empty PSK identity hints work as expected, even if an explicit
2590 // ServerKeyExchange is sent.
2591 testCases = append(testCases, testCase{
2592 name: "ExplicitEmptyPSKHint",
2593 config: Config{
2594 MaxVersion: VersionTLS12,
2595 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2596 PreSharedKey: []byte("secret"),
2597 Bugs: ProtocolBugs{
2598 AlwaysSendPreSharedKeyIdentityHint: true,
2599 },
2600 },
2601 flags: []string{"-psk", "secret"},
2602 })
2603
Adam Langleycef75832015-09-03 14:51:12 -07002604 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2605 // 1.1 specific cipher suite settings. A server is setup with the given
2606 // cipher lists and then a connection is made for each member of
2607 // expectations. The cipher suite that the server selects must match
2608 // the specified one.
2609 var versionSpecificCiphersTest = []struct {
2610 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2611 // expectations is a map from TLS version to cipher suite id.
2612 expectations map[uint16]uint16
2613 }{
2614 {
2615 // Test that the null case (where no version-specific ciphers are set)
2616 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002617 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2618 "", // no ciphers specifically for TLS ≥ 1.0
2619 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002620 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002621 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2622 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2623 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2624 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002625 },
2626 },
2627 {
2628 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2629 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002630 "DES-CBC3-SHA:AES128-SHA", // default
2631 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2632 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002633 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002635 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2636 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2637 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2638 },
2639 },
2640 {
2641 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2642 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002643 "DES-CBC3-SHA:AES128-SHA", // default
2644 "", // no ciphers specifically for TLS ≥ 1.0
2645 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002646 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2648 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002649 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2650 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2651 },
2652 },
2653 {
2654 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2655 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002656 "DES-CBC3-SHA:AES128-SHA", // default
2657 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2658 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002659 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002661 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2662 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2663 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2664 },
2665 },
2666 }
2667
2668 for i, test := range versionSpecificCiphersTest {
2669 for version, expectedCipherSuite := range test.expectations {
2670 flags := []string{"-cipher", test.ciphersDefault}
2671 if len(test.ciphersTLS10) > 0 {
2672 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2673 }
2674 if len(test.ciphersTLS11) > 0 {
2675 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2676 }
2677
2678 testCases = append(testCases, testCase{
2679 testType: serverTest,
2680 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2681 config: Config{
2682 MaxVersion: version,
2683 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002684 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 -07002685 },
2686 flags: flags,
2687 expectedCipher: expectedCipherSuite,
2688 })
2689 }
2690 }
Adam Langley95c29f32014-06-20 12:00:00 -07002691}
2692
2693func addBadECDSASignatureTests() {
2694 for badR := BadValue(1); badR < NumBadValues; badR++ {
2695 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002696 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002697 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2698 config: Config{
2699 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002700 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002701 Bugs: ProtocolBugs{
2702 BadECDSAR: badR,
2703 BadECDSAS: badS,
2704 },
2705 },
2706 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002707 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002708 })
2709 }
2710 }
2711}
2712
Adam Langley80842bd2014-06-20 12:00:00 -07002713func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002714 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002715 name: "MaxCBCPadding",
2716 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002717 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002718 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2719 Bugs: ProtocolBugs{
2720 MaxPadding: true,
2721 },
2722 },
2723 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2724 })
David Benjamin025b3d32014-07-01 19:53:04 -04002725 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002726 name: "BadCBCPadding",
2727 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002728 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2730 Bugs: ProtocolBugs{
2731 PaddingFirstByteBad: true,
2732 },
2733 },
2734 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002735 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002736 })
2737 // OpenSSL previously had an issue where the first byte of padding in
2738 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002739 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002740 name: "BadCBCPadding255",
2741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002742 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2744 Bugs: ProtocolBugs{
2745 MaxPadding: true,
2746 PaddingFirstByteBadIf255: true,
2747 },
2748 },
2749 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2750 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002751 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002752 })
2753}
2754
Kenny Root7fdeaf12014-08-05 15:23:37 -07002755func addCBCSplittingTests() {
2756 testCases = append(testCases, testCase{
2757 name: "CBCRecordSplitting",
2758 config: Config{
2759 MaxVersion: VersionTLS10,
2760 MinVersion: VersionTLS10,
2761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2762 },
David Benjaminac8302a2015-09-01 17:18:15 -04002763 messageLen: -1, // read until EOF
2764 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002765 flags: []string{
2766 "-async",
2767 "-write-different-record-sizes",
2768 "-cbc-record-splitting",
2769 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002770 })
2771 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772 name: "CBCRecordSplittingPartialWrite",
2773 config: Config{
2774 MaxVersion: VersionTLS10,
2775 MinVersion: VersionTLS10,
2776 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2777 },
2778 messageLen: -1, // read until EOF
2779 flags: []string{
2780 "-async",
2781 "-write-different-record-sizes",
2782 "-cbc-record-splitting",
2783 "-partial-write",
2784 },
2785 })
2786}
2787
David Benjamin636293b2014-07-08 17:59:18 -04002788func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002789 // Add a dummy cert pool to stress certificate authority parsing.
2790 // TODO(davidben): Add tests that those values parse out correctly.
2791 certPool := x509.NewCertPool()
2792 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2793 if err != nil {
2794 panic(err)
2795 }
2796 certPool.AddCert(cert)
2797
David Benjamin636293b2014-07-08 17:59:18 -04002798 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002799 testCases = append(testCases, testCase{
2800 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002801 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002802 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 ClientAuth: RequireAnyClientCert,
2806 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002807 },
2808 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002809 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2810 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002811 },
2812 })
2813 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002814 testType: serverTest,
2815 name: ver.name + "-Server-ClientAuth-RSA",
2816 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002817 MinVersion: ver.version,
2818 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002819 Certificates: []Certificate{rsaCertificate},
2820 },
2821 flags: []string{"-require-any-client-certificate"},
2822 })
David Benjamine098ec22014-08-27 23:13:20 -04002823 if ver.version != VersionSSL30 {
2824 testCases = append(testCases, testCase{
2825 testType: serverTest,
2826 name: ver.name + "-Server-ClientAuth-ECDSA",
2827 config: Config{
2828 MinVersion: ver.version,
2829 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002830 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002831 },
2832 flags: []string{"-require-any-client-certificate"},
2833 })
2834 testCases = append(testCases, testCase{
2835 testType: clientTest,
2836 name: ver.name + "-Client-ClientAuth-ECDSA",
2837 config: Config{
2838 MinVersion: ver.version,
2839 MaxVersion: ver.version,
2840 ClientAuth: RequireAnyClientCert,
2841 ClientCAs: certPool,
2842 },
2843 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002846 },
2847 })
2848 }
Adam Langley37646832016-08-01 16:16:46 -07002849
2850 testCases = append(testCases, testCase{
2851 name: "NoClientCertificate-" + ver.name,
2852 config: Config{
2853 MinVersion: ver.version,
2854 MaxVersion: ver.version,
2855 ClientAuth: RequireAnyClientCert,
2856 },
2857 shouldFail: true,
2858 expectedLocalError: "client didn't provide a certificate",
2859 })
2860
2861 testCases = append(testCases, testCase{
2862 // Even if not configured to expect a certificate, OpenSSL will
2863 // return X509_V_OK as the verify_result.
2864 testType: serverTest,
2865 name: "NoClientCertificateRequested-Server-" + ver.name,
2866 config: Config{
2867 MinVersion: ver.version,
2868 MaxVersion: ver.version,
2869 },
2870 flags: []string{
2871 "-expect-verify-result",
2872 },
2873 // TODO(davidben): Switch this to true when TLS 1.3
2874 // supports session resumption.
2875 resumeSession: ver.version < VersionTLS13,
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // If a client certificate is not provided, OpenSSL will still
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificate-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 "-verify-peer",
2890 },
2891 // TODO(davidben): Switch this to true when TLS 1.3
2892 // supports session resumption.
2893 resumeSession: ver.version < VersionTLS13,
2894 })
2895
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: "RequireAnyClientCertificate-" + ver.name,
2899 config: Config{
2900 MinVersion: ver.version,
2901 MaxVersion: ver.version,
2902 },
2903 flags: []string{"-require-any-client-certificate"},
2904 shouldFail: true,
2905 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2906 })
2907
2908 if ver.version != VersionSSL30 {
2909 testCases = append(testCases, testCase{
2910 testType: serverTest,
2911 name: "SkipClientCertificate-" + ver.name,
2912 config: Config{
2913 MinVersion: ver.version,
2914 MaxVersion: ver.version,
2915 Bugs: ProtocolBugs{
2916 SkipClientCertificate: true,
2917 },
2918 },
2919 // Setting SSL_VERIFY_PEER allows anonymous clients.
2920 flags: []string{"-verify-peer"},
2921 shouldFail: true,
2922 expectedError: ":UNEXPECTED_MESSAGE:",
2923 })
2924 }
David Benjamin636293b2014-07-08 17:59:18 -04002925 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002926
David Benjaminc032dfa2016-05-12 14:54:57 -04002927 // Client auth is only legal in certificate-based ciphers.
2928 testCases = append(testCases, testCase{
2929 testType: clientTest,
2930 name: "ClientAuth-PSK",
2931 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002932 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002933 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2934 PreSharedKey: []byte("secret"),
2935 ClientAuth: RequireAnyClientCert,
2936 },
2937 flags: []string{
2938 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2939 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2940 "-psk", "secret",
2941 },
2942 shouldFail: true,
2943 expectedError: ":UNEXPECTED_MESSAGE:",
2944 })
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-ECDHE_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_ECDHE_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 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002962
2963 // Regression test for a bug where the client CA list, if explicitly
2964 // set to NULL, was mis-encoded.
2965 testCases = append(testCases, testCase{
2966 testType: serverTest,
2967 name: "Null-Client-CA-List",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 Certificates: []Certificate{rsaCertificate},
2971 },
2972 flags: []string{
2973 "-require-any-client-certificate",
2974 "-use-null-client-ca-list",
2975 },
2976 })
David Benjamin636293b2014-07-08 17:59:18 -04002977}
2978
Adam Langley75712922014-10-10 16:23:43 -07002979func addExtendedMasterSecretTests() {
2980 const expectEMSFlag = "-expect-extended-master-secret"
2981
2982 for _, with := range []bool{false, true} {
2983 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002984 if with {
2985 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002986 }
2987
2988 for _, isClient := range []bool{false, true} {
2989 suffix := "-Server"
2990 testType := serverTest
2991 if isClient {
2992 suffix = "-Client"
2993 testType = clientTest
2994 }
2995
2996 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002997 // In TLS 1.3, the extension is irrelevant and
2998 // always reports as enabled.
2999 var flags []string
3000 if with || ver.version >= VersionTLS13 {
3001 flags = []string{expectEMSFlag}
3002 }
3003
Adam Langley75712922014-10-10 16:23:43 -07003004 test := testCase{
3005 testType: testType,
3006 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3007 config: Config{
3008 MinVersion: ver.version,
3009 MaxVersion: ver.version,
3010 Bugs: ProtocolBugs{
3011 NoExtendedMasterSecret: !with,
3012 RequireExtendedMasterSecret: with,
3013 },
3014 },
David Benjamin48cae082014-10-27 01:06:24 -04003015 flags: flags,
3016 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003017 }
3018 if test.shouldFail {
3019 test.expectedLocalError = "extended master secret required but not supported by peer"
3020 }
3021 testCases = append(testCases, test)
3022 }
3023 }
3024 }
3025
Adam Langleyba5934b2015-06-02 10:50:35 -07003026 for _, isClient := range []bool{false, true} {
3027 for _, supportedInFirstConnection := range []bool{false, true} {
3028 for _, supportedInResumeConnection := range []bool{false, true} {
3029 boolToWord := func(b bool) string {
3030 if b {
3031 return "Yes"
3032 }
3033 return "No"
3034 }
3035 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3036 if isClient {
3037 suffix += "Client"
3038 } else {
3039 suffix += "Server"
3040 }
3041
3042 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003043 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003044 Bugs: ProtocolBugs{
3045 RequireExtendedMasterSecret: true,
3046 },
3047 }
3048
3049 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003051 Bugs: ProtocolBugs{
3052 NoExtendedMasterSecret: true,
3053 },
3054 }
3055
3056 test := testCase{
3057 name: "ExtendedMasterSecret-" + suffix,
3058 resumeSession: true,
3059 }
3060
3061 if !isClient {
3062 test.testType = serverTest
3063 }
3064
3065 if supportedInFirstConnection {
3066 test.config = supportedConfig
3067 } else {
3068 test.config = noSupportConfig
3069 }
3070
3071 if supportedInResumeConnection {
3072 test.resumeConfig = &supportedConfig
3073 } else {
3074 test.resumeConfig = &noSupportConfig
3075 }
3076
3077 switch suffix {
3078 case "YesToYes-Client", "YesToYes-Server":
3079 // When a session is resumed, it should
3080 // still be aware that its master
3081 // secret was generated via EMS and
3082 // thus it's safe to use tls-unique.
3083 test.flags = []string{expectEMSFlag}
3084 case "NoToYes-Server":
3085 // If an original connection did not
3086 // contain EMS, but a resumption
3087 // handshake does, then a server should
3088 // not resume the session.
3089 test.expectResumeRejected = true
3090 case "YesToNo-Server":
3091 // Resuming an EMS session without the
3092 // EMS extension should cause the
3093 // server to abort the connection.
3094 test.shouldFail = true
3095 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3096 case "NoToYes-Client":
3097 // A client should abort a connection
3098 // where the server resumed a non-EMS
3099 // session but echoed the EMS
3100 // extension.
3101 test.shouldFail = true
3102 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3103 case "YesToNo-Client":
3104 // A client should abort a connection
3105 // where the server didn't echo EMS
3106 // when the session used it.
3107 test.shouldFail = true
3108 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3109 }
3110
3111 testCases = append(testCases, test)
3112 }
3113 }
3114 }
David Benjamin163c9562016-08-29 23:14:17 -04003115
3116 // Switching EMS on renegotiation is forbidden.
3117 testCases = append(testCases, testCase{
3118 name: "ExtendedMasterSecret-Renego-NoEMS",
3119 config: Config{
3120 MaxVersion: VersionTLS12,
3121 Bugs: ProtocolBugs{
3122 NoExtendedMasterSecret: true,
3123 NoExtendedMasterSecretOnRenegotiation: true,
3124 },
3125 },
3126 renegotiate: 1,
3127 flags: []string{
3128 "-renegotiate-freely",
3129 "-expect-total-renegotiations", "1",
3130 },
3131 })
3132
3133 testCases = append(testCases, testCase{
3134 name: "ExtendedMasterSecret-Renego-Upgrade",
3135 config: Config{
3136 MaxVersion: VersionTLS12,
3137 Bugs: ProtocolBugs{
3138 NoExtendedMasterSecret: true,
3139 },
3140 },
3141 renegotiate: 1,
3142 flags: []string{
3143 "-renegotiate-freely",
3144 "-expect-total-renegotiations", "1",
3145 },
3146 shouldFail: true,
3147 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Downgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecretOnRenegotiation: 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 })
Adam Langley75712922014-10-10 16:23:43 -07003166}
3167
David Benjamin582ba042016-07-07 12:33:25 -07003168type stateMachineTestConfig struct {
3169 protocol protocol
3170 async bool
3171 splitHandshake, packHandshakeFlight bool
3172}
3173
David Benjamin43ec06f2014-08-05 02:28:57 -04003174// Adds tests that try to cover the range of the handshake state machine, under
3175// various conditions. Some of these are redundant with other tests, but they
3176// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003177func addAllStateMachineCoverageTests() {
3178 for _, async := range []bool{false, true} {
3179 for _, protocol := range []protocol{tls, dtls} {
3180 addStateMachineCoverageTests(stateMachineTestConfig{
3181 protocol: protocol,
3182 async: async,
3183 })
3184 addStateMachineCoverageTests(stateMachineTestConfig{
3185 protocol: protocol,
3186 async: async,
3187 splitHandshake: true,
3188 })
3189 if protocol == tls {
3190 addStateMachineCoverageTests(stateMachineTestConfig{
3191 protocol: protocol,
3192 async: async,
3193 packHandshakeFlight: true,
3194 })
3195 }
3196 }
3197 }
3198}
3199
3200func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003201 var tests []testCase
3202
3203 // Basic handshake, with resumption. Client and server,
3204 // session ID and session ticket.
3205 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 name: "Basic-Client",
3207 config: Config{
3208 MaxVersion: VersionTLS12,
3209 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003211 // Ensure session tickets are used, not session IDs.
3212 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 })
3214 tests = append(tests, testCase{
3215 name: "Basic-Client-RenewTicket",
3216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003217 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 Bugs: ProtocolBugs{
3219 RenewTicketOnResume: true,
3220 },
3221 },
David Benjamin46662482016-08-17 00:51:00 -04003222 flags: []string{"-expect-ticket-renewal"},
3223 resumeSession: true,
3224 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 })
3226 tests = append(tests, testCase{
3227 name: "Basic-Client-NoTicket",
3228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 SessionTicketsDisabled: true,
3231 },
3232 resumeSession: true,
3233 })
3234 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003235 name: "Basic-Client-Implicit",
3236 config: Config{
3237 MaxVersion: VersionTLS12,
3238 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003239 flags: []string{"-implicit-handshake"},
3240 resumeSession: true,
3241 })
3242 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003243 testType: serverTest,
3244 name: "Basic-Server",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003247 Bugs: ProtocolBugs{
3248 RequireSessionTickets: true,
3249 },
3250 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003251 resumeSession: true,
3252 })
3253 tests = append(tests, testCase{
3254 testType: serverTest,
3255 name: "Basic-Server-NoTickets",
3256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003257 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 SessionTicketsDisabled: true,
3259 },
3260 resumeSession: true,
3261 })
3262 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 testType: serverTest,
3264 name: "Basic-Server-Implicit",
3265 config: Config{
3266 MaxVersion: VersionTLS12,
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 flags: []string{"-implicit-handshake"},
3269 resumeSession: true,
3270 })
3271 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003272 testType: serverTest,
3273 name: "Basic-Server-EarlyCallback",
3274 config: Config{
3275 MaxVersion: VersionTLS12,
3276 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 flags: []string{"-use-early-callback"},
3278 resumeSession: true,
3279 })
3280
Steven Valdez143e8b32016-07-11 13:19:03 -04003281 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003282 if config.protocol == tls {
3283 tests = append(tests, testCase{
3284 name: "TLS13-1RTT-Client",
3285 config: Config{
3286 MaxVersion: VersionTLS13,
3287 MinVersion: VersionTLS13,
3288 },
David Benjamin46662482016-08-17 00:51:00 -04003289 resumeSession: true,
3290 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003291 })
3292
3293 tests = append(tests, testCase{
3294 testType: serverTest,
3295 name: "TLS13-1RTT-Server",
3296 config: Config{
3297 MaxVersion: VersionTLS13,
3298 MinVersion: VersionTLS13,
3299 },
David Benjamin46662482016-08-17 00:51:00 -04003300 resumeSession: true,
3301 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003302 })
3303
3304 tests = append(tests, testCase{
3305 name: "TLS13-HelloRetryRequest-Client",
3306 config: Config{
3307 MaxVersion: VersionTLS13,
3308 MinVersion: VersionTLS13,
3309 // P-384 requires a HelloRetryRequest against
3310 // BoringSSL's default configuration. Assert
3311 // that we do indeed test this with
3312 // ExpectMissingKeyShare.
3313 CurvePreferences: []CurveID{CurveP384},
3314 Bugs: ProtocolBugs{
3315 ExpectMissingKeyShare: true,
3316 },
3317 },
3318 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3319 resumeSession: true,
3320 })
3321
3322 tests = append(tests, testCase{
3323 testType: serverTest,
3324 name: "TLS13-HelloRetryRequest-Server",
3325 config: Config{
3326 MaxVersion: VersionTLS13,
3327 MinVersion: VersionTLS13,
3328 // Require a HelloRetryRequest for every curve.
3329 DefaultCurves: []CurveID{},
3330 },
3331 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3332 resumeSession: true,
3333 })
3334 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003335
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 // TLS client auth.
3337 tests = append(tests, testCase{
3338 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003339 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003341 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003342 ClientAuth: RequestClientCert,
3343 },
3344 })
3345 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003346 testType: serverTest,
3347 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 config: Config{
3349 MaxVersion: VersionTLS12,
3350 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003351 // Setting SSL_VERIFY_PEER allows anonymous clients.
3352 flags: []string{"-verify-peer"},
3353 })
David Benjamin582ba042016-07-07 12:33:25 -07003354 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003355 tests = append(tests, testCase{
3356 testType: clientTest,
3357 name: "ClientAuth-NoCertificate-Client-SSL3",
3358 config: Config{
3359 MaxVersion: VersionSSL30,
3360 ClientAuth: RequestClientCert,
3361 },
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "ClientAuth-NoCertificate-Server-SSL3",
3366 config: Config{
3367 MaxVersion: VersionSSL30,
3368 },
3369 // Setting SSL_VERIFY_PEER allows anonymous clients.
3370 flags: []string{"-verify-peer"},
3371 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-TLS13",
3375 config: Config{
3376 MaxVersion: VersionTLS13,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-TLS13",
3383 config: Config{
3384 MaxVersion: VersionTLS13,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003389 }
3390 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003391 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003392 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003394 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 ClientAuth: RequireAnyClientCert,
3396 },
3397 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 },
3401 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003402 tests = append(tests, testCase{
3403 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003404 name: "ClientAuth-RSA-Client-TLS13",
3405 config: Config{
3406 MaxVersion: VersionTLS13,
3407 ClientAuth: RequireAnyClientCert,
3408 },
3409 flags: []string{
3410 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3411 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3412 },
3413 })
3414 tests = append(tests, testCase{
3415 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003416 name: "ClientAuth-ECDSA-Client",
3417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003418 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 ClientAuth: RequireAnyClientCert,
3420 },
3421 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003424 },
3425 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003426 tests = append(tests, testCase{
3427 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003428 name: "ClientAuth-ECDSA-Client-TLS13",
3429 config: Config{
3430 MaxVersion: VersionTLS13,
3431 ClientAuth: RequireAnyClientCert,
3432 },
3433 flags: []string{
3434 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3435 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3436 },
3437 })
3438 tests = append(tests, testCase{
3439 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 name: "ClientAuth-NoCertificate-OldCallback",
3441 config: Config{
3442 MaxVersion: VersionTLS12,
3443 ClientAuth: RequestClientCert,
3444 },
3445 flags: []string{"-use-old-client-cert-callback"},
3446 })
3447 tests = append(tests, testCase{
3448 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003449 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3450 config: Config{
3451 MaxVersion: VersionTLS13,
3452 ClientAuth: RequestClientCert,
3453 },
3454 flags: []string{"-use-old-client-cert-callback"},
3455 })
3456 tests = append(tests, testCase{
3457 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003458 name: "ClientAuth-OldCallback",
3459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003460 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003461 ClientAuth: RequireAnyClientCert,
3462 },
3463 flags: []string{
3464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3466 "-use-old-client-cert-callback",
3467 },
3468 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003469 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003470 testType: clientTest,
3471 name: "ClientAuth-OldCallback-TLS13",
3472 config: Config{
3473 MaxVersion: VersionTLS13,
3474 ClientAuth: RequireAnyClientCert,
3475 },
3476 flags: []string{
3477 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3478 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3479 "-use-old-client-cert-callback",
3480 },
3481 })
3482 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 testType: serverTest,
3484 name: "ClientAuth-Server",
3485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 Certificates: []Certificate{rsaCertificate},
3488 },
3489 flags: []string{"-require-any-client-certificate"},
3490 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "ClientAuth-Server-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 Certificates: []Certificate{rsaCertificate},
3497 },
3498 flags: []string{"-require-any-client-certificate"},
3499 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003500
David Benjamin4c3ddf72016-06-29 18:13:53 -04003501 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 tests = append(tests, testCase{
3503 testType: serverTest,
3504 name: "Basic-Server-RSA",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3508 },
3509 flags: []string{
3510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3512 },
3513 })
3514 tests = append(tests, testCase{
3515 testType: serverTest,
3516 name: "Basic-Server-ECDHE-RSA",
3517 config: Config{
3518 MaxVersion: VersionTLS12,
3519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3520 },
3521 flags: []string{
3522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3524 },
3525 })
3526 tests = append(tests, testCase{
3527 testType: serverTest,
3528 name: "Basic-Server-ECDHE-ECDSA",
3529 config: Config{
3530 MaxVersion: VersionTLS12,
3531 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3532 },
3533 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003534 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3535 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 },
3537 })
3538
David Benjamin760b1dd2015-05-15 23:33:48 -04003539 // No session ticket support; server doesn't send NewSessionTicket.
3540 tests = append(tests, testCase{
3541 name: "SessionTicketsDisabled-Client",
3542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003543 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 SessionTicketsDisabled: true,
3545 },
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "SessionTicketsDisabled-Server",
3550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003552 SessionTicketsDisabled: true,
3553 },
3554 })
3555
3556 // Skip ServerKeyExchange in PSK key exchange if there's no
3557 // identity hint.
3558 tests = append(tests, testCase{
3559 name: "EmptyPSKHint-Client",
3560 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003561 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3563 PreSharedKey: []byte("secret"),
3564 },
3565 flags: []string{"-psk", "secret"},
3566 })
3567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "EmptyPSKHint-Server",
3570 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003571 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003572 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3573 PreSharedKey: []byte("secret"),
3574 },
3575 flags: []string{"-psk", "secret"},
3576 })
3577
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003579 tests = append(tests, testCase{
3580 testType: clientTest,
3581 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003585 flags: []string{
3586 "-enable-ocsp-stapling",
3587 "-expect-ocsp-response",
3588 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003589 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003592 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003593 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003594 testType: serverTest,
3595 name: "OCSPStapling-Server",
3596 config: Config{
3597 MaxVersion: VersionTLS12,
3598 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003599 expectedOCSPResponse: testOCSPResponse,
3600 flags: []string{
3601 "-ocsp-response",
3602 base64.StdEncoding.EncodeToString(testOCSPResponse),
3603 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003604 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003605 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003606 tests = append(tests, testCase{
3607 testType: clientTest,
3608 name: "OCSPStapling-Client-TLS13",
3609 config: Config{
3610 MaxVersion: VersionTLS13,
3611 },
3612 flags: []string{
3613 "-enable-ocsp-stapling",
3614 "-expect-ocsp-response",
3615 base64.StdEncoding.EncodeToString(testOCSPResponse),
3616 "-verify-peer",
3617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003619 })
3620 tests = append(tests, testCase{
3621 testType: serverTest,
3622 name: "OCSPStapling-Server-TLS13",
3623 config: Config{
3624 MaxVersion: VersionTLS13,
3625 },
3626 expectedOCSPResponse: testOCSPResponse,
3627 flags: []string{
3628 "-ocsp-response",
3629 base64.StdEncoding.EncodeToString(testOCSPResponse),
3630 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003631 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003632 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003633
David Benjamin4c3ddf72016-06-29 18:13:53 -04003634 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003635 for _, vers := range tlsVersions {
3636 if config.protocol == dtls && !vers.hasDTLS {
3637 continue
3638 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003639 for _, testType := range []testType{clientTest, serverTest} {
3640 suffix := "-Client"
3641 if testType == serverTest {
3642 suffix = "-Server"
3643 }
3644 suffix += "-" + vers.name
3645
3646 flag := "-verify-peer"
3647 if testType == serverTest {
3648 flag = "-require-any-client-certificate"
3649 }
3650
3651 tests = append(tests, testCase{
3652 testType: testType,
3653 name: "CertificateVerificationSucceed" + suffix,
3654 config: Config{
3655 MaxVersion: vers.version,
3656 Certificates: []Certificate{rsaCertificate},
3657 },
3658 flags: []string{
3659 flag,
3660 "-expect-verify-result",
3661 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003662 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003663 })
3664 tests = append(tests, testCase{
3665 testType: testType,
3666 name: "CertificateVerificationFail" + suffix,
3667 config: Config{
3668 MaxVersion: vers.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 },
3671 flags: []string{
3672 flag,
3673 "-verify-fail",
3674 },
3675 shouldFail: true,
3676 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3677 })
3678 }
3679
3680 // By default, the client is in a soft fail mode where the peer
3681 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003682 tests = append(tests, testCase{
3683 testType: clientTest,
3684 name: "CertificateVerificationSoftFail-" + vers.name,
3685 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003686 MaxVersion: vers.version,
3687 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003688 },
3689 flags: []string{
3690 "-verify-fail",
3691 "-expect-verify-result",
3692 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003693 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003694 })
3695 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003696
David Benjamin1d4f4c02016-07-26 18:03:08 -04003697 tests = append(tests, testCase{
3698 name: "ShimSendAlert",
3699 flags: []string{"-send-alert"},
3700 shimWritesFirst: true,
3701 shouldFail: true,
3702 expectedLocalError: "remote error: decompression failure",
3703 })
3704
David Benjamin582ba042016-07-07 12:33:25 -07003705 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003706 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003707 name: "Renegotiate-Client",
3708 config: Config{
3709 MaxVersion: VersionTLS12,
3710 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003711 renegotiate: 1,
3712 flags: []string{
3713 "-renegotiate-freely",
3714 "-expect-total-renegotiations", "1",
3715 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003716 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717
David Benjamin47921102016-07-28 11:29:18 -04003718 tests = append(tests, testCase{
3719 name: "SendHalfHelloRequest",
3720 config: Config{
3721 MaxVersion: VersionTLS12,
3722 Bugs: ProtocolBugs{
3723 PackHelloRequestWithFinished: config.packHandshakeFlight,
3724 },
3725 },
3726 sendHalfHelloRequest: true,
3727 flags: []string{"-renegotiate-ignore"},
3728 shouldFail: true,
3729 expectedError: ":UNEXPECTED_RECORD:",
3730 })
3731
David Benjamin760b1dd2015-05-15 23:33:48 -04003732 // NPN on client and server; results in post-handshake message.
3733 tests = append(tests, testCase{
3734 name: "NPN-Client",
3735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 NextProtos: []string{"foo"},
3738 },
3739 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003740 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003741 expectedNextProto: "foo",
3742 expectedNextProtoType: npn,
3743 })
3744 tests = append(tests, testCase{
3745 testType: serverTest,
3746 name: "NPN-Server",
3747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 NextProtos: []string{"bar"},
3750 },
3751 flags: []string{
3752 "-advertise-npn", "\x03foo\x03bar\x03baz",
3753 "-expect-next-proto", "bar",
3754 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003755 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003756 expectedNextProto: "bar",
3757 expectedNextProtoType: npn,
3758 })
3759
3760 // TODO(davidben): Add tests for when False Start doesn't trigger.
3761
3762 // Client does False Start and negotiates NPN.
3763 tests = append(tests, testCase{
3764 name: "FalseStart",
3765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003766 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3768 NextProtos: []string{"foo"},
3769 Bugs: ProtocolBugs{
3770 ExpectFalseStart: true,
3771 },
3772 },
3773 flags: []string{
3774 "-false-start",
3775 "-select-next-proto", "foo",
3776 },
3777 shimWritesFirst: true,
3778 resumeSession: true,
3779 })
3780
3781 // Client does False Start and negotiates ALPN.
3782 tests = append(tests, testCase{
3783 name: "FalseStart-ALPN",
3784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3787 NextProtos: []string{"foo"},
3788 Bugs: ProtocolBugs{
3789 ExpectFalseStart: true,
3790 },
3791 },
3792 flags: []string{
3793 "-false-start",
3794 "-advertise-alpn", "\x03foo",
3795 },
3796 shimWritesFirst: true,
3797 resumeSession: true,
3798 })
3799
3800 // Client does False Start but doesn't explicitly call
3801 // SSL_connect.
3802 tests = append(tests, testCase{
3803 name: "FalseStart-Implicit",
3804 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003805 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3807 NextProtos: []string{"foo"},
3808 },
3809 flags: []string{
3810 "-implicit-handshake",
3811 "-false-start",
3812 "-advertise-alpn", "\x03foo",
3813 },
3814 })
3815
3816 // False Start without session tickets.
3817 tests = append(tests, testCase{
3818 name: "FalseStart-SessionTicketsDisabled",
3819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003820 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3822 NextProtos: []string{"foo"},
3823 SessionTicketsDisabled: true,
3824 Bugs: ProtocolBugs{
3825 ExpectFalseStart: true,
3826 },
3827 },
3828 flags: []string{
3829 "-false-start",
3830 "-select-next-proto", "foo",
3831 },
3832 shimWritesFirst: true,
3833 })
3834
Adam Langleydf759b52016-07-11 15:24:37 -07003835 tests = append(tests, testCase{
3836 name: "FalseStart-CECPQ1",
3837 config: Config{
3838 MaxVersion: VersionTLS12,
3839 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3840 NextProtos: []string{"foo"},
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-cipher", "DEFAULT:kCECPQ1",
3848 "-select-next-proto", "foo",
3849 },
3850 shimWritesFirst: true,
3851 resumeSession: true,
3852 })
3853
David Benjamin760b1dd2015-05-15 23:33:48 -04003854 // Server parses a V2ClientHello.
3855 tests = append(tests, testCase{
3856 testType: serverTest,
3857 name: "SendV2ClientHello",
3858 config: Config{
3859 // Choose a cipher suite that does not involve
3860 // elliptic curves, so no extensions are
3861 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003862 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003863 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003864 Bugs: ProtocolBugs{
3865 SendV2ClientHello: true,
3866 },
3867 },
3868 })
3869
3870 // Client sends a Channel ID.
3871 tests = append(tests, testCase{
3872 name: "ChannelID-Client",
3873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 RequestChannelID: true,
3876 },
Adam Langley7c803a62015-06-15 15:35:05 -07003877 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003878 resumeSession: true,
3879 expectChannelID: true,
3880 })
3881
3882 // Server accepts a Channel ID.
3883 tests = append(tests, testCase{
3884 testType: serverTest,
3885 name: "ChannelID-Server",
3886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003887 MaxVersion: VersionTLS12,
3888 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003889 },
3890 flags: []string{
3891 "-expect-channel-id",
3892 base64.StdEncoding.EncodeToString(channelIDBytes),
3893 },
3894 resumeSession: true,
3895 expectChannelID: true,
3896 })
David Benjamin30789da2015-08-29 22:56:45 -04003897
David Benjaminf8fcdf32016-06-08 15:56:13 -04003898 // Channel ID and NPN at the same time, to ensure their relative
3899 // ordering is correct.
3900 tests = append(tests, testCase{
3901 name: "ChannelID-NPN-Client",
3902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003904 RequestChannelID: true,
3905 NextProtos: []string{"foo"},
3906 },
3907 flags: []string{
3908 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3909 "-select-next-proto", "foo",
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 expectedNextProto: "foo",
3914 expectedNextProtoType: npn,
3915 })
3916 tests = append(tests, testCase{
3917 testType: serverTest,
3918 name: "ChannelID-NPN-Server",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 ChannelID: channelIDKey,
3922 NextProtos: []string{"bar"},
3923 },
3924 flags: []string{
3925 "-expect-channel-id",
3926 base64.StdEncoding.EncodeToString(channelIDBytes),
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
3930 resumeSession: true,
3931 expectChannelID: true,
3932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
David Benjamin30789da2015-08-29 22:56:45 -04003936 // Bidirectional shutdown with the runner initiating.
3937 tests = append(tests, testCase{
3938 name: "Shutdown-Runner",
3939 config: Config{
3940 Bugs: ProtocolBugs{
3941 ExpectCloseNotify: true,
3942 },
3943 },
3944 flags: []string{"-check-close-notify"},
3945 })
3946
3947 // Bidirectional shutdown with the shim initiating. The runner,
3948 // in the meantime, sends garbage before the close_notify which
3949 // the shim must ignore.
3950 tests = append(tests, testCase{
3951 name: "Shutdown-Shim",
3952 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003953 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003954 Bugs: ProtocolBugs{
3955 ExpectCloseNotify: true,
3956 },
3957 },
3958 shimShutsDown: true,
3959 sendEmptyRecords: 1,
3960 sendWarningAlerts: 1,
3961 flags: []string{"-check-close-notify"},
3962 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 // TODO(davidben): DTLS 1.3 will want a similar thing for
3965 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003966 tests = append(tests, testCase{
3967 name: "SkipHelloVerifyRequest",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 Bugs: ProtocolBugs{
3971 SkipHelloVerifyRequest: true,
3972 },
3973 },
3974 })
3975 }
3976
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003978 test.protocol = config.protocol
3979 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003980 test.name += "-DTLS"
3981 }
David Benjamin582ba042016-07-07 12:33:25 -07003982 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003983 test.name += "-Async"
3984 test.flags = append(test.flags, "-async")
3985 } else {
3986 test.name += "-Sync"
3987 }
David Benjamin582ba042016-07-07 12:33:25 -07003988 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003989 test.name += "-SplitHandshakeRecords"
3990 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003991 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003992 test.config.Bugs.MaxPacketLength = 256
3993 test.flags = append(test.flags, "-mtu", "256")
3994 }
3995 }
David Benjamin582ba042016-07-07 12:33:25 -07003996 if config.packHandshakeFlight {
3997 test.name += "-PackHandshakeFlight"
3998 test.config.Bugs.PackHandshakeFlight = true
3999 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004000 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004001 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004002}
4003
Adam Langley524e7172015-02-20 16:04:00 -08004004func addDDoSCallbackTests() {
4005 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004006 for _, resume := range []bool{false, true} {
4007 suffix := "Resume"
4008 if resume {
4009 suffix = "No" + suffix
4010 }
4011
4012 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 testType: serverTest,
4014 name: "Server-DDoS-OK-" + suffix,
4015 config: Config{
4016 MaxVersion: VersionTLS12,
4017 },
Adam Langley524e7172015-02-20 16:04:00 -08004018 flags: []string{"-install-ddos-callback"},
4019 resumeSession: resume,
4020 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004021 testCases = append(testCases, testCase{
4022 testType: serverTest,
4023 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4024 config: Config{
4025 MaxVersion: VersionTLS13,
4026 },
4027 flags: []string{"-install-ddos-callback"},
4028 resumeSession: resume,
4029 })
Adam Langley524e7172015-02-20 16:04:00 -08004030
4031 failFlag := "-fail-ddos-callback"
4032 if resume {
4033 failFlag = "-fail-second-ddos-callback"
4034 }
4035 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 testType: serverTest,
4037 name: "Server-DDoS-Reject-" + suffix,
4038 config: Config{
4039 MaxVersion: VersionTLS12,
4040 },
David Benjamin2c66e072016-09-16 15:58:00 -04004041 flags: []string{"-install-ddos-callback", failFlag},
4042 resumeSession: resume,
4043 shouldFail: true,
4044 expectedError: ":CONNECTION_REJECTED:",
4045 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004046 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004047 testCases = append(testCases, testCase{
4048 testType: serverTest,
4049 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4050 config: Config{
4051 MaxVersion: VersionTLS13,
4052 },
David Benjamin2c66e072016-09-16 15:58:00 -04004053 flags: []string{"-install-ddos-callback", failFlag},
4054 resumeSession: resume,
4055 shouldFail: true,
4056 expectedError: ":CONNECTION_REJECTED:",
4057 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004058 })
Adam Langley524e7172015-02-20 16:04:00 -08004059 }
4060}
4061
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004062func addVersionNegotiationTests() {
4063 for i, shimVers := range tlsVersions {
4064 // Assemble flags to disable all newer versions on the shim.
4065 var flags []string
4066 for _, vers := range tlsVersions[i+1:] {
4067 flags = append(flags, vers.flag)
4068 }
4069
4070 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004071 protocols := []protocol{tls}
4072 if runnerVers.hasDTLS && shimVers.hasDTLS {
4073 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004074 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004075 for _, protocol := range protocols {
4076 expectedVersion := shimVers.version
4077 if runnerVers.version < shimVers.version {
4078 expectedVersion = runnerVers.version
4079 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004080
David Benjamin8b8c0062014-11-23 02:47:52 -05004081 suffix := shimVers.name + "-" + runnerVers.name
4082 if protocol == dtls {
4083 suffix += "-DTLS"
4084 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004085
David Benjamin1eb367c2014-12-12 18:17:51 -05004086 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4087
David Benjamin1e29a6b2014-12-10 02:27:24 -05004088 clientVers := shimVers.version
4089 if clientVers > VersionTLS10 {
4090 clientVers = VersionTLS10
4091 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004092 serverVers := expectedVersion
4093 if expectedVersion >= VersionTLS13 {
4094 serverVers = VersionTLS10
4095 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004096 testCases = append(testCases, testCase{
4097 protocol: protocol,
4098 testType: clientTest,
4099 name: "VersionNegotiation-Client-" + suffix,
4100 config: Config{
4101 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004102 Bugs: ProtocolBugs{
4103 ExpectInitialRecordVersion: clientVers,
4104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004105 },
4106 flags: flags,
4107 expectedVersion: expectedVersion,
4108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004109 testCases = append(testCases, testCase{
4110 protocol: protocol,
4111 testType: clientTest,
4112 name: "VersionNegotiation-Client2-" + suffix,
4113 config: Config{
4114 MaxVersion: runnerVers.version,
4115 Bugs: ProtocolBugs{
4116 ExpectInitialRecordVersion: clientVers,
4117 },
4118 },
4119 flags: []string{"-max-version", shimVersFlag},
4120 expectedVersion: expectedVersion,
4121 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004122
4123 testCases = append(testCases, testCase{
4124 protocol: protocol,
4125 testType: serverTest,
4126 name: "VersionNegotiation-Server-" + suffix,
4127 config: Config{
4128 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004129 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004130 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004131 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004132 },
4133 flags: flags,
4134 expectedVersion: expectedVersion,
4135 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004136 testCases = append(testCases, testCase{
4137 protocol: protocol,
4138 testType: serverTest,
4139 name: "VersionNegotiation-Server2-" + suffix,
4140 config: Config{
4141 MaxVersion: runnerVers.version,
4142 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004143 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004144 },
4145 },
4146 flags: []string{"-max-version", shimVersFlag},
4147 expectedVersion: expectedVersion,
4148 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004149 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004150 }
4151 }
David Benjamin95c69562016-06-29 18:15:03 -04004152
4153 // Test for version tolerance.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "MinorVersionTolerance",
4157 config: Config{
4158 Bugs: ProtocolBugs{
4159 SendClientVersion: 0x03ff,
4160 },
4161 },
4162 expectedVersion: VersionTLS13,
4163 })
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "MajorVersionTolerance",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0400,
4170 },
4171 },
4172 expectedVersion: VersionTLS13,
4173 })
4174 testCases = append(testCases, testCase{
4175 protocol: dtls,
4176 testType: serverTest,
4177 name: "MinorVersionTolerance-DTLS",
4178 config: Config{
4179 Bugs: ProtocolBugs{
4180 SendClientVersion: 0x03ff,
4181 },
4182 },
4183 expectedVersion: VersionTLS12,
4184 })
4185 testCases = append(testCases, testCase{
4186 protocol: dtls,
4187 testType: serverTest,
4188 name: "MajorVersionTolerance-DTLS",
4189 config: Config{
4190 Bugs: ProtocolBugs{
4191 SendClientVersion: 0x0400,
4192 },
4193 },
4194 expectedVersion: VersionTLS12,
4195 })
4196
4197 // Test that versions below 3.0 are rejected.
4198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "VersionTooLow",
4201 config: Config{
4202 Bugs: ProtocolBugs{
4203 SendClientVersion: 0x0200,
4204 },
4205 },
4206 shouldFail: true,
4207 expectedError: ":UNSUPPORTED_PROTOCOL:",
4208 })
4209 testCases = append(testCases, testCase{
4210 protocol: dtls,
4211 testType: serverTest,
4212 name: "VersionTooLow-DTLS",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 // 0x0201 is the lowest version expressable in
4216 // DTLS.
4217 SendClientVersion: 0x0201,
4218 },
4219 },
4220 shouldFail: true,
4221 expectedError: ":UNSUPPORTED_PROTOCOL:",
4222 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004223
David Benjamin2dc02042016-09-19 19:57:37 -04004224 testCases = append(testCases, testCase{
4225 name: "ServerBogusVersion",
4226 config: Config{
4227 Bugs: ProtocolBugs{
4228 SendServerHelloVersion: 0x1234,
4229 },
4230 },
4231 shouldFail: true,
4232 expectedError: ":UNSUPPORTED_PROTOCOL:",
4233 })
4234
David Benjamin1f61f0d2016-07-10 12:20:35 -04004235 // Test TLS 1.3's downgrade signal.
4236 testCases = append(testCases, testCase{
4237 name: "Downgrade-TLS12-Client",
4238 config: Config{
4239 Bugs: ProtocolBugs{
4240 NegotiateVersion: VersionTLS12,
4241 },
4242 },
David Benjamin55108632016-08-11 22:01:18 -04004243 // TODO(davidben): This test should fail once TLS 1.3 is final
4244 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004245 })
4246 testCases = append(testCases, testCase{
4247 testType: serverTest,
4248 name: "Downgrade-TLS12-Server",
4249 config: Config{
4250 Bugs: ProtocolBugs{
4251 SendClientVersion: VersionTLS12,
4252 },
4253 },
David Benjamin55108632016-08-11 22:01:18 -04004254 // TODO(davidben): This test should fail once TLS 1.3 is final
4255 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004256 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004257}
4258
David Benjaminaccb4542014-12-12 23:44:33 -05004259func addMinimumVersionTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all older versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[:i] {
4264 flags = append(flags, vers.flag)
4265 }
4266
4267 for _, runnerVers := range tlsVersions {
4268 protocols := []protocol{tls}
4269 if runnerVers.hasDTLS && shimVers.hasDTLS {
4270 protocols = append(protocols, dtls)
4271 }
4272 for _, protocol := range protocols {
4273 suffix := shimVers.name + "-" + runnerVers.name
4274 if protocol == dtls {
4275 suffix += "-DTLS"
4276 }
4277 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4278
David Benjaminaccb4542014-12-12 23:44:33 -05004279 var expectedVersion uint16
4280 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004281 var expectedClientError, expectedServerError string
4282 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004283 if runnerVers.version >= shimVers.version {
4284 expectedVersion = runnerVers.version
4285 } else {
4286 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004287 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4288 expectedServerLocalError = "remote error: protocol version not supported"
4289 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4290 // If the client's minimum version is TLS 1.3 and the runner's
4291 // maximum is below TLS 1.2, the runner will fail to select a
4292 // cipher before the shim rejects the selected version.
4293 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4294 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4295 } else {
4296 expectedClientError = expectedServerError
4297 expectedClientLocalError = expectedServerLocalError
4298 }
David Benjaminaccb4542014-12-12 23:44:33 -05004299 }
4300
4301 testCases = append(testCases, testCase{
4302 protocol: protocol,
4303 testType: clientTest,
4304 name: "MinimumVersion-Client-" + suffix,
4305 config: Config{
4306 MaxVersion: runnerVers.version,
4307 },
David Benjamin87909c02014-12-13 01:55:01 -05004308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004311 expectedError: expectedClientError,
4312 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004313 })
4314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: clientTest,
4317 name: "MinimumVersion-Client2-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
4320 },
David Benjamin87909c02014-12-13 01:55:01 -05004321 flags: []string{"-min-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004324 expectedError: expectedClientError,
4325 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004326 })
4327
4328 testCases = append(testCases, testCase{
4329 protocol: protocol,
4330 testType: serverTest,
4331 name: "MinimumVersion-Server-" + suffix,
4332 config: Config{
4333 MaxVersion: runnerVers.version,
4334 },
David Benjamin87909c02014-12-13 01:55:01 -05004335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004338 expectedError: expectedServerError,
4339 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004340 })
4341 testCases = append(testCases, testCase{
4342 protocol: protocol,
4343 testType: serverTest,
4344 name: "MinimumVersion-Server2-" + suffix,
4345 config: Config{
4346 MaxVersion: runnerVers.version,
4347 },
David Benjamin87909c02014-12-13 01:55:01 -05004348 flags: []string{"-min-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004351 expectedError: expectedServerError,
4352 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004353 })
4354 }
4355 }
4356 }
4357}
4358
David Benjamine78bfde2014-09-06 12:45:15 -04004359func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004360 // TODO(davidben): Extensions, where applicable, all move their server
4361 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4362 // tests for both. Also test interaction with 0-RTT when implemented.
4363
David Benjamin97d17d92016-07-14 16:12:00 -04004364 // Repeat extensions tests all versions except SSL 3.0.
4365 for _, ver := range tlsVersions {
4366 if ver.version == VersionSSL30 {
4367 continue
4368 }
4369
David Benjamin97d17d92016-07-14 16:12:00 -04004370 // Test that duplicate extensions are rejected.
4371 testCases = append(testCases, testCase{
4372 testType: clientTest,
4373 name: "DuplicateExtensionClient-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 Bugs: ProtocolBugs{
4377 DuplicateExtension: true,
4378 },
David Benjamine78bfde2014-09-06 12:45:15 -04004379 },
David Benjamin97d17d92016-07-14 16:12:00 -04004380 shouldFail: true,
4381 expectedLocalError: "remote error: error decoding message",
4382 })
4383 testCases = append(testCases, testCase{
4384 testType: serverTest,
4385 name: "DuplicateExtensionServer-" + ver.name,
4386 config: Config{
4387 MaxVersion: ver.version,
4388 Bugs: ProtocolBugs{
4389 DuplicateExtension: true,
4390 },
David Benjamine78bfde2014-09-06 12:45:15 -04004391 },
David Benjamin97d17d92016-07-14 16:12:00 -04004392 shouldFail: true,
4393 expectedLocalError: "remote error: error decoding message",
4394 })
4395
4396 // Test SNI.
4397 testCases = append(testCases, testCase{
4398 testType: clientTest,
4399 name: "ServerNameExtensionClient-" + ver.name,
4400 config: Config{
4401 MaxVersion: ver.version,
4402 Bugs: ProtocolBugs{
4403 ExpectServerName: "example.com",
4404 },
David Benjamine78bfde2014-09-06 12:45:15 -04004405 },
David Benjamin97d17d92016-07-14 16:12:00 -04004406 flags: []string{"-host-name", "example.com"},
4407 })
4408 testCases = append(testCases, testCase{
4409 testType: clientTest,
4410 name: "ServerNameExtensionClientMismatch-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 Bugs: ProtocolBugs{
4414 ExpectServerName: "mismatch.com",
4415 },
David Benjamine78bfde2014-09-06 12:45:15 -04004416 },
David Benjamin97d17d92016-07-14 16:12:00 -04004417 flags: []string{"-host-name", "example.com"},
4418 shouldFail: true,
4419 expectedLocalError: "tls: unexpected server name",
4420 })
4421 testCases = append(testCases, testCase{
4422 testType: clientTest,
4423 name: "ServerNameExtensionClientMissing-" + ver.name,
4424 config: Config{
4425 MaxVersion: ver.version,
4426 Bugs: ProtocolBugs{
4427 ExpectServerName: "missing.com",
4428 },
David Benjamine78bfde2014-09-06 12:45:15 -04004429 },
David Benjamin97d17d92016-07-14 16:12:00 -04004430 shouldFail: true,
4431 expectedLocalError: "tls: unexpected server name",
4432 })
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ServerNameExtensionServer-" + ver.name,
4436 config: Config{
4437 MaxVersion: ver.version,
4438 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004439 },
David Benjamin97d17d92016-07-14 16:12:00 -04004440 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004441 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004442 })
4443
4444 // Test ALPN.
4445 testCases = append(testCases, testCase{
4446 testType: clientTest,
4447 name: "ALPNClient-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo"},
4451 },
4452 flags: []string{
4453 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4454 "-expect-alpn", "foo",
4455 },
4456 expectedNextProto: "foo",
4457 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004458 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004459 })
4460 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004461 testType: clientTest,
4462 name: "ALPNClient-Mismatch-" + ver.name,
4463 config: Config{
4464 MaxVersion: ver.version,
4465 Bugs: ProtocolBugs{
4466 SendALPN: "baz",
4467 },
4468 },
4469 flags: []string{
4470 "-advertise-alpn", "\x03foo\x03bar",
4471 },
4472 shouldFail: true,
4473 expectedError: ":INVALID_ALPN_PROTOCOL:",
4474 expectedLocalError: "remote error: illegal parameter",
4475 })
4476 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004477 testType: serverTest,
4478 name: "ALPNServer-" + ver.name,
4479 config: Config{
4480 MaxVersion: ver.version,
4481 NextProtos: []string{"foo", "bar", "baz"},
4482 },
4483 flags: []string{
4484 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4485 "-select-alpn", "foo",
4486 },
4487 expectedNextProto: "foo",
4488 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004489 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004490 })
4491 testCases = append(testCases, testCase{
4492 testType: serverTest,
4493 name: "ALPNServer-Decline-" + ver.name,
4494 config: Config{
4495 MaxVersion: ver.version,
4496 NextProtos: []string{"foo", "bar", "baz"},
4497 },
4498 flags: []string{"-decline-alpn"},
4499 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004500 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004501 })
4502
David Benjamin25fe85b2016-08-09 20:00:32 -04004503 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4504 // called once.
4505 testCases = append(testCases, testCase{
4506 testType: serverTest,
4507 name: "ALPNServer-Async-" + ver.name,
4508 config: Config{
4509 MaxVersion: ver.version,
4510 NextProtos: []string{"foo", "bar", "baz"},
4511 },
4512 flags: []string{
4513 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4514 "-select-alpn", "foo",
4515 "-async",
4516 },
4517 expectedNextProto: "foo",
4518 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004519 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004520 })
4521
David Benjamin97d17d92016-07-14 16:12:00 -04004522 var emptyString string
4523 testCases = append(testCases, testCase{
4524 testType: clientTest,
4525 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 NextProtos: []string{""},
4529 Bugs: ProtocolBugs{
4530 // A server returning an empty ALPN protocol
4531 // should be rejected.
4532 ALPNProtocol: &emptyString,
4533 },
4534 },
4535 flags: []string{
4536 "-advertise-alpn", "\x03foo",
4537 },
4538 shouldFail: true,
4539 expectedError: ":PARSE_TLSEXT:",
4540 })
4541 testCases = append(testCases, testCase{
4542 testType: serverTest,
4543 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4544 config: Config{
4545 MaxVersion: ver.version,
4546 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004547 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004548 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004549 },
David Benjamin97d17d92016-07-14 16:12:00 -04004550 flags: []string{
4551 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004552 },
David Benjamin97d17d92016-07-14 16:12:00 -04004553 shouldFail: true,
4554 expectedError: ":PARSE_TLSEXT:",
4555 })
4556
4557 // Test NPN and the interaction with ALPN.
4558 if ver.version < VersionTLS13 {
4559 // Test that the server prefers ALPN over NPN.
4560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "ALPNServer-Preferred-" + ver.name,
4563 config: Config{
4564 MaxVersion: ver.version,
4565 NextProtos: []string{"foo", "bar", "baz"},
4566 },
4567 flags: []string{
4568 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4569 "-select-alpn", "foo",
4570 "-advertise-npn", "\x03foo\x03bar\x03baz",
4571 },
4572 expectedNextProto: "foo",
4573 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004574 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004575 })
4576 testCases = append(testCases, testCase{
4577 testType: serverTest,
4578 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 NextProtos: []string{"foo", "bar", "baz"},
4582 Bugs: ProtocolBugs{
4583 SwapNPNAndALPN: true,
4584 },
4585 },
4586 flags: []string{
4587 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4588 "-select-alpn", "foo",
4589 "-advertise-npn", "\x03foo\x03bar\x03baz",
4590 },
4591 expectedNextProto: "foo",
4592 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004593 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004594 })
4595
4596 // Test that negotiating both NPN and ALPN is forbidden.
4597 testCases = append(testCases, testCase{
4598 name: "NegotiateALPNAndNPN-" + ver.name,
4599 config: Config{
4600 MaxVersion: ver.version,
4601 NextProtos: []string{"foo", "bar", "baz"},
4602 Bugs: ProtocolBugs{
4603 NegotiateALPNAndNPN: true,
4604 },
4605 },
4606 flags: []string{
4607 "-advertise-alpn", "\x03foo",
4608 "-select-next-proto", "foo",
4609 },
4610 shouldFail: true,
4611 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4612 })
4613 testCases = append(testCases, testCase{
4614 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4615 config: Config{
4616 MaxVersion: ver.version,
4617 NextProtos: []string{"foo", "bar", "baz"},
4618 Bugs: ProtocolBugs{
4619 NegotiateALPNAndNPN: true,
4620 SwapNPNAndALPN: true,
4621 },
4622 },
4623 flags: []string{
4624 "-advertise-alpn", "\x03foo",
4625 "-select-next-proto", "foo",
4626 },
4627 shouldFail: true,
4628 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4629 })
4630
4631 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4632 testCases = append(testCases, testCase{
4633 name: "DisableNPN-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 NextProtos: []string{"foo"},
4637 },
4638 flags: []string{
4639 "-select-next-proto", "foo",
4640 "-disable-npn",
4641 },
4642 expectNoNextProto: true,
4643 })
4644 }
4645
4646 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004647
4648 // Resume with a corrupt ticket.
4649 testCases = append(testCases, testCase{
4650 testType: serverTest,
4651 name: "CorruptTicket-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 CorruptTicket: true,
4656 },
4657 },
4658 resumeSession: true,
4659 expectResumeRejected: true,
4660 })
4661 // Test the ticket callback, with and without renewal.
4662 testCases = append(testCases, testCase{
4663 testType: serverTest,
4664 name: "TicketCallback-" + ver.name,
4665 config: Config{
4666 MaxVersion: ver.version,
4667 },
4668 resumeSession: true,
4669 flags: []string{"-use-ticket-callback"},
4670 })
4671 testCases = append(testCases, testCase{
4672 testType: serverTest,
4673 name: "TicketCallback-Renew-" + ver.name,
4674 config: Config{
4675 MaxVersion: ver.version,
4676 Bugs: ProtocolBugs{
4677 ExpectNewTicket: true,
4678 },
4679 },
4680 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4681 resumeSession: true,
4682 })
4683
4684 // Test that the ticket callback is only called once when everything before
4685 // it in the ClientHello is asynchronous. This corrupts the ticket so
4686 // certificate selection callbacks run.
4687 testCases = append(testCases, testCase{
4688 testType: serverTest,
4689 name: "TicketCallback-SingleCall-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 Bugs: ProtocolBugs{
4693 CorruptTicket: true,
4694 },
4695 },
4696 resumeSession: true,
4697 expectResumeRejected: true,
4698 flags: []string{
4699 "-use-ticket-callback",
4700 "-async",
4701 },
4702 })
4703
4704 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004705 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004706 testCases = append(testCases, testCase{
4707 testType: serverTest,
4708 name: "OversizedSessionId-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 Bugs: ProtocolBugs{
4712 OversizedSessionId: true,
4713 },
4714 },
4715 resumeSession: true,
4716 shouldFail: true,
4717 expectedError: ":DECODE_ERROR:",
4718 })
4719 }
4720
4721 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4722 // are ignored.
4723 if ver.hasDTLS {
4724 testCases = append(testCases, testCase{
4725 protocol: dtls,
4726 name: "SRTP-Client-" + ver.name,
4727 config: Config{
4728 MaxVersion: ver.version,
4729 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4730 },
4731 flags: []string{
4732 "-srtp-profiles",
4733 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4734 },
4735 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4736 })
4737 testCases = append(testCases, testCase{
4738 protocol: dtls,
4739 testType: serverTest,
4740 name: "SRTP-Server-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4744 },
4745 flags: []string{
4746 "-srtp-profiles",
4747 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4748 },
4749 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4750 })
4751 // Test that the MKI is ignored.
4752 testCases = append(testCases, testCase{
4753 protocol: dtls,
4754 testType: serverTest,
4755 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4759 Bugs: ProtocolBugs{
4760 SRTPMasterKeyIdentifer: "bogus",
4761 },
4762 },
4763 flags: []string{
4764 "-srtp-profiles",
4765 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4766 },
4767 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4768 })
4769 // Test that SRTP isn't negotiated on the server if there were
4770 // no matching profiles.
4771 testCases = append(testCases, testCase{
4772 protocol: dtls,
4773 testType: serverTest,
4774 name: "SRTP-Server-NoMatch-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 SRTPProtectionProfiles: []uint16{100, 101, 102},
4778 },
4779 flags: []string{
4780 "-srtp-profiles",
4781 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4782 },
4783 expectedSRTPProtectionProfile: 0,
4784 })
4785 // Test that the server returning an invalid SRTP profile is
4786 // flagged as an error by the client.
4787 testCases = append(testCases, testCase{
4788 protocol: dtls,
4789 name: "SRTP-Client-NoMatch-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 Bugs: ProtocolBugs{
4793 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4794 },
4795 },
4796 flags: []string{
4797 "-srtp-profiles",
4798 "SRTP_AES128_CM_SHA1_80",
4799 },
4800 shouldFail: true,
4801 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4802 })
4803 }
4804
4805 // Test SCT list.
4806 testCases = append(testCases, testCase{
4807 name: "SignedCertificateTimestampList-Client-" + ver.name,
4808 testType: clientTest,
4809 config: Config{
4810 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004811 },
David Benjamin97d17d92016-07-14 16:12:00 -04004812 flags: []string{
4813 "-enable-signed-cert-timestamps",
4814 "-expect-signed-cert-timestamps",
4815 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004816 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004818 })
4819 testCases = append(testCases, testCase{
4820 name: "SendSCTListOnResume-" + ver.name,
4821 config: Config{
4822 MaxVersion: ver.version,
4823 Bugs: ProtocolBugs{
4824 SendSCTListOnResume: []byte("bogus"),
4825 },
David Benjamind98452d2015-06-16 14:16:23 -04004826 },
David Benjamin97d17d92016-07-14 16:12:00 -04004827 flags: []string{
4828 "-enable-signed-cert-timestamps",
4829 "-expect-signed-cert-timestamps",
4830 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004831 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004832 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004833 })
4834 testCases = append(testCases, testCase{
4835 name: "SignedCertificateTimestampList-Server-" + ver.name,
4836 testType: serverTest,
4837 config: Config{
4838 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004839 },
David Benjamin97d17d92016-07-14 16:12:00 -04004840 flags: []string{
4841 "-signed-cert-timestamps",
4842 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004843 },
David Benjamin97d17d92016-07-14 16:12:00 -04004844 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004846 })
4847 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004848
Paul Lietar4fac72e2015-09-09 13:44:55 +01004849 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004850 testType: clientTest,
4851 name: "ClientHelloPadding",
4852 config: Config{
4853 Bugs: ProtocolBugs{
4854 RequireClientHelloSize: 512,
4855 },
4856 },
4857 // This hostname just needs to be long enough to push the
4858 // ClientHello into F5's danger zone between 256 and 511 bytes
4859 // long.
4860 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4861 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004862
4863 // Extensions should not function in SSL 3.0.
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "SSLv3Extensions-NoALPN",
4867 config: Config{
4868 MaxVersion: VersionSSL30,
4869 NextProtos: []string{"foo", "bar", "baz"},
4870 },
4871 flags: []string{
4872 "-select-alpn", "foo",
4873 },
4874 expectNoNextProto: true,
4875 })
4876
4877 // Test session tickets separately as they follow a different codepath.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "SSLv3Extensions-NoTickets",
4881 config: Config{
4882 MaxVersion: VersionSSL30,
4883 Bugs: ProtocolBugs{
4884 // Historically, session tickets in SSL 3.0
4885 // failed in different ways depending on whether
4886 // the client supported renegotiation_info.
4887 NoRenegotiationInfo: true,
4888 },
4889 },
4890 resumeSession: true,
4891 })
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "SSLv3Extensions-NoTickets2",
4895 config: Config{
4896 MaxVersion: VersionSSL30,
4897 },
4898 resumeSession: true,
4899 })
4900
4901 // But SSL 3.0 does send and process renegotiation_info.
4902 testCases = append(testCases, testCase{
4903 testType: serverTest,
4904 name: "SSLv3Extensions-RenegotiationInfo",
4905 config: Config{
4906 MaxVersion: VersionSSL30,
4907 Bugs: ProtocolBugs{
4908 RequireRenegotiationInfo: true,
4909 },
4910 },
4911 })
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4915 config: Config{
4916 MaxVersion: VersionSSL30,
4917 Bugs: ProtocolBugs{
4918 NoRenegotiationInfo: true,
4919 SendRenegotiationSCSV: true,
4920 RequireRenegotiationInfo: true,
4921 },
4922 },
4923 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004924
4925 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4926 // in ServerHello.
4927 testCases = append(testCases, testCase{
4928 name: "NPN-Forbidden-TLS13",
4929 config: Config{
4930 MaxVersion: VersionTLS13,
4931 NextProtos: []string{"foo"},
4932 Bugs: ProtocolBugs{
4933 NegotiateNPNAtAllVersions: true,
4934 },
4935 },
4936 flags: []string{"-select-next-proto", "foo"},
4937 shouldFail: true,
4938 expectedError: ":ERROR_PARSING_EXTENSION:",
4939 })
4940 testCases = append(testCases, testCase{
4941 name: "EMS-Forbidden-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 Bugs: ProtocolBugs{
4945 NegotiateEMSAtAllVersions: true,
4946 },
4947 },
4948 shouldFail: true,
4949 expectedError: ":ERROR_PARSING_EXTENSION:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "RenegotiationInfo-Forbidden-TLS13",
4953 config: Config{
4954 MaxVersion: VersionTLS13,
4955 Bugs: ProtocolBugs{
4956 NegotiateRenegotiationInfoAtAllVersions: true,
4957 },
4958 },
4959 shouldFail: true,
4960 expectedError: ":ERROR_PARSING_EXTENSION:",
4961 })
4962 testCases = append(testCases, testCase{
4963 name: "ChannelID-Forbidden-TLS13",
4964 config: Config{
4965 MaxVersion: VersionTLS13,
4966 RequestChannelID: true,
4967 Bugs: ProtocolBugs{
4968 NegotiateChannelIDAtAllVersions: true,
4969 },
4970 },
4971 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4972 shouldFail: true,
4973 expectedError: ":ERROR_PARSING_EXTENSION:",
4974 })
4975 testCases = append(testCases, testCase{
4976 name: "Ticket-Forbidden-TLS13",
4977 config: Config{
4978 MaxVersion: VersionTLS12,
4979 },
4980 resumeConfig: &Config{
4981 MaxVersion: VersionTLS13,
4982 Bugs: ProtocolBugs{
4983 AdvertiseTicketExtension: true,
4984 },
4985 },
4986 resumeSession: true,
4987 shouldFail: true,
4988 expectedError: ":ERROR_PARSING_EXTENSION:",
4989 })
4990
4991 // Test that illegal extensions in TLS 1.3 are declined by the server if
4992 // offered in ClientHello. The runner's server will fail if this occurs,
4993 // so we exercise the offering path. (EMS and Renegotiation Info are
4994 // implicit in every test.)
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "ChannelID-Declined-TLS13",
4998 config: Config{
4999 MaxVersion: VersionTLS13,
5000 ChannelID: channelIDKey,
5001 },
5002 flags: []string{"-enable-channel-id"},
5003 })
5004 testCases = append(testCases, testCase{
5005 testType: serverTest,
5006 name: "NPN-Server",
5007 config: Config{
5008 MaxVersion: VersionTLS13,
5009 NextProtos: []string{"bar"},
5010 },
5011 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5012 })
David Benjamine78bfde2014-09-06 12:45:15 -04005013}
5014
David Benjamin01fe8202014-09-24 15:21:44 -04005015func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005016 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005017 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005018 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5019 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5020 // TLS 1.3 only shares ciphers with TLS 1.2, so
5021 // we skip certain combinations and use a
5022 // different cipher to test with.
5023 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5024 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5025 continue
5026 }
5027 }
5028
David Benjamin8b8c0062014-11-23 02:47:52 -05005029 protocols := []protocol{tls}
5030 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5031 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005032 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005033 for _, protocol := range protocols {
5034 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5035 if protocol == dtls {
5036 suffix += "-DTLS"
5037 }
5038
David Benjaminece3de92015-03-16 18:02:20 -04005039 if sessionVers.version == resumeVers.version {
5040 testCases = append(testCases, testCase{
5041 protocol: protocol,
5042 name: "Resume-Client" + suffix,
5043 resumeSession: true,
5044 config: Config{
5045 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005046 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005047 Bugs: ProtocolBugs{
5048 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5049 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5050 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005051 },
David Benjaminece3de92015-03-16 18:02:20 -04005052 expectedVersion: sessionVers.version,
5053 expectedResumeVersion: resumeVers.version,
5054 })
5055 } else {
David Benjamin405da482016-08-08 17:25:07 -04005056 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5057
5058 // Offering a TLS 1.3 session sends an empty session ID, so
5059 // there is no way to convince a non-lookahead client the
5060 // session was resumed. It will appear to the client that a
5061 // stray ChangeCipherSpec was sent.
5062 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5063 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005064 }
5065
David Benjaminece3de92015-03-16 18:02:20 -04005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 name: "Resume-Client-Mismatch" + suffix,
5069 resumeSession: true,
5070 config: Config{
5071 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005072 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005073 },
David Benjaminece3de92015-03-16 18:02:20 -04005074 expectedVersion: sessionVers.version,
5075 resumeConfig: &Config{
5076 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005077 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005078 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005079 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005080 },
5081 },
5082 expectedResumeVersion: resumeVers.version,
5083 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005084 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005085 })
5086 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005087
5088 testCases = append(testCases, testCase{
5089 protocol: protocol,
5090 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005091 resumeSession: true,
5092 config: Config{
5093 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005094 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005095 },
5096 expectedVersion: sessionVers.version,
5097 resumeConfig: &Config{
5098 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005099 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005100 },
5101 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005102 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 expectedResumeVersion: resumeVers.version,
5104 })
5105
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 testCases = append(testCases, testCase{
5107 protocol: protocol,
5108 testType: serverTest,
5109 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005110 resumeSession: true,
5111 config: Config{
5112 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005113 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005114 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005115 expectedVersion: sessionVers.version,
5116 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005117 resumeConfig: &Config{
5118 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005119 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005120 Bugs: ProtocolBugs{
5121 SendBothTickets: true,
5122 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 },
5124 expectedResumeVersion: resumeVers.version,
5125 })
5126 }
David Benjamin01fe8202014-09-24 15:21:44 -04005127 }
5128 }
David Benjaminece3de92015-03-16 18:02:20 -04005129
5130 testCases = append(testCases, testCase{
5131 name: "Resume-Client-CipherMismatch",
5132 resumeSession: true,
5133 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005134 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005135 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5136 },
5137 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005138 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5140 Bugs: ProtocolBugs{
5141 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5142 },
5143 },
5144 shouldFail: true,
5145 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5146 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005147
5148 testCases = append(testCases, testCase{
5149 name: "Resume-Client-CipherMismatch-TLS13",
5150 resumeSession: true,
5151 config: Config{
5152 MaxVersion: VersionTLS13,
5153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5154 },
5155 resumeConfig: &Config{
5156 MaxVersion: VersionTLS13,
5157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5158 Bugs: ProtocolBugs{
5159 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5164 })
David Benjamin01fe8202014-09-24 15:21:44 -04005165}
5166
Adam Langley2ae77d22014-10-28 17:29:33 -07005167func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005168 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005169 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005170 testType: serverTest,
5171 name: "Renegotiate-Server-Forbidden",
5172 config: Config{
5173 MaxVersion: VersionTLS12,
5174 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005175 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005176 shouldFail: true,
5177 expectedError: ":NO_RENEGOTIATION:",
5178 expectedLocalError: "remote error: no renegotiation",
5179 })
Adam Langley5021b222015-06-12 18:27:58 -07005180 // The server shouldn't echo the renegotiation extension unless
5181 // requested by the client.
5182 testCases = append(testCases, testCase{
5183 testType: serverTest,
5184 name: "Renegotiate-Server-NoExt",
5185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005186 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005187 Bugs: ProtocolBugs{
5188 NoRenegotiationInfo: true,
5189 RequireRenegotiationInfo: true,
5190 },
5191 },
5192 shouldFail: true,
5193 expectedLocalError: "renegotiation extension missing",
5194 })
5195 // The renegotiation SCSV should be sufficient for the server to echo
5196 // the extension.
5197 testCases = append(testCases, testCase{
5198 testType: serverTest,
5199 name: "Renegotiate-Server-NoExt-SCSV",
5200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005201 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005202 Bugs: ProtocolBugs{
5203 NoRenegotiationInfo: true,
5204 SendRenegotiationSCSV: true,
5205 RequireRenegotiationInfo: true,
5206 },
5207 },
5208 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005209 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005210 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005212 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005213 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005214 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005215 },
5216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005217 renegotiate: 1,
5218 flags: []string{
5219 "-renegotiate-freely",
5220 "-expect-total-renegotiations", "1",
5221 },
David Benjamincdea40c2015-03-19 14:09:43 -04005222 })
5223 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005224 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005225 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005227 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005228 Bugs: ProtocolBugs{
5229 EmptyRenegotiationInfo: true,
5230 },
5231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005232 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005233 shouldFail: true,
5234 expectedError: ":RENEGOTIATION_MISMATCH:",
5235 })
5236 testCases = append(testCases, testCase{
5237 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005238 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005241 Bugs: ProtocolBugs{
5242 BadRenegotiationInfo: true,
5243 },
5244 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005245 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005246 shouldFail: true,
5247 expectedError: ":RENEGOTIATION_MISMATCH:",
5248 })
5249 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005250 name: "Renegotiate-Client-Downgrade",
5251 renegotiate: 1,
5252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005253 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005254 Bugs: ProtocolBugs{
5255 NoRenegotiationInfoAfterInitial: true,
5256 },
5257 },
5258 flags: []string{"-renegotiate-freely"},
5259 shouldFail: true,
5260 expectedError: ":RENEGOTIATION_MISMATCH:",
5261 })
5262 testCases = append(testCases, testCase{
5263 name: "Renegotiate-Client-Upgrade",
5264 renegotiate: 1,
5265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005266 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005267 Bugs: ProtocolBugs{
5268 NoRenegotiationInfoInInitial: true,
5269 },
5270 },
5271 flags: []string{"-renegotiate-freely"},
5272 shouldFail: true,
5273 expectedError: ":RENEGOTIATION_MISMATCH:",
5274 })
5275 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005276 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005277 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005279 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005280 Bugs: ProtocolBugs{
5281 NoRenegotiationInfo: true,
5282 },
5283 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005284 flags: []string{
5285 "-renegotiate-freely",
5286 "-expect-total-renegotiations", "1",
5287 },
David Benjamincff0b902015-05-15 23:09:47 -04005288 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005289
5290 // Test that the server may switch ciphers on renegotiation without
5291 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005292 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005293 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005294 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005295 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005296 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005297 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005298 },
5299 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005300 flags: []string{
5301 "-renegotiate-freely",
5302 "-expect-total-renegotiations", "1",
5303 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005304 })
5305 testCases = append(testCases, testCase{
5306 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005307 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005308 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005309 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005310 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5311 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005312 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005313 flags: []string{
5314 "-renegotiate-freely",
5315 "-expect-total-renegotiations", "1",
5316 },
David Benjaminb16346b2015-04-08 19:16:58 -04005317 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005318
5319 // Test that the server may not switch versions on renegotiation.
5320 testCases = append(testCases, testCase{
5321 name: "Renegotiate-Client-SwitchVersion",
5322 config: Config{
5323 MaxVersion: VersionTLS12,
5324 // Pick a cipher which exists at both versions.
5325 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5326 Bugs: ProtocolBugs{
5327 NegotiateVersionOnRenego: VersionTLS11,
5328 },
5329 },
5330 renegotiate: 1,
5331 flags: []string{
5332 "-renegotiate-freely",
5333 "-expect-total-renegotiations", "1",
5334 },
5335 shouldFail: true,
5336 expectedError: ":WRONG_SSL_VERSION:",
5337 })
5338
David Benjaminb16346b2015-04-08 19:16:58 -04005339 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005340 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005341 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005342 config: Config{
5343 MaxVersion: VersionTLS10,
5344 Bugs: ProtocolBugs{
5345 RequireSameRenegoClientVersion: true,
5346 },
5347 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005348 flags: []string{
5349 "-renegotiate-freely",
5350 "-expect-total-renegotiations", "1",
5351 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005352 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005353 testCases = append(testCases, testCase{
5354 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005355 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005356 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005357 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005358 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5359 NextProtos: []string{"foo"},
5360 },
5361 flags: []string{
5362 "-false-start",
5363 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005364 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005365 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005366 },
5367 shimWritesFirst: true,
5368 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005369
5370 // Client-side renegotiation controls.
5371 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005372 name: "Renegotiate-Client-Forbidden-1",
5373 config: Config{
5374 MaxVersion: VersionTLS12,
5375 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005376 renegotiate: 1,
5377 shouldFail: true,
5378 expectedError: ":NO_RENEGOTIATION:",
5379 expectedLocalError: "remote error: no renegotiation",
5380 })
5381 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005382 name: "Renegotiate-Client-Once-1",
5383 config: Config{
5384 MaxVersion: VersionTLS12,
5385 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005386 renegotiate: 1,
5387 flags: []string{
5388 "-renegotiate-once",
5389 "-expect-total-renegotiations", "1",
5390 },
5391 })
5392 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005393 name: "Renegotiate-Client-Freely-1",
5394 config: Config{
5395 MaxVersion: VersionTLS12,
5396 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005397 renegotiate: 1,
5398 flags: []string{
5399 "-renegotiate-freely",
5400 "-expect-total-renegotiations", "1",
5401 },
5402 })
5403 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005404 name: "Renegotiate-Client-Once-2",
5405 config: Config{
5406 MaxVersion: VersionTLS12,
5407 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005408 renegotiate: 2,
5409 flags: []string{"-renegotiate-once"},
5410 shouldFail: true,
5411 expectedError: ":NO_RENEGOTIATION:",
5412 expectedLocalError: "remote error: no renegotiation",
5413 })
5414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005415 name: "Renegotiate-Client-Freely-2",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005419 renegotiate: 2,
5420 flags: []string{
5421 "-renegotiate-freely",
5422 "-expect-total-renegotiations", "2",
5423 },
5424 })
Adam Langley27a0d082015-11-03 13:34:10 -08005425 testCases = append(testCases, testCase{
5426 name: "Renegotiate-Client-NoIgnore",
5427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005429 Bugs: ProtocolBugs{
5430 SendHelloRequestBeforeEveryAppDataRecord: true,
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":NO_RENEGOTIATION:",
5435 })
5436 testCases = append(testCases, testCase{
5437 name: "Renegotiate-Client-Ignore",
5438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005439 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005440 Bugs: ProtocolBugs{
5441 SendHelloRequestBeforeEveryAppDataRecord: true,
5442 },
5443 },
5444 flags: []string{
5445 "-renegotiate-ignore",
5446 "-expect-total-renegotiations", "0",
5447 },
5448 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005449
David Benjamin397c8e62016-07-08 14:14:36 -07005450 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005451 testCases = append(testCases, testCase{
5452 name: "StrayHelloRequest",
5453 config: Config{
5454 MaxVersion: VersionTLS12,
5455 Bugs: ProtocolBugs{
5456 SendHelloRequestBeforeEveryHandshakeMessage: true,
5457 },
5458 },
5459 })
5460 testCases = append(testCases, testCase{
5461 name: "StrayHelloRequest-Packed",
5462 config: Config{
5463 MaxVersion: VersionTLS12,
5464 Bugs: ProtocolBugs{
5465 PackHandshakeFlight: true,
5466 SendHelloRequestBeforeEveryHandshakeMessage: true,
5467 },
5468 },
5469 })
5470
David Benjamin12d2c482016-07-24 10:56:51 -04005471 // Test renegotiation works if HelloRequest and server Finished come in
5472 // the same record.
5473 testCases = append(testCases, testCase{
5474 name: "Renegotiate-Client-Packed",
5475 config: Config{
5476 MaxVersion: VersionTLS12,
5477 Bugs: ProtocolBugs{
5478 PackHandshakeFlight: true,
5479 PackHelloRequestWithFinished: true,
5480 },
5481 },
5482 renegotiate: 1,
5483 flags: []string{
5484 "-renegotiate-freely",
5485 "-expect-total-renegotiations", "1",
5486 },
5487 })
5488
David Benjamin397c8e62016-07-08 14:14:36 -07005489 // Renegotiation is forbidden in TLS 1.3.
5490 testCases = append(testCases, testCase{
5491 name: "Renegotiate-Client-TLS13",
5492 config: Config{
5493 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005494 Bugs: ProtocolBugs{
5495 SendHelloRequestBeforeEveryAppDataRecord: true,
5496 },
David Benjamin397c8e62016-07-08 14:14:36 -07005497 },
David Benjamin397c8e62016-07-08 14:14:36 -07005498 flags: []string{
5499 "-renegotiate-freely",
5500 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005501 shouldFail: true,
5502 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005503 })
5504
5505 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5506 testCases = append(testCases, testCase{
5507 name: "StrayHelloRequest-TLS13",
5508 config: Config{
5509 MaxVersion: VersionTLS13,
5510 Bugs: ProtocolBugs{
5511 SendHelloRequestBeforeEveryHandshakeMessage: true,
5512 },
5513 },
5514 shouldFail: true,
5515 expectedError: ":UNEXPECTED_MESSAGE:",
5516 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005517}
5518
David Benjamin5e961c12014-11-07 01:48:35 -05005519func addDTLSReplayTests() {
5520 // Test that sequence number replays are detected.
5521 testCases = append(testCases, testCase{
5522 protocol: dtls,
5523 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005524 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005525 replayWrites: true,
5526 })
5527
David Benjamin8e6db492015-07-25 18:29:23 -04005528 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005529 // than the retransmit window.
5530 testCases = append(testCases, testCase{
5531 protocol: dtls,
5532 name: "DTLS-Replay-LargeGaps",
5533 config: Config{
5534 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005535 SequenceNumberMapping: func(in uint64) uint64 {
5536 return in * 127
5537 },
David Benjamin5e961c12014-11-07 01:48:35 -05005538 },
5539 },
David Benjamin8e6db492015-07-25 18:29:23 -04005540 messageCount: 200,
5541 replayWrites: true,
5542 })
5543
5544 // Test the incoming sequence number changing non-monotonically.
5545 testCases = append(testCases, testCase{
5546 protocol: dtls,
5547 name: "DTLS-Replay-NonMonotonic",
5548 config: Config{
5549 Bugs: ProtocolBugs{
5550 SequenceNumberMapping: func(in uint64) uint64 {
5551 return in ^ 31
5552 },
5553 },
5554 },
5555 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005556 replayWrites: true,
5557 })
5558}
5559
Nick Harper60edffd2016-06-21 15:19:24 -07005560var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005561 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005562 id signatureAlgorithm
5563 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005564}{
Nick Harper60edffd2016-06-21 15:19:24 -07005565 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5566 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5567 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5568 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005569 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005570 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5571 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5572 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005573 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5574 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5575 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005576 // Tests for key types prior to TLS 1.2.
5577 {"RSA", 0, testCertRSA},
5578 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005579}
5580
Nick Harper60edffd2016-06-21 15:19:24 -07005581const fakeSigAlg1 signatureAlgorithm = 0x2a01
5582const fakeSigAlg2 signatureAlgorithm = 0xff01
5583
5584func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005585 // Not all ciphers involve a signature. Advertise a list which gives all
5586 // versions a signing cipher.
5587 signingCiphers := []uint16{
5588 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5589 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5590 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5591 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5592 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5593 }
5594
David Benjaminca3d5452016-07-14 12:51:01 -04005595 var allAlgorithms []signatureAlgorithm
5596 for _, alg := range testSignatureAlgorithms {
5597 if alg.id != 0 {
5598 allAlgorithms = append(allAlgorithms, alg.id)
5599 }
5600 }
5601
Nick Harper60edffd2016-06-21 15:19:24 -07005602 // Make sure each signature algorithm works. Include some fake values in
5603 // the list and ensure they're ignored.
5604 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005605 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005606 if (ver.version < VersionTLS12) != (alg.id == 0) {
5607 continue
5608 }
5609
5610 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5611 // or remove it in C.
5612 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005613 continue
5614 }
Nick Harper60edffd2016-06-21 15:19:24 -07005615
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005616 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005617 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005618 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5619 shouldFail = true
5620 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005621 // RSA-PKCS1 does not exist in TLS 1.3.
5622 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5623 shouldFail = true
5624 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005625
5626 var signError, verifyError string
5627 if shouldFail {
5628 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5629 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005630 }
David Benjamin000800a2014-11-14 01:43:59 -05005631
David Benjamin1fb125c2016-07-08 18:52:12 -07005632 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005633
David Benjamin7a41d372016-07-09 11:21:54 -07005634 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005635 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005636 config: Config{
5637 MaxVersion: ver.version,
5638 ClientAuth: RequireAnyClientCert,
5639 VerifySignatureAlgorithms: []signatureAlgorithm{
5640 fakeSigAlg1,
5641 alg.id,
5642 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005643 },
David Benjamin7a41d372016-07-09 11:21:54 -07005644 },
5645 flags: []string{
5646 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5647 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5648 "-enable-all-curves",
5649 },
5650 shouldFail: shouldFail,
5651 expectedError: signError,
5652 expectedPeerSignatureAlgorithm: alg.id,
5653 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005654
David Benjamin7a41d372016-07-09 11:21:54 -07005655 testCases = append(testCases, testCase{
5656 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005657 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005658 config: Config{
5659 MaxVersion: ver.version,
5660 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5661 SignSignatureAlgorithms: []signatureAlgorithm{
5662 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005663 },
David Benjamin7a41d372016-07-09 11:21:54 -07005664 Bugs: ProtocolBugs{
5665 SkipECDSACurveCheck: shouldFail,
5666 IgnoreSignatureVersionChecks: shouldFail,
5667 // The client won't advertise 1.3-only algorithms after
5668 // version negotiation.
5669 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005670 },
David Benjamin7a41d372016-07-09 11:21:54 -07005671 },
5672 flags: []string{
5673 "-require-any-client-certificate",
5674 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5675 "-enable-all-curves",
5676 },
5677 shouldFail: shouldFail,
5678 expectedError: verifyError,
5679 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005680
5681 testCases = append(testCases, testCase{
5682 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005683 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005684 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005685 MaxVersion: ver.version,
5686 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005687 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005688 fakeSigAlg1,
5689 alg.id,
5690 fakeSigAlg2,
5691 },
5692 },
5693 flags: []string{
5694 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5695 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5696 "-enable-all-curves",
5697 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005698 shouldFail: shouldFail,
5699 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005700 expectedPeerSignatureAlgorithm: alg.id,
5701 })
5702
5703 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005704 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005705 config: Config{
5706 MaxVersion: ver.version,
5707 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005708 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005709 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005710 alg.id,
5711 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005712 Bugs: ProtocolBugs{
5713 SkipECDSACurveCheck: shouldFail,
5714 IgnoreSignatureVersionChecks: shouldFail,
5715 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005716 },
5717 flags: []string{
5718 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5719 "-enable-all-curves",
5720 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005721 shouldFail: shouldFail,
5722 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005723 })
David Benjamin5208fd42016-07-13 21:43:25 -04005724
5725 if !shouldFail {
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "ClientAuth-InvalidSignature" + suffix,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5732 SignSignatureAlgorithms: []signatureAlgorithm{
5733 alg.id,
5734 },
5735 Bugs: ProtocolBugs{
5736 InvalidSignature: true,
5737 },
5738 },
5739 flags: []string{
5740 "-require-any-client-certificate",
5741 "-enable-all-curves",
5742 },
5743 shouldFail: true,
5744 expectedError: ":BAD_SIGNATURE:",
5745 })
5746
5747 testCases = append(testCases, testCase{
5748 name: "ServerAuth-InvalidSignature" + suffix,
5749 config: Config{
5750 MaxVersion: ver.version,
5751 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5752 CipherSuites: signingCiphers,
5753 SignSignatureAlgorithms: []signatureAlgorithm{
5754 alg.id,
5755 },
5756 Bugs: ProtocolBugs{
5757 InvalidSignature: true,
5758 },
5759 },
5760 flags: []string{"-enable-all-curves"},
5761 shouldFail: true,
5762 expectedError: ":BAD_SIGNATURE:",
5763 })
5764 }
David Benjaminca3d5452016-07-14 12:51:01 -04005765
5766 if ver.version >= VersionTLS12 && !shouldFail {
5767 testCases = append(testCases, testCase{
5768 name: "ClientAuth-Sign-Negotiate" + suffix,
5769 config: Config{
5770 MaxVersion: ver.version,
5771 ClientAuth: RequireAnyClientCert,
5772 VerifySignatureAlgorithms: allAlgorithms,
5773 },
5774 flags: []string{
5775 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5776 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5777 "-enable-all-curves",
5778 "-signing-prefs", strconv.Itoa(int(alg.id)),
5779 },
5780 expectedPeerSignatureAlgorithm: alg.id,
5781 })
5782
5783 testCases = append(testCases, testCase{
5784 testType: serverTest,
5785 name: "ServerAuth-Sign-Negotiate" + suffix,
5786 config: Config{
5787 MaxVersion: ver.version,
5788 CipherSuites: signingCiphers,
5789 VerifySignatureAlgorithms: allAlgorithms,
5790 },
5791 flags: []string{
5792 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5793 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5794 "-enable-all-curves",
5795 "-signing-prefs", strconv.Itoa(int(alg.id)),
5796 },
5797 expectedPeerSignatureAlgorithm: alg.id,
5798 })
5799 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005800 }
David Benjamin000800a2014-11-14 01:43:59 -05005801 }
5802
Nick Harper60edffd2016-06-21 15:19:24 -07005803 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005804 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005805 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005806 config: Config{
5807 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005808 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005809 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005810 signatureECDSAWithP521AndSHA512,
5811 signatureRSAPKCS1WithSHA384,
5812 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005813 },
5814 },
5815 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005816 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5817 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005818 },
Nick Harper60edffd2016-06-21 15:19:24 -07005819 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005820 })
5821
5822 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005823 name: "ClientAuth-SignatureType-TLS13",
5824 config: Config{
5825 ClientAuth: RequireAnyClientCert,
5826 MaxVersion: VersionTLS13,
5827 VerifySignatureAlgorithms: []signatureAlgorithm{
5828 signatureECDSAWithP521AndSHA512,
5829 signatureRSAPKCS1WithSHA384,
5830 signatureRSAPSSWithSHA384,
5831 signatureECDSAWithSHA1,
5832 },
5833 },
5834 flags: []string{
5835 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5836 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5837 },
5838 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5839 })
5840
5841 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005842 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005843 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005845 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005847 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005848 signatureECDSAWithP521AndSHA512,
5849 signatureRSAPKCS1WithSHA384,
5850 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005851 },
5852 },
Nick Harper60edffd2016-06-21 15:19:24 -07005853 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005854 })
5855
Steven Valdez143e8b32016-07-11 13:19:03 -04005856 testCases = append(testCases, testCase{
5857 testType: serverTest,
5858 name: "ServerAuth-SignatureType-TLS13",
5859 config: Config{
5860 MaxVersion: VersionTLS13,
5861 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5862 VerifySignatureAlgorithms: []signatureAlgorithm{
5863 signatureECDSAWithP521AndSHA512,
5864 signatureRSAPKCS1WithSHA384,
5865 signatureRSAPSSWithSHA384,
5866 signatureECDSAWithSHA1,
5867 },
5868 },
5869 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5870 })
5871
David Benjamina95e9f32016-07-08 16:28:04 -07005872 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005873 testCases = append(testCases, testCase{
5874 testType: serverTest,
5875 name: "Verify-ClientAuth-SignatureType",
5876 config: Config{
5877 MaxVersion: VersionTLS12,
5878 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005879 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005880 signatureRSAPKCS1WithSHA256,
5881 },
5882 Bugs: ProtocolBugs{
5883 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5884 },
5885 },
5886 flags: []string{
5887 "-require-any-client-certificate",
5888 },
5889 shouldFail: true,
5890 expectedError: ":WRONG_SIGNATURE_TYPE:",
5891 })
5892
5893 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005894 testType: serverTest,
5895 name: "Verify-ClientAuth-SignatureType-TLS13",
5896 config: Config{
5897 MaxVersion: VersionTLS13,
5898 Certificates: []Certificate{rsaCertificate},
5899 SignSignatureAlgorithms: []signatureAlgorithm{
5900 signatureRSAPSSWithSHA256,
5901 },
5902 Bugs: ProtocolBugs{
5903 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5904 },
5905 },
5906 flags: []string{
5907 "-require-any-client-certificate",
5908 },
5909 shouldFail: true,
5910 expectedError: ":WRONG_SIGNATURE_TYPE:",
5911 })
5912
5913 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005914 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005915 config: Config{
5916 MaxVersion: VersionTLS12,
5917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005918 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005919 signatureRSAPKCS1WithSHA256,
5920 },
5921 Bugs: ProtocolBugs{
5922 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5923 },
5924 },
5925 shouldFail: true,
5926 expectedError: ":WRONG_SIGNATURE_TYPE:",
5927 })
5928
Steven Valdez143e8b32016-07-11 13:19:03 -04005929 testCases = append(testCases, testCase{
5930 name: "Verify-ServerAuth-SignatureType-TLS13",
5931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5934 SignSignatureAlgorithms: []signatureAlgorithm{
5935 signatureRSAPSSWithSHA256,
5936 },
5937 Bugs: ProtocolBugs{
5938 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":WRONG_SIGNATURE_TYPE:",
5943 })
5944
David Benjamin51dd7d62016-07-08 16:07:01 -07005945 // Test that, if the list is missing, the peer falls back to SHA-1 in
5946 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005947 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005948 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005950 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005951 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005952 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005953 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005954 },
5955 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005956 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005957 },
5958 },
5959 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005960 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5961 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005962 },
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005967 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005968 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005969 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005970 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005971 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005972 },
5973 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005974 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005975 },
5976 },
David Benjaminee32bea2016-08-17 13:36:44 -04005977 flags: []string{
5978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5980 },
5981 })
5982
5983 testCases = append(testCases, testCase{
5984 name: "ClientAuth-SHA1-Fallback-ECDSA",
5985 config: Config{
5986 MaxVersion: VersionTLS12,
5987 ClientAuth: RequireAnyClientCert,
5988 VerifySignatureAlgorithms: []signatureAlgorithm{
5989 signatureECDSAWithSHA1,
5990 },
5991 Bugs: ProtocolBugs{
5992 NoSignatureAlgorithms: true,
5993 },
5994 },
5995 flags: []string{
5996 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5997 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5998 },
5999 })
6000
6001 testCases = append(testCases, testCase{
6002 testType: serverTest,
6003 name: "ServerAuth-SHA1-Fallback-ECDSA",
6004 config: Config{
6005 MaxVersion: VersionTLS12,
6006 VerifySignatureAlgorithms: []signatureAlgorithm{
6007 signatureECDSAWithSHA1,
6008 },
6009 Bugs: ProtocolBugs{
6010 NoSignatureAlgorithms: true,
6011 },
6012 },
6013 flags: []string{
6014 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6015 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6016 },
David Benjamin000800a2014-11-14 01:43:59 -05006017 })
David Benjamin72dc7832015-03-16 17:49:43 -04006018
David Benjamin51dd7d62016-07-08 16:07:01 -07006019 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006020 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006021 config: Config{
6022 MaxVersion: VersionTLS13,
6023 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006024 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006025 signatureRSAPKCS1WithSHA1,
6026 },
6027 Bugs: ProtocolBugs{
6028 NoSignatureAlgorithms: true,
6029 },
6030 },
6031 flags: []string{
6032 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6033 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6034 },
David Benjamin48901652016-08-01 12:12:47 -04006035 shouldFail: true,
6036 // An empty CertificateRequest signature algorithm list is a
6037 // syntax error in TLS 1.3.
6038 expectedError: ":DECODE_ERROR:",
6039 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006040 })
6041
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006044 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006045 config: Config{
6046 MaxVersion: VersionTLS13,
6047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006048 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006049 signatureRSAPKCS1WithSHA1,
6050 },
6051 Bugs: ProtocolBugs{
6052 NoSignatureAlgorithms: true,
6053 },
6054 },
6055 shouldFail: true,
6056 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6057 })
6058
David Benjaminb62d2872016-07-18 14:55:02 +02006059 // Test that hash preferences are enforced. BoringSSL does not implement
6060 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006061 testCases = append(testCases, testCase{
6062 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006063 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006065 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006066 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006067 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006068 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006069 },
6070 Bugs: ProtocolBugs{
6071 IgnorePeerSignatureAlgorithmPreferences: true,
6072 },
6073 },
6074 flags: []string{"-require-any-client-certificate"},
6075 shouldFail: true,
6076 expectedError: ":WRONG_SIGNATURE_TYPE:",
6077 })
6078
6079 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006080 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006082 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006083 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006084 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006085 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006086 },
6087 Bugs: ProtocolBugs{
6088 IgnorePeerSignatureAlgorithmPreferences: true,
6089 },
6090 },
6091 shouldFail: true,
6092 expectedError: ":WRONG_SIGNATURE_TYPE:",
6093 })
David Benjaminb62d2872016-07-18 14:55:02 +02006094 testCases = append(testCases, testCase{
6095 testType: serverTest,
6096 name: "ClientAuth-Enforced-TLS13",
6097 config: Config{
6098 MaxVersion: VersionTLS13,
6099 Certificates: []Certificate{rsaCertificate},
6100 SignSignatureAlgorithms: []signatureAlgorithm{
6101 signatureRSAPKCS1WithMD5,
6102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 IgnoreSignatureVersionChecks: true,
6106 },
6107 },
6108 flags: []string{"-require-any-client-certificate"},
6109 shouldFail: true,
6110 expectedError: ":WRONG_SIGNATURE_TYPE:",
6111 })
6112
6113 testCases = append(testCases, testCase{
6114 name: "ServerAuth-Enforced-TLS13",
6115 config: Config{
6116 MaxVersion: VersionTLS13,
6117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6118 SignSignatureAlgorithms: []signatureAlgorithm{
6119 signatureRSAPKCS1WithMD5,
6120 },
6121 Bugs: ProtocolBugs{
6122 IgnorePeerSignatureAlgorithmPreferences: true,
6123 IgnoreSignatureVersionChecks: true,
6124 },
6125 },
6126 shouldFail: true,
6127 expectedError: ":WRONG_SIGNATURE_TYPE:",
6128 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006129
6130 // Test that the agreed upon digest respects the client preferences and
6131 // the server digests.
6132 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006133 name: "NoCommonAlgorithms-Digests",
6134 config: Config{
6135 MaxVersion: VersionTLS12,
6136 ClientAuth: RequireAnyClientCert,
6137 VerifySignatureAlgorithms: []signatureAlgorithm{
6138 signatureRSAPKCS1WithSHA512,
6139 signatureRSAPKCS1WithSHA1,
6140 },
6141 },
6142 flags: []string{
6143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6145 "-digest-prefs", "SHA256",
6146 },
6147 shouldFail: true,
6148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6149 })
6150 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006151 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006153 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006154 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006155 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006156 signatureRSAPKCS1WithSHA512,
6157 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006158 },
6159 },
6160 flags: []string{
6161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006163 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006164 },
David Benjaminca3d5452016-07-14 12:51:01 -04006165 shouldFail: true,
6166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6167 })
6168 testCases = append(testCases, testCase{
6169 name: "NoCommonAlgorithms-TLS13",
6170 config: Config{
6171 MaxVersion: VersionTLS13,
6172 ClientAuth: RequireAnyClientCert,
6173 VerifySignatureAlgorithms: []signatureAlgorithm{
6174 signatureRSAPSSWithSHA512,
6175 signatureRSAPSSWithSHA384,
6176 },
6177 },
6178 flags: []string{
6179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6181 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6182 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006183 shouldFail: true,
6184 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006185 })
6186 testCases = append(testCases, testCase{
6187 name: "Agree-Digest-SHA256",
6188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006189 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006190 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006191 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006192 signatureRSAPKCS1WithSHA1,
6193 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006194 },
6195 },
6196 flags: []string{
6197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006199 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006200 },
Nick Harper60edffd2016-06-21 15:19:24 -07006201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006202 })
6203 testCases = append(testCases, testCase{
6204 name: "Agree-Digest-SHA1",
6205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006206 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006209 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006210 },
6211 },
6212 flags: []string{
6213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006215 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006216 },
Nick Harper60edffd2016-06-21 15:19:24 -07006217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 })
6219 testCases = append(testCases, testCase{
6220 name: "Agree-Digest-Default",
6221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006222 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006223 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006225 signatureRSAPKCS1WithSHA256,
6226 signatureECDSAWithP256AndSHA256,
6227 signatureRSAPKCS1WithSHA1,
6228 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006229 },
6230 },
6231 flags: []string{
6232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6234 },
Nick Harper60edffd2016-06-21 15:19:24 -07006235 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006236 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006237
David Benjaminca3d5452016-07-14 12:51:01 -04006238 // Test that the signing preference list may include extra algorithms
6239 // without negotiation problems.
6240 testCases = append(testCases, testCase{
6241 testType: serverTest,
6242 name: "FilterExtraAlgorithms",
6243 config: Config{
6244 MaxVersion: VersionTLS12,
6245 VerifySignatureAlgorithms: []signatureAlgorithm{
6246 signatureRSAPKCS1WithSHA256,
6247 },
6248 },
6249 flags: []string{
6250 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6251 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6252 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6253 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6254 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6255 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6256 },
6257 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6258 })
6259
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6261 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006262 testCases = append(testCases, testCase{
6263 name: "CheckLeafCurve",
6264 config: Config{
6265 MaxVersion: VersionTLS12,
6266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006267 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006268 },
6269 flags: []string{"-p384-only"},
6270 shouldFail: true,
6271 expectedError: ":BAD_ECC_CERT:",
6272 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006273
6274 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6275 testCases = append(testCases, testCase{
6276 name: "CheckLeafCurve-TLS13",
6277 config: Config{
6278 MaxVersion: VersionTLS13,
6279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6280 Certificates: []Certificate{ecdsaP256Certificate},
6281 },
6282 flags: []string{"-p384-only"},
6283 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006284
6285 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6286 testCases = append(testCases, testCase{
6287 name: "ECDSACurveMismatch-Verify-TLS12",
6288 config: Config{
6289 MaxVersion: VersionTLS12,
6290 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6291 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006292 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006293 signatureECDSAWithP384AndSHA384,
6294 },
6295 },
6296 })
6297
6298 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6299 testCases = append(testCases, testCase{
6300 name: "ECDSACurveMismatch-Verify-TLS13",
6301 config: Config{
6302 MaxVersion: VersionTLS13,
6303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6304 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006305 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006306 signatureECDSAWithP384AndSHA384,
6307 },
6308 Bugs: ProtocolBugs{
6309 SkipECDSACurveCheck: true,
6310 },
6311 },
6312 shouldFail: true,
6313 expectedError: ":WRONG_SIGNATURE_TYPE:",
6314 })
6315
6316 // Signature algorithm selection in TLS 1.3 should take the curve into
6317 // account.
6318 testCases = append(testCases, testCase{
6319 testType: serverTest,
6320 name: "ECDSACurveMismatch-Sign-TLS13",
6321 config: Config{
6322 MaxVersion: VersionTLS13,
6323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006324 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006325 signatureECDSAWithP384AndSHA384,
6326 signatureECDSAWithP256AndSHA256,
6327 },
6328 },
6329 flags: []string{
6330 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6331 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6332 },
6333 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6334 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006335
6336 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6337 // server does not attempt to sign in that case.
6338 testCases = append(testCases, testCase{
6339 testType: serverTest,
6340 name: "RSA-PSS-Large",
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 VerifySignatureAlgorithms: []signatureAlgorithm{
6344 signatureRSAPSSWithSHA512,
6345 },
6346 },
6347 flags: []string{
6348 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6349 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6350 },
6351 shouldFail: true,
6352 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6353 })
David Benjamin57e929f2016-08-30 00:30:38 -04006354
6355 // Test that RSA-PSS is enabled by default for TLS 1.2.
6356 testCases = append(testCases, testCase{
6357 testType: clientTest,
6358 name: "RSA-PSS-Default-Verify",
6359 config: Config{
6360 MaxVersion: VersionTLS12,
6361 SignSignatureAlgorithms: []signatureAlgorithm{
6362 signatureRSAPSSWithSHA256,
6363 },
6364 },
6365 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6366 })
6367
6368 testCases = append(testCases, testCase{
6369 testType: serverTest,
6370 name: "RSA-PSS-Default-Sign",
6371 config: Config{
6372 MaxVersion: VersionTLS12,
6373 VerifySignatureAlgorithms: []signatureAlgorithm{
6374 signatureRSAPSSWithSHA256,
6375 },
6376 },
6377 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6378 })
David Benjamin000800a2014-11-14 01:43:59 -05006379}
6380
David Benjamin83f90402015-01-27 01:09:43 -05006381// timeouts is the retransmit schedule for BoringSSL. It doubles and
6382// caps at 60 seconds. On the 13th timeout, it gives up.
6383var timeouts = []time.Duration{
6384 1 * time.Second,
6385 2 * time.Second,
6386 4 * time.Second,
6387 8 * time.Second,
6388 16 * time.Second,
6389 32 * time.Second,
6390 60 * time.Second,
6391 60 * time.Second,
6392 60 * time.Second,
6393 60 * time.Second,
6394 60 * time.Second,
6395 60 * time.Second,
6396 60 * time.Second,
6397}
6398
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006399// shortTimeouts is an alternate set of timeouts which would occur if the
6400// initial timeout duration was set to 250ms.
6401var shortTimeouts = []time.Duration{
6402 250 * time.Millisecond,
6403 500 * time.Millisecond,
6404 1 * time.Second,
6405 2 * time.Second,
6406 4 * time.Second,
6407 8 * time.Second,
6408 16 * time.Second,
6409 32 * time.Second,
6410 60 * time.Second,
6411 60 * time.Second,
6412 60 * time.Second,
6413 60 * time.Second,
6414 60 * time.Second,
6415}
6416
David Benjamin83f90402015-01-27 01:09:43 -05006417func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006418 // These tests work by coordinating some behavior on both the shim and
6419 // the runner.
6420 //
6421 // TimeoutSchedule configures the runner to send a series of timeout
6422 // opcodes to the shim (see packetAdaptor) immediately before reading
6423 // each peer handshake flight N. The timeout opcode both simulates a
6424 // timeout in the shim and acts as a synchronization point to help the
6425 // runner bracket each handshake flight.
6426 //
6427 // We assume the shim does not read from the channel eagerly. It must
6428 // first wait until it has sent flight N and is ready to receive
6429 // handshake flight N+1. At this point, it will process the timeout
6430 // opcode. It must then immediately respond with a timeout ACK and act
6431 // as if the shim was idle for the specified amount of time.
6432 //
6433 // The runner then drops all packets received before the ACK and
6434 // continues waiting for flight N. This ordering results in one attempt
6435 // at sending flight N to be dropped. For the test to complete, the
6436 // shim must send flight N again, testing that the shim implements DTLS
6437 // retransmit on a timeout.
6438
Steven Valdez143e8b32016-07-11 13:19:03 -04006439 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006440 // likely be more epochs to cross and the final message's retransmit may
6441 // be more complex.
6442
David Benjamin585d7a42016-06-02 14:58:00 -04006443 for _, async := range []bool{true, false} {
6444 var tests []testCase
6445
6446 // Test that this is indeed the timeout schedule. Stress all
6447 // four patterns of handshake.
6448 for i := 1; i < len(timeouts); i++ {
6449 number := strconv.Itoa(i)
6450 tests = append(tests, testCase{
6451 protocol: dtls,
6452 name: "DTLS-Retransmit-Client-" + number,
6453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006454 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006455 Bugs: ProtocolBugs{
6456 TimeoutSchedule: timeouts[:i],
6457 },
6458 },
6459 resumeSession: true,
6460 })
6461 tests = append(tests, testCase{
6462 protocol: dtls,
6463 testType: serverTest,
6464 name: "DTLS-Retransmit-Server-" + number,
6465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006466 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006467 Bugs: ProtocolBugs{
6468 TimeoutSchedule: timeouts[:i],
6469 },
6470 },
6471 resumeSession: true,
6472 })
6473 }
6474
6475 // Test that exceeding the timeout schedule hits a read
6476 // timeout.
6477 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006478 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006479 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006481 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006482 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006483 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006484 },
6485 },
6486 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006487 shouldFail: true,
6488 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006489 })
David Benjamin585d7a42016-06-02 14:58:00 -04006490
6491 if async {
6492 // Test that timeout handling has a fudge factor, due to API
6493 // problems.
6494 tests = append(tests, testCase{
6495 protocol: dtls,
6496 name: "DTLS-Retransmit-Fudge",
6497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006498 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006499 Bugs: ProtocolBugs{
6500 TimeoutSchedule: []time.Duration{
6501 timeouts[0] - 10*time.Millisecond,
6502 },
6503 },
6504 },
6505 resumeSession: true,
6506 })
6507 }
6508
6509 // Test that the final Finished retransmitting isn't
6510 // duplicated if the peer badly fragments everything.
6511 tests = append(tests, testCase{
6512 testType: serverTest,
6513 protocol: dtls,
6514 name: "DTLS-Retransmit-Fragmented",
6515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006517 Bugs: ProtocolBugs{
6518 TimeoutSchedule: []time.Duration{timeouts[0]},
6519 MaxHandshakeRecordLength: 2,
6520 },
6521 },
6522 })
6523
6524 // Test the timeout schedule when a shorter initial timeout duration is set.
6525 tests = append(tests, testCase{
6526 protocol: dtls,
6527 name: "DTLS-Retransmit-Short-Client",
6528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006529 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006530 Bugs: ProtocolBugs{
6531 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6532 },
6533 },
6534 resumeSession: true,
6535 flags: []string{"-initial-timeout-duration-ms", "250"},
6536 })
6537 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006538 protocol: dtls,
6539 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006540 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006542 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006543 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006544 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006545 },
6546 },
6547 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006548 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006549 })
David Benjamin585d7a42016-06-02 14:58:00 -04006550
6551 for _, test := range tests {
6552 if async {
6553 test.name += "-Async"
6554 test.flags = append(test.flags, "-async")
6555 }
6556
6557 testCases = append(testCases, test)
6558 }
David Benjamin83f90402015-01-27 01:09:43 -05006559 }
David Benjamin83f90402015-01-27 01:09:43 -05006560}
6561
David Benjaminc565ebb2015-04-03 04:06:36 -04006562func addExportKeyingMaterialTests() {
6563 for _, vers := range tlsVersions {
6564 if vers.version == VersionSSL30 {
6565 continue
6566 }
6567 testCases = append(testCases, testCase{
6568 name: "ExportKeyingMaterial-" + vers.name,
6569 config: Config{
6570 MaxVersion: vers.version,
6571 },
6572 exportKeyingMaterial: 1024,
6573 exportLabel: "label",
6574 exportContext: "context",
6575 useExportContext: true,
6576 })
6577 testCases = append(testCases, testCase{
6578 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6579 config: Config{
6580 MaxVersion: vers.version,
6581 },
6582 exportKeyingMaterial: 1024,
6583 })
6584 testCases = append(testCases, testCase{
6585 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6586 config: Config{
6587 MaxVersion: vers.version,
6588 },
6589 exportKeyingMaterial: 1024,
6590 useExportContext: true,
6591 })
6592 testCases = append(testCases, testCase{
6593 name: "ExportKeyingMaterial-Small-" + vers.name,
6594 config: Config{
6595 MaxVersion: vers.version,
6596 },
6597 exportKeyingMaterial: 1,
6598 exportLabel: "label",
6599 exportContext: "context",
6600 useExportContext: true,
6601 })
6602 }
6603 testCases = append(testCases, testCase{
6604 name: "ExportKeyingMaterial-SSL3",
6605 config: Config{
6606 MaxVersion: VersionSSL30,
6607 },
6608 exportKeyingMaterial: 1024,
6609 exportLabel: "label",
6610 exportContext: "context",
6611 useExportContext: true,
6612 shouldFail: true,
6613 expectedError: "failed to export keying material",
6614 })
6615}
6616
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006617func addTLSUniqueTests() {
6618 for _, isClient := range []bool{false, true} {
6619 for _, isResumption := range []bool{false, true} {
6620 for _, hasEMS := range []bool{false, true} {
6621 var suffix string
6622 if isResumption {
6623 suffix = "Resume-"
6624 } else {
6625 suffix = "Full-"
6626 }
6627
6628 if hasEMS {
6629 suffix += "EMS-"
6630 } else {
6631 suffix += "NoEMS-"
6632 }
6633
6634 if isClient {
6635 suffix += "Client"
6636 } else {
6637 suffix += "Server"
6638 }
6639
6640 test := testCase{
6641 name: "TLSUnique-" + suffix,
6642 testTLSUnique: true,
6643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006645 Bugs: ProtocolBugs{
6646 NoExtendedMasterSecret: !hasEMS,
6647 },
6648 },
6649 }
6650
6651 if isResumption {
6652 test.resumeSession = true
6653 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006654 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006655 Bugs: ProtocolBugs{
6656 NoExtendedMasterSecret: !hasEMS,
6657 },
6658 }
6659 }
6660
6661 if isResumption && !hasEMS {
6662 test.shouldFail = true
6663 test.expectedError = "failed to get tls-unique"
6664 }
6665
6666 testCases = append(testCases, test)
6667 }
6668 }
6669 }
6670}
6671
Adam Langley09505632015-07-30 18:10:13 -07006672func addCustomExtensionTests() {
6673 expectedContents := "custom extension"
6674 emptyString := ""
6675
6676 for _, isClient := range []bool{false, true} {
6677 suffix := "Server"
6678 flag := "-enable-server-custom-extension"
6679 testType := serverTest
6680 if isClient {
6681 suffix = "Client"
6682 flag = "-enable-client-custom-extension"
6683 testType = clientTest
6684 }
6685
6686 testCases = append(testCases, testCase{
6687 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006688 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006689 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006690 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006691 Bugs: ProtocolBugs{
6692 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006693 ExpectedCustomExtension: &expectedContents,
6694 },
6695 },
6696 flags: []string{flag},
6697 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006698 testCases = append(testCases, testCase{
6699 testType: testType,
6700 name: "CustomExtensions-" + suffix + "-TLS13",
6701 config: Config{
6702 MaxVersion: VersionTLS13,
6703 Bugs: ProtocolBugs{
6704 CustomExtension: expectedContents,
6705 ExpectedCustomExtension: &expectedContents,
6706 },
6707 },
6708 flags: []string{flag},
6709 })
Adam Langley09505632015-07-30 18:10:13 -07006710
6711 // If the parse callback fails, the handshake should also fail.
6712 testCases = append(testCases, testCase{
6713 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006714 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006716 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006717 Bugs: ProtocolBugs{
6718 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006719 ExpectedCustomExtension: &expectedContents,
6720 },
6721 },
David Benjamin399e7c92015-07-30 23:01:27 -04006722 flags: []string{flag},
6723 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006724 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6725 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006726 testCases = append(testCases, testCase{
6727 testType: testType,
6728 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6729 config: Config{
6730 MaxVersion: VersionTLS13,
6731 Bugs: ProtocolBugs{
6732 CustomExtension: expectedContents + "foo",
6733 ExpectedCustomExtension: &expectedContents,
6734 },
6735 },
6736 flags: []string{flag},
6737 shouldFail: true,
6738 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6739 })
Adam Langley09505632015-07-30 18:10:13 -07006740
6741 // If the add callback fails, the handshake should also fail.
6742 testCases = append(testCases, testCase{
6743 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006744 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006745 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006746 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006747 Bugs: ProtocolBugs{
6748 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006749 ExpectedCustomExtension: &expectedContents,
6750 },
6751 },
David Benjamin399e7c92015-07-30 23:01:27 -04006752 flags: []string{flag, "-custom-extension-fail-add"},
6753 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006754 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6755 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006756 testCases = append(testCases, testCase{
6757 testType: testType,
6758 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6759 config: Config{
6760 MaxVersion: VersionTLS13,
6761 Bugs: ProtocolBugs{
6762 CustomExtension: expectedContents,
6763 ExpectedCustomExtension: &expectedContents,
6764 },
6765 },
6766 flags: []string{flag, "-custom-extension-fail-add"},
6767 shouldFail: true,
6768 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6769 })
Adam Langley09505632015-07-30 18:10:13 -07006770
6771 // If the add callback returns zero, no extension should be
6772 // added.
6773 skipCustomExtension := expectedContents
6774 if isClient {
6775 // For the case where the client skips sending the
6776 // custom extension, the server must not “echo” it.
6777 skipCustomExtension = ""
6778 }
6779 testCases = append(testCases, testCase{
6780 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006781 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006783 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006784 Bugs: ProtocolBugs{
6785 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006786 ExpectedCustomExtension: &emptyString,
6787 },
6788 },
6789 flags: []string{flag, "-custom-extension-skip"},
6790 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006791 testCases = append(testCases, testCase{
6792 testType: testType,
6793 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6794 config: Config{
6795 MaxVersion: VersionTLS13,
6796 Bugs: ProtocolBugs{
6797 CustomExtension: skipCustomExtension,
6798 ExpectedCustomExtension: &emptyString,
6799 },
6800 },
6801 flags: []string{flag, "-custom-extension-skip"},
6802 })
Adam Langley09505632015-07-30 18:10:13 -07006803 }
6804
6805 // The custom extension add callback should not be called if the client
6806 // doesn't send the extension.
6807 testCases = append(testCases, testCase{
6808 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006809 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006811 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006812 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006813 ExpectedCustomExtension: &emptyString,
6814 },
6815 },
6816 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6817 })
Adam Langley2deb9842015-08-07 11:15:37 -07006818
Steven Valdez143e8b32016-07-11 13:19:03 -04006819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "CustomExtensions-NotCalled-Server-TLS13",
6822 config: Config{
6823 MaxVersion: VersionTLS13,
6824 Bugs: ProtocolBugs{
6825 ExpectedCustomExtension: &emptyString,
6826 },
6827 },
6828 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6829 })
6830
Adam Langley2deb9842015-08-07 11:15:37 -07006831 // Test an unknown extension from the server.
6832 testCases = append(testCases, testCase{
6833 testType: clientTest,
6834 name: "UnknownExtension-Client",
6835 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006836 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006837 Bugs: ProtocolBugs{
6838 CustomExtension: expectedContents,
6839 },
6840 },
David Benjamin0c40a962016-08-01 12:05:50 -04006841 shouldFail: true,
6842 expectedError: ":UNEXPECTED_EXTENSION:",
6843 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006844 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006845 testCases = append(testCases, testCase{
6846 testType: clientTest,
6847 name: "UnknownExtension-Client-TLS13",
6848 config: Config{
6849 MaxVersion: VersionTLS13,
6850 Bugs: ProtocolBugs{
6851 CustomExtension: expectedContents,
6852 },
6853 },
David Benjamin0c40a962016-08-01 12:05:50 -04006854 shouldFail: true,
6855 expectedError: ":UNEXPECTED_EXTENSION:",
6856 expectedLocalError: "remote error: unsupported extension",
6857 })
6858
6859 // Test a known but unoffered extension from the server.
6860 testCases = append(testCases, testCase{
6861 testType: clientTest,
6862 name: "UnofferedExtension-Client",
6863 config: Config{
6864 MaxVersion: VersionTLS12,
6865 Bugs: ProtocolBugs{
6866 SendALPN: "alpn",
6867 },
6868 },
6869 shouldFail: true,
6870 expectedError: ":UNEXPECTED_EXTENSION:",
6871 expectedLocalError: "remote error: unsupported extension",
6872 })
6873 testCases = append(testCases, testCase{
6874 testType: clientTest,
6875 name: "UnofferedExtension-Client-TLS13",
6876 config: Config{
6877 MaxVersion: VersionTLS13,
6878 Bugs: ProtocolBugs{
6879 SendALPN: "alpn",
6880 },
6881 },
6882 shouldFail: true,
6883 expectedError: ":UNEXPECTED_EXTENSION:",
6884 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006885 })
Adam Langley09505632015-07-30 18:10:13 -07006886}
6887
David Benjaminb36a3952015-12-01 18:53:13 -05006888func addRSAClientKeyExchangeTests() {
6889 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6893 config: Config{
6894 // Ensure the ClientHello version and final
6895 // version are different, to detect if the
6896 // server uses the wrong one.
6897 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006898 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006899 Bugs: ProtocolBugs{
6900 BadRSAClientKeyExchange: bad,
6901 },
6902 },
6903 shouldFail: true,
6904 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6905 })
6906 }
David Benjamine63d9d72016-09-19 18:27:34 -04006907
6908 // The server must compare whatever was in ClientHello.version for the
6909 // RSA premaster.
6910 testCases = append(testCases, testCase{
6911 testType: serverTest,
6912 name: "SendClientVersion-RSA",
6913 config: Config{
6914 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6915 Bugs: ProtocolBugs{
6916 SendClientVersion: 0x1234,
6917 },
6918 },
6919 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6920 })
David Benjaminb36a3952015-12-01 18:53:13 -05006921}
6922
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006923var testCurves = []struct {
6924 name string
6925 id CurveID
6926}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006927 {"P-256", CurveP256},
6928 {"P-384", CurveP384},
6929 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006930 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006931}
6932
Steven Valdez5440fe02016-07-18 12:40:30 -04006933const bogusCurve = 0x1234
6934
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006935func addCurveTests() {
6936 for _, curve := range testCurves {
6937 testCases = append(testCases, testCase{
6938 name: "CurveTest-Client-" + curve.name,
6939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006940 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006941 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6942 CurvePreferences: []CurveID{curve.id},
6943 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006944 flags: []string{
6945 "-enable-all-curves",
6946 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6947 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006948 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006949 })
6950 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006951 name: "CurveTest-Client-" + curve.name + "-TLS13",
6952 config: Config{
6953 MaxVersion: VersionTLS13,
6954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6955 CurvePreferences: []CurveID{curve.id},
6956 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006957 flags: []string{
6958 "-enable-all-curves",
6959 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6960 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006961 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006962 })
6963 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006964 testType: serverTest,
6965 name: "CurveTest-Server-" + curve.name,
6966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006967 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6969 CurvePreferences: []CurveID{curve.id},
6970 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006971 flags: []string{
6972 "-enable-all-curves",
6973 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6974 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006975 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006976 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006977 testCases = append(testCases, testCase{
6978 testType: serverTest,
6979 name: "CurveTest-Server-" + curve.name + "-TLS13",
6980 config: Config{
6981 MaxVersion: VersionTLS13,
6982 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6983 CurvePreferences: []CurveID{curve.id},
6984 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006985 flags: []string{
6986 "-enable-all-curves",
6987 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6988 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006989 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006990 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006991 }
David Benjamin241ae832016-01-15 03:04:54 -05006992
6993 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "UnknownCurve",
6997 config: Config{
6998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6999 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7000 },
7001 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007002
7003 // The server must not consider ECDHE ciphers when there are no
7004 // supported curves.
7005 testCases = append(testCases, testCase{
7006 testType: serverTest,
7007 name: "NoSupportedCurves",
7008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007009 MaxVersion: VersionTLS12,
7010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7011 Bugs: ProtocolBugs{
7012 NoSupportedCurves: true,
7013 },
7014 },
7015 shouldFail: true,
7016 expectedError: ":NO_SHARED_CIPHER:",
7017 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007018 testCases = append(testCases, testCase{
7019 testType: serverTest,
7020 name: "NoSupportedCurves-TLS13",
7021 config: Config{
7022 MaxVersion: VersionTLS13,
7023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7024 Bugs: ProtocolBugs{
7025 NoSupportedCurves: true,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedError: ":NO_SHARED_CIPHER:",
7030 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007031
7032 // The server must fall back to another cipher when there are no
7033 // supported curves.
7034 testCases = append(testCases, testCase{
7035 testType: serverTest,
7036 name: "NoCommonCurves",
7037 config: Config{
7038 MaxVersion: VersionTLS12,
7039 CipherSuites: []uint16{
7040 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7041 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7042 },
7043 CurvePreferences: []CurveID{CurveP224},
7044 },
7045 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7046 })
7047
7048 // The client must reject bogus curves and disabled curves.
7049 testCases = append(testCases, testCase{
7050 name: "BadECDHECurve",
7051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007052 MaxVersion: VersionTLS12,
7053 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7054 Bugs: ProtocolBugs{
7055 SendCurve: bogusCurve,
7056 },
7057 },
7058 shouldFail: true,
7059 expectedError: ":WRONG_CURVE:",
7060 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007061 testCases = append(testCases, testCase{
7062 name: "BadECDHECurve-TLS13",
7063 config: Config{
7064 MaxVersion: VersionTLS13,
7065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7066 Bugs: ProtocolBugs{
7067 SendCurve: bogusCurve,
7068 },
7069 },
7070 shouldFail: true,
7071 expectedError: ":WRONG_CURVE:",
7072 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007073
7074 testCases = append(testCases, testCase{
7075 name: "UnsupportedCurve",
7076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007077 MaxVersion: VersionTLS12,
7078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7079 CurvePreferences: []CurveID{CurveP256},
7080 Bugs: ProtocolBugs{
7081 IgnorePeerCurvePreferences: true,
7082 },
7083 },
7084 flags: []string{"-p384-only"},
7085 shouldFail: true,
7086 expectedError: ":WRONG_CURVE:",
7087 })
7088
David Benjamin4f921572016-07-17 14:20:10 +02007089 testCases = append(testCases, testCase{
7090 // TODO(davidben): Add a TLS 1.3 version where
7091 // HelloRetryRequest requests an unsupported curve.
7092 name: "UnsupportedCurve-ServerHello-TLS13",
7093 config: Config{
7094 MaxVersion: VersionTLS12,
7095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7096 CurvePreferences: []CurveID{CurveP384},
7097 Bugs: ProtocolBugs{
7098 SendCurve: CurveP256,
7099 },
7100 },
7101 flags: []string{"-p384-only"},
7102 shouldFail: true,
7103 expectedError: ":WRONG_CURVE:",
7104 })
7105
David Benjamin4c3ddf72016-06-29 18:13:53 -04007106 // Test invalid curve points.
7107 testCases = append(testCases, testCase{
7108 name: "InvalidECDHPoint-Client",
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 InvalidECDHPoint: true,
7115 },
7116 },
7117 shouldFail: true,
7118 expectedError: ":INVALID_ENCODING:",
7119 })
7120 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007121 name: "InvalidECDHPoint-Client-TLS13",
7122 config: Config{
7123 MaxVersion: VersionTLS13,
7124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7125 CurvePreferences: []CurveID{CurveP256},
7126 Bugs: ProtocolBugs{
7127 InvalidECDHPoint: true,
7128 },
7129 },
7130 shouldFail: true,
7131 expectedError: ":INVALID_ENCODING:",
7132 })
7133 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007134 testType: serverTest,
7135 name: "InvalidECDHPoint-Server",
7136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007137 MaxVersion: VersionTLS12,
7138 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7139 CurvePreferences: []CurveID{CurveP256},
7140 Bugs: ProtocolBugs{
7141 InvalidECDHPoint: true,
7142 },
7143 },
7144 shouldFail: true,
7145 expectedError: ":INVALID_ENCODING:",
7146 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007147 testCases = append(testCases, testCase{
7148 testType: serverTest,
7149 name: "InvalidECDHPoint-Server-TLS13",
7150 config: Config{
7151 MaxVersion: VersionTLS13,
7152 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7153 CurvePreferences: []CurveID{CurveP256},
7154 Bugs: ProtocolBugs{
7155 InvalidECDHPoint: true,
7156 },
7157 },
7158 shouldFail: true,
7159 expectedError: ":INVALID_ENCODING:",
7160 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007161}
7162
Matt Braithwaite54217e42016-06-13 13:03:47 -07007163func addCECPQ1Tests() {
7164 testCases = append(testCases, testCase{
7165 testType: clientTest,
7166 name: "CECPQ1-Client-BadX25519Part",
7167 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007168 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007169 MinVersion: VersionTLS12,
7170 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7171 Bugs: ProtocolBugs{
7172 CECPQ1BadX25519Part: true,
7173 },
7174 },
7175 flags: []string{"-cipher", "kCECPQ1"},
7176 shouldFail: true,
7177 expectedLocalError: "local error: bad record MAC",
7178 })
7179 testCases = append(testCases, testCase{
7180 testType: clientTest,
7181 name: "CECPQ1-Client-BadNewhopePart",
7182 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007183 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007184 MinVersion: VersionTLS12,
7185 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7186 Bugs: ProtocolBugs{
7187 CECPQ1BadNewhopePart: true,
7188 },
7189 },
7190 flags: []string{"-cipher", "kCECPQ1"},
7191 shouldFail: true,
7192 expectedLocalError: "local error: bad record MAC",
7193 })
7194 testCases = append(testCases, testCase{
7195 testType: serverTest,
7196 name: "CECPQ1-Server-BadX25519Part",
7197 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007198 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007199 MinVersion: VersionTLS12,
7200 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7201 Bugs: ProtocolBugs{
7202 CECPQ1BadX25519Part: true,
7203 },
7204 },
7205 flags: []string{"-cipher", "kCECPQ1"},
7206 shouldFail: true,
7207 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7208 })
7209 testCases = append(testCases, testCase{
7210 testType: serverTest,
7211 name: "CECPQ1-Server-BadNewhopePart",
7212 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007213 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007214 MinVersion: VersionTLS12,
7215 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7216 Bugs: ProtocolBugs{
7217 CECPQ1BadNewhopePart: true,
7218 },
7219 },
7220 flags: []string{"-cipher", "kCECPQ1"},
7221 shouldFail: true,
7222 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7223 })
7224}
7225
David Benjamin5c4e8572016-08-19 17:44:53 -04007226func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007227 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007228 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007229 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007230 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007231 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7232 Bugs: ProtocolBugs{
7233 // This is a 1234-bit prime number, generated
7234 // with:
7235 // openssl gendh 1234 | openssl asn1parse -i
7236 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7237 },
7238 },
David Benjamin9e68f192016-06-30 14:55:33 -04007239 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007240 })
7241 testCases = append(testCases, testCase{
7242 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007243 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007244 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007245 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007246 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7247 },
7248 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007249 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007250 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007251}
7252
David Benjaminc9ae27c2016-06-24 22:56:37 -04007253func addTLS13RecordTests() {
7254 testCases = append(testCases, testCase{
7255 name: "TLS13-RecordPadding",
7256 config: Config{
7257 MaxVersion: VersionTLS13,
7258 MinVersion: VersionTLS13,
7259 Bugs: ProtocolBugs{
7260 RecordPadding: 10,
7261 },
7262 },
7263 })
7264
7265 testCases = append(testCases, testCase{
7266 name: "TLS13-EmptyRecords",
7267 config: Config{
7268 MaxVersion: VersionTLS13,
7269 MinVersion: VersionTLS13,
7270 Bugs: ProtocolBugs{
7271 OmitRecordContents: true,
7272 },
7273 },
7274 shouldFail: true,
7275 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7276 })
7277
7278 testCases = append(testCases, testCase{
7279 name: "TLS13-OnlyPadding",
7280 config: Config{
7281 MaxVersion: VersionTLS13,
7282 MinVersion: VersionTLS13,
7283 Bugs: ProtocolBugs{
7284 OmitRecordContents: true,
7285 RecordPadding: 10,
7286 },
7287 },
7288 shouldFail: true,
7289 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7290 })
7291
7292 testCases = append(testCases, testCase{
7293 name: "TLS13-WrongOuterRecord",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 MinVersion: VersionTLS13,
7297 Bugs: ProtocolBugs{
7298 OuterRecordType: recordTypeHandshake,
7299 },
7300 },
7301 shouldFail: true,
7302 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7303 })
7304}
7305
David Benjamin82261be2016-07-07 14:32:50 -07007306func addChangeCipherSpecTests() {
7307 // Test missing ChangeCipherSpecs.
7308 testCases = append(testCases, testCase{
7309 name: "SkipChangeCipherSpec-Client",
7310 config: Config{
7311 MaxVersion: VersionTLS12,
7312 Bugs: ProtocolBugs{
7313 SkipChangeCipherSpec: true,
7314 },
7315 },
7316 shouldFail: true,
7317 expectedError: ":UNEXPECTED_RECORD:",
7318 })
7319 testCases = append(testCases, testCase{
7320 testType: serverTest,
7321 name: "SkipChangeCipherSpec-Server",
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 Bugs: ProtocolBugs{
7325 SkipChangeCipherSpec: true,
7326 },
7327 },
7328 shouldFail: true,
7329 expectedError: ":UNEXPECTED_RECORD:",
7330 })
7331 testCases = append(testCases, testCase{
7332 testType: serverTest,
7333 name: "SkipChangeCipherSpec-Server-NPN",
7334 config: Config{
7335 MaxVersion: VersionTLS12,
7336 NextProtos: []string{"bar"},
7337 Bugs: ProtocolBugs{
7338 SkipChangeCipherSpec: true,
7339 },
7340 },
7341 flags: []string{
7342 "-advertise-npn", "\x03foo\x03bar\x03baz",
7343 },
7344 shouldFail: true,
7345 expectedError: ":UNEXPECTED_RECORD:",
7346 })
7347
7348 // Test synchronization between the handshake and ChangeCipherSpec.
7349 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7350 // rejected. Test both with and without handshake packing to handle both
7351 // when the partial post-CCS message is in its own record and when it is
7352 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007353 for _, packed := range []bool{false, true} {
7354 var suffix string
7355 if packed {
7356 suffix = "-Packed"
7357 }
7358
7359 testCases = append(testCases, testCase{
7360 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7361 config: Config{
7362 MaxVersion: VersionTLS12,
7363 Bugs: ProtocolBugs{
7364 FragmentAcrossChangeCipherSpec: true,
7365 PackHandshakeFlight: packed,
7366 },
7367 },
7368 shouldFail: true,
7369 expectedError: ":UNEXPECTED_RECORD:",
7370 })
7371 testCases = append(testCases, testCase{
7372 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7373 config: Config{
7374 MaxVersion: VersionTLS12,
7375 },
7376 resumeSession: true,
7377 resumeConfig: &Config{
7378 MaxVersion: VersionTLS12,
7379 Bugs: ProtocolBugs{
7380 FragmentAcrossChangeCipherSpec: true,
7381 PackHandshakeFlight: packed,
7382 },
7383 },
7384 shouldFail: true,
7385 expectedError: ":UNEXPECTED_RECORD:",
7386 })
7387 testCases = append(testCases, testCase{
7388 testType: serverTest,
7389 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7390 config: Config{
7391 MaxVersion: VersionTLS12,
7392 Bugs: ProtocolBugs{
7393 FragmentAcrossChangeCipherSpec: true,
7394 PackHandshakeFlight: packed,
7395 },
7396 },
7397 shouldFail: true,
7398 expectedError: ":UNEXPECTED_RECORD:",
7399 })
7400 testCases = append(testCases, testCase{
7401 testType: serverTest,
7402 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7403 config: Config{
7404 MaxVersion: VersionTLS12,
7405 },
7406 resumeSession: true,
7407 resumeConfig: &Config{
7408 MaxVersion: VersionTLS12,
7409 Bugs: ProtocolBugs{
7410 FragmentAcrossChangeCipherSpec: true,
7411 PackHandshakeFlight: packed,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":UNEXPECTED_RECORD:",
7416 })
7417 testCases = append(testCases, testCase{
7418 testType: serverTest,
7419 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 NextProtos: []string{"bar"},
7423 Bugs: ProtocolBugs{
7424 FragmentAcrossChangeCipherSpec: true,
7425 PackHandshakeFlight: packed,
7426 },
7427 },
7428 flags: []string{
7429 "-advertise-npn", "\x03foo\x03bar\x03baz",
7430 },
7431 shouldFail: true,
7432 expectedError: ":UNEXPECTED_RECORD:",
7433 })
7434 }
7435
David Benjamin61672812016-07-14 23:10:43 -04007436 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7437 // messages in the handshake queue. Do this by testing the server
7438 // reading the client Finished, reversing the flight so Finished comes
7439 // first.
7440 testCases = append(testCases, testCase{
7441 protocol: dtls,
7442 testType: serverTest,
7443 name: "SendUnencryptedFinished-DTLS",
7444 config: Config{
7445 MaxVersion: VersionTLS12,
7446 Bugs: ProtocolBugs{
7447 SendUnencryptedFinished: true,
7448 ReverseHandshakeFragments: true,
7449 },
7450 },
7451 shouldFail: true,
7452 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7453 })
7454
Steven Valdez143e8b32016-07-11 13:19:03 -04007455 // Test synchronization between encryption changes and the handshake in
7456 // TLS 1.3, where ChangeCipherSpec is implicit.
7457 testCases = append(testCases, testCase{
7458 name: "PartialEncryptedExtensionsWithServerHello",
7459 config: Config{
7460 MaxVersion: VersionTLS13,
7461 Bugs: ProtocolBugs{
7462 PartialEncryptedExtensionsWithServerHello: true,
7463 },
7464 },
7465 shouldFail: true,
7466 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7467 })
7468 testCases = append(testCases, testCase{
7469 testType: serverTest,
7470 name: "PartialClientFinishedWithClientHello",
7471 config: Config{
7472 MaxVersion: VersionTLS13,
7473 Bugs: ProtocolBugs{
7474 PartialClientFinishedWithClientHello: true,
7475 },
7476 },
7477 shouldFail: true,
7478 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7479 })
7480
David Benjamin82261be2016-07-07 14:32:50 -07007481 // Test that early ChangeCipherSpecs are handled correctly.
7482 testCases = append(testCases, testCase{
7483 testType: serverTest,
7484 name: "EarlyChangeCipherSpec-server-1",
7485 config: Config{
7486 MaxVersion: VersionTLS12,
7487 Bugs: ProtocolBugs{
7488 EarlyChangeCipherSpec: 1,
7489 },
7490 },
7491 shouldFail: true,
7492 expectedError: ":UNEXPECTED_RECORD:",
7493 })
7494 testCases = append(testCases, testCase{
7495 testType: serverTest,
7496 name: "EarlyChangeCipherSpec-server-2",
7497 config: Config{
7498 MaxVersion: VersionTLS12,
7499 Bugs: ProtocolBugs{
7500 EarlyChangeCipherSpec: 2,
7501 },
7502 },
7503 shouldFail: true,
7504 expectedError: ":UNEXPECTED_RECORD:",
7505 })
7506 testCases = append(testCases, testCase{
7507 protocol: dtls,
7508 name: "StrayChangeCipherSpec",
7509 config: Config{
7510 // TODO(davidben): Once DTLS 1.3 exists, test
7511 // that stray ChangeCipherSpec messages are
7512 // rejected.
7513 MaxVersion: VersionTLS12,
7514 Bugs: ProtocolBugs{
7515 StrayChangeCipherSpec: true,
7516 },
7517 },
7518 })
7519
7520 // Test that the contents of ChangeCipherSpec are checked.
7521 testCases = append(testCases, testCase{
7522 name: "BadChangeCipherSpec-1",
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 Bugs: ProtocolBugs{
7526 BadChangeCipherSpec: []byte{2},
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7531 })
7532 testCases = append(testCases, testCase{
7533 name: "BadChangeCipherSpec-2",
7534 config: Config{
7535 MaxVersion: VersionTLS12,
7536 Bugs: ProtocolBugs{
7537 BadChangeCipherSpec: []byte{1, 1},
7538 },
7539 },
7540 shouldFail: true,
7541 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7542 })
7543 testCases = append(testCases, testCase{
7544 protocol: dtls,
7545 name: "BadChangeCipherSpec-DTLS-1",
7546 config: Config{
7547 MaxVersion: VersionTLS12,
7548 Bugs: ProtocolBugs{
7549 BadChangeCipherSpec: []byte{2},
7550 },
7551 },
7552 shouldFail: true,
7553 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7554 })
7555 testCases = append(testCases, testCase{
7556 protocol: dtls,
7557 name: "BadChangeCipherSpec-DTLS-2",
7558 config: Config{
7559 MaxVersion: VersionTLS12,
7560 Bugs: ProtocolBugs{
7561 BadChangeCipherSpec: []byte{1, 1},
7562 },
7563 },
7564 shouldFail: true,
7565 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7566 })
7567}
7568
David Benjamincd2c8062016-09-09 11:28:16 -04007569type perMessageTest struct {
7570 messageType uint8
7571 test testCase
7572}
7573
7574// makePerMessageTests returns a series of test templates which cover each
7575// message in the TLS handshake. These may be used with bugs like
7576// WrongMessageType to fully test a per-message bug.
7577func makePerMessageTests() []perMessageTest {
7578 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007579 for _, protocol := range []protocol{tls, dtls} {
7580 var suffix string
7581 if protocol == dtls {
7582 suffix = "-DTLS"
7583 }
7584
David Benjamincd2c8062016-09-09 11:28:16 -04007585 ret = append(ret, perMessageTest{
7586 messageType: typeClientHello,
7587 test: testCase{
7588 protocol: protocol,
7589 testType: serverTest,
7590 name: "ClientHello" + suffix,
7591 config: Config{
7592 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007593 },
7594 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007595 })
7596
7597 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007598 ret = append(ret, perMessageTest{
7599 messageType: typeHelloVerifyRequest,
7600 test: testCase{
7601 protocol: protocol,
7602 name: "HelloVerifyRequest" + suffix,
7603 config: Config{
7604 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007605 },
7606 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007607 })
7608 }
7609
David Benjamincd2c8062016-09-09 11:28:16 -04007610 ret = append(ret, perMessageTest{
7611 messageType: typeServerHello,
7612 test: testCase{
7613 protocol: protocol,
7614 name: "ServerHello" + suffix,
7615 config: Config{
7616 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007617 },
7618 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007619 })
7620
David Benjamincd2c8062016-09-09 11:28:16 -04007621 ret = append(ret, perMessageTest{
7622 messageType: typeCertificate,
7623 test: testCase{
7624 protocol: protocol,
7625 name: "ServerCertificate" + suffix,
7626 config: Config{
7627 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007628 },
7629 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007630 })
7631
David Benjamincd2c8062016-09-09 11:28:16 -04007632 ret = append(ret, perMessageTest{
7633 messageType: typeCertificateStatus,
7634 test: testCase{
7635 protocol: protocol,
7636 name: "CertificateStatus" + suffix,
7637 config: Config{
7638 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007639 },
David Benjamincd2c8062016-09-09 11:28:16 -04007640 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007641 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007642 })
7643
David Benjamincd2c8062016-09-09 11:28:16 -04007644 ret = append(ret, perMessageTest{
7645 messageType: typeServerKeyExchange,
7646 test: testCase{
7647 protocol: protocol,
7648 name: "ServerKeyExchange" + suffix,
7649 config: Config{
7650 MaxVersion: VersionTLS12,
7651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007652 },
7653 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007654 })
7655
David Benjamincd2c8062016-09-09 11:28:16 -04007656 ret = append(ret, perMessageTest{
7657 messageType: typeCertificateRequest,
7658 test: testCase{
7659 protocol: protocol,
7660 name: "CertificateRequest" + suffix,
7661 config: Config{
7662 MaxVersion: VersionTLS12,
7663 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007664 },
7665 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007666 })
7667
David Benjamincd2c8062016-09-09 11:28:16 -04007668 ret = append(ret, perMessageTest{
7669 messageType: typeServerHelloDone,
7670 test: testCase{
7671 protocol: protocol,
7672 name: "ServerHelloDone" + suffix,
7673 config: Config{
7674 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007675 },
7676 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007677 })
7678
David Benjamincd2c8062016-09-09 11:28:16 -04007679 ret = append(ret, perMessageTest{
7680 messageType: typeCertificate,
7681 test: testCase{
7682 testType: serverTest,
7683 protocol: protocol,
7684 name: "ClientCertificate" + suffix,
7685 config: Config{
7686 Certificates: []Certificate{rsaCertificate},
7687 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007688 },
David Benjamincd2c8062016-09-09 11:28:16 -04007689 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007690 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007691 })
7692
David Benjamincd2c8062016-09-09 11:28:16 -04007693 ret = append(ret, perMessageTest{
7694 messageType: typeCertificateVerify,
7695 test: testCase{
7696 testType: serverTest,
7697 protocol: protocol,
7698 name: "CertificateVerify" + suffix,
7699 config: Config{
7700 Certificates: []Certificate{rsaCertificate},
7701 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007702 },
David Benjamincd2c8062016-09-09 11:28:16 -04007703 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007704 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007705 })
7706
David Benjamincd2c8062016-09-09 11:28:16 -04007707 ret = append(ret, perMessageTest{
7708 messageType: typeClientKeyExchange,
7709 test: testCase{
7710 testType: serverTest,
7711 protocol: protocol,
7712 name: "ClientKeyExchange" + suffix,
7713 config: Config{
7714 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007715 },
7716 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007717 })
7718
7719 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007720 ret = append(ret, perMessageTest{
7721 messageType: typeNextProtocol,
7722 test: testCase{
7723 testType: serverTest,
7724 protocol: protocol,
7725 name: "NextProtocol" + suffix,
7726 config: Config{
7727 MaxVersion: VersionTLS12,
7728 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007729 },
David Benjamincd2c8062016-09-09 11:28:16 -04007730 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007731 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007732 })
7733
David Benjamincd2c8062016-09-09 11:28:16 -04007734 ret = append(ret, perMessageTest{
7735 messageType: typeChannelID,
7736 test: testCase{
7737 testType: serverTest,
7738 protocol: protocol,
7739 name: "ChannelID" + suffix,
7740 config: Config{
7741 MaxVersion: VersionTLS12,
7742 ChannelID: channelIDKey,
7743 },
7744 flags: []string{
7745 "-expect-channel-id",
7746 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007747 },
7748 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007749 })
7750 }
7751
David Benjamincd2c8062016-09-09 11:28:16 -04007752 ret = append(ret, perMessageTest{
7753 messageType: typeFinished,
7754 test: testCase{
7755 testType: serverTest,
7756 protocol: protocol,
7757 name: "ClientFinished" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007760 },
7761 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 })
7763
David Benjamincd2c8062016-09-09 11:28:16 -04007764 ret = append(ret, perMessageTest{
7765 messageType: typeNewSessionTicket,
7766 test: testCase{
7767 protocol: protocol,
7768 name: "NewSessionTicket" + suffix,
7769 config: Config{
7770 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007771 },
7772 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007773 })
7774
David Benjamincd2c8062016-09-09 11:28:16 -04007775 ret = append(ret, perMessageTest{
7776 messageType: typeFinished,
7777 test: testCase{
7778 protocol: protocol,
7779 name: "ServerFinished" + suffix,
7780 config: Config{
7781 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007782 },
7783 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007784 })
7785
7786 }
David Benjamincd2c8062016-09-09 11:28:16 -04007787
7788 ret = append(ret, perMessageTest{
7789 messageType: typeClientHello,
7790 test: testCase{
7791 testType: serverTest,
7792 name: "TLS13-ClientHello",
7793 config: Config{
7794 MaxVersion: VersionTLS13,
7795 },
7796 },
7797 })
7798
7799 ret = append(ret, perMessageTest{
7800 messageType: typeServerHello,
7801 test: testCase{
7802 name: "TLS13-ServerHello",
7803 config: Config{
7804 MaxVersion: VersionTLS13,
7805 },
7806 },
7807 })
7808
7809 ret = append(ret, perMessageTest{
7810 messageType: typeEncryptedExtensions,
7811 test: testCase{
7812 name: "TLS13-EncryptedExtensions",
7813 config: Config{
7814 MaxVersion: VersionTLS13,
7815 },
7816 },
7817 })
7818
7819 ret = append(ret, perMessageTest{
7820 messageType: typeCertificateRequest,
7821 test: testCase{
7822 name: "TLS13-CertificateRequest",
7823 config: Config{
7824 MaxVersion: VersionTLS13,
7825 ClientAuth: RequireAnyClientCert,
7826 },
7827 },
7828 })
7829
7830 ret = append(ret, perMessageTest{
7831 messageType: typeCertificate,
7832 test: testCase{
7833 name: "TLS13-ServerCertificate",
7834 config: Config{
7835 MaxVersion: VersionTLS13,
7836 },
7837 },
7838 })
7839
7840 ret = append(ret, perMessageTest{
7841 messageType: typeCertificateVerify,
7842 test: testCase{
7843 name: "TLS13-ServerCertificateVerify",
7844 config: Config{
7845 MaxVersion: VersionTLS13,
7846 },
7847 },
7848 })
7849
7850 ret = append(ret, perMessageTest{
7851 messageType: typeFinished,
7852 test: testCase{
7853 name: "TLS13-ServerFinished",
7854 config: Config{
7855 MaxVersion: VersionTLS13,
7856 },
7857 },
7858 })
7859
7860 ret = append(ret, perMessageTest{
7861 messageType: typeCertificate,
7862 test: testCase{
7863 testType: serverTest,
7864 name: "TLS13-ClientCertificate",
7865 config: Config{
7866 Certificates: []Certificate{rsaCertificate},
7867 MaxVersion: VersionTLS13,
7868 },
7869 flags: []string{"-require-any-client-certificate"},
7870 },
7871 })
7872
7873 ret = append(ret, perMessageTest{
7874 messageType: typeCertificateVerify,
7875 test: testCase{
7876 testType: serverTest,
7877 name: "TLS13-ClientCertificateVerify",
7878 config: Config{
7879 Certificates: []Certificate{rsaCertificate},
7880 MaxVersion: VersionTLS13,
7881 },
7882 flags: []string{"-require-any-client-certificate"},
7883 },
7884 })
7885
7886 ret = append(ret, perMessageTest{
7887 messageType: typeFinished,
7888 test: testCase{
7889 testType: serverTest,
7890 name: "TLS13-ClientFinished",
7891 config: Config{
7892 MaxVersion: VersionTLS13,
7893 },
7894 },
7895 })
7896
7897 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007898}
7899
David Benjamincd2c8062016-09-09 11:28:16 -04007900func addWrongMessageTypeTests() {
7901 for _, t := range makePerMessageTests() {
7902 t.test.name = "WrongMessageType-" + t.test.name
7903 t.test.config.Bugs.SendWrongMessageType = t.messageType
7904 t.test.shouldFail = true
7905 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7906 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007907
David Benjamincd2c8062016-09-09 11:28:16 -04007908 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7909 // In TLS 1.3, a bad ServerHello means the client sends
7910 // an unencrypted alert while the server expects
7911 // encryption, so the alert is not readable by runner.
7912 t.test.expectedLocalError = "local error: bad record MAC"
7913 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007914
David Benjamincd2c8062016-09-09 11:28:16 -04007915 testCases = append(testCases, t.test)
7916 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007917}
7918
David Benjamin639846e2016-09-09 11:41:18 -04007919func addTrailingMessageDataTests() {
7920 for _, t := range makePerMessageTests() {
7921 t.test.name = "TrailingMessageData-" + t.test.name
7922 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7923 t.test.shouldFail = true
7924 t.test.expectedError = ":DECODE_ERROR:"
7925 t.test.expectedLocalError = "remote error: error decoding message"
7926
7927 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7928 // In TLS 1.3, a bad ServerHello means the client sends
7929 // an unencrypted alert while the server expects
7930 // encryption, so the alert is not readable by runner.
7931 t.test.expectedLocalError = "local error: bad record MAC"
7932 }
7933
7934 if t.messageType == typeFinished {
7935 // Bad Finished messages read as the verify data having
7936 // the wrong length.
7937 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7938 t.test.expectedLocalError = "remote error: error decrypting message"
7939 }
7940
7941 testCases = append(testCases, t.test)
7942 }
7943}
7944
Steven Valdez143e8b32016-07-11 13:19:03 -04007945func addTLS13HandshakeTests() {
7946 testCases = append(testCases, testCase{
7947 testType: clientTest,
7948 name: "MissingKeyShare-Client",
7949 config: Config{
7950 MaxVersion: VersionTLS13,
7951 Bugs: ProtocolBugs{
7952 MissingKeyShare: true,
7953 },
7954 },
7955 shouldFail: true,
7956 expectedError: ":MISSING_KEY_SHARE:",
7957 })
7958
7959 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007960 testType: serverTest,
7961 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007962 config: Config{
7963 MaxVersion: VersionTLS13,
7964 Bugs: ProtocolBugs{
7965 MissingKeyShare: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":MISSING_KEY_SHARE:",
7970 })
7971
7972 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007973 testType: serverTest,
7974 name: "DuplicateKeyShares",
7975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 Bugs: ProtocolBugs{
7978 DuplicateKeyShares: true,
7979 },
7980 },
David Benjamin7e1f9842016-09-20 19:24:40 -04007981 shouldFail: true,
7982 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007983 })
7984
7985 testCases = append(testCases, testCase{
7986 testType: clientTest,
7987 name: "EmptyEncryptedExtensions",
7988 config: Config{
7989 MaxVersion: VersionTLS13,
7990 Bugs: ProtocolBugs{
7991 EmptyEncryptedExtensions: true,
7992 },
7993 },
7994 shouldFail: true,
7995 expectedLocalError: "remote error: error decoding message",
7996 })
7997
7998 testCases = append(testCases, testCase{
7999 testType: clientTest,
8000 name: "EncryptedExtensionsWithKeyShare",
8001 config: Config{
8002 MaxVersion: VersionTLS13,
8003 Bugs: ProtocolBugs{
8004 EncryptedExtensionsWithKeyShare: true,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedLocalError: "remote error: unsupported extension",
8009 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008010
8011 testCases = append(testCases, testCase{
8012 testType: serverTest,
8013 name: "SendHelloRetryRequest",
8014 config: Config{
8015 MaxVersion: VersionTLS13,
8016 // Require a HelloRetryRequest for every curve.
8017 DefaultCurves: []CurveID{},
8018 },
8019 expectedCurveID: CurveX25519,
8020 })
8021
8022 testCases = append(testCases, testCase{
8023 testType: serverTest,
8024 name: "SendHelloRetryRequest-2",
8025 config: Config{
8026 MaxVersion: VersionTLS13,
8027 DefaultCurves: []CurveID{CurveP384},
8028 },
8029 // Although the ClientHello did not predict our preferred curve,
8030 // we always select it whether it is predicted or not.
8031 expectedCurveID: CurveX25519,
8032 })
8033
8034 testCases = append(testCases, testCase{
8035 name: "UnknownCurve-HelloRetryRequest",
8036 config: Config{
8037 MaxVersion: VersionTLS13,
8038 // P-384 requires HelloRetryRequest in BoringSSL.
8039 CurvePreferences: []CurveID{CurveP384},
8040 Bugs: ProtocolBugs{
8041 SendHelloRetryRequestCurve: bogusCurve,
8042 },
8043 },
8044 shouldFail: true,
8045 expectedError: ":WRONG_CURVE:",
8046 })
8047
8048 testCases = append(testCases, testCase{
8049 name: "DisabledCurve-HelloRetryRequest",
8050 config: Config{
8051 MaxVersion: VersionTLS13,
8052 CurvePreferences: []CurveID{CurveP256},
8053 Bugs: ProtocolBugs{
8054 IgnorePeerCurvePreferences: true,
8055 },
8056 },
8057 flags: []string{"-p384-only"},
8058 shouldFail: true,
8059 expectedError: ":WRONG_CURVE:",
8060 })
8061
8062 testCases = append(testCases, testCase{
8063 name: "UnnecessaryHelloRetryRequest",
8064 config: Config{
8065 MaxVersion: VersionTLS13,
8066 Bugs: ProtocolBugs{
8067 UnnecessaryHelloRetryRequest: true,
8068 },
8069 },
8070 shouldFail: true,
8071 expectedError: ":WRONG_CURVE:",
8072 })
8073
8074 testCases = append(testCases, testCase{
8075 name: "SecondHelloRetryRequest",
8076 config: Config{
8077 MaxVersion: VersionTLS13,
8078 // P-384 requires HelloRetryRequest in BoringSSL.
8079 CurvePreferences: []CurveID{CurveP384},
8080 Bugs: ProtocolBugs{
8081 SecondHelloRetryRequest: true,
8082 },
8083 },
8084 shouldFail: true,
8085 expectedError: ":UNEXPECTED_MESSAGE:",
8086 })
8087
8088 testCases = append(testCases, testCase{
8089 testType: serverTest,
8090 name: "SecondClientHelloMissingKeyShare",
8091 config: Config{
8092 MaxVersion: VersionTLS13,
8093 DefaultCurves: []CurveID{},
8094 Bugs: ProtocolBugs{
8095 SecondClientHelloMissingKeyShare: true,
8096 },
8097 },
8098 shouldFail: true,
8099 expectedError: ":MISSING_KEY_SHARE:",
8100 })
8101
8102 testCases = append(testCases, testCase{
8103 testType: serverTest,
8104 name: "SecondClientHelloWrongCurve",
8105 config: Config{
8106 MaxVersion: VersionTLS13,
8107 DefaultCurves: []CurveID{},
8108 Bugs: ProtocolBugs{
8109 MisinterpretHelloRetryRequestCurve: CurveP521,
8110 },
8111 },
8112 shouldFail: true,
8113 expectedError: ":WRONG_CURVE:",
8114 })
8115
8116 testCases = append(testCases, testCase{
8117 name: "HelloRetryRequestVersionMismatch",
8118 config: Config{
8119 MaxVersion: VersionTLS13,
8120 // P-384 requires HelloRetryRequest in BoringSSL.
8121 CurvePreferences: []CurveID{CurveP384},
8122 Bugs: ProtocolBugs{
8123 SendServerHelloVersion: 0x0305,
8124 },
8125 },
8126 shouldFail: true,
8127 expectedError: ":WRONG_VERSION_NUMBER:",
8128 })
8129
8130 testCases = append(testCases, testCase{
8131 name: "HelloRetryRequestCurveMismatch",
8132 config: Config{
8133 MaxVersion: VersionTLS13,
8134 // P-384 requires HelloRetryRequest in BoringSSL.
8135 CurvePreferences: []CurveID{CurveP384},
8136 Bugs: ProtocolBugs{
8137 // Send P-384 (correct) in the HelloRetryRequest.
8138 SendHelloRetryRequestCurve: CurveP384,
8139 // But send P-256 in the ServerHello.
8140 SendCurve: CurveP256,
8141 },
8142 },
8143 shouldFail: true,
8144 expectedError: ":WRONG_CURVE:",
8145 })
8146
8147 // Test the server selecting a curve that requires a HelloRetryRequest
8148 // without sending it.
8149 testCases = append(testCases, testCase{
8150 name: "SkipHelloRetryRequest",
8151 config: Config{
8152 MaxVersion: VersionTLS13,
8153 // P-384 requires HelloRetryRequest in BoringSSL.
8154 CurvePreferences: []CurveID{CurveP384},
8155 Bugs: ProtocolBugs{
8156 SkipHelloRetryRequest: true,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":WRONG_CURVE:",
8161 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008162
8163 testCases = append(testCases, testCase{
8164 name: "TLS13-RequestContextInHandshake",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 MinVersion: VersionTLS13,
8168 ClientAuth: RequireAnyClientCert,
8169 Bugs: ProtocolBugs{
8170 SendRequestContext: []byte("request context"),
8171 },
8172 },
8173 flags: []string{
8174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8176 },
8177 shouldFail: true,
8178 expectedError: ":DECODE_ERROR:",
8179 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008180
8181 testCases = append(testCases, testCase{
8182 testType: serverTest,
8183 name: "TLS13-TrailingKeyShareData",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 Bugs: ProtocolBugs{
8187 TrailingKeyShareData: true,
8188 },
8189 },
8190 shouldFail: true,
8191 expectedError: ":DECODE_ERROR:",
8192 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008193}
8194
Adam Langley7c803a62015-06-15 15:35:05 -07008195func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008196 defer wg.Done()
8197
8198 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008199 var err error
8200
8201 if *mallocTest < 0 {
8202 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008203 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008204 } else {
8205 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8206 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008207 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008208 if err != nil {
8209 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8210 }
8211 break
8212 }
8213 }
8214 }
Adam Langley95c29f32014-06-20 12:00:00 -07008215 statusChan <- statusMsg{test: test, err: err}
8216 }
8217}
8218
8219type statusMsg struct {
8220 test *testCase
8221 started bool
8222 err error
8223}
8224
David Benjamin5f237bc2015-02-11 17:14:15 -05008225func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008226 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008227
David Benjamin5f237bc2015-02-11 17:14:15 -05008228 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008229 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008230 if !*pipe {
8231 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008232 var erase string
8233 for i := 0; i < lineLen; i++ {
8234 erase += "\b \b"
8235 }
8236 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008237 }
8238
Adam Langley95c29f32014-06-20 12:00:00 -07008239 if msg.started {
8240 started++
8241 } else {
8242 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008243
8244 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008245 if msg.err == errUnimplemented {
8246 if *pipe {
8247 // Print each test instead of a status line.
8248 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8249 }
8250 unimplemented++
8251 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8252 } else {
8253 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8254 failed++
8255 testOutput.addResult(msg.test.name, "FAIL")
8256 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008257 } else {
8258 if *pipe {
8259 // Print each test instead of a status line.
8260 fmt.Printf("PASSED (%s)\n", msg.test.name)
8261 }
8262 testOutput.addResult(msg.test.name, "PASS")
8263 }
Adam Langley95c29f32014-06-20 12:00:00 -07008264 }
8265
David Benjamin5f237bc2015-02-11 17:14:15 -05008266 if !*pipe {
8267 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008268 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008269 lineLen = len(line)
8270 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008271 }
Adam Langley95c29f32014-06-20 12:00:00 -07008272 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008273
8274 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008275}
8276
8277func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008278 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008279 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008280 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008281
Adam Langley7c803a62015-06-15 15:35:05 -07008282 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008283 addCipherSuiteTests()
8284 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008285 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008286 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008287 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008288 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008289 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008290 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008291 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008292 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008293 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008294 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008295 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008296 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008297 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008298 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008299 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008300 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008301 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008302 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008303 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008304 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008305 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008306 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008307 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008308 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008309 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008310 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008311
8312 var wg sync.WaitGroup
8313
Adam Langley7c803a62015-06-15 15:35:05 -07008314 statusChan := make(chan statusMsg, *numWorkers)
8315 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008316 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008317
EKRf71d7ed2016-08-06 13:25:12 -07008318 if len(*shimConfigFile) != 0 {
8319 encoded, err := ioutil.ReadFile(*shimConfigFile)
8320 if err != nil {
8321 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8322 os.Exit(1)
8323 }
8324
8325 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8326 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8327 os.Exit(1)
8328 }
8329 }
8330
David Benjamin025b3d32014-07-01 19:53:04 -04008331 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008332
Adam Langley7c803a62015-06-15 15:35:05 -07008333 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008334 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008335 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008336 }
8337
David Benjamin270f0a72016-03-17 14:41:36 -04008338 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008339 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008340 matched := true
8341 if len(*testToRun) != 0 {
8342 var err error
8343 matched, err = filepath.Match(*testToRun, testCases[i].name)
8344 if err != nil {
8345 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8346 os.Exit(1)
8347 }
8348 }
8349
EKRf71d7ed2016-08-06 13:25:12 -07008350 if !*includeDisabled {
8351 for pattern := range shimConfig.DisabledTests {
8352 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8353 if err != nil {
8354 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8355 os.Exit(1)
8356 }
8357
8358 if isDisabled {
8359 matched = false
8360 break
8361 }
8362 }
8363 }
8364
David Benjamin17e12922016-07-28 18:04:43 -04008365 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008366 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008367 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008368 }
8369 }
David Benjamin17e12922016-07-28 18:04:43 -04008370
David Benjamin270f0a72016-03-17 14:41:36 -04008371 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008372 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008373 os.Exit(1)
8374 }
Adam Langley95c29f32014-06-20 12:00:00 -07008375
8376 close(testChan)
8377 wg.Wait()
8378 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008379 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008380
8381 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008382
8383 if *jsonOutput != "" {
8384 if err := testOutput.writeTo(*jsonOutput); err != nil {
8385 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8386 }
8387 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008388
EKR842ae6c2016-07-27 09:22:05 +02008389 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8390 os.Exit(1)
8391 }
8392
8393 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008394 os.Exit(1)
8395 }
Adam Langley95c29f32014-06-20 12:00:00 -07008396}