blob: e5faae5207f6ca476db0034c9e03c90a4baca209 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 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.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin33863262016-07-08 17:20:12 -070060type testCert int
61
David Benjamin025b3d32014-07-01 19:53:04 -040062const (
David Benjamin33863262016-07-08 17:20:12 -070063 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040064 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070065 testCertECDSAP256
66 testCertECDSAP384
67 testCertECDSAP521
68)
69
70const (
71 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040072 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070073 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
74 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
75 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040076)
77
78const (
David Benjamina08e49d2014-08-24 01:46:07 -040079 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040080 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070081 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
82 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
83 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040084 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040085)
86
David Benjamin7944a9f2016-07-12 22:27:01 -040087var (
88 rsaCertificate Certificate
89 rsa1024Certificate Certificate
90 ecdsaP256Certificate Certificate
91 ecdsaP384Certificate Certificate
92 ecdsaP521Certificate Certificate
93)
David Benjamin33863262016-07-08 17:20:12 -070094
95var testCerts = []struct {
96 id testCert
97 certFile, keyFile string
98 cert *Certificate
99}{
100 {
101 id: testCertRSA,
102 certFile: rsaCertificateFile,
103 keyFile: rsaKeyFile,
104 cert: &rsaCertificate,
105 },
106 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 id: testCertRSA1024,
108 certFile: rsa1024CertificateFile,
109 keyFile: rsa1024KeyFile,
110 cert: &rsa1024Certificate,
111 },
112 {
David Benjamin33863262016-07-08 17:20:12 -0700113 id: testCertECDSAP256,
114 certFile: ecdsaP256CertificateFile,
115 keyFile: ecdsaP256KeyFile,
116 cert: &ecdsaP256Certificate,
117 },
118 {
119 id: testCertECDSAP384,
120 certFile: ecdsaP384CertificateFile,
121 keyFile: ecdsaP384KeyFile,
122 cert: &ecdsaP384Certificate,
123 },
124 {
125 id: testCertECDSAP521,
126 certFile: ecdsaP521CertificateFile,
127 keyFile: ecdsaP521KeyFile,
128 cert: &ecdsaP521Certificate,
129 },
130}
131
David Benjamina08e49d2014-08-24 01:46:07 -0400132var channelIDKey *ecdsa.PrivateKey
133var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700134
David Benjamin61f95272014-11-25 01:55:35 -0500135var testOCSPResponse = []byte{1, 2, 3, 4}
136var testSCTList = []byte{5, 6, 7, 8}
137
Adam Langley95c29f32014-06-20 12:00:00 -0700138func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700139 for i := range testCerts {
140 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
141 if err != nil {
142 panic(err)
143 }
144 cert.OCSPStaple = testOCSPResponse
145 cert.SignedCertificateTimestampList = testSCTList
146 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700147 }
David Benjamina08e49d2014-08-24 01:46:07 -0400148
Adam Langley7c803a62015-06-15 15:35:05 -0700149 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400150 if err != nil {
151 panic(err)
152 }
153 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
154 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
155 panic("bad key type")
156 }
157 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
158 if err != nil {
159 panic(err)
160 }
161 if channelIDKey.Curve != elliptic.P256() {
162 panic("bad curve")
163 }
164
165 channelIDBytes = make([]byte, 64)
166 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
167 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700168}
169
David Benjamin33863262016-07-08 17:20:12 -0700170func getRunnerCertificate(t testCert) Certificate {
171 for _, cert := range testCerts {
172 if cert.id == t {
173 return *cert.cert
174 }
175 }
176 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700177}
178
David Benjamin33863262016-07-08 17:20:12 -0700179func getShimCertificate(t testCert) string {
180 for _, cert := range testCerts {
181 if cert.id == t {
182 return cert.certFile
183 }
184 }
185 panic("Unknown test certificate")
186}
187
188func getShimKey(t testCert) string {
189 for _, cert := range testCerts {
190 if cert.id == t {
191 return cert.keyFile
192 }
193 }
194 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700195}
196
David Benjamin025b3d32014-07-01 19:53:04 -0400197type testType int
198
199const (
200 clientTest testType = iota
201 serverTest
202)
203
David Benjamin6fd297b2014-08-11 18:43:38 -0400204type protocol int
205
206const (
207 tls protocol = iota
208 dtls
209)
210
David Benjaminfc7b0862014-09-06 13:21:53 -0400211const (
212 alpn = 1
213 npn = 2
214)
215
Adam Langley95c29f32014-06-20 12:00:00 -0700216type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400217 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400218 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700219 name string
220 config Config
221 shouldFail bool
222 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700223 // expectedLocalError, if not empty, contains a substring that must be
224 // found in the local error.
225 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400226 // expectedVersion, if non-zero, specifies the TLS version that must be
227 // negotiated.
228 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400229 // expectedResumeVersion, if non-zero, specifies the TLS version that
230 // must be negotiated on resumption. If zero, expectedVersion is used.
231 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400232 // expectedCipher, if non-zero, specifies the TLS cipher suite that
233 // should be negotiated.
234 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400235 // expectChannelID controls whether the connection should have
236 // negotiated a Channel ID with channelIDKey.
237 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400238 // expectedNextProto controls whether the connection should
239 // negotiate a next protocol via NPN or ALPN.
240 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400241 // expectNoNextProto, if true, means that no next protocol should be
242 // negotiated.
243 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400244 // expectedNextProtoType, if non-zero, is the expected next
245 // protocol negotiation mechanism.
246 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500247 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
248 // should be negotiated. If zero, none should be negotiated.
249 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100250 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
251 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100252 // expectedSCTList, if not nil, is the expected SCT list to be received.
253 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700254 // expectedPeerSignatureAlgorithm, if not zero, is the signature
255 // algorithm that the peer should have used in the handshake.
256 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700257 // messageLen is the length, in bytes, of the test message that will be
258 // sent.
259 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400260 // messageCount is the number of test messages that will be sent.
261 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400262 // certFile is the path to the certificate to use for the server.
263 certFile string
264 // keyFile is the path to the private key to use for the server.
265 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400266 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400267 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400268 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700269 // expectResumeRejected, if true, specifies that the attempted
270 // resumption must be rejected by the client. This is only valid for a
271 // serverTest.
272 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400273 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500274 // resumption. Unless newSessionsOnResume is set,
275 // SessionTicketKey, ServerSessionCache, and
276 // ClientSessionCache are copied from the initial connection's
277 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400278 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500279 // newSessionsOnResume, if true, will cause resumeConfig to
280 // use a different session resumption context.
281 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400282 // noSessionCache, if true, will cause the server to run without a
283 // session cache.
284 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400285 // sendPrefix sends a prefix on the socket before actually performing a
286 // handshake.
287 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400288 // shimWritesFirst controls whether the shim sends an initial "hello"
289 // message before doing a roundtrip with the runner.
290 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400291 // shimShutsDown, if true, runs a test where the shim shuts down the
292 // connection immediately after the handshake rather than echoing
293 // messages from the runner.
294 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400295 // renegotiate indicates the number of times the connection should be
296 // renegotiated during the exchange.
297 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700298 // renegotiateCiphers is a list of ciphersuite ids that will be
299 // switched in just before renegotiation.
300 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500301 // replayWrites, if true, configures the underlying transport
302 // to replay every write it makes in DTLS tests.
303 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500304 // damageFirstWrite, if true, configures the underlying transport to
305 // damage the final byte of the first application data write.
306 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400307 // exportKeyingMaterial, if non-zero, configures the test to exchange
308 // keying material and verify they match.
309 exportKeyingMaterial int
310 exportLabel string
311 exportContext string
312 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400313 // flags, if not empty, contains a list of command-line flags that will
314 // be passed to the shim program.
315 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700316 // testTLSUnique, if true, causes the shim to send the tls-unique value
317 // which will be compared against the expected value.
318 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400319 // sendEmptyRecords is the number of consecutive empty records to send
320 // before and after the test message.
321 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400322 // sendWarningAlerts is the number of consecutive warning alerts to send
323 // before and after the test message.
324 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400325 // expectMessageDropped, if true, means the test message is expected to
326 // be dropped by the client rather than echoed back.
327 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700328}
329
Adam Langley7c803a62015-06-15 15:35:05 -0700330var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700331
David Benjamin9867b7d2016-03-01 23:25:48 -0500332func writeTranscript(test *testCase, isResume bool, data []byte) {
333 if len(data) == 0 {
334 return
335 }
336
337 protocol := "tls"
338 if test.protocol == dtls {
339 protocol = "dtls"
340 }
341
342 side := "client"
343 if test.testType == serverTest {
344 side = "server"
345 }
346
347 dir := path.Join(*transcriptDir, protocol, side)
348 if err := os.MkdirAll(dir, 0755); err != nil {
349 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
350 return
351 }
352
353 name := test.name
354 if isResume {
355 name += "-Resume"
356 } else {
357 name += "-Normal"
358 }
359
360 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
361 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
362 }
363}
364
David Benjamin3ed59772016-03-08 12:50:21 -0500365// A timeoutConn implements an idle timeout on each Read and Write operation.
366type timeoutConn struct {
367 net.Conn
368 timeout time.Duration
369}
370
371func (t *timeoutConn) Read(b []byte) (int, error) {
372 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
373 return 0, err
374 }
375 return t.Conn.Read(b)
376}
377
378func (t *timeoutConn) Write(b []byte) (int, error) {
379 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
380 return 0, err
381 }
382 return t.Conn.Write(b)
383}
384
David Benjamin8e6db492015-07-25 18:29:23 -0400385func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400386 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500387
David Benjamin6fd297b2014-08-11 18:43:38 -0400388 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500389 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
390 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500391 }
392
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500394 local, peer := "client", "server"
395 if test.testType == clientTest {
396 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500397 }
David Benjaminebda9b32015-11-02 15:33:18 -0500398 connDebug := &recordingConn{
399 Conn: conn,
400 isDatagram: test.protocol == dtls,
401 local: local,
402 peer: peer,
403 }
404 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500405 if *flagDebug {
406 defer connDebug.WriteTo(os.Stdout)
407 }
408 if len(*transcriptDir) != 0 {
409 defer func() {
410 writeTranscript(test, isResume, connDebug.Transcript())
411 }()
412 }
David Benjaminebda9b32015-11-02 15:33:18 -0500413
414 if config.Bugs.PacketAdaptor != nil {
415 config.Bugs.PacketAdaptor.debug = connDebug
416 }
417 }
418
419 if test.replayWrites {
420 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400421 }
422
David Benjamin3ed59772016-03-08 12:50:21 -0500423 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 if test.damageFirstWrite {
425 connDamage = newDamageAdaptor(conn)
426 conn = connDamage
427 }
428
David Benjamin6fd297b2014-08-11 18:43:38 -0400429 if test.sendPrefix != "" {
430 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
431 return err
432 }
David Benjamin98e882e2014-08-08 13:24:34 -0400433 }
434
David Benjamin1d5c83e2014-07-22 19:20:02 -0400435 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400436 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400437 if test.protocol == dtls {
438 tlsConn = DTLSServer(conn, config)
439 } else {
440 tlsConn = Server(conn, config)
441 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400442 } else {
443 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400444 if test.protocol == dtls {
445 tlsConn = DTLSClient(conn, config)
446 } else {
447 tlsConn = Client(conn, config)
448 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400449 }
David Benjamin30789da2015-08-29 22:56:45 -0400450 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451
Adam Langley95c29f32014-06-20 12:00:00 -0700452 if err := tlsConn.Handshake(); err != nil {
453 return err
454 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700455
David Benjamin01fe8202014-09-24 15:21:44 -0400456 // TODO(davidben): move all per-connection expectations into a dedicated
457 // expectations struct that can be specified separately for the two
458 // legs.
459 expectedVersion := test.expectedVersion
460 if isResume && test.expectedResumeVersion != 0 {
461 expectedVersion = test.expectedResumeVersion
462 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700463 connState := tlsConn.ConnectionState()
464 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400465 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400466 }
467
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700468 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400469 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
470 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700471 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
472 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
473 }
David Benjamin90da8c82015-04-20 14:57:57 -0400474
David Benjamina08e49d2014-08-24 01:46:07 -0400475 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700476 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400477 if channelID == nil {
478 return fmt.Errorf("no channel ID negotiated")
479 }
480 if channelID.Curve != channelIDKey.Curve ||
481 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
482 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
483 return fmt.Errorf("incorrect channel ID")
484 }
485 }
486
David Benjaminae2888f2014-09-06 12:58:58 -0400487 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700488 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400489 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
490 }
491 }
492
David Benjaminc7ce9772015-10-09 19:32:41 -0400493 if test.expectNoNextProto {
494 if actual := connState.NegotiatedProtocol; actual != "" {
495 return fmt.Errorf("got unexpected next proto %s", actual)
496 }
497 }
498
David Benjaminfc7b0862014-09-06 13:21:53 -0400499 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700500 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400501 return fmt.Errorf("next proto type mismatch")
502 }
503 }
504
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700505 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500506 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
507 }
508
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100509 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
510 return fmt.Errorf("OCSP Response mismatch")
511 }
512
Paul Lietar4fac72e2015-09-09 13:44:55 +0100513 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
514 return fmt.Errorf("SCT list mismatch")
515 }
516
Nick Harper60edffd2016-06-21 15:19:24 -0700517 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
518 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400519 }
520
David Benjaminc565ebb2015-04-03 04:06:36 -0400521 if test.exportKeyingMaterial > 0 {
522 actual := make([]byte, test.exportKeyingMaterial)
523 if _, err := io.ReadFull(tlsConn, actual); err != nil {
524 return err
525 }
526 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
527 if err != nil {
528 return err
529 }
530 if !bytes.Equal(actual, expected) {
531 return fmt.Errorf("keying material mismatch")
532 }
533 }
534
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700535 if test.testTLSUnique {
536 var peersValue [12]byte
537 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
538 return err
539 }
540 expected := tlsConn.ConnectionState().TLSUnique
541 if !bytes.Equal(peersValue[:], expected) {
542 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
543 }
544 }
545
David Benjamine58c4f52014-08-24 03:47:07 -0400546 if test.shimWritesFirst {
547 var buf [5]byte
548 _, err := io.ReadFull(tlsConn, buf[:])
549 if err != nil {
550 return err
551 }
552 if string(buf[:]) != "hello" {
553 return fmt.Errorf("bad initial message")
554 }
555 }
556
David Benjamina8ebe222015-06-06 03:04:39 -0400557 for i := 0; i < test.sendEmptyRecords; i++ {
558 tlsConn.Write(nil)
559 }
560
David Benjamin24f346d2015-06-06 03:28:08 -0400561 for i := 0; i < test.sendWarningAlerts; i++ {
562 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
563 }
564
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400565 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700566 if test.renegotiateCiphers != nil {
567 config.CipherSuites = test.renegotiateCiphers
568 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400569 for i := 0; i < test.renegotiate; i++ {
570 if err := tlsConn.Renegotiate(); err != nil {
571 return err
572 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700573 }
574 } else if test.renegotiateCiphers != nil {
575 panic("renegotiateCiphers without renegotiate")
576 }
577
David Benjamin5fa3eba2015-01-22 16:35:40 -0500578 if test.damageFirstWrite {
579 connDamage.setDamage(true)
580 tlsConn.Write([]byte("DAMAGED WRITE"))
581 connDamage.setDamage(false)
582 }
583
David Benjamin8e6db492015-07-25 18:29:23 -0400584 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700585 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
588 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700589 // Read until EOF.
590 _, err := io.Copy(ioutil.Discard, tlsConn)
591 return err
592 }
David Benjamin4417d052015-04-05 04:17:25 -0400593 if messageLen == 0 {
594 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700595 }
Adam Langley95c29f32014-06-20 12:00:00 -0700596
David Benjamin8e6db492015-07-25 18:29:23 -0400597 messageCount := test.messageCount
598 if messageCount == 0 {
599 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400600 }
601
David Benjamin8e6db492015-07-25 18:29:23 -0400602 for j := 0; j < messageCount; j++ {
603 testMessage := make([]byte, messageLen)
604 for i := range testMessage {
605 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400606 }
David Benjamin8e6db492015-07-25 18:29:23 -0400607 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700608
David Benjamin8e6db492015-07-25 18:29:23 -0400609 for i := 0; i < test.sendEmptyRecords; i++ {
610 tlsConn.Write(nil)
611 }
612
613 for i := 0; i < test.sendWarningAlerts; i++ {
614 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
615 }
616
David Benjamin4f75aaf2015-09-01 16:53:10 -0400617 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400618 // The shim will not respond.
619 continue
620 }
621
David Benjamin8e6db492015-07-25 18:29:23 -0400622 buf := make([]byte, len(testMessage))
623 if test.protocol == dtls {
624 bufTmp := make([]byte, len(buf)+1)
625 n, err := tlsConn.Read(bufTmp)
626 if err != nil {
627 return err
628 }
629 if n != len(buf) {
630 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
631 }
632 copy(buf, bufTmp)
633 } else {
634 _, err := io.ReadFull(tlsConn, buf)
635 if err != nil {
636 return err
637 }
638 }
639
640 for i, v := range buf {
641 if v != testMessage[i]^0xff {
642 return fmt.Errorf("bad reply contents at byte %d", i)
643 }
Adam Langley95c29f32014-06-20 12:00:00 -0700644 }
645 }
646
647 return nil
648}
649
David Benjamin325b5c32014-07-01 19:40:31 -0400650func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
651 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700652 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400653 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700654 }
David Benjamin325b5c32014-07-01 19:40:31 -0400655 valgrindArgs = append(valgrindArgs, path)
656 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700657
David Benjamin325b5c32014-07-01 19:40:31 -0400658 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700659}
660
David Benjamin325b5c32014-07-01 19:40:31 -0400661func gdbOf(path string, args ...string) *exec.Cmd {
662 xtermArgs := []string{"-e", "gdb", "--args"}
663 xtermArgs = append(xtermArgs, path)
664 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin325b5c32014-07-01 19:40:31 -0400666 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700667}
668
David Benjamind16bf342015-12-18 00:53:12 -0500669func lldbOf(path string, args ...string) *exec.Cmd {
670 xtermArgs := []string{"-e", "lldb", "--"}
671 xtermArgs = append(xtermArgs, path)
672 xtermArgs = append(xtermArgs, args...)
673
674 return exec.Command("xterm", xtermArgs...)
675}
676
Adam Langley69a01602014-11-17 17:26:55 -0800677type moreMallocsError struct{}
678
679func (moreMallocsError) Error() string {
680 return "child process did not exhaust all allocation calls"
681}
682
683var errMoreMallocs = moreMallocsError{}
684
David Benjamin87c8a642015-02-21 01:54:29 -0500685// accept accepts a connection from listener, unless waitChan signals a process
686// exit first.
687func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
688 type connOrError struct {
689 conn net.Conn
690 err error
691 }
692 connChan := make(chan connOrError, 1)
693 go func() {
694 conn, err := listener.Accept()
695 connChan <- connOrError{conn, err}
696 close(connChan)
697 }()
698 select {
699 case result := <-connChan:
700 return result.conn, result.err
701 case childErr := <-waitChan:
702 waitChan <- childErr
703 return nil, fmt.Errorf("child exited early: %s", childErr)
704 }
705}
706
Adam Langley7c803a62015-06-15 15:35:05 -0700707func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700708 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
709 panic("Error expected without shouldFail in " + test.name)
710 }
711
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700712 if test.expectResumeRejected && !test.resumeSession {
713 panic("expectResumeRejected without resumeSession in " + test.name)
714 }
715
David Benjamin87c8a642015-02-21 01:54:29 -0500716 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
717 if err != nil {
718 panic(err)
719 }
720 defer func() {
721 if listener != nil {
722 listener.Close()
723 }
724 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700725
David Benjamin87c8a642015-02-21 01:54:29 -0500726 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400727 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400728 flags = append(flags, "-server")
729
David Benjamin025b3d32014-07-01 19:53:04 -0400730 flags = append(flags, "-key-file")
731 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700732 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400733 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700734 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400735 }
736
737 flags = append(flags, "-cert-file")
738 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700739 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400740 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 }
743 }
David Benjamin5a593af2014-08-11 19:51:50 -0400744
David Benjamin6fd297b2014-08-11 18:43:38 -0400745 if test.protocol == dtls {
746 flags = append(flags, "-dtls")
747 }
748
David Benjamin5a593af2014-08-11 19:51:50 -0400749 if test.resumeSession {
750 flags = append(flags, "-resume")
751 }
752
David Benjamine58c4f52014-08-24 03:47:07 -0400753 if test.shimWritesFirst {
754 flags = append(flags, "-shim-writes-first")
755 }
756
David Benjamin30789da2015-08-29 22:56:45 -0400757 if test.shimShutsDown {
758 flags = append(flags, "-shim-shuts-down")
759 }
760
David Benjaminc565ebb2015-04-03 04:06:36 -0400761 if test.exportKeyingMaterial > 0 {
762 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
763 flags = append(flags, "-export-label", test.exportLabel)
764 flags = append(flags, "-export-context", test.exportContext)
765 if test.useExportContext {
766 flags = append(flags, "-use-export-context")
767 }
768 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700769 if test.expectResumeRejected {
770 flags = append(flags, "-expect-session-miss")
771 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400772
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700773 if test.testTLSUnique {
774 flags = append(flags, "-tls-unique")
775 }
776
David Benjamin025b3d32014-07-01 19:53:04 -0400777 flags = append(flags, test.flags...)
778
779 var shim *exec.Cmd
780 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700781 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700782 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700783 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500784 } else if *useLLDB {
785 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400786 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700787 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400788 }
David Benjamin025b3d32014-07-01 19:53:04 -0400789 shim.Stdin = os.Stdin
790 var stdoutBuf, stderrBuf bytes.Buffer
791 shim.Stdout = &stdoutBuf
792 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800793 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500794 shim.Env = os.Environ()
795 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800796 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400797 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800798 }
799 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
800 }
David Benjamin025b3d32014-07-01 19:53:04 -0400801
802 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700803 panic(err)
804 }
David Benjamin87c8a642015-02-21 01:54:29 -0500805 waitChan := make(chan error, 1)
806 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
808 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400809 if !test.noSessionCache {
810 config.ClientSessionCache = NewLRUClientSessionCache(1)
811 config.ServerSessionCache = NewLRUServerSessionCache(1)
812 }
David Benjamin025b3d32014-07-01 19:53:04 -0400813 if test.testType == clientTest {
814 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700815 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400816 }
David Benjamin87c8a642015-02-21 01:54:29 -0500817 } else {
818 // Supply a ServerName to ensure a constant session cache key,
819 // rather than falling back to net.Conn.RemoteAddr.
820 if len(config.ServerName) == 0 {
821 config.ServerName = "test"
822 }
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
David Benjaminf2b83632016-03-01 22:57:46 -0500824 if *fuzzer {
825 config.Bugs.NullAllCiphers = true
826 }
David Benjamin2e045a92016-06-08 13:09:56 -0400827 if *deterministic {
828 config.Rand = &deterministicRand{}
829 }
Adam Langley95c29f32014-06-20 12:00:00 -0700830
David Benjamin87c8a642015-02-21 01:54:29 -0500831 conn, err := acceptOrWait(listener, waitChan)
832 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400833 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500834 conn.Close()
835 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500836
David Benjamin1d5c83e2014-07-22 19:20:02 -0400837 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400838 var resumeConfig Config
839 if test.resumeConfig != nil {
840 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500841 if len(resumeConfig.ServerName) == 0 {
842 resumeConfig.ServerName = config.ServerName
843 }
David Benjamin01fe8202014-09-24 15:21:44 -0400844 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700845 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400846 }
David Benjaminba4594a2015-06-18 18:36:15 -0400847 if test.newSessionsOnResume {
848 if !test.noSessionCache {
849 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
850 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
851 }
852 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500853 resumeConfig.SessionTicketKey = config.SessionTicketKey
854 resumeConfig.ClientSessionCache = config.ClientSessionCache
855 resumeConfig.ServerSessionCache = config.ServerSessionCache
856 }
David Benjaminf2b83632016-03-01 22:57:46 -0500857 if *fuzzer {
858 resumeConfig.Bugs.NullAllCiphers = true
859 }
David Benjamin2e045a92016-06-08 13:09:56 -0400860 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400861 } else {
862 resumeConfig = config
863 }
David Benjamin87c8a642015-02-21 01:54:29 -0500864 var connResume net.Conn
865 connResume, err = acceptOrWait(listener, waitChan)
866 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400867 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500868 connResume.Close()
869 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400870 }
871
David Benjamin87c8a642015-02-21 01:54:29 -0500872 // Close the listener now. This is to avoid hangs should the shim try to
873 // open more connections than expected.
874 listener.Close()
875 listener = nil
876
877 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800878 if exitError, ok := childErr.(*exec.ExitError); ok {
879 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
880 return errMoreMallocs
881 }
882 }
Adam Langley95c29f32014-06-20 12:00:00 -0700883
David Benjamin9bea3492016-03-02 10:59:16 -0500884 // Account for Windows line endings.
885 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
886 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500887
888 // Separate the errors from the shim and those from tools like
889 // AddressSanitizer.
890 var extraStderr string
891 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
892 stderr = stderrParts[0]
893 extraStderr = stderrParts[1]
894 }
895
Adam Langley95c29f32014-06-20 12:00:00 -0700896 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400897 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700898 localError := "none"
899 if err != nil {
900 localError = err.Error()
901 }
902 if len(test.expectedLocalError) != 0 {
903 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
904 }
Adam Langley95c29f32014-06-20 12:00:00 -0700905
906 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700907 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700908 if childErr != nil {
909 childError = childErr.Error()
910 }
911
912 var msg string
913 switch {
914 case failed && !test.shouldFail:
915 msg = "unexpected failure"
916 case !failed && test.shouldFail:
917 msg = "unexpected success"
918 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700919 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700920 default:
921 panic("internal error")
922 }
923
David Benjaminc565ebb2015-04-03 04:06:36 -0400924 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 -0700925 }
926
David Benjaminff3a1492016-03-02 10:12:06 -0500927 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
928 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700929 }
930
931 return nil
932}
933
934var tlsVersions = []struct {
935 name string
936 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400937 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500938 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700939}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500940 {"SSL3", VersionSSL30, "-no-ssl3", false},
941 {"TLS1", VersionTLS10, "-no-tls1", true},
942 {"TLS11", VersionTLS11, "-no-tls11", false},
943 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400944 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700945}
946
947var testCipherSuites = []struct {
948 name string
949 id uint16
950}{
951 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400952 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700953 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400954 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400955 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700956 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400957 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400958 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
959 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400960 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400961 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
962 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400963 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700964 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
965 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400966 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
967 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700968 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400969 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500970 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500971 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700974 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400975 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400976 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700977 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400978 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500979 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500980 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700982 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
983 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
984 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
985 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400986 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
987 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700988 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
989 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500990 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400991 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
992 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400993 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700994 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400995 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700996 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700997}
998
David Benjamin8b8c0062014-11-23 02:47:52 -0500999func hasComponent(suiteName, component string) bool {
1000 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1001}
1002
David Benjaminf7768e42014-08-31 02:06:47 -04001003func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001004 return hasComponent(suiteName, "GCM") ||
1005 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001006 hasComponent(suiteName, "SHA384") ||
1007 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001008}
1009
Nick Harper1fd39d82016-06-14 18:14:35 -07001010func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001011 // Only AEADs.
1012 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1013 return false
1014 }
1015 // No old CHACHA20_POLY1305.
1016 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1017 return false
1018 }
1019 // Must have ECDHE.
1020 // TODO(davidben,svaldez): Add pure PSK support.
1021 if !hasComponent(suiteName, "ECDHE") {
1022 return false
1023 }
1024 // TODO(davidben,svaldez): Add PSK support.
1025 if hasComponent(suiteName, "PSK") {
1026 return false
1027 }
1028 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001029}
1030
David Benjamin8b8c0062014-11-23 02:47:52 -05001031func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001032 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001033}
1034
Adam Langleya7997f12015-05-14 17:38:50 -07001035func bigFromHex(hex string) *big.Int {
1036 ret, ok := new(big.Int).SetString(hex, 16)
1037 if !ok {
1038 panic("failed to parse hex number 0x" + hex)
1039 }
1040 return ret
1041}
1042
Adam Langley7c803a62015-06-15 15:35:05 -07001043func addBasicTests() {
1044 basicTests := []testCase{
1045 {
Adam Langley7c803a62015-06-15 15:35:05 -07001046 name: "NoFallbackSCSV",
1047 config: Config{
1048 Bugs: ProtocolBugs{
1049 FailIfNotFallbackSCSV: true,
1050 },
1051 },
1052 shouldFail: true,
1053 expectedLocalError: "no fallback SCSV found",
1054 },
1055 {
1056 name: "SendFallbackSCSV",
1057 config: Config{
1058 Bugs: ProtocolBugs{
1059 FailIfNotFallbackSCSV: true,
1060 },
1061 },
1062 flags: []string{"-fallback-scsv"},
1063 },
1064 {
1065 name: "ClientCertificateTypes",
1066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001067 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001068 ClientAuth: RequestClientCert,
1069 ClientCertificateTypes: []byte{
1070 CertTypeDSSSign,
1071 CertTypeRSASign,
1072 CertTypeECDSASign,
1073 },
1074 },
1075 flags: []string{
1076 "-expect-certificate-types",
1077 base64.StdEncoding.EncodeToString([]byte{
1078 CertTypeDSSSign,
1079 CertTypeRSASign,
1080 CertTypeECDSASign,
1081 }),
1082 },
1083 },
1084 {
Adam Langley7c803a62015-06-15 15:35:05 -07001085 name: "UnauthenticatedECDH",
1086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001087 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1089 Bugs: ProtocolBugs{
1090 UnauthenticatedECDH: true,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":UNEXPECTED_MESSAGE:",
1095 },
1096 {
1097 name: "SkipCertificateStatus",
1098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001099 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1101 Bugs: ProtocolBugs{
1102 SkipCertificateStatus: true,
1103 },
1104 },
1105 flags: []string{
1106 "-enable-ocsp-stapling",
1107 },
1108 },
1109 {
1110 name: "SkipServerKeyExchange",
1111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001112 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1114 Bugs: ProtocolBugs{
1115 SkipServerKeyExchange: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedError: ":UNEXPECTED_MESSAGE:",
1120 },
1121 {
Adam Langley7c803a62015-06-15 15:35:05 -07001122 testType: serverTest,
1123 name: "Alert",
1124 config: Config{
1125 Bugs: ProtocolBugs{
1126 SendSpuriousAlert: alertRecordOverflow,
1127 },
1128 },
1129 shouldFail: true,
1130 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1131 },
1132 {
1133 protocol: dtls,
1134 testType: serverTest,
1135 name: "Alert-DTLS",
1136 config: Config{
1137 Bugs: ProtocolBugs{
1138 SendSpuriousAlert: alertRecordOverflow,
1139 },
1140 },
1141 shouldFail: true,
1142 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1143 },
1144 {
1145 testType: serverTest,
1146 name: "FragmentAlert",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 FragmentAlert: true,
1150 SendSpuriousAlert: alertRecordOverflow,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":BAD_ALERT:",
1155 },
1156 {
1157 protocol: dtls,
1158 testType: serverTest,
1159 name: "FragmentAlert-DTLS",
1160 config: Config{
1161 Bugs: ProtocolBugs{
1162 FragmentAlert: true,
1163 SendSpuriousAlert: alertRecordOverflow,
1164 },
1165 },
1166 shouldFail: true,
1167 expectedError: ":BAD_ALERT:",
1168 },
1169 {
1170 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001171 name: "DoubleAlert",
1172 config: Config{
1173 Bugs: ProtocolBugs{
1174 DoubleAlert: true,
1175 SendSpuriousAlert: alertRecordOverflow,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":BAD_ALERT:",
1180 },
1181 {
1182 protocol: dtls,
1183 testType: serverTest,
1184 name: "DoubleAlert-DTLS",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 DoubleAlert: true,
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":BAD_ALERT:",
1193 },
1194 {
Adam Langley7c803a62015-06-15 15:35:05 -07001195 name: "SkipNewSessionTicket",
1196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001197 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001198 Bugs: ProtocolBugs{
1199 SkipNewSessionTicket: true,
1200 },
1201 },
1202 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001203 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001204 },
1205 {
1206 testType: serverTest,
1207 name: "FallbackSCSV",
1208 config: Config{
1209 MaxVersion: VersionTLS11,
1210 Bugs: ProtocolBugs{
1211 SendFallbackSCSV: true,
1212 },
1213 },
1214 shouldFail: true,
1215 expectedError: ":INAPPROPRIATE_FALLBACK:",
1216 },
1217 {
1218 testType: serverTest,
1219 name: "FallbackSCSV-VersionMatch",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 SendFallbackSCSV: true,
1223 },
1224 },
1225 },
1226 {
1227 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001228 name: "FallbackSCSV-VersionMatch-TLS12",
1229 config: Config{
1230 MaxVersion: VersionTLS12,
1231 Bugs: ProtocolBugs{
1232 SendFallbackSCSV: true,
1233 },
1234 },
1235 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1236 },
1237 {
1238 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001239 name: "FragmentedClientVersion",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 MaxHandshakeRecordLength: 1,
1243 FragmentClientVersion: true,
1244 },
1245 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001246 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001247 },
1248 {
Adam Langley7c803a62015-06-15 15:35:05 -07001249 testType: serverTest,
1250 name: "HttpGET",
1251 sendPrefix: "GET / HTTP/1.0\n",
1252 shouldFail: true,
1253 expectedError: ":HTTP_REQUEST:",
1254 },
1255 {
1256 testType: serverTest,
1257 name: "HttpPOST",
1258 sendPrefix: "POST / HTTP/1.0\n",
1259 shouldFail: true,
1260 expectedError: ":HTTP_REQUEST:",
1261 },
1262 {
1263 testType: serverTest,
1264 name: "HttpHEAD",
1265 sendPrefix: "HEAD / HTTP/1.0\n",
1266 shouldFail: true,
1267 expectedError: ":HTTP_REQUEST:",
1268 },
1269 {
1270 testType: serverTest,
1271 name: "HttpPUT",
1272 sendPrefix: "PUT / HTTP/1.0\n",
1273 shouldFail: true,
1274 expectedError: ":HTTP_REQUEST:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "HttpCONNECT",
1279 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1280 shouldFail: true,
1281 expectedError: ":HTTPS_PROXY_REQUEST:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "Garbage",
1286 sendPrefix: "blah",
1287 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001288 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001289 },
1290 {
Adam Langley7c803a62015-06-15 15:35:05 -07001291 name: "RSAEphemeralKey",
1292 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001293 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001294 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1295 Bugs: ProtocolBugs{
1296 RSAEphemeralKey: true,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":UNEXPECTED_MESSAGE:",
1301 },
1302 {
1303 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001304 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001305 shouldFail: true,
1306 expectedError: ":WRONG_SSL_VERSION:",
1307 },
1308 {
1309 protocol: dtls,
1310 name: "DisableEverything-DTLS",
1311 flags: []string{"-no-tls12", "-no-tls1"},
1312 shouldFail: true,
1313 expectedError: ":WRONG_SSL_VERSION:",
1314 },
1315 {
Adam Langley7c803a62015-06-15 15:35:05 -07001316 protocol: dtls,
1317 testType: serverTest,
1318 name: "MTU",
1319 config: Config{
1320 Bugs: ProtocolBugs{
1321 MaxPacketLength: 256,
1322 },
1323 },
1324 flags: []string{"-mtu", "256"},
1325 },
1326 {
1327 protocol: dtls,
1328 testType: serverTest,
1329 name: "MTUExceeded",
1330 config: Config{
1331 Bugs: ProtocolBugs{
1332 MaxPacketLength: 255,
1333 },
1334 },
1335 flags: []string{"-mtu", "256"},
1336 shouldFail: true,
1337 expectedLocalError: "dtls: exceeded maximum packet length",
1338 },
1339 {
1340 name: "CertMismatchRSA",
1341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001342 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001343 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001344 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001345 Bugs: ProtocolBugs{
1346 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1347 },
1348 },
1349 shouldFail: true,
1350 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1351 },
1352 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001353 name: "CertMismatchRSA-TLS13",
1354 config: Config{
1355 MaxVersion: VersionTLS13,
1356 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1357 Certificates: []Certificate{ecdsaP256Certificate},
1358 Bugs: ProtocolBugs{
1359 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1360 },
1361 },
1362 shouldFail: true,
1363 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1364 },
1365 {
Adam Langley7c803a62015-06-15 15:35:05 -07001366 name: "CertMismatchECDSA",
1367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001368 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001370 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 Bugs: ProtocolBugs{
1372 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1373 },
1374 },
1375 shouldFail: true,
1376 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1377 },
1378 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001379 name: "CertMismatchECDSA-TLS13",
1380 config: Config{
1381 MaxVersion: VersionTLS13,
1382 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1383 Certificates: []Certificate{rsaCertificate},
1384 Bugs: ProtocolBugs{
1385 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1386 },
1387 },
1388 shouldFail: true,
1389 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1390 },
1391 {
Adam Langley7c803a62015-06-15 15:35:05 -07001392 name: "EmptyCertificateList",
1393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001394 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001395 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1396 Bugs: ProtocolBugs{
1397 EmptyCertificateList: true,
1398 },
1399 },
1400 shouldFail: true,
1401 expectedError: ":DECODE_ERROR:",
1402 },
1403 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001404 name: "EmptyCertificateList-TLS13",
1405 config: Config{
1406 MaxVersion: VersionTLS13,
1407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1408 Bugs: ProtocolBugs{
1409 EmptyCertificateList: true,
1410 },
1411 },
1412 shouldFail: true,
1413 expectedError: ":DECODE_ERROR:",
1414 },
1415 {
Adam Langley7c803a62015-06-15 15:35:05 -07001416 name: "TLSFatalBadPackets",
1417 damageFirstWrite: true,
1418 shouldFail: true,
1419 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1420 },
1421 {
1422 protocol: dtls,
1423 name: "DTLSIgnoreBadPackets",
1424 damageFirstWrite: true,
1425 },
1426 {
1427 protocol: dtls,
1428 name: "DTLSIgnoreBadPackets-Async",
1429 damageFirstWrite: true,
1430 flags: []string{"-async"},
1431 },
1432 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001433 name: "AppDataBeforeHandshake",
1434 config: Config{
1435 Bugs: ProtocolBugs{
1436 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":UNEXPECTED_RECORD:",
1441 },
1442 {
1443 name: "AppDataBeforeHandshake-Empty",
1444 config: Config{
1445 Bugs: ProtocolBugs{
1446 AppDataBeforeHandshake: []byte{},
1447 },
1448 },
1449 shouldFail: true,
1450 expectedError: ":UNEXPECTED_RECORD:",
1451 },
1452 {
1453 protocol: dtls,
1454 name: "AppDataBeforeHandshake-DTLS",
1455 config: Config{
1456 Bugs: ProtocolBugs{
1457 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1458 },
1459 },
1460 shouldFail: true,
1461 expectedError: ":UNEXPECTED_RECORD:",
1462 },
1463 {
1464 protocol: dtls,
1465 name: "AppDataBeforeHandshake-DTLS-Empty",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte{},
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
Adam Langley7c803a62015-06-15 15:35:05 -07001475 name: "AppDataAfterChangeCipherSpec",
1476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001477 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001478 Bugs: ProtocolBugs{
1479 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1480 },
1481 },
1482 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001483 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001484 },
1485 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001486 name: "AppDataAfterChangeCipherSpec-Empty",
1487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001488 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001489 Bugs: ProtocolBugs{
1490 AppDataAfterChangeCipherSpec: []byte{},
1491 },
1492 },
1493 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001494 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 },
1496 {
Adam Langley7c803a62015-06-15 15:35:05 -07001497 protocol: dtls,
1498 name: "AppDataAfterChangeCipherSpec-DTLS",
1499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001500 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001501 Bugs: ProtocolBugs{
1502 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 // BoringSSL's DTLS implementation will drop the out-of-order
1506 // application data.
1507 },
1508 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001509 protocol: dtls,
1510 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001512 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001513 Bugs: ProtocolBugs{
1514 AppDataAfterChangeCipherSpec: []byte{},
1515 },
1516 },
1517 // BoringSSL's DTLS implementation will drop the out-of-order
1518 // application data.
1519 },
1520 {
Adam Langley7c803a62015-06-15 15:35:05 -07001521 name: "AlertAfterChangeCipherSpec",
1522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001523 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001524 Bugs: ProtocolBugs{
1525 AlertAfterChangeCipherSpec: alertRecordOverflow,
1526 },
1527 },
1528 shouldFail: true,
1529 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1530 },
1531 {
1532 protocol: dtls,
1533 name: "AlertAfterChangeCipherSpec-DTLS",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 AlertAfterChangeCipherSpec: alertRecordOverflow,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1542 },
1543 {
1544 protocol: dtls,
1545 name: "ReorderHandshakeFragments-Small-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 ReorderHandshakeFragments: true,
1549 // Small enough that every handshake message is
1550 // fragmented.
1551 MaxHandshakeRecordLength: 2,
1552 },
1553 },
1554 },
1555 {
1556 protocol: dtls,
1557 name: "ReorderHandshakeFragments-Large-DTLS",
1558 config: Config{
1559 Bugs: ProtocolBugs{
1560 ReorderHandshakeFragments: true,
1561 // Large enough that no handshake message is
1562 // fragmented.
1563 MaxHandshakeRecordLength: 2048,
1564 },
1565 },
1566 },
1567 {
1568 protocol: dtls,
1569 name: "MixCompleteMessageWithFragments-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 ReorderHandshakeFragments: true,
1573 MixCompleteMessageWithFragments: true,
1574 MaxHandshakeRecordLength: 2,
1575 },
1576 },
1577 },
1578 {
1579 name: "SendInvalidRecordType",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 SendInvalidRecordType: true,
1583 },
1584 },
1585 shouldFail: true,
1586 expectedError: ":UNEXPECTED_RECORD:",
1587 },
1588 {
1589 protocol: dtls,
1590 name: "SendInvalidRecordType-DTLS",
1591 config: Config{
1592 Bugs: ProtocolBugs{
1593 SendInvalidRecordType: true,
1594 },
1595 },
1596 shouldFail: true,
1597 expectedError: ":UNEXPECTED_RECORD:",
1598 },
1599 {
1600 name: "FalseStart-SkipServerSecondLeg",
1601 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001602 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001603 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1604 NextProtos: []string{"foo"},
1605 Bugs: ProtocolBugs{
1606 SkipNewSessionTicket: true,
1607 SkipChangeCipherSpec: true,
1608 SkipFinished: true,
1609 ExpectFalseStart: true,
1610 },
1611 },
1612 flags: []string{
1613 "-false-start",
1614 "-handshake-never-done",
1615 "-advertise-alpn", "\x03foo",
1616 },
1617 shimWritesFirst: true,
1618 shouldFail: true,
1619 expectedError: ":UNEXPECTED_RECORD:",
1620 },
1621 {
1622 name: "FalseStart-SkipServerSecondLeg-Implicit",
1623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001624 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1626 NextProtos: []string{"foo"},
1627 Bugs: ProtocolBugs{
1628 SkipNewSessionTicket: true,
1629 SkipChangeCipherSpec: true,
1630 SkipFinished: true,
1631 },
1632 },
1633 flags: []string{
1634 "-implicit-handshake",
1635 "-false-start",
1636 "-handshake-never-done",
1637 "-advertise-alpn", "\x03foo",
1638 },
1639 shouldFail: true,
1640 expectedError: ":UNEXPECTED_RECORD:",
1641 },
1642 {
1643 testType: serverTest,
1644 name: "FailEarlyCallback",
1645 flags: []string{"-fail-early-callback"},
1646 shouldFail: true,
1647 expectedError: ":CONNECTION_REJECTED:",
1648 expectedLocalError: "remote error: access denied",
1649 },
1650 {
Adam Langley7c803a62015-06-15 15:35:05 -07001651 protocol: dtls,
1652 name: "FragmentMessageTypeMismatch-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 MaxHandshakeRecordLength: 2,
1656 FragmentMessageTypeMismatch: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":FRAGMENT_MISMATCH:",
1661 },
1662 {
1663 protocol: dtls,
1664 name: "FragmentMessageLengthMismatch-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxHandshakeRecordLength: 2,
1668 FragmentMessageLengthMismatch: true,
1669 },
1670 },
1671 shouldFail: true,
1672 expectedError: ":FRAGMENT_MISMATCH:",
1673 },
1674 {
1675 protocol: dtls,
1676 name: "SplitFragments-Header-DTLS",
1677 config: Config{
1678 Bugs: ProtocolBugs{
1679 SplitFragments: 2,
1680 },
1681 },
1682 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001683 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001684 },
1685 {
1686 protocol: dtls,
1687 name: "SplitFragments-Boundary-DTLS",
1688 config: Config{
1689 Bugs: ProtocolBugs{
1690 SplitFragments: dtlsRecordHeaderLen,
1691 },
1692 },
1693 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001694 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001695 },
1696 {
1697 protocol: dtls,
1698 name: "SplitFragments-Body-DTLS",
1699 config: Config{
1700 Bugs: ProtocolBugs{
1701 SplitFragments: dtlsRecordHeaderLen + 1,
1702 },
1703 },
1704 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001705 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001706 },
1707 {
1708 protocol: dtls,
1709 name: "SendEmptyFragments-DTLS",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 SendEmptyFragments: true,
1713 },
1714 },
1715 },
1716 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001717 name: "BadFinished-Client",
1718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001719 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001720 Bugs: ProtocolBugs{
1721 BadFinished: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":DIGEST_CHECK_FAILED:",
1726 },
1727 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001728 name: "BadFinished-Client-TLS13",
1729 config: Config{
1730 MaxVersion: VersionTLS13,
1731 Bugs: ProtocolBugs{
1732 BadFinished: true,
1733 },
1734 },
1735 shouldFail: true,
1736 expectedError: ":DIGEST_CHECK_FAILED:",
1737 },
1738 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001739 testType: serverTest,
1740 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001742 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001743 Bugs: ProtocolBugs{
1744 BadFinished: true,
1745 },
1746 },
1747 shouldFail: true,
1748 expectedError: ":DIGEST_CHECK_FAILED:",
1749 },
1750 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001751 testType: serverTest,
1752 name: "BadFinished-Server-TLS13",
1753 config: Config{
1754 MaxVersion: VersionTLS13,
1755 Bugs: ProtocolBugs{
1756 BadFinished: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DIGEST_CHECK_FAILED:",
1761 },
1762 {
Adam Langley7c803a62015-06-15 15:35:05 -07001763 name: "FalseStart-BadFinished",
1764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001765 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1767 NextProtos: []string{"foo"},
1768 Bugs: ProtocolBugs{
1769 BadFinished: true,
1770 ExpectFalseStart: true,
1771 },
1772 },
1773 flags: []string{
1774 "-false-start",
1775 "-handshake-never-done",
1776 "-advertise-alpn", "\x03foo",
1777 },
1778 shimWritesFirst: true,
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
1783 name: "NoFalseStart-NoALPN",
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 Bugs: ProtocolBugs{
1788 ExpectFalseStart: true,
1789 AlertBeforeFalseStartTest: alertAccessDenied,
1790 },
1791 },
1792 flags: []string{
1793 "-false-start",
1794 },
1795 shimWritesFirst: true,
1796 shouldFail: true,
1797 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1798 expectedLocalError: "tls: peer did not false start: EOF",
1799 },
1800 {
1801 name: "NoFalseStart-NoAEAD",
1802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1805 NextProtos: []string{"foo"},
1806 Bugs: ProtocolBugs{
1807 ExpectFalseStart: true,
1808 AlertBeforeFalseStartTest: alertAccessDenied,
1809 },
1810 },
1811 flags: []string{
1812 "-false-start",
1813 "-advertise-alpn", "\x03foo",
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-RSA",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
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-DHE_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_DHE_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 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 protocol: dtls,
1862 name: "SendSplitAlert-Sync",
1863 config: Config{
1864 Bugs: ProtocolBugs{
1865 SendSplitAlert: true,
1866 },
1867 },
1868 },
1869 {
1870 protocol: dtls,
1871 name: "SendSplitAlert-Async",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendSplitAlert: true,
1875 },
1876 },
1877 flags: []string{"-async"},
1878 },
1879 {
1880 protocol: dtls,
1881 name: "PackDTLSHandshake",
1882 config: Config{
1883 Bugs: ProtocolBugs{
1884 MaxHandshakeRecordLength: 2,
1885 PackHandshakeFragments: 20,
1886 PackHandshakeRecords: 200,
1887 },
1888 },
1889 },
1890 {
Adam Langley7c803a62015-06-15 15:35:05 -07001891 name: "SendEmptyRecords-Pass",
1892 sendEmptyRecords: 32,
1893 },
1894 {
1895 name: "SendEmptyRecords",
1896 sendEmptyRecords: 33,
1897 shouldFail: true,
1898 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1899 },
1900 {
1901 name: "SendEmptyRecords-Async",
1902 sendEmptyRecords: 33,
1903 flags: []string{"-async"},
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Pass",
1909 sendWarningAlerts: 4,
1910 },
1911 {
1912 protocol: dtls,
1913 name: "SendWarningAlerts-DTLS-Pass",
1914 sendWarningAlerts: 4,
1915 },
1916 {
1917 name: "SendWarningAlerts",
1918 sendWarningAlerts: 5,
1919 shouldFail: true,
1920 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1921 },
1922 {
1923 name: "SendWarningAlerts-Async",
1924 sendWarningAlerts: 5,
1925 flags: []string{"-async"},
1926 shouldFail: true,
1927 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1928 },
David Benjaminba4594a2015-06-18 18:36:15 -04001929 {
1930 name: "EmptySessionID",
1931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001932 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001933 SessionTicketsDisabled: true,
1934 },
1935 noSessionCache: true,
1936 flags: []string{"-expect-no-session"},
1937 },
David Benjamin30789da2015-08-29 22:56:45 -04001938 {
1939 name: "Unclean-Shutdown",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 NoCloseNotify: true,
1943 ExpectCloseNotify: true,
1944 },
1945 },
1946 shimShutsDown: true,
1947 flags: []string{"-check-close-notify"},
1948 shouldFail: true,
1949 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1950 },
1951 {
1952 name: "Unclean-Shutdown-Ignored",
1953 config: Config{
1954 Bugs: ProtocolBugs{
1955 NoCloseNotify: true,
1956 },
1957 },
1958 shimShutsDown: true,
1959 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001960 {
David Benjaminfa214e42016-05-10 17:03:10 -04001961 name: "Unclean-Shutdown-Alert",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendAlertOnShutdown: alertDecompressionFailure,
1965 ExpectCloseNotify: true,
1966 },
1967 },
1968 shimShutsDown: true,
1969 flags: []string{"-check-close-notify"},
1970 shouldFail: true,
1971 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1972 },
1973 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001974 name: "LargePlaintext",
1975 config: Config{
1976 Bugs: ProtocolBugs{
1977 SendLargeRecords: true,
1978 },
1979 },
1980 messageLen: maxPlaintext + 1,
1981 shouldFail: true,
1982 expectedError: ":DATA_LENGTH_TOO_LONG:",
1983 },
1984 {
1985 protocol: dtls,
1986 name: "LargePlaintext-DTLS",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 SendLargeRecords: true,
1990 },
1991 },
1992 messageLen: maxPlaintext + 1,
1993 shouldFail: true,
1994 expectedError: ":DATA_LENGTH_TOO_LONG:",
1995 },
1996 {
1997 name: "LargeCiphertext",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendLargeRecords: true,
2001 },
2002 },
2003 messageLen: maxPlaintext * 2,
2004 shouldFail: true,
2005 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2006 },
2007 {
2008 protocol: dtls,
2009 name: "LargeCiphertext-DTLS",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 SendLargeRecords: true,
2013 },
2014 },
2015 messageLen: maxPlaintext * 2,
2016 // Unlike the other four cases, DTLS drops records which
2017 // are invalid before authentication, so the connection
2018 // does not fail.
2019 expectMessageDropped: true,
2020 },
David Benjamindd6fed92015-10-23 17:41:12 -04002021 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002022 // In TLS 1.2 and below, empty NewSessionTicket messages
2023 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002024 name: "SendEmptySessionTicket",
2025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002026 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002027 Bugs: ProtocolBugs{
2028 SendEmptySessionTicket: true,
2029 FailIfSessionOffered: true,
2030 },
2031 },
2032 flags: []string{"-expect-no-session"},
2033 resumeSession: true,
2034 expectResumeRejected: true,
2035 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002036 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002037 name: "BadHelloRequest-1",
2038 renegotiate: 1,
2039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002040 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002041 Bugs: ProtocolBugs{
2042 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2043 },
2044 },
2045 flags: []string{
2046 "-renegotiate-freely",
2047 "-expect-total-renegotiations", "1",
2048 },
2049 shouldFail: true,
2050 expectedError: ":BAD_HELLO_REQUEST:",
2051 },
2052 {
2053 name: "BadHelloRequest-2",
2054 renegotiate: 1,
2055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002057 Bugs: ProtocolBugs{
2058 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2059 },
2060 },
2061 flags: []string{
2062 "-renegotiate-freely",
2063 "-expect-total-renegotiations", "1",
2064 },
2065 shouldFail: true,
2066 expectedError: ":BAD_HELLO_REQUEST:",
2067 },
David Benjaminef1b0092015-11-21 14:05:44 -05002068 {
2069 testType: serverTest,
2070 name: "SupportTicketsWithSessionID",
2071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002072 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002073 SessionTicketsDisabled: true,
2074 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002075 resumeConfig: &Config{
2076 MaxVersion: VersionTLS12,
2077 },
David Benjaminef1b0092015-11-21 14:05:44 -05002078 resumeSession: true,
2079 },
Adam Langley7c803a62015-06-15 15:35:05 -07002080 }
Adam Langley7c803a62015-06-15 15:35:05 -07002081 testCases = append(testCases, basicTests...)
2082}
2083
Adam Langley95c29f32014-06-20 12:00:00 -07002084func addCipherSuiteTests() {
2085 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002086 const psk = "12345"
2087 const pskIdentity = "luggage combo"
2088
Adam Langley95c29f32014-06-20 12:00:00 -07002089 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002090 var certFile string
2091 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002092 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002093 cert = ecdsaP256Certificate
2094 certFile = ecdsaP256CertificateFile
2095 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002096 } else {
David Benjamin33863262016-07-08 17:20:12 -07002097 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002098 certFile = rsaCertificateFile
2099 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002100 }
2101
David Benjamin48cae082014-10-27 01:06:24 -04002102 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002103 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002104 flags = append(flags,
2105 "-psk", psk,
2106 "-psk-identity", pskIdentity)
2107 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002108 if hasComponent(suite.name, "NULL") {
2109 // NULL ciphers must be explicitly enabled.
2110 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2111 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002112 if hasComponent(suite.name, "CECPQ1") {
2113 // CECPQ1 ciphers must be explicitly enabled.
2114 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2115 }
David Benjamin48cae082014-10-27 01:06:24 -04002116
Adam Langley95c29f32014-06-20 12:00:00 -07002117 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002118 for _, protocol := range []protocol{tls, dtls} {
2119 var prefix string
2120 if protocol == dtls {
2121 if !ver.hasDTLS {
2122 continue
2123 }
2124 prefix = "D"
2125 }
Adam Langley95c29f32014-06-20 12:00:00 -07002126
David Benjamin0407e762016-06-17 16:41:18 -04002127 var shouldServerFail, shouldClientFail bool
2128 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2129 // BoringSSL clients accept ECDHE on SSLv3, but
2130 // a BoringSSL server will never select it
2131 // because the extension is missing.
2132 shouldServerFail = true
2133 }
2134 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2135 shouldClientFail = true
2136 shouldServerFail = true
2137 }
David Benjamin54c217c2016-07-13 12:35:25 -04002138 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002139 shouldClientFail = true
2140 shouldServerFail = true
2141 }
David Benjamin0407e762016-06-17 16:41:18 -04002142 if !isDTLSCipher(suite.name) && protocol == dtls {
2143 shouldClientFail = true
2144 shouldServerFail = true
2145 }
David Benjamin4298d772015-12-19 00:18:25 -05002146
David Benjamin0407e762016-06-17 16:41:18 -04002147 var expectedServerError, expectedClientError string
2148 if shouldServerFail {
2149 expectedServerError = ":NO_SHARED_CIPHER:"
2150 }
2151 if shouldClientFail {
2152 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2153 }
David Benjamin025b3d32014-07-01 19:53:04 -04002154
David Benjamin9deb1172016-07-13 17:13:49 -04002155 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2156 resumeSession := ver.version < VersionTLS13
2157
David Benjamin6fd297b2014-08-11 18:43:38 -04002158 testCases = append(testCases, testCase{
2159 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002160 protocol: protocol,
2161
2162 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002163 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002164 MinVersion: ver.version,
2165 MaxVersion: ver.version,
2166 CipherSuites: []uint16{suite.id},
2167 Certificates: []Certificate{cert},
2168 PreSharedKey: []byte(psk),
2169 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002170 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002171 EnableAllCiphers: shouldServerFail,
2172 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002173 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002174 },
2175 certFile: certFile,
2176 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002177 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002178 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002179 shouldFail: shouldServerFail,
2180 expectedError: expectedServerError,
2181 })
2182
2183 testCases = append(testCases, testCase{
2184 testType: clientTest,
2185 protocol: protocol,
2186 name: prefix + ver.name + "-" + suite.name + "-client",
2187 config: Config{
2188 MinVersion: ver.version,
2189 MaxVersion: ver.version,
2190 CipherSuites: []uint16{suite.id},
2191 Certificates: []Certificate{cert},
2192 PreSharedKey: []byte(psk),
2193 PreSharedKeyIdentity: pskIdentity,
2194 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002195 EnableAllCiphers: shouldClientFail,
2196 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002197 },
2198 },
2199 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002200 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002201 shouldFail: shouldClientFail,
2202 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002203 })
David Benjamin2c99d282015-09-01 10:23:00 -04002204
Nick Harper1fd39d82016-06-14 18:14:35 -07002205 if !shouldClientFail {
2206 // Ensure the maximum record size is accepted.
2207 testCases = append(testCases, testCase{
2208 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2209 config: Config{
2210 MinVersion: ver.version,
2211 MaxVersion: ver.version,
2212 CipherSuites: []uint16{suite.id},
2213 Certificates: []Certificate{cert},
2214 PreSharedKey: []byte(psk),
2215 PreSharedKeyIdentity: pskIdentity,
2216 },
2217 flags: flags,
2218 messageLen: maxPlaintext,
2219 })
2220 }
2221 }
David Benjamin2c99d282015-09-01 10:23:00 -04002222 }
Adam Langley95c29f32014-06-20 12:00:00 -07002223 }
Adam Langleya7997f12015-05-14 17:38:50 -07002224
2225 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002226 name: "NoSharedCipher",
2227 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002228 MaxVersion: VersionTLS12,
2229 CipherSuites: []uint16{},
2230 },
2231 shouldFail: true,
2232 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2233 })
2234
2235 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002236 name: "NoSharedCipher-TLS13",
2237 config: Config{
2238 MaxVersion: VersionTLS13,
2239 CipherSuites: []uint16{},
2240 },
2241 shouldFail: true,
2242 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2243 })
2244
2245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002246 name: "UnsupportedCipherSuite",
2247 config: Config{
2248 MaxVersion: VersionTLS12,
2249 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2250 Bugs: ProtocolBugs{
2251 IgnorePeerCipherPreferences: true,
2252 },
2253 },
2254 flags: []string{"-cipher", "DEFAULT:!RC4"},
2255 shouldFail: true,
2256 expectedError: ":WRONG_CIPHER_RETURNED:",
2257 })
2258
2259 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002260 name: "WeakDH",
2261 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002262 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002263 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2264 Bugs: ProtocolBugs{
2265 // This is a 1023-bit prime number, generated
2266 // with:
2267 // openssl gendh 1023 | openssl asn1parse -i
2268 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2269 },
2270 },
2271 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002272 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002273 })
Adam Langleycef75832015-09-03 14:51:12 -07002274
David Benjamincd24a392015-11-11 13:23:05 -08002275 testCases = append(testCases, testCase{
2276 name: "SillyDH",
2277 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002278 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002279 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2280 Bugs: ProtocolBugs{
2281 // This is a 4097-bit prime number, generated
2282 // with:
2283 // openssl gendh 4097 | openssl asn1parse -i
2284 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2285 },
2286 },
2287 shouldFail: true,
2288 expectedError: ":DH_P_TOO_LONG:",
2289 })
2290
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002291 // This test ensures that Diffie-Hellman public values are padded with
2292 // zeros so that they're the same length as the prime. This is to avoid
2293 // hitting a bug in yaSSL.
2294 testCases = append(testCases, testCase{
2295 testType: serverTest,
2296 name: "DHPublicValuePadded",
2297 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002298 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002299 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2300 Bugs: ProtocolBugs{
2301 RequireDHPublicValueLen: (1025 + 7) / 8,
2302 },
2303 },
2304 flags: []string{"-use-sparse-dh-prime"},
2305 })
David Benjamincd24a392015-11-11 13:23:05 -08002306
David Benjamin241ae832016-01-15 03:04:54 -05002307 // The server must be tolerant to bogus ciphers.
2308 const bogusCipher = 0x1234
2309 testCases = append(testCases, testCase{
2310 testType: serverTest,
2311 name: "UnknownCipher",
2312 config: Config{
2313 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2314 },
2315 })
2316
Adam Langleycef75832015-09-03 14:51:12 -07002317 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2318 // 1.1 specific cipher suite settings. A server is setup with the given
2319 // cipher lists and then a connection is made for each member of
2320 // expectations. The cipher suite that the server selects must match
2321 // the specified one.
2322 var versionSpecificCiphersTest = []struct {
2323 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2324 // expectations is a map from TLS version to cipher suite id.
2325 expectations map[uint16]uint16
2326 }{
2327 {
2328 // Test that the null case (where no version-specific ciphers are set)
2329 // works as expected.
2330 "RC4-SHA:AES128-SHA", // default ciphers
2331 "", // no ciphers specifically for TLS ≥ 1.0
2332 "", // no ciphers specifically for TLS ≥ 1.1
2333 map[uint16]uint16{
2334 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2335 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2336 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2337 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2338 },
2339 },
2340 {
2341 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2342 // cipher.
2343 "RC4-SHA:AES128-SHA", // default
2344 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2345 "", // no ciphers specifically for TLS ≥ 1.1
2346 map[uint16]uint16{
2347 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2348 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2349 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2350 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2351 },
2352 },
2353 {
2354 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2355 // cipher.
2356 "RC4-SHA:AES128-SHA", // default
2357 "", // no ciphers specifically for TLS ≥ 1.0
2358 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2359 map[uint16]uint16{
2360 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2361 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2362 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2363 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2364 },
2365 },
2366 {
2367 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2368 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2369 "RC4-SHA:AES128-SHA", // default
2370 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2371 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2372 map[uint16]uint16{
2373 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2374 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2375 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2376 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2377 },
2378 },
2379 }
2380
2381 for i, test := range versionSpecificCiphersTest {
2382 for version, expectedCipherSuite := range test.expectations {
2383 flags := []string{"-cipher", test.ciphersDefault}
2384 if len(test.ciphersTLS10) > 0 {
2385 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2386 }
2387 if len(test.ciphersTLS11) > 0 {
2388 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2389 }
2390
2391 testCases = append(testCases, testCase{
2392 testType: serverTest,
2393 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2394 config: Config{
2395 MaxVersion: version,
2396 MinVersion: version,
2397 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2398 },
2399 flags: flags,
2400 expectedCipher: expectedCipherSuite,
2401 })
2402 }
2403 }
Adam Langley95c29f32014-06-20 12:00:00 -07002404}
2405
2406func addBadECDSASignatureTests() {
2407 for badR := BadValue(1); badR < NumBadValues; badR++ {
2408 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002409 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002410 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2411 config: Config{
2412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002413 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002414 Bugs: ProtocolBugs{
2415 BadECDSAR: badR,
2416 BadECDSAS: badS,
2417 },
2418 },
2419 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002420 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002421 })
2422 }
2423 }
2424}
2425
Adam Langley80842bd2014-06-20 12:00:00 -07002426func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002427 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002428 name: "MaxCBCPadding",
2429 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002430 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2432 Bugs: ProtocolBugs{
2433 MaxPadding: true,
2434 },
2435 },
2436 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2437 })
David Benjamin025b3d32014-07-01 19:53:04 -04002438 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002439 name: "BadCBCPadding",
2440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002441 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2443 Bugs: ProtocolBugs{
2444 PaddingFirstByteBad: true,
2445 },
2446 },
2447 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002448 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002449 })
2450 // OpenSSL previously had an issue where the first byte of padding in
2451 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002452 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002453 name: "BadCBCPadding255",
2454 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002455 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002456 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2457 Bugs: ProtocolBugs{
2458 MaxPadding: true,
2459 PaddingFirstByteBadIf255: true,
2460 },
2461 },
2462 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2463 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002464 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002465 })
2466}
2467
Kenny Root7fdeaf12014-08-05 15:23:37 -07002468func addCBCSplittingTests() {
2469 testCases = append(testCases, testCase{
2470 name: "CBCRecordSplitting",
2471 config: Config{
2472 MaxVersion: VersionTLS10,
2473 MinVersion: VersionTLS10,
2474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2475 },
David Benjaminac8302a2015-09-01 17:18:15 -04002476 messageLen: -1, // read until EOF
2477 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002478 flags: []string{
2479 "-async",
2480 "-write-different-record-sizes",
2481 "-cbc-record-splitting",
2482 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002483 })
2484 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002485 name: "CBCRecordSplittingPartialWrite",
2486 config: Config{
2487 MaxVersion: VersionTLS10,
2488 MinVersion: VersionTLS10,
2489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2490 },
2491 messageLen: -1, // read until EOF
2492 flags: []string{
2493 "-async",
2494 "-write-different-record-sizes",
2495 "-cbc-record-splitting",
2496 "-partial-write",
2497 },
2498 })
2499}
2500
David Benjamin636293b2014-07-08 17:59:18 -04002501func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002502 // Add a dummy cert pool to stress certificate authority parsing.
2503 // TODO(davidben): Add tests that those values parse out correctly.
2504 certPool := x509.NewCertPool()
2505 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2506 if err != nil {
2507 panic(err)
2508 }
2509 certPool.AddCert(cert)
2510
David Benjamin636293b2014-07-08 17:59:18 -04002511 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002512 testCases = append(testCases, testCase{
2513 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002514 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002515 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002516 MinVersion: ver.version,
2517 MaxVersion: ver.version,
2518 ClientAuth: RequireAnyClientCert,
2519 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002520 },
2521 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002524 },
2525 })
2526 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002527 testType: serverTest,
2528 name: ver.name + "-Server-ClientAuth-RSA",
2529 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002530 MinVersion: ver.version,
2531 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002532 Certificates: []Certificate{rsaCertificate},
2533 },
2534 flags: []string{"-require-any-client-certificate"},
2535 })
David Benjamine098ec22014-08-27 23:13:20 -04002536 if ver.version != VersionSSL30 {
2537 testCases = append(testCases, testCase{
2538 testType: serverTest,
2539 name: ver.name + "-Server-ClientAuth-ECDSA",
2540 config: Config{
2541 MinVersion: ver.version,
2542 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002543 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002544 },
2545 flags: []string{"-require-any-client-certificate"},
2546 })
2547 testCases = append(testCases, testCase{
2548 testType: clientTest,
2549 name: ver.name + "-Client-ClientAuth-ECDSA",
2550 config: Config{
2551 MinVersion: ver.version,
2552 MaxVersion: ver.version,
2553 ClientAuth: RequireAnyClientCert,
2554 ClientCAs: certPool,
2555 },
2556 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002557 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2558 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002559 },
2560 })
2561 }
David Benjamin636293b2014-07-08 17:59:18 -04002562 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002563
2564 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002565 name: "NoClientCertificate",
2566 config: Config{
2567 MaxVersion: VersionTLS12,
2568 ClientAuth: RequireAnyClientCert,
2569 },
2570 shouldFail: true,
2571 expectedLocalError: "client didn't provide a certificate",
2572 })
2573
2574 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002575 name: "NoClientCertificate-TLS13",
2576 config: Config{
2577 MaxVersion: VersionTLS13,
2578 ClientAuth: RequireAnyClientCert,
2579 },
2580 shouldFail: true,
2581 expectedLocalError: "client didn't provide a certificate",
2582 })
2583
2584 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002585 testType: serverTest,
2586 name: "RequireAnyClientCertificate",
2587 config: Config{
2588 MaxVersion: VersionTLS12,
2589 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002590 flags: []string{"-require-any-client-certificate"},
2591 shouldFail: true,
2592 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2593 })
2594
2595 testCases = append(testCases, testCase{
2596 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002597 name: "RequireAnyClientCertificate-TLS13",
2598 config: Config{
2599 MaxVersion: VersionTLS13,
2600 },
2601 flags: []string{"-require-any-client-certificate"},
2602 shouldFail: true,
2603 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2604 })
2605
2606 testCases = append(testCases, testCase{
2607 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002608 name: "RequireAnyClientCertificate-SSL3",
2609 config: Config{
2610 MaxVersion: VersionSSL30,
2611 },
2612 flags: []string{"-require-any-client-certificate"},
2613 shouldFail: true,
2614 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2615 })
2616
2617 testCases = append(testCases, testCase{
2618 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002619 name: "SkipClientCertificate",
2620 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002621 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002622 Bugs: ProtocolBugs{
2623 SkipClientCertificate: true,
2624 },
2625 },
2626 // Setting SSL_VERIFY_PEER allows anonymous clients.
2627 flags: []string{"-verify-peer"},
2628 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002629 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002630 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002631
Steven Valdez143e8b32016-07-11 13:19:03 -04002632 testCases = append(testCases, testCase{
2633 testType: serverTest,
2634 name: "SkipClientCertificate-TLS13",
2635 config: Config{
2636 MaxVersion: VersionTLS13,
2637 Bugs: ProtocolBugs{
2638 SkipClientCertificate: true,
2639 },
2640 },
2641 // Setting SSL_VERIFY_PEER allows anonymous clients.
2642 flags: []string{"-verify-peer"},
2643 shouldFail: true,
2644 expectedError: ":UNEXPECTED_MESSAGE:",
2645 })
2646
David Benjaminc032dfa2016-05-12 14:54:57 -04002647 // Client auth is only legal in certificate-based ciphers.
2648 testCases = append(testCases, testCase{
2649 testType: clientTest,
2650 name: "ClientAuth-PSK",
2651 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002652 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002653 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2654 PreSharedKey: []byte("secret"),
2655 ClientAuth: RequireAnyClientCert,
2656 },
2657 flags: []string{
2658 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2659 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2660 "-psk", "secret",
2661 },
2662 shouldFail: true,
2663 expectedError: ":UNEXPECTED_MESSAGE:",
2664 })
2665 testCases = append(testCases, testCase{
2666 testType: clientTest,
2667 name: "ClientAuth-ECDHE_PSK",
2668 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002669 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002670 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2671 PreSharedKey: []byte("secret"),
2672 ClientAuth: RequireAnyClientCert,
2673 },
2674 flags: []string{
2675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2677 "-psk", "secret",
2678 },
2679 shouldFail: true,
2680 expectedError: ":UNEXPECTED_MESSAGE:",
2681 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002682
2683 // Regression test for a bug where the client CA list, if explicitly
2684 // set to NULL, was mis-encoded.
2685 testCases = append(testCases, testCase{
2686 testType: serverTest,
2687 name: "Null-Client-CA-List",
2688 config: Config{
2689 MaxVersion: VersionTLS12,
2690 Certificates: []Certificate{rsaCertificate},
2691 },
2692 flags: []string{
2693 "-require-any-client-certificate",
2694 "-use-null-client-ca-list",
2695 },
2696 })
David Benjamin636293b2014-07-08 17:59:18 -04002697}
2698
Adam Langley75712922014-10-10 16:23:43 -07002699func addExtendedMasterSecretTests() {
2700 const expectEMSFlag = "-expect-extended-master-secret"
2701
2702 for _, with := range []bool{false, true} {
2703 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002704 if with {
2705 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002706 }
2707
2708 for _, isClient := range []bool{false, true} {
2709 suffix := "-Server"
2710 testType := serverTest
2711 if isClient {
2712 suffix = "-Client"
2713 testType = clientTest
2714 }
2715
2716 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002717 // In TLS 1.3, the extension is irrelevant and
2718 // always reports as enabled.
2719 var flags []string
2720 if with || ver.version >= VersionTLS13 {
2721 flags = []string{expectEMSFlag}
2722 }
2723
Adam Langley75712922014-10-10 16:23:43 -07002724 test := testCase{
2725 testType: testType,
2726 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2727 config: Config{
2728 MinVersion: ver.version,
2729 MaxVersion: ver.version,
2730 Bugs: ProtocolBugs{
2731 NoExtendedMasterSecret: !with,
2732 RequireExtendedMasterSecret: with,
2733 },
2734 },
David Benjamin48cae082014-10-27 01:06:24 -04002735 flags: flags,
2736 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002737 }
2738 if test.shouldFail {
2739 test.expectedLocalError = "extended master secret required but not supported by peer"
2740 }
2741 testCases = append(testCases, test)
2742 }
2743 }
2744 }
2745
Adam Langleyba5934b2015-06-02 10:50:35 -07002746 for _, isClient := range []bool{false, true} {
2747 for _, supportedInFirstConnection := range []bool{false, true} {
2748 for _, supportedInResumeConnection := range []bool{false, true} {
2749 boolToWord := func(b bool) string {
2750 if b {
2751 return "Yes"
2752 }
2753 return "No"
2754 }
2755 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2756 if isClient {
2757 suffix += "Client"
2758 } else {
2759 suffix += "Server"
2760 }
2761
2762 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002763 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002764 Bugs: ProtocolBugs{
2765 RequireExtendedMasterSecret: true,
2766 },
2767 }
2768
2769 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002770 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002771 Bugs: ProtocolBugs{
2772 NoExtendedMasterSecret: true,
2773 },
2774 }
2775
2776 test := testCase{
2777 name: "ExtendedMasterSecret-" + suffix,
2778 resumeSession: true,
2779 }
2780
2781 if !isClient {
2782 test.testType = serverTest
2783 }
2784
2785 if supportedInFirstConnection {
2786 test.config = supportedConfig
2787 } else {
2788 test.config = noSupportConfig
2789 }
2790
2791 if supportedInResumeConnection {
2792 test.resumeConfig = &supportedConfig
2793 } else {
2794 test.resumeConfig = &noSupportConfig
2795 }
2796
2797 switch suffix {
2798 case "YesToYes-Client", "YesToYes-Server":
2799 // When a session is resumed, it should
2800 // still be aware that its master
2801 // secret was generated via EMS and
2802 // thus it's safe to use tls-unique.
2803 test.flags = []string{expectEMSFlag}
2804 case "NoToYes-Server":
2805 // If an original connection did not
2806 // contain EMS, but a resumption
2807 // handshake does, then a server should
2808 // not resume the session.
2809 test.expectResumeRejected = true
2810 case "YesToNo-Server":
2811 // Resuming an EMS session without the
2812 // EMS extension should cause the
2813 // server to abort the connection.
2814 test.shouldFail = true
2815 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2816 case "NoToYes-Client":
2817 // A client should abort a connection
2818 // where the server resumed a non-EMS
2819 // session but echoed the EMS
2820 // extension.
2821 test.shouldFail = true
2822 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2823 case "YesToNo-Client":
2824 // A client should abort a connection
2825 // where the server didn't echo EMS
2826 // when the session used it.
2827 test.shouldFail = true
2828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2829 }
2830
2831 testCases = append(testCases, test)
2832 }
2833 }
2834 }
Adam Langley75712922014-10-10 16:23:43 -07002835}
2836
David Benjamin582ba042016-07-07 12:33:25 -07002837type stateMachineTestConfig struct {
2838 protocol protocol
2839 async bool
2840 splitHandshake, packHandshakeFlight bool
2841}
2842
David Benjamin43ec06f2014-08-05 02:28:57 -04002843// Adds tests that try to cover the range of the handshake state machine, under
2844// various conditions. Some of these are redundant with other tests, but they
2845// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002846func addAllStateMachineCoverageTests() {
2847 for _, async := range []bool{false, true} {
2848 for _, protocol := range []protocol{tls, dtls} {
2849 addStateMachineCoverageTests(stateMachineTestConfig{
2850 protocol: protocol,
2851 async: async,
2852 })
2853 addStateMachineCoverageTests(stateMachineTestConfig{
2854 protocol: protocol,
2855 async: async,
2856 splitHandshake: true,
2857 })
2858 if protocol == tls {
2859 addStateMachineCoverageTests(stateMachineTestConfig{
2860 protocol: protocol,
2861 async: async,
2862 packHandshakeFlight: true,
2863 })
2864 }
2865 }
2866 }
2867}
2868
2869func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002870 var tests []testCase
2871
2872 // Basic handshake, with resumption. Client and server,
2873 // session ID and session ticket.
2874 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002875 name: "Basic-Client",
2876 config: Config{
2877 MaxVersion: VersionTLS12,
2878 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002879 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002880 // Ensure session tickets are used, not session IDs.
2881 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002882 })
2883 tests = append(tests, testCase{
2884 name: "Basic-Client-RenewTicket",
2885 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002886 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002887 Bugs: ProtocolBugs{
2888 RenewTicketOnResume: true,
2889 },
2890 },
David Benjaminba4594a2015-06-18 18:36:15 -04002891 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002892 resumeSession: true,
2893 })
2894 tests = append(tests, testCase{
2895 name: "Basic-Client-NoTicket",
2896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002897 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002898 SessionTicketsDisabled: true,
2899 },
2900 resumeSession: true,
2901 })
2902 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002903 name: "Basic-Client-Implicit",
2904 config: Config{
2905 MaxVersion: VersionTLS12,
2906 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002907 flags: []string{"-implicit-handshake"},
2908 resumeSession: true,
2909 })
2910 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002911 testType: serverTest,
2912 name: "Basic-Server",
2913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002914 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002915 Bugs: ProtocolBugs{
2916 RequireSessionTickets: true,
2917 },
2918 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002919 resumeSession: true,
2920 })
2921 tests = append(tests, testCase{
2922 testType: serverTest,
2923 name: "Basic-Server-NoTickets",
2924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002925 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002926 SessionTicketsDisabled: true,
2927 },
2928 resumeSession: true,
2929 })
2930 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 testType: serverTest,
2932 name: "Basic-Server-Implicit",
2933 config: Config{
2934 MaxVersion: VersionTLS12,
2935 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002936 flags: []string{"-implicit-handshake"},
2937 resumeSession: true,
2938 })
2939 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002940 testType: serverTest,
2941 name: "Basic-Server-EarlyCallback",
2942 config: Config{
2943 MaxVersion: VersionTLS12,
2944 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002945 flags: []string{"-use-early-callback"},
2946 resumeSession: true,
2947 })
2948
Steven Valdez143e8b32016-07-11 13:19:03 -04002949 // TLS 1.3 basic handshake shapes.
2950 tests = append(tests, testCase{
2951 name: "TLS13-1RTT-Client",
2952 config: Config{
2953 MaxVersion: VersionTLS13,
2954 },
2955 })
2956 tests = append(tests, testCase{
2957 testType: serverTest,
2958 name: "TLS13-1RTT-Server",
2959 config: Config{
2960 MaxVersion: VersionTLS13,
2961 },
2962 })
2963
David Benjamin760b1dd2015-05-15 23:33:48 -04002964 // TLS client auth.
2965 tests = append(tests, testCase{
2966 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002967 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002969 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002970 ClientAuth: RequestClientCert,
2971 },
2972 })
2973 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002974 testType: serverTest,
2975 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002976 config: Config{
2977 MaxVersion: VersionTLS12,
2978 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002979 // Setting SSL_VERIFY_PEER allows anonymous clients.
2980 flags: []string{"-verify-peer"},
2981 })
David Benjamin582ba042016-07-07 12:33:25 -07002982 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002983 tests = append(tests, testCase{
2984 testType: clientTest,
2985 name: "ClientAuth-NoCertificate-Client-SSL3",
2986 config: Config{
2987 MaxVersion: VersionSSL30,
2988 ClientAuth: RequestClientCert,
2989 },
2990 })
2991 tests = append(tests, testCase{
2992 testType: serverTest,
2993 name: "ClientAuth-NoCertificate-Server-SSL3",
2994 config: Config{
2995 MaxVersion: VersionSSL30,
2996 },
2997 // Setting SSL_VERIFY_PEER allows anonymous clients.
2998 flags: []string{"-verify-peer"},
2999 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003000 tests = append(tests, testCase{
3001 testType: clientTest,
3002 name: "ClientAuth-NoCertificate-Client-TLS13",
3003 config: Config{
3004 MaxVersion: VersionTLS13,
3005 ClientAuth: RequestClientCert,
3006 },
3007 })
3008 tests = append(tests, testCase{
3009 testType: serverTest,
3010 name: "ClientAuth-NoCertificate-Server-TLS13",
3011 config: Config{
3012 MaxVersion: VersionTLS13,
3013 },
3014 // Setting SSL_VERIFY_PEER allows anonymous clients.
3015 flags: []string{"-verify-peer"},
3016 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003017 }
3018 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003019 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003020 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003022 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 ClientAuth: RequireAnyClientCert,
3024 },
3025 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003026 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3027 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003028 },
3029 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003030 tests = append(tests, testCase{
3031 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003032 name: "ClientAuth-RSA-Client-TLS13",
3033 config: Config{
3034 MaxVersion: VersionTLS13,
3035 ClientAuth: RequireAnyClientCert,
3036 },
3037 flags: []string{
3038 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3039 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3040 },
3041 })
3042 tests = append(tests, testCase{
3043 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003044 name: "ClientAuth-ECDSA-Client",
3045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003046 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003047 ClientAuth: RequireAnyClientCert,
3048 },
3049 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003050 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3051 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003052 },
3053 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003054 tests = append(tests, testCase{
3055 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003056 name: "ClientAuth-ECDSA-Client-TLS13",
3057 config: Config{
3058 MaxVersion: VersionTLS13,
3059 ClientAuth: RequireAnyClientCert,
3060 },
3061 flags: []string{
3062 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3063 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3064 },
3065 })
3066 tests = append(tests, testCase{
3067 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 name: "ClientAuth-NoCertificate-OldCallback",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 ClientAuth: RequestClientCert,
3072 },
3073 flags: []string{"-use-old-client-cert-callback"},
3074 })
3075 tests = append(tests, testCase{
3076 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003077 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3078 config: Config{
3079 MaxVersion: VersionTLS13,
3080 ClientAuth: RequestClientCert,
3081 },
3082 flags: []string{"-use-old-client-cert-callback"},
3083 })
3084 tests = append(tests, testCase{
3085 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003086 name: "ClientAuth-OldCallback",
3087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003088 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003089 ClientAuth: RequireAnyClientCert,
3090 },
3091 flags: []string{
3092 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3093 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3094 "-use-old-client-cert-callback",
3095 },
3096 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003098 testType: clientTest,
3099 name: "ClientAuth-OldCallback-TLS13",
3100 config: Config{
3101 MaxVersion: VersionTLS13,
3102 ClientAuth: RequireAnyClientCert,
3103 },
3104 flags: []string{
3105 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3106 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3107 "-use-old-client-cert-callback",
3108 },
3109 })
3110 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003111 testType: serverTest,
3112 name: "ClientAuth-Server",
3113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003115 Certificates: []Certificate{rsaCertificate},
3116 },
3117 flags: []string{"-require-any-client-certificate"},
3118 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003119 tests = append(tests, testCase{
3120 testType: serverTest,
3121 name: "ClientAuth-Server-TLS13",
3122 config: Config{
3123 MaxVersion: VersionTLS13,
3124 Certificates: []Certificate{rsaCertificate},
3125 },
3126 flags: []string{"-require-any-client-certificate"},
3127 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003128
David Benjamin4c3ddf72016-06-29 18:13:53 -04003129 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003130 tests = append(tests, testCase{
3131 testType: serverTest,
3132 name: "Basic-Server-RSA",
3133 config: Config{
3134 MaxVersion: VersionTLS12,
3135 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3136 },
3137 flags: []string{
3138 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3139 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3140 },
3141 })
3142 tests = append(tests, testCase{
3143 testType: serverTest,
3144 name: "Basic-Server-ECDHE-RSA",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3148 },
3149 flags: []string{
3150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3152 },
3153 })
3154 tests = append(tests, testCase{
3155 testType: serverTest,
3156 name: "Basic-Server-ECDHE-ECDSA",
3157 config: Config{
3158 MaxVersion: VersionTLS12,
3159 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3160 },
3161 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003162 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3163 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003164 },
3165 })
3166
David Benjamin760b1dd2015-05-15 23:33:48 -04003167 // No session ticket support; server doesn't send NewSessionTicket.
3168 tests = append(tests, testCase{
3169 name: "SessionTicketsDisabled-Client",
3170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003171 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003172 SessionTicketsDisabled: true,
3173 },
3174 })
3175 tests = append(tests, testCase{
3176 testType: serverTest,
3177 name: "SessionTicketsDisabled-Server",
3178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003179 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003180 SessionTicketsDisabled: true,
3181 },
3182 })
3183
3184 // Skip ServerKeyExchange in PSK key exchange if there's no
3185 // identity hint.
3186 tests = append(tests, testCase{
3187 name: "EmptyPSKHint-Client",
3188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003189 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003190 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3191 PreSharedKey: []byte("secret"),
3192 },
3193 flags: []string{"-psk", "secret"},
3194 })
3195 tests = append(tests, testCase{
3196 testType: serverTest,
3197 name: "EmptyPSKHint-Server",
3198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003199 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003200 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3201 PreSharedKey: []byte("secret"),
3202 },
3203 flags: []string{"-psk", "secret"},
3204 })
3205
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 // OCSP stapling tests.
3207 //
3208 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003209 tests = append(tests, testCase{
3210 testType: clientTest,
3211 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 config: Config{
3213 MaxVersion: VersionTLS12,
3214 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003215 flags: []string{
3216 "-enable-ocsp-stapling",
3217 "-expect-ocsp-response",
3218 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003219 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003220 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003221 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003222 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003223 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003224 testType: serverTest,
3225 name: "OCSPStapling-Server",
3226 config: Config{
3227 MaxVersion: VersionTLS12,
3228 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003229 expectedOCSPResponse: testOCSPResponse,
3230 flags: []string{
3231 "-ocsp-response",
3232 base64.StdEncoding.EncodeToString(testOCSPResponse),
3233 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003234 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003235 })
3236
David Benjamin4c3ddf72016-06-29 18:13:53 -04003237 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003238 for _, vers := range tlsVersions {
3239 if config.protocol == dtls && !vers.hasDTLS {
3240 continue
3241 }
3242 tests = append(tests, testCase{
3243 testType: clientTest,
3244 name: "CertificateVerificationSucceed-" + vers.name,
3245 config: Config{
3246 MaxVersion: vers.version,
3247 },
3248 flags: []string{
3249 "-verify-peer",
3250 },
3251 })
3252 tests = append(tests, testCase{
3253 testType: clientTest,
3254 name: "CertificateVerificationFail-" + vers.name,
3255 config: Config{
3256 MaxVersion: vers.version,
3257 },
3258 flags: []string{
3259 "-verify-fail",
3260 "-verify-peer",
3261 },
3262 shouldFail: true,
3263 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3264 })
3265 tests = append(tests, testCase{
3266 testType: clientTest,
3267 name: "CertificateVerificationSoftFail-" + vers.name,
3268 config: Config{
3269 MaxVersion: vers.version,
3270 },
3271 flags: []string{
3272 "-verify-fail",
3273 "-expect-verify-result",
3274 },
3275 })
3276 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003277
David Benjamin582ba042016-07-07 12:33:25 -07003278 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003279 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003280 name: "Renegotiate-Client",
3281 config: Config{
3282 MaxVersion: VersionTLS12,
3283 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003284 renegotiate: 1,
3285 flags: []string{
3286 "-renegotiate-freely",
3287 "-expect-total-renegotiations", "1",
3288 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290
David Benjamin760b1dd2015-05-15 23:33:48 -04003291 // NPN on client and server; results in post-handshake message.
3292 tests = append(tests, testCase{
3293 name: "NPN-Client",
3294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003295 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003296 NextProtos: []string{"foo"},
3297 },
3298 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003299 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003300 expectedNextProto: "foo",
3301 expectedNextProtoType: npn,
3302 })
3303 tests = append(tests, testCase{
3304 testType: serverTest,
3305 name: "NPN-Server",
3306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003307 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003308 NextProtos: []string{"bar"},
3309 },
3310 flags: []string{
3311 "-advertise-npn", "\x03foo\x03bar\x03baz",
3312 "-expect-next-proto", "bar",
3313 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003314 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003315 expectedNextProto: "bar",
3316 expectedNextProtoType: npn,
3317 })
3318
3319 // TODO(davidben): Add tests for when False Start doesn't trigger.
3320
3321 // Client does False Start and negotiates NPN.
3322 tests = append(tests, testCase{
3323 name: "FalseStart",
3324 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003325 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003326 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3327 NextProtos: []string{"foo"},
3328 Bugs: ProtocolBugs{
3329 ExpectFalseStart: true,
3330 },
3331 },
3332 flags: []string{
3333 "-false-start",
3334 "-select-next-proto", "foo",
3335 },
3336 shimWritesFirst: true,
3337 resumeSession: true,
3338 })
3339
3340 // Client does False Start and negotiates ALPN.
3341 tests = append(tests, testCase{
3342 name: "FalseStart-ALPN",
3343 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003344 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3346 NextProtos: []string{"foo"},
3347 Bugs: ProtocolBugs{
3348 ExpectFalseStart: true,
3349 },
3350 },
3351 flags: []string{
3352 "-false-start",
3353 "-advertise-alpn", "\x03foo",
3354 },
3355 shimWritesFirst: true,
3356 resumeSession: true,
3357 })
3358
3359 // Client does False Start but doesn't explicitly call
3360 // SSL_connect.
3361 tests = append(tests, testCase{
3362 name: "FalseStart-Implicit",
3363 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003364 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003365 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3366 NextProtos: []string{"foo"},
3367 },
3368 flags: []string{
3369 "-implicit-handshake",
3370 "-false-start",
3371 "-advertise-alpn", "\x03foo",
3372 },
3373 })
3374
3375 // False Start without session tickets.
3376 tests = append(tests, testCase{
3377 name: "FalseStart-SessionTicketsDisabled",
3378 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003379 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3381 NextProtos: []string{"foo"},
3382 SessionTicketsDisabled: true,
3383 Bugs: ProtocolBugs{
3384 ExpectFalseStart: true,
3385 },
3386 },
3387 flags: []string{
3388 "-false-start",
3389 "-select-next-proto", "foo",
3390 },
3391 shimWritesFirst: true,
3392 })
3393
Adam Langleydf759b52016-07-11 15:24:37 -07003394 tests = append(tests, testCase{
3395 name: "FalseStart-CECPQ1",
3396 config: Config{
3397 MaxVersion: VersionTLS12,
3398 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3399 NextProtos: []string{"foo"},
3400 Bugs: ProtocolBugs{
3401 ExpectFalseStart: true,
3402 },
3403 },
3404 flags: []string{
3405 "-false-start",
3406 "-cipher", "DEFAULT:kCECPQ1",
3407 "-select-next-proto", "foo",
3408 },
3409 shimWritesFirst: true,
3410 resumeSession: true,
3411 })
3412
David Benjamin760b1dd2015-05-15 23:33:48 -04003413 // Server parses a V2ClientHello.
3414 tests = append(tests, testCase{
3415 testType: serverTest,
3416 name: "SendV2ClientHello",
3417 config: Config{
3418 // Choose a cipher suite that does not involve
3419 // elliptic curves, so no extensions are
3420 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003421 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003422 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3423 Bugs: ProtocolBugs{
3424 SendV2ClientHello: true,
3425 },
3426 },
3427 })
3428
3429 // Client sends a Channel ID.
3430 tests = append(tests, testCase{
3431 name: "ChannelID-Client",
3432 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003433 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003434 RequestChannelID: true,
3435 },
Adam Langley7c803a62015-06-15 15:35:05 -07003436 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003437 resumeSession: true,
3438 expectChannelID: true,
3439 })
3440
3441 // Server accepts a Channel ID.
3442 tests = append(tests, testCase{
3443 testType: serverTest,
3444 name: "ChannelID-Server",
3445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003446 MaxVersion: VersionTLS12,
3447 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003448 },
3449 flags: []string{
3450 "-expect-channel-id",
3451 base64.StdEncoding.EncodeToString(channelIDBytes),
3452 },
3453 resumeSession: true,
3454 expectChannelID: true,
3455 })
David Benjamin30789da2015-08-29 22:56:45 -04003456
David Benjaminf8fcdf32016-06-08 15:56:13 -04003457 // Channel ID and NPN at the same time, to ensure their relative
3458 // ordering is correct.
3459 tests = append(tests, testCase{
3460 name: "ChannelID-NPN-Client",
3461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003462 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003463 RequestChannelID: true,
3464 NextProtos: []string{"foo"},
3465 },
3466 flags: []string{
3467 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3468 "-select-next-proto", "foo",
3469 },
3470 resumeSession: true,
3471 expectChannelID: true,
3472 expectedNextProto: "foo",
3473 expectedNextProtoType: npn,
3474 })
3475 tests = append(tests, testCase{
3476 testType: serverTest,
3477 name: "ChannelID-NPN-Server",
3478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003479 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003480 ChannelID: channelIDKey,
3481 NextProtos: []string{"bar"},
3482 },
3483 flags: []string{
3484 "-expect-channel-id",
3485 base64.StdEncoding.EncodeToString(channelIDBytes),
3486 "-advertise-npn", "\x03foo\x03bar\x03baz",
3487 "-expect-next-proto", "bar",
3488 },
3489 resumeSession: true,
3490 expectChannelID: true,
3491 expectedNextProto: "bar",
3492 expectedNextProtoType: npn,
3493 })
3494
David Benjamin30789da2015-08-29 22:56:45 -04003495 // Bidirectional shutdown with the runner initiating.
3496 tests = append(tests, testCase{
3497 name: "Shutdown-Runner",
3498 config: Config{
3499 Bugs: ProtocolBugs{
3500 ExpectCloseNotify: true,
3501 },
3502 },
3503 flags: []string{"-check-close-notify"},
3504 })
3505
3506 // Bidirectional shutdown with the shim initiating. The runner,
3507 // in the meantime, sends garbage before the close_notify which
3508 // the shim must ignore.
3509 tests = append(tests, testCase{
3510 name: "Shutdown-Shim",
3511 config: Config{
3512 Bugs: ProtocolBugs{
3513 ExpectCloseNotify: true,
3514 },
3515 },
3516 shimShutsDown: true,
3517 sendEmptyRecords: 1,
3518 sendWarningAlerts: 1,
3519 flags: []string{"-check-close-notify"},
3520 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003521 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003522 // TODO(davidben): DTLS 1.3 will want a similar thing for
3523 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003524 tests = append(tests, testCase{
3525 name: "SkipHelloVerifyRequest",
3526 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003527 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003528 Bugs: ProtocolBugs{
3529 SkipHelloVerifyRequest: true,
3530 },
3531 },
3532 })
3533 }
3534
David Benjamin760b1dd2015-05-15 23:33:48 -04003535 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003536 test.protocol = config.protocol
3537 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003538 test.name += "-DTLS"
3539 }
David Benjamin582ba042016-07-07 12:33:25 -07003540 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003541 test.name += "-Async"
3542 test.flags = append(test.flags, "-async")
3543 } else {
3544 test.name += "-Sync"
3545 }
David Benjamin582ba042016-07-07 12:33:25 -07003546 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003547 test.name += "-SplitHandshakeRecords"
3548 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003549 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003550 test.config.Bugs.MaxPacketLength = 256
3551 test.flags = append(test.flags, "-mtu", "256")
3552 }
3553 }
David Benjamin582ba042016-07-07 12:33:25 -07003554 if config.packHandshakeFlight {
3555 test.name += "-PackHandshakeFlight"
3556 test.config.Bugs.PackHandshakeFlight = true
3557 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003558 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003559 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003560}
3561
Adam Langley524e7172015-02-20 16:04:00 -08003562func addDDoSCallbackTests() {
3563 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003564 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003565 for _, resume := range []bool{false, true} {
3566 suffix := "Resume"
3567 if resume {
3568 suffix = "No" + suffix
3569 }
3570
3571 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003572 testType: serverTest,
3573 name: "Server-DDoS-OK-" + suffix,
3574 config: Config{
3575 MaxVersion: VersionTLS12,
3576 },
Adam Langley524e7172015-02-20 16:04:00 -08003577 flags: []string{"-install-ddos-callback"},
3578 resumeSession: resume,
3579 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003580 if !resume {
3581 testCases = append(testCases, testCase{
3582 testType: serverTest,
3583 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3584 config: Config{
3585 MaxVersion: VersionTLS13,
3586 },
3587 flags: []string{"-install-ddos-callback"},
3588 resumeSession: resume,
3589 })
3590 }
Adam Langley524e7172015-02-20 16:04:00 -08003591
3592 failFlag := "-fail-ddos-callback"
3593 if resume {
3594 failFlag = "-fail-second-ddos-callback"
3595 }
3596 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003597 testType: serverTest,
3598 name: "Server-DDoS-Reject-" + suffix,
3599 config: Config{
3600 MaxVersion: VersionTLS12,
3601 },
Adam Langley524e7172015-02-20 16:04:00 -08003602 flags: []string{"-install-ddos-callback", failFlag},
3603 resumeSession: resume,
3604 shouldFail: true,
3605 expectedError: ":CONNECTION_REJECTED:",
3606 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003607 if !resume {
3608 testCases = append(testCases, testCase{
3609 testType: serverTest,
3610 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3611 config: Config{
3612 MaxVersion: VersionTLS13,
3613 },
3614 flags: []string{"-install-ddos-callback", failFlag},
3615 resumeSession: resume,
3616 shouldFail: true,
3617 expectedError: ":CONNECTION_REJECTED:",
3618 })
3619 }
Adam Langley524e7172015-02-20 16:04:00 -08003620 }
3621}
3622
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003623func addVersionNegotiationTests() {
3624 for i, shimVers := range tlsVersions {
3625 // Assemble flags to disable all newer versions on the shim.
3626 var flags []string
3627 for _, vers := range tlsVersions[i+1:] {
3628 flags = append(flags, vers.flag)
3629 }
3630
3631 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003632 protocols := []protocol{tls}
3633 if runnerVers.hasDTLS && shimVers.hasDTLS {
3634 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003635 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003636 for _, protocol := range protocols {
3637 expectedVersion := shimVers.version
3638 if runnerVers.version < shimVers.version {
3639 expectedVersion = runnerVers.version
3640 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003641
David Benjamin8b8c0062014-11-23 02:47:52 -05003642 suffix := shimVers.name + "-" + runnerVers.name
3643 if protocol == dtls {
3644 suffix += "-DTLS"
3645 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003646
David Benjamin1eb367c2014-12-12 18:17:51 -05003647 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3648
David Benjamin1e29a6b2014-12-10 02:27:24 -05003649 clientVers := shimVers.version
3650 if clientVers > VersionTLS10 {
3651 clientVers = VersionTLS10
3652 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003653 serverVers := expectedVersion
3654 if expectedVersion >= VersionTLS13 {
3655 serverVers = VersionTLS10
3656 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003657 testCases = append(testCases, testCase{
3658 protocol: protocol,
3659 testType: clientTest,
3660 name: "VersionNegotiation-Client-" + suffix,
3661 config: Config{
3662 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003663 Bugs: ProtocolBugs{
3664 ExpectInitialRecordVersion: clientVers,
3665 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003666 },
3667 flags: flags,
3668 expectedVersion: expectedVersion,
3669 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003670 testCases = append(testCases, testCase{
3671 protocol: protocol,
3672 testType: clientTest,
3673 name: "VersionNegotiation-Client2-" + suffix,
3674 config: Config{
3675 MaxVersion: runnerVers.version,
3676 Bugs: ProtocolBugs{
3677 ExpectInitialRecordVersion: clientVers,
3678 },
3679 },
3680 flags: []string{"-max-version", shimVersFlag},
3681 expectedVersion: expectedVersion,
3682 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003683
3684 testCases = append(testCases, testCase{
3685 protocol: protocol,
3686 testType: serverTest,
3687 name: "VersionNegotiation-Server-" + suffix,
3688 config: Config{
3689 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003690 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003691 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003692 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003693 },
3694 flags: flags,
3695 expectedVersion: expectedVersion,
3696 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003697 testCases = append(testCases, testCase{
3698 protocol: protocol,
3699 testType: serverTest,
3700 name: "VersionNegotiation-Server2-" + suffix,
3701 config: Config{
3702 MaxVersion: runnerVers.version,
3703 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003704 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003705 },
3706 },
3707 flags: []string{"-max-version", shimVersFlag},
3708 expectedVersion: expectedVersion,
3709 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003710 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003711 }
3712 }
David Benjamin95c69562016-06-29 18:15:03 -04003713
3714 // Test for version tolerance.
3715 testCases = append(testCases, testCase{
3716 testType: serverTest,
3717 name: "MinorVersionTolerance",
3718 config: Config{
3719 Bugs: ProtocolBugs{
3720 SendClientVersion: 0x03ff,
3721 },
3722 },
3723 expectedVersion: VersionTLS13,
3724 })
3725 testCases = append(testCases, testCase{
3726 testType: serverTest,
3727 name: "MajorVersionTolerance",
3728 config: Config{
3729 Bugs: ProtocolBugs{
3730 SendClientVersion: 0x0400,
3731 },
3732 },
3733 expectedVersion: VersionTLS13,
3734 })
3735 testCases = append(testCases, testCase{
3736 protocol: dtls,
3737 testType: serverTest,
3738 name: "MinorVersionTolerance-DTLS",
3739 config: Config{
3740 Bugs: ProtocolBugs{
3741 SendClientVersion: 0x03ff,
3742 },
3743 },
3744 expectedVersion: VersionTLS12,
3745 })
3746 testCases = append(testCases, testCase{
3747 protocol: dtls,
3748 testType: serverTest,
3749 name: "MajorVersionTolerance-DTLS",
3750 config: Config{
3751 Bugs: ProtocolBugs{
3752 SendClientVersion: 0x0400,
3753 },
3754 },
3755 expectedVersion: VersionTLS12,
3756 })
3757
3758 // Test that versions below 3.0 are rejected.
3759 testCases = append(testCases, testCase{
3760 testType: serverTest,
3761 name: "VersionTooLow",
3762 config: Config{
3763 Bugs: ProtocolBugs{
3764 SendClientVersion: 0x0200,
3765 },
3766 },
3767 shouldFail: true,
3768 expectedError: ":UNSUPPORTED_PROTOCOL:",
3769 })
3770 testCases = append(testCases, testCase{
3771 protocol: dtls,
3772 testType: serverTest,
3773 name: "VersionTooLow-DTLS",
3774 config: Config{
3775 Bugs: ProtocolBugs{
3776 // 0x0201 is the lowest version expressable in
3777 // DTLS.
3778 SendClientVersion: 0x0201,
3779 },
3780 },
3781 shouldFail: true,
3782 expectedError: ":UNSUPPORTED_PROTOCOL:",
3783 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003784
3785 // Test TLS 1.3's downgrade signal.
3786 testCases = append(testCases, testCase{
3787 name: "Downgrade-TLS12-Client",
3788 config: Config{
3789 Bugs: ProtocolBugs{
3790 NegotiateVersion: VersionTLS12,
3791 },
3792 },
3793 shouldFail: true,
3794 expectedError: ":DOWNGRADE_DETECTED:",
3795 })
3796 testCases = append(testCases, testCase{
3797 testType: serverTest,
3798 name: "Downgrade-TLS12-Server",
3799 config: Config{
3800 Bugs: ProtocolBugs{
3801 SendClientVersion: VersionTLS12,
3802 },
3803 },
3804 shouldFail: true,
3805 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3806 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003807}
3808
David Benjaminaccb4542014-12-12 23:44:33 -05003809func addMinimumVersionTests() {
3810 for i, shimVers := range tlsVersions {
3811 // Assemble flags to disable all older versions on the shim.
3812 var flags []string
3813 for _, vers := range tlsVersions[:i] {
3814 flags = append(flags, vers.flag)
3815 }
3816
3817 for _, runnerVers := range tlsVersions {
3818 protocols := []protocol{tls}
3819 if runnerVers.hasDTLS && shimVers.hasDTLS {
3820 protocols = append(protocols, dtls)
3821 }
3822 for _, protocol := range protocols {
3823 suffix := shimVers.name + "-" + runnerVers.name
3824 if protocol == dtls {
3825 suffix += "-DTLS"
3826 }
3827 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3828
David Benjaminaccb4542014-12-12 23:44:33 -05003829 var expectedVersion uint16
3830 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003831 var expectedClientError, expectedServerError string
3832 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003833 if runnerVers.version >= shimVers.version {
3834 expectedVersion = runnerVers.version
3835 } else {
3836 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003837 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3838 expectedServerLocalError = "remote error: protocol version not supported"
3839 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3840 // If the client's minimum version is TLS 1.3 and the runner's
3841 // maximum is below TLS 1.2, the runner will fail to select a
3842 // cipher before the shim rejects the selected version.
3843 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3844 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3845 } else {
3846 expectedClientError = expectedServerError
3847 expectedClientLocalError = expectedServerLocalError
3848 }
David Benjaminaccb4542014-12-12 23:44:33 -05003849 }
3850
3851 testCases = append(testCases, testCase{
3852 protocol: protocol,
3853 testType: clientTest,
3854 name: "MinimumVersion-Client-" + suffix,
3855 config: Config{
3856 MaxVersion: runnerVers.version,
3857 },
David Benjamin87909c02014-12-13 01:55:01 -05003858 flags: flags,
3859 expectedVersion: expectedVersion,
3860 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003861 expectedError: expectedClientError,
3862 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003863 })
3864 testCases = append(testCases, testCase{
3865 protocol: protocol,
3866 testType: clientTest,
3867 name: "MinimumVersion-Client2-" + suffix,
3868 config: Config{
3869 MaxVersion: runnerVers.version,
3870 },
David Benjamin87909c02014-12-13 01:55:01 -05003871 flags: []string{"-min-version", shimVersFlag},
3872 expectedVersion: expectedVersion,
3873 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003874 expectedError: expectedClientError,
3875 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003876 })
3877
3878 testCases = append(testCases, testCase{
3879 protocol: protocol,
3880 testType: serverTest,
3881 name: "MinimumVersion-Server-" + suffix,
3882 config: Config{
3883 MaxVersion: runnerVers.version,
3884 },
David Benjamin87909c02014-12-13 01:55:01 -05003885 flags: flags,
3886 expectedVersion: expectedVersion,
3887 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003888 expectedError: expectedServerError,
3889 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003890 })
3891 testCases = append(testCases, testCase{
3892 protocol: protocol,
3893 testType: serverTest,
3894 name: "MinimumVersion-Server2-" + suffix,
3895 config: Config{
3896 MaxVersion: runnerVers.version,
3897 },
David Benjamin87909c02014-12-13 01:55:01 -05003898 flags: []string{"-min-version", shimVersFlag},
3899 expectedVersion: expectedVersion,
3900 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003901 expectedError: expectedServerError,
3902 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003903 })
3904 }
3905 }
3906 }
3907}
3908
David Benjamine78bfde2014-09-06 12:45:15 -04003909func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003910 // TODO(davidben): Extensions, where applicable, all move their server
3911 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3912 // tests for both. Also test interaction with 0-RTT when implemented.
3913
David Benjamin97d17d92016-07-14 16:12:00 -04003914 // Repeat extensions tests all versions except SSL 3.0.
3915 for _, ver := range tlsVersions {
3916 if ver.version == VersionSSL30 {
3917 continue
3918 }
3919
3920 // TODO(davidben): Implement resumption in TLS 1.3.
3921 resumeSession := ver.version < VersionTLS13
3922
3923 // Test that duplicate extensions are rejected.
3924 testCases = append(testCases, testCase{
3925 testType: clientTest,
3926 name: "DuplicateExtensionClient-" + ver.name,
3927 config: Config{
3928 MaxVersion: ver.version,
3929 Bugs: ProtocolBugs{
3930 DuplicateExtension: true,
3931 },
David Benjamine78bfde2014-09-06 12:45:15 -04003932 },
David Benjamin97d17d92016-07-14 16:12:00 -04003933 shouldFail: true,
3934 expectedLocalError: "remote error: error decoding message",
3935 })
3936 testCases = append(testCases, testCase{
3937 testType: serverTest,
3938 name: "DuplicateExtensionServer-" + ver.name,
3939 config: Config{
3940 MaxVersion: ver.version,
3941 Bugs: ProtocolBugs{
3942 DuplicateExtension: true,
3943 },
David Benjamine78bfde2014-09-06 12:45:15 -04003944 },
David Benjamin97d17d92016-07-14 16:12:00 -04003945 shouldFail: true,
3946 expectedLocalError: "remote error: error decoding message",
3947 })
3948
3949 // Test SNI.
3950 testCases = append(testCases, testCase{
3951 testType: clientTest,
3952 name: "ServerNameExtensionClient-" + ver.name,
3953 config: Config{
3954 MaxVersion: ver.version,
3955 Bugs: ProtocolBugs{
3956 ExpectServerName: "example.com",
3957 },
David Benjamine78bfde2014-09-06 12:45:15 -04003958 },
David Benjamin97d17d92016-07-14 16:12:00 -04003959 flags: []string{"-host-name", "example.com"},
3960 })
3961 testCases = append(testCases, testCase{
3962 testType: clientTest,
3963 name: "ServerNameExtensionClientMismatch-" + ver.name,
3964 config: Config{
3965 MaxVersion: ver.version,
3966 Bugs: ProtocolBugs{
3967 ExpectServerName: "mismatch.com",
3968 },
David Benjamine78bfde2014-09-06 12:45:15 -04003969 },
David Benjamin97d17d92016-07-14 16:12:00 -04003970 flags: []string{"-host-name", "example.com"},
3971 shouldFail: true,
3972 expectedLocalError: "tls: unexpected server name",
3973 })
3974 testCases = append(testCases, testCase{
3975 testType: clientTest,
3976 name: "ServerNameExtensionClientMissing-" + ver.name,
3977 config: Config{
3978 MaxVersion: ver.version,
3979 Bugs: ProtocolBugs{
3980 ExpectServerName: "missing.com",
3981 },
David Benjamine78bfde2014-09-06 12:45:15 -04003982 },
David Benjamin97d17d92016-07-14 16:12:00 -04003983 shouldFail: true,
3984 expectedLocalError: "tls: unexpected server name",
3985 })
3986 testCases = append(testCases, testCase{
3987 testType: serverTest,
3988 name: "ServerNameExtensionServer-" + ver.name,
3989 config: Config{
3990 MaxVersion: ver.version,
3991 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04003992 },
David Benjamin97d17d92016-07-14 16:12:00 -04003993 flags: []string{"-expect-server-name", "example.com"},
3994 resumeSession: resumeSession,
3995 })
3996
3997 // Test ALPN.
3998 testCases = append(testCases, testCase{
3999 testType: clientTest,
4000 name: "ALPNClient-" + ver.name,
4001 config: Config{
4002 MaxVersion: ver.version,
4003 NextProtos: []string{"foo"},
4004 },
4005 flags: []string{
4006 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4007 "-expect-alpn", "foo",
4008 },
4009 expectedNextProto: "foo",
4010 expectedNextProtoType: alpn,
4011 resumeSession: resumeSession,
4012 })
4013 testCases = append(testCases, testCase{
4014 testType: serverTest,
4015 name: "ALPNServer-" + ver.name,
4016 config: Config{
4017 MaxVersion: ver.version,
4018 NextProtos: []string{"foo", "bar", "baz"},
4019 },
4020 flags: []string{
4021 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4022 "-select-alpn", "foo",
4023 },
4024 expectedNextProto: "foo",
4025 expectedNextProtoType: alpn,
4026 resumeSession: resumeSession,
4027 })
4028 testCases = append(testCases, testCase{
4029 testType: serverTest,
4030 name: "ALPNServer-Decline-" + ver.name,
4031 config: Config{
4032 MaxVersion: ver.version,
4033 NextProtos: []string{"foo", "bar", "baz"},
4034 },
4035 flags: []string{"-decline-alpn"},
4036 expectNoNextProto: true,
4037 resumeSession: resumeSession,
4038 })
4039
4040 var emptyString string
4041 testCases = append(testCases, testCase{
4042 testType: clientTest,
4043 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4044 config: Config{
4045 MaxVersion: ver.version,
4046 NextProtos: []string{""},
4047 Bugs: ProtocolBugs{
4048 // A server returning an empty ALPN protocol
4049 // should be rejected.
4050 ALPNProtocol: &emptyString,
4051 },
4052 },
4053 flags: []string{
4054 "-advertise-alpn", "\x03foo",
4055 },
4056 shouldFail: true,
4057 expectedError: ":PARSE_TLSEXT:",
4058 })
4059 testCases = append(testCases, testCase{
4060 testType: serverTest,
4061 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4062 config: Config{
4063 MaxVersion: ver.version,
4064 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004065 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004066 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004067 },
David Benjamin97d17d92016-07-14 16:12:00 -04004068 flags: []string{
4069 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004070 },
David Benjamin97d17d92016-07-14 16:12:00 -04004071 shouldFail: true,
4072 expectedError: ":PARSE_TLSEXT:",
4073 })
4074
4075 // Test NPN and the interaction with ALPN.
4076 if ver.version < VersionTLS13 {
4077 // Test that the server prefers ALPN over NPN.
4078 testCases = append(testCases, testCase{
4079 testType: serverTest,
4080 name: "ALPNServer-Preferred-" + ver.name,
4081 config: Config{
4082 MaxVersion: ver.version,
4083 NextProtos: []string{"foo", "bar", "baz"},
4084 },
4085 flags: []string{
4086 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4087 "-select-alpn", "foo",
4088 "-advertise-npn", "\x03foo\x03bar\x03baz",
4089 },
4090 expectedNextProto: "foo",
4091 expectedNextProtoType: alpn,
4092 resumeSession: resumeSession,
4093 })
4094 testCases = append(testCases, testCase{
4095 testType: serverTest,
4096 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4097 config: Config{
4098 MaxVersion: ver.version,
4099 NextProtos: []string{"foo", "bar", "baz"},
4100 Bugs: ProtocolBugs{
4101 SwapNPNAndALPN: true,
4102 },
4103 },
4104 flags: []string{
4105 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4106 "-select-alpn", "foo",
4107 "-advertise-npn", "\x03foo\x03bar\x03baz",
4108 },
4109 expectedNextProto: "foo",
4110 expectedNextProtoType: alpn,
4111 resumeSession: resumeSession,
4112 })
4113
4114 // Test that negotiating both NPN and ALPN is forbidden.
4115 testCases = append(testCases, testCase{
4116 name: "NegotiateALPNAndNPN-" + ver.name,
4117 config: Config{
4118 MaxVersion: ver.version,
4119 NextProtos: []string{"foo", "bar", "baz"},
4120 Bugs: ProtocolBugs{
4121 NegotiateALPNAndNPN: true,
4122 },
4123 },
4124 flags: []string{
4125 "-advertise-alpn", "\x03foo",
4126 "-select-next-proto", "foo",
4127 },
4128 shouldFail: true,
4129 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4130 })
4131 testCases = append(testCases, testCase{
4132 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4133 config: Config{
4134 MaxVersion: ver.version,
4135 NextProtos: []string{"foo", "bar", "baz"},
4136 Bugs: ProtocolBugs{
4137 NegotiateALPNAndNPN: true,
4138 SwapNPNAndALPN: true,
4139 },
4140 },
4141 flags: []string{
4142 "-advertise-alpn", "\x03foo",
4143 "-select-next-proto", "foo",
4144 },
4145 shouldFail: true,
4146 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4147 })
4148
4149 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4150 testCases = append(testCases, testCase{
4151 name: "DisableNPN-" + ver.name,
4152 config: Config{
4153 MaxVersion: ver.version,
4154 NextProtos: []string{"foo"},
4155 },
4156 flags: []string{
4157 "-select-next-proto", "foo",
4158 "-disable-npn",
4159 },
4160 expectNoNextProto: true,
4161 })
4162 }
4163
4164 // Test ticket behavior.
4165 //
4166 // TODO(davidben): Add TLS 1.3 versions of these.
4167 if ver.version < VersionTLS13 {
4168 // Resume with a corrupt ticket.
4169 testCases = append(testCases, testCase{
4170 testType: serverTest,
4171 name: "CorruptTicket-" + ver.name,
4172 config: Config{
4173 MaxVersion: ver.version,
4174 Bugs: ProtocolBugs{
4175 CorruptTicket: true,
4176 },
4177 },
4178 resumeSession: true,
4179 expectResumeRejected: true,
4180 })
4181 // Test the ticket callback, with and without renewal.
4182 testCases = append(testCases, testCase{
4183 testType: serverTest,
4184 name: "TicketCallback-" + ver.name,
4185 config: Config{
4186 MaxVersion: ver.version,
4187 },
4188 resumeSession: true,
4189 flags: []string{"-use-ticket-callback"},
4190 })
4191 testCases = append(testCases, testCase{
4192 testType: serverTest,
4193 name: "TicketCallback-Renew-" + ver.name,
4194 config: Config{
4195 MaxVersion: ver.version,
4196 Bugs: ProtocolBugs{
4197 ExpectNewTicket: true,
4198 },
4199 },
4200 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4201 resumeSession: true,
4202 })
4203
4204 // Resume with an oversized session id.
4205 testCases = append(testCases, testCase{
4206 testType: serverTest,
4207 name: "OversizedSessionId-" + ver.name,
4208 config: Config{
4209 MaxVersion: ver.version,
4210 Bugs: ProtocolBugs{
4211 OversizedSessionId: true,
4212 },
4213 },
4214 resumeSession: true,
4215 shouldFail: true,
4216 expectedError: ":DECODE_ERROR:",
4217 })
4218 }
4219
4220 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4221 // are ignored.
4222 if ver.hasDTLS {
4223 testCases = append(testCases, testCase{
4224 protocol: dtls,
4225 name: "SRTP-Client-" + ver.name,
4226 config: Config{
4227 MaxVersion: ver.version,
4228 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4229 },
4230 flags: []string{
4231 "-srtp-profiles",
4232 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4233 },
4234 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4235 })
4236 testCases = append(testCases, testCase{
4237 protocol: dtls,
4238 testType: serverTest,
4239 name: "SRTP-Server-" + ver.name,
4240 config: Config{
4241 MaxVersion: ver.version,
4242 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4243 },
4244 flags: []string{
4245 "-srtp-profiles",
4246 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4247 },
4248 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4249 })
4250 // Test that the MKI is ignored.
4251 testCases = append(testCases, testCase{
4252 protocol: dtls,
4253 testType: serverTest,
4254 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4255 config: Config{
4256 MaxVersion: ver.version,
4257 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4258 Bugs: ProtocolBugs{
4259 SRTPMasterKeyIdentifer: "bogus",
4260 },
4261 },
4262 flags: []string{
4263 "-srtp-profiles",
4264 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4265 },
4266 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4267 })
4268 // Test that SRTP isn't negotiated on the server if there were
4269 // no matching profiles.
4270 testCases = append(testCases, testCase{
4271 protocol: dtls,
4272 testType: serverTest,
4273 name: "SRTP-Server-NoMatch-" + ver.name,
4274 config: Config{
4275 MaxVersion: ver.version,
4276 SRTPProtectionProfiles: []uint16{100, 101, 102},
4277 },
4278 flags: []string{
4279 "-srtp-profiles",
4280 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4281 },
4282 expectedSRTPProtectionProfile: 0,
4283 })
4284 // Test that the server returning an invalid SRTP profile is
4285 // flagged as an error by the client.
4286 testCases = append(testCases, testCase{
4287 protocol: dtls,
4288 name: "SRTP-Client-NoMatch-" + ver.name,
4289 config: Config{
4290 MaxVersion: ver.version,
4291 Bugs: ProtocolBugs{
4292 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4293 },
4294 },
4295 flags: []string{
4296 "-srtp-profiles",
4297 "SRTP_AES128_CM_SHA1_80",
4298 },
4299 shouldFail: true,
4300 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4301 })
4302 }
4303
4304 // Test SCT list.
4305 testCases = append(testCases, testCase{
4306 name: "SignedCertificateTimestampList-Client-" + ver.name,
4307 testType: clientTest,
4308 config: Config{
4309 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004310 },
David Benjamin97d17d92016-07-14 16:12:00 -04004311 flags: []string{
4312 "-enable-signed-cert-timestamps",
4313 "-expect-signed-cert-timestamps",
4314 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004315 },
David Benjamin97d17d92016-07-14 16:12:00 -04004316 resumeSession: resumeSession,
4317 })
4318 testCases = append(testCases, testCase{
4319 name: "SendSCTListOnResume-" + ver.name,
4320 config: Config{
4321 MaxVersion: ver.version,
4322 Bugs: ProtocolBugs{
4323 SendSCTListOnResume: []byte("bogus"),
4324 },
David Benjamind98452d2015-06-16 14:16:23 -04004325 },
David Benjamin97d17d92016-07-14 16:12:00 -04004326 flags: []string{
4327 "-enable-signed-cert-timestamps",
4328 "-expect-signed-cert-timestamps",
4329 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004330 },
David Benjamin97d17d92016-07-14 16:12:00 -04004331 resumeSession: resumeSession,
4332 })
4333 testCases = append(testCases, testCase{
4334 name: "SignedCertificateTimestampList-Server-" + ver.name,
4335 testType: serverTest,
4336 config: Config{
4337 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004338 },
David Benjamin97d17d92016-07-14 16:12:00 -04004339 flags: []string{
4340 "-signed-cert-timestamps",
4341 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004342 },
David Benjamin97d17d92016-07-14 16:12:00 -04004343 expectedSCTList: testSCTList,
4344 resumeSession: resumeSession,
4345 })
4346 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004347
Paul Lietar4fac72e2015-09-09 13:44:55 +01004348 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004349 testType: clientTest,
4350 name: "ClientHelloPadding",
4351 config: Config{
4352 Bugs: ProtocolBugs{
4353 RequireClientHelloSize: 512,
4354 },
4355 },
4356 // This hostname just needs to be long enough to push the
4357 // ClientHello into F5's danger zone between 256 and 511 bytes
4358 // long.
4359 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4360 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004361
4362 // Extensions should not function in SSL 3.0.
4363 testCases = append(testCases, testCase{
4364 testType: serverTest,
4365 name: "SSLv3Extensions-NoALPN",
4366 config: Config{
4367 MaxVersion: VersionSSL30,
4368 NextProtos: []string{"foo", "bar", "baz"},
4369 },
4370 flags: []string{
4371 "-select-alpn", "foo",
4372 },
4373 expectNoNextProto: true,
4374 })
4375
4376 // Test session tickets separately as they follow a different codepath.
4377 testCases = append(testCases, testCase{
4378 testType: serverTest,
4379 name: "SSLv3Extensions-NoTickets",
4380 config: Config{
4381 MaxVersion: VersionSSL30,
4382 Bugs: ProtocolBugs{
4383 // Historically, session tickets in SSL 3.0
4384 // failed in different ways depending on whether
4385 // the client supported renegotiation_info.
4386 NoRenegotiationInfo: true,
4387 },
4388 },
4389 resumeSession: true,
4390 })
4391 testCases = append(testCases, testCase{
4392 testType: serverTest,
4393 name: "SSLv3Extensions-NoTickets2",
4394 config: Config{
4395 MaxVersion: VersionSSL30,
4396 },
4397 resumeSession: true,
4398 })
4399
4400 // But SSL 3.0 does send and process renegotiation_info.
4401 testCases = append(testCases, testCase{
4402 testType: serverTest,
4403 name: "SSLv3Extensions-RenegotiationInfo",
4404 config: Config{
4405 MaxVersion: VersionSSL30,
4406 Bugs: ProtocolBugs{
4407 RequireRenegotiationInfo: true,
4408 },
4409 },
4410 })
4411 testCases = append(testCases, testCase{
4412 testType: serverTest,
4413 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4414 config: Config{
4415 MaxVersion: VersionSSL30,
4416 Bugs: ProtocolBugs{
4417 NoRenegotiationInfo: true,
4418 SendRenegotiationSCSV: true,
4419 RequireRenegotiationInfo: true,
4420 },
4421 },
4422 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004423
4424 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4425 // in ServerHello.
4426 testCases = append(testCases, testCase{
4427 name: "NPN-Forbidden-TLS13",
4428 config: Config{
4429 MaxVersion: VersionTLS13,
4430 NextProtos: []string{"foo"},
4431 Bugs: ProtocolBugs{
4432 NegotiateNPNAtAllVersions: true,
4433 },
4434 },
4435 flags: []string{"-select-next-proto", "foo"},
4436 shouldFail: true,
4437 expectedError: ":ERROR_PARSING_EXTENSION:",
4438 })
4439 testCases = append(testCases, testCase{
4440 name: "EMS-Forbidden-TLS13",
4441 config: Config{
4442 MaxVersion: VersionTLS13,
4443 Bugs: ProtocolBugs{
4444 NegotiateEMSAtAllVersions: true,
4445 },
4446 },
4447 shouldFail: true,
4448 expectedError: ":ERROR_PARSING_EXTENSION:",
4449 })
4450 testCases = append(testCases, testCase{
4451 name: "RenegotiationInfo-Forbidden-TLS13",
4452 config: Config{
4453 MaxVersion: VersionTLS13,
4454 Bugs: ProtocolBugs{
4455 NegotiateRenegotiationInfoAtAllVersions: true,
4456 },
4457 },
4458 shouldFail: true,
4459 expectedError: ":ERROR_PARSING_EXTENSION:",
4460 })
4461 testCases = append(testCases, testCase{
4462 name: "ChannelID-Forbidden-TLS13",
4463 config: Config{
4464 MaxVersion: VersionTLS13,
4465 RequestChannelID: true,
4466 Bugs: ProtocolBugs{
4467 NegotiateChannelIDAtAllVersions: true,
4468 },
4469 },
4470 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4471 shouldFail: true,
4472 expectedError: ":ERROR_PARSING_EXTENSION:",
4473 })
4474 testCases = append(testCases, testCase{
4475 name: "Ticket-Forbidden-TLS13",
4476 config: Config{
4477 MaxVersion: VersionTLS12,
4478 },
4479 resumeConfig: &Config{
4480 MaxVersion: VersionTLS13,
4481 Bugs: ProtocolBugs{
4482 AdvertiseTicketExtension: true,
4483 },
4484 },
4485 resumeSession: true,
4486 shouldFail: true,
4487 expectedError: ":ERROR_PARSING_EXTENSION:",
4488 })
4489
4490 // Test that illegal extensions in TLS 1.3 are declined by the server if
4491 // offered in ClientHello. The runner's server will fail if this occurs,
4492 // so we exercise the offering path. (EMS and Renegotiation Info are
4493 // implicit in every test.)
4494 testCases = append(testCases, testCase{
4495 testType: serverTest,
4496 name: "ChannelID-Declined-TLS13",
4497 config: Config{
4498 MaxVersion: VersionTLS13,
4499 ChannelID: channelIDKey,
4500 },
4501 flags: []string{"-enable-channel-id"},
4502 })
4503 testCases = append(testCases, testCase{
4504 testType: serverTest,
4505 name: "NPN-Server",
4506 config: Config{
4507 MaxVersion: VersionTLS13,
4508 NextProtos: []string{"bar"},
4509 },
4510 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4511 })
David Benjamine78bfde2014-09-06 12:45:15 -04004512}
4513
David Benjamin01fe8202014-09-24 15:21:44 -04004514func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004515 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004516 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4517 if sessionVers.version >= VersionTLS13 {
4518 continue
4519 }
David Benjamin01fe8202014-09-24 15:21:44 -04004520 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004521 if resumeVers.version >= VersionTLS13 {
4522 continue
4523 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004524 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4525 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4526 // TLS 1.3 only shares ciphers with TLS 1.2, so
4527 // we skip certain combinations and use a
4528 // different cipher to test with.
4529 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4530 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4531 continue
4532 }
4533 }
4534
David Benjamin8b8c0062014-11-23 02:47:52 -05004535 protocols := []protocol{tls}
4536 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4537 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004538 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004539 for _, protocol := range protocols {
4540 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4541 if protocol == dtls {
4542 suffix += "-DTLS"
4543 }
4544
David Benjaminece3de92015-03-16 18:02:20 -04004545 if sessionVers.version == resumeVers.version {
4546 testCases = append(testCases, testCase{
4547 protocol: protocol,
4548 name: "Resume-Client" + suffix,
4549 resumeSession: true,
4550 config: Config{
4551 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004552 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004553 },
David Benjaminece3de92015-03-16 18:02:20 -04004554 expectedVersion: sessionVers.version,
4555 expectedResumeVersion: resumeVers.version,
4556 })
4557 } else {
4558 testCases = append(testCases, testCase{
4559 protocol: protocol,
4560 name: "Resume-Client-Mismatch" + suffix,
4561 resumeSession: true,
4562 config: Config{
4563 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004564 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004565 },
David Benjaminece3de92015-03-16 18:02:20 -04004566 expectedVersion: sessionVers.version,
4567 resumeConfig: &Config{
4568 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004569 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004570 Bugs: ProtocolBugs{
4571 AllowSessionVersionMismatch: true,
4572 },
4573 },
4574 expectedResumeVersion: resumeVers.version,
4575 shouldFail: true,
4576 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4577 })
4578 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004579
4580 testCases = append(testCases, testCase{
4581 protocol: protocol,
4582 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004583 resumeSession: true,
4584 config: Config{
4585 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004586 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004587 },
4588 expectedVersion: sessionVers.version,
4589 resumeConfig: &Config{
4590 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004591 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004592 },
4593 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004594 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004595 expectedResumeVersion: resumeVers.version,
4596 })
4597
David Benjamin8b8c0062014-11-23 02:47:52 -05004598 testCases = append(testCases, testCase{
4599 protocol: protocol,
4600 testType: serverTest,
4601 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004602 resumeSession: true,
4603 config: Config{
4604 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004605 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004606 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004607 expectedVersion: sessionVers.version,
4608 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004609 resumeConfig: &Config{
4610 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004611 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004612 },
4613 expectedResumeVersion: resumeVers.version,
4614 })
4615 }
David Benjamin01fe8202014-09-24 15:21:44 -04004616 }
4617 }
David Benjaminece3de92015-03-16 18:02:20 -04004618
Nick Harper1fd39d82016-06-14 18:14:35 -07004619 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004620 testCases = append(testCases, testCase{
4621 name: "Resume-Client-CipherMismatch",
4622 resumeSession: true,
4623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004624 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004625 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4626 },
4627 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004628 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004629 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4630 Bugs: ProtocolBugs{
4631 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4632 },
4633 },
4634 shouldFail: true,
4635 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4636 })
David Benjamin01fe8202014-09-24 15:21:44 -04004637}
4638
Adam Langley2ae77d22014-10-28 17:29:33 -07004639func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004640 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004641 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004642 testType: serverTest,
4643 name: "Renegotiate-Server-Forbidden",
4644 config: Config{
4645 MaxVersion: VersionTLS12,
4646 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004647 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004648 shouldFail: true,
4649 expectedError: ":NO_RENEGOTIATION:",
4650 expectedLocalError: "remote error: no renegotiation",
4651 })
Adam Langley5021b222015-06-12 18:27:58 -07004652 // The server shouldn't echo the renegotiation extension unless
4653 // requested by the client.
4654 testCases = append(testCases, testCase{
4655 testType: serverTest,
4656 name: "Renegotiate-Server-NoExt",
4657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004658 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004659 Bugs: ProtocolBugs{
4660 NoRenegotiationInfo: true,
4661 RequireRenegotiationInfo: true,
4662 },
4663 },
4664 shouldFail: true,
4665 expectedLocalError: "renegotiation extension missing",
4666 })
4667 // The renegotiation SCSV should be sufficient for the server to echo
4668 // the extension.
4669 testCases = append(testCases, testCase{
4670 testType: serverTest,
4671 name: "Renegotiate-Server-NoExt-SCSV",
4672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004673 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004674 Bugs: ProtocolBugs{
4675 NoRenegotiationInfo: true,
4676 SendRenegotiationSCSV: true,
4677 RequireRenegotiationInfo: true,
4678 },
4679 },
4680 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004681 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004682 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004684 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004685 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004686 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004687 },
4688 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004689 renegotiate: 1,
4690 flags: []string{
4691 "-renegotiate-freely",
4692 "-expect-total-renegotiations", "1",
4693 },
David Benjamincdea40c2015-03-19 14:09:43 -04004694 })
4695 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004696 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004697 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004699 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004700 Bugs: ProtocolBugs{
4701 EmptyRenegotiationInfo: true,
4702 },
4703 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004704 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004705 shouldFail: true,
4706 expectedError: ":RENEGOTIATION_MISMATCH:",
4707 })
4708 testCases = append(testCases, testCase{
4709 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004710 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004712 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004713 Bugs: ProtocolBugs{
4714 BadRenegotiationInfo: true,
4715 },
4716 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004717 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004718 shouldFail: true,
4719 expectedError: ":RENEGOTIATION_MISMATCH:",
4720 })
4721 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004722 name: "Renegotiate-Client-Downgrade",
4723 renegotiate: 1,
4724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004725 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004726 Bugs: ProtocolBugs{
4727 NoRenegotiationInfoAfterInitial: true,
4728 },
4729 },
4730 flags: []string{"-renegotiate-freely"},
4731 shouldFail: true,
4732 expectedError: ":RENEGOTIATION_MISMATCH:",
4733 })
4734 testCases = append(testCases, testCase{
4735 name: "Renegotiate-Client-Upgrade",
4736 renegotiate: 1,
4737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004738 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004739 Bugs: ProtocolBugs{
4740 NoRenegotiationInfoInInitial: true,
4741 },
4742 },
4743 flags: []string{"-renegotiate-freely"},
4744 shouldFail: true,
4745 expectedError: ":RENEGOTIATION_MISMATCH:",
4746 })
4747 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004748 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004749 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004751 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004752 Bugs: ProtocolBugs{
4753 NoRenegotiationInfo: true,
4754 },
4755 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004756 flags: []string{
4757 "-renegotiate-freely",
4758 "-expect-total-renegotiations", "1",
4759 },
David Benjamincff0b902015-05-15 23:09:47 -04004760 })
4761 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004762 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004763 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004765 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004766 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4767 },
4768 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004769 flags: []string{
4770 "-renegotiate-freely",
4771 "-expect-total-renegotiations", "1",
4772 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004773 })
4774 testCases = append(testCases, testCase{
4775 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004776 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004778 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4780 },
4781 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004782 flags: []string{
4783 "-renegotiate-freely",
4784 "-expect-total-renegotiations", "1",
4785 },
David Benjaminb16346b2015-04-08 19:16:58 -04004786 })
4787 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004788 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004789 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004790 config: Config{
4791 MaxVersion: VersionTLS10,
4792 Bugs: ProtocolBugs{
4793 RequireSameRenegoClientVersion: true,
4794 },
4795 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004796 flags: []string{
4797 "-renegotiate-freely",
4798 "-expect-total-renegotiations", "1",
4799 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004800 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004801 testCases = append(testCases, testCase{
4802 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004803 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004804 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004805 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4807 NextProtos: []string{"foo"},
4808 },
4809 flags: []string{
4810 "-false-start",
4811 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004812 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004813 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004814 },
4815 shimWritesFirst: true,
4816 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004817
4818 // Client-side renegotiation controls.
4819 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004820 name: "Renegotiate-Client-Forbidden-1",
4821 config: Config{
4822 MaxVersion: VersionTLS12,
4823 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004824 renegotiate: 1,
4825 shouldFail: true,
4826 expectedError: ":NO_RENEGOTIATION:",
4827 expectedLocalError: "remote error: no renegotiation",
4828 })
4829 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004830 name: "Renegotiate-Client-Once-1",
4831 config: Config{
4832 MaxVersion: VersionTLS12,
4833 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004834 renegotiate: 1,
4835 flags: []string{
4836 "-renegotiate-once",
4837 "-expect-total-renegotiations", "1",
4838 },
4839 })
4840 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004841 name: "Renegotiate-Client-Freely-1",
4842 config: Config{
4843 MaxVersion: VersionTLS12,
4844 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004845 renegotiate: 1,
4846 flags: []string{
4847 "-renegotiate-freely",
4848 "-expect-total-renegotiations", "1",
4849 },
4850 })
4851 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004852 name: "Renegotiate-Client-Once-2",
4853 config: Config{
4854 MaxVersion: VersionTLS12,
4855 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004856 renegotiate: 2,
4857 flags: []string{"-renegotiate-once"},
4858 shouldFail: true,
4859 expectedError: ":NO_RENEGOTIATION:",
4860 expectedLocalError: "remote error: no renegotiation",
4861 })
4862 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004863 name: "Renegotiate-Client-Freely-2",
4864 config: Config{
4865 MaxVersion: VersionTLS12,
4866 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004867 renegotiate: 2,
4868 flags: []string{
4869 "-renegotiate-freely",
4870 "-expect-total-renegotiations", "2",
4871 },
4872 })
Adam Langley27a0d082015-11-03 13:34:10 -08004873 testCases = append(testCases, testCase{
4874 name: "Renegotiate-Client-NoIgnore",
4875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004876 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004877 Bugs: ProtocolBugs{
4878 SendHelloRequestBeforeEveryAppDataRecord: true,
4879 },
4880 },
4881 shouldFail: true,
4882 expectedError: ":NO_RENEGOTIATION:",
4883 })
4884 testCases = append(testCases, testCase{
4885 name: "Renegotiate-Client-Ignore",
4886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004887 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004888 Bugs: ProtocolBugs{
4889 SendHelloRequestBeforeEveryAppDataRecord: true,
4890 },
4891 },
4892 flags: []string{
4893 "-renegotiate-ignore",
4894 "-expect-total-renegotiations", "0",
4895 },
4896 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004897
David Benjamin397c8e62016-07-08 14:14:36 -07004898 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004899 testCases = append(testCases, testCase{
4900 name: "StrayHelloRequest",
4901 config: Config{
4902 MaxVersion: VersionTLS12,
4903 Bugs: ProtocolBugs{
4904 SendHelloRequestBeforeEveryHandshakeMessage: true,
4905 },
4906 },
4907 })
4908 testCases = append(testCases, testCase{
4909 name: "StrayHelloRequest-Packed",
4910 config: Config{
4911 MaxVersion: VersionTLS12,
4912 Bugs: ProtocolBugs{
4913 PackHandshakeFlight: true,
4914 SendHelloRequestBeforeEveryHandshakeMessage: true,
4915 },
4916 },
4917 })
4918
David Benjamin397c8e62016-07-08 14:14:36 -07004919 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04004920 //
4921 // TODO(davidben): This test current asserts that we ignore
4922 // HelloRequests, but we actually should hard reject them. Fix this
4923 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07004924 testCases = append(testCases, testCase{
4925 name: "Renegotiate-Client-TLS13",
4926 config: Config{
4927 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04004928 Bugs: ProtocolBugs{
4929 SendHelloRequestBeforeEveryAppDataRecord: true,
4930 },
David Benjamin397c8e62016-07-08 14:14:36 -07004931 },
David Benjamin397c8e62016-07-08 14:14:36 -07004932 flags: []string{
4933 "-renegotiate-freely",
4934 },
David Benjamin397c8e62016-07-08 14:14:36 -07004935 })
4936
4937 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4938 testCases = append(testCases, testCase{
4939 name: "StrayHelloRequest-TLS13",
4940 config: Config{
4941 MaxVersion: VersionTLS13,
4942 Bugs: ProtocolBugs{
4943 SendHelloRequestBeforeEveryHandshakeMessage: true,
4944 },
4945 },
4946 shouldFail: true,
4947 expectedError: ":UNEXPECTED_MESSAGE:",
4948 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004949}
4950
David Benjamin5e961c12014-11-07 01:48:35 -05004951func addDTLSReplayTests() {
4952 // Test that sequence number replays are detected.
4953 testCases = append(testCases, testCase{
4954 protocol: dtls,
4955 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004956 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004957 replayWrites: true,
4958 })
4959
David Benjamin8e6db492015-07-25 18:29:23 -04004960 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004961 // than the retransmit window.
4962 testCases = append(testCases, testCase{
4963 protocol: dtls,
4964 name: "DTLS-Replay-LargeGaps",
4965 config: Config{
4966 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004967 SequenceNumberMapping: func(in uint64) uint64 {
4968 return in * 127
4969 },
David Benjamin5e961c12014-11-07 01:48:35 -05004970 },
4971 },
David Benjamin8e6db492015-07-25 18:29:23 -04004972 messageCount: 200,
4973 replayWrites: true,
4974 })
4975
4976 // Test the incoming sequence number changing non-monotonically.
4977 testCases = append(testCases, testCase{
4978 protocol: dtls,
4979 name: "DTLS-Replay-NonMonotonic",
4980 config: Config{
4981 Bugs: ProtocolBugs{
4982 SequenceNumberMapping: func(in uint64) uint64 {
4983 return in ^ 31
4984 },
4985 },
4986 },
4987 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004988 replayWrites: true,
4989 })
4990}
4991
Nick Harper60edffd2016-06-21 15:19:24 -07004992var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004993 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004994 id signatureAlgorithm
4995 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004996}{
Nick Harper60edffd2016-06-21 15:19:24 -07004997 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4998 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4999 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5000 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005001 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005002 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5003 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5004 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005005 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5006 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5007 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005008 // Tests for key types prior to TLS 1.2.
5009 {"RSA", 0, testCertRSA},
5010 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005011}
5012
Nick Harper60edffd2016-06-21 15:19:24 -07005013const fakeSigAlg1 signatureAlgorithm = 0x2a01
5014const fakeSigAlg2 signatureAlgorithm = 0xff01
5015
5016func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005017 // Not all ciphers involve a signature. Advertise a list which gives all
5018 // versions a signing cipher.
5019 signingCiphers := []uint16{
5020 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5021 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5022 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5023 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5024 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5025 }
5026
David Benjaminca3d5452016-07-14 12:51:01 -04005027 var allAlgorithms []signatureAlgorithm
5028 for _, alg := range testSignatureAlgorithms {
5029 if alg.id != 0 {
5030 allAlgorithms = append(allAlgorithms, alg.id)
5031 }
5032 }
5033
Nick Harper60edffd2016-06-21 15:19:24 -07005034 // Make sure each signature algorithm works. Include some fake values in
5035 // the list and ensure they're ignored.
5036 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005037 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005038 if (ver.version < VersionTLS12) != (alg.id == 0) {
5039 continue
5040 }
5041
5042 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5043 // or remove it in C.
5044 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005045 continue
5046 }
Nick Harper60edffd2016-06-21 15:19:24 -07005047
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005048 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005049 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005050 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5051 shouldFail = true
5052 }
5053 // RSA-PSS does not exist in TLS 1.2.
5054 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5055 shouldFail = true
5056 }
5057
5058 var signError, verifyError string
5059 if shouldFail {
5060 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5061 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005062 }
David Benjamin000800a2014-11-14 01:43:59 -05005063
David Benjamin1fb125c2016-07-08 18:52:12 -07005064 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005065
David Benjamin7a41d372016-07-09 11:21:54 -07005066 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005067 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005068 config: Config{
5069 MaxVersion: ver.version,
5070 ClientAuth: RequireAnyClientCert,
5071 VerifySignatureAlgorithms: []signatureAlgorithm{
5072 fakeSigAlg1,
5073 alg.id,
5074 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005075 },
David Benjamin7a41d372016-07-09 11:21:54 -07005076 },
5077 flags: []string{
5078 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5079 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5080 "-enable-all-curves",
5081 },
5082 shouldFail: shouldFail,
5083 expectedError: signError,
5084 expectedPeerSignatureAlgorithm: alg.id,
5085 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005086
David Benjamin7a41d372016-07-09 11:21:54 -07005087 testCases = append(testCases, testCase{
5088 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005089 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005090 config: Config{
5091 MaxVersion: ver.version,
5092 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5093 SignSignatureAlgorithms: []signatureAlgorithm{
5094 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005095 },
David Benjamin7a41d372016-07-09 11:21:54 -07005096 Bugs: ProtocolBugs{
5097 SkipECDSACurveCheck: shouldFail,
5098 IgnoreSignatureVersionChecks: shouldFail,
5099 // The client won't advertise 1.3-only algorithms after
5100 // version negotiation.
5101 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005102 },
David Benjamin7a41d372016-07-09 11:21:54 -07005103 },
5104 flags: []string{
5105 "-require-any-client-certificate",
5106 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5107 "-enable-all-curves",
5108 },
5109 shouldFail: shouldFail,
5110 expectedError: verifyError,
5111 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005112
5113 testCases = append(testCases, testCase{
5114 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005115 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005116 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005117 MaxVersion: ver.version,
5118 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005119 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005120 fakeSigAlg1,
5121 alg.id,
5122 fakeSigAlg2,
5123 },
5124 },
5125 flags: []string{
5126 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5127 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5128 "-enable-all-curves",
5129 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005130 shouldFail: shouldFail,
5131 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005132 expectedPeerSignatureAlgorithm: alg.id,
5133 })
5134
5135 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005136 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005137 config: Config{
5138 MaxVersion: ver.version,
5139 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005140 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005141 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005142 alg.id,
5143 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005144 Bugs: ProtocolBugs{
5145 SkipECDSACurveCheck: shouldFail,
5146 IgnoreSignatureVersionChecks: shouldFail,
5147 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005148 },
5149 flags: []string{
5150 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5151 "-enable-all-curves",
5152 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005153 shouldFail: shouldFail,
5154 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005155 })
David Benjamin5208fd42016-07-13 21:43:25 -04005156
5157 if !shouldFail {
5158 testCases = append(testCases, testCase{
5159 testType: serverTest,
5160 name: "ClientAuth-InvalidSignature" + suffix,
5161 config: Config{
5162 MaxVersion: ver.version,
5163 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5164 SignSignatureAlgorithms: []signatureAlgorithm{
5165 alg.id,
5166 },
5167 Bugs: ProtocolBugs{
5168 InvalidSignature: true,
5169 },
5170 },
5171 flags: []string{
5172 "-require-any-client-certificate",
5173 "-enable-all-curves",
5174 },
5175 shouldFail: true,
5176 expectedError: ":BAD_SIGNATURE:",
5177 })
5178
5179 testCases = append(testCases, testCase{
5180 name: "ServerAuth-InvalidSignature" + suffix,
5181 config: Config{
5182 MaxVersion: ver.version,
5183 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5184 CipherSuites: signingCiphers,
5185 SignSignatureAlgorithms: []signatureAlgorithm{
5186 alg.id,
5187 },
5188 Bugs: ProtocolBugs{
5189 InvalidSignature: true,
5190 },
5191 },
5192 flags: []string{"-enable-all-curves"},
5193 shouldFail: true,
5194 expectedError: ":BAD_SIGNATURE:",
5195 })
5196 }
David Benjaminca3d5452016-07-14 12:51:01 -04005197
5198 if ver.version >= VersionTLS12 && !shouldFail {
5199 testCases = append(testCases, testCase{
5200 name: "ClientAuth-Sign-Negotiate" + suffix,
5201 config: Config{
5202 MaxVersion: ver.version,
5203 ClientAuth: RequireAnyClientCert,
5204 VerifySignatureAlgorithms: allAlgorithms,
5205 },
5206 flags: []string{
5207 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5208 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5209 "-enable-all-curves",
5210 "-signing-prefs", strconv.Itoa(int(alg.id)),
5211 },
5212 expectedPeerSignatureAlgorithm: alg.id,
5213 })
5214
5215 testCases = append(testCases, testCase{
5216 testType: serverTest,
5217 name: "ServerAuth-Sign-Negotiate" + suffix,
5218 config: Config{
5219 MaxVersion: ver.version,
5220 CipherSuites: signingCiphers,
5221 VerifySignatureAlgorithms: allAlgorithms,
5222 },
5223 flags: []string{
5224 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5225 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5226 "-enable-all-curves",
5227 "-signing-prefs", strconv.Itoa(int(alg.id)),
5228 },
5229 expectedPeerSignatureAlgorithm: alg.id,
5230 })
5231 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005232 }
David Benjamin000800a2014-11-14 01:43:59 -05005233 }
5234
Nick Harper60edffd2016-06-21 15:19:24 -07005235 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005236 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005237 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005238 config: Config{
5239 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005241 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005242 signatureECDSAWithP521AndSHA512,
5243 signatureRSAPKCS1WithSHA384,
5244 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005245 },
5246 },
5247 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005248 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5249 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005250 },
Nick Harper60edffd2016-06-21 15:19:24 -07005251 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005252 })
5253
5254 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005255 name: "ClientAuth-SignatureType-TLS13",
5256 config: Config{
5257 ClientAuth: RequireAnyClientCert,
5258 MaxVersion: VersionTLS13,
5259 VerifySignatureAlgorithms: []signatureAlgorithm{
5260 signatureECDSAWithP521AndSHA512,
5261 signatureRSAPKCS1WithSHA384,
5262 signatureRSAPSSWithSHA384,
5263 signatureECDSAWithSHA1,
5264 },
5265 },
5266 flags: []string{
5267 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5268 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5269 },
5270 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5271 })
5272
5273 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005274 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005275 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005276 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005277 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005278 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005279 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005280 signatureECDSAWithP521AndSHA512,
5281 signatureRSAPKCS1WithSHA384,
5282 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005283 },
5284 },
Nick Harper60edffd2016-06-21 15:19:24 -07005285 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005286 })
5287
Steven Valdez143e8b32016-07-11 13:19:03 -04005288 testCases = append(testCases, testCase{
5289 testType: serverTest,
5290 name: "ServerAuth-SignatureType-TLS13",
5291 config: Config{
5292 MaxVersion: VersionTLS13,
5293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5294 VerifySignatureAlgorithms: []signatureAlgorithm{
5295 signatureECDSAWithP521AndSHA512,
5296 signatureRSAPKCS1WithSHA384,
5297 signatureRSAPSSWithSHA384,
5298 signatureECDSAWithSHA1,
5299 },
5300 },
5301 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5302 })
5303
David Benjamina95e9f32016-07-08 16:28:04 -07005304 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005305 testCases = append(testCases, testCase{
5306 testType: serverTest,
5307 name: "Verify-ClientAuth-SignatureType",
5308 config: Config{
5309 MaxVersion: VersionTLS12,
5310 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005311 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005312 signatureRSAPKCS1WithSHA256,
5313 },
5314 Bugs: ProtocolBugs{
5315 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5316 },
5317 },
5318 flags: []string{
5319 "-require-any-client-certificate",
5320 },
5321 shouldFail: true,
5322 expectedError: ":WRONG_SIGNATURE_TYPE:",
5323 })
5324
5325 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005326 testType: serverTest,
5327 name: "Verify-ClientAuth-SignatureType-TLS13",
5328 config: Config{
5329 MaxVersion: VersionTLS13,
5330 Certificates: []Certificate{rsaCertificate},
5331 SignSignatureAlgorithms: []signatureAlgorithm{
5332 signatureRSAPSSWithSHA256,
5333 },
5334 Bugs: ProtocolBugs{
5335 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5336 },
5337 },
5338 flags: []string{
5339 "-require-any-client-certificate",
5340 },
5341 shouldFail: true,
5342 expectedError: ":WRONG_SIGNATURE_TYPE:",
5343 })
5344
5345 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005346 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005347 config: Config{
5348 MaxVersion: VersionTLS12,
5349 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005350 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005351 signatureRSAPKCS1WithSHA256,
5352 },
5353 Bugs: ProtocolBugs{
5354 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5355 },
5356 },
5357 shouldFail: true,
5358 expectedError: ":WRONG_SIGNATURE_TYPE:",
5359 })
5360
Steven Valdez143e8b32016-07-11 13:19:03 -04005361 testCases = append(testCases, testCase{
5362 name: "Verify-ServerAuth-SignatureType-TLS13",
5363 config: Config{
5364 MaxVersion: VersionTLS13,
5365 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5366 SignSignatureAlgorithms: []signatureAlgorithm{
5367 signatureRSAPSSWithSHA256,
5368 },
5369 Bugs: ProtocolBugs{
5370 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5371 },
5372 },
5373 shouldFail: true,
5374 expectedError: ":WRONG_SIGNATURE_TYPE:",
5375 })
5376
David Benjamin51dd7d62016-07-08 16:07:01 -07005377 // Test that, if the list is missing, the peer falls back to SHA-1 in
5378 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005379 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005380 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005382 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005383 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005384 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005385 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005386 },
5387 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005388 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005389 },
5390 },
5391 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005392 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5393 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005394 },
5395 })
5396
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005399 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005401 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005403 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005404 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005405 },
5406 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005407 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005408 },
5409 },
5410 })
David Benjamin72dc7832015-03-16 17:49:43 -04005411
David Benjamin51dd7d62016-07-08 16:07:01 -07005412 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005413 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005414 config: Config{
5415 MaxVersion: VersionTLS13,
5416 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005417 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005418 signatureRSAPKCS1WithSHA1,
5419 },
5420 Bugs: ProtocolBugs{
5421 NoSignatureAlgorithms: true,
5422 },
5423 },
5424 flags: []string{
5425 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5426 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5427 },
5428 shouldFail: true,
5429 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5430 })
5431
5432 testCases = append(testCases, testCase{
5433 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005434 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005435 config: Config{
5436 MaxVersion: VersionTLS13,
5437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005438 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005439 signatureRSAPKCS1WithSHA1,
5440 },
5441 Bugs: ProtocolBugs{
5442 NoSignatureAlgorithms: true,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5447 })
5448
David Benjamin72dc7832015-03-16 17:49:43 -04005449 // Test that hash preferences are enforced. BoringSSL defaults to
5450 // rejecting MD5 signatures.
5451 testCases = append(testCases, testCase{
5452 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005453 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005455 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005456 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005457 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005458 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005459 // Advertise SHA-1 so the handshake will
5460 // proceed, but the shim's preferences will be
5461 // ignored in CertificateVerify generation, so
5462 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005463 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005464 },
5465 Bugs: ProtocolBugs{
5466 IgnorePeerSignatureAlgorithmPreferences: true,
5467 },
5468 },
5469 flags: []string{"-require-any-client-certificate"},
5470 shouldFail: true,
5471 expectedError: ":WRONG_SIGNATURE_TYPE:",
5472 })
5473
5474 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005475 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005477 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005479 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005480 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005481 },
5482 Bugs: ProtocolBugs{
5483 IgnorePeerSignatureAlgorithmPreferences: true,
5484 },
5485 },
5486 shouldFail: true,
5487 expectedError: ":WRONG_SIGNATURE_TYPE:",
5488 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005489
5490 // Test that the agreed upon digest respects the client preferences and
5491 // the server digests.
5492 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005493 name: "NoCommonAlgorithms-Digests",
5494 config: Config{
5495 MaxVersion: VersionTLS12,
5496 ClientAuth: RequireAnyClientCert,
5497 VerifySignatureAlgorithms: []signatureAlgorithm{
5498 signatureRSAPKCS1WithSHA512,
5499 signatureRSAPKCS1WithSHA1,
5500 },
5501 },
5502 flags: []string{
5503 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5504 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5505 "-digest-prefs", "SHA256",
5506 },
5507 shouldFail: true,
5508 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5509 })
5510 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005511 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005513 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005514 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005515 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005516 signatureRSAPKCS1WithSHA512,
5517 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005518 },
5519 },
5520 flags: []string{
5521 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5522 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005523 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005524 },
David Benjaminca3d5452016-07-14 12:51:01 -04005525 shouldFail: true,
5526 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5527 })
5528 testCases = append(testCases, testCase{
5529 name: "NoCommonAlgorithms-TLS13",
5530 config: Config{
5531 MaxVersion: VersionTLS13,
5532 ClientAuth: RequireAnyClientCert,
5533 VerifySignatureAlgorithms: []signatureAlgorithm{
5534 signatureRSAPSSWithSHA512,
5535 signatureRSAPSSWithSHA384,
5536 },
5537 },
5538 flags: []string{
5539 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5540 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5541 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5542 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005543 shouldFail: true,
5544 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005545 })
5546 testCases = append(testCases, testCase{
5547 name: "Agree-Digest-SHA256",
5548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005549 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005550 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005551 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005552 signatureRSAPKCS1WithSHA1,
5553 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005554 },
5555 },
5556 flags: []string{
5557 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5558 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005559 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005560 },
Nick Harper60edffd2016-06-21 15:19:24 -07005561 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005562 })
5563 testCases = append(testCases, testCase{
5564 name: "Agree-Digest-SHA1",
5565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005566 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005567 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005568 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005569 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005570 },
5571 },
5572 flags: []string{
5573 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5574 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005575 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005576 },
Nick Harper60edffd2016-06-21 15:19:24 -07005577 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005578 })
5579 testCases = append(testCases, testCase{
5580 name: "Agree-Digest-Default",
5581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005582 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005583 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005584 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005585 signatureRSAPKCS1WithSHA256,
5586 signatureECDSAWithP256AndSHA256,
5587 signatureRSAPKCS1WithSHA1,
5588 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005589 },
5590 },
5591 flags: []string{
5592 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5593 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5594 },
Nick Harper60edffd2016-06-21 15:19:24 -07005595 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005596 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005597
David Benjaminca3d5452016-07-14 12:51:01 -04005598 // Test that the signing preference list may include extra algorithms
5599 // without negotiation problems.
5600 testCases = append(testCases, testCase{
5601 testType: serverTest,
5602 name: "FilterExtraAlgorithms",
5603 config: Config{
5604 MaxVersion: VersionTLS12,
5605 VerifySignatureAlgorithms: []signatureAlgorithm{
5606 signatureRSAPKCS1WithSHA256,
5607 },
5608 },
5609 flags: []string{
5610 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5611 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5612 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5613 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5614 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5615 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5616 },
5617 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5618 })
5619
David Benjamin4c3ddf72016-06-29 18:13:53 -04005620 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5621 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005622 testCases = append(testCases, testCase{
5623 name: "CheckLeafCurve",
5624 config: Config{
5625 MaxVersion: VersionTLS12,
5626 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005627 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005628 },
5629 flags: []string{"-p384-only"},
5630 shouldFail: true,
5631 expectedError: ":BAD_ECC_CERT:",
5632 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005633
5634 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5635 testCases = append(testCases, testCase{
5636 name: "CheckLeafCurve-TLS13",
5637 config: Config{
5638 MaxVersion: VersionTLS13,
5639 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5640 Certificates: []Certificate{ecdsaP256Certificate},
5641 },
5642 flags: []string{"-p384-only"},
5643 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005644
5645 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5646 testCases = append(testCases, testCase{
5647 name: "ECDSACurveMismatch-Verify-TLS12",
5648 config: Config{
5649 MaxVersion: VersionTLS12,
5650 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5651 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005652 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005653 signatureECDSAWithP384AndSHA384,
5654 },
5655 },
5656 })
5657
5658 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5659 testCases = append(testCases, testCase{
5660 name: "ECDSACurveMismatch-Verify-TLS13",
5661 config: Config{
5662 MaxVersion: VersionTLS13,
5663 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5664 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005665 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005666 signatureECDSAWithP384AndSHA384,
5667 },
5668 Bugs: ProtocolBugs{
5669 SkipECDSACurveCheck: true,
5670 },
5671 },
5672 shouldFail: true,
5673 expectedError: ":WRONG_SIGNATURE_TYPE:",
5674 })
5675
5676 // Signature algorithm selection in TLS 1.3 should take the curve into
5677 // account.
5678 testCases = append(testCases, testCase{
5679 testType: serverTest,
5680 name: "ECDSACurveMismatch-Sign-TLS13",
5681 config: Config{
5682 MaxVersion: VersionTLS13,
5683 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005684 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005685 signatureECDSAWithP384AndSHA384,
5686 signatureECDSAWithP256AndSHA256,
5687 },
5688 },
5689 flags: []string{
5690 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5691 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5692 },
5693 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5694 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005695
5696 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5697 // server does not attempt to sign in that case.
5698 testCases = append(testCases, testCase{
5699 testType: serverTest,
5700 name: "RSA-PSS-Large",
5701 config: Config{
5702 MaxVersion: VersionTLS13,
5703 VerifySignatureAlgorithms: []signatureAlgorithm{
5704 signatureRSAPSSWithSHA512,
5705 },
5706 },
5707 flags: []string{
5708 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5709 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5710 },
5711 shouldFail: true,
5712 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5713 })
David Benjamin000800a2014-11-14 01:43:59 -05005714}
5715
David Benjamin83f90402015-01-27 01:09:43 -05005716// timeouts is the retransmit schedule for BoringSSL. It doubles and
5717// caps at 60 seconds. On the 13th timeout, it gives up.
5718var timeouts = []time.Duration{
5719 1 * time.Second,
5720 2 * time.Second,
5721 4 * time.Second,
5722 8 * time.Second,
5723 16 * time.Second,
5724 32 * time.Second,
5725 60 * time.Second,
5726 60 * time.Second,
5727 60 * time.Second,
5728 60 * time.Second,
5729 60 * time.Second,
5730 60 * time.Second,
5731 60 * time.Second,
5732}
5733
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005734// shortTimeouts is an alternate set of timeouts which would occur if the
5735// initial timeout duration was set to 250ms.
5736var shortTimeouts = []time.Duration{
5737 250 * time.Millisecond,
5738 500 * time.Millisecond,
5739 1 * time.Second,
5740 2 * time.Second,
5741 4 * time.Second,
5742 8 * time.Second,
5743 16 * time.Second,
5744 32 * time.Second,
5745 60 * time.Second,
5746 60 * time.Second,
5747 60 * time.Second,
5748 60 * time.Second,
5749 60 * time.Second,
5750}
5751
David Benjamin83f90402015-01-27 01:09:43 -05005752func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005753 // These tests work by coordinating some behavior on both the shim and
5754 // the runner.
5755 //
5756 // TimeoutSchedule configures the runner to send a series of timeout
5757 // opcodes to the shim (see packetAdaptor) immediately before reading
5758 // each peer handshake flight N. The timeout opcode both simulates a
5759 // timeout in the shim and acts as a synchronization point to help the
5760 // runner bracket each handshake flight.
5761 //
5762 // We assume the shim does not read from the channel eagerly. It must
5763 // first wait until it has sent flight N and is ready to receive
5764 // handshake flight N+1. At this point, it will process the timeout
5765 // opcode. It must then immediately respond with a timeout ACK and act
5766 // as if the shim was idle for the specified amount of time.
5767 //
5768 // The runner then drops all packets received before the ACK and
5769 // continues waiting for flight N. This ordering results in one attempt
5770 // at sending flight N to be dropped. For the test to complete, the
5771 // shim must send flight N again, testing that the shim implements DTLS
5772 // retransmit on a timeout.
5773
Steven Valdez143e8b32016-07-11 13:19:03 -04005774 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005775 // likely be more epochs to cross and the final message's retransmit may
5776 // be more complex.
5777
David Benjamin585d7a42016-06-02 14:58:00 -04005778 for _, async := range []bool{true, false} {
5779 var tests []testCase
5780
5781 // Test that this is indeed the timeout schedule. Stress all
5782 // four patterns of handshake.
5783 for i := 1; i < len(timeouts); i++ {
5784 number := strconv.Itoa(i)
5785 tests = append(tests, testCase{
5786 protocol: dtls,
5787 name: "DTLS-Retransmit-Client-" + number,
5788 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005789 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005790 Bugs: ProtocolBugs{
5791 TimeoutSchedule: timeouts[:i],
5792 },
5793 },
5794 resumeSession: true,
5795 })
5796 tests = append(tests, testCase{
5797 protocol: dtls,
5798 testType: serverTest,
5799 name: "DTLS-Retransmit-Server-" + number,
5800 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005801 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005802 Bugs: ProtocolBugs{
5803 TimeoutSchedule: timeouts[:i],
5804 },
5805 },
5806 resumeSession: true,
5807 })
5808 }
5809
5810 // Test that exceeding the timeout schedule hits a read
5811 // timeout.
5812 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005813 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005814 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005816 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005817 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005818 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005819 },
5820 },
5821 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005822 shouldFail: true,
5823 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005824 })
David Benjamin585d7a42016-06-02 14:58:00 -04005825
5826 if async {
5827 // Test that timeout handling has a fudge factor, due to API
5828 // problems.
5829 tests = append(tests, testCase{
5830 protocol: dtls,
5831 name: "DTLS-Retransmit-Fudge",
5832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005833 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005834 Bugs: ProtocolBugs{
5835 TimeoutSchedule: []time.Duration{
5836 timeouts[0] - 10*time.Millisecond,
5837 },
5838 },
5839 },
5840 resumeSession: true,
5841 })
5842 }
5843
5844 // Test that the final Finished retransmitting isn't
5845 // duplicated if the peer badly fragments everything.
5846 tests = append(tests, testCase{
5847 testType: serverTest,
5848 protocol: dtls,
5849 name: "DTLS-Retransmit-Fragmented",
5850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005851 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005852 Bugs: ProtocolBugs{
5853 TimeoutSchedule: []time.Duration{timeouts[0]},
5854 MaxHandshakeRecordLength: 2,
5855 },
5856 },
5857 })
5858
5859 // Test the timeout schedule when a shorter initial timeout duration is set.
5860 tests = append(tests, testCase{
5861 protocol: dtls,
5862 name: "DTLS-Retransmit-Short-Client",
5863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005864 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005865 Bugs: ProtocolBugs{
5866 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5867 },
5868 },
5869 resumeSession: true,
5870 flags: []string{"-initial-timeout-duration-ms", "250"},
5871 })
5872 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005873 protocol: dtls,
5874 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005875 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005876 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005877 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005878 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005879 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005880 },
5881 },
5882 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005883 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005884 })
David Benjamin585d7a42016-06-02 14:58:00 -04005885
5886 for _, test := range tests {
5887 if async {
5888 test.name += "-Async"
5889 test.flags = append(test.flags, "-async")
5890 }
5891
5892 testCases = append(testCases, test)
5893 }
David Benjamin83f90402015-01-27 01:09:43 -05005894 }
David Benjamin83f90402015-01-27 01:09:43 -05005895}
5896
David Benjaminc565ebb2015-04-03 04:06:36 -04005897func addExportKeyingMaterialTests() {
5898 for _, vers := range tlsVersions {
5899 if vers.version == VersionSSL30 {
5900 continue
5901 }
5902 testCases = append(testCases, testCase{
5903 name: "ExportKeyingMaterial-" + vers.name,
5904 config: Config{
5905 MaxVersion: vers.version,
5906 },
5907 exportKeyingMaterial: 1024,
5908 exportLabel: "label",
5909 exportContext: "context",
5910 useExportContext: true,
5911 })
5912 testCases = append(testCases, testCase{
5913 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5914 config: Config{
5915 MaxVersion: vers.version,
5916 },
5917 exportKeyingMaterial: 1024,
5918 })
5919 testCases = append(testCases, testCase{
5920 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5921 config: Config{
5922 MaxVersion: vers.version,
5923 },
5924 exportKeyingMaterial: 1024,
5925 useExportContext: true,
5926 })
5927 testCases = append(testCases, testCase{
5928 name: "ExportKeyingMaterial-Small-" + vers.name,
5929 config: Config{
5930 MaxVersion: vers.version,
5931 },
5932 exportKeyingMaterial: 1,
5933 exportLabel: "label",
5934 exportContext: "context",
5935 useExportContext: true,
5936 })
5937 }
5938 testCases = append(testCases, testCase{
5939 name: "ExportKeyingMaterial-SSL3",
5940 config: Config{
5941 MaxVersion: VersionSSL30,
5942 },
5943 exportKeyingMaterial: 1024,
5944 exportLabel: "label",
5945 exportContext: "context",
5946 useExportContext: true,
5947 shouldFail: true,
5948 expectedError: "failed to export keying material",
5949 })
5950}
5951
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005952func addTLSUniqueTests() {
5953 for _, isClient := range []bool{false, true} {
5954 for _, isResumption := range []bool{false, true} {
5955 for _, hasEMS := range []bool{false, true} {
5956 var suffix string
5957 if isResumption {
5958 suffix = "Resume-"
5959 } else {
5960 suffix = "Full-"
5961 }
5962
5963 if hasEMS {
5964 suffix += "EMS-"
5965 } else {
5966 suffix += "NoEMS-"
5967 }
5968
5969 if isClient {
5970 suffix += "Client"
5971 } else {
5972 suffix += "Server"
5973 }
5974
5975 test := testCase{
5976 name: "TLSUnique-" + suffix,
5977 testTLSUnique: true,
5978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005979 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005980 Bugs: ProtocolBugs{
5981 NoExtendedMasterSecret: !hasEMS,
5982 },
5983 },
5984 }
5985
5986 if isResumption {
5987 test.resumeSession = true
5988 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005989 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005990 Bugs: ProtocolBugs{
5991 NoExtendedMasterSecret: !hasEMS,
5992 },
5993 }
5994 }
5995
5996 if isResumption && !hasEMS {
5997 test.shouldFail = true
5998 test.expectedError = "failed to get tls-unique"
5999 }
6000
6001 testCases = append(testCases, test)
6002 }
6003 }
6004 }
6005}
6006
Adam Langley09505632015-07-30 18:10:13 -07006007func addCustomExtensionTests() {
6008 expectedContents := "custom extension"
6009 emptyString := ""
6010
6011 for _, isClient := range []bool{false, true} {
6012 suffix := "Server"
6013 flag := "-enable-server-custom-extension"
6014 testType := serverTest
6015 if isClient {
6016 suffix = "Client"
6017 flag = "-enable-client-custom-extension"
6018 testType = clientTest
6019 }
6020
6021 testCases = append(testCases, testCase{
6022 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006023 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006025 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006026 Bugs: ProtocolBugs{
6027 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006028 ExpectedCustomExtension: &expectedContents,
6029 },
6030 },
6031 flags: []string{flag},
6032 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006033 testCases = append(testCases, testCase{
6034 testType: testType,
6035 name: "CustomExtensions-" + suffix + "-TLS13",
6036 config: Config{
6037 MaxVersion: VersionTLS13,
6038 Bugs: ProtocolBugs{
6039 CustomExtension: expectedContents,
6040 ExpectedCustomExtension: &expectedContents,
6041 },
6042 },
6043 flags: []string{flag},
6044 })
Adam Langley09505632015-07-30 18:10:13 -07006045
6046 // If the parse callback fails, the handshake should also fail.
6047 testCases = append(testCases, testCase{
6048 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006049 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006051 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006052 Bugs: ProtocolBugs{
6053 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006054 ExpectedCustomExtension: &expectedContents,
6055 },
6056 },
David Benjamin399e7c92015-07-30 23:01:27 -04006057 flags: []string{flag},
6058 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006059 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6060 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006061 testCases = append(testCases, testCase{
6062 testType: testType,
6063 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6064 config: Config{
6065 MaxVersion: VersionTLS13,
6066 Bugs: ProtocolBugs{
6067 CustomExtension: expectedContents + "foo",
6068 ExpectedCustomExtension: &expectedContents,
6069 },
6070 },
6071 flags: []string{flag},
6072 shouldFail: true,
6073 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6074 })
Adam Langley09505632015-07-30 18:10:13 -07006075
6076 // If the add callback fails, the handshake should also fail.
6077 testCases = append(testCases, testCase{
6078 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006079 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006081 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006082 Bugs: ProtocolBugs{
6083 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006084 ExpectedCustomExtension: &expectedContents,
6085 },
6086 },
David Benjamin399e7c92015-07-30 23:01:27 -04006087 flags: []string{flag, "-custom-extension-fail-add"},
6088 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006089 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6090 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006091 testCases = append(testCases, testCase{
6092 testType: testType,
6093 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6094 config: Config{
6095 MaxVersion: VersionTLS13,
6096 Bugs: ProtocolBugs{
6097 CustomExtension: expectedContents,
6098 ExpectedCustomExtension: &expectedContents,
6099 },
6100 },
6101 flags: []string{flag, "-custom-extension-fail-add"},
6102 shouldFail: true,
6103 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6104 })
Adam Langley09505632015-07-30 18:10:13 -07006105
6106 // If the add callback returns zero, no extension should be
6107 // added.
6108 skipCustomExtension := expectedContents
6109 if isClient {
6110 // For the case where the client skips sending the
6111 // custom extension, the server must not “echo” it.
6112 skipCustomExtension = ""
6113 }
6114 testCases = append(testCases, testCase{
6115 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006116 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006118 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006119 Bugs: ProtocolBugs{
6120 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006121 ExpectedCustomExtension: &emptyString,
6122 },
6123 },
6124 flags: []string{flag, "-custom-extension-skip"},
6125 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006126 testCases = append(testCases, testCase{
6127 testType: testType,
6128 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6129 config: Config{
6130 MaxVersion: VersionTLS13,
6131 Bugs: ProtocolBugs{
6132 CustomExtension: skipCustomExtension,
6133 ExpectedCustomExtension: &emptyString,
6134 },
6135 },
6136 flags: []string{flag, "-custom-extension-skip"},
6137 })
Adam Langley09505632015-07-30 18:10:13 -07006138 }
6139
6140 // The custom extension add callback should not be called if the client
6141 // doesn't send the extension.
6142 testCases = append(testCases, testCase{
6143 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006144 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006146 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006147 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006148 ExpectedCustomExtension: &emptyString,
6149 },
6150 },
6151 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6152 })
Adam Langley2deb9842015-08-07 11:15:37 -07006153
Steven Valdez143e8b32016-07-11 13:19:03 -04006154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "CustomExtensions-NotCalled-Server-TLS13",
6157 config: Config{
6158 MaxVersion: VersionTLS13,
6159 Bugs: ProtocolBugs{
6160 ExpectedCustomExtension: &emptyString,
6161 },
6162 },
6163 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6164 })
6165
Adam Langley2deb9842015-08-07 11:15:37 -07006166 // Test an unknown extension from the server.
6167 testCases = append(testCases, testCase{
6168 testType: clientTest,
6169 name: "UnknownExtension-Client",
6170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006172 Bugs: ProtocolBugs{
6173 CustomExtension: expectedContents,
6174 },
6175 },
6176 shouldFail: true,
6177 expectedError: ":UNEXPECTED_EXTENSION:",
6178 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006179 testCases = append(testCases, testCase{
6180 testType: clientTest,
6181 name: "UnknownExtension-Client-TLS13",
6182 config: Config{
6183 MaxVersion: VersionTLS13,
6184 Bugs: ProtocolBugs{
6185 CustomExtension: expectedContents,
6186 },
6187 },
6188 shouldFail: true,
6189 expectedError: ":UNEXPECTED_EXTENSION:",
6190 })
Adam Langley09505632015-07-30 18:10:13 -07006191}
6192
David Benjaminb36a3952015-12-01 18:53:13 -05006193func addRSAClientKeyExchangeTests() {
6194 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6195 testCases = append(testCases, testCase{
6196 testType: serverTest,
6197 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6198 config: Config{
6199 // Ensure the ClientHello version and final
6200 // version are different, to detect if the
6201 // server uses the wrong one.
6202 MaxVersion: VersionTLS11,
6203 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6204 Bugs: ProtocolBugs{
6205 BadRSAClientKeyExchange: bad,
6206 },
6207 },
6208 shouldFail: true,
6209 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6210 })
6211 }
6212}
6213
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006214var testCurves = []struct {
6215 name string
6216 id CurveID
6217}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006218 {"P-256", CurveP256},
6219 {"P-384", CurveP384},
6220 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006221 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006222}
6223
6224func addCurveTests() {
6225 for _, curve := range testCurves {
6226 testCases = append(testCases, testCase{
6227 name: "CurveTest-Client-" + curve.name,
6228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006229 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6231 CurvePreferences: []CurveID{curve.id},
6232 },
6233 flags: []string{"-enable-all-curves"},
6234 })
6235 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006236 name: "CurveTest-Client-" + curve.name + "-TLS13",
6237 config: Config{
6238 MaxVersion: VersionTLS13,
6239 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6240 CurvePreferences: []CurveID{curve.id},
6241 },
6242 flags: []string{"-enable-all-curves"},
6243 })
6244 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006245 testType: serverTest,
6246 name: "CurveTest-Server-" + curve.name,
6247 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006248 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006249 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6250 CurvePreferences: []CurveID{curve.id},
6251 },
6252 flags: []string{"-enable-all-curves"},
6253 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006254 testCases = append(testCases, testCase{
6255 testType: serverTest,
6256 name: "CurveTest-Server-" + curve.name + "-TLS13",
6257 config: Config{
6258 MaxVersion: VersionTLS13,
6259 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6260 CurvePreferences: []CurveID{curve.id},
6261 },
6262 flags: []string{"-enable-all-curves"},
6263 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006264 }
David Benjamin241ae832016-01-15 03:04:54 -05006265
6266 // The server must be tolerant to bogus curves.
6267 const bogusCurve = 0x1234
6268 testCases = append(testCases, testCase{
6269 testType: serverTest,
6270 name: "UnknownCurve",
6271 config: Config{
6272 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6273 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6274 },
6275 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006276
6277 // The server must not consider ECDHE ciphers when there are no
6278 // supported curves.
6279 testCases = append(testCases, testCase{
6280 testType: serverTest,
6281 name: "NoSupportedCurves",
6282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006283 MaxVersion: VersionTLS12,
6284 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6285 Bugs: ProtocolBugs{
6286 NoSupportedCurves: true,
6287 },
6288 },
6289 shouldFail: true,
6290 expectedError: ":NO_SHARED_CIPHER:",
6291 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006292 testCases = append(testCases, testCase{
6293 testType: serverTest,
6294 name: "NoSupportedCurves-TLS13",
6295 config: Config{
6296 MaxVersion: VersionTLS13,
6297 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6298 Bugs: ProtocolBugs{
6299 NoSupportedCurves: true,
6300 },
6301 },
6302 shouldFail: true,
6303 expectedError: ":NO_SHARED_CIPHER:",
6304 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006305
6306 // The server must fall back to another cipher when there are no
6307 // supported curves.
6308 testCases = append(testCases, testCase{
6309 testType: serverTest,
6310 name: "NoCommonCurves",
6311 config: Config{
6312 MaxVersion: VersionTLS12,
6313 CipherSuites: []uint16{
6314 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6315 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6316 },
6317 CurvePreferences: []CurveID{CurveP224},
6318 },
6319 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6320 })
6321
6322 // The client must reject bogus curves and disabled curves.
6323 testCases = append(testCases, testCase{
6324 name: "BadECDHECurve",
6325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006326 MaxVersion: VersionTLS12,
6327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6328 Bugs: ProtocolBugs{
6329 SendCurve: bogusCurve,
6330 },
6331 },
6332 shouldFail: true,
6333 expectedError: ":WRONG_CURVE:",
6334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006335 testCases = append(testCases, testCase{
6336 name: "BadECDHECurve-TLS13",
6337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6340 Bugs: ProtocolBugs{
6341 SendCurve: bogusCurve,
6342 },
6343 },
6344 shouldFail: true,
6345 expectedError: ":WRONG_CURVE:",
6346 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006347
6348 testCases = append(testCases, testCase{
6349 name: "UnsupportedCurve",
6350 config: Config{
Steven Valdez143e8b32016-07-11 13:19:03 -04006351 // TODO(davidben): Add a TLS 1.3 version of this test.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006352 MaxVersion: VersionTLS12,
6353 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6354 CurvePreferences: []CurveID{CurveP256},
6355 Bugs: ProtocolBugs{
6356 IgnorePeerCurvePreferences: true,
6357 },
6358 },
6359 flags: []string{"-p384-only"},
6360 shouldFail: true,
6361 expectedError: ":WRONG_CURVE:",
6362 })
6363
6364 // Test invalid curve points.
6365 testCases = append(testCases, testCase{
6366 name: "InvalidECDHPoint-Client",
6367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006368 MaxVersion: VersionTLS12,
6369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6370 CurvePreferences: []CurveID{CurveP256},
6371 Bugs: ProtocolBugs{
6372 InvalidECDHPoint: true,
6373 },
6374 },
6375 shouldFail: true,
6376 expectedError: ":INVALID_ENCODING:",
6377 })
6378 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006379 name: "InvalidECDHPoint-Client-TLS13",
6380 config: Config{
6381 MaxVersion: VersionTLS13,
6382 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6383 CurvePreferences: []CurveID{CurveP256},
6384 Bugs: ProtocolBugs{
6385 InvalidECDHPoint: true,
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":INVALID_ENCODING:",
6390 })
6391 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006392 testType: serverTest,
6393 name: "InvalidECDHPoint-Server",
6394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006395 MaxVersion: VersionTLS12,
6396 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6397 CurvePreferences: []CurveID{CurveP256},
6398 Bugs: ProtocolBugs{
6399 InvalidECDHPoint: true,
6400 },
6401 },
6402 shouldFail: true,
6403 expectedError: ":INVALID_ENCODING:",
6404 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006405 testCases = append(testCases, testCase{
6406 testType: serverTest,
6407 name: "InvalidECDHPoint-Server-TLS13",
6408 config: Config{
6409 MaxVersion: VersionTLS13,
6410 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6411 CurvePreferences: []CurveID{CurveP256},
6412 Bugs: ProtocolBugs{
6413 InvalidECDHPoint: true,
6414 },
6415 },
6416 shouldFail: true,
6417 expectedError: ":INVALID_ENCODING:",
6418 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006419}
6420
Matt Braithwaite54217e42016-06-13 13:03:47 -07006421func addCECPQ1Tests() {
6422 testCases = append(testCases, testCase{
6423 testType: clientTest,
6424 name: "CECPQ1-Client-BadX25519Part",
6425 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006426 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006427 MinVersion: VersionTLS12,
6428 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6429 Bugs: ProtocolBugs{
6430 CECPQ1BadX25519Part: true,
6431 },
6432 },
6433 flags: []string{"-cipher", "kCECPQ1"},
6434 shouldFail: true,
6435 expectedLocalError: "local error: bad record MAC",
6436 })
6437 testCases = append(testCases, testCase{
6438 testType: clientTest,
6439 name: "CECPQ1-Client-BadNewhopePart",
6440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006441 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006442 MinVersion: VersionTLS12,
6443 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6444 Bugs: ProtocolBugs{
6445 CECPQ1BadNewhopePart: true,
6446 },
6447 },
6448 flags: []string{"-cipher", "kCECPQ1"},
6449 shouldFail: true,
6450 expectedLocalError: "local error: bad record MAC",
6451 })
6452 testCases = append(testCases, testCase{
6453 testType: serverTest,
6454 name: "CECPQ1-Server-BadX25519Part",
6455 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006456 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006457 MinVersion: VersionTLS12,
6458 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6459 Bugs: ProtocolBugs{
6460 CECPQ1BadX25519Part: true,
6461 },
6462 },
6463 flags: []string{"-cipher", "kCECPQ1"},
6464 shouldFail: true,
6465 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6466 })
6467 testCases = append(testCases, testCase{
6468 testType: serverTest,
6469 name: "CECPQ1-Server-BadNewhopePart",
6470 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006471 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006472 MinVersion: VersionTLS12,
6473 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6474 Bugs: ProtocolBugs{
6475 CECPQ1BadNewhopePart: true,
6476 },
6477 },
6478 flags: []string{"-cipher", "kCECPQ1"},
6479 shouldFail: true,
6480 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6481 })
6482}
6483
David Benjamin4cc36ad2015-12-19 14:23:26 -05006484func addKeyExchangeInfoTests() {
6485 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006486 name: "KeyExchangeInfo-DHE-Client",
6487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006488 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006489 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6490 Bugs: ProtocolBugs{
6491 // This is a 1234-bit prime number, generated
6492 // with:
6493 // openssl gendh 1234 | openssl asn1parse -i
6494 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6495 },
6496 },
David Benjamin9e68f192016-06-30 14:55:33 -04006497 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006498 })
6499 testCases = append(testCases, testCase{
6500 testType: serverTest,
6501 name: "KeyExchangeInfo-DHE-Server",
6502 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006503 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006504 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6505 },
6506 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006507 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006508 })
6509
6510 testCases = append(testCases, testCase{
6511 name: "KeyExchangeInfo-ECDHE-Client",
6512 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006513 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006514 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6515 CurvePreferences: []CurveID{CurveX25519},
6516 },
David Benjamin9e68f192016-06-30 14:55:33 -04006517 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006518 })
6519 testCases = append(testCases, testCase{
6520 testType: serverTest,
6521 name: "KeyExchangeInfo-ECDHE-Server",
6522 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006523 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6525 CurvePreferences: []CurveID{CurveX25519},
6526 },
David Benjamin9e68f192016-06-30 14:55:33 -04006527 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006528 })
6529}
6530
David Benjaminc9ae27c2016-06-24 22:56:37 -04006531func addTLS13RecordTests() {
6532 testCases = append(testCases, testCase{
6533 name: "TLS13-RecordPadding",
6534 config: Config{
6535 MaxVersion: VersionTLS13,
6536 MinVersion: VersionTLS13,
6537 Bugs: ProtocolBugs{
6538 RecordPadding: 10,
6539 },
6540 },
6541 })
6542
6543 testCases = append(testCases, testCase{
6544 name: "TLS13-EmptyRecords",
6545 config: Config{
6546 MaxVersion: VersionTLS13,
6547 MinVersion: VersionTLS13,
6548 Bugs: ProtocolBugs{
6549 OmitRecordContents: true,
6550 },
6551 },
6552 shouldFail: true,
6553 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6554 })
6555
6556 testCases = append(testCases, testCase{
6557 name: "TLS13-OnlyPadding",
6558 config: Config{
6559 MaxVersion: VersionTLS13,
6560 MinVersion: VersionTLS13,
6561 Bugs: ProtocolBugs{
6562 OmitRecordContents: true,
6563 RecordPadding: 10,
6564 },
6565 },
6566 shouldFail: true,
6567 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6568 })
6569
6570 testCases = append(testCases, testCase{
6571 name: "TLS13-WrongOuterRecord",
6572 config: Config{
6573 MaxVersion: VersionTLS13,
6574 MinVersion: VersionTLS13,
6575 Bugs: ProtocolBugs{
6576 OuterRecordType: recordTypeHandshake,
6577 },
6578 },
6579 shouldFail: true,
6580 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6581 })
6582}
6583
David Benjamin82261be2016-07-07 14:32:50 -07006584func addChangeCipherSpecTests() {
6585 // Test missing ChangeCipherSpecs.
6586 testCases = append(testCases, testCase{
6587 name: "SkipChangeCipherSpec-Client",
6588 config: Config{
6589 MaxVersion: VersionTLS12,
6590 Bugs: ProtocolBugs{
6591 SkipChangeCipherSpec: true,
6592 },
6593 },
6594 shouldFail: true,
6595 expectedError: ":UNEXPECTED_RECORD:",
6596 })
6597 testCases = append(testCases, testCase{
6598 testType: serverTest,
6599 name: "SkipChangeCipherSpec-Server",
6600 config: Config{
6601 MaxVersion: VersionTLS12,
6602 Bugs: ProtocolBugs{
6603 SkipChangeCipherSpec: true,
6604 },
6605 },
6606 shouldFail: true,
6607 expectedError: ":UNEXPECTED_RECORD:",
6608 })
6609 testCases = append(testCases, testCase{
6610 testType: serverTest,
6611 name: "SkipChangeCipherSpec-Server-NPN",
6612 config: Config{
6613 MaxVersion: VersionTLS12,
6614 NextProtos: []string{"bar"},
6615 Bugs: ProtocolBugs{
6616 SkipChangeCipherSpec: true,
6617 },
6618 },
6619 flags: []string{
6620 "-advertise-npn", "\x03foo\x03bar\x03baz",
6621 },
6622 shouldFail: true,
6623 expectedError: ":UNEXPECTED_RECORD:",
6624 })
6625
6626 // Test synchronization between the handshake and ChangeCipherSpec.
6627 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6628 // rejected. Test both with and without handshake packing to handle both
6629 // when the partial post-CCS message is in its own record and when it is
6630 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006631 for _, packed := range []bool{false, true} {
6632 var suffix string
6633 if packed {
6634 suffix = "-Packed"
6635 }
6636
6637 testCases = append(testCases, testCase{
6638 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6639 config: Config{
6640 MaxVersion: VersionTLS12,
6641 Bugs: ProtocolBugs{
6642 FragmentAcrossChangeCipherSpec: true,
6643 PackHandshakeFlight: packed,
6644 },
6645 },
6646 shouldFail: true,
6647 expectedError: ":UNEXPECTED_RECORD:",
6648 })
6649 testCases = append(testCases, testCase{
6650 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6651 config: Config{
6652 MaxVersion: VersionTLS12,
6653 },
6654 resumeSession: true,
6655 resumeConfig: &Config{
6656 MaxVersion: VersionTLS12,
6657 Bugs: ProtocolBugs{
6658 FragmentAcrossChangeCipherSpec: true,
6659 PackHandshakeFlight: packed,
6660 },
6661 },
6662 shouldFail: true,
6663 expectedError: ":UNEXPECTED_RECORD:",
6664 })
6665 testCases = append(testCases, testCase{
6666 testType: serverTest,
6667 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6668 config: Config{
6669 MaxVersion: VersionTLS12,
6670 Bugs: ProtocolBugs{
6671 FragmentAcrossChangeCipherSpec: true,
6672 PackHandshakeFlight: packed,
6673 },
6674 },
6675 shouldFail: true,
6676 expectedError: ":UNEXPECTED_RECORD:",
6677 })
6678 testCases = append(testCases, testCase{
6679 testType: serverTest,
6680 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6681 config: Config{
6682 MaxVersion: VersionTLS12,
6683 },
6684 resumeSession: true,
6685 resumeConfig: &Config{
6686 MaxVersion: VersionTLS12,
6687 Bugs: ProtocolBugs{
6688 FragmentAcrossChangeCipherSpec: true,
6689 PackHandshakeFlight: packed,
6690 },
6691 },
6692 shouldFail: true,
6693 expectedError: ":UNEXPECTED_RECORD:",
6694 })
6695 testCases = append(testCases, testCase{
6696 testType: serverTest,
6697 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6698 config: Config{
6699 MaxVersion: VersionTLS12,
6700 NextProtos: []string{"bar"},
6701 Bugs: ProtocolBugs{
6702 FragmentAcrossChangeCipherSpec: true,
6703 PackHandshakeFlight: packed,
6704 },
6705 },
6706 flags: []string{
6707 "-advertise-npn", "\x03foo\x03bar\x03baz",
6708 },
6709 shouldFail: true,
6710 expectedError: ":UNEXPECTED_RECORD:",
6711 })
6712 }
6713
David Benjamin61672812016-07-14 23:10:43 -04006714 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6715 // messages in the handshake queue. Do this by testing the server
6716 // reading the client Finished, reversing the flight so Finished comes
6717 // first.
6718 testCases = append(testCases, testCase{
6719 protocol: dtls,
6720 testType: serverTest,
6721 name: "SendUnencryptedFinished-DTLS",
6722 config: Config{
6723 MaxVersion: VersionTLS12,
6724 Bugs: ProtocolBugs{
6725 SendUnencryptedFinished: true,
6726 ReverseHandshakeFragments: true,
6727 },
6728 },
6729 shouldFail: true,
6730 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6731 })
6732
Steven Valdez143e8b32016-07-11 13:19:03 -04006733 // Test synchronization between encryption changes and the handshake in
6734 // TLS 1.3, where ChangeCipherSpec is implicit.
6735 testCases = append(testCases, testCase{
6736 name: "PartialEncryptedExtensionsWithServerHello",
6737 config: Config{
6738 MaxVersion: VersionTLS13,
6739 Bugs: ProtocolBugs{
6740 PartialEncryptedExtensionsWithServerHello: true,
6741 },
6742 },
6743 shouldFail: true,
6744 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6745 })
6746 testCases = append(testCases, testCase{
6747 testType: serverTest,
6748 name: "PartialClientFinishedWithClientHello",
6749 config: Config{
6750 MaxVersion: VersionTLS13,
6751 Bugs: ProtocolBugs{
6752 PartialClientFinishedWithClientHello: true,
6753 },
6754 },
6755 shouldFail: true,
6756 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6757 })
6758
David Benjamin82261be2016-07-07 14:32:50 -07006759 // Test that early ChangeCipherSpecs are handled correctly.
6760 testCases = append(testCases, testCase{
6761 testType: serverTest,
6762 name: "EarlyChangeCipherSpec-server-1",
6763 config: Config{
6764 MaxVersion: VersionTLS12,
6765 Bugs: ProtocolBugs{
6766 EarlyChangeCipherSpec: 1,
6767 },
6768 },
6769 shouldFail: true,
6770 expectedError: ":UNEXPECTED_RECORD:",
6771 })
6772 testCases = append(testCases, testCase{
6773 testType: serverTest,
6774 name: "EarlyChangeCipherSpec-server-2",
6775 config: Config{
6776 MaxVersion: VersionTLS12,
6777 Bugs: ProtocolBugs{
6778 EarlyChangeCipherSpec: 2,
6779 },
6780 },
6781 shouldFail: true,
6782 expectedError: ":UNEXPECTED_RECORD:",
6783 })
6784 testCases = append(testCases, testCase{
6785 protocol: dtls,
6786 name: "StrayChangeCipherSpec",
6787 config: Config{
6788 // TODO(davidben): Once DTLS 1.3 exists, test
6789 // that stray ChangeCipherSpec messages are
6790 // rejected.
6791 MaxVersion: VersionTLS12,
6792 Bugs: ProtocolBugs{
6793 StrayChangeCipherSpec: true,
6794 },
6795 },
6796 })
6797
6798 // Test that the contents of ChangeCipherSpec are checked.
6799 testCases = append(testCases, testCase{
6800 name: "BadChangeCipherSpec-1",
6801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 Bugs: ProtocolBugs{
6804 BadChangeCipherSpec: []byte{2},
6805 },
6806 },
6807 shouldFail: true,
6808 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6809 })
6810 testCases = append(testCases, testCase{
6811 name: "BadChangeCipherSpec-2",
6812 config: Config{
6813 MaxVersion: VersionTLS12,
6814 Bugs: ProtocolBugs{
6815 BadChangeCipherSpec: []byte{1, 1},
6816 },
6817 },
6818 shouldFail: true,
6819 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6820 })
6821 testCases = append(testCases, testCase{
6822 protocol: dtls,
6823 name: "BadChangeCipherSpec-DTLS-1",
6824 config: Config{
6825 MaxVersion: VersionTLS12,
6826 Bugs: ProtocolBugs{
6827 BadChangeCipherSpec: []byte{2},
6828 },
6829 },
6830 shouldFail: true,
6831 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6832 })
6833 testCases = append(testCases, testCase{
6834 protocol: dtls,
6835 name: "BadChangeCipherSpec-DTLS-2",
6836 config: Config{
6837 MaxVersion: VersionTLS12,
6838 Bugs: ProtocolBugs{
6839 BadChangeCipherSpec: []byte{1, 1},
6840 },
6841 },
6842 shouldFail: true,
6843 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6844 })
6845}
6846
David Benjamin0b8d5da2016-07-15 00:39:56 -04006847func addWrongMessageTypeTests() {
6848 for _, protocol := range []protocol{tls, dtls} {
6849 var suffix string
6850 if protocol == dtls {
6851 suffix = "-DTLS"
6852 }
6853
6854 testCases = append(testCases, testCase{
6855 protocol: protocol,
6856 testType: serverTest,
6857 name: "WrongMessageType-ClientHello" + suffix,
6858 config: Config{
6859 MaxVersion: VersionTLS12,
6860 Bugs: ProtocolBugs{
6861 SendWrongMessageType: typeClientHello,
6862 },
6863 },
6864 shouldFail: true,
6865 expectedError: ":UNEXPECTED_MESSAGE:",
6866 expectedLocalError: "remote error: unexpected message",
6867 })
6868
6869 if protocol == dtls {
6870 testCases = append(testCases, testCase{
6871 protocol: protocol,
6872 name: "WrongMessageType-HelloVerifyRequest" + suffix,
6873 config: Config{
6874 MaxVersion: VersionTLS12,
6875 Bugs: ProtocolBugs{
6876 SendWrongMessageType: typeHelloVerifyRequest,
6877 },
6878 },
6879 shouldFail: true,
6880 expectedError: ":UNEXPECTED_MESSAGE:",
6881 expectedLocalError: "remote error: unexpected message",
6882 })
6883 }
6884
6885 testCases = append(testCases, testCase{
6886 protocol: protocol,
6887 name: "WrongMessageType-ServerHello" + suffix,
6888 config: Config{
6889 MaxVersion: VersionTLS12,
6890 Bugs: ProtocolBugs{
6891 SendWrongMessageType: typeServerHello,
6892 },
6893 },
6894 shouldFail: true,
6895 expectedError: ":UNEXPECTED_MESSAGE:",
6896 expectedLocalError: "remote error: unexpected message",
6897 })
6898
6899 testCases = append(testCases, testCase{
6900 protocol: protocol,
6901 name: "WrongMessageType-ServerCertificate" + suffix,
6902 config: Config{
6903 MaxVersion: VersionTLS12,
6904 Bugs: ProtocolBugs{
6905 SendWrongMessageType: typeCertificate,
6906 },
6907 },
6908 shouldFail: true,
6909 expectedError: ":UNEXPECTED_MESSAGE:",
6910 expectedLocalError: "remote error: unexpected message",
6911 })
6912
6913 testCases = append(testCases, testCase{
6914 protocol: protocol,
6915 name: "WrongMessageType-CertificateStatus" + suffix,
6916 config: Config{
6917 MaxVersion: VersionTLS12,
6918 Bugs: ProtocolBugs{
6919 SendWrongMessageType: typeCertificateStatus,
6920 },
6921 },
6922 flags: []string{"-enable-ocsp-stapling"},
6923 shouldFail: true,
6924 expectedError: ":UNEXPECTED_MESSAGE:",
6925 expectedLocalError: "remote error: unexpected message",
6926 })
6927
6928 testCases = append(testCases, testCase{
6929 protocol: protocol,
6930 name: "WrongMessageType-ServerKeyExchange" + suffix,
6931 config: Config{
6932 MaxVersion: VersionTLS12,
6933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6934 Bugs: ProtocolBugs{
6935 SendWrongMessageType: typeServerKeyExchange,
6936 },
6937 },
6938 shouldFail: true,
6939 expectedError: ":UNEXPECTED_MESSAGE:",
6940 expectedLocalError: "remote error: unexpected message",
6941 })
6942
6943 testCases = append(testCases, testCase{
6944 protocol: protocol,
6945 name: "WrongMessageType-CertificateRequest" + suffix,
6946 config: Config{
6947 MaxVersion: VersionTLS12,
6948 ClientAuth: RequireAnyClientCert,
6949 Bugs: ProtocolBugs{
6950 SendWrongMessageType: typeCertificateRequest,
6951 },
6952 },
6953 shouldFail: true,
6954 expectedError: ":UNEXPECTED_MESSAGE:",
6955 expectedLocalError: "remote error: unexpected message",
6956 })
6957
6958 testCases = append(testCases, testCase{
6959 protocol: protocol,
6960 name: "WrongMessageType-ServerHelloDone" + suffix,
6961 config: Config{
6962 MaxVersion: VersionTLS12,
6963 Bugs: ProtocolBugs{
6964 SendWrongMessageType: typeServerHelloDone,
6965 },
6966 },
6967 shouldFail: true,
6968 expectedError: ":UNEXPECTED_MESSAGE:",
6969 expectedLocalError: "remote error: unexpected message",
6970 })
6971
6972 testCases = append(testCases, testCase{
6973 testType: serverTest,
6974 protocol: protocol,
6975 name: "WrongMessageType-ClientCertificate" + suffix,
6976 config: Config{
6977 Certificates: []Certificate{rsaCertificate},
6978 MaxVersion: VersionTLS12,
6979 Bugs: ProtocolBugs{
6980 SendWrongMessageType: typeCertificate,
6981 },
6982 },
6983 flags: []string{"-require-any-client-certificate"},
6984 shouldFail: true,
6985 expectedError: ":UNEXPECTED_MESSAGE:",
6986 expectedLocalError: "remote error: unexpected message",
6987 })
6988
6989 testCases = append(testCases, testCase{
6990 testType: serverTest,
6991 protocol: protocol,
6992 name: "WrongMessageType-CertificateVerify" + suffix,
6993 config: Config{
6994 Certificates: []Certificate{rsaCertificate},
6995 MaxVersion: VersionTLS12,
6996 Bugs: ProtocolBugs{
6997 SendWrongMessageType: typeCertificateVerify,
6998 },
6999 },
7000 flags: []string{"-require-any-client-certificate"},
7001 shouldFail: true,
7002 expectedError: ":UNEXPECTED_MESSAGE:",
7003 expectedLocalError: "remote error: unexpected message",
7004 })
7005
7006 testCases = append(testCases, testCase{
7007 testType: serverTest,
7008 protocol: protocol,
7009 name: "WrongMessageType-ClientKeyExchange" + suffix,
7010 config: Config{
7011 MaxVersion: VersionTLS12,
7012 Bugs: ProtocolBugs{
7013 SendWrongMessageType: typeClientKeyExchange,
7014 },
7015 },
7016 shouldFail: true,
7017 expectedError: ":UNEXPECTED_MESSAGE:",
7018 expectedLocalError: "remote error: unexpected message",
7019 })
7020
7021 if protocol != dtls {
7022 testCases = append(testCases, testCase{
7023 testType: serverTest,
7024 protocol: protocol,
7025 name: "WrongMessageType-NextProtocol" + suffix,
7026 config: Config{
7027 MaxVersion: VersionTLS12,
7028 NextProtos: []string{"bar"},
7029 Bugs: ProtocolBugs{
7030 SendWrongMessageType: typeNextProtocol,
7031 },
7032 },
7033 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7034 shouldFail: true,
7035 expectedError: ":UNEXPECTED_MESSAGE:",
7036 expectedLocalError: "remote error: unexpected message",
7037 })
7038
7039 testCases = append(testCases, testCase{
7040 testType: serverTest,
7041 protocol: protocol,
7042 name: "WrongMessageType-ChannelID" + suffix,
7043 config: Config{
7044 MaxVersion: VersionTLS12,
7045 ChannelID: channelIDKey,
7046 Bugs: ProtocolBugs{
7047 SendWrongMessageType: typeChannelID,
7048 },
7049 },
7050 flags: []string{
7051 "-expect-channel-id",
7052 base64.StdEncoding.EncodeToString(channelIDBytes),
7053 },
7054 shouldFail: true,
7055 expectedError: ":UNEXPECTED_MESSAGE:",
7056 expectedLocalError: "remote error: unexpected message",
7057 })
7058 }
7059
7060 testCases = append(testCases, testCase{
7061 testType: serverTest,
7062 protocol: protocol,
7063 name: "WrongMessageType-ClientFinished" + suffix,
7064 config: Config{
7065 MaxVersion: VersionTLS12,
7066 Bugs: ProtocolBugs{
7067 SendWrongMessageType: typeFinished,
7068 },
7069 },
7070 shouldFail: true,
7071 expectedError: ":UNEXPECTED_MESSAGE:",
7072 expectedLocalError: "remote error: unexpected message",
7073 })
7074
7075 testCases = append(testCases, testCase{
7076 protocol: protocol,
7077 name: "WrongMessageType-NewSessionTicket" + suffix,
7078 config: Config{
7079 MaxVersion: VersionTLS12,
7080 Bugs: ProtocolBugs{
7081 SendWrongMessageType: typeNewSessionTicket,
7082 },
7083 },
7084 shouldFail: true,
7085 expectedError: ":UNEXPECTED_MESSAGE:",
7086 expectedLocalError: "remote error: unexpected message",
7087 })
7088
7089 testCases = append(testCases, testCase{
7090 protocol: protocol,
7091 name: "WrongMessageType-ServerFinished" + suffix,
7092 config: Config{
7093 MaxVersion: VersionTLS12,
7094 Bugs: ProtocolBugs{
7095 SendWrongMessageType: typeFinished,
7096 },
7097 },
7098 shouldFail: true,
7099 expectedError: ":UNEXPECTED_MESSAGE:",
7100 expectedLocalError: "remote error: unexpected message",
7101 })
7102
7103 }
7104}
7105
Steven Valdez143e8b32016-07-11 13:19:03 -04007106func addTLS13WrongMessageTypeTests() {
7107 testCases = append(testCases, testCase{
7108 testType: serverTest,
7109 name: "WrongMessageType-TLS13-ClientHello",
7110 config: Config{
7111 MaxVersion: VersionTLS13,
7112 Bugs: ProtocolBugs{
7113 SendWrongMessageType: typeClientHello,
7114 },
7115 },
7116 shouldFail: true,
7117 expectedError: ":UNEXPECTED_MESSAGE:",
7118 expectedLocalError: "remote error: unexpected message",
7119 })
7120
7121 testCases = append(testCases, testCase{
7122 name: "WrongMessageType-TLS13-ServerHello",
7123 config: Config{
7124 MaxVersion: VersionTLS13,
7125 Bugs: ProtocolBugs{
7126 SendWrongMessageType: typeServerHello,
7127 },
7128 },
7129 shouldFail: true,
7130 expectedError: ":UNEXPECTED_MESSAGE:",
7131 // The alert comes in with the wrong encryption.
7132 expectedLocalError: "local error: bad record MAC",
7133 })
7134
7135 testCases = append(testCases, testCase{
7136 name: "WrongMessageType-TLS13-EncryptedExtensions",
7137 config: Config{
7138 MaxVersion: VersionTLS13,
7139 Bugs: ProtocolBugs{
7140 SendWrongMessageType: typeEncryptedExtensions,
7141 },
7142 },
7143 shouldFail: true,
7144 expectedError: ":UNEXPECTED_MESSAGE:",
7145 expectedLocalError: "remote error: unexpected message",
7146 })
7147
7148 testCases = append(testCases, testCase{
7149 name: "WrongMessageType-TLS13-CertificateRequest",
7150 config: Config{
7151 MaxVersion: VersionTLS13,
7152 ClientAuth: RequireAnyClientCert,
7153 Bugs: ProtocolBugs{
7154 SendWrongMessageType: typeCertificateRequest,
7155 },
7156 },
7157 shouldFail: true,
7158 expectedError: ":UNEXPECTED_MESSAGE:",
7159 expectedLocalError: "remote error: unexpected message",
7160 })
7161
7162 testCases = append(testCases, testCase{
7163 name: "WrongMessageType-TLS13-ServerCertificate",
7164 config: Config{
7165 MaxVersion: VersionTLS13,
7166 Bugs: ProtocolBugs{
7167 SendWrongMessageType: typeCertificate,
7168 },
7169 },
7170 shouldFail: true,
7171 expectedError: ":UNEXPECTED_MESSAGE:",
7172 expectedLocalError: "remote error: unexpected message",
7173 })
7174
7175 testCases = append(testCases, testCase{
7176 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7177 config: Config{
7178 MaxVersion: VersionTLS13,
7179 Bugs: ProtocolBugs{
7180 SendWrongMessageType: typeCertificateVerify,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_MESSAGE:",
7185 expectedLocalError: "remote error: unexpected message",
7186 })
7187
7188 testCases = append(testCases, testCase{
7189 name: "WrongMessageType-TLS13-ServerFinished",
7190 config: Config{
7191 MaxVersion: VersionTLS13,
7192 Bugs: ProtocolBugs{
7193 SendWrongMessageType: typeFinished,
7194 },
7195 },
7196 shouldFail: true,
7197 expectedError: ":UNEXPECTED_MESSAGE:",
7198 expectedLocalError: "remote error: unexpected message",
7199 })
7200
7201 testCases = append(testCases, testCase{
7202 testType: serverTest,
7203 name: "WrongMessageType-TLS13-ClientCertificate",
7204 config: Config{
7205 Certificates: []Certificate{rsaCertificate},
7206 MaxVersion: VersionTLS13,
7207 Bugs: ProtocolBugs{
7208 SendWrongMessageType: typeCertificate,
7209 },
7210 },
7211 flags: []string{"-require-any-client-certificate"},
7212 shouldFail: true,
7213 expectedError: ":UNEXPECTED_MESSAGE:",
7214 expectedLocalError: "remote error: unexpected message",
7215 })
7216
7217 testCases = append(testCases, testCase{
7218 testType: serverTest,
7219 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7220 config: Config{
7221 Certificates: []Certificate{rsaCertificate},
7222 MaxVersion: VersionTLS13,
7223 Bugs: ProtocolBugs{
7224 SendWrongMessageType: typeCertificateVerify,
7225 },
7226 },
7227 flags: []string{"-require-any-client-certificate"},
7228 shouldFail: true,
7229 expectedError: ":UNEXPECTED_MESSAGE:",
7230 expectedLocalError: "remote error: unexpected message",
7231 })
7232
7233 testCases = append(testCases, testCase{
7234 testType: serverTest,
7235 name: "WrongMessageType-TLS13-ClientFinished",
7236 config: Config{
7237 MaxVersion: VersionTLS13,
7238 Bugs: ProtocolBugs{
7239 SendWrongMessageType: typeFinished,
7240 },
7241 },
7242 shouldFail: true,
7243 expectedError: ":UNEXPECTED_MESSAGE:",
7244 expectedLocalError: "remote error: unexpected message",
7245 })
7246}
7247
7248func addTLS13HandshakeTests() {
7249 testCases = append(testCases, testCase{
7250 testType: clientTest,
7251 name: "MissingKeyShare-Client",
7252 config: Config{
7253 MaxVersion: VersionTLS13,
7254 Bugs: ProtocolBugs{
7255 MissingKeyShare: true,
7256 },
7257 },
7258 shouldFail: true,
7259 expectedError: ":MISSING_KEY_SHARE:",
7260 })
7261
7262 testCases = append(testCases, testCase{
7263 name: "MissingKeyShare-Server",
7264 config: Config{
7265 MaxVersion: VersionTLS13,
7266 Bugs: ProtocolBugs{
7267 MissingKeyShare: true,
7268 },
7269 },
7270 shouldFail: true,
7271 expectedError: ":MISSING_KEY_SHARE:",
7272 })
7273
7274 testCases = append(testCases, testCase{
7275 testType: clientTest,
7276 name: "ClientHelloMissingKeyShare",
7277 config: Config{
7278 MaxVersion: VersionTLS13,
7279 Bugs: ProtocolBugs{
7280 MissingKeyShare: true,
7281 },
7282 },
7283 shouldFail: true,
7284 expectedError: ":MISSING_KEY_SHARE:",
7285 })
7286
7287 testCases = append(testCases, testCase{
7288 testType: clientTest,
7289 name: "MissingKeyShare",
7290 config: Config{
7291 MaxVersion: VersionTLS13,
7292 Bugs: ProtocolBugs{
7293 MissingKeyShare: true,
7294 },
7295 },
7296 shouldFail: true,
7297 expectedError: ":MISSING_KEY_SHARE:",
7298 })
7299
7300 testCases = append(testCases, testCase{
7301 testType: serverTest,
7302 name: "DuplicateKeyShares",
7303 config: Config{
7304 MaxVersion: VersionTLS13,
7305 Bugs: ProtocolBugs{
7306 DuplicateKeyShares: true,
7307 },
7308 },
7309 })
7310
7311 testCases = append(testCases, testCase{
7312 testType: clientTest,
7313 name: "EmptyEncryptedExtensions",
7314 config: Config{
7315 MaxVersion: VersionTLS13,
7316 Bugs: ProtocolBugs{
7317 EmptyEncryptedExtensions: true,
7318 },
7319 },
7320 shouldFail: true,
7321 expectedLocalError: "remote error: error decoding message",
7322 })
7323
7324 testCases = append(testCases, testCase{
7325 testType: clientTest,
7326 name: "EncryptedExtensionsWithKeyShare",
7327 config: Config{
7328 MaxVersion: VersionTLS13,
7329 Bugs: ProtocolBugs{
7330 EncryptedExtensionsWithKeyShare: true,
7331 },
7332 },
7333 shouldFail: true,
7334 expectedLocalError: "remote error: unsupported extension",
7335 })
7336}
7337
Adam Langley7c803a62015-06-15 15:35:05 -07007338func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007339 defer wg.Done()
7340
7341 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007342 var err error
7343
7344 if *mallocTest < 0 {
7345 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007346 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007347 } else {
7348 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7349 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007350 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007351 if err != nil {
7352 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7353 }
7354 break
7355 }
7356 }
7357 }
Adam Langley95c29f32014-06-20 12:00:00 -07007358 statusChan <- statusMsg{test: test, err: err}
7359 }
7360}
7361
7362type statusMsg struct {
7363 test *testCase
7364 started bool
7365 err error
7366}
7367
David Benjamin5f237bc2015-02-11 17:14:15 -05007368func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07007369 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007370
David Benjamin5f237bc2015-02-11 17:14:15 -05007371 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007372 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007373 if !*pipe {
7374 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007375 var erase string
7376 for i := 0; i < lineLen; i++ {
7377 erase += "\b \b"
7378 }
7379 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007380 }
7381
Adam Langley95c29f32014-06-20 12:00:00 -07007382 if msg.started {
7383 started++
7384 } else {
7385 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007386
7387 if msg.err != nil {
7388 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7389 failed++
7390 testOutput.addResult(msg.test.name, "FAIL")
7391 } else {
7392 if *pipe {
7393 // Print each test instead of a status line.
7394 fmt.Printf("PASSED (%s)\n", msg.test.name)
7395 }
7396 testOutput.addResult(msg.test.name, "PASS")
7397 }
Adam Langley95c29f32014-06-20 12:00:00 -07007398 }
7399
David Benjamin5f237bc2015-02-11 17:14:15 -05007400 if !*pipe {
7401 // Print a new status line.
7402 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
7403 lineLen = len(line)
7404 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007405 }
Adam Langley95c29f32014-06-20 12:00:00 -07007406 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007407
7408 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007409}
7410
7411func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007412 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007413 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007414 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007415
Adam Langley7c803a62015-06-15 15:35:05 -07007416 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007417 addCipherSuiteTests()
7418 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007419 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007420 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007421 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007422 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007423 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007424 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007425 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007426 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007427 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007428 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007429 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007430 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007431 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007432 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007433 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007434 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007435 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007436 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007437 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007438 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007439 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007440 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007441 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007442 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007443 addTLS13WrongMessageTypeTests()
7444 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007445
7446 var wg sync.WaitGroup
7447
Adam Langley7c803a62015-06-15 15:35:05 -07007448 statusChan := make(chan statusMsg, *numWorkers)
7449 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007450 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007451
David Benjamin025b3d32014-07-01 19:53:04 -04007452 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007453
Adam Langley7c803a62015-06-15 15:35:05 -07007454 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007455 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007456 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007457 }
7458
David Benjamin270f0a72016-03-17 14:41:36 -04007459 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007460 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07007461 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04007462 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007463 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007464 }
7465 }
David Benjamin270f0a72016-03-17 14:41:36 -04007466 if !foundTest {
7467 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
7468 os.Exit(1)
7469 }
Adam Langley95c29f32014-06-20 12:00:00 -07007470
7471 close(testChan)
7472 wg.Wait()
7473 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007474 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007475
7476 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007477
7478 if *jsonOutput != "" {
7479 if err := testOutput.writeTo(*jsonOutput); err != nil {
7480 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7481 }
7482 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007483
7484 if !testOutput.allPassed {
7485 os.Exit(1)
7486 }
Adam Langley95c29f32014-06-20 12:00:00 -07007487}