blob: 02e26a2b0db5ab6ed0d36b2a84e8074f7e0ec474 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
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 {
David Benjamine8e84b92016-08-03 15:39:47 -04001928 name: "SendWarningAlerts-Pass",
1929 config: Config{
1930 MaxVersion: VersionTLS12,
1931 },
Adam Langley7c803a62015-06-15 15:35:05 -07001932 sendWarningAlerts: 4,
1933 },
1934 {
David Benjamine8e84b92016-08-03 15:39:47 -04001935 protocol: dtls,
1936 name: "SendWarningAlerts-DTLS-Pass",
1937 config: Config{
1938 MaxVersion: VersionTLS12,
1939 },
Adam Langley7c803a62015-06-15 15:35:05 -07001940 sendWarningAlerts: 4,
1941 },
1942 {
David Benjamine8e84b92016-08-03 15:39:47 -04001943 name: "SendWarningAlerts-TLS13",
1944 config: Config{
1945 MaxVersion: VersionTLS13,
1946 },
1947 sendWarningAlerts: 4,
1948 shouldFail: true,
1949 expectedError: ":BAD_ALERT:",
1950 expectedLocalError: "remote error: error decoding message",
1951 },
1952 {
1953 name: "SendWarningAlerts",
1954 config: Config{
1955 MaxVersion: VersionTLS12,
1956 },
Adam Langley7c803a62015-06-15 15:35:05 -07001957 sendWarningAlerts: 5,
1958 shouldFail: true,
1959 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1960 },
1961 {
David Benjamine8e84b92016-08-03 15:39:47 -04001962 name: "SendWarningAlerts-Async",
1963 config: Config{
1964 MaxVersion: VersionTLS12,
1965 },
Adam Langley7c803a62015-06-15 15:35:05 -07001966 sendWarningAlerts: 5,
1967 flags: []string{"-async"},
1968 shouldFail: true,
1969 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1970 },
David Benjaminba4594a2015-06-18 18:36:15 -04001971 {
1972 name: "EmptySessionID",
1973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001974 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001975 SessionTicketsDisabled: true,
1976 },
1977 noSessionCache: true,
1978 flags: []string{"-expect-no-session"},
1979 },
David Benjamin30789da2015-08-29 22:56:45 -04001980 {
1981 name: "Unclean-Shutdown",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 NoCloseNotify: true,
1985 ExpectCloseNotify: true,
1986 },
1987 },
1988 shimShutsDown: true,
1989 flags: []string{"-check-close-notify"},
1990 shouldFail: true,
1991 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1992 },
1993 {
1994 name: "Unclean-Shutdown-Ignored",
1995 config: Config{
1996 Bugs: ProtocolBugs{
1997 NoCloseNotify: true,
1998 },
1999 },
2000 shimShutsDown: true,
2001 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002002 {
David Benjaminfa214e42016-05-10 17:03:10 -04002003 name: "Unclean-Shutdown-Alert",
2004 config: Config{
2005 Bugs: ProtocolBugs{
2006 SendAlertOnShutdown: alertDecompressionFailure,
2007 ExpectCloseNotify: true,
2008 },
2009 },
2010 shimShutsDown: true,
2011 flags: []string{"-check-close-notify"},
2012 shouldFail: true,
2013 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2014 },
2015 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002016 name: "LargePlaintext",
2017 config: Config{
2018 Bugs: ProtocolBugs{
2019 SendLargeRecords: true,
2020 },
2021 },
2022 messageLen: maxPlaintext + 1,
2023 shouldFail: true,
2024 expectedError: ":DATA_LENGTH_TOO_LONG:",
2025 },
2026 {
2027 protocol: dtls,
2028 name: "LargePlaintext-DTLS",
2029 config: Config{
2030 Bugs: ProtocolBugs{
2031 SendLargeRecords: true,
2032 },
2033 },
2034 messageLen: maxPlaintext + 1,
2035 shouldFail: true,
2036 expectedError: ":DATA_LENGTH_TOO_LONG:",
2037 },
2038 {
2039 name: "LargeCiphertext",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 SendLargeRecords: true,
2043 },
2044 },
2045 messageLen: maxPlaintext * 2,
2046 shouldFail: true,
2047 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2048 },
2049 {
2050 protocol: dtls,
2051 name: "LargeCiphertext-DTLS",
2052 config: Config{
2053 Bugs: ProtocolBugs{
2054 SendLargeRecords: true,
2055 },
2056 },
2057 messageLen: maxPlaintext * 2,
2058 // Unlike the other four cases, DTLS drops records which
2059 // are invalid before authentication, so the connection
2060 // does not fail.
2061 expectMessageDropped: true,
2062 },
David Benjamindd6fed92015-10-23 17:41:12 -04002063 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002064 // In TLS 1.2 and below, empty NewSessionTicket messages
2065 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002066 name: "SendEmptySessionTicket",
2067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002068 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002069 Bugs: ProtocolBugs{
2070 SendEmptySessionTicket: true,
2071 FailIfSessionOffered: true,
2072 },
2073 },
2074 flags: []string{"-expect-no-session"},
2075 resumeSession: true,
2076 expectResumeRejected: true,
2077 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002078 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002079 name: "BadHelloRequest-1",
2080 renegotiate: 1,
2081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002082 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002083 Bugs: ProtocolBugs{
2084 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2085 },
2086 },
2087 flags: []string{
2088 "-renegotiate-freely",
2089 "-expect-total-renegotiations", "1",
2090 },
2091 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002092 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002093 },
2094 {
2095 name: "BadHelloRequest-2",
2096 renegotiate: 1,
2097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002098 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002099 Bugs: ProtocolBugs{
2100 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2101 },
2102 },
2103 flags: []string{
2104 "-renegotiate-freely",
2105 "-expect-total-renegotiations", "1",
2106 },
2107 shouldFail: true,
2108 expectedError: ":BAD_HELLO_REQUEST:",
2109 },
David Benjaminef1b0092015-11-21 14:05:44 -05002110 {
2111 testType: serverTest,
2112 name: "SupportTicketsWithSessionID",
2113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002114 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002115 SessionTicketsDisabled: true,
2116 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002117 resumeConfig: &Config{
2118 MaxVersion: VersionTLS12,
2119 },
David Benjaminef1b0092015-11-21 14:05:44 -05002120 resumeSession: true,
2121 },
David Benjamin02edcd02016-07-27 17:40:37 -04002122 {
2123 protocol: dtls,
2124 name: "DTLS-SendExtraFinished",
2125 config: Config{
2126 Bugs: ProtocolBugs{
2127 SendExtraFinished: true,
2128 },
2129 },
2130 shouldFail: true,
2131 expectedError: ":UNEXPECTED_RECORD:",
2132 },
2133 {
2134 protocol: dtls,
2135 name: "DTLS-SendExtraFinished-Reordered",
2136 config: Config{
2137 Bugs: ProtocolBugs{
2138 MaxHandshakeRecordLength: 2,
2139 ReorderHandshakeFragments: true,
2140 SendExtraFinished: true,
2141 },
2142 },
2143 shouldFail: true,
2144 expectedError: ":UNEXPECTED_RECORD:",
2145 },
David Benjamine97fb482016-07-29 09:23:07 -04002146 {
2147 testType: serverTest,
2148 name: "V2ClientHello-EmptyRecordPrefix",
2149 config: Config{
2150 // Choose a cipher suite that does not involve
2151 // elliptic curves, so no extensions are
2152 // involved.
2153 MaxVersion: VersionTLS12,
2154 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2155 Bugs: ProtocolBugs{
2156 SendV2ClientHello: true,
2157 },
2158 },
2159 sendPrefix: string([]byte{
2160 byte(recordTypeHandshake),
2161 3, 1, // version
2162 0, 0, // length
2163 }),
2164 // A no-op empty record may not be sent before V2ClientHello.
2165 shouldFail: true,
2166 expectedError: ":WRONG_VERSION_NUMBER:",
2167 },
2168 {
2169 testType: serverTest,
2170 name: "V2ClientHello-WarningAlertPrefix",
2171 config: Config{
2172 // Choose a cipher suite that does not involve
2173 // elliptic curves, so no extensions are
2174 // involved.
2175 MaxVersion: VersionTLS12,
2176 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2177 Bugs: ProtocolBugs{
2178 SendV2ClientHello: true,
2179 },
2180 },
2181 sendPrefix: string([]byte{
2182 byte(recordTypeAlert),
2183 3, 1, // version
2184 0, 2, // length
2185 alertLevelWarning, byte(alertDecompressionFailure),
2186 }),
2187 // A no-op warning alert may not be sent before V2ClientHello.
2188 shouldFail: true,
2189 expectedError: ":WRONG_VERSION_NUMBER:",
2190 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002191 {
2192 testType: clientTest,
2193 name: "KeyUpdate",
2194 config: Config{
2195 MaxVersion: VersionTLS13,
2196 Bugs: ProtocolBugs{
2197 SendKeyUpdateBeforeEveryAppDataRecord: true,
2198 },
2199 },
2200 },
Adam Langley7c803a62015-06-15 15:35:05 -07002201 }
Adam Langley7c803a62015-06-15 15:35:05 -07002202 testCases = append(testCases, basicTests...)
2203}
2204
Adam Langley95c29f32014-06-20 12:00:00 -07002205func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002206 const bogusCipher = 0xfe00
2207
Adam Langley95c29f32014-06-20 12:00:00 -07002208 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002209 const psk = "12345"
2210 const pskIdentity = "luggage combo"
2211
Adam Langley95c29f32014-06-20 12:00:00 -07002212 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002213 var certFile string
2214 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002215 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002216 cert = ecdsaP256Certificate
2217 certFile = ecdsaP256CertificateFile
2218 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002219 } else {
David Benjamin33863262016-07-08 17:20:12 -07002220 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002221 certFile = rsaCertificateFile
2222 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002223 }
2224
David Benjamin48cae082014-10-27 01:06:24 -04002225 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002226 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002227 flags = append(flags,
2228 "-psk", psk,
2229 "-psk-identity", pskIdentity)
2230 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002231 if hasComponent(suite.name, "NULL") {
2232 // NULL ciphers must be explicitly enabled.
2233 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2234 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002235 if hasComponent(suite.name, "CECPQ1") {
2236 // CECPQ1 ciphers must be explicitly enabled.
2237 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2238 }
David Benjamin48cae082014-10-27 01:06:24 -04002239
Adam Langley95c29f32014-06-20 12:00:00 -07002240 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002241 for _, protocol := range []protocol{tls, dtls} {
2242 var prefix string
2243 if protocol == dtls {
2244 if !ver.hasDTLS {
2245 continue
2246 }
2247 prefix = "D"
2248 }
Adam Langley95c29f32014-06-20 12:00:00 -07002249
David Benjamin0407e762016-06-17 16:41:18 -04002250 var shouldServerFail, shouldClientFail bool
2251 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2252 // BoringSSL clients accept ECDHE on SSLv3, but
2253 // a BoringSSL server will never select it
2254 // because the extension is missing.
2255 shouldServerFail = true
2256 }
2257 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2258 shouldClientFail = true
2259 shouldServerFail = true
2260 }
David Benjamin54c217c2016-07-13 12:35:25 -04002261 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002262 shouldClientFail = true
2263 shouldServerFail = true
2264 }
David Benjamin0407e762016-06-17 16:41:18 -04002265 if !isDTLSCipher(suite.name) && protocol == dtls {
2266 shouldClientFail = true
2267 shouldServerFail = true
2268 }
David Benjamin4298d772015-12-19 00:18:25 -05002269
David Benjamin0407e762016-06-17 16:41:18 -04002270 var expectedServerError, expectedClientError string
2271 if shouldServerFail {
2272 expectedServerError = ":NO_SHARED_CIPHER:"
2273 }
2274 if shouldClientFail {
2275 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2276 }
David Benjamin025b3d32014-07-01 19:53:04 -04002277
David Benjamin9deb1172016-07-13 17:13:49 -04002278 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2279 resumeSession := ver.version < VersionTLS13
2280
David Benjamin6fd297b2014-08-11 18:43:38 -04002281 testCases = append(testCases, testCase{
2282 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002283 protocol: protocol,
2284
2285 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002286 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002287 MinVersion: ver.version,
2288 MaxVersion: ver.version,
2289 CipherSuites: []uint16{suite.id},
2290 Certificates: []Certificate{cert},
2291 PreSharedKey: []byte(psk),
2292 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002293 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002294 EnableAllCiphers: shouldServerFail,
2295 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002296 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002297 },
2298 certFile: certFile,
2299 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002300 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002301 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002302 shouldFail: shouldServerFail,
2303 expectedError: expectedServerError,
2304 })
2305
2306 testCases = append(testCases, testCase{
2307 testType: clientTest,
2308 protocol: protocol,
2309 name: prefix + ver.name + "-" + suite.name + "-client",
2310 config: Config{
2311 MinVersion: ver.version,
2312 MaxVersion: ver.version,
2313 CipherSuites: []uint16{suite.id},
2314 Certificates: []Certificate{cert},
2315 PreSharedKey: []byte(psk),
2316 PreSharedKeyIdentity: pskIdentity,
2317 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002318 EnableAllCiphers: shouldClientFail,
2319 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002320 },
2321 },
2322 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002323 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002324 shouldFail: shouldClientFail,
2325 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002326 })
David Benjamin2c99d282015-09-01 10:23:00 -04002327
Nick Harper1fd39d82016-06-14 18:14:35 -07002328 if !shouldClientFail {
2329 // Ensure the maximum record size is accepted.
2330 testCases = append(testCases, testCase{
2331 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2332 config: Config{
2333 MinVersion: ver.version,
2334 MaxVersion: ver.version,
2335 CipherSuites: []uint16{suite.id},
2336 Certificates: []Certificate{cert},
2337 PreSharedKey: []byte(psk),
2338 PreSharedKeyIdentity: pskIdentity,
2339 },
2340 flags: flags,
2341 messageLen: maxPlaintext,
2342 })
2343 }
2344 }
David Benjamin2c99d282015-09-01 10:23:00 -04002345 }
Adam Langley95c29f32014-06-20 12:00:00 -07002346 }
Adam Langleya7997f12015-05-14 17:38:50 -07002347
2348 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002349 name: "NoSharedCipher",
2350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002351 MaxVersion: VersionTLS12,
2352 CipherSuites: []uint16{},
2353 },
2354 shouldFail: true,
2355 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2356 })
2357
2358 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002359 name: "NoSharedCipher-TLS13",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 CipherSuites: []uint16{},
2363 },
2364 shouldFail: true,
2365 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2366 })
2367
2368 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002369 name: "UnsupportedCipherSuite",
2370 config: Config{
2371 MaxVersion: VersionTLS12,
2372 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2373 Bugs: ProtocolBugs{
2374 IgnorePeerCipherPreferences: true,
2375 },
2376 },
2377 flags: []string{"-cipher", "DEFAULT:!RC4"},
2378 shouldFail: true,
2379 expectedError: ":WRONG_CIPHER_RETURNED:",
2380 })
2381
2382 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002383 name: "ServerHelloBogusCipher",
2384 config: Config{
2385 MaxVersion: VersionTLS12,
2386 Bugs: ProtocolBugs{
2387 SendCipherSuite: bogusCipher,
2388 },
2389 },
2390 shouldFail: true,
2391 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2392 })
2393 testCases = append(testCases, testCase{
2394 name: "ServerHelloBogusCipher-TLS13",
2395 config: Config{
2396 MaxVersion: VersionTLS13,
2397 Bugs: ProtocolBugs{
2398 SendCipherSuite: bogusCipher,
2399 },
2400 },
2401 shouldFail: true,
2402 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2403 })
2404
2405 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002406 name: "WeakDH",
2407 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002408 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002409 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2410 Bugs: ProtocolBugs{
2411 // This is a 1023-bit prime number, generated
2412 // with:
2413 // openssl gendh 1023 | openssl asn1parse -i
2414 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2415 },
2416 },
2417 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002418 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002419 })
Adam Langleycef75832015-09-03 14:51:12 -07002420
David Benjamincd24a392015-11-11 13:23:05 -08002421 testCases = append(testCases, testCase{
2422 name: "SillyDH",
2423 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002424 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002425 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2426 Bugs: ProtocolBugs{
2427 // This is a 4097-bit prime number, generated
2428 // with:
2429 // openssl gendh 4097 | openssl asn1parse -i
2430 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2431 },
2432 },
2433 shouldFail: true,
2434 expectedError: ":DH_P_TOO_LONG:",
2435 })
2436
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002437 // This test ensures that Diffie-Hellman public values are padded with
2438 // zeros so that they're the same length as the prime. This is to avoid
2439 // hitting a bug in yaSSL.
2440 testCases = append(testCases, testCase{
2441 testType: serverTest,
2442 name: "DHPublicValuePadded",
2443 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002444 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002445 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2446 Bugs: ProtocolBugs{
2447 RequireDHPublicValueLen: (1025 + 7) / 8,
2448 },
2449 },
2450 flags: []string{"-use-sparse-dh-prime"},
2451 })
David Benjamincd24a392015-11-11 13:23:05 -08002452
David Benjamin241ae832016-01-15 03:04:54 -05002453 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002454 testCases = append(testCases, testCase{
2455 testType: serverTest,
2456 name: "UnknownCipher",
2457 config: Config{
2458 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2459 },
2460 })
2461
Adam Langleycef75832015-09-03 14:51:12 -07002462 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2463 // 1.1 specific cipher suite settings. A server is setup with the given
2464 // cipher lists and then a connection is made for each member of
2465 // expectations. The cipher suite that the server selects must match
2466 // the specified one.
2467 var versionSpecificCiphersTest = []struct {
2468 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2469 // expectations is a map from TLS version to cipher suite id.
2470 expectations map[uint16]uint16
2471 }{
2472 {
2473 // Test that the null case (where no version-specific ciphers are set)
2474 // works as expected.
2475 "RC4-SHA:AES128-SHA", // default ciphers
2476 "", // no ciphers specifically for TLS ≥ 1.0
2477 "", // no ciphers specifically for TLS ≥ 1.1
2478 map[uint16]uint16{
2479 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2480 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2481 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2482 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2483 },
2484 },
2485 {
2486 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2487 // cipher.
2488 "RC4-SHA:AES128-SHA", // default
2489 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2490 "", // no ciphers specifically for TLS ≥ 1.1
2491 map[uint16]uint16{
2492 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2493 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2494 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2495 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2496 },
2497 },
2498 {
2499 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2500 // cipher.
2501 "RC4-SHA:AES128-SHA", // default
2502 "", // no ciphers specifically for TLS ≥ 1.0
2503 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2504 map[uint16]uint16{
2505 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2506 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2507 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2508 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2509 },
2510 },
2511 {
2512 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2513 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2514 "RC4-SHA:AES128-SHA", // default
2515 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2516 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2517 map[uint16]uint16{
2518 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2519 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2520 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2521 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2522 },
2523 },
2524 }
2525
2526 for i, test := range versionSpecificCiphersTest {
2527 for version, expectedCipherSuite := range test.expectations {
2528 flags := []string{"-cipher", test.ciphersDefault}
2529 if len(test.ciphersTLS10) > 0 {
2530 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2531 }
2532 if len(test.ciphersTLS11) > 0 {
2533 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2534 }
2535
2536 testCases = append(testCases, testCase{
2537 testType: serverTest,
2538 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2539 config: Config{
2540 MaxVersion: version,
2541 MinVersion: version,
2542 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2543 },
2544 flags: flags,
2545 expectedCipher: expectedCipherSuite,
2546 })
2547 }
2548 }
Adam Langley95c29f32014-06-20 12:00:00 -07002549}
2550
2551func addBadECDSASignatureTests() {
2552 for badR := BadValue(1); badR < NumBadValues; badR++ {
2553 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002554 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002555 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2556 config: Config{
2557 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002558 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002559 Bugs: ProtocolBugs{
2560 BadECDSAR: badR,
2561 BadECDSAS: badS,
2562 },
2563 },
2564 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002565 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002566 })
2567 }
2568 }
2569}
2570
Adam Langley80842bd2014-06-20 12:00:00 -07002571func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002572 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002573 name: "MaxCBCPadding",
2574 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002575 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2577 Bugs: ProtocolBugs{
2578 MaxPadding: true,
2579 },
2580 },
2581 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2582 })
David Benjamin025b3d32014-07-01 19:53:04 -04002583 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002584 name: "BadCBCPadding",
2585 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002586 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002587 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2588 Bugs: ProtocolBugs{
2589 PaddingFirstByteBad: true,
2590 },
2591 },
2592 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002593 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002594 })
2595 // OpenSSL previously had an issue where the first byte of padding in
2596 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002597 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002598 name: "BadCBCPadding255",
2599 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002600 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002601 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2602 Bugs: ProtocolBugs{
2603 MaxPadding: true,
2604 PaddingFirstByteBadIf255: true,
2605 },
2606 },
2607 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2608 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002609 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002610 })
2611}
2612
Kenny Root7fdeaf12014-08-05 15:23:37 -07002613func addCBCSplittingTests() {
2614 testCases = append(testCases, testCase{
2615 name: "CBCRecordSplitting",
2616 config: Config{
2617 MaxVersion: VersionTLS10,
2618 MinVersion: VersionTLS10,
2619 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2620 },
David Benjaminac8302a2015-09-01 17:18:15 -04002621 messageLen: -1, // read until EOF
2622 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002623 flags: []string{
2624 "-async",
2625 "-write-different-record-sizes",
2626 "-cbc-record-splitting",
2627 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002628 })
2629 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002630 name: "CBCRecordSplittingPartialWrite",
2631 config: Config{
2632 MaxVersion: VersionTLS10,
2633 MinVersion: VersionTLS10,
2634 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2635 },
2636 messageLen: -1, // read until EOF
2637 flags: []string{
2638 "-async",
2639 "-write-different-record-sizes",
2640 "-cbc-record-splitting",
2641 "-partial-write",
2642 },
2643 })
2644}
2645
David Benjamin636293b2014-07-08 17:59:18 -04002646func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002647 // Add a dummy cert pool to stress certificate authority parsing.
2648 // TODO(davidben): Add tests that those values parse out correctly.
2649 certPool := x509.NewCertPool()
2650 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2651 if err != nil {
2652 panic(err)
2653 }
2654 certPool.AddCert(cert)
2655
David Benjamin636293b2014-07-08 17:59:18 -04002656 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002657 testCases = append(testCases, testCase{
2658 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002659 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002660 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002661 MinVersion: ver.version,
2662 MaxVersion: ver.version,
2663 ClientAuth: RequireAnyClientCert,
2664 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002665 },
2666 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002669 },
2670 })
2671 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002672 testType: serverTest,
2673 name: ver.name + "-Server-ClientAuth-RSA",
2674 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002675 MinVersion: ver.version,
2676 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002677 Certificates: []Certificate{rsaCertificate},
2678 },
2679 flags: []string{"-require-any-client-certificate"},
2680 })
David Benjamine098ec22014-08-27 23:13:20 -04002681 if ver.version != VersionSSL30 {
2682 testCases = append(testCases, testCase{
2683 testType: serverTest,
2684 name: ver.name + "-Server-ClientAuth-ECDSA",
2685 config: Config{
2686 MinVersion: ver.version,
2687 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002688 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002689 },
2690 flags: []string{"-require-any-client-certificate"},
2691 })
2692 testCases = append(testCases, testCase{
2693 testType: clientTest,
2694 name: ver.name + "-Client-ClientAuth-ECDSA",
2695 config: Config{
2696 MinVersion: ver.version,
2697 MaxVersion: ver.version,
2698 ClientAuth: RequireAnyClientCert,
2699 ClientCAs: certPool,
2700 },
2701 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002702 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2703 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002704 },
2705 })
2706 }
David Benjamin636293b2014-07-08 17:59:18 -04002707 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002708
2709 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002710 name: "NoClientCertificate",
2711 config: Config{
2712 MaxVersion: VersionTLS12,
2713 ClientAuth: RequireAnyClientCert,
2714 },
2715 shouldFail: true,
2716 expectedLocalError: "client didn't provide a certificate",
2717 })
2718
2719 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002720 name: "NoClientCertificate-TLS13",
2721 config: Config{
2722 MaxVersion: VersionTLS13,
2723 ClientAuth: RequireAnyClientCert,
2724 },
2725 shouldFail: true,
2726 expectedLocalError: "client didn't provide a certificate",
2727 })
2728
2729 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002730 testType: serverTest,
2731 name: "RequireAnyClientCertificate",
2732 config: Config{
2733 MaxVersion: VersionTLS12,
2734 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002735 flags: []string{"-require-any-client-certificate"},
2736 shouldFail: true,
2737 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2738 })
2739
2740 testCases = append(testCases, testCase{
2741 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002742 name: "RequireAnyClientCertificate-TLS13",
2743 config: Config{
2744 MaxVersion: VersionTLS13,
2745 },
2746 flags: []string{"-require-any-client-certificate"},
2747 shouldFail: true,
2748 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2749 })
2750
2751 testCases = append(testCases, testCase{
2752 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002753 name: "RequireAnyClientCertificate-SSL3",
2754 config: Config{
2755 MaxVersion: VersionSSL30,
2756 },
2757 flags: []string{"-require-any-client-certificate"},
2758 shouldFail: true,
2759 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2760 })
2761
2762 testCases = append(testCases, testCase{
2763 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002764 name: "SkipClientCertificate",
2765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002766 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002767 Bugs: ProtocolBugs{
2768 SkipClientCertificate: true,
2769 },
2770 },
2771 // Setting SSL_VERIFY_PEER allows anonymous clients.
2772 flags: []string{"-verify-peer"},
2773 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002774 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002775 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002776
Steven Valdez143e8b32016-07-11 13:19:03 -04002777 testCases = append(testCases, testCase{
2778 testType: serverTest,
2779 name: "SkipClientCertificate-TLS13",
2780 config: Config{
2781 MaxVersion: VersionTLS13,
2782 Bugs: ProtocolBugs{
2783 SkipClientCertificate: true,
2784 },
2785 },
2786 // Setting SSL_VERIFY_PEER allows anonymous clients.
2787 flags: []string{"-verify-peer"},
2788 shouldFail: true,
2789 expectedError: ":UNEXPECTED_MESSAGE:",
2790 })
2791
David Benjaminc032dfa2016-05-12 14:54:57 -04002792 // Client auth is only legal in certificate-based ciphers.
2793 testCases = append(testCases, testCase{
2794 testType: clientTest,
2795 name: "ClientAuth-PSK",
2796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002797 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002798 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2799 PreSharedKey: []byte("secret"),
2800 ClientAuth: RequireAnyClientCert,
2801 },
2802 flags: []string{
2803 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2804 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2805 "-psk", "secret",
2806 },
2807 shouldFail: true,
2808 expectedError: ":UNEXPECTED_MESSAGE:",
2809 })
2810 testCases = append(testCases, testCase{
2811 testType: clientTest,
2812 name: "ClientAuth-ECDHE_PSK",
2813 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002814 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002815 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2816 PreSharedKey: []byte("secret"),
2817 ClientAuth: RequireAnyClientCert,
2818 },
2819 flags: []string{
2820 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2821 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2822 "-psk", "secret",
2823 },
2824 shouldFail: true,
2825 expectedError: ":UNEXPECTED_MESSAGE:",
2826 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002827
2828 // Regression test for a bug where the client CA list, if explicitly
2829 // set to NULL, was mis-encoded.
2830 testCases = append(testCases, testCase{
2831 testType: serverTest,
2832 name: "Null-Client-CA-List",
2833 config: Config{
2834 MaxVersion: VersionTLS12,
2835 Certificates: []Certificate{rsaCertificate},
2836 },
2837 flags: []string{
2838 "-require-any-client-certificate",
2839 "-use-null-client-ca-list",
2840 },
2841 })
David Benjamin636293b2014-07-08 17:59:18 -04002842}
2843
Adam Langley75712922014-10-10 16:23:43 -07002844func addExtendedMasterSecretTests() {
2845 const expectEMSFlag = "-expect-extended-master-secret"
2846
2847 for _, with := range []bool{false, true} {
2848 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002849 if with {
2850 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002851 }
2852
2853 for _, isClient := range []bool{false, true} {
2854 suffix := "-Server"
2855 testType := serverTest
2856 if isClient {
2857 suffix = "-Client"
2858 testType = clientTest
2859 }
2860
2861 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002862 // In TLS 1.3, the extension is irrelevant and
2863 // always reports as enabled.
2864 var flags []string
2865 if with || ver.version >= VersionTLS13 {
2866 flags = []string{expectEMSFlag}
2867 }
2868
Adam Langley75712922014-10-10 16:23:43 -07002869 test := testCase{
2870 testType: testType,
2871 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2872 config: Config{
2873 MinVersion: ver.version,
2874 MaxVersion: ver.version,
2875 Bugs: ProtocolBugs{
2876 NoExtendedMasterSecret: !with,
2877 RequireExtendedMasterSecret: with,
2878 },
2879 },
David Benjamin48cae082014-10-27 01:06:24 -04002880 flags: flags,
2881 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002882 }
2883 if test.shouldFail {
2884 test.expectedLocalError = "extended master secret required but not supported by peer"
2885 }
2886 testCases = append(testCases, test)
2887 }
2888 }
2889 }
2890
Adam Langleyba5934b2015-06-02 10:50:35 -07002891 for _, isClient := range []bool{false, true} {
2892 for _, supportedInFirstConnection := range []bool{false, true} {
2893 for _, supportedInResumeConnection := range []bool{false, true} {
2894 boolToWord := func(b bool) string {
2895 if b {
2896 return "Yes"
2897 }
2898 return "No"
2899 }
2900 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2901 if isClient {
2902 suffix += "Client"
2903 } else {
2904 suffix += "Server"
2905 }
2906
2907 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002908 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002909 Bugs: ProtocolBugs{
2910 RequireExtendedMasterSecret: true,
2911 },
2912 }
2913
2914 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002915 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002916 Bugs: ProtocolBugs{
2917 NoExtendedMasterSecret: true,
2918 },
2919 }
2920
2921 test := testCase{
2922 name: "ExtendedMasterSecret-" + suffix,
2923 resumeSession: true,
2924 }
2925
2926 if !isClient {
2927 test.testType = serverTest
2928 }
2929
2930 if supportedInFirstConnection {
2931 test.config = supportedConfig
2932 } else {
2933 test.config = noSupportConfig
2934 }
2935
2936 if supportedInResumeConnection {
2937 test.resumeConfig = &supportedConfig
2938 } else {
2939 test.resumeConfig = &noSupportConfig
2940 }
2941
2942 switch suffix {
2943 case "YesToYes-Client", "YesToYes-Server":
2944 // When a session is resumed, it should
2945 // still be aware that its master
2946 // secret was generated via EMS and
2947 // thus it's safe to use tls-unique.
2948 test.flags = []string{expectEMSFlag}
2949 case "NoToYes-Server":
2950 // If an original connection did not
2951 // contain EMS, but a resumption
2952 // handshake does, then a server should
2953 // not resume the session.
2954 test.expectResumeRejected = true
2955 case "YesToNo-Server":
2956 // Resuming an EMS session without the
2957 // EMS extension should cause the
2958 // server to abort the connection.
2959 test.shouldFail = true
2960 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2961 case "NoToYes-Client":
2962 // A client should abort a connection
2963 // where the server resumed a non-EMS
2964 // session but echoed the EMS
2965 // extension.
2966 test.shouldFail = true
2967 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2968 case "YesToNo-Client":
2969 // A client should abort a connection
2970 // where the server didn't echo EMS
2971 // when the session used it.
2972 test.shouldFail = true
2973 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2974 }
2975
2976 testCases = append(testCases, test)
2977 }
2978 }
2979 }
Adam Langley75712922014-10-10 16:23:43 -07002980}
2981
David Benjamin582ba042016-07-07 12:33:25 -07002982type stateMachineTestConfig struct {
2983 protocol protocol
2984 async bool
2985 splitHandshake, packHandshakeFlight bool
2986}
2987
David Benjamin43ec06f2014-08-05 02:28:57 -04002988// Adds tests that try to cover the range of the handshake state machine, under
2989// various conditions. Some of these are redundant with other tests, but they
2990// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002991func addAllStateMachineCoverageTests() {
2992 for _, async := range []bool{false, true} {
2993 for _, protocol := range []protocol{tls, dtls} {
2994 addStateMachineCoverageTests(stateMachineTestConfig{
2995 protocol: protocol,
2996 async: async,
2997 })
2998 addStateMachineCoverageTests(stateMachineTestConfig{
2999 protocol: protocol,
3000 async: async,
3001 splitHandshake: true,
3002 })
3003 if protocol == tls {
3004 addStateMachineCoverageTests(stateMachineTestConfig{
3005 protocol: protocol,
3006 async: async,
3007 packHandshakeFlight: true,
3008 })
3009 }
3010 }
3011 }
3012}
3013
3014func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003015 var tests []testCase
3016
3017 // Basic handshake, with resumption. Client and server,
3018 // session ID and session ticket.
3019 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003020 name: "Basic-Client",
3021 config: Config{
3022 MaxVersion: VersionTLS12,
3023 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003024 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003025 // Ensure session tickets are used, not session IDs.
3026 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003027 })
3028 tests = append(tests, testCase{
3029 name: "Basic-Client-RenewTicket",
3030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003031 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003032 Bugs: ProtocolBugs{
3033 RenewTicketOnResume: true,
3034 },
3035 },
David Benjaminba4594a2015-06-18 18:36:15 -04003036 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003037 resumeSession: true,
3038 })
3039 tests = append(tests, testCase{
3040 name: "Basic-Client-NoTicket",
3041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003042 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 SessionTicketsDisabled: true,
3044 },
3045 resumeSession: true,
3046 })
3047 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003048 name: "Basic-Client-Implicit",
3049 config: Config{
3050 MaxVersion: VersionTLS12,
3051 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003052 flags: []string{"-implicit-handshake"},
3053 resumeSession: true,
3054 })
3055 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003056 testType: serverTest,
3057 name: "Basic-Server",
3058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003059 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003060 Bugs: ProtocolBugs{
3061 RequireSessionTickets: true,
3062 },
3063 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003064 resumeSession: true,
3065 })
3066 tests = append(tests, testCase{
3067 testType: serverTest,
3068 name: "Basic-Server-NoTickets",
3069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003070 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003071 SessionTicketsDisabled: true,
3072 },
3073 resumeSession: true,
3074 })
3075 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003076 testType: serverTest,
3077 name: "Basic-Server-Implicit",
3078 config: Config{
3079 MaxVersion: VersionTLS12,
3080 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003081 flags: []string{"-implicit-handshake"},
3082 resumeSession: true,
3083 })
3084 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003085 testType: serverTest,
3086 name: "Basic-Server-EarlyCallback",
3087 config: Config{
3088 MaxVersion: VersionTLS12,
3089 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 flags: []string{"-use-early-callback"},
3091 resumeSession: true,
3092 })
3093
Steven Valdez143e8b32016-07-11 13:19:03 -04003094 // TLS 1.3 basic handshake shapes.
3095 tests = append(tests, testCase{
3096 name: "TLS13-1RTT-Client",
3097 config: Config{
3098 MaxVersion: VersionTLS13,
3099 },
3100 })
3101 tests = append(tests, testCase{
3102 testType: serverTest,
3103 name: "TLS13-1RTT-Server",
3104 config: Config{
3105 MaxVersion: VersionTLS13,
3106 },
3107 })
3108
David Benjamin760b1dd2015-05-15 23:33:48 -04003109 // TLS client auth.
3110 tests = append(tests, testCase{
3111 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003112 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003115 ClientAuth: RequestClientCert,
3116 },
3117 })
3118 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003119 testType: serverTest,
3120 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003121 config: Config{
3122 MaxVersion: VersionTLS12,
3123 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003124 // Setting SSL_VERIFY_PEER allows anonymous clients.
3125 flags: []string{"-verify-peer"},
3126 })
David Benjamin582ba042016-07-07 12:33:25 -07003127 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003128 tests = append(tests, testCase{
3129 testType: clientTest,
3130 name: "ClientAuth-NoCertificate-Client-SSL3",
3131 config: Config{
3132 MaxVersion: VersionSSL30,
3133 ClientAuth: RequestClientCert,
3134 },
3135 })
3136 tests = append(tests, testCase{
3137 testType: serverTest,
3138 name: "ClientAuth-NoCertificate-Server-SSL3",
3139 config: Config{
3140 MaxVersion: VersionSSL30,
3141 },
3142 // Setting SSL_VERIFY_PEER allows anonymous clients.
3143 flags: []string{"-verify-peer"},
3144 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003145 tests = append(tests, testCase{
3146 testType: clientTest,
3147 name: "ClientAuth-NoCertificate-Client-TLS13",
3148 config: Config{
3149 MaxVersion: VersionTLS13,
3150 ClientAuth: RequestClientCert,
3151 },
3152 })
3153 tests = append(tests, testCase{
3154 testType: serverTest,
3155 name: "ClientAuth-NoCertificate-Server-TLS13",
3156 config: Config{
3157 MaxVersion: VersionTLS13,
3158 },
3159 // Setting SSL_VERIFY_PEER allows anonymous clients.
3160 flags: []string{"-verify-peer"},
3161 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003162 }
3163 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003164 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003165 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003167 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003168 ClientAuth: RequireAnyClientCert,
3169 },
3170 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003171 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3172 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003173 },
3174 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003175 tests = append(tests, testCase{
3176 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003177 name: "ClientAuth-RSA-Client-TLS13",
3178 config: Config{
3179 MaxVersion: VersionTLS13,
3180 ClientAuth: RequireAnyClientCert,
3181 },
3182 flags: []string{
3183 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3184 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3185 },
3186 })
3187 tests = append(tests, testCase{
3188 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003189 name: "ClientAuth-ECDSA-Client",
3190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003191 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003192 ClientAuth: RequireAnyClientCert,
3193 },
3194 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003195 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3196 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003197 },
3198 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003199 tests = append(tests, testCase{
3200 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003201 name: "ClientAuth-ECDSA-Client-TLS13",
3202 config: Config{
3203 MaxVersion: VersionTLS13,
3204 ClientAuth: RequireAnyClientCert,
3205 },
3206 flags: []string{
3207 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3208 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3209 },
3210 })
3211 tests = append(tests, testCase{
3212 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003213 name: "ClientAuth-NoCertificate-OldCallback",
3214 config: Config{
3215 MaxVersion: VersionTLS12,
3216 ClientAuth: RequestClientCert,
3217 },
3218 flags: []string{"-use-old-client-cert-callback"},
3219 })
3220 tests = append(tests, testCase{
3221 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003222 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3223 config: Config{
3224 MaxVersion: VersionTLS13,
3225 ClientAuth: RequestClientCert,
3226 },
3227 flags: []string{"-use-old-client-cert-callback"},
3228 })
3229 tests = append(tests, testCase{
3230 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003231 name: "ClientAuth-OldCallback",
3232 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003233 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003234 ClientAuth: RequireAnyClientCert,
3235 },
3236 flags: []string{
3237 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3238 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3239 "-use-old-client-cert-callback",
3240 },
3241 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003242 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003243 testType: clientTest,
3244 name: "ClientAuth-OldCallback-TLS13",
3245 config: Config{
3246 MaxVersion: VersionTLS13,
3247 ClientAuth: RequireAnyClientCert,
3248 },
3249 flags: []string{
3250 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3251 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3252 "-use-old-client-cert-callback",
3253 },
3254 })
3255 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003256 testType: serverTest,
3257 name: "ClientAuth-Server",
3258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003259 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003260 Certificates: []Certificate{rsaCertificate},
3261 },
3262 flags: []string{"-require-any-client-certificate"},
3263 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003264 tests = append(tests, testCase{
3265 testType: serverTest,
3266 name: "ClientAuth-Server-TLS13",
3267 config: Config{
3268 MaxVersion: VersionTLS13,
3269 Certificates: []Certificate{rsaCertificate},
3270 },
3271 flags: []string{"-require-any-client-certificate"},
3272 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003273
David Benjamin4c3ddf72016-06-29 18:13:53 -04003274 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003275 tests = append(tests, testCase{
3276 testType: serverTest,
3277 name: "Basic-Server-RSA",
3278 config: Config{
3279 MaxVersion: VersionTLS12,
3280 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3281 },
3282 flags: []string{
3283 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3284 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3285 },
3286 })
3287 tests = append(tests, testCase{
3288 testType: serverTest,
3289 name: "Basic-Server-ECDHE-RSA",
3290 config: Config{
3291 MaxVersion: VersionTLS12,
3292 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3293 },
3294 flags: []string{
3295 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3296 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3297 },
3298 })
3299 tests = append(tests, testCase{
3300 testType: serverTest,
3301 name: "Basic-Server-ECDHE-ECDSA",
3302 config: Config{
3303 MaxVersion: VersionTLS12,
3304 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3305 },
3306 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003307 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3308 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003309 },
3310 })
3311
David Benjamin760b1dd2015-05-15 23:33:48 -04003312 // No session ticket support; server doesn't send NewSessionTicket.
3313 tests = append(tests, testCase{
3314 name: "SessionTicketsDisabled-Client",
3315 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003316 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003317 SessionTicketsDisabled: true,
3318 },
3319 })
3320 tests = append(tests, testCase{
3321 testType: serverTest,
3322 name: "SessionTicketsDisabled-Server",
3323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003324 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003325 SessionTicketsDisabled: true,
3326 },
3327 })
3328
3329 // Skip ServerKeyExchange in PSK key exchange if there's no
3330 // identity hint.
3331 tests = append(tests, testCase{
3332 name: "EmptyPSKHint-Client",
3333 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003334 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003335 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3336 PreSharedKey: []byte("secret"),
3337 },
3338 flags: []string{"-psk", "secret"},
3339 })
3340 tests = append(tests, testCase{
3341 testType: serverTest,
3342 name: "EmptyPSKHint-Server",
3343 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003344 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3346 PreSharedKey: []byte("secret"),
3347 },
3348 flags: []string{"-psk", "secret"},
3349 })
3350
David Benjamin4c3ddf72016-06-29 18:13:53 -04003351 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003352 tests = append(tests, testCase{
3353 testType: clientTest,
3354 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003355 config: Config{
3356 MaxVersion: VersionTLS12,
3357 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003358 flags: []string{
3359 "-enable-ocsp-stapling",
3360 "-expect-ocsp-response",
3361 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003362 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003363 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003364 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003365 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003366 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003367 testType: serverTest,
3368 name: "OCSPStapling-Server",
3369 config: Config{
3370 MaxVersion: VersionTLS12,
3371 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003372 expectedOCSPResponse: testOCSPResponse,
3373 flags: []string{
3374 "-ocsp-response",
3375 base64.StdEncoding.EncodeToString(testOCSPResponse),
3376 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003377 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003378 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003379 tests = append(tests, testCase{
3380 testType: clientTest,
3381 name: "OCSPStapling-Client-TLS13",
3382 config: Config{
3383 MaxVersion: VersionTLS13,
3384 },
3385 flags: []string{
3386 "-enable-ocsp-stapling",
3387 "-expect-ocsp-response",
3388 base64.StdEncoding.EncodeToString(testOCSPResponse),
3389 "-verify-peer",
3390 },
3391 // TODO(davidben): Enable this when resumption is implemented
3392 // in TLS 1.3.
3393 resumeSession: false,
3394 })
3395 tests = append(tests, testCase{
3396 testType: serverTest,
3397 name: "OCSPStapling-Server-TLS13",
3398 config: Config{
3399 MaxVersion: VersionTLS13,
3400 },
3401 expectedOCSPResponse: testOCSPResponse,
3402 flags: []string{
3403 "-ocsp-response",
3404 base64.StdEncoding.EncodeToString(testOCSPResponse),
3405 },
3406 // TODO(davidben): Enable this when resumption is implemented
3407 // in TLS 1.3.
3408 resumeSession: false,
3409 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003410
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003412 for _, vers := range tlsVersions {
3413 if config.protocol == dtls && !vers.hasDTLS {
3414 continue
3415 }
3416 tests = append(tests, testCase{
3417 testType: clientTest,
3418 name: "CertificateVerificationSucceed-" + vers.name,
3419 config: Config{
3420 MaxVersion: vers.version,
3421 },
3422 flags: []string{
3423 "-verify-peer",
3424 },
Adam Langley9498e742016-07-18 10:17:16 -07003425 resumeSession: vers.version != VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04003426 })
3427 tests = append(tests, testCase{
3428 testType: clientTest,
3429 name: "CertificateVerificationFail-" + vers.name,
3430 config: Config{
3431 MaxVersion: vers.version,
3432 },
3433 flags: []string{
3434 "-verify-fail",
3435 "-verify-peer",
3436 },
3437 shouldFail: true,
3438 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3439 })
3440 tests = append(tests, testCase{
3441 testType: clientTest,
3442 name: "CertificateVerificationSoftFail-" + vers.name,
3443 config: Config{
3444 MaxVersion: vers.version,
3445 },
3446 flags: []string{
3447 "-verify-fail",
3448 "-expect-verify-result",
3449 },
Adam Langley9498e742016-07-18 10:17:16 -07003450 resumeSession: vers.version != VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04003451 })
3452 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003453
David Benjamin1d4f4c02016-07-26 18:03:08 -04003454 tests = append(tests, testCase{
3455 name: "ShimSendAlert",
3456 flags: []string{"-send-alert"},
3457 shimWritesFirst: true,
3458 shouldFail: true,
3459 expectedLocalError: "remote error: decompression failure",
3460 })
3461
David Benjamin582ba042016-07-07 12:33:25 -07003462 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003463 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003464 name: "Renegotiate-Client",
3465 config: Config{
3466 MaxVersion: VersionTLS12,
3467 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003468 renegotiate: 1,
3469 flags: []string{
3470 "-renegotiate-freely",
3471 "-expect-total-renegotiations", "1",
3472 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003473 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003474
David Benjamin47921102016-07-28 11:29:18 -04003475 tests = append(tests, testCase{
3476 name: "SendHalfHelloRequest",
3477 config: Config{
3478 MaxVersion: VersionTLS12,
3479 Bugs: ProtocolBugs{
3480 PackHelloRequestWithFinished: config.packHandshakeFlight,
3481 },
3482 },
3483 sendHalfHelloRequest: true,
3484 flags: []string{"-renegotiate-ignore"},
3485 shouldFail: true,
3486 expectedError: ":UNEXPECTED_RECORD:",
3487 })
3488
David Benjamin760b1dd2015-05-15 23:33:48 -04003489 // NPN on client and server; results in post-handshake message.
3490 tests = append(tests, testCase{
3491 name: "NPN-Client",
3492 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003493 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003494 NextProtos: []string{"foo"},
3495 },
3496 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003497 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003498 expectedNextProto: "foo",
3499 expectedNextProtoType: npn,
3500 })
3501 tests = append(tests, testCase{
3502 testType: serverTest,
3503 name: "NPN-Server",
3504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003505 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003506 NextProtos: []string{"bar"},
3507 },
3508 flags: []string{
3509 "-advertise-npn", "\x03foo\x03bar\x03baz",
3510 "-expect-next-proto", "bar",
3511 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003512 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003513 expectedNextProto: "bar",
3514 expectedNextProtoType: npn,
3515 })
3516
3517 // TODO(davidben): Add tests for when False Start doesn't trigger.
3518
3519 // Client does False Start and negotiates NPN.
3520 tests = append(tests, testCase{
3521 name: "FalseStart",
3522 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003523 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3525 NextProtos: []string{"foo"},
3526 Bugs: ProtocolBugs{
3527 ExpectFalseStart: true,
3528 },
3529 },
3530 flags: []string{
3531 "-false-start",
3532 "-select-next-proto", "foo",
3533 },
3534 shimWritesFirst: true,
3535 resumeSession: true,
3536 })
3537
3538 // Client does False Start and negotiates ALPN.
3539 tests = append(tests, testCase{
3540 name: "FalseStart-ALPN",
3541 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003542 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003543 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3544 NextProtos: []string{"foo"},
3545 Bugs: ProtocolBugs{
3546 ExpectFalseStart: true,
3547 },
3548 },
3549 flags: []string{
3550 "-false-start",
3551 "-advertise-alpn", "\x03foo",
3552 },
3553 shimWritesFirst: true,
3554 resumeSession: true,
3555 })
3556
3557 // Client does False Start but doesn't explicitly call
3558 // SSL_connect.
3559 tests = append(tests, testCase{
3560 name: "FalseStart-Implicit",
3561 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003562 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003563 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3564 NextProtos: []string{"foo"},
3565 },
3566 flags: []string{
3567 "-implicit-handshake",
3568 "-false-start",
3569 "-advertise-alpn", "\x03foo",
3570 },
3571 })
3572
3573 // False Start without session tickets.
3574 tests = append(tests, testCase{
3575 name: "FalseStart-SessionTicketsDisabled",
3576 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003577 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003578 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3579 NextProtos: []string{"foo"},
3580 SessionTicketsDisabled: true,
3581 Bugs: ProtocolBugs{
3582 ExpectFalseStart: true,
3583 },
3584 },
3585 flags: []string{
3586 "-false-start",
3587 "-select-next-proto", "foo",
3588 },
3589 shimWritesFirst: true,
3590 })
3591
Adam Langleydf759b52016-07-11 15:24:37 -07003592 tests = append(tests, testCase{
3593 name: "FalseStart-CECPQ1",
3594 config: Config{
3595 MaxVersion: VersionTLS12,
3596 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3597 NextProtos: []string{"foo"},
3598 Bugs: ProtocolBugs{
3599 ExpectFalseStart: true,
3600 },
3601 },
3602 flags: []string{
3603 "-false-start",
3604 "-cipher", "DEFAULT:kCECPQ1",
3605 "-select-next-proto", "foo",
3606 },
3607 shimWritesFirst: true,
3608 resumeSession: true,
3609 })
3610
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 // Server parses a V2ClientHello.
3612 tests = append(tests, testCase{
3613 testType: serverTest,
3614 name: "SendV2ClientHello",
3615 config: Config{
3616 // Choose a cipher suite that does not involve
3617 // elliptic curves, so no extensions are
3618 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003619 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003620 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3621 Bugs: ProtocolBugs{
3622 SendV2ClientHello: true,
3623 },
3624 },
3625 })
3626
3627 // Client sends a Channel ID.
3628 tests = append(tests, testCase{
3629 name: "ChannelID-Client",
3630 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003631 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003632 RequestChannelID: true,
3633 },
Adam Langley7c803a62015-06-15 15:35:05 -07003634 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003635 resumeSession: true,
3636 expectChannelID: true,
3637 })
3638
3639 // Server accepts a Channel ID.
3640 tests = append(tests, testCase{
3641 testType: serverTest,
3642 name: "ChannelID-Server",
3643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003644 MaxVersion: VersionTLS12,
3645 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003646 },
3647 flags: []string{
3648 "-expect-channel-id",
3649 base64.StdEncoding.EncodeToString(channelIDBytes),
3650 },
3651 resumeSession: true,
3652 expectChannelID: true,
3653 })
David Benjamin30789da2015-08-29 22:56:45 -04003654
David Benjaminf8fcdf32016-06-08 15:56:13 -04003655 // Channel ID and NPN at the same time, to ensure their relative
3656 // ordering is correct.
3657 tests = append(tests, testCase{
3658 name: "ChannelID-NPN-Client",
3659 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003660 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003661 RequestChannelID: true,
3662 NextProtos: []string{"foo"},
3663 },
3664 flags: []string{
3665 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3666 "-select-next-proto", "foo",
3667 },
3668 resumeSession: true,
3669 expectChannelID: true,
3670 expectedNextProto: "foo",
3671 expectedNextProtoType: npn,
3672 })
3673 tests = append(tests, testCase{
3674 testType: serverTest,
3675 name: "ChannelID-NPN-Server",
3676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003677 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003678 ChannelID: channelIDKey,
3679 NextProtos: []string{"bar"},
3680 },
3681 flags: []string{
3682 "-expect-channel-id",
3683 base64.StdEncoding.EncodeToString(channelIDBytes),
3684 "-advertise-npn", "\x03foo\x03bar\x03baz",
3685 "-expect-next-proto", "bar",
3686 },
3687 resumeSession: true,
3688 expectChannelID: true,
3689 expectedNextProto: "bar",
3690 expectedNextProtoType: npn,
3691 })
3692
David Benjamin30789da2015-08-29 22:56:45 -04003693 // Bidirectional shutdown with the runner initiating.
3694 tests = append(tests, testCase{
3695 name: "Shutdown-Runner",
3696 config: Config{
3697 Bugs: ProtocolBugs{
3698 ExpectCloseNotify: true,
3699 },
3700 },
3701 flags: []string{"-check-close-notify"},
3702 })
3703
3704 // Bidirectional shutdown with the shim initiating. The runner,
3705 // in the meantime, sends garbage before the close_notify which
3706 // the shim must ignore.
3707 tests = append(tests, testCase{
3708 name: "Shutdown-Shim",
3709 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003710 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003711 Bugs: ProtocolBugs{
3712 ExpectCloseNotify: true,
3713 },
3714 },
3715 shimShutsDown: true,
3716 sendEmptyRecords: 1,
3717 sendWarningAlerts: 1,
3718 flags: []string{"-check-close-notify"},
3719 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003720 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003721 // TODO(davidben): DTLS 1.3 will want a similar thing for
3722 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 tests = append(tests, testCase{
3724 name: "SkipHelloVerifyRequest",
3725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003726 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003727 Bugs: ProtocolBugs{
3728 SkipHelloVerifyRequest: true,
3729 },
3730 },
3731 })
3732 }
3733
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003735 test.protocol = config.protocol
3736 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003737 test.name += "-DTLS"
3738 }
David Benjamin582ba042016-07-07 12:33:25 -07003739 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003740 test.name += "-Async"
3741 test.flags = append(test.flags, "-async")
3742 } else {
3743 test.name += "-Sync"
3744 }
David Benjamin582ba042016-07-07 12:33:25 -07003745 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003746 test.name += "-SplitHandshakeRecords"
3747 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003748 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003749 test.config.Bugs.MaxPacketLength = 256
3750 test.flags = append(test.flags, "-mtu", "256")
3751 }
3752 }
David Benjamin582ba042016-07-07 12:33:25 -07003753 if config.packHandshakeFlight {
3754 test.name += "-PackHandshakeFlight"
3755 test.config.Bugs.PackHandshakeFlight = true
3756 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003757 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003758 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003759}
3760
Adam Langley524e7172015-02-20 16:04:00 -08003761func addDDoSCallbackTests() {
3762 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003763 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003764 for _, resume := range []bool{false, true} {
3765 suffix := "Resume"
3766 if resume {
3767 suffix = "No" + suffix
3768 }
3769
3770 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003771 testType: serverTest,
3772 name: "Server-DDoS-OK-" + suffix,
3773 config: Config{
3774 MaxVersion: VersionTLS12,
3775 },
Adam Langley524e7172015-02-20 16:04:00 -08003776 flags: []string{"-install-ddos-callback"},
3777 resumeSession: resume,
3778 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003779 if !resume {
3780 testCases = append(testCases, testCase{
3781 testType: serverTest,
3782 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3783 config: Config{
3784 MaxVersion: VersionTLS13,
3785 },
3786 flags: []string{"-install-ddos-callback"},
3787 resumeSession: resume,
3788 })
3789 }
Adam Langley524e7172015-02-20 16:04:00 -08003790
3791 failFlag := "-fail-ddos-callback"
3792 if resume {
3793 failFlag = "-fail-second-ddos-callback"
3794 }
3795 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003796 testType: serverTest,
3797 name: "Server-DDoS-Reject-" + suffix,
3798 config: Config{
3799 MaxVersion: VersionTLS12,
3800 },
Adam Langley524e7172015-02-20 16:04:00 -08003801 flags: []string{"-install-ddos-callback", failFlag},
3802 resumeSession: resume,
3803 shouldFail: true,
3804 expectedError: ":CONNECTION_REJECTED:",
3805 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003806 if !resume {
3807 testCases = append(testCases, testCase{
3808 testType: serverTest,
3809 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3810 config: Config{
3811 MaxVersion: VersionTLS13,
3812 },
3813 flags: []string{"-install-ddos-callback", failFlag},
3814 resumeSession: resume,
3815 shouldFail: true,
3816 expectedError: ":CONNECTION_REJECTED:",
3817 })
3818 }
Adam Langley524e7172015-02-20 16:04:00 -08003819 }
3820}
3821
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003822func addVersionNegotiationTests() {
3823 for i, shimVers := range tlsVersions {
3824 // Assemble flags to disable all newer versions on the shim.
3825 var flags []string
3826 for _, vers := range tlsVersions[i+1:] {
3827 flags = append(flags, vers.flag)
3828 }
3829
3830 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003831 protocols := []protocol{tls}
3832 if runnerVers.hasDTLS && shimVers.hasDTLS {
3833 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003834 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003835 for _, protocol := range protocols {
3836 expectedVersion := shimVers.version
3837 if runnerVers.version < shimVers.version {
3838 expectedVersion = runnerVers.version
3839 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003840
David Benjamin8b8c0062014-11-23 02:47:52 -05003841 suffix := shimVers.name + "-" + runnerVers.name
3842 if protocol == dtls {
3843 suffix += "-DTLS"
3844 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003845
David Benjamin1eb367c2014-12-12 18:17:51 -05003846 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3847
David Benjamin1e29a6b2014-12-10 02:27:24 -05003848 clientVers := shimVers.version
3849 if clientVers > VersionTLS10 {
3850 clientVers = VersionTLS10
3851 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003852 serverVers := expectedVersion
3853 if expectedVersion >= VersionTLS13 {
3854 serverVers = VersionTLS10
3855 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003856 testCases = append(testCases, testCase{
3857 protocol: protocol,
3858 testType: clientTest,
3859 name: "VersionNegotiation-Client-" + suffix,
3860 config: Config{
3861 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003862 Bugs: ProtocolBugs{
3863 ExpectInitialRecordVersion: clientVers,
3864 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003865 },
3866 flags: flags,
3867 expectedVersion: expectedVersion,
3868 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003869 testCases = append(testCases, testCase{
3870 protocol: protocol,
3871 testType: clientTest,
3872 name: "VersionNegotiation-Client2-" + suffix,
3873 config: Config{
3874 MaxVersion: runnerVers.version,
3875 Bugs: ProtocolBugs{
3876 ExpectInitialRecordVersion: clientVers,
3877 },
3878 },
3879 flags: []string{"-max-version", shimVersFlag},
3880 expectedVersion: expectedVersion,
3881 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003882
3883 testCases = append(testCases, testCase{
3884 protocol: protocol,
3885 testType: serverTest,
3886 name: "VersionNegotiation-Server-" + suffix,
3887 config: Config{
3888 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003889 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003890 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003891 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003892 },
3893 flags: flags,
3894 expectedVersion: expectedVersion,
3895 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003896 testCases = append(testCases, testCase{
3897 protocol: protocol,
3898 testType: serverTest,
3899 name: "VersionNegotiation-Server2-" + suffix,
3900 config: Config{
3901 MaxVersion: runnerVers.version,
3902 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003903 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003904 },
3905 },
3906 flags: []string{"-max-version", shimVersFlag},
3907 expectedVersion: expectedVersion,
3908 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003909 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003910 }
3911 }
David Benjamin95c69562016-06-29 18:15:03 -04003912
3913 // Test for version tolerance.
3914 testCases = append(testCases, testCase{
3915 testType: serverTest,
3916 name: "MinorVersionTolerance",
3917 config: Config{
3918 Bugs: ProtocolBugs{
3919 SendClientVersion: 0x03ff,
3920 },
3921 },
3922 expectedVersion: VersionTLS13,
3923 })
3924 testCases = append(testCases, testCase{
3925 testType: serverTest,
3926 name: "MajorVersionTolerance",
3927 config: Config{
3928 Bugs: ProtocolBugs{
3929 SendClientVersion: 0x0400,
3930 },
3931 },
3932 expectedVersion: VersionTLS13,
3933 })
3934 testCases = append(testCases, testCase{
3935 protocol: dtls,
3936 testType: serverTest,
3937 name: "MinorVersionTolerance-DTLS",
3938 config: Config{
3939 Bugs: ProtocolBugs{
3940 SendClientVersion: 0x03ff,
3941 },
3942 },
3943 expectedVersion: VersionTLS12,
3944 })
3945 testCases = append(testCases, testCase{
3946 protocol: dtls,
3947 testType: serverTest,
3948 name: "MajorVersionTolerance-DTLS",
3949 config: Config{
3950 Bugs: ProtocolBugs{
3951 SendClientVersion: 0x0400,
3952 },
3953 },
3954 expectedVersion: VersionTLS12,
3955 })
3956
3957 // Test that versions below 3.0 are rejected.
3958 testCases = append(testCases, testCase{
3959 testType: serverTest,
3960 name: "VersionTooLow",
3961 config: Config{
3962 Bugs: ProtocolBugs{
3963 SendClientVersion: 0x0200,
3964 },
3965 },
3966 shouldFail: true,
3967 expectedError: ":UNSUPPORTED_PROTOCOL:",
3968 })
3969 testCases = append(testCases, testCase{
3970 protocol: dtls,
3971 testType: serverTest,
3972 name: "VersionTooLow-DTLS",
3973 config: Config{
3974 Bugs: ProtocolBugs{
3975 // 0x0201 is the lowest version expressable in
3976 // DTLS.
3977 SendClientVersion: 0x0201,
3978 },
3979 },
3980 shouldFail: true,
3981 expectedError: ":UNSUPPORTED_PROTOCOL:",
3982 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003983
3984 // Test TLS 1.3's downgrade signal.
3985 testCases = append(testCases, testCase{
3986 name: "Downgrade-TLS12-Client",
3987 config: Config{
3988 Bugs: ProtocolBugs{
3989 NegotiateVersion: VersionTLS12,
3990 },
3991 },
3992 shouldFail: true,
3993 expectedError: ":DOWNGRADE_DETECTED:",
3994 })
3995 testCases = append(testCases, testCase{
3996 testType: serverTest,
3997 name: "Downgrade-TLS12-Server",
3998 config: Config{
3999 Bugs: ProtocolBugs{
4000 SendClientVersion: VersionTLS12,
4001 },
4002 },
4003 shouldFail: true,
4004 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4005 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004006
4007 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4008 // behave correctly when both real maximum and fallback versions are
4009 // set.
4010 testCases = append(testCases, testCase{
4011 name: "Downgrade-TLS12-Client-Fallback",
4012 config: Config{
4013 Bugs: ProtocolBugs{
4014 FailIfNotFallbackSCSV: true,
4015 },
4016 },
4017 flags: []string{
4018 "-max-version", strconv.Itoa(VersionTLS13),
4019 "-fallback-version", strconv.Itoa(VersionTLS12),
4020 },
4021 shouldFail: true,
4022 expectedError: ":DOWNGRADE_DETECTED:",
4023 })
4024 testCases = append(testCases, testCase{
4025 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4026 flags: []string{
4027 "-max-version", strconv.Itoa(VersionTLS12),
4028 "-fallback-version", strconv.Itoa(VersionTLS12),
4029 },
4030 })
4031
4032 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4033 // just have such connections fail than risk getting confused because we
4034 // didn't sent the 1.3 ClientHello.)
4035 testCases = append(testCases, testCase{
4036 name: "Downgrade-TLS12-Fallback-CheckVersion",
4037 config: Config{
4038 Bugs: ProtocolBugs{
4039 NegotiateVersion: VersionTLS13,
4040 FailIfNotFallbackSCSV: true,
4041 },
4042 },
4043 flags: []string{
4044 "-max-version", strconv.Itoa(VersionTLS13),
4045 "-fallback-version", strconv.Itoa(VersionTLS12),
4046 },
4047 shouldFail: true,
4048 expectedError: ":UNSUPPORTED_PROTOCOL:",
4049 })
4050
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004051}
4052
David Benjaminaccb4542014-12-12 23:44:33 -05004053func addMinimumVersionTests() {
4054 for i, shimVers := range tlsVersions {
4055 // Assemble flags to disable all older versions on the shim.
4056 var flags []string
4057 for _, vers := range tlsVersions[:i] {
4058 flags = append(flags, vers.flag)
4059 }
4060
4061 for _, runnerVers := range tlsVersions {
4062 protocols := []protocol{tls}
4063 if runnerVers.hasDTLS && shimVers.hasDTLS {
4064 protocols = append(protocols, dtls)
4065 }
4066 for _, protocol := range protocols {
4067 suffix := shimVers.name + "-" + runnerVers.name
4068 if protocol == dtls {
4069 suffix += "-DTLS"
4070 }
4071 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4072
David Benjaminaccb4542014-12-12 23:44:33 -05004073 var expectedVersion uint16
4074 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004075 var expectedClientError, expectedServerError string
4076 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004077 if runnerVers.version >= shimVers.version {
4078 expectedVersion = runnerVers.version
4079 } else {
4080 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004081 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4082 expectedServerLocalError = "remote error: protocol version not supported"
4083 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4084 // If the client's minimum version is TLS 1.3 and the runner's
4085 // maximum is below TLS 1.2, the runner will fail to select a
4086 // cipher before the shim rejects the selected version.
4087 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4088 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4089 } else {
4090 expectedClientError = expectedServerError
4091 expectedClientLocalError = expectedServerLocalError
4092 }
David Benjaminaccb4542014-12-12 23:44:33 -05004093 }
4094
4095 testCases = append(testCases, testCase{
4096 protocol: protocol,
4097 testType: clientTest,
4098 name: "MinimumVersion-Client-" + suffix,
4099 config: Config{
4100 MaxVersion: runnerVers.version,
4101 },
David Benjamin87909c02014-12-13 01:55:01 -05004102 flags: flags,
4103 expectedVersion: expectedVersion,
4104 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004105 expectedError: expectedClientError,
4106 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004107 })
4108 testCases = append(testCases, testCase{
4109 protocol: protocol,
4110 testType: clientTest,
4111 name: "MinimumVersion-Client2-" + suffix,
4112 config: Config{
4113 MaxVersion: runnerVers.version,
4114 },
David Benjamin87909c02014-12-13 01:55:01 -05004115 flags: []string{"-min-version", shimVersFlag},
4116 expectedVersion: expectedVersion,
4117 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004118 expectedError: expectedClientError,
4119 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004120 })
4121
4122 testCases = append(testCases, testCase{
4123 protocol: protocol,
4124 testType: serverTest,
4125 name: "MinimumVersion-Server-" + suffix,
4126 config: Config{
4127 MaxVersion: runnerVers.version,
4128 },
David Benjamin87909c02014-12-13 01:55:01 -05004129 flags: flags,
4130 expectedVersion: expectedVersion,
4131 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004132 expectedError: expectedServerError,
4133 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004134 })
4135 testCases = append(testCases, testCase{
4136 protocol: protocol,
4137 testType: serverTest,
4138 name: "MinimumVersion-Server2-" + suffix,
4139 config: Config{
4140 MaxVersion: runnerVers.version,
4141 },
David Benjamin87909c02014-12-13 01:55:01 -05004142 flags: []string{"-min-version", shimVersFlag},
4143 expectedVersion: expectedVersion,
4144 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004145 expectedError: expectedServerError,
4146 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004147 })
4148 }
4149 }
4150 }
4151}
4152
David Benjamine78bfde2014-09-06 12:45:15 -04004153func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004154 // TODO(davidben): Extensions, where applicable, all move their server
4155 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4156 // tests for both. Also test interaction with 0-RTT when implemented.
4157
David Benjamin97d17d92016-07-14 16:12:00 -04004158 // Repeat extensions tests all versions except SSL 3.0.
4159 for _, ver := range tlsVersions {
4160 if ver.version == VersionSSL30 {
4161 continue
4162 }
4163
4164 // TODO(davidben): Implement resumption in TLS 1.3.
4165 resumeSession := ver.version < VersionTLS13
4166
4167 // Test that duplicate extensions are rejected.
4168 testCases = append(testCases, testCase{
4169 testType: clientTest,
4170 name: "DuplicateExtensionClient-" + ver.name,
4171 config: Config{
4172 MaxVersion: ver.version,
4173 Bugs: ProtocolBugs{
4174 DuplicateExtension: true,
4175 },
David Benjamine78bfde2014-09-06 12:45:15 -04004176 },
David Benjamin97d17d92016-07-14 16:12:00 -04004177 shouldFail: true,
4178 expectedLocalError: "remote error: error decoding message",
4179 })
4180 testCases = append(testCases, testCase{
4181 testType: serverTest,
4182 name: "DuplicateExtensionServer-" + ver.name,
4183 config: Config{
4184 MaxVersion: ver.version,
4185 Bugs: ProtocolBugs{
4186 DuplicateExtension: true,
4187 },
David Benjamine78bfde2014-09-06 12:45:15 -04004188 },
David Benjamin97d17d92016-07-14 16:12:00 -04004189 shouldFail: true,
4190 expectedLocalError: "remote error: error decoding message",
4191 })
4192
4193 // Test SNI.
4194 testCases = append(testCases, testCase{
4195 testType: clientTest,
4196 name: "ServerNameExtensionClient-" + ver.name,
4197 config: Config{
4198 MaxVersion: ver.version,
4199 Bugs: ProtocolBugs{
4200 ExpectServerName: "example.com",
4201 },
David Benjamine78bfde2014-09-06 12:45:15 -04004202 },
David Benjamin97d17d92016-07-14 16:12:00 -04004203 flags: []string{"-host-name", "example.com"},
4204 })
4205 testCases = append(testCases, testCase{
4206 testType: clientTest,
4207 name: "ServerNameExtensionClientMismatch-" + ver.name,
4208 config: Config{
4209 MaxVersion: ver.version,
4210 Bugs: ProtocolBugs{
4211 ExpectServerName: "mismatch.com",
4212 },
David Benjamine78bfde2014-09-06 12:45:15 -04004213 },
David Benjamin97d17d92016-07-14 16:12:00 -04004214 flags: []string{"-host-name", "example.com"},
4215 shouldFail: true,
4216 expectedLocalError: "tls: unexpected server name",
4217 })
4218 testCases = append(testCases, testCase{
4219 testType: clientTest,
4220 name: "ServerNameExtensionClientMissing-" + ver.name,
4221 config: Config{
4222 MaxVersion: ver.version,
4223 Bugs: ProtocolBugs{
4224 ExpectServerName: "missing.com",
4225 },
David Benjamine78bfde2014-09-06 12:45:15 -04004226 },
David Benjamin97d17d92016-07-14 16:12:00 -04004227 shouldFail: true,
4228 expectedLocalError: "tls: unexpected server name",
4229 })
4230 testCases = append(testCases, testCase{
4231 testType: serverTest,
4232 name: "ServerNameExtensionServer-" + ver.name,
4233 config: Config{
4234 MaxVersion: ver.version,
4235 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004236 },
David Benjamin97d17d92016-07-14 16:12:00 -04004237 flags: []string{"-expect-server-name", "example.com"},
4238 resumeSession: resumeSession,
4239 })
4240
4241 // Test ALPN.
4242 testCases = append(testCases, testCase{
4243 testType: clientTest,
4244 name: "ALPNClient-" + ver.name,
4245 config: Config{
4246 MaxVersion: ver.version,
4247 NextProtos: []string{"foo"},
4248 },
4249 flags: []string{
4250 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4251 "-expect-alpn", "foo",
4252 },
4253 expectedNextProto: "foo",
4254 expectedNextProtoType: alpn,
4255 resumeSession: resumeSession,
4256 })
4257 testCases = append(testCases, testCase{
4258 testType: serverTest,
4259 name: "ALPNServer-" + ver.name,
4260 config: Config{
4261 MaxVersion: ver.version,
4262 NextProtos: []string{"foo", "bar", "baz"},
4263 },
4264 flags: []string{
4265 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4266 "-select-alpn", "foo",
4267 },
4268 expectedNextProto: "foo",
4269 expectedNextProtoType: alpn,
4270 resumeSession: resumeSession,
4271 })
4272 testCases = append(testCases, testCase{
4273 testType: serverTest,
4274 name: "ALPNServer-Decline-" + ver.name,
4275 config: Config{
4276 MaxVersion: ver.version,
4277 NextProtos: []string{"foo", "bar", "baz"},
4278 },
4279 flags: []string{"-decline-alpn"},
4280 expectNoNextProto: true,
4281 resumeSession: resumeSession,
4282 })
4283
4284 var emptyString string
4285 testCases = append(testCases, testCase{
4286 testType: clientTest,
4287 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4288 config: Config{
4289 MaxVersion: ver.version,
4290 NextProtos: []string{""},
4291 Bugs: ProtocolBugs{
4292 // A server returning an empty ALPN protocol
4293 // should be rejected.
4294 ALPNProtocol: &emptyString,
4295 },
4296 },
4297 flags: []string{
4298 "-advertise-alpn", "\x03foo",
4299 },
4300 shouldFail: true,
4301 expectedError: ":PARSE_TLSEXT:",
4302 })
4303 testCases = append(testCases, testCase{
4304 testType: serverTest,
4305 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4306 config: Config{
4307 MaxVersion: ver.version,
4308 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004309 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004310 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004311 },
David Benjamin97d17d92016-07-14 16:12:00 -04004312 flags: []string{
4313 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004314 },
David Benjamin97d17d92016-07-14 16:12:00 -04004315 shouldFail: true,
4316 expectedError: ":PARSE_TLSEXT:",
4317 })
4318
4319 // Test NPN and the interaction with ALPN.
4320 if ver.version < VersionTLS13 {
4321 // Test that the server prefers ALPN over NPN.
4322 testCases = append(testCases, testCase{
4323 testType: serverTest,
4324 name: "ALPNServer-Preferred-" + ver.name,
4325 config: Config{
4326 MaxVersion: ver.version,
4327 NextProtos: []string{"foo", "bar", "baz"},
4328 },
4329 flags: []string{
4330 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4331 "-select-alpn", "foo",
4332 "-advertise-npn", "\x03foo\x03bar\x03baz",
4333 },
4334 expectedNextProto: "foo",
4335 expectedNextProtoType: alpn,
4336 resumeSession: resumeSession,
4337 })
4338 testCases = append(testCases, testCase{
4339 testType: serverTest,
4340 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4341 config: Config{
4342 MaxVersion: ver.version,
4343 NextProtos: []string{"foo", "bar", "baz"},
4344 Bugs: ProtocolBugs{
4345 SwapNPNAndALPN: true,
4346 },
4347 },
4348 flags: []string{
4349 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4350 "-select-alpn", "foo",
4351 "-advertise-npn", "\x03foo\x03bar\x03baz",
4352 },
4353 expectedNextProto: "foo",
4354 expectedNextProtoType: alpn,
4355 resumeSession: resumeSession,
4356 })
4357
4358 // Test that negotiating both NPN and ALPN is forbidden.
4359 testCases = append(testCases, testCase{
4360 name: "NegotiateALPNAndNPN-" + ver.name,
4361 config: Config{
4362 MaxVersion: ver.version,
4363 NextProtos: []string{"foo", "bar", "baz"},
4364 Bugs: ProtocolBugs{
4365 NegotiateALPNAndNPN: true,
4366 },
4367 },
4368 flags: []string{
4369 "-advertise-alpn", "\x03foo",
4370 "-select-next-proto", "foo",
4371 },
4372 shouldFail: true,
4373 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4374 })
4375 testCases = append(testCases, testCase{
4376 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4377 config: Config{
4378 MaxVersion: ver.version,
4379 NextProtos: []string{"foo", "bar", "baz"},
4380 Bugs: ProtocolBugs{
4381 NegotiateALPNAndNPN: true,
4382 SwapNPNAndALPN: true,
4383 },
4384 },
4385 flags: []string{
4386 "-advertise-alpn", "\x03foo",
4387 "-select-next-proto", "foo",
4388 },
4389 shouldFail: true,
4390 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4391 })
4392
4393 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4394 testCases = append(testCases, testCase{
4395 name: "DisableNPN-" + ver.name,
4396 config: Config{
4397 MaxVersion: ver.version,
4398 NextProtos: []string{"foo"},
4399 },
4400 flags: []string{
4401 "-select-next-proto", "foo",
4402 "-disable-npn",
4403 },
4404 expectNoNextProto: true,
4405 })
4406 }
4407
4408 // Test ticket behavior.
4409 //
4410 // TODO(davidben): Add TLS 1.3 versions of these.
4411 if ver.version < VersionTLS13 {
4412 // Resume with a corrupt ticket.
4413 testCases = append(testCases, testCase{
4414 testType: serverTest,
4415 name: "CorruptTicket-" + ver.name,
4416 config: Config{
4417 MaxVersion: ver.version,
4418 Bugs: ProtocolBugs{
4419 CorruptTicket: true,
4420 },
4421 },
4422 resumeSession: true,
4423 expectResumeRejected: true,
4424 })
4425 // Test the ticket callback, with and without renewal.
4426 testCases = append(testCases, testCase{
4427 testType: serverTest,
4428 name: "TicketCallback-" + ver.name,
4429 config: Config{
4430 MaxVersion: ver.version,
4431 },
4432 resumeSession: true,
4433 flags: []string{"-use-ticket-callback"},
4434 })
4435 testCases = append(testCases, testCase{
4436 testType: serverTest,
4437 name: "TicketCallback-Renew-" + ver.name,
4438 config: Config{
4439 MaxVersion: ver.version,
4440 Bugs: ProtocolBugs{
4441 ExpectNewTicket: true,
4442 },
4443 },
4444 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4445 resumeSession: true,
4446 })
4447
4448 // Resume with an oversized session id.
4449 testCases = append(testCases, testCase{
4450 testType: serverTest,
4451 name: "OversizedSessionId-" + ver.name,
4452 config: Config{
4453 MaxVersion: ver.version,
4454 Bugs: ProtocolBugs{
4455 OversizedSessionId: true,
4456 },
4457 },
4458 resumeSession: true,
4459 shouldFail: true,
4460 expectedError: ":DECODE_ERROR:",
4461 })
4462 }
4463
4464 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4465 // are ignored.
4466 if ver.hasDTLS {
4467 testCases = append(testCases, testCase{
4468 protocol: dtls,
4469 name: "SRTP-Client-" + ver.name,
4470 config: Config{
4471 MaxVersion: ver.version,
4472 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4473 },
4474 flags: []string{
4475 "-srtp-profiles",
4476 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4477 },
4478 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4479 })
4480 testCases = append(testCases, testCase{
4481 protocol: dtls,
4482 testType: serverTest,
4483 name: "SRTP-Server-" + ver.name,
4484 config: Config{
4485 MaxVersion: ver.version,
4486 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4487 },
4488 flags: []string{
4489 "-srtp-profiles",
4490 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4491 },
4492 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4493 })
4494 // Test that the MKI is ignored.
4495 testCases = append(testCases, testCase{
4496 protocol: dtls,
4497 testType: serverTest,
4498 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4499 config: Config{
4500 MaxVersion: ver.version,
4501 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4502 Bugs: ProtocolBugs{
4503 SRTPMasterKeyIdentifer: "bogus",
4504 },
4505 },
4506 flags: []string{
4507 "-srtp-profiles",
4508 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4509 },
4510 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4511 })
4512 // Test that SRTP isn't negotiated on the server if there were
4513 // no matching profiles.
4514 testCases = append(testCases, testCase{
4515 protocol: dtls,
4516 testType: serverTest,
4517 name: "SRTP-Server-NoMatch-" + ver.name,
4518 config: Config{
4519 MaxVersion: ver.version,
4520 SRTPProtectionProfiles: []uint16{100, 101, 102},
4521 },
4522 flags: []string{
4523 "-srtp-profiles",
4524 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4525 },
4526 expectedSRTPProtectionProfile: 0,
4527 })
4528 // Test that the server returning an invalid SRTP profile is
4529 // flagged as an error by the client.
4530 testCases = append(testCases, testCase{
4531 protocol: dtls,
4532 name: "SRTP-Client-NoMatch-" + ver.name,
4533 config: Config{
4534 MaxVersion: ver.version,
4535 Bugs: ProtocolBugs{
4536 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4537 },
4538 },
4539 flags: []string{
4540 "-srtp-profiles",
4541 "SRTP_AES128_CM_SHA1_80",
4542 },
4543 shouldFail: true,
4544 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4545 })
4546 }
4547
4548 // Test SCT list.
4549 testCases = append(testCases, testCase{
4550 name: "SignedCertificateTimestampList-Client-" + ver.name,
4551 testType: clientTest,
4552 config: Config{
4553 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004554 },
David Benjamin97d17d92016-07-14 16:12:00 -04004555 flags: []string{
4556 "-enable-signed-cert-timestamps",
4557 "-expect-signed-cert-timestamps",
4558 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004559 },
David Benjamin97d17d92016-07-14 16:12:00 -04004560 resumeSession: resumeSession,
4561 })
4562 testCases = append(testCases, testCase{
4563 name: "SendSCTListOnResume-" + ver.name,
4564 config: Config{
4565 MaxVersion: ver.version,
4566 Bugs: ProtocolBugs{
4567 SendSCTListOnResume: []byte("bogus"),
4568 },
David Benjamind98452d2015-06-16 14:16:23 -04004569 },
David Benjamin97d17d92016-07-14 16:12:00 -04004570 flags: []string{
4571 "-enable-signed-cert-timestamps",
4572 "-expect-signed-cert-timestamps",
4573 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004574 },
David Benjamin97d17d92016-07-14 16:12:00 -04004575 resumeSession: resumeSession,
4576 })
4577 testCases = append(testCases, testCase{
4578 name: "SignedCertificateTimestampList-Server-" + ver.name,
4579 testType: serverTest,
4580 config: Config{
4581 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004582 },
David Benjamin97d17d92016-07-14 16:12:00 -04004583 flags: []string{
4584 "-signed-cert-timestamps",
4585 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004586 },
David Benjamin97d17d92016-07-14 16:12:00 -04004587 expectedSCTList: testSCTList,
4588 resumeSession: resumeSession,
4589 })
4590 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004591
Paul Lietar4fac72e2015-09-09 13:44:55 +01004592 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004593 testType: clientTest,
4594 name: "ClientHelloPadding",
4595 config: Config{
4596 Bugs: ProtocolBugs{
4597 RequireClientHelloSize: 512,
4598 },
4599 },
4600 // This hostname just needs to be long enough to push the
4601 // ClientHello into F5's danger zone between 256 and 511 bytes
4602 // long.
4603 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4604 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004605
4606 // Extensions should not function in SSL 3.0.
4607 testCases = append(testCases, testCase{
4608 testType: serverTest,
4609 name: "SSLv3Extensions-NoALPN",
4610 config: Config{
4611 MaxVersion: VersionSSL30,
4612 NextProtos: []string{"foo", "bar", "baz"},
4613 },
4614 flags: []string{
4615 "-select-alpn", "foo",
4616 },
4617 expectNoNextProto: true,
4618 })
4619
4620 // Test session tickets separately as they follow a different codepath.
4621 testCases = append(testCases, testCase{
4622 testType: serverTest,
4623 name: "SSLv3Extensions-NoTickets",
4624 config: Config{
4625 MaxVersion: VersionSSL30,
4626 Bugs: ProtocolBugs{
4627 // Historically, session tickets in SSL 3.0
4628 // failed in different ways depending on whether
4629 // the client supported renegotiation_info.
4630 NoRenegotiationInfo: true,
4631 },
4632 },
4633 resumeSession: true,
4634 })
4635 testCases = append(testCases, testCase{
4636 testType: serverTest,
4637 name: "SSLv3Extensions-NoTickets2",
4638 config: Config{
4639 MaxVersion: VersionSSL30,
4640 },
4641 resumeSession: true,
4642 })
4643
4644 // But SSL 3.0 does send and process renegotiation_info.
4645 testCases = append(testCases, testCase{
4646 testType: serverTest,
4647 name: "SSLv3Extensions-RenegotiationInfo",
4648 config: Config{
4649 MaxVersion: VersionSSL30,
4650 Bugs: ProtocolBugs{
4651 RequireRenegotiationInfo: true,
4652 },
4653 },
4654 })
4655 testCases = append(testCases, testCase{
4656 testType: serverTest,
4657 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4658 config: Config{
4659 MaxVersion: VersionSSL30,
4660 Bugs: ProtocolBugs{
4661 NoRenegotiationInfo: true,
4662 SendRenegotiationSCSV: true,
4663 RequireRenegotiationInfo: true,
4664 },
4665 },
4666 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004667
4668 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4669 // in ServerHello.
4670 testCases = append(testCases, testCase{
4671 name: "NPN-Forbidden-TLS13",
4672 config: Config{
4673 MaxVersion: VersionTLS13,
4674 NextProtos: []string{"foo"},
4675 Bugs: ProtocolBugs{
4676 NegotiateNPNAtAllVersions: true,
4677 },
4678 },
4679 flags: []string{"-select-next-proto", "foo"},
4680 shouldFail: true,
4681 expectedError: ":ERROR_PARSING_EXTENSION:",
4682 })
4683 testCases = append(testCases, testCase{
4684 name: "EMS-Forbidden-TLS13",
4685 config: Config{
4686 MaxVersion: VersionTLS13,
4687 Bugs: ProtocolBugs{
4688 NegotiateEMSAtAllVersions: true,
4689 },
4690 },
4691 shouldFail: true,
4692 expectedError: ":ERROR_PARSING_EXTENSION:",
4693 })
4694 testCases = append(testCases, testCase{
4695 name: "RenegotiationInfo-Forbidden-TLS13",
4696 config: Config{
4697 MaxVersion: VersionTLS13,
4698 Bugs: ProtocolBugs{
4699 NegotiateRenegotiationInfoAtAllVersions: true,
4700 },
4701 },
4702 shouldFail: true,
4703 expectedError: ":ERROR_PARSING_EXTENSION:",
4704 })
4705 testCases = append(testCases, testCase{
4706 name: "ChannelID-Forbidden-TLS13",
4707 config: Config{
4708 MaxVersion: VersionTLS13,
4709 RequestChannelID: true,
4710 Bugs: ProtocolBugs{
4711 NegotiateChannelIDAtAllVersions: true,
4712 },
4713 },
4714 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4715 shouldFail: true,
4716 expectedError: ":ERROR_PARSING_EXTENSION:",
4717 })
4718 testCases = append(testCases, testCase{
4719 name: "Ticket-Forbidden-TLS13",
4720 config: Config{
4721 MaxVersion: VersionTLS12,
4722 },
4723 resumeConfig: &Config{
4724 MaxVersion: VersionTLS13,
4725 Bugs: ProtocolBugs{
4726 AdvertiseTicketExtension: true,
4727 },
4728 },
4729 resumeSession: true,
4730 shouldFail: true,
4731 expectedError: ":ERROR_PARSING_EXTENSION:",
4732 })
4733
4734 // Test that illegal extensions in TLS 1.3 are declined by the server if
4735 // offered in ClientHello. The runner's server will fail if this occurs,
4736 // so we exercise the offering path. (EMS and Renegotiation Info are
4737 // implicit in every test.)
4738 testCases = append(testCases, testCase{
4739 testType: serverTest,
4740 name: "ChannelID-Declined-TLS13",
4741 config: Config{
4742 MaxVersion: VersionTLS13,
4743 ChannelID: channelIDKey,
4744 },
4745 flags: []string{"-enable-channel-id"},
4746 })
4747 testCases = append(testCases, testCase{
4748 testType: serverTest,
4749 name: "NPN-Server",
4750 config: Config{
4751 MaxVersion: VersionTLS13,
4752 NextProtos: []string{"bar"},
4753 },
4754 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4755 })
David Benjamine78bfde2014-09-06 12:45:15 -04004756}
4757
David Benjamin01fe8202014-09-24 15:21:44 -04004758func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004759 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004760 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4761 if sessionVers.version >= VersionTLS13 {
4762 continue
4763 }
David Benjamin01fe8202014-09-24 15:21:44 -04004764 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004765 if resumeVers.version >= VersionTLS13 {
4766 continue
4767 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004768 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4769 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4770 // TLS 1.3 only shares ciphers with TLS 1.2, so
4771 // we skip certain combinations and use a
4772 // different cipher to test with.
4773 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4774 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4775 continue
4776 }
4777 }
4778
David Benjamin8b8c0062014-11-23 02:47:52 -05004779 protocols := []protocol{tls}
4780 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4781 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004782 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004783 for _, protocol := range protocols {
4784 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4785 if protocol == dtls {
4786 suffix += "-DTLS"
4787 }
4788
David Benjaminece3de92015-03-16 18:02:20 -04004789 if sessionVers.version == resumeVers.version {
4790 testCases = append(testCases, testCase{
4791 protocol: protocol,
4792 name: "Resume-Client" + suffix,
4793 resumeSession: true,
4794 config: Config{
4795 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004796 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004797 },
David Benjaminece3de92015-03-16 18:02:20 -04004798 expectedVersion: sessionVers.version,
4799 expectedResumeVersion: resumeVers.version,
4800 })
4801 } else {
4802 testCases = append(testCases, testCase{
4803 protocol: protocol,
4804 name: "Resume-Client-Mismatch" + suffix,
4805 resumeSession: true,
4806 config: Config{
4807 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004808 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004809 },
David Benjaminece3de92015-03-16 18:02:20 -04004810 expectedVersion: sessionVers.version,
4811 resumeConfig: &Config{
4812 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004813 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004814 Bugs: ProtocolBugs{
4815 AllowSessionVersionMismatch: true,
4816 },
4817 },
4818 expectedResumeVersion: resumeVers.version,
4819 shouldFail: true,
4820 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4821 })
4822 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004823
4824 testCases = append(testCases, testCase{
4825 protocol: protocol,
4826 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004827 resumeSession: true,
4828 config: Config{
4829 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004830 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004831 },
4832 expectedVersion: sessionVers.version,
4833 resumeConfig: &Config{
4834 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004835 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004836 },
4837 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004838 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004839 expectedResumeVersion: resumeVers.version,
4840 })
4841
David Benjamin8b8c0062014-11-23 02:47:52 -05004842 testCases = append(testCases, testCase{
4843 protocol: protocol,
4844 testType: serverTest,
4845 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004846 resumeSession: true,
4847 config: Config{
4848 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004849 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004850 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004851 expectedVersion: sessionVers.version,
4852 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004853 resumeConfig: &Config{
4854 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004855 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004856 },
4857 expectedResumeVersion: resumeVers.version,
4858 })
4859 }
David Benjamin01fe8202014-09-24 15:21:44 -04004860 }
4861 }
David Benjaminece3de92015-03-16 18:02:20 -04004862
Nick Harper1fd39d82016-06-14 18:14:35 -07004863 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004864 testCases = append(testCases, testCase{
4865 name: "Resume-Client-CipherMismatch",
4866 resumeSession: true,
4867 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004868 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004869 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4870 },
4871 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004872 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004873 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4874 Bugs: ProtocolBugs{
4875 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4876 },
4877 },
4878 shouldFail: true,
4879 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4880 })
David Benjamin01fe8202014-09-24 15:21:44 -04004881}
4882
Adam Langley2ae77d22014-10-28 17:29:33 -07004883func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004884 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004885 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004886 testType: serverTest,
4887 name: "Renegotiate-Server-Forbidden",
4888 config: Config{
4889 MaxVersion: VersionTLS12,
4890 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004891 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004892 shouldFail: true,
4893 expectedError: ":NO_RENEGOTIATION:",
4894 expectedLocalError: "remote error: no renegotiation",
4895 })
Adam Langley5021b222015-06-12 18:27:58 -07004896 // The server shouldn't echo the renegotiation extension unless
4897 // requested by the client.
4898 testCases = append(testCases, testCase{
4899 testType: serverTest,
4900 name: "Renegotiate-Server-NoExt",
4901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004902 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004903 Bugs: ProtocolBugs{
4904 NoRenegotiationInfo: true,
4905 RequireRenegotiationInfo: true,
4906 },
4907 },
4908 shouldFail: true,
4909 expectedLocalError: "renegotiation extension missing",
4910 })
4911 // The renegotiation SCSV should be sufficient for the server to echo
4912 // the extension.
4913 testCases = append(testCases, testCase{
4914 testType: serverTest,
4915 name: "Renegotiate-Server-NoExt-SCSV",
4916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004917 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004918 Bugs: ProtocolBugs{
4919 NoRenegotiationInfo: true,
4920 SendRenegotiationSCSV: true,
4921 RequireRenegotiationInfo: true,
4922 },
4923 },
4924 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004925 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004926 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004928 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004929 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004930 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004931 },
4932 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004933 renegotiate: 1,
4934 flags: []string{
4935 "-renegotiate-freely",
4936 "-expect-total-renegotiations", "1",
4937 },
David Benjamincdea40c2015-03-19 14:09:43 -04004938 })
4939 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004940 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004941 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004943 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004944 Bugs: ProtocolBugs{
4945 EmptyRenegotiationInfo: true,
4946 },
4947 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004948 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004949 shouldFail: true,
4950 expectedError: ":RENEGOTIATION_MISMATCH:",
4951 })
4952 testCases = append(testCases, testCase{
4953 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004954 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004956 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004957 Bugs: ProtocolBugs{
4958 BadRenegotiationInfo: true,
4959 },
4960 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004961 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004962 shouldFail: true,
4963 expectedError: ":RENEGOTIATION_MISMATCH:",
4964 })
4965 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004966 name: "Renegotiate-Client-Downgrade",
4967 renegotiate: 1,
4968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004969 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004970 Bugs: ProtocolBugs{
4971 NoRenegotiationInfoAfterInitial: true,
4972 },
4973 },
4974 flags: []string{"-renegotiate-freely"},
4975 shouldFail: true,
4976 expectedError: ":RENEGOTIATION_MISMATCH:",
4977 })
4978 testCases = append(testCases, testCase{
4979 name: "Renegotiate-Client-Upgrade",
4980 renegotiate: 1,
4981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004982 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004983 Bugs: ProtocolBugs{
4984 NoRenegotiationInfoInInitial: true,
4985 },
4986 },
4987 flags: []string{"-renegotiate-freely"},
4988 shouldFail: true,
4989 expectedError: ":RENEGOTIATION_MISMATCH:",
4990 })
4991 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004992 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004993 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004995 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004996 Bugs: ProtocolBugs{
4997 NoRenegotiationInfo: true,
4998 },
4999 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005000 flags: []string{
5001 "-renegotiate-freely",
5002 "-expect-total-renegotiations", "1",
5003 },
David Benjamincff0b902015-05-15 23:09:47 -04005004 })
5005 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005006 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005007 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005008 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005009 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005010 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5011 },
5012 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005013 flags: []string{
5014 "-renegotiate-freely",
5015 "-expect-total-renegotiations", "1",
5016 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005017 })
5018 testCases = append(testCases, testCase{
5019 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005020 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005021 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005022 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5024 },
5025 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005026 flags: []string{
5027 "-renegotiate-freely",
5028 "-expect-total-renegotiations", "1",
5029 },
David Benjaminb16346b2015-04-08 19:16:58 -04005030 })
5031 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005032 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005033 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005034 config: Config{
5035 MaxVersion: VersionTLS10,
5036 Bugs: ProtocolBugs{
5037 RequireSameRenegoClientVersion: true,
5038 },
5039 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005040 flags: []string{
5041 "-renegotiate-freely",
5042 "-expect-total-renegotiations", "1",
5043 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005044 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005045 testCases = append(testCases, testCase{
5046 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005047 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005048 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005049 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005050 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5051 NextProtos: []string{"foo"},
5052 },
5053 flags: []string{
5054 "-false-start",
5055 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005056 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005057 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005058 },
5059 shimWritesFirst: true,
5060 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005061
5062 // Client-side renegotiation controls.
5063 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005064 name: "Renegotiate-Client-Forbidden-1",
5065 config: Config{
5066 MaxVersion: VersionTLS12,
5067 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005068 renegotiate: 1,
5069 shouldFail: true,
5070 expectedError: ":NO_RENEGOTIATION:",
5071 expectedLocalError: "remote error: no renegotiation",
5072 })
5073 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005074 name: "Renegotiate-Client-Once-1",
5075 config: Config{
5076 MaxVersion: VersionTLS12,
5077 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005078 renegotiate: 1,
5079 flags: []string{
5080 "-renegotiate-once",
5081 "-expect-total-renegotiations", "1",
5082 },
5083 })
5084 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005085 name: "Renegotiate-Client-Freely-1",
5086 config: Config{
5087 MaxVersion: VersionTLS12,
5088 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005089 renegotiate: 1,
5090 flags: []string{
5091 "-renegotiate-freely",
5092 "-expect-total-renegotiations", "1",
5093 },
5094 })
5095 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005096 name: "Renegotiate-Client-Once-2",
5097 config: Config{
5098 MaxVersion: VersionTLS12,
5099 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005100 renegotiate: 2,
5101 flags: []string{"-renegotiate-once"},
5102 shouldFail: true,
5103 expectedError: ":NO_RENEGOTIATION:",
5104 expectedLocalError: "remote error: no renegotiation",
5105 })
5106 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005107 name: "Renegotiate-Client-Freely-2",
5108 config: Config{
5109 MaxVersion: VersionTLS12,
5110 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005111 renegotiate: 2,
5112 flags: []string{
5113 "-renegotiate-freely",
5114 "-expect-total-renegotiations", "2",
5115 },
5116 })
Adam Langley27a0d082015-11-03 13:34:10 -08005117 testCases = append(testCases, testCase{
5118 name: "Renegotiate-Client-NoIgnore",
5119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005120 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005121 Bugs: ProtocolBugs{
5122 SendHelloRequestBeforeEveryAppDataRecord: true,
5123 },
5124 },
5125 shouldFail: true,
5126 expectedError: ":NO_RENEGOTIATION:",
5127 })
5128 testCases = append(testCases, testCase{
5129 name: "Renegotiate-Client-Ignore",
5130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005131 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005132 Bugs: ProtocolBugs{
5133 SendHelloRequestBeforeEveryAppDataRecord: true,
5134 },
5135 },
5136 flags: []string{
5137 "-renegotiate-ignore",
5138 "-expect-total-renegotiations", "0",
5139 },
5140 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005141
David Benjamin397c8e62016-07-08 14:14:36 -07005142 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005143 testCases = append(testCases, testCase{
5144 name: "StrayHelloRequest",
5145 config: Config{
5146 MaxVersion: VersionTLS12,
5147 Bugs: ProtocolBugs{
5148 SendHelloRequestBeforeEveryHandshakeMessage: true,
5149 },
5150 },
5151 })
5152 testCases = append(testCases, testCase{
5153 name: "StrayHelloRequest-Packed",
5154 config: Config{
5155 MaxVersion: VersionTLS12,
5156 Bugs: ProtocolBugs{
5157 PackHandshakeFlight: true,
5158 SendHelloRequestBeforeEveryHandshakeMessage: true,
5159 },
5160 },
5161 })
5162
David Benjamin12d2c482016-07-24 10:56:51 -04005163 // Test renegotiation works if HelloRequest and server Finished come in
5164 // the same record.
5165 testCases = append(testCases, testCase{
5166 name: "Renegotiate-Client-Packed",
5167 config: Config{
5168 MaxVersion: VersionTLS12,
5169 Bugs: ProtocolBugs{
5170 PackHandshakeFlight: true,
5171 PackHelloRequestWithFinished: true,
5172 },
5173 },
5174 renegotiate: 1,
5175 flags: []string{
5176 "-renegotiate-freely",
5177 "-expect-total-renegotiations", "1",
5178 },
5179 })
5180
David Benjamin397c8e62016-07-08 14:14:36 -07005181 // Renegotiation is forbidden in TLS 1.3.
5182 testCases = append(testCases, testCase{
5183 name: "Renegotiate-Client-TLS13",
5184 config: Config{
5185 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005186 Bugs: ProtocolBugs{
5187 SendHelloRequestBeforeEveryAppDataRecord: true,
5188 },
David Benjamin397c8e62016-07-08 14:14:36 -07005189 },
David Benjamin397c8e62016-07-08 14:14:36 -07005190 flags: []string{
5191 "-renegotiate-freely",
5192 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005193 shouldFail: true,
5194 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005195 })
5196
5197 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5198 testCases = append(testCases, testCase{
5199 name: "StrayHelloRequest-TLS13",
5200 config: Config{
5201 MaxVersion: VersionTLS13,
5202 Bugs: ProtocolBugs{
5203 SendHelloRequestBeforeEveryHandshakeMessage: true,
5204 },
5205 },
5206 shouldFail: true,
5207 expectedError: ":UNEXPECTED_MESSAGE:",
5208 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005209}
5210
David Benjamin5e961c12014-11-07 01:48:35 -05005211func addDTLSReplayTests() {
5212 // Test that sequence number replays are detected.
5213 testCases = append(testCases, testCase{
5214 protocol: dtls,
5215 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005216 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005217 replayWrites: true,
5218 })
5219
David Benjamin8e6db492015-07-25 18:29:23 -04005220 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005221 // than the retransmit window.
5222 testCases = append(testCases, testCase{
5223 protocol: dtls,
5224 name: "DTLS-Replay-LargeGaps",
5225 config: Config{
5226 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005227 SequenceNumberMapping: func(in uint64) uint64 {
5228 return in * 127
5229 },
David Benjamin5e961c12014-11-07 01:48:35 -05005230 },
5231 },
David Benjamin8e6db492015-07-25 18:29:23 -04005232 messageCount: 200,
5233 replayWrites: true,
5234 })
5235
5236 // Test the incoming sequence number changing non-monotonically.
5237 testCases = append(testCases, testCase{
5238 protocol: dtls,
5239 name: "DTLS-Replay-NonMonotonic",
5240 config: Config{
5241 Bugs: ProtocolBugs{
5242 SequenceNumberMapping: func(in uint64) uint64 {
5243 return in ^ 31
5244 },
5245 },
5246 },
5247 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005248 replayWrites: true,
5249 })
5250}
5251
Nick Harper60edffd2016-06-21 15:19:24 -07005252var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005253 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005254 id signatureAlgorithm
5255 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005256}{
Nick Harper60edffd2016-06-21 15:19:24 -07005257 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5258 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5259 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5260 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005261 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005262 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5263 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5264 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005265 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5266 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5267 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005268 // Tests for key types prior to TLS 1.2.
5269 {"RSA", 0, testCertRSA},
5270 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005271}
5272
Nick Harper60edffd2016-06-21 15:19:24 -07005273const fakeSigAlg1 signatureAlgorithm = 0x2a01
5274const fakeSigAlg2 signatureAlgorithm = 0xff01
5275
5276func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005277 // Not all ciphers involve a signature. Advertise a list which gives all
5278 // versions a signing cipher.
5279 signingCiphers := []uint16{
5280 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5281 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5282 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5283 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5284 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5285 }
5286
David Benjaminca3d5452016-07-14 12:51:01 -04005287 var allAlgorithms []signatureAlgorithm
5288 for _, alg := range testSignatureAlgorithms {
5289 if alg.id != 0 {
5290 allAlgorithms = append(allAlgorithms, alg.id)
5291 }
5292 }
5293
Nick Harper60edffd2016-06-21 15:19:24 -07005294 // Make sure each signature algorithm works. Include some fake values in
5295 // the list and ensure they're ignored.
5296 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005297 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005298 if (ver.version < VersionTLS12) != (alg.id == 0) {
5299 continue
5300 }
5301
5302 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5303 // or remove it in C.
5304 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005305 continue
5306 }
Nick Harper60edffd2016-06-21 15:19:24 -07005307
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005308 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005309 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005310 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5311 shouldFail = true
5312 }
5313 // RSA-PSS does not exist in TLS 1.2.
5314 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5315 shouldFail = true
5316 }
5317
5318 var signError, verifyError string
5319 if shouldFail {
5320 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5321 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005322 }
David Benjamin000800a2014-11-14 01:43:59 -05005323
David Benjamin1fb125c2016-07-08 18:52:12 -07005324 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005325
David Benjamin7a41d372016-07-09 11:21:54 -07005326 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005327 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005328 config: Config{
5329 MaxVersion: ver.version,
5330 ClientAuth: RequireAnyClientCert,
5331 VerifySignatureAlgorithms: []signatureAlgorithm{
5332 fakeSigAlg1,
5333 alg.id,
5334 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005335 },
David Benjamin7a41d372016-07-09 11:21:54 -07005336 },
5337 flags: []string{
5338 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5339 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5340 "-enable-all-curves",
5341 },
5342 shouldFail: shouldFail,
5343 expectedError: signError,
5344 expectedPeerSignatureAlgorithm: alg.id,
5345 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005346
David Benjamin7a41d372016-07-09 11:21:54 -07005347 testCases = append(testCases, testCase{
5348 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005349 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005350 config: Config{
5351 MaxVersion: ver.version,
5352 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5353 SignSignatureAlgorithms: []signatureAlgorithm{
5354 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005355 },
David Benjamin7a41d372016-07-09 11:21:54 -07005356 Bugs: ProtocolBugs{
5357 SkipECDSACurveCheck: shouldFail,
5358 IgnoreSignatureVersionChecks: shouldFail,
5359 // The client won't advertise 1.3-only algorithms after
5360 // version negotiation.
5361 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005362 },
David Benjamin7a41d372016-07-09 11:21:54 -07005363 },
5364 flags: []string{
5365 "-require-any-client-certificate",
5366 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5367 "-enable-all-curves",
5368 },
5369 shouldFail: shouldFail,
5370 expectedError: verifyError,
5371 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005372
5373 testCases = append(testCases, testCase{
5374 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005375 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005376 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005377 MaxVersion: ver.version,
5378 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005379 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005380 fakeSigAlg1,
5381 alg.id,
5382 fakeSigAlg2,
5383 },
5384 },
5385 flags: []string{
5386 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5387 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5388 "-enable-all-curves",
5389 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005390 shouldFail: shouldFail,
5391 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005392 expectedPeerSignatureAlgorithm: alg.id,
5393 })
5394
5395 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005396 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005397 config: Config{
5398 MaxVersion: ver.version,
5399 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005400 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005401 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005402 alg.id,
5403 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005404 Bugs: ProtocolBugs{
5405 SkipECDSACurveCheck: shouldFail,
5406 IgnoreSignatureVersionChecks: shouldFail,
5407 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005408 },
5409 flags: []string{
5410 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5411 "-enable-all-curves",
5412 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005413 shouldFail: shouldFail,
5414 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005415 })
David Benjamin5208fd42016-07-13 21:43:25 -04005416
5417 if !shouldFail {
5418 testCases = append(testCases, testCase{
5419 testType: serverTest,
5420 name: "ClientAuth-InvalidSignature" + suffix,
5421 config: Config{
5422 MaxVersion: ver.version,
5423 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5424 SignSignatureAlgorithms: []signatureAlgorithm{
5425 alg.id,
5426 },
5427 Bugs: ProtocolBugs{
5428 InvalidSignature: true,
5429 },
5430 },
5431 flags: []string{
5432 "-require-any-client-certificate",
5433 "-enable-all-curves",
5434 },
5435 shouldFail: true,
5436 expectedError: ":BAD_SIGNATURE:",
5437 })
5438
5439 testCases = append(testCases, testCase{
5440 name: "ServerAuth-InvalidSignature" + suffix,
5441 config: Config{
5442 MaxVersion: ver.version,
5443 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5444 CipherSuites: signingCiphers,
5445 SignSignatureAlgorithms: []signatureAlgorithm{
5446 alg.id,
5447 },
5448 Bugs: ProtocolBugs{
5449 InvalidSignature: true,
5450 },
5451 },
5452 flags: []string{"-enable-all-curves"},
5453 shouldFail: true,
5454 expectedError: ":BAD_SIGNATURE:",
5455 })
5456 }
David Benjaminca3d5452016-07-14 12:51:01 -04005457
5458 if ver.version >= VersionTLS12 && !shouldFail {
5459 testCases = append(testCases, testCase{
5460 name: "ClientAuth-Sign-Negotiate" + suffix,
5461 config: Config{
5462 MaxVersion: ver.version,
5463 ClientAuth: RequireAnyClientCert,
5464 VerifySignatureAlgorithms: allAlgorithms,
5465 },
5466 flags: []string{
5467 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5468 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5469 "-enable-all-curves",
5470 "-signing-prefs", strconv.Itoa(int(alg.id)),
5471 },
5472 expectedPeerSignatureAlgorithm: alg.id,
5473 })
5474
5475 testCases = append(testCases, testCase{
5476 testType: serverTest,
5477 name: "ServerAuth-Sign-Negotiate" + suffix,
5478 config: Config{
5479 MaxVersion: ver.version,
5480 CipherSuites: signingCiphers,
5481 VerifySignatureAlgorithms: allAlgorithms,
5482 },
5483 flags: []string{
5484 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5485 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5486 "-enable-all-curves",
5487 "-signing-prefs", strconv.Itoa(int(alg.id)),
5488 },
5489 expectedPeerSignatureAlgorithm: alg.id,
5490 })
5491 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005492 }
David Benjamin000800a2014-11-14 01:43:59 -05005493 }
5494
Nick Harper60edffd2016-06-21 15:19:24 -07005495 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005496 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005497 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005498 config: Config{
5499 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005500 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005501 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005502 signatureECDSAWithP521AndSHA512,
5503 signatureRSAPKCS1WithSHA384,
5504 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005505 },
5506 },
5507 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005508 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5509 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005510 },
Nick Harper60edffd2016-06-21 15:19:24 -07005511 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005512 })
5513
5514 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005515 name: "ClientAuth-SignatureType-TLS13",
5516 config: Config{
5517 ClientAuth: RequireAnyClientCert,
5518 MaxVersion: VersionTLS13,
5519 VerifySignatureAlgorithms: []signatureAlgorithm{
5520 signatureECDSAWithP521AndSHA512,
5521 signatureRSAPKCS1WithSHA384,
5522 signatureRSAPSSWithSHA384,
5523 signatureECDSAWithSHA1,
5524 },
5525 },
5526 flags: []string{
5527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5529 },
5530 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5531 })
5532
5533 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005534 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005535 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005536 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005537 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005538 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005539 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005540 signatureECDSAWithP521AndSHA512,
5541 signatureRSAPKCS1WithSHA384,
5542 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005543 },
5544 },
Nick Harper60edffd2016-06-21 15:19:24 -07005545 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005546 })
5547
Steven Valdez143e8b32016-07-11 13:19:03 -04005548 testCases = append(testCases, testCase{
5549 testType: serverTest,
5550 name: "ServerAuth-SignatureType-TLS13",
5551 config: Config{
5552 MaxVersion: VersionTLS13,
5553 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5554 VerifySignatureAlgorithms: []signatureAlgorithm{
5555 signatureECDSAWithP521AndSHA512,
5556 signatureRSAPKCS1WithSHA384,
5557 signatureRSAPSSWithSHA384,
5558 signatureECDSAWithSHA1,
5559 },
5560 },
5561 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5562 })
5563
David Benjamina95e9f32016-07-08 16:28:04 -07005564 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005565 testCases = append(testCases, testCase{
5566 testType: serverTest,
5567 name: "Verify-ClientAuth-SignatureType",
5568 config: Config{
5569 MaxVersion: VersionTLS12,
5570 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005571 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005572 signatureRSAPKCS1WithSHA256,
5573 },
5574 Bugs: ProtocolBugs{
5575 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5576 },
5577 },
5578 flags: []string{
5579 "-require-any-client-certificate",
5580 },
5581 shouldFail: true,
5582 expectedError: ":WRONG_SIGNATURE_TYPE:",
5583 })
5584
5585 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005586 testType: serverTest,
5587 name: "Verify-ClientAuth-SignatureType-TLS13",
5588 config: Config{
5589 MaxVersion: VersionTLS13,
5590 Certificates: []Certificate{rsaCertificate},
5591 SignSignatureAlgorithms: []signatureAlgorithm{
5592 signatureRSAPSSWithSHA256,
5593 },
5594 Bugs: ProtocolBugs{
5595 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5596 },
5597 },
5598 flags: []string{
5599 "-require-any-client-certificate",
5600 },
5601 shouldFail: true,
5602 expectedError: ":WRONG_SIGNATURE_TYPE:",
5603 })
5604
5605 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005606 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005607 config: Config{
5608 MaxVersion: VersionTLS12,
5609 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005610 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005611 signatureRSAPKCS1WithSHA256,
5612 },
5613 Bugs: ProtocolBugs{
5614 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5615 },
5616 },
5617 shouldFail: true,
5618 expectedError: ":WRONG_SIGNATURE_TYPE:",
5619 })
5620
Steven Valdez143e8b32016-07-11 13:19:03 -04005621 testCases = append(testCases, testCase{
5622 name: "Verify-ServerAuth-SignatureType-TLS13",
5623 config: Config{
5624 MaxVersion: VersionTLS13,
5625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5626 SignSignatureAlgorithms: []signatureAlgorithm{
5627 signatureRSAPSSWithSHA256,
5628 },
5629 Bugs: ProtocolBugs{
5630 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5631 },
5632 },
5633 shouldFail: true,
5634 expectedError: ":WRONG_SIGNATURE_TYPE:",
5635 })
5636
David Benjamin51dd7d62016-07-08 16:07:01 -07005637 // Test that, if the list is missing, the peer falls back to SHA-1 in
5638 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005639 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005640 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005641 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005642 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005643 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005644 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005645 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005646 },
5647 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005648 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005649 },
5650 },
5651 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005652 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5653 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005654 },
5655 })
5656
5657 testCases = append(testCases, testCase{
5658 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005659 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005661 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005662 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005663 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005664 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005665 },
5666 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005667 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005668 },
5669 },
5670 })
David Benjamin72dc7832015-03-16 17:49:43 -04005671
David Benjamin51dd7d62016-07-08 16:07:01 -07005672 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005673 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005674 config: Config{
5675 MaxVersion: VersionTLS13,
5676 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005677 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005678 signatureRSAPKCS1WithSHA1,
5679 },
5680 Bugs: ProtocolBugs{
5681 NoSignatureAlgorithms: true,
5682 },
5683 },
5684 flags: []string{
5685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5687 },
David Benjamin48901652016-08-01 12:12:47 -04005688 shouldFail: true,
5689 // An empty CertificateRequest signature algorithm list is a
5690 // syntax error in TLS 1.3.
5691 expectedError: ":DECODE_ERROR:",
5692 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005693 })
5694
5695 testCases = append(testCases, testCase{
5696 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005697 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005698 config: Config{
5699 MaxVersion: VersionTLS13,
5700 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005701 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005702 signatureRSAPKCS1WithSHA1,
5703 },
5704 Bugs: ProtocolBugs{
5705 NoSignatureAlgorithms: true,
5706 },
5707 },
5708 shouldFail: true,
5709 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5710 })
5711
David Benjaminb62d2872016-07-18 14:55:02 +02005712 // Test that hash preferences are enforced. BoringSSL does not implement
5713 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005714 testCases = append(testCases, testCase{
5715 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005716 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005718 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005719 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005720 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005721 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005722 },
5723 Bugs: ProtocolBugs{
5724 IgnorePeerSignatureAlgorithmPreferences: true,
5725 },
5726 },
5727 flags: []string{"-require-any-client-certificate"},
5728 shouldFail: true,
5729 expectedError: ":WRONG_SIGNATURE_TYPE:",
5730 })
5731
5732 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005733 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005734 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005735 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005737 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005738 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005739 },
5740 Bugs: ProtocolBugs{
5741 IgnorePeerSignatureAlgorithmPreferences: true,
5742 },
5743 },
5744 shouldFail: true,
5745 expectedError: ":WRONG_SIGNATURE_TYPE:",
5746 })
David Benjaminb62d2872016-07-18 14:55:02 +02005747 testCases = append(testCases, testCase{
5748 testType: serverTest,
5749 name: "ClientAuth-Enforced-TLS13",
5750 config: Config{
5751 MaxVersion: VersionTLS13,
5752 Certificates: []Certificate{rsaCertificate},
5753 SignSignatureAlgorithms: []signatureAlgorithm{
5754 signatureRSAPKCS1WithMD5,
5755 },
5756 Bugs: ProtocolBugs{
5757 IgnorePeerSignatureAlgorithmPreferences: true,
5758 IgnoreSignatureVersionChecks: true,
5759 },
5760 },
5761 flags: []string{"-require-any-client-certificate"},
5762 shouldFail: true,
5763 expectedError: ":WRONG_SIGNATURE_TYPE:",
5764 })
5765
5766 testCases = append(testCases, testCase{
5767 name: "ServerAuth-Enforced-TLS13",
5768 config: Config{
5769 MaxVersion: VersionTLS13,
5770 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5771 SignSignatureAlgorithms: []signatureAlgorithm{
5772 signatureRSAPKCS1WithMD5,
5773 },
5774 Bugs: ProtocolBugs{
5775 IgnorePeerSignatureAlgorithmPreferences: true,
5776 IgnoreSignatureVersionChecks: true,
5777 },
5778 },
5779 shouldFail: true,
5780 expectedError: ":WRONG_SIGNATURE_TYPE:",
5781 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005782
5783 // Test that the agreed upon digest respects the client preferences and
5784 // the server digests.
5785 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005786 name: "NoCommonAlgorithms-Digests",
5787 config: Config{
5788 MaxVersion: VersionTLS12,
5789 ClientAuth: RequireAnyClientCert,
5790 VerifySignatureAlgorithms: []signatureAlgorithm{
5791 signatureRSAPKCS1WithSHA512,
5792 signatureRSAPKCS1WithSHA1,
5793 },
5794 },
5795 flags: []string{
5796 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5797 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5798 "-digest-prefs", "SHA256",
5799 },
5800 shouldFail: true,
5801 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5802 })
5803 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005804 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005805 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005806 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005807 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005808 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005809 signatureRSAPKCS1WithSHA512,
5810 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005811 },
5812 },
5813 flags: []string{
5814 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5815 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005816 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005817 },
David Benjaminca3d5452016-07-14 12:51:01 -04005818 shouldFail: true,
5819 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5820 })
5821 testCases = append(testCases, testCase{
5822 name: "NoCommonAlgorithms-TLS13",
5823 config: Config{
5824 MaxVersion: VersionTLS13,
5825 ClientAuth: RequireAnyClientCert,
5826 VerifySignatureAlgorithms: []signatureAlgorithm{
5827 signatureRSAPSSWithSHA512,
5828 signatureRSAPSSWithSHA384,
5829 },
5830 },
5831 flags: []string{
5832 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5833 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5834 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5835 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005836 shouldFail: true,
5837 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005838 })
5839 testCases = append(testCases, testCase{
5840 name: "Agree-Digest-SHA256",
5841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005842 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005843 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005844 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005845 signatureRSAPKCS1WithSHA1,
5846 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005847 },
5848 },
5849 flags: []string{
5850 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5851 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005852 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005853 },
Nick Harper60edffd2016-06-21 15:19:24 -07005854 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005855 })
5856 testCases = append(testCases, testCase{
5857 name: "Agree-Digest-SHA1",
5858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005859 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005860 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005861 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005862 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005863 },
5864 },
5865 flags: []string{
5866 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5867 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005868 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005869 },
Nick Harper60edffd2016-06-21 15:19:24 -07005870 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005871 })
5872 testCases = append(testCases, testCase{
5873 name: "Agree-Digest-Default",
5874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005875 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005876 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005877 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005878 signatureRSAPKCS1WithSHA256,
5879 signatureECDSAWithP256AndSHA256,
5880 signatureRSAPKCS1WithSHA1,
5881 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005882 },
5883 },
5884 flags: []string{
5885 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5886 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5887 },
Nick Harper60edffd2016-06-21 15:19:24 -07005888 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005889 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005890
David Benjaminca3d5452016-07-14 12:51:01 -04005891 // Test that the signing preference list may include extra algorithms
5892 // without negotiation problems.
5893 testCases = append(testCases, testCase{
5894 testType: serverTest,
5895 name: "FilterExtraAlgorithms",
5896 config: Config{
5897 MaxVersion: VersionTLS12,
5898 VerifySignatureAlgorithms: []signatureAlgorithm{
5899 signatureRSAPKCS1WithSHA256,
5900 },
5901 },
5902 flags: []string{
5903 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5904 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5905 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5906 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5907 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5908 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5909 },
5910 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5911 })
5912
David Benjamin4c3ddf72016-06-29 18:13:53 -04005913 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5914 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005915 testCases = append(testCases, testCase{
5916 name: "CheckLeafCurve",
5917 config: Config{
5918 MaxVersion: VersionTLS12,
5919 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005920 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005921 },
5922 flags: []string{"-p384-only"},
5923 shouldFail: true,
5924 expectedError: ":BAD_ECC_CERT:",
5925 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005926
5927 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5928 testCases = append(testCases, testCase{
5929 name: "CheckLeafCurve-TLS13",
5930 config: Config{
5931 MaxVersion: VersionTLS13,
5932 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5933 Certificates: []Certificate{ecdsaP256Certificate},
5934 },
5935 flags: []string{"-p384-only"},
5936 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005937
5938 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5939 testCases = append(testCases, testCase{
5940 name: "ECDSACurveMismatch-Verify-TLS12",
5941 config: Config{
5942 MaxVersion: VersionTLS12,
5943 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5944 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005945 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005946 signatureECDSAWithP384AndSHA384,
5947 },
5948 },
5949 })
5950
5951 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5952 testCases = append(testCases, testCase{
5953 name: "ECDSACurveMismatch-Verify-TLS13",
5954 config: Config{
5955 MaxVersion: VersionTLS13,
5956 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5957 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005958 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005959 signatureECDSAWithP384AndSHA384,
5960 },
5961 Bugs: ProtocolBugs{
5962 SkipECDSACurveCheck: true,
5963 },
5964 },
5965 shouldFail: true,
5966 expectedError: ":WRONG_SIGNATURE_TYPE:",
5967 })
5968
5969 // Signature algorithm selection in TLS 1.3 should take the curve into
5970 // account.
5971 testCases = append(testCases, testCase{
5972 testType: serverTest,
5973 name: "ECDSACurveMismatch-Sign-TLS13",
5974 config: Config{
5975 MaxVersion: VersionTLS13,
5976 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005977 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005978 signatureECDSAWithP384AndSHA384,
5979 signatureECDSAWithP256AndSHA256,
5980 },
5981 },
5982 flags: []string{
5983 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5984 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5985 },
5986 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5987 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005988
5989 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5990 // server does not attempt to sign in that case.
5991 testCases = append(testCases, testCase{
5992 testType: serverTest,
5993 name: "RSA-PSS-Large",
5994 config: Config{
5995 MaxVersion: VersionTLS13,
5996 VerifySignatureAlgorithms: []signatureAlgorithm{
5997 signatureRSAPSSWithSHA512,
5998 },
5999 },
6000 flags: []string{
6001 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6002 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6003 },
6004 shouldFail: true,
6005 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6006 })
David Benjamin000800a2014-11-14 01:43:59 -05006007}
6008
David Benjamin83f90402015-01-27 01:09:43 -05006009// timeouts is the retransmit schedule for BoringSSL. It doubles and
6010// caps at 60 seconds. On the 13th timeout, it gives up.
6011var timeouts = []time.Duration{
6012 1 * time.Second,
6013 2 * time.Second,
6014 4 * time.Second,
6015 8 * time.Second,
6016 16 * time.Second,
6017 32 * time.Second,
6018 60 * time.Second,
6019 60 * time.Second,
6020 60 * time.Second,
6021 60 * time.Second,
6022 60 * time.Second,
6023 60 * time.Second,
6024 60 * time.Second,
6025}
6026
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006027// shortTimeouts is an alternate set of timeouts which would occur if the
6028// initial timeout duration was set to 250ms.
6029var shortTimeouts = []time.Duration{
6030 250 * time.Millisecond,
6031 500 * time.Millisecond,
6032 1 * time.Second,
6033 2 * time.Second,
6034 4 * time.Second,
6035 8 * time.Second,
6036 16 * time.Second,
6037 32 * time.Second,
6038 60 * time.Second,
6039 60 * time.Second,
6040 60 * time.Second,
6041 60 * time.Second,
6042 60 * time.Second,
6043}
6044
David Benjamin83f90402015-01-27 01:09:43 -05006045func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006046 // These tests work by coordinating some behavior on both the shim and
6047 // the runner.
6048 //
6049 // TimeoutSchedule configures the runner to send a series of timeout
6050 // opcodes to the shim (see packetAdaptor) immediately before reading
6051 // each peer handshake flight N. The timeout opcode both simulates a
6052 // timeout in the shim and acts as a synchronization point to help the
6053 // runner bracket each handshake flight.
6054 //
6055 // We assume the shim does not read from the channel eagerly. It must
6056 // first wait until it has sent flight N and is ready to receive
6057 // handshake flight N+1. At this point, it will process the timeout
6058 // opcode. It must then immediately respond with a timeout ACK and act
6059 // as if the shim was idle for the specified amount of time.
6060 //
6061 // The runner then drops all packets received before the ACK and
6062 // continues waiting for flight N. This ordering results in one attempt
6063 // at sending flight N to be dropped. For the test to complete, the
6064 // shim must send flight N again, testing that the shim implements DTLS
6065 // retransmit on a timeout.
6066
Steven Valdez143e8b32016-07-11 13:19:03 -04006067 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006068 // likely be more epochs to cross and the final message's retransmit may
6069 // be more complex.
6070
David Benjamin585d7a42016-06-02 14:58:00 -04006071 for _, async := range []bool{true, false} {
6072 var tests []testCase
6073
6074 // Test that this is indeed the timeout schedule. Stress all
6075 // four patterns of handshake.
6076 for i := 1; i < len(timeouts); i++ {
6077 number := strconv.Itoa(i)
6078 tests = append(tests, testCase{
6079 protocol: dtls,
6080 name: "DTLS-Retransmit-Client-" + number,
6081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006082 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006083 Bugs: ProtocolBugs{
6084 TimeoutSchedule: timeouts[:i],
6085 },
6086 },
6087 resumeSession: true,
6088 })
6089 tests = append(tests, testCase{
6090 protocol: dtls,
6091 testType: serverTest,
6092 name: "DTLS-Retransmit-Server-" + number,
6093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006094 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006095 Bugs: ProtocolBugs{
6096 TimeoutSchedule: timeouts[:i],
6097 },
6098 },
6099 resumeSession: true,
6100 })
6101 }
6102
6103 // Test that exceeding the timeout schedule hits a read
6104 // timeout.
6105 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006106 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006107 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006109 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006110 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006111 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006112 },
6113 },
6114 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006115 shouldFail: true,
6116 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006117 })
David Benjamin585d7a42016-06-02 14:58:00 -04006118
6119 if async {
6120 // Test that timeout handling has a fudge factor, due to API
6121 // problems.
6122 tests = append(tests, testCase{
6123 protocol: dtls,
6124 name: "DTLS-Retransmit-Fudge",
6125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006126 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006127 Bugs: ProtocolBugs{
6128 TimeoutSchedule: []time.Duration{
6129 timeouts[0] - 10*time.Millisecond,
6130 },
6131 },
6132 },
6133 resumeSession: true,
6134 })
6135 }
6136
6137 // Test that the final Finished retransmitting isn't
6138 // duplicated if the peer badly fragments everything.
6139 tests = append(tests, testCase{
6140 testType: serverTest,
6141 protocol: dtls,
6142 name: "DTLS-Retransmit-Fragmented",
6143 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006144 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006145 Bugs: ProtocolBugs{
6146 TimeoutSchedule: []time.Duration{timeouts[0]},
6147 MaxHandshakeRecordLength: 2,
6148 },
6149 },
6150 })
6151
6152 // Test the timeout schedule when a shorter initial timeout duration is set.
6153 tests = append(tests, testCase{
6154 protocol: dtls,
6155 name: "DTLS-Retransmit-Short-Client",
6156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006157 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006158 Bugs: ProtocolBugs{
6159 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6160 },
6161 },
6162 resumeSession: true,
6163 flags: []string{"-initial-timeout-duration-ms", "250"},
6164 })
6165 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006166 protocol: dtls,
6167 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006168 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006170 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006171 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006172 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006173 },
6174 },
6175 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006176 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006177 })
David Benjamin585d7a42016-06-02 14:58:00 -04006178
6179 for _, test := range tests {
6180 if async {
6181 test.name += "-Async"
6182 test.flags = append(test.flags, "-async")
6183 }
6184
6185 testCases = append(testCases, test)
6186 }
David Benjamin83f90402015-01-27 01:09:43 -05006187 }
David Benjamin83f90402015-01-27 01:09:43 -05006188}
6189
David Benjaminc565ebb2015-04-03 04:06:36 -04006190func addExportKeyingMaterialTests() {
6191 for _, vers := range tlsVersions {
6192 if vers.version == VersionSSL30 {
6193 continue
6194 }
6195 testCases = append(testCases, testCase{
6196 name: "ExportKeyingMaterial-" + vers.name,
6197 config: Config{
6198 MaxVersion: vers.version,
6199 },
6200 exportKeyingMaterial: 1024,
6201 exportLabel: "label",
6202 exportContext: "context",
6203 useExportContext: true,
6204 })
6205 testCases = append(testCases, testCase{
6206 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6207 config: Config{
6208 MaxVersion: vers.version,
6209 },
6210 exportKeyingMaterial: 1024,
6211 })
6212 testCases = append(testCases, testCase{
6213 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6214 config: Config{
6215 MaxVersion: vers.version,
6216 },
6217 exportKeyingMaterial: 1024,
6218 useExportContext: true,
6219 })
6220 testCases = append(testCases, testCase{
6221 name: "ExportKeyingMaterial-Small-" + vers.name,
6222 config: Config{
6223 MaxVersion: vers.version,
6224 },
6225 exportKeyingMaterial: 1,
6226 exportLabel: "label",
6227 exportContext: "context",
6228 useExportContext: true,
6229 })
6230 }
6231 testCases = append(testCases, testCase{
6232 name: "ExportKeyingMaterial-SSL3",
6233 config: Config{
6234 MaxVersion: VersionSSL30,
6235 },
6236 exportKeyingMaterial: 1024,
6237 exportLabel: "label",
6238 exportContext: "context",
6239 useExportContext: true,
6240 shouldFail: true,
6241 expectedError: "failed to export keying material",
6242 })
6243}
6244
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006245func addTLSUniqueTests() {
6246 for _, isClient := range []bool{false, true} {
6247 for _, isResumption := range []bool{false, true} {
6248 for _, hasEMS := range []bool{false, true} {
6249 var suffix string
6250 if isResumption {
6251 suffix = "Resume-"
6252 } else {
6253 suffix = "Full-"
6254 }
6255
6256 if hasEMS {
6257 suffix += "EMS-"
6258 } else {
6259 suffix += "NoEMS-"
6260 }
6261
6262 if isClient {
6263 suffix += "Client"
6264 } else {
6265 suffix += "Server"
6266 }
6267
6268 test := testCase{
6269 name: "TLSUnique-" + suffix,
6270 testTLSUnique: true,
6271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006272 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006273 Bugs: ProtocolBugs{
6274 NoExtendedMasterSecret: !hasEMS,
6275 },
6276 },
6277 }
6278
6279 if isResumption {
6280 test.resumeSession = true
6281 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006282 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006283 Bugs: ProtocolBugs{
6284 NoExtendedMasterSecret: !hasEMS,
6285 },
6286 }
6287 }
6288
6289 if isResumption && !hasEMS {
6290 test.shouldFail = true
6291 test.expectedError = "failed to get tls-unique"
6292 }
6293
6294 testCases = append(testCases, test)
6295 }
6296 }
6297 }
6298}
6299
Adam Langley09505632015-07-30 18:10:13 -07006300func addCustomExtensionTests() {
6301 expectedContents := "custom extension"
6302 emptyString := ""
6303
6304 for _, isClient := range []bool{false, true} {
6305 suffix := "Server"
6306 flag := "-enable-server-custom-extension"
6307 testType := serverTest
6308 if isClient {
6309 suffix = "Client"
6310 flag = "-enable-client-custom-extension"
6311 testType = clientTest
6312 }
6313
6314 testCases = append(testCases, testCase{
6315 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006316 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006318 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006319 Bugs: ProtocolBugs{
6320 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006321 ExpectedCustomExtension: &expectedContents,
6322 },
6323 },
6324 flags: []string{flag},
6325 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006326 testCases = append(testCases, testCase{
6327 testType: testType,
6328 name: "CustomExtensions-" + suffix + "-TLS13",
6329 config: Config{
6330 MaxVersion: VersionTLS13,
6331 Bugs: ProtocolBugs{
6332 CustomExtension: expectedContents,
6333 ExpectedCustomExtension: &expectedContents,
6334 },
6335 },
6336 flags: []string{flag},
6337 })
Adam Langley09505632015-07-30 18:10:13 -07006338
6339 // If the parse callback fails, the handshake should also fail.
6340 testCases = append(testCases, testCase{
6341 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006342 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006343 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006344 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006345 Bugs: ProtocolBugs{
6346 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006347 ExpectedCustomExtension: &expectedContents,
6348 },
6349 },
David Benjamin399e7c92015-07-30 23:01:27 -04006350 flags: []string{flag},
6351 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006352 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6353 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006354 testCases = append(testCases, testCase{
6355 testType: testType,
6356 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6357 config: Config{
6358 MaxVersion: VersionTLS13,
6359 Bugs: ProtocolBugs{
6360 CustomExtension: expectedContents + "foo",
6361 ExpectedCustomExtension: &expectedContents,
6362 },
6363 },
6364 flags: []string{flag},
6365 shouldFail: true,
6366 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6367 })
Adam Langley09505632015-07-30 18:10:13 -07006368
6369 // If the add callback fails, the handshake should also fail.
6370 testCases = append(testCases, testCase{
6371 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006372 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006374 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006375 Bugs: ProtocolBugs{
6376 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006377 ExpectedCustomExtension: &expectedContents,
6378 },
6379 },
David Benjamin399e7c92015-07-30 23:01:27 -04006380 flags: []string{flag, "-custom-extension-fail-add"},
6381 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006382 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6383 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006384 testCases = append(testCases, testCase{
6385 testType: testType,
6386 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6387 config: Config{
6388 MaxVersion: VersionTLS13,
6389 Bugs: ProtocolBugs{
6390 CustomExtension: expectedContents,
6391 ExpectedCustomExtension: &expectedContents,
6392 },
6393 },
6394 flags: []string{flag, "-custom-extension-fail-add"},
6395 shouldFail: true,
6396 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6397 })
Adam Langley09505632015-07-30 18:10:13 -07006398
6399 // If the add callback returns zero, no extension should be
6400 // added.
6401 skipCustomExtension := expectedContents
6402 if isClient {
6403 // For the case where the client skips sending the
6404 // custom extension, the server must not “echo” it.
6405 skipCustomExtension = ""
6406 }
6407 testCases = append(testCases, testCase{
6408 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006409 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006411 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006412 Bugs: ProtocolBugs{
6413 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006414 ExpectedCustomExtension: &emptyString,
6415 },
6416 },
6417 flags: []string{flag, "-custom-extension-skip"},
6418 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006419 testCases = append(testCases, testCase{
6420 testType: testType,
6421 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6422 config: Config{
6423 MaxVersion: VersionTLS13,
6424 Bugs: ProtocolBugs{
6425 CustomExtension: skipCustomExtension,
6426 ExpectedCustomExtension: &emptyString,
6427 },
6428 },
6429 flags: []string{flag, "-custom-extension-skip"},
6430 })
Adam Langley09505632015-07-30 18:10:13 -07006431 }
6432
6433 // The custom extension add callback should not be called if the client
6434 // doesn't send the extension.
6435 testCases = append(testCases, testCase{
6436 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006437 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006439 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006440 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006441 ExpectedCustomExtension: &emptyString,
6442 },
6443 },
6444 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6445 })
Adam Langley2deb9842015-08-07 11:15:37 -07006446
Steven Valdez143e8b32016-07-11 13:19:03 -04006447 testCases = append(testCases, testCase{
6448 testType: serverTest,
6449 name: "CustomExtensions-NotCalled-Server-TLS13",
6450 config: Config{
6451 MaxVersion: VersionTLS13,
6452 Bugs: ProtocolBugs{
6453 ExpectedCustomExtension: &emptyString,
6454 },
6455 },
6456 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6457 })
6458
Adam Langley2deb9842015-08-07 11:15:37 -07006459 // Test an unknown extension from the server.
6460 testCases = append(testCases, testCase{
6461 testType: clientTest,
6462 name: "UnknownExtension-Client",
6463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006464 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006465 Bugs: ProtocolBugs{
6466 CustomExtension: expectedContents,
6467 },
6468 },
David Benjamin0c40a962016-08-01 12:05:50 -04006469 shouldFail: true,
6470 expectedError: ":UNEXPECTED_EXTENSION:",
6471 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006472 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006473 testCases = append(testCases, testCase{
6474 testType: clientTest,
6475 name: "UnknownExtension-Client-TLS13",
6476 config: Config{
6477 MaxVersion: VersionTLS13,
6478 Bugs: ProtocolBugs{
6479 CustomExtension: expectedContents,
6480 },
6481 },
David Benjamin0c40a962016-08-01 12:05:50 -04006482 shouldFail: true,
6483 expectedError: ":UNEXPECTED_EXTENSION:",
6484 expectedLocalError: "remote error: unsupported extension",
6485 })
6486
6487 // Test a known but unoffered extension from the server.
6488 testCases = append(testCases, testCase{
6489 testType: clientTest,
6490 name: "UnofferedExtension-Client",
6491 config: Config{
6492 MaxVersion: VersionTLS12,
6493 Bugs: ProtocolBugs{
6494 SendALPN: "alpn",
6495 },
6496 },
6497 shouldFail: true,
6498 expectedError: ":UNEXPECTED_EXTENSION:",
6499 expectedLocalError: "remote error: unsupported extension",
6500 })
6501 testCases = append(testCases, testCase{
6502 testType: clientTest,
6503 name: "UnofferedExtension-Client-TLS13",
6504 config: Config{
6505 MaxVersion: VersionTLS13,
6506 Bugs: ProtocolBugs{
6507 SendALPN: "alpn",
6508 },
6509 },
6510 shouldFail: true,
6511 expectedError: ":UNEXPECTED_EXTENSION:",
6512 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006513 })
Adam Langley09505632015-07-30 18:10:13 -07006514}
6515
David Benjaminb36a3952015-12-01 18:53:13 -05006516func addRSAClientKeyExchangeTests() {
6517 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6518 testCases = append(testCases, testCase{
6519 testType: serverTest,
6520 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6521 config: Config{
6522 // Ensure the ClientHello version and final
6523 // version are different, to detect if the
6524 // server uses the wrong one.
6525 MaxVersion: VersionTLS11,
6526 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6527 Bugs: ProtocolBugs{
6528 BadRSAClientKeyExchange: bad,
6529 },
6530 },
6531 shouldFail: true,
6532 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6533 })
6534 }
6535}
6536
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006537var testCurves = []struct {
6538 name string
6539 id CurveID
6540}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006541 {"P-256", CurveP256},
6542 {"P-384", CurveP384},
6543 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006544 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006545}
6546
Steven Valdez5440fe02016-07-18 12:40:30 -04006547const bogusCurve = 0x1234
6548
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006549func addCurveTests() {
6550 for _, curve := range testCurves {
6551 testCases = append(testCases, testCase{
6552 name: "CurveTest-Client-" + curve.name,
6553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006554 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006555 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6556 CurvePreferences: []CurveID{curve.id},
6557 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006558 flags: []string{"-enable-all-curves"},
6559 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006560 })
6561 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006562 name: "CurveTest-Client-" + curve.name + "-TLS13",
6563 config: Config{
6564 MaxVersion: VersionTLS13,
6565 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6566 CurvePreferences: []CurveID{curve.id},
6567 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006568 flags: []string{"-enable-all-curves"},
6569 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006570 })
6571 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006572 testType: serverTest,
6573 name: "CurveTest-Server-" + curve.name,
6574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006575 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6577 CurvePreferences: []CurveID{curve.id},
6578 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006579 flags: []string{"-enable-all-curves"},
6580 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006581 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006582 testCases = append(testCases, testCase{
6583 testType: serverTest,
6584 name: "CurveTest-Server-" + curve.name + "-TLS13",
6585 config: Config{
6586 MaxVersion: VersionTLS13,
6587 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6588 CurvePreferences: []CurveID{curve.id},
6589 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006590 flags: []string{"-enable-all-curves"},
6591 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006592 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006593 }
David Benjamin241ae832016-01-15 03:04:54 -05006594
6595 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006596 testCases = append(testCases, testCase{
6597 testType: serverTest,
6598 name: "UnknownCurve",
6599 config: Config{
6600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6601 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6602 },
6603 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006604
6605 // The server must not consider ECDHE ciphers when there are no
6606 // supported curves.
6607 testCases = append(testCases, testCase{
6608 testType: serverTest,
6609 name: "NoSupportedCurves",
6610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006611 MaxVersion: VersionTLS12,
6612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6613 Bugs: ProtocolBugs{
6614 NoSupportedCurves: true,
6615 },
6616 },
6617 shouldFail: true,
6618 expectedError: ":NO_SHARED_CIPHER:",
6619 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006620 testCases = append(testCases, testCase{
6621 testType: serverTest,
6622 name: "NoSupportedCurves-TLS13",
6623 config: Config{
6624 MaxVersion: VersionTLS13,
6625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6626 Bugs: ProtocolBugs{
6627 NoSupportedCurves: true,
6628 },
6629 },
6630 shouldFail: true,
6631 expectedError: ":NO_SHARED_CIPHER:",
6632 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006633
6634 // The server must fall back to another cipher when there are no
6635 // supported curves.
6636 testCases = append(testCases, testCase{
6637 testType: serverTest,
6638 name: "NoCommonCurves",
6639 config: Config{
6640 MaxVersion: VersionTLS12,
6641 CipherSuites: []uint16{
6642 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6643 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6644 },
6645 CurvePreferences: []CurveID{CurveP224},
6646 },
6647 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6648 })
6649
6650 // The client must reject bogus curves and disabled curves.
6651 testCases = append(testCases, testCase{
6652 name: "BadECDHECurve",
6653 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006654 MaxVersion: VersionTLS12,
6655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6656 Bugs: ProtocolBugs{
6657 SendCurve: bogusCurve,
6658 },
6659 },
6660 shouldFail: true,
6661 expectedError: ":WRONG_CURVE:",
6662 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006663 testCases = append(testCases, testCase{
6664 name: "BadECDHECurve-TLS13",
6665 config: Config{
6666 MaxVersion: VersionTLS13,
6667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6668 Bugs: ProtocolBugs{
6669 SendCurve: bogusCurve,
6670 },
6671 },
6672 shouldFail: true,
6673 expectedError: ":WRONG_CURVE:",
6674 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006675
6676 testCases = append(testCases, testCase{
6677 name: "UnsupportedCurve",
6678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006679 MaxVersion: VersionTLS12,
6680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6681 CurvePreferences: []CurveID{CurveP256},
6682 Bugs: ProtocolBugs{
6683 IgnorePeerCurvePreferences: true,
6684 },
6685 },
6686 flags: []string{"-p384-only"},
6687 shouldFail: true,
6688 expectedError: ":WRONG_CURVE:",
6689 })
6690
David Benjamin4f921572016-07-17 14:20:10 +02006691 testCases = append(testCases, testCase{
6692 // TODO(davidben): Add a TLS 1.3 version where
6693 // HelloRetryRequest requests an unsupported curve.
6694 name: "UnsupportedCurve-ServerHello-TLS13",
6695 config: Config{
6696 MaxVersion: VersionTLS12,
6697 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6698 CurvePreferences: []CurveID{CurveP384},
6699 Bugs: ProtocolBugs{
6700 SendCurve: CurveP256,
6701 },
6702 },
6703 flags: []string{"-p384-only"},
6704 shouldFail: true,
6705 expectedError: ":WRONG_CURVE:",
6706 })
6707
David Benjamin4c3ddf72016-06-29 18:13:53 -04006708 // Test invalid curve points.
6709 testCases = append(testCases, testCase{
6710 name: "InvalidECDHPoint-Client",
6711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006712 MaxVersion: VersionTLS12,
6713 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6714 CurvePreferences: []CurveID{CurveP256},
6715 Bugs: ProtocolBugs{
6716 InvalidECDHPoint: true,
6717 },
6718 },
6719 shouldFail: true,
6720 expectedError: ":INVALID_ENCODING:",
6721 })
6722 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006723 name: "InvalidECDHPoint-Client-TLS13",
6724 config: Config{
6725 MaxVersion: VersionTLS13,
6726 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6727 CurvePreferences: []CurveID{CurveP256},
6728 Bugs: ProtocolBugs{
6729 InvalidECDHPoint: true,
6730 },
6731 },
6732 shouldFail: true,
6733 expectedError: ":INVALID_ENCODING:",
6734 })
6735 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006736 testType: serverTest,
6737 name: "InvalidECDHPoint-Server",
6738 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006739 MaxVersion: VersionTLS12,
6740 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6741 CurvePreferences: []CurveID{CurveP256},
6742 Bugs: ProtocolBugs{
6743 InvalidECDHPoint: true,
6744 },
6745 },
6746 shouldFail: true,
6747 expectedError: ":INVALID_ENCODING:",
6748 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006749 testCases = append(testCases, testCase{
6750 testType: serverTest,
6751 name: "InvalidECDHPoint-Server-TLS13",
6752 config: Config{
6753 MaxVersion: VersionTLS13,
6754 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6755 CurvePreferences: []CurveID{CurveP256},
6756 Bugs: ProtocolBugs{
6757 InvalidECDHPoint: true,
6758 },
6759 },
6760 shouldFail: true,
6761 expectedError: ":INVALID_ENCODING:",
6762 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006763}
6764
Matt Braithwaite54217e42016-06-13 13:03:47 -07006765func addCECPQ1Tests() {
6766 testCases = append(testCases, testCase{
6767 testType: clientTest,
6768 name: "CECPQ1-Client-BadX25519Part",
6769 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006770 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006771 MinVersion: VersionTLS12,
6772 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6773 Bugs: ProtocolBugs{
6774 CECPQ1BadX25519Part: true,
6775 },
6776 },
6777 flags: []string{"-cipher", "kCECPQ1"},
6778 shouldFail: true,
6779 expectedLocalError: "local error: bad record MAC",
6780 })
6781 testCases = append(testCases, testCase{
6782 testType: clientTest,
6783 name: "CECPQ1-Client-BadNewhopePart",
6784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006785 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006786 MinVersion: VersionTLS12,
6787 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6788 Bugs: ProtocolBugs{
6789 CECPQ1BadNewhopePart: true,
6790 },
6791 },
6792 flags: []string{"-cipher", "kCECPQ1"},
6793 shouldFail: true,
6794 expectedLocalError: "local error: bad record MAC",
6795 })
6796 testCases = append(testCases, testCase{
6797 testType: serverTest,
6798 name: "CECPQ1-Server-BadX25519Part",
6799 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006800 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006801 MinVersion: VersionTLS12,
6802 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6803 Bugs: ProtocolBugs{
6804 CECPQ1BadX25519Part: true,
6805 },
6806 },
6807 flags: []string{"-cipher", "kCECPQ1"},
6808 shouldFail: true,
6809 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6810 })
6811 testCases = append(testCases, testCase{
6812 testType: serverTest,
6813 name: "CECPQ1-Server-BadNewhopePart",
6814 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006815 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006816 MinVersion: VersionTLS12,
6817 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6818 Bugs: ProtocolBugs{
6819 CECPQ1BadNewhopePart: true,
6820 },
6821 },
6822 flags: []string{"-cipher", "kCECPQ1"},
6823 shouldFail: true,
6824 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6825 })
6826}
6827
David Benjamin4cc36ad2015-12-19 14:23:26 -05006828func addKeyExchangeInfoTests() {
6829 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006830 name: "KeyExchangeInfo-DHE-Client",
6831 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006832 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006833 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6834 Bugs: ProtocolBugs{
6835 // This is a 1234-bit prime number, generated
6836 // with:
6837 // openssl gendh 1234 | openssl asn1parse -i
6838 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6839 },
6840 },
David Benjamin9e68f192016-06-30 14:55:33 -04006841 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006842 })
6843 testCases = append(testCases, testCase{
6844 testType: serverTest,
6845 name: "KeyExchangeInfo-DHE-Server",
6846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006847 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006848 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6849 },
6850 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006851 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006852 })
6853
6854 testCases = append(testCases, testCase{
6855 name: "KeyExchangeInfo-ECDHE-Client",
6856 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006857 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006858 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6859 CurvePreferences: []CurveID{CurveX25519},
6860 },
David Benjamin9e68f192016-06-30 14:55:33 -04006861 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006862 })
6863 testCases = append(testCases, testCase{
6864 testType: serverTest,
6865 name: "KeyExchangeInfo-ECDHE-Server",
6866 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006867 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006868 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6869 CurvePreferences: []CurveID{CurveX25519},
6870 },
David Benjamin9e68f192016-06-30 14:55:33 -04006871 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006872 })
6873}
6874
David Benjaminc9ae27c2016-06-24 22:56:37 -04006875func addTLS13RecordTests() {
6876 testCases = append(testCases, testCase{
6877 name: "TLS13-RecordPadding",
6878 config: Config{
6879 MaxVersion: VersionTLS13,
6880 MinVersion: VersionTLS13,
6881 Bugs: ProtocolBugs{
6882 RecordPadding: 10,
6883 },
6884 },
6885 })
6886
6887 testCases = append(testCases, testCase{
6888 name: "TLS13-EmptyRecords",
6889 config: Config{
6890 MaxVersion: VersionTLS13,
6891 MinVersion: VersionTLS13,
6892 Bugs: ProtocolBugs{
6893 OmitRecordContents: true,
6894 },
6895 },
6896 shouldFail: true,
6897 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6898 })
6899
6900 testCases = append(testCases, testCase{
6901 name: "TLS13-OnlyPadding",
6902 config: Config{
6903 MaxVersion: VersionTLS13,
6904 MinVersion: VersionTLS13,
6905 Bugs: ProtocolBugs{
6906 OmitRecordContents: true,
6907 RecordPadding: 10,
6908 },
6909 },
6910 shouldFail: true,
6911 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6912 })
6913
6914 testCases = append(testCases, testCase{
6915 name: "TLS13-WrongOuterRecord",
6916 config: Config{
6917 MaxVersion: VersionTLS13,
6918 MinVersion: VersionTLS13,
6919 Bugs: ProtocolBugs{
6920 OuterRecordType: recordTypeHandshake,
6921 },
6922 },
6923 shouldFail: true,
6924 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6925 })
6926}
6927
David Benjamin82261be2016-07-07 14:32:50 -07006928func addChangeCipherSpecTests() {
6929 // Test missing ChangeCipherSpecs.
6930 testCases = append(testCases, testCase{
6931 name: "SkipChangeCipherSpec-Client",
6932 config: Config{
6933 MaxVersion: VersionTLS12,
6934 Bugs: ProtocolBugs{
6935 SkipChangeCipherSpec: true,
6936 },
6937 },
6938 shouldFail: true,
6939 expectedError: ":UNEXPECTED_RECORD:",
6940 })
6941 testCases = append(testCases, testCase{
6942 testType: serverTest,
6943 name: "SkipChangeCipherSpec-Server",
6944 config: Config{
6945 MaxVersion: VersionTLS12,
6946 Bugs: ProtocolBugs{
6947 SkipChangeCipherSpec: true,
6948 },
6949 },
6950 shouldFail: true,
6951 expectedError: ":UNEXPECTED_RECORD:",
6952 })
6953 testCases = append(testCases, testCase{
6954 testType: serverTest,
6955 name: "SkipChangeCipherSpec-Server-NPN",
6956 config: Config{
6957 MaxVersion: VersionTLS12,
6958 NextProtos: []string{"bar"},
6959 Bugs: ProtocolBugs{
6960 SkipChangeCipherSpec: true,
6961 },
6962 },
6963 flags: []string{
6964 "-advertise-npn", "\x03foo\x03bar\x03baz",
6965 },
6966 shouldFail: true,
6967 expectedError: ":UNEXPECTED_RECORD:",
6968 })
6969
6970 // Test synchronization between the handshake and ChangeCipherSpec.
6971 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6972 // rejected. Test both with and without handshake packing to handle both
6973 // when the partial post-CCS message is in its own record and when it is
6974 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006975 for _, packed := range []bool{false, true} {
6976 var suffix string
6977 if packed {
6978 suffix = "-Packed"
6979 }
6980
6981 testCases = append(testCases, testCase{
6982 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6983 config: Config{
6984 MaxVersion: VersionTLS12,
6985 Bugs: ProtocolBugs{
6986 FragmentAcrossChangeCipherSpec: true,
6987 PackHandshakeFlight: packed,
6988 },
6989 },
6990 shouldFail: true,
6991 expectedError: ":UNEXPECTED_RECORD:",
6992 })
6993 testCases = append(testCases, testCase{
6994 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6995 config: Config{
6996 MaxVersion: VersionTLS12,
6997 },
6998 resumeSession: true,
6999 resumeConfig: &Config{
7000 MaxVersion: VersionTLS12,
7001 Bugs: ProtocolBugs{
7002 FragmentAcrossChangeCipherSpec: true,
7003 PackHandshakeFlight: packed,
7004 },
7005 },
7006 shouldFail: true,
7007 expectedError: ":UNEXPECTED_RECORD:",
7008 })
7009 testCases = append(testCases, testCase{
7010 testType: serverTest,
7011 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7012 config: Config{
7013 MaxVersion: VersionTLS12,
7014 Bugs: ProtocolBugs{
7015 FragmentAcrossChangeCipherSpec: true,
7016 PackHandshakeFlight: packed,
7017 },
7018 },
7019 shouldFail: true,
7020 expectedError: ":UNEXPECTED_RECORD:",
7021 })
7022 testCases = append(testCases, testCase{
7023 testType: serverTest,
7024 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7025 config: Config{
7026 MaxVersion: VersionTLS12,
7027 },
7028 resumeSession: true,
7029 resumeConfig: &Config{
7030 MaxVersion: VersionTLS12,
7031 Bugs: ProtocolBugs{
7032 FragmentAcrossChangeCipherSpec: true,
7033 PackHandshakeFlight: packed,
7034 },
7035 },
7036 shouldFail: true,
7037 expectedError: ":UNEXPECTED_RECORD:",
7038 })
7039 testCases = append(testCases, testCase{
7040 testType: serverTest,
7041 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7042 config: Config{
7043 MaxVersion: VersionTLS12,
7044 NextProtos: []string{"bar"},
7045 Bugs: ProtocolBugs{
7046 FragmentAcrossChangeCipherSpec: true,
7047 PackHandshakeFlight: packed,
7048 },
7049 },
7050 flags: []string{
7051 "-advertise-npn", "\x03foo\x03bar\x03baz",
7052 },
7053 shouldFail: true,
7054 expectedError: ":UNEXPECTED_RECORD:",
7055 })
7056 }
7057
David Benjamin61672812016-07-14 23:10:43 -04007058 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7059 // messages in the handshake queue. Do this by testing the server
7060 // reading the client Finished, reversing the flight so Finished comes
7061 // first.
7062 testCases = append(testCases, testCase{
7063 protocol: dtls,
7064 testType: serverTest,
7065 name: "SendUnencryptedFinished-DTLS",
7066 config: Config{
7067 MaxVersion: VersionTLS12,
7068 Bugs: ProtocolBugs{
7069 SendUnencryptedFinished: true,
7070 ReverseHandshakeFragments: true,
7071 },
7072 },
7073 shouldFail: true,
7074 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7075 })
7076
Steven Valdez143e8b32016-07-11 13:19:03 -04007077 // Test synchronization between encryption changes and the handshake in
7078 // TLS 1.3, where ChangeCipherSpec is implicit.
7079 testCases = append(testCases, testCase{
7080 name: "PartialEncryptedExtensionsWithServerHello",
7081 config: Config{
7082 MaxVersion: VersionTLS13,
7083 Bugs: ProtocolBugs{
7084 PartialEncryptedExtensionsWithServerHello: true,
7085 },
7086 },
7087 shouldFail: true,
7088 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7089 })
7090 testCases = append(testCases, testCase{
7091 testType: serverTest,
7092 name: "PartialClientFinishedWithClientHello",
7093 config: Config{
7094 MaxVersion: VersionTLS13,
7095 Bugs: ProtocolBugs{
7096 PartialClientFinishedWithClientHello: true,
7097 },
7098 },
7099 shouldFail: true,
7100 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7101 })
7102
David Benjamin82261be2016-07-07 14:32:50 -07007103 // Test that early ChangeCipherSpecs are handled correctly.
7104 testCases = append(testCases, testCase{
7105 testType: serverTest,
7106 name: "EarlyChangeCipherSpec-server-1",
7107 config: Config{
7108 MaxVersion: VersionTLS12,
7109 Bugs: ProtocolBugs{
7110 EarlyChangeCipherSpec: 1,
7111 },
7112 },
7113 shouldFail: true,
7114 expectedError: ":UNEXPECTED_RECORD:",
7115 })
7116 testCases = append(testCases, testCase{
7117 testType: serverTest,
7118 name: "EarlyChangeCipherSpec-server-2",
7119 config: Config{
7120 MaxVersion: VersionTLS12,
7121 Bugs: ProtocolBugs{
7122 EarlyChangeCipherSpec: 2,
7123 },
7124 },
7125 shouldFail: true,
7126 expectedError: ":UNEXPECTED_RECORD:",
7127 })
7128 testCases = append(testCases, testCase{
7129 protocol: dtls,
7130 name: "StrayChangeCipherSpec",
7131 config: Config{
7132 // TODO(davidben): Once DTLS 1.3 exists, test
7133 // that stray ChangeCipherSpec messages are
7134 // rejected.
7135 MaxVersion: VersionTLS12,
7136 Bugs: ProtocolBugs{
7137 StrayChangeCipherSpec: true,
7138 },
7139 },
7140 })
7141
7142 // Test that the contents of ChangeCipherSpec are checked.
7143 testCases = append(testCases, testCase{
7144 name: "BadChangeCipherSpec-1",
7145 config: Config{
7146 MaxVersion: VersionTLS12,
7147 Bugs: ProtocolBugs{
7148 BadChangeCipherSpec: []byte{2},
7149 },
7150 },
7151 shouldFail: true,
7152 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7153 })
7154 testCases = append(testCases, testCase{
7155 name: "BadChangeCipherSpec-2",
7156 config: Config{
7157 MaxVersion: VersionTLS12,
7158 Bugs: ProtocolBugs{
7159 BadChangeCipherSpec: []byte{1, 1},
7160 },
7161 },
7162 shouldFail: true,
7163 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7164 })
7165 testCases = append(testCases, testCase{
7166 protocol: dtls,
7167 name: "BadChangeCipherSpec-DTLS-1",
7168 config: Config{
7169 MaxVersion: VersionTLS12,
7170 Bugs: ProtocolBugs{
7171 BadChangeCipherSpec: []byte{2},
7172 },
7173 },
7174 shouldFail: true,
7175 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7176 })
7177 testCases = append(testCases, testCase{
7178 protocol: dtls,
7179 name: "BadChangeCipherSpec-DTLS-2",
7180 config: Config{
7181 MaxVersion: VersionTLS12,
7182 Bugs: ProtocolBugs{
7183 BadChangeCipherSpec: []byte{1, 1},
7184 },
7185 },
7186 shouldFail: true,
7187 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7188 })
7189}
7190
David Benjamin0b8d5da2016-07-15 00:39:56 -04007191func addWrongMessageTypeTests() {
7192 for _, protocol := range []protocol{tls, dtls} {
7193 var suffix string
7194 if protocol == dtls {
7195 suffix = "-DTLS"
7196 }
7197
7198 testCases = append(testCases, testCase{
7199 protocol: protocol,
7200 testType: serverTest,
7201 name: "WrongMessageType-ClientHello" + suffix,
7202 config: Config{
7203 MaxVersion: VersionTLS12,
7204 Bugs: ProtocolBugs{
7205 SendWrongMessageType: typeClientHello,
7206 },
7207 },
7208 shouldFail: true,
7209 expectedError: ":UNEXPECTED_MESSAGE:",
7210 expectedLocalError: "remote error: unexpected message",
7211 })
7212
7213 if protocol == dtls {
7214 testCases = append(testCases, testCase{
7215 protocol: protocol,
7216 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7217 config: Config{
7218 MaxVersion: VersionTLS12,
7219 Bugs: ProtocolBugs{
7220 SendWrongMessageType: typeHelloVerifyRequest,
7221 },
7222 },
7223 shouldFail: true,
7224 expectedError: ":UNEXPECTED_MESSAGE:",
7225 expectedLocalError: "remote error: unexpected message",
7226 })
7227 }
7228
7229 testCases = append(testCases, testCase{
7230 protocol: protocol,
7231 name: "WrongMessageType-ServerHello" + suffix,
7232 config: Config{
7233 MaxVersion: VersionTLS12,
7234 Bugs: ProtocolBugs{
7235 SendWrongMessageType: typeServerHello,
7236 },
7237 },
7238 shouldFail: true,
7239 expectedError: ":UNEXPECTED_MESSAGE:",
7240 expectedLocalError: "remote error: unexpected message",
7241 })
7242
7243 testCases = append(testCases, testCase{
7244 protocol: protocol,
7245 name: "WrongMessageType-ServerCertificate" + suffix,
7246 config: Config{
7247 MaxVersion: VersionTLS12,
7248 Bugs: ProtocolBugs{
7249 SendWrongMessageType: typeCertificate,
7250 },
7251 },
7252 shouldFail: true,
7253 expectedError: ":UNEXPECTED_MESSAGE:",
7254 expectedLocalError: "remote error: unexpected message",
7255 })
7256
7257 testCases = append(testCases, testCase{
7258 protocol: protocol,
7259 name: "WrongMessageType-CertificateStatus" + suffix,
7260 config: Config{
7261 MaxVersion: VersionTLS12,
7262 Bugs: ProtocolBugs{
7263 SendWrongMessageType: typeCertificateStatus,
7264 },
7265 },
7266 flags: []string{"-enable-ocsp-stapling"},
7267 shouldFail: true,
7268 expectedError: ":UNEXPECTED_MESSAGE:",
7269 expectedLocalError: "remote error: unexpected message",
7270 })
7271
7272 testCases = append(testCases, testCase{
7273 protocol: protocol,
7274 name: "WrongMessageType-ServerKeyExchange" + suffix,
7275 config: Config{
7276 MaxVersion: VersionTLS12,
7277 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7278 Bugs: ProtocolBugs{
7279 SendWrongMessageType: typeServerKeyExchange,
7280 },
7281 },
7282 shouldFail: true,
7283 expectedError: ":UNEXPECTED_MESSAGE:",
7284 expectedLocalError: "remote error: unexpected message",
7285 })
7286
7287 testCases = append(testCases, testCase{
7288 protocol: protocol,
7289 name: "WrongMessageType-CertificateRequest" + suffix,
7290 config: Config{
7291 MaxVersion: VersionTLS12,
7292 ClientAuth: RequireAnyClientCert,
7293 Bugs: ProtocolBugs{
7294 SendWrongMessageType: typeCertificateRequest,
7295 },
7296 },
7297 shouldFail: true,
7298 expectedError: ":UNEXPECTED_MESSAGE:",
7299 expectedLocalError: "remote error: unexpected message",
7300 })
7301
7302 testCases = append(testCases, testCase{
7303 protocol: protocol,
7304 name: "WrongMessageType-ServerHelloDone" + suffix,
7305 config: Config{
7306 MaxVersion: VersionTLS12,
7307 Bugs: ProtocolBugs{
7308 SendWrongMessageType: typeServerHelloDone,
7309 },
7310 },
7311 shouldFail: true,
7312 expectedError: ":UNEXPECTED_MESSAGE:",
7313 expectedLocalError: "remote error: unexpected message",
7314 })
7315
7316 testCases = append(testCases, testCase{
7317 testType: serverTest,
7318 protocol: protocol,
7319 name: "WrongMessageType-ClientCertificate" + suffix,
7320 config: Config{
7321 Certificates: []Certificate{rsaCertificate},
7322 MaxVersion: VersionTLS12,
7323 Bugs: ProtocolBugs{
7324 SendWrongMessageType: typeCertificate,
7325 },
7326 },
7327 flags: []string{"-require-any-client-certificate"},
7328 shouldFail: true,
7329 expectedError: ":UNEXPECTED_MESSAGE:",
7330 expectedLocalError: "remote error: unexpected message",
7331 })
7332
7333 testCases = append(testCases, testCase{
7334 testType: serverTest,
7335 protocol: protocol,
7336 name: "WrongMessageType-CertificateVerify" + suffix,
7337 config: Config{
7338 Certificates: []Certificate{rsaCertificate},
7339 MaxVersion: VersionTLS12,
7340 Bugs: ProtocolBugs{
7341 SendWrongMessageType: typeCertificateVerify,
7342 },
7343 },
7344 flags: []string{"-require-any-client-certificate"},
7345 shouldFail: true,
7346 expectedError: ":UNEXPECTED_MESSAGE:",
7347 expectedLocalError: "remote error: unexpected message",
7348 })
7349
7350 testCases = append(testCases, testCase{
7351 testType: serverTest,
7352 protocol: protocol,
7353 name: "WrongMessageType-ClientKeyExchange" + suffix,
7354 config: Config{
7355 MaxVersion: VersionTLS12,
7356 Bugs: ProtocolBugs{
7357 SendWrongMessageType: typeClientKeyExchange,
7358 },
7359 },
7360 shouldFail: true,
7361 expectedError: ":UNEXPECTED_MESSAGE:",
7362 expectedLocalError: "remote error: unexpected message",
7363 })
7364
7365 if protocol != dtls {
7366 testCases = append(testCases, testCase{
7367 testType: serverTest,
7368 protocol: protocol,
7369 name: "WrongMessageType-NextProtocol" + suffix,
7370 config: Config{
7371 MaxVersion: VersionTLS12,
7372 NextProtos: []string{"bar"},
7373 Bugs: ProtocolBugs{
7374 SendWrongMessageType: typeNextProtocol,
7375 },
7376 },
7377 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7378 shouldFail: true,
7379 expectedError: ":UNEXPECTED_MESSAGE:",
7380 expectedLocalError: "remote error: unexpected message",
7381 })
7382
7383 testCases = append(testCases, testCase{
7384 testType: serverTest,
7385 protocol: protocol,
7386 name: "WrongMessageType-ChannelID" + suffix,
7387 config: Config{
7388 MaxVersion: VersionTLS12,
7389 ChannelID: channelIDKey,
7390 Bugs: ProtocolBugs{
7391 SendWrongMessageType: typeChannelID,
7392 },
7393 },
7394 flags: []string{
7395 "-expect-channel-id",
7396 base64.StdEncoding.EncodeToString(channelIDBytes),
7397 },
7398 shouldFail: true,
7399 expectedError: ":UNEXPECTED_MESSAGE:",
7400 expectedLocalError: "remote error: unexpected message",
7401 })
7402 }
7403
7404 testCases = append(testCases, testCase{
7405 testType: serverTest,
7406 protocol: protocol,
7407 name: "WrongMessageType-ClientFinished" + suffix,
7408 config: Config{
7409 MaxVersion: VersionTLS12,
7410 Bugs: ProtocolBugs{
7411 SendWrongMessageType: typeFinished,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":UNEXPECTED_MESSAGE:",
7416 expectedLocalError: "remote error: unexpected message",
7417 })
7418
7419 testCases = append(testCases, testCase{
7420 protocol: protocol,
7421 name: "WrongMessageType-NewSessionTicket" + suffix,
7422 config: Config{
7423 MaxVersion: VersionTLS12,
7424 Bugs: ProtocolBugs{
7425 SendWrongMessageType: typeNewSessionTicket,
7426 },
7427 },
7428 shouldFail: true,
7429 expectedError: ":UNEXPECTED_MESSAGE:",
7430 expectedLocalError: "remote error: unexpected message",
7431 })
7432
7433 testCases = append(testCases, testCase{
7434 protocol: protocol,
7435 name: "WrongMessageType-ServerFinished" + suffix,
7436 config: Config{
7437 MaxVersion: VersionTLS12,
7438 Bugs: ProtocolBugs{
7439 SendWrongMessageType: typeFinished,
7440 },
7441 },
7442 shouldFail: true,
7443 expectedError: ":UNEXPECTED_MESSAGE:",
7444 expectedLocalError: "remote error: unexpected message",
7445 })
7446
7447 }
7448}
7449
Steven Valdez143e8b32016-07-11 13:19:03 -04007450func addTLS13WrongMessageTypeTests() {
7451 testCases = append(testCases, testCase{
7452 testType: serverTest,
7453 name: "WrongMessageType-TLS13-ClientHello",
7454 config: Config{
7455 MaxVersion: VersionTLS13,
7456 Bugs: ProtocolBugs{
7457 SendWrongMessageType: typeClientHello,
7458 },
7459 },
7460 shouldFail: true,
7461 expectedError: ":UNEXPECTED_MESSAGE:",
7462 expectedLocalError: "remote error: unexpected message",
7463 })
7464
7465 testCases = append(testCases, testCase{
7466 name: "WrongMessageType-TLS13-ServerHello",
7467 config: Config{
7468 MaxVersion: VersionTLS13,
7469 Bugs: ProtocolBugs{
7470 SendWrongMessageType: typeServerHello,
7471 },
7472 },
7473 shouldFail: true,
7474 expectedError: ":UNEXPECTED_MESSAGE:",
7475 // The alert comes in with the wrong encryption.
7476 expectedLocalError: "local error: bad record MAC",
7477 })
7478
7479 testCases = append(testCases, testCase{
7480 name: "WrongMessageType-TLS13-EncryptedExtensions",
7481 config: Config{
7482 MaxVersion: VersionTLS13,
7483 Bugs: ProtocolBugs{
7484 SendWrongMessageType: typeEncryptedExtensions,
7485 },
7486 },
7487 shouldFail: true,
7488 expectedError: ":UNEXPECTED_MESSAGE:",
7489 expectedLocalError: "remote error: unexpected message",
7490 })
7491
7492 testCases = append(testCases, testCase{
7493 name: "WrongMessageType-TLS13-CertificateRequest",
7494 config: Config{
7495 MaxVersion: VersionTLS13,
7496 ClientAuth: RequireAnyClientCert,
7497 Bugs: ProtocolBugs{
7498 SendWrongMessageType: typeCertificateRequest,
7499 },
7500 },
7501 shouldFail: true,
7502 expectedError: ":UNEXPECTED_MESSAGE:",
7503 expectedLocalError: "remote error: unexpected message",
7504 })
7505
7506 testCases = append(testCases, testCase{
7507 name: "WrongMessageType-TLS13-ServerCertificate",
7508 config: Config{
7509 MaxVersion: VersionTLS13,
7510 Bugs: ProtocolBugs{
7511 SendWrongMessageType: typeCertificate,
7512 },
7513 },
7514 shouldFail: true,
7515 expectedError: ":UNEXPECTED_MESSAGE:",
7516 expectedLocalError: "remote error: unexpected message",
7517 })
7518
7519 testCases = append(testCases, testCase{
7520 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7521 config: Config{
7522 MaxVersion: VersionTLS13,
7523 Bugs: ProtocolBugs{
7524 SendWrongMessageType: typeCertificateVerify,
7525 },
7526 },
7527 shouldFail: true,
7528 expectedError: ":UNEXPECTED_MESSAGE:",
7529 expectedLocalError: "remote error: unexpected message",
7530 })
7531
7532 testCases = append(testCases, testCase{
7533 name: "WrongMessageType-TLS13-ServerFinished",
7534 config: Config{
7535 MaxVersion: VersionTLS13,
7536 Bugs: ProtocolBugs{
7537 SendWrongMessageType: typeFinished,
7538 },
7539 },
7540 shouldFail: true,
7541 expectedError: ":UNEXPECTED_MESSAGE:",
7542 expectedLocalError: "remote error: unexpected message",
7543 })
7544
7545 testCases = append(testCases, testCase{
7546 testType: serverTest,
7547 name: "WrongMessageType-TLS13-ClientCertificate",
7548 config: Config{
7549 Certificates: []Certificate{rsaCertificate},
7550 MaxVersion: VersionTLS13,
7551 Bugs: ProtocolBugs{
7552 SendWrongMessageType: typeCertificate,
7553 },
7554 },
7555 flags: []string{"-require-any-client-certificate"},
7556 shouldFail: true,
7557 expectedError: ":UNEXPECTED_MESSAGE:",
7558 expectedLocalError: "remote error: unexpected message",
7559 })
7560
7561 testCases = append(testCases, testCase{
7562 testType: serverTest,
7563 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7564 config: Config{
7565 Certificates: []Certificate{rsaCertificate},
7566 MaxVersion: VersionTLS13,
7567 Bugs: ProtocolBugs{
7568 SendWrongMessageType: typeCertificateVerify,
7569 },
7570 },
7571 flags: []string{"-require-any-client-certificate"},
7572 shouldFail: true,
7573 expectedError: ":UNEXPECTED_MESSAGE:",
7574 expectedLocalError: "remote error: unexpected message",
7575 })
7576
7577 testCases = append(testCases, testCase{
7578 testType: serverTest,
7579 name: "WrongMessageType-TLS13-ClientFinished",
7580 config: Config{
7581 MaxVersion: VersionTLS13,
7582 Bugs: ProtocolBugs{
7583 SendWrongMessageType: typeFinished,
7584 },
7585 },
7586 shouldFail: true,
7587 expectedError: ":UNEXPECTED_MESSAGE:",
7588 expectedLocalError: "remote error: unexpected message",
7589 })
7590}
7591
7592func addTLS13HandshakeTests() {
7593 testCases = append(testCases, testCase{
7594 testType: clientTest,
7595 name: "MissingKeyShare-Client",
7596 config: Config{
7597 MaxVersion: VersionTLS13,
7598 Bugs: ProtocolBugs{
7599 MissingKeyShare: true,
7600 },
7601 },
7602 shouldFail: true,
7603 expectedError: ":MISSING_KEY_SHARE:",
7604 })
7605
7606 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007607 testType: serverTest,
7608 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007609 config: Config{
7610 MaxVersion: VersionTLS13,
7611 Bugs: ProtocolBugs{
7612 MissingKeyShare: true,
7613 },
7614 },
7615 shouldFail: true,
7616 expectedError: ":MISSING_KEY_SHARE:",
7617 })
7618
7619 testCases = append(testCases, testCase{
7620 testType: clientTest,
7621 name: "ClientHelloMissingKeyShare",
7622 config: Config{
7623 MaxVersion: VersionTLS13,
7624 Bugs: ProtocolBugs{
7625 MissingKeyShare: true,
7626 },
7627 },
7628 shouldFail: true,
7629 expectedError: ":MISSING_KEY_SHARE:",
7630 })
7631
7632 testCases = append(testCases, testCase{
7633 testType: clientTest,
7634 name: "MissingKeyShare",
7635 config: Config{
7636 MaxVersion: VersionTLS13,
7637 Bugs: ProtocolBugs{
7638 MissingKeyShare: true,
7639 },
7640 },
7641 shouldFail: true,
7642 expectedError: ":MISSING_KEY_SHARE:",
7643 })
7644
7645 testCases = append(testCases, testCase{
7646 testType: serverTest,
7647 name: "DuplicateKeyShares",
7648 config: Config{
7649 MaxVersion: VersionTLS13,
7650 Bugs: ProtocolBugs{
7651 DuplicateKeyShares: true,
7652 },
7653 },
7654 })
7655
7656 testCases = append(testCases, testCase{
7657 testType: clientTest,
7658 name: "EmptyEncryptedExtensions",
7659 config: Config{
7660 MaxVersion: VersionTLS13,
7661 Bugs: ProtocolBugs{
7662 EmptyEncryptedExtensions: true,
7663 },
7664 },
7665 shouldFail: true,
7666 expectedLocalError: "remote error: error decoding message",
7667 })
7668
7669 testCases = append(testCases, testCase{
7670 testType: clientTest,
7671 name: "EncryptedExtensionsWithKeyShare",
7672 config: Config{
7673 MaxVersion: VersionTLS13,
7674 Bugs: ProtocolBugs{
7675 EncryptedExtensionsWithKeyShare: true,
7676 },
7677 },
7678 shouldFail: true,
7679 expectedLocalError: "remote error: unsupported extension",
7680 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007681
7682 testCases = append(testCases, testCase{
7683 testType: serverTest,
7684 name: "SendHelloRetryRequest",
7685 config: Config{
7686 MaxVersion: VersionTLS13,
7687 // Require a HelloRetryRequest for every curve.
7688 DefaultCurves: []CurveID{},
7689 },
7690 expectedCurveID: CurveX25519,
7691 })
7692
7693 testCases = append(testCases, testCase{
7694 testType: serverTest,
7695 name: "SendHelloRetryRequest-2",
7696 config: Config{
7697 MaxVersion: VersionTLS13,
7698 DefaultCurves: []CurveID{CurveP384},
7699 },
7700 // Although the ClientHello did not predict our preferred curve,
7701 // we always select it whether it is predicted or not.
7702 expectedCurveID: CurveX25519,
7703 })
7704
7705 testCases = append(testCases, testCase{
7706 name: "UnknownCurve-HelloRetryRequest",
7707 config: Config{
7708 MaxVersion: VersionTLS13,
7709 // P-384 requires HelloRetryRequest in BoringSSL.
7710 CurvePreferences: []CurveID{CurveP384},
7711 Bugs: ProtocolBugs{
7712 SendHelloRetryRequestCurve: bogusCurve,
7713 },
7714 },
7715 shouldFail: true,
7716 expectedError: ":WRONG_CURVE:",
7717 })
7718
7719 testCases = append(testCases, testCase{
7720 name: "DisabledCurve-HelloRetryRequest",
7721 config: Config{
7722 MaxVersion: VersionTLS13,
7723 CurvePreferences: []CurveID{CurveP256},
7724 Bugs: ProtocolBugs{
7725 IgnorePeerCurvePreferences: true,
7726 },
7727 },
7728 flags: []string{"-p384-only"},
7729 shouldFail: true,
7730 expectedError: ":WRONG_CURVE:",
7731 })
7732
7733 testCases = append(testCases, testCase{
7734 name: "UnnecessaryHelloRetryRequest",
7735 config: Config{
7736 MaxVersion: VersionTLS13,
7737 Bugs: ProtocolBugs{
7738 UnnecessaryHelloRetryRequest: true,
7739 },
7740 },
7741 shouldFail: true,
7742 expectedError: ":WRONG_CURVE:",
7743 })
7744
7745 testCases = append(testCases, testCase{
7746 name: "SecondHelloRetryRequest",
7747 config: Config{
7748 MaxVersion: VersionTLS13,
7749 // P-384 requires HelloRetryRequest in BoringSSL.
7750 CurvePreferences: []CurveID{CurveP384},
7751 Bugs: ProtocolBugs{
7752 SecondHelloRetryRequest: true,
7753 },
7754 },
7755 shouldFail: true,
7756 expectedError: ":UNEXPECTED_MESSAGE:",
7757 })
7758
7759 testCases = append(testCases, testCase{
7760 testType: serverTest,
7761 name: "SecondClientHelloMissingKeyShare",
7762 config: Config{
7763 MaxVersion: VersionTLS13,
7764 DefaultCurves: []CurveID{},
7765 Bugs: ProtocolBugs{
7766 SecondClientHelloMissingKeyShare: true,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":MISSING_KEY_SHARE:",
7771 })
7772
7773 testCases = append(testCases, testCase{
7774 testType: serverTest,
7775 name: "SecondClientHelloWrongCurve",
7776 config: Config{
7777 MaxVersion: VersionTLS13,
7778 DefaultCurves: []CurveID{},
7779 Bugs: ProtocolBugs{
7780 MisinterpretHelloRetryRequestCurve: CurveP521,
7781 },
7782 },
7783 shouldFail: true,
7784 expectedError: ":WRONG_CURVE:",
7785 })
7786
7787 testCases = append(testCases, testCase{
7788 name: "HelloRetryRequestVersionMismatch",
7789 config: Config{
7790 MaxVersion: VersionTLS13,
7791 // P-384 requires HelloRetryRequest in BoringSSL.
7792 CurvePreferences: []CurveID{CurveP384},
7793 Bugs: ProtocolBugs{
7794 SendServerHelloVersion: 0x0305,
7795 },
7796 },
7797 shouldFail: true,
7798 expectedError: ":WRONG_VERSION_NUMBER:",
7799 })
7800
7801 testCases = append(testCases, testCase{
7802 name: "HelloRetryRequestCurveMismatch",
7803 config: Config{
7804 MaxVersion: VersionTLS13,
7805 // P-384 requires HelloRetryRequest in BoringSSL.
7806 CurvePreferences: []CurveID{CurveP384},
7807 Bugs: ProtocolBugs{
7808 // Send P-384 (correct) in the HelloRetryRequest.
7809 SendHelloRetryRequestCurve: CurveP384,
7810 // But send P-256 in the ServerHello.
7811 SendCurve: CurveP256,
7812 },
7813 },
7814 shouldFail: true,
7815 expectedError: ":WRONG_CURVE:",
7816 })
7817
7818 // Test the server selecting a curve that requires a HelloRetryRequest
7819 // without sending it.
7820 testCases = append(testCases, testCase{
7821 name: "SkipHelloRetryRequest",
7822 config: Config{
7823 MaxVersion: VersionTLS13,
7824 // P-384 requires HelloRetryRequest in BoringSSL.
7825 CurvePreferences: []CurveID{CurveP384},
7826 Bugs: ProtocolBugs{
7827 SkipHelloRetryRequest: true,
7828 },
7829 },
7830 shouldFail: true,
7831 expectedError: ":WRONG_CURVE:",
7832 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007833}
7834
Adam Langley7c803a62015-06-15 15:35:05 -07007835func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007836 defer wg.Done()
7837
7838 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007839 var err error
7840
7841 if *mallocTest < 0 {
7842 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007843 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007844 } else {
7845 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7846 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007847 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007848 if err != nil {
7849 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7850 }
7851 break
7852 }
7853 }
7854 }
Adam Langley95c29f32014-06-20 12:00:00 -07007855 statusChan <- statusMsg{test: test, err: err}
7856 }
7857}
7858
7859type statusMsg struct {
7860 test *testCase
7861 started bool
7862 err error
7863}
7864
David Benjamin5f237bc2015-02-11 17:14:15 -05007865func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007866 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007867
David Benjamin5f237bc2015-02-11 17:14:15 -05007868 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007869 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007870 if !*pipe {
7871 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007872 var erase string
7873 for i := 0; i < lineLen; i++ {
7874 erase += "\b \b"
7875 }
7876 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007877 }
7878
Adam Langley95c29f32014-06-20 12:00:00 -07007879 if msg.started {
7880 started++
7881 } else {
7882 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007883
7884 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02007885 if msg.err == errUnimplemented {
7886 if *pipe {
7887 // Print each test instead of a status line.
7888 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
7889 }
7890 unimplemented++
7891 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
7892 } else {
7893 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7894 failed++
7895 testOutput.addResult(msg.test.name, "FAIL")
7896 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007897 } else {
7898 if *pipe {
7899 // Print each test instead of a status line.
7900 fmt.Printf("PASSED (%s)\n", msg.test.name)
7901 }
7902 testOutput.addResult(msg.test.name, "PASS")
7903 }
Adam Langley95c29f32014-06-20 12:00:00 -07007904 }
7905
David Benjamin5f237bc2015-02-11 17:14:15 -05007906 if !*pipe {
7907 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02007908 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05007909 lineLen = len(line)
7910 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007911 }
Adam Langley95c29f32014-06-20 12:00:00 -07007912 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007913
7914 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007915}
7916
7917func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007918 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007919 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007920 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007921
Adam Langley7c803a62015-06-15 15:35:05 -07007922 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007923 addCipherSuiteTests()
7924 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007925 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007926 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007927 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007928 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007929 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007930 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007931 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007932 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007933 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007934 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007935 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007936 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007937 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007938 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007939 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007940 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007941 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007942 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007943 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007944 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007945 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007946 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007947 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007948 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007949 addTLS13WrongMessageTypeTests()
7950 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007951
7952 var wg sync.WaitGroup
7953
Adam Langley7c803a62015-06-15 15:35:05 -07007954 statusChan := make(chan statusMsg, *numWorkers)
7955 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007956 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007957
David Benjamin025b3d32014-07-01 19:53:04 -04007958 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007959
Adam Langley7c803a62015-06-15 15:35:05 -07007960 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007961 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007962 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007963 }
7964
David Benjamin270f0a72016-03-17 14:41:36 -04007965 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007966 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04007967 matched := true
7968 if len(*testToRun) != 0 {
7969 var err error
7970 matched, err = filepath.Match(*testToRun, testCases[i].name)
7971 if err != nil {
7972 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
7973 os.Exit(1)
7974 }
7975 }
7976
7977 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04007978 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007979 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007980 }
7981 }
David Benjamin17e12922016-07-28 18:04:43 -04007982
David Benjamin270f0a72016-03-17 14:41:36 -04007983 if !foundTest {
David Benjamin17e12922016-07-28 18:04:43 -04007984 fmt.Fprintf(os.Stderr, "No tests matched %q\n", *testToRun)
David Benjamin270f0a72016-03-17 14:41:36 -04007985 os.Exit(1)
7986 }
Adam Langley95c29f32014-06-20 12:00:00 -07007987
7988 close(testChan)
7989 wg.Wait()
7990 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007991 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007992
7993 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007994
7995 if *jsonOutput != "" {
7996 if err := testOutput.writeTo(*jsonOutput); err != nil {
7997 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7998 }
7999 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008000
EKR842ae6c2016-07-27 09:22:05 +02008001 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8002 os.Exit(1)
8003 }
8004
8005 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008006 os.Exit(1)
8007 }
Adam Langley95c29f32014-06-20 12:00:00 -07008008}