blob: c3bdc9a66453459f7786f7277598552e56b1d300 [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 },
Adam Langley7c803a62015-06-15 15:35:05 -07002124 }
Adam Langley7c803a62015-06-15 15:35:05 -07002125 testCases = append(testCases, basicTests...)
2126}
2127
Adam Langley95c29f32014-06-20 12:00:00 -07002128func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002129 const bogusCipher = 0xfe00
2130
Adam Langley95c29f32014-06-20 12:00:00 -07002131 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002132 const psk = "12345"
2133 const pskIdentity = "luggage combo"
2134
Adam Langley95c29f32014-06-20 12:00:00 -07002135 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002136 var certFile string
2137 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002138 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002139 cert = ecdsaP256Certificate
2140 certFile = ecdsaP256CertificateFile
2141 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002142 } else {
David Benjamin33863262016-07-08 17:20:12 -07002143 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002144 certFile = rsaCertificateFile
2145 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002146 }
2147
David Benjamin48cae082014-10-27 01:06:24 -04002148 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002149 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002150 flags = append(flags,
2151 "-psk", psk,
2152 "-psk-identity", pskIdentity)
2153 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002154 if hasComponent(suite.name, "NULL") {
2155 // NULL ciphers must be explicitly enabled.
2156 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2157 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002158 if hasComponent(suite.name, "CECPQ1") {
2159 // CECPQ1 ciphers must be explicitly enabled.
2160 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2161 }
David Benjamin48cae082014-10-27 01:06:24 -04002162
Adam Langley95c29f32014-06-20 12:00:00 -07002163 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002164 for _, protocol := range []protocol{tls, dtls} {
2165 var prefix string
2166 if protocol == dtls {
2167 if !ver.hasDTLS {
2168 continue
2169 }
2170 prefix = "D"
2171 }
Adam Langley95c29f32014-06-20 12:00:00 -07002172
David Benjamin0407e762016-06-17 16:41:18 -04002173 var shouldServerFail, shouldClientFail bool
2174 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2175 // BoringSSL clients accept ECDHE on SSLv3, but
2176 // a BoringSSL server will never select it
2177 // because the extension is missing.
2178 shouldServerFail = true
2179 }
2180 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2181 shouldClientFail = true
2182 shouldServerFail = true
2183 }
David Benjamin54c217c2016-07-13 12:35:25 -04002184 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002185 shouldClientFail = true
2186 shouldServerFail = true
2187 }
David Benjamin0407e762016-06-17 16:41:18 -04002188 if !isDTLSCipher(suite.name) && protocol == dtls {
2189 shouldClientFail = true
2190 shouldServerFail = true
2191 }
David Benjamin4298d772015-12-19 00:18:25 -05002192
David Benjamin0407e762016-06-17 16:41:18 -04002193 var expectedServerError, expectedClientError string
2194 if shouldServerFail {
2195 expectedServerError = ":NO_SHARED_CIPHER:"
2196 }
2197 if shouldClientFail {
2198 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2199 }
David Benjamin025b3d32014-07-01 19:53:04 -04002200
David Benjamin9deb1172016-07-13 17:13:49 -04002201 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2202 resumeSession := ver.version < VersionTLS13
2203
David Benjamin6fd297b2014-08-11 18:43:38 -04002204 testCases = append(testCases, testCase{
2205 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002206 protocol: protocol,
2207
2208 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002209 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002210 MinVersion: ver.version,
2211 MaxVersion: ver.version,
2212 CipherSuites: []uint16{suite.id},
2213 Certificates: []Certificate{cert},
2214 PreSharedKey: []byte(psk),
2215 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002216 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002217 EnableAllCiphers: shouldServerFail,
2218 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002219 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002220 },
2221 certFile: certFile,
2222 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002223 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002224 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002225 shouldFail: shouldServerFail,
2226 expectedError: expectedServerError,
2227 })
2228
2229 testCases = append(testCases, testCase{
2230 testType: clientTest,
2231 protocol: protocol,
2232 name: prefix + ver.name + "-" + suite.name + "-client",
2233 config: Config{
2234 MinVersion: ver.version,
2235 MaxVersion: ver.version,
2236 CipherSuites: []uint16{suite.id},
2237 Certificates: []Certificate{cert},
2238 PreSharedKey: []byte(psk),
2239 PreSharedKeyIdentity: pskIdentity,
2240 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002241 EnableAllCiphers: shouldClientFail,
2242 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002243 },
2244 },
2245 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002246 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002247 shouldFail: shouldClientFail,
2248 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002249 })
David Benjamin2c99d282015-09-01 10:23:00 -04002250
Nick Harper1fd39d82016-06-14 18:14:35 -07002251 if !shouldClientFail {
2252 // Ensure the maximum record size is accepted.
2253 testCases = append(testCases, testCase{
2254 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2255 config: Config{
2256 MinVersion: ver.version,
2257 MaxVersion: ver.version,
2258 CipherSuites: []uint16{suite.id},
2259 Certificates: []Certificate{cert},
2260 PreSharedKey: []byte(psk),
2261 PreSharedKeyIdentity: pskIdentity,
2262 },
2263 flags: flags,
2264 messageLen: maxPlaintext,
2265 })
2266 }
2267 }
David Benjamin2c99d282015-09-01 10:23:00 -04002268 }
Adam Langley95c29f32014-06-20 12:00:00 -07002269 }
Adam Langleya7997f12015-05-14 17:38:50 -07002270
2271 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002272 name: "NoSharedCipher",
2273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002274 MaxVersion: VersionTLS12,
2275 CipherSuites: []uint16{},
2276 },
2277 shouldFail: true,
2278 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2279 })
2280
2281 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002282 name: "NoSharedCipher-TLS13",
2283 config: Config{
2284 MaxVersion: VersionTLS13,
2285 CipherSuites: []uint16{},
2286 },
2287 shouldFail: true,
2288 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2289 })
2290
2291 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002292 name: "UnsupportedCipherSuite",
2293 config: Config{
2294 MaxVersion: VersionTLS12,
2295 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2296 Bugs: ProtocolBugs{
2297 IgnorePeerCipherPreferences: true,
2298 },
2299 },
2300 flags: []string{"-cipher", "DEFAULT:!RC4"},
2301 shouldFail: true,
2302 expectedError: ":WRONG_CIPHER_RETURNED:",
2303 })
2304
2305 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002306 name: "ServerHelloBogusCipher",
2307 config: Config{
2308 MaxVersion: VersionTLS12,
2309 Bugs: ProtocolBugs{
2310 SendCipherSuite: bogusCipher,
2311 },
2312 },
2313 shouldFail: true,
2314 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2315 })
2316 testCases = append(testCases, testCase{
2317 name: "ServerHelloBogusCipher-TLS13",
2318 config: Config{
2319 MaxVersion: VersionTLS13,
2320 Bugs: ProtocolBugs{
2321 SendCipherSuite: bogusCipher,
2322 },
2323 },
2324 shouldFail: true,
2325 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2326 })
2327
2328 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002329 name: "WeakDH",
2330 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002331 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002332 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2333 Bugs: ProtocolBugs{
2334 // This is a 1023-bit prime number, generated
2335 // with:
2336 // openssl gendh 1023 | openssl asn1parse -i
2337 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2338 },
2339 },
2340 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002341 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002342 })
Adam Langleycef75832015-09-03 14:51:12 -07002343
David Benjamincd24a392015-11-11 13:23:05 -08002344 testCases = append(testCases, testCase{
2345 name: "SillyDH",
2346 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002347 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002348 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2349 Bugs: ProtocolBugs{
2350 // This is a 4097-bit prime number, generated
2351 // with:
2352 // openssl gendh 4097 | openssl asn1parse -i
2353 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2354 },
2355 },
2356 shouldFail: true,
2357 expectedError: ":DH_P_TOO_LONG:",
2358 })
2359
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002360 // This test ensures that Diffie-Hellman public values are padded with
2361 // zeros so that they're the same length as the prime. This is to avoid
2362 // hitting a bug in yaSSL.
2363 testCases = append(testCases, testCase{
2364 testType: serverTest,
2365 name: "DHPublicValuePadded",
2366 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002367 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002368 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2369 Bugs: ProtocolBugs{
2370 RequireDHPublicValueLen: (1025 + 7) / 8,
2371 },
2372 },
2373 flags: []string{"-use-sparse-dh-prime"},
2374 })
David Benjamincd24a392015-11-11 13:23:05 -08002375
David Benjamin241ae832016-01-15 03:04:54 -05002376 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002377 testCases = append(testCases, testCase{
2378 testType: serverTest,
2379 name: "UnknownCipher",
2380 config: Config{
2381 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2382 },
2383 })
2384
Adam Langleycef75832015-09-03 14:51:12 -07002385 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2386 // 1.1 specific cipher suite settings. A server is setup with the given
2387 // cipher lists and then a connection is made for each member of
2388 // expectations. The cipher suite that the server selects must match
2389 // the specified one.
2390 var versionSpecificCiphersTest = []struct {
2391 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2392 // expectations is a map from TLS version to cipher suite id.
2393 expectations map[uint16]uint16
2394 }{
2395 {
2396 // Test that the null case (where no version-specific ciphers are set)
2397 // works as expected.
2398 "RC4-SHA:AES128-SHA", // default ciphers
2399 "", // no ciphers specifically for TLS ≥ 1.0
2400 "", // no ciphers specifically for TLS ≥ 1.1
2401 map[uint16]uint16{
2402 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2403 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2404 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2405 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2406 },
2407 },
2408 {
2409 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2410 // cipher.
2411 "RC4-SHA:AES128-SHA", // default
2412 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2413 "", // no ciphers specifically for TLS ≥ 1.1
2414 map[uint16]uint16{
2415 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2416 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2417 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2418 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2419 },
2420 },
2421 {
2422 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2423 // cipher.
2424 "RC4-SHA:AES128-SHA", // default
2425 "", // no ciphers specifically for TLS ≥ 1.0
2426 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2427 map[uint16]uint16{
2428 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2429 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2430 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2431 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2432 },
2433 },
2434 {
2435 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2436 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2437 "RC4-SHA:AES128-SHA", // default
2438 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2439 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2440 map[uint16]uint16{
2441 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2442 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2443 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2444 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2445 },
2446 },
2447 }
2448
2449 for i, test := range versionSpecificCiphersTest {
2450 for version, expectedCipherSuite := range test.expectations {
2451 flags := []string{"-cipher", test.ciphersDefault}
2452 if len(test.ciphersTLS10) > 0 {
2453 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2454 }
2455 if len(test.ciphersTLS11) > 0 {
2456 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2457 }
2458
2459 testCases = append(testCases, testCase{
2460 testType: serverTest,
2461 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2462 config: Config{
2463 MaxVersion: version,
2464 MinVersion: version,
2465 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2466 },
2467 flags: flags,
2468 expectedCipher: expectedCipherSuite,
2469 })
2470 }
2471 }
Adam Langley95c29f32014-06-20 12:00:00 -07002472}
2473
2474func addBadECDSASignatureTests() {
2475 for badR := BadValue(1); badR < NumBadValues; badR++ {
2476 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002477 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002478 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2479 config: Config{
2480 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002481 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002482 Bugs: ProtocolBugs{
2483 BadECDSAR: badR,
2484 BadECDSAS: badS,
2485 },
2486 },
2487 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002488 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002489 })
2490 }
2491 }
2492}
2493
Adam Langley80842bd2014-06-20 12:00:00 -07002494func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002495 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002496 name: "MaxCBCPadding",
2497 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002498 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002499 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2500 Bugs: ProtocolBugs{
2501 MaxPadding: true,
2502 },
2503 },
2504 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2505 })
David Benjamin025b3d32014-07-01 19:53:04 -04002506 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002507 name: "BadCBCPadding",
2508 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002509 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2511 Bugs: ProtocolBugs{
2512 PaddingFirstByteBad: true,
2513 },
2514 },
2515 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002516 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002517 })
2518 // OpenSSL previously had an issue where the first byte of padding in
2519 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002520 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002521 name: "BadCBCPadding255",
2522 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002523 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2525 Bugs: ProtocolBugs{
2526 MaxPadding: true,
2527 PaddingFirstByteBadIf255: true,
2528 },
2529 },
2530 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2531 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002532 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002533 })
2534}
2535
Kenny Root7fdeaf12014-08-05 15:23:37 -07002536func addCBCSplittingTests() {
2537 testCases = append(testCases, testCase{
2538 name: "CBCRecordSplitting",
2539 config: Config{
2540 MaxVersion: VersionTLS10,
2541 MinVersion: VersionTLS10,
2542 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2543 },
David Benjaminac8302a2015-09-01 17:18:15 -04002544 messageLen: -1, // read until EOF
2545 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002546 flags: []string{
2547 "-async",
2548 "-write-different-record-sizes",
2549 "-cbc-record-splitting",
2550 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002551 })
2552 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002553 name: "CBCRecordSplittingPartialWrite",
2554 config: Config{
2555 MaxVersion: VersionTLS10,
2556 MinVersion: VersionTLS10,
2557 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2558 },
2559 messageLen: -1, // read until EOF
2560 flags: []string{
2561 "-async",
2562 "-write-different-record-sizes",
2563 "-cbc-record-splitting",
2564 "-partial-write",
2565 },
2566 })
2567}
2568
David Benjamin636293b2014-07-08 17:59:18 -04002569func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002570 // Add a dummy cert pool to stress certificate authority parsing.
2571 // TODO(davidben): Add tests that those values parse out correctly.
2572 certPool := x509.NewCertPool()
2573 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2574 if err != nil {
2575 panic(err)
2576 }
2577 certPool.AddCert(cert)
2578
David Benjamin636293b2014-07-08 17:59:18 -04002579 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002580 testCases = append(testCases, testCase{
2581 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002582 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002583 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002584 MinVersion: ver.version,
2585 MaxVersion: ver.version,
2586 ClientAuth: RequireAnyClientCert,
2587 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002588 },
2589 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002590 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2591 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002592 },
2593 })
2594 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002595 testType: serverTest,
2596 name: ver.name + "-Server-ClientAuth-RSA",
2597 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002598 MinVersion: ver.version,
2599 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002600 Certificates: []Certificate{rsaCertificate},
2601 },
2602 flags: []string{"-require-any-client-certificate"},
2603 })
David Benjamine098ec22014-08-27 23:13:20 -04002604 if ver.version != VersionSSL30 {
2605 testCases = append(testCases, testCase{
2606 testType: serverTest,
2607 name: ver.name + "-Server-ClientAuth-ECDSA",
2608 config: Config{
2609 MinVersion: ver.version,
2610 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002611 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002612 },
2613 flags: []string{"-require-any-client-certificate"},
2614 })
2615 testCases = append(testCases, testCase{
2616 testType: clientTest,
2617 name: ver.name + "-Client-ClientAuth-ECDSA",
2618 config: Config{
2619 MinVersion: ver.version,
2620 MaxVersion: ver.version,
2621 ClientAuth: RequireAnyClientCert,
2622 ClientCAs: certPool,
2623 },
2624 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002625 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2626 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002627 },
2628 })
2629 }
David Benjamin636293b2014-07-08 17:59:18 -04002630 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002631
2632 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002633 name: "NoClientCertificate",
2634 config: Config{
2635 MaxVersion: VersionTLS12,
2636 ClientAuth: RequireAnyClientCert,
2637 },
2638 shouldFail: true,
2639 expectedLocalError: "client didn't provide a certificate",
2640 })
2641
2642 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002643 name: "NoClientCertificate-TLS13",
2644 config: Config{
2645 MaxVersion: VersionTLS13,
2646 ClientAuth: RequireAnyClientCert,
2647 },
2648 shouldFail: true,
2649 expectedLocalError: "client didn't provide a certificate",
2650 })
2651
2652 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002653 testType: serverTest,
2654 name: "RequireAnyClientCertificate",
2655 config: Config{
2656 MaxVersion: VersionTLS12,
2657 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002658 flags: []string{"-require-any-client-certificate"},
2659 shouldFail: true,
2660 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2661 })
2662
2663 testCases = append(testCases, testCase{
2664 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002665 name: "RequireAnyClientCertificate-TLS13",
2666 config: Config{
2667 MaxVersion: VersionTLS13,
2668 },
2669 flags: []string{"-require-any-client-certificate"},
2670 shouldFail: true,
2671 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2672 })
2673
2674 testCases = append(testCases, testCase{
2675 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002676 name: "RequireAnyClientCertificate-SSL3",
2677 config: Config{
2678 MaxVersion: VersionSSL30,
2679 },
2680 flags: []string{"-require-any-client-certificate"},
2681 shouldFail: true,
2682 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2683 })
2684
2685 testCases = append(testCases, testCase{
2686 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002687 name: "SkipClientCertificate",
2688 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002689 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002690 Bugs: ProtocolBugs{
2691 SkipClientCertificate: true,
2692 },
2693 },
2694 // Setting SSL_VERIFY_PEER allows anonymous clients.
2695 flags: []string{"-verify-peer"},
2696 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002697 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002698 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002699
Steven Valdez143e8b32016-07-11 13:19:03 -04002700 testCases = append(testCases, testCase{
2701 testType: serverTest,
2702 name: "SkipClientCertificate-TLS13",
2703 config: Config{
2704 MaxVersion: VersionTLS13,
2705 Bugs: ProtocolBugs{
2706 SkipClientCertificate: true,
2707 },
2708 },
2709 // Setting SSL_VERIFY_PEER allows anonymous clients.
2710 flags: []string{"-verify-peer"},
2711 shouldFail: true,
2712 expectedError: ":UNEXPECTED_MESSAGE:",
2713 })
2714
David Benjaminc032dfa2016-05-12 14:54:57 -04002715 // Client auth is only legal in certificate-based ciphers.
2716 testCases = append(testCases, testCase{
2717 testType: clientTest,
2718 name: "ClientAuth-PSK",
2719 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002720 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002721 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2722 PreSharedKey: []byte("secret"),
2723 ClientAuth: RequireAnyClientCert,
2724 },
2725 flags: []string{
2726 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2727 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2728 "-psk", "secret",
2729 },
2730 shouldFail: true,
2731 expectedError: ":UNEXPECTED_MESSAGE:",
2732 })
2733 testCases = append(testCases, testCase{
2734 testType: clientTest,
2735 name: "ClientAuth-ECDHE_PSK",
2736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002737 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002738 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2739 PreSharedKey: []byte("secret"),
2740 ClientAuth: RequireAnyClientCert,
2741 },
2742 flags: []string{
2743 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2744 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2745 "-psk", "secret",
2746 },
2747 shouldFail: true,
2748 expectedError: ":UNEXPECTED_MESSAGE:",
2749 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002750
2751 // Regression test for a bug where the client CA list, if explicitly
2752 // set to NULL, was mis-encoded.
2753 testCases = append(testCases, testCase{
2754 testType: serverTest,
2755 name: "Null-Client-CA-List",
2756 config: Config{
2757 MaxVersion: VersionTLS12,
2758 Certificates: []Certificate{rsaCertificate},
2759 },
2760 flags: []string{
2761 "-require-any-client-certificate",
2762 "-use-null-client-ca-list",
2763 },
2764 })
David Benjamin636293b2014-07-08 17:59:18 -04002765}
2766
Adam Langley75712922014-10-10 16:23:43 -07002767func addExtendedMasterSecretTests() {
2768 const expectEMSFlag = "-expect-extended-master-secret"
2769
2770 for _, with := range []bool{false, true} {
2771 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002772 if with {
2773 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002774 }
2775
2776 for _, isClient := range []bool{false, true} {
2777 suffix := "-Server"
2778 testType := serverTest
2779 if isClient {
2780 suffix = "-Client"
2781 testType = clientTest
2782 }
2783
2784 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002785 // In TLS 1.3, the extension is irrelevant and
2786 // always reports as enabled.
2787 var flags []string
2788 if with || ver.version >= VersionTLS13 {
2789 flags = []string{expectEMSFlag}
2790 }
2791
Adam Langley75712922014-10-10 16:23:43 -07002792 test := testCase{
2793 testType: testType,
2794 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2795 config: Config{
2796 MinVersion: ver.version,
2797 MaxVersion: ver.version,
2798 Bugs: ProtocolBugs{
2799 NoExtendedMasterSecret: !with,
2800 RequireExtendedMasterSecret: with,
2801 },
2802 },
David Benjamin48cae082014-10-27 01:06:24 -04002803 flags: flags,
2804 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002805 }
2806 if test.shouldFail {
2807 test.expectedLocalError = "extended master secret required but not supported by peer"
2808 }
2809 testCases = append(testCases, test)
2810 }
2811 }
2812 }
2813
Adam Langleyba5934b2015-06-02 10:50:35 -07002814 for _, isClient := range []bool{false, true} {
2815 for _, supportedInFirstConnection := range []bool{false, true} {
2816 for _, supportedInResumeConnection := range []bool{false, true} {
2817 boolToWord := func(b bool) string {
2818 if b {
2819 return "Yes"
2820 }
2821 return "No"
2822 }
2823 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2824 if isClient {
2825 suffix += "Client"
2826 } else {
2827 suffix += "Server"
2828 }
2829
2830 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002831 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002832 Bugs: ProtocolBugs{
2833 RequireExtendedMasterSecret: true,
2834 },
2835 }
2836
2837 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002838 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002839 Bugs: ProtocolBugs{
2840 NoExtendedMasterSecret: true,
2841 },
2842 }
2843
2844 test := testCase{
2845 name: "ExtendedMasterSecret-" + suffix,
2846 resumeSession: true,
2847 }
2848
2849 if !isClient {
2850 test.testType = serverTest
2851 }
2852
2853 if supportedInFirstConnection {
2854 test.config = supportedConfig
2855 } else {
2856 test.config = noSupportConfig
2857 }
2858
2859 if supportedInResumeConnection {
2860 test.resumeConfig = &supportedConfig
2861 } else {
2862 test.resumeConfig = &noSupportConfig
2863 }
2864
2865 switch suffix {
2866 case "YesToYes-Client", "YesToYes-Server":
2867 // When a session is resumed, it should
2868 // still be aware that its master
2869 // secret was generated via EMS and
2870 // thus it's safe to use tls-unique.
2871 test.flags = []string{expectEMSFlag}
2872 case "NoToYes-Server":
2873 // If an original connection did not
2874 // contain EMS, but a resumption
2875 // handshake does, then a server should
2876 // not resume the session.
2877 test.expectResumeRejected = true
2878 case "YesToNo-Server":
2879 // Resuming an EMS session without the
2880 // EMS extension should cause the
2881 // server to abort the connection.
2882 test.shouldFail = true
2883 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2884 case "NoToYes-Client":
2885 // A client should abort a connection
2886 // where the server resumed a non-EMS
2887 // session but echoed the EMS
2888 // extension.
2889 test.shouldFail = true
2890 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2891 case "YesToNo-Client":
2892 // A client should abort a connection
2893 // where the server didn't echo EMS
2894 // when the session used it.
2895 test.shouldFail = true
2896 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2897 }
2898
2899 testCases = append(testCases, test)
2900 }
2901 }
2902 }
Adam Langley75712922014-10-10 16:23:43 -07002903}
2904
David Benjamin582ba042016-07-07 12:33:25 -07002905type stateMachineTestConfig struct {
2906 protocol protocol
2907 async bool
2908 splitHandshake, packHandshakeFlight bool
2909}
2910
David Benjamin43ec06f2014-08-05 02:28:57 -04002911// Adds tests that try to cover the range of the handshake state machine, under
2912// various conditions. Some of these are redundant with other tests, but they
2913// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002914func addAllStateMachineCoverageTests() {
2915 for _, async := range []bool{false, true} {
2916 for _, protocol := range []protocol{tls, dtls} {
2917 addStateMachineCoverageTests(stateMachineTestConfig{
2918 protocol: protocol,
2919 async: async,
2920 })
2921 addStateMachineCoverageTests(stateMachineTestConfig{
2922 protocol: protocol,
2923 async: async,
2924 splitHandshake: true,
2925 })
2926 if protocol == tls {
2927 addStateMachineCoverageTests(stateMachineTestConfig{
2928 protocol: protocol,
2929 async: async,
2930 packHandshakeFlight: true,
2931 })
2932 }
2933 }
2934 }
2935}
2936
2937func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002938 var tests []testCase
2939
2940 // Basic handshake, with resumption. Client and server,
2941 // session ID and session ticket.
2942 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002943 name: "Basic-Client",
2944 config: Config{
2945 MaxVersion: VersionTLS12,
2946 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002947 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002948 // Ensure session tickets are used, not session IDs.
2949 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002950 })
2951 tests = append(tests, testCase{
2952 name: "Basic-Client-RenewTicket",
2953 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002954 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002955 Bugs: ProtocolBugs{
2956 RenewTicketOnResume: true,
2957 },
2958 },
David Benjaminba4594a2015-06-18 18:36:15 -04002959 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002960 resumeSession: true,
2961 })
2962 tests = append(tests, testCase{
2963 name: "Basic-Client-NoTicket",
2964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002965 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002966 SessionTicketsDisabled: true,
2967 },
2968 resumeSession: true,
2969 })
2970 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002971 name: "Basic-Client-Implicit",
2972 config: Config{
2973 MaxVersion: VersionTLS12,
2974 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002975 flags: []string{"-implicit-handshake"},
2976 resumeSession: true,
2977 })
2978 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002979 testType: serverTest,
2980 name: "Basic-Server",
2981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002982 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002983 Bugs: ProtocolBugs{
2984 RequireSessionTickets: true,
2985 },
2986 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002987 resumeSession: true,
2988 })
2989 tests = append(tests, testCase{
2990 testType: serverTest,
2991 name: "Basic-Server-NoTickets",
2992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002993 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002994 SessionTicketsDisabled: true,
2995 },
2996 resumeSession: true,
2997 })
2998 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002999 testType: serverTest,
3000 name: "Basic-Server-Implicit",
3001 config: Config{
3002 MaxVersion: VersionTLS12,
3003 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003004 flags: []string{"-implicit-handshake"},
3005 resumeSession: true,
3006 })
3007 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003008 testType: serverTest,
3009 name: "Basic-Server-EarlyCallback",
3010 config: Config{
3011 MaxVersion: VersionTLS12,
3012 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003013 flags: []string{"-use-early-callback"},
3014 resumeSession: true,
3015 })
3016
Steven Valdez143e8b32016-07-11 13:19:03 -04003017 // TLS 1.3 basic handshake shapes.
3018 tests = append(tests, testCase{
3019 name: "TLS13-1RTT-Client",
3020 config: Config{
3021 MaxVersion: VersionTLS13,
3022 },
3023 })
3024 tests = append(tests, testCase{
3025 testType: serverTest,
3026 name: "TLS13-1RTT-Server",
3027 config: Config{
3028 MaxVersion: VersionTLS13,
3029 },
3030 })
3031
David Benjamin760b1dd2015-05-15 23:33:48 -04003032 // TLS client auth.
3033 tests = append(tests, testCase{
3034 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003035 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003037 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003038 ClientAuth: RequestClientCert,
3039 },
3040 })
3041 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003042 testType: serverTest,
3043 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003044 config: Config{
3045 MaxVersion: VersionTLS12,
3046 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003047 // Setting SSL_VERIFY_PEER allows anonymous clients.
3048 flags: []string{"-verify-peer"},
3049 })
David Benjamin582ba042016-07-07 12:33:25 -07003050 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003051 tests = append(tests, testCase{
3052 testType: clientTest,
3053 name: "ClientAuth-NoCertificate-Client-SSL3",
3054 config: Config{
3055 MaxVersion: VersionSSL30,
3056 ClientAuth: RequestClientCert,
3057 },
3058 })
3059 tests = append(tests, testCase{
3060 testType: serverTest,
3061 name: "ClientAuth-NoCertificate-Server-SSL3",
3062 config: Config{
3063 MaxVersion: VersionSSL30,
3064 },
3065 // Setting SSL_VERIFY_PEER allows anonymous clients.
3066 flags: []string{"-verify-peer"},
3067 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003068 tests = append(tests, testCase{
3069 testType: clientTest,
3070 name: "ClientAuth-NoCertificate-Client-TLS13",
3071 config: Config{
3072 MaxVersion: VersionTLS13,
3073 ClientAuth: RequestClientCert,
3074 },
3075 })
3076 tests = append(tests, testCase{
3077 testType: serverTest,
3078 name: "ClientAuth-NoCertificate-Server-TLS13",
3079 config: Config{
3080 MaxVersion: VersionTLS13,
3081 },
3082 // Setting SSL_VERIFY_PEER allows anonymous clients.
3083 flags: []string{"-verify-peer"},
3084 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003085 }
3086 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003087 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003088 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003090 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003091 ClientAuth: RequireAnyClientCert,
3092 },
3093 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003094 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3095 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003096 },
3097 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003098 tests = append(tests, testCase{
3099 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003100 name: "ClientAuth-RSA-Client-TLS13",
3101 config: Config{
3102 MaxVersion: VersionTLS13,
3103 ClientAuth: RequireAnyClientCert,
3104 },
3105 flags: []string{
3106 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3107 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3108 },
3109 })
3110 tests = append(tests, testCase{
3111 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003112 name: "ClientAuth-ECDSA-Client",
3113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003115 ClientAuth: RequireAnyClientCert,
3116 },
3117 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003118 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3119 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003120 },
3121 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003122 tests = append(tests, testCase{
3123 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003124 name: "ClientAuth-ECDSA-Client-TLS13",
3125 config: Config{
3126 MaxVersion: VersionTLS13,
3127 ClientAuth: RequireAnyClientCert,
3128 },
3129 flags: []string{
3130 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3131 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3132 },
3133 })
3134 tests = append(tests, testCase{
3135 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003136 name: "ClientAuth-NoCertificate-OldCallback",
3137 config: Config{
3138 MaxVersion: VersionTLS12,
3139 ClientAuth: RequestClientCert,
3140 },
3141 flags: []string{"-use-old-client-cert-callback"},
3142 })
3143 tests = append(tests, testCase{
3144 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003145 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3146 config: Config{
3147 MaxVersion: VersionTLS13,
3148 ClientAuth: RequestClientCert,
3149 },
3150 flags: []string{"-use-old-client-cert-callback"},
3151 })
3152 tests = append(tests, testCase{
3153 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003154 name: "ClientAuth-OldCallback",
3155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003156 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003157 ClientAuth: RequireAnyClientCert,
3158 },
3159 flags: []string{
3160 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3161 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3162 "-use-old-client-cert-callback",
3163 },
3164 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003165 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003166 testType: clientTest,
3167 name: "ClientAuth-OldCallback-TLS13",
3168 config: Config{
3169 MaxVersion: VersionTLS13,
3170 ClientAuth: RequireAnyClientCert,
3171 },
3172 flags: []string{
3173 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3174 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3175 "-use-old-client-cert-callback",
3176 },
3177 })
3178 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003179 testType: serverTest,
3180 name: "ClientAuth-Server",
3181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003182 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003183 Certificates: []Certificate{rsaCertificate},
3184 },
3185 flags: []string{"-require-any-client-certificate"},
3186 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003187 tests = append(tests, testCase{
3188 testType: serverTest,
3189 name: "ClientAuth-Server-TLS13",
3190 config: Config{
3191 MaxVersion: VersionTLS13,
3192 Certificates: []Certificate{rsaCertificate},
3193 },
3194 flags: []string{"-require-any-client-certificate"},
3195 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003196
David Benjamin4c3ddf72016-06-29 18:13:53 -04003197 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003198 tests = append(tests, testCase{
3199 testType: serverTest,
3200 name: "Basic-Server-RSA",
3201 config: Config{
3202 MaxVersion: VersionTLS12,
3203 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3204 },
3205 flags: []string{
3206 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3207 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3208 },
3209 })
3210 tests = append(tests, testCase{
3211 testType: serverTest,
3212 name: "Basic-Server-ECDHE-RSA",
3213 config: Config{
3214 MaxVersion: VersionTLS12,
3215 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3216 },
3217 flags: []string{
3218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3220 },
3221 })
3222 tests = append(tests, testCase{
3223 testType: serverTest,
3224 name: "Basic-Server-ECDHE-ECDSA",
3225 config: Config{
3226 MaxVersion: VersionTLS12,
3227 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3228 },
3229 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003230 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3231 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003232 },
3233 })
3234
David Benjamin760b1dd2015-05-15 23:33:48 -04003235 // No session ticket support; server doesn't send NewSessionTicket.
3236 tests = append(tests, testCase{
3237 name: "SessionTicketsDisabled-Client",
3238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003239 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003240 SessionTicketsDisabled: true,
3241 },
3242 })
3243 tests = append(tests, testCase{
3244 testType: serverTest,
3245 name: "SessionTicketsDisabled-Server",
3246 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003247 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003248 SessionTicketsDisabled: true,
3249 },
3250 })
3251
3252 // Skip ServerKeyExchange in PSK key exchange if there's no
3253 // identity hint.
3254 tests = append(tests, testCase{
3255 name: "EmptyPSKHint-Client",
3256 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003257 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3259 PreSharedKey: []byte("secret"),
3260 },
3261 flags: []string{"-psk", "secret"},
3262 })
3263 tests = append(tests, testCase{
3264 testType: serverTest,
3265 name: "EmptyPSKHint-Server",
3266 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003267 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3269 PreSharedKey: []byte("secret"),
3270 },
3271 flags: []string{"-psk", "secret"},
3272 })
3273
David Benjamin4c3ddf72016-06-29 18:13:53 -04003274 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003275 tests = append(tests, testCase{
3276 testType: clientTest,
3277 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003278 config: Config{
3279 MaxVersion: VersionTLS12,
3280 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003281 flags: []string{
3282 "-enable-ocsp-stapling",
3283 "-expect-ocsp-response",
3284 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003285 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003286 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003287 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003288 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003289 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290 testType: serverTest,
3291 name: "OCSPStapling-Server",
3292 config: Config{
3293 MaxVersion: VersionTLS12,
3294 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003295 expectedOCSPResponse: testOCSPResponse,
3296 flags: []string{
3297 "-ocsp-response",
3298 base64.StdEncoding.EncodeToString(testOCSPResponse),
3299 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003300 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003301 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003302 tests = append(tests, testCase{
3303 testType: clientTest,
3304 name: "OCSPStapling-Client-TLS13",
3305 config: Config{
3306 MaxVersion: VersionTLS13,
3307 },
3308 flags: []string{
3309 "-enable-ocsp-stapling",
3310 "-expect-ocsp-response",
3311 base64.StdEncoding.EncodeToString(testOCSPResponse),
3312 "-verify-peer",
3313 },
3314 // TODO(davidben): Enable this when resumption is implemented
3315 // in TLS 1.3.
3316 resumeSession: false,
3317 })
3318 tests = append(tests, testCase{
3319 testType: serverTest,
3320 name: "OCSPStapling-Server-TLS13",
3321 config: Config{
3322 MaxVersion: VersionTLS13,
3323 },
3324 expectedOCSPResponse: testOCSPResponse,
3325 flags: []string{
3326 "-ocsp-response",
3327 base64.StdEncoding.EncodeToString(testOCSPResponse),
3328 },
3329 // TODO(davidben): Enable this when resumption is implemented
3330 // in TLS 1.3.
3331 resumeSession: false,
3332 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003333
David Benjamin4c3ddf72016-06-29 18:13:53 -04003334 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003335 for _, vers := range tlsVersions {
3336 if config.protocol == dtls && !vers.hasDTLS {
3337 continue
3338 }
3339 tests = append(tests, testCase{
3340 testType: clientTest,
3341 name: "CertificateVerificationSucceed-" + vers.name,
3342 config: Config{
3343 MaxVersion: vers.version,
3344 },
3345 flags: []string{
3346 "-verify-peer",
3347 },
3348 })
3349 tests = append(tests, testCase{
3350 testType: clientTest,
3351 name: "CertificateVerificationFail-" + vers.name,
3352 config: Config{
3353 MaxVersion: vers.version,
3354 },
3355 flags: []string{
3356 "-verify-fail",
3357 "-verify-peer",
3358 },
3359 shouldFail: true,
3360 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3361 })
3362 tests = append(tests, testCase{
3363 testType: clientTest,
3364 name: "CertificateVerificationSoftFail-" + vers.name,
3365 config: Config{
3366 MaxVersion: vers.version,
3367 },
3368 flags: []string{
3369 "-verify-fail",
3370 "-expect-verify-result",
3371 },
3372 })
3373 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003374
David Benjamin1d4f4c02016-07-26 18:03:08 -04003375 tests = append(tests, testCase{
3376 name: "ShimSendAlert",
3377 flags: []string{"-send-alert"},
3378 shimWritesFirst: true,
3379 shouldFail: true,
3380 expectedLocalError: "remote error: decompression failure",
3381 })
3382
David Benjamin582ba042016-07-07 12:33:25 -07003383 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003384 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003385 name: "Renegotiate-Client",
3386 config: Config{
3387 MaxVersion: VersionTLS12,
3388 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003389 renegotiate: 1,
3390 flags: []string{
3391 "-renegotiate-freely",
3392 "-expect-total-renegotiations", "1",
3393 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003394 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003395
David Benjamin47921102016-07-28 11:29:18 -04003396 tests = append(tests, testCase{
3397 name: "SendHalfHelloRequest",
3398 config: Config{
3399 MaxVersion: VersionTLS12,
3400 Bugs: ProtocolBugs{
3401 PackHelloRequestWithFinished: config.packHandshakeFlight,
3402 },
3403 },
3404 sendHalfHelloRequest: true,
3405 flags: []string{"-renegotiate-ignore"},
3406 shouldFail: true,
3407 expectedError: ":UNEXPECTED_RECORD:",
3408 })
3409
David Benjamin760b1dd2015-05-15 23:33:48 -04003410 // NPN on client and server; results in post-handshake message.
3411 tests = append(tests, testCase{
3412 name: "NPN-Client",
3413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003414 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003415 NextProtos: []string{"foo"},
3416 },
3417 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003418 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003419 expectedNextProto: "foo",
3420 expectedNextProtoType: npn,
3421 })
3422 tests = append(tests, testCase{
3423 testType: serverTest,
3424 name: "NPN-Server",
3425 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003427 NextProtos: []string{"bar"},
3428 },
3429 flags: []string{
3430 "-advertise-npn", "\x03foo\x03bar\x03baz",
3431 "-expect-next-proto", "bar",
3432 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003433 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003434 expectedNextProto: "bar",
3435 expectedNextProtoType: npn,
3436 })
3437
3438 // TODO(davidben): Add tests for when False Start doesn't trigger.
3439
3440 // Client does False Start and negotiates NPN.
3441 tests = append(tests, testCase{
3442 name: "FalseStart",
3443 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003444 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3446 NextProtos: []string{"foo"},
3447 Bugs: ProtocolBugs{
3448 ExpectFalseStart: true,
3449 },
3450 },
3451 flags: []string{
3452 "-false-start",
3453 "-select-next-proto", "foo",
3454 },
3455 shimWritesFirst: true,
3456 resumeSession: true,
3457 })
3458
3459 // Client does False Start and negotiates ALPN.
3460 tests = append(tests, testCase{
3461 name: "FalseStart-ALPN",
3462 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003463 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3465 NextProtos: []string{"foo"},
3466 Bugs: ProtocolBugs{
3467 ExpectFalseStart: true,
3468 },
3469 },
3470 flags: []string{
3471 "-false-start",
3472 "-advertise-alpn", "\x03foo",
3473 },
3474 shimWritesFirst: true,
3475 resumeSession: true,
3476 })
3477
3478 // Client does False Start but doesn't explicitly call
3479 // SSL_connect.
3480 tests = append(tests, testCase{
3481 name: "FalseStart-Implicit",
3482 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003483 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003484 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3485 NextProtos: []string{"foo"},
3486 },
3487 flags: []string{
3488 "-implicit-handshake",
3489 "-false-start",
3490 "-advertise-alpn", "\x03foo",
3491 },
3492 })
3493
3494 // False Start without session tickets.
3495 tests = append(tests, testCase{
3496 name: "FalseStart-SessionTicketsDisabled",
3497 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003498 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003499 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3500 NextProtos: []string{"foo"},
3501 SessionTicketsDisabled: true,
3502 Bugs: ProtocolBugs{
3503 ExpectFalseStart: true,
3504 },
3505 },
3506 flags: []string{
3507 "-false-start",
3508 "-select-next-proto", "foo",
3509 },
3510 shimWritesFirst: true,
3511 })
3512
Adam Langleydf759b52016-07-11 15:24:37 -07003513 tests = append(tests, testCase{
3514 name: "FalseStart-CECPQ1",
3515 config: Config{
3516 MaxVersion: VersionTLS12,
3517 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3518 NextProtos: []string{"foo"},
3519 Bugs: ProtocolBugs{
3520 ExpectFalseStart: true,
3521 },
3522 },
3523 flags: []string{
3524 "-false-start",
3525 "-cipher", "DEFAULT:kCECPQ1",
3526 "-select-next-proto", "foo",
3527 },
3528 shimWritesFirst: true,
3529 resumeSession: true,
3530 })
3531
David Benjamin760b1dd2015-05-15 23:33:48 -04003532 // Server parses a V2ClientHello.
3533 tests = append(tests, testCase{
3534 testType: serverTest,
3535 name: "SendV2ClientHello",
3536 config: Config{
3537 // Choose a cipher suite that does not involve
3538 // elliptic curves, so no extensions are
3539 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003540 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003541 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3542 Bugs: ProtocolBugs{
3543 SendV2ClientHello: true,
3544 },
3545 },
3546 })
3547
3548 // Client sends a Channel ID.
3549 tests = append(tests, testCase{
3550 name: "ChannelID-Client",
3551 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003552 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003553 RequestChannelID: true,
3554 },
Adam Langley7c803a62015-06-15 15:35:05 -07003555 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 resumeSession: true,
3557 expectChannelID: true,
3558 })
3559
3560 // Server accepts a Channel ID.
3561 tests = append(tests, testCase{
3562 testType: serverTest,
3563 name: "ChannelID-Server",
3564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003565 MaxVersion: VersionTLS12,
3566 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003567 },
3568 flags: []string{
3569 "-expect-channel-id",
3570 base64.StdEncoding.EncodeToString(channelIDBytes),
3571 },
3572 resumeSession: true,
3573 expectChannelID: true,
3574 })
David Benjamin30789da2015-08-29 22:56:45 -04003575
David Benjaminf8fcdf32016-06-08 15:56:13 -04003576 // Channel ID and NPN at the same time, to ensure their relative
3577 // ordering is correct.
3578 tests = append(tests, testCase{
3579 name: "ChannelID-NPN-Client",
3580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003581 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003582 RequestChannelID: true,
3583 NextProtos: []string{"foo"},
3584 },
3585 flags: []string{
3586 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3587 "-select-next-proto", "foo",
3588 },
3589 resumeSession: true,
3590 expectChannelID: true,
3591 expectedNextProto: "foo",
3592 expectedNextProtoType: npn,
3593 })
3594 tests = append(tests, testCase{
3595 testType: serverTest,
3596 name: "ChannelID-NPN-Server",
3597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003598 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003599 ChannelID: channelIDKey,
3600 NextProtos: []string{"bar"},
3601 },
3602 flags: []string{
3603 "-expect-channel-id",
3604 base64.StdEncoding.EncodeToString(channelIDBytes),
3605 "-advertise-npn", "\x03foo\x03bar\x03baz",
3606 "-expect-next-proto", "bar",
3607 },
3608 resumeSession: true,
3609 expectChannelID: true,
3610 expectedNextProto: "bar",
3611 expectedNextProtoType: npn,
3612 })
3613
David Benjamin30789da2015-08-29 22:56:45 -04003614 // Bidirectional shutdown with the runner initiating.
3615 tests = append(tests, testCase{
3616 name: "Shutdown-Runner",
3617 config: Config{
3618 Bugs: ProtocolBugs{
3619 ExpectCloseNotify: true,
3620 },
3621 },
3622 flags: []string{"-check-close-notify"},
3623 })
3624
3625 // Bidirectional shutdown with the shim initiating. The runner,
3626 // in the meantime, sends garbage before the close_notify which
3627 // the shim must ignore.
3628 tests = append(tests, testCase{
3629 name: "Shutdown-Shim",
3630 config: Config{
3631 Bugs: ProtocolBugs{
3632 ExpectCloseNotify: true,
3633 },
3634 },
3635 shimShutsDown: true,
3636 sendEmptyRecords: 1,
3637 sendWarningAlerts: 1,
3638 flags: []string{"-check-close-notify"},
3639 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003640 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003641 // TODO(davidben): DTLS 1.3 will want a similar thing for
3642 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003643 tests = append(tests, testCase{
3644 name: "SkipHelloVerifyRequest",
3645 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003646 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003647 Bugs: ProtocolBugs{
3648 SkipHelloVerifyRequest: true,
3649 },
3650 },
3651 })
3652 }
3653
David Benjamin760b1dd2015-05-15 23:33:48 -04003654 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003655 test.protocol = config.protocol
3656 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003657 test.name += "-DTLS"
3658 }
David Benjamin582ba042016-07-07 12:33:25 -07003659 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003660 test.name += "-Async"
3661 test.flags = append(test.flags, "-async")
3662 } else {
3663 test.name += "-Sync"
3664 }
David Benjamin582ba042016-07-07 12:33:25 -07003665 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003666 test.name += "-SplitHandshakeRecords"
3667 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003668 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003669 test.config.Bugs.MaxPacketLength = 256
3670 test.flags = append(test.flags, "-mtu", "256")
3671 }
3672 }
David Benjamin582ba042016-07-07 12:33:25 -07003673 if config.packHandshakeFlight {
3674 test.name += "-PackHandshakeFlight"
3675 test.config.Bugs.PackHandshakeFlight = true
3676 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003677 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003678 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003679}
3680
Adam Langley524e7172015-02-20 16:04:00 -08003681func addDDoSCallbackTests() {
3682 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003683 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003684 for _, resume := range []bool{false, true} {
3685 suffix := "Resume"
3686 if resume {
3687 suffix = "No" + suffix
3688 }
3689
3690 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003691 testType: serverTest,
3692 name: "Server-DDoS-OK-" + suffix,
3693 config: Config{
3694 MaxVersion: VersionTLS12,
3695 },
Adam Langley524e7172015-02-20 16:04:00 -08003696 flags: []string{"-install-ddos-callback"},
3697 resumeSession: resume,
3698 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003699 if !resume {
3700 testCases = append(testCases, testCase{
3701 testType: serverTest,
3702 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3703 config: Config{
3704 MaxVersion: VersionTLS13,
3705 },
3706 flags: []string{"-install-ddos-callback"},
3707 resumeSession: resume,
3708 })
3709 }
Adam Langley524e7172015-02-20 16:04:00 -08003710
3711 failFlag := "-fail-ddos-callback"
3712 if resume {
3713 failFlag = "-fail-second-ddos-callback"
3714 }
3715 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003716 testType: serverTest,
3717 name: "Server-DDoS-Reject-" + suffix,
3718 config: Config{
3719 MaxVersion: VersionTLS12,
3720 },
Adam Langley524e7172015-02-20 16:04:00 -08003721 flags: []string{"-install-ddos-callback", failFlag},
3722 resumeSession: resume,
3723 shouldFail: true,
3724 expectedError: ":CONNECTION_REJECTED:",
3725 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003726 if !resume {
3727 testCases = append(testCases, testCase{
3728 testType: serverTest,
3729 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3730 config: Config{
3731 MaxVersion: VersionTLS13,
3732 },
3733 flags: []string{"-install-ddos-callback", failFlag},
3734 resumeSession: resume,
3735 shouldFail: true,
3736 expectedError: ":CONNECTION_REJECTED:",
3737 })
3738 }
Adam Langley524e7172015-02-20 16:04:00 -08003739 }
3740}
3741
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003742func addVersionNegotiationTests() {
3743 for i, shimVers := range tlsVersions {
3744 // Assemble flags to disable all newer versions on the shim.
3745 var flags []string
3746 for _, vers := range tlsVersions[i+1:] {
3747 flags = append(flags, vers.flag)
3748 }
3749
3750 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003751 protocols := []protocol{tls}
3752 if runnerVers.hasDTLS && shimVers.hasDTLS {
3753 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003754 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003755 for _, protocol := range protocols {
3756 expectedVersion := shimVers.version
3757 if runnerVers.version < shimVers.version {
3758 expectedVersion = runnerVers.version
3759 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003760
David Benjamin8b8c0062014-11-23 02:47:52 -05003761 suffix := shimVers.name + "-" + runnerVers.name
3762 if protocol == dtls {
3763 suffix += "-DTLS"
3764 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003765
David Benjamin1eb367c2014-12-12 18:17:51 -05003766 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3767
David Benjamin1e29a6b2014-12-10 02:27:24 -05003768 clientVers := shimVers.version
3769 if clientVers > VersionTLS10 {
3770 clientVers = VersionTLS10
3771 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003772 serverVers := expectedVersion
3773 if expectedVersion >= VersionTLS13 {
3774 serverVers = VersionTLS10
3775 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003776 testCases = append(testCases, testCase{
3777 protocol: protocol,
3778 testType: clientTest,
3779 name: "VersionNegotiation-Client-" + suffix,
3780 config: Config{
3781 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003782 Bugs: ProtocolBugs{
3783 ExpectInitialRecordVersion: clientVers,
3784 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003785 },
3786 flags: flags,
3787 expectedVersion: expectedVersion,
3788 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003789 testCases = append(testCases, testCase{
3790 protocol: protocol,
3791 testType: clientTest,
3792 name: "VersionNegotiation-Client2-" + suffix,
3793 config: Config{
3794 MaxVersion: runnerVers.version,
3795 Bugs: ProtocolBugs{
3796 ExpectInitialRecordVersion: clientVers,
3797 },
3798 },
3799 flags: []string{"-max-version", shimVersFlag},
3800 expectedVersion: expectedVersion,
3801 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003802
3803 testCases = append(testCases, testCase{
3804 protocol: protocol,
3805 testType: serverTest,
3806 name: "VersionNegotiation-Server-" + suffix,
3807 config: Config{
3808 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003809 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003810 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003811 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003812 },
3813 flags: flags,
3814 expectedVersion: expectedVersion,
3815 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003816 testCases = append(testCases, testCase{
3817 protocol: protocol,
3818 testType: serverTest,
3819 name: "VersionNegotiation-Server2-" + suffix,
3820 config: Config{
3821 MaxVersion: runnerVers.version,
3822 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003823 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003824 },
3825 },
3826 flags: []string{"-max-version", shimVersFlag},
3827 expectedVersion: expectedVersion,
3828 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003829 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003830 }
3831 }
David Benjamin95c69562016-06-29 18:15:03 -04003832
3833 // Test for version tolerance.
3834 testCases = append(testCases, testCase{
3835 testType: serverTest,
3836 name: "MinorVersionTolerance",
3837 config: Config{
3838 Bugs: ProtocolBugs{
3839 SendClientVersion: 0x03ff,
3840 },
3841 },
3842 expectedVersion: VersionTLS13,
3843 })
3844 testCases = append(testCases, testCase{
3845 testType: serverTest,
3846 name: "MajorVersionTolerance",
3847 config: Config{
3848 Bugs: ProtocolBugs{
3849 SendClientVersion: 0x0400,
3850 },
3851 },
3852 expectedVersion: VersionTLS13,
3853 })
3854 testCases = append(testCases, testCase{
3855 protocol: dtls,
3856 testType: serverTest,
3857 name: "MinorVersionTolerance-DTLS",
3858 config: Config{
3859 Bugs: ProtocolBugs{
3860 SendClientVersion: 0x03ff,
3861 },
3862 },
3863 expectedVersion: VersionTLS12,
3864 })
3865 testCases = append(testCases, testCase{
3866 protocol: dtls,
3867 testType: serverTest,
3868 name: "MajorVersionTolerance-DTLS",
3869 config: Config{
3870 Bugs: ProtocolBugs{
3871 SendClientVersion: 0x0400,
3872 },
3873 },
3874 expectedVersion: VersionTLS12,
3875 })
3876
3877 // Test that versions below 3.0 are rejected.
3878 testCases = append(testCases, testCase{
3879 testType: serverTest,
3880 name: "VersionTooLow",
3881 config: Config{
3882 Bugs: ProtocolBugs{
3883 SendClientVersion: 0x0200,
3884 },
3885 },
3886 shouldFail: true,
3887 expectedError: ":UNSUPPORTED_PROTOCOL:",
3888 })
3889 testCases = append(testCases, testCase{
3890 protocol: dtls,
3891 testType: serverTest,
3892 name: "VersionTooLow-DTLS",
3893 config: Config{
3894 Bugs: ProtocolBugs{
3895 // 0x0201 is the lowest version expressable in
3896 // DTLS.
3897 SendClientVersion: 0x0201,
3898 },
3899 },
3900 shouldFail: true,
3901 expectedError: ":UNSUPPORTED_PROTOCOL:",
3902 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003903
3904 // Test TLS 1.3's downgrade signal.
3905 testCases = append(testCases, testCase{
3906 name: "Downgrade-TLS12-Client",
3907 config: Config{
3908 Bugs: ProtocolBugs{
3909 NegotiateVersion: VersionTLS12,
3910 },
3911 },
3912 shouldFail: true,
3913 expectedError: ":DOWNGRADE_DETECTED:",
3914 })
3915 testCases = append(testCases, testCase{
3916 testType: serverTest,
3917 name: "Downgrade-TLS12-Server",
3918 config: Config{
3919 Bugs: ProtocolBugs{
3920 SendClientVersion: VersionTLS12,
3921 },
3922 },
3923 shouldFail: true,
3924 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3925 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02003926
3927 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
3928 // behave correctly when both real maximum and fallback versions are
3929 // set.
3930 testCases = append(testCases, testCase{
3931 name: "Downgrade-TLS12-Client-Fallback",
3932 config: Config{
3933 Bugs: ProtocolBugs{
3934 FailIfNotFallbackSCSV: true,
3935 },
3936 },
3937 flags: []string{
3938 "-max-version", strconv.Itoa(VersionTLS13),
3939 "-fallback-version", strconv.Itoa(VersionTLS12),
3940 },
3941 shouldFail: true,
3942 expectedError: ":DOWNGRADE_DETECTED:",
3943 })
3944 testCases = append(testCases, testCase{
3945 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
3946 flags: []string{
3947 "-max-version", strconv.Itoa(VersionTLS12),
3948 "-fallback-version", strconv.Itoa(VersionTLS12),
3949 },
3950 })
3951
3952 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
3953 // just have such connections fail than risk getting confused because we
3954 // didn't sent the 1.3 ClientHello.)
3955 testCases = append(testCases, testCase{
3956 name: "Downgrade-TLS12-Fallback-CheckVersion",
3957 config: Config{
3958 Bugs: ProtocolBugs{
3959 NegotiateVersion: VersionTLS13,
3960 FailIfNotFallbackSCSV: true,
3961 },
3962 },
3963 flags: []string{
3964 "-max-version", strconv.Itoa(VersionTLS13),
3965 "-fallback-version", strconv.Itoa(VersionTLS12),
3966 },
3967 shouldFail: true,
3968 expectedError: ":UNSUPPORTED_PROTOCOL:",
3969 })
3970
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003971}
3972
David Benjaminaccb4542014-12-12 23:44:33 -05003973func addMinimumVersionTests() {
3974 for i, shimVers := range tlsVersions {
3975 // Assemble flags to disable all older versions on the shim.
3976 var flags []string
3977 for _, vers := range tlsVersions[:i] {
3978 flags = append(flags, vers.flag)
3979 }
3980
3981 for _, runnerVers := range tlsVersions {
3982 protocols := []protocol{tls}
3983 if runnerVers.hasDTLS && shimVers.hasDTLS {
3984 protocols = append(protocols, dtls)
3985 }
3986 for _, protocol := range protocols {
3987 suffix := shimVers.name + "-" + runnerVers.name
3988 if protocol == dtls {
3989 suffix += "-DTLS"
3990 }
3991 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3992
David Benjaminaccb4542014-12-12 23:44:33 -05003993 var expectedVersion uint16
3994 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003995 var expectedClientError, expectedServerError string
3996 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003997 if runnerVers.version >= shimVers.version {
3998 expectedVersion = runnerVers.version
3999 } else {
4000 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004001 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4002 expectedServerLocalError = "remote error: protocol version not supported"
4003 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4004 // If the client's minimum version is TLS 1.3 and the runner's
4005 // maximum is below TLS 1.2, the runner will fail to select a
4006 // cipher before the shim rejects the selected version.
4007 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4008 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4009 } else {
4010 expectedClientError = expectedServerError
4011 expectedClientLocalError = expectedServerLocalError
4012 }
David Benjaminaccb4542014-12-12 23:44:33 -05004013 }
4014
4015 testCases = append(testCases, testCase{
4016 protocol: protocol,
4017 testType: clientTest,
4018 name: "MinimumVersion-Client-" + suffix,
4019 config: Config{
4020 MaxVersion: runnerVers.version,
4021 },
David Benjamin87909c02014-12-13 01:55:01 -05004022 flags: flags,
4023 expectedVersion: expectedVersion,
4024 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004025 expectedError: expectedClientError,
4026 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004027 })
4028 testCases = append(testCases, testCase{
4029 protocol: protocol,
4030 testType: clientTest,
4031 name: "MinimumVersion-Client2-" + suffix,
4032 config: Config{
4033 MaxVersion: runnerVers.version,
4034 },
David Benjamin87909c02014-12-13 01:55:01 -05004035 flags: []string{"-min-version", shimVersFlag},
4036 expectedVersion: expectedVersion,
4037 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004038 expectedError: expectedClientError,
4039 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004040 })
4041
4042 testCases = append(testCases, testCase{
4043 protocol: protocol,
4044 testType: serverTest,
4045 name: "MinimumVersion-Server-" + suffix,
4046 config: Config{
4047 MaxVersion: runnerVers.version,
4048 },
David Benjamin87909c02014-12-13 01:55:01 -05004049 flags: flags,
4050 expectedVersion: expectedVersion,
4051 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004052 expectedError: expectedServerError,
4053 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004054 })
4055 testCases = append(testCases, testCase{
4056 protocol: protocol,
4057 testType: serverTest,
4058 name: "MinimumVersion-Server2-" + suffix,
4059 config: Config{
4060 MaxVersion: runnerVers.version,
4061 },
David Benjamin87909c02014-12-13 01:55:01 -05004062 flags: []string{"-min-version", shimVersFlag},
4063 expectedVersion: expectedVersion,
4064 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004065 expectedError: expectedServerError,
4066 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004067 })
4068 }
4069 }
4070 }
4071}
4072
David Benjamine78bfde2014-09-06 12:45:15 -04004073func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004074 // TODO(davidben): Extensions, where applicable, all move their server
4075 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4076 // tests for both. Also test interaction with 0-RTT when implemented.
4077
David Benjamin97d17d92016-07-14 16:12:00 -04004078 // Repeat extensions tests all versions except SSL 3.0.
4079 for _, ver := range tlsVersions {
4080 if ver.version == VersionSSL30 {
4081 continue
4082 }
4083
4084 // TODO(davidben): Implement resumption in TLS 1.3.
4085 resumeSession := ver.version < VersionTLS13
4086
4087 // Test that duplicate extensions are rejected.
4088 testCases = append(testCases, testCase{
4089 testType: clientTest,
4090 name: "DuplicateExtensionClient-" + ver.name,
4091 config: Config{
4092 MaxVersion: ver.version,
4093 Bugs: ProtocolBugs{
4094 DuplicateExtension: true,
4095 },
David Benjamine78bfde2014-09-06 12:45:15 -04004096 },
David Benjamin97d17d92016-07-14 16:12:00 -04004097 shouldFail: true,
4098 expectedLocalError: "remote error: error decoding message",
4099 })
4100 testCases = append(testCases, testCase{
4101 testType: serverTest,
4102 name: "DuplicateExtensionServer-" + ver.name,
4103 config: Config{
4104 MaxVersion: ver.version,
4105 Bugs: ProtocolBugs{
4106 DuplicateExtension: true,
4107 },
David Benjamine78bfde2014-09-06 12:45:15 -04004108 },
David Benjamin97d17d92016-07-14 16:12:00 -04004109 shouldFail: true,
4110 expectedLocalError: "remote error: error decoding message",
4111 })
4112
4113 // Test SNI.
4114 testCases = append(testCases, testCase{
4115 testType: clientTest,
4116 name: "ServerNameExtensionClient-" + ver.name,
4117 config: Config{
4118 MaxVersion: ver.version,
4119 Bugs: ProtocolBugs{
4120 ExpectServerName: "example.com",
4121 },
David Benjamine78bfde2014-09-06 12:45:15 -04004122 },
David Benjamin97d17d92016-07-14 16:12:00 -04004123 flags: []string{"-host-name", "example.com"},
4124 })
4125 testCases = append(testCases, testCase{
4126 testType: clientTest,
4127 name: "ServerNameExtensionClientMismatch-" + ver.name,
4128 config: Config{
4129 MaxVersion: ver.version,
4130 Bugs: ProtocolBugs{
4131 ExpectServerName: "mismatch.com",
4132 },
David Benjamine78bfde2014-09-06 12:45:15 -04004133 },
David Benjamin97d17d92016-07-14 16:12:00 -04004134 flags: []string{"-host-name", "example.com"},
4135 shouldFail: true,
4136 expectedLocalError: "tls: unexpected server name",
4137 })
4138 testCases = append(testCases, testCase{
4139 testType: clientTest,
4140 name: "ServerNameExtensionClientMissing-" + ver.name,
4141 config: Config{
4142 MaxVersion: ver.version,
4143 Bugs: ProtocolBugs{
4144 ExpectServerName: "missing.com",
4145 },
David Benjamine78bfde2014-09-06 12:45:15 -04004146 },
David Benjamin97d17d92016-07-14 16:12:00 -04004147 shouldFail: true,
4148 expectedLocalError: "tls: unexpected server name",
4149 })
4150 testCases = append(testCases, testCase{
4151 testType: serverTest,
4152 name: "ServerNameExtensionServer-" + ver.name,
4153 config: Config{
4154 MaxVersion: ver.version,
4155 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004156 },
David Benjamin97d17d92016-07-14 16:12:00 -04004157 flags: []string{"-expect-server-name", "example.com"},
4158 resumeSession: resumeSession,
4159 })
4160
4161 // Test ALPN.
4162 testCases = append(testCases, testCase{
4163 testType: clientTest,
4164 name: "ALPNClient-" + ver.name,
4165 config: Config{
4166 MaxVersion: ver.version,
4167 NextProtos: []string{"foo"},
4168 },
4169 flags: []string{
4170 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4171 "-expect-alpn", "foo",
4172 },
4173 expectedNextProto: "foo",
4174 expectedNextProtoType: alpn,
4175 resumeSession: resumeSession,
4176 })
4177 testCases = append(testCases, testCase{
4178 testType: serverTest,
4179 name: "ALPNServer-" + ver.name,
4180 config: Config{
4181 MaxVersion: ver.version,
4182 NextProtos: []string{"foo", "bar", "baz"},
4183 },
4184 flags: []string{
4185 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4186 "-select-alpn", "foo",
4187 },
4188 expectedNextProto: "foo",
4189 expectedNextProtoType: alpn,
4190 resumeSession: resumeSession,
4191 })
4192 testCases = append(testCases, testCase{
4193 testType: serverTest,
4194 name: "ALPNServer-Decline-" + ver.name,
4195 config: Config{
4196 MaxVersion: ver.version,
4197 NextProtos: []string{"foo", "bar", "baz"},
4198 },
4199 flags: []string{"-decline-alpn"},
4200 expectNoNextProto: true,
4201 resumeSession: resumeSession,
4202 })
4203
4204 var emptyString string
4205 testCases = append(testCases, testCase{
4206 testType: clientTest,
4207 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4208 config: Config{
4209 MaxVersion: ver.version,
4210 NextProtos: []string{""},
4211 Bugs: ProtocolBugs{
4212 // A server returning an empty ALPN protocol
4213 // should be rejected.
4214 ALPNProtocol: &emptyString,
4215 },
4216 },
4217 flags: []string{
4218 "-advertise-alpn", "\x03foo",
4219 },
4220 shouldFail: true,
4221 expectedError: ":PARSE_TLSEXT:",
4222 })
4223 testCases = append(testCases, testCase{
4224 testType: serverTest,
4225 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4226 config: Config{
4227 MaxVersion: ver.version,
4228 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004229 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004230 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004231 },
David Benjamin97d17d92016-07-14 16:12:00 -04004232 flags: []string{
4233 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004234 },
David Benjamin97d17d92016-07-14 16:12:00 -04004235 shouldFail: true,
4236 expectedError: ":PARSE_TLSEXT:",
4237 })
4238
4239 // Test NPN and the interaction with ALPN.
4240 if ver.version < VersionTLS13 {
4241 // Test that the server prefers ALPN over NPN.
4242 testCases = append(testCases, testCase{
4243 testType: serverTest,
4244 name: "ALPNServer-Preferred-" + ver.name,
4245 config: Config{
4246 MaxVersion: ver.version,
4247 NextProtos: []string{"foo", "bar", "baz"},
4248 },
4249 flags: []string{
4250 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4251 "-select-alpn", "foo",
4252 "-advertise-npn", "\x03foo\x03bar\x03baz",
4253 },
4254 expectedNextProto: "foo",
4255 expectedNextProtoType: alpn,
4256 resumeSession: resumeSession,
4257 })
4258 testCases = append(testCases, testCase{
4259 testType: serverTest,
4260 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4261 config: Config{
4262 MaxVersion: ver.version,
4263 NextProtos: []string{"foo", "bar", "baz"},
4264 Bugs: ProtocolBugs{
4265 SwapNPNAndALPN: true,
4266 },
4267 },
4268 flags: []string{
4269 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4270 "-select-alpn", "foo",
4271 "-advertise-npn", "\x03foo\x03bar\x03baz",
4272 },
4273 expectedNextProto: "foo",
4274 expectedNextProtoType: alpn,
4275 resumeSession: resumeSession,
4276 })
4277
4278 // Test that negotiating both NPN and ALPN is forbidden.
4279 testCases = append(testCases, testCase{
4280 name: "NegotiateALPNAndNPN-" + ver.name,
4281 config: Config{
4282 MaxVersion: ver.version,
4283 NextProtos: []string{"foo", "bar", "baz"},
4284 Bugs: ProtocolBugs{
4285 NegotiateALPNAndNPN: true,
4286 },
4287 },
4288 flags: []string{
4289 "-advertise-alpn", "\x03foo",
4290 "-select-next-proto", "foo",
4291 },
4292 shouldFail: true,
4293 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4294 })
4295 testCases = append(testCases, testCase{
4296 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4297 config: Config{
4298 MaxVersion: ver.version,
4299 NextProtos: []string{"foo", "bar", "baz"},
4300 Bugs: ProtocolBugs{
4301 NegotiateALPNAndNPN: true,
4302 SwapNPNAndALPN: true,
4303 },
4304 },
4305 flags: []string{
4306 "-advertise-alpn", "\x03foo",
4307 "-select-next-proto", "foo",
4308 },
4309 shouldFail: true,
4310 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4311 })
4312
4313 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4314 testCases = append(testCases, testCase{
4315 name: "DisableNPN-" + ver.name,
4316 config: Config{
4317 MaxVersion: ver.version,
4318 NextProtos: []string{"foo"},
4319 },
4320 flags: []string{
4321 "-select-next-proto", "foo",
4322 "-disable-npn",
4323 },
4324 expectNoNextProto: true,
4325 })
4326 }
4327
4328 // Test ticket behavior.
4329 //
4330 // TODO(davidben): Add TLS 1.3 versions of these.
4331 if ver.version < VersionTLS13 {
4332 // Resume with a corrupt ticket.
4333 testCases = append(testCases, testCase{
4334 testType: serverTest,
4335 name: "CorruptTicket-" + ver.name,
4336 config: Config{
4337 MaxVersion: ver.version,
4338 Bugs: ProtocolBugs{
4339 CorruptTicket: true,
4340 },
4341 },
4342 resumeSession: true,
4343 expectResumeRejected: true,
4344 })
4345 // Test the ticket callback, with and without renewal.
4346 testCases = append(testCases, testCase{
4347 testType: serverTest,
4348 name: "TicketCallback-" + ver.name,
4349 config: Config{
4350 MaxVersion: ver.version,
4351 },
4352 resumeSession: true,
4353 flags: []string{"-use-ticket-callback"},
4354 })
4355 testCases = append(testCases, testCase{
4356 testType: serverTest,
4357 name: "TicketCallback-Renew-" + ver.name,
4358 config: Config{
4359 MaxVersion: ver.version,
4360 Bugs: ProtocolBugs{
4361 ExpectNewTicket: true,
4362 },
4363 },
4364 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4365 resumeSession: true,
4366 })
4367
4368 // Resume with an oversized session id.
4369 testCases = append(testCases, testCase{
4370 testType: serverTest,
4371 name: "OversizedSessionId-" + ver.name,
4372 config: Config{
4373 MaxVersion: ver.version,
4374 Bugs: ProtocolBugs{
4375 OversizedSessionId: true,
4376 },
4377 },
4378 resumeSession: true,
4379 shouldFail: true,
4380 expectedError: ":DECODE_ERROR:",
4381 })
4382 }
4383
4384 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4385 // are ignored.
4386 if ver.hasDTLS {
4387 testCases = append(testCases, testCase{
4388 protocol: dtls,
4389 name: "SRTP-Client-" + ver.name,
4390 config: Config{
4391 MaxVersion: ver.version,
4392 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4393 },
4394 flags: []string{
4395 "-srtp-profiles",
4396 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4397 },
4398 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4399 })
4400 testCases = append(testCases, testCase{
4401 protocol: dtls,
4402 testType: serverTest,
4403 name: "SRTP-Server-" + ver.name,
4404 config: Config{
4405 MaxVersion: ver.version,
4406 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4407 },
4408 flags: []string{
4409 "-srtp-profiles",
4410 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4411 },
4412 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4413 })
4414 // Test that the MKI is ignored.
4415 testCases = append(testCases, testCase{
4416 protocol: dtls,
4417 testType: serverTest,
4418 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4419 config: Config{
4420 MaxVersion: ver.version,
4421 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4422 Bugs: ProtocolBugs{
4423 SRTPMasterKeyIdentifer: "bogus",
4424 },
4425 },
4426 flags: []string{
4427 "-srtp-profiles",
4428 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4429 },
4430 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4431 })
4432 // Test that SRTP isn't negotiated on the server if there were
4433 // no matching profiles.
4434 testCases = append(testCases, testCase{
4435 protocol: dtls,
4436 testType: serverTest,
4437 name: "SRTP-Server-NoMatch-" + ver.name,
4438 config: Config{
4439 MaxVersion: ver.version,
4440 SRTPProtectionProfiles: []uint16{100, 101, 102},
4441 },
4442 flags: []string{
4443 "-srtp-profiles",
4444 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4445 },
4446 expectedSRTPProtectionProfile: 0,
4447 })
4448 // Test that the server returning an invalid SRTP profile is
4449 // flagged as an error by the client.
4450 testCases = append(testCases, testCase{
4451 protocol: dtls,
4452 name: "SRTP-Client-NoMatch-" + ver.name,
4453 config: Config{
4454 MaxVersion: ver.version,
4455 Bugs: ProtocolBugs{
4456 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4457 },
4458 },
4459 flags: []string{
4460 "-srtp-profiles",
4461 "SRTP_AES128_CM_SHA1_80",
4462 },
4463 shouldFail: true,
4464 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4465 })
4466 }
4467
4468 // Test SCT list.
4469 testCases = append(testCases, testCase{
4470 name: "SignedCertificateTimestampList-Client-" + ver.name,
4471 testType: clientTest,
4472 config: Config{
4473 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004474 },
David Benjamin97d17d92016-07-14 16:12:00 -04004475 flags: []string{
4476 "-enable-signed-cert-timestamps",
4477 "-expect-signed-cert-timestamps",
4478 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004479 },
David Benjamin97d17d92016-07-14 16:12:00 -04004480 resumeSession: resumeSession,
4481 })
4482 testCases = append(testCases, testCase{
4483 name: "SendSCTListOnResume-" + ver.name,
4484 config: Config{
4485 MaxVersion: ver.version,
4486 Bugs: ProtocolBugs{
4487 SendSCTListOnResume: []byte("bogus"),
4488 },
David Benjamind98452d2015-06-16 14:16:23 -04004489 },
David Benjamin97d17d92016-07-14 16:12:00 -04004490 flags: []string{
4491 "-enable-signed-cert-timestamps",
4492 "-expect-signed-cert-timestamps",
4493 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004494 },
David Benjamin97d17d92016-07-14 16:12:00 -04004495 resumeSession: resumeSession,
4496 })
4497 testCases = append(testCases, testCase{
4498 name: "SignedCertificateTimestampList-Server-" + ver.name,
4499 testType: serverTest,
4500 config: Config{
4501 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004502 },
David Benjamin97d17d92016-07-14 16:12:00 -04004503 flags: []string{
4504 "-signed-cert-timestamps",
4505 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004506 },
David Benjamin97d17d92016-07-14 16:12:00 -04004507 expectedSCTList: testSCTList,
4508 resumeSession: resumeSession,
4509 })
4510 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511
Paul Lietar4fac72e2015-09-09 13:44:55 +01004512 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004513 testType: clientTest,
4514 name: "ClientHelloPadding",
4515 config: Config{
4516 Bugs: ProtocolBugs{
4517 RequireClientHelloSize: 512,
4518 },
4519 },
4520 // This hostname just needs to be long enough to push the
4521 // ClientHello into F5's danger zone between 256 and 511 bytes
4522 // long.
4523 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4524 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004525
4526 // Extensions should not function in SSL 3.0.
4527 testCases = append(testCases, testCase{
4528 testType: serverTest,
4529 name: "SSLv3Extensions-NoALPN",
4530 config: Config{
4531 MaxVersion: VersionSSL30,
4532 NextProtos: []string{"foo", "bar", "baz"},
4533 },
4534 flags: []string{
4535 "-select-alpn", "foo",
4536 },
4537 expectNoNextProto: true,
4538 })
4539
4540 // Test session tickets separately as they follow a different codepath.
4541 testCases = append(testCases, testCase{
4542 testType: serverTest,
4543 name: "SSLv3Extensions-NoTickets",
4544 config: Config{
4545 MaxVersion: VersionSSL30,
4546 Bugs: ProtocolBugs{
4547 // Historically, session tickets in SSL 3.0
4548 // failed in different ways depending on whether
4549 // the client supported renegotiation_info.
4550 NoRenegotiationInfo: true,
4551 },
4552 },
4553 resumeSession: true,
4554 })
4555 testCases = append(testCases, testCase{
4556 testType: serverTest,
4557 name: "SSLv3Extensions-NoTickets2",
4558 config: Config{
4559 MaxVersion: VersionSSL30,
4560 },
4561 resumeSession: true,
4562 })
4563
4564 // But SSL 3.0 does send and process renegotiation_info.
4565 testCases = append(testCases, testCase{
4566 testType: serverTest,
4567 name: "SSLv3Extensions-RenegotiationInfo",
4568 config: Config{
4569 MaxVersion: VersionSSL30,
4570 Bugs: ProtocolBugs{
4571 RequireRenegotiationInfo: true,
4572 },
4573 },
4574 })
4575 testCases = append(testCases, testCase{
4576 testType: serverTest,
4577 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4578 config: Config{
4579 MaxVersion: VersionSSL30,
4580 Bugs: ProtocolBugs{
4581 NoRenegotiationInfo: true,
4582 SendRenegotiationSCSV: true,
4583 RequireRenegotiationInfo: true,
4584 },
4585 },
4586 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004587
4588 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4589 // in ServerHello.
4590 testCases = append(testCases, testCase{
4591 name: "NPN-Forbidden-TLS13",
4592 config: Config{
4593 MaxVersion: VersionTLS13,
4594 NextProtos: []string{"foo"},
4595 Bugs: ProtocolBugs{
4596 NegotiateNPNAtAllVersions: true,
4597 },
4598 },
4599 flags: []string{"-select-next-proto", "foo"},
4600 shouldFail: true,
4601 expectedError: ":ERROR_PARSING_EXTENSION:",
4602 })
4603 testCases = append(testCases, testCase{
4604 name: "EMS-Forbidden-TLS13",
4605 config: Config{
4606 MaxVersion: VersionTLS13,
4607 Bugs: ProtocolBugs{
4608 NegotiateEMSAtAllVersions: true,
4609 },
4610 },
4611 shouldFail: true,
4612 expectedError: ":ERROR_PARSING_EXTENSION:",
4613 })
4614 testCases = append(testCases, testCase{
4615 name: "RenegotiationInfo-Forbidden-TLS13",
4616 config: Config{
4617 MaxVersion: VersionTLS13,
4618 Bugs: ProtocolBugs{
4619 NegotiateRenegotiationInfoAtAllVersions: true,
4620 },
4621 },
4622 shouldFail: true,
4623 expectedError: ":ERROR_PARSING_EXTENSION:",
4624 })
4625 testCases = append(testCases, testCase{
4626 name: "ChannelID-Forbidden-TLS13",
4627 config: Config{
4628 MaxVersion: VersionTLS13,
4629 RequestChannelID: true,
4630 Bugs: ProtocolBugs{
4631 NegotiateChannelIDAtAllVersions: true,
4632 },
4633 },
4634 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4635 shouldFail: true,
4636 expectedError: ":ERROR_PARSING_EXTENSION:",
4637 })
4638 testCases = append(testCases, testCase{
4639 name: "Ticket-Forbidden-TLS13",
4640 config: Config{
4641 MaxVersion: VersionTLS12,
4642 },
4643 resumeConfig: &Config{
4644 MaxVersion: VersionTLS13,
4645 Bugs: ProtocolBugs{
4646 AdvertiseTicketExtension: true,
4647 },
4648 },
4649 resumeSession: true,
4650 shouldFail: true,
4651 expectedError: ":ERROR_PARSING_EXTENSION:",
4652 })
4653
4654 // Test that illegal extensions in TLS 1.3 are declined by the server if
4655 // offered in ClientHello. The runner's server will fail if this occurs,
4656 // so we exercise the offering path. (EMS and Renegotiation Info are
4657 // implicit in every test.)
4658 testCases = append(testCases, testCase{
4659 testType: serverTest,
4660 name: "ChannelID-Declined-TLS13",
4661 config: Config{
4662 MaxVersion: VersionTLS13,
4663 ChannelID: channelIDKey,
4664 },
4665 flags: []string{"-enable-channel-id"},
4666 })
4667 testCases = append(testCases, testCase{
4668 testType: serverTest,
4669 name: "NPN-Server",
4670 config: Config{
4671 MaxVersion: VersionTLS13,
4672 NextProtos: []string{"bar"},
4673 },
4674 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4675 })
David Benjamine78bfde2014-09-06 12:45:15 -04004676}
4677
David Benjamin01fe8202014-09-24 15:21:44 -04004678func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004679 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004680 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4681 if sessionVers.version >= VersionTLS13 {
4682 continue
4683 }
David Benjamin01fe8202014-09-24 15:21:44 -04004684 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004685 if resumeVers.version >= VersionTLS13 {
4686 continue
4687 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4689 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4690 // TLS 1.3 only shares ciphers with TLS 1.2, so
4691 // we skip certain combinations and use a
4692 // different cipher to test with.
4693 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4694 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4695 continue
4696 }
4697 }
4698
David Benjamin8b8c0062014-11-23 02:47:52 -05004699 protocols := []protocol{tls}
4700 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4701 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004702 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004703 for _, protocol := range protocols {
4704 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4705 if protocol == dtls {
4706 suffix += "-DTLS"
4707 }
4708
David Benjaminece3de92015-03-16 18:02:20 -04004709 if sessionVers.version == resumeVers.version {
4710 testCases = append(testCases, testCase{
4711 protocol: protocol,
4712 name: "Resume-Client" + suffix,
4713 resumeSession: true,
4714 config: Config{
4715 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004716 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004717 },
David Benjaminece3de92015-03-16 18:02:20 -04004718 expectedVersion: sessionVers.version,
4719 expectedResumeVersion: resumeVers.version,
4720 })
4721 } else {
4722 testCases = append(testCases, testCase{
4723 protocol: protocol,
4724 name: "Resume-Client-Mismatch" + suffix,
4725 resumeSession: true,
4726 config: Config{
4727 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004728 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004729 },
David Benjaminece3de92015-03-16 18:02:20 -04004730 expectedVersion: sessionVers.version,
4731 resumeConfig: &Config{
4732 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004733 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004734 Bugs: ProtocolBugs{
4735 AllowSessionVersionMismatch: true,
4736 },
4737 },
4738 expectedResumeVersion: resumeVers.version,
4739 shouldFail: true,
4740 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4741 })
4742 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004743
4744 testCases = append(testCases, testCase{
4745 protocol: protocol,
4746 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004747 resumeSession: true,
4748 config: Config{
4749 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004750 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004751 },
4752 expectedVersion: sessionVers.version,
4753 resumeConfig: &Config{
4754 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004755 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004756 },
4757 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004758 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004759 expectedResumeVersion: resumeVers.version,
4760 })
4761
David Benjamin8b8c0062014-11-23 02:47:52 -05004762 testCases = append(testCases, testCase{
4763 protocol: protocol,
4764 testType: serverTest,
4765 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004766 resumeSession: true,
4767 config: Config{
4768 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004769 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004770 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004771 expectedVersion: sessionVers.version,
4772 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004773 resumeConfig: &Config{
4774 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004775 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004776 },
4777 expectedResumeVersion: resumeVers.version,
4778 })
4779 }
David Benjamin01fe8202014-09-24 15:21:44 -04004780 }
4781 }
David Benjaminece3de92015-03-16 18:02:20 -04004782
Nick Harper1fd39d82016-06-14 18:14:35 -07004783 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004784 testCases = append(testCases, testCase{
4785 name: "Resume-Client-CipherMismatch",
4786 resumeSession: true,
4787 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004788 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004789 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4790 },
4791 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004792 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004793 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4794 Bugs: ProtocolBugs{
4795 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4796 },
4797 },
4798 shouldFail: true,
4799 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4800 })
David Benjamin01fe8202014-09-24 15:21:44 -04004801}
4802
Adam Langley2ae77d22014-10-28 17:29:33 -07004803func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004804 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004805 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004806 testType: serverTest,
4807 name: "Renegotiate-Server-Forbidden",
4808 config: Config{
4809 MaxVersion: VersionTLS12,
4810 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004811 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004812 shouldFail: true,
4813 expectedError: ":NO_RENEGOTIATION:",
4814 expectedLocalError: "remote error: no renegotiation",
4815 })
Adam Langley5021b222015-06-12 18:27:58 -07004816 // The server shouldn't echo the renegotiation extension unless
4817 // requested by the client.
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
4820 name: "Renegotiate-Server-NoExt",
4821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004822 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004823 Bugs: ProtocolBugs{
4824 NoRenegotiationInfo: true,
4825 RequireRenegotiationInfo: true,
4826 },
4827 },
4828 shouldFail: true,
4829 expectedLocalError: "renegotiation extension missing",
4830 })
4831 // The renegotiation SCSV should be sufficient for the server to echo
4832 // the extension.
4833 testCases = append(testCases, testCase{
4834 testType: serverTest,
4835 name: "Renegotiate-Server-NoExt-SCSV",
4836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004837 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004838 Bugs: ProtocolBugs{
4839 NoRenegotiationInfo: true,
4840 SendRenegotiationSCSV: true,
4841 RequireRenegotiationInfo: true,
4842 },
4843 },
4844 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004845 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004846 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004848 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004849 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004850 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004851 },
4852 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004853 renegotiate: 1,
4854 flags: []string{
4855 "-renegotiate-freely",
4856 "-expect-total-renegotiations", "1",
4857 },
David Benjamincdea40c2015-03-19 14:09:43 -04004858 })
4859 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004860 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004861 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004863 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004864 Bugs: ProtocolBugs{
4865 EmptyRenegotiationInfo: true,
4866 },
4867 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004868 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004869 shouldFail: true,
4870 expectedError: ":RENEGOTIATION_MISMATCH:",
4871 })
4872 testCases = append(testCases, testCase{
4873 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004874 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004876 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004877 Bugs: ProtocolBugs{
4878 BadRenegotiationInfo: true,
4879 },
4880 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004881 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004882 shouldFail: true,
4883 expectedError: ":RENEGOTIATION_MISMATCH:",
4884 })
4885 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004886 name: "Renegotiate-Client-Downgrade",
4887 renegotiate: 1,
4888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004889 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004890 Bugs: ProtocolBugs{
4891 NoRenegotiationInfoAfterInitial: true,
4892 },
4893 },
4894 flags: []string{"-renegotiate-freely"},
4895 shouldFail: true,
4896 expectedError: ":RENEGOTIATION_MISMATCH:",
4897 })
4898 testCases = append(testCases, testCase{
4899 name: "Renegotiate-Client-Upgrade",
4900 renegotiate: 1,
4901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004902 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004903 Bugs: ProtocolBugs{
4904 NoRenegotiationInfoInInitial: true,
4905 },
4906 },
4907 flags: []string{"-renegotiate-freely"},
4908 shouldFail: true,
4909 expectedError: ":RENEGOTIATION_MISMATCH:",
4910 })
4911 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004912 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004913 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004915 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004916 Bugs: ProtocolBugs{
4917 NoRenegotiationInfo: true,
4918 },
4919 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004920 flags: []string{
4921 "-renegotiate-freely",
4922 "-expect-total-renegotiations", "1",
4923 },
David Benjamincff0b902015-05-15 23:09:47 -04004924 })
4925 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004926 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004927 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004929 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004930 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4931 },
4932 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004933 flags: []string{
4934 "-renegotiate-freely",
4935 "-expect-total-renegotiations", "1",
4936 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004937 })
4938 testCases = append(testCases, testCase{
4939 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004940 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004942 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4944 },
4945 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004946 flags: []string{
4947 "-renegotiate-freely",
4948 "-expect-total-renegotiations", "1",
4949 },
David Benjaminb16346b2015-04-08 19:16:58 -04004950 })
4951 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004952 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004953 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004954 config: Config{
4955 MaxVersion: VersionTLS10,
4956 Bugs: ProtocolBugs{
4957 RequireSameRenegoClientVersion: true,
4958 },
4959 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004960 flags: []string{
4961 "-renegotiate-freely",
4962 "-expect-total-renegotiations", "1",
4963 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004964 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004965 testCases = append(testCases, testCase{
4966 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004967 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004968 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004969 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004970 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4971 NextProtos: []string{"foo"},
4972 },
4973 flags: []string{
4974 "-false-start",
4975 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004976 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004977 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004978 },
4979 shimWritesFirst: true,
4980 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004981
4982 // Client-side renegotiation controls.
4983 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004984 name: "Renegotiate-Client-Forbidden-1",
4985 config: Config{
4986 MaxVersion: VersionTLS12,
4987 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004988 renegotiate: 1,
4989 shouldFail: true,
4990 expectedError: ":NO_RENEGOTIATION:",
4991 expectedLocalError: "remote error: no renegotiation",
4992 })
4993 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004994 name: "Renegotiate-Client-Once-1",
4995 config: Config{
4996 MaxVersion: VersionTLS12,
4997 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004998 renegotiate: 1,
4999 flags: []string{
5000 "-renegotiate-once",
5001 "-expect-total-renegotiations", "1",
5002 },
5003 })
5004 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005005 name: "Renegotiate-Client-Freely-1",
5006 config: Config{
5007 MaxVersion: VersionTLS12,
5008 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005009 renegotiate: 1,
5010 flags: []string{
5011 "-renegotiate-freely",
5012 "-expect-total-renegotiations", "1",
5013 },
5014 })
5015 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005016 name: "Renegotiate-Client-Once-2",
5017 config: Config{
5018 MaxVersion: VersionTLS12,
5019 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005020 renegotiate: 2,
5021 flags: []string{"-renegotiate-once"},
5022 shouldFail: true,
5023 expectedError: ":NO_RENEGOTIATION:",
5024 expectedLocalError: "remote error: no renegotiation",
5025 })
5026 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005027 name: "Renegotiate-Client-Freely-2",
5028 config: Config{
5029 MaxVersion: VersionTLS12,
5030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005031 renegotiate: 2,
5032 flags: []string{
5033 "-renegotiate-freely",
5034 "-expect-total-renegotiations", "2",
5035 },
5036 })
Adam Langley27a0d082015-11-03 13:34:10 -08005037 testCases = append(testCases, testCase{
5038 name: "Renegotiate-Client-NoIgnore",
5039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005040 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005041 Bugs: ProtocolBugs{
5042 SendHelloRequestBeforeEveryAppDataRecord: true,
5043 },
5044 },
5045 shouldFail: true,
5046 expectedError: ":NO_RENEGOTIATION:",
5047 })
5048 testCases = append(testCases, testCase{
5049 name: "Renegotiate-Client-Ignore",
5050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005051 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005052 Bugs: ProtocolBugs{
5053 SendHelloRequestBeforeEveryAppDataRecord: true,
5054 },
5055 },
5056 flags: []string{
5057 "-renegotiate-ignore",
5058 "-expect-total-renegotiations", "0",
5059 },
5060 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061
David Benjamin397c8e62016-07-08 14:14:36 -07005062 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005063 testCases = append(testCases, testCase{
5064 name: "StrayHelloRequest",
5065 config: Config{
5066 MaxVersion: VersionTLS12,
5067 Bugs: ProtocolBugs{
5068 SendHelloRequestBeforeEveryHandshakeMessage: true,
5069 },
5070 },
5071 })
5072 testCases = append(testCases, testCase{
5073 name: "StrayHelloRequest-Packed",
5074 config: Config{
5075 MaxVersion: VersionTLS12,
5076 Bugs: ProtocolBugs{
5077 PackHandshakeFlight: true,
5078 SendHelloRequestBeforeEveryHandshakeMessage: true,
5079 },
5080 },
5081 })
5082
David Benjamin12d2c482016-07-24 10:56:51 -04005083 // Test renegotiation works if HelloRequest and server Finished come in
5084 // the same record.
5085 testCases = append(testCases, testCase{
5086 name: "Renegotiate-Client-Packed",
5087 config: Config{
5088 MaxVersion: VersionTLS12,
5089 Bugs: ProtocolBugs{
5090 PackHandshakeFlight: true,
5091 PackHelloRequestWithFinished: true,
5092 },
5093 },
5094 renegotiate: 1,
5095 flags: []string{
5096 "-renegotiate-freely",
5097 "-expect-total-renegotiations", "1",
5098 },
5099 })
5100
David Benjamin397c8e62016-07-08 14:14:36 -07005101 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04005102 //
5103 // TODO(davidben): This test current asserts that we ignore
5104 // HelloRequests, but we actually should hard reject them. Fix this
5105 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07005106 testCases = append(testCases, testCase{
5107 name: "Renegotiate-Client-TLS13",
5108 config: Config{
5109 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005110 Bugs: ProtocolBugs{
5111 SendHelloRequestBeforeEveryAppDataRecord: true,
5112 },
David Benjamin397c8e62016-07-08 14:14:36 -07005113 },
David Benjamin397c8e62016-07-08 14:14:36 -07005114 flags: []string{
5115 "-renegotiate-freely",
5116 },
David Benjamin397c8e62016-07-08 14:14:36 -07005117 })
5118
5119 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5120 testCases = append(testCases, testCase{
5121 name: "StrayHelloRequest-TLS13",
5122 config: Config{
5123 MaxVersion: VersionTLS13,
5124 Bugs: ProtocolBugs{
5125 SendHelloRequestBeforeEveryHandshakeMessage: true,
5126 },
5127 },
5128 shouldFail: true,
5129 expectedError: ":UNEXPECTED_MESSAGE:",
5130 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005131}
5132
David Benjamin5e961c12014-11-07 01:48:35 -05005133func addDTLSReplayTests() {
5134 // Test that sequence number replays are detected.
5135 testCases = append(testCases, testCase{
5136 protocol: dtls,
5137 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005138 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005139 replayWrites: true,
5140 })
5141
David Benjamin8e6db492015-07-25 18:29:23 -04005142 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005143 // than the retransmit window.
5144 testCases = append(testCases, testCase{
5145 protocol: dtls,
5146 name: "DTLS-Replay-LargeGaps",
5147 config: Config{
5148 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005149 SequenceNumberMapping: func(in uint64) uint64 {
5150 return in * 127
5151 },
David Benjamin5e961c12014-11-07 01:48:35 -05005152 },
5153 },
David Benjamin8e6db492015-07-25 18:29:23 -04005154 messageCount: 200,
5155 replayWrites: true,
5156 })
5157
5158 // Test the incoming sequence number changing non-monotonically.
5159 testCases = append(testCases, testCase{
5160 protocol: dtls,
5161 name: "DTLS-Replay-NonMonotonic",
5162 config: Config{
5163 Bugs: ProtocolBugs{
5164 SequenceNumberMapping: func(in uint64) uint64 {
5165 return in ^ 31
5166 },
5167 },
5168 },
5169 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005170 replayWrites: true,
5171 })
5172}
5173
Nick Harper60edffd2016-06-21 15:19:24 -07005174var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005175 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005176 id signatureAlgorithm
5177 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005178}{
Nick Harper60edffd2016-06-21 15:19:24 -07005179 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5180 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5181 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5182 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005183 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005184 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5185 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5186 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005187 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5188 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5189 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005190 // Tests for key types prior to TLS 1.2.
5191 {"RSA", 0, testCertRSA},
5192 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005193}
5194
Nick Harper60edffd2016-06-21 15:19:24 -07005195const fakeSigAlg1 signatureAlgorithm = 0x2a01
5196const fakeSigAlg2 signatureAlgorithm = 0xff01
5197
5198func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005199 // Not all ciphers involve a signature. Advertise a list which gives all
5200 // versions a signing cipher.
5201 signingCiphers := []uint16{
5202 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5203 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5204 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5205 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5206 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5207 }
5208
David Benjaminca3d5452016-07-14 12:51:01 -04005209 var allAlgorithms []signatureAlgorithm
5210 for _, alg := range testSignatureAlgorithms {
5211 if alg.id != 0 {
5212 allAlgorithms = append(allAlgorithms, alg.id)
5213 }
5214 }
5215
Nick Harper60edffd2016-06-21 15:19:24 -07005216 // Make sure each signature algorithm works. Include some fake values in
5217 // the list and ensure they're ignored.
5218 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005219 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005220 if (ver.version < VersionTLS12) != (alg.id == 0) {
5221 continue
5222 }
5223
5224 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5225 // or remove it in C.
5226 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005227 continue
5228 }
Nick Harper60edffd2016-06-21 15:19:24 -07005229
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005230 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005231 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005232 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5233 shouldFail = true
5234 }
5235 // RSA-PSS does not exist in TLS 1.2.
5236 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5237 shouldFail = true
5238 }
5239
5240 var signError, verifyError string
5241 if shouldFail {
5242 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5243 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005244 }
David Benjamin000800a2014-11-14 01:43:59 -05005245
David Benjamin1fb125c2016-07-08 18:52:12 -07005246 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005247
David Benjamin7a41d372016-07-09 11:21:54 -07005248 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005249 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005250 config: Config{
5251 MaxVersion: ver.version,
5252 ClientAuth: RequireAnyClientCert,
5253 VerifySignatureAlgorithms: []signatureAlgorithm{
5254 fakeSigAlg1,
5255 alg.id,
5256 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005257 },
David Benjamin7a41d372016-07-09 11:21:54 -07005258 },
5259 flags: []string{
5260 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5261 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5262 "-enable-all-curves",
5263 },
5264 shouldFail: shouldFail,
5265 expectedError: signError,
5266 expectedPeerSignatureAlgorithm: alg.id,
5267 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005268
David Benjamin7a41d372016-07-09 11:21:54 -07005269 testCases = append(testCases, testCase{
5270 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005271 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005272 config: Config{
5273 MaxVersion: ver.version,
5274 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5275 SignSignatureAlgorithms: []signatureAlgorithm{
5276 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005277 },
David Benjamin7a41d372016-07-09 11:21:54 -07005278 Bugs: ProtocolBugs{
5279 SkipECDSACurveCheck: shouldFail,
5280 IgnoreSignatureVersionChecks: shouldFail,
5281 // The client won't advertise 1.3-only algorithms after
5282 // version negotiation.
5283 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005284 },
David Benjamin7a41d372016-07-09 11:21:54 -07005285 },
5286 flags: []string{
5287 "-require-any-client-certificate",
5288 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5289 "-enable-all-curves",
5290 },
5291 shouldFail: shouldFail,
5292 expectedError: verifyError,
5293 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005294
5295 testCases = append(testCases, testCase{
5296 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005297 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005298 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005299 MaxVersion: ver.version,
5300 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005301 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005302 fakeSigAlg1,
5303 alg.id,
5304 fakeSigAlg2,
5305 },
5306 },
5307 flags: []string{
5308 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5309 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5310 "-enable-all-curves",
5311 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005312 shouldFail: shouldFail,
5313 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005314 expectedPeerSignatureAlgorithm: alg.id,
5315 })
5316
5317 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005318 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005319 config: Config{
5320 MaxVersion: ver.version,
5321 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005322 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005323 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005324 alg.id,
5325 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005326 Bugs: ProtocolBugs{
5327 SkipECDSACurveCheck: shouldFail,
5328 IgnoreSignatureVersionChecks: shouldFail,
5329 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005330 },
5331 flags: []string{
5332 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5333 "-enable-all-curves",
5334 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005335 shouldFail: shouldFail,
5336 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005337 })
David Benjamin5208fd42016-07-13 21:43:25 -04005338
5339 if !shouldFail {
5340 testCases = append(testCases, testCase{
5341 testType: serverTest,
5342 name: "ClientAuth-InvalidSignature" + suffix,
5343 config: Config{
5344 MaxVersion: ver.version,
5345 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5346 SignSignatureAlgorithms: []signatureAlgorithm{
5347 alg.id,
5348 },
5349 Bugs: ProtocolBugs{
5350 InvalidSignature: true,
5351 },
5352 },
5353 flags: []string{
5354 "-require-any-client-certificate",
5355 "-enable-all-curves",
5356 },
5357 shouldFail: true,
5358 expectedError: ":BAD_SIGNATURE:",
5359 })
5360
5361 testCases = append(testCases, testCase{
5362 name: "ServerAuth-InvalidSignature" + suffix,
5363 config: Config{
5364 MaxVersion: ver.version,
5365 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5366 CipherSuites: signingCiphers,
5367 SignSignatureAlgorithms: []signatureAlgorithm{
5368 alg.id,
5369 },
5370 Bugs: ProtocolBugs{
5371 InvalidSignature: true,
5372 },
5373 },
5374 flags: []string{"-enable-all-curves"},
5375 shouldFail: true,
5376 expectedError: ":BAD_SIGNATURE:",
5377 })
5378 }
David Benjaminca3d5452016-07-14 12:51:01 -04005379
5380 if ver.version >= VersionTLS12 && !shouldFail {
5381 testCases = append(testCases, testCase{
5382 name: "ClientAuth-Sign-Negotiate" + suffix,
5383 config: Config{
5384 MaxVersion: ver.version,
5385 ClientAuth: RequireAnyClientCert,
5386 VerifySignatureAlgorithms: allAlgorithms,
5387 },
5388 flags: []string{
5389 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5390 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5391 "-enable-all-curves",
5392 "-signing-prefs", strconv.Itoa(int(alg.id)),
5393 },
5394 expectedPeerSignatureAlgorithm: alg.id,
5395 })
5396
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
5399 name: "ServerAuth-Sign-Negotiate" + suffix,
5400 config: Config{
5401 MaxVersion: ver.version,
5402 CipherSuites: signingCiphers,
5403 VerifySignatureAlgorithms: allAlgorithms,
5404 },
5405 flags: []string{
5406 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5407 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5408 "-enable-all-curves",
5409 "-signing-prefs", strconv.Itoa(int(alg.id)),
5410 },
5411 expectedPeerSignatureAlgorithm: alg.id,
5412 })
5413 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005414 }
David Benjamin000800a2014-11-14 01:43:59 -05005415 }
5416
Nick Harper60edffd2016-06-21 15:19:24 -07005417 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005418 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005419 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005420 config: Config{
5421 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005422 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005423 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005424 signatureECDSAWithP521AndSHA512,
5425 signatureRSAPKCS1WithSHA384,
5426 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005427 },
5428 },
5429 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005430 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5431 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005432 },
Nick Harper60edffd2016-06-21 15:19:24 -07005433 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005434 })
5435
5436 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005437 name: "ClientAuth-SignatureType-TLS13",
5438 config: Config{
5439 ClientAuth: RequireAnyClientCert,
5440 MaxVersion: VersionTLS13,
5441 VerifySignatureAlgorithms: []signatureAlgorithm{
5442 signatureECDSAWithP521AndSHA512,
5443 signatureRSAPKCS1WithSHA384,
5444 signatureRSAPSSWithSHA384,
5445 signatureECDSAWithSHA1,
5446 },
5447 },
5448 flags: []string{
5449 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5450 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5451 },
5452 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5453 })
5454
5455 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005456 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005457 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005459 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005461 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005462 signatureECDSAWithP521AndSHA512,
5463 signatureRSAPKCS1WithSHA384,
5464 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005465 },
5466 },
Nick Harper60edffd2016-06-21 15:19:24 -07005467 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005468 })
5469
Steven Valdez143e8b32016-07-11 13:19:03 -04005470 testCases = append(testCases, testCase{
5471 testType: serverTest,
5472 name: "ServerAuth-SignatureType-TLS13",
5473 config: Config{
5474 MaxVersion: VersionTLS13,
5475 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5476 VerifySignatureAlgorithms: []signatureAlgorithm{
5477 signatureECDSAWithP521AndSHA512,
5478 signatureRSAPKCS1WithSHA384,
5479 signatureRSAPSSWithSHA384,
5480 signatureECDSAWithSHA1,
5481 },
5482 },
5483 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5484 })
5485
David Benjamina95e9f32016-07-08 16:28:04 -07005486 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005487 testCases = append(testCases, testCase{
5488 testType: serverTest,
5489 name: "Verify-ClientAuth-SignatureType",
5490 config: Config{
5491 MaxVersion: VersionTLS12,
5492 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005493 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005494 signatureRSAPKCS1WithSHA256,
5495 },
5496 Bugs: ProtocolBugs{
5497 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5498 },
5499 },
5500 flags: []string{
5501 "-require-any-client-certificate",
5502 },
5503 shouldFail: true,
5504 expectedError: ":WRONG_SIGNATURE_TYPE:",
5505 })
5506
5507 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005508 testType: serverTest,
5509 name: "Verify-ClientAuth-SignatureType-TLS13",
5510 config: Config{
5511 MaxVersion: VersionTLS13,
5512 Certificates: []Certificate{rsaCertificate},
5513 SignSignatureAlgorithms: []signatureAlgorithm{
5514 signatureRSAPSSWithSHA256,
5515 },
5516 Bugs: ProtocolBugs{
5517 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5518 },
5519 },
5520 flags: []string{
5521 "-require-any-client-certificate",
5522 },
5523 shouldFail: true,
5524 expectedError: ":WRONG_SIGNATURE_TYPE:",
5525 })
5526
5527 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005528 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005529 config: Config{
5530 MaxVersion: VersionTLS12,
5531 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005532 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005533 signatureRSAPKCS1WithSHA256,
5534 },
5535 Bugs: ProtocolBugs{
5536 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5537 },
5538 },
5539 shouldFail: true,
5540 expectedError: ":WRONG_SIGNATURE_TYPE:",
5541 })
5542
Steven Valdez143e8b32016-07-11 13:19:03 -04005543 testCases = append(testCases, testCase{
5544 name: "Verify-ServerAuth-SignatureType-TLS13",
5545 config: Config{
5546 MaxVersion: VersionTLS13,
5547 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5548 SignSignatureAlgorithms: []signatureAlgorithm{
5549 signatureRSAPSSWithSHA256,
5550 },
5551 Bugs: ProtocolBugs{
5552 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5553 },
5554 },
5555 shouldFail: true,
5556 expectedError: ":WRONG_SIGNATURE_TYPE:",
5557 })
5558
David Benjamin51dd7d62016-07-08 16:07:01 -07005559 // Test that, if the list is missing, the peer falls back to SHA-1 in
5560 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005561 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005562 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005563 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005564 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005565 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005566 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005567 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005568 },
5569 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005570 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005571 },
5572 },
5573 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005574 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5575 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005576 },
5577 })
5578
5579 testCases = append(testCases, testCase{
5580 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005581 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005583 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005584 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005585 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005586 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005587 },
5588 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005589 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005590 },
5591 },
5592 })
David Benjamin72dc7832015-03-16 17:49:43 -04005593
David Benjamin51dd7d62016-07-08 16:07:01 -07005594 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005595 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005596 config: Config{
5597 MaxVersion: VersionTLS13,
5598 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005599 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005600 signatureRSAPKCS1WithSHA1,
5601 },
5602 Bugs: ProtocolBugs{
5603 NoSignatureAlgorithms: true,
5604 },
5605 },
5606 flags: []string{
5607 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5608 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5609 },
5610 shouldFail: true,
5611 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5612 })
5613
5614 testCases = append(testCases, testCase{
5615 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005616 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005617 config: Config{
5618 MaxVersion: VersionTLS13,
5619 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005620 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005621 signatureRSAPKCS1WithSHA1,
5622 },
5623 Bugs: ProtocolBugs{
5624 NoSignatureAlgorithms: true,
5625 },
5626 },
5627 shouldFail: true,
5628 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5629 })
5630
David Benjaminb62d2872016-07-18 14:55:02 +02005631 // Test that hash preferences are enforced. BoringSSL does not implement
5632 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005633 testCases = append(testCases, testCase{
5634 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005635 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005636 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005637 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005638 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005639 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005640 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005641 },
5642 Bugs: ProtocolBugs{
5643 IgnorePeerSignatureAlgorithmPreferences: true,
5644 },
5645 },
5646 flags: []string{"-require-any-client-certificate"},
5647 shouldFail: true,
5648 expectedError: ":WRONG_SIGNATURE_TYPE:",
5649 })
5650
5651 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005652 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005653 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005654 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005656 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005657 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005658 },
5659 Bugs: ProtocolBugs{
5660 IgnorePeerSignatureAlgorithmPreferences: true,
5661 },
5662 },
5663 shouldFail: true,
5664 expectedError: ":WRONG_SIGNATURE_TYPE:",
5665 })
David Benjaminb62d2872016-07-18 14:55:02 +02005666 testCases = append(testCases, testCase{
5667 testType: serverTest,
5668 name: "ClientAuth-Enforced-TLS13",
5669 config: Config{
5670 MaxVersion: VersionTLS13,
5671 Certificates: []Certificate{rsaCertificate},
5672 SignSignatureAlgorithms: []signatureAlgorithm{
5673 signatureRSAPKCS1WithMD5,
5674 },
5675 Bugs: ProtocolBugs{
5676 IgnorePeerSignatureAlgorithmPreferences: true,
5677 IgnoreSignatureVersionChecks: true,
5678 },
5679 },
5680 flags: []string{"-require-any-client-certificate"},
5681 shouldFail: true,
5682 expectedError: ":WRONG_SIGNATURE_TYPE:",
5683 })
5684
5685 testCases = append(testCases, testCase{
5686 name: "ServerAuth-Enforced-TLS13",
5687 config: Config{
5688 MaxVersion: VersionTLS13,
5689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5690 SignSignatureAlgorithms: []signatureAlgorithm{
5691 signatureRSAPKCS1WithMD5,
5692 },
5693 Bugs: ProtocolBugs{
5694 IgnorePeerSignatureAlgorithmPreferences: true,
5695 IgnoreSignatureVersionChecks: true,
5696 },
5697 },
5698 shouldFail: true,
5699 expectedError: ":WRONG_SIGNATURE_TYPE:",
5700 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005701
5702 // Test that the agreed upon digest respects the client preferences and
5703 // the server digests.
5704 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005705 name: "NoCommonAlgorithms-Digests",
5706 config: Config{
5707 MaxVersion: VersionTLS12,
5708 ClientAuth: RequireAnyClientCert,
5709 VerifySignatureAlgorithms: []signatureAlgorithm{
5710 signatureRSAPKCS1WithSHA512,
5711 signatureRSAPKCS1WithSHA1,
5712 },
5713 },
5714 flags: []string{
5715 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5716 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5717 "-digest-prefs", "SHA256",
5718 },
5719 shouldFail: true,
5720 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5721 })
5722 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005723 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005725 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005726 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005727 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005728 signatureRSAPKCS1WithSHA512,
5729 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005730 },
5731 },
5732 flags: []string{
5733 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5734 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005735 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005736 },
David Benjaminca3d5452016-07-14 12:51:01 -04005737 shouldFail: true,
5738 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5739 })
5740 testCases = append(testCases, testCase{
5741 name: "NoCommonAlgorithms-TLS13",
5742 config: Config{
5743 MaxVersion: VersionTLS13,
5744 ClientAuth: RequireAnyClientCert,
5745 VerifySignatureAlgorithms: []signatureAlgorithm{
5746 signatureRSAPSSWithSHA512,
5747 signatureRSAPSSWithSHA384,
5748 },
5749 },
5750 flags: []string{
5751 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5752 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5753 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5754 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005755 shouldFail: true,
5756 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005757 })
5758 testCases = append(testCases, testCase{
5759 name: "Agree-Digest-SHA256",
5760 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005761 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005762 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005763 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005764 signatureRSAPKCS1WithSHA1,
5765 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005766 },
5767 },
5768 flags: []string{
5769 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5770 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005771 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005772 },
Nick Harper60edffd2016-06-21 15:19:24 -07005773 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005774 })
5775 testCases = append(testCases, testCase{
5776 name: "Agree-Digest-SHA1",
5777 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005778 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005779 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005780 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005781 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005782 },
5783 },
5784 flags: []string{
5785 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5786 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005787 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005788 },
Nick Harper60edffd2016-06-21 15:19:24 -07005789 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005790 })
5791 testCases = append(testCases, testCase{
5792 name: "Agree-Digest-Default",
5793 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005794 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005795 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005796 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005797 signatureRSAPKCS1WithSHA256,
5798 signatureECDSAWithP256AndSHA256,
5799 signatureRSAPKCS1WithSHA1,
5800 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005801 },
5802 },
5803 flags: []string{
5804 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5805 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5806 },
Nick Harper60edffd2016-06-21 15:19:24 -07005807 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005808 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005809
David Benjaminca3d5452016-07-14 12:51:01 -04005810 // Test that the signing preference list may include extra algorithms
5811 // without negotiation problems.
5812 testCases = append(testCases, testCase{
5813 testType: serverTest,
5814 name: "FilterExtraAlgorithms",
5815 config: Config{
5816 MaxVersion: VersionTLS12,
5817 VerifySignatureAlgorithms: []signatureAlgorithm{
5818 signatureRSAPKCS1WithSHA256,
5819 },
5820 },
5821 flags: []string{
5822 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5823 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5824 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5825 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5826 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5827 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5828 },
5829 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5830 })
5831
David Benjamin4c3ddf72016-06-29 18:13:53 -04005832 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5833 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005834 testCases = append(testCases, testCase{
5835 name: "CheckLeafCurve",
5836 config: Config{
5837 MaxVersion: VersionTLS12,
5838 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005839 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005840 },
5841 flags: []string{"-p384-only"},
5842 shouldFail: true,
5843 expectedError: ":BAD_ECC_CERT:",
5844 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005845
5846 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5847 testCases = append(testCases, testCase{
5848 name: "CheckLeafCurve-TLS13",
5849 config: Config{
5850 MaxVersion: VersionTLS13,
5851 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5852 Certificates: []Certificate{ecdsaP256Certificate},
5853 },
5854 flags: []string{"-p384-only"},
5855 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005856
5857 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5858 testCases = append(testCases, testCase{
5859 name: "ECDSACurveMismatch-Verify-TLS12",
5860 config: Config{
5861 MaxVersion: VersionTLS12,
5862 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5863 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005864 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005865 signatureECDSAWithP384AndSHA384,
5866 },
5867 },
5868 })
5869
5870 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5871 testCases = append(testCases, testCase{
5872 name: "ECDSACurveMismatch-Verify-TLS13",
5873 config: Config{
5874 MaxVersion: VersionTLS13,
5875 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5876 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005877 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005878 signatureECDSAWithP384AndSHA384,
5879 },
5880 Bugs: ProtocolBugs{
5881 SkipECDSACurveCheck: true,
5882 },
5883 },
5884 shouldFail: true,
5885 expectedError: ":WRONG_SIGNATURE_TYPE:",
5886 })
5887
5888 // Signature algorithm selection in TLS 1.3 should take the curve into
5889 // account.
5890 testCases = append(testCases, testCase{
5891 testType: serverTest,
5892 name: "ECDSACurveMismatch-Sign-TLS13",
5893 config: Config{
5894 MaxVersion: VersionTLS13,
5895 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005896 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005897 signatureECDSAWithP384AndSHA384,
5898 signatureECDSAWithP256AndSHA256,
5899 },
5900 },
5901 flags: []string{
5902 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5903 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5904 },
5905 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5906 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005907
5908 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5909 // server does not attempt to sign in that case.
5910 testCases = append(testCases, testCase{
5911 testType: serverTest,
5912 name: "RSA-PSS-Large",
5913 config: Config{
5914 MaxVersion: VersionTLS13,
5915 VerifySignatureAlgorithms: []signatureAlgorithm{
5916 signatureRSAPSSWithSHA512,
5917 },
5918 },
5919 flags: []string{
5920 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5921 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5922 },
5923 shouldFail: true,
5924 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5925 })
David Benjamin000800a2014-11-14 01:43:59 -05005926}
5927
David Benjamin83f90402015-01-27 01:09:43 -05005928// timeouts is the retransmit schedule for BoringSSL. It doubles and
5929// caps at 60 seconds. On the 13th timeout, it gives up.
5930var timeouts = []time.Duration{
5931 1 * time.Second,
5932 2 * time.Second,
5933 4 * time.Second,
5934 8 * time.Second,
5935 16 * time.Second,
5936 32 * time.Second,
5937 60 * time.Second,
5938 60 * time.Second,
5939 60 * time.Second,
5940 60 * time.Second,
5941 60 * time.Second,
5942 60 * time.Second,
5943 60 * time.Second,
5944}
5945
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005946// shortTimeouts is an alternate set of timeouts which would occur if the
5947// initial timeout duration was set to 250ms.
5948var shortTimeouts = []time.Duration{
5949 250 * time.Millisecond,
5950 500 * time.Millisecond,
5951 1 * time.Second,
5952 2 * time.Second,
5953 4 * time.Second,
5954 8 * time.Second,
5955 16 * time.Second,
5956 32 * time.Second,
5957 60 * time.Second,
5958 60 * time.Second,
5959 60 * time.Second,
5960 60 * time.Second,
5961 60 * time.Second,
5962}
5963
David Benjamin83f90402015-01-27 01:09:43 -05005964func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005965 // These tests work by coordinating some behavior on both the shim and
5966 // the runner.
5967 //
5968 // TimeoutSchedule configures the runner to send a series of timeout
5969 // opcodes to the shim (see packetAdaptor) immediately before reading
5970 // each peer handshake flight N. The timeout opcode both simulates a
5971 // timeout in the shim and acts as a synchronization point to help the
5972 // runner bracket each handshake flight.
5973 //
5974 // We assume the shim does not read from the channel eagerly. It must
5975 // first wait until it has sent flight N and is ready to receive
5976 // handshake flight N+1. At this point, it will process the timeout
5977 // opcode. It must then immediately respond with a timeout ACK and act
5978 // as if the shim was idle for the specified amount of time.
5979 //
5980 // The runner then drops all packets received before the ACK and
5981 // continues waiting for flight N. This ordering results in one attempt
5982 // at sending flight N to be dropped. For the test to complete, the
5983 // shim must send flight N again, testing that the shim implements DTLS
5984 // retransmit on a timeout.
5985
Steven Valdez143e8b32016-07-11 13:19:03 -04005986 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005987 // likely be more epochs to cross and the final message's retransmit may
5988 // be more complex.
5989
David Benjamin585d7a42016-06-02 14:58:00 -04005990 for _, async := range []bool{true, false} {
5991 var tests []testCase
5992
5993 // Test that this is indeed the timeout schedule. Stress all
5994 // four patterns of handshake.
5995 for i := 1; i < len(timeouts); i++ {
5996 number := strconv.Itoa(i)
5997 tests = append(tests, testCase{
5998 protocol: dtls,
5999 name: "DTLS-Retransmit-Client-" + number,
6000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006001 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006002 Bugs: ProtocolBugs{
6003 TimeoutSchedule: timeouts[:i],
6004 },
6005 },
6006 resumeSession: true,
6007 })
6008 tests = append(tests, testCase{
6009 protocol: dtls,
6010 testType: serverTest,
6011 name: "DTLS-Retransmit-Server-" + number,
6012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006013 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006014 Bugs: ProtocolBugs{
6015 TimeoutSchedule: timeouts[:i],
6016 },
6017 },
6018 resumeSession: true,
6019 })
6020 }
6021
6022 // Test that exceeding the timeout schedule hits a read
6023 // timeout.
6024 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006025 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006026 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006028 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006029 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006030 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006031 },
6032 },
6033 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006034 shouldFail: true,
6035 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006036 })
David Benjamin585d7a42016-06-02 14:58:00 -04006037
6038 if async {
6039 // Test that timeout handling has a fudge factor, due to API
6040 // problems.
6041 tests = append(tests, testCase{
6042 protocol: dtls,
6043 name: "DTLS-Retransmit-Fudge",
6044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006045 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006046 Bugs: ProtocolBugs{
6047 TimeoutSchedule: []time.Duration{
6048 timeouts[0] - 10*time.Millisecond,
6049 },
6050 },
6051 },
6052 resumeSession: true,
6053 })
6054 }
6055
6056 // Test that the final Finished retransmitting isn't
6057 // duplicated if the peer badly fragments everything.
6058 tests = append(tests, testCase{
6059 testType: serverTest,
6060 protocol: dtls,
6061 name: "DTLS-Retransmit-Fragmented",
6062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006063 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006064 Bugs: ProtocolBugs{
6065 TimeoutSchedule: []time.Duration{timeouts[0]},
6066 MaxHandshakeRecordLength: 2,
6067 },
6068 },
6069 })
6070
6071 // Test the timeout schedule when a shorter initial timeout duration is set.
6072 tests = append(tests, testCase{
6073 protocol: dtls,
6074 name: "DTLS-Retransmit-Short-Client",
6075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006076 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006077 Bugs: ProtocolBugs{
6078 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6079 },
6080 },
6081 resumeSession: true,
6082 flags: []string{"-initial-timeout-duration-ms", "250"},
6083 })
6084 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006085 protocol: dtls,
6086 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006087 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006089 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006090 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006091 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006092 },
6093 },
6094 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006095 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006096 })
David Benjamin585d7a42016-06-02 14:58:00 -04006097
6098 for _, test := range tests {
6099 if async {
6100 test.name += "-Async"
6101 test.flags = append(test.flags, "-async")
6102 }
6103
6104 testCases = append(testCases, test)
6105 }
David Benjamin83f90402015-01-27 01:09:43 -05006106 }
David Benjamin83f90402015-01-27 01:09:43 -05006107}
6108
David Benjaminc565ebb2015-04-03 04:06:36 -04006109func addExportKeyingMaterialTests() {
6110 for _, vers := range tlsVersions {
6111 if vers.version == VersionSSL30 {
6112 continue
6113 }
6114 testCases = append(testCases, testCase{
6115 name: "ExportKeyingMaterial-" + vers.name,
6116 config: Config{
6117 MaxVersion: vers.version,
6118 },
6119 exportKeyingMaterial: 1024,
6120 exportLabel: "label",
6121 exportContext: "context",
6122 useExportContext: true,
6123 })
6124 testCases = append(testCases, testCase{
6125 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6126 config: Config{
6127 MaxVersion: vers.version,
6128 },
6129 exportKeyingMaterial: 1024,
6130 })
6131 testCases = append(testCases, testCase{
6132 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6133 config: Config{
6134 MaxVersion: vers.version,
6135 },
6136 exportKeyingMaterial: 1024,
6137 useExportContext: true,
6138 })
6139 testCases = append(testCases, testCase{
6140 name: "ExportKeyingMaterial-Small-" + vers.name,
6141 config: Config{
6142 MaxVersion: vers.version,
6143 },
6144 exportKeyingMaterial: 1,
6145 exportLabel: "label",
6146 exportContext: "context",
6147 useExportContext: true,
6148 })
6149 }
6150 testCases = append(testCases, testCase{
6151 name: "ExportKeyingMaterial-SSL3",
6152 config: Config{
6153 MaxVersion: VersionSSL30,
6154 },
6155 exportKeyingMaterial: 1024,
6156 exportLabel: "label",
6157 exportContext: "context",
6158 useExportContext: true,
6159 shouldFail: true,
6160 expectedError: "failed to export keying material",
6161 })
6162}
6163
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006164func addTLSUniqueTests() {
6165 for _, isClient := range []bool{false, true} {
6166 for _, isResumption := range []bool{false, true} {
6167 for _, hasEMS := range []bool{false, true} {
6168 var suffix string
6169 if isResumption {
6170 suffix = "Resume-"
6171 } else {
6172 suffix = "Full-"
6173 }
6174
6175 if hasEMS {
6176 suffix += "EMS-"
6177 } else {
6178 suffix += "NoEMS-"
6179 }
6180
6181 if isClient {
6182 suffix += "Client"
6183 } else {
6184 suffix += "Server"
6185 }
6186
6187 test := testCase{
6188 name: "TLSUnique-" + suffix,
6189 testTLSUnique: true,
6190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006191 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006192 Bugs: ProtocolBugs{
6193 NoExtendedMasterSecret: !hasEMS,
6194 },
6195 },
6196 }
6197
6198 if isResumption {
6199 test.resumeSession = true
6200 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006201 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006202 Bugs: ProtocolBugs{
6203 NoExtendedMasterSecret: !hasEMS,
6204 },
6205 }
6206 }
6207
6208 if isResumption && !hasEMS {
6209 test.shouldFail = true
6210 test.expectedError = "failed to get tls-unique"
6211 }
6212
6213 testCases = append(testCases, test)
6214 }
6215 }
6216 }
6217}
6218
Adam Langley09505632015-07-30 18:10:13 -07006219func addCustomExtensionTests() {
6220 expectedContents := "custom extension"
6221 emptyString := ""
6222
6223 for _, isClient := range []bool{false, true} {
6224 suffix := "Server"
6225 flag := "-enable-server-custom-extension"
6226 testType := serverTest
6227 if isClient {
6228 suffix = "Client"
6229 flag = "-enable-client-custom-extension"
6230 testType = clientTest
6231 }
6232
6233 testCases = append(testCases, testCase{
6234 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006235 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006237 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006238 Bugs: ProtocolBugs{
6239 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006240 ExpectedCustomExtension: &expectedContents,
6241 },
6242 },
6243 flags: []string{flag},
6244 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006245 testCases = append(testCases, testCase{
6246 testType: testType,
6247 name: "CustomExtensions-" + suffix + "-TLS13",
6248 config: Config{
6249 MaxVersion: VersionTLS13,
6250 Bugs: ProtocolBugs{
6251 CustomExtension: expectedContents,
6252 ExpectedCustomExtension: &expectedContents,
6253 },
6254 },
6255 flags: []string{flag},
6256 })
Adam Langley09505632015-07-30 18:10:13 -07006257
6258 // If the parse callback fails, the handshake should also fail.
6259 testCases = append(testCases, testCase{
6260 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006261 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006263 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006264 Bugs: ProtocolBugs{
6265 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006266 ExpectedCustomExtension: &expectedContents,
6267 },
6268 },
David Benjamin399e7c92015-07-30 23:01:27 -04006269 flags: []string{flag},
6270 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006271 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6272 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006273 testCases = append(testCases, testCase{
6274 testType: testType,
6275 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6276 config: Config{
6277 MaxVersion: VersionTLS13,
6278 Bugs: ProtocolBugs{
6279 CustomExtension: expectedContents + "foo",
6280 ExpectedCustomExtension: &expectedContents,
6281 },
6282 },
6283 flags: []string{flag},
6284 shouldFail: true,
6285 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6286 })
Adam Langley09505632015-07-30 18:10:13 -07006287
6288 // If the add callback fails, the handshake should also fail.
6289 testCases = append(testCases, testCase{
6290 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006291 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006293 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006294 Bugs: ProtocolBugs{
6295 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006296 ExpectedCustomExtension: &expectedContents,
6297 },
6298 },
David Benjamin399e7c92015-07-30 23:01:27 -04006299 flags: []string{flag, "-custom-extension-fail-add"},
6300 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006301 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6302 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006303 testCases = append(testCases, testCase{
6304 testType: testType,
6305 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6306 config: Config{
6307 MaxVersion: VersionTLS13,
6308 Bugs: ProtocolBugs{
6309 CustomExtension: expectedContents,
6310 ExpectedCustomExtension: &expectedContents,
6311 },
6312 },
6313 flags: []string{flag, "-custom-extension-fail-add"},
6314 shouldFail: true,
6315 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6316 })
Adam Langley09505632015-07-30 18:10:13 -07006317
6318 // If the add callback returns zero, no extension should be
6319 // added.
6320 skipCustomExtension := expectedContents
6321 if isClient {
6322 // For the case where the client skips sending the
6323 // custom extension, the server must not “echo” it.
6324 skipCustomExtension = ""
6325 }
6326 testCases = append(testCases, testCase{
6327 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006328 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006330 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006331 Bugs: ProtocolBugs{
6332 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006333 ExpectedCustomExtension: &emptyString,
6334 },
6335 },
6336 flags: []string{flag, "-custom-extension-skip"},
6337 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006338 testCases = append(testCases, testCase{
6339 testType: testType,
6340 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 Bugs: ProtocolBugs{
6344 CustomExtension: skipCustomExtension,
6345 ExpectedCustomExtension: &emptyString,
6346 },
6347 },
6348 flags: []string{flag, "-custom-extension-skip"},
6349 })
Adam Langley09505632015-07-30 18:10:13 -07006350 }
6351
6352 // The custom extension add callback should not be called if the client
6353 // doesn't send the extension.
6354 testCases = append(testCases, testCase{
6355 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006356 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006358 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006359 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006360 ExpectedCustomExtension: &emptyString,
6361 },
6362 },
6363 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6364 })
Adam Langley2deb9842015-08-07 11:15:37 -07006365
Steven Valdez143e8b32016-07-11 13:19:03 -04006366 testCases = append(testCases, testCase{
6367 testType: serverTest,
6368 name: "CustomExtensions-NotCalled-Server-TLS13",
6369 config: Config{
6370 MaxVersion: VersionTLS13,
6371 Bugs: ProtocolBugs{
6372 ExpectedCustomExtension: &emptyString,
6373 },
6374 },
6375 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6376 })
6377
Adam Langley2deb9842015-08-07 11:15:37 -07006378 // Test an unknown extension from the server.
6379 testCases = append(testCases, testCase{
6380 testType: clientTest,
6381 name: "UnknownExtension-Client",
6382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006383 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006384 Bugs: ProtocolBugs{
6385 CustomExtension: expectedContents,
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":UNEXPECTED_EXTENSION:",
6390 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006391 testCases = append(testCases, testCase{
6392 testType: clientTest,
6393 name: "UnknownExtension-Client-TLS13",
6394 config: Config{
6395 MaxVersion: VersionTLS13,
6396 Bugs: ProtocolBugs{
6397 CustomExtension: expectedContents,
6398 },
6399 },
6400 shouldFail: true,
6401 expectedError: ":UNEXPECTED_EXTENSION:",
6402 })
Adam Langley09505632015-07-30 18:10:13 -07006403}
6404
David Benjaminb36a3952015-12-01 18:53:13 -05006405func addRSAClientKeyExchangeTests() {
6406 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6407 testCases = append(testCases, testCase{
6408 testType: serverTest,
6409 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6410 config: Config{
6411 // Ensure the ClientHello version and final
6412 // version are different, to detect if the
6413 // server uses the wrong one.
6414 MaxVersion: VersionTLS11,
6415 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6416 Bugs: ProtocolBugs{
6417 BadRSAClientKeyExchange: bad,
6418 },
6419 },
6420 shouldFail: true,
6421 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6422 })
6423 }
6424}
6425
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006426var testCurves = []struct {
6427 name string
6428 id CurveID
6429}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006430 {"P-256", CurveP256},
6431 {"P-384", CurveP384},
6432 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006433 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006434}
6435
Steven Valdez5440fe02016-07-18 12:40:30 -04006436const bogusCurve = 0x1234
6437
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006438func addCurveTests() {
6439 for _, curve := range testCurves {
6440 testCases = append(testCases, testCase{
6441 name: "CurveTest-Client-" + curve.name,
6442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006443 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6445 CurvePreferences: []CurveID{curve.id},
6446 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006447 flags: []string{"-enable-all-curves"},
6448 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006449 })
6450 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006451 name: "CurveTest-Client-" + curve.name + "-TLS13",
6452 config: Config{
6453 MaxVersion: VersionTLS13,
6454 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6455 CurvePreferences: []CurveID{curve.id},
6456 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006457 flags: []string{"-enable-all-curves"},
6458 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006459 })
6460 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006461 testType: serverTest,
6462 name: "CurveTest-Server-" + curve.name,
6463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006464 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6466 CurvePreferences: []CurveID{curve.id},
6467 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006468 flags: []string{"-enable-all-curves"},
6469 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006470 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006471 testCases = append(testCases, testCase{
6472 testType: serverTest,
6473 name: "CurveTest-Server-" + curve.name + "-TLS13",
6474 config: Config{
6475 MaxVersion: VersionTLS13,
6476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6477 CurvePreferences: []CurveID{curve.id},
6478 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006479 flags: []string{"-enable-all-curves"},
6480 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006481 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006482 }
David Benjamin241ae832016-01-15 03:04:54 -05006483
6484 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006485 testCases = append(testCases, testCase{
6486 testType: serverTest,
6487 name: "UnknownCurve",
6488 config: Config{
6489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6490 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6491 },
6492 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006493
6494 // The server must not consider ECDHE ciphers when there are no
6495 // supported curves.
6496 testCases = append(testCases, testCase{
6497 testType: serverTest,
6498 name: "NoSupportedCurves",
6499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006500 MaxVersion: VersionTLS12,
6501 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6502 Bugs: ProtocolBugs{
6503 NoSupportedCurves: true,
6504 },
6505 },
6506 shouldFail: true,
6507 expectedError: ":NO_SHARED_CIPHER:",
6508 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006509 testCases = append(testCases, testCase{
6510 testType: serverTest,
6511 name: "NoSupportedCurves-TLS13",
6512 config: Config{
6513 MaxVersion: VersionTLS13,
6514 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6515 Bugs: ProtocolBugs{
6516 NoSupportedCurves: true,
6517 },
6518 },
6519 shouldFail: true,
6520 expectedError: ":NO_SHARED_CIPHER:",
6521 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006522
6523 // The server must fall back to another cipher when there are no
6524 // supported curves.
6525 testCases = append(testCases, testCase{
6526 testType: serverTest,
6527 name: "NoCommonCurves",
6528 config: Config{
6529 MaxVersion: VersionTLS12,
6530 CipherSuites: []uint16{
6531 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6532 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6533 },
6534 CurvePreferences: []CurveID{CurveP224},
6535 },
6536 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6537 })
6538
6539 // The client must reject bogus curves and disabled curves.
6540 testCases = append(testCases, testCase{
6541 name: "BadECDHECurve",
6542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006543 MaxVersion: VersionTLS12,
6544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6545 Bugs: ProtocolBugs{
6546 SendCurve: bogusCurve,
6547 },
6548 },
6549 shouldFail: true,
6550 expectedError: ":WRONG_CURVE:",
6551 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006552 testCases = append(testCases, testCase{
6553 name: "BadECDHECurve-TLS13",
6554 config: Config{
6555 MaxVersion: VersionTLS13,
6556 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6557 Bugs: ProtocolBugs{
6558 SendCurve: bogusCurve,
6559 },
6560 },
6561 shouldFail: true,
6562 expectedError: ":WRONG_CURVE:",
6563 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006564
6565 testCases = append(testCases, testCase{
6566 name: "UnsupportedCurve",
6567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006568 MaxVersion: VersionTLS12,
6569 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6570 CurvePreferences: []CurveID{CurveP256},
6571 Bugs: ProtocolBugs{
6572 IgnorePeerCurvePreferences: true,
6573 },
6574 },
6575 flags: []string{"-p384-only"},
6576 shouldFail: true,
6577 expectedError: ":WRONG_CURVE:",
6578 })
6579
David Benjamin4f921572016-07-17 14:20:10 +02006580 testCases = append(testCases, testCase{
6581 // TODO(davidben): Add a TLS 1.3 version where
6582 // HelloRetryRequest requests an unsupported curve.
6583 name: "UnsupportedCurve-ServerHello-TLS13",
6584 config: Config{
6585 MaxVersion: VersionTLS12,
6586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6587 CurvePreferences: []CurveID{CurveP384},
6588 Bugs: ProtocolBugs{
6589 SendCurve: CurveP256,
6590 },
6591 },
6592 flags: []string{"-p384-only"},
6593 shouldFail: true,
6594 expectedError: ":WRONG_CURVE:",
6595 })
6596
David Benjamin4c3ddf72016-06-29 18:13:53 -04006597 // Test invalid curve points.
6598 testCases = append(testCases, testCase{
6599 name: "InvalidECDHPoint-Client",
6600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006601 MaxVersion: VersionTLS12,
6602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6603 CurvePreferences: []CurveID{CurveP256},
6604 Bugs: ProtocolBugs{
6605 InvalidECDHPoint: true,
6606 },
6607 },
6608 shouldFail: true,
6609 expectedError: ":INVALID_ENCODING:",
6610 })
6611 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006612 name: "InvalidECDHPoint-Client-TLS13",
6613 config: Config{
6614 MaxVersion: VersionTLS13,
6615 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6616 CurvePreferences: []CurveID{CurveP256},
6617 Bugs: ProtocolBugs{
6618 InvalidECDHPoint: true,
6619 },
6620 },
6621 shouldFail: true,
6622 expectedError: ":INVALID_ENCODING:",
6623 })
6624 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006625 testType: serverTest,
6626 name: "InvalidECDHPoint-Server",
6627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006628 MaxVersion: VersionTLS12,
6629 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6630 CurvePreferences: []CurveID{CurveP256},
6631 Bugs: ProtocolBugs{
6632 InvalidECDHPoint: true,
6633 },
6634 },
6635 shouldFail: true,
6636 expectedError: ":INVALID_ENCODING:",
6637 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006638 testCases = append(testCases, testCase{
6639 testType: serverTest,
6640 name: "InvalidECDHPoint-Server-TLS13",
6641 config: Config{
6642 MaxVersion: VersionTLS13,
6643 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6644 CurvePreferences: []CurveID{CurveP256},
6645 Bugs: ProtocolBugs{
6646 InvalidECDHPoint: true,
6647 },
6648 },
6649 shouldFail: true,
6650 expectedError: ":INVALID_ENCODING:",
6651 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006652}
6653
Matt Braithwaite54217e42016-06-13 13:03:47 -07006654func addCECPQ1Tests() {
6655 testCases = append(testCases, testCase{
6656 testType: clientTest,
6657 name: "CECPQ1-Client-BadX25519Part",
6658 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006659 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006660 MinVersion: VersionTLS12,
6661 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6662 Bugs: ProtocolBugs{
6663 CECPQ1BadX25519Part: true,
6664 },
6665 },
6666 flags: []string{"-cipher", "kCECPQ1"},
6667 shouldFail: true,
6668 expectedLocalError: "local error: bad record MAC",
6669 })
6670 testCases = append(testCases, testCase{
6671 testType: clientTest,
6672 name: "CECPQ1-Client-BadNewhopePart",
6673 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006674 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006675 MinVersion: VersionTLS12,
6676 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6677 Bugs: ProtocolBugs{
6678 CECPQ1BadNewhopePart: true,
6679 },
6680 },
6681 flags: []string{"-cipher", "kCECPQ1"},
6682 shouldFail: true,
6683 expectedLocalError: "local error: bad record MAC",
6684 })
6685 testCases = append(testCases, testCase{
6686 testType: serverTest,
6687 name: "CECPQ1-Server-BadX25519Part",
6688 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006689 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006690 MinVersion: VersionTLS12,
6691 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6692 Bugs: ProtocolBugs{
6693 CECPQ1BadX25519Part: true,
6694 },
6695 },
6696 flags: []string{"-cipher", "kCECPQ1"},
6697 shouldFail: true,
6698 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6699 })
6700 testCases = append(testCases, testCase{
6701 testType: serverTest,
6702 name: "CECPQ1-Server-BadNewhopePart",
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 CECPQ1BadNewhopePart: true,
6709 },
6710 },
6711 flags: []string{"-cipher", "kCECPQ1"},
6712 shouldFail: true,
6713 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6714 })
6715}
6716
David Benjamin4cc36ad2015-12-19 14:23:26 -05006717func addKeyExchangeInfoTests() {
6718 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006719 name: "KeyExchangeInfo-DHE-Client",
6720 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006721 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006722 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6723 Bugs: ProtocolBugs{
6724 // This is a 1234-bit prime number, generated
6725 // with:
6726 // openssl gendh 1234 | openssl asn1parse -i
6727 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6728 },
6729 },
David Benjamin9e68f192016-06-30 14:55:33 -04006730 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006731 })
6732 testCases = append(testCases, testCase{
6733 testType: serverTest,
6734 name: "KeyExchangeInfo-DHE-Server",
6735 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006736 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006737 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6738 },
6739 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006740 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006741 })
6742
6743 testCases = append(testCases, testCase{
6744 name: "KeyExchangeInfo-ECDHE-Client",
6745 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006746 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006747 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6748 CurvePreferences: []CurveID{CurveX25519},
6749 },
David Benjamin9e68f192016-06-30 14:55:33 -04006750 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006751 })
6752 testCases = append(testCases, testCase{
6753 testType: serverTest,
6754 name: "KeyExchangeInfo-ECDHE-Server",
6755 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006756 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006757 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6758 CurvePreferences: []CurveID{CurveX25519},
6759 },
David Benjamin9e68f192016-06-30 14:55:33 -04006760 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006761 })
6762}
6763
David Benjaminc9ae27c2016-06-24 22:56:37 -04006764func addTLS13RecordTests() {
6765 testCases = append(testCases, testCase{
6766 name: "TLS13-RecordPadding",
6767 config: Config{
6768 MaxVersion: VersionTLS13,
6769 MinVersion: VersionTLS13,
6770 Bugs: ProtocolBugs{
6771 RecordPadding: 10,
6772 },
6773 },
6774 })
6775
6776 testCases = append(testCases, testCase{
6777 name: "TLS13-EmptyRecords",
6778 config: Config{
6779 MaxVersion: VersionTLS13,
6780 MinVersion: VersionTLS13,
6781 Bugs: ProtocolBugs{
6782 OmitRecordContents: true,
6783 },
6784 },
6785 shouldFail: true,
6786 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6787 })
6788
6789 testCases = append(testCases, testCase{
6790 name: "TLS13-OnlyPadding",
6791 config: Config{
6792 MaxVersion: VersionTLS13,
6793 MinVersion: VersionTLS13,
6794 Bugs: ProtocolBugs{
6795 OmitRecordContents: true,
6796 RecordPadding: 10,
6797 },
6798 },
6799 shouldFail: true,
6800 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6801 })
6802
6803 testCases = append(testCases, testCase{
6804 name: "TLS13-WrongOuterRecord",
6805 config: Config{
6806 MaxVersion: VersionTLS13,
6807 MinVersion: VersionTLS13,
6808 Bugs: ProtocolBugs{
6809 OuterRecordType: recordTypeHandshake,
6810 },
6811 },
6812 shouldFail: true,
6813 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6814 })
6815}
6816
David Benjamin82261be2016-07-07 14:32:50 -07006817func addChangeCipherSpecTests() {
6818 // Test missing ChangeCipherSpecs.
6819 testCases = append(testCases, testCase{
6820 name: "SkipChangeCipherSpec-Client",
6821 config: Config{
6822 MaxVersion: VersionTLS12,
6823 Bugs: ProtocolBugs{
6824 SkipChangeCipherSpec: true,
6825 },
6826 },
6827 shouldFail: true,
6828 expectedError: ":UNEXPECTED_RECORD:",
6829 })
6830 testCases = append(testCases, testCase{
6831 testType: serverTest,
6832 name: "SkipChangeCipherSpec-Server",
6833 config: Config{
6834 MaxVersion: VersionTLS12,
6835 Bugs: ProtocolBugs{
6836 SkipChangeCipherSpec: true,
6837 },
6838 },
6839 shouldFail: true,
6840 expectedError: ":UNEXPECTED_RECORD:",
6841 })
6842 testCases = append(testCases, testCase{
6843 testType: serverTest,
6844 name: "SkipChangeCipherSpec-Server-NPN",
6845 config: Config{
6846 MaxVersion: VersionTLS12,
6847 NextProtos: []string{"bar"},
6848 Bugs: ProtocolBugs{
6849 SkipChangeCipherSpec: true,
6850 },
6851 },
6852 flags: []string{
6853 "-advertise-npn", "\x03foo\x03bar\x03baz",
6854 },
6855 shouldFail: true,
6856 expectedError: ":UNEXPECTED_RECORD:",
6857 })
6858
6859 // Test synchronization between the handshake and ChangeCipherSpec.
6860 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6861 // rejected. Test both with and without handshake packing to handle both
6862 // when the partial post-CCS message is in its own record and when it is
6863 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006864 for _, packed := range []bool{false, true} {
6865 var suffix string
6866 if packed {
6867 suffix = "-Packed"
6868 }
6869
6870 testCases = append(testCases, testCase{
6871 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6872 config: Config{
6873 MaxVersion: VersionTLS12,
6874 Bugs: ProtocolBugs{
6875 FragmentAcrossChangeCipherSpec: true,
6876 PackHandshakeFlight: packed,
6877 },
6878 },
6879 shouldFail: true,
6880 expectedError: ":UNEXPECTED_RECORD:",
6881 })
6882 testCases = append(testCases, testCase{
6883 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6884 config: Config{
6885 MaxVersion: VersionTLS12,
6886 },
6887 resumeSession: true,
6888 resumeConfig: &Config{
6889 MaxVersion: VersionTLS12,
6890 Bugs: ProtocolBugs{
6891 FragmentAcrossChangeCipherSpec: true,
6892 PackHandshakeFlight: packed,
6893 },
6894 },
6895 shouldFail: true,
6896 expectedError: ":UNEXPECTED_RECORD:",
6897 })
6898 testCases = append(testCases, testCase{
6899 testType: serverTest,
6900 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6901 config: Config{
6902 MaxVersion: VersionTLS12,
6903 Bugs: ProtocolBugs{
6904 FragmentAcrossChangeCipherSpec: true,
6905 PackHandshakeFlight: packed,
6906 },
6907 },
6908 shouldFail: true,
6909 expectedError: ":UNEXPECTED_RECORD:",
6910 })
6911 testCases = append(testCases, testCase{
6912 testType: serverTest,
6913 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6914 config: Config{
6915 MaxVersion: VersionTLS12,
6916 },
6917 resumeSession: true,
6918 resumeConfig: &Config{
6919 MaxVersion: VersionTLS12,
6920 Bugs: ProtocolBugs{
6921 FragmentAcrossChangeCipherSpec: true,
6922 PackHandshakeFlight: packed,
6923 },
6924 },
6925 shouldFail: true,
6926 expectedError: ":UNEXPECTED_RECORD:",
6927 })
6928 testCases = append(testCases, testCase{
6929 testType: serverTest,
6930 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6931 config: Config{
6932 MaxVersion: VersionTLS12,
6933 NextProtos: []string{"bar"},
6934 Bugs: ProtocolBugs{
6935 FragmentAcrossChangeCipherSpec: true,
6936 PackHandshakeFlight: packed,
6937 },
6938 },
6939 flags: []string{
6940 "-advertise-npn", "\x03foo\x03bar\x03baz",
6941 },
6942 shouldFail: true,
6943 expectedError: ":UNEXPECTED_RECORD:",
6944 })
6945 }
6946
David Benjamin61672812016-07-14 23:10:43 -04006947 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6948 // messages in the handshake queue. Do this by testing the server
6949 // reading the client Finished, reversing the flight so Finished comes
6950 // first.
6951 testCases = append(testCases, testCase{
6952 protocol: dtls,
6953 testType: serverTest,
6954 name: "SendUnencryptedFinished-DTLS",
6955 config: Config{
6956 MaxVersion: VersionTLS12,
6957 Bugs: ProtocolBugs{
6958 SendUnencryptedFinished: true,
6959 ReverseHandshakeFragments: true,
6960 },
6961 },
6962 shouldFail: true,
6963 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6964 })
6965
Steven Valdez143e8b32016-07-11 13:19:03 -04006966 // Test synchronization between encryption changes and the handshake in
6967 // TLS 1.3, where ChangeCipherSpec is implicit.
6968 testCases = append(testCases, testCase{
6969 name: "PartialEncryptedExtensionsWithServerHello",
6970 config: Config{
6971 MaxVersion: VersionTLS13,
6972 Bugs: ProtocolBugs{
6973 PartialEncryptedExtensionsWithServerHello: true,
6974 },
6975 },
6976 shouldFail: true,
6977 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6978 })
6979 testCases = append(testCases, testCase{
6980 testType: serverTest,
6981 name: "PartialClientFinishedWithClientHello",
6982 config: Config{
6983 MaxVersion: VersionTLS13,
6984 Bugs: ProtocolBugs{
6985 PartialClientFinishedWithClientHello: true,
6986 },
6987 },
6988 shouldFail: true,
6989 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6990 })
6991
David Benjamin82261be2016-07-07 14:32:50 -07006992 // Test that early ChangeCipherSpecs are handled correctly.
6993 testCases = append(testCases, testCase{
6994 testType: serverTest,
6995 name: "EarlyChangeCipherSpec-server-1",
6996 config: Config{
6997 MaxVersion: VersionTLS12,
6998 Bugs: ProtocolBugs{
6999 EarlyChangeCipherSpec: 1,
7000 },
7001 },
7002 shouldFail: true,
7003 expectedError: ":UNEXPECTED_RECORD:",
7004 })
7005 testCases = append(testCases, testCase{
7006 testType: serverTest,
7007 name: "EarlyChangeCipherSpec-server-2",
7008 config: Config{
7009 MaxVersion: VersionTLS12,
7010 Bugs: ProtocolBugs{
7011 EarlyChangeCipherSpec: 2,
7012 },
7013 },
7014 shouldFail: true,
7015 expectedError: ":UNEXPECTED_RECORD:",
7016 })
7017 testCases = append(testCases, testCase{
7018 protocol: dtls,
7019 name: "StrayChangeCipherSpec",
7020 config: Config{
7021 // TODO(davidben): Once DTLS 1.3 exists, test
7022 // that stray ChangeCipherSpec messages are
7023 // rejected.
7024 MaxVersion: VersionTLS12,
7025 Bugs: ProtocolBugs{
7026 StrayChangeCipherSpec: true,
7027 },
7028 },
7029 })
7030
7031 // Test that the contents of ChangeCipherSpec are checked.
7032 testCases = append(testCases, testCase{
7033 name: "BadChangeCipherSpec-1",
7034 config: Config{
7035 MaxVersion: VersionTLS12,
7036 Bugs: ProtocolBugs{
7037 BadChangeCipherSpec: []byte{2},
7038 },
7039 },
7040 shouldFail: true,
7041 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7042 })
7043 testCases = append(testCases, testCase{
7044 name: "BadChangeCipherSpec-2",
7045 config: Config{
7046 MaxVersion: VersionTLS12,
7047 Bugs: ProtocolBugs{
7048 BadChangeCipherSpec: []byte{1, 1},
7049 },
7050 },
7051 shouldFail: true,
7052 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7053 })
7054 testCases = append(testCases, testCase{
7055 protocol: dtls,
7056 name: "BadChangeCipherSpec-DTLS-1",
7057 config: Config{
7058 MaxVersion: VersionTLS12,
7059 Bugs: ProtocolBugs{
7060 BadChangeCipherSpec: []byte{2},
7061 },
7062 },
7063 shouldFail: true,
7064 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7065 })
7066 testCases = append(testCases, testCase{
7067 protocol: dtls,
7068 name: "BadChangeCipherSpec-DTLS-2",
7069 config: Config{
7070 MaxVersion: VersionTLS12,
7071 Bugs: ProtocolBugs{
7072 BadChangeCipherSpec: []byte{1, 1},
7073 },
7074 },
7075 shouldFail: true,
7076 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7077 })
7078}
7079
David Benjamin0b8d5da2016-07-15 00:39:56 -04007080func addWrongMessageTypeTests() {
7081 for _, protocol := range []protocol{tls, dtls} {
7082 var suffix string
7083 if protocol == dtls {
7084 suffix = "-DTLS"
7085 }
7086
7087 testCases = append(testCases, testCase{
7088 protocol: protocol,
7089 testType: serverTest,
7090 name: "WrongMessageType-ClientHello" + suffix,
7091 config: Config{
7092 MaxVersion: VersionTLS12,
7093 Bugs: ProtocolBugs{
7094 SendWrongMessageType: typeClientHello,
7095 },
7096 },
7097 shouldFail: true,
7098 expectedError: ":UNEXPECTED_MESSAGE:",
7099 expectedLocalError: "remote error: unexpected message",
7100 })
7101
7102 if protocol == dtls {
7103 testCases = append(testCases, testCase{
7104 protocol: protocol,
7105 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7106 config: Config{
7107 MaxVersion: VersionTLS12,
7108 Bugs: ProtocolBugs{
7109 SendWrongMessageType: typeHelloVerifyRequest,
7110 },
7111 },
7112 shouldFail: true,
7113 expectedError: ":UNEXPECTED_MESSAGE:",
7114 expectedLocalError: "remote error: unexpected message",
7115 })
7116 }
7117
7118 testCases = append(testCases, testCase{
7119 protocol: protocol,
7120 name: "WrongMessageType-ServerHello" + suffix,
7121 config: Config{
7122 MaxVersion: VersionTLS12,
7123 Bugs: ProtocolBugs{
7124 SendWrongMessageType: typeServerHello,
7125 },
7126 },
7127 shouldFail: true,
7128 expectedError: ":UNEXPECTED_MESSAGE:",
7129 expectedLocalError: "remote error: unexpected message",
7130 })
7131
7132 testCases = append(testCases, testCase{
7133 protocol: protocol,
7134 name: "WrongMessageType-ServerCertificate" + suffix,
7135 config: Config{
7136 MaxVersion: VersionTLS12,
7137 Bugs: ProtocolBugs{
7138 SendWrongMessageType: typeCertificate,
7139 },
7140 },
7141 shouldFail: true,
7142 expectedError: ":UNEXPECTED_MESSAGE:",
7143 expectedLocalError: "remote error: unexpected message",
7144 })
7145
7146 testCases = append(testCases, testCase{
7147 protocol: protocol,
7148 name: "WrongMessageType-CertificateStatus" + suffix,
7149 config: Config{
7150 MaxVersion: VersionTLS12,
7151 Bugs: ProtocolBugs{
7152 SendWrongMessageType: typeCertificateStatus,
7153 },
7154 },
7155 flags: []string{"-enable-ocsp-stapling"},
7156 shouldFail: true,
7157 expectedError: ":UNEXPECTED_MESSAGE:",
7158 expectedLocalError: "remote error: unexpected message",
7159 })
7160
7161 testCases = append(testCases, testCase{
7162 protocol: protocol,
7163 name: "WrongMessageType-ServerKeyExchange" + suffix,
7164 config: Config{
7165 MaxVersion: VersionTLS12,
7166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7167 Bugs: ProtocolBugs{
7168 SendWrongMessageType: typeServerKeyExchange,
7169 },
7170 },
7171 shouldFail: true,
7172 expectedError: ":UNEXPECTED_MESSAGE:",
7173 expectedLocalError: "remote error: unexpected message",
7174 })
7175
7176 testCases = append(testCases, testCase{
7177 protocol: protocol,
7178 name: "WrongMessageType-CertificateRequest" + suffix,
7179 config: Config{
7180 MaxVersion: VersionTLS12,
7181 ClientAuth: RequireAnyClientCert,
7182 Bugs: ProtocolBugs{
7183 SendWrongMessageType: typeCertificateRequest,
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-ServerHelloDone" + suffix,
7194 config: Config{
7195 MaxVersion: VersionTLS12,
7196 Bugs: ProtocolBugs{
7197 SendWrongMessageType: typeServerHelloDone,
7198 },
7199 },
7200 shouldFail: true,
7201 expectedError: ":UNEXPECTED_MESSAGE:",
7202 expectedLocalError: "remote error: unexpected message",
7203 })
7204
7205 testCases = append(testCases, testCase{
7206 testType: serverTest,
7207 protocol: protocol,
7208 name: "WrongMessageType-ClientCertificate" + suffix,
7209 config: Config{
7210 Certificates: []Certificate{rsaCertificate},
7211 MaxVersion: VersionTLS12,
7212 Bugs: ProtocolBugs{
7213 SendWrongMessageType: typeCertificate,
7214 },
7215 },
7216 flags: []string{"-require-any-client-certificate"},
7217 shouldFail: true,
7218 expectedError: ":UNEXPECTED_MESSAGE:",
7219 expectedLocalError: "remote error: unexpected message",
7220 })
7221
7222 testCases = append(testCases, testCase{
7223 testType: serverTest,
7224 protocol: protocol,
7225 name: "WrongMessageType-CertificateVerify" + suffix,
7226 config: Config{
7227 Certificates: []Certificate{rsaCertificate},
7228 MaxVersion: VersionTLS12,
7229 Bugs: ProtocolBugs{
7230 SendWrongMessageType: typeCertificateVerify,
7231 },
7232 },
7233 flags: []string{"-require-any-client-certificate"},
7234 shouldFail: true,
7235 expectedError: ":UNEXPECTED_MESSAGE:",
7236 expectedLocalError: "remote error: unexpected message",
7237 })
7238
7239 testCases = append(testCases, testCase{
7240 testType: serverTest,
7241 protocol: protocol,
7242 name: "WrongMessageType-ClientKeyExchange" + suffix,
7243 config: Config{
7244 MaxVersion: VersionTLS12,
7245 Bugs: ProtocolBugs{
7246 SendWrongMessageType: typeClientKeyExchange,
7247 },
7248 },
7249 shouldFail: true,
7250 expectedError: ":UNEXPECTED_MESSAGE:",
7251 expectedLocalError: "remote error: unexpected message",
7252 })
7253
7254 if protocol != dtls {
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 protocol: protocol,
7258 name: "WrongMessageType-NextProtocol" + suffix,
7259 config: Config{
7260 MaxVersion: VersionTLS12,
7261 NextProtos: []string{"bar"},
7262 Bugs: ProtocolBugs{
7263 SendWrongMessageType: typeNextProtocol,
7264 },
7265 },
7266 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7267 shouldFail: true,
7268 expectedError: ":UNEXPECTED_MESSAGE:",
7269 expectedLocalError: "remote error: unexpected message",
7270 })
7271
7272 testCases = append(testCases, testCase{
7273 testType: serverTest,
7274 protocol: protocol,
7275 name: "WrongMessageType-ChannelID" + suffix,
7276 config: Config{
7277 MaxVersion: VersionTLS12,
7278 ChannelID: channelIDKey,
7279 Bugs: ProtocolBugs{
7280 SendWrongMessageType: typeChannelID,
7281 },
7282 },
7283 flags: []string{
7284 "-expect-channel-id",
7285 base64.StdEncoding.EncodeToString(channelIDBytes),
7286 },
7287 shouldFail: true,
7288 expectedError: ":UNEXPECTED_MESSAGE:",
7289 expectedLocalError: "remote error: unexpected message",
7290 })
7291 }
7292
7293 testCases = append(testCases, testCase{
7294 testType: serverTest,
7295 protocol: protocol,
7296 name: "WrongMessageType-ClientFinished" + suffix,
7297 config: Config{
7298 MaxVersion: VersionTLS12,
7299 Bugs: ProtocolBugs{
7300 SendWrongMessageType: typeFinished,
7301 },
7302 },
7303 shouldFail: true,
7304 expectedError: ":UNEXPECTED_MESSAGE:",
7305 expectedLocalError: "remote error: unexpected message",
7306 })
7307
7308 testCases = append(testCases, testCase{
7309 protocol: protocol,
7310 name: "WrongMessageType-NewSessionTicket" + suffix,
7311 config: Config{
7312 MaxVersion: VersionTLS12,
7313 Bugs: ProtocolBugs{
7314 SendWrongMessageType: typeNewSessionTicket,
7315 },
7316 },
7317 shouldFail: true,
7318 expectedError: ":UNEXPECTED_MESSAGE:",
7319 expectedLocalError: "remote error: unexpected message",
7320 })
7321
7322 testCases = append(testCases, testCase{
7323 protocol: protocol,
7324 name: "WrongMessageType-ServerFinished" + suffix,
7325 config: Config{
7326 MaxVersion: VersionTLS12,
7327 Bugs: ProtocolBugs{
7328 SendWrongMessageType: typeFinished,
7329 },
7330 },
7331 shouldFail: true,
7332 expectedError: ":UNEXPECTED_MESSAGE:",
7333 expectedLocalError: "remote error: unexpected message",
7334 })
7335
7336 }
7337}
7338
Steven Valdez143e8b32016-07-11 13:19:03 -04007339func addTLS13WrongMessageTypeTests() {
7340 testCases = append(testCases, testCase{
7341 testType: serverTest,
7342 name: "WrongMessageType-TLS13-ClientHello",
7343 config: Config{
7344 MaxVersion: VersionTLS13,
7345 Bugs: ProtocolBugs{
7346 SendWrongMessageType: typeClientHello,
7347 },
7348 },
7349 shouldFail: true,
7350 expectedError: ":UNEXPECTED_MESSAGE:",
7351 expectedLocalError: "remote error: unexpected message",
7352 })
7353
7354 testCases = append(testCases, testCase{
7355 name: "WrongMessageType-TLS13-ServerHello",
7356 config: Config{
7357 MaxVersion: VersionTLS13,
7358 Bugs: ProtocolBugs{
7359 SendWrongMessageType: typeServerHello,
7360 },
7361 },
7362 shouldFail: true,
7363 expectedError: ":UNEXPECTED_MESSAGE:",
7364 // The alert comes in with the wrong encryption.
7365 expectedLocalError: "local error: bad record MAC",
7366 })
7367
7368 testCases = append(testCases, testCase{
7369 name: "WrongMessageType-TLS13-EncryptedExtensions",
7370 config: Config{
7371 MaxVersion: VersionTLS13,
7372 Bugs: ProtocolBugs{
7373 SendWrongMessageType: typeEncryptedExtensions,
7374 },
7375 },
7376 shouldFail: true,
7377 expectedError: ":UNEXPECTED_MESSAGE:",
7378 expectedLocalError: "remote error: unexpected message",
7379 })
7380
7381 testCases = append(testCases, testCase{
7382 name: "WrongMessageType-TLS13-CertificateRequest",
7383 config: Config{
7384 MaxVersion: VersionTLS13,
7385 ClientAuth: RequireAnyClientCert,
7386 Bugs: ProtocolBugs{
7387 SendWrongMessageType: typeCertificateRequest,
7388 },
7389 },
7390 shouldFail: true,
7391 expectedError: ":UNEXPECTED_MESSAGE:",
7392 expectedLocalError: "remote error: unexpected message",
7393 })
7394
7395 testCases = append(testCases, testCase{
7396 name: "WrongMessageType-TLS13-ServerCertificate",
7397 config: Config{
7398 MaxVersion: VersionTLS13,
7399 Bugs: ProtocolBugs{
7400 SendWrongMessageType: typeCertificate,
7401 },
7402 },
7403 shouldFail: true,
7404 expectedError: ":UNEXPECTED_MESSAGE:",
7405 expectedLocalError: "remote error: unexpected message",
7406 })
7407
7408 testCases = append(testCases, testCase{
7409 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7410 config: Config{
7411 MaxVersion: VersionTLS13,
7412 Bugs: ProtocolBugs{
7413 SendWrongMessageType: typeCertificateVerify,
7414 },
7415 },
7416 shouldFail: true,
7417 expectedError: ":UNEXPECTED_MESSAGE:",
7418 expectedLocalError: "remote error: unexpected message",
7419 })
7420
7421 testCases = append(testCases, testCase{
7422 name: "WrongMessageType-TLS13-ServerFinished",
7423 config: Config{
7424 MaxVersion: VersionTLS13,
7425 Bugs: ProtocolBugs{
7426 SendWrongMessageType: typeFinished,
7427 },
7428 },
7429 shouldFail: true,
7430 expectedError: ":UNEXPECTED_MESSAGE:",
7431 expectedLocalError: "remote error: unexpected message",
7432 })
7433
7434 testCases = append(testCases, testCase{
7435 testType: serverTest,
7436 name: "WrongMessageType-TLS13-ClientCertificate",
7437 config: Config{
7438 Certificates: []Certificate{rsaCertificate},
7439 MaxVersion: VersionTLS13,
7440 Bugs: ProtocolBugs{
7441 SendWrongMessageType: typeCertificate,
7442 },
7443 },
7444 flags: []string{"-require-any-client-certificate"},
7445 shouldFail: true,
7446 expectedError: ":UNEXPECTED_MESSAGE:",
7447 expectedLocalError: "remote error: unexpected message",
7448 })
7449
7450 testCases = append(testCases, testCase{
7451 testType: serverTest,
7452 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7453 config: Config{
7454 Certificates: []Certificate{rsaCertificate},
7455 MaxVersion: VersionTLS13,
7456 Bugs: ProtocolBugs{
7457 SendWrongMessageType: typeCertificateVerify,
7458 },
7459 },
7460 flags: []string{"-require-any-client-certificate"},
7461 shouldFail: true,
7462 expectedError: ":UNEXPECTED_MESSAGE:",
7463 expectedLocalError: "remote error: unexpected message",
7464 })
7465
7466 testCases = append(testCases, testCase{
7467 testType: serverTest,
7468 name: "WrongMessageType-TLS13-ClientFinished",
7469 config: Config{
7470 MaxVersion: VersionTLS13,
7471 Bugs: ProtocolBugs{
7472 SendWrongMessageType: typeFinished,
7473 },
7474 },
7475 shouldFail: true,
7476 expectedError: ":UNEXPECTED_MESSAGE:",
7477 expectedLocalError: "remote error: unexpected message",
7478 })
7479}
7480
7481func addTLS13HandshakeTests() {
7482 testCases = append(testCases, testCase{
7483 testType: clientTest,
7484 name: "MissingKeyShare-Client",
7485 config: Config{
7486 MaxVersion: VersionTLS13,
7487 Bugs: ProtocolBugs{
7488 MissingKeyShare: true,
7489 },
7490 },
7491 shouldFail: true,
7492 expectedError: ":MISSING_KEY_SHARE:",
7493 })
7494
7495 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007496 testType: serverTest,
7497 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007498 config: Config{
7499 MaxVersion: VersionTLS13,
7500 Bugs: ProtocolBugs{
7501 MissingKeyShare: true,
7502 },
7503 },
7504 shouldFail: true,
7505 expectedError: ":MISSING_KEY_SHARE:",
7506 })
7507
7508 testCases = append(testCases, testCase{
7509 testType: clientTest,
7510 name: "ClientHelloMissingKeyShare",
7511 config: Config{
7512 MaxVersion: VersionTLS13,
7513 Bugs: ProtocolBugs{
7514 MissingKeyShare: true,
7515 },
7516 },
7517 shouldFail: true,
7518 expectedError: ":MISSING_KEY_SHARE:",
7519 })
7520
7521 testCases = append(testCases, testCase{
7522 testType: clientTest,
7523 name: "MissingKeyShare",
7524 config: Config{
7525 MaxVersion: VersionTLS13,
7526 Bugs: ProtocolBugs{
7527 MissingKeyShare: true,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":MISSING_KEY_SHARE:",
7532 })
7533
7534 testCases = append(testCases, testCase{
7535 testType: serverTest,
7536 name: "DuplicateKeyShares",
7537 config: Config{
7538 MaxVersion: VersionTLS13,
7539 Bugs: ProtocolBugs{
7540 DuplicateKeyShares: true,
7541 },
7542 },
7543 })
7544
7545 testCases = append(testCases, testCase{
7546 testType: clientTest,
7547 name: "EmptyEncryptedExtensions",
7548 config: Config{
7549 MaxVersion: VersionTLS13,
7550 Bugs: ProtocolBugs{
7551 EmptyEncryptedExtensions: true,
7552 },
7553 },
7554 shouldFail: true,
7555 expectedLocalError: "remote error: error decoding message",
7556 })
7557
7558 testCases = append(testCases, testCase{
7559 testType: clientTest,
7560 name: "EncryptedExtensionsWithKeyShare",
7561 config: Config{
7562 MaxVersion: VersionTLS13,
7563 Bugs: ProtocolBugs{
7564 EncryptedExtensionsWithKeyShare: true,
7565 },
7566 },
7567 shouldFail: true,
7568 expectedLocalError: "remote error: unsupported extension",
7569 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007570
7571 testCases = append(testCases, testCase{
7572 testType: serverTest,
7573 name: "SendHelloRetryRequest",
7574 config: Config{
7575 MaxVersion: VersionTLS13,
7576 // Require a HelloRetryRequest for every curve.
7577 DefaultCurves: []CurveID{},
7578 },
7579 expectedCurveID: CurveX25519,
7580 })
7581
7582 testCases = append(testCases, testCase{
7583 testType: serverTest,
7584 name: "SendHelloRetryRequest-2",
7585 config: Config{
7586 MaxVersion: VersionTLS13,
7587 DefaultCurves: []CurveID{CurveP384},
7588 },
7589 // Although the ClientHello did not predict our preferred curve,
7590 // we always select it whether it is predicted or not.
7591 expectedCurveID: CurveX25519,
7592 })
7593
7594 testCases = append(testCases, testCase{
7595 name: "UnknownCurve-HelloRetryRequest",
7596 config: Config{
7597 MaxVersion: VersionTLS13,
7598 // P-384 requires HelloRetryRequest in BoringSSL.
7599 CurvePreferences: []CurveID{CurveP384},
7600 Bugs: ProtocolBugs{
7601 SendHelloRetryRequestCurve: bogusCurve,
7602 },
7603 },
7604 shouldFail: true,
7605 expectedError: ":WRONG_CURVE:",
7606 })
7607
7608 testCases = append(testCases, testCase{
7609 name: "DisabledCurve-HelloRetryRequest",
7610 config: Config{
7611 MaxVersion: VersionTLS13,
7612 CurvePreferences: []CurveID{CurveP256},
7613 Bugs: ProtocolBugs{
7614 IgnorePeerCurvePreferences: true,
7615 },
7616 },
7617 flags: []string{"-p384-only"},
7618 shouldFail: true,
7619 expectedError: ":WRONG_CURVE:",
7620 })
7621
7622 testCases = append(testCases, testCase{
7623 name: "UnnecessaryHelloRetryRequest",
7624 config: Config{
7625 MaxVersion: VersionTLS13,
7626 Bugs: ProtocolBugs{
7627 UnnecessaryHelloRetryRequest: true,
7628 },
7629 },
7630 shouldFail: true,
7631 expectedError: ":WRONG_CURVE:",
7632 })
7633
7634 testCases = append(testCases, testCase{
7635 name: "SecondHelloRetryRequest",
7636 config: Config{
7637 MaxVersion: VersionTLS13,
7638 // P-384 requires HelloRetryRequest in BoringSSL.
7639 CurvePreferences: []CurveID{CurveP384},
7640 Bugs: ProtocolBugs{
7641 SecondHelloRetryRequest: true,
7642 },
7643 },
7644 shouldFail: true,
7645 expectedError: ":UNEXPECTED_MESSAGE:",
7646 })
7647
7648 testCases = append(testCases, testCase{
7649 testType: serverTest,
7650 name: "SecondClientHelloMissingKeyShare",
7651 config: Config{
7652 MaxVersion: VersionTLS13,
7653 DefaultCurves: []CurveID{},
7654 Bugs: ProtocolBugs{
7655 SecondClientHelloMissingKeyShare: true,
7656 },
7657 },
7658 shouldFail: true,
7659 expectedError: ":MISSING_KEY_SHARE:",
7660 })
7661
7662 testCases = append(testCases, testCase{
7663 testType: serverTest,
7664 name: "SecondClientHelloWrongCurve",
7665 config: Config{
7666 MaxVersion: VersionTLS13,
7667 DefaultCurves: []CurveID{},
7668 Bugs: ProtocolBugs{
7669 MisinterpretHelloRetryRequestCurve: CurveP521,
7670 },
7671 },
7672 shouldFail: true,
7673 expectedError: ":WRONG_CURVE:",
7674 })
7675
7676 testCases = append(testCases, testCase{
7677 name: "HelloRetryRequestVersionMismatch",
7678 config: Config{
7679 MaxVersion: VersionTLS13,
7680 // P-384 requires HelloRetryRequest in BoringSSL.
7681 CurvePreferences: []CurveID{CurveP384},
7682 Bugs: ProtocolBugs{
7683 SendServerHelloVersion: 0x0305,
7684 },
7685 },
7686 shouldFail: true,
7687 expectedError: ":WRONG_VERSION_NUMBER:",
7688 })
7689
7690 testCases = append(testCases, testCase{
7691 name: "HelloRetryRequestCurveMismatch",
7692 config: Config{
7693 MaxVersion: VersionTLS13,
7694 // P-384 requires HelloRetryRequest in BoringSSL.
7695 CurvePreferences: []CurveID{CurveP384},
7696 Bugs: ProtocolBugs{
7697 // Send P-384 (correct) in the HelloRetryRequest.
7698 SendHelloRetryRequestCurve: CurveP384,
7699 // But send P-256 in the ServerHello.
7700 SendCurve: CurveP256,
7701 },
7702 },
7703 shouldFail: true,
7704 expectedError: ":WRONG_CURVE:",
7705 })
7706
7707 // Test the server selecting a curve that requires a HelloRetryRequest
7708 // without sending it.
7709 testCases = append(testCases, testCase{
7710 name: "SkipHelloRetryRequest",
7711 config: Config{
7712 MaxVersion: VersionTLS13,
7713 // P-384 requires HelloRetryRequest in BoringSSL.
7714 CurvePreferences: []CurveID{CurveP384},
7715 Bugs: ProtocolBugs{
7716 SkipHelloRetryRequest: true,
7717 },
7718 },
7719 shouldFail: true,
7720 expectedError: ":WRONG_CURVE:",
7721 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007722}
7723
Adam Langley7c803a62015-06-15 15:35:05 -07007724func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007725 defer wg.Done()
7726
7727 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007728 var err error
7729
7730 if *mallocTest < 0 {
7731 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007732 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007733 } else {
7734 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7735 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007736 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007737 if err != nil {
7738 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7739 }
7740 break
7741 }
7742 }
7743 }
Adam Langley95c29f32014-06-20 12:00:00 -07007744 statusChan <- statusMsg{test: test, err: err}
7745 }
7746}
7747
7748type statusMsg struct {
7749 test *testCase
7750 started bool
7751 err error
7752}
7753
David Benjamin5f237bc2015-02-11 17:14:15 -05007754func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007755 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007756
David Benjamin5f237bc2015-02-11 17:14:15 -05007757 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007758 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007759 if !*pipe {
7760 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007761 var erase string
7762 for i := 0; i < lineLen; i++ {
7763 erase += "\b \b"
7764 }
7765 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007766 }
7767
Adam Langley95c29f32014-06-20 12:00:00 -07007768 if msg.started {
7769 started++
7770 } else {
7771 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007772
7773 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02007774 if msg.err == errUnimplemented {
7775 if *pipe {
7776 // Print each test instead of a status line.
7777 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
7778 }
7779 unimplemented++
7780 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
7781 } else {
7782 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7783 failed++
7784 testOutput.addResult(msg.test.name, "FAIL")
7785 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007786 } else {
7787 if *pipe {
7788 // Print each test instead of a status line.
7789 fmt.Printf("PASSED (%s)\n", msg.test.name)
7790 }
7791 testOutput.addResult(msg.test.name, "PASS")
7792 }
Adam Langley95c29f32014-06-20 12:00:00 -07007793 }
7794
David Benjamin5f237bc2015-02-11 17:14:15 -05007795 if !*pipe {
7796 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02007797 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05007798 lineLen = len(line)
7799 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007800 }
Adam Langley95c29f32014-06-20 12:00:00 -07007801 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007802
7803 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007804}
7805
7806func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007807 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007808 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007809 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007810
Adam Langley7c803a62015-06-15 15:35:05 -07007811 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007812 addCipherSuiteTests()
7813 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007814 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007815 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007816 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007817 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007818 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007819 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007820 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007821 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007822 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007823 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007824 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007825 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007826 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007827 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007828 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007829 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007830 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007831 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007832 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007833 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007834 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007835 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007836 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007837 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007838 addTLS13WrongMessageTypeTests()
7839 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007840
7841 var wg sync.WaitGroup
7842
Adam Langley7c803a62015-06-15 15:35:05 -07007843 statusChan := make(chan statusMsg, *numWorkers)
7844 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007845 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007846
David Benjamin025b3d32014-07-01 19:53:04 -04007847 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007848
Adam Langley7c803a62015-06-15 15:35:05 -07007849 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007850 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007851 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007852 }
7853
David Benjamin270f0a72016-03-17 14:41:36 -04007854 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007855 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04007856 matched := true
7857 if len(*testToRun) != 0 {
7858 var err error
7859 matched, err = filepath.Match(*testToRun, testCases[i].name)
7860 if err != nil {
7861 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
7862 os.Exit(1)
7863 }
7864 }
7865
7866 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04007867 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007868 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007869 }
7870 }
David Benjamin17e12922016-07-28 18:04:43 -04007871
David Benjamin270f0a72016-03-17 14:41:36 -04007872 if !foundTest {
David Benjamin17e12922016-07-28 18:04:43 -04007873 fmt.Fprintf(os.Stderr, "No tests matched %q\n", *testToRun)
David Benjamin270f0a72016-03-17 14:41:36 -04007874 os.Exit(1)
7875 }
Adam Langley95c29f32014-06-20 12:00:00 -07007876
7877 close(testChan)
7878 wg.Wait()
7879 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007880 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007881
7882 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007883
7884 if *jsonOutput != "" {
7885 if err := testOutput.writeTo(*jsonOutput); err != nil {
7886 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7887 }
7888 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007889
EKR842ae6c2016-07-27 09:22:05 +02007890 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
7891 os.Exit(1)
7892 }
7893
7894 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04007895 os.Exit(1)
7896 }
Adam Langley95c29f32014-06-20 12:00:00 -07007897}