blob: 5c70e912c7dceb33772b6fac268c65fd049eec2e [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
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
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"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020024 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070025 "flag"
26 "fmt"
27 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070028 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070029 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070030 "net"
31 "os"
32 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040033 "path"
David Benjamin17e12922016-07-28 18:04:43 -040034 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040035 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080036 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070037 "strings"
38 "sync"
39 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050040 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070041)
42
Adam Langley69a01602014-11-17 17:26:55 -080043var (
EKR842ae6c2016-07-27 09:22:05 +020044 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
45 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
46 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
47 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
48 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
49 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.")
50 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
51 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040052 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020053 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
54 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
55 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
56 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
57 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
58 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
59 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
60 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020061 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
Adam Langley69a01602014-11-17 17:26:55 -080062)
Adam Langley95c29f32014-06-20 12:00:00 -070063
David Benjamin33863262016-07-08 17:20:12 -070064type testCert int
65
David Benjamin025b3d32014-07-01 19:53:04 -040066const (
David Benjamin33863262016-07-08 17:20:12 -070067 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040068 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070069 testCertECDSAP256
70 testCertECDSAP384
71 testCertECDSAP521
72)
73
74const (
75 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040076 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070077 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
78 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
79 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040080)
81
82const (
David Benjamina08e49d2014-08-24 01:46:07 -040083 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040084 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070085 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
86 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
87 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040088 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040089)
90
David Benjamin7944a9f2016-07-12 22:27:01 -040091var (
92 rsaCertificate Certificate
93 rsa1024Certificate Certificate
94 ecdsaP256Certificate Certificate
95 ecdsaP384Certificate Certificate
96 ecdsaP521Certificate Certificate
97)
David Benjamin33863262016-07-08 17:20:12 -070098
99var testCerts = []struct {
100 id testCert
101 certFile, keyFile string
102 cert *Certificate
103}{
104 {
105 id: testCertRSA,
106 certFile: rsaCertificateFile,
107 keyFile: rsaKeyFile,
108 cert: &rsaCertificate,
109 },
110 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 id: testCertRSA1024,
112 certFile: rsa1024CertificateFile,
113 keyFile: rsa1024KeyFile,
114 cert: &rsa1024Certificate,
115 },
116 {
David Benjamin33863262016-07-08 17:20:12 -0700117 id: testCertECDSAP256,
118 certFile: ecdsaP256CertificateFile,
119 keyFile: ecdsaP256KeyFile,
120 cert: &ecdsaP256Certificate,
121 },
122 {
123 id: testCertECDSAP384,
124 certFile: ecdsaP384CertificateFile,
125 keyFile: ecdsaP384KeyFile,
126 cert: &ecdsaP384Certificate,
127 },
128 {
129 id: testCertECDSAP521,
130 certFile: ecdsaP521CertificateFile,
131 keyFile: ecdsaP521KeyFile,
132 cert: &ecdsaP521Certificate,
133 },
134}
135
David Benjamina08e49d2014-08-24 01:46:07 -0400136var channelIDKey *ecdsa.PrivateKey
137var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700138
David Benjamin61f95272014-11-25 01:55:35 -0500139var testOCSPResponse = []byte{1, 2, 3, 4}
140var testSCTList = []byte{5, 6, 7, 8}
141
Adam Langley95c29f32014-06-20 12:00:00 -0700142func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700143 for i := range testCerts {
144 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
145 if err != nil {
146 panic(err)
147 }
148 cert.OCSPStaple = testOCSPResponse
149 cert.SignedCertificateTimestampList = testSCTList
150 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700151 }
David Benjamina08e49d2014-08-24 01:46:07 -0400152
Adam Langley7c803a62015-06-15 15:35:05 -0700153 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400154 if err != nil {
155 panic(err)
156 }
157 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
158 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
159 panic("bad key type")
160 }
161 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
162 if err != nil {
163 panic(err)
164 }
165 if channelIDKey.Curve != elliptic.P256() {
166 panic("bad curve")
167 }
168
169 channelIDBytes = make([]byte, 64)
170 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
171 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700172}
173
David Benjamin33863262016-07-08 17:20:12 -0700174func getRunnerCertificate(t testCert) Certificate {
175 for _, cert := range testCerts {
176 if cert.id == t {
177 return *cert.cert
178 }
179 }
180 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700181}
182
David Benjamin33863262016-07-08 17:20:12 -0700183func getShimCertificate(t testCert) string {
184 for _, cert := range testCerts {
185 if cert.id == t {
186 return cert.certFile
187 }
188 }
189 panic("Unknown test certificate")
190}
191
192func getShimKey(t testCert) string {
193 for _, cert := range testCerts {
194 if cert.id == t {
195 return cert.keyFile
196 }
197 }
198 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700199}
200
David Benjamin025b3d32014-07-01 19:53:04 -0400201type testType int
202
203const (
204 clientTest testType = iota
205 serverTest
206)
207
David Benjamin6fd297b2014-08-11 18:43:38 -0400208type protocol int
209
210const (
211 tls protocol = iota
212 dtls
213)
214
David Benjaminfc7b0862014-09-06 13:21:53 -0400215const (
216 alpn = 1
217 npn = 2
218)
219
Adam Langley95c29f32014-06-20 12:00:00 -0700220type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400221 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400222 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700223 name string
224 config Config
225 shouldFail bool
226 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700227 // expectedLocalError, if not empty, contains a substring that must be
228 // found in the local error.
229 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400230 // expectedVersion, if non-zero, specifies the TLS version that must be
231 // negotiated.
232 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400233 // expectedResumeVersion, if non-zero, specifies the TLS version that
234 // must be negotiated on resumption. If zero, expectedVersion is used.
235 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400236 // expectedCipher, if non-zero, specifies the TLS cipher suite that
237 // should be negotiated.
238 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400239 // expectChannelID controls whether the connection should have
240 // negotiated a Channel ID with channelIDKey.
241 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400242 // expectedNextProto controls whether the connection should
243 // negotiate a next protocol via NPN or ALPN.
244 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400245 // expectNoNextProto, if true, means that no next protocol should be
246 // negotiated.
247 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400248 // expectedNextProtoType, if non-zero, is the expected next
249 // protocol negotiation mechanism.
250 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500251 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
252 // should be negotiated. If zero, none should be negotiated.
253 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100254 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
255 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100256 // expectedSCTList, if not nil, is the expected SCT list to be received.
257 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700258 // expectedPeerSignatureAlgorithm, if not zero, is the signature
259 // algorithm that the peer should have used in the handshake.
260 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400261 // expectedCurveID, if not zero, is the curve that the handshake should
262 // have used.
263 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700264 // messageLen is the length, in bytes, of the test message that will be
265 // sent.
266 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400267 // messageCount is the number of test messages that will be sent.
268 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400269 // certFile is the path to the certificate to use for the server.
270 certFile string
271 // keyFile is the path to the private key to use for the server.
272 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400273 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400274 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400275 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700276 // expectResumeRejected, if true, specifies that the attempted
277 // resumption must be rejected by the client. This is only valid for a
278 // serverTest.
279 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400280 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500281 // resumption. Unless newSessionsOnResume is set,
282 // SessionTicketKey, ServerSessionCache, and
283 // ClientSessionCache are copied from the initial connection's
284 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400285 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500286 // newSessionsOnResume, if true, will cause resumeConfig to
287 // use a different session resumption context.
288 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400289 // noSessionCache, if true, will cause the server to run without a
290 // session cache.
291 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400292 // sendPrefix sends a prefix on the socket before actually performing a
293 // handshake.
294 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400295 // shimWritesFirst controls whether the shim sends an initial "hello"
296 // message before doing a roundtrip with the runner.
297 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400298 // shimShutsDown, if true, runs a test where the shim shuts down the
299 // connection immediately after the handshake rather than echoing
300 // messages from the runner.
301 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400302 // renegotiate indicates the number of times the connection should be
303 // renegotiated during the exchange.
304 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400305 // sendHalfHelloRequest, if true, causes the server to send half a
306 // HelloRequest when the handshake completes.
307 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700308 // renegotiateCiphers is a list of ciphersuite ids that will be
309 // switched in just before renegotiation.
310 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500311 // replayWrites, if true, configures the underlying transport
312 // to replay every write it makes in DTLS tests.
313 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500314 // damageFirstWrite, if true, configures the underlying transport to
315 // damage the final byte of the first application data write.
316 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400317 // exportKeyingMaterial, if non-zero, configures the test to exchange
318 // keying material and verify they match.
319 exportKeyingMaterial int
320 exportLabel string
321 exportContext string
322 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400323 // flags, if not empty, contains a list of command-line flags that will
324 // be passed to the shim program.
325 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700326 // testTLSUnique, if true, causes the shim to send the tls-unique value
327 // which will be compared against the expected value.
328 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400329 // sendEmptyRecords is the number of consecutive empty records to send
330 // before and after the test message.
331 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400332 // sendWarningAlerts is the number of consecutive warning alerts to send
333 // before and after the test message.
334 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400335 // expectMessageDropped, if true, means the test message is expected to
336 // be dropped by the client rather than echoed back.
337 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700338}
339
Adam Langley7c803a62015-06-15 15:35:05 -0700340var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700341
David Benjamin9867b7d2016-03-01 23:25:48 -0500342func writeTranscript(test *testCase, isResume bool, data []byte) {
343 if len(data) == 0 {
344 return
345 }
346
347 protocol := "tls"
348 if test.protocol == dtls {
349 protocol = "dtls"
350 }
351
352 side := "client"
353 if test.testType == serverTest {
354 side = "server"
355 }
356
357 dir := path.Join(*transcriptDir, protocol, side)
358 if err := os.MkdirAll(dir, 0755); err != nil {
359 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
360 return
361 }
362
363 name := test.name
364 if isResume {
365 name += "-Resume"
366 } else {
367 name += "-Normal"
368 }
369
370 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
371 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
372 }
373}
374
David Benjamin3ed59772016-03-08 12:50:21 -0500375// A timeoutConn implements an idle timeout on each Read and Write operation.
376type timeoutConn struct {
377 net.Conn
378 timeout time.Duration
379}
380
381func (t *timeoutConn) Read(b []byte) (int, error) {
382 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
383 return 0, err
384 }
385 return t.Conn.Read(b)
386}
387
388func (t *timeoutConn) Write(b []byte) (int, error) {
389 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
390 return 0, err
391 }
392 return t.Conn.Write(b)
393}
394
David Benjamin8e6db492015-07-25 18:29:23 -0400395func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400396 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500397
David Benjamin6fd297b2014-08-11 18:43:38 -0400398 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500399 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
400 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500401 }
402
David Benjamin9867b7d2016-03-01 23:25:48 -0500403 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500404 local, peer := "client", "server"
405 if test.testType == clientTest {
406 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500407 }
David Benjaminebda9b32015-11-02 15:33:18 -0500408 connDebug := &recordingConn{
409 Conn: conn,
410 isDatagram: test.protocol == dtls,
411 local: local,
412 peer: peer,
413 }
414 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500415 if *flagDebug {
416 defer connDebug.WriteTo(os.Stdout)
417 }
418 if len(*transcriptDir) != 0 {
419 defer func() {
420 writeTranscript(test, isResume, connDebug.Transcript())
421 }()
422 }
David Benjaminebda9b32015-11-02 15:33:18 -0500423
424 if config.Bugs.PacketAdaptor != nil {
425 config.Bugs.PacketAdaptor.debug = connDebug
426 }
427 }
428
429 if test.replayWrites {
430 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400431 }
432
David Benjamin3ed59772016-03-08 12:50:21 -0500433 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500434 if test.damageFirstWrite {
435 connDamage = newDamageAdaptor(conn)
436 conn = connDamage
437 }
438
David Benjamin6fd297b2014-08-11 18:43:38 -0400439 if test.sendPrefix != "" {
440 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
441 return err
442 }
David Benjamin98e882e2014-08-08 13:24:34 -0400443 }
444
David Benjamin1d5c83e2014-07-22 19:20:02 -0400445 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400446 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400447 if test.protocol == dtls {
448 tlsConn = DTLSServer(conn, config)
449 } else {
450 tlsConn = Server(conn, config)
451 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400452 } else {
453 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400454 if test.protocol == dtls {
455 tlsConn = DTLSClient(conn, config)
456 } else {
457 tlsConn = Client(conn, config)
458 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400459 }
David Benjamin30789da2015-08-29 22:56:45 -0400460 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400461
Adam Langley95c29f32014-06-20 12:00:00 -0700462 if err := tlsConn.Handshake(); err != nil {
463 return err
464 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700465
David Benjamin01fe8202014-09-24 15:21:44 -0400466 // TODO(davidben): move all per-connection expectations into a dedicated
467 // expectations struct that can be specified separately for the two
468 // legs.
469 expectedVersion := test.expectedVersion
470 if isResume && test.expectedResumeVersion != 0 {
471 expectedVersion = test.expectedResumeVersion
472 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700473 connState := tlsConn.ConnectionState()
474 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400475 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400476 }
477
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700478 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400479 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
480 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700481 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
482 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
483 }
David Benjamin90da8c82015-04-20 14:57:57 -0400484
David Benjamina08e49d2014-08-24 01:46:07 -0400485 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700486 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400487 if channelID == nil {
488 return fmt.Errorf("no channel ID negotiated")
489 }
490 if channelID.Curve != channelIDKey.Curve ||
491 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
492 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
493 return fmt.Errorf("incorrect channel ID")
494 }
495 }
496
David Benjaminae2888f2014-09-06 12:58:58 -0400497 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700498 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400499 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
500 }
501 }
502
David Benjaminc7ce9772015-10-09 19:32:41 -0400503 if test.expectNoNextProto {
504 if actual := connState.NegotiatedProtocol; actual != "" {
505 return fmt.Errorf("got unexpected next proto %s", actual)
506 }
507 }
508
David Benjaminfc7b0862014-09-06 13:21:53 -0400509 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700510 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400511 return fmt.Errorf("next proto type mismatch")
512 }
513 }
514
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700515 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500516 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
517 }
518
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100519 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300520 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100521 }
522
Paul Lietar4fac72e2015-09-09 13:44:55 +0100523 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
524 return fmt.Errorf("SCT list mismatch")
525 }
526
Nick Harper60edffd2016-06-21 15:19:24 -0700527 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
528 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400529 }
530
Steven Valdez5440fe02016-07-18 12:40:30 -0400531 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
532 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
533 }
534
David Benjaminc565ebb2015-04-03 04:06:36 -0400535 if test.exportKeyingMaterial > 0 {
536 actual := make([]byte, test.exportKeyingMaterial)
537 if _, err := io.ReadFull(tlsConn, actual); err != nil {
538 return err
539 }
540 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
541 if err != nil {
542 return err
543 }
544 if !bytes.Equal(actual, expected) {
545 return fmt.Errorf("keying material mismatch")
546 }
547 }
548
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700549 if test.testTLSUnique {
550 var peersValue [12]byte
551 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
552 return err
553 }
554 expected := tlsConn.ConnectionState().TLSUnique
555 if !bytes.Equal(peersValue[:], expected) {
556 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
557 }
558 }
559
David Benjamine58c4f52014-08-24 03:47:07 -0400560 if test.shimWritesFirst {
561 var buf [5]byte
562 _, err := io.ReadFull(tlsConn, buf[:])
563 if err != nil {
564 return err
565 }
566 if string(buf[:]) != "hello" {
567 return fmt.Errorf("bad initial message")
568 }
569 }
570
David Benjamina8ebe222015-06-06 03:04:39 -0400571 for i := 0; i < test.sendEmptyRecords; i++ {
572 tlsConn.Write(nil)
573 }
574
David Benjamin24f346d2015-06-06 03:28:08 -0400575 for i := 0; i < test.sendWarningAlerts; i++ {
576 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
577 }
578
David Benjamin47921102016-07-28 11:29:18 -0400579 if test.sendHalfHelloRequest {
580 tlsConn.SendHalfHelloRequest()
581 }
582
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400583 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700584 if test.renegotiateCiphers != nil {
585 config.CipherSuites = test.renegotiateCiphers
586 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400587 for i := 0; i < test.renegotiate; i++ {
588 if err := tlsConn.Renegotiate(); err != nil {
589 return err
590 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700591 }
592 } else if test.renegotiateCiphers != nil {
593 panic("renegotiateCiphers without renegotiate")
594 }
595
David Benjamin5fa3eba2015-01-22 16:35:40 -0500596 if test.damageFirstWrite {
597 connDamage.setDamage(true)
598 tlsConn.Write([]byte("DAMAGED WRITE"))
599 connDamage.setDamage(false)
600 }
601
David Benjamin8e6db492015-07-25 18:29:23 -0400602 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700603 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400604 if test.protocol == dtls {
605 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
606 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700607 // Read until EOF.
608 _, err := io.Copy(ioutil.Discard, tlsConn)
609 return err
610 }
David Benjamin4417d052015-04-05 04:17:25 -0400611 if messageLen == 0 {
612 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700613 }
Adam Langley95c29f32014-06-20 12:00:00 -0700614
David Benjamin8e6db492015-07-25 18:29:23 -0400615 messageCount := test.messageCount
616 if messageCount == 0 {
617 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400618 }
619
David Benjamin8e6db492015-07-25 18:29:23 -0400620 for j := 0; j < messageCount; j++ {
621 testMessage := make([]byte, messageLen)
622 for i := range testMessage {
623 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400624 }
David Benjamin8e6db492015-07-25 18:29:23 -0400625 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700626
David Benjamin8e6db492015-07-25 18:29:23 -0400627 for i := 0; i < test.sendEmptyRecords; i++ {
628 tlsConn.Write(nil)
629 }
630
631 for i := 0; i < test.sendWarningAlerts; i++ {
632 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
633 }
634
David Benjamin4f75aaf2015-09-01 16:53:10 -0400635 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400636 // The shim will not respond.
637 continue
638 }
639
David Benjamin8e6db492015-07-25 18:29:23 -0400640 buf := make([]byte, len(testMessage))
641 if test.protocol == dtls {
642 bufTmp := make([]byte, len(buf)+1)
643 n, err := tlsConn.Read(bufTmp)
644 if err != nil {
645 return err
646 }
647 if n != len(buf) {
648 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
649 }
650 copy(buf, bufTmp)
651 } else {
652 _, err := io.ReadFull(tlsConn, buf)
653 if err != nil {
654 return err
655 }
656 }
657
658 for i, v := range buf {
659 if v != testMessage[i]^0xff {
660 return fmt.Errorf("bad reply contents at byte %d", i)
661 }
Adam Langley95c29f32014-06-20 12:00:00 -0700662 }
663 }
664
665 return nil
666}
667
David Benjamin325b5c32014-07-01 19:40:31 -0400668func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
669 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700670 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400671 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700672 }
David Benjamin325b5c32014-07-01 19:40:31 -0400673 valgrindArgs = append(valgrindArgs, path)
674 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700675
David Benjamin325b5c32014-07-01 19:40:31 -0400676 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700677}
678
David Benjamin325b5c32014-07-01 19:40:31 -0400679func gdbOf(path string, args ...string) *exec.Cmd {
680 xtermArgs := []string{"-e", "gdb", "--args"}
681 xtermArgs = append(xtermArgs, path)
682 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700683
David Benjamin325b5c32014-07-01 19:40:31 -0400684 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700685}
686
David Benjamind16bf342015-12-18 00:53:12 -0500687func lldbOf(path string, args ...string) *exec.Cmd {
688 xtermArgs := []string{"-e", "lldb", "--"}
689 xtermArgs = append(xtermArgs, path)
690 xtermArgs = append(xtermArgs, args...)
691
692 return exec.Command("xterm", xtermArgs...)
693}
694
EKR842ae6c2016-07-27 09:22:05 +0200695var (
696 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
697 errUnimplemented = errors.New("child process does not implement needed flags")
698)
Adam Langley69a01602014-11-17 17:26:55 -0800699
David Benjamin87c8a642015-02-21 01:54:29 -0500700// accept accepts a connection from listener, unless waitChan signals a process
701// exit first.
702func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
703 type connOrError struct {
704 conn net.Conn
705 err error
706 }
707 connChan := make(chan connOrError, 1)
708 go func() {
709 conn, err := listener.Accept()
710 connChan <- connOrError{conn, err}
711 close(connChan)
712 }()
713 select {
714 case result := <-connChan:
715 return result.conn, result.err
716 case childErr := <-waitChan:
717 waitChan <- childErr
718 return nil, fmt.Errorf("child exited early: %s", childErr)
719 }
720}
721
Adam Langley7c803a62015-06-15 15:35:05 -0700722func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700723 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
724 panic("Error expected without shouldFail in " + test.name)
725 }
726
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700727 if test.expectResumeRejected && !test.resumeSession {
728 panic("expectResumeRejected without resumeSession in " + test.name)
729 }
730
David Benjamin87c8a642015-02-21 01:54:29 -0500731 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
732 if err != nil {
733 panic(err)
734 }
735 defer func() {
736 if listener != nil {
737 listener.Close()
738 }
739 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700740
David Benjamin87c8a642015-02-21 01:54:29 -0500741 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400742 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400743 flags = append(flags, "-server")
744
David Benjamin025b3d32014-07-01 19:53:04 -0400745 flags = append(flags, "-key-file")
746 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700747 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400748 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700749 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400750 }
751
752 flags = append(flags, "-cert-file")
753 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700754 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400755 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700756 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400757 }
758 }
David Benjamin5a593af2014-08-11 19:51:50 -0400759
David Benjamin6fd297b2014-08-11 18:43:38 -0400760 if test.protocol == dtls {
761 flags = append(flags, "-dtls")
762 }
763
David Benjamin5a593af2014-08-11 19:51:50 -0400764 if test.resumeSession {
765 flags = append(flags, "-resume")
766 }
767
David Benjamine58c4f52014-08-24 03:47:07 -0400768 if test.shimWritesFirst {
769 flags = append(flags, "-shim-writes-first")
770 }
771
David Benjamin30789da2015-08-29 22:56:45 -0400772 if test.shimShutsDown {
773 flags = append(flags, "-shim-shuts-down")
774 }
775
David Benjaminc565ebb2015-04-03 04:06:36 -0400776 if test.exportKeyingMaterial > 0 {
777 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
778 flags = append(flags, "-export-label", test.exportLabel)
779 flags = append(flags, "-export-context", test.exportContext)
780 if test.useExportContext {
781 flags = append(flags, "-use-export-context")
782 }
783 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700784 if test.expectResumeRejected {
785 flags = append(flags, "-expect-session-miss")
786 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400787
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700788 if test.testTLSUnique {
789 flags = append(flags, "-tls-unique")
790 }
791
David Benjamin025b3d32014-07-01 19:53:04 -0400792 flags = append(flags, test.flags...)
793
794 var shim *exec.Cmd
795 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700796 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700797 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700798 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500799 } else if *useLLDB {
800 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400801 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700802 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400803 }
David Benjamin025b3d32014-07-01 19:53:04 -0400804 shim.Stdin = os.Stdin
805 var stdoutBuf, stderrBuf bytes.Buffer
806 shim.Stdout = &stdoutBuf
807 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800808 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500809 shim.Env = os.Environ()
810 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800811 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400812 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800813 }
814 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
815 }
David Benjamin025b3d32014-07-01 19:53:04 -0400816
817 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700818 panic(err)
819 }
David Benjamin87c8a642015-02-21 01:54:29 -0500820 waitChan := make(chan error, 1)
821 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700822
823 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400824 if !test.noSessionCache {
825 config.ClientSessionCache = NewLRUClientSessionCache(1)
826 config.ServerSessionCache = NewLRUServerSessionCache(1)
827 }
David Benjamin025b3d32014-07-01 19:53:04 -0400828 if test.testType == clientTest {
829 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700830 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400831 }
David Benjamin87c8a642015-02-21 01:54:29 -0500832 } else {
833 // Supply a ServerName to ensure a constant session cache key,
834 // rather than falling back to net.Conn.RemoteAddr.
835 if len(config.ServerName) == 0 {
836 config.ServerName = "test"
837 }
David Benjamin025b3d32014-07-01 19:53:04 -0400838 }
David Benjaminf2b83632016-03-01 22:57:46 -0500839 if *fuzzer {
840 config.Bugs.NullAllCiphers = true
841 }
David Benjamin2e045a92016-06-08 13:09:56 -0400842 if *deterministic {
843 config.Rand = &deterministicRand{}
844 }
Adam Langley95c29f32014-06-20 12:00:00 -0700845
David Benjamin87c8a642015-02-21 01:54:29 -0500846 conn, err := acceptOrWait(listener, waitChan)
847 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400848 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500849 conn.Close()
850 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500851
David Benjamin1d5c83e2014-07-22 19:20:02 -0400852 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400853 var resumeConfig Config
854 if test.resumeConfig != nil {
855 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500856 if len(resumeConfig.ServerName) == 0 {
857 resumeConfig.ServerName = config.ServerName
858 }
David Benjamin01fe8202014-09-24 15:21:44 -0400859 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700860 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400861 }
David Benjaminba4594a2015-06-18 18:36:15 -0400862 if test.newSessionsOnResume {
863 if !test.noSessionCache {
864 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
865 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
866 }
867 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500868 resumeConfig.SessionTicketKey = config.SessionTicketKey
869 resumeConfig.ClientSessionCache = config.ClientSessionCache
870 resumeConfig.ServerSessionCache = config.ServerSessionCache
871 }
David Benjaminf2b83632016-03-01 22:57:46 -0500872 if *fuzzer {
873 resumeConfig.Bugs.NullAllCiphers = true
874 }
David Benjamin2e045a92016-06-08 13:09:56 -0400875 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400876 } else {
877 resumeConfig = config
878 }
David Benjamin87c8a642015-02-21 01:54:29 -0500879 var connResume net.Conn
880 connResume, err = acceptOrWait(listener, waitChan)
881 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400882 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500883 connResume.Close()
884 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400885 }
886
David Benjamin87c8a642015-02-21 01:54:29 -0500887 // Close the listener now. This is to avoid hangs should the shim try to
888 // open more connections than expected.
889 listener.Close()
890 listener = nil
891
892 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800893 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200894 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
895 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800896 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200897 case 89:
898 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800899 }
900 }
Adam Langley95c29f32014-06-20 12:00:00 -0700901
David Benjamin9bea3492016-03-02 10:59:16 -0500902 // Account for Windows line endings.
903 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
904 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500905
906 // Separate the errors from the shim and those from tools like
907 // AddressSanitizer.
908 var extraStderr string
909 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
910 stderr = stderrParts[0]
911 extraStderr = stderrParts[1]
912 }
913
Adam Langley95c29f32014-06-20 12:00:00 -0700914 failed := err != nil || childErr != nil
EKR173bf932016-07-29 15:52:49 +0200915 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError) ||
916 (*looseErrors && strings.Contains(stderr, "UNTRANSLATED_ERROR"))
917
Adam Langleyac61fa32014-06-23 12:03:11 -0700918 localError := "none"
919 if err != nil {
920 localError = err.Error()
921 }
922 if len(test.expectedLocalError) != 0 {
923 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
924 }
Adam Langley95c29f32014-06-20 12:00:00 -0700925
926 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700927 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700928 if childErr != nil {
929 childError = childErr.Error()
930 }
931
932 var msg string
933 switch {
934 case failed && !test.shouldFail:
935 msg = "unexpected failure"
936 case !failed && test.shouldFail:
937 msg = "unexpected success"
938 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700939 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700940 default:
941 panic("internal error")
942 }
943
David Benjaminc565ebb2015-04-03 04:06:36 -0400944 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700945 }
946
David Benjaminff3a1492016-03-02 10:12:06 -0500947 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
948 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700949 }
950
951 return nil
952}
953
954var tlsVersions = []struct {
955 name string
956 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400957 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500958 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700959}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500960 {"SSL3", VersionSSL30, "-no-ssl3", false},
961 {"TLS1", VersionTLS10, "-no-tls1", true},
962 {"TLS11", VersionTLS11, "-no-tls11", false},
963 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400964 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700965}
966
967var testCipherSuites = []struct {
968 name string
969 id uint16
970}{
971 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400972 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400974 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400975 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700976 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400977 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400978 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
979 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400980 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400981 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
982 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400983 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700984 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
985 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400986 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
987 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700988 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400989 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500990 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500991 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700992 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700993 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700994 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400995 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400996 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700997 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400998 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500999 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001000 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001001 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001002 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1003 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1004 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1005 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001006 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1007 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001008 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1009 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001010 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001011 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1012 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001013 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001014 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001015 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001016 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001017}
1018
David Benjamin8b8c0062014-11-23 02:47:52 -05001019func hasComponent(suiteName, component string) bool {
1020 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1021}
1022
David Benjaminf7768e42014-08-31 02:06:47 -04001023func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001024 return hasComponent(suiteName, "GCM") ||
1025 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001026 hasComponent(suiteName, "SHA384") ||
1027 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001028}
1029
Nick Harper1fd39d82016-06-14 18:14:35 -07001030func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001031 // Only AEADs.
1032 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1033 return false
1034 }
1035 // No old CHACHA20_POLY1305.
1036 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1037 return false
1038 }
1039 // Must have ECDHE.
1040 // TODO(davidben,svaldez): Add pure PSK support.
1041 if !hasComponent(suiteName, "ECDHE") {
1042 return false
1043 }
1044 // TODO(davidben,svaldez): Add PSK support.
1045 if hasComponent(suiteName, "PSK") {
1046 return false
1047 }
1048 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001049}
1050
David Benjamin8b8c0062014-11-23 02:47:52 -05001051func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001052 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001053}
1054
Adam Langleya7997f12015-05-14 17:38:50 -07001055func bigFromHex(hex string) *big.Int {
1056 ret, ok := new(big.Int).SetString(hex, 16)
1057 if !ok {
1058 panic("failed to parse hex number 0x" + hex)
1059 }
1060 return ret
1061}
1062
Adam Langley7c803a62015-06-15 15:35:05 -07001063func addBasicTests() {
1064 basicTests := []testCase{
1065 {
Adam Langley7c803a62015-06-15 15:35:05 -07001066 name: "NoFallbackSCSV",
1067 config: Config{
1068 Bugs: ProtocolBugs{
1069 FailIfNotFallbackSCSV: true,
1070 },
1071 },
1072 shouldFail: true,
1073 expectedLocalError: "no fallback SCSV found",
1074 },
1075 {
1076 name: "SendFallbackSCSV",
1077 config: Config{
1078 Bugs: ProtocolBugs{
1079 FailIfNotFallbackSCSV: true,
1080 },
1081 },
1082 flags: []string{"-fallback-scsv"},
1083 },
1084 {
1085 name: "ClientCertificateTypes",
1086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001087 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001088 ClientAuth: RequestClientCert,
1089 ClientCertificateTypes: []byte{
1090 CertTypeDSSSign,
1091 CertTypeRSASign,
1092 CertTypeECDSASign,
1093 },
1094 },
1095 flags: []string{
1096 "-expect-certificate-types",
1097 base64.StdEncoding.EncodeToString([]byte{
1098 CertTypeDSSSign,
1099 CertTypeRSASign,
1100 CertTypeECDSASign,
1101 }),
1102 },
1103 },
1104 {
Adam Langley7c803a62015-06-15 15:35:05 -07001105 name: "UnauthenticatedECDH",
1106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001107 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1109 Bugs: ProtocolBugs{
1110 UnauthenticatedECDH: true,
1111 },
1112 },
1113 shouldFail: true,
1114 expectedError: ":UNEXPECTED_MESSAGE:",
1115 },
1116 {
1117 name: "SkipCertificateStatus",
1118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001119 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001120 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1121 Bugs: ProtocolBugs{
1122 SkipCertificateStatus: true,
1123 },
1124 },
1125 flags: []string{
1126 "-enable-ocsp-stapling",
1127 },
1128 },
1129 {
1130 name: "SkipServerKeyExchange",
1131 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001132 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001133 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1134 Bugs: ProtocolBugs{
1135 SkipServerKeyExchange: true,
1136 },
1137 },
1138 shouldFail: true,
1139 expectedError: ":UNEXPECTED_MESSAGE:",
1140 },
1141 {
Adam Langley7c803a62015-06-15 15:35:05 -07001142 testType: serverTest,
1143 name: "Alert",
1144 config: Config{
1145 Bugs: ProtocolBugs{
1146 SendSpuriousAlert: alertRecordOverflow,
1147 },
1148 },
1149 shouldFail: true,
1150 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1151 },
1152 {
1153 protocol: dtls,
1154 testType: serverTest,
1155 name: "Alert-DTLS",
1156 config: Config{
1157 Bugs: ProtocolBugs{
1158 SendSpuriousAlert: alertRecordOverflow,
1159 },
1160 },
1161 shouldFail: true,
1162 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1163 },
1164 {
1165 testType: serverTest,
1166 name: "FragmentAlert",
1167 config: Config{
1168 Bugs: ProtocolBugs{
1169 FragmentAlert: true,
1170 SendSpuriousAlert: alertRecordOverflow,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedError: ":BAD_ALERT:",
1175 },
1176 {
1177 protocol: dtls,
1178 testType: serverTest,
1179 name: "FragmentAlert-DTLS",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 FragmentAlert: true,
1183 SendSpuriousAlert: alertRecordOverflow,
1184 },
1185 },
1186 shouldFail: true,
1187 expectedError: ":BAD_ALERT:",
1188 },
1189 {
1190 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001191 name: "DoubleAlert",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 DoubleAlert: true,
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":BAD_ALERT:",
1200 },
1201 {
1202 protocol: dtls,
1203 testType: serverTest,
1204 name: "DoubleAlert-DTLS",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 DoubleAlert: true,
1208 SendSpuriousAlert: alertRecordOverflow,
1209 },
1210 },
1211 shouldFail: true,
1212 expectedError: ":BAD_ALERT:",
1213 },
1214 {
Adam Langley7c803a62015-06-15 15:35:05 -07001215 name: "SkipNewSessionTicket",
1216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001217 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001218 Bugs: ProtocolBugs{
1219 SkipNewSessionTicket: true,
1220 },
1221 },
1222 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001223 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001224 },
1225 {
1226 testType: serverTest,
1227 name: "FallbackSCSV",
1228 config: Config{
1229 MaxVersion: VersionTLS11,
1230 Bugs: ProtocolBugs{
1231 SendFallbackSCSV: true,
1232 },
1233 },
1234 shouldFail: true,
1235 expectedError: ":INAPPROPRIATE_FALLBACK:",
1236 },
1237 {
1238 testType: serverTest,
1239 name: "FallbackSCSV-VersionMatch",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 SendFallbackSCSV: true,
1243 },
1244 },
1245 },
1246 {
1247 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001248 name: "FallbackSCSV-VersionMatch-TLS12",
1249 config: Config{
1250 MaxVersion: VersionTLS12,
1251 Bugs: ProtocolBugs{
1252 SendFallbackSCSV: true,
1253 },
1254 },
1255 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1256 },
1257 {
1258 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001259 name: "FragmentedClientVersion",
1260 config: Config{
1261 Bugs: ProtocolBugs{
1262 MaxHandshakeRecordLength: 1,
1263 FragmentClientVersion: true,
1264 },
1265 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001266 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001267 },
1268 {
Adam Langley7c803a62015-06-15 15:35:05 -07001269 testType: serverTest,
1270 name: "HttpGET",
1271 sendPrefix: "GET / HTTP/1.0\n",
1272 shouldFail: true,
1273 expectedError: ":HTTP_REQUEST:",
1274 },
1275 {
1276 testType: serverTest,
1277 name: "HttpPOST",
1278 sendPrefix: "POST / HTTP/1.0\n",
1279 shouldFail: true,
1280 expectedError: ":HTTP_REQUEST:",
1281 },
1282 {
1283 testType: serverTest,
1284 name: "HttpHEAD",
1285 sendPrefix: "HEAD / HTTP/1.0\n",
1286 shouldFail: true,
1287 expectedError: ":HTTP_REQUEST:",
1288 },
1289 {
1290 testType: serverTest,
1291 name: "HttpPUT",
1292 sendPrefix: "PUT / HTTP/1.0\n",
1293 shouldFail: true,
1294 expectedError: ":HTTP_REQUEST:",
1295 },
1296 {
1297 testType: serverTest,
1298 name: "HttpCONNECT",
1299 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1300 shouldFail: true,
1301 expectedError: ":HTTPS_PROXY_REQUEST:",
1302 },
1303 {
1304 testType: serverTest,
1305 name: "Garbage",
1306 sendPrefix: "blah",
1307 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001308 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 name: "RSAEphemeralKey",
1312 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001313 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001314 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1315 Bugs: ProtocolBugs{
1316 RSAEphemeralKey: true,
1317 },
1318 },
1319 shouldFail: true,
1320 expectedError: ":UNEXPECTED_MESSAGE:",
1321 },
1322 {
1323 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001324 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001325 shouldFail: true,
1326 expectedError: ":WRONG_SSL_VERSION:",
1327 },
1328 {
1329 protocol: dtls,
1330 name: "DisableEverything-DTLS",
1331 flags: []string{"-no-tls12", "-no-tls1"},
1332 shouldFail: true,
1333 expectedError: ":WRONG_SSL_VERSION:",
1334 },
1335 {
Adam Langley7c803a62015-06-15 15:35:05 -07001336 protocol: dtls,
1337 testType: serverTest,
1338 name: "MTU",
1339 config: Config{
1340 Bugs: ProtocolBugs{
1341 MaxPacketLength: 256,
1342 },
1343 },
1344 flags: []string{"-mtu", "256"},
1345 },
1346 {
1347 protocol: dtls,
1348 testType: serverTest,
1349 name: "MTUExceeded",
1350 config: Config{
1351 Bugs: ProtocolBugs{
1352 MaxPacketLength: 255,
1353 },
1354 },
1355 flags: []string{"-mtu", "256"},
1356 shouldFail: true,
1357 expectedLocalError: "dtls: exceeded maximum packet length",
1358 },
1359 {
1360 name: "CertMismatchRSA",
1361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001362 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001363 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001364 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001365 Bugs: ProtocolBugs{
1366 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1371 },
1372 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001373 name: "CertMismatchRSA-TLS13",
1374 config: Config{
1375 MaxVersion: VersionTLS13,
1376 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1377 Certificates: []Certificate{ecdsaP256Certificate},
1378 Bugs: ProtocolBugs{
1379 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1384 },
1385 {
Adam Langley7c803a62015-06-15 15:35:05 -07001386 name: "CertMismatchECDSA",
1387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001388 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001389 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001390 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001391 Bugs: ProtocolBugs{
1392 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1397 },
1398 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001399 name: "CertMismatchECDSA-TLS13",
1400 config: Config{
1401 MaxVersion: VersionTLS13,
1402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1403 Certificates: []Certificate{rsaCertificate},
1404 Bugs: ProtocolBugs{
1405 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1406 },
1407 },
1408 shouldFail: true,
1409 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1410 },
1411 {
Adam Langley7c803a62015-06-15 15:35:05 -07001412 name: "EmptyCertificateList",
1413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001414 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1416 Bugs: ProtocolBugs{
1417 EmptyCertificateList: true,
1418 },
1419 },
1420 shouldFail: true,
1421 expectedError: ":DECODE_ERROR:",
1422 },
1423 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001424 name: "EmptyCertificateList-TLS13",
1425 config: Config{
1426 MaxVersion: VersionTLS13,
1427 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1428 Bugs: ProtocolBugs{
1429 EmptyCertificateList: true,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":DECODE_ERROR:",
1434 },
1435 {
Adam Langley7c803a62015-06-15 15:35:05 -07001436 name: "TLSFatalBadPackets",
1437 damageFirstWrite: true,
1438 shouldFail: true,
1439 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1440 },
1441 {
1442 protocol: dtls,
1443 name: "DTLSIgnoreBadPackets",
1444 damageFirstWrite: true,
1445 },
1446 {
1447 protocol: dtls,
1448 name: "DTLSIgnoreBadPackets-Async",
1449 damageFirstWrite: true,
1450 flags: []string{"-async"},
1451 },
1452 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001453 name: "AppDataBeforeHandshake",
1454 config: Config{
1455 Bugs: ProtocolBugs{
1456 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1457 },
1458 },
1459 shouldFail: true,
1460 expectedError: ":UNEXPECTED_RECORD:",
1461 },
1462 {
1463 name: "AppDataBeforeHandshake-Empty",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AppDataBeforeHandshake: []byte{},
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":UNEXPECTED_RECORD:",
1471 },
1472 {
1473 protocol: dtls,
1474 name: "AppDataBeforeHandshake-DTLS",
1475 config: Config{
1476 Bugs: ProtocolBugs{
1477 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1478 },
1479 },
1480 shouldFail: true,
1481 expectedError: ":UNEXPECTED_RECORD:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "AppDataBeforeHandshake-DTLS-Empty",
1486 config: Config{
1487 Bugs: ProtocolBugs{
1488 AppDataBeforeHandshake: []byte{},
1489 },
1490 },
1491 shouldFail: true,
1492 expectedError: ":UNEXPECTED_RECORD:",
1493 },
1494 {
Adam Langley7c803a62015-06-15 15:35:05 -07001495 name: "AppDataAfterChangeCipherSpec",
1496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001497 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001498 Bugs: ProtocolBugs{
1499 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1500 },
1501 },
1502 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001503 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001504 },
1505 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001506 name: "AppDataAfterChangeCipherSpec-Empty",
1507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001508 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001509 Bugs: ProtocolBugs{
1510 AppDataAfterChangeCipherSpec: []byte{},
1511 },
1512 },
1513 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001514 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001515 },
1516 {
Adam Langley7c803a62015-06-15 15:35:05 -07001517 protocol: dtls,
1518 name: "AppDataAfterChangeCipherSpec-DTLS",
1519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001520 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001521 Bugs: ProtocolBugs{
1522 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1523 },
1524 },
1525 // BoringSSL's DTLS implementation will drop the out-of-order
1526 // application data.
1527 },
1528 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001529 protocol: dtls,
1530 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte{},
1535 },
1536 },
1537 // BoringSSL's DTLS implementation will drop the out-of-order
1538 // application data.
1539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "AlertAfterChangeCipherSpec",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 AlertAfterChangeCipherSpec: alertRecordOverflow,
1546 },
1547 },
1548 shouldFail: true,
1549 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1550 },
1551 {
1552 protocol: dtls,
1553 name: "AlertAfterChangeCipherSpec-DTLS",
1554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001555 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001556 Bugs: ProtocolBugs{
1557 AlertAfterChangeCipherSpec: alertRecordOverflow,
1558 },
1559 },
1560 shouldFail: true,
1561 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1562 },
1563 {
1564 protocol: dtls,
1565 name: "ReorderHandshakeFragments-Small-DTLS",
1566 config: Config{
1567 Bugs: ProtocolBugs{
1568 ReorderHandshakeFragments: true,
1569 // Small enough that every handshake message is
1570 // fragmented.
1571 MaxHandshakeRecordLength: 2,
1572 },
1573 },
1574 },
1575 {
1576 protocol: dtls,
1577 name: "ReorderHandshakeFragments-Large-DTLS",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 ReorderHandshakeFragments: true,
1581 // Large enough that no handshake message is
1582 // fragmented.
1583 MaxHandshakeRecordLength: 2048,
1584 },
1585 },
1586 },
1587 {
1588 protocol: dtls,
1589 name: "MixCompleteMessageWithFragments-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 MixCompleteMessageWithFragments: true,
1594 MaxHandshakeRecordLength: 2,
1595 },
1596 },
1597 },
1598 {
1599 name: "SendInvalidRecordType",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 SendInvalidRecordType: true,
1603 },
1604 },
1605 shouldFail: true,
1606 expectedError: ":UNEXPECTED_RECORD:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "SendInvalidRecordType-DTLS",
1611 config: Config{
1612 Bugs: ProtocolBugs{
1613 SendInvalidRecordType: true,
1614 },
1615 },
1616 shouldFail: true,
1617 expectedError: ":UNEXPECTED_RECORD:",
1618 },
1619 {
1620 name: "FalseStart-SkipServerSecondLeg",
1621 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001622 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1624 NextProtos: []string{"foo"},
1625 Bugs: ProtocolBugs{
1626 SkipNewSessionTicket: true,
1627 SkipChangeCipherSpec: true,
1628 SkipFinished: true,
1629 ExpectFalseStart: true,
1630 },
1631 },
1632 flags: []string{
1633 "-false-start",
1634 "-handshake-never-done",
1635 "-advertise-alpn", "\x03foo",
1636 },
1637 shimWritesFirst: true,
1638 shouldFail: true,
1639 expectedError: ":UNEXPECTED_RECORD:",
1640 },
1641 {
1642 name: "FalseStart-SkipServerSecondLeg-Implicit",
1643 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001644 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001645 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1646 NextProtos: []string{"foo"},
1647 Bugs: ProtocolBugs{
1648 SkipNewSessionTicket: true,
1649 SkipChangeCipherSpec: true,
1650 SkipFinished: true,
1651 },
1652 },
1653 flags: []string{
1654 "-implicit-handshake",
1655 "-false-start",
1656 "-handshake-never-done",
1657 "-advertise-alpn", "\x03foo",
1658 },
1659 shouldFail: true,
1660 expectedError: ":UNEXPECTED_RECORD:",
1661 },
1662 {
1663 testType: serverTest,
1664 name: "FailEarlyCallback",
1665 flags: []string{"-fail-early-callback"},
1666 shouldFail: true,
1667 expectedError: ":CONNECTION_REJECTED:",
1668 expectedLocalError: "remote error: access denied",
1669 },
1670 {
Adam Langley7c803a62015-06-15 15:35:05 -07001671 protocol: dtls,
1672 name: "FragmentMessageTypeMismatch-DTLS",
1673 config: Config{
1674 Bugs: ProtocolBugs{
1675 MaxHandshakeRecordLength: 2,
1676 FragmentMessageTypeMismatch: true,
1677 },
1678 },
1679 shouldFail: true,
1680 expectedError: ":FRAGMENT_MISMATCH:",
1681 },
1682 {
1683 protocol: dtls,
1684 name: "FragmentMessageLengthMismatch-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 MaxHandshakeRecordLength: 2,
1688 FragmentMessageLengthMismatch: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":FRAGMENT_MISMATCH:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "SplitFragments-Header-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 SplitFragments: 2,
1700 },
1701 },
1702 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001703 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001704 },
1705 {
1706 protocol: dtls,
1707 name: "SplitFragments-Boundary-DTLS",
1708 config: Config{
1709 Bugs: ProtocolBugs{
1710 SplitFragments: dtlsRecordHeaderLen,
1711 },
1712 },
1713 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001714 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001715 },
1716 {
1717 protocol: dtls,
1718 name: "SplitFragments-Body-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 SplitFragments: dtlsRecordHeaderLen + 1,
1722 },
1723 },
1724 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001725 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001726 },
1727 {
1728 protocol: dtls,
1729 name: "SendEmptyFragments-DTLS",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 SendEmptyFragments: true,
1733 },
1734 },
1735 },
1736 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001737 name: "BadFinished-Client",
1738 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001739 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001740 Bugs: ProtocolBugs{
1741 BadFinished: true,
1742 },
1743 },
1744 shouldFail: true,
1745 expectedError: ":DIGEST_CHECK_FAILED:",
1746 },
1747 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001748 name: "BadFinished-Client-TLS13",
1749 config: Config{
1750 MaxVersion: VersionTLS13,
1751 Bugs: ProtocolBugs{
1752 BadFinished: true,
1753 },
1754 },
1755 shouldFail: true,
1756 expectedError: ":DIGEST_CHECK_FAILED:",
1757 },
1758 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001759 testType: serverTest,
1760 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001762 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001763 Bugs: ProtocolBugs{
1764 BadFinished: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":DIGEST_CHECK_FAILED:",
1769 },
1770 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001771 testType: serverTest,
1772 name: "BadFinished-Server-TLS13",
1773 config: Config{
1774 MaxVersion: VersionTLS13,
1775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
Adam Langley7c803a62015-06-15 15:35:05 -07001783 name: "FalseStart-BadFinished",
1784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001785 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1787 NextProtos: []string{"foo"},
1788 Bugs: ProtocolBugs{
1789 BadFinished: true,
1790 ExpectFalseStart: true,
1791 },
1792 },
1793 flags: []string{
1794 "-false-start",
1795 "-handshake-never-done",
1796 "-advertise-alpn", "\x03foo",
1797 },
1798 shimWritesFirst: true,
1799 shouldFail: true,
1800 expectedError: ":DIGEST_CHECK_FAILED:",
1801 },
1802 {
1803 name: "NoFalseStart-NoALPN",
1804 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001805 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1807 Bugs: ProtocolBugs{
1808 ExpectFalseStart: true,
1809 AlertBeforeFalseStartTest: alertAccessDenied,
1810 },
1811 },
1812 flags: []string{
1813 "-false-start",
1814 },
1815 shimWritesFirst: true,
1816 shouldFail: true,
1817 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1818 expectedLocalError: "tls: peer did not false start: EOF",
1819 },
1820 {
1821 name: "NoFalseStart-NoAEAD",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1825 NextProtos: []string{"foo"},
1826 Bugs: ProtocolBugs{
1827 ExpectFalseStart: true,
1828 AlertBeforeFalseStartTest: alertAccessDenied,
1829 },
1830 },
1831 flags: []string{
1832 "-false-start",
1833 "-advertise-alpn", "\x03foo",
1834 },
1835 shimWritesFirst: true,
1836 shouldFail: true,
1837 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1838 expectedLocalError: "tls: peer did not false start: EOF",
1839 },
1840 {
1841 name: "NoFalseStart-RSA",
1842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001843 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001844 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1845 NextProtos: []string{"foo"},
1846 Bugs: ProtocolBugs{
1847 ExpectFalseStart: true,
1848 AlertBeforeFalseStartTest: alertAccessDenied,
1849 },
1850 },
1851 flags: []string{
1852 "-false-start",
1853 "-advertise-alpn", "\x03foo",
1854 },
1855 shimWritesFirst: true,
1856 shouldFail: true,
1857 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1858 expectedLocalError: "tls: peer did not false start: EOF",
1859 },
1860 {
1861 name: "NoFalseStart-DHE_RSA",
1862 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001863 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001864 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1865 NextProtos: []string{"foo"},
1866 Bugs: ProtocolBugs{
1867 ExpectFalseStart: true,
1868 AlertBeforeFalseStartTest: alertAccessDenied,
1869 },
1870 },
1871 flags: []string{
1872 "-false-start",
1873 "-advertise-alpn", "\x03foo",
1874 },
1875 shimWritesFirst: true,
1876 shouldFail: true,
1877 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1878 expectedLocalError: "tls: peer did not false start: EOF",
1879 },
1880 {
Adam Langley7c803a62015-06-15 15:35:05 -07001881 protocol: dtls,
1882 name: "SendSplitAlert-Sync",
1883 config: Config{
1884 Bugs: ProtocolBugs{
1885 SendSplitAlert: true,
1886 },
1887 },
1888 },
1889 {
1890 protocol: dtls,
1891 name: "SendSplitAlert-Async",
1892 config: Config{
1893 Bugs: ProtocolBugs{
1894 SendSplitAlert: true,
1895 },
1896 },
1897 flags: []string{"-async"},
1898 },
1899 {
1900 protocol: dtls,
1901 name: "PackDTLSHandshake",
1902 config: Config{
1903 Bugs: ProtocolBugs{
1904 MaxHandshakeRecordLength: 2,
1905 PackHandshakeFragments: 20,
1906 PackHandshakeRecords: 200,
1907 },
1908 },
1909 },
1910 {
Adam Langley7c803a62015-06-15 15:35:05 -07001911 name: "SendEmptyRecords-Pass",
1912 sendEmptyRecords: 32,
1913 },
1914 {
1915 name: "SendEmptyRecords",
1916 sendEmptyRecords: 33,
1917 shouldFail: true,
1918 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1919 },
1920 {
1921 name: "SendEmptyRecords-Async",
1922 sendEmptyRecords: 33,
1923 flags: []string{"-async"},
1924 shouldFail: true,
1925 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1926 },
1927 {
1928 name: "SendWarningAlerts-Pass",
1929 sendWarningAlerts: 4,
1930 },
1931 {
1932 protocol: dtls,
1933 name: "SendWarningAlerts-DTLS-Pass",
1934 sendWarningAlerts: 4,
1935 },
1936 {
1937 name: "SendWarningAlerts",
1938 sendWarningAlerts: 5,
1939 shouldFail: true,
1940 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1941 },
1942 {
1943 name: "SendWarningAlerts-Async",
1944 sendWarningAlerts: 5,
1945 flags: []string{"-async"},
1946 shouldFail: true,
1947 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1948 },
David Benjaminba4594a2015-06-18 18:36:15 -04001949 {
1950 name: "EmptySessionID",
1951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001952 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001953 SessionTicketsDisabled: true,
1954 },
1955 noSessionCache: true,
1956 flags: []string{"-expect-no-session"},
1957 },
David Benjamin30789da2015-08-29 22:56:45 -04001958 {
1959 name: "Unclean-Shutdown",
1960 config: Config{
1961 Bugs: ProtocolBugs{
1962 NoCloseNotify: true,
1963 ExpectCloseNotify: true,
1964 },
1965 },
1966 shimShutsDown: true,
1967 flags: []string{"-check-close-notify"},
1968 shouldFail: true,
1969 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1970 },
1971 {
1972 name: "Unclean-Shutdown-Ignored",
1973 config: Config{
1974 Bugs: ProtocolBugs{
1975 NoCloseNotify: true,
1976 },
1977 },
1978 shimShutsDown: true,
1979 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001980 {
David Benjaminfa214e42016-05-10 17:03:10 -04001981 name: "Unclean-Shutdown-Alert",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 SendAlertOnShutdown: alertDecompressionFailure,
1985 ExpectCloseNotify: true,
1986 },
1987 },
1988 shimShutsDown: true,
1989 flags: []string{"-check-close-notify"},
1990 shouldFail: true,
1991 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1992 },
1993 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001994 name: "LargePlaintext",
1995 config: Config{
1996 Bugs: ProtocolBugs{
1997 SendLargeRecords: true,
1998 },
1999 },
2000 messageLen: maxPlaintext + 1,
2001 shouldFail: true,
2002 expectedError: ":DATA_LENGTH_TOO_LONG:",
2003 },
2004 {
2005 protocol: dtls,
2006 name: "LargePlaintext-DTLS",
2007 config: Config{
2008 Bugs: ProtocolBugs{
2009 SendLargeRecords: true,
2010 },
2011 },
2012 messageLen: maxPlaintext + 1,
2013 shouldFail: true,
2014 expectedError: ":DATA_LENGTH_TOO_LONG:",
2015 },
2016 {
2017 name: "LargeCiphertext",
2018 config: Config{
2019 Bugs: ProtocolBugs{
2020 SendLargeRecords: true,
2021 },
2022 },
2023 messageLen: maxPlaintext * 2,
2024 shouldFail: true,
2025 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2026 },
2027 {
2028 protocol: dtls,
2029 name: "LargeCiphertext-DTLS",
2030 config: Config{
2031 Bugs: ProtocolBugs{
2032 SendLargeRecords: true,
2033 },
2034 },
2035 messageLen: maxPlaintext * 2,
2036 // Unlike the other four cases, DTLS drops records which
2037 // are invalid before authentication, so the connection
2038 // does not fail.
2039 expectMessageDropped: true,
2040 },
David Benjamindd6fed92015-10-23 17:41:12 -04002041 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002042 // In TLS 1.2 and below, empty NewSessionTicket messages
2043 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002044 name: "SendEmptySessionTicket",
2045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002046 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002047 Bugs: ProtocolBugs{
2048 SendEmptySessionTicket: true,
2049 FailIfSessionOffered: true,
2050 },
2051 },
2052 flags: []string{"-expect-no-session"},
2053 resumeSession: true,
2054 expectResumeRejected: true,
2055 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002056 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002057 name: "BadHelloRequest-1",
2058 renegotiate: 1,
2059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002060 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002061 Bugs: ProtocolBugs{
2062 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2063 },
2064 },
2065 flags: []string{
2066 "-renegotiate-freely",
2067 "-expect-total-renegotiations", "1",
2068 },
2069 shouldFail: true,
2070 expectedError: ":BAD_HELLO_REQUEST:",
2071 },
2072 {
2073 name: "BadHelloRequest-2",
2074 renegotiate: 1,
2075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002076 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002077 Bugs: ProtocolBugs{
2078 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2079 },
2080 },
2081 flags: []string{
2082 "-renegotiate-freely",
2083 "-expect-total-renegotiations", "1",
2084 },
2085 shouldFail: true,
2086 expectedError: ":BAD_HELLO_REQUEST:",
2087 },
David Benjaminef1b0092015-11-21 14:05:44 -05002088 {
2089 testType: serverTest,
2090 name: "SupportTicketsWithSessionID",
2091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002092 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002093 SessionTicketsDisabled: true,
2094 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002095 resumeConfig: &Config{
2096 MaxVersion: VersionTLS12,
2097 },
David Benjaminef1b0092015-11-21 14:05:44 -05002098 resumeSession: true,
2099 },
David Benjamin02edcd02016-07-27 17:40:37 -04002100 {
2101 protocol: dtls,
2102 name: "DTLS-SendExtraFinished",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendExtraFinished: true,
2106 },
2107 },
2108 shouldFail: true,
2109 expectedError: ":UNEXPECTED_RECORD:",
2110 },
2111 {
2112 protocol: dtls,
2113 name: "DTLS-SendExtraFinished-Reordered",
2114 config: Config{
2115 Bugs: ProtocolBugs{
2116 MaxHandshakeRecordLength: 2,
2117 ReorderHandshakeFragments: true,
2118 SendExtraFinished: true,
2119 },
2120 },
2121 shouldFail: true,
2122 expectedError: ":UNEXPECTED_RECORD:",
2123 },
David Benjamine97fb482016-07-29 09:23:07 -04002124 {
2125 testType: serverTest,
2126 name: "V2ClientHello-EmptyRecordPrefix",
2127 config: Config{
2128 // Choose a cipher suite that does not involve
2129 // elliptic curves, so no extensions are
2130 // involved.
2131 MaxVersion: VersionTLS12,
2132 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2133 Bugs: ProtocolBugs{
2134 SendV2ClientHello: true,
2135 },
2136 },
2137 sendPrefix: string([]byte{
2138 byte(recordTypeHandshake),
2139 3, 1, // version
2140 0, 0, // length
2141 }),
2142 // A no-op empty record may not be sent before V2ClientHello.
2143 shouldFail: true,
2144 expectedError: ":WRONG_VERSION_NUMBER:",
2145 },
2146 {
2147 testType: serverTest,
2148 name: "V2ClientHello-WarningAlertPrefix",
2149 config: Config{
2150 // Choose a cipher suite that does not involve
2151 // elliptic curves, so no extensions are
2152 // involved.
2153 MaxVersion: VersionTLS12,
2154 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2155 Bugs: ProtocolBugs{
2156 SendV2ClientHello: true,
2157 },
2158 },
2159 sendPrefix: string([]byte{
2160 byte(recordTypeAlert),
2161 3, 1, // version
2162 0, 2, // length
2163 alertLevelWarning, byte(alertDecompressionFailure),
2164 }),
2165 // A no-op warning alert may not be sent before V2ClientHello.
2166 shouldFail: true,
2167 expectedError: ":WRONG_VERSION_NUMBER:",
2168 },
Adam Langley7c803a62015-06-15 15:35:05 -07002169 }
Adam Langley7c803a62015-06-15 15:35:05 -07002170 testCases = append(testCases, basicTests...)
2171}
2172
Adam Langley95c29f32014-06-20 12:00:00 -07002173func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002174 const bogusCipher = 0xfe00
2175
Adam Langley95c29f32014-06-20 12:00:00 -07002176 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002177 const psk = "12345"
2178 const pskIdentity = "luggage combo"
2179
Adam Langley95c29f32014-06-20 12:00:00 -07002180 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002181 var certFile string
2182 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002183 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002184 cert = ecdsaP256Certificate
2185 certFile = ecdsaP256CertificateFile
2186 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002187 } else {
David Benjamin33863262016-07-08 17:20:12 -07002188 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002189 certFile = rsaCertificateFile
2190 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002191 }
2192
David Benjamin48cae082014-10-27 01:06:24 -04002193 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002194 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002195 flags = append(flags,
2196 "-psk", psk,
2197 "-psk-identity", pskIdentity)
2198 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002199 if hasComponent(suite.name, "NULL") {
2200 // NULL ciphers must be explicitly enabled.
2201 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2202 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002203 if hasComponent(suite.name, "CECPQ1") {
2204 // CECPQ1 ciphers must be explicitly enabled.
2205 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2206 }
David Benjamin48cae082014-10-27 01:06:24 -04002207
Adam Langley95c29f32014-06-20 12:00:00 -07002208 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002209 for _, protocol := range []protocol{tls, dtls} {
2210 var prefix string
2211 if protocol == dtls {
2212 if !ver.hasDTLS {
2213 continue
2214 }
2215 prefix = "D"
2216 }
Adam Langley95c29f32014-06-20 12:00:00 -07002217
David Benjamin0407e762016-06-17 16:41:18 -04002218 var shouldServerFail, shouldClientFail bool
2219 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2220 // BoringSSL clients accept ECDHE on SSLv3, but
2221 // a BoringSSL server will never select it
2222 // because the extension is missing.
2223 shouldServerFail = true
2224 }
2225 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2226 shouldClientFail = true
2227 shouldServerFail = true
2228 }
David Benjamin54c217c2016-07-13 12:35:25 -04002229 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002230 shouldClientFail = true
2231 shouldServerFail = true
2232 }
David Benjamin0407e762016-06-17 16:41:18 -04002233 if !isDTLSCipher(suite.name) && protocol == dtls {
2234 shouldClientFail = true
2235 shouldServerFail = true
2236 }
David Benjamin4298d772015-12-19 00:18:25 -05002237
David Benjamin0407e762016-06-17 16:41:18 -04002238 var expectedServerError, expectedClientError string
2239 if shouldServerFail {
2240 expectedServerError = ":NO_SHARED_CIPHER:"
2241 }
2242 if shouldClientFail {
2243 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2244 }
David Benjamin025b3d32014-07-01 19:53:04 -04002245
David Benjamin9deb1172016-07-13 17:13:49 -04002246 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2247 resumeSession := ver.version < VersionTLS13
2248
David Benjamin6fd297b2014-08-11 18:43:38 -04002249 testCases = append(testCases, testCase{
2250 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002251 protocol: protocol,
2252
2253 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002254 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002255 MinVersion: ver.version,
2256 MaxVersion: ver.version,
2257 CipherSuites: []uint16{suite.id},
2258 Certificates: []Certificate{cert},
2259 PreSharedKey: []byte(psk),
2260 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002261 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002262 EnableAllCiphers: shouldServerFail,
2263 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002264 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002265 },
2266 certFile: certFile,
2267 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002268 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002269 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002270 shouldFail: shouldServerFail,
2271 expectedError: expectedServerError,
2272 })
2273
2274 testCases = append(testCases, testCase{
2275 testType: clientTest,
2276 protocol: protocol,
2277 name: prefix + ver.name + "-" + suite.name + "-client",
2278 config: Config{
2279 MinVersion: ver.version,
2280 MaxVersion: ver.version,
2281 CipherSuites: []uint16{suite.id},
2282 Certificates: []Certificate{cert},
2283 PreSharedKey: []byte(psk),
2284 PreSharedKeyIdentity: pskIdentity,
2285 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002286 EnableAllCiphers: shouldClientFail,
2287 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002288 },
2289 },
2290 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002291 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002292 shouldFail: shouldClientFail,
2293 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002294 })
David Benjamin2c99d282015-09-01 10:23:00 -04002295
Nick Harper1fd39d82016-06-14 18:14:35 -07002296 if !shouldClientFail {
2297 // Ensure the maximum record size is accepted.
2298 testCases = append(testCases, testCase{
2299 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2300 config: Config{
2301 MinVersion: ver.version,
2302 MaxVersion: ver.version,
2303 CipherSuites: []uint16{suite.id},
2304 Certificates: []Certificate{cert},
2305 PreSharedKey: []byte(psk),
2306 PreSharedKeyIdentity: pskIdentity,
2307 },
2308 flags: flags,
2309 messageLen: maxPlaintext,
2310 })
2311 }
2312 }
David Benjamin2c99d282015-09-01 10:23:00 -04002313 }
Adam Langley95c29f32014-06-20 12:00:00 -07002314 }
Adam Langleya7997f12015-05-14 17:38:50 -07002315
2316 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002317 name: "NoSharedCipher",
2318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002319 MaxVersion: VersionTLS12,
2320 CipherSuites: []uint16{},
2321 },
2322 shouldFail: true,
2323 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2324 })
2325
2326 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002327 name: "NoSharedCipher-TLS13",
2328 config: Config{
2329 MaxVersion: VersionTLS13,
2330 CipherSuites: []uint16{},
2331 },
2332 shouldFail: true,
2333 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2334 })
2335
2336 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002337 name: "UnsupportedCipherSuite",
2338 config: Config{
2339 MaxVersion: VersionTLS12,
2340 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2341 Bugs: ProtocolBugs{
2342 IgnorePeerCipherPreferences: true,
2343 },
2344 },
2345 flags: []string{"-cipher", "DEFAULT:!RC4"},
2346 shouldFail: true,
2347 expectedError: ":WRONG_CIPHER_RETURNED:",
2348 })
2349
2350 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002351 name: "ServerHelloBogusCipher",
2352 config: Config{
2353 MaxVersion: VersionTLS12,
2354 Bugs: ProtocolBugs{
2355 SendCipherSuite: bogusCipher,
2356 },
2357 },
2358 shouldFail: true,
2359 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2360 })
2361 testCases = append(testCases, testCase{
2362 name: "ServerHelloBogusCipher-TLS13",
2363 config: Config{
2364 MaxVersion: VersionTLS13,
2365 Bugs: ProtocolBugs{
2366 SendCipherSuite: bogusCipher,
2367 },
2368 },
2369 shouldFail: true,
2370 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2371 })
2372
2373 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002374 name: "WeakDH",
2375 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002376 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002377 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2378 Bugs: ProtocolBugs{
2379 // This is a 1023-bit prime number, generated
2380 // with:
2381 // openssl gendh 1023 | openssl asn1parse -i
2382 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2383 },
2384 },
2385 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002386 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002387 })
Adam Langleycef75832015-09-03 14:51:12 -07002388
David Benjamincd24a392015-11-11 13:23:05 -08002389 testCases = append(testCases, testCase{
2390 name: "SillyDH",
2391 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002392 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002393 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2394 Bugs: ProtocolBugs{
2395 // This is a 4097-bit prime number, generated
2396 // with:
2397 // openssl gendh 4097 | openssl asn1parse -i
2398 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2399 },
2400 },
2401 shouldFail: true,
2402 expectedError: ":DH_P_TOO_LONG:",
2403 })
2404
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002405 // This test ensures that Diffie-Hellman public values are padded with
2406 // zeros so that they're the same length as the prime. This is to avoid
2407 // hitting a bug in yaSSL.
2408 testCases = append(testCases, testCase{
2409 testType: serverTest,
2410 name: "DHPublicValuePadded",
2411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002412 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002413 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2414 Bugs: ProtocolBugs{
2415 RequireDHPublicValueLen: (1025 + 7) / 8,
2416 },
2417 },
2418 flags: []string{"-use-sparse-dh-prime"},
2419 })
David Benjamincd24a392015-11-11 13:23:05 -08002420
David Benjamin241ae832016-01-15 03:04:54 -05002421 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002422 testCases = append(testCases, testCase{
2423 testType: serverTest,
2424 name: "UnknownCipher",
2425 config: Config{
2426 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2427 },
2428 })
2429
Adam Langleycef75832015-09-03 14:51:12 -07002430 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2431 // 1.1 specific cipher suite settings. A server is setup with the given
2432 // cipher lists and then a connection is made for each member of
2433 // expectations. The cipher suite that the server selects must match
2434 // the specified one.
2435 var versionSpecificCiphersTest = []struct {
2436 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2437 // expectations is a map from TLS version to cipher suite id.
2438 expectations map[uint16]uint16
2439 }{
2440 {
2441 // Test that the null case (where no version-specific ciphers are set)
2442 // works as expected.
2443 "RC4-SHA:AES128-SHA", // default ciphers
2444 "", // no ciphers specifically for TLS ≥ 1.0
2445 "", // no ciphers specifically for TLS ≥ 1.1
2446 map[uint16]uint16{
2447 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2448 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2449 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2450 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2451 },
2452 },
2453 {
2454 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2455 // cipher.
2456 "RC4-SHA:AES128-SHA", // default
2457 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2458 "", // no ciphers specifically for TLS ≥ 1.1
2459 map[uint16]uint16{
2460 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2461 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2462 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2463 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2464 },
2465 },
2466 {
2467 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2468 // cipher.
2469 "RC4-SHA:AES128-SHA", // default
2470 "", // no ciphers specifically for TLS ≥ 1.0
2471 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2472 map[uint16]uint16{
2473 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2474 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2475 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2476 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2477 },
2478 },
2479 {
2480 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2481 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2482 "RC4-SHA:AES128-SHA", // default
2483 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2484 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2485 map[uint16]uint16{
2486 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2487 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2488 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2489 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2490 },
2491 },
2492 }
2493
2494 for i, test := range versionSpecificCiphersTest {
2495 for version, expectedCipherSuite := range test.expectations {
2496 flags := []string{"-cipher", test.ciphersDefault}
2497 if len(test.ciphersTLS10) > 0 {
2498 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2499 }
2500 if len(test.ciphersTLS11) > 0 {
2501 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2502 }
2503
2504 testCases = append(testCases, testCase{
2505 testType: serverTest,
2506 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2507 config: Config{
2508 MaxVersion: version,
2509 MinVersion: version,
2510 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2511 },
2512 flags: flags,
2513 expectedCipher: expectedCipherSuite,
2514 })
2515 }
2516 }
Adam Langley95c29f32014-06-20 12:00:00 -07002517}
2518
2519func addBadECDSASignatureTests() {
2520 for badR := BadValue(1); badR < NumBadValues; badR++ {
2521 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002522 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002523 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2524 config: Config{
2525 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002526 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002527 Bugs: ProtocolBugs{
2528 BadECDSAR: badR,
2529 BadECDSAS: badS,
2530 },
2531 },
2532 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002533 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002534 })
2535 }
2536 }
2537}
2538
Adam Langley80842bd2014-06-20 12:00:00 -07002539func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002540 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002541 name: "MaxCBCPadding",
2542 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002543 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2545 Bugs: ProtocolBugs{
2546 MaxPadding: true,
2547 },
2548 },
2549 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2550 })
David Benjamin025b3d32014-07-01 19:53:04 -04002551 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002552 name: "BadCBCPadding",
2553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002554 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002555 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2556 Bugs: ProtocolBugs{
2557 PaddingFirstByteBad: true,
2558 },
2559 },
2560 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002561 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002562 })
2563 // OpenSSL previously had an issue where the first byte of padding in
2564 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002565 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002566 name: "BadCBCPadding255",
2567 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002568 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002569 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2570 Bugs: ProtocolBugs{
2571 MaxPadding: true,
2572 PaddingFirstByteBadIf255: true,
2573 },
2574 },
2575 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2576 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002577 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002578 })
2579}
2580
Kenny Root7fdeaf12014-08-05 15:23:37 -07002581func addCBCSplittingTests() {
2582 testCases = append(testCases, testCase{
2583 name: "CBCRecordSplitting",
2584 config: Config{
2585 MaxVersion: VersionTLS10,
2586 MinVersion: VersionTLS10,
2587 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2588 },
David Benjaminac8302a2015-09-01 17:18:15 -04002589 messageLen: -1, // read until EOF
2590 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002591 flags: []string{
2592 "-async",
2593 "-write-different-record-sizes",
2594 "-cbc-record-splitting",
2595 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002596 })
2597 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002598 name: "CBCRecordSplittingPartialWrite",
2599 config: Config{
2600 MaxVersion: VersionTLS10,
2601 MinVersion: VersionTLS10,
2602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2603 },
2604 messageLen: -1, // read until EOF
2605 flags: []string{
2606 "-async",
2607 "-write-different-record-sizes",
2608 "-cbc-record-splitting",
2609 "-partial-write",
2610 },
2611 })
2612}
2613
David Benjamin636293b2014-07-08 17:59:18 -04002614func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002615 // Add a dummy cert pool to stress certificate authority parsing.
2616 // TODO(davidben): Add tests that those values parse out correctly.
2617 certPool := x509.NewCertPool()
2618 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2619 if err != nil {
2620 panic(err)
2621 }
2622 certPool.AddCert(cert)
2623
David Benjamin636293b2014-07-08 17:59:18 -04002624 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002625 testCases = append(testCases, testCase{
2626 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002627 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002628 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002629 MinVersion: ver.version,
2630 MaxVersion: ver.version,
2631 ClientAuth: RequireAnyClientCert,
2632 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002633 },
2634 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002635 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2636 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002637 },
2638 })
2639 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002640 testType: serverTest,
2641 name: ver.name + "-Server-ClientAuth-RSA",
2642 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002643 MinVersion: ver.version,
2644 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002645 Certificates: []Certificate{rsaCertificate},
2646 },
2647 flags: []string{"-require-any-client-certificate"},
2648 })
David Benjamine098ec22014-08-27 23:13:20 -04002649 if ver.version != VersionSSL30 {
2650 testCases = append(testCases, testCase{
2651 testType: serverTest,
2652 name: ver.name + "-Server-ClientAuth-ECDSA",
2653 config: Config{
2654 MinVersion: ver.version,
2655 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002656 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002657 },
2658 flags: []string{"-require-any-client-certificate"},
2659 })
2660 testCases = append(testCases, testCase{
2661 testType: clientTest,
2662 name: ver.name + "-Client-ClientAuth-ECDSA",
2663 config: Config{
2664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
2666 ClientAuth: RequireAnyClientCert,
2667 ClientCAs: certPool,
2668 },
2669 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002670 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2671 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002672 },
2673 })
2674 }
David Benjamin636293b2014-07-08 17:59:18 -04002675 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002676
2677 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002678 name: "NoClientCertificate",
2679 config: Config{
2680 MaxVersion: VersionTLS12,
2681 ClientAuth: RequireAnyClientCert,
2682 },
2683 shouldFail: true,
2684 expectedLocalError: "client didn't provide a certificate",
2685 })
2686
2687 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002688 name: "NoClientCertificate-TLS13",
2689 config: Config{
2690 MaxVersion: VersionTLS13,
2691 ClientAuth: RequireAnyClientCert,
2692 },
2693 shouldFail: true,
2694 expectedLocalError: "client didn't provide a certificate",
2695 })
2696
2697 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002698 testType: serverTest,
2699 name: "RequireAnyClientCertificate",
2700 config: Config{
2701 MaxVersion: VersionTLS12,
2702 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002703 flags: []string{"-require-any-client-certificate"},
2704 shouldFail: true,
2705 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2706 })
2707
2708 testCases = append(testCases, testCase{
2709 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002710 name: "RequireAnyClientCertificate-TLS13",
2711 config: Config{
2712 MaxVersion: VersionTLS13,
2713 },
2714 flags: []string{"-require-any-client-certificate"},
2715 shouldFail: true,
2716 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2717 })
2718
2719 testCases = append(testCases, testCase{
2720 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002721 name: "RequireAnyClientCertificate-SSL3",
2722 config: Config{
2723 MaxVersion: VersionSSL30,
2724 },
2725 flags: []string{"-require-any-client-certificate"},
2726 shouldFail: true,
2727 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2728 })
2729
2730 testCases = append(testCases, testCase{
2731 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002732 name: "SkipClientCertificate",
2733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002734 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002735 Bugs: ProtocolBugs{
2736 SkipClientCertificate: true,
2737 },
2738 },
2739 // Setting SSL_VERIFY_PEER allows anonymous clients.
2740 flags: []string{"-verify-peer"},
2741 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002742 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002743 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002744
Steven Valdez143e8b32016-07-11 13:19:03 -04002745 testCases = append(testCases, testCase{
2746 testType: serverTest,
2747 name: "SkipClientCertificate-TLS13",
2748 config: Config{
2749 MaxVersion: VersionTLS13,
2750 Bugs: ProtocolBugs{
2751 SkipClientCertificate: true,
2752 },
2753 },
2754 // Setting SSL_VERIFY_PEER allows anonymous clients.
2755 flags: []string{"-verify-peer"},
2756 shouldFail: true,
2757 expectedError: ":UNEXPECTED_MESSAGE:",
2758 })
2759
David Benjaminc032dfa2016-05-12 14:54:57 -04002760 // Client auth is only legal in certificate-based ciphers.
2761 testCases = append(testCases, testCase{
2762 testType: clientTest,
2763 name: "ClientAuth-PSK",
2764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002765 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002766 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2767 PreSharedKey: []byte("secret"),
2768 ClientAuth: RequireAnyClientCert,
2769 },
2770 flags: []string{
2771 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2772 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2773 "-psk", "secret",
2774 },
2775 shouldFail: true,
2776 expectedError: ":UNEXPECTED_MESSAGE:",
2777 })
2778 testCases = append(testCases, testCase{
2779 testType: clientTest,
2780 name: "ClientAuth-ECDHE_PSK",
2781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002782 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002783 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2784 PreSharedKey: []byte("secret"),
2785 ClientAuth: RequireAnyClientCert,
2786 },
2787 flags: []string{
2788 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2789 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2790 "-psk", "secret",
2791 },
2792 shouldFail: true,
2793 expectedError: ":UNEXPECTED_MESSAGE:",
2794 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002795
2796 // Regression test for a bug where the client CA list, if explicitly
2797 // set to NULL, was mis-encoded.
2798 testCases = append(testCases, testCase{
2799 testType: serverTest,
2800 name: "Null-Client-CA-List",
2801 config: Config{
2802 MaxVersion: VersionTLS12,
2803 Certificates: []Certificate{rsaCertificate},
2804 },
2805 flags: []string{
2806 "-require-any-client-certificate",
2807 "-use-null-client-ca-list",
2808 },
2809 })
David Benjamin636293b2014-07-08 17:59:18 -04002810}
2811
Adam Langley75712922014-10-10 16:23:43 -07002812func addExtendedMasterSecretTests() {
2813 const expectEMSFlag = "-expect-extended-master-secret"
2814
2815 for _, with := range []bool{false, true} {
2816 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002817 if with {
2818 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002819 }
2820
2821 for _, isClient := range []bool{false, true} {
2822 suffix := "-Server"
2823 testType := serverTest
2824 if isClient {
2825 suffix = "-Client"
2826 testType = clientTest
2827 }
2828
2829 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002830 // In TLS 1.3, the extension is irrelevant and
2831 // always reports as enabled.
2832 var flags []string
2833 if with || ver.version >= VersionTLS13 {
2834 flags = []string{expectEMSFlag}
2835 }
2836
Adam Langley75712922014-10-10 16:23:43 -07002837 test := testCase{
2838 testType: testType,
2839 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2840 config: Config{
2841 MinVersion: ver.version,
2842 MaxVersion: ver.version,
2843 Bugs: ProtocolBugs{
2844 NoExtendedMasterSecret: !with,
2845 RequireExtendedMasterSecret: with,
2846 },
2847 },
David Benjamin48cae082014-10-27 01:06:24 -04002848 flags: flags,
2849 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002850 }
2851 if test.shouldFail {
2852 test.expectedLocalError = "extended master secret required but not supported by peer"
2853 }
2854 testCases = append(testCases, test)
2855 }
2856 }
2857 }
2858
Adam Langleyba5934b2015-06-02 10:50:35 -07002859 for _, isClient := range []bool{false, true} {
2860 for _, supportedInFirstConnection := range []bool{false, true} {
2861 for _, supportedInResumeConnection := range []bool{false, true} {
2862 boolToWord := func(b bool) string {
2863 if b {
2864 return "Yes"
2865 }
2866 return "No"
2867 }
2868 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2869 if isClient {
2870 suffix += "Client"
2871 } else {
2872 suffix += "Server"
2873 }
2874
2875 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002876 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002877 Bugs: ProtocolBugs{
2878 RequireExtendedMasterSecret: true,
2879 },
2880 }
2881
2882 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002883 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002884 Bugs: ProtocolBugs{
2885 NoExtendedMasterSecret: true,
2886 },
2887 }
2888
2889 test := testCase{
2890 name: "ExtendedMasterSecret-" + suffix,
2891 resumeSession: true,
2892 }
2893
2894 if !isClient {
2895 test.testType = serverTest
2896 }
2897
2898 if supportedInFirstConnection {
2899 test.config = supportedConfig
2900 } else {
2901 test.config = noSupportConfig
2902 }
2903
2904 if supportedInResumeConnection {
2905 test.resumeConfig = &supportedConfig
2906 } else {
2907 test.resumeConfig = &noSupportConfig
2908 }
2909
2910 switch suffix {
2911 case "YesToYes-Client", "YesToYes-Server":
2912 // When a session is resumed, it should
2913 // still be aware that its master
2914 // secret was generated via EMS and
2915 // thus it's safe to use tls-unique.
2916 test.flags = []string{expectEMSFlag}
2917 case "NoToYes-Server":
2918 // If an original connection did not
2919 // contain EMS, but a resumption
2920 // handshake does, then a server should
2921 // not resume the session.
2922 test.expectResumeRejected = true
2923 case "YesToNo-Server":
2924 // Resuming an EMS session without the
2925 // EMS extension should cause the
2926 // server to abort the connection.
2927 test.shouldFail = true
2928 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2929 case "NoToYes-Client":
2930 // A client should abort a connection
2931 // where the server resumed a non-EMS
2932 // session but echoed the EMS
2933 // extension.
2934 test.shouldFail = true
2935 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2936 case "YesToNo-Client":
2937 // A client should abort a connection
2938 // where the server didn't echo EMS
2939 // when the session used it.
2940 test.shouldFail = true
2941 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2942 }
2943
2944 testCases = append(testCases, test)
2945 }
2946 }
2947 }
Adam Langley75712922014-10-10 16:23:43 -07002948}
2949
David Benjamin582ba042016-07-07 12:33:25 -07002950type stateMachineTestConfig struct {
2951 protocol protocol
2952 async bool
2953 splitHandshake, packHandshakeFlight bool
2954}
2955
David Benjamin43ec06f2014-08-05 02:28:57 -04002956// Adds tests that try to cover the range of the handshake state machine, under
2957// various conditions. Some of these are redundant with other tests, but they
2958// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002959func addAllStateMachineCoverageTests() {
2960 for _, async := range []bool{false, true} {
2961 for _, protocol := range []protocol{tls, dtls} {
2962 addStateMachineCoverageTests(stateMachineTestConfig{
2963 protocol: protocol,
2964 async: async,
2965 })
2966 addStateMachineCoverageTests(stateMachineTestConfig{
2967 protocol: protocol,
2968 async: async,
2969 splitHandshake: true,
2970 })
2971 if protocol == tls {
2972 addStateMachineCoverageTests(stateMachineTestConfig{
2973 protocol: protocol,
2974 async: async,
2975 packHandshakeFlight: true,
2976 })
2977 }
2978 }
2979 }
2980}
2981
2982func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002983 var tests []testCase
2984
2985 // Basic handshake, with resumption. Client and server,
2986 // session ID and session ticket.
2987 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002988 name: "Basic-Client",
2989 config: Config{
2990 MaxVersion: VersionTLS12,
2991 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002992 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002993 // Ensure session tickets are used, not session IDs.
2994 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002995 })
2996 tests = append(tests, testCase{
2997 name: "Basic-Client-RenewTicket",
2998 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002999 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003000 Bugs: ProtocolBugs{
3001 RenewTicketOnResume: true,
3002 },
3003 },
David Benjaminba4594a2015-06-18 18:36:15 -04003004 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003005 resumeSession: true,
3006 })
3007 tests = append(tests, testCase{
3008 name: "Basic-Client-NoTicket",
3009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003010 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003011 SessionTicketsDisabled: true,
3012 },
3013 resumeSession: true,
3014 })
3015 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003016 name: "Basic-Client-Implicit",
3017 config: Config{
3018 MaxVersion: VersionTLS12,
3019 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003020 flags: []string{"-implicit-handshake"},
3021 resumeSession: true,
3022 })
3023 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003024 testType: serverTest,
3025 name: "Basic-Server",
3026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003028 Bugs: ProtocolBugs{
3029 RequireSessionTickets: true,
3030 },
3031 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003032 resumeSession: true,
3033 })
3034 tests = append(tests, testCase{
3035 testType: serverTest,
3036 name: "Basic-Server-NoTickets",
3037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003038 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003039 SessionTicketsDisabled: true,
3040 },
3041 resumeSession: true,
3042 })
3043 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003044 testType: serverTest,
3045 name: "Basic-Server-Implicit",
3046 config: Config{
3047 MaxVersion: VersionTLS12,
3048 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003049 flags: []string{"-implicit-handshake"},
3050 resumeSession: true,
3051 })
3052 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003053 testType: serverTest,
3054 name: "Basic-Server-EarlyCallback",
3055 config: Config{
3056 MaxVersion: VersionTLS12,
3057 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003058 flags: []string{"-use-early-callback"},
3059 resumeSession: true,
3060 })
3061
Steven Valdez143e8b32016-07-11 13:19:03 -04003062 // TLS 1.3 basic handshake shapes.
3063 tests = append(tests, testCase{
3064 name: "TLS13-1RTT-Client",
3065 config: Config{
3066 MaxVersion: VersionTLS13,
3067 },
3068 })
3069 tests = append(tests, testCase{
3070 testType: serverTest,
3071 name: "TLS13-1RTT-Server",
3072 config: Config{
3073 MaxVersion: VersionTLS13,
3074 },
3075 })
3076
David Benjamin760b1dd2015-05-15 23:33:48 -04003077 // TLS client auth.
3078 tests = append(tests, testCase{
3079 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003080 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003082 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003083 ClientAuth: RequestClientCert,
3084 },
3085 })
3086 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003087 testType: serverTest,
3088 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003089 config: Config{
3090 MaxVersion: VersionTLS12,
3091 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003092 // Setting SSL_VERIFY_PEER allows anonymous clients.
3093 flags: []string{"-verify-peer"},
3094 })
David Benjamin582ba042016-07-07 12:33:25 -07003095 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003096 tests = append(tests, testCase{
3097 testType: clientTest,
3098 name: "ClientAuth-NoCertificate-Client-SSL3",
3099 config: Config{
3100 MaxVersion: VersionSSL30,
3101 ClientAuth: RequestClientCert,
3102 },
3103 })
3104 tests = append(tests, testCase{
3105 testType: serverTest,
3106 name: "ClientAuth-NoCertificate-Server-SSL3",
3107 config: Config{
3108 MaxVersion: VersionSSL30,
3109 },
3110 // Setting SSL_VERIFY_PEER allows anonymous clients.
3111 flags: []string{"-verify-peer"},
3112 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003113 tests = append(tests, testCase{
3114 testType: clientTest,
3115 name: "ClientAuth-NoCertificate-Client-TLS13",
3116 config: Config{
3117 MaxVersion: VersionTLS13,
3118 ClientAuth: RequestClientCert,
3119 },
3120 })
3121 tests = append(tests, testCase{
3122 testType: serverTest,
3123 name: "ClientAuth-NoCertificate-Server-TLS13",
3124 config: Config{
3125 MaxVersion: VersionTLS13,
3126 },
3127 // Setting SSL_VERIFY_PEER allows anonymous clients.
3128 flags: []string{"-verify-peer"},
3129 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003130 }
3131 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003132 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003133 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003135 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003136 ClientAuth: RequireAnyClientCert,
3137 },
3138 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003139 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3140 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003141 },
3142 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003143 tests = append(tests, testCase{
3144 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003145 name: "ClientAuth-RSA-Client-TLS13",
3146 config: Config{
3147 MaxVersion: VersionTLS13,
3148 ClientAuth: RequireAnyClientCert,
3149 },
3150 flags: []string{
3151 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3152 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3153 },
3154 })
3155 tests = append(tests, testCase{
3156 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003157 name: "ClientAuth-ECDSA-Client",
3158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003159 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003160 ClientAuth: RequireAnyClientCert,
3161 },
3162 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003163 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3164 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003165 },
3166 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003167 tests = append(tests, testCase{
3168 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003169 name: "ClientAuth-ECDSA-Client-TLS13",
3170 config: Config{
3171 MaxVersion: VersionTLS13,
3172 ClientAuth: RequireAnyClientCert,
3173 },
3174 flags: []string{
3175 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3176 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3177 },
3178 })
3179 tests = append(tests, testCase{
3180 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003181 name: "ClientAuth-NoCertificate-OldCallback",
3182 config: Config{
3183 MaxVersion: VersionTLS12,
3184 ClientAuth: RequestClientCert,
3185 },
3186 flags: []string{"-use-old-client-cert-callback"},
3187 })
3188 tests = append(tests, testCase{
3189 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003190 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3191 config: Config{
3192 MaxVersion: VersionTLS13,
3193 ClientAuth: RequestClientCert,
3194 },
3195 flags: []string{"-use-old-client-cert-callback"},
3196 })
3197 tests = append(tests, testCase{
3198 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003199 name: "ClientAuth-OldCallback",
3200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003201 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003202 ClientAuth: RequireAnyClientCert,
3203 },
3204 flags: []string{
3205 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3206 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3207 "-use-old-client-cert-callback",
3208 },
3209 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003211 testType: clientTest,
3212 name: "ClientAuth-OldCallback-TLS13",
3213 config: Config{
3214 MaxVersion: VersionTLS13,
3215 ClientAuth: RequireAnyClientCert,
3216 },
3217 flags: []string{
3218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3220 "-use-old-client-cert-callback",
3221 },
3222 })
3223 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003224 testType: serverTest,
3225 name: "ClientAuth-Server",
3226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003227 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003228 Certificates: []Certificate{rsaCertificate},
3229 },
3230 flags: []string{"-require-any-client-certificate"},
3231 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003232 tests = append(tests, testCase{
3233 testType: serverTest,
3234 name: "ClientAuth-Server-TLS13",
3235 config: Config{
3236 MaxVersion: VersionTLS13,
3237 Certificates: []Certificate{rsaCertificate},
3238 },
3239 flags: []string{"-require-any-client-certificate"},
3240 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003241
David Benjamin4c3ddf72016-06-29 18:13:53 -04003242 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003243 tests = append(tests, testCase{
3244 testType: serverTest,
3245 name: "Basic-Server-RSA",
3246 config: Config{
3247 MaxVersion: VersionTLS12,
3248 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3249 },
3250 flags: []string{
3251 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3252 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3253 },
3254 })
3255 tests = append(tests, testCase{
3256 testType: serverTest,
3257 name: "Basic-Server-ECDHE-RSA",
3258 config: Config{
3259 MaxVersion: VersionTLS12,
3260 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3261 },
3262 flags: []string{
3263 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3264 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3265 },
3266 })
3267 tests = append(tests, testCase{
3268 testType: serverTest,
3269 name: "Basic-Server-ECDHE-ECDSA",
3270 config: Config{
3271 MaxVersion: VersionTLS12,
3272 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3273 },
3274 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003275 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3276 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003277 },
3278 })
3279
David Benjamin760b1dd2015-05-15 23:33:48 -04003280 // No session ticket support; server doesn't send NewSessionTicket.
3281 tests = append(tests, testCase{
3282 name: "SessionTicketsDisabled-Client",
3283 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003284 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003285 SessionTicketsDisabled: true,
3286 },
3287 })
3288 tests = append(tests, testCase{
3289 testType: serverTest,
3290 name: "SessionTicketsDisabled-Server",
3291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003292 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003293 SessionTicketsDisabled: true,
3294 },
3295 })
3296
3297 // Skip ServerKeyExchange in PSK key exchange if there's no
3298 // identity hint.
3299 tests = append(tests, testCase{
3300 name: "EmptyPSKHint-Client",
3301 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003302 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003303 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3304 PreSharedKey: []byte("secret"),
3305 },
3306 flags: []string{"-psk", "secret"},
3307 })
3308 tests = append(tests, testCase{
3309 testType: serverTest,
3310 name: "EmptyPSKHint-Server",
3311 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003312 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003313 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3314 PreSharedKey: []byte("secret"),
3315 },
3316 flags: []string{"-psk", "secret"},
3317 })
3318
David Benjamin4c3ddf72016-06-29 18:13:53 -04003319 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003320 tests = append(tests, testCase{
3321 testType: clientTest,
3322 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003323 config: Config{
3324 MaxVersion: VersionTLS12,
3325 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003326 flags: []string{
3327 "-enable-ocsp-stapling",
3328 "-expect-ocsp-response",
3329 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003330 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003331 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003332 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003333 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003334 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003335 testType: serverTest,
3336 name: "OCSPStapling-Server",
3337 config: Config{
3338 MaxVersion: VersionTLS12,
3339 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003340 expectedOCSPResponse: testOCSPResponse,
3341 flags: []string{
3342 "-ocsp-response",
3343 base64.StdEncoding.EncodeToString(testOCSPResponse),
3344 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003345 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003346 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003347 tests = append(tests, testCase{
3348 testType: clientTest,
3349 name: "OCSPStapling-Client-TLS13",
3350 config: Config{
3351 MaxVersion: VersionTLS13,
3352 },
3353 flags: []string{
3354 "-enable-ocsp-stapling",
3355 "-expect-ocsp-response",
3356 base64.StdEncoding.EncodeToString(testOCSPResponse),
3357 "-verify-peer",
3358 },
3359 // TODO(davidben): Enable this when resumption is implemented
3360 // in TLS 1.3.
3361 resumeSession: false,
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "OCSPStapling-Server-TLS13",
3366 config: Config{
3367 MaxVersion: VersionTLS13,
3368 },
3369 expectedOCSPResponse: testOCSPResponse,
3370 flags: []string{
3371 "-ocsp-response",
3372 base64.StdEncoding.EncodeToString(testOCSPResponse),
3373 },
3374 // TODO(davidben): Enable this when resumption is implemented
3375 // in TLS 1.3.
3376 resumeSession: false,
3377 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003378
David Benjamin4c3ddf72016-06-29 18:13:53 -04003379 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003380 for _, vers := range tlsVersions {
3381 if config.protocol == dtls && !vers.hasDTLS {
3382 continue
3383 }
3384 tests = append(tests, testCase{
3385 testType: clientTest,
3386 name: "CertificateVerificationSucceed-" + vers.name,
3387 config: Config{
3388 MaxVersion: vers.version,
3389 },
3390 flags: []string{
3391 "-verify-peer",
3392 },
3393 })
3394 tests = append(tests, testCase{
3395 testType: clientTest,
3396 name: "CertificateVerificationFail-" + vers.name,
3397 config: Config{
3398 MaxVersion: vers.version,
3399 },
3400 flags: []string{
3401 "-verify-fail",
3402 "-verify-peer",
3403 },
3404 shouldFail: true,
3405 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3406 })
3407 tests = append(tests, testCase{
3408 testType: clientTest,
3409 name: "CertificateVerificationSoftFail-" + vers.name,
3410 config: Config{
3411 MaxVersion: vers.version,
3412 },
3413 flags: []string{
3414 "-verify-fail",
3415 "-expect-verify-result",
3416 },
3417 })
3418 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003419
David Benjamin1d4f4c02016-07-26 18:03:08 -04003420 tests = append(tests, testCase{
3421 name: "ShimSendAlert",
3422 flags: []string{"-send-alert"},
3423 shimWritesFirst: true,
3424 shouldFail: true,
3425 expectedLocalError: "remote error: decompression failure",
3426 })
3427
David Benjamin582ba042016-07-07 12:33:25 -07003428 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003429 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003430 name: "Renegotiate-Client",
3431 config: Config{
3432 MaxVersion: VersionTLS12,
3433 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003434 renegotiate: 1,
3435 flags: []string{
3436 "-renegotiate-freely",
3437 "-expect-total-renegotiations", "1",
3438 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003439 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440
David Benjamin47921102016-07-28 11:29:18 -04003441 tests = append(tests, testCase{
3442 name: "SendHalfHelloRequest",
3443 config: Config{
3444 MaxVersion: VersionTLS12,
3445 Bugs: ProtocolBugs{
3446 PackHelloRequestWithFinished: config.packHandshakeFlight,
3447 },
3448 },
3449 sendHalfHelloRequest: true,
3450 flags: []string{"-renegotiate-ignore"},
3451 shouldFail: true,
3452 expectedError: ":UNEXPECTED_RECORD:",
3453 })
3454
David Benjamin760b1dd2015-05-15 23:33:48 -04003455 // NPN on client and server; results in post-handshake message.
3456 tests = append(tests, testCase{
3457 name: "NPN-Client",
3458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003459 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003460 NextProtos: []string{"foo"},
3461 },
3462 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003463 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003464 expectedNextProto: "foo",
3465 expectedNextProtoType: npn,
3466 })
3467 tests = append(tests, testCase{
3468 testType: serverTest,
3469 name: "NPN-Server",
3470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003471 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003472 NextProtos: []string{"bar"},
3473 },
3474 flags: []string{
3475 "-advertise-npn", "\x03foo\x03bar\x03baz",
3476 "-expect-next-proto", "bar",
3477 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003478 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003479 expectedNextProto: "bar",
3480 expectedNextProtoType: npn,
3481 })
3482
3483 // TODO(davidben): Add tests for when False Start doesn't trigger.
3484
3485 // Client does False Start and negotiates NPN.
3486 tests = append(tests, testCase{
3487 name: "FalseStart",
3488 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003489 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003490 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3491 NextProtos: []string{"foo"},
3492 Bugs: ProtocolBugs{
3493 ExpectFalseStart: true,
3494 },
3495 },
3496 flags: []string{
3497 "-false-start",
3498 "-select-next-proto", "foo",
3499 },
3500 shimWritesFirst: true,
3501 resumeSession: true,
3502 })
3503
3504 // Client does False Start and negotiates ALPN.
3505 tests = append(tests, testCase{
3506 name: "FalseStart-ALPN",
3507 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003508 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3510 NextProtos: []string{"foo"},
3511 Bugs: ProtocolBugs{
3512 ExpectFalseStart: true,
3513 },
3514 },
3515 flags: []string{
3516 "-false-start",
3517 "-advertise-alpn", "\x03foo",
3518 },
3519 shimWritesFirst: true,
3520 resumeSession: true,
3521 })
3522
3523 // Client does False Start but doesn't explicitly call
3524 // SSL_connect.
3525 tests = append(tests, testCase{
3526 name: "FalseStart-Implicit",
3527 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003528 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003529 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3530 NextProtos: []string{"foo"},
3531 },
3532 flags: []string{
3533 "-implicit-handshake",
3534 "-false-start",
3535 "-advertise-alpn", "\x03foo",
3536 },
3537 })
3538
3539 // False Start without session tickets.
3540 tests = append(tests, testCase{
3541 name: "FalseStart-SessionTicketsDisabled",
3542 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003543 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3545 NextProtos: []string{"foo"},
3546 SessionTicketsDisabled: true,
3547 Bugs: ProtocolBugs{
3548 ExpectFalseStart: true,
3549 },
3550 },
3551 flags: []string{
3552 "-false-start",
3553 "-select-next-proto", "foo",
3554 },
3555 shimWritesFirst: true,
3556 })
3557
Adam Langleydf759b52016-07-11 15:24:37 -07003558 tests = append(tests, testCase{
3559 name: "FalseStart-CECPQ1",
3560 config: Config{
3561 MaxVersion: VersionTLS12,
3562 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3563 NextProtos: []string{"foo"},
3564 Bugs: ProtocolBugs{
3565 ExpectFalseStart: true,
3566 },
3567 },
3568 flags: []string{
3569 "-false-start",
3570 "-cipher", "DEFAULT:kCECPQ1",
3571 "-select-next-proto", "foo",
3572 },
3573 shimWritesFirst: true,
3574 resumeSession: true,
3575 })
3576
David Benjamin760b1dd2015-05-15 23:33:48 -04003577 // Server parses a V2ClientHello.
3578 tests = append(tests, testCase{
3579 testType: serverTest,
3580 name: "SendV2ClientHello",
3581 config: Config{
3582 // Choose a cipher suite that does not involve
3583 // elliptic curves, so no extensions are
3584 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003585 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3587 Bugs: ProtocolBugs{
3588 SendV2ClientHello: true,
3589 },
3590 },
3591 })
3592
3593 // Client sends a Channel ID.
3594 tests = append(tests, testCase{
3595 name: "ChannelID-Client",
3596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003597 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003598 RequestChannelID: true,
3599 },
Adam Langley7c803a62015-06-15 15:35:05 -07003600 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003601 resumeSession: true,
3602 expectChannelID: true,
3603 })
3604
3605 // Server accepts a Channel ID.
3606 tests = append(tests, testCase{
3607 testType: serverTest,
3608 name: "ChannelID-Server",
3609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003610 MaxVersion: VersionTLS12,
3611 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003612 },
3613 flags: []string{
3614 "-expect-channel-id",
3615 base64.StdEncoding.EncodeToString(channelIDBytes),
3616 },
3617 resumeSession: true,
3618 expectChannelID: true,
3619 })
David Benjamin30789da2015-08-29 22:56:45 -04003620
David Benjaminf8fcdf32016-06-08 15:56:13 -04003621 // Channel ID and NPN at the same time, to ensure their relative
3622 // ordering is correct.
3623 tests = append(tests, testCase{
3624 name: "ChannelID-NPN-Client",
3625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003626 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003627 RequestChannelID: true,
3628 NextProtos: []string{"foo"},
3629 },
3630 flags: []string{
3631 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3632 "-select-next-proto", "foo",
3633 },
3634 resumeSession: true,
3635 expectChannelID: true,
3636 expectedNextProto: "foo",
3637 expectedNextProtoType: npn,
3638 })
3639 tests = append(tests, testCase{
3640 testType: serverTest,
3641 name: "ChannelID-NPN-Server",
3642 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003643 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003644 ChannelID: channelIDKey,
3645 NextProtos: []string{"bar"},
3646 },
3647 flags: []string{
3648 "-expect-channel-id",
3649 base64.StdEncoding.EncodeToString(channelIDBytes),
3650 "-advertise-npn", "\x03foo\x03bar\x03baz",
3651 "-expect-next-proto", "bar",
3652 },
3653 resumeSession: true,
3654 expectChannelID: true,
3655 expectedNextProto: "bar",
3656 expectedNextProtoType: npn,
3657 })
3658
David Benjamin30789da2015-08-29 22:56:45 -04003659 // Bidirectional shutdown with the runner initiating.
3660 tests = append(tests, testCase{
3661 name: "Shutdown-Runner",
3662 config: Config{
3663 Bugs: ProtocolBugs{
3664 ExpectCloseNotify: true,
3665 },
3666 },
3667 flags: []string{"-check-close-notify"},
3668 })
3669
3670 // Bidirectional shutdown with the shim initiating. The runner,
3671 // in the meantime, sends garbage before the close_notify which
3672 // the shim must ignore.
3673 tests = append(tests, testCase{
3674 name: "Shutdown-Shim",
3675 config: Config{
3676 Bugs: ProtocolBugs{
3677 ExpectCloseNotify: true,
3678 },
3679 },
3680 shimShutsDown: true,
3681 sendEmptyRecords: 1,
3682 sendWarningAlerts: 1,
3683 flags: []string{"-check-close-notify"},
3684 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003685 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003686 // TODO(davidben): DTLS 1.3 will want a similar thing for
3687 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003688 tests = append(tests, testCase{
3689 name: "SkipHelloVerifyRequest",
3690 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003691 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003692 Bugs: ProtocolBugs{
3693 SkipHelloVerifyRequest: true,
3694 },
3695 },
3696 })
3697 }
3698
David Benjamin760b1dd2015-05-15 23:33:48 -04003699 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003700 test.protocol = config.protocol
3701 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003702 test.name += "-DTLS"
3703 }
David Benjamin582ba042016-07-07 12:33:25 -07003704 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003705 test.name += "-Async"
3706 test.flags = append(test.flags, "-async")
3707 } else {
3708 test.name += "-Sync"
3709 }
David Benjamin582ba042016-07-07 12:33:25 -07003710 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003711 test.name += "-SplitHandshakeRecords"
3712 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003713 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003714 test.config.Bugs.MaxPacketLength = 256
3715 test.flags = append(test.flags, "-mtu", "256")
3716 }
3717 }
David Benjamin582ba042016-07-07 12:33:25 -07003718 if config.packHandshakeFlight {
3719 test.name += "-PackHandshakeFlight"
3720 test.config.Bugs.PackHandshakeFlight = true
3721 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003722 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003723 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003724}
3725
Adam Langley524e7172015-02-20 16:04:00 -08003726func addDDoSCallbackTests() {
3727 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003728 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003729 for _, resume := range []bool{false, true} {
3730 suffix := "Resume"
3731 if resume {
3732 suffix = "No" + suffix
3733 }
3734
3735 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003736 testType: serverTest,
3737 name: "Server-DDoS-OK-" + suffix,
3738 config: Config{
3739 MaxVersion: VersionTLS12,
3740 },
Adam Langley524e7172015-02-20 16:04:00 -08003741 flags: []string{"-install-ddos-callback"},
3742 resumeSession: resume,
3743 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003744 if !resume {
3745 testCases = append(testCases, testCase{
3746 testType: serverTest,
3747 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3748 config: Config{
3749 MaxVersion: VersionTLS13,
3750 },
3751 flags: []string{"-install-ddos-callback"},
3752 resumeSession: resume,
3753 })
3754 }
Adam Langley524e7172015-02-20 16:04:00 -08003755
3756 failFlag := "-fail-ddos-callback"
3757 if resume {
3758 failFlag = "-fail-second-ddos-callback"
3759 }
3760 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003761 testType: serverTest,
3762 name: "Server-DDoS-Reject-" + suffix,
3763 config: Config{
3764 MaxVersion: VersionTLS12,
3765 },
Adam Langley524e7172015-02-20 16:04:00 -08003766 flags: []string{"-install-ddos-callback", failFlag},
3767 resumeSession: resume,
3768 shouldFail: true,
3769 expectedError: ":CONNECTION_REJECTED:",
3770 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003771 if !resume {
3772 testCases = append(testCases, testCase{
3773 testType: serverTest,
3774 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3775 config: Config{
3776 MaxVersion: VersionTLS13,
3777 },
3778 flags: []string{"-install-ddos-callback", failFlag},
3779 resumeSession: resume,
3780 shouldFail: true,
3781 expectedError: ":CONNECTION_REJECTED:",
3782 })
3783 }
Adam Langley524e7172015-02-20 16:04:00 -08003784 }
3785}
3786
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003787func addVersionNegotiationTests() {
3788 for i, shimVers := range tlsVersions {
3789 // Assemble flags to disable all newer versions on the shim.
3790 var flags []string
3791 for _, vers := range tlsVersions[i+1:] {
3792 flags = append(flags, vers.flag)
3793 }
3794
3795 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003796 protocols := []protocol{tls}
3797 if runnerVers.hasDTLS && shimVers.hasDTLS {
3798 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003799 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003800 for _, protocol := range protocols {
3801 expectedVersion := shimVers.version
3802 if runnerVers.version < shimVers.version {
3803 expectedVersion = runnerVers.version
3804 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003805
David Benjamin8b8c0062014-11-23 02:47:52 -05003806 suffix := shimVers.name + "-" + runnerVers.name
3807 if protocol == dtls {
3808 suffix += "-DTLS"
3809 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003810
David Benjamin1eb367c2014-12-12 18:17:51 -05003811 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3812
David Benjamin1e29a6b2014-12-10 02:27:24 -05003813 clientVers := shimVers.version
3814 if clientVers > VersionTLS10 {
3815 clientVers = VersionTLS10
3816 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003817 serverVers := expectedVersion
3818 if expectedVersion >= VersionTLS13 {
3819 serverVers = VersionTLS10
3820 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003821 testCases = append(testCases, testCase{
3822 protocol: protocol,
3823 testType: clientTest,
3824 name: "VersionNegotiation-Client-" + suffix,
3825 config: Config{
3826 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003827 Bugs: ProtocolBugs{
3828 ExpectInitialRecordVersion: clientVers,
3829 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003830 },
3831 flags: flags,
3832 expectedVersion: expectedVersion,
3833 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003834 testCases = append(testCases, testCase{
3835 protocol: protocol,
3836 testType: clientTest,
3837 name: "VersionNegotiation-Client2-" + suffix,
3838 config: Config{
3839 MaxVersion: runnerVers.version,
3840 Bugs: ProtocolBugs{
3841 ExpectInitialRecordVersion: clientVers,
3842 },
3843 },
3844 flags: []string{"-max-version", shimVersFlag},
3845 expectedVersion: expectedVersion,
3846 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003847
3848 testCases = append(testCases, testCase{
3849 protocol: protocol,
3850 testType: serverTest,
3851 name: "VersionNegotiation-Server-" + suffix,
3852 config: Config{
3853 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003854 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003855 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003856 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003857 },
3858 flags: flags,
3859 expectedVersion: expectedVersion,
3860 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003861 testCases = append(testCases, testCase{
3862 protocol: protocol,
3863 testType: serverTest,
3864 name: "VersionNegotiation-Server2-" + suffix,
3865 config: Config{
3866 MaxVersion: runnerVers.version,
3867 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003868 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003869 },
3870 },
3871 flags: []string{"-max-version", shimVersFlag},
3872 expectedVersion: expectedVersion,
3873 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003874 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003875 }
3876 }
David Benjamin95c69562016-06-29 18:15:03 -04003877
3878 // Test for version tolerance.
3879 testCases = append(testCases, testCase{
3880 testType: serverTest,
3881 name: "MinorVersionTolerance",
3882 config: Config{
3883 Bugs: ProtocolBugs{
3884 SendClientVersion: 0x03ff,
3885 },
3886 },
3887 expectedVersion: VersionTLS13,
3888 })
3889 testCases = append(testCases, testCase{
3890 testType: serverTest,
3891 name: "MajorVersionTolerance",
3892 config: Config{
3893 Bugs: ProtocolBugs{
3894 SendClientVersion: 0x0400,
3895 },
3896 },
3897 expectedVersion: VersionTLS13,
3898 })
3899 testCases = append(testCases, testCase{
3900 protocol: dtls,
3901 testType: serverTest,
3902 name: "MinorVersionTolerance-DTLS",
3903 config: Config{
3904 Bugs: ProtocolBugs{
3905 SendClientVersion: 0x03ff,
3906 },
3907 },
3908 expectedVersion: VersionTLS12,
3909 })
3910 testCases = append(testCases, testCase{
3911 protocol: dtls,
3912 testType: serverTest,
3913 name: "MajorVersionTolerance-DTLS",
3914 config: Config{
3915 Bugs: ProtocolBugs{
3916 SendClientVersion: 0x0400,
3917 },
3918 },
3919 expectedVersion: VersionTLS12,
3920 })
3921
3922 // Test that versions below 3.0 are rejected.
3923 testCases = append(testCases, testCase{
3924 testType: serverTest,
3925 name: "VersionTooLow",
3926 config: Config{
3927 Bugs: ProtocolBugs{
3928 SendClientVersion: 0x0200,
3929 },
3930 },
3931 shouldFail: true,
3932 expectedError: ":UNSUPPORTED_PROTOCOL:",
3933 })
3934 testCases = append(testCases, testCase{
3935 protocol: dtls,
3936 testType: serverTest,
3937 name: "VersionTooLow-DTLS",
3938 config: Config{
3939 Bugs: ProtocolBugs{
3940 // 0x0201 is the lowest version expressable in
3941 // DTLS.
3942 SendClientVersion: 0x0201,
3943 },
3944 },
3945 shouldFail: true,
3946 expectedError: ":UNSUPPORTED_PROTOCOL:",
3947 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003948
3949 // Test TLS 1.3's downgrade signal.
3950 testCases = append(testCases, testCase{
3951 name: "Downgrade-TLS12-Client",
3952 config: Config{
3953 Bugs: ProtocolBugs{
3954 NegotiateVersion: VersionTLS12,
3955 },
3956 },
3957 shouldFail: true,
3958 expectedError: ":DOWNGRADE_DETECTED:",
3959 })
3960 testCases = append(testCases, testCase{
3961 testType: serverTest,
3962 name: "Downgrade-TLS12-Server",
3963 config: Config{
3964 Bugs: ProtocolBugs{
3965 SendClientVersion: VersionTLS12,
3966 },
3967 },
3968 shouldFail: true,
3969 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3970 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02003971
3972 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
3973 // behave correctly when both real maximum and fallback versions are
3974 // set.
3975 testCases = append(testCases, testCase{
3976 name: "Downgrade-TLS12-Client-Fallback",
3977 config: Config{
3978 Bugs: ProtocolBugs{
3979 FailIfNotFallbackSCSV: true,
3980 },
3981 },
3982 flags: []string{
3983 "-max-version", strconv.Itoa(VersionTLS13),
3984 "-fallback-version", strconv.Itoa(VersionTLS12),
3985 },
3986 shouldFail: true,
3987 expectedError: ":DOWNGRADE_DETECTED:",
3988 })
3989 testCases = append(testCases, testCase{
3990 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
3991 flags: []string{
3992 "-max-version", strconv.Itoa(VersionTLS12),
3993 "-fallback-version", strconv.Itoa(VersionTLS12),
3994 },
3995 })
3996
3997 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
3998 // just have such connections fail than risk getting confused because we
3999 // didn't sent the 1.3 ClientHello.)
4000 testCases = append(testCases, testCase{
4001 name: "Downgrade-TLS12-Fallback-CheckVersion",
4002 config: Config{
4003 Bugs: ProtocolBugs{
4004 NegotiateVersion: VersionTLS13,
4005 FailIfNotFallbackSCSV: true,
4006 },
4007 },
4008 flags: []string{
4009 "-max-version", strconv.Itoa(VersionTLS13),
4010 "-fallback-version", strconv.Itoa(VersionTLS12),
4011 },
4012 shouldFail: true,
4013 expectedError: ":UNSUPPORTED_PROTOCOL:",
4014 })
4015
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004016}
4017
David Benjaminaccb4542014-12-12 23:44:33 -05004018func addMinimumVersionTests() {
4019 for i, shimVers := range tlsVersions {
4020 // Assemble flags to disable all older versions on the shim.
4021 var flags []string
4022 for _, vers := range tlsVersions[:i] {
4023 flags = append(flags, vers.flag)
4024 }
4025
4026 for _, runnerVers := range tlsVersions {
4027 protocols := []protocol{tls}
4028 if runnerVers.hasDTLS && shimVers.hasDTLS {
4029 protocols = append(protocols, dtls)
4030 }
4031 for _, protocol := range protocols {
4032 suffix := shimVers.name + "-" + runnerVers.name
4033 if protocol == dtls {
4034 suffix += "-DTLS"
4035 }
4036 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4037
David Benjaminaccb4542014-12-12 23:44:33 -05004038 var expectedVersion uint16
4039 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004040 var expectedClientError, expectedServerError string
4041 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004042 if runnerVers.version >= shimVers.version {
4043 expectedVersion = runnerVers.version
4044 } else {
4045 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004046 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4047 expectedServerLocalError = "remote error: protocol version not supported"
4048 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4049 // If the client's minimum version is TLS 1.3 and the runner's
4050 // maximum is below TLS 1.2, the runner will fail to select a
4051 // cipher before the shim rejects the selected version.
4052 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4053 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4054 } else {
4055 expectedClientError = expectedServerError
4056 expectedClientLocalError = expectedServerLocalError
4057 }
David Benjaminaccb4542014-12-12 23:44:33 -05004058 }
4059
4060 testCases = append(testCases, testCase{
4061 protocol: protocol,
4062 testType: clientTest,
4063 name: "MinimumVersion-Client-" + suffix,
4064 config: Config{
4065 MaxVersion: runnerVers.version,
4066 },
David Benjamin87909c02014-12-13 01:55:01 -05004067 flags: flags,
4068 expectedVersion: expectedVersion,
4069 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004070 expectedError: expectedClientError,
4071 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004072 })
4073 testCases = append(testCases, testCase{
4074 protocol: protocol,
4075 testType: clientTest,
4076 name: "MinimumVersion-Client2-" + suffix,
4077 config: Config{
4078 MaxVersion: runnerVers.version,
4079 },
David Benjamin87909c02014-12-13 01:55:01 -05004080 flags: []string{"-min-version", shimVersFlag},
4081 expectedVersion: expectedVersion,
4082 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004083 expectedError: expectedClientError,
4084 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004085 })
4086
4087 testCases = append(testCases, testCase{
4088 protocol: protocol,
4089 testType: serverTest,
4090 name: "MinimumVersion-Server-" + suffix,
4091 config: Config{
4092 MaxVersion: runnerVers.version,
4093 },
David Benjamin87909c02014-12-13 01:55:01 -05004094 flags: flags,
4095 expectedVersion: expectedVersion,
4096 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004097 expectedError: expectedServerError,
4098 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004099 })
4100 testCases = append(testCases, testCase{
4101 protocol: protocol,
4102 testType: serverTest,
4103 name: "MinimumVersion-Server2-" + suffix,
4104 config: Config{
4105 MaxVersion: runnerVers.version,
4106 },
David Benjamin87909c02014-12-13 01:55:01 -05004107 flags: []string{"-min-version", shimVersFlag},
4108 expectedVersion: expectedVersion,
4109 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004110 expectedError: expectedServerError,
4111 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004112 })
4113 }
4114 }
4115 }
4116}
4117
David Benjamine78bfde2014-09-06 12:45:15 -04004118func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004119 // TODO(davidben): Extensions, where applicable, all move their server
4120 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4121 // tests for both. Also test interaction with 0-RTT when implemented.
4122
David Benjamin97d17d92016-07-14 16:12:00 -04004123 // Repeat extensions tests all versions except SSL 3.0.
4124 for _, ver := range tlsVersions {
4125 if ver.version == VersionSSL30 {
4126 continue
4127 }
4128
4129 // TODO(davidben): Implement resumption in TLS 1.3.
4130 resumeSession := ver.version < VersionTLS13
4131
4132 // Test that duplicate extensions are rejected.
4133 testCases = append(testCases, testCase{
4134 testType: clientTest,
4135 name: "DuplicateExtensionClient-" + ver.name,
4136 config: Config{
4137 MaxVersion: ver.version,
4138 Bugs: ProtocolBugs{
4139 DuplicateExtension: true,
4140 },
David Benjamine78bfde2014-09-06 12:45:15 -04004141 },
David Benjamin97d17d92016-07-14 16:12:00 -04004142 shouldFail: true,
4143 expectedLocalError: "remote error: error decoding message",
4144 })
4145 testCases = append(testCases, testCase{
4146 testType: serverTest,
4147 name: "DuplicateExtensionServer-" + ver.name,
4148 config: Config{
4149 MaxVersion: ver.version,
4150 Bugs: ProtocolBugs{
4151 DuplicateExtension: true,
4152 },
David Benjamine78bfde2014-09-06 12:45:15 -04004153 },
David Benjamin97d17d92016-07-14 16:12:00 -04004154 shouldFail: true,
4155 expectedLocalError: "remote error: error decoding message",
4156 })
4157
4158 // Test SNI.
4159 testCases = append(testCases, testCase{
4160 testType: clientTest,
4161 name: "ServerNameExtensionClient-" + ver.name,
4162 config: Config{
4163 MaxVersion: ver.version,
4164 Bugs: ProtocolBugs{
4165 ExpectServerName: "example.com",
4166 },
David Benjamine78bfde2014-09-06 12:45:15 -04004167 },
David Benjamin97d17d92016-07-14 16:12:00 -04004168 flags: []string{"-host-name", "example.com"},
4169 })
4170 testCases = append(testCases, testCase{
4171 testType: clientTest,
4172 name: "ServerNameExtensionClientMismatch-" + ver.name,
4173 config: Config{
4174 MaxVersion: ver.version,
4175 Bugs: ProtocolBugs{
4176 ExpectServerName: "mismatch.com",
4177 },
David Benjamine78bfde2014-09-06 12:45:15 -04004178 },
David Benjamin97d17d92016-07-14 16:12:00 -04004179 flags: []string{"-host-name", "example.com"},
4180 shouldFail: true,
4181 expectedLocalError: "tls: unexpected server name",
4182 })
4183 testCases = append(testCases, testCase{
4184 testType: clientTest,
4185 name: "ServerNameExtensionClientMissing-" + ver.name,
4186 config: Config{
4187 MaxVersion: ver.version,
4188 Bugs: ProtocolBugs{
4189 ExpectServerName: "missing.com",
4190 },
David Benjamine78bfde2014-09-06 12:45:15 -04004191 },
David Benjamin97d17d92016-07-14 16:12:00 -04004192 shouldFail: true,
4193 expectedLocalError: "tls: unexpected server name",
4194 })
4195 testCases = append(testCases, testCase{
4196 testType: serverTest,
4197 name: "ServerNameExtensionServer-" + ver.name,
4198 config: Config{
4199 MaxVersion: ver.version,
4200 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004201 },
David Benjamin97d17d92016-07-14 16:12:00 -04004202 flags: []string{"-expect-server-name", "example.com"},
4203 resumeSession: resumeSession,
4204 })
4205
4206 // Test ALPN.
4207 testCases = append(testCases, testCase{
4208 testType: clientTest,
4209 name: "ALPNClient-" + ver.name,
4210 config: Config{
4211 MaxVersion: ver.version,
4212 NextProtos: []string{"foo"},
4213 },
4214 flags: []string{
4215 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4216 "-expect-alpn", "foo",
4217 },
4218 expectedNextProto: "foo",
4219 expectedNextProtoType: alpn,
4220 resumeSession: resumeSession,
4221 })
4222 testCases = append(testCases, testCase{
4223 testType: serverTest,
4224 name: "ALPNServer-" + ver.name,
4225 config: Config{
4226 MaxVersion: ver.version,
4227 NextProtos: []string{"foo", "bar", "baz"},
4228 },
4229 flags: []string{
4230 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4231 "-select-alpn", "foo",
4232 },
4233 expectedNextProto: "foo",
4234 expectedNextProtoType: alpn,
4235 resumeSession: resumeSession,
4236 })
4237 testCases = append(testCases, testCase{
4238 testType: serverTest,
4239 name: "ALPNServer-Decline-" + ver.name,
4240 config: Config{
4241 MaxVersion: ver.version,
4242 NextProtos: []string{"foo", "bar", "baz"},
4243 },
4244 flags: []string{"-decline-alpn"},
4245 expectNoNextProto: true,
4246 resumeSession: resumeSession,
4247 })
4248
4249 var emptyString string
4250 testCases = append(testCases, testCase{
4251 testType: clientTest,
4252 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4253 config: Config{
4254 MaxVersion: ver.version,
4255 NextProtos: []string{""},
4256 Bugs: ProtocolBugs{
4257 // A server returning an empty ALPN protocol
4258 // should be rejected.
4259 ALPNProtocol: &emptyString,
4260 },
4261 },
4262 flags: []string{
4263 "-advertise-alpn", "\x03foo",
4264 },
4265 shouldFail: true,
4266 expectedError: ":PARSE_TLSEXT:",
4267 })
4268 testCases = append(testCases, testCase{
4269 testType: serverTest,
4270 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4271 config: Config{
4272 MaxVersion: ver.version,
4273 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004274 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004275 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004276 },
David Benjamin97d17d92016-07-14 16:12:00 -04004277 flags: []string{
4278 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004279 },
David Benjamin97d17d92016-07-14 16:12:00 -04004280 shouldFail: true,
4281 expectedError: ":PARSE_TLSEXT:",
4282 })
4283
4284 // Test NPN and the interaction with ALPN.
4285 if ver.version < VersionTLS13 {
4286 // Test that the server prefers ALPN over NPN.
4287 testCases = append(testCases, testCase{
4288 testType: serverTest,
4289 name: "ALPNServer-Preferred-" + ver.name,
4290 config: Config{
4291 MaxVersion: ver.version,
4292 NextProtos: []string{"foo", "bar", "baz"},
4293 },
4294 flags: []string{
4295 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4296 "-select-alpn", "foo",
4297 "-advertise-npn", "\x03foo\x03bar\x03baz",
4298 },
4299 expectedNextProto: "foo",
4300 expectedNextProtoType: alpn,
4301 resumeSession: resumeSession,
4302 })
4303 testCases = append(testCases, testCase{
4304 testType: serverTest,
4305 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4306 config: Config{
4307 MaxVersion: ver.version,
4308 NextProtos: []string{"foo", "bar", "baz"},
4309 Bugs: ProtocolBugs{
4310 SwapNPNAndALPN: true,
4311 },
4312 },
4313 flags: []string{
4314 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4315 "-select-alpn", "foo",
4316 "-advertise-npn", "\x03foo\x03bar\x03baz",
4317 },
4318 expectedNextProto: "foo",
4319 expectedNextProtoType: alpn,
4320 resumeSession: resumeSession,
4321 })
4322
4323 // Test that negotiating both NPN and ALPN is forbidden.
4324 testCases = append(testCases, testCase{
4325 name: "NegotiateALPNAndNPN-" + ver.name,
4326 config: Config{
4327 MaxVersion: ver.version,
4328 NextProtos: []string{"foo", "bar", "baz"},
4329 Bugs: ProtocolBugs{
4330 NegotiateALPNAndNPN: true,
4331 },
4332 },
4333 flags: []string{
4334 "-advertise-alpn", "\x03foo",
4335 "-select-next-proto", "foo",
4336 },
4337 shouldFail: true,
4338 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4339 })
4340 testCases = append(testCases, testCase{
4341 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4342 config: Config{
4343 MaxVersion: ver.version,
4344 NextProtos: []string{"foo", "bar", "baz"},
4345 Bugs: ProtocolBugs{
4346 NegotiateALPNAndNPN: true,
4347 SwapNPNAndALPN: true,
4348 },
4349 },
4350 flags: []string{
4351 "-advertise-alpn", "\x03foo",
4352 "-select-next-proto", "foo",
4353 },
4354 shouldFail: true,
4355 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4356 })
4357
4358 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4359 testCases = append(testCases, testCase{
4360 name: "DisableNPN-" + ver.name,
4361 config: Config{
4362 MaxVersion: ver.version,
4363 NextProtos: []string{"foo"},
4364 },
4365 flags: []string{
4366 "-select-next-proto", "foo",
4367 "-disable-npn",
4368 },
4369 expectNoNextProto: true,
4370 })
4371 }
4372
4373 // Test ticket behavior.
4374 //
4375 // TODO(davidben): Add TLS 1.3 versions of these.
4376 if ver.version < VersionTLS13 {
4377 // Resume with a corrupt ticket.
4378 testCases = append(testCases, testCase{
4379 testType: serverTest,
4380 name: "CorruptTicket-" + ver.name,
4381 config: Config{
4382 MaxVersion: ver.version,
4383 Bugs: ProtocolBugs{
4384 CorruptTicket: true,
4385 },
4386 },
4387 resumeSession: true,
4388 expectResumeRejected: true,
4389 })
4390 // Test the ticket callback, with and without renewal.
4391 testCases = append(testCases, testCase{
4392 testType: serverTest,
4393 name: "TicketCallback-" + ver.name,
4394 config: Config{
4395 MaxVersion: ver.version,
4396 },
4397 resumeSession: true,
4398 flags: []string{"-use-ticket-callback"},
4399 })
4400 testCases = append(testCases, testCase{
4401 testType: serverTest,
4402 name: "TicketCallback-Renew-" + ver.name,
4403 config: Config{
4404 MaxVersion: ver.version,
4405 Bugs: ProtocolBugs{
4406 ExpectNewTicket: true,
4407 },
4408 },
4409 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4410 resumeSession: true,
4411 })
4412
4413 // Resume with an oversized session id.
4414 testCases = append(testCases, testCase{
4415 testType: serverTest,
4416 name: "OversizedSessionId-" + ver.name,
4417 config: Config{
4418 MaxVersion: ver.version,
4419 Bugs: ProtocolBugs{
4420 OversizedSessionId: true,
4421 },
4422 },
4423 resumeSession: true,
4424 shouldFail: true,
4425 expectedError: ":DECODE_ERROR:",
4426 })
4427 }
4428
4429 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4430 // are ignored.
4431 if ver.hasDTLS {
4432 testCases = append(testCases, testCase{
4433 protocol: dtls,
4434 name: "SRTP-Client-" + ver.name,
4435 config: Config{
4436 MaxVersion: ver.version,
4437 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4438 },
4439 flags: []string{
4440 "-srtp-profiles",
4441 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4442 },
4443 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4444 })
4445 testCases = append(testCases, testCase{
4446 protocol: dtls,
4447 testType: serverTest,
4448 name: "SRTP-Server-" + ver.name,
4449 config: Config{
4450 MaxVersion: ver.version,
4451 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4452 },
4453 flags: []string{
4454 "-srtp-profiles",
4455 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4456 },
4457 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4458 })
4459 // Test that the MKI is ignored.
4460 testCases = append(testCases, testCase{
4461 protocol: dtls,
4462 testType: serverTest,
4463 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4464 config: Config{
4465 MaxVersion: ver.version,
4466 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4467 Bugs: ProtocolBugs{
4468 SRTPMasterKeyIdentifer: "bogus",
4469 },
4470 },
4471 flags: []string{
4472 "-srtp-profiles",
4473 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4474 },
4475 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4476 })
4477 // Test that SRTP isn't negotiated on the server if there were
4478 // no matching profiles.
4479 testCases = append(testCases, testCase{
4480 protocol: dtls,
4481 testType: serverTest,
4482 name: "SRTP-Server-NoMatch-" + ver.name,
4483 config: Config{
4484 MaxVersion: ver.version,
4485 SRTPProtectionProfiles: []uint16{100, 101, 102},
4486 },
4487 flags: []string{
4488 "-srtp-profiles",
4489 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4490 },
4491 expectedSRTPProtectionProfile: 0,
4492 })
4493 // Test that the server returning an invalid SRTP profile is
4494 // flagged as an error by the client.
4495 testCases = append(testCases, testCase{
4496 protocol: dtls,
4497 name: "SRTP-Client-NoMatch-" + ver.name,
4498 config: Config{
4499 MaxVersion: ver.version,
4500 Bugs: ProtocolBugs{
4501 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4502 },
4503 },
4504 flags: []string{
4505 "-srtp-profiles",
4506 "SRTP_AES128_CM_SHA1_80",
4507 },
4508 shouldFail: true,
4509 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4510 })
4511 }
4512
4513 // Test SCT list.
4514 testCases = append(testCases, testCase{
4515 name: "SignedCertificateTimestampList-Client-" + ver.name,
4516 testType: clientTest,
4517 config: Config{
4518 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004519 },
David Benjamin97d17d92016-07-14 16:12:00 -04004520 flags: []string{
4521 "-enable-signed-cert-timestamps",
4522 "-expect-signed-cert-timestamps",
4523 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004524 },
David Benjamin97d17d92016-07-14 16:12:00 -04004525 resumeSession: resumeSession,
4526 })
4527 testCases = append(testCases, testCase{
4528 name: "SendSCTListOnResume-" + ver.name,
4529 config: Config{
4530 MaxVersion: ver.version,
4531 Bugs: ProtocolBugs{
4532 SendSCTListOnResume: []byte("bogus"),
4533 },
David Benjamind98452d2015-06-16 14:16:23 -04004534 },
David Benjamin97d17d92016-07-14 16:12:00 -04004535 flags: []string{
4536 "-enable-signed-cert-timestamps",
4537 "-expect-signed-cert-timestamps",
4538 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004539 },
David Benjamin97d17d92016-07-14 16:12:00 -04004540 resumeSession: resumeSession,
4541 })
4542 testCases = append(testCases, testCase{
4543 name: "SignedCertificateTimestampList-Server-" + ver.name,
4544 testType: serverTest,
4545 config: Config{
4546 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004547 },
David Benjamin97d17d92016-07-14 16:12:00 -04004548 flags: []string{
4549 "-signed-cert-timestamps",
4550 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004551 },
David Benjamin97d17d92016-07-14 16:12:00 -04004552 expectedSCTList: testSCTList,
4553 resumeSession: resumeSession,
4554 })
4555 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004556
Paul Lietar4fac72e2015-09-09 13:44:55 +01004557 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004558 testType: clientTest,
4559 name: "ClientHelloPadding",
4560 config: Config{
4561 Bugs: ProtocolBugs{
4562 RequireClientHelloSize: 512,
4563 },
4564 },
4565 // This hostname just needs to be long enough to push the
4566 // ClientHello into F5's danger zone between 256 and 511 bytes
4567 // long.
4568 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4569 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004570
4571 // Extensions should not function in SSL 3.0.
4572 testCases = append(testCases, testCase{
4573 testType: serverTest,
4574 name: "SSLv3Extensions-NoALPN",
4575 config: Config{
4576 MaxVersion: VersionSSL30,
4577 NextProtos: []string{"foo", "bar", "baz"},
4578 },
4579 flags: []string{
4580 "-select-alpn", "foo",
4581 },
4582 expectNoNextProto: true,
4583 })
4584
4585 // Test session tickets separately as they follow a different codepath.
4586 testCases = append(testCases, testCase{
4587 testType: serverTest,
4588 name: "SSLv3Extensions-NoTickets",
4589 config: Config{
4590 MaxVersion: VersionSSL30,
4591 Bugs: ProtocolBugs{
4592 // Historically, session tickets in SSL 3.0
4593 // failed in different ways depending on whether
4594 // the client supported renegotiation_info.
4595 NoRenegotiationInfo: true,
4596 },
4597 },
4598 resumeSession: true,
4599 })
4600 testCases = append(testCases, testCase{
4601 testType: serverTest,
4602 name: "SSLv3Extensions-NoTickets2",
4603 config: Config{
4604 MaxVersion: VersionSSL30,
4605 },
4606 resumeSession: true,
4607 })
4608
4609 // But SSL 3.0 does send and process renegotiation_info.
4610 testCases = append(testCases, testCase{
4611 testType: serverTest,
4612 name: "SSLv3Extensions-RenegotiationInfo",
4613 config: Config{
4614 MaxVersion: VersionSSL30,
4615 Bugs: ProtocolBugs{
4616 RequireRenegotiationInfo: true,
4617 },
4618 },
4619 })
4620 testCases = append(testCases, testCase{
4621 testType: serverTest,
4622 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4623 config: Config{
4624 MaxVersion: VersionSSL30,
4625 Bugs: ProtocolBugs{
4626 NoRenegotiationInfo: true,
4627 SendRenegotiationSCSV: true,
4628 RequireRenegotiationInfo: true,
4629 },
4630 },
4631 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004632
4633 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4634 // in ServerHello.
4635 testCases = append(testCases, testCase{
4636 name: "NPN-Forbidden-TLS13",
4637 config: Config{
4638 MaxVersion: VersionTLS13,
4639 NextProtos: []string{"foo"},
4640 Bugs: ProtocolBugs{
4641 NegotiateNPNAtAllVersions: true,
4642 },
4643 },
4644 flags: []string{"-select-next-proto", "foo"},
4645 shouldFail: true,
4646 expectedError: ":ERROR_PARSING_EXTENSION:",
4647 })
4648 testCases = append(testCases, testCase{
4649 name: "EMS-Forbidden-TLS13",
4650 config: Config{
4651 MaxVersion: VersionTLS13,
4652 Bugs: ProtocolBugs{
4653 NegotiateEMSAtAllVersions: true,
4654 },
4655 },
4656 shouldFail: true,
4657 expectedError: ":ERROR_PARSING_EXTENSION:",
4658 })
4659 testCases = append(testCases, testCase{
4660 name: "RenegotiationInfo-Forbidden-TLS13",
4661 config: Config{
4662 MaxVersion: VersionTLS13,
4663 Bugs: ProtocolBugs{
4664 NegotiateRenegotiationInfoAtAllVersions: true,
4665 },
4666 },
4667 shouldFail: true,
4668 expectedError: ":ERROR_PARSING_EXTENSION:",
4669 })
4670 testCases = append(testCases, testCase{
4671 name: "ChannelID-Forbidden-TLS13",
4672 config: Config{
4673 MaxVersion: VersionTLS13,
4674 RequestChannelID: true,
4675 Bugs: ProtocolBugs{
4676 NegotiateChannelIDAtAllVersions: true,
4677 },
4678 },
4679 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4680 shouldFail: true,
4681 expectedError: ":ERROR_PARSING_EXTENSION:",
4682 })
4683 testCases = append(testCases, testCase{
4684 name: "Ticket-Forbidden-TLS13",
4685 config: Config{
4686 MaxVersion: VersionTLS12,
4687 },
4688 resumeConfig: &Config{
4689 MaxVersion: VersionTLS13,
4690 Bugs: ProtocolBugs{
4691 AdvertiseTicketExtension: true,
4692 },
4693 },
4694 resumeSession: true,
4695 shouldFail: true,
4696 expectedError: ":ERROR_PARSING_EXTENSION:",
4697 })
4698
4699 // Test that illegal extensions in TLS 1.3 are declined by the server if
4700 // offered in ClientHello. The runner's server will fail if this occurs,
4701 // so we exercise the offering path. (EMS and Renegotiation Info are
4702 // implicit in every test.)
4703 testCases = append(testCases, testCase{
4704 testType: serverTest,
4705 name: "ChannelID-Declined-TLS13",
4706 config: Config{
4707 MaxVersion: VersionTLS13,
4708 ChannelID: channelIDKey,
4709 },
4710 flags: []string{"-enable-channel-id"},
4711 })
4712 testCases = append(testCases, testCase{
4713 testType: serverTest,
4714 name: "NPN-Server",
4715 config: Config{
4716 MaxVersion: VersionTLS13,
4717 NextProtos: []string{"bar"},
4718 },
4719 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4720 })
David Benjamine78bfde2014-09-06 12:45:15 -04004721}
4722
David Benjamin01fe8202014-09-24 15:21:44 -04004723func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004724 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004725 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4726 if sessionVers.version >= VersionTLS13 {
4727 continue
4728 }
David Benjamin01fe8202014-09-24 15:21:44 -04004729 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004730 if resumeVers.version >= VersionTLS13 {
4731 continue
4732 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004733 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4734 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4735 // TLS 1.3 only shares ciphers with TLS 1.2, so
4736 // we skip certain combinations and use a
4737 // different cipher to test with.
4738 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4739 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4740 continue
4741 }
4742 }
4743
David Benjamin8b8c0062014-11-23 02:47:52 -05004744 protocols := []protocol{tls}
4745 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4746 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004747 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004748 for _, protocol := range protocols {
4749 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4750 if protocol == dtls {
4751 suffix += "-DTLS"
4752 }
4753
David Benjaminece3de92015-03-16 18:02:20 -04004754 if sessionVers.version == resumeVers.version {
4755 testCases = append(testCases, testCase{
4756 protocol: protocol,
4757 name: "Resume-Client" + suffix,
4758 resumeSession: true,
4759 config: Config{
4760 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004761 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004762 },
David Benjaminece3de92015-03-16 18:02:20 -04004763 expectedVersion: sessionVers.version,
4764 expectedResumeVersion: resumeVers.version,
4765 })
4766 } else {
4767 testCases = append(testCases, testCase{
4768 protocol: protocol,
4769 name: "Resume-Client-Mismatch" + suffix,
4770 resumeSession: true,
4771 config: Config{
4772 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004773 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004774 },
David Benjaminece3de92015-03-16 18:02:20 -04004775 expectedVersion: sessionVers.version,
4776 resumeConfig: &Config{
4777 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004778 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004779 Bugs: ProtocolBugs{
4780 AllowSessionVersionMismatch: true,
4781 },
4782 },
4783 expectedResumeVersion: resumeVers.version,
4784 shouldFail: true,
4785 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4786 })
4787 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004788
4789 testCases = append(testCases, testCase{
4790 protocol: protocol,
4791 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004792 resumeSession: true,
4793 config: Config{
4794 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004795 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004796 },
4797 expectedVersion: sessionVers.version,
4798 resumeConfig: &Config{
4799 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004800 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004801 },
4802 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004803 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004804 expectedResumeVersion: resumeVers.version,
4805 })
4806
David Benjamin8b8c0062014-11-23 02:47:52 -05004807 testCases = append(testCases, testCase{
4808 protocol: protocol,
4809 testType: serverTest,
4810 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004811 resumeSession: true,
4812 config: Config{
4813 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004814 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004815 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004816 expectedVersion: sessionVers.version,
4817 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004818 resumeConfig: &Config{
4819 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004820 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004821 },
4822 expectedResumeVersion: resumeVers.version,
4823 })
4824 }
David Benjamin01fe8202014-09-24 15:21:44 -04004825 }
4826 }
David Benjaminece3de92015-03-16 18:02:20 -04004827
Nick Harper1fd39d82016-06-14 18:14:35 -07004828 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004829 testCases = append(testCases, testCase{
4830 name: "Resume-Client-CipherMismatch",
4831 resumeSession: true,
4832 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004833 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004834 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4835 },
4836 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004837 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004838 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4839 Bugs: ProtocolBugs{
4840 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4841 },
4842 },
4843 shouldFail: true,
4844 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4845 })
David Benjamin01fe8202014-09-24 15:21:44 -04004846}
4847
Adam Langley2ae77d22014-10-28 17:29:33 -07004848func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004849 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004850 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004851 testType: serverTest,
4852 name: "Renegotiate-Server-Forbidden",
4853 config: Config{
4854 MaxVersion: VersionTLS12,
4855 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004856 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004857 shouldFail: true,
4858 expectedError: ":NO_RENEGOTIATION:",
4859 expectedLocalError: "remote error: no renegotiation",
4860 })
Adam Langley5021b222015-06-12 18:27:58 -07004861 // The server shouldn't echo the renegotiation extension unless
4862 // requested by the client.
4863 testCases = append(testCases, testCase{
4864 testType: serverTest,
4865 name: "Renegotiate-Server-NoExt",
4866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004867 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004868 Bugs: ProtocolBugs{
4869 NoRenegotiationInfo: true,
4870 RequireRenegotiationInfo: true,
4871 },
4872 },
4873 shouldFail: true,
4874 expectedLocalError: "renegotiation extension missing",
4875 })
4876 // The renegotiation SCSV should be sufficient for the server to echo
4877 // the extension.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "Renegotiate-Server-NoExt-SCSV",
4881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004882 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004883 Bugs: ProtocolBugs{
4884 NoRenegotiationInfo: true,
4885 SendRenegotiationSCSV: true,
4886 RequireRenegotiationInfo: true,
4887 },
4888 },
4889 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004890 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004891 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004893 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004894 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004895 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004896 },
4897 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004898 renegotiate: 1,
4899 flags: []string{
4900 "-renegotiate-freely",
4901 "-expect-total-renegotiations", "1",
4902 },
David Benjamincdea40c2015-03-19 14:09:43 -04004903 })
4904 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004905 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004906 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004907 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004908 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004909 Bugs: ProtocolBugs{
4910 EmptyRenegotiationInfo: true,
4911 },
4912 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004913 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004914 shouldFail: true,
4915 expectedError: ":RENEGOTIATION_MISMATCH:",
4916 })
4917 testCases = append(testCases, testCase{
4918 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004919 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004920 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004921 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004922 Bugs: ProtocolBugs{
4923 BadRenegotiationInfo: true,
4924 },
4925 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004926 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004927 shouldFail: true,
4928 expectedError: ":RENEGOTIATION_MISMATCH:",
4929 })
4930 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004931 name: "Renegotiate-Client-Downgrade",
4932 renegotiate: 1,
4933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004934 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004935 Bugs: ProtocolBugs{
4936 NoRenegotiationInfoAfterInitial: true,
4937 },
4938 },
4939 flags: []string{"-renegotiate-freely"},
4940 shouldFail: true,
4941 expectedError: ":RENEGOTIATION_MISMATCH:",
4942 })
4943 testCases = append(testCases, testCase{
4944 name: "Renegotiate-Client-Upgrade",
4945 renegotiate: 1,
4946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004947 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004948 Bugs: ProtocolBugs{
4949 NoRenegotiationInfoInInitial: true,
4950 },
4951 },
4952 flags: []string{"-renegotiate-freely"},
4953 shouldFail: true,
4954 expectedError: ":RENEGOTIATION_MISMATCH:",
4955 })
4956 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004957 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004958 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004960 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004961 Bugs: ProtocolBugs{
4962 NoRenegotiationInfo: true,
4963 },
4964 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004965 flags: []string{
4966 "-renegotiate-freely",
4967 "-expect-total-renegotiations", "1",
4968 },
David Benjamincff0b902015-05-15 23:09:47 -04004969 })
4970 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004971 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004972 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004973 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004974 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004975 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4976 },
4977 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004978 flags: []string{
4979 "-renegotiate-freely",
4980 "-expect-total-renegotiations", "1",
4981 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004982 })
4983 testCases = append(testCases, testCase{
4984 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004985 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004986 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004987 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004988 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4989 },
4990 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004991 flags: []string{
4992 "-renegotiate-freely",
4993 "-expect-total-renegotiations", "1",
4994 },
David Benjaminb16346b2015-04-08 19:16:58 -04004995 })
4996 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004997 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004998 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004999 config: Config{
5000 MaxVersion: VersionTLS10,
5001 Bugs: ProtocolBugs{
5002 RequireSameRenegoClientVersion: true,
5003 },
5004 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005005 flags: []string{
5006 "-renegotiate-freely",
5007 "-expect-total-renegotiations", "1",
5008 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005009 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005010 testCases = append(testCases, testCase{
5011 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005012 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005013 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005014 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5016 NextProtos: []string{"foo"},
5017 },
5018 flags: []string{
5019 "-false-start",
5020 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005021 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005022 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005023 },
5024 shimWritesFirst: true,
5025 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005026
5027 // Client-side renegotiation controls.
5028 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005029 name: "Renegotiate-Client-Forbidden-1",
5030 config: Config{
5031 MaxVersion: VersionTLS12,
5032 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005033 renegotiate: 1,
5034 shouldFail: true,
5035 expectedError: ":NO_RENEGOTIATION:",
5036 expectedLocalError: "remote error: no renegotiation",
5037 })
5038 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005039 name: "Renegotiate-Client-Once-1",
5040 config: Config{
5041 MaxVersion: VersionTLS12,
5042 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005043 renegotiate: 1,
5044 flags: []string{
5045 "-renegotiate-once",
5046 "-expect-total-renegotiations", "1",
5047 },
5048 })
5049 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005050 name: "Renegotiate-Client-Freely-1",
5051 config: Config{
5052 MaxVersion: VersionTLS12,
5053 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005054 renegotiate: 1,
5055 flags: []string{
5056 "-renegotiate-freely",
5057 "-expect-total-renegotiations", "1",
5058 },
5059 })
5060 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061 name: "Renegotiate-Client-Once-2",
5062 config: Config{
5063 MaxVersion: VersionTLS12,
5064 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005065 renegotiate: 2,
5066 flags: []string{"-renegotiate-once"},
5067 shouldFail: true,
5068 expectedError: ":NO_RENEGOTIATION:",
5069 expectedLocalError: "remote error: no renegotiation",
5070 })
5071 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005072 name: "Renegotiate-Client-Freely-2",
5073 config: Config{
5074 MaxVersion: VersionTLS12,
5075 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005076 renegotiate: 2,
5077 flags: []string{
5078 "-renegotiate-freely",
5079 "-expect-total-renegotiations", "2",
5080 },
5081 })
Adam Langley27a0d082015-11-03 13:34:10 -08005082 testCases = append(testCases, testCase{
5083 name: "Renegotiate-Client-NoIgnore",
5084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005085 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005086 Bugs: ProtocolBugs{
5087 SendHelloRequestBeforeEveryAppDataRecord: true,
5088 },
5089 },
5090 shouldFail: true,
5091 expectedError: ":NO_RENEGOTIATION:",
5092 })
5093 testCases = append(testCases, testCase{
5094 name: "Renegotiate-Client-Ignore",
5095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005096 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005097 Bugs: ProtocolBugs{
5098 SendHelloRequestBeforeEveryAppDataRecord: true,
5099 },
5100 },
5101 flags: []string{
5102 "-renegotiate-ignore",
5103 "-expect-total-renegotiations", "0",
5104 },
5105 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005106
David Benjamin397c8e62016-07-08 14:14:36 -07005107 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005108 testCases = append(testCases, testCase{
5109 name: "StrayHelloRequest",
5110 config: Config{
5111 MaxVersion: VersionTLS12,
5112 Bugs: ProtocolBugs{
5113 SendHelloRequestBeforeEveryHandshakeMessage: true,
5114 },
5115 },
5116 })
5117 testCases = append(testCases, testCase{
5118 name: "StrayHelloRequest-Packed",
5119 config: Config{
5120 MaxVersion: VersionTLS12,
5121 Bugs: ProtocolBugs{
5122 PackHandshakeFlight: true,
5123 SendHelloRequestBeforeEveryHandshakeMessage: true,
5124 },
5125 },
5126 })
5127
David Benjamin12d2c482016-07-24 10:56:51 -04005128 // Test renegotiation works if HelloRequest and server Finished come in
5129 // the same record.
5130 testCases = append(testCases, testCase{
5131 name: "Renegotiate-Client-Packed",
5132 config: Config{
5133 MaxVersion: VersionTLS12,
5134 Bugs: ProtocolBugs{
5135 PackHandshakeFlight: true,
5136 PackHelloRequestWithFinished: true,
5137 },
5138 },
5139 renegotiate: 1,
5140 flags: []string{
5141 "-renegotiate-freely",
5142 "-expect-total-renegotiations", "1",
5143 },
5144 })
5145
David Benjamin397c8e62016-07-08 14:14:36 -07005146 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04005147 //
5148 // TODO(davidben): This test current asserts that we ignore
5149 // HelloRequests, but we actually should hard reject them. Fix this
5150 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07005151 testCases = append(testCases, testCase{
5152 name: "Renegotiate-Client-TLS13",
5153 config: Config{
5154 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005155 Bugs: ProtocolBugs{
5156 SendHelloRequestBeforeEveryAppDataRecord: true,
5157 },
David Benjamin397c8e62016-07-08 14:14:36 -07005158 },
David Benjamin397c8e62016-07-08 14:14:36 -07005159 flags: []string{
5160 "-renegotiate-freely",
5161 },
David Benjamin397c8e62016-07-08 14:14:36 -07005162 })
5163
5164 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5165 testCases = append(testCases, testCase{
5166 name: "StrayHelloRequest-TLS13",
5167 config: Config{
5168 MaxVersion: VersionTLS13,
5169 Bugs: ProtocolBugs{
5170 SendHelloRequestBeforeEveryHandshakeMessage: true,
5171 },
5172 },
5173 shouldFail: true,
5174 expectedError: ":UNEXPECTED_MESSAGE:",
5175 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005176}
5177
David Benjamin5e961c12014-11-07 01:48:35 -05005178func addDTLSReplayTests() {
5179 // Test that sequence number replays are detected.
5180 testCases = append(testCases, testCase{
5181 protocol: dtls,
5182 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005183 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005184 replayWrites: true,
5185 })
5186
David Benjamin8e6db492015-07-25 18:29:23 -04005187 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005188 // than the retransmit window.
5189 testCases = append(testCases, testCase{
5190 protocol: dtls,
5191 name: "DTLS-Replay-LargeGaps",
5192 config: Config{
5193 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005194 SequenceNumberMapping: func(in uint64) uint64 {
5195 return in * 127
5196 },
David Benjamin5e961c12014-11-07 01:48:35 -05005197 },
5198 },
David Benjamin8e6db492015-07-25 18:29:23 -04005199 messageCount: 200,
5200 replayWrites: true,
5201 })
5202
5203 // Test the incoming sequence number changing non-monotonically.
5204 testCases = append(testCases, testCase{
5205 protocol: dtls,
5206 name: "DTLS-Replay-NonMonotonic",
5207 config: Config{
5208 Bugs: ProtocolBugs{
5209 SequenceNumberMapping: func(in uint64) uint64 {
5210 return in ^ 31
5211 },
5212 },
5213 },
5214 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005215 replayWrites: true,
5216 })
5217}
5218
Nick Harper60edffd2016-06-21 15:19:24 -07005219var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005220 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005221 id signatureAlgorithm
5222 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005223}{
Nick Harper60edffd2016-06-21 15:19:24 -07005224 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5225 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5226 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5227 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005228 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005229 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5230 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5231 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005232 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5233 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5234 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005235 // Tests for key types prior to TLS 1.2.
5236 {"RSA", 0, testCertRSA},
5237 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005238}
5239
Nick Harper60edffd2016-06-21 15:19:24 -07005240const fakeSigAlg1 signatureAlgorithm = 0x2a01
5241const fakeSigAlg2 signatureAlgorithm = 0xff01
5242
5243func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005244 // Not all ciphers involve a signature. Advertise a list which gives all
5245 // versions a signing cipher.
5246 signingCiphers := []uint16{
5247 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5248 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5249 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5250 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5251 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5252 }
5253
David Benjaminca3d5452016-07-14 12:51:01 -04005254 var allAlgorithms []signatureAlgorithm
5255 for _, alg := range testSignatureAlgorithms {
5256 if alg.id != 0 {
5257 allAlgorithms = append(allAlgorithms, alg.id)
5258 }
5259 }
5260
Nick Harper60edffd2016-06-21 15:19:24 -07005261 // Make sure each signature algorithm works. Include some fake values in
5262 // the list and ensure they're ignored.
5263 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005264 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005265 if (ver.version < VersionTLS12) != (alg.id == 0) {
5266 continue
5267 }
5268
5269 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5270 // or remove it in C.
5271 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005272 continue
5273 }
Nick Harper60edffd2016-06-21 15:19:24 -07005274
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005275 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005276 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005277 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5278 shouldFail = true
5279 }
5280 // RSA-PSS does not exist in TLS 1.2.
5281 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5282 shouldFail = true
5283 }
5284
5285 var signError, verifyError string
5286 if shouldFail {
5287 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5288 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005289 }
David Benjamin000800a2014-11-14 01:43:59 -05005290
David Benjamin1fb125c2016-07-08 18:52:12 -07005291 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005292
David Benjamin7a41d372016-07-09 11:21:54 -07005293 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005294 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005295 config: Config{
5296 MaxVersion: ver.version,
5297 ClientAuth: RequireAnyClientCert,
5298 VerifySignatureAlgorithms: []signatureAlgorithm{
5299 fakeSigAlg1,
5300 alg.id,
5301 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005302 },
David Benjamin7a41d372016-07-09 11:21:54 -07005303 },
5304 flags: []string{
5305 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5306 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5307 "-enable-all-curves",
5308 },
5309 shouldFail: shouldFail,
5310 expectedError: signError,
5311 expectedPeerSignatureAlgorithm: alg.id,
5312 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005313
David Benjamin7a41d372016-07-09 11:21:54 -07005314 testCases = append(testCases, testCase{
5315 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005316 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005317 config: Config{
5318 MaxVersion: ver.version,
5319 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5320 SignSignatureAlgorithms: []signatureAlgorithm{
5321 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005322 },
David Benjamin7a41d372016-07-09 11:21:54 -07005323 Bugs: ProtocolBugs{
5324 SkipECDSACurveCheck: shouldFail,
5325 IgnoreSignatureVersionChecks: shouldFail,
5326 // The client won't advertise 1.3-only algorithms after
5327 // version negotiation.
5328 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005329 },
David Benjamin7a41d372016-07-09 11:21:54 -07005330 },
5331 flags: []string{
5332 "-require-any-client-certificate",
5333 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5334 "-enable-all-curves",
5335 },
5336 shouldFail: shouldFail,
5337 expectedError: verifyError,
5338 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005339
5340 testCases = append(testCases, testCase{
5341 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005342 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005343 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005344 MaxVersion: ver.version,
5345 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005346 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005347 fakeSigAlg1,
5348 alg.id,
5349 fakeSigAlg2,
5350 },
5351 },
5352 flags: []string{
5353 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5354 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5355 "-enable-all-curves",
5356 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005357 shouldFail: shouldFail,
5358 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005359 expectedPeerSignatureAlgorithm: alg.id,
5360 })
5361
5362 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005363 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005364 config: Config{
5365 MaxVersion: ver.version,
5366 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005367 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005368 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005369 alg.id,
5370 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005371 Bugs: ProtocolBugs{
5372 SkipECDSACurveCheck: shouldFail,
5373 IgnoreSignatureVersionChecks: shouldFail,
5374 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005375 },
5376 flags: []string{
5377 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5378 "-enable-all-curves",
5379 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005380 shouldFail: shouldFail,
5381 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005382 })
David Benjamin5208fd42016-07-13 21:43:25 -04005383
5384 if !shouldFail {
5385 testCases = append(testCases, testCase{
5386 testType: serverTest,
5387 name: "ClientAuth-InvalidSignature" + suffix,
5388 config: Config{
5389 MaxVersion: ver.version,
5390 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5391 SignSignatureAlgorithms: []signatureAlgorithm{
5392 alg.id,
5393 },
5394 Bugs: ProtocolBugs{
5395 InvalidSignature: true,
5396 },
5397 },
5398 flags: []string{
5399 "-require-any-client-certificate",
5400 "-enable-all-curves",
5401 },
5402 shouldFail: true,
5403 expectedError: ":BAD_SIGNATURE:",
5404 })
5405
5406 testCases = append(testCases, testCase{
5407 name: "ServerAuth-InvalidSignature" + suffix,
5408 config: Config{
5409 MaxVersion: ver.version,
5410 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5411 CipherSuites: signingCiphers,
5412 SignSignatureAlgorithms: []signatureAlgorithm{
5413 alg.id,
5414 },
5415 Bugs: ProtocolBugs{
5416 InvalidSignature: true,
5417 },
5418 },
5419 flags: []string{"-enable-all-curves"},
5420 shouldFail: true,
5421 expectedError: ":BAD_SIGNATURE:",
5422 })
5423 }
David Benjaminca3d5452016-07-14 12:51:01 -04005424
5425 if ver.version >= VersionTLS12 && !shouldFail {
5426 testCases = append(testCases, testCase{
5427 name: "ClientAuth-Sign-Negotiate" + suffix,
5428 config: Config{
5429 MaxVersion: ver.version,
5430 ClientAuth: RequireAnyClientCert,
5431 VerifySignatureAlgorithms: allAlgorithms,
5432 },
5433 flags: []string{
5434 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5435 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5436 "-enable-all-curves",
5437 "-signing-prefs", strconv.Itoa(int(alg.id)),
5438 },
5439 expectedPeerSignatureAlgorithm: alg.id,
5440 })
5441
5442 testCases = append(testCases, testCase{
5443 testType: serverTest,
5444 name: "ServerAuth-Sign-Negotiate" + suffix,
5445 config: Config{
5446 MaxVersion: ver.version,
5447 CipherSuites: signingCiphers,
5448 VerifySignatureAlgorithms: allAlgorithms,
5449 },
5450 flags: []string{
5451 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5452 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5453 "-enable-all-curves",
5454 "-signing-prefs", strconv.Itoa(int(alg.id)),
5455 },
5456 expectedPeerSignatureAlgorithm: alg.id,
5457 })
5458 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005459 }
David Benjamin000800a2014-11-14 01:43:59 -05005460 }
5461
Nick Harper60edffd2016-06-21 15:19:24 -07005462 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005463 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005464 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005465 config: Config{
5466 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005467 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005468 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005469 signatureECDSAWithP521AndSHA512,
5470 signatureRSAPKCS1WithSHA384,
5471 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005472 },
5473 },
5474 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005475 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5476 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005477 },
Nick Harper60edffd2016-06-21 15:19:24 -07005478 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005479 })
5480
5481 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005482 name: "ClientAuth-SignatureType-TLS13",
5483 config: Config{
5484 ClientAuth: RequireAnyClientCert,
5485 MaxVersion: VersionTLS13,
5486 VerifySignatureAlgorithms: []signatureAlgorithm{
5487 signatureECDSAWithP521AndSHA512,
5488 signatureRSAPKCS1WithSHA384,
5489 signatureRSAPSSWithSHA384,
5490 signatureECDSAWithSHA1,
5491 },
5492 },
5493 flags: []string{
5494 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5495 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5496 },
5497 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5498 })
5499
5500 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005501 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005502 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005504 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005506 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005507 signatureECDSAWithP521AndSHA512,
5508 signatureRSAPKCS1WithSHA384,
5509 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005510 },
5511 },
Nick Harper60edffd2016-06-21 15:19:24 -07005512 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005513 })
5514
Steven Valdez143e8b32016-07-11 13:19:03 -04005515 testCases = append(testCases, testCase{
5516 testType: serverTest,
5517 name: "ServerAuth-SignatureType-TLS13",
5518 config: Config{
5519 MaxVersion: VersionTLS13,
5520 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5521 VerifySignatureAlgorithms: []signatureAlgorithm{
5522 signatureECDSAWithP521AndSHA512,
5523 signatureRSAPKCS1WithSHA384,
5524 signatureRSAPSSWithSHA384,
5525 signatureECDSAWithSHA1,
5526 },
5527 },
5528 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5529 })
5530
David Benjamina95e9f32016-07-08 16:28:04 -07005531 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005532 testCases = append(testCases, testCase{
5533 testType: serverTest,
5534 name: "Verify-ClientAuth-SignatureType",
5535 config: Config{
5536 MaxVersion: VersionTLS12,
5537 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005538 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005539 signatureRSAPKCS1WithSHA256,
5540 },
5541 Bugs: ProtocolBugs{
5542 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5543 },
5544 },
5545 flags: []string{
5546 "-require-any-client-certificate",
5547 },
5548 shouldFail: true,
5549 expectedError: ":WRONG_SIGNATURE_TYPE:",
5550 })
5551
5552 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005553 testType: serverTest,
5554 name: "Verify-ClientAuth-SignatureType-TLS13",
5555 config: Config{
5556 MaxVersion: VersionTLS13,
5557 Certificates: []Certificate{rsaCertificate},
5558 SignSignatureAlgorithms: []signatureAlgorithm{
5559 signatureRSAPSSWithSHA256,
5560 },
5561 Bugs: ProtocolBugs{
5562 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5563 },
5564 },
5565 flags: []string{
5566 "-require-any-client-certificate",
5567 },
5568 shouldFail: true,
5569 expectedError: ":WRONG_SIGNATURE_TYPE:",
5570 })
5571
5572 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005573 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005574 config: Config{
5575 MaxVersion: VersionTLS12,
5576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005577 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005578 signatureRSAPKCS1WithSHA256,
5579 },
5580 Bugs: ProtocolBugs{
5581 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5582 },
5583 },
5584 shouldFail: true,
5585 expectedError: ":WRONG_SIGNATURE_TYPE:",
5586 })
5587
Steven Valdez143e8b32016-07-11 13:19:03 -04005588 testCases = append(testCases, testCase{
5589 name: "Verify-ServerAuth-SignatureType-TLS13",
5590 config: Config{
5591 MaxVersion: VersionTLS13,
5592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5593 SignSignatureAlgorithms: []signatureAlgorithm{
5594 signatureRSAPSSWithSHA256,
5595 },
5596 Bugs: ProtocolBugs{
5597 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5598 },
5599 },
5600 shouldFail: true,
5601 expectedError: ":WRONG_SIGNATURE_TYPE:",
5602 })
5603
David Benjamin51dd7d62016-07-08 16:07:01 -07005604 // Test that, if the list is missing, the peer falls back to SHA-1 in
5605 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005606 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005607 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005608 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005609 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005610 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005611 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005612 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005613 },
5614 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005615 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005616 },
5617 },
5618 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005619 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5620 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005621 },
5622 })
5623
5624 testCases = append(testCases, testCase{
5625 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005626 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005628 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005629 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005630 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005631 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005632 },
5633 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005634 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005635 },
5636 },
5637 })
David Benjamin72dc7832015-03-16 17:49:43 -04005638
David Benjamin51dd7d62016-07-08 16:07:01 -07005639 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005640 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005641 config: Config{
5642 MaxVersion: VersionTLS13,
5643 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005644 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005645 signatureRSAPKCS1WithSHA1,
5646 },
5647 Bugs: ProtocolBugs{
5648 NoSignatureAlgorithms: true,
5649 },
5650 },
5651 flags: []string{
5652 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5653 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5654 },
5655 shouldFail: true,
5656 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5657 })
5658
5659 testCases = append(testCases, testCase{
5660 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005661 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005662 config: Config{
5663 MaxVersion: VersionTLS13,
5664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005665 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005666 signatureRSAPKCS1WithSHA1,
5667 },
5668 Bugs: ProtocolBugs{
5669 NoSignatureAlgorithms: true,
5670 },
5671 },
5672 shouldFail: true,
5673 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5674 })
5675
David Benjaminb62d2872016-07-18 14:55:02 +02005676 // Test that hash preferences are enforced. BoringSSL does not implement
5677 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005678 testCases = append(testCases, testCase{
5679 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005680 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005681 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005682 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005683 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005684 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005685 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005686 },
5687 Bugs: ProtocolBugs{
5688 IgnorePeerSignatureAlgorithmPreferences: true,
5689 },
5690 },
5691 flags: []string{"-require-any-client-certificate"},
5692 shouldFail: true,
5693 expectedError: ":WRONG_SIGNATURE_TYPE:",
5694 })
5695
5696 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005697 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005699 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005700 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005701 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005702 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005703 },
5704 Bugs: ProtocolBugs{
5705 IgnorePeerSignatureAlgorithmPreferences: true,
5706 },
5707 },
5708 shouldFail: true,
5709 expectedError: ":WRONG_SIGNATURE_TYPE:",
5710 })
David Benjaminb62d2872016-07-18 14:55:02 +02005711 testCases = append(testCases, testCase{
5712 testType: serverTest,
5713 name: "ClientAuth-Enforced-TLS13",
5714 config: Config{
5715 MaxVersion: VersionTLS13,
5716 Certificates: []Certificate{rsaCertificate},
5717 SignSignatureAlgorithms: []signatureAlgorithm{
5718 signatureRSAPKCS1WithMD5,
5719 },
5720 Bugs: ProtocolBugs{
5721 IgnorePeerSignatureAlgorithmPreferences: true,
5722 IgnoreSignatureVersionChecks: true,
5723 },
5724 },
5725 flags: []string{"-require-any-client-certificate"},
5726 shouldFail: true,
5727 expectedError: ":WRONG_SIGNATURE_TYPE:",
5728 })
5729
5730 testCases = append(testCases, testCase{
5731 name: "ServerAuth-Enforced-TLS13",
5732 config: Config{
5733 MaxVersion: VersionTLS13,
5734 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5735 SignSignatureAlgorithms: []signatureAlgorithm{
5736 signatureRSAPKCS1WithMD5,
5737 },
5738 Bugs: ProtocolBugs{
5739 IgnorePeerSignatureAlgorithmPreferences: true,
5740 IgnoreSignatureVersionChecks: true,
5741 },
5742 },
5743 shouldFail: true,
5744 expectedError: ":WRONG_SIGNATURE_TYPE:",
5745 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005746
5747 // Test that the agreed upon digest respects the client preferences and
5748 // the server digests.
5749 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005750 name: "NoCommonAlgorithms-Digests",
5751 config: Config{
5752 MaxVersion: VersionTLS12,
5753 ClientAuth: RequireAnyClientCert,
5754 VerifySignatureAlgorithms: []signatureAlgorithm{
5755 signatureRSAPKCS1WithSHA512,
5756 signatureRSAPKCS1WithSHA1,
5757 },
5758 },
5759 flags: []string{
5760 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5761 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5762 "-digest-prefs", "SHA256",
5763 },
5764 shouldFail: true,
5765 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5766 })
5767 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005768 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005769 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005770 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005771 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005772 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005773 signatureRSAPKCS1WithSHA512,
5774 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005775 },
5776 },
5777 flags: []string{
5778 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5779 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005780 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005781 },
David Benjaminca3d5452016-07-14 12:51:01 -04005782 shouldFail: true,
5783 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5784 })
5785 testCases = append(testCases, testCase{
5786 name: "NoCommonAlgorithms-TLS13",
5787 config: Config{
5788 MaxVersion: VersionTLS13,
5789 ClientAuth: RequireAnyClientCert,
5790 VerifySignatureAlgorithms: []signatureAlgorithm{
5791 signatureRSAPSSWithSHA512,
5792 signatureRSAPSSWithSHA384,
5793 },
5794 },
5795 flags: []string{
5796 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5797 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5798 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5799 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005800 shouldFail: true,
5801 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005802 })
5803 testCases = append(testCases, testCase{
5804 name: "Agree-Digest-SHA256",
5805 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005806 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005807 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005808 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005809 signatureRSAPKCS1WithSHA1,
5810 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005811 },
5812 },
5813 flags: []string{
5814 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5815 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005816 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005817 },
Nick Harper60edffd2016-06-21 15:19:24 -07005818 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005819 })
5820 testCases = append(testCases, testCase{
5821 name: "Agree-Digest-SHA1",
5822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005823 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005824 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005825 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005826 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005827 },
5828 },
5829 flags: []string{
5830 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5831 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005832 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005833 },
Nick Harper60edffd2016-06-21 15:19:24 -07005834 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005835 })
5836 testCases = append(testCases, testCase{
5837 name: "Agree-Digest-Default",
5838 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005839 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005840 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005841 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005842 signatureRSAPKCS1WithSHA256,
5843 signatureECDSAWithP256AndSHA256,
5844 signatureRSAPKCS1WithSHA1,
5845 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005846 },
5847 },
5848 flags: []string{
5849 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5850 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5851 },
Nick Harper60edffd2016-06-21 15:19:24 -07005852 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005853 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005854
David Benjaminca3d5452016-07-14 12:51:01 -04005855 // Test that the signing preference list may include extra algorithms
5856 // without negotiation problems.
5857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "FilterExtraAlgorithms",
5860 config: Config{
5861 MaxVersion: VersionTLS12,
5862 VerifySignatureAlgorithms: []signatureAlgorithm{
5863 signatureRSAPKCS1WithSHA256,
5864 },
5865 },
5866 flags: []string{
5867 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5868 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5869 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5870 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5871 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5872 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5873 },
5874 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5875 })
5876
David Benjamin4c3ddf72016-06-29 18:13:53 -04005877 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5878 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005879 testCases = append(testCases, testCase{
5880 name: "CheckLeafCurve",
5881 config: Config{
5882 MaxVersion: VersionTLS12,
5883 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005884 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005885 },
5886 flags: []string{"-p384-only"},
5887 shouldFail: true,
5888 expectedError: ":BAD_ECC_CERT:",
5889 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005890
5891 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5892 testCases = append(testCases, testCase{
5893 name: "CheckLeafCurve-TLS13",
5894 config: Config{
5895 MaxVersion: VersionTLS13,
5896 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5897 Certificates: []Certificate{ecdsaP256Certificate},
5898 },
5899 flags: []string{"-p384-only"},
5900 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005901
5902 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5903 testCases = append(testCases, testCase{
5904 name: "ECDSACurveMismatch-Verify-TLS12",
5905 config: Config{
5906 MaxVersion: VersionTLS12,
5907 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5908 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005909 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005910 signatureECDSAWithP384AndSHA384,
5911 },
5912 },
5913 })
5914
5915 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5916 testCases = append(testCases, testCase{
5917 name: "ECDSACurveMismatch-Verify-TLS13",
5918 config: Config{
5919 MaxVersion: VersionTLS13,
5920 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5921 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005922 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005923 signatureECDSAWithP384AndSHA384,
5924 },
5925 Bugs: ProtocolBugs{
5926 SkipECDSACurveCheck: true,
5927 },
5928 },
5929 shouldFail: true,
5930 expectedError: ":WRONG_SIGNATURE_TYPE:",
5931 })
5932
5933 // Signature algorithm selection in TLS 1.3 should take the curve into
5934 // account.
5935 testCases = append(testCases, testCase{
5936 testType: serverTest,
5937 name: "ECDSACurveMismatch-Sign-TLS13",
5938 config: Config{
5939 MaxVersion: VersionTLS13,
5940 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005941 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005942 signatureECDSAWithP384AndSHA384,
5943 signatureECDSAWithP256AndSHA256,
5944 },
5945 },
5946 flags: []string{
5947 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5948 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5949 },
5950 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5951 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005952
5953 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5954 // server does not attempt to sign in that case.
5955 testCases = append(testCases, testCase{
5956 testType: serverTest,
5957 name: "RSA-PSS-Large",
5958 config: Config{
5959 MaxVersion: VersionTLS13,
5960 VerifySignatureAlgorithms: []signatureAlgorithm{
5961 signatureRSAPSSWithSHA512,
5962 },
5963 },
5964 flags: []string{
5965 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5966 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5967 },
5968 shouldFail: true,
5969 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5970 })
David Benjamin000800a2014-11-14 01:43:59 -05005971}
5972
David Benjamin83f90402015-01-27 01:09:43 -05005973// timeouts is the retransmit schedule for BoringSSL. It doubles and
5974// caps at 60 seconds. On the 13th timeout, it gives up.
5975var timeouts = []time.Duration{
5976 1 * time.Second,
5977 2 * time.Second,
5978 4 * time.Second,
5979 8 * time.Second,
5980 16 * time.Second,
5981 32 * time.Second,
5982 60 * time.Second,
5983 60 * time.Second,
5984 60 * time.Second,
5985 60 * time.Second,
5986 60 * time.Second,
5987 60 * time.Second,
5988 60 * time.Second,
5989}
5990
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005991// shortTimeouts is an alternate set of timeouts which would occur if the
5992// initial timeout duration was set to 250ms.
5993var shortTimeouts = []time.Duration{
5994 250 * time.Millisecond,
5995 500 * time.Millisecond,
5996 1 * time.Second,
5997 2 * time.Second,
5998 4 * time.Second,
5999 8 * time.Second,
6000 16 * time.Second,
6001 32 * time.Second,
6002 60 * time.Second,
6003 60 * time.Second,
6004 60 * time.Second,
6005 60 * time.Second,
6006 60 * time.Second,
6007}
6008
David Benjamin83f90402015-01-27 01:09:43 -05006009func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006010 // These tests work by coordinating some behavior on both the shim and
6011 // the runner.
6012 //
6013 // TimeoutSchedule configures the runner to send a series of timeout
6014 // opcodes to the shim (see packetAdaptor) immediately before reading
6015 // each peer handshake flight N. The timeout opcode both simulates a
6016 // timeout in the shim and acts as a synchronization point to help the
6017 // runner bracket each handshake flight.
6018 //
6019 // We assume the shim does not read from the channel eagerly. It must
6020 // first wait until it has sent flight N and is ready to receive
6021 // handshake flight N+1. At this point, it will process the timeout
6022 // opcode. It must then immediately respond with a timeout ACK and act
6023 // as if the shim was idle for the specified amount of time.
6024 //
6025 // The runner then drops all packets received before the ACK and
6026 // continues waiting for flight N. This ordering results in one attempt
6027 // at sending flight N to be dropped. For the test to complete, the
6028 // shim must send flight N again, testing that the shim implements DTLS
6029 // retransmit on a timeout.
6030
Steven Valdez143e8b32016-07-11 13:19:03 -04006031 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006032 // likely be more epochs to cross and the final message's retransmit may
6033 // be more complex.
6034
David Benjamin585d7a42016-06-02 14:58:00 -04006035 for _, async := range []bool{true, false} {
6036 var tests []testCase
6037
6038 // Test that this is indeed the timeout schedule. Stress all
6039 // four patterns of handshake.
6040 for i := 1; i < len(timeouts); i++ {
6041 number := strconv.Itoa(i)
6042 tests = append(tests, testCase{
6043 protocol: dtls,
6044 name: "DTLS-Retransmit-Client-" + number,
6045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006046 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006047 Bugs: ProtocolBugs{
6048 TimeoutSchedule: timeouts[:i],
6049 },
6050 },
6051 resumeSession: true,
6052 })
6053 tests = append(tests, testCase{
6054 protocol: dtls,
6055 testType: serverTest,
6056 name: "DTLS-Retransmit-Server-" + number,
6057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006058 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006059 Bugs: ProtocolBugs{
6060 TimeoutSchedule: timeouts[:i],
6061 },
6062 },
6063 resumeSession: true,
6064 })
6065 }
6066
6067 // Test that exceeding the timeout schedule hits a read
6068 // timeout.
6069 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006070 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006071 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006073 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006074 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006075 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006076 },
6077 },
6078 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006079 shouldFail: true,
6080 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006081 })
David Benjamin585d7a42016-06-02 14:58:00 -04006082
6083 if async {
6084 // Test that timeout handling has a fudge factor, due to API
6085 // problems.
6086 tests = append(tests, testCase{
6087 protocol: dtls,
6088 name: "DTLS-Retransmit-Fudge",
6089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006090 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006091 Bugs: ProtocolBugs{
6092 TimeoutSchedule: []time.Duration{
6093 timeouts[0] - 10*time.Millisecond,
6094 },
6095 },
6096 },
6097 resumeSession: true,
6098 })
6099 }
6100
6101 // Test that the final Finished retransmitting isn't
6102 // duplicated if the peer badly fragments everything.
6103 tests = append(tests, testCase{
6104 testType: serverTest,
6105 protocol: dtls,
6106 name: "DTLS-Retransmit-Fragmented",
6107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006108 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006109 Bugs: ProtocolBugs{
6110 TimeoutSchedule: []time.Duration{timeouts[0]},
6111 MaxHandshakeRecordLength: 2,
6112 },
6113 },
6114 })
6115
6116 // Test the timeout schedule when a shorter initial timeout duration is set.
6117 tests = append(tests, testCase{
6118 protocol: dtls,
6119 name: "DTLS-Retransmit-Short-Client",
6120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006121 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006122 Bugs: ProtocolBugs{
6123 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6124 },
6125 },
6126 resumeSession: true,
6127 flags: []string{"-initial-timeout-duration-ms", "250"},
6128 })
6129 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006130 protocol: dtls,
6131 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006132 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006134 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006135 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006136 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006137 },
6138 },
6139 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006140 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006141 })
David Benjamin585d7a42016-06-02 14:58:00 -04006142
6143 for _, test := range tests {
6144 if async {
6145 test.name += "-Async"
6146 test.flags = append(test.flags, "-async")
6147 }
6148
6149 testCases = append(testCases, test)
6150 }
David Benjamin83f90402015-01-27 01:09:43 -05006151 }
David Benjamin83f90402015-01-27 01:09:43 -05006152}
6153
David Benjaminc565ebb2015-04-03 04:06:36 -04006154func addExportKeyingMaterialTests() {
6155 for _, vers := range tlsVersions {
6156 if vers.version == VersionSSL30 {
6157 continue
6158 }
6159 testCases = append(testCases, testCase{
6160 name: "ExportKeyingMaterial-" + vers.name,
6161 config: Config{
6162 MaxVersion: vers.version,
6163 },
6164 exportKeyingMaterial: 1024,
6165 exportLabel: "label",
6166 exportContext: "context",
6167 useExportContext: true,
6168 })
6169 testCases = append(testCases, testCase{
6170 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6171 config: Config{
6172 MaxVersion: vers.version,
6173 },
6174 exportKeyingMaterial: 1024,
6175 })
6176 testCases = append(testCases, testCase{
6177 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6178 config: Config{
6179 MaxVersion: vers.version,
6180 },
6181 exportKeyingMaterial: 1024,
6182 useExportContext: true,
6183 })
6184 testCases = append(testCases, testCase{
6185 name: "ExportKeyingMaterial-Small-" + vers.name,
6186 config: Config{
6187 MaxVersion: vers.version,
6188 },
6189 exportKeyingMaterial: 1,
6190 exportLabel: "label",
6191 exportContext: "context",
6192 useExportContext: true,
6193 })
6194 }
6195 testCases = append(testCases, testCase{
6196 name: "ExportKeyingMaterial-SSL3",
6197 config: Config{
6198 MaxVersion: VersionSSL30,
6199 },
6200 exportKeyingMaterial: 1024,
6201 exportLabel: "label",
6202 exportContext: "context",
6203 useExportContext: true,
6204 shouldFail: true,
6205 expectedError: "failed to export keying material",
6206 })
6207}
6208
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006209func addTLSUniqueTests() {
6210 for _, isClient := range []bool{false, true} {
6211 for _, isResumption := range []bool{false, true} {
6212 for _, hasEMS := range []bool{false, true} {
6213 var suffix string
6214 if isResumption {
6215 suffix = "Resume-"
6216 } else {
6217 suffix = "Full-"
6218 }
6219
6220 if hasEMS {
6221 suffix += "EMS-"
6222 } else {
6223 suffix += "NoEMS-"
6224 }
6225
6226 if isClient {
6227 suffix += "Client"
6228 } else {
6229 suffix += "Server"
6230 }
6231
6232 test := testCase{
6233 name: "TLSUnique-" + suffix,
6234 testTLSUnique: true,
6235 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006236 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006237 Bugs: ProtocolBugs{
6238 NoExtendedMasterSecret: !hasEMS,
6239 },
6240 },
6241 }
6242
6243 if isResumption {
6244 test.resumeSession = true
6245 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006246 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006247 Bugs: ProtocolBugs{
6248 NoExtendedMasterSecret: !hasEMS,
6249 },
6250 }
6251 }
6252
6253 if isResumption && !hasEMS {
6254 test.shouldFail = true
6255 test.expectedError = "failed to get tls-unique"
6256 }
6257
6258 testCases = append(testCases, test)
6259 }
6260 }
6261 }
6262}
6263
Adam Langley09505632015-07-30 18:10:13 -07006264func addCustomExtensionTests() {
6265 expectedContents := "custom extension"
6266 emptyString := ""
6267
6268 for _, isClient := range []bool{false, true} {
6269 suffix := "Server"
6270 flag := "-enable-server-custom-extension"
6271 testType := serverTest
6272 if isClient {
6273 suffix = "Client"
6274 flag = "-enable-client-custom-extension"
6275 testType = clientTest
6276 }
6277
6278 testCases = append(testCases, testCase{
6279 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006280 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006282 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006283 Bugs: ProtocolBugs{
6284 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006285 ExpectedCustomExtension: &expectedContents,
6286 },
6287 },
6288 flags: []string{flag},
6289 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006290 testCases = append(testCases, testCase{
6291 testType: testType,
6292 name: "CustomExtensions-" + suffix + "-TLS13",
6293 config: Config{
6294 MaxVersion: VersionTLS13,
6295 Bugs: ProtocolBugs{
6296 CustomExtension: expectedContents,
6297 ExpectedCustomExtension: &expectedContents,
6298 },
6299 },
6300 flags: []string{flag},
6301 })
Adam Langley09505632015-07-30 18:10:13 -07006302
6303 // If the parse callback fails, the handshake should also fail.
6304 testCases = append(testCases, testCase{
6305 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006306 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006308 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006309 Bugs: ProtocolBugs{
6310 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006311 ExpectedCustomExtension: &expectedContents,
6312 },
6313 },
David Benjamin399e7c92015-07-30 23:01:27 -04006314 flags: []string{flag},
6315 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006316 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6317 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006318 testCases = append(testCases, testCase{
6319 testType: testType,
6320 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6321 config: Config{
6322 MaxVersion: VersionTLS13,
6323 Bugs: ProtocolBugs{
6324 CustomExtension: expectedContents + "foo",
6325 ExpectedCustomExtension: &expectedContents,
6326 },
6327 },
6328 flags: []string{flag},
6329 shouldFail: true,
6330 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6331 })
Adam Langley09505632015-07-30 18:10:13 -07006332
6333 // If the add callback fails, the handshake should also fail.
6334 testCases = append(testCases, testCase{
6335 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006336 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006338 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006339 Bugs: ProtocolBugs{
6340 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006341 ExpectedCustomExtension: &expectedContents,
6342 },
6343 },
David Benjamin399e7c92015-07-30 23:01:27 -04006344 flags: []string{flag, "-custom-extension-fail-add"},
6345 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006346 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6347 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006348 testCases = append(testCases, testCase{
6349 testType: testType,
6350 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6351 config: Config{
6352 MaxVersion: VersionTLS13,
6353 Bugs: ProtocolBugs{
6354 CustomExtension: expectedContents,
6355 ExpectedCustomExtension: &expectedContents,
6356 },
6357 },
6358 flags: []string{flag, "-custom-extension-fail-add"},
6359 shouldFail: true,
6360 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6361 })
Adam Langley09505632015-07-30 18:10:13 -07006362
6363 // If the add callback returns zero, no extension should be
6364 // added.
6365 skipCustomExtension := expectedContents
6366 if isClient {
6367 // For the case where the client skips sending the
6368 // custom extension, the server must not “echo” it.
6369 skipCustomExtension = ""
6370 }
6371 testCases = append(testCases, testCase{
6372 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006373 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006375 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006376 Bugs: ProtocolBugs{
6377 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006378 ExpectedCustomExtension: &emptyString,
6379 },
6380 },
6381 flags: []string{flag, "-custom-extension-skip"},
6382 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006383 testCases = append(testCases, testCase{
6384 testType: testType,
6385 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6386 config: Config{
6387 MaxVersion: VersionTLS13,
6388 Bugs: ProtocolBugs{
6389 CustomExtension: skipCustomExtension,
6390 ExpectedCustomExtension: &emptyString,
6391 },
6392 },
6393 flags: []string{flag, "-custom-extension-skip"},
6394 })
Adam Langley09505632015-07-30 18:10:13 -07006395 }
6396
6397 // The custom extension add callback should not be called if the client
6398 // doesn't send the extension.
6399 testCases = append(testCases, testCase{
6400 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006401 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006403 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006404 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006405 ExpectedCustomExtension: &emptyString,
6406 },
6407 },
6408 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6409 })
Adam Langley2deb9842015-08-07 11:15:37 -07006410
Steven Valdez143e8b32016-07-11 13:19:03 -04006411 testCases = append(testCases, testCase{
6412 testType: serverTest,
6413 name: "CustomExtensions-NotCalled-Server-TLS13",
6414 config: Config{
6415 MaxVersion: VersionTLS13,
6416 Bugs: ProtocolBugs{
6417 ExpectedCustomExtension: &emptyString,
6418 },
6419 },
6420 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6421 })
6422
Adam Langley2deb9842015-08-07 11:15:37 -07006423 // Test an unknown extension from the server.
6424 testCases = append(testCases, testCase{
6425 testType: clientTest,
6426 name: "UnknownExtension-Client",
6427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006428 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006429 Bugs: ProtocolBugs{
6430 CustomExtension: expectedContents,
6431 },
6432 },
6433 shouldFail: true,
6434 expectedError: ":UNEXPECTED_EXTENSION:",
6435 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006436 testCases = append(testCases, testCase{
6437 testType: clientTest,
6438 name: "UnknownExtension-Client-TLS13",
6439 config: Config{
6440 MaxVersion: VersionTLS13,
6441 Bugs: ProtocolBugs{
6442 CustomExtension: expectedContents,
6443 },
6444 },
6445 shouldFail: true,
6446 expectedError: ":UNEXPECTED_EXTENSION:",
6447 })
Adam Langley09505632015-07-30 18:10:13 -07006448}
6449
David Benjaminb36a3952015-12-01 18:53:13 -05006450func addRSAClientKeyExchangeTests() {
6451 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6452 testCases = append(testCases, testCase{
6453 testType: serverTest,
6454 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6455 config: Config{
6456 // Ensure the ClientHello version and final
6457 // version are different, to detect if the
6458 // server uses the wrong one.
6459 MaxVersion: VersionTLS11,
6460 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6461 Bugs: ProtocolBugs{
6462 BadRSAClientKeyExchange: bad,
6463 },
6464 },
6465 shouldFail: true,
6466 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6467 })
6468 }
6469}
6470
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006471var testCurves = []struct {
6472 name string
6473 id CurveID
6474}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006475 {"P-256", CurveP256},
6476 {"P-384", CurveP384},
6477 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006478 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006479}
6480
Steven Valdez5440fe02016-07-18 12:40:30 -04006481const bogusCurve = 0x1234
6482
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006483func addCurveTests() {
6484 for _, curve := range testCurves {
6485 testCases = append(testCases, testCase{
6486 name: "CurveTest-Client-" + curve.name,
6487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006488 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6490 CurvePreferences: []CurveID{curve.id},
6491 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006492 flags: []string{"-enable-all-curves"},
6493 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006494 })
6495 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006496 name: "CurveTest-Client-" + curve.name + "-TLS13",
6497 config: Config{
6498 MaxVersion: VersionTLS13,
6499 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6500 CurvePreferences: []CurveID{curve.id},
6501 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006502 flags: []string{"-enable-all-curves"},
6503 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006504 })
6505 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006506 testType: serverTest,
6507 name: "CurveTest-Server-" + curve.name,
6508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006509 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6511 CurvePreferences: []CurveID{curve.id},
6512 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006513 flags: []string{"-enable-all-curves"},
6514 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006515 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006516 testCases = append(testCases, testCase{
6517 testType: serverTest,
6518 name: "CurveTest-Server-" + curve.name + "-TLS13",
6519 config: Config{
6520 MaxVersion: VersionTLS13,
6521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6522 CurvePreferences: []CurveID{curve.id},
6523 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006524 flags: []string{"-enable-all-curves"},
6525 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006526 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006527 }
David Benjamin241ae832016-01-15 03:04:54 -05006528
6529 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006530 testCases = append(testCases, testCase{
6531 testType: serverTest,
6532 name: "UnknownCurve",
6533 config: Config{
6534 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6535 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6536 },
6537 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006538
6539 // The server must not consider ECDHE ciphers when there are no
6540 // supported curves.
6541 testCases = append(testCases, testCase{
6542 testType: serverTest,
6543 name: "NoSupportedCurves",
6544 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006545 MaxVersion: VersionTLS12,
6546 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6547 Bugs: ProtocolBugs{
6548 NoSupportedCurves: true,
6549 },
6550 },
6551 shouldFail: true,
6552 expectedError: ":NO_SHARED_CIPHER:",
6553 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006554 testCases = append(testCases, testCase{
6555 testType: serverTest,
6556 name: "NoSupportedCurves-TLS13",
6557 config: Config{
6558 MaxVersion: VersionTLS13,
6559 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6560 Bugs: ProtocolBugs{
6561 NoSupportedCurves: true,
6562 },
6563 },
6564 shouldFail: true,
6565 expectedError: ":NO_SHARED_CIPHER:",
6566 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006567
6568 // The server must fall back to another cipher when there are no
6569 // supported curves.
6570 testCases = append(testCases, testCase{
6571 testType: serverTest,
6572 name: "NoCommonCurves",
6573 config: Config{
6574 MaxVersion: VersionTLS12,
6575 CipherSuites: []uint16{
6576 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6577 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6578 },
6579 CurvePreferences: []CurveID{CurveP224},
6580 },
6581 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6582 })
6583
6584 // The client must reject bogus curves and disabled curves.
6585 testCases = append(testCases, testCase{
6586 name: "BadECDHECurve",
6587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006588 MaxVersion: VersionTLS12,
6589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6590 Bugs: ProtocolBugs{
6591 SendCurve: bogusCurve,
6592 },
6593 },
6594 shouldFail: true,
6595 expectedError: ":WRONG_CURVE:",
6596 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006597 testCases = append(testCases, testCase{
6598 name: "BadECDHECurve-TLS13",
6599 config: Config{
6600 MaxVersion: VersionTLS13,
6601 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6602 Bugs: ProtocolBugs{
6603 SendCurve: bogusCurve,
6604 },
6605 },
6606 shouldFail: true,
6607 expectedError: ":WRONG_CURVE:",
6608 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006609
6610 testCases = append(testCases, testCase{
6611 name: "UnsupportedCurve",
6612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006613 MaxVersion: VersionTLS12,
6614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6615 CurvePreferences: []CurveID{CurveP256},
6616 Bugs: ProtocolBugs{
6617 IgnorePeerCurvePreferences: true,
6618 },
6619 },
6620 flags: []string{"-p384-only"},
6621 shouldFail: true,
6622 expectedError: ":WRONG_CURVE:",
6623 })
6624
David Benjamin4f921572016-07-17 14:20:10 +02006625 testCases = append(testCases, testCase{
6626 // TODO(davidben): Add a TLS 1.3 version where
6627 // HelloRetryRequest requests an unsupported curve.
6628 name: "UnsupportedCurve-ServerHello-TLS13",
6629 config: Config{
6630 MaxVersion: VersionTLS12,
6631 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6632 CurvePreferences: []CurveID{CurveP384},
6633 Bugs: ProtocolBugs{
6634 SendCurve: CurveP256,
6635 },
6636 },
6637 flags: []string{"-p384-only"},
6638 shouldFail: true,
6639 expectedError: ":WRONG_CURVE:",
6640 })
6641
David Benjamin4c3ddf72016-06-29 18:13:53 -04006642 // Test invalid curve points.
6643 testCases = append(testCases, testCase{
6644 name: "InvalidECDHPoint-Client",
6645 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006646 MaxVersion: VersionTLS12,
6647 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6648 CurvePreferences: []CurveID{CurveP256},
6649 Bugs: ProtocolBugs{
6650 InvalidECDHPoint: true,
6651 },
6652 },
6653 shouldFail: true,
6654 expectedError: ":INVALID_ENCODING:",
6655 })
6656 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006657 name: "InvalidECDHPoint-Client-TLS13",
6658 config: Config{
6659 MaxVersion: VersionTLS13,
6660 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6661 CurvePreferences: []CurveID{CurveP256},
6662 Bugs: ProtocolBugs{
6663 InvalidECDHPoint: true,
6664 },
6665 },
6666 shouldFail: true,
6667 expectedError: ":INVALID_ENCODING:",
6668 })
6669 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670 testType: serverTest,
6671 name: "InvalidECDHPoint-Server",
6672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006673 MaxVersion: VersionTLS12,
6674 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6675 CurvePreferences: []CurveID{CurveP256},
6676 Bugs: ProtocolBugs{
6677 InvalidECDHPoint: true,
6678 },
6679 },
6680 shouldFail: true,
6681 expectedError: ":INVALID_ENCODING:",
6682 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006683 testCases = append(testCases, testCase{
6684 testType: serverTest,
6685 name: "InvalidECDHPoint-Server-TLS13",
6686 config: Config{
6687 MaxVersion: VersionTLS13,
6688 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6689 CurvePreferences: []CurveID{CurveP256},
6690 Bugs: ProtocolBugs{
6691 InvalidECDHPoint: true,
6692 },
6693 },
6694 shouldFail: true,
6695 expectedError: ":INVALID_ENCODING:",
6696 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006697}
6698
Matt Braithwaite54217e42016-06-13 13:03:47 -07006699func addCECPQ1Tests() {
6700 testCases = append(testCases, testCase{
6701 testType: clientTest,
6702 name: "CECPQ1-Client-BadX25519Part",
6703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006704 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006705 MinVersion: VersionTLS12,
6706 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6707 Bugs: ProtocolBugs{
6708 CECPQ1BadX25519Part: true,
6709 },
6710 },
6711 flags: []string{"-cipher", "kCECPQ1"},
6712 shouldFail: true,
6713 expectedLocalError: "local error: bad record MAC",
6714 })
6715 testCases = append(testCases, testCase{
6716 testType: clientTest,
6717 name: "CECPQ1-Client-BadNewhopePart",
6718 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006719 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006720 MinVersion: VersionTLS12,
6721 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6722 Bugs: ProtocolBugs{
6723 CECPQ1BadNewhopePart: true,
6724 },
6725 },
6726 flags: []string{"-cipher", "kCECPQ1"},
6727 shouldFail: true,
6728 expectedLocalError: "local error: bad record MAC",
6729 })
6730 testCases = append(testCases, testCase{
6731 testType: serverTest,
6732 name: "CECPQ1-Server-BadX25519Part",
6733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006734 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006735 MinVersion: VersionTLS12,
6736 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6737 Bugs: ProtocolBugs{
6738 CECPQ1BadX25519Part: true,
6739 },
6740 },
6741 flags: []string{"-cipher", "kCECPQ1"},
6742 shouldFail: true,
6743 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6744 })
6745 testCases = append(testCases, testCase{
6746 testType: serverTest,
6747 name: "CECPQ1-Server-BadNewhopePart",
6748 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006749 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006750 MinVersion: VersionTLS12,
6751 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6752 Bugs: ProtocolBugs{
6753 CECPQ1BadNewhopePart: true,
6754 },
6755 },
6756 flags: []string{"-cipher", "kCECPQ1"},
6757 shouldFail: true,
6758 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6759 })
6760}
6761
David Benjamin4cc36ad2015-12-19 14:23:26 -05006762func addKeyExchangeInfoTests() {
6763 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006764 name: "KeyExchangeInfo-DHE-Client",
6765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006766 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006767 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6768 Bugs: ProtocolBugs{
6769 // This is a 1234-bit prime number, generated
6770 // with:
6771 // openssl gendh 1234 | openssl asn1parse -i
6772 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6773 },
6774 },
David Benjamin9e68f192016-06-30 14:55:33 -04006775 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006776 })
6777 testCases = append(testCases, testCase{
6778 testType: serverTest,
6779 name: "KeyExchangeInfo-DHE-Server",
6780 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006781 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006782 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6783 },
6784 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006785 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006786 })
6787
6788 testCases = append(testCases, testCase{
6789 name: "KeyExchangeInfo-ECDHE-Client",
6790 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006791 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6793 CurvePreferences: []CurveID{CurveX25519},
6794 },
David Benjamin9e68f192016-06-30 14:55:33 -04006795 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006796 })
6797 testCases = append(testCases, testCase{
6798 testType: serverTest,
6799 name: "KeyExchangeInfo-ECDHE-Server",
6800 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006801 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6803 CurvePreferences: []CurveID{CurveX25519},
6804 },
David Benjamin9e68f192016-06-30 14:55:33 -04006805 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006806 })
6807}
6808
David Benjaminc9ae27c2016-06-24 22:56:37 -04006809func addTLS13RecordTests() {
6810 testCases = append(testCases, testCase{
6811 name: "TLS13-RecordPadding",
6812 config: Config{
6813 MaxVersion: VersionTLS13,
6814 MinVersion: VersionTLS13,
6815 Bugs: ProtocolBugs{
6816 RecordPadding: 10,
6817 },
6818 },
6819 })
6820
6821 testCases = append(testCases, testCase{
6822 name: "TLS13-EmptyRecords",
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 MinVersion: VersionTLS13,
6826 Bugs: ProtocolBugs{
6827 OmitRecordContents: true,
6828 },
6829 },
6830 shouldFail: true,
6831 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6832 })
6833
6834 testCases = append(testCases, testCase{
6835 name: "TLS13-OnlyPadding",
6836 config: Config{
6837 MaxVersion: VersionTLS13,
6838 MinVersion: VersionTLS13,
6839 Bugs: ProtocolBugs{
6840 OmitRecordContents: true,
6841 RecordPadding: 10,
6842 },
6843 },
6844 shouldFail: true,
6845 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6846 })
6847
6848 testCases = append(testCases, testCase{
6849 name: "TLS13-WrongOuterRecord",
6850 config: Config{
6851 MaxVersion: VersionTLS13,
6852 MinVersion: VersionTLS13,
6853 Bugs: ProtocolBugs{
6854 OuterRecordType: recordTypeHandshake,
6855 },
6856 },
6857 shouldFail: true,
6858 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6859 })
6860}
6861
David Benjamin82261be2016-07-07 14:32:50 -07006862func addChangeCipherSpecTests() {
6863 // Test missing ChangeCipherSpecs.
6864 testCases = append(testCases, testCase{
6865 name: "SkipChangeCipherSpec-Client",
6866 config: Config{
6867 MaxVersion: VersionTLS12,
6868 Bugs: ProtocolBugs{
6869 SkipChangeCipherSpec: true,
6870 },
6871 },
6872 shouldFail: true,
6873 expectedError: ":UNEXPECTED_RECORD:",
6874 })
6875 testCases = append(testCases, testCase{
6876 testType: serverTest,
6877 name: "SkipChangeCipherSpec-Server",
6878 config: Config{
6879 MaxVersion: VersionTLS12,
6880 Bugs: ProtocolBugs{
6881 SkipChangeCipherSpec: true,
6882 },
6883 },
6884 shouldFail: true,
6885 expectedError: ":UNEXPECTED_RECORD:",
6886 })
6887 testCases = append(testCases, testCase{
6888 testType: serverTest,
6889 name: "SkipChangeCipherSpec-Server-NPN",
6890 config: Config{
6891 MaxVersion: VersionTLS12,
6892 NextProtos: []string{"bar"},
6893 Bugs: ProtocolBugs{
6894 SkipChangeCipherSpec: true,
6895 },
6896 },
6897 flags: []string{
6898 "-advertise-npn", "\x03foo\x03bar\x03baz",
6899 },
6900 shouldFail: true,
6901 expectedError: ":UNEXPECTED_RECORD:",
6902 })
6903
6904 // Test synchronization between the handshake and ChangeCipherSpec.
6905 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6906 // rejected. Test both with and without handshake packing to handle both
6907 // when the partial post-CCS message is in its own record and when it is
6908 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006909 for _, packed := range []bool{false, true} {
6910 var suffix string
6911 if packed {
6912 suffix = "-Packed"
6913 }
6914
6915 testCases = append(testCases, testCase{
6916 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6917 config: Config{
6918 MaxVersion: VersionTLS12,
6919 Bugs: ProtocolBugs{
6920 FragmentAcrossChangeCipherSpec: true,
6921 PackHandshakeFlight: packed,
6922 },
6923 },
6924 shouldFail: true,
6925 expectedError: ":UNEXPECTED_RECORD:",
6926 })
6927 testCases = append(testCases, testCase{
6928 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6929 config: Config{
6930 MaxVersion: VersionTLS12,
6931 },
6932 resumeSession: true,
6933 resumeConfig: &Config{
6934 MaxVersion: VersionTLS12,
6935 Bugs: ProtocolBugs{
6936 FragmentAcrossChangeCipherSpec: true,
6937 PackHandshakeFlight: packed,
6938 },
6939 },
6940 shouldFail: true,
6941 expectedError: ":UNEXPECTED_RECORD:",
6942 })
6943 testCases = append(testCases, testCase{
6944 testType: serverTest,
6945 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6946 config: Config{
6947 MaxVersion: VersionTLS12,
6948 Bugs: ProtocolBugs{
6949 FragmentAcrossChangeCipherSpec: true,
6950 PackHandshakeFlight: packed,
6951 },
6952 },
6953 shouldFail: true,
6954 expectedError: ":UNEXPECTED_RECORD:",
6955 })
6956 testCases = append(testCases, testCase{
6957 testType: serverTest,
6958 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6959 config: Config{
6960 MaxVersion: VersionTLS12,
6961 },
6962 resumeSession: true,
6963 resumeConfig: &Config{
6964 MaxVersion: VersionTLS12,
6965 Bugs: ProtocolBugs{
6966 FragmentAcrossChangeCipherSpec: true,
6967 PackHandshakeFlight: packed,
6968 },
6969 },
6970 shouldFail: true,
6971 expectedError: ":UNEXPECTED_RECORD:",
6972 })
6973 testCases = append(testCases, testCase{
6974 testType: serverTest,
6975 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6976 config: Config{
6977 MaxVersion: VersionTLS12,
6978 NextProtos: []string{"bar"},
6979 Bugs: ProtocolBugs{
6980 FragmentAcrossChangeCipherSpec: true,
6981 PackHandshakeFlight: packed,
6982 },
6983 },
6984 flags: []string{
6985 "-advertise-npn", "\x03foo\x03bar\x03baz",
6986 },
6987 shouldFail: true,
6988 expectedError: ":UNEXPECTED_RECORD:",
6989 })
6990 }
6991
David Benjamin61672812016-07-14 23:10:43 -04006992 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6993 // messages in the handshake queue. Do this by testing the server
6994 // reading the client Finished, reversing the flight so Finished comes
6995 // first.
6996 testCases = append(testCases, testCase{
6997 protocol: dtls,
6998 testType: serverTest,
6999 name: "SendUnencryptedFinished-DTLS",
7000 config: Config{
7001 MaxVersion: VersionTLS12,
7002 Bugs: ProtocolBugs{
7003 SendUnencryptedFinished: true,
7004 ReverseHandshakeFragments: true,
7005 },
7006 },
7007 shouldFail: true,
7008 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7009 })
7010
Steven Valdez143e8b32016-07-11 13:19:03 -04007011 // Test synchronization between encryption changes and the handshake in
7012 // TLS 1.3, where ChangeCipherSpec is implicit.
7013 testCases = append(testCases, testCase{
7014 name: "PartialEncryptedExtensionsWithServerHello",
7015 config: Config{
7016 MaxVersion: VersionTLS13,
7017 Bugs: ProtocolBugs{
7018 PartialEncryptedExtensionsWithServerHello: true,
7019 },
7020 },
7021 shouldFail: true,
7022 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7023 })
7024 testCases = append(testCases, testCase{
7025 testType: serverTest,
7026 name: "PartialClientFinishedWithClientHello",
7027 config: Config{
7028 MaxVersion: VersionTLS13,
7029 Bugs: ProtocolBugs{
7030 PartialClientFinishedWithClientHello: true,
7031 },
7032 },
7033 shouldFail: true,
7034 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7035 })
7036
David Benjamin82261be2016-07-07 14:32:50 -07007037 // Test that early ChangeCipherSpecs are handled correctly.
7038 testCases = append(testCases, testCase{
7039 testType: serverTest,
7040 name: "EarlyChangeCipherSpec-server-1",
7041 config: Config{
7042 MaxVersion: VersionTLS12,
7043 Bugs: ProtocolBugs{
7044 EarlyChangeCipherSpec: 1,
7045 },
7046 },
7047 shouldFail: true,
7048 expectedError: ":UNEXPECTED_RECORD:",
7049 })
7050 testCases = append(testCases, testCase{
7051 testType: serverTest,
7052 name: "EarlyChangeCipherSpec-server-2",
7053 config: Config{
7054 MaxVersion: VersionTLS12,
7055 Bugs: ProtocolBugs{
7056 EarlyChangeCipherSpec: 2,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedError: ":UNEXPECTED_RECORD:",
7061 })
7062 testCases = append(testCases, testCase{
7063 protocol: dtls,
7064 name: "StrayChangeCipherSpec",
7065 config: Config{
7066 // TODO(davidben): Once DTLS 1.3 exists, test
7067 // that stray ChangeCipherSpec messages are
7068 // rejected.
7069 MaxVersion: VersionTLS12,
7070 Bugs: ProtocolBugs{
7071 StrayChangeCipherSpec: true,
7072 },
7073 },
7074 })
7075
7076 // Test that the contents of ChangeCipherSpec are checked.
7077 testCases = append(testCases, testCase{
7078 name: "BadChangeCipherSpec-1",
7079 config: Config{
7080 MaxVersion: VersionTLS12,
7081 Bugs: ProtocolBugs{
7082 BadChangeCipherSpec: []byte{2},
7083 },
7084 },
7085 shouldFail: true,
7086 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7087 })
7088 testCases = append(testCases, testCase{
7089 name: "BadChangeCipherSpec-2",
7090 config: Config{
7091 MaxVersion: VersionTLS12,
7092 Bugs: ProtocolBugs{
7093 BadChangeCipherSpec: []byte{1, 1},
7094 },
7095 },
7096 shouldFail: true,
7097 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7098 })
7099 testCases = append(testCases, testCase{
7100 protocol: dtls,
7101 name: "BadChangeCipherSpec-DTLS-1",
7102 config: Config{
7103 MaxVersion: VersionTLS12,
7104 Bugs: ProtocolBugs{
7105 BadChangeCipherSpec: []byte{2},
7106 },
7107 },
7108 shouldFail: true,
7109 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7110 })
7111 testCases = append(testCases, testCase{
7112 protocol: dtls,
7113 name: "BadChangeCipherSpec-DTLS-2",
7114 config: Config{
7115 MaxVersion: VersionTLS12,
7116 Bugs: ProtocolBugs{
7117 BadChangeCipherSpec: []byte{1, 1},
7118 },
7119 },
7120 shouldFail: true,
7121 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7122 })
7123}
7124
David Benjamin0b8d5da2016-07-15 00:39:56 -04007125func addWrongMessageTypeTests() {
7126 for _, protocol := range []protocol{tls, dtls} {
7127 var suffix string
7128 if protocol == dtls {
7129 suffix = "-DTLS"
7130 }
7131
7132 testCases = append(testCases, testCase{
7133 protocol: protocol,
7134 testType: serverTest,
7135 name: "WrongMessageType-ClientHello" + suffix,
7136 config: Config{
7137 MaxVersion: VersionTLS12,
7138 Bugs: ProtocolBugs{
7139 SendWrongMessageType: typeClientHello,
7140 },
7141 },
7142 shouldFail: true,
7143 expectedError: ":UNEXPECTED_MESSAGE:",
7144 expectedLocalError: "remote error: unexpected message",
7145 })
7146
7147 if protocol == dtls {
7148 testCases = append(testCases, testCase{
7149 protocol: protocol,
7150 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7151 config: Config{
7152 MaxVersion: VersionTLS12,
7153 Bugs: ProtocolBugs{
7154 SendWrongMessageType: typeHelloVerifyRequest,
7155 },
7156 },
7157 shouldFail: true,
7158 expectedError: ":UNEXPECTED_MESSAGE:",
7159 expectedLocalError: "remote error: unexpected message",
7160 })
7161 }
7162
7163 testCases = append(testCases, testCase{
7164 protocol: protocol,
7165 name: "WrongMessageType-ServerHello" + suffix,
7166 config: Config{
7167 MaxVersion: VersionTLS12,
7168 Bugs: ProtocolBugs{
7169 SendWrongMessageType: typeServerHello,
7170 },
7171 },
7172 shouldFail: true,
7173 expectedError: ":UNEXPECTED_MESSAGE:",
7174 expectedLocalError: "remote error: unexpected message",
7175 })
7176
7177 testCases = append(testCases, testCase{
7178 protocol: protocol,
7179 name: "WrongMessageType-ServerCertificate" + suffix,
7180 config: Config{
7181 MaxVersion: VersionTLS12,
7182 Bugs: ProtocolBugs{
7183 SendWrongMessageType: typeCertificate,
7184 },
7185 },
7186 shouldFail: true,
7187 expectedError: ":UNEXPECTED_MESSAGE:",
7188 expectedLocalError: "remote error: unexpected message",
7189 })
7190
7191 testCases = append(testCases, testCase{
7192 protocol: protocol,
7193 name: "WrongMessageType-CertificateStatus" + suffix,
7194 config: Config{
7195 MaxVersion: VersionTLS12,
7196 Bugs: ProtocolBugs{
7197 SendWrongMessageType: typeCertificateStatus,
7198 },
7199 },
7200 flags: []string{"-enable-ocsp-stapling"},
7201 shouldFail: true,
7202 expectedError: ":UNEXPECTED_MESSAGE:",
7203 expectedLocalError: "remote error: unexpected message",
7204 })
7205
7206 testCases = append(testCases, testCase{
7207 protocol: protocol,
7208 name: "WrongMessageType-ServerKeyExchange" + suffix,
7209 config: Config{
7210 MaxVersion: VersionTLS12,
7211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7212 Bugs: ProtocolBugs{
7213 SendWrongMessageType: typeServerKeyExchange,
7214 },
7215 },
7216 shouldFail: true,
7217 expectedError: ":UNEXPECTED_MESSAGE:",
7218 expectedLocalError: "remote error: unexpected message",
7219 })
7220
7221 testCases = append(testCases, testCase{
7222 protocol: protocol,
7223 name: "WrongMessageType-CertificateRequest" + suffix,
7224 config: Config{
7225 MaxVersion: VersionTLS12,
7226 ClientAuth: RequireAnyClientCert,
7227 Bugs: ProtocolBugs{
7228 SendWrongMessageType: typeCertificateRequest,
7229 },
7230 },
7231 shouldFail: true,
7232 expectedError: ":UNEXPECTED_MESSAGE:",
7233 expectedLocalError: "remote error: unexpected message",
7234 })
7235
7236 testCases = append(testCases, testCase{
7237 protocol: protocol,
7238 name: "WrongMessageType-ServerHelloDone" + suffix,
7239 config: Config{
7240 MaxVersion: VersionTLS12,
7241 Bugs: ProtocolBugs{
7242 SendWrongMessageType: typeServerHelloDone,
7243 },
7244 },
7245 shouldFail: true,
7246 expectedError: ":UNEXPECTED_MESSAGE:",
7247 expectedLocalError: "remote error: unexpected message",
7248 })
7249
7250 testCases = append(testCases, testCase{
7251 testType: serverTest,
7252 protocol: protocol,
7253 name: "WrongMessageType-ClientCertificate" + suffix,
7254 config: Config{
7255 Certificates: []Certificate{rsaCertificate},
7256 MaxVersion: VersionTLS12,
7257 Bugs: ProtocolBugs{
7258 SendWrongMessageType: typeCertificate,
7259 },
7260 },
7261 flags: []string{"-require-any-client-certificate"},
7262 shouldFail: true,
7263 expectedError: ":UNEXPECTED_MESSAGE:",
7264 expectedLocalError: "remote error: unexpected message",
7265 })
7266
7267 testCases = append(testCases, testCase{
7268 testType: serverTest,
7269 protocol: protocol,
7270 name: "WrongMessageType-CertificateVerify" + suffix,
7271 config: Config{
7272 Certificates: []Certificate{rsaCertificate},
7273 MaxVersion: VersionTLS12,
7274 Bugs: ProtocolBugs{
7275 SendWrongMessageType: typeCertificateVerify,
7276 },
7277 },
7278 flags: []string{"-require-any-client-certificate"},
7279 shouldFail: true,
7280 expectedError: ":UNEXPECTED_MESSAGE:",
7281 expectedLocalError: "remote error: unexpected message",
7282 })
7283
7284 testCases = append(testCases, testCase{
7285 testType: serverTest,
7286 protocol: protocol,
7287 name: "WrongMessageType-ClientKeyExchange" + suffix,
7288 config: Config{
7289 MaxVersion: VersionTLS12,
7290 Bugs: ProtocolBugs{
7291 SendWrongMessageType: typeClientKeyExchange,
7292 },
7293 },
7294 shouldFail: true,
7295 expectedError: ":UNEXPECTED_MESSAGE:",
7296 expectedLocalError: "remote error: unexpected message",
7297 })
7298
7299 if protocol != dtls {
7300 testCases = append(testCases, testCase{
7301 testType: serverTest,
7302 protocol: protocol,
7303 name: "WrongMessageType-NextProtocol" + suffix,
7304 config: Config{
7305 MaxVersion: VersionTLS12,
7306 NextProtos: []string{"bar"},
7307 Bugs: ProtocolBugs{
7308 SendWrongMessageType: typeNextProtocol,
7309 },
7310 },
7311 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7312 shouldFail: true,
7313 expectedError: ":UNEXPECTED_MESSAGE:",
7314 expectedLocalError: "remote error: unexpected message",
7315 })
7316
7317 testCases = append(testCases, testCase{
7318 testType: serverTest,
7319 protocol: protocol,
7320 name: "WrongMessageType-ChannelID" + suffix,
7321 config: Config{
7322 MaxVersion: VersionTLS12,
7323 ChannelID: channelIDKey,
7324 Bugs: ProtocolBugs{
7325 SendWrongMessageType: typeChannelID,
7326 },
7327 },
7328 flags: []string{
7329 "-expect-channel-id",
7330 base64.StdEncoding.EncodeToString(channelIDBytes),
7331 },
7332 shouldFail: true,
7333 expectedError: ":UNEXPECTED_MESSAGE:",
7334 expectedLocalError: "remote error: unexpected message",
7335 })
7336 }
7337
7338 testCases = append(testCases, testCase{
7339 testType: serverTest,
7340 protocol: protocol,
7341 name: "WrongMessageType-ClientFinished" + suffix,
7342 config: Config{
7343 MaxVersion: VersionTLS12,
7344 Bugs: ProtocolBugs{
7345 SendWrongMessageType: typeFinished,
7346 },
7347 },
7348 shouldFail: true,
7349 expectedError: ":UNEXPECTED_MESSAGE:",
7350 expectedLocalError: "remote error: unexpected message",
7351 })
7352
7353 testCases = append(testCases, testCase{
7354 protocol: protocol,
7355 name: "WrongMessageType-NewSessionTicket" + suffix,
7356 config: Config{
7357 MaxVersion: VersionTLS12,
7358 Bugs: ProtocolBugs{
7359 SendWrongMessageType: typeNewSessionTicket,
7360 },
7361 },
7362 shouldFail: true,
7363 expectedError: ":UNEXPECTED_MESSAGE:",
7364 expectedLocalError: "remote error: unexpected message",
7365 })
7366
7367 testCases = append(testCases, testCase{
7368 protocol: protocol,
7369 name: "WrongMessageType-ServerFinished" + suffix,
7370 config: Config{
7371 MaxVersion: VersionTLS12,
7372 Bugs: ProtocolBugs{
7373 SendWrongMessageType: typeFinished,
7374 },
7375 },
7376 shouldFail: true,
7377 expectedError: ":UNEXPECTED_MESSAGE:",
7378 expectedLocalError: "remote error: unexpected message",
7379 })
7380
7381 }
7382}
7383
Steven Valdez143e8b32016-07-11 13:19:03 -04007384func addTLS13WrongMessageTypeTests() {
7385 testCases = append(testCases, testCase{
7386 testType: serverTest,
7387 name: "WrongMessageType-TLS13-ClientHello",
7388 config: Config{
7389 MaxVersion: VersionTLS13,
7390 Bugs: ProtocolBugs{
7391 SendWrongMessageType: typeClientHello,
7392 },
7393 },
7394 shouldFail: true,
7395 expectedError: ":UNEXPECTED_MESSAGE:",
7396 expectedLocalError: "remote error: unexpected message",
7397 })
7398
7399 testCases = append(testCases, testCase{
7400 name: "WrongMessageType-TLS13-ServerHello",
7401 config: Config{
7402 MaxVersion: VersionTLS13,
7403 Bugs: ProtocolBugs{
7404 SendWrongMessageType: typeServerHello,
7405 },
7406 },
7407 shouldFail: true,
7408 expectedError: ":UNEXPECTED_MESSAGE:",
7409 // The alert comes in with the wrong encryption.
7410 expectedLocalError: "local error: bad record MAC",
7411 })
7412
7413 testCases = append(testCases, testCase{
7414 name: "WrongMessageType-TLS13-EncryptedExtensions",
7415 config: Config{
7416 MaxVersion: VersionTLS13,
7417 Bugs: ProtocolBugs{
7418 SendWrongMessageType: typeEncryptedExtensions,
7419 },
7420 },
7421 shouldFail: true,
7422 expectedError: ":UNEXPECTED_MESSAGE:",
7423 expectedLocalError: "remote error: unexpected message",
7424 })
7425
7426 testCases = append(testCases, testCase{
7427 name: "WrongMessageType-TLS13-CertificateRequest",
7428 config: Config{
7429 MaxVersion: VersionTLS13,
7430 ClientAuth: RequireAnyClientCert,
7431 Bugs: ProtocolBugs{
7432 SendWrongMessageType: typeCertificateRequest,
7433 },
7434 },
7435 shouldFail: true,
7436 expectedError: ":UNEXPECTED_MESSAGE:",
7437 expectedLocalError: "remote error: unexpected message",
7438 })
7439
7440 testCases = append(testCases, testCase{
7441 name: "WrongMessageType-TLS13-ServerCertificate",
7442 config: Config{
7443 MaxVersion: VersionTLS13,
7444 Bugs: ProtocolBugs{
7445 SendWrongMessageType: typeCertificate,
7446 },
7447 },
7448 shouldFail: true,
7449 expectedError: ":UNEXPECTED_MESSAGE:",
7450 expectedLocalError: "remote error: unexpected message",
7451 })
7452
7453 testCases = append(testCases, testCase{
7454 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7455 config: Config{
7456 MaxVersion: VersionTLS13,
7457 Bugs: ProtocolBugs{
7458 SendWrongMessageType: typeCertificateVerify,
7459 },
7460 },
7461 shouldFail: true,
7462 expectedError: ":UNEXPECTED_MESSAGE:",
7463 expectedLocalError: "remote error: unexpected message",
7464 })
7465
7466 testCases = append(testCases, testCase{
7467 name: "WrongMessageType-TLS13-ServerFinished",
7468 config: Config{
7469 MaxVersion: VersionTLS13,
7470 Bugs: ProtocolBugs{
7471 SendWrongMessageType: typeFinished,
7472 },
7473 },
7474 shouldFail: true,
7475 expectedError: ":UNEXPECTED_MESSAGE:",
7476 expectedLocalError: "remote error: unexpected message",
7477 })
7478
7479 testCases = append(testCases, testCase{
7480 testType: serverTest,
7481 name: "WrongMessageType-TLS13-ClientCertificate",
7482 config: Config{
7483 Certificates: []Certificate{rsaCertificate},
7484 MaxVersion: VersionTLS13,
7485 Bugs: ProtocolBugs{
7486 SendWrongMessageType: typeCertificate,
7487 },
7488 },
7489 flags: []string{"-require-any-client-certificate"},
7490 shouldFail: true,
7491 expectedError: ":UNEXPECTED_MESSAGE:",
7492 expectedLocalError: "remote error: unexpected message",
7493 })
7494
7495 testCases = append(testCases, testCase{
7496 testType: serverTest,
7497 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7498 config: Config{
7499 Certificates: []Certificate{rsaCertificate},
7500 MaxVersion: VersionTLS13,
7501 Bugs: ProtocolBugs{
7502 SendWrongMessageType: typeCertificateVerify,
7503 },
7504 },
7505 flags: []string{"-require-any-client-certificate"},
7506 shouldFail: true,
7507 expectedError: ":UNEXPECTED_MESSAGE:",
7508 expectedLocalError: "remote error: unexpected message",
7509 })
7510
7511 testCases = append(testCases, testCase{
7512 testType: serverTest,
7513 name: "WrongMessageType-TLS13-ClientFinished",
7514 config: Config{
7515 MaxVersion: VersionTLS13,
7516 Bugs: ProtocolBugs{
7517 SendWrongMessageType: typeFinished,
7518 },
7519 },
7520 shouldFail: true,
7521 expectedError: ":UNEXPECTED_MESSAGE:",
7522 expectedLocalError: "remote error: unexpected message",
7523 })
7524}
7525
7526func addTLS13HandshakeTests() {
7527 testCases = append(testCases, testCase{
7528 testType: clientTest,
7529 name: "MissingKeyShare-Client",
7530 config: Config{
7531 MaxVersion: VersionTLS13,
7532 Bugs: ProtocolBugs{
7533 MissingKeyShare: true,
7534 },
7535 },
7536 shouldFail: true,
7537 expectedError: ":MISSING_KEY_SHARE:",
7538 })
7539
7540 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007541 testType: serverTest,
7542 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007543 config: Config{
7544 MaxVersion: VersionTLS13,
7545 Bugs: ProtocolBugs{
7546 MissingKeyShare: true,
7547 },
7548 },
7549 shouldFail: true,
7550 expectedError: ":MISSING_KEY_SHARE:",
7551 })
7552
7553 testCases = append(testCases, testCase{
7554 testType: clientTest,
7555 name: "ClientHelloMissingKeyShare",
7556 config: Config{
7557 MaxVersion: VersionTLS13,
7558 Bugs: ProtocolBugs{
7559 MissingKeyShare: true,
7560 },
7561 },
7562 shouldFail: true,
7563 expectedError: ":MISSING_KEY_SHARE:",
7564 })
7565
7566 testCases = append(testCases, testCase{
7567 testType: clientTest,
7568 name: "MissingKeyShare",
7569 config: Config{
7570 MaxVersion: VersionTLS13,
7571 Bugs: ProtocolBugs{
7572 MissingKeyShare: true,
7573 },
7574 },
7575 shouldFail: true,
7576 expectedError: ":MISSING_KEY_SHARE:",
7577 })
7578
7579 testCases = append(testCases, testCase{
7580 testType: serverTest,
7581 name: "DuplicateKeyShares",
7582 config: Config{
7583 MaxVersion: VersionTLS13,
7584 Bugs: ProtocolBugs{
7585 DuplicateKeyShares: true,
7586 },
7587 },
7588 })
7589
7590 testCases = append(testCases, testCase{
7591 testType: clientTest,
7592 name: "EmptyEncryptedExtensions",
7593 config: Config{
7594 MaxVersion: VersionTLS13,
7595 Bugs: ProtocolBugs{
7596 EmptyEncryptedExtensions: true,
7597 },
7598 },
7599 shouldFail: true,
7600 expectedLocalError: "remote error: error decoding message",
7601 })
7602
7603 testCases = append(testCases, testCase{
7604 testType: clientTest,
7605 name: "EncryptedExtensionsWithKeyShare",
7606 config: Config{
7607 MaxVersion: VersionTLS13,
7608 Bugs: ProtocolBugs{
7609 EncryptedExtensionsWithKeyShare: true,
7610 },
7611 },
7612 shouldFail: true,
7613 expectedLocalError: "remote error: unsupported extension",
7614 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007615
7616 testCases = append(testCases, testCase{
7617 testType: serverTest,
7618 name: "SendHelloRetryRequest",
7619 config: Config{
7620 MaxVersion: VersionTLS13,
7621 // Require a HelloRetryRequest for every curve.
7622 DefaultCurves: []CurveID{},
7623 },
7624 expectedCurveID: CurveX25519,
7625 })
7626
7627 testCases = append(testCases, testCase{
7628 testType: serverTest,
7629 name: "SendHelloRetryRequest-2",
7630 config: Config{
7631 MaxVersion: VersionTLS13,
7632 DefaultCurves: []CurveID{CurveP384},
7633 },
7634 // Although the ClientHello did not predict our preferred curve,
7635 // we always select it whether it is predicted or not.
7636 expectedCurveID: CurveX25519,
7637 })
7638
7639 testCases = append(testCases, testCase{
7640 name: "UnknownCurve-HelloRetryRequest",
7641 config: Config{
7642 MaxVersion: VersionTLS13,
7643 // P-384 requires HelloRetryRequest in BoringSSL.
7644 CurvePreferences: []CurveID{CurveP384},
7645 Bugs: ProtocolBugs{
7646 SendHelloRetryRequestCurve: bogusCurve,
7647 },
7648 },
7649 shouldFail: true,
7650 expectedError: ":WRONG_CURVE:",
7651 })
7652
7653 testCases = append(testCases, testCase{
7654 name: "DisabledCurve-HelloRetryRequest",
7655 config: Config{
7656 MaxVersion: VersionTLS13,
7657 CurvePreferences: []CurveID{CurveP256},
7658 Bugs: ProtocolBugs{
7659 IgnorePeerCurvePreferences: true,
7660 },
7661 },
7662 flags: []string{"-p384-only"},
7663 shouldFail: true,
7664 expectedError: ":WRONG_CURVE:",
7665 })
7666
7667 testCases = append(testCases, testCase{
7668 name: "UnnecessaryHelloRetryRequest",
7669 config: Config{
7670 MaxVersion: VersionTLS13,
7671 Bugs: ProtocolBugs{
7672 UnnecessaryHelloRetryRequest: true,
7673 },
7674 },
7675 shouldFail: true,
7676 expectedError: ":WRONG_CURVE:",
7677 })
7678
7679 testCases = append(testCases, testCase{
7680 name: "SecondHelloRetryRequest",
7681 config: Config{
7682 MaxVersion: VersionTLS13,
7683 // P-384 requires HelloRetryRequest in BoringSSL.
7684 CurvePreferences: []CurveID{CurveP384},
7685 Bugs: ProtocolBugs{
7686 SecondHelloRetryRequest: true,
7687 },
7688 },
7689 shouldFail: true,
7690 expectedError: ":UNEXPECTED_MESSAGE:",
7691 })
7692
7693 testCases = append(testCases, testCase{
7694 testType: serverTest,
7695 name: "SecondClientHelloMissingKeyShare",
7696 config: Config{
7697 MaxVersion: VersionTLS13,
7698 DefaultCurves: []CurveID{},
7699 Bugs: ProtocolBugs{
7700 SecondClientHelloMissingKeyShare: true,
7701 },
7702 },
7703 shouldFail: true,
7704 expectedError: ":MISSING_KEY_SHARE:",
7705 })
7706
7707 testCases = append(testCases, testCase{
7708 testType: serverTest,
7709 name: "SecondClientHelloWrongCurve",
7710 config: Config{
7711 MaxVersion: VersionTLS13,
7712 DefaultCurves: []CurveID{},
7713 Bugs: ProtocolBugs{
7714 MisinterpretHelloRetryRequestCurve: CurveP521,
7715 },
7716 },
7717 shouldFail: true,
7718 expectedError: ":WRONG_CURVE:",
7719 })
7720
7721 testCases = append(testCases, testCase{
7722 name: "HelloRetryRequestVersionMismatch",
7723 config: Config{
7724 MaxVersion: VersionTLS13,
7725 // P-384 requires HelloRetryRequest in BoringSSL.
7726 CurvePreferences: []CurveID{CurveP384},
7727 Bugs: ProtocolBugs{
7728 SendServerHelloVersion: 0x0305,
7729 },
7730 },
7731 shouldFail: true,
7732 expectedError: ":WRONG_VERSION_NUMBER:",
7733 })
7734
7735 testCases = append(testCases, testCase{
7736 name: "HelloRetryRequestCurveMismatch",
7737 config: Config{
7738 MaxVersion: VersionTLS13,
7739 // P-384 requires HelloRetryRequest in BoringSSL.
7740 CurvePreferences: []CurveID{CurveP384},
7741 Bugs: ProtocolBugs{
7742 // Send P-384 (correct) in the HelloRetryRequest.
7743 SendHelloRetryRequestCurve: CurveP384,
7744 // But send P-256 in the ServerHello.
7745 SendCurve: CurveP256,
7746 },
7747 },
7748 shouldFail: true,
7749 expectedError: ":WRONG_CURVE:",
7750 })
7751
7752 // Test the server selecting a curve that requires a HelloRetryRequest
7753 // without sending it.
7754 testCases = append(testCases, testCase{
7755 name: "SkipHelloRetryRequest",
7756 config: Config{
7757 MaxVersion: VersionTLS13,
7758 // P-384 requires HelloRetryRequest in BoringSSL.
7759 CurvePreferences: []CurveID{CurveP384},
7760 Bugs: ProtocolBugs{
7761 SkipHelloRetryRequest: true,
7762 },
7763 },
7764 shouldFail: true,
7765 expectedError: ":WRONG_CURVE:",
7766 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007767}
7768
Adam Langley7c803a62015-06-15 15:35:05 -07007769func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007770 defer wg.Done()
7771
7772 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007773 var err error
7774
7775 if *mallocTest < 0 {
7776 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007777 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007778 } else {
7779 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7780 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007781 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007782 if err != nil {
7783 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7784 }
7785 break
7786 }
7787 }
7788 }
Adam Langley95c29f32014-06-20 12:00:00 -07007789 statusChan <- statusMsg{test: test, err: err}
7790 }
7791}
7792
7793type statusMsg struct {
7794 test *testCase
7795 started bool
7796 err error
7797}
7798
David Benjamin5f237bc2015-02-11 17:14:15 -05007799func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007800 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007801
David Benjamin5f237bc2015-02-11 17:14:15 -05007802 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007803 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007804 if !*pipe {
7805 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007806 var erase string
7807 for i := 0; i < lineLen; i++ {
7808 erase += "\b \b"
7809 }
7810 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007811 }
7812
Adam Langley95c29f32014-06-20 12:00:00 -07007813 if msg.started {
7814 started++
7815 } else {
7816 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007817
7818 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02007819 if msg.err == errUnimplemented {
7820 if *pipe {
7821 // Print each test instead of a status line.
7822 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
7823 }
7824 unimplemented++
7825 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
7826 } else {
7827 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7828 failed++
7829 testOutput.addResult(msg.test.name, "FAIL")
7830 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007831 } else {
7832 if *pipe {
7833 // Print each test instead of a status line.
7834 fmt.Printf("PASSED (%s)\n", msg.test.name)
7835 }
7836 testOutput.addResult(msg.test.name, "PASS")
7837 }
Adam Langley95c29f32014-06-20 12:00:00 -07007838 }
7839
David Benjamin5f237bc2015-02-11 17:14:15 -05007840 if !*pipe {
7841 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02007842 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05007843 lineLen = len(line)
7844 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007845 }
Adam Langley95c29f32014-06-20 12:00:00 -07007846 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007847
7848 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007849}
7850
7851func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007852 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007853 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007854 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007855
Adam Langley7c803a62015-06-15 15:35:05 -07007856 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007857 addCipherSuiteTests()
7858 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007859 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007860 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007861 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007862 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007863 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007864 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007865 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007866 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007867 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007868 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007869 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007870 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007871 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007872 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007873 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007874 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007875 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007876 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007877 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007878 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007879 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007880 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007881 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007882 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007883 addTLS13WrongMessageTypeTests()
7884 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007885
7886 var wg sync.WaitGroup
7887
Adam Langley7c803a62015-06-15 15:35:05 -07007888 statusChan := make(chan statusMsg, *numWorkers)
7889 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007890 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007891
David Benjamin025b3d32014-07-01 19:53:04 -04007892 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007893
Adam Langley7c803a62015-06-15 15:35:05 -07007894 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007895 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007896 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007897 }
7898
David Benjamin270f0a72016-03-17 14:41:36 -04007899 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007900 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04007901 matched := true
7902 if len(*testToRun) != 0 {
7903 var err error
7904 matched, err = filepath.Match(*testToRun, testCases[i].name)
7905 if err != nil {
7906 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
7907 os.Exit(1)
7908 }
7909 }
7910
7911 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04007912 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007913 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007914 }
7915 }
David Benjamin17e12922016-07-28 18:04:43 -04007916
David Benjamin270f0a72016-03-17 14:41:36 -04007917 if !foundTest {
David Benjamin17e12922016-07-28 18:04:43 -04007918 fmt.Fprintf(os.Stderr, "No tests matched %q\n", *testToRun)
David Benjamin270f0a72016-03-17 14:41:36 -04007919 os.Exit(1)
7920 }
Adam Langley95c29f32014-06-20 12:00:00 -07007921
7922 close(testChan)
7923 wg.Wait()
7924 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007925 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007926
7927 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007928
7929 if *jsonOutput != "" {
7930 if err := testOutput.writeTo(*jsonOutput); err != nil {
7931 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7932 }
7933 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007934
EKR842ae6c2016-07-27 09:22:05 +02007935 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
7936 os.Exit(1)
7937 }
7938
7939 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04007940 os.Exit(1)
7941 }
Adam Langley95c29f32014-06-20 12:00:00 -07007942}