blob: 5a3256ca8982b5df711a40cc5b4d9078591147cb [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},
Nick Harper1fd39d82016-06-14 18:14:35 -0700944 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
945 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700946}
947
948var testCipherSuites = []struct {
949 name string
950 id uint16
951}{
952 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400953 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700954 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400955 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400956 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700957 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400958 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400959 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
960 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400961 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400962 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
963 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400964 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700965 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
966 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400967 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
968 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700969 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400970 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500971 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500972 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700974 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700975 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400976 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400977 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700978 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400979 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500980 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500981 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700982 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700983 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
984 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
985 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
986 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400987 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
988 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700989 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
990 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500991 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400992 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
993 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400994 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700995 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400996 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700997 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700998}
999
David Benjamin8b8c0062014-11-23 02:47:52 -05001000func hasComponent(suiteName, component string) bool {
1001 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1002}
1003
David Benjaminf7768e42014-08-31 02:06:47 -04001004func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001005 return hasComponent(suiteName, "GCM") ||
1006 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001007 hasComponent(suiteName, "SHA384") ||
1008 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001009}
1010
Nick Harper1fd39d82016-06-14 18:14:35 -07001011func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001012 // Only AEADs.
1013 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1014 return false
1015 }
1016 // No old CHACHA20_POLY1305.
1017 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1018 return false
1019 }
1020 // Must have ECDHE.
1021 // TODO(davidben,svaldez): Add pure PSK support.
1022 if !hasComponent(suiteName, "ECDHE") {
1023 return false
1024 }
1025 // TODO(davidben,svaldez): Add PSK support.
1026 if hasComponent(suiteName, "PSK") {
1027 return false
1028 }
1029 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001030}
1031
David Benjamin8b8c0062014-11-23 02:47:52 -05001032func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001033 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001034}
1035
Adam Langleya7997f12015-05-14 17:38:50 -07001036func bigFromHex(hex string) *big.Int {
1037 ret, ok := new(big.Int).SetString(hex, 16)
1038 if !ok {
1039 panic("failed to parse hex number 0x" + hex)
1040 }
1041 return ret
1042}
1043
Adam Langley7c803a62015-06-15 15:35:05 -07001044func addBasicTests() {
1045 basicTests := []testCase{
1046 {
Adam Langley7c803a62015-06-15 15:35:05 -07001047 name: "NoFallbackSCSV",
1048 config: Config{
1049 Bugs: ProtocolBugs{
1050 FailIfNotFallbackSCSV: true,
1051 },
1052 },
1053 shouldFail: true,
1054 expectedLocalError: "no fallback SCSV found",
1055 },
1056 {
1057 name: "SendFallbackSCSV",
1058 config: Config{
1059 Bugs: ProtocolBugs{
1060 FailIfNotFallbackSCSV: true,
1061 },
1062 },
1063 flags: []string{"-fallback-scsv"},
1064 },
1065 {
1066 name: "ClientCertificateTypes",
1067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001068 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001069 ClientAuth: RequestClientCert,
1070 ClientCertificateTypes: []byte{
1071 CertTypeDSSSign,
1072 CertTypeRSASign,
1073 CertTypeECDSASign,
1074 },
1075 },
1076 flags: []string{
1077 "-expect-certificate-types",
1078 base64.StdEncoding.EncodeToString([]byte{
1079 CertTypeDSSSign,
1080 CertTypeRSASign,
1081 CertTypeECDSASign,
1082 }),
1083 },
1084 },
1085 {
Adam Langley7c803a62015-06-15 15:35:05 -07001086 name: "UnauthenticatedECDH",
1087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001088 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001089 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1090 Bugs: ProtocolBugs{
1091 UnauthenticatedECDH: true,
1092 },
1093 },
1094 shouldFail: true,
1095 expectedError: ":UNEXPECTED_MESSAGE:",
1096 },
1097 {
1098 name: "SkipCertificateStatus",
1099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001100 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1102 Bugs: ProtocolBugs{
1103 SkipCertificateStatus: true,
1104 },
1105 },
1106 flags: []string{
1107 "-enable-ocsp-stapling",
1108 },
1109 },
1110 {
1111 name: "SkipServerKeyExchange",
1112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001113 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1115 Bugs: ProtocolBugs{
1116 SkipServerKeyExchange: true,
1117 },
1118 },
1119 shouldFail: true,
1120 expectedError: ":UNEXPECTED_MESSAGE:",
1121 },
1122 {
Adam Langley7c803a62015-06-15 15:35:05 -07001123 testType: serverTest,
1124 name: "Alert",
1125 config: Config{
1126 Bugs: ProtocolBugs{
1127 SendSpuriousAlert: alertRecordOverflow,
1128 },
1129 },
1130 shouldFail: true,
1131 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1132 },
1133 {
1134 protocol: dtls,
1135 testType: serverTest,
1136 name: "Alert-DTLS",
1137 config: Config{
1138 Bugs: ProtocolBugs{
1139 SendSpuriousAlert: alertRecordOverflow,
1140 },
1141 },
1142 shouldFail: true,
1143 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1144 },
1145 {
1146 testType: serverTest,
1147 name: "FragmentAlert",
1148 config: Config{
1149 Bugs: ProtocolBugs{
1150 FragmentAlert: true,
1151 SendSpuriousAlert: alertRecordOverflow,
1152 },
1153 },
1154 shouldFail: true,
1155 expectedError: ":BAD_ALERT:",
1156 },
1157 {
1158 protocol: dtls,
1159 testType: serverTest,
1160 name: "FragmentAlert-DTLS",
1161 config: Config{
1162 Bugs: ProtocolBugs{
1163 FragmentAlert: true,
1164 SendSpuriousAlert: alertRecordOverflow,
1165 },
1166 },
1167 shouldFail: true,
1168 expectedError: ":BAD_ALERT:",
1169 },
1170 {
1171 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001172 name: "DoubleAlert",
1173 config: Config{
1174 Bugs: ProtocolBugs{
1175 DoubleAlert: true,
1176 SendSpuriousAlert: alertRecordOverflow,
1177 },
1178 },
1179 shouldFail: true,
1180 expectedError: ":BAD_ALERT:",
1181 },
1182 {
1183 protocol: dtls,
1184 testType: serverTest,
1185 name: "DoubleAlert-DTLS",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 DoubleAlert: true,
1189 SendSpuriousAlert: alertRecordOverflow,
1190 },
1191 },
1192 shouldFail: true,
1193 expectedError: ":BAD_ALERT:",
1194 },
1195 {
Adam Langley7c803a62015-06-15 15:35:05 -07001196 name: "SkipNewSessionTicket",
1197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001198 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001199 Bugs: ProtocolBugs{
1200 SkipNewSessionTicket: true,
1201 },
1202 },
1203 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001204 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001205 },
1206 {
1207 testType: serverTest,
1208 name: "FallbackSCSV",
1209 config: Config{
1210 MaxVersion: VersionTLS11,
1211 Bugs: ProtocolBugs{
1212 SendFallbackSCSV: true,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":INAPPROPRIATE_FALLBACK:",
1217 },
1218 {
1219 testType: serverTest,
1220 name: "FallbackSCSV-VersionMatch",
1221 config: Config{
1222 Bugs: ProtocolBugs{
1223 SendFallbackSCSV: true,
1224 },
1225 },
1226 },
1227 {
1228 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001229 name: "FallbackSCSV-VersionMatch-TLS12",
1230 config: Config{
1231 MaxVersion: VersionTLS12,
1232 Bugs: ProtocolBugs{
1233 SendFallbackSCSV: true,
1234 },
1235 },
1236 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1237 },
1238 {
1239 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001240 name: "FragmentedClientVersion",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 MaxHandshakeRecordLength: 1,
1244 FragmentClientVersion: true,
1245 },
1246 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001247 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001248 },
1249 {
Adam Langley7c803a62015-06-15 15:35:05 -07001250 testType: serverTest,
1251 name: "HttpGET",
1252 sendPrefix: "GET / HTTP/1.0\n",
1253 shouldFail: true,
1254 expectedError: ":HTTP_REQUEST:",
1255 },
1256 {
1257 testType: serverTest,
1258 name: "HttpPOST",
1259 sendPrefix: "POST / HTTP/1.0\n",
1260 shouldFail: true,
1261 expectedError: ":HTTP_REQUEST:",
1262 },
1263 {
1264 testType: serverTest,
1265 name: "HttpHEAD",
1266 sendPrefix: "HEAD / HTTP/1.0\n",
1267 shouldFail: true,
1268 expectedError: ":HTTP_REQUEST:",
1269 },
1270 {
1271 testType: serverTest,
1272 name: "HttpPUT",
1273 sendPrefix: "PUT / HTTP/1.0\n",
1274 shouldFail: true,
1275 expectedError: ":HTTP_REQUEST:",
1276 },
1277 {
1278 testType: serverTest,
1279 name: "HttpCONNECT",
1280 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1281 shouldFail: true,
1282 expectedError: ":HTTPS_PROXY_REQUEST:",
1283 },
1284 {
1285 testType: serverTest,
1286 name: "Garbage",
1287 sendPrefix: "blah",
1288 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001289 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001290 },
1291 {
Adam Langley7c803a62015-06-15 15:35:05 -07001292 name: "RSAEphemeralKey",
1293 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001294 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001295 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1296 Bugs: ProtocolBugs{
1297 RSAEphemeralKey: true,
1298 },
1299 },
1300 shouldFail: true,
1301 expectedError: ":UNEXPECTED_MESSAGE:",
1302 },
1303 {
1304 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001305 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001306 shouldFail: true,
1307 expectedError: ":WRONG_SSL_VERSION:",
1308 },
1309 {
1310 protocol: dtls,
1311 name: "DisableEverything-DTLS",
1312 flags: []string{"-no-tls12", "-no-tls1"},
1313 shouldFail: true,
1314 expectedError: ":WRONG_SSL_VERSION:",
1315 },
1316 {
Adam Langley7c803a62015-06-15 15:35:05 -07001317 protocol: dtls,
1318 testType: serverTest,
1319 name: "MTU",
1320 config: Config{
1321 Bugs: ProtocolBugs{
1322 MaxPacketLength: 256,
1323 },
1324 },
1325 flags: []string{"-mtu", "256"},
1326 },
1327 {
1328 protocol: dtls,
1329 testType: serverTest,
1330 name: "MTUExceeded",
1331 config: Config{
1332 Bugs: ProtocolBugs{
1333 MaxPacketLength: 255,
1334 },
1335 },
1336 flags: []string{"-mtu", "256"},
1337 shouldFail: true,
1338 expectedLocalError: "dtls: exceeded maximum packet length",
1339 },
1340 {
1341 name: "CertMismatchRSA",
1342 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001343 // TODO(davidben): Add a TLS 1.3 version of this test.
1344 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001345 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001346 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001347 Bugs: ProtocolBugs{
1348 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1349 },
1350 },
1351 shouldFail: true,
1352 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1353 },
1354 {
1355 name: "CertMismatchECDSA",
1356 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001357 // TODO(davidben): Add a TLS 1.3 version of this test.
1358 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001359 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001360 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001361 Bugs: ProtocolBugs{
1362 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1363 },
1364 },
1365 shouldFail: true,
1366 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1367 },
1368 {
1369 name: "EmptyCertificateList",
1370 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001371 // TODO(davidben): Add a TLS 1.3 version of this test.
1372 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1374 Bugs: ProtocolBugs{
1375 EmptyCertificateList: true,
1376 },
1377 },
1378 shouldFail: true,
1379 expectedError: ":DECODE_ERROR:",
1380 },
1381 {
1382 name: "TLSFatalBadPackets",
1383 damageFirstWrite: true,
1384 shouldFail: true,
1385 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1386 },
1387 {
1388 protocol: dtls,
1389 name: "DTLSIgnoreBadPackets",
1390 damageFirstWrite: true,
1391 },
1392 {
1393 protocol: dtls,
1394 name: "DTLSIgnoreBadPackets-Async",
1395 damageFirstWrite: true,
1396 flags: []string{"-async"},
1397 },
1398 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001399 name: "AppDataBeforeHandshake",
1400 config: Config{
1401 Bugs: ProtocolBugs{
1402 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":UNEXPECTED_RECORD:",
1407 },
1408 {
1409 name: "AppDataBeforeHandshake-Empty",
1410 config: Config{
1411 Bugs: ProtocolBugs{
1412 AppDataBeforeHandshake: []byte{},
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":UNEXPECTED_RECORD:",
1417 },
1418 {
1419 protocol: dtls,
1420 name: "AppDataBeforeHandshake-DTLS",
1421 config: Config{
1422 Bugs: ProtocolBugs{
1423 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1424 },
1425 },
1426 shouldFail: true,
1427 expectedError: ":UNEXPECTED_RECORD:",
1428 },
1429 {
1430 protocol: dtls,
1431 name: "AppDataBeforeHandshake-DTLS-Empty",
1432 config: Config{
1433 Bugs: ProtocolBugs{
1434 AppDataBeforeHandshake: []byte{},
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_RECORD:",
1439 },
1440 {
Adam Langley7c803a62015-06-15 15:35:05 -07001441 name: "AppDataAfterChangeCipherSpec",
1442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001443 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 Bugs: ProtocolBugs{
1445 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1446 },
1447 },
1448 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001449 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001450 },
1451 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001452 name: "AppDataAfterChangeCipherSpec-Empty",
1453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001454 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001455 Bugs: ProtocolBugs{
1456 AppDataAfterChangeCipherSpec: []byte{},
1457 },
1458 },
1459 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001460 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001461 },
1462 {
Adam Langley7c803a62015-06-15 15:35:05 -07001463 protocol: dtls,
1464 name: "AppDataAfterChangeCipherSpec-DTLS",
1465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001466 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001467 Bugs: ProtocolBugs{
1468 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1469 },
1470 },
1471 // BoringSSL's DTLS implementation will drop the out-of-order
1472 // application data.
1473 },
1474 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001475 protocol: dtls,
1476 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001478 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001479 Bugs: ProtocolBugs{
1480 AppDataAfterChangeCipherSpec: []byte{},
1481 },
1482 },
1483 // BoringSSL's DTLS implementation will drop the out-of-order
1484 // application data.
1485 },
1486 {
Adam Langley7c803a62015-06-15 15:35:05 -07001487 name: "AlertAfterChangeCipherSpec",
1488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001489 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001490 Bugs: ProtocolBugs{
1491 AlertAfterChangeCipherSpec: alertRecordOverflow,
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1496 },
1497 {
1498 protocol: dtls,
1499 name: "AlertAfterChangeCipherSpec-DTLS",
1500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001501 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001502 Bugs: ProtocolBugs{
1503 AlertAfterChangeCipherSpec: alertRecordOverflow,
1504 },
1505 },
1506 shouldFail: true,
1507 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1508 },
1509 {
1510 protocol: dtls,
1511 name: "ReorderHandshakeFragments-Small-DTLS",
1512 config: Config{
1513 Bugs: ProtocolBugs{
1514 ReorderHandshakeFragments: true,
1515 // Small enough that every handshake message is
1516 // fragmented.
1517 MaxHandshakeRecordLength: 2,
1518 },
1519 },
1520 },
1521 {
1522 protocol: dtls,
1523 name: "ReorderHandshakeFragments-Large-DTLS",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 ReorderHandshakeFragments: true,
1527 // Large enough that no handshake message is
1528 // fragmented.
1529 MaxHandshakeRecordLength: 2048,
1530 },
1531 },
1532 },
1533 {
1534 protocol: dtls,
1535 name: "MixCompleteMessageWithFragments-DTLS",
1536 config: Config{
1537 Bugs: ProtocolBugs{
1538 ReorderHandshakeFragments: true,
1539 MixCompleteMessageWithFragments: true,
1540 MaxHandshakeRecordLength: 2,
1541 },
1542 },
1543 },
1544 {
1545 name: "SendInvalidRecordType",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 SendInvalidRecordType: true,
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: ":UNEXPECTED_RECORD:",
1553 },
1554 {
1555 protocol: dtls,
1556 name: "SendInvalidRecordType-DTLS",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 SendInvalidRecordType: true,
1560 },
1561 },
1562 shouldFail: true,
1563 expectedError: ":UNEXPECTED_RECORD:",
1564 },
1565 {
1566 name: "FalseStart-SkipServerSecondLeg",
1567 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001568 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001569 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1570 NextProtos: []string{"foo"},
1571 Bugs: ProtocolBugs{
1572 SkipNewSessionTicket: true,
1573 SkipChangeCipherSpec: true,
1574 SkipFinished: true,
1575 ExpectFalseStart: true,
1576 },
1577 },
1578 flags: []string{
1579 "-false-start",
1580 "-handshake-never-done",
1581 "-advertise-alpn", "\x03foo",
1582 },
1583 shimWritesFirst: true,
1584 shouldFail: true,
1585 expectedError: ":UNEXPECTED_RECORD:",
1586 },
1587 {
1588 name: "FalseStart-SkipServerSecondLeg-Implicit",
1589 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001590 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001591 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1592 NextProtos: []string{"foo"},
1593 Bugs: ProtocolBugs{
1594 SkipNewSessionTicket: true,
1595 SkipChangeCipherSpec: true,
1596 SkipFinished: true,
1597 },
1598 },
1599 flags: []string{
1600 "-implicit-handshake",
1601 "-false-start",
1602 "-handshake-never-done",
1603 "-advertise-alpn", "\x03foo",
1604 },
1605 shouldFail: true,
1606 expectedError: ":UNEXPECTED_RECORD:",
1607 },
1608 {
1609 testType: serverTest,
1610 name: "FailEarlyCallback",
1611 flags: []string{"-fail-early-callback"},
1612 shouldFail: true,
1613 expectedError: ":CONNECTION_REJECTED:",
1614 expectedLocalError: "remote error: access denied",
1615 },
1616 {
1617 name: "WrongMessageType",
1618 config: Config{
David Benjamin1edae6b2016-07-13 16:58:23 -04001619 MaxVersion: VersionTLS12,
1620 Bugs: ProtocolBugs{
1621 WrongCertificateMessageType: true,
1622 },
1623 },
1624 shouldFail: true,
1625 expectedError: ":UNEXPECTED_MESSAGE:",
1626 expectedLocalError: "remote error: unexpected message",
1627 },
1628 {
1629 name: "WrongMessageType-TLS13",
1630 config: Config{
Adam Langley7c803a62015-06-15 15:35:05 -07001631 Bugs: ProtocolBugs{
1632 WrongCertificateMessageType: true,
1633 },
1634 },
1635 shouldFail: true,
1636 expectedError: ":UNEXPECTED_MESSAGE:",
1637 expectedLocalError: "remote error: unexpected message",
1638 },
1639 {
1640 protocol: dtls,
1641 name: "WrongMessageType-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 WrongCertificateMessageType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_MESSAGE:",
1649 expectedLocalError: "remote error: unexpected message",
1650 },
1651 {
1652 protocol: dtls,
1653 name: "FragmentMessageTypeMismatch-DTLS",
1654 config: Config{
1655 Bugs: ProtocolBugs{
1656 MaxHandshakeRecordLength: 2,
1657 FragmentMessageTypeMismatch: true,
1658 },
1659 },
1660 shouldFail: true,
1661 expectedError: ":FRAGMENT_MISMATCH:",
1662 },
1663 {
1664 protocol: dtls,
1665 name: "FragmentMessageLengthMismatch-DTLS",
1666 config: Config{
1667 Bugs: ProtocolBugs{
1668 MaxHandshakeRecordLength: 2,
1669 FragmentMessageLengthMismatch: true,
1670 },
1671 },
1672 shouldFail: true,
1673 expectedError: ":FRAGMENT_MISMATCH:",
1674 },
1675 {
1676 protocol: dtls,
1677 name: "SplitFragments-Header-DTLS",
1678 config: Config{
1679 Bugs: ProtocolBugs{
1680 SplitFragments: 2,
1681 },
1682 },
1683 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001684 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001685 },
1686 {
1687 protocol: dtls,
1688 name: "SplitFragments-Boundary-DTLS",
1689 config: Config{
1690 Bugs: ProtocolBugs{
1691 SplitFragments: dtlsRecordHeaderLen,
1692 },
1693 },
1694 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001695 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001696 },
1697 {
1698 protocol: dtls,
1699 name: "SplitFragments-Body-DTLS",
1700 config: Config{
1701 Bugs: ProtocolBugs{
1702 SplitFragments: dtlsRecordHeaderLen + 1,
1703 },
1704 },
1705 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001706 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001707 },
1708 {
1709 protocol: dtls,
1710 name: "SendEmptyFragments-DTLS",
1711 config: Config{
1712 Bugs: ProtocolBugs{
1713 SendEmptyFragments: true,
1714 },
1715 },
1716 },
1717 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001718 name: "BadFinished-Client",
1719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001720 // TODO(davidben): Add a TLS 1.3 version of this.
1721 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001722 Bugs: ProtocolBugs{
1723 BadFinished: true,
1724 },
1725 },
1726 shouldFail: true,
1727 expectedError: ":DIGEST_CHECK_FAILED:",
1728 },
1729 {
1730 testType: serverTest,
1731 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001733 // TODO(davidben): Add a TLS 1.3 version of this.
1734 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001735 Bugs: ProtocolBugs{
1736 BadFinished: true,
1737 },
1738 },
1739 shouldFail: true,
1740 expectedError: ":DIGEST_CHECK_FAILED:",
1741 },
1742 {
1743 name: "FalseStart-BadFinished",
1744 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001745 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1747 NextProtos: []string{"foo"},
1748 Bugs: ProtocolBugs{
1749 BadFinished: true,
1750 ExpectFalseStart: true,
1751 },
1752 },
1753 flags: []string{
1754 "-false-start",
1755 "-handshake-never-done",
1756 "-advertise-alpn", "\x03foo",
1757 },
1758 shimWritesFirst: true,
1759 shouldFail: true,
1760 expectedError: ":DIGEST_CHECK_FAILED:",
1761 },
1762 {
1763 name: "NoFalseStart-NoALPN",
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 Bugs: ProtocolBugs{
1768 ExpectFalseStart: true,
1769 AlertBeforeFalseStartTest: alertAccessDenied,
1770 },
1771 },
1772 flags: []string{
1773 "-false-start",
1774 },
1775 shimWritesFirst: true,
1776 shouldFail: true,
1777 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1778 expectedLocalError: "tls: peer did not false start: EOF",
1779 },
1780 {
1781 name: "NoFalseStart-NoAEAD",
1782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001783 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1785 NextProtos: []string{"foo"},
1786 Bugs: ProtocolBugs{
1787 ExpectFalseStart: true,
1788 AlertBeforeFalseStartTest: alertAccessDenied,
1789 },
1790 },
1791 flags: []string{
1792 "-false-start",
1793 "-advertise-alpn", "\x03foo",
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-RSA",
1802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
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-DHE_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_DHE_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 {
Adam Langley7c803a62015-06-15 15:35:05 -07001841 protocol: dtls,
1842 name: "SendSplitAlert-Sync",
1843 config: Config{
1844 Bugs: ProtocolBugs{
1845 SendSplitAlert: true,
1846 },
1847 },
1848 },
1849 {
1850 protocol: dtls,
1851 name: "SendSplitAlert-Async",
1852 config: Config{
1853 Bugs: ProtocolBugs{
1854 SendSplitAlert: true,
1855 },
1856 },
1857 flags: []string{"-async"},
1858 },
1859 {
1860 protocol: dtls,
1861 name: "PackDTLSHandshake",
1862 config: Config{
1863 Bugs: ProtocolBugs{
1864 MaxHandshakeRecordLength: 2,
1865 PackHandshakeFragments: 20,
1866 PackHandshakeRecords: 200,
1867 },
1868 },
1869 },
1870 {
Adam Langley7c803a62015-06-15 15:35:05 -07001871 name: "SendEmptyRecords-Pass",
1872 sendEmptyRecords: 32,
1873 },
1874 {
1875 name: "SendEmptyRecords",
1876 sendEmptyRecords: 33,
1877 shouldFail: true,
1878 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1879 },
1880 {
1881 name: "SendEmptyRecords-Async",
1882 sendEmptyRecords: 33,
1883 flags: []string{"-async"},
1884 shouldFail: true,
1885 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1886 },
1887 {
1888 name: "SendWarningAlerts-Pass",
1889 sendWarningAlerts: 4,
1890 },
1891 {
1892 protocol: dtls,
1893 name: "SendWarningAlerts-DTLS-Pass",
1894 sendWarningAlerts: 4,
1895 },
1896 {
1897 name: "SendWarningAlerts",
1898 sendWarningAlerts: 5,
1899 shouldFail: true,
1900 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1901 },
1902 {
1903 name: "SendWarningAlerts-Async",
1904 sendWarningAlerts: 5,
1905 flags: []string{"-async"},
1906 shouldFail: true,
1907 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1908 },
David Benjaminba4594a2015-06-18 18:36:15 -04001909 {
1910 name: "EmptySessionID",
1911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001912 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001913 SessionTicketsDisabled: true,
1914 },
1915 noSessionCache: true,
1916 flags: []string{"-expect-no-session"},
1917 },
David Benjamin30789da2015-08-29 22:56:45 -04001918 {
1919 name: "Unclean-Shutdown",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 NoCloseNotify: true,
1923 ExpectCloseNotify: true,
1924 },
1925 },
1926 shimShutsDown: true,
1927 flags: []string{"-check-close-notify"},
1928 shouldFail: true,
1929 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1930 },
1931 {
1932 name: "Unclean-Shutdown-Ignored",
1933 config: Config{
1934 Bugs: ProtocolBugs{
1935 NoCloseNotify: true,
1936 },
1937 },
1938 shimShutsDown: true,
1939 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001940 {
David Benjaminfa214e42016-05-10 17:03:10 -04001941 name: "Unclean-Shutdown-Alert",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendAlertOnShutdown: alertDecompressionFailure,
1945 ExpectCloseNotify: true,
1946 },
1947 },
1948 shimShutsDown: true,
1949 flags: []string{"-check-close-notify"},
1950 shouldFail: true,
1951 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1952 },
1953 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001954 name: "LargePlaintext",
1955 config: Config{
1956 Bugs: ProtocolBugs{
1957 SendLargeRecords: true,
1958 },
1959 },
1960 messageLen: maxPlaintext + 1,
1961 shouldFail: true,
1962 expectedError: ":DATA_LENGTH_TOO_LONG:",
1963 },
1964 {
1965 protocol: dtls,
1966 name: "LargePlaintext-DTLS",
1967 config: Config{
1968 Bugs: ProtocolBugs{
1969 SendLargeRecords: true,
1970 },
1971 },
1972 messageLen: maxPlaintext + 1,
1973 shouldFail: true,
1974 expectedError: ":DATA_LENGTH_TOO_LONG:",
1975 },
1976 {
1977 name: "LargeCiphertext",
1978 config: Config{
1979 Bugs: ProtocolBugs{
1980 SendLargeRecords: true,
1981 },
1982 },
1983 messageLen: maxPlaintext * 2,
1984 shouldFail: true,
1985 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1986 },
1987 {
1988 protocol: dtls,
1989 name: "LargeCiphertext-DTLS",
1990 config: Config{
1991 Bugs: ProtocolBugs{
1992 SendLargeRecords: true,
1993 },
1994 },
1995 messageLen: maxPlaintext * 2,
1996 // Unlike the other four cases, DTLS drops records which
1997 // are invalid before authentication, so the connection
1998 // does not fail.
1999 expectMessageDropped: true,
2000 },
David Benjamindd6fed92015-10-23 17:41:12 -04002001 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002002 // In TLS 1.2 and below, empty NewSessionTicket messages
2003 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002004 name: "SendEmptySessionTicket",
2005 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002006 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002007 Bugs: ProtocolBugs{
2008 SendEmptySessionTicket: true,
2009 FailIfSessionOffered: true,
2010 },
2011 },
2012 flags: []string{"-expect-no-session"},
2013 resumeSession: true,
2014 expectResumeRejected: true,
2015 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002016 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002017 name: "BadHelloRequest-1",
2018 renegotiate: 1,
2019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002020 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002021 Bugs: ProtocolBugs{
2022 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2023 },
2024 },
2025 flags: []string{
2026 "-renegotiate-freely",
2027 "-expect-total-renegotiations", "1",
2028 },
2029 shouldFail: true,
2030 expectedError: ":BAD_HELLO_REQUEST:",
2031 },
2032 {
2033 name: "BadHelloRequest-2",
2034 renegotiate: 1,
2035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002036 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002037 Bugs: ProtocolBugs{
2038 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2039 },
2040 },
2041 flags: []string{
2042 "-renegotiate-freely",
2043 "-expect-total-renegotiations", "1",
2044 },
2045 shouldFail: true,
2046 expectedError: ":BAD_HELLO_REQUEST:",
2047 },
David Benjaminef1b0092015-11-21 14:05:44 -05002048 {
2049 testType: serverTest,
2050 name: "SupportTicketsWithSessionID",
2051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002052 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002053 SessionTicketsDisabled: true,
2054 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002055 resumeConfig: &Config{
2056 MaxVersion: VersionTLS12,
2057 },
David Benjaminef1b0092015-11-21 14:05:44 -05002058 resumeSession: true,
2059 },
Adam Langley7c803a62015-06-15 15:35:05 -07002060 }
Adam Langley7c803a62015-06-15 15:35:05 -07002061 testCases = append(testCases, basicTests...)
2062}
2063
Adam Langley95c29f32014-06-20 12:00:00 -07002064func addCipherSuiteTests() {
2065 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002066 const psk = "12345"
2067 const pskIdentity = "luggage combo"
2068
Adam Langley95c29f32014-06-20 12:00:00 -07002069 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002070 var certFile string
2071 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002072 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002073 cert = ecdsaP256Certificate
2074 certFile = ecdsaP256CertificateFile
2075 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002076 } else {
David Benjamin33863262016-07-08 17:20:12 -07002077 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002078 certFile = rsaCertificateFile
2079 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002080 }
2081
David Benjamin48cae082014-10-27 01:06:24 -04002082 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002083 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002084 flags = append(flags,
2085 "-psk", psk,
2086 "-psk-identity", pskIdentity)
2087 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002088 if hasComponent(suite.name, "NULL") {
2089 // NULL ciphers must be explicitly enabled.
2090 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2091 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002092 if hasComponent(suite.name, "CECPQ1") {
2093 // CECPQ1 ciphers must be explicitly enabled.
2094 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2095 }
David Benjamin48cae082014-10-27 01:06:24 -04002096
Adam Langley95c29f32014-06-20 12:00:00 -07002097 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002098 for _, protocol := range []protocol{tls, dtls} {
2099 var prefix string
2100 if protocol == dtls {
2101 if !ver.hasDTLS {
2102 continue
2103 }
2104 prefix = "D"
2105 }
Adam Langley95c29f32014-06-20 12:00:00 -07002106
David Benjamin0407e762016-06-17 16:41:18 -04002107 var shouldServerFail, shouldClientFail bool
2108 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2109 // BoringSSL clients accept ECDHE on SSLv3, but
2110 // a BoringSSL server will never select it
2111 // because the extension is missing.
2112 shouldServerFail = true
2113 }
2114 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2115 shouldClientFail = true
2116 shouldServerFail = true
2117 }
David Benjamin54c217c2016-07-13 12:35:25 -04002118 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002119 shouldClientFail = true
2120 shouldServerFail = true
2121 }
David Benjamin0407e762016-06-17 16:41:18 -04002122 if !isDTLSCipher(suite.name) && protocol == dtls {
2123 shouldClientFail = true
2124 shouldServerFail = true
2125 }
David Benjamin4298d772015-12-19 00:18:25 -05002126
David Benjamin0407e762016-06-17 16:41:18 -04002127 var expectedServerError, expectedClientError string
2128 if shouldServerFail {
2129 expectedServerError = ":NO_SHARED_CIPHER:"
2130 }
2131 if shouldClientFail {
2132 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2133 }
David Benjamin025b3d32014-07-01 19:53:04 -04002134
David Benjamin9deb1172016-07-13 17:13:49 -04002135 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2136 resumeSession := ver.version < VersionTLS13
2137
David Benjamin6fd297b2014-08-11 18:43:38 -04002138 testCases = append(testCases, testCase{
2139 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002140 protocol: protocol,
2141
2142 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002143 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002144 MinVersion: ver.version,
2145 MaxVersion: ver.version,
2146 CipherSuites: []uint16{suite.id},
2147 Certificates: []Certificate{cert},
2148 PreSharedKey: []byte(psk),
2149 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002150 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002151 EnableAllCiphers: shouldServerFail,
2152 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002153 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002154 },
2155 certFile: certFile,
2156 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002157 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002158 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002159 shouldFail: shouldServerFail,
2160 expectedError: expectedServerError,
2161 })
2162
2163 testCases = append(testCases, testCase{
2164 testType: clientTest,
2165 protocol: protocol,
2166 name: prefix + ver.name + "-" + suite.name + "-client",
2167 config: Config{
2168 MinVersion: ver.version,
2169 MaxVersion: ver.version,
2170 CipherSuites: []uint16{suite.id},
2171 Certificates: []Certificate{cert},
2172 PreSharedKey: []byte(psk),
2173 PreSharedKeyIdentity: pskIdentity,
2174 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002175 EnableAllCiphers: shouldClientFail,
2176 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002177 },
2178 },
2179 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002180 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002181 shouldFail: shouldClientFail,
2182 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002183 })
David Benjamin2c99d282015-09-01 10:23:00 -04002184
Nick Harper1fd39d82016-06-14 18:14:35 -07002185 if !shouldClientFail {
2186 // Ensure the maximum record size is accepted.
2187 testCases = append(testCases, testCase{
2188 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2189 config: Config{
2190 MinVersion: ver.version,
2191 MaxVersion: ver.version,
2192 CipherSuites: []uint16{suite.id},
2193 Certificates: []Certificate{cert},
2194 PreSharedKey: []byte(psk),
2195 PreSharedKeyIdentity: pskIdentity,
2196 },
2197 flags: flags,
2198 messageLen: maxPlaintext,
2199 })
2200 }
2201 }
David Benjamin2c99d282015-09-01 10:23:00 -04002202 }
Adam Langley95c29f32014-06-20 12:00:00 -07002203 }
Adam Langleya7997f12015-05-14 17:38:50 -07002204
2205 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002206 name: "NoSharedCipher",
2207 config: Config{
2208 // TODO(davidben): Add a TLS 1.3 version of this test.
2209 MaxVersion: VersionTLS12,
2210 CipherSuites: []uint16{},
2211 },
2212 shouldFail: true,
2213 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2214 })
2215
2216 testCases = append(testCases, testCase{
2217 name: "UnsupportedCipherSuite",
2218 config: Config{
2219 MaxVersion: VersionTLS12,
2220 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2221 Bugs: ProtocolBugs{
2222 IgnorePeerCipherPreferences: true,
2223 },
2224 },
2225 flags: []string{"-cipher", "DEFAULT:!RC4"},
2226 shouldFail: true,
2227 expectedError: ":WRONG_CIPHER_RETURNED:",
2228 })
2229
2230 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002231 name: "WeakDH",
2232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002233 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002234 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2235 Bugs: ProtocolBugs{
2236 // This is a 1023-bit prime number, generated
2237 // with:
2238 // openssl gendh 1023 | openssl asn1parse -i
2239 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2240 },
2241 },
2242 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002243 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002244 })
Adam Langleycef75832015-09-03 14:51:12 -07002245
David Benjamincd24a392015-11-11 13:23:05 -08002246 testCases = append(testCases, testCase{
2247 name: "SillyDH",
2248 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002249 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002250 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2251 Bugs: ProtocolBugs{
2252 // This is a 4097-bit prime number, generated
2253 // with:
2254 // openssl gendh 4097 | openssl asn1parse -i
2255 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2256 },
2257 },
2258 shouldFail: true,
2259 expectedError: ":DH_P_TOO_LONG:",
2260 })
2261
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002262 // This test ensures that Diffie-Hellman public values are padded with
2263 // zeros so that they're the same length as the prime. This is to avoid
2264 // hitting a bug in yaSSL.
2265 testCases = append(testCases, testCase{
2266 testType: serverTest,
2267 name: "DHPublicValuePadded",
2268 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002269 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002270 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2271 Bugs: ProtocolBugs{
2272 RequireDHPublicValueLen: (1025 + 7) / 8,
2273 },
2274 },
2275 flags: []string{"-use-sparse-dh-prime"},
2276 })
David Benjamincd24a392015-11-11 13:23:05 -08002277
David Benjamin241ae832016-01-15 03:04:54 -05002278 // The server must be tolerant to bogus ciphers.
2279 const bogusCipher = 0x1234
2280 testCases = append(testCases, testCase{
2281 testType: serverTest,
2282 name: "UnknownCipher",
2283 config: Config{
2284 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2285 },
2286 })
2287
Adam Langleycef75832015-09-03 14:51:12 -07002288 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2289 // 1.1 specific cipher suite settings. A server is setup with the given
2290 // cipher lists and then a connection is made for each member of
2291 // expectations. The cipher suite that the server selects must match
2292 // the specified one.
2293 var versionSpecificCiphersTest = []struct {
2294 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2295 // expectations is a map from TLS version to cipher suite id.
2296 expectations map[uint16]uint16
2297 }{
2298 {
2299 // Test that the null case (where no version-specific ciphers are set)
2300 // works as expected.
2301 "RC4-SHA:AES128-SHA", // default ciphers
2302 "", // no ciphers specifically for TLS ≥ 1.0
2303 "", // no ciphers specifically for TLS ≥ 1.1
2304 map[uint16]uint16{
2305 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2306 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2307 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2308 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2309 },
2310 },
2311 {
2312 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2313 // cipher.
2314 "RC4-SHA:AES128-SHA", // default
2315 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2316 "", // no ciphers specifically for TLS ≥ 1.1
2317 map[uint16]uint16{
2318 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2319 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2320 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2321 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2322 },
2323 },
2324 {
2325 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2326 // cipher.
2327 "RC4-SHA:AES128-SHA", // default
2328 "", // no ciphers specifically for TLS ≥ 1.0
2329 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2330 map[uint16]uint16{
2331 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2332 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2333 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2334 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2335 },
2336 },
2337 {
2338 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2339 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2340 "RC4-SHA:AES128-SHA", // default
2341 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2342 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2343 map[uint16]uint16{
2344 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2345 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2346 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2347 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2348 },
2349 },
2350 }
2351
2352 for i, test := range versionSpecificCiphersTest {
2353 for version, expectedCipherSuite := range test.expectations {
2354 flags := []string{"-cipher", test.ciphersDefault}
2355 if len(test.ciphersTLS10) > 0 {
2356 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2357 }
2358 if len(test.ciphersTLS11) > 0 {
2359 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2360 }
2361
2362 testCases = append(testCases, testCase{
2363 testType: serverTest,
2364 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2365 config: Config{
2366 MaxVersion: version,
2367 MinVersion: version,
2368 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2369 },
2370 flags: flags,
2371 expectedCipher: expectedCipherSuite,
2372 })
2373 }
2374 }
Adam Langley95c29f32014-06-20 12:00:00 -07002375}
2376
2377func addBadECDSASignatureTests() {
2378 for badR := BadValue(1); badR < NumBadValues; badR++ {
2379 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002380 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002381 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2382 config: Config{
2383 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002384 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002385 Bugs: ProtocolBugs{
2386 BadECDSAR: badR,
2387 BadECDSAS: badS,
2388 },
2389 },
2390 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002391 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002392 })
2393 }
2394 }
2395}
2396
Adam Langley80842bd2014-06-20 12:00:00 -07002397func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002398 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002399 name: "MaxCBCPadding",
2400 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002401 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2403 Bugs: ProtocolBugs{
2404 MaxPadding: true,
2405 },
2406 },
2407 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2408 })
David Benjamin025b3d32014-07-01 19:53:04 -04002409 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002410 name: "BadCBCPadding",
2411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002412 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2414 Bugs: ProtocolBugs{
2415 PaddingFirstByteBad: true,
2416 },
2417 },
2418 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002419 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002420 })
2421 // OpenSSL previously had an issue where the first byte of padding in
2422 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002423 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002424 name: "BadCBCPadding255",
2425 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002426 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002427 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2428 Bugs: ProtocolBugs{
2429 MaxPadding: true,
2430 PaddingFirstByteBadIf255: true,
2431 },
2432 },
2433 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2434 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002435 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002436 })
2437}
2438
Kenny Root7fdeaf12014-08-05 15:23:37 -07002439func addCBCSplittingTests() {
2440 testCases = append(testCases, testCase{
2441 name: "CBCRecordSplitting",
2442 config: Config{
2443 MaxVersion: VersionTLS10,
2444 MinVersion: VersionTLS10,
2445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2446 },
David Benjaminac8302a2015-09-01 17:18:15 -04002447 messageLen: -1, // read until EOF
2448 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002449 flags: []string{
2450 "-async",
2451 "-write-different-record-sizes",
2452 "-cbc-record-splitting",
2453 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002454 })
2455 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002456 name: "CBCRecordSplittingPartialWrite",
2457 config: Config{
2458 MaxVersion: VersionTLS10,
2459 MinVersion: VersionTLS10,
2460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2461 },
2462 messageLen: -1, // read until EOF
2463 flags: []string{
2464 "-async",
2465 "-write-different-record-sizes",
2466 "-cbc-record-splitting",
2467 "-partial-write",
2468 },
2469 })
2470}
2471
David Benjamin636293b2014-07-08 17:59:18 -04002472func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002473 // Add a dummy cert pool to stress certificate authority parsing.
2474 // TODO(davidben): Add tests that those values parse out correctly.
2475 certPool := x509.NewCertPool()
2476 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2477 if err != nil {
2478 panic(err)
2479 }
2480 certPool.AddCert(cert)
2481
David Benjamin636293b2014-07-08 17:59:18 -04002482 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002483 testCases = append(testCases, testCase{
2484 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002485 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002486 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002487 MinVersion: ver.version,
2488 MaxVersion: ver.version,
2489 ClientAuth: RequireAnyClientCert,
2490 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002491 },
2492 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002493 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2494 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002495 },
2496 })
2497 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002498 testType: serverTest,
2499 name: ver.name + "-Server-ClientAuth-RSA",
2500 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002501 MinVersion: ver.version,
2502 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002503 Certificates: []Certificate{rsaCertificate},
2504 },
2505 flags: []string{"-require-any-client-certificate"},
2506 })
David Benjamine098ec22014-08-27 23:13:20 -04002507 if ver.version != VersionSSL30 {
2508 testCases = append(testCases, testCase{
2509 testType: serverTest,
2510 name: ver.name + "-Server-ClientAuth-ECDSA",
2511 config: Config{
2512 MinVersion: ver.version,
2513 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002514 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002515 },
2516 flags: []string{"-require-any-client-certificate"},
2517 })
2518 testCases = append(testCases, testCase{
2519 testType: clientTest,
2520 name: ver.name + "-Client-ClientAuth-ECDSA",
2521 config: Config{
2522 MinVersion: ver.version,
2523 MaxVersion: ver.version,
2524 ClientAuth: RequireAnyClientCert,
2525 ClientCAs: certPool,
2526 },
2527 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002528 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2529 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002530 },
2531 })
2532 }
David Benjamin636293b2014-07-08 17:59:18 -04002533 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002534
Nick Harper1fd39d82016-06-14 18:14:35 -07002535 // TODO(davidben): These tests will need TLS 1.3 versions when the
2536 // handshake is separate.
2537
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002538 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002539 name: "NoClientCertificate",
2540 config: Config{
2541 MaxVersion: VersionTLS12,
2542 ClientAuth: RequireAnyClientCert,
2543 },
2544 shouldFail: true,
2545 expectedLocalError: "client didn't provide a certificate",
2546 })
2547
2548 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002549 testType: serverTest,
2550 name: "RequireAnyClientCertificate",
2551 config: Config{
2552 MaxVersion: VersionTLS12,
2553 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002554 flags: []string{"-require-any-client-certificate"},
2555 shouldFail: true,
2556 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2557 })
2558
2559 testCases = append(testCases, testCase{
2560 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002561 name: "RequireAnyClientCertificate-SSL3",
2562 config: Config{
2563 MaxVersion: VersionSSL30,
2564 },
2565 flags: []string{"-require-any-client-certificate"},
2566 shouldFail: true,
2567 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2568 })
2569
2570 testCases = append(testCases, testCase{
2571 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002572 name: "SkipClientCertificate",
2573 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002574 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002575 Bugs: ProtocolBugs{
2576 SkipClientCertificate: true,
2577 },
2578 },
2579 // Setting SSL_VERIFY_PEER allows anonymous clients.
2580 flags: []string{"-verify-peer"},
2581 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002582 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002583 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002584
2585 // Client auth is only legal in certificate-based ciphers.
2586 testCases = append(testCases, testCase{
2587 testType: clientTest,
2588 name: "ClientAuth-PSK",
2589 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002590 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002591 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2592 PreSharedKey: []byte("secret"),
2593 ClientAuth: RequireAnyClientCert,
2594 },
2595 flags: []string{
2596 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2597 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2598 "-psk", "secret",
2599 },
2600 shouldFail: true,
2601 expectedError: ":UNEXPECTED_MESSAGE:",
2602 })
2603 testCases = append(testCases, testCase{
2604 testType: clientTest,
2605 name: "ClientAuth-ECDHE_PSK",
2606 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002607 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002608 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2609 PreSharedKey: []byte("secret"),
2610 ClientAuth: RequireAnyClientCert,
2611 },
2612 flags: []string{
2613 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2614 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2615 "-psk", "secret",
2616 },
2617 shouldFail: true,
2618 expectedError: ":UNEXPECTED_MESSAGE:",
2619 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002620
2621 // Regression test for a bug where the client CA list, if explicitly
2622 // set to NULL, was mis-encoded.
2623 testCases = append(testCases, testCase{
2624 testType: serverTest,
2625 name: "Null-Client-CA-List",
2626 config: Config{
2627 MaxVersion: VersionTLS12,
2628 Certificates: []Certificate{rsaCertificate},
2629 },
2630 flags: []string{
2631 "-require-any-client-certificate",
2632 "-use-null-client-ca-list",
2633 },
2634 })
David Benjamin636293b2014-07-08 17:59:18 -04002635}
2636
Adam Langley75712922014-10-10 16:23:43 -07002637func addExtendedMasterSecretTests() {
2638 const expectEMSFlag = "-expect-extended-master-secret"
2639
2640 for _, with := range []bool{false, true} {
2641 prefix := "No"
2642 var flags []string
2643 if with {
2644 prefix = ""
2645 flags = []string{expectEMSFlag}
2646 }
2647
2648 for _, isClient := range []bool{false, true} {
2649 suffix := "-Server"
2650 testType := serverTest
2651 if isClient {
2652 suffix = "-Client"
2653 testType = clientTest
2654 }
2655
David Benjamin4c3ddf72016-06-29 18:13:53 -04002656 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2657 // test that the extension is irrelevant, but the API
2658 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002659 for _, ver := range tlsVersions {
2660 test := testCase{
2661 testType: testType,
2662 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2663 config: Config{
2664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
2666 Bugs: ProtocolBugs{
2667 NoExtendedMasterSecret: !with,
2668 RequireExtendedMasterSecret: with,
2669 },
2670 },
David Benjamin48cae082014-10-27 01:06:24 -04002671 flags: flags,
2672 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002673 }
2674 if test.shouldFail {
2675 test.expectedLocalError = "extended master secret required but not supported by peer"
2676 }
2677 testCases = append(testCases, test)
2678 }
2679 }
2680 }
2681
Adam Langleyba5934b2015-06-02 10:50:35 -07002682 for _, isClient := range []bool{false, true} {
2683 for _, supportedInFirstConnection := range []bool{false, true} {
2684 for _, supportedInResumeConnection := range []bool{false, true} {
2685 boolToWord := func(b bool) string {
2686 if b {
2687 return "Yes"
2688 }
2689 return "No"
2690 }
2691 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2692 if isClient {
2693 suffix += "Client"
2694 } else {
2695 suffix += "Server"
2696 }
2697
2698 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002699 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002700 Bugs: ProtocolBugs{
2701 RequireExtendedMasterSecret: true,
2702 },
2703 }
2704
2705 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002706 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002707 Bugs: ProtocolBugs{
2708 NoExtendedMasterSecret: true,
2709 },
2710 }
2711
2712 test := testCase{
2713 name: "ExtendedMasterSecret-" + suffix,
2714 resumeSession: true,
2715 }
2716
2717 if !isClient {
2718 test.testType = serverTest
2719 }
2720
2721 if supportedInFirstConnection {
2722 test.config = supportedConfig
2723 } else {
2724 test.config = noSupportConfig
2725 }
2726
2727 if supportedInResumeConnection {
2728 test.resumeConfig = &supportedConfig
2729 } else {
2730 test.resumeConfig = &noSupportConfig
2731 }
2732
2733 switch suffix {
2734 case "YesToYes-Client", "YesToYes-Server":
2735 // When a session is resumed, it should
2736 // still be aware that its master
2737 // secret was generated via EMS and
2738 // thus it's safe to use tls-unique.
2739 test.flags = []string{expectEMSFlag}
2740 case "NoToYes-Server":
2741 // If an original connection did not
2742 // contain EMS, but a resumption
2743 // handshake does, then a server should
2744 // not resume the session.
2745 test.expectResumeRejected = true
2746 case "YesToNo-Server":
2747 // Resuming an EMS session without the
2748 // EMS extension should cause the
2749 // server to abort the connection.
2750 test.shouldFail = true
2751 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2752 case "NoToYes-Client":
2753 // A client should abort a connection
2754 // where the server resumed a non-EMS
2755 // session but echoed the EMS
2756 // extension.
2757 test.shouldFail = true
2758 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2759 case "YesToNo-Client":
2760 // A client should abort a connection
2761 // where the server didn't echo EMS
2762 // when the session used it.
2763 test.shouldFail = true
2764 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2765 }
2766
2767 testCases = append(testCases, test)
2768 }
2769 }
2770 }
Adam Langley75712922014-10-10 16:23:43 -07002771}
2772
David Benjamin582ba042016-07-07 12:33:25 -07002773type stateMachineTestConfig struct {
2774 protocol protocol
2775 async bool
2776 splitHandshake, packHandshakeFlight bool
2777}
2778
David Benjamin43ec06f2014-08-05 02:28:57 -04002779// Adds tests that try to cover the range of the handshake state machine, under
2780// various conditions. Some of these are redundant with other tests, but they
2781// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002782func addAllStateMachineCoverageTests() {
2783 for _, async := range []bool{false, true} {
2784 for _, protocol := range []protocol{tls, dtls} {
2785 addStateMachineCoverageTests(stateMachineTestConfig{
2786 protocol: protocol,
2787 async: async,
2788 })
2789 addStateMachineCoverageTests(stateMachineTestConfig{
2790 protocol: protocol,
2791 async: async,
2792 splitHandshake: true,
2793 })
2794 if protocol == tls {
2795 addStateMachineCoverageTests(stateMachineTestConfig{
2796 protocol: protocol,
2797 async: async,
2798 packHandshakeFlight: true,
2799 })
2800 }
2801 }
2802 }
2803}
2804
2805func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002806 var tests []testCase
2807
2808 // Basic handshake, with resumption. Client and server,
2809 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002810 //
2811 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2812 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002813 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002814 name: "Basic-Client",
2815 config: Config{
2816 MaxVersion: VersionTLS12,
2817 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002818 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002819 // Ensure session tickets are used, not session IDs.
2820 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002821 })
2822 tests = append(tests, testCase{
2823 name: "Basic-Client-RenewTicket",
2824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002825 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002826 Bugs: ProtocolBugs{
2827 RenewTicketOnResume: true,
2828 },
2829 },
David Benjaminba4594a2015-06-18 18:36:15 -04002830 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002831 resumeSession: true,
2832 })
2833 tests = append(tests, testCase{
2834 name: "Basic-Client-NoTicket",
2835 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002836 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002837 SessionTicketsDisabled: true,
2838 },
2839 resumeSession: true,
2840 })
2841 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002842 name: "Basic-Client-Implicit",
2843 config: Config{
2844 MaxVersion: VersionTLS12,
2845 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002846 flags: []string{"-implicit-handshake"},
2847 resumeSession: true,
2848 })
2849 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002850 testType: serverTest,
2851 name: "Basic-Server",
2852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002853 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002854 Bugs: ProtocolBugs{
2855 RequireSessionTickets: true,
2856 },
2857 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002858 resumeSession: true,
2859 })
2860 tests = append(tests, testCase{
2861 testType: serverTest,
2862 name: "Basic-Server-NoTickets",
2863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002864 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002865 SessionTicketsDisabled: true,
2866 },
2867 resumeSession: true,
2868 })
2869 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002870 testType: serverTest,
2871 name: "Basic-Server-Implicit",
2872 config: Config{
2873 MaxVersion: VersionTLS12,
2874 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002875 flags: []string{"-implicit-handshake"},
2876 resumeSession: true,
2877 })
2878 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002879 testType: serverTest,
2880 name: "Basic-Server-EarlyCallback",
2881 config: Config{
2882 MaxVersion: VersionTLS12,
2883 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002884 flags: []string{"-use-early-callback"},
2885 resumeSession: true,
2886 })
2887
2888 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002889 //
2890 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002891 tests = append(tests, testCase{
2892 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002893 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002895 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002896 ClientAuth: RequestClientCert,
2897 },
2898 })
2899 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002900 testType: serverTest,
2901 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002902 config: Config{
2903 MaxVersion: VersionTLS12,
2904 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002905 // Setting SSL_VERIFY_PEER allows anonymous clients.
2906 flags: []string{"-verify-peer"},
2907 })
David Benjamin582ba042016-07-07 12:33:25 -07002908 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002909 tests = append(tests, testCase{
2910 testType: clientTest,
2911 name: "ClientAuth-NoCertificate-Client-SSL3",
2912 config: Config{
2913 MaxVersion: VersionSSL30,
2914 ClientAuth: RequestClientCert,
2915 },
2916 })
2917 tests = append(tests, testCase{
2918 testType: serverTest,
2919 name: "ClientAuth-NoCertificate-Server-SSL3",
2920 config: Config{
2921 MaxVersion: VersionSSL30,
2922 },
2923 // Setting SSL_VERIFY_PEER allows anonymous clients.
2924 flags: []string{"-verify-peer"},
2925 })
2926 }
2927 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002928 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002929 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002930 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002932 ClientAuth: RequireAnyClientCert,
2933 },
2934 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002935 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2936 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002937 },
2938 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002939 tests = append(tests, testCase{
2940 testType: clientTest,
2941 name: "ClientAuth-ECDSA-Client",
2942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002943 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002944 ClientAuth: RequireAnyClientCert,
2945 },
2946 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002947 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2948 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002949 },
2950 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002951 tests = append(tests, testCase{
2952 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002953 name: "ClientAuth-NoCertificate-OldCallback",
2954 config: Config{
2955 MaxVersion: VersionTLS12,
2956 ClientAuth: RequestClientCert,
2957 },
2958 flags: []string{"-use-old-client-cert-callback"},
2959 })
2960 tests = append(tests, testCase{
2961 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002962 name: "ClientAuth-OldCallback",
2963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002964 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002965 ClientAuth: RequireAnyClientCert,
2966 },
2967 flags: []string{
2968 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2969 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2970 "-use-old-client-cert-callback",
2971 },
2972 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002973 tests = append(tests, testCase{
2974 testType: serverTest,
2975 name: "ClientAuth-Server",
2976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002977 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002978 Certificates: []Certificate{rsaCertificate},
2979 },
2980 flags: []string{"-require-any-client-certificate"},
2981 })
2982
David Benjamin4c3ddf72016-06-29 18:13:53 -04002983 // Test each key exchange on the server side for async keys.
2984 //
2985 // TODO(davidben): Add TLS 1.3 versions of these.
2986 tests = append(tests, testCase{
2987 testType: serverTest,
2988 name: "Basic-Server-RSA",
2989 config: Config{
2990 MaxVersion: VersionTLS12,
2991 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2992 },
2993 flags: []string{
2994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2996 },
2997 })
2998 tests = append(tests, testCase{
2999 testType: serverTest,
3000 name: "Basic-Server-ECDHE-RSA",
3001 config: Config{
3002 MaxVersion: VersionTLS12,
3003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3004 },
3005 flags: []string{
3006 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3007 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3008 },
3009 })
3010 tests = append(tests, testCase{
3011 testType: serverTest,
3012 name: "Basic-Server-ECDHE-ECDSA",
3013 config: Config{
3014 MaxVersion: VersionTLS12,
3015 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3016 },
3017 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003018 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3019 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003020 },
3021 })
3022
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 // No session ticket support; server doesn't send NewSessionTicket.
3024 tests = append(tests, testCase{
3025 name: "SessionTicketsDisabled-Client",
3026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003028 SessionTicketsDisabled: true,
3029 },
3030 })
3031 tests = append(tests, testCase{
3032 testType: serverTest,
3033 name: "SessionTicketsDisabled-Server",
3034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003035 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003036 SessionTicketsDisabled: true,
3037 },
3038 })
3039
3040 // Skip ServerKeyExchange in PSK key exchange if there's no
3041 // identity hint.
3042 tests = append(tests, testCase{
3043 name: "EmptyPSKHint-Client",
3044 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003045 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003046 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3047 PreSharedKey: []byte("secret"),
3048 },
3049 flags: []string{"-psk", "secret"},
3050 })
3051 tests = append(tests, testCase{
3052 testType: serverTest,
3053 name: "EmptyPSKHint-Server",
3054 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003055 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003056 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3057 PreSharedKey: []byte("secret"),
3058 },
3059 flags: []string{"-psk", "secret"},
3060 })
3061
David Benjamin4c3ddf72016-06-29 18:13:53 -04003062 // OCSP stapling tests.
3063 //
3064 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003065 tests = append(tests, testCase{
3066 testType: clientTest,
3067 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 config: Config{
3069 MaxVersion: VersionTLS12,
3070 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003071 flags: []string{
3072 "-enable-ocsp-stapling",
3073 "-expect-ocsp-response",
3074 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003075 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003076 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003077 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003078 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003079 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003080 testType: serverTest,
3081 name: "OCSPStapling-Server",
3082 config: Config{
3083 MaxVersion: VersionTLS12,
3084 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003085 expectedOCSPResponse: testOCSPResponse,
3086 flags: []string{
3087 "-ocsp-response",
3088 base64.StdEncoding.EncodeToString(testOCSPResponse),
3089 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003090 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003091 })
3092
David Benjamin4c3ddf72016-06-29 18:13:53 -04003093 // Certificate verification tests.
3094 //
3095 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003096 tests = append(tests, testCase{
3097 testType: clientTest,
3098 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003099 config: Config{
3100 MaxVersion: VersionTLS12,
3101 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003102 flags: []string{
3103 "-verify-peer",
3104 },
3105 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003106 tests = append(tests, testCase{
3107 testType: clientTest,
3108 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 config: Config{
3110 MaxVersion: VersionTLS12,
3111 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003112 flags: []string{
3113 "-verify-fail",
3114 "-verify-peer",
3115 },
3116 shouldFail: true,
3117 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3118 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003119 tests = append(tests, testCase{
3120 testType: clientTest,
3121 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003122 config: Config{
3123 MaxVersion: VersionTLS12,
3124 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003125 flags: []string{
3126 "-verify-fail",
3127 "-expect-verify-result",
3128 },
3129 })
3130
David Benjamin582ba042016-07-07 12:33:25 -07003131 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003132 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003133 name: "Renegotiate-Client",
3134 config: Config{
3135 MaxVersion: VersionTLS12,
3136 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003137 renegotiate: 1,
3138 flags: []string{
3139 "-renegotiate-freely",
3140 "-expect-total-renegotiations", "1",
3141 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003142 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003143
David Benjamin760b1dd2015-05-15 23:33:48 -04003144 // NPN on client and server; results in post-handshake message.
3145 tests = append(tests, testCase{
3146 name: "NPN-Client",
3147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003148 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003149 NextProtos: []string{"foo"},
3150 },
3151 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003152 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003153 expectedNextProto: "foo",
3154 expectedNextProtoType: npn,
3155 })
3156 tests = append(tests, testCase{
3157 testType: serverTest,
3158 name: "NPN-Server",
3159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003160 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003161 NextProtos: []string{"bar"},
3162 },
3163 flags: []string{
3164 "-advertise-npn", "\x03foo\x03bar\x03baz",
3165 "-expect-next-proto", "bar",
3166 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003167 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003168 expectedNextProto: "bar",
3169 expectedNextProtoType: npn,
3170 })
3171
3172 // TODO(davidben): Add tests for when False Start doesn't trigger.
3173
3174 // Client does False Start and negotiates NPN.
3175 tests = append(tests, testCase{
3176 name: "FalseStart",
3177 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003178 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3180 NextProtos: []string{"foo"},
3181 Bugs: ProtocolBugs{
3182 ExpectFalseStart: true,
3183 },
3184 },
3185 flags: []string{
3186 "-false-start",
3187 "-select-next-proto", "foo",
3188 },
3189 shimWritesFirst: true,
3190 resumeSession: true,
3191 })
3192
3193 // Client does False Start and negotiates ALPN.
3194 tests = append(tests, testCase{
3195 name: "FalseStart-ALPN",
3196 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003197 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3199 NextProtos: []string{"foo"},
3200 Bugs: ProtocolBugs{
3201 ExpectFalseStart: true,
3202 },
3203 },
3204 flags: []string{
3205 "-false-start",
3206 "-advertise-alpn", "\x03foo",
3207 },
3208 shimWritesFirst: true,
3209 resumeSession: true,
3210 })
3211
3212 // Client does False Start but doesn't explicitly call
3213 // SSL_connect.
3214 tests = append(tests, testCase{
3215 name: "FalseStart-Implicit",
3216 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003217 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3219 NextProtos: []string{"foo"},
3220 },
3221 flags: []string{
3222 "-implicit-handshake",
3223 "-false-start",
3224 "-advertise-alpn", "\x03foo",
3225 },
3226 })
3227
3228 // False Start without session tickets.
3229 tests = append(tests, testCase{
3230 name: "FalseStart-SessionTicketsDisabled",
3231 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003232 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003233 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3234 NextProtos: []string{"foo"},
3235 SessionTicketsDisabled: true,
3236 Bugs: ProtocolBugs{
3237 ExpectFalseStart: true,
3238 },
3239 },
3240 flags: []string{
3241 "-false-start",
3242 "-select-next-proto", "foo",
3243 },
3244 shimWritesFirst: true,
3245 })
3246
Adam Langleydf759b52016-07-11 15:24:37 -07003247 tests = append(tests, testCase{
3248 name: "FalseStart-CECPQ1",
3249 config: Config{
3250 MaxVersion: VersionTLS12,
3251 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3252 NextProtos: []string{"foo"},
3253 Bugs: ProtocolBugs{
3254 ExpectFalseStart: true,
3255 },
3256 },
3257 flags: []string{
3258 "-false-start",
3259 "-cipher", "DEFAULT:kCECPQ1",
3260 "-select-next-proto", "foo",
3261 },
3262 shimWritesFirst: true,
3263 resumeSession: true,
3264 })
3265
David Benjamin760b1dd2015-05-15 23:33:48 -04003266 // Server parses a V2ClientHello.
3267 tests = append(tests, testCase{
3268 testType: serverTest,
3269 name: "SendV2ClientHello",
3270 config: Config{
3271 // Choose a cipher suite that does not involve
3272 // elliptic curves, so no extensions are
3273 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003274 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3276 Bugs: ProtocolBugs{
3277 SendV2ClientHello: true,
3278 },
3279 },
3280 })
3281
3282 // Client sends a Channel ID.
3283 tests = append(tests, testCase{
3284 name: "ChannelID-Client",
3285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003286 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003287 RequestChannelID: true,
3288 },
Adam Langley7c803a62015-06-15 15:35:05 -07003289 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003290 resumeSession: true,
3291 expectChannelID: true,
3292 })
3293
3294 // Server accepts a Channel ID.
3295 tests = append(tests, testCase{
3296 testType: serverTest,
3297 name: "ChannelID-Server",
3298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003299 MaxVersion: VersionTLS12,
3300 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003301 },
3302 flags: []string{
3303 "-expect-channel-id",
3304 base64.StdEncoding.EncodeToString(channelIDBytes),
3305 },
3306 resumeSession: true,
3307 expectChannelID: true,
3308 })
David Benjamin30789da2015-08-29 22:56:45 -04003309
David Benjaminf8fcdf32016-06-08 15:56:13 -04003310 // Channel ID and NPN at the same time, to ensure their relative
3311 // ordering is correct.
3312 tests = append(tests, testCase{
3313 name: "ChannelID-NPN-Client",
3314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003315 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003316 RequestChannelID: true,
3317 NextProtos: []string{"foo"},
3318 },
3319 flags: []string{
3320 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3321 "-select-next-proto", "foo",
3322 },
3323 resumeSession: true,
3324 expectChannelID: true,
3325 expectedNextProto: "foo",
3326 expectedNextProtoType: npn,
3327 })
3328 tests = append(tests, testCase{
3329 testType: serverTest,
3330 name: "ChannelID-NPN-Server",
3331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003332 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003333 ChannelID: channelIDKey,
3334 NextProtos: []string{"bar"},
3335 },
3336 flags: []string{
3337 "-expect-channel-id",
3338 base64.StdEncoding.EncodeToString(channelIDBytes),
3339 "-advertise-npn", "\x03foo\x03bar\x03baz",
3340 "-expect-next-proto", "bar",
3341 },
3342 resumeSession: true,
3343 expectChannelID: true,
3344 expectedNextProto: "bar",
3345 expectedNextProtoType: npn,
3346 })
3347
David Benjamin30789da2015-08-29 22:56:45 -04003348 // Bidirectional shutdown with the runner initiating.
3349 tests = append(tests, testCase{
3350 name: "Shutdown-Runner",
3351 config: Config{
3352 Bugs: ProtocolBugs{
3353 ExpectCloseNotify: true,
3354 },
3355 },
3356 flags: []string{"-check-close-notify"},
3357 })
3358
3359 // Bidirectional shutdown with the shim initiating. The runner,
3360 // in the meantime, sends garbage before the close_notify which
3361 // the shim must ignore.
3362 tests = append(tests, testCase{
3363 name: "Shutdown-Shim",
3364 config: Config{
3365 Bugs: ProtocolBugs{
3366 ExpectCloseNotify: true,
3367 },
3368 },
3369 shimShutsDown: true,
3370 sendEmptyRecords: 1,
3371 sendWarningAlerts: 1,
3372 flags: []string{"-check-close-notify"},
3373 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003374 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003375 // TODO(davidben): DTLS 1.3 will want a similar thing for
3376 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003377 tests = append(tests, testCase{
3378 name: "SkipHelloVerifyRequest",
3379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003380 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 Bugs: ProtocolBugs{
3382 SkipHelloVerifyRequest: true,
3383 },
3384 },
3385 })
3386 }
3387
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003389 test.protocol = config.protocol
3390 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003391 test.name += "-DTLS"
3392 }
David Benjamin582ba042016-07-07 12:33:25 -07003393 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003394 test.name += "-Async"
3395 test.flags = append(test.flags, "-async")
3396 } else {
3397 test.name += "-Sync"
3398 }
David Benjamin582ba042016-07-07 12:33:25 -07003399 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003400 test.name += "-SplitHandshakeRecords"
3401 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003402 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003403 test.config.Bugs.MaxPacketLength = 256
3404 test.flags = append(test.flags, "-mtu", "256")
3405 }
3406 }
David Benjamin582ba042016-07-07 12:33:25 -07003407 if config.packHandshakeFlight {
3408 test.name += "-PackHandshakeFlight"
3409 test.config.Bugs.PackHandshakeFlight = true
3410 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003412 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003413}
3414
Adam Langley524e7172015-02-20 16:04:00 -08003415func addDDoSCallbackTests() {
3416 // DDoS callback.
3417
3418 for _, resume := range []bool{false, true} {
3419 suffix := "Resume"
3420 if resume {
3421 suffix = "No" + suffix
3422 }
3423
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3425
Adam Langley524e7172015-02-20 16:04:00 -08003426 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003427 testType: serverTest,
3428 name: "Server-DDoS-OK-" + suffix,
3429 config: Config{
3430 MaxVersion: VersionTLS12,
3431 },
Adam Langley524e7172015-02-20 16:04:00 -08003432 flags: []string{"-install-ddos-callback"},
3433 resumeSession: resume,
3434 })
3435
3436 failFlag := "-fail-ddos-callback"
3437 if resume {
3438 failFlag = "-fail-second-ddos-callback"
3439 }
3440 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003441 testType: serverTest,
3442 name: "Server-DDoS-Reject-" + suffix,
3443 config: Config{
3444 MaxVersion: VersionTLS12,
3445 },
Adam Langley524e7172015-02-20 16:04:00 -08003446 flags: []string{"-install-ddos-callback", failFlag},
3447 resumeSession: resume,
3448 shouldFail: true,
3449 expectedError: ":CONNECTION_REJECTED:",
3450 })
3451 }
3452}
3453
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003454func addVersionNegotiationTests() {
3455 for i, shimVers := range tlsVersions {
3456 // Assemble flags to disable all newer versions on the shim.
3457 var flags []string
3458 for _, vers := range tlsVersions[i+1:] {
3459 flags = append(flags, vers.flag)
3460 }
3461
3462 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003463 protocols := []protocol{tls}
3464 if runnerVers.hasDTLS && shimVers.hasDTLS {
3465 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003466 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003467 for _, protocol := range protocols {
3468 expectedVersion := shimVers.version
3469 if runnerVers.version < shimVers.version {
3470 expectedVersion = runnerVers.version
3471 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003472
David Benjamin8b8c0062014-11-23 02:47:52 -05003473 suffix := shimVers.name + "-" + runnerVers.name
3474 if protocol == dtls {
3475 suffix += "-DTLS"
3476 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003477
David Benjamin1eb367c2014-12-12 18:17:51 -05003478 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3479
David Benjamin1e29a6b2014-12-10 02:27:24 -05003480 clientVers := shimVers.version
3481 if clientVers > VersionTLS10 {
3482 clientVers = VersionTLS10
3483 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003484 serverVers := expectedVersion
3485 if expectedVersion >= VersionTLS13 {
3486 serverVers = VersionTLS10
3487 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003488 testCases = append(testCases, testCase{
3489 protocol: protocol,
3490 testType: clientTest,
3491 name: "VersionNegotiation-Client-" + suffix,
3492 config: Config{
3493 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003494 Bugs: ProtocolBugs{
3495 ExpectInitialRecordVersion: clientVers,
3496 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003497 },
3498 flags: flags,
3499 expectedVersion: expectedVersion,
3500 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003501 testCases = append(testCases, testCase{
3502 protocol: protocol,
3503 testType: clientTest,
3504 name: "VersionNegotiation-Client2-" + suffix,
3505 config: Config{
3506 MaxVersion: runnerVers.version,
3507 Bugs: ProtocolBugs{
3508 ExpectInitialRecordVersion: clientVers,
3509 },
3510 },
3511 flags: []string{"-max-version", shimVersFlag},
3512 expectedVersion: expectedVersion,
3513 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003514
3515 testCases = append(testCases, testCase{
3516 protocol: protocol,
3517 testType: serverTest,
3518 name: "VersionNegotiation-Server-" + suffix,
3519 config: Config{
3520 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003521 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003522 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003523 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003524 },
3525 flags: flags,
3526 expectedVersion: expectedVersion,
3527 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003528 testCases = append(testCases, testCase{
3529 protocol: protocol,
3530 testType: serverTest,
3531 name: "VersionNegotiation-Server2-" + suffix,
3532 config: Config{
3533 MaxVersion: runnerVers.version,
3534 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003535 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003536 },
3537 },
3538 flags: []string{"-max-version", shimVersFlag},
3539 expectedVersion: expectedVersion,
3540 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003541 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003542 }
3543 }
David Benjamin95c69562016-06-29 18:15:03 -04003544
3545 // Test for version tolerance.
3546 testCases = append(testCases, testCase{
3547 testType: serverTest,
3548 name: "MinorVersionTolerance",
3549 config: Config{
3550 Bugs: ProtocolBugs{
3551 SendClientVersion: 0x03ff,
3552 },
3553 },
3554 expectedVersion: VersionTLS13,
3555 })
3556 testCases = append(testCases, testCase{
3557 testType: serverTest,
3558 name: "MajorVersionTolerance",
3559 config: Config{
3560 Bugs: ProtocolBugs{
3561 SendClientVersion: 0x0400,
3562 },
3563 },
3564 expectedVersion: VersionTLS13,
3565 })
3566 testCases = append(testCases, testCase{
3567 protocol: dtls,
3568 testType: serverTest,
3569 name: "MinorVersionTolerance-DTLS",
3570 config: Config{
3571 Bugs: ProtocolBugs{
3572 SendClientVersion: 0x03ff,
3573 },
3574 },
3575 expectedVersion: VersionTLS12,
3576 })
3577 testCases = append(testCases, testCase{
3578 protocol: dtls,
3579 testType: serverTest,
3580 name: "MajorVersionTolerance-DTLS",
3581 config: Config{
3582 Bugs: ProtocolBugs{
3583 SendClientVersion: 0x0400,
3584 },
3585 },
3586 expectedVersion: VersionTLS12,
3587 })
3588
3589 // Test that versions below 3.0 are rejected.
3590 testCases = append(testCases, testCase{
3591 testType: serverTest,
3592 name: "VersionTooLow",
3593 config: Config{
3594 Bugs: ProtocolBugs{
3595 SendClientVersion: 0x0200,
3596 },
3597 },
3598 shouldFail: true,
3599 expectedError: ":UNSUPPORTED_PROTOCOL:",
3600 })
3601 testCases = append(testCases, testCase{
3602 protocol: dtls,
3603 testType: serverTest,
3604 name: "VersionTooLow-DTLS",
3605 config: Config{
3606 Bugs: ProtocolBugs{
3607 // 0x0201 is the lowest version expressable in
3608 // DTLS.
3609 SendClientVersion: 0x0201,
3610 },
3611 },
3612 shouldFail: true,
3613 expectedError: ":UNSUPPORTED_PROTOCOL:",
3614 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003615
3616 // Test TLS 1.3's downgrade signal.
3617 testCases = append(testCases, testCase{
3618 name: "Downgrade-TLS12-Client",
3619 config: Config{
3620 Bugs: ProtocolBugs{
3621 NegotiateVersion: VersionTLS12,
3622 },
3623 },
3624 shouldFail: true,
3625 expectedError: ":DOWNGRADE_DETECTED:",
3626 })
3627 testCases = append(testCases, testCase{
3628 testType: serverTest,
3629 name: "Downgrade-TLS12-Server",
3630 config: Config{
3631 Bugs: ProtocolBugs{
3632 SendClientVersion: VersionTLS12,
3633 },
3634 },
3635 shouldFail: true,
3636 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3637 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003638}
3639
David Benjaminaccb4542014-12-12 23:44:33 -05003640func addMinimumVersionTests() {
3641 for i, shimVers := range tlsVersions {
3642 // Assemble flags to disable all older versions on the shim.
3643 var flags []string
3644 for _, vers := range tlsVersions[:i] {
3645 flags = append(flags, vers.flag)
3646 }
3647
3648 for _, runnerVers := range tlsVersions {
3649 protocols := []protocol{tls}
3650 if runnerVers.hasDTLS && shimVers.hasDTLS {
3651 protocols = append(protocols, dtls)
3652 }
3653 for _, protocol := range protocols {
3654 suffix := shimVers.name + "-" + runnerVers.name
3655 if protocol == dtls {
3656 suffix += "-DTLS"
3657 }
3658 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3659
David Benjaminaccb4542014-12-12 23:44:33 -05003660 var expectedVersion uint16
3661 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003662 var expectedClientError, expectedServerError string
3663 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003664 if runnerVers.version >= shimVers.version {
3665 expectedVersion = runnerVers.version
3666 } else {
3667 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003668 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3669 expectedServerLocalError = "remote error: protocol version not supported"
3670 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3671 // If the client's minimum version is TLS 1.3 and the runner's
3672 // maximum is below TLS 1.2, the runner will fail to select a
3673 // cipher before the shim rejects the selected version.
3674 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3675 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3676 } else {
3677 expectedClientError = expectedServerError
3678 expectedClientLocalError = expectedServerLocalError
3679 }
David Benjaminaccb4542014-12-12 23:44:33 -05003680 }
3681
3682 testCases = append(testCases, testCase{
3683 protocol: protocol,
3684 testType: clientTest,
3685 name: "MinimumVersion-Client-" + suffix,
3686 config: Config{
3687 MaxVersion: runnerVers.version,
3688 },
David Benjamin87909c02014-12-13 01:55:01 -05003689 flags: flags,
3690 expectedVersion: expectedVersion,
3691 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003692 expectedError: expectedClientError,
3693 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003694 })
3695 testCases = append(testCases, testCase{
3696 protocol: protocol,
3697 testType: clientTest,
3698 name: "MinimumVersion-Client2-" + suffix,
3699 config: Config{
3700 MaxVersion: runnerVers.version,
3701 },
David Benjamin87909c02014-12-13 01:55:01 -05003702 flags: []string{"-min-version", shimVersFlag},
3703 expectedVersion: expectedVersion,
3704 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003705 expectedError: expectedClientError,
3706 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003707 })
3708
3709 testCases = append(testCases, testCase{
3710 protocol: protocol,
3711 testType: serverTest,
3712 name: "MinimumVersion-Server-" + suffix,
3713 config: Config{
3714 MaxVersion: runnerVers.version,
3715 },
David Benjamin87909c02014-12-13 01:55:01 -05003716 flags: flags,
3717 expectedVersion: expectedVersion,
3718 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003719 expectedError: expectedServerError,
3720 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003721 })
3722 testCases = append(testCases, testCase{
3723 protocol: protocol,
3724 testType: serverTest,
3725 name: "MinimumVersion-Server2-" + suffix,
3726 config: Config{
3727 MaxVersion: runnerVers.version,
3728 },
David Benjamin87909c02014-12-13 01:55:01 -05003729 flags: []string{"-min-version", shimVersFlag},
3730 expectedVersion: expectedVersion,
3731 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003732 expectedError: expectedServerError,
3733 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003734 })
3735 }
3736 }
3737 }
3738}
3739
David Benjamine78bfde2014-09-06 12:45:15 -04003740func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003741 // TODO(davidben): Extensions, where applicable, all move their server
3742 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3743 // tests for both. Also test interaction with 0-RTT when implemented.
3744
David Benjamine78bfde2014-09-06 12:45:15 -04003745 testCases = append(testCases, testCase{
3746 testType: clientTest,
3747 name: "DuplicateExtensionClient",
3748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003749 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003750 Bugs: ProtocolBugs{
3751 DuplicateExtension: true,
3752 },
3753 },
3754 shouldFail: true,
3755 expectedLocalError: "remote error: error decoding message",
3756 })
3757 testCases = append(testCases, testCase{
3758 testType: serverTest,
3759 name: "DuplicateExtensionServer",
3760 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003761 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003762 Bugs: ProtocolBugs{
3763 DuplicateExtension: true,
3764 },
3765 },
3766 shouldFail: true,
3767 expectedLocalError: "remote error: error decoding message",
3768 })
3769 testCases = append(testCases, testCase{
3770 testType: clientTest,
3771 name: "ServerNameExtensionClient",
3772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003773 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003774 Bugs: ProtocolBugs{
3775 ExpectServerName: "example.com",
3776 },
3777 },
3778 flags: []string{"-host-name", "example.com"},
3779 })
3780 testCases = append(testCases, testCase{
3781 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003782 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003784 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003785 Bugs: ProtocolBugs{
3786 ExpectServerName: "mismatch.com",
3787 },
3788 },
3789 flags: []string{"-host-name", "example.com"},
3790 shouldFail: true,
3791 expectedLocalError: "tls: unexpected server name",
3792 })
3793 testCases = append(testCases, testCase{
3794 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003795 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003797 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003798 Bugs: ProtocolBugs{
3799 ExpectServerName: "missing.com",
3800 },
3801 },
3802 shouldFail: true,
3803 expectedLocalError: "tls: unexpected server name",
3804 })
3805 testCases = append(testCases, testCase{
3806 testType: serverTest,
3807 name: "ServerNameExtensionServer",
3808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003810 ServerName: "example.com",
3811 },
3812 flags: []string{"-expect-server-name", "example.com"},
3813 resumeSession: true,
3814 })
David Benjaminae2888f2014-09-06 12:58:58 -04003815 testCases = append(testCases, testCase{
3816 testType: clientTest,
3817 name: "ALPNClient",
3818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003819 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003820 NextProtos: []string{"foo"},
3821 },
3822 flags: []string{
3823 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3824 "-expect-alpn", "foo",
3825 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003826 expectedNextProto: "foo",
3827 expectedNextProtoType: alpn,
3828 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003829 })
3830 testCases = append(testCases, testCase{
3831 testType: serverTest,
3832 name: "ALPNServer",
3833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003834 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003835 NextProtos: []string{"foo", "bar", "baz"},
3836 },
3837 flags: []string{
3838 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3839 "-select-alpn", "foo",
3840 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003841 expectedNextProto: "foo",
3842 expectedNextProtoType: alpn,
3843 resumeSession: true,
3844 })
David Benjamin594e7d22016-03-17 17:49:56 -04003845 testCases = append(testCases, testCase{
3846 testType: serverTest,
3847 name: "ALPNServer-Decline",
3848 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003849 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003850 NextProtos: []string{"foo", "bar", "baz"},
3851 },
3852 flags: []string{"-decline-alpn"},
3853 expectNoNextProto: true,
3854 resumeSession: true,
3855 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003856 // Test that the server prefers ALPN over NPN.
3857 testCases = append(testCases, testCase{
3858 testType: serverTest,
3859 name: "ALPNServer-Preferred",
3860 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003861 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003862 NextProtos: []string{"foo", "bar", "baz"},
3863 },
3864 flags: []string{
3865 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3866 "-select-alpn", "foo",
3867 "-advertise-npn", "\x03foo\x03bar\x03baz",
3868 },
3869 expectedNextProto: "foo",
3870 expectedNextProtoType: alpn,
3871 resumeSession: true,
3872 })
3873 testCases = append(testCases, testCase{
3874 testType: serverTest,
3875 name: "ALPNServer-Preferred-Swapped",
3876 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003877 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003878 NextProtos: []string{"foo", "bar", "baz"},
3879 Bugs: ProtocolBugs{
3880 SwapNPNAndALPN: true,
3881 },
3882 },
3883 flags: []string{
3884 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3885 "-select-alpn", "foo",
3886 "-advertise-npn", "\x03foo\x03bar\x03baz",
3887 },
3888 expectedNextProto: "foo",
3889 expectedNextProtoType: alpn,
3890 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003891 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003892 var emptyString string
3893 testCases = append(testCases, testCase{
3894 testType: clientTest,
3895 name: "ALPNClient-EmptyProtocolName",
3896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003897 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003898 NextProtos: []string{""},
3899 Bugs: ProtocolBugs{
3900 // A server returning an empty ALPN protocol
3901 // should be rejected.
3902 ALPNProtocol: &emptyString,
3903 },
3904 },
3905 flags: []string{
3906 "-advertise-alpn", "\x03foo",
3907 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003908 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003909 expectedError: ":PARSE_TLSEXT:",
3910 })
3911 testCases = append(testCases, testCase{
3912 testType: serverTest,
3913 name: "ALPNServer-EmptyProtocolName",
3914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003915 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003916 // A ClientHello containing an empty ALPN protocol
3917 // should be rejected.
3918 NextProtos: []string{"foo", "", "baz"},
3919 },
3920 flags: []string{
3921 "-select-alpn", "foo",
3922 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003923 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003924 expectedError: ":PARSE_TLSEXT:",
3925 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003926 // Test that negotiating both NPN and ALPN is forbidden.
3927 testCases = append(testCases, testCase{
3928 name: "NegotiateALPNAndNPN",
3929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003930 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003931 NextProtos: []string{"foo", "bar", "baz"},
3932 Bugs: ProtocolBugs{
3933 NegotiateALPNAndNPN: true,
3934 },
3935 },
3936 flags: []string{
3937 "-advertise-alpn", "\x03foo",
3938 "-select-next-proto", "foo",
3939 },
3940 shouldFail: true,
3941 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3942 })
3943 testCases = append(testCases, testCase{
3944 name: "NegotiateALPNAndNPN-Swapped",
3945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003947 NextProtos: []string{"foo", "bar", "baz"},
3948 Bugs: ProtocolBugs{
3949 NegotiateALPNAndNPN: true,
3950 SwapNPNAndALPN: true,
3951 },
3952 },
3953 flags: []string{
3954 "-advertise-alpn", "\x03foo",
3955 "-select-next-proto", "foo",
3956 },
3957 shouldFail: true,
3958 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3959 })
David Benjamin091c4b92015-10-26 13:33:21 -04003960 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3961 testCases = append(testCases, testCase{
3962 name: "DisableNPN",
3963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003965 NextProtos: []string{"foo"},
3966 },
3967 flags: []string{
3968 "-select-next-proto", "foo",
3969 "-disable-npn",
3970 },
3971 expectNoNextProto: true,
3972 })
Adam Langley38311732014-10-16 19:04:35 -07003973 // Resume with a corrupt ticket.
3974 testCases = append(testCases, testCase{
3975 testType: serverTest,
3976 name: "CorruptTicket",
3977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003979 Bugs: ProtocolBugs{
3980 CorruptTicket: true,
3981 },
3982 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003983 resumeSession: true,
3984 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003985 })
David Benjamind98452d2015-06-16 14:16:23 -04003986 // Test the ticket callback, with and without renewal.
3987 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003988 testType: serverTest,
3989 name: "TicketCallback",
3990 config: Config{
3991 MaxVersion: VersionTLS12,
3992 },
David Benjamind98452d2015-06-16 14:16:23 -04003993 resumeSession: true,
3994 flags: []string{"-use-ticket-callback"},
3995 })
3996 testCases = append(testCases, testCase{
3997 testType: serverTest,
3998 name: "TicketCallback-Renew",
3999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004000 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004001 Bugs: ProtocolBugs{
4002 ExpectNewTicket: true,
4003 },
4004 },
4005 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4006 resumeSession: true,
4007 })
Adam Langley38311732014-10-16 19:04:35 -07004008 // Resume with an oversized session id.
4009 testCases = append(testCases, testCase{
4010 testType: serverTest,
4011 name: "OversizedSessionId",
4012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004014 Bugs: ProtocolBugs{
4015 OversizedSessionId: true,
4016 },
4017 },
4018 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004019 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004020 expectedError: ":DECODE_ERROR:",
4021 })
David Benjaminca6c8262014-11-15 19:06:08 -05004022 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4023 // are ignored.
4024 testCases = append(testCases, testCase{
4025 protocol: dtls,
4026 name: "SRTP-Client",
4027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004028 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004029 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4030 },
4031 flags: []string{
4032 "-srtp-profiles",
4033 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4034 },
4035 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4036 })
4037 testCases = append(testCases, testCase{
4038 protocol: dtls,
4039 testType: serverTest,
4040 name: "SRTP-Server",
4041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004042 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004043 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4044 },
4045 flags: []string{
4046 "-srtp-profiles",
4047 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4048 },
4049 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4050 })
4051 // Test that the MKI is ignored.
4052 testCases = append(testCases, testCase{
4053 protocol: dtls,
4054 testType: serverTest,
4055 name: "SRTP-Server-IgnoreMKI",
4056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004057 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004058 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4059 Bugs: ProtocolBugs{
4060 SRTPMasterKeyIdentifer: "bogus",
4061 },
4062 },
4063 flags: []string{
4064 "-srtp-profiles",
4065 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4066 },
4067 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4068 })
4069 // Test that SRTP isn't negotiated on the server if there were
4070 // no matching profiles.
4071 testCases = append(testCases, testCase{
4072 protocol: dtls,
4073 testType: serverTest,
4074 name: "SRTP-Server-NoMatch",
4075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004076 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004077 SRTPProtectionProfiles: []uint16{100, 101, 102},
4078 },
4079 flags: []string{
4080 "-srtp-profiles",
4081 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4082 },
4083 expectedSRTPProtectionProfile: 0,
4084 })
4085 // Test that the server returning an invalid SRTP profile is
4086 // flagged as an error by the client.
4087 testCases = append(testCases, testCase{
4088 protocol: dtls,
4089 name: "SRTP-Client-NoMatch",
4090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004091 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004092 Bugs: ProtocolBugs{
4093 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4094 },
4095 },
4096 flags: []string{
4097 "-srtp-profiles",
4098 "SRTP_AES128_CM_SHA1_80",
4099 },
4100 shouldFail: true,
4101 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4102 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004103 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004104 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004105 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004106 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004107 config: Config{
4108 MaxVersion: VersionTLS12,
4109 },
David Benjamin61f95272014-11-25 01:55:35 -05004110 flags: []string{
4111 "-enable-signed-cert-timestamps",
4112 "-expect-signed-cert-timestamps",
4113 base64.StdEncoding.EncodeToString(testSCTList),
4114 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004115 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004116 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004117 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004118 name: "SendSCTListOnResume",
4119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004120 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004121 Bugs: ProtocolBugs{
4122 SendSCTListOnResume: []byte("bogus"),
4123 },
4124 },
4125 flags: []string{
4126 "-enable-signed-cert-timestamps",
4127 "-expect-signed-cert-timestamps",
4128 base64.StdEncoding.EncodeToString(testSCTList),
4129 },
4130 resumeSession: true,
4131 })
4132 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004133 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004134 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004135 config: Config{
4136 MaxVersion: VersionTLS12,
4137 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004138 flags: []string{
4139 "-signed-cert-timestamps",
4140 base64.StdEncoding.EncodeToString(testSCTList),
4141 },
4142 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004143 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004144 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004145
Paul Lietar4fac72e2015-09-09 13:44:55 +01004146 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004147 testType: clientTest,
4148 name: "ClientHelloPadding",
4149 config: Config{
4150 Bugs: ProtocolBugs{
4151 RequireClientHelloSize: 512,
4152 },
4153 },
4154 // This hostname just needs to be long enough to push the
4155 // ClientHello into F5's danger zone between 256 and 511 bytes
4156 // long.
4157 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4158 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004159
4160 // Extensions should not function in SSL 3.0.
4161 testCases = append(testCases, testCase{
4162 testType: serverTest,
4163 name: "SSLv3Extensions-NoALPN",
4164 config: Config{
4165 MaxVersion: VersionSSL30,
4166 NextProtos: []string{"foo", "bar", "baz"},
4167 },
4168 flags: []string{
4169 "-select-alpn", "foo",
4170 },
4171 expectNoNextProto: true,
4172 })
4173
4174 // Test session tickets separately as they follow a different codepath.
4175 testCases = append(testCases, testCase{
4176 testType: serverTest,
4177 name: "SSLv3Extensions-NoTickets",
4178 config: Config{
4179 MaxVersion: VersionSSL30,
4180 Bugs: ProtocolBugs{
4181 // Historically, session tickets in SSL 3.0
4182 // failed in different ways depending on whether
4183 // the client supported renegotiation_info.
4184 NoRenegotiationInfo: true,
4185 },
4186 },
4187 resumeSession: true,
4188 })
4189 testCases = append(testCases, testCase{
4190 testType: serverTest,
4191 name: "SSLv3Extensions-NoTickets2",
4192 config: Config{
4193 MaxVersion: VersionSSL30,
4194 },
4195 resumeSession: true,
4196 })
4197
4198 // But SSL 3.0 does send and process renegotiation_info.
4199 testCases = append(testCases, testCase{
4200 testType: serverTest,
4201 name: "SSLv3Extensions-RenegotiationInfo",
4202 config: Config{
4203 MaxVersion: VersionSSL30,
4204 Bugs: ProtocolBugs{
4205 RequireRenegotiationInfo: true,
4206 },
4207 },
4208 })
4209 testCases = append(testCases, testCase{
4210 testType: serverTest,
4211 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4212 config: Config{
4213 MaxVersion: VersionSSL30,
4214 Bugs: ProtocolBugs{
4215 NoRenegotiationInfo: true,
4216 SendRenegotiationSCSV: true,
4217 RequireRenegotiationInfo: true,
4218 },
4219 },
4220 })
David Benjamine78bfde2014-09-06 12:45:15 -04004221}
4222
David Benjamin01fe8202014-09-24 15:21:44 -04004223func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004224 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004225 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4226 if sessionVers.version >= VersionTLS13 {
4227 continue
4228 }
David Benjamin01fe8202014-09-24 15:21:44 -04004229 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004230 if resumeVers.version >= VersionTLS13 {
4231 continue
4232 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004233 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4234 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4235 // TLS 1.3 only shares ciphers with TLS 1.2, so
4236 // we skip certain combinations and use a
4237 // different cipher to test with.
4238 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4239 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4240 continue
4241 }
4242 }
4243
David Benjamin8b8c0062014-11-23 02:47:52 -05004244 protocols := []protocol{tls}
4245 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4246 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004247 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004248 for _, protocol := range protocols {
4249 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4250 if protocol == dtls {
4251 suffix += "-DTLS"
4252 }
4253
David Benjaminece3de92015-03-16 18:02:20 -04004254 if sessionVers.version == resumeVers.version {
4255 testCases = append(testCases, testCase{
4256 protocol: protocol,
4257 name: "Resume-Client" + suffix,
4258 resumeSession: true,
4259 config: Config{
4260 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004261 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004262 },
David Benjaminece3de92015-03-16 18:02:20 -04004263 expectedVersion: sessionVers.version,
4264 expectedResumeVersion: resumeVers.version,
4265 })
4266 } else {
4267 testCases = append(testCases, testCase{
4268 protocol: protocol,
4269 name: "Resume-Client-Mismatch" + suffix,
4270 resumeSession: true,
4271 config: Config{
4272 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004273 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004274 },
David Benjaminece3de92015-03-16 18:02:20 -04004275 expectedVersion: sessionVers.version,
4276 resumeConfig: &Config{
4277 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004278 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004279 Bugs: ProtocolBugs{
4280 AllowSessionVersionMismatch: true,
4281 },
4282 },
4283 expectedResumeVersion: resumeVers.version,
4284 shouldFail: true,
4285 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4286 })
4287 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004288
4289 testCases = append(testCases, testCase{
4290 protocol: protocol,
4291 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004292 resumeSession: true,
4293 config: Config{
4294 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004295 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004296 },
4297 expectedVersion: sessionVers.version,
4298 resumeConfig: &Config{
4299 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004300 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004301 },
4302 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004303 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004304 expectedResumeVersion: resumeVers.version,
4305 })
4306
David Benjamin8b8c0062014-11-23 02:47:52 -05004307 testCases = append(testCases, testCase{
4308 protocol: protocol,
4309 testType: serverTest,
4310 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004311 resumeSession: true,
4312 config: Config{
4313 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004314 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004315 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004316 expectedVersion: sessionVers.version,
4317 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004318 resumeConfig: &Config{
4319 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004320 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004321 },
4322 expectedResumeVersion: resumeVers.version,
4323 })
4324 }
David Benjamin01fe8202014-09-24 15:21:44 -04004325 }
4326 }
David Benjaminece3de92015-03-16 18:02:20 -04004327
Nick Harper1fd39d82016-06-14 18:14:35 -07004328 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004329 testCases = append(testCases, testCase{
4330 name: "Resume-Client-CipherMismatch",
4331 resumeSession: true,
4332 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004333 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004334 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4335 },
4336 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004337 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004338 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4339 Bugs: ProtocolBugs{
4340 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4341 },
4342 },
4343 shouldFail: true,
4344 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4345 })
David Benjamin01fe8202014-09-24 15:21:44 -04004346}
4347
Adam Langley2ae77d22014-10-28 17:29:33 -07004348func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004349 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004350 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004351 testType: serverTest,
4352 name: "Renegotiate-Server-Forbidden",
4353 config: Config{
4354 MaxVersion: VersionTLS12,
4355 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004356 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004357 shouldFail: true,
4358 expectedError: ":NO_RENEGOTIATION:",
4359 expectedLocalError: "remote error: no renegotiation",
4360 })
Adam Langley5021b222015-06-12 18:27:58 -07004361 // The server shouldn't echo the renegotiation extension unless
4362 // requested by the client.
4363 testCases = append(testCases, testCase{
4364 testType: serverTest,
4365 name: "Renegotiate-Server-NoExt",
4366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004367 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004368 Bugs: ProtocolBugs{
4369 NoRenegotiationInfo: true,
4370 RequireRenegotiationInfo: true,
4371 },
4372 },
4373 shouldFail: true,
4374 expectedLocalError: "renegotiation extension missing",
4375 })
4376 // The renegotiation SCSV should be sufficient for the server to echo
4377 // the extension.
4378 testCases = append(testCases, testCase{
4379 testType: serverTest,
4380 name: "Renegotiate-Server-NoExt-SCSV",
4381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004382 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004383 Bugs: ProtocolBugs{
4384 NoRenegotiationInfo: true,
4385 SendRenegotiationSCSV: true,
4386 RequireRenegotiationInfo: true,
4387 },
4388 },
4389 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004390 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004391 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004393 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004394 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004395 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004396 },
4397 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004398 renegotiate: 1,
4399 flags: []string{
4400 "-renegotiate-freely",
4401 "-expect-total-renegotiations", "1",
4402 },
David Benjamincdea40c2015-03-19 14:09:43 -04004403 })
4404 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004405 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004406 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004408 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004409 Bugs: ProtocolBugs{
4410 EmptyRenegotiationInfo: true,
4411 },
4412 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004413 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004414 shouldFail: true,
4415 expectedError: ":RENEGOTIATION_MISMATCH:",
4416 })
4417 testCases = append(testCases, testCase{
4418 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004419 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004421 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004422 Bugs: ProtocolBugs{
4423 BadRenegotiationInfo: true,
4424 },
4425 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004426 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004427 shouldFail: true,
4428 expectedError: ":RENEGOTIATION_MISMATCH:",
4429 })
4430 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004431 name: "Renegotiate-Client-Downgrade",
4432 renegotiate: 1,
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004435 Bugs: ProtocolBugs{
4436 NoRenegotiationInfoAfterInitial: true,
4437 },
4438 },
4439 flags: []string{"-renegotiate-freely"},
4440 shouldFail: true,
4441 expectedError: ":RENEGOTIATION_MISMATCH:",
4442 })
4443 testCases = append(testCases, testCase{
4444 name: "Renegotiate-Client-Upgrade",
4445 renegotiate: 1,
4446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004447 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004448 Bugs: ProtocolBugs{
4449 NoRenegotiationInfoInInitial: true,
4450 },
4451 },
4452 flags: []string{"-renegotiate-freely"},
4453 shouldFail: true,
4454 expectedError: ":RENEGOTIATION_MISMATCH:",
4455 })
4456 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004457 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004458 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004461 Bugs: ProtocolBugs{
4462 NoRenegotiationInfo: true,
4463 },
4464 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004465 flags: []string{
4466 "-renegotiate-freely",
4467 "-expect-total-renegotiations", "1",
4468 },
David Benjamincff0b902015-05-15 23:09:47 -04004469 })
4470 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004471 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004472 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004473 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004474 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004475 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4476 },
4477 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004478 flags: []string{
4479 "-renegotiate-freely",
4480 "-expect-total-renegotiations", "1",
4481 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004482 })
4483 testCases = append(testCases, testCase{
4484 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004485 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004486 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004487 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004488 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4489 },
4490 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004491 flags: []string{
4492 "-renegotiate-freely",
4493 "-expect-total-renegotiations", "1",
4494 },
David Benjaminb16346b2015-04-08 19:16:58 -04004495 })
4496 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004497 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004498 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004499 config: Config{
4500 MaxVersion: VersionTLS10,
4501 Bugs: ProtocolBugs{
4502 RequireSameRenegoClientVersion: true,
4503 },
4504 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004505 flags: []string{
4506 "-renegotiate-freely",
4507 "-expect-total-renegotiations", "1",
4508 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004509 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004510 testCases = append(testCases, testCase{
4511 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004512 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004513 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004514 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004515 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4516 NextProtos: []string{"foo"},
4517 },
4518 flags: []string{
4519 "-false-start",
4520 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004521 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004522 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004523 },
4524 shimWritesFirst: true,
4525 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004526
4527 // Client-side renegotiation controls.
4528 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004529 name: "Renegotiate-Client-Forbidden-1",
4530 config: Config{
4531 MaxVersion: VersionTLS12,
4532 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004533 renegotiate: 1,
4534 shouldFail: true,
4535 expectedError: ":NO_RENEGOTIATION:",
4536 expectedLocalError: "remote error: no renegotiation",
4537 })
4538 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004539 name: "Renegotiate-Client-Once-1",
4540 config: Config{
4541 MaxVersion: VersionTLS12,
4542 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004543 renegotiate: 1,
4544 flags: []string{
4545 "-renegotiate-once",
4546 "-expect-total-renegotiations", "1",
4547 },
4548 })
4549 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004550 name: "Renegotiate-Client-Freely-1",
4551 config: Config{
4552 MaxVersion: VersionTLS12,
4553 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004554 renegotiate: 1,
4555 flags: []string{
4556 "-renegotiate-freely",
4557 "-expect-total-renegotiations", "1",
4558 },
4559 })
4560 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004561 name: "Renegotiate-Client-Once-2",
4562 config: Config{
4563 MaxVersion: VersionTLS12,
4564 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004565 renegotiate: 2,
4566 flags: []string{"-renegotiate-once"},
4567 shouldFail: true,
4568 expectedError: ":NO_RENEGOTIATION:",
4569 expectedLocalError: "remote error: no renegotiation",
4570 })
4571 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004572 name: "Renegotiate-Client-Freely-2",
4573 config: Config{
4574 MaxVersion: VersionTLS12,
4575 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004576 renegotiate: 2,
4577 flags: []string{
4578 "-renegotiate-freely",
4579 "-expect-total-renegotiations", "2",
4580 },
4581 })
Adam Langley27a0d082015-11-03 13:34:10 -08004582 testCases = append(testCases, testCase{
4583 name: "Renegotiate-Client-NoIgnore",
4584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004585 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004586 Bugs: ProtocolBugs{
4587 SendHelloRequestBeforeEveryAppDataRecord: true,
4588 },
4589 },
4590 shouldFail: true,
4591 expectedError: ":NO_RENEGOTIATION:",
4592 })
4593 testCases = append(testCases, testCase{
4594 name: "Renegotiate-Client-Ignore",
4595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004596 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004597 Bugs: ProtocolBugs{
4598 SendHelloRequestBeforeEveryAppDataRecord: true,
4599 },
4600 },
4601 flags: []string{
4602 "-renegotiate-ignore",
4603 "-expect-total-renegotiations", "0",
4604 },
4605 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004606
David Benjamin397c8e62016-07-08 14:14:36 -07004607 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004608 testCases = append(testCases, testCase{
4609 name: "StrayHelloRequest",
4610 config: Config{
4611 MaxVersion: VersionTLS12,
4612 Bugs: ProtocolBugs{
4613 SendHelloRequestBeforeEveryHandshakeMessage: true,
4614 },
4615 },
4616 })
4617 testCases = append(testCases, testCase{
4618 name: "StrayHelloRequest-Packed",
4619 config: Config{
4620 MaxVersion: VersionTLS12,
4621 Bugs: ProtocolBugs{
4622 PackHandshakeFlight: true,
4623 SendHelloRequestBeforeEveryHandshakeMessage: true,
4624 },
4625 },
4626 })
4627
David Benjamin397c8e62016-07-08 14:14:36 -07004628 // Renegotiation is forbidden in TLS 1.3.
4629 testCases = append(testCases, testCase{
4630 name: "Renegotiate-Client-TLS13",
4631 config: Config{
4632 MaxVersion: VersionTLS13,
4633 },
4634 renegotiate: 1,
4635 flags: []string{
4636 "-renegotiate-freely",
4637 },
4638 shouldFail: true,
4639 expectedError: ":NO_RENEGOTIATION:",
4640 })
4641
4642 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4643 testCases = append(testCases, testCase{
4644 name: "StrayHelloRequest-TLS13",
4645 config: Config{
4646 MaxVersion: VersionTLS13,
4647 Bugs: ProtocolBugs{
4648 SendHelloRequestBeforeEveryHandshakeMessage: true,
4649 },
4650 },
4651 shouldFail: true,
4652 expectedError: ":UNEXPECTED_MESSAGE:",
4653 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004654}
4655
David Benjamin5e961c12014-11-07 01:48:35 -05004656func addDTLSReplayTests() {
4657 // Test that sequence number replays are detected.
4658 testCases = append(testCases, testCase{
4659 protocol: dtls,
4660 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004661 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004662 replayWrites: true,
4663 })
4664
David Benjamin8e6db492015-07-25 18:29:23 -04004665 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004666 // than the retransmit window.
4667 testCases = append(testCases, testCase{
4668 protocol: dtls,
4669 name: "DTLS-Replay-LargeGaps",
4670 config: Config{
4671 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004672 SequenceNumberMapping: func(in uint64) uint64 {
4673 return in * 127
4674 },
David Benjamin5e961c12014-11-07 01:48:35 -05004675 },
4676 },
David Benjamin8e6db492015-07-25 18:29:23 -04004677 messageCount: 200,
4678 replayWrites: true,
4679 })
4680
4681 // Test the incoming sequence number changing non-monotonically.
4682 testCases = append(testCases, testCase{
4683 protocol: dtls,
4684 name: "DTLS-Replay-NonMonotonic",
4685 config: Config{
4686 Bugs: ProtocolBugs{
4687 SequenceNumberMapping: func(in uint64) uint64 {
4688 return in ^ 31
4689 },
4690 },
4691 },
4692 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004693 replayWrites: true,
4694 })
4695}
4696
Nick Harper60edffd2016-06-21 15:19:24 -07004697var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004698 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004699 id signatureAlgorithm
4700 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004701}{
Nick Harper60edffd2016-06-21 15:19:24 -07004702 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4703 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4704 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4705 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004706 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004707 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4708 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4709 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004710 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4711 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4712 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04004713 // Tests for key types prior to TLS 1.2.
4714 {"RSA", 0, testCertRSA},
4715 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05004716}
4717
Nick Harper60edffd2016-06-21 15:19:24 -07004718const fakeSigAlg1 signatureAlgorithm = 0x2a01
4719const fakeSigAlg2 signatureAlgorithm = 0xff01
4720
4721func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04004722 // Not all ciphers involve a signature. Advertise a list which gives all
4723 // versions a signing cipher.
4724 signingCiphers := []uint16{
4725 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4726 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4727 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
4728 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
4729 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
4730 }
4731
David Benjaminca3d5452016-07-14 12:51:01 -04004732 var allAlgorithms []signatureAlgorithm
4733 for _, alg := range testSignatureAlgorithms {
4734 if alg.id != 0 {
4735 allAlgorithms = append(allAlgorithms, alg.id)
4736 }
4737 }
4738
Nick Harper60edffd2016-06-21 15:19:24 -07004739 // Make sure each signature algorithm works. Include some fake values in
4740 // the list and ensure they're ignored.
4741 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004742 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04004743 if (ver.version < VersionTLS12) != (alg.id == 0) {
4744 continue
4745 }
4746
4747 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
4748 // or remove it in C.
4749 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07004750 continue
4751 }
Nick Harper60edffd2016-06-21 15:19:24 -07004752
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004753 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004754 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004755 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4756 shouldFail = true
4757 }
4758 // RSA-PSS does not exist in TLS 1.2.
4759 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4760 shouldFail = true
4761 }
4762
4763 var signError, verifyError string
4764 if shouldFail {
4765 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4766 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004767 }
David Benjamin000800a2014-11-14 01:43:59 -05004768
David Benjamin1fb125c2016-07-08 18:52:12 -07004769 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004770
David Benjamin7a41d372016-07-09 11:21:54 -07004771 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004772 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07004773 config: Config{
4774 MaxVersion: ver.version,
4775 ClientAuth: RequireAnyClientCert,
4776 VerifySignatureAlgorithms: []signatureAlgorithm{
4777 fakeSigAlg1,
4778 alg.id,
4779 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004780 },
David Benjamin7a41d372016-07-09 11:21:54 -07004781 },
4782 flags: []string{
4783 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4784 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4785 "-enable-all-curves",
4786 },
4787 shouldFail: shouldFail,
4788 expectedError: signError,
4789 expectedPeerSignatureAlgorithm: alg.id,
4790 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004791
David Benjamin7a41d372016-07-09 11:21:54 -07004792 testCases = append(testCases, testCase{
4793 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004794 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07004795 config: Config{
4796 MaxVersion: ver.version,
4797 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4798 SignSignatureAlgorithms: []signatureAlgorithm{
4799 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004800 },
David Benjamin7a41d372016-07-09 11:21:54 -07004801 Bugs: ProtocolBugs{
4802 SkipECDSACurveCheck: shouldFail,
4803 IgnoreSignatureVersionChecks: shouldFail,
4804 // The client won't advertise 1.3-only algorithms after
4805 // version negotiation.
4806 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004807 },
David Benjamin7a41d372016-07-09 11:21:54 -07004808 },
4809 flags: []string{
4810 "-require-any-client-certificate",
4811 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4812 "-enable-all-curves",
4813 },
4814 shouldFail: shouldFail,
4815 expectedError: verifyError,
4816 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004817
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004820 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07004821 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04004822 MaxVersion: ver.version,
4823 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07004824 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004825 fakeSigAlg1,
4826 alg.id,
4827 fakeSigAlg2,
4828 },
4829 },
4830 flags: []string{
4831 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4832 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4833 "-enable-all-curves",
4834 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004835 shouldFail: shouldFail,
4836 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004837 expectedPeerSignatureAlgorithm: alg.id,
4838 })
4839
4840 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004841 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07004842 config: Config{
4843 MaxVersion: ver.version,
4844 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04004845 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07004846 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004847 alg.id,
4848 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004849 Bugs: ProtocolBugs{
4850 SkipECDSACurveCheck: shouldFail,
4851 IgnoreSignatureVersionChecks: shouldFail,
4852 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004853 },
4854 flags: []string{
4855 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4856 "-enable-all-curves",
4857 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004858 shouldFail: shouldFail,
4859 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004860 })
David Benjamin5208fd42016-07-13 21:43:25 -04004861
4862 if !shouldFail {
4863 testCases = append(testCases, testCase{
4864 testType: serverTest,
4865 name: "ClientAuth-InvalidSignature" + suffix,
4866 config: Config{
4867 MaxVersion: ver.version,
4868 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4869 SignSignatureAlgorithms: []signatureAlgorithm{
4870 alg.id,
4871 },
4872 Bugs: ProtocolBugs{
4873 InvalidSignature: true,
4874 },
4875 },
4876 flags: []string{
4877 "-require-any-client-certificate",
4878 "-enable-all-curves",
4879 },
4880 shouldFail: true,
4881 expectedError: ":BAD_SIGNATURE:",
4882 })
4883
4884 testCases = append(testCases, testCase{
4885 name: "ServerAuth-InvalidSignature" + suffix,
4886 config: Config{
4887 MaxVersion: ver.version,
4888 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4889 CipherSuites: signingCiphers,
4890 SignSignatureAlgorithms: []signatureAlgorithm{
4891 alg.id,
4892 },
4893 Bugs: ProtocolBugs{
4894 InvalidSignature: true,
4895 },
4896 },
4897 flags: []string{"-enable-all-curves"},
4898 shouldFail: true,
4899 expectedError: ":BAD_SIGNATURE:",
4900 })
4901 }
David Benjaminca3d5452016-07-14 12:51:01 -04004902
4903 if ver.version >= VersionTLS12 && !shouldFail {
4904 testCases = append(testCases, testCase{
4905 name: "ClientAuth-Sign-Negotiate" + suffix,
4906 config: Config{
4907 MaxVersion: ver.version,
4908 ClientAuth: RequireAnyClientCert,
4909 VerifySignatureAlgorithms: allAlgorithms,
4910 },
4911 flags: []string{
4912 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4913 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4914 "-enable-all-curves",
4915 "-signing-prefs", strconv.Itoa(int(alg.id)),
4916 },
4917 expectedPeerSignatureAlgorithm: alg.id,
4918 })
4919
4920 testCases = append(testCases, testCase{
4921 testType: serverTest,
4922 name: "ServerAuth-Sign-Negotiate" + suffix,
4923 config: Config{
4924 MaxVersion: ver.version,
4925 CipherSuites: signingCiphers,
4926 VerifySignatureAlgorithms: allAlgorithms,
4927 },
4928 flags: []string{
4929 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4930 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4931 "-enable-all-curves",
4932 "-signing-prefs", strconv.Itoa(int(alg.id)),
4933 },
4934 expectedPeerSignatureAlgorithm: alg.id,
4935 })
4936 }
David Benjamin1fb125c2016-07-08 18:52:12 -07004937 }
David Benjamin000800a2014-11-14 01:43:59 -05004938 }
4939
Nick Harper60edffd2016-06-21 15:19:24 -07004940 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004941 //
4942 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004943 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004944 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05004945 config: Config{
4946 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004947 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004948 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004949 signatureECDSAWithP521AndSHA512,
4950 signatureRSAPKCS1WithSHA384,
4951 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004952 },
4953 },
4954 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004957 },
Nick Harper60edffd2016-06-21 15:19:24 -07004958 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004959 })
4960
4961 testCases = append(testCases, testCase{
4962 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004963 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05004964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004965 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004967 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004968 signatureECDSAWithP521AndSHA512,
4969 signatureRSAPKCS1WithSHA384,
4970 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004971 },
4972 },
Nick Harper60edffd2016-06-21 15:19:24 -07004973 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004974 })
4975
David Benjamina95e9f32016-07-08 16:28:04 -07004976 // Test that signature verification takes the key type into account.
4977 //
4978 // TODO(davidben): Test this in TLS 1.3.
4979 testCases = append(testCases, testCase{
4980 testType: serverTest,
4981 name: "Verify-ClientAuth-SignatureType",
4982 config: Config{
4983 MaxVersion: VersionTLS12,
4984 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004985 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004986 signatureRSAPKCS1WithSHA256,
4987 },
4988 Bugs: ProtocolBugs{
4989 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4990 },
4991 },
4992 flags: []string{
4993 "-require-any-client-certificate",
4994 },
4995 shouldFail: true,
4996 expectedError: ":WRONG_SIGNATURE_TYPE:",
4997 })
4998
4999 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005000 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005001 config: Config{
5002 MaxVersion: VersionTLS12,
5003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005004 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005005 signatureRSAPKCS1WithSHA256,
5006 },
5007 Bugs: ProtocolBugs{
5008 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5009 },
5010 },
5011 shouldFail: true,
5012 expectedError: ":WRONG_SIGNATURE_TYPE:",
5013 })
5014
David Benjamin51dd7d62016-07-08 16:07:01 -07005015 // Test that, if the list is missing, the peer falls back to SHA-1 in
5016 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005017 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005018 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005020 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005021 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005022 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005023 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005024 },
5025 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005026 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005027 },
5028 },
5029 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005030 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5031 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005032 },
5033 })
5034
5035 testCases = append(testCases, testCase{
5036 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005037 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005039 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005040 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005041 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005042 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005043 },
5044 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005045 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005046 },
5047 },
5048 })
David Benjamin72dc7832015-03-16 17:49:43 -04005049
David Benjamin51dd7d62016-07-08 16:07:01 -07005050 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005051 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005052 config: Config{
5053 MaxVersion: VersionTLS13,
5054 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005055 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005056 signatureRSAPKCS1WithSHA1,
5057 },
5058 Bugs: ProtocolBugs{
5059 NoSignatureAlgorithms: true,
5060 },
5061 },
5062 flags: []string{
5063 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5064 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5065 },
5066 shouldFail: true,
5067 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5068 })
5069
5070 testCases = append(testCases, testCase{
5071 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005072 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005073 config: Config{
5074 MaxVersion: VersionTLS13,
5075 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005076 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005077 signatureRSAPKCS1WithSHA1,
5078 },
5079 Bugs: ProtocolBugs{
5080 NoSignatureAlgorithms: true,
5081 },
5082 },
5083 shouldFail: true,
5084 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5085 })
5086
David Benjamin72dc7832015-03-16 17:49:43 -04005087 // Test that hash preferences are enforced. BoringSSL defaults to
5088 // rejecting MD5 signatures.
5089 testCases = append(testCases, testCase{
5090 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005091 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005092 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005093 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005094 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005095 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005096 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005097 // Advertise SHA-1 so the handshake will
5098 // proceed, but the shim's preferences will be
5099 // ignored in CertificateVerify generation, so
5100 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005101 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005102 },
5103 Bugs: ProtocolBugs{
5104 IgnorePeerSignatureAlgorithmPreferences: true,
5105 },
5106 },
5107 flags: []string{"-require-any-client-certificate"},
5108 shouldFail: true,
5109 expectedError: ":WRONG_SIGNATURE_TYPE:",
5110 })
5111
5112 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005113 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005115 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005117 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005118 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005119 },
5120 Bugs: ProtocolBugs{
5121 IgnorePeerSignatureAlgorithmPreferences: true,
5122 },
5123 },
5124 shouldFail: true,
5125 expectedError: ":WRONG_SIGNATURE_TYPE:",
5126 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005127
5128 // Test that the agreed upon digest respects the client preferences and
5129 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005130 //
5131 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005132 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005133 name: "NoCommonAlgorithms-Digests",
5134 config: Config{
5135 MaxVersion: VersionTLS12,
5136 ClientAuth: RequireAnyClientCert,
5137 VerifySignatureAlgorithms: []signatureAlgorithm{
5138 signatureRSAPKCS1WithSHA512,
5139 signatureRSAPKCS1WithSHA1,
5140 },
5141 },
5142 flags: []string{
5143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5145 "-digest-prefs", "SHA256",
5146 },
5147 shouldFail: true,
5148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5149 })
5150 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005151 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005153 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005154 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005155 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005156 signatureRSAPKCS1WithSHA512,
5157 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005158 },
5159 },
5160 flags: []string{
5161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005163 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005164 },
David Benjaminca3d5452016-07-14 12:51:01 -04005165 shouldFail: true,
5166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5167 })
5168 testCases = append(testCases, testCase{
5169 name: "NoCommonAlgorithms-TLS13",
5170 config: Config{
5171 MaxVersion: VersionTLS13,
5172 ClientAuth: RequireAnyClientCert,
5173 VerifySignatureAlgorithms: []signatureAlgorithm{
5174 signatureRSAPSSWithSHA512,
5175 signatureRSAPSSWithSHA384,
5176 },
5177 },
5178 flags: []string{
5179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5181 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5182 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005183 shouldFail: true,
5184 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005185 })
5186 testCases = append(testCases, testCase{
5187 name: "Agree-Digest-SHA256",
5188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005189 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005190 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005191 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005192 signatureRSAPKCS1WithSHA1,
5193 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005194 },
5195 },
5196 flags: []string{
5197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005199 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005200 },
Nick Harper60edffd2016-06-21 15:19:24 -07005201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005202 })
5203 testCases = append(testCases, testCase{
5204 name: "Agree-Digest-SHA1",
5205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005206 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005209 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005210 },
5211 },
5212 flags: []string{
5213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005215 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005216 },
Nick Harper60edffd2016-06-21 15:19:24 -07005217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005218 })
5219 testCases = append(testCases, testCase{
5220 name: "Agree-Digest-Default",
5221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005222 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005223 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005225 signatureRSAPKCS1WithSHA256,
5226 signatureECDSAWithP256AndSHA256,
5227 signatureRSAPKCS1WithSHA1,
5228 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005229 },
5230 },
5231 flags: []string{
5232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5234 },
Nick Harper60edffd2016-06-21 15:19:24 -07005235 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005236 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005237
David Benjaminca3d5452016-07-14 12:51:01 -04005238 // Test that the signing preference list may include extra algorithms
5239 // without negotiation problems.
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "FilterExtraAlgorithms",
5243 config: Config{
5244 MaxVersion: VersionTLS12,
5245 VerifySignatureAlgorithms: []signatureAlgorithm{
5246 signatureRSAPKCS1WithSHA256,
5247 },
5248 },
5249 flags: []string{
5250 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5251 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5252 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5253 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5254 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5255 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5256 },
5257 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5258 })
5259
David Benjamin4c3ddf72016-06-29 18:13:53 -04005260 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5261 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005262 testCases = append(testCases, testCase{
5263 name: "CheckLeafCurve",
5264 config: Config{
5265 MaxVersion: VersionTLS12,
5266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005267 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005268 },
5269 flags: []string{"-p384-only"},
5270 shouldFail: true,
5271 expectedError: ":BAD_ECC_CERT:",
5272 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005273
5274 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5275 testCases = append(testCases, testCase{
5276 name: "CheckLeafCurve-TLS13",
5277 config: Config{
5278 MaxVersion: VersionTLS13,
5279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5280 Certificates: []Certificate{ecdsaP256Certificate},
5281 },
5282 flags: []string{"-p384-only"},
5283 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005284
5285 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5286 testCases = append(testCases, testCase{
5287 name: "ECDSACurveMismatch-Verify-TLS12",
5288 config: Config{
5289 MaxVersion: VersionTLS12,
5290 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5291 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005292 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005293 signatureECDSAWithP384AndSHA384,
5294 },
5295 },
5296 })
5297
5298 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5299 testCases = append(testCases, testCase{
5300 name: "ECDSACurveMismatch-Verify-TLS13",
5301 config: Config{
5302 MaxVersion: VersionTLS13,
5303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5304 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005305 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005306 signatureECDSAWithP384AndSHA384,
5307 },
5308 Bugs: ProtocolBugs{
5309 SkipECDSACurveCheck: true,
5310 },
5311 },
5312 shouldFail: true,
5313 expectedError: ":WRONG_SIGNATURE_TYPE:",
5314 })
5315
5316 // Signature algorithm selection in TLS 1.3 should take the curve into
5317 // account.
5318 testCases = append(testCases, testCase{
5319 testType: serverTest,
5320 name: "ECDSACurveMismatch-Sign-TLS13",
5321 config: Config{
5322 MaxVersion: VersionTLS13,
5323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005324 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005325 signatureECDSAWithP384AndSHA384,
5326 signatureECDSAWithP256AndSHA256,
5327 },
5328 },
5329 flags: []string{
5330 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5331 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5332 },
5333 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5334 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005335
5336 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5337 // server does not attempt to sign in that case.
5338 testCases = append(testCases, testCase{
5339 testType: serverTest,
5340 name: "RSA-PSS-Large",
5341 config: Config{
5342 MaxVersion: VersionTLS13,
5343 VerifySignatureAlgorithms: []signatureAlgorithm{
5344 signatureRSAPSSWithSHA512,
5345 },
5346 },
5347 flags: []string{
5348 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5349 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5350 },
5351 shouldFail: true,
5352 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5353 })
David Benjamin000800a2014-11-14 01:43:59 -05005354}
5355
David Benjamin83f90402015-01-27 01:09:43 -05005356// timeouts is the retransmit schedule for BoringSSL. It doubles and
5357// caps at 60 seconds. On the 13th timeout, it gives up.
5358var timeouts = []time.Duration{
5359 1 * time.Second,
5360 2 * time.Second,
5361 4 * time.Second,
5362 8 * time.Second,
5363 16 * time.Second,
5364 32 * time.Second,
5365 60 * time.Second,
5366 60 * time.Second,
5367 60 * time.Second,
5368 60 * time.Second,
5369 60 * time.Second,
5370 60 * time.Second,
5371 60 * time.Second,
5372}
5373
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005374// shortTimeouts is an alternate set of timeouts which would occur if the
5375// initial timeout duration was set to 250ms.
5376var shortTimeouts = []time.Duration{
5377 250 * time.Millisecond,
5378 500 * time.Millisecond,
5379 1 * time.Second,
5380 2 * time.Second,
5381 4 * time.Second,
5382 8 * time.Second,
5383 16 * time.Second,
5384 32 * time.Second,
5385 60 * time.Second,
5386 60 * time.Second,
5387 60 * time.Second,
5388 60 * time.Second,
5389 60 * time.Second,
5390}
5391
David Benjamin83f90402015-01-27 01:09:43 -05005392func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005393 // These tests work by coordinating some behavior on both the shim and
5394 // the runner.
5395 //
5396 // TimeoutSchedule configures the runner to send a series of timeout
5397 // opcodes to the shim (see packetAdaptor) immediately before reading
5398 // each peer handshake flight N. The timeout opcode both simulates a
5399 // timeout in the shim and acts as a synchronization point to help the
5400 // runner bracket each handshake flight.
5401 //
5402 // We assume the shim does not read from the channel eagerly. It must
5403 // first wait until it has sent flight N and is ready to receive
5404 // handshake flight N+1. At this point, it will process the timeout
5405 // opcode. It must then immediately respond with a timeout ACK and act
5406 // as if the shim was idle for the specified amount of time.
5407 //
5408 // The runner then drops all packets received before the ACK and
5409 // continues waiting for flight N. This ordering results in one attempt
5410 // at sending flight N to be dropped. For the test to complete, the
5411 // shim must send flight N again, testing that the shim implements DTLS
5412 // retransmit on a timeout.
5413
David Benjamin4c3ddf72016-06-29 18:13:53 -04005414 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5415 // likely be more epochs to cross and the final message's retransmit may
5416 // be more complex.
5417
David Benjamin585d7a42016-06-02 14:58:00 -04005418 for _, async := range []bool{true, false} {
5419 var tests []testCase
5420
5421 // Test that this is indeed the timeout schedule. Stress all
5422 // four patterns of handshake.
5423 for i := 1; i < len(timeouts); i++ {
5424 number := strconv.Itoa(i)
5425 tests = append(tests, testCase{
5426 protocol: dtls,
5427 name: "DTLS-Retransmit-Client-" + number,
5428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005429 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005430 Bugs: ProtocolBugs{
5431 TimeoutSchedule: timeouts[:i],
5432 },
5433 },
5434 resumeSession: true,
5435 })
5436 tests = append(tests, testCase{
5437 protocol: dtls,
5438 testType: serverTest,
5439 name: "DTLS-Retransmit-Server-" + number,
5440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005441 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005442 Bugs: ProtocolBugs{
5443 TimeoutSchedule: timeouts[:i],
5444 },
5445 },
5446 resumeSession: true,
5447 })
5448 }
5449
5450 // Test that exceeding the timeout schedule hits a read
5451 // timeout.
5452 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005453 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005454 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005456 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005457 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005458 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005459 },
5460 },
5461 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005462 shouldFail: true,
5463 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005464 })
David Benjamin585d7a42016-06-02 14:58:00 -04005465
5466 if async {
5467 // Test that timeout handling has a fudge factor, due to API
5468 // problems.
5469 tests = append(tests, testCase{
5470 protocol: dtls,
5471 name: "DTLS-Retransmit-Fudge",
5472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005473 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005474 Bugs: ProtocolBugs{
5475 TimeoutSchedule: []time.Duration{
5476 timeouts[0] - 10*time.Millisecond,
5477 },
5478 },
5479 },
5480 resumeSession: true,
5481 })
5482 }
5483
5484 // Test that the final Finished retransmitting isn't
5485 // duplicated if the peer badly fragments everything.
5486 tests = append(tests, testCase{
5487 testType: serverTest,
5488 protocol: dtls,
5489 name: "DTLS-Retransmit-Fragmented",
5490 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005491 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005492 Bugs: ProtocolBugs{
5493 TimeoutSchedule: []time.Duration{timeouts[0]},
5494 MaxHandshakeRecordLength: 2,
5495 },
5496 },
5497 })
5498
5499 // Test the timeout schedule when a shorter initial timeout duration is set.
5500 tests = append(tests, testCase{
5501 protocol: dtls,
5502 name: "DTLS-Retransmit-Short-Client",
5503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005504 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005505 Bugs: ProtocolBugs{
5506 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5507 },
5508 },
5509 resumeSession: true,
5510 flags: []string{"-initial-timeout-duration-ms", "250"},
5511 })
5512 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005513 protocol: dtls,
5514 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005515 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005517 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005518 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005519 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005520 },
5521 },
5522 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005523 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005524 })
David Benjamin585d7a42016-06-02 14:58:00 -04005525
5526 for _, test := range tests {
5527 if async {
5528 test.name += "-Async"
5529 test.flags = append(test.flags, "-async")
5530 }
5531
5532 testCases = append(testCases, test)
5533 }
David Benjamin83f90402015-01-27 01:09:43 -05005534 }
David Benjamin83f90402015-01-27 01:09:43 -05005535}
5536
David Benjaminc565ebb2015-04-03 04:06:36 -04005537func addExportKeyingMaterialTests() {
5538 for _, vers := range tlsVersions {
5539 if vers.version == VersionSSL30 {
5540 continue
5541 }
5542 testCases = append(testCases, testCase{
5543 name: "ExportKeyingMaterial-" + vers.name,
5544 config: Config{
5545 MaxVersion: vers.version,
5546 },
5547 exportKeyingMaterial: 1024,
5548 exportLabel: "label",
5549 exportContext: "context",
5550 useExportContext: true,
5551 })
5552 testCases = append(testCases, testCase{
5553 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5554 config: Config{
5555 MaxVersion: vers.version,
5556 },
5557 exportKeyingMaterial: 1024,
5558 })
5559 testCases = append(testCases, testCase{
5560 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5561 config: Config{
5562 MaxVersion: vers.version,
5563 },
5564 exportKeyingMaterial: 1024,
5565 useExportContext: true,
5566 })
5567 testCases = append(testCases, testCase{
5568 name: "ExportKeyingMaterial-Small-" + vers.name,
5569 config: Config{
5570 MaxVersion: vers.version,
5571 },
5572 exportKeyingMaterial: 1,
5573 exportLabel: "label",
5574 exportContext: "context",
5575 useExportContext: true,
5576 })
5577 }
5578 testCases = append(testCases, testCase{
5579 name: "ExportKeyingMaterial-SSL3",
5580 config: Config{
5581 MaxVersion: VersionSSL30,
5582 },
5583 exportKeyingMaterial: 1024,
5584 exportLabel: "label",
5585 exportContext: "context",
5586 useExportContext: true,
5587 shouldFail: true,
5588 expectedError: "failed to export keying material",
5589 })
5590}
5591
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005592func addTLSUniqueTests() {
5593 for _, isClient := range []bool{false, true} {
5594 for _, isResumption := range []bool{false, true} {
5595 for _, hasEMS := range []bool{false, true} {
5596 var suffix string
5597 if isResumption {
5598 suffix = "Resume-"
5599 } else {
5600 suffix = "Full-"
5601 }
5602
5603 if hasEMS {
5604 suffix += "EMS-"
5605 } else {
5606 suffix += "NoEMS-"
5607 }
5608
5609 if isClient {
5610 suffix += "Client"
5611 } else {
5612 suffix += "Server"
5613 }
5614
5615 test := testCase{
5616 name: "TLSUnique-" + suffix,
5617 testTLSUnique: true,
5618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005619 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005620 Bugs: ProtocolBugs{
5621 NoExtendedMasterSecret: !hasEMS,
5622 },
5623 },
5624 }
5625
5626 if isResumption {
5627 test.resumeSession = true
5628 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005629 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005630 Bugs: ProtocolBugs{
5631 NoExtendedMasterSecret: !hasEMS,
5632 },
5633 }
5634 }
5635
5636 if isResumption && !hasEMS {
5637 test.shouldFail = true
5638 test.expectedError = "failed to get tls-unique"
5639 }
5640
5641 testCases = append(testCases, test)
5642 }
5643 }
5644 }
5645}
5646
Adam Langley09505632015-07-30 18:10:13 -07005647func addCustomExtensionTests() {
5648 expectedContents := "custom extension"
5649 emptyString := ""
5650
David Benjamin4c3ddf72016-06-29 18:13:53 -04005651 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005652 for _, isClient := range []bool{false, true} {
5653 suffix := "Server"
5654 flag := "-enable-server-custom-extension"
5655 testType := serverTest
5656 if isClient {
5657 suffix = "Client"
5658 flag = "-enable-client-custom-extension"
5659 testType = clientTest
5660 }
5661
5662 testCases = append(testCases, testCase{
5663 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005664 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005665 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005666 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005667 Bugs: ProtocolBugs{
5668 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005669 ExpectedCustomExtension: &expectedContents,
5670 },
5671 },
5672 flags: []string{flag},
5673 })
5674
5675 // If the parse callback fails, the handshake should also fail.
5676 testCases = append(testCases, testCase{
5677 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005678 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005680 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005681 Bugs: ProtocolBugs{
5682 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005683 ExpectedCustomExtension: &expectedContents,
5684 },
5685 },
David Benjamin399e7c92015-07-30 23:01:27 -04005686 flags: []string{flag},
5687 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005688 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5689 })
5690
5691 // If the add callback fails, the handshake should also fail.
5692 testCases = append(testCases, testCase{
5693 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005694 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005695 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005696 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005697 Bugs: ProtocolBugs{
5698 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005699 ExpectedCustomExtension: &expectedContents,
5700 },
5701 },
David Benjamin399e7c92015-07-30 23:01:27 -04005702 flags: []string{flag, "-custom-extension-fail-add"},
5703 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005704 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5705 })
5706
5707 // If the add callback returns zero, no extension should be
5708 // added.
5709 skipCustomExtension := expectedContents
5710 if isClient {
5711 // For the case where the client skips sending the
5712 // custom extension, the server must not “echo” it.
5713 skipCustomExtension = ""
5714 }
5715 testCases = append(testCases, testCase{
5716 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005717 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005719 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005720 Bugs: ProtocolBugs{
5721 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005722 ExpectedCustomExtension: &emptyString,
5723 },
5724 },
5725 flags: []string{flag, "-custom-extension-skip"},
5726 })
5727 }
5728
5729 // The custom extension add callback should not be called if the client
5730 // doesn't send the extension.
5731 testCases = append(testCases, testCase{
5732 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005733 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005734 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005735 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005736 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005737 ExpectedCustomExtension: &emptyString,
5738 },
5739 },
5740 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5741 })
Adam Langley2deb9842015-08-07 11:15:37 -07005742
5743 // Test an unknown extension from the server.
5744 testCases = append(testCases, testCase{
5745 testType: clientTest,
5746 name: "UnknownExtension-Client",
5747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005748 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005749 Bugs: ProtocolBugs{
5750 CustomExtension: expectedContents,
5751 },
5752 },
5753 shouldFail: true,
5754 expectedError: ":UNEXPECTED_EXTENSION:",
5755 })
Adam Langley09505632015-07-30 18:10:13 -07005756}
5757
David Benjaminb36a3952015-12-01 18:53:13 -05005758func addRSAClientKeyExchangeTests() {
5759 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5760 testCases = append(testCases, testCase{
5761 testType: serverTest,
5762 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5763 config: Config{
5764 // Ensure the ClientHello version and final
5765 // version are different, to detect if the
5766 // server uses the wrong one.
5767 MaxVersion: VersionTLS11,
5768 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5769 Bugs: ProtocolBugs{
5770 BadRSAClientKeyExchange: bad,
5771 },
5772 },
5773 shouldFail: true,
5774 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5775 })
5776 }
5777}
5778
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005779var testCurves = []struct {
5780 name string
5781 id CurveID
5782}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005783 {"P-256", CurveP256},
5784 {"P-384", CurveP384},
5785 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005786 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005787}
5788
5789func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005790 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005791 for _, curve := range testCurves {
5792 testCases = append(testCases, testCase{
5793 name: "CurveTest-Client-" + curve.name,
5794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005795 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5797 CurvePreferences: []CurveID{curve.id},
5798 },
5799 flags: []string{"-enable-all-curves"},
5800 })
5801 testCases = append(testCases, testCase{
5802 testType: serverTest,
5803 name: "CurveTest-Server-" + curve.name,
5804 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005805 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5807 CurvePreferences: []CurveID{curve.id},
5808 },
5809 flags: []string{"-enable-all-curves"},
5810 })
5811 }
David Benjamin241ae832016-01-15 03:04:54 -05005812
5813 // The server must be tolerant to bogus curves.
5814 const bogusCurve = 0x1234
5815 testCases = append(testCases, testCase{
5816 testType: serverTest,
5817 name: "UnknownCurve",
5818 config: Config{
5819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5820 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5821 },
5822 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005823
5824 // The server must not consider ECDHE ciphers when there are no
5825 // supported curves.
5826 testCases = append(testCases, testCase{
5827 testType: serverTest,
5828 name: "NoSupportedCurves",
5829 config: Config{
5830 // TODO(davidben): Add a TLS 1.3 version of this.
5831 MaxVersion: VersionTLS12,
5832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5833 Bugs: ProtocolBugs{
5834 NoSupportedCurves: true,
5835 },
5836 },
5837 shouldFail: true,
5838 expectedError: ":NO_SHARED_CIPHER:",
5839 })
5840
5841 // The server must fall back to another cipher when there are no
5842 // supported curves.
5843 testCases = append(testCases, testCase{
5844 testType: serverTest,
5845 name: "NoCommonCurves",
5846 config: Config{
5847 MaxVersion: VersionTLS12,
5848 CipherSuites: []uint16{
5849 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5850 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5851 },
5852 CurvePreferences: []CurveID{CurveP224},
5853 },
5854 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5855 })
5856
5857 // The client must reject bogus curves and disabled curves.
5858 testCases = append(testCases, testCase{
5859 name: "BadECDHECurve",
5860 config: Config{
5861 // TODO(davidben): Add a TLS 1.3 version of this.
5862 MaxVersion: VersionTLS12,
5863 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5864 Bugs: ProtocolBugs{
5865 SendCurve: bogusCurve,
5866 },
5867 },
5868 shouldFail: true,
5869 expectedError: ":WRONG_CURVE:",
5870 })
5871
5872 testCases = append(testCases, testCase{
5873 name: "UnsupportedCurve",
5874 config: Config{
5875 // TODO(davidben): Add a TLS 1.3 version of this.
5876 MaxVersion: VersionTLS12,
5877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5878 CurvePreferences: []CurveID{CurveP256},
5879 Bugs: ProtocolBugs{
5880 IgnorePeerCurvePreferences: true,
5881 },
5882 },
5883 flags: []string{"-p384-only"},
5884 shouldFail: true,
5885 expectedError: ":WRONG_CURVE:",
5886 })
5887
5888 // Test invalid curve points.
5889 testCases = append(testCases, testCase{
5890 name: "InvalidECDHPoint-Client",
5891 config: Config{
5892 // TODO(davidben): Add a TLS 1.3 version of this test.
5893 MaxVersion: VersionTLS12,
5894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5895 CurvePreferences: []CurveID{CurveP256},
5896 Bugs: ProtocolBugs{
5897 InvalidECDHPoint: true,
5898 },
5899 },
5900 shouldFail: true,
5901 expectedError: ":INVALID_ENCODING:",
5902 })
5903 testCases = append(testCases, testCase{
5904 testType: serverTest,
5905 name: "InvalidECDHPoint-Server",
5906 config: Config{
5907 // TODO(davidben): Add a TLS 1.3 version of this test.
5908 MaxVersion: VersionTLS12,
5909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5910 CurvePreferences: []CurveID{CurveP256},
5911 Bugs: ProtocolBugs{
5912 InvalidECDHPoint: true,
5913 },
5914 },
5915 shouldFail: true,
5916 expectedError: ":INVALID_ENCODING:",
5917 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005918}
5919
Matt Braithwaite54217e42016-06-13 13:03:47 -07005920func addCECPQ1Tests() {
5921 testCases = append(testCases, testCase{
5922 testType: clientTest,
5923 name: "CECPQ1-Client-BadX25519Part",
5924 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005925 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005926 MinVersion: VersionTLS12,
5927 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5928 Bugs: ProtocolBugs{
5929 CECPQ1BadX25519Part: true,
5930 },
5931 },
5932 flags: []string{"-cipher", "kCECPQ1"},
5933 shouldFail: true,
5934 expectedLocalError: "local error: bad record MAC",
5935 })
5936 testCases = append(testCases, testCase{
5937 testType: clientTest,
5938 name: "CECPQ1-Client-BadNewhopePart",
5939 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005940 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005941 MinVersion: VersionTLS12,
5942 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5943 Bugs: ProtocolBugs{
5944 CECPQ1BadNewhopePart: true,
5945 },
5946 },
5947 flags: []string{"-cipher", "kCECPQ1"},
5948 shouldFail: true,
5949 expectedLocalError: "local error: bad record MAC",
5950 })
5951 testCases = append(testCases, testCase{
5952 testType: serverTest,
5953 name: "CECPQ1-Server-BadX25519Part",
5954 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005955 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005956 MinVersion: VersionTLS12,
5957 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5958 Bugs: ProtocolBugs{
5959 CECPQ1BadX25519Part: true,
5960 },
5961 },
5962 flags: []string{"-cipher", "kCECPQ1"},
5963 shouldFail: true,
5964 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5965 })
5966 testCases = append(testCases, testCase{
5967 testType: serverTest,
5968 name: "CECPQ1-Server-BadNewhopePart",
5969 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005970 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005971 MinVersion: VersionTLS12,
5972 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5973 Bugs: ProtocolBugs{
5974 CECPQ1BadNewhopePart: true,
5975 },
5976 },
5977 flags: []string{"-cipher", "kCECPQ1"},
5978 shouldFail: true,
5979 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5980 })
5981}
5982
David Benjamin4cc36ad2015-12-19 14:23:26 -05005983func addKeyExchangeInfoTests() {
5984 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005985 name: "KeyExchangeInfo-DHE-Client",
5986 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005987 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005988 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5989 Bugs: ProtocolBugs{
5990 // This is a 1234-bit prime number, generated
5991 // with:
5992 // openssl gendh 1234 | openssl asn1parse -i
5993 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5994 },
5995 },
David Benjamin9e68f192016-06-30 14:55:33 -04005996 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005997 })
5998 testCases = append(testCases, testCase{
5999 testType: serverTest,
6000 name: "KeyExchangeInfo-DHE-Server",
6001 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006002 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006003 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6004 },
6005 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006006 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006007 })
6008
Nick Harper1fd39d82016-06-14 18:14:35 -07006009 // TODO(davidben): Add TLS 1.3 versions of these tests once the
6010 // handshake is separate.
6011
David Benjamin4cc36ad2015-12-19 14:23:26 -05006012 testCases = append(testCases, testCase{
6013 name: "KeyExchangeInfo-ECDHE-Client",
6014 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006015 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006016 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6017 CurvePreferences: []CurveID{CurveX25519},
6018 },
David Benjamin9e68f192016-06-30 14:55:33 -04006019 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006020 })
6021 testCases = append(testCases, testCase{
6022 testType: serverTest,
6023 name: "KeyExchangeInfo-ECDHE-Server",
6024 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006025 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6027 CurvePreferences: []CurveID{CurveX25519},
6028 },
David Benjamin9e68f192016-06-30 14:55:33 -04006029 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006030 })
6031}
6032
David Benjaminc9ae27c2016-06-24 22:56:37 -04006033func addTLS13RecordTests() {
6034 testCases = append(testCases, testCase{
6035 name: "TLS13-RecordPadding",
6036 config: Config{
6037 MaxVersion: VersionTLS13,
6038 MinVersion: VersionTLS13,
6039 Bugs: ProtocolBugs{
6040 RecordPadding: 10,
6041 },
6042 },
6043 })
6044
6045 testCases = append(testCases, testCase{
6046 name: "TLS13-EmptyRecords",
6047 config: Config{
6048 MaxVersion: VersionTLS13,
6049 MinVersion: VersionTLS13,
6050 Bugs: ProtocolBugs{
6051 OmitRecordContents: true,
6052 },
6053 },
6054 shouldFail: true,
6055 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6056 })
6057
6058 testCases = append(testCases, testCase{
6059 name: "TLS13-OnlyPadding",
6060 config: Config{
6061 MaxVersion: VersionTLS13,
6062 MinVersion: VersionTLS13,
6063 Bugs: ProtocolBugs{
6064 OmitRecordContents: true,
6065 RecordPadding: 10,
6066 },
6067 },
6068 shouldFail: true,
6069 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6070 })
6071
6072 testCases = append(testCases, testCase{
6073 name: "TLS13-WrongOuterRecord",
6074 config: Config{
6075 MaxVersion: VersionTLS13,
6076 MinVersion: VersionTLS13,
6077 Bugs: ProtocolBugs{
6078 OuterRecordType: recordTypeHandshake,
6079 },
6080 },
6081 shouldFail: true,
6082 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6083 })
6084}
6085
David Benjamin82261be2016-07-07 14:32:50 -07006086func addChangeCipherSpecTests() {
6087 // Test missing ChangeCipherSpecs.
6088 testCases = append(testCases, testCase{
6089 name: "SkipChangeCipherSpec-Client",
6090 config: Config{
6091 MaxVersion: VersionTLS12,
6092 Bugs: ProtocolBugs{
6093 SkipChangeCipherSpec: true,
6094 },
6095 },
6096 shouldFail: true,
6097 expectedError: ":UNEXPECTED_RECORD:",
6098 })
6099 testCases = append(testCases, testCase{
6100 testType: serverTest,
6101 name: "SkipChangeCipherSpec-Server",
6102 config: Config{
6103 MaxVersion: VersionTLS12,
6104 Bugs: ProtocolBugs{
6105 SkipChangeCipherSpec: true,
6106 },
6107 },
6108 shouldFail: true,
6109 expectedError: ":UNEXPECTED_RECORD:",
6110 })
6111 testCases = append(testCases, testCase{
6112 testType: serverTest,
6113 name: "SkipChangeCipherSpec-Server-NPN",
6114 config: Config{
6115 MaxVersion: VersionTLS12,
6116 NextProtos: []string{"bar"},
6117 Bugs: ProtocolBugs{
6118 SkipChangeCipherSpec: true,
6119 },
6120 },
6121 flags: []string{
6122 "-advertise-npn", "\x03foo\x03bar\x03baz",
6123 },
6124 shouldFail: true,
6125 expectedError: ":UNEXPECTED_RECORD:",
6126 })
6127
6128 // Test synchronization between the handshake and ChangeCipherSpec.
6129 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6130 // rejected. Test both with and without handshake packing to handle both
6131 // when the partial post-CCS message is in its own record and when it is
6132 // attached to the pre-CCS message.
6133 //
6134 // TODO(davidben): Fix and test DTLS as well.
6135 for _, packed := range []bool{false, true} {
6136 var suffix string
6137 if packed {
6138 suffix = "-Packed"
6139 }
6140
6141 testCases = append(testCases, testCase{
6142 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6143 config: Config{
6144 MaxVersion: VersionTLS12,
6145 Bugs: ProtocolBugs{
6146 FragmentAcrossChangeCipherSpec: true,
6147 PackHandshakeFlight: packed,
6148 },
6149 },
6150 shouldFail: true,
6151 expectedError: ":UNEXPECTED_RECORD:",
6152 })
6153 testCases = append(testCases, testCase{
6154 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6155 config: Config{
6156 MaxVersion: VersionTLS12,
6157 },
6158 resumeSession: true,
6159 resumeConfig: &Config{
6160 MaxVersion: VersionTLS12,
6161 Bugs: ProtocolBugs{
6162 FragmentAcrossChangeCipherSpec: true,
6163 PackHandshakeFlight: packed,
6164 },
6165 },
6166 shouldFail: true,
6167 expectedError: ":UNEXPECTED_RECORD:",
6168 })
6169 testCases = append(testCases, testCase{
6170 testType: serverTest,
6171 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6172 config: Config{
6173 MaxVersion: VersionTLS12,
6174 Bugs: ProtocolBugs{
6175 FragmentAcrossChangeCipherSpec: true,
6176 PackHandshakeFlight: packed,
6177 },
6178 },
6179 shouldFail: true,
6180 expectedError: ":UNEXPECTED_RECORD:",
6181 })
6182 testCases = append(testCases, testCase{
6183 testType: serverTest,
6184 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6185 config: Config{
6186 MaxVersion: VersionTLS12,
6187 },
6188 resumeSession: true,
6189 resumeConfig: &Config{
6190 MaxVersion: VersionTLS12,
6191 Bugs: ProtocolBugs{
6192 FragmentAcrossChangeCipherSpec: true,
6193 PackHandshakeFlight: packed,
6194 },
6195 },
6196 shouldFail: true,
6197 expectedError: ":UNEXPECTED_RECORD:",
6198 })
6199 testCases = append(testCases, testCase{
6200 testType: serverTest,
6201 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6202 config: Config{
6203 MaxVersion: VersionTLS12,
6204 NextProtos: []string{"bar"},
6205 Bugs: ProtocolBugs{
6206 FragmentAcrossChangeCipherSpec: true,
6207 PackHandshakeFlight: packed,
6208 },
6209 },
6210 flags: []string{
6211 "-advertise-npn", "\x03foo\x03bar\x03baz",
6212 },
6213 shouldFail: true,
6214 expectedError: ":UNEXPECTED_RECORD:",
6215 })
6216 }
6217
6218 // Test that early ChangeCipherSpecs are handled correctly.
6219 testCases = append(testCases, testCase{
6220 testType: serverTest,
6221 name: "EarlyChangeCipherSpec-server-1",
6222 config: Config{
6223 MaxVersion: VersionTLS12,
6224 Bugs: ProtocolBugs{
6225 EarlyChangeCipherSpec: 1,
6226 },
6227 },
6228 shouldFail: true,
6229 expectedError: ":UNEXPECTED_RECORD:",
6230 })
6231 testCases = append(testCases, testCase{
6232 testType: serverTest,
6233 name: "EarlyChangeCipherSpec-server-2",
6234 config: Config{
6235 MaxVersion: VersionTLS12,
6236 Bugs: ProtocolBugs{
6237 EarlyChangeCipherSpec: 2,
6238 },
6239 },
6240 shouldFail: true,
6241 expectedError: ":UNEXPECTED_RECORD:",
6242 })
6243 testCases = append(testCases, testCase{
6244 protocol: dtls,
6245 name: "StrayChangeCipherSpec",
6246 config: Config{
6247 // TODO(davidben): Once DTLS 1.3 exists, test
6248 // that stray ChangeCipherSpec messages are
6249 // rejected.
6250 MaxVersion: VersionTLS12,
6251 Bugs: ProtocolBugs{
6252 StrayChangeCipherSpec: true,
6253 },
6254 },
6255 })
6256
6257 // Test that the contents of ChangeCipherSpec are checked.
6258 testCases = append(testCases, testCase{
6259 name: "BadChangeCipherSpec-1",
6260 config: Config{
6261 MaxVersion: VersionTLS12,
6262 Bugs: ProtocolBugs{
6263 BadChangeCipherSpec: []byte{2},
6264 },
6265 },
6266 shouldFail: true,
6267 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6268 })
6269 testCases = append(testCases, testCase{
6270 name: "BadChangeCipherSpec-2",
6271 config: Config{
6272 MaxVersion: VersionTLS12,
6273 Bugs: ProtocolBugs{
6274 BadChangeCipherSpec: []byte{1, 1},
6275 },
6276 },
6277 shouldFail: true,
6278 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6279 })
6280 testCases = append(testCases, testCase{
6281 protocol: dtls,
6282 name: "BadChangeCipherSpec-DTLS-1",
6283 config: Config{
6284 MaxVersion: VersionTLS12,
6285 Bugs: ProtocolBugs{
6286 BadChangeCipherSpec: []byte{2},
6287 },
6288 },
6289 shouldFail: true,
6290 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6291 })
6292 testCases = append(testCases, testCase{
6293 protocol: dtls,
6294 name: "BadChangeCipherSpec-DTLS-2",
6295 config: Config{
6296 MaxVersion: VersionTLS12,
6297 Bugs: ProtocolBugs{
6298 BadChangeCipherSpec: []byte{1, 1},
6299 },
6300 },
6301 shouldFail: true,
6302 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6303 })
6304}
6305
Adam Langley7c803a62015-06-15 15:35:05 -07006306func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006307 defer wg.Done()
6308
6309 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006310 var err error
6311
6312 if *mallocTest < 0 {
6313 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006314 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006315 } else {
6316 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6317 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006318 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006319 if err != nil {
6320 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6321 }
6322 break
6323 }
6324 }
6325 }
Adam Langley95c29f32014-06-20 12:00:00 -07006326 statusChan <- statusMsg{test: test, err: err}
6327 }
6328}
6329
6330type statusMsg struct {
6331 test *testCase
6332 started bool
6333 err error
6334}
6335
David Benjamin5f237bc2015-02-11 17:14:15 -05006336func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006337 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006338
David Benjamin5f237bc2015-02-11 17:14:15 -05006339 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006340 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006341 if !*pipe {
6342 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006343 var erase string
6344 for i := 0; i < lineLen; i++ {
6345 erase += "\b \b"
6346 }
6347 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006348 }
6349
Adam Langley95c29f32014-06-20 12:00:00 -07006350 if msg.started {
6351 started++
6352 } else {
6353 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006354
6355 if msg.err != nil {
6356 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6357 failed++
6358 testOutput.addResult(msg.test.name, "FAIL")
6359 } else {
6360 if *pipe {
6361 // Print each test instead of a status line.
6362 fmt.Printf("PASSED (%s)\n", msg.test.name)
6363 }
6364 testOutput.addResult(msg.test.name, "PASS")
6365 }
Adam Langley95c29f32014-06-20 12:00:00 -07006366 }
6367
David Benjamin5f237bc2015-02-11 17:14:15 -05006368 if !*pipe {
6369 // Print a new status line.
6370 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6371 lineLen = len(line)
6372 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006373 }
Adam Langley95c29f32014-06-20 12:00:00 -07006374 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006375
6376 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006377}
6378
6379func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006380 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006381 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006382 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006383
Adam Langley7c803a62015-06-15 15:35:05 -07006384 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006385 addCipherSuiteTests()
6386 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006387 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006388 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006389 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006390 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006391 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006392 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006393 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006394 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006395 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006396 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006397 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006398 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006399 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006400 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006401 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006402 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006403 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006404 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006405 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006406 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006407 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006408 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006409 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006410
6411 var wg sync.WaitGroup
6412
Adam Langley7c803a62015-06-15 15:35:05 -07006413 statusChan := make(chan statusMsg, *numWorkers)
6414 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006415 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006416
David Benjamin025b3d32014-07-01 19:53:04 -04006417 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006418
Adam Langley7c803a62015-06-15 15:35:05 -07006419 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006420 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006421 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006422 }
6423
David Benjamin270f0a72016-03-17 14:41:36 -04006424 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006425 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006426 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006427 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006428 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006429 }
6430 }
David Benjamin270f0a72016-03-17 14:41:36 -04006431 if !foundTest {
6432 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6433 os.Exit(1)
6434 }
Adam Langley95c29f32014-06-20 12:00:00 -07006435
6436 close(testChan)
6437 wg.Wait()
6438 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006439 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006440
6441 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006442
6443 if *jsonOutput != "" {
6444 if err := testOutput.writeTo(*jsonOutput); err != nil {
6445 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6446 }
6447 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006448
6449 if !testOutput.allPassed {
6450 os.Exit(1)
6451 }
Adam Langley95c29f32014-06-20 12:00:00 -07006452}