blob: b6e7ac7940667709c67a988a4bf9f63dc826e35d [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 Benjamin3ed59772016-03-08 12:50:21 -050056 timeout = flag.Int("timeout", 15, "The number of seconds to wait for a read or write to bssl_shim.")
Adam Langley69a01602014-11-17 17:26:55 -080057)
Adam Langley95c29f32014-06-20 12:00:00 -070058
David Benjamin025b3d32014-07-01 19:53:04 -040059const (
60 rsaCertificateFile = "cert.pem"
61 ecdsaCertificateFile = "ecdsa_cert.pem"
62)
63
64const (
David Benjamina08e49d2014-08-24 01:46:07 -040065 rsaKeyFile = "key.pem"
66 ecdsaKeyFile = "ecdsa_key.pem"
67 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040068)
69
Adam Langley95c29f32014-06-20 12:00:00 -070070var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040071var channelIDKey *ecdsa.PrivateKey
72var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070073
David Benjamin61f95272014-11-25 01:55:35 -050074var testOCSPResponse = []byte{1, 2, 3, 4}
75var testSCTList = []byte{5, 6, 7, 8}
76
Adam Langley95c29f32014-06-20 12:00:00 -070077func initCertificates() {
78 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070079 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070080 if err != nil {
81 panic(err)
82 }
David Benjamin61f95272014-11-25 01:55:35 -050083 rsaCertificate.OCSPStaple = testOCSPResponse
84 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070085
Adam Langley7c803a62015-06-15 15:35:05 -070086 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070087 if err != nil {
88 panic(err)
89 }
David Benjamin61f95272014-11-25 01:55:35 -050090 ecdsaCertificate.OCSPStaple = testOCSPResponse
91 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040092
Adam Langley7c803a62015-06-15 15:35:05 -070093 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040094 if err != nil {
95 panic(err)
96 }
97 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
98 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
99 panic("bad key type")
100 }
101 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
102 if err != nil {
103 panic(err)
104 }
105 if channelIDKey.Curve != elliptic.P256() {
106 panic("bad curve")
107 }
108
109 channelIDBytes = make([]byte, 64)
110 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
111 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700112}
113
114var certificateOnce sync.Once
115
116func getRSACertificate() Certificate {
117 certificateOnce.Do(initCertificates)
118 return rsaCertificate
119}
120
121func getECDSACertificate() Certificate {
122 certificateOnce.Do(initCertificates)
123 return ecdsaCertificate
124}
125
David Benjamin025b3d32014-07-01 19:53:04 -0400126type testType int
127
128const (
129 clientTest testType = iota
130 serverTest
131)
132
David Benjamin6fd297b2014-08-11 18:43:38 -0400133type protocol int
134
135const (
136 tls protocol = iota
137 dtls
138)
139
David Benjaminfc7b0862014-09-06 13:21:53 -0400140const (
141 alpn = 1
142 npn = 2
143)
144
Adam Langley95c29f32014-06-20 12:00:00 -0700145type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400146 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400147 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700148 name string
149 config Config
150 shouldFail bool
151 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700152 // expectedLocalError, if not empty, contains a substring that must be
153 // found in the local error.
154 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400155 // expectedVersion, if non-zero, specifies the TLS version that must be
156 // negotiated.
157 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400158 // expectedResumeVersion, if non-zero, specifies the TLS version that
159 // must be negotiated on resumption. If zero, expectedVersion is used.
160 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400161 // expectedCipher, if non-zero, specifies the TLS cipher suite that
162 // should be negotiated.
163 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400164 // expectChannelID controls whether the connection should have
165 // negotiated a Channel ID with channelIDKey.
166 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400167 // expectedNextProto controls whether the connection should
168 // negotiate a next protocol via NPN or ALPN.
169 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400170 // expectNoNextProto, if true, means that no next protocol should be
171 // negotiated.
172 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400173 // expectedNextProtoType, if non-zero, is the expected next
174 // protocol negotiation mechanism.
175 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500176 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
177 // should be negotiated. If zero, none should be negotiated.
178 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100179 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
180 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100181 // expectedSCTList, if not nil, is the expected SCT list to be received.
182 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400183 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
184 // hash function that the client should have used when signing the
185 // handshake with a client certificate.
186 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700187 // messageLen is the length, in bytes, of the test message that will be
188 // sent.
189 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400190 // messageCount is the number of test messages that will be sent.
191 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400192 // digestPrefs is the list of digest preferences from the client.
193 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400194 // certFile is the path to the certificate to use for the server.
195 certFile string
196 // keyFile is the path to the private key to use for the server.
197 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400198 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400199 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400200 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700201 // expectResumeRejected, if true, specifies that the attempted
202 // resumption must be rejected by the client. This is only valid for a
203 // serverTest.
204 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400205 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500206 // resumption. Unless newSessionsOnResume is set,
207 // SessionTicketKey, ServerSessionCache, and
208 // ClientSessionCache are copied from the initial connection's
209 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400210 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500211 // newSessionsOnResume, if true, will cause resumeConfig to
212 // use a different session resumption context.
213 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400214 // noSessionCache, if true, will cause the server to run without a
215 // session cache.
216 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400217 // sendPrefix sends a prefix on the socket before actually performing a
218 // handshake.
219 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400220 // shimWritesFirst controls whether the shim sends an initial "hello"
221 // message before doing a roundtrip with the runner.
222 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400223 // shimShutsDown, if true, runs a test where the shim shuts down the
224 // connection immediately after the handshake rather than echoing
225 // messages from the runner.
226 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400227 // renegotiate indicates the number of times the connection should be
228 // renegotiated during the exchange.
229 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700230 // renegotiateCiphers is a list of ciphersuite ids that will be
231 // switched in just before renegotiation.
232 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500233 // replayWrites, if true, configures the underlying transport
234 // to replay every write it makes in DTLS tests.
235 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500236 // damageFirstWrite, if true, configures the underlying transport to
237 // damage the final byte of the first application data write.
238 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400239 // exportKeyingMaterial, if non-zero, configures the test to exchange
240 // keying material and verify they match.
241 exportKeyingMaterial int
242 exportLabel string
243 exportContext string
244 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400245 // flags, if not empty, contains a list of command-line flags that will
246 // be passed to the shim program.
247 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700248 // testTLSUnique, if true, causes the shim to send the tls-unique value
249 // which will be compared against the expected value.
250 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400251 // sendEmptyRecords is the number of consecutive empty records to send
252 // before and after the test message.
253 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400254 // sendWarningAlerts is the number of consecutive warning alerts to send
255 // before and after the test message.
256 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400257 // expectMessageDropped, if true, means the test message is expected to
258 // be dropped by the client rather than echoed back.
259 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700260}
261
Adam Langley7c803a62015-06-15 15:35:05 -0700262var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700263
David Benjamin9867b7d2016-03-01 23:25:48 -0500264func writeTranscript(test *testCase, isResume bool, data []byte) {
265 if len(data) == 0 {
266 return
267 }
268
269 protocol := "tls"
270 if test.protocol == dtls {
271 protocol = "dtls"
272 }
273
274 side := "client"
275 if test.testType == serverTest {
276 side = "server"
277 }
278
279 dir := path.Join(*transcriptDir, protocol, side)
280 if err := os.MkdirAll(dir, 0755); err != nil {
281 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
282 return
283 }
284
285 name := test.name
286 if isResume {
287 name += "-Resume"
288 } else {
289 name += "-Normal"
290 }
291
292 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
293 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
294 }
295}
296
David Benjamin3ed59772016-03-08 12:50:21 -0500297// A timeoutConn implements an idle timeout on each Read and Write operation.
298type timeoutConn struct {
299 net.Conn
300 timeout time.Duration
301}
302
303func (t *timeoutConn) Read(b []byte) (int, error) {
304 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
305 return 0, err
306 }
307 return t.Conn.Read(b)
308}
309
310func (t *timeoutConn) Write(b []byte) (int, error) {
311 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
312 return 0, err
313 }
314 return t.Conn.Write(b)
315}
316
David Benjamin8e6db492015-07-25 18:29:23 -0400317func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin3ed59772016-03-08 12:50:21 -0500318 conn = &timeoutConn{conn, time.Duration(*timeout) * time.Second}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500319
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500321 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
322 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500323 }
324
David Benjamin9867b7d2016-03-01 23:25:48 -0500325 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500326 local, peer := "client", "server"
327 if test.testType == clientTest {
328 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500329 }
David Benjaminebda9b32015-11-02 15:33:18 -0500330 connDebug := &recordingConn{
331 Conn: conn,
332 isDatagram: test.protocol == dtls,
333 local: local,
334 peer: peer,
335 }
336 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500337 if *flagDebug {
338 defer connDebug.WriteTo(os.Stdout)
339 }
340 if len(*transcriptDir) != 0 {
341 defer func() {
342 writeTranscript(test, isResume, connDebug.Transcript())
343 }()
344 }
David Benjaminebda9b32015-11-02 15:33:18 -0500345
346 if config.Bugs.PacketAdaptor != nil {
347 config.Bugs.PacketAdaptor.debug = connDebug
348 }
349 }
350
351 if test.replayWrites {
352 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400353 }
354
David Benjamin3ed59772016-03-08 12:50:21 -0500355 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500356 if test.damageFirstWrite {
357 connDamage = newDamageAdaptor(conn)
358 conn = connDamage
359 }
360
David Benjamin6fd297b2014-08-11 18:43:38 -0400361 if test.sendPrefix != "" {
362 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
363 return err
364 }
David Benjamin98e882e2014-08-08 13:24:34 -0400365 }
366
David Benjamin1d5c83e2014-07-22 19:20:02 -0400367 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400368 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400369 if test.protocol == dtls {
370 tlsConn = DTLSServer(conn, config)
371 } else {
372 tlsConn = Server(conn, config)
373 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400374 } else {
375 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400376 if test.protocol == dtls {
377 tlsConn = DTLSClient(conn, config)
378 } else {
379 tlsConn = Client(conn, config)
380 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400381 }
David Benjamin30789da2015-08-29 22:56:45 -0400382 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400383
Adam Langley95c29f32014-06-20 12:00:00 -0700384 if err := tlsConn.Handshake(); err != nil {
385 return err
386 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700387
David Benjamin01fe8202014-09-24 15:21:44 -0400388 // TODO(davidben): move all per-connection expectations into a dedicated
389 // expectations struct that can be specified separately for the two
390 // legs.
391 expectedVersion := test.expectedVersion
392 if isResume && test.expectedResumeVersion != 0 {
393 expectedVersion = test.expectedResumeVersion
394 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700395 connState := tlsConn.ConnectionState()
396 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400397 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400398 }
399
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700400 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400401 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
402 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700403 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
404 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
405 }
David Benjamin90da8c82015-04-20 14:57:57 -0400406
David Benjamina08e49d2014-08-24 01:46:07 -0400407 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700408 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400409 if channelID == nil {
410 return fmt.Errorf("no channel ID negotiated")
411 }
412 if channelID.Curve != channelIDKey.Curve ||
413 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
414 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
415 return fmt.Errorf("incorrect channel ID")
416 }
417 }
418
David Benjaminae2888f2014-09-06 12:58:58 -0400419 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700420 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400421 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
422 }
423 }
424
David Benjaminc7ce9772015-10-09 19:32:41 -0400425 if test.expectNoNextProto {
426 if actual := connState.NegotiatedProtocol; actual != "" {
427 return fmt.Errorf("got unexpected next proto %s", actual)
428 }
429 }
430
David Benjaminfc7b0862014-09-06 13:21:53 -0400431 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700432 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400433 return fmt.Errorf("next proto type mismatch")
434 }
435 }
436
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700437 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500438 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
439 }
440
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100441 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
442 return fmt.Errorf("OCSP Response mismatch")
443 }
444
Paul Lietar4fac72e2015-09-09 13:44:55 +0100445 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
446 return fmt.Errorf("SCT list mismatch")
447 }
448
Steven Valdez0d62f262015-09-04 12:41:04 -0400449 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
450 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
451 }
452
David Benjaminc565ebb2015-04-03 04:06:36 -0400453 if test.exportKeyingMaterial > 0 {
454 actual := make([]byte, test.exportKeyingMaterial)
455 if _, err := io.ReadFull(tlsConn, actual); err != nil {
456 return err
457 }
458 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
459 if err != nil {
460 return err
461 }
462 if !bytes.Equal(actual, expected) {
463 return fmt.Errorf("keying material mismatch")
464 }
465 }
466
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700467 if test.testTLSUnique {
468 var peersValue [12]byte
469 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
470 return err
471 }
472 expected := tlsConn.ConnectionState().TLSUnique
473 if !bytes.Equal(peersValue[:], expected) {
474 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
475 }
476 }
477
David Benjamine58c4f52014-08-24 03:47:07 -0400478 if test.shimWritesFirst {
479 var buf [5]byte
480 _, err := io.ReadFull(tlsConn, buf[:])
481 if err != nil {
482 return err
483 }
484 if string(buf[:]) != "hello" {
485 return fmt.Errorf("bad initial message")
486 }
487 }
488
David Benjamina8ebe222015-06-06 03:04:39 -0400489 for i := 0; i < test.sendEmptyRecords; i++ {
490 tlsConn.Write(nil)
491 }
492
David Benjamin24f346d2015-06-06 03:28:08 -0400493 for i := 0; i < test.sendWarningAlerts; i++ {
494 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
495 }
496
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400497 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700498 if test.renegotiateCiphers != nil {
499 config.CipherSuites = test.renegotiateCiphers
500 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400501 for i := 0; i < test.renegotiate; i++ {
502 if err := tlsConn.Renegotiate(); err != nil {
503 return err
504 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700505 }
506 } else if test.renegotiateCiphers != nil {
507 panic("renegotiateCiphers without renegotiate")
508 }
509
David Benjamin5fa3eba2015-01-22 16:35:40 -0500510 if test.damageFirstWrite {
511 connDamage.setDamage(true)
512 tlsConn.Write([]byte("DAMAGED WRITE"))
513 connDamage.setDamage(false)
514 }
515
David Benjamin8e6db492015-07-25 18:29:23 -0400516 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700517 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400518 if test.protocol == dtls {
519 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
520 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700521 // Read until EOF.
522 _, err := io.Copy(ioutil.Discard, tlsConn)
523 return err
524 }
David Benjamin4417d052015-04-05 04:17:25 -0400525 if messageLen == 0 {
526 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700527 }
Adam Langley95c29f32014-06-20 12:00:00 -0700528
David Benjamin8e6db492015-07-25 18:29:23 -0400529 messageCount := test.messageCount
530 if messageCount == 0 {
531 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400532 }
533
David Benjamin8e6db492015-07-25 18:29:23 -0400534 for j := 0; j < messageCount; j++ {
535 testMessage := make([]byte, messageLen)
536 for i := range testMessage {
537 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400538 }
David Benjamin8e6db492015-07-25 18:29:23 -0400539 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700540
David Benjamin8e6db492015-07-25 18:29:23 -0400541 for i := 0; i < test.sendEmptyRecords; i++ {
542 tlsConn.Write(nil)
543 }
544
545 for i := 0; i < test.sendWarningAlerts; i++ {
546 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
547 }
548
David Benjamin4f75aaf2015-09-01 16:53:10 -0400549 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400550 // The shim will not respond.
551 continue
552 }
553
David Benjamin8e6db492015-07-25 18:29:23 -0400554 buf := make([]byte, len(testMessage))
555 if test.protocol == dtls {
556 bufTmp := make([]byte, len(buf)+1)
557 n, err := tlsConn.Read(bufTmp)
558 if err != nil {
559 return err
560 }
561 if n != len(buf) {
562 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
563 }
564 copy(buf, bufTmp)
565 } else {
566 _, err := io.ReadFull(tlsConn, buf)
567 if err != nil {
568 return err
569 }
570 }
571
572 for i, v := range buf {
573 if v != testMessage[i]^0xff {
574 return fmt.Errorf("bad reply contents at byte %d", i)
575 }
Adam Langley95c29f32014-06-20 12:00:00 -0700576 }
577 }
578
579 return nil
580}
581
David Benjamin325b5c32014-07-01 19:40:31 -0400582func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
583 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700584 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400585 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700586 }
David Benjamin325b5c32014-07-01 19:40:31 -0400587 valgrindArgs = append(valgrindArgs, path)
588 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700589
David Benjamin325b5c32014-07-01 19:40:31 -0400590 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700591}
592
David Benjamin325b5c32014-07-01 19:40:31 -0400593func gdbOf(path string, args ...string) *exec.Cmd {
594 xtermArgs := []string{"-e", "gdb", "--args"}
595 xtermArgs = append(xtermArgs, path)
596 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700597
David Benjamin325b5c32014-07-01 19:40:31 -0400598 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700599}
600
David Benjamind16bf342015-12-18 00:53:12 -0500601func lldbOf(path string, args ...string) *exec.Cmd {
602 xtermArgs := []string{"-e", "lldb", "--"}
603 xtermArgs = append(xtermArgs, path)
604 xtermArgs = append(xtermArgs, args...)
605
606 return exec.Command("xterm", xtermArgs...)
607}
608
Adam Langley69a01602014-11-17 17:26:55 -0800609type moreMallocsError struct{}
610
611func (moreMallocsError) Error() string {
612 return "child process did not exhaust all allocation calls"
613}
614
615var errMoreMallocs = moreMallocsError{}
616
David Benjamin87c8a642015-02-21 01:54:29 -0500617// accept accepts a connection from listener, unless waitChan signals a process
618// exit first.
619func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
620 type connOrError struct {
621 conn net.Conn
622 err error
623 }
624 connChan := make(chan connOrError, 1)
625 go func() {
626 conn, err := listener.Accept()
627 connChan <- connOrError{conn, err}
628 close(connChan)
629 }()
630 select {
631 case result := <-connChan:
632 return result.conn, result.err
633 case childErr := <-waitChan:
634 waitChan <- childErr
635 return nil, fmt.Errorf("child exited early: %s", childErr)
636 }
637}
638
Adam Langley7c803a62015-06-15 15:35:05 -0700639func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700640 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
641 panic("Error expected without shouldFail in " + test.name)
642 }
643
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700644 if test.expectResumeRejected && !test.resumeSession {
645 panic("expectResumeRejected without resumeSession in " + test.name)
646 }
647
Steven Valdez0d62f262015-09-04 12:41:04 -0400648 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
649 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
650 }
651
David Benjamin87c8a642015-02-21 01:54:29 -0500652 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
653 if err != nil {
654 panic(err)
655 }
656 defer func() {
657 if listener != nil {
658 listener.Close()
659 }
660 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700661
David Benjamin87c8a642015-02-21 01:54:29 -0500662 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400663 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400664 flags = append(flags, "-server")
665
David Benjamin025b3d32014-07-01 19:53:04 -0400666 flags = append(flags, "-key-file")
667 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700668 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400669 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700670 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400671 }
672
673 flags = append(flags, "-cert-file")
674 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700675 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400676 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700677 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400678 }
679 }
David Benjamin5a593af2014-08-11 19:51:50 -0400680
Steven Valdez0d62f262015-09-04 12:41:04 -0400681 if test.digestPrefs != "" {
682 flags = append(flags, "-digest-prefs")
683 flags = append(flags, test.digestPrefs)
684 }
685
David Benjamin6fd297b2014-08-11 18:43:38 -0400686 if test.protocol == dtls {
687 flags = append(flags, "-dtls")
688 }
689
David Benjamin5a593af2014-08-11 19:51:50 -0400690 if test.resumeSession {
691 flags = append(flags, "-resume")
692 }
693
David Benjamine58c4f52014-08-24 03:47:07 -0400694 if test.shimWritesFirst {
695 flags = append(flags, "-shim-writes-first")
696 }
697
David Benjamin30789da2015-08-29 22:56:45 -0400698 if test.shimShutsDown {
699 flags = append(flags, "-shim-shuts-down")
700 }
701
David Benjaminc565ebb2015-04-03 04:06:36 -0400702 if test.exportKeyingMaterial > 0 {
703 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
704 flags = append(flags, "-export-label", test.exportLabel)
705 flags = append(flags, "-export-context", test.exportContext)
706 if test.useExportContext {
707 flags = append(flags, "-use-export-context")
708 }
709 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700710 if test.expectResumeRejected {
711 flags = append(flags, "-expect-session-miss")
712 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400713
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700714 if test.testTLSUnique {
715 flags = append(flags, "-tls-unique")
716 }
717
David Benjamin025b3d32014-07-01 19:53:04 -0400718 flags = append(flags, test.flags...)
719
720 var shim *exec.Cmd
721 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700722 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700723 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700724 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500725 } else if *useLLDB {
726 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400727 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700728 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400729 }
David Benjamin025b3d32014-07-01 19:53:04 -0400730 shim.Stdin = os.Stdin
731 var stdoutBuf, stderrBuf bytes.Buffer
732 shim.Stdout = &stdoutBuf
733 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800734 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500735 shim.Env = os.Environ()
736 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800737 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400738 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800739 }
740 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
741 }
David Benjamin025b3d32014-07-01 19:53:04 -0400742
743 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700744 panic(err)
745 }
David Benjamin87c8a642015-02-21 01:54:29 -0500746 waitChan := make(chan error, 1)
747 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700748
749 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400750 if !test.noSessionCache {
751 config.ClientSessionCache = NewLRUClientSessionCache(1)
752 config.ServerSessionCache = NewLRUServerSessionCache(1)
753 }
David Benjamin025b3d32014-07-01 19:53:04 -0400754 if test.testType == clientTest {
755 if len(config.Certificates) == 0 {
756 config.Certificates = []Certificate{getRSACertificate()}
757 }
David Benjamin87c8a642015-02-21 01:54:29 -0500758 } else {
759 // Supply a ServerName to ensure a constant session cache key,
760 // rather than falling back to net.Conn.RemoteAddr.
761 if len(config.ServerName) == 0 {
762 config.ServerName = "test"
763 }
David Benjamin025b3d32014-07-01 19:53:04 -0400764 }
David Benjaminf2b83632016-03-01 22:57:46 -0500765 if *fuzzer {
766 config.Bugs.NullAllCiphers = true
767 }
Adam Langley95c29f32014-06-20 12:00:00 -0700768
David Benjamin87c8a642015-02-21 01:54:29 -0500769 conn, err := acceptOrWait(listener, waitChan)
770 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400771 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500772 conn.Close()
773 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500774
David Benjamin1d5c83e2014-07-22 19:20:02 -0400775 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400776 var resumeConfig Config
777 if test.resumeConfig != nil {
778 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500779 if len(resumeConfig.ServerName) == 0 {
780 resumeConfig.ServerName = config.ServerName
781 }
David Benjamin01fe8202014-09-24 15:21:44 -0400782 if len(resumeConfig.Certificates) == 0 {
783 resumeConfig.Certificates = []Certificate{getRSACertificate()}
784 }
David Benjaminba4594a2015-06-18 18:36:15 -0400785 if test.newSessionsOnResume {
786 if !test.noSessionCache {
787 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
788 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
789 }
790 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500791 resumeConfig.SessionTicketKey = config.SessionTicketKey
792 resumeConfig.ClientSessionCache = config.ClientSessionCache
793 resumeConfig.ServerSessionCache = config.ServerSessionCache
794 }
David Benjaminf2b83632016-03-01 22:57:46 -0500795 if *fuzzer {
796 resumeConfig.Bugs.NullAllCiphers = true
797 }
David Benjamin01fe8202014-09-24 15:21:44 -0400798 } else {
799 resumeConfig = config
800 }
David Benjamin87c8a642015-02-21 01:54:29 -0500801 var connResume net.Conn
802 connResume, err = acceptOrWait(listener, waitChan)
803 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400804 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500805 connResume.Close()
806 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400807 }
808
David Benjamin87c8a642015-02-21 01:54:29 -0500809 // Close the listener now. This is to avoid hangs should the shim try to
810 // open more connections than expected.
811 listener.Close()
812 listener = nil
813
814 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800815 if exitError, ok := childErr.(*exec.ExitError); ok {
816 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
817 return errMoreMallocs
818 }
819 }
Adam Langley95c29f32014-06-20 12:00:00 -0700820
David Benjamin9bea3492016-03-02 10:59:16 -0500821 // Account for Windows line endings.
822 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
823 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500824
825 // Separate the errors from the shim and those from tools like
826 // AddressSanitizer.
827 var extraStderr string
828 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
829 stderr = stderrParts[0]
830 extraStderr = stderrParts[1]
831 }
832
Adam Langley95c29f32014-06-20 12:00:00 -0700833 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400834 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700835 localError := "none"
836 if err != nil {
837 localError = err.Error()
838 }
839 if len(test.expectedLocalError) != 0 {
840 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
841 }
Adam Langley95c29f32014-06-20 12:00:00 -0700842
843 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700844 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700845 if childErr != nil {
846 childError = childErr.Error()
847 }
848
849 var msg string
850 switch {
851 case failed && !test.shouldFail:
852 msg = "unexpected failure"
853 case !failed && test.shouldFail:
854 msg = "unexpected success"
855 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700856 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700857 default:
858 panic("internal error")
859 }
860
David Benjaminc565ebb2015-04-03 04:06:36 -0400861 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 -0700862 }
863
David Benjaminff3a1492016-03-02 10:12:06 -0500864 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
865 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700866 }
867
868 return nil
869}
870
871var tlsVersions = []struct {
872 name string
873 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400874 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500875 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700876}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500877 {"SSL3", VersionSSL30, "-no-ssl3", false},
878 {"TLS1", VersionTLS10, "-no-tls1", true},
879 {"TLS11", VersionTLS11, "-no-tls11", false},
880 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700881}
882
883var testCipherSuites = []struct {
884 name string
885 id uint16
886}{
887 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400888 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700889 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400890 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400891 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700892 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400893 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400894 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
895 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400896 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400897 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
898 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400899 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700900 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
901 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400902 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
903 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700904 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400905 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500906 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500907 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700908 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700909 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700910 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400911 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400912 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700913 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400914 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500915 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500916 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700917 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400918 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
919 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700920 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
921 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500922 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -0400923 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700924 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400925 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700926 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700927}
928
David Benjamin8b8c0062014-11-23 02:47:52 -0500929func hasComponent(suiteName, component string) bool {
930 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
931}
932
David Benjamin4298d772015-12-19 00:18:25 -0500933func isTLSOnly(suiteName string) bool {
934 // BoringSSL doesn't support ECDHE without a curves extension, and
935 // SSLv3 doesn't contain extensions.
936 return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName)
937}
938
David Benjaminf7768e42014-08-31 02:06:47 -0400939func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500940 return hasComponent(suiteName, "GCM") ||
941 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400942 hasComponent(suiteName, "SHA384") ||
943 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500944}
945
946func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700947 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400948}
949
Adam Langleya7997f12015-05-14 17:38:50 -0700950func bigFromHex(hex string) *big.Int {
951 ret, ok := new(big.Int).SetString(hex, 16)
952 if !ok {
953 panic("failed to parse hex number 0x" + hex)
954 }
955 return ret
956}
957
Adam Langley7c803a62015-06-15 15:35:05 -0700958func addBasicTests() {
959 basicTests := []testCase{
960 {
961 name: "BadRSASignature",
962 config: Config{
963 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
964 Bugs: ProtocolBugs{
965 InvalidSKXSignature: true,
966 },
967 },
968 shouldFail: true,
969 expectedError: ":BAD_SIGNATURE:",
970 },
971 {
972 name: "BadECDSASignature",
973 config: Config{
974 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
975 Bugs: ProtocolBugs{
976 InvalidSKXSignature: true,
977 },
978 Certificates: []Certificate{getECDSACertificate()},
979 },
980 shouldFail: true,
981 expectedError: ":BAD_SIGNATURE:",
982 },
983 {
David Benjamin6de0e532015-07-28 22:43:19 -0400984 testType: serverTest,
985 name: "BadRSASignature-ClientAuth",
986 config: Config{
987 Bugs: ProtocolBugs{
988 InvalidCertVerifySignature: true,
989 },
990 Certificates: []Certificate{getRSACertificate()},
991 },
992 shouldFail: true,
993 expectedError: ":BAD_SIGNATURE:",
994 flags: []string{"-require-any-client-certificate"},
995 },
996 {
997 testType: serverTest,
998 name: "BadECDSASignature-ClientAuth",
999 config: Config{
1000 Bugs: ProtocolBugs{
1001 InvalidCertVerifySignature: true,
1002 },
1003 Certificates: []Certificate{getECDSACertificate()},
1004 },
1005 shouldFail: true,
1006 expectedError: ":BAD_SIGNATURE:",
1007 flags: []string{"-require-any-client-certificate"},
1008 },
1009 {
Adam Langley7c803a62015-06-15 15:35:05 -07001010 name: "BadECDSACurve",
1011 config: Config{
1012 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1013 Bugs: ProtocolBugs{
1014 InvalidSKXCurve: true,
1015 },
1016 Certificates: []Certificate{getECDSACertificate()},
1017 },
1018 shouldFail: true,
1019 expectedError: ":WRONG_CURVE:",
1020 },
1021 {
Adam Langley7c803a62015-06-15 15:35:05 -07001022 name: "NoFallbackSCSV",
1023 config: Config{
1024 Bugs: ProtocolBugs{
1025 FailIfNotFallbackSCSV: true,
1026 },
1027 },
1028 shouldFail: true,
1029 expectedLocalError: "no fallback SCSV found",
1030 },
1031 {
1032 name: "SendFallbackSCSV",
1033 config: Config{
1034 Bugs: ProtocolBugs{
1035 FailIfNotFallbackSCSV: true,
1036 },
1037 },
1038 flags: []string{"-fallback-scsv"},
1039 },
1040 {
1041 name: "ClientCertificateTypes",
1042 config: Config{
1043 ClientAuth: RequestClientCert,
1044 ClientCertificateTypes: []byte{
1045 CertTypeDSSSign,
1046 CertTypeRSASign,
1047 CertTypeECDSASign,
1048 },
1049 },
1050 flags: []string{
1051 "-expect-certificate-types",
1052 base64.StdEncoding.EncodeToString([]byte{
1053 CertTypeDSSSign,
1054 CertTypeRSASign,
1055 CertTypeECDSASign,
1056 }),
1057 },
1058 },
1059 {
1060 name: "NoClientCertificate",
1061 config: Config{
1062 ClientAuth: RequireAnyClientCert,
1063 },
1064 shouldFail: true,
1065 expectedLocalError: "client didn't provide a certificate",
1066 },
1067 {
1068 name: "UnauthenticatedECDH",
1069 config: Config{
1070 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1071 Bugs: ProtocolBugs{
1072 UnauthenticatedECDH: true,
1073 },
1074 },
1075 shouldFail: true,
1076 expectedError: ":UNEXPECTED_MESSAGE:",
1077 },
1078 {
1079 name: "SkipCertificateStatus",
1080 config: Config{
1081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1082 Bugs: ProtocolBugs{
1083 SkipCertificateStatus: true,
1084 },
1085 },
1086 flags: []string{
1087 "-enable-ocsp-stapling",
1088 },
1089 },
1090 {
1091 name: "SkipServerKeyExchange",
1092 config: Config{
1093 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1094 Bugs: ProtocolBugs{
1095 SkipServerKeyExchange: true,
1096 },
1097 },
1098 shouldFail: true,
1099 expectedError: ":UNEXPECTED_MESSAGE:",
1100 },
1101 {
1102 name: "SkipChangeCipherSpec-Client",
1103 config: Config{
1104 Bugs: ProtocolBugs{
1105 SkipChangeCipherSpec: true,
1106 },
1107 },
1108 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001109 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001110 },
1111 {
1112 testType: serverTest,
1113 name: "SkipChangeCipherSpec-Server",
1114 config: Config{
1115 Bugs: ProtocolBugs{
1116 SkipChangeCipherSpec: true,
1117 },
1118 },
1119 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001120 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001121 },
1122 {
1123 testType: serverTest,
1124 name: "SkipChangeCipherSpec-Server-NPN",
1125 config: Config{
1126 NextProtos: []string{"bar"},
1127 Bugs: ProtocolBugs{
1128 SkipChangeCipherSpec: true,
1129 },
1130 },
1131 flags: []string{
1132 "-advertise-npn", "\x03foo\x03bar\x03baz",
1133 },
1134 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001135 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001136 },
1137 {
1138 name: "FragmentAcrossChangeCipherSpec-Client",
1139 config: Config{
1140 Bugs: ProtocolBugs{
1141 FragmentAcrossChangeCipherSpec: true,
1142 },
1143 },
1144 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001145 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001146 },
1147 {
1148 testType: serverTest,
1149 name: "FragmentAcrossChangeCipherSpec-Server",
1150 config: Config{
1151 Bugs: ProtocolBugs{
1152 FragmentAcrossChangeCipherSpec: true,
1153 },
1154 },
1155 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001156 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001157 },
1158 {
1159 testType: serverTest,
1160 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1161 config: Config{
1162 NextProtos: []string{"bar"},
1163 Bugs: ProtocolBugs{
1164 FragmentAcrossChangeCipherSpec: true,
1165 },
1166 },
1167 flags: []string{
1168 "-advertise-npn", "\x03foo\x03bar\x03baz",
1169 },
1170 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001171 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001172 },
1173 {
1174 testType: serverTest,
1175 name: "Alert",
1176 config: Config{
1177 Bugs: ProtocolBugs{
1178 SendSpuriousAlert: alertRecordOverflow,
1179 },
1180 },
1181 shouldFail: true,
1182 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1183 },
1184 {
1185 protocol: dtls,
1186 testType: serverTest,
1187 name: "Alert-DTLS",
1188 config: Config{
1189 Bugs: ProtocolBugs{
1190 SendSpuriousAlert: alertRecordOverflow,
1191 },
1192 },
1193 shouldFail: true,
1194 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1195 },
1196 {
1197 testType: serverTest,
1198 name: "FragmentAlert",
1199 config: Config{
1200 Bugs: ProtocolBugs{
1201 FragmentAlert: true,
1202 SendSpuriousAlert: alertRecordOverflow,
1203 },
1204 },
1205 shouldFail: true,
1206 expectedError: ":BAD_ALERT:",
1207 },
1208 {
1209 protocol: dtls,
1210 testType: serverTest,
1211 name: "FragmentAlert-DTLS",
1212 config: Config{
1213 Bugs: ProtocolBugs{
1214 FragmentAlert: true,
1215 SendSpuriousAlert: alertRecordOverflow,
1216 },
1217 },
1218 shouldFail: true,
1219 expectedError: ":BAD_ALERT:",
1220 },
1221 {
1222 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001223 name: "DoubleAlert",
1224 config: Config{
1225 Bugs: ProtocolBugs{
1226 DoubleAlert: true,
1227 SendSpuriousAlert: alertRecordOverflow,
1228 },
1229 },
1230 shouldFail: true,
1231 expectedError: ":BAD_ALERT:",
1232 },
1233 {
1234 protocol: dtls,
1235 testType: serverTest,
1236 name: "DoubleAlert-DTLS",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 DoubleAlert: true,
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":BAD_ALERT:",
1245 },
1246 {
1247 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001248 name: "EarlyChangeCipherSpec-server-1",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 EarlyChangeCipherSpec: 1,
1252 },
1253 },
1254 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001255 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001256 },
1257 {
1258 testType: serverTest,
1259 name: "EarlyChangeCipherSpec-server-2",
1260 config: Config{
1261 Bugs: ProtocolBugs{
1262 EarlyChangeCipherSpec: 2,
1263 },
1264 },
1265 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001266 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001267 },
1268 {
1269 name: "SkipNewSessionTicket",
1270 config: Config{
1271 Bugs: ProtocolBugs{
1272 SkipNewSessionTicket: true,
1273 },
1274 },
1275 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001276 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001277 },
1278 {
1279 testType: serverTest,
1280 name: "FallbackSCSV",
1281 config: Config{
1282 MaxVersion: VersionTLS11,
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 shouldFail: true,
1288 expectedError: ":INAPPROPRIATE_FALLBACK:",
1289 },
1290 {
1291 testType: serverTest,
1292 name: "FallbackSCSV-VersionMatch",
1293 config: Config{
1294 Bugs: ProtocolBugs{
1295 SendFallbackSCSV: true,
1296 },
1297 },
1298 },
1299 {
1300 testType: serverTest,
1301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
1308 expectedVersion: VersionTLS12,
1309 },
1310 {
1311 testType: serverTest,
1312 name: "MinorVersionTolerance",
1313 config: Config{
1314 Bugs: ProtocolBugs{
1315 SendClientVersion: 0x03ff,
1316 },
1317 },
1318 expectedVersion: VersionTLS12,
1319 },
1320 {
1321 testType: serverTest,
1322 name: "MajorVersionTolerance",
1323 config: Config{
1324 Bugs: ProtocolBugs{
1325 SendClientVersion: 0x0400,
1326 },
1327 },
1328 expectedVersion: VersionTLS12,
1329 },
1330 {
1331 testType: serverTest,
1332 name: "VersionTooLow",
1333 config: Config{
1334 Bugs: ProtocolBugs{
1335 SendClientVersion: 0x0200,
1336 },
1337 },
1338 shouldFail: true,
1339 expectedError: ":UNSUPPORTED_PROTOCOL:",
1340 },
1341 {
1342 testType: serverTest,
1343 name: "HttpGET",
1344 sendPrefix: "GET / HTTP/1.0\n",
1345 shouldFail: true,
1346 expectedError: ":HTTP_REQUEST:",
1347 },
1348 {
1349 testType: serverTest,
1350 name: "HttpPOST",
1351 sendPrefix: "POST / HTTP/1.0\n",
1352 shouldFail: true,
1353 expectedError: ":HTTP_REQUEST:",
1354 },
1355 {
1356 testType: serverTest,
1357 name: "HttpHEAD",
1358 sendPrefix: "HEAD / HTTP/1.0\n",
1359 shouldFail: true,
1360 expectedError: ":HTTP_REQUEST:",
1361 },
1362 {
1363 testType: serverTest,
1364 name: "HttpPUT",
1365 sendPrefix: "PUT / HTTP/1.0\n",
1366 shouldFail: true,
1367 expectedError: ":HTTP_REQUEST:",
1368 },
1369 {
1370 testType: serverTest,
1371 name: "HttpCONNECT",
1372 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1373 shouldFail: true,
1374 expectedError: ":HTTPS_PROXY_REQUEST:",
1375 },
1376 {
1377 testType: serverTest,
1378 name: "Garbage",
1379 sendPrefix: "blah",
1380 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001381 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001382 },
1383 {
1384 name: "SkipCipherVersionCheck",
1385 config: Config{
1386 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1387 MaxVersion: VersionTLS11,
1388 Bugs: ProtocolBugs{
1389 SkipCipherVersionCheck: true,
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":WRONG_CIPHER_RETURNED:",
1394 },
1395 {
1396 name: "RSAEphemeralKey",
1397 config: Config{
1398 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1399 Bugs: ProtocolBugs{
1400 RSAEphemeralKey: true,
1401 },
1402 },
1403 shouldFail: true,
1404 expectedError: ":UNEXPECTED_MESSAGE:",
1405 },
1406 {
1407 name: "DisableEverything",
1408 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1409 shouldFail: true,
1410 expectedError: ":WRONG_SSL_VERSION:",
1411 },
1412 {
1413 protocol: dtls,
1414 name: "DisableEverything-DTLS",
1415 flags: []string{"-no-tls12", "-no-tls1"},
1416 shouldFail: true,
1417 expectedError: ":WRONG_SSL_VERSION:",
1418 },
1419 {
1420 name: "NoSharedCipher",
1421 config: Config{
1422 CipherSuites: []uint16{},
1423 },
1424 shouldFail: true,
1425 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1426 },
1427 {
1428 protocol: dtls,
1429 testType: serverTest,
1430 name: "MTU",
1431 config: Config{
1432 Bugs: ProtocolBugs{
1433 MaxPacketLength: 256,
1434 },
1435 },
1436 flags: []string{"-mtu", "256"},
1437 },
1438 {
1439 protocol: dtls,
1440 testType: serverTest,
1441 name: "MTUExceeded",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 MaxPacketLength: 255,
1445 },
1446 },
1447 flags: []string{"-mtu", "256"},
1448 shouldFail: true,
1449 expectedLocalError: "dtls: exceeded maximum packet length",
1450 },
1451 {
1452 name: "CertMismatchRSA",
1453 config: Config{
1454 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1455 Certificates: []Certificate{getECDSACertificate()},
1456 Bugs: ProtocolBugs{
1457 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1458 },
1459 },
1460 shouldFail: true,
1461 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1462 },
1463 {
1464 name: "CertMismatchECDSA",
1465 config: Config{
1466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1467 Certificates: []Certificate{getRSACertificate()},
1468 Bugs: ProtocolBugs{
1469 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1470 },
1471 },
1472 shouldFail: true,
1473 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1474 },
1475 {
1476 name: "EmptyCertificateList",
1477 config: Config{
1478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1479 Bugs: ProtocolBugs{
1480 EmptyCertificateList: true,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":DECODE_ERROR:",
1485 },
1486 {
1487 name: "TLSFatalBadPackets",
1488 damageFirstWrite: true,
1489 shouldFail: true,
1490 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1491 },
1492 {
1493 protocol: dtls,
1494 name: "DTLSIgnoreBadPackets",
1495 damageFirstWrite: true,
1496 },
1497 {
1498 protocol: dtls,
1499 name: "DTLSIgnoreBadPackets-Async",
1500 damageFirstWrite: true,
1501 flags: []string{"-async"},
1502 },
1503 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001504 name: "AppDataBeforeHandshake",
1505 config: Config{
1506 Bugs: ProtocolBugs{
1507 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_RECORD:",
1512 },
1513 {
1514 name: "AppDataBeforeHandshake-Empty",
1515 config: Config{
1516 Bugs: ProtocolBugs{
1517 AppDataBeforeHandshake: []byte{},
1518 },
1519 },
1520 shouldFail: true,
1521 expectedError: ":UNEXPECTED_RECORD:",
1522 },
1523 {
1524 protocol: dtls,
1525 name: "AppDataBeforeHandshake-DTLS",
1526 config: Config{
1527 Bugs: ProtocolBugs{
1528 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1529 },
1530 },
1531 shouldFail: true,
1532 expectedError: ":UNEXPECTED_RECORD:",
1533 },
1534 {
1535 protocol: dtls,
1536 name: "AppDataBeforeHandshake-DTLS-Empty",
1537 config: Config{
1538 Bugs: ProtocolBugs{
1539 AppDataBeforeHandshake: []byte{},
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_RECORD:",
1544 },
1545 {
Adam Langley7c803a62015-06-15 15:35:05 -07001546 name: "AppDataAfterChangeCipherSpec",
1547 config: Config{
1548 Bugs: ProtocolBugs{
1549 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1550 },
1551 },
1552 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001553 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001554 },
1555 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001556 name: "AppDataAfterChangeCipherSpec-Empty",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 AppDataAfterChangeCipherSpec: []byte{},
1560 },
1561 },
1562 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001563 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001564 },
1565 {
Adam Langley7c803a62015-06-15 15:35:05 -07001566 protocol: dtls,
1567 name: "AppDataAfterChangeCipherSpec-DTLS",
1568 config: Config{
1569 Bugs: ProtocolBugs{
1570 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1571 },
1572 },
1573 // BoringSSL's DTLS implementation will drop the out-of-order
1574 // application data.
1575 },
1576 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001577 protocol: dtls,
1578 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1579 config: Config{
1580 Bugs: ProtocolBugs{
1581 AppDataAfterChangeCipherSpec: []byte{},
1582 },
1583 },
1584 // BoringSSL's DTLS implementation will drop the out-of-order
1585 // application data.
1586 },
1587 {
Adam Langley7c803a62015-06-15 15:35:05 -07001588 name: "AlertAfterChangeCipherSpec",
1589 config: Config{
1590 Bugs: ProtocolBugs{
1591 AlertAfterChangeCipherSpec: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "AlertAfterChangeCipherSpec-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 AlertAfterChangeCipherSpec: alertRecordOverflow,
1603 },
1604 },
1605 shouldFail: true,
1606 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "ReorderHandshakeFragments-Small-DTLS",
1611 config: Config{
1612 Bugs: ProtocolBugs{
1613 ReorderHandshakeFragments: true,
1614 // Small enough that every handshake message is
1615 // fragmented.
1616 MaxHandshakeRecordLength: 2,
1617 },
1618 },
1619 },
1620 {
1621 protocol: dtls,
1622 name: "ReorderHandshakeFragments-Large-DTLS",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 ReorderHandshakeFragments: true,
1626 // Large enough that no handshake message is
1627 // fragmented.
1628 MaxHandshakeRecordLength: 2048,
1629 },
1630 },
1631 },
1632 {
1633 protocol: dtls,
1634 name: "MixCompleteMessageWithFragments-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 ReorderHandshakeFragments: true,
1638 MixCompleteMessageWithFragments: true,
1639 MaxHandshakeRecordLength: 2,
1640 },
1641 },
1642 },
1643 {
1644 name: "SendInvalidRecordType",
1645 config: Config{
1646 Bugs: ProtocolBugs{
1647 SendInvalidRecordType: true,
1648 },
1649 },
1650 shouldFail: true,
1651 expectedError: ":UNEXPECTED_RECORD:",
1652 },
1653 {
1654 protocol: dtls,
1655 name: "SendInvalidRecordType-DTLS",
1656 config: Config{
1657 Bugs: ProtocolBugs{
1658 SendInvalidRecordType: true,
1659 },
1660 },
1661 shouldFail: true,
1662 expectedError: ":UNEXPECTED_RECORD:",
1663 },
1664 {
1665 name: "FalseStart-SkipServerSecondLeg",
1666 config: Config{
1667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1668 NextProtos: []string{"foo"},
1669 Bugs: ProtocolBugs{
1670 SkipNewSessionTicket: true,
1671 SkipChangeCipherSpec: true,
1672 SkipFinished: true,
1673 ExpectFalseStart: true,
1674 },
1675 },
1676 flags: []string{
1677 "-false-start",
1678 "-handshake-never-done",
1679 "-advertise-alpn", "\x03foo",
1680 },
1681 shimWritesFirst: true,
1682 shouldFail: true,
1683 expectedError: ":UNEXPECTED_RECORD:",
1684 },
1685 {
1686 name: "FalseStart-SkipServerSecondLeg-Implicit",
1687 config: Config{
1688 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1689 NextProtos: []string{"foo"},
1690 Bugs: ProtocolBugs{
1691 SkipNewSessionTicket: true,
1692 SkipChangeCipherSpec: true,
1693 SkipFinished: true,
1694 },
1695 },
1696 flags: []string{
1697 "-implicit-handshake",
1698 "-false-start",
1699 "-handshake-never-done",
1700 "-advertise-alpn", "\x03foo",
1701 },
1702 shouldFail: true,
1703 expectedError: ":UNEXPECTED_RECORD:",
1704 },
1705 {
1706 testType: serverTest,
1707 name: "FailEarlyCallback",
1708 flags: []string{"-fail-early-callback"},
1709 shouldFail: true,
1710 expectedError: ":CONNECTION_REJECTED:",
1711 expectedLocalError: "remote error: access denied",
1712 },
1713 {
1714 name: "WrongMessageType",
1715 config: Config{
1716 Bugs: ProtocolBugs{
1717 WrongCertificateMessageType: true,
1718 },
1719 },
1720 shouldFail: true,
1721 expectedError: ":UNEXPECTED_MESSAGE:",
1722 expectedLocalError: "remote error: unexpected message",
1723 },
1724 {
1725 protocol: dtls,
1726 name: "WrongMessageType-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 WrongCertificateMessageType: true,
1730 },
1731 },
1732 shouldFail: true,
1733 expectedError: ":UNEXPECTED_MESSAGE:",
1734 expectedLocalError: "remote error: unexpected message",
1735 },
1736 {
1737 protocol: dtls,
1738 name: "FragmentMessageTypeMismatch-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 MaxHandshakeRecordLength: 2,
1742 FragmentMessageTypeMismatch: true,
1743 },
1744 },
1745 shouldFail: true,
1746 expectedError: ":FRAGMENT_MISMATCH:",
1747 },
1748 {
1749 protocol: dtls,
1750 name: "FragmentMessageLengthMismatch-DTLS",
1751 config: Config{
1752 Bugs: ProtocolBugs{
1753 MaxHandshakeRecordLength: 2,
1754 FragmentMessageLengthMismatch: true,
1755 },
1756 },
1757 shouldFail: true,
1758 expectedError: ":FRAGMENT_MISMATCH:",
1759 },
1760 {
1761 protocol: dtls,
1762 name: "SplitFragments-Header-DTLS",
1763 config: Config{
1764 Bugs: ProtocolBugs{
1765 SplitFragments: 2,
1766 },
1767 },
1768 shouldFail: true,
1769 expectedError: ":UNEXPECTED_MESSAGE:",
1770 },
1771 {
1772 protocol: dtls,
1773 name: "SplitFragments-Boundary-DTLS",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 SplitFragments: dtlsRecordHeaderLen,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1781 },
1782 {
1783 protocol: dtls,
1784 name: "SplitFragments-Body-DTLS",
1785 config: Config{
1786 Bugs: ProtocolBugs{
1787 SplitFragments: dtlsRecordHeaderLen + 1,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1792 },
1793 {
1794 protocol: dtls,
1795 name: "SendEmptyFragments-DTLS",
1796 config: Config{
1797 Bugs: ProtocolBugs{
1798 SendEmptyFragments: true,
1799 },
1800 },
1801 },
1802 {
1803 name: "UnsupportedCipherSuite",
1804 config: Config{
1805 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1806 Bugs: ProtocolBugs{
1807 IgnorePeerCipherPreferences: true,
1808 },
1809 },
1810 flags: []string{"-cipher", "DEFAULT:!RC4"},
1811 shouldFail: true,
1812 expectedError: ":WRONG_CIPHER_RETURNED:",
1813 },
1814 {
1815 name: "UnsupportedCurve",
1816 config: Config{
David Benjamin64d92502015-12-19 02:20:57 -05001817 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1818 CurvePreferences: []CurveID{CurveP256},
Adam Langley7c803a62015-06-15 15:35:05 -07001819 Bugs: ProtocolBugs{
1820 IgnorePeerCurvePreferences: true,
1821 },
1822 },
David Benjamin64d92502015-12-19 02:20:57 -05001823 flags: []string{"-p384-only"},
Adam Langley7c803a62015-06-15 15:35:05 -07001824 shouldFail: true,
1825 expectedError: ":WRONG_CURVE:",
1826 },
1827 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001828 name: "BadFinished-Client",
1829 config: Config{
1830 Bugs: ProtocolBugs{
1831 BadFinished: true,
1832 },
1833 },
1834 shouldFail: true,
1835 expectedError: ":DIGEST_CHECK_FAILED:",
1836 },
1837 {
1838 testType: serverTest,
1839 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001840 config: Config{
1841 Bugs: ProtocolBugs{
1842 BadFinished: true,
1843 },
1844 },
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 name: "FalseStart-BadFinished",
1850 config: Config{
1851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1852 NextProtos: []string{"foo"},
1853 Bugs: ProtocolBugs{
1854 BadFinished: true,
1855 ExpectFalseStart: true,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 "-handshake-never-done",
1861 "-advertise-alpn", "\x03foo",
1862 },
1863 shimWritesFirst: true,
1864 shouldFail: true,
1865 expectedError: ":DIGEST_CHECK_FAILED:",
1866 },
1867 {
1868 name: "NoFalseStart-NoALPN",
1869 config: Config{
1870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1871 Bugs: ProtocolBugs{
1872 ExpectFalseStart: true,
1873 AlertBeforeFalseStartTest: alertAccessDenied,
1874 },
1875 },
1876 flags: []string{
1877 "-false-start",
1878 },
1879 shimWritesFirst: true,
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1882 expectedLocalError: "tls: peer did not false start: EOF",
1883 },
1884 {
1885 name: "NoFalseStart-NoAEAD",
1886 config: Config{
1887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1888 NextProtos: []string{"foo"},
1889 Bugs: ProtocolBugs{
1890 ExpectFalseStart: true,
1891 AlertBeforeFalseStartTest: alertAccessDenied,
1892 },
1893 },
1894 flags: []string{
1895 "-false-start",
1896 "-advertise-alpn", "\x03foo",
1897 },
1898 shimWritesFirst: true,
1899 shouldFail: true,
1900 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1901 expectedLocalError: "tls: peer did not false start: EOF",
1902 },
1903 {
1904 name: "NoFalseStart-RSA",
1905 config: Config{
1906 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1907 NextProtos: []string{"foo"},
1908 Bugs: ProtocolBugs{
1909 ExpectFalseStart: true,
1910 AlertBeforeFalseStartTest: alertAccessDenied,
1911 },
1912 },
1913 flags: []string{
1914 "-false-start",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1920 expectedLocalError: "tls: peer did not false start: EOF",
1921 },
1922 {
1923 name: "NoFalseStart-DHE_RSA",
1924 config: Config{
1925 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1926 NextProtos: []string{"foo"},
1927 Bugs: ProtocolBugs{
1928 ExpectFalseStart: true,
1929 AlertBeforeFalseStartTest: alertAccessDenied,
1930 },
1931 },
1932 flags: []string{
1933 "-false-start",
1934 "-advertise-alpn", "\x03foo",
1935 },
1936 shimWritesFirst: true,
1937 shouldFail: true,
1938 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1939 expectedLocalError: "tls: peer did not false start: EOF",
1940 },
1941 {
1942 testType: serverTest,
1943 name: "NoSupportedCurves",
1944 config: Config{
1945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1946 Bugs: ProtocolBugs{
1947 NoSupportedCurves: true,
1948 },
1949 },
David Benjamin4298d772015-12-19 00:18:25 -05001950 shouldFail: true,
1951 expectedError: ":NO_SHARED_CIPHER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001952 },
1953 {
1954 testType: serverTest,
1955 name: "NoCommonCurves",
1956 config: Config{
1957 CipherSuites: []uint16{
1958 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1959 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1960 },
1961 CurvePreferences: []CurveID{CurveP224},
1962 },
1963 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1964 },
1965 {
1966 protocol: dtls,
1967 name: "SendSplitAlert-Sync",
1968 config: Config{
1969 Bugs: ProtocolBugs{
1970 SendSplitAlert: true,
1971 },
1972 },
1973 },
1974 {
1975 protocol: dtls,
1976 name: "SendSplitAlert-Async",
1977 config: Config{
1978 Bugs: ProtocolBugs{
1979 SendSplitAlert: true,
1980 },
1981 },
1982 flags: []string{"-async"},
1983 },
1984 {
1985 protocol: dtls,
1986 name: "PackDTLSHandshake",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 MaxHandshakeRecordLength: 2,
1990 PackHandshakeFragments: 20,
1991 PackHandshakeRecords: 200,
1992 },
1993 },
1994 },
1995 {
1996 testType: serverTest,
1997 protocol: dtls,
1998 name: "NoRC4-DTLS",
1999 config: Config{
2000 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2001 Bugs: ProtocolBugs{
2002 EnableAllCiphersInDTLS: true,
2003 },
2004 },
2005 shouldFail: true,
2006 expectedError: ":NO_SHARED_CIPHER:",
2007 },
2008 {
2009 name: "SendEmptyRecords-Pass",
2010 sendEmptyRecords: 32,
2011 },
2012 {
2013 name: "SendEmptyRecords",
2014 sendEmptyRecords: 33,
2015 shouldFail: true,
2016 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2017 },
2018 {
2019 name: "SendEmptyRecords-Async",
2020 sendEmptyRecords: 33,
2021 flags: []string{"-async"},
2022 shouldFail: true,
2023 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2024 },
2025 {
2026 name: "SendWarningAlerts-Pass",
2027 sendWarningAlerts: 4,
2028 },
2029 {
2030 protocol: dtls,
2031 name: "SendWarningAlerts-DTLS-Pass",
2032 sendWarningAlerts: 4,
2033 },
2034 {
2035 name: "SendWarningAlerts",
2036 sendWarningAlerts: 5,
2037 shouldFail: true,
2038 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2039 },
2040 {
2041 name: "SendWarningAlerts-Async",
2042 sendWarningAlerts: 5,
2043 flags: []string{"-async"},
2044 shouldFail: true,
2045 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2046 },
David Benjaminba4594a2015-06-18 18:36:15 -04002047 {
2048 name: "EmptySessionID",
2049 config: Config{
2050 SessionTicketsDisabled: true,
2051 },
2052 noSessionCache: true,
2053 flags: []string{"-expect-no-session"},
2054 },
David Benjamin30789da2015-08-29 22:56:45 -04002055 {
2056 name: "Unclean-Shutdown",
2057 config: Config{
2058 Bugs: ProtocolBugs{
2059 NoCloseNotify: true,
2060 ExpectCloseNotify: true,
2061 },
2062 },
2063 shimShutsDown: true,
2064 flags: []string{"-check-close-notify"},
2065 shouldFail: true,
2066 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2067 },
2068 {
2069 name: "Unclean-Shutdown-Ignored",
2070 config: Config{
2071 Bugs: ProtocolBugs{
2072 NoCloseNotify: true,
2073 },
2074 },
2075 shimShutsDown: true,
2076 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002077 {
David Benjaminfa214e42016-05-10 17:03:10 -04002078 name: "Unclean-Shutdown-Alert",
2079 config: Config{
2080 Bugs: ProtocolBugs{
2081 SendAlertOnShutdown: alertDecompressionFailure,
2082 ExpectCloseNotify: true,
2083 },
2084 },
2085 shimShutsDown: true,
2086 flags: []string{"-check-close-notify"},
2087 shouldFail: true,
2088 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2089 },
2090 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002091 name: "LargePlaintext",
2092 config: Config{
2093 Bugs: ProtocolBugs{
2094 SendLargeRecords: true,
2095 },
2096 },
2097 messageLen: maxPlaintext + 1,
2098 shouldFail: true,
2099 expectedError: ":DATA_LENGTH_TOO_LONG:",
2100 },
2101 {
2102 protocol: dtls,
2103 name: "LargePlaintext-DTLS",
2104 config: Config{
2105 Bugs: ProtocolBugs{
2106 SendLargeRecords: true,
2107 },
2108 },
2109 messageLen: maxPlaintext + 1,
2110 shouldFail: true,
2111 expectedError: ":DATA_LENGTH_TOO_LONG:",
2112 },
2113 {
2114 name: "LargeCiphertext",
2115 config: Config{
2116 Bugs: ProtocolBugs{
2117 SendLargeRecords: true,
2118 },
2119 },
2120 messageLen: maxPlaintext * 2,
2121 shouldFail: true,
2122 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2123 },
2124 {
2125 protocol: dtls,
2126 name: "LargeCiphertext-DTLS",
2127 config: Config{
2128 Bugs: ProtocolBugs{
2129 SendLargeRecords: true,
2130 },
2131 },
2132 messageLen: maxPlaintext * 2,
2133 // Unlike the other four cases, DTLS drops records which
2134 // are invalid before authentication, so the connection
2135 // does not fail.
2136 expectMessageDropped: true,
2137 },
David Benjamindd6fed92015-10-23 17:41:12 -04002138 {
2139 name: "SendEmptySessionTicket",
2140 config: Config{
2141 Bugs: ProtocolBugs{
2142 SendEmptySessionTicket: true,
2143 FailIfSessionOffered: true,
2144 },
2145 },
2146 flags: []string{"-expect-no-session"},
2147 resumeSession: true,
2148 expectResumeRejected: true,
2149 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002150 {
2151 name: "CheckLeafCurve",
2152 config: Config{
2153 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2154 Certificates: []Certificate{getECDSACertificate()},
2155 },
2156 flags: []string{"-p384-only"},
2157 shouldFail: true,
2158 expectedError: ":BAD_ECC_CERT:",
2159 },
David Benjamin8411b242015-11-26 12:07:28 -05002160 {
2161 name: "BadChangeCipherSpec-1",
2162 config: Config{
2163 Bugs: ProtocolBugs{
2164 BadChangeCipherSpec: []byte{2},
2165 },
2166 },
2167 shouldFail: true,
2168 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2169 },
2170 {
2171 name: "BadChangeCipherSpec-2",
2172 config: Config{
2173 Bugs: ProtocolBugs{
2174 BadChangeCipherSpec: []byte{1, 1},
2175 },
2176 },
2177 shouldFail: true,
2178 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2179 },
2180 {
2181 protocol: dtls,
2182 name: "BadChangeCipherSpec-DTLS-1",
2183 config: Config{
2184 Bugs: ProtocolBugs{
2185 BadChangeCipherSpec: []byte{2},
2186 },
2187 },
2188 shouldFail: true,
2189 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2190 },
2191 {
2192 protocol: dtls,
2193 name: "BadChangeCipherSpec-DTLS-2",
2194 config: Config{
2195 Bugs: ProtocolBugs{
2196 BadChangeCipherSpec: []byte{1, 1},
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2201 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002202 {
2203 name: "BadHelloRequest-1",
2204 renegotiate: 1,
2205 config: Config{
2206 Bugs: ProtocolBugs{
2207 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2208 },
2209 },
2210 flags: []string{
2211 "-renegotiate-freely",
2212 "-expect-total-renegotiations", "1",
2213 },
2214 shouldFail: true,
2215 expectedError: ":BAD_HELLO_REQUEST:",
2216 },
2217 {
2218 name: "BadHelloRequest-2",
2219 renegotiate: 1,
2220 config: Config{
2221 Bugs: ProtocolBugs{
2222 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2223 },
2224 },
2225 flags: []string{
2226 "-renegotiate-freely",
2227 "-expect-total-renegotiations", "1",
2228 },
2229 shouldFail: true,
2230 expectedError: ":BAD_HELLO_REQUEST:",
2231 },
David Benjaminef1b0092015-11-21 14:05:44 -05002232 {
2233 testType: serverTest,
2234 name: "SupportTicketsWithSessionID",
2235 config: Config{
2236 SessionTicketsDisabled: true,
2237 },
2238 resumeConfig: &Config{},
2239 resumeSession: true,
2240 },
David Benjamin2b07fa42016-03-02 00:23:57 -05002241 {
2242 name: "InvalidECDHPoint-Client",
2243 config: Config{
2244 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2245 CurvePreferences: []CurveID{CurveP256},
2246 Bugs: ProtocolBugs{
2247 InvalidECDHPoint: true,
2248 },
2249 },
2250 shouldFail: true,
2251 expectedError: ":INVALID_ENCODING:",
2252 },
2253 {
2254 testType: serverTest,
2255 name: "InvalidECDHPoint-Server",
2256 config: Config{
2257 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2258 CurvePreferences: []CurveID{CurveP256},
2259 Bugs: ProtocolBugs{
2260 InvalidECDHPoint: true,
2261 },
2262 },
2263 shouldFail: true,
2264 expectedError: ":INVALID_ENCODING:",
2265 },
Adam Langley7c803a62015-06-15 15:35:05 -07002266 }
Adam Langley7c803a62015-06-15 15:35:05 -07002267 testCases = append(testCases, basicTests...)
2268}
2269
Adam Langley95c29f32014-06-20 12:00:00 -07002270func addCipherSuiteTests() {
2271 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002272 const psk = "12345"
2273 const pskIdentity = "luggage combo"
2274
Adam Langley95c29f32014-06-20 12:00:00 -07002275 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002276 var certFile string
2277 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002278 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002279 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002280 certFile = ecdsaCertificateFile
2281 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002282 } else {
2283 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002284 certFile = rsaCertificateFile
2285 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002286 }
2287
David Benjamin48cae082014-10-27 01:06:24 -04002288 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002289 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002290 flags = append(flags,
2291 "-psk", psk,
2292 "-psk-identity", pskIdentity)
2293 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002294 if hasComponent(suite.name, "NULL") {
2295 // NULL ciphers must be explicitly enabled.
2296 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2297 }
David Benjamin48cae082014-10-27 01:06:24 -04002298
Adam Langley95c29f32014-06-20 12:00:00 -07002299 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002300 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002301 continue
2302 }
2303
David Benjamin4298d772015-12-19 00:18:25 -05002304 shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30
2305
2306 expectedError := ""
2307 if shouldFail {
2308 expectedError = ":NO_SHARED_CIPHER:"
2309 }
David Benjamin025b3d32014-07-01 19:53:04 -04002310
David Benjamin76d8abe2014-08-14 16:25:34 -04002311 testCases = append(testCases, testCase{
2312 testType: serverTest,
2313 name: ver.name + "-" + suite.name + "-server",
2314 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002315 MinVersion: ver.version,
2316 MaxVersion: ver.version,
2317 CipherSuites: []uint16{suite.id},
2318 Certificates: []Certificate{cert},
2319 PreSharedKey: []byte(psk),
2320 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002321 },
2322 certFile: certFile,
2323 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002324 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002325 resumeSession: true,
David Benjamin4298d772015-12-19 00:18:25 -05002326 shouldFail: shouldFail,
2327 expectedError: expectedError,
2328 })
2329
2330 if shouldFail {
2331 continue
2332 }
2333
2334 testCases = append(testCases, testCase{
2335 testType: clientTest,
2336 name: ver.name + "-" + suite.name + "-client",
2337 config: Config{
2338 MinVersion: ver.version,
2339 MaxVersion: ver.version,
2340 CipherSuites: []uint16{suite.id},
2341 Certificates: []Certificate{cert},
2342 PreSharedKey: []byte(psk),
2343 PreSharedKeyIdentity: pskIdentity,
2344 },
2345 flags: flags,
2346 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002347 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002348
David Benjamin8b8c0062014-11-23 02:47:52 -05002349 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002350 testCases = append(testCases, testCase{
2351 testType: clientTest,
2352 protocol: dtls,
2353 name: "D" + ver.name + "-" + suite.name + "-client",
2354 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002355 MinVersion: ver.version,
2356 MaxVersion: ver.version,
2357 CipherSuites: []uint16{suite.id},
2358 Certificates: []Certificate{cert},
2359 PreSharedKey: []byte(psk),
2360 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002361 },
David Benjamin48cae082014-10-27 01:06:24 -04002362 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002363 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002364 })
2365 testCases = append(testCases, testCase{
2366 testType: serverTest,
2367 protocol: dtls,
2368 name: "D" + ver.name + "-" + suite.name + "-server",
2369 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002370 MinVersion: ver.version,
2371 MaxVersion: ver.version,
2372 CipherSuites: []uint16{suite.id},
2373 Certificates: []Certificate{cert},
2374 PreSharedKey: []byte(psk),
2375 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002376 },
2377 certFile: certFile,
2378 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002379 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002380 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002381 })
2382 }
Adam Langley95c29f32014-06-20 12:00:00 -07002383 }
David Benjamin2c99d282015-09-01 10:23:00 -04002384
2385 // Ensure both TLS and DTLS accept their maximum record sizes.
2386 testCases = append(testCases, testCase{
2387 name: suite.name + "-LargeRecord",
2388 config: Config{
2389 CipherSuites: []uint16{suite.id},
2390 Certificates: []Certificate{cert},
2391 PreSharedKey: []byte(psk),
2392 PreSharedKeyIdentity: pskIdentity,
2393 },
2394 flags: flags,
2395 messageLen: maxPlaintext,
2396 })
David Benjamin2c99d282015-09-01 10:23:00 -04002397 if isDTLSCipher(suite.name) {
2398 testCases = append(testCases, testCase{
2399 protocol: dtls,
2400 name: suite.name + "-LargeRecord-DTLS",
2401 config: Config{
2402 CipherSuites: []uint16{suite.id},
2403 Certificates: []Certificate{cert},
2404 PreSharedKey: []byte(psk),
2405 PreSharedKeyIdentity: pskIdentity,
2406 },
2407 flags: flags,
2408 messageLen: maxPlaintext,
2409 })
2410 }
Adam Langley95c29f32014-06-20 12:00:00 -07002411 }
Adam Langleya7997f12015-05-14 17:38:50 -07002412
2413 testCases = append(testCases, testCase{
2414 name: "WeakDH",
2415 config: Config{
2416 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2417 Bugs: ProtocolBugs{
2418 // This is a 1023-bit prime number, generated
2419 // with:
2420 // openssl gendh 1023 | openssl asn1parse -i
2421 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2422 },
2423 },
2424 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002425 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002426 })
Adam Langleycef75832015-09-03 14:51:12 -07002427
David Benjamincd24a392015-11-11 13:23:05 -08002428 testCases = append(testCases, testCase{
2429 name: "SillyDH",
2430 config: Config{
2431 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2432 Bugs: ProtocolBugs{
2433 // This is a 4097-bit prime number, generated
2434 // with:
2435 // openssl gendh 4097 | openssl asn1parse -i
2436 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2437 },
2438 },
2439 shouldFail: true,
2440 expectedError: ":DH_P_TOO_LONG:",
2441 })
2442
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002443 // This test ensures that Diffie-Hellman public values are padded with
2444 // zeros so that they're the same length as the prime. This is to avoid
2445 // hitting a bug in yaSSL.
2446 testCases = append(testCases, testCase{
2447 testType: serverTest,
2448 name: "DHPublicValuePadded",
2449 config: Config{
2450 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2451 Bugs: ProtocolBugs{
2452 RequireDHPublicValueLen: (1025 + 7) / 8,
2453 },
2454 },
2455 flags: []string{"-use-sparse-dh-prime"},
2456 })
David Benjamincd24a392015-11-11 13:23:05 -08002457
David Benjamin241ae832016-01-15 03:04:54 -05002458 // The server must be tolerant to bogus ciphers.
2459 const bogusCipher = 0x1234
2460 testCases = append(testCases, testCase{
2461 testType: serverTest,
2462 name: "UnknownCipher",
2463 config: Config{
2464 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2465 },
2466 })
2467
Adam Langleycef75832015-09-03 14:51:12 -07002468 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2469 // 1.1 specific cipher suite settings. A server is setup with the given
2470 // cipher lists and then a connection is made for each member of
2471 // expectations. The cipher suite that the server selects must match
2472 // the specified one.
2473 var versionSpecificCiphersTest = []struct {
2474 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2475 // expectations is a map from TLS version to cipher suite id.
2476 expectations map[uint16]uint16
2477 }{
2478 {
2479 // Test that the null case (where no version-specific ciphers are set)
2480 // works as expected.
2481 "RC4-SHA:AES128-SHA", // default ciphers
2482 "", // no ciphers specifically for TLS ≥ 1.0
2483 "", // no ciphers specifically for TLS ≥ 1.1
2484 map[uint16]uint16{
2485 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2486 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2487 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2488 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2489 },
2490 },
2491 {
2492 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2493 // cipher.
2494 "RC4-SHA:AES128-SHA", // default
2495 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2496 "", // no ciphers specifically for TLS ≥ 1.1
2497 map[uint16]uint16{
2498 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2499 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2500 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2501 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2502 },
2503 },
2504 {
2505 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2506 // cipher.
2507 "RC4-SHA:AES128-SHA", // default
2508 "", // no ciphers specifically for TLS ≥ 1.0
2509 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2510 map[uint16]uint16{
2511 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2512 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2513 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2514 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2515 },
2516 },
2517 {
2518 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2519 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2520 "RC4-SHA:AES128-SHA", // default
2521 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2522 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2523 map[uint16]uint16{
2524 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2525 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2526 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2527 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2528 },
2529 },
2530 }
2531
2532 for i, test := range versionSpecificCiphersTest {
2533 for version, expectedCipherSuite := range test.expectations {
2534 flags := []string{"-cipher", test.ciphersDefault}
2535 if len(test.ciphersTLS10) > 0 {
2536 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2537 }
2538 if len(test.ciphersTLS11) > 0 {
2539 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2540 }
2541
2542 testCases = append(testCases, testCase{
2543 testType: serverTest,
2544 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2545 config: Config{
2546 MaxVersion: version,
2547 MinVersion: version,
2548 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2549 },
2550 flags: flags,
2551 expectedCipher: expectedCipherSuite,
2552 })
2553 }
2554 }
Adam Langley95c29f32014-06-20 12:00:00 -07002555}
2556
2557func addBadECDSASignatureTests() {
2558 for badR := BadValue(1); badR < NumBadValues; badR++ {
2559 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002560 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002561 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2562 config: Config{
2563 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2564 Certificates: []Certificate{getECDSACertificate()},
2565 Bugs: ProtocolBugs{
2566 BadECDSAR: badR,
2567 BadECDSAS: badS,
2568 },
2569 },
2570 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002571 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002572 })
2573 }
2574 }
2575}
2576
Adam Langley80842bd2014-06-20 12:00:00 -07002577func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002578 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002579 name: "MaxCBCPadding",
2580 config: Config{
2581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2582 Bugs: ProtocolBugs{
2583 MaxPadding: true,
2584 },
2585 },
2586 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2587 })
David Benjamin025b3d32014-07-01 19:53:04 -04002588 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002589 name: "BadCBCPadding",
2590 config: Config{
2591 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2592 Bugs: ProtocolBugs{
2593 PaddingFirstByteBad: true,
2594 },
2595 },
2596 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002597 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002598 })
2599 // OpenSSL previously had an issue where the first byte of padding in
2600 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002601 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002602 name: "BadCBCPadding255",
2603 config: Config{
2604 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2605 Bugs: ProtocolBugs{
2606 MaxPadding: true,
2607 PaddingFirstByteBadIf255: true,
2608 },
2609 },
2610 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2611 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002612 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002613 })
2614}
2615
Kenny Root7fdeaf12014-08-05 15:23:37 -07002616func addCBCSplittingTests() {
2617 testCases = append(testCases, testCase{
2618 name: "CBCRecordSplitting",
2619 config: Config{
2620 MaxVersion: VersionTLS10,
2621 MinVersion: VersionTLS10,
2622 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2623 },
David Benjaminac8302a2015-09-01 17:18:15 -04002624 messageLen: -1, // read until EOF
2625 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002626 flags: []string{
2627 "-async",
2628 "-write-different-record-sizes",
2629 "-cbc-record-splitting",
2630 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002631 })
2632 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002633 name: "CBCRecordSplittingPartialWrite",
2634 config: Config{
2635 MaxVersion: VersionTLS10,
2636 MinVersion: VersionTLS10,
2637 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2638 },
2639 messageLen: -1, // read until EOF
2640 flags: []string{
2641 "-async",
2642 "-write-different-record-sizes",
2643 "-cbc-record-splitting",
2644 "-partial-write",
2645 },
2646 })
2647}
2648
David Benjamin636293b2014-07-08 17:59:18 -04002649func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002650 // Add a dummy cert pool to stress certificate authority parsing.
2651 // TODO(davidben): Add tests that those values parse out correctly.
2652 certPool := x509.NewCertPool()
2653 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2654 if err != nil {
2655 panic(err)
2656 }
2657 certPool.AddCert(cert)
2658
David Benjamin636293b2014-07-08 17:59:18 -04002659 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002660 testCases = append(testCases, testCase{
2661 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002662 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002663 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
2666 ClientAuth: RequireAnyClientCert,
2667 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002668 },
2669 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002670 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2671 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002672 },
2673 })
2674 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002675 testType: serverTest,
2676 name: ver.name + "-Server-ClientAuth-RSA",
2677 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002678 MinVersion: ver.version,
2679 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002680 Certificates: []Certificate{rsaCertificate},
2681 },
2682 flags: []string{"-require-any-client-certificate"},
2683 })
David Benjamine098ec22014-08-27 23:13:20 -04002684 if ver.version != VersionSSL30 {
2685 testCases = append(testCases, testCase{
2686 testType: serverTest,
2687 name: ver.name + "-Server-ClientAuth-ECDSA",
2688 config: Config{
2689 MinVersion: ver.version,
2690 MaxVersion: ver.version,
2691 Certificates: []Certificate{ecdsaCertificate},
2692 },
2693 flags: []string{"-require-any-client-certificate"},
2694 })
2695 testCases = append(testCases, testCase{
2696 testType: clientTest,
2697 name: ver.name + "-Client-ClientAuth-ECDSA",
2698 config: Config{
2699 MinVersion: ver.version,
2700 MaxVersion: ver.version,
2701 ClientAuth: RequireAnyClientCert,
2702 ClientCAs: certPool,
2703 },
2704 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002705 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2706 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002707 },
2708 })
2709 }
David Benjamin636293b2014-07-08 17:59:18 -04002710 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002711
2712 testCases = append(testCases, testCase{
2713 testType: serverTest,
2714 name: "RequireAnyClientCertificate",
2715 flags: []string{"-require-any-client-certificate"},
2716 shouldFail: true,
2717 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2718 })
2719
2720 testCases = append(testCases, testCase{
2721 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002722 name: "RequireAnyClientCertificate-SSL3",
2723 config: Config{
2724 MaxVersion: VersionSSL30,
2725 },
2726 flags: []string{"-require-any-client-certificate"},
2727 shouldFail: true,
2728 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2729 })
2730
2731 testCases = append(testCases, testCase{
2732 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002733 name: "SkipClientCertificate",
2734 config: Config{
2735 Bugs: ProtocolBugs{
2736 SkipClientCertificate: true,
2737 },
2738 },
2739 // Setting SSL_VERIFY_PEER allows anonymous clients.
2740 flags: []string{"-verify-peer"},
2741 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002742 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002743 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002744
2745 // Client auth is only legal in certificate-based ciphers.
2746 testCases = append(testCases, testCase{
2747 testType: clientTest,
2748 name: "ClientAuth-PSK",
2749 config: Config{
2750 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2751 PreSharedKey: []byte("secret"),
2752 ClientAuth: RequireAnyClientCert,
2753 },
2754 flags: []string{
2755 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2756 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2757 "-psk", "secret",
2758 },
2759 shouldFail: true,
2760 expectedError: ":UNEXPECTED_MESSAGE:",
2761 })
2762 testCases = append(testCases, testCase{
2763 testType: clientTest,
2764 name: "ClientAuth-ECDHE_PSK",
2765 config: Config{
2766 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2767 PreSharedKey: []byte("secret"),
2768 ClientAuth: RequireAnyClientCert,
2769 },
2770 flags: []string{
2771 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2772 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2773 "-psk", "secret",
2774 },
2775 shouldFail: true,
2776 expectedError: ":UNEXPECTED_MESSAGE:",
2777 })
David Benjamin636293b2014-07-08 17:59:18 -04002778}
2779
Adam Langley75712922014-10-10 16:23:43 -07002780func addExtendedMasterSecretTests() {
2781 const expectEMSFlag = "-expect-extended-master-secret"
2782
2783 for _, with := range []bool{false, true} {
2784 prefix := "No"
2785 var flags []string
2786 if with {
2787 prefix = ""
2788 flags = []string{expectEMSFlag}
2789 }
2790
2791 for _, isClient := range []bool{false, true} {
2792 suffix := "-Server"
2793 testType := serverTest
2794 if isClient {
2795 suffix = "-Client"
2796 testType = clientTest
2797 }
2798
2799 for _, ver := range tlsVersions {
2800 test := testCase{
2801 testType: testType,
2802 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2803 config: Config{
2804 MinVersion: ver.version,
2805 MaxVersion: ver.version,
2806 Bugs: ProtocolBugs{
2807 NoExtendedMasterSecret: !with,
2808 RequireExtendedMasterSecret: with,
2809 },
2810 },
David Benjamin48cae082014-10-27 01:06:24 -04002811 flags: flags,
2812 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002813 }
2814 if test.shouldFail {
2815 test.expectedLocalError = "extended master secret required but not supported by peer"
2816 }
2817 testCases = append(testCases, test)
2818 }
2819 }
2820 }
2821
Adam Langleyba5934b2015-06-02 10:50:35 -07002822 for _, isClient := range []bool{false, true} {
2823 for _, supportedInFirstConnection := range []bool{false, true} {
2824 for _, supportedInResumeConnection := range []bool{false, true} {
2825 boolToWord := func(b bool) string {
2826 if b {
2827 return "Yes"
2828 }
2829 return "No"
2830 }
2831 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2832 if isClient {
2833 suffix += "Client"
2834 } else {
2835 suffix += "Server"
2836 }
2837
2838 supportedConfig := Config{
2839 Bugs: ProtocolBugs{
2840 RequireExtendedMasterSecret: true,
2841 },
2842 }
2843
2844 noSupportConfig := Config{
2845 Bugs: ProtocolBugs{
2846 NoExtendedMasterSecret: true,
2847 },
2848 }
2849
2850 test := testCase{
2851 name: "ExtendedMasterSecret-" + suffix,
2852 resumeSession: true,
2853 }
2854
2855 if !isClient {
2856 test.testType = serverTest
2857 }
2858
2859 if supportedInFirstConnection {
2860 test.config = supportedConfig
2861 } else {
2862 test.config = noSupportConfig
2863 }
2864
2865 if supportedInResumeConnection {
2866 test.resumeConfig = &supportedConfig
2867 } else {
2868 test.resumeConfig = &noSupportConfig
2869 }
2870
2871 switch suffix {
2872 case "YesToYes-Client", "YesToYes-Server":
2873 // When a session is resumed, it should
2874 // still be aware that its master
2875 // secret was generated via EMS and
2876 // thus it's safe to use tls-unique.
2877 test.flags = []string{expectEMSFlag}
2878 case "NoToYes-Server":
2879 // If an original connection did not
2880 // contain EMS, but a resumption
2881 // handshake does, then a server should
2882 // not resume the session.
2883 test.expectResumeRejected = true
2884 case "YesToNo-Server":
2885 // Resuming an EMS session without the
2886 // EMS extension should cause the
2887 // server to abort the connection.
2888 test.shouldFail = true
2889 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2890 case "NoToYes-Client":
2891 // A client should abort a connection
2892 // where the server resumed a non-EMS
2893 // session but echoed the EMS
2894 // extension.
2895 test.shouldFail = true
2896 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2897 case "YesToNo-Client":
2898 // A client should abort a connection
2899 // where the server didn't echo EMS
2900 // when the session used it.
2901 test.shouldFail = true
2902 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2903 }
2904
2905 testCases = append(testCases, test)
2906 }
2907 }
2908 }
Adam Langley75712922014-10-10 16:23:43 -07002909}
2910
David Benjamin43ec06f2014-08-05 02:28:57 -04002911// Adds tests that try to cover the range of the handshake state machine, under
2912// various conditions. Some of these are redundant with other tests, but they
2913// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002914func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002915 var tests []testCase
2916
2917 // Basic handshake, with resumption. Client and server,
2918 // session ID and session ticket.
2919 tests = append(tests, testCase{
2920 name: "Basic-Client",
2921 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002922 // Ensure session tickets are used, not session IDs.
2923 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002924 })
2925 tests = append(tests, testCase{
2926 name: "Basic-Client-RenewTicket",
2927 config: Config{
2928 Bugs: ProtocolBugs{
2929 RenewTicketOnResume: true,
2930 },
2931 },
David Benjaminba4594a2015-06-18 18:36:15 -04002932 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002933 resumeSession: true,
2934 })
2935 tests = append(tests, testCase{
2936 name: "Basic-Client-NoTicket",
2937 config: Config{
2938 SessionTicketsDisabled: true,
2939 },
2940 resumeSession: true,
2941 })
2942 tests = append(tests, testCase{
2943 name: "Basic-Client-Implicit",
2944 flags: []string{"-implicit-handshake"},
2945 resumeSession: true,
2946 })
2947 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002948 testType: serverTest,
2949 name: "Basic-Server",
2950 config: Config{
2951 Bugs: ProtocolBugs{
2952 RequireSessionTickets: true,
2953 },
2954 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002955 resumeSession: true,
2956 })
2957 tests = append(tests, testCase{
2958 testType: serverTest,
2959 name: "Basic-Server-NoTickets",
2960 config: Config{
2961 SessionTicketsDisabled: true,
2962 },
2963 resumeSession: true,
2964 })
2965 tests = append(tests, testCase{
2966 testType: serverTest,
2967 name: "Basic-Server-Implicit",
2968 flags: []string{"-implicit-handshake"},
2969 resumeSession: true,
2970 })
2971 tests = append(tests, testCase{
2972 testType: serverTest,
2973 name: "Basic-Server-EarlyCallback",
2974 flags: []string{"-use-early-callback"},
2975 resumeSession: true,
2976 })
2977
2978 // TLS client auth.
2979 tests = append(tests, testCase{
2980 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002981 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002982 config: Config{
2983 ClientAuth: RequestClientCert,
2984 },
2985 })
2986 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002987 testType: serverTest,
2988 name: "ClientAuth-NoCertificate-Server",
2989 // Setting SSL_VERIFY_PEER allows anonymous clients.
2990 flags: []string{"-verify-peer"},
2991 })
2992 if protocol == tls {
2993 tests = append(tests, testCase{
2994 testType: clientTest,
2995 name: "ClientAuth-NoCertificate-Client-SSL3",
2996 config: Config{
2997 MaxVersion: VersionSSL30,
2998 ClientAuth: RequestClientCert,
2999 },
3000 })
3001 tests = append(tests, testCase{
3002 testType: serverTest,
3003 name: "ClientAuth-NoCertificate-Server-SSL3",
3004 config: Config{
3005 MaxVersion: VersionSSL30,
3006 },
3007 // Setting SSL_VERIFY_PEER allows anonymous clients.
3008 flags: []string{"-verify-peer"},
3009 })
3010 }
3011 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003012 testType: clientTest,
3013 name: "ClientAuth-NoCertificate-OldCallback",
3014 config: Config{
3015 ClientAuth: RequestClientCert,
3016 },
3017 flags: []string{"-use-old-client-cert-callback"},
3018 })
3019 tests = append(tests, testCase{
3020 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003021 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003022 config: Config{
3023 ClientAuth: RequireAnyClientCert,
3024 },
3025 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003026 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3027 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003028 },
3029 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003030 tests = append(tests, testCase{
3031 testType: clientTest,
3032 name: "ClientAuth-ECDSA-Client",
3033 config: Config{
3034 ClientAuth: RequireAnyClientCert,
3035 },
3036 flags: []string{
3037 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3038 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3039 },
3040 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003041 tests = append(tests, testCase{
3042 testType: clientTest,
3043 name: "ClientAuth-OldCallback",
3044 config: Config{
3045 ClientAuth: RequireAnyClientCert,
3046 },
3047 flags: []string{
3048 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3049 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3050 "-use-old-client-cert-callback",
3051 },
3052 })
3053
David Benjaminb4d65fd2015-05-29 17:11:21 -04003054 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003055 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04003056 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003057 testType: serverTest,
3058 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04003059 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003060 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04003061 },
3062 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07003063 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3064 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04003065 },
3066 })
nagendra modadugu601448a2015-07-24 09:31:31 -07003067 tests = append(tests, testCase{
3068 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003069 name: "Basic-Server-ECDHE-RSA",
3070 config: Config{
3071 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3072 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003073 flags: []string{
3074 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3075 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003076 },
3077 })
3078 tests = append(tests, testCase{
3079 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003080 name: "Basic-Server-ECDHE-ECDSA",
3081 config: Config{
3082 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3083 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003084 flags: []string{
3085 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3086 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003087 },
3088 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04003089 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 tests = append(tests, testCase{
3091 testType: serverTest,
3092 name: "ClientAuth-Server",
3093 config: Config{
3094 Certificates: []Certificate{rsaCertificate},
3095 },
3096 flags: []string{"-require-any-client-certificate"},
3097 })
3098
3099 // No session ticket support; server doesn't send NewSessionTicket.
3100 tests = append(tests, testCase{
3101 name: "SessionTicketsDisabled-Client",
3102 config: Config{
3103 SessionTicketsDisabled: true,
3104 },
3105 })
3106 tests = append(tests, testCase{
3107 testType: serverTest,
3108 name: "SessionTicketsDisabled-Server",
3109 config: Config{
3110 SessionTicketsDisabled: true,
3111 },
3112 })
3113
3114 // Skip ServerKeyExchange in PSK key exchange if there's no
3115 // identity hint.
3116 tests = append(tests, testCase{
3117 name: "EmptyPSKHint-Client",
3118 config: Config{
3119 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3120 PreSharedKey: []byte("secret"),
3121 },
3122 flags: []string{"-psk", "secret"},
3123 })
3124 tests = append(tests, testCase{
3125 testType: serverTest,
3126 name: "EmptyPSKHint-Server",
3127 config: Config{
3128 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3129 PreSharedKey: []byte("secret"),
3130 },
3131 flags: []string{"-psk", "secret"},
3132 })
3133
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003134 tests = append(tests, testCase{
3135 testType: clientTest,
3136 name: "OCSPStapling-Client",
3137 flags: []string{
3138 "-enable-ocsp-stapling",
3139 "-expect-ocsp-response",
3140 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003141 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003142 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003143 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003144 })
3145
3146 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04003147 testType: serverTest,
3148 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003149 expectedOCSPResponse: testOCSPResponse,
3150 flags: []string{
3151 "-ocsp-response",
3152 base64.StdEncoding.EncodeToString(testOCSPResponse),
3153 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003154 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003155 })
3156
Paul Lietar8f1c2682015-08-18 12:21:54 +01003157 tests = append(tests, testCase{
3158 testType: clientTest,
3159 name: "CertificateVerificationSucceed",
3160 flags: []string{
3161 "-verify-peer",
3162 },
3163 })
3164
3165 tests = append(tests, testCase{
3166 testType: clientTest,
3167 name: "CertificateVerificationFail",
3168 flags: []string{
3169 "-verify-fail",
3170 "-verify-peer",
3171 },
3172 shouldFail: true,
3173 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3174 })
3175
3176 tests = append(tests, testCase{
3177 testType: clientTest,
3178 name: "CertificateVerificationSoftFail",
3179 flags: []string{
3180 "-verify-fail",
3181 "-expect-verify-result",
3182 },
3183 })
3184
David Benjamin760b1dd2015-05-15 23:33:48 -04003185 if protocol == tls {
3186 tests = append(tests, testCase{
3187 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003188 renegotiate: 1,
3189 flags: []string{
3190 "-renegotiate-freely",
3191 "-expect-total-renegotiations", "1",
3192 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003193 })
3194 // NPN on client and server; results in post-handshake message.
3195 tests = append(tests, testCase{
3196 name: "NPN-Client",
3197 config: Config{
3198 NextProtos: []string{"foo"},
3199 },
3200 flags: []string{"-select-next-proto", "foo"},
3201 expectedNextProto: "foo",
3202 expectedNextProtoType: npn,
3203 })
3204 tests = append(tests, testCase{
3205 testType: serverTest,
3206 name: "NPN-Server",
3207 config: Config{
3208 NextProtos: []string{"bar"},
3209 },
3210 flags: []string{
3211 "-advertise-npn", "\x03foo\x03bar\x03baz",
3212 "-expect-next-proto", "bar",
3213 },
3214 expectedNextProto: "bar",
3215 expectedNextProtoType: npn,
3216 })
3217
3218 // TODO(davidben): Add tests for when False Start doesn't trigger.
3219
3220 // Client does False Start and negotiates NPN.
3221 tests = append(tests, testCase{
3222 name: "FalseStart",
3223 config: Config{
3224 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3225 NextProtos: []string{"foo"},
3226 Bugs: ProtocolBugs{
3227 ExpectFalseStart: true,
3228 },
3229 },
3230 flags: []string{
3231 "-false-start",
3232 "-select-next-proto", "foo",
3233 },
3234 shimWritesFirst: true,
3235 resumeSession: true,
3236 })
3237
3238 // Client does False Start and negotiates ALPN.
3239 tests = append(tests, testCase{
3240 name: "FalseStart-ALPN",
3241 config: Config{
3242 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3243 NextProtos: []string{"foo"},
3244 Bugs: ProtocolBugs{
3245 ExpectFalseStart: true,
3246 },
3247 },
3248 flags: []string{
3249 "-false-start",
3250 "-advertise-alpn", "\x03foo",
3251 },
3252 shimWritesFirst: true,
3253 resumeSession: true,
3254 })
3255
3256 // Client does False Start but doesn't explicitly call
3257 // SSL_connect.
3258 tests = append(tests, testCase{
3259 name: "FalseStart-Implicit",
3260 config: Config{
3261 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3262 NextProtos: []string{"foo"},
3263 },
3264 flags: []string{
3265 "-implicit-handshake",
3266 "-false-start",
3267 "-advertise-alpn", "\x03foo",
3268 },
3269 })
3270
3271 // False Start without session tickets.
3272 tests = append(tests, testCase{
3273 name: "FalseStart-SessionTicketsDisabled",
3274 config: Config{
3275 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3276 NextProtos: []string{"foo"},
3277 SessionTicketsDisabled: true,
3278 Bugs: ProtocolBugs{
3279 ExpectFalseStart: true,
3280 },
3281 },
3282 flags: []string{
3283 "-false-start",
3284 "-select-next-proto", "foo",
3285 },
3286 shimWritesFirst: true,
3287 })
3288
3289 // Server parses a V2ClientHello.
3290 tests = append(tests, testCase{
3291 testType: serverTest,
3292 name: "SendV2ClientHello",
3293 config: Config{
3294 // Choose a cipher suite that does not involve
3295 // elliptic curves, so no extensions are
3296 // involved.
3297 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3298 Bugs: ProtocolBugs{
3299 SendV2ClientHello: true,
3300 },
3301 },
3302 })
3303
3304 // Client sends a Channel ID.
3305 tests = append(tests, testCase{
3306 name: "ChannelID-Client",
3307 config: Config{
3308 RequestChannelID: true,
3309 },
Adam Langley7c803a62015-06-15 15:35:05 -07003310 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003311 resumeSession: true,
3312 expectChannelID: true,
3313 })
3314
3315 // Server accepts a Channel ID.
3316 tests = append(tests, testCase{
3317 testType: serverTest,
3318 name: "ChannelID-Server",
3319 config: Config{
3320 ChannelID: channelIDKey,
3321 },
3322 flags: []string{
3323 "-expect-channel-id",
3324 base64.StdEncoding.EncodeToString(channelIDBytes),
3325 },
3326 resumeSession: true,
3327 expectChannelID: true,
3328 })
David Benjamin30789da2015-08-29 22:56:45 -04003329
3330 // Bidirectional shutdown with the runner initiating.
3331 tests = append(tests, testCase{
3332 name: "Shutdown-Runner",
3333 config: Config{
3334 Bugs: ProtocolBugs{
3335 ExpectCloseNotify: true,
3336 },
3337 },
3338 flags: []string{"-check-close-notify"},
3339 })
3340
3341 // Bidirectional shutdown with the shim initiating. The runner,
3342 // in the meantime, sends garbage before the close_notify which
3343 // the shim must ignore.
3344 tests = append(tests, testCase{
3345 name: "Shutdown-Shim",
3346 config: Config{
3347 Bugs: ProtocolBugs{
3348 ExpectCloseNotify: true,
3349 },
3350 },
3351 shimShutsDown: true,
3352 sendEmptyRecords: 1,
3353 sendWarningAlerts: 1,
3354 flags: []string{"-check-close-notify"},
3355 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003356 } else {
3357 tests = append(tests, testCase{
3358 name: "SkipHelloVerifyRequest",
3359 config: Config{
3360 Bugs: ProtocolBugs{
3361 SkipHelloVerifyRequest: true,
3362 },
3363 },
3364 })
3365 }
3366
David Benjamin760b1dd2015-05-15 23:33:48 -04003367 for _, test := range tests {
3368 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003369 if protocol == dtls {
3370 test.name += "-DTLS"
3371 }
3372 if async {
3373 test.name += "-Async"
3374 test.flags = append(test.flags, "-async")
3375 } else {
3376 test.name += "-Sync"
3377 }
3378 if splitHandshake {
3379 test.name += "-SplitHandshakeRecords"
3380 test.config.Bugs.MaxHandshakeRecordLength = 1
3381 if protocol == dtls {
3382 test.config.Bugs.MaxPacketLength = 256
3383 test.flags = append(test.flags, "-mtu", "256")
3384 }
3385 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003386 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003387 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003388}
3389
Adam Langley524e7172015-02-20 16:04:00 -08003390func addDDoSCallbackTests() {
3391 // DDoS callback.
3392
3393 for _, resume := range []bool{false, true} {
3394 suffix := "Resume"
3395 if resume {
3396 suffix = "No" + suffix
3397 }
3398
3399 testCases = append(testCases, testCase{
3400 testType: serverTest,
3401 name: "Server-DDoS-OK-" + suffix,
3402 flags: []string{"-install-ddos-callback"},
3403 resumeSession: resume,
3404 })
3405
3406 failFlag := "-fail-ddos-callback"
3407 if resume {
3408 failFlag = "-fail-second-ddos-callback"
3409 }
3410 testCases = append(testCases, testCase{
3411 testType: serverTest,
3412 name: "Server-DDoS-Reject-" + suffix,
3413 flags: []string{"-install-ddos-callback", failFlag},
3414 resumeSession: resume,
3415 shouldFail: true,
3416 expectedError: ":CONNECTION_REJECTED:",
3417 })
3418 }
3419}
3420
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003421func addVersionNegotiationTests() {
3422 for i, shimVers := range tlsVersions {
3423 // Assemble flags to disable all newer versions on the shim.
3424 var flags []string
3425 for _, vers := range tlsVersions[i+1:] {
3426 flags = append(flags, vers.flag)
3427 }
3428
3429 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003430 protocols := []protocol{tls}
3431 if runnerVers.hasDTLS && shimVers.hasDTLS {
3432 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003433 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003434 for _, protocol := range protocols {
3435 expectedVersion := shimVers.version
3436 if runnerVers.version < shimVers.version {
3437 expectedVersion = runnerVers.version
3438 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003439
David Benjamin8b8c0062014-11-23 02:47:52 -05003440 suffix := shimVers.name + "-" + runnerVers.name
3441 if protocol == dtls {
3442 suffix += "-DTLS"
3443 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003444
David Benjamin1eb367c2014-12-12 18:17:51 -05003445 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3446
David Benjamin1e29a6b2014-12-10 02:27:24 -05003447 clientVers := shimVers.version
3448 if clientVers > VersionTLS10 {
3449 clientVers = VersionTLS10
3450 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003451 testCases = append(testCases, testCase{
3452 protocol: protocol,
3453 testType: clientTest,
3454 name: "VersionNegotiation-Client-" + suffix,
3455 config: Config{
3456 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003457 Bugs: ProtocolBugs{
3458 ExpectInitialRecordVersion: clientVers,
3459 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003460 },
3461 flags: flags,
3462 expectedVersion: expectedVersion,
3463 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003464 testCases = append(testCases, testCase{
3465 protocol: protocol,
3466 testType: clientTest,
3467 name: "VersionNegotiation-Client2-" + suffix,
3468 config: Config{
3469 MaxVersion: runnerVers.version,
3470 Bugs: ProtocolBugs{
3471 ExpectInitialRecordVersion: clientVers,
3472 },
3473 },
3474 flags: []string{"-max-version", shimVersFlag},
3475 expectedVersion: expectedVersion,
3476 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003477
3478 testCases = append(testCases, testCase{
3479 protocol: protocol,
3480 testType: serverTest,
3481 name: "VersionNegotiation-Server-" + suffix,
3482 config: Config{
3483 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003484 Bugs: ProtocolBugs{
3485 ExpectInitialRecordVersion: expectedVersion,
3486 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003487 },
3488 flags: flags,
3489 expectedVersion: expectedVersion,
3490 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003491 testCases = append(testCases, testCase{
3492 protocol: protocol,
3493 testType: serverTest,
3494 name: "VersionNegotiation-Server2-" + suffix,
3495 config: Config{
3496 MaxVersion: runnerVers.version,
3497 Bugs: ProtocolBugs{
3498 ExpectInitialRecordVersion: expectedVersion,
3499 },
3500 },
3501 flags: []string{"-max-version", shimVersFlag},
3502 expectedVersion: expectedVersion,
3503 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003504 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003505 }
3506 }
3507}
3508
David Benjaminaccb4542014-12-12 23:44:33 -05003509func addMinimumVersionTests() {
3510 for i, shimVers := range tlsVersions {
3511 // Assemble flags to disable all older versions on the shim.
3512 var flags []string
3513 for _, vers := range tlsVersions[:i] {
3514 flags = append(flags, vers.flag)
3515 }
3516
3517 for _, runnerVers := range tlsVersions {
3518 protocols := []protocol{tls}
3519 if runnerVers.hasDTLS && shimVers.hasDTLS {
3520 protocols = append(protocols, dtls)
3521 }
3522 for _, protocol := range protocols {
3523 suffix := shimVers.name + "-" + runnerVers.name
3524 if protocol == dtls {
3525 suffix += "-DTLS"
3526 }
3527 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3528
David Benjaminaccb4542014-12-12 23:44:33 -05003529 var expectedVersion uint16
3530 var shouldFail bool
3531 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003532 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003533 if runnerVers.version >= shimVers.version {
3534 expectedVersion = runnerVers.version
3535 } else {
3536 shouldFail = true
3537 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamina565d292015-12-30 16:51:32 -05003538 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05003539 }
3540
3541 testCases = append(testCases, testCase{
3542 protocol: protocol,
3543 testType: clientTest,
3544 name: "MinimumVersion-Client-" + suffix,
3545 config: Config{
3546 MaxVersion: runnerVers.version,
3547 },
David Benjamin87909c02014-12-13 01:55:01 -05003548 flags: flags,
3549 expectedVersion: expectedVersion,
3550 shouldFail: shouldFail,
3551 expectedError: expectedError,
3552 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003553 })
3554 testCases = append(testCases, testCase{
3555 protocol: protocol,
3556 testType: clientTest,
3557 name: "MinimumVersion-Client2-" + suffix,
3558 config: Config{
3559 MaxVersion: runnerVers.version,
3560 },
David Benjamin87909c02014-12-13 01:55:01 -05003561 flags: []string{"-min-version", shimVersFlag},
3562 expectedVersion: expectedVersion,
3563 shouldFail: shouldFail,
3564 expectedError: expectedError,
3565 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003566 })
3567
3568 testCases = append(testCases, testCase{
3569 protocol: protocol,
3570 testType: serverTest,
3571 name: "MinimumVersion-Server-" + suffix,
3572 config: Config{
3573 MaxVersion: runnerVers.version,
3574 },
David Benjamin87909c02014-12-13 01:55:01 -05003575 flags: flags,
3576 expectedVersion: expectedVersion,
3577 shouldFail: shouldFail,
3578 expectedError: expectedError,
3579 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003580 })
3581 testCases = append(testCases, testCase{
3582 protocol: protocol,
3583 testType: serverTest,
3584 name: "MinimumVersion-Server2-" + suffix,
3585 config: Config{
3586 MaxVersion: runnerVers.version,
3587 },
David Benjamin87909c02014-12-13 01:55:01 -05003588 flags: []string{"-min-version", shimVersFlag},
3589 expectedVersion: expectedVersion,
3590 shouldFail: shouldFail,
3591 expectedError: expectedError,
3592 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003593 })
3594 }
3595 }
3596 }
3597}
3598
David Benjamine78bfde2014-09-06 12:45:15 -04003599func addExtensionTests() {
3600 testCases = append(testCases, testCase{
3601 testType: clientTest,
3602 name: "DuplicateExtensionClient",
3603 config: Config{
3604 Bugs: ProtocolBugs{
3605 DuplicateExtension: true,
3606 },
3607 },
3608 shouldFail: true,
3609 expectedLocalError: "remote error: error decoding message",
3610 })
3611 testCases = append(testCases, testCase{
3612 testType: serverTest,
3613 name: "DuplicateExtensionServer",
3614 config: Config{
3615 Bugs: ProtocolBugs{
3616 DuplicateExtension: true,
3617 },
3618 },
3619 shouldFail: true,
3620 expectedLocalError: "remote error: error decoding message",
3621 })
3622 testCases = append(testCases, testCase{
3623 testType: clientTest,
3624 name: "ServerNameExtensionClient",
3625 config: Config{
3626 Bugs: ProtocolBugs{
3627 ExpectServerName: "example.com",
3628 },
3629 },
3630 flags: []string{"-host-name", "example.com"},
3631 })
3632 testCases = append(testCases, testCase{
3633 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003634 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003635 config: Config{
3636 Bugs: ProtocolBugs{
3637 ExpectServerName: "mismatch.com",
3638 },
3639 },
3640 flags: []string{"-host-name", "example.com"},
3641 shouldFail: true,
3642 expectedLocalError: "tls: unexpected server name",
3643 })
3644 testCases = append(testCases, testCase{
3645 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003646 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003647 config: Config{
3648 Bugs: ProtocolBugs{
3649 ExpectServerName: "missing.com",
3650 },
3651 },
3652 shouldFail: true,
3653 expectedLocalError: "tls: unexpected server name",
3654 })
3655 testCases = append(testCases, testCase{
3656 testType: serverTest,
3657 name: "ServerNameExtensionServer",
3658 config: Config{
3659 ServerName: "example.com",
3660 },
3661 flags: []string{"-expect-server-name", "example.com"},
3662 resumeSession: true,
3663 })
David Benjaminae2888f2014-09-06 12:58:58 -04003664 testCases = append(testCases, testCase{
3665 testType: clientTest,
3666 name: "ALPNClient",
3667 config: Config{
3668 NextProtos: []string{"foo"},
3669 },
3670 flags: []string{
3671 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3672 "-expect-alpn", "foo",
3673 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003674 expectedNextProto: "foo",
3675 expectedNextProtoType: alpn,
3676 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003677 })
3678 testCases = append(testCases, testCase{
3679 testType: serverTest,
3680 name: "ALPNServer",
3681 config: Config{
3682 NextProtos: []string{"foo", "bar", "baz"},
3683 },
3684 flags: []string{
3685 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3686 "-select-alpn", "foo",
3687 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003688 expectedNextProto: "foo",
3689 expectedNextProtoType: alpn,
3690 resumeSession: true,
3691 })
David Benjamin594e7d22016-03-17 17:49:56 -04003692 testCases = append(testCases, testCase{
3693 testType: serverTest,
3694 name: "ALPNServer-Decline",
3695 config: Config{
3696 NextProtos: []string{"foo", "bar", "baz"},
3697 },
3698 flags: []string{"-decline-alpn"},
3699 expectNoNextProto: true,
3700 resumeSession: true,
3701 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003702 // Test that the server prefers ALPN over NPN.
3703 testCases = append(testCases, testCase{
3704 testType: serverTest,
3705 name: "ALPNServer-Preferred",
3706 config: Config{
3707 NextProtos: []string{"foo", "bar", "baz"},
3708 },
3709 flags: []string{
3710 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3711 "-select-alpn", "foo",
3712 "-advertise-npn", "\x03foo\x03bar\x03baz",
3713 },
3714 expectedNextProto: "foo",
3715 expectedNextProtoType: alpn,
3716 resumeSession: true,
3717 })
3718 testCases = append(testCases, testCase{
3719 testType: serverTest,
3720 name: "ALPNServer-Preferred-Swapped",
3721 config: Config{
3722 NextProtos: []string{"foo", "bar", "baz"},
3723 Bugs: ProtocolBugs{
3724 SwapNPNAndALPN: true,
3725 },
3726 },
3727 flags: []string{
3728 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3729 "-select-alpn", "foo",
3730 "-advertise-npn", "\x03foo\x03bar\x03baz",
3731 },
3732 expectedNextProto: "foo",
3733 expectedNextProtoType: alpn,
3734 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003735 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003736 var emptyString string
3737 testCases = append(testCases, testCase{
3738 testType: clientTest,
3739 name: "ALPNClient-EmptyProtocolName",
3740 config: Config{
3741 NextProtos: []string{""},
3742 Bugs: ProtocolBugs{
3743 // A server returning an empty ALPN protocol
3744 // should be rejected.
3745 ALPNProtocol: &emptyString,
3746 },
3747 },
3748 flags: []string{
3749 "-advertise-alpn", "\x03foo",
3750 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003751 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003752 expectedError: ":PARSE_TLSEXT:",
3753 })
3754 testCases = append(testCases, testCase{
3755 testType: serverTest,
3756 name: "ALPNServer-EmptyProtocolName",
3757 config: Config{
3758 // A ClientHello containing an empty ALPN protocol
3759 // should be rejected.
3760 NextProtos: []string{"foo", "", "baz"},
3761 },
3762 flags: []string{
3763 "-select-alpn", "foo",
3764 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003765 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003766 expectedError: ":PARSE_TLSEXT:",
3767 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003768 // Test that negotiating both NPN and ALPN is forbidden.
3769 testCases = append(testCases, testCase{
3770 name: "NegotiateALPNAndNPN",
3771 config: Config{
3772 NextProtos: []string{"foo", "bar", "baz"},
3773 Bugs: ProtocolBugs{
3774 NegotiateALPNAndNPN: true,
3775 },
3776 },
3777 flags: []string{
3778 "-advertise-alpn", "\x03foo",
3779 "-select-next-proto", "foo",
3780 },
3781 shouldFail: true,
3782 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3783 })
3784 testCases = append(testCases, testCase{
3785 name: "NegotiateALPNAndNPN-Swapped",
3786 config: Config{
3787 NextProtos: []string{"foo", "bar", "baz"},
3788 Bugs: ProtocolBugs{
3789 NegotiateALPNAndNPN: true,
3790 SwapNPNAndALPN: true,
3791 },
3792 },
3793 flags: []string{
3794 "-advertise-alpn", "\x03foo",
3795 "-select-next-proto", "foo",
3796 },
3797 shouldFail: true,
3798 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3799 })
David Benjamin091c4b92015-10-26 13:33:21 -04003800 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3801 testCases = append(testCases, testCase{
3802 name: "DisableNPN",
3803 config: Config{
3804 NextProtos: []string{"foo"},
3805 },
3806 flags: []string{
3807 "-select-next-proto", "foo",
3808 "-disable-npn",
3809 },
3810 expectNoNextProto: true,
3811 })
Adam Langley38311732014-10-16 19:04:35 -07003812 // Resume with a corrupt ticket.
3813 testCases = append(testCases, testCase{
3814 testType: serverTest,
3815 name: "CorruptTicket",
3816 config: Config{
3817 Bugs: ProtocolBugs{
3818 CorruptTicket: true,
3819 },
3820 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003821 resumeSession: true,
3822 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003823 })
David Benjamind98452d2015-06-16 14:16:23 -04003824 // Test the ticket callback, with and without renewal.
3825 testCases = append(testCases, testCase{
3826 testType: serverTest,
3827 name: "TicketCallback",
3828 resumeSession: true,
3829 flags: []string{"-use-ticket-callback"},
3830 })
3831 testCases = append(testCases, testCase{
3832 testType: serverTest,
3833 name: "TicketCallback-Renew",
3834 config: Config{
3835 Bugs: ProtocolBugs{
3836 ExpectNewTicket: true,
3837 },
3838 },
3839 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3840 resumeSession: true,
3841 })
Adam Langley38311732014-10-16 19:04:35 -07003842 // Resume with an oversized session id.
3843 testCases = append(testCases, testCase{
3844 testType: serverTest,
3845 name: "OversizedSessionId",
3846 config: Config{
3847 Bugs: ProtocolBugs{
3848 OversizedSessionId: true,
3849 },
3850 },
3851 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003852 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003853 expectedError: ":DECODE_ERROR:",
3854 })
David Benjaminca6c8262014-11-15 19:06:08 -05003855 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3856 // are ignored.
3857 testCases = append(testCases, testCase{
3858 protocol: dtls,
3859 name: "SRTP-Client",
3860 config: Config{
3861 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3862 },
3863 flags: []string{
3864 "-srtp-profiles",
3865 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3866 },
3867 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3868 })
3869 testCases = append(testCases, testCase{
3870 protocol: dtls,
3871 testType: serverTest,
3872 name: "SRTP-Server",
3873 config: Config{
3874 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3875 },
3876 flags: []string{
3877 "-srtp-profiles",
3878 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3879 },
3880 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3881 })
3882 // Test that the MKI is ignored.
3883 testCases = append(testCases, testCase{
3884 protocol: dtls,
3885 testType: serverTest,
3886 name: "SRTP-Server-IgnoreMKI",
3887 config: Config{
3888 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3889 Bugs: ProtocolBugs{
3890 SRTPMasterKeyIdentifer: "bogus",
3891 },
3892 },
3893 flags: []string{
3894 "-srtp-profiles",
3895 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3896 },
3897 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3898 })
3899 // Test that SRTP isn't negotiated on the server if there were
3900 // no matching profiles.
3901 testCases = append(testCases, testCase{
3902 protocol: dtls,
3903 testType: serverTest,
3904 name: "SRTP-Server-NoMatch",
3905 config: Config{
3906 SRTPProtectionProfiles: []uint16{100, 101, 102},
3907 },
3908 flags: []string{
3909 "-srtp-profiles",
3910 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3911 },
3912 expectedSRTPProtectionProfile: 0,
3913 })
3914 // Test that the server returning an invalid SRTP profile is
3915 // flagged as an error by the client.
3916 testCases = append(testCases, testCase{
3917 protocol: dtls,
3918 name: "SRTP-Client-NoMatch",
3919 config: Config{
3920 Bugs: ProtocolBugs{
3921 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3922 },
3923 },
3924 flags: []string{
3925 "-srtp-profiles",
3926 "SRTP_AES128_CM_SHA1_80",
3927 },
3928 shouldFail: true,
3929 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3930 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003931 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003932 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003933 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003934 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003935 flags: []string{
3936 "-enable-signed-cert-timestamps",
3937 "-expect-signed-cert-timestamps",
3938 base64.StdEncoding.EncodeToString(testSCTList),
3939 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003940 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003941 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003942 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04003943 name: "SendSCTListOnResume",
3944 config: Config{
3945 Bugs: ProtocolBugs{
3946 SendSCTListOnResume: []byte("bogus"),
3947 },
3948 },
3949 flags: []string{
3950 "-enable-signed-cert-timestamps",
3951 "-expect-signed-cert-timestamps",
3952 base64.StdEncoding.EncodeToString(testSCTList),
3953 },
3954 resumeSession: true,
3955 })
3956 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003957 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003958 testType: serverTest,
3959 flags: []string{
3960 "-signed-cert-timestamps",
3961 base64.StdEncoding.EncodeToString(testSCTList),
3962 },
3963 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003964 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003965 })
3966 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003967 testType: clientTest,
3968 name: "ClientHelloPadding",
3969 config: Config{
3970 Bugs: ProtocolBugs{
3971 RequireClientHelloSize: 512,
3972 },
3973 },
3974 // This hostname just needs to be long enough to push the
3975 // ClientHello into F5's danger zone between 256 and 511 bytes
3976 // long.
3977 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3978 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003979
3980 // Extensions should not function in SSL 3.0.
3981 testCases = append(testCases, testCase{
3982 testType: serverTest,
3983 name: "SSLv3Extensions-NoALPN",
3984 config: Config{
3985 MaxVersion: VersionSSL30,
3986 NextProtos: []string{"foo", "bar", "baz"},
3987 },
3988 flags: []string{
3989 "-select-alpn", "foo",
3990 },
3991 expectNoNextProto: true,
3992 })
3993
3994 // Test session tickets separately as they follow a different codepath.
3995 testCases = append(testCases, testCase{
3996 testType: serverTest,
3997 name: "SSLv3Extensions-NoTickets",
3998 config: Config{
3999 MaxVersion: VersionSSL30,
4000 Bugs: ProtocolBugs{
4001 // Historically, session tickets in SSL 3.0
4002 // failed in different ways depending on whether
4003 // the client supported renegotiation_info.
4004 NoRenegotiationInfo: true,
4005 },
4006 },
4007 resumeSession: true,
4008 })
4009 testCases = append(testCases, testCase{
4010 testType: serverTest,
4011 name: "SSLv3Extensions-NoTickets2",
4012 config: Config{
4013 MaxVersion: VersionSSL30,
4014 },
4015 resumeSession: true,
4016 })
4017
4018 // But SSL 3.0 does send and process renegotiation_info.
4019 testCases = append(testCases, testCase{
4020 testType: serverTest,
4021 name: "SSLv3Extensions-RenegotiationInfo",
4022 config: Config{
4023 MaxVersion: VersionSSL30,
4024 Bugs: ProtocolBugs{
4025 RequireRenegotiationInfo: true,
4026 },
4027 },
4028 })
4029 testCases = append(testCases, testCase{
4030 testType: serverTest,
4031 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4032 config: Config{
4033 MaxVersion: VersionSSL30,
4034 Bugs: ProtocolBugs{
4035 NoRenegotiationInfo: true,
4036 SendRenegotiationSCSV: true,
4037 RequireRenegotiationInfo: true,
4038 },
4039 },
4040 })
David Benjamine78bfde2014-09-06 12:45:15 -04004041}
4042
David Benjamin01fe8202014-09-24 15:21:44 -04004043func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004044 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004045 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004046 protocols := []protocol{tls}
4047 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4048 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004049 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004050 for _, protocol := range protocols {
4051 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4052 if protocol == dtls {
4053 suffix += "-DTLS"
4054 }
4055
David Benjaminece3de92015-03-16 18:02:20 -04004056 if sessionVers.version == resumeVers.version {
4057 testCases = append(testCases, testCase{
4058 protocol: protocol,
4059 name: "Resume-Client" + suffix,
4060 resumeSession: true,
4061 config: Config{
4062 MaxVersion: sessionVers.version,
4063 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004064 },
David Benjaminece3de92015-03-16 18:02:20 -04004065 expectedVersion: sessionVers.version,
4066 expectedResumeVersion: resumeVers.version,
4067 })
4068 } else {
4069 testCases = append(testCases, testCase{
4070 protocol: protocol,
4071 name: "Resume-Client-Mismatch" + suffix,
4072 resumeSession: true,
4073 config: Config{
4074 MaxVersion: sessionVers.version,
4075 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004076 },
David Benjaminece3de92015-03-16 18:02:20 -04004077 expectedVersion: sessionVers.version,
4078 resumeConfig: &Config{
4079 MaxVersion: resumeVers.version,
4080 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4081 Bugs: ProtocolBugs{
4082 AllowSessionVersionMismatch: true,
4083 },
4084 },
4085 expectedResumeVersion: resumeVers.version,
4086 shouldFail: true,
4087 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4088 })
4089 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004090
4091 testCases = append(testCases, testCase{
4092 protocol: protocol,
4093 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004094 resumeSession: true,
4095 config: Config{
4096 MaxVersion: sessionVers.version,
4097 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4098 },
4099 expectedVersion: sessionVers.version,
4100 resumeConfig: &Config{
4101 MaxVersion: resumeVers.version,
4102 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4103 },
4104 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004105 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004106 expectedResumeVersion: resumeVers.version,
4107 })
4108
David Benjamin8b8c0062014-11-23 02:47:52 -05004109 testCases = append(testCases, testCase{
4110 protocol: protocol,
4111 testType: serverTest,
4112 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004113 resumeSession: true,
4114 config: Config{
4115 MaxVersion: sessionVers.version,
4116 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4117 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004118 expectedVersion: sessionVers.version,
4119 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004120 resumeConfig: &Config{
4121 MaxVersion: resumeVers.version,
4122 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4123 },
4124 expectedResumeVersion: resumeVers.version,
4125 })
4126 }
David Benjamin01fe8202014-09-24 15:21:44 -04004127 }
4128 }
David Benjaminece3de92015-03-16 18:02:20 -04004129
4130 testCases = append(testCases, testCase{
4131 name: "Resume-Client-CipherMismatch",
4132 resumeSession: true,
4133 config: Config{
4134 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4135 },
4136 resumeConfig: &Config{
4137 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4138 Bugs: ProtocolBugs{
4139 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4140 },
4141 },
4142 shouldFail: true,
4143 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4144 })
David Benjamin01fe8202014-09-24 15:21:44 -04004145}
4146
Adam Langley2ae77d22014-10-28 17:29:33 -07004147func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004148 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004149 testCases = append(testCases, testCase{
4150 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04004151 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004152 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004153 shouldFail: true,
4154 expectedError: ":NO_RENEGOTIATION:",
4155 expectedLocalError: "remote error: no renegotiation",
4156 })
Adam Langley5021b222015-06-12 18:27:58 -07004157 // The server shouldn't echo the renegotiation extension unless
4158 // requested by the client.
4159 testCases = append(testCases, testCase{
4160 testType: serverTest,
4161 name: "Renegotiate-Server-NoExt",
4162 config: Config{
4163 Bugs: ProtocolBugs{
4164 NoRenegotiationInfo: true,
4165 RequireRenegotiationInfo: true,
4166 },
4167 },
4168 shouldFail: true,
4169 expectedLocalError: "renegotiation extension missing",
4170 })
4171 // The renegotiation SCSV should be sufficient for the server to echo
4172 // the extension.
4173 testCases = append(testCases, testCase{
4174 testType: serverTest,
4175 name: "Renegotiate-Server-NoExt-SCSV",
4176 config: Config{
4177 Bugs: ProtocolBugs{
4178 NoRenegotiationInfo: true,
4179 SendRenegotiationSCSV: true,
4180 RequireRenegotiationInfo: true,
4181 },
4182 },
4183 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004184 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004185 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004186 config: Config{
4187 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004188 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004189 },
4190 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004191 renegotiate: 1,
4192 flags: []string{
4193 "-renegotiate-freely",
4194 "-expect-total-renegotiations", "1",
4195 },
David Benjamincdea40c2015-03-19 14:09:43 -04004196 })
4197 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004198 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004199 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004200 config: Config{
4201 Bugs: ProtocolBugs{
4202 EmptyRenegotiationInfo: true,
4203 },
4204 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004205 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004206 shouldFail: true,
4207 expectedError: ":RENEGOTIATION_MISMATCH:",
4208 })
4209 testCases = append(testCases, testCase{
4210 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004211 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004212 config: Config{
4213 Bugs: ProtocolBugs{
4214 BadRenegotiationInfo: true,
4215 },
4216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004217 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004218 shouldFail: true,
4219 expectedError: ":RENEGOTIATION_MISMATCH:",
4220 })
4221 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004222 name: "Renegotiate-Client-Downgrade",
4223 renegotiate: 1,
4224 config: Config{
4225 Bugs: ProtocolBugs{
4226 NoRenegotiationInfoAfterInitial: true,
4227 },
4228 },
4229 flags: []string{"-renegotiate-freely"},
4230 shouldFail: true,
4231 expectedError: ":RENEGOTIATION_MISMATCH:",
4232 })
4233 testCases = append(testCases, testCase{
4234 name: "Renegotiate-Client-Upgrade",
4235 renegotiate: 1,
4236 config: Config{
4237 Bugs: ProtocolBugs{
4238 NoRenegotiationInfoInInitial: true,
4239 },
4240 },
4241 flags: []string{"-renegotiate-freely"},
4242 shouldFail: true,
4243 expectedError: ":RENEGOTIATION_MISMATCH:",
4244 })
4245 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004246 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004247 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004248 config: Config{
4249 Bugs: ProtocolBugs{
4250 NoRenegotiationInfo: true,
4251 },
4252 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004253 flags: []string{
4254 "-renegotiate-freely",
4255 "-expect-total-renegotiations", "1",
4256 },
David Benjamincff0b902015-05-15 23:09:47 -04004257 })
4258 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004259 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004260 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004261 config: Config{
4262 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4263 },
4264 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004265 flags: []string{
4266 "-renegotiate-freely",
4267 "-expect-total-renegotiations", "1",
4268 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004269 })
4270 testCases = append(testCases, testCase{
4271 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004272 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004273 config: Config{
4274 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4275 },
4276 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004277 flags: []string{
4278 "-renegotiate-freely",
4279 "-expect-total-renegotiations", "1",
4280 },
David Benjaminb16346b2015-04-08 19:16:58 -04004281 })
4282 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004283 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004284 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004285 config: Config{
4286 MaxVersion: VersionTLS10,
4287 Bugs: ProtocolBugs{
4288 RequireSameRenegoClientVersion: true,
4289 },
4290 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004291 flags: []string{
4292 "-renegotiate-freely",
4293 "-expect-total-renegotiations", "1",
4294 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004295 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004296 testCases = append(testCases, testCase{
4297 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004298 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004299 config: Config{
4300 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4301 NextProtos: []string{"foo"},
4302 },
4303 flags: []string{
4304 "-false-start",
4305 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004306 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004307 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004308 },
4309 shimWritesFirst: true,
4310 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004311
4312 // Client-side renegotiation controls.
4313 testCases = append(testCases, testCase{
4314 name: "Renegotiate-Client-Forbidden-1",
4315 renegotiate: 1,
4316 shouldFail: true,
4317 expectedError: ":NO_RENEGOTIATION:",
4318 expectedLocalError: "remote error: no renegotiation",
4319 })
4320 testCases = append(testCases, testCase{
4321 name: "Renegotiate-Client-Once-1",
4322 renegotiate: 1,
4323 flags: []string{
4324 "-renegotiate-once",
4325 "-expect-total-renegotiations", "1",
4326 },
4327 })
4328 testCases = append(testCases, testCase{
4329 name: "Renegotiate-Client-Freely-1",
4330 renegotiate: 1,
4331 flags: []string{
4332 "-renegotiate-freely",
4333 "-expect-total-renegotiations", "1",
4334 },
4335 })
4336 testCases = append(testCases, testCase{
4337 name: "Renegotiate-Client-Once-2",
4338 renegotiate: 2,
4339 flags: []string{"-renegotiate-once"},
4340 shouldFail: true,
4341 expectedError: ":NO_RENEGOTIATION:",
4342 expectedLocalError: "remote error: no renegotiation",
4343 })
4344 testCases = append(testCases, testCase{
4345 name: "Renegotiate-Client-Freely-2",
4346 renegotiate: 2,
4347 flags: []string{
4348 "-renegotiate-freely",
4349 "-expect-total-renegotiations", "2",
4350 },
4351 })
Adam Langley27a0d082015-11-03 13:34:10 -08004352 testCases = append(testCases, testCase{
4353 name: "Renegotiate-Client-NoIgnore",
4354 config: Config{
4355 Bugs: ProtocolBugs{
4356 SendHelloRequestBeforeEveryAppDataRecord: true,
4357 },
4358 },
4359 shouldFail: true,
4360 expectedError: ":NO_RENEGOTIATION:",
4361 })
4362 testCases = append(testCases, testCase{
4363 name: "Renegotiate-Client-Ignore",
4364 config: Config{
4365 Bugs: ProtocolBugs{
4366 SendHelloRequestBeforeEveryAppDataRecord: true,
4367 },
4368 },
4369 flags: []string{
4370 "-renegotiate-ignore",
4371 "-expect-total-renegotiations", "0",
4372 },
4373 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004374}
4375
David Benjamin5e961c12014-11-07 01:48:35 -05004376func addDTLSReplayTests() {
4377 // Test that sequence number replays are detected.
4378 testCases = append(testCases, testCase{
4379 protocol: dtls,
4380 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004381 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004382 replayWrites: true,
4383 })
4384
David Benjamin8e6db492015-07-25 18:29:23 -04004385 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004386 // than the retransmit window.
4387 testCases = append(testCases, testCase{
4388 protocol: dtls,
4389 name: "DTLS-Replay-LargeGaps",
4390 config: Config{
4391 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004392 SequenceNumberMapping: func(in uint64) uint64 {
4393 return in * 127
4394 },
David Benjamin5e961c12014-11-07 01:48:35 -05004395 },
4396 },
David Benjamin8e6db492015-07-25 18:29:23 -04004397 messageCount: 200,
4398 replayWrites: true,
4399 })
4400
4401 // Test the incoming sequence number changing non-monotonically.
4402 testCases = append(testCases, testCase{
4403 protocol: dtls,
4404 name: "DTLS-Replay-NonMonotonic",
4405 config: Config{
4406 Bugs: ProtocolBugs{
4407 SequenceNumberMapping: func(in uint64) uint64 {
4408 return in ^ 31
4409 },
4410 },
4411 },
4412 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004413 replayWrites: true,
4414 })
4415}
4416
David Benjamin000800a2014-11-14 01:43:59 -05004417var testHashes = []struct {
4418 name string
4419 id uint8
4420}{
4421 {"SHA1", hashSHA1},
David Benjamin000800a2014-11-14 01:43:59 -05004422 {"SHA256", hashSHA256},
4423 {"SHA384", hashSHA384},
4424 {"SHA512", hashSHA512},
4425}
4426
4427func addSigningHashTests() {
4428 // Make sure each hash works. Include some fake hashes in the list and
4429 // ensure they're ignored.
4430 for _, hash := range testHashes {
4431 testCases = append(testCases, testCase{
4432 name: "SigningHash-ClientAuth-" + hash.name,
4433 config: Config{
4434 ClientAuth: RequireAnyClientCert,
4435 SignatureAndHashes: []signatureAndHash{
4436 {signatureRSA, 42},
4437 {signatureRSA, hash.id},
4438 {signatureRSA, 255},
4439 },
4440 },
4441 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004442 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4443 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004444 },
4445 })
4446
4447 testCases = append(testCases, testCase{
4448 testType: serverTest,
4449 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4450 config: Config{
4451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4452 SignatureAndHashes: []signatureAndHash{
4453 {signatureRSA, 42},
4454 {signatureRSA, hash.id},
4455 {signatureRSA, 255},
4456 },
4457 },
4458 })
David Benjamin6e807652015-11-02 12:02:20 -05004459
4460 testCases = append(testCases, testCase{
4461 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4462 config: Config{
4463 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4464 SignatureAndHashes: []signatureAndHash{
4465 {signatureRSA, 42},
4466 {signatureRSA, hash.id},
4467 {signatureRSA, 255},
4468 },
4469 },
4470 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4471 })
David Benjamin000800a2014-11-14 01:43:59 -05004472 }
4473
4474 // Test that hash resolution takes the signature type into account.
4475 testCases = append(testCases, testCase{
4476 name: "SigningHash-ClientAuth-SignatureType",
4477 config: Config{
4478 ClientAuth: RequireAnyClientCert,
4479 SignatureAndHashes: []signatureAndHash{
4480 {signatureECDSA, hashSHA512},
4481 {signatureRSA, hashSHA384},
4482 {signatureECDSA, hashSHA1},
4483 },
4484 },
4485 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004486 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4487 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004488 },
4489 })
4490
4491 testCases = append(testCases, testCase{
4492 testType: serverTest,
4493 name: "SigningHash-ServerKeyExchange-SignatureType",
4494 config: Config{
4495 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4496 SignatureAndHashes: []signatureAndHash{
4497 {signatureECDSA, hashSHA512},
4498 {signatureRSA, hashSHA384},
4499 {signatureECDSA, hashSHA1},
4500 },
4501 },
4502 })
4503
4504 // Test that, if the list is missing, the peer falls back to SHA-1.
4505 testCases = append(testCases, testCase{
4506 name: "SigningHash-ClientAuth-Fallback",
4507 config: Config{
4508 ClientAuth: RequireAnyClientCert,
4509 SignatureAndHashes: []signatureAndHash{
4510 {signatureRSA, hashSHA1},
4511 },
4512 Bugs: ProtocolBugs{
4513 NoSignatureAndHashes: true,
4514 },
4515 },
4516 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004517 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4518 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004519 },
4520 })
4521
4522 testCases = append(testCases, testCase{
4523 testType: serverTest,
4524 name: "SigningHash-ServerKeyExchange-Fallback",
4525 config: Config{
4526 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4527 SignatureAndHashes: []signatureAndHash{
4528 {signatureRSA, hashSHA1},
4529 },
4530 Bugs: ProtocolBugs{
4531 NoSignatureAndHashes: true,
4532 },
4533 },
4534 })
David Benjamin72dc7832015-03-16 17:49:43 -04004535
4536 // Test that hash preferences are enforced. BoringSSL defaults to
4537 // rejecting MD5 signatures.
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "SigningHash-ClientAuth-Enforced",
4541 config: Config{
4542 Certificates: []Certificate{rsaCertificate},
4543 SignatureAndHashes: []signatureAndHash{
4544 {signatureRSA, hashMD5},
4545 // Advertise SHA-1 so the handshake will
4546 // proceed, but the shim's preferences will be
4547 // ignored in CertificateVerify generation, so
4548 // MD5 will be chosen.
4549 {signatureRSA, hashSHA1},
4550 },
4551 Bugs: ProtocolBugs{
4552 IgnorePeerSignatureAlgorithmPreferences: true,
4553 },
4554 },
4555 flags: []string{"-require-any-client-certificate"},
4556 shouldFail: true,
4557 expectedError: ":WRONG_SIGNATURE_TYPE:",
4558 })
4559
4560 testCases = append(testCases, testCase{
4561 name: "SigningHash-ServerKeyExchange-Enforced",
4562 config: Config{
4563 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4564 SignatureAndHashes: []signatureAndHash{
4565 {signatureRSA, hashMD5},
4566 },
4567 Bugs: ProtocolBugs{
4568 IgnorePeerSignatureAlgorithmPreferences: true,
4569 },
4570 },
4571 shouldFail: true,
4572 expectedError: ":WRONG_SIGNATURE_TYPE:",
4573 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004574
4575 // Test that the agreed upon digest respects the client preferences and
4576 // the server digests.
4577 testCases = append(testCases, testCase{
4578 name: "Agree-Digest-Fallback",
4579 config: Config{
4580 ClientAuth: RequireAnyClientCert,
4581 SignatureAndHashes: []signatureAndHash{
4582 {signatureRSA, hashSHA512},
4583 {signatureRSA, hashSHA1},
4584 },
4585 },
4586 flags: []string{
4587 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4588 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4589 },
4590 digestPrefs: "SHA256",
4591 expectedClientCertSignatureHash: hashSHA1,
4592 })
4593 testCases = append(testCases, testCase{
4594 name: "Agree-Digest-SHA256",
4595 config: Config{
4596 ClientAuth: RequireAnyClientCert,
4597 SignatureAndHashes: []signatureAndHash{
4598 {signatureRSA, hashSHA1},
4599 {signatureRSA, hashSHA256},
4600 },
4601 },
4602 flags: []string{
4603 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4604 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4605 },
4606 digestPrefs: "SHA256,SHA1",
4607 expectedClientCertSignatureHash: hashSHA256,
4608 })
4609 testCases = append(testCases, testCase{
4610 name: "Agree-Digest-SHA1",
4611 config: Config{
4612 ClientAuth: RequireAnyClientCert,
4613 SignatureAndHashes: []signatureAndHash{
4614 {signatureRSA, hashSHA1},
4615 },
4616 },
4617 flags: []string{
4618 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4619 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4620 },
4621 digestPrefs: "SHA512,SHA256,SHA1",
4622 expectedClientCertSignatureHash: hashSHA1,
4623 })
4624 testCases = append(testCases, testCase{
4625 name: "Agree-Digest-Default",
4626 config: Config{
4627 ClientAuth: RequireAnyClientCert,
4628 SignatureAndHashes: []signatureAndHash{
4629 {signatureRSA, hashSHA256},
4630 {signatureECDSA, hashSHA256},
4631 {signatureRSA, hashSHA1},
4632 {signatureECDSA, hashSHA1},
4633 },
4634 },
4635 flags: []string{
4636 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4637 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4638 },
4639 expectedClientCertSignatureHash: hashSHA256,
4640 })
David Benjamin000800a2014-11-14 01:43:59 -05004641}
4642
David Benjamin83f90402015-01-27 01:09:43 -05004643// timeouts is the retransmit schedule for BoringSSL. It doubles and
4644// caps at 60 seconds. On the 13th timeout, it gives up.
4645var timeouts = []time.Duration{
4646 1 * time.Second,
4647 2 * time.Second,
4648 4 * time.Second,
4649 8 * time.Second,
4650 16 * time.Second,
4651 32 * time.Second,
4652 60 * time.Second,
4653 60 * time.Second,
4654 60 * time.Second,
4655 60 * time.Second,
4656 60 * time.Second,
4657 60 * time.Second,
4658 60 * time.Second,
4659}
4660
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004661// shortTimeouts is an alternate set of timeouts which would occur if the
4662// initial timeout duration was set to 250ms.
4663var shortTimeouts = []time.Duration{
4664 250 * time.Millisecond,
4665 500 * time.Millisecond,
4666 1 * time.Second,
4667 2 * time.Second,
4668 4 * time.Second,
4669 8 * time.Second,
4670 16 * time.Second,
4671 32 * time.Second,
4672 60 * time.Second,
4673 60 * time.Second,
4674 60 * time.Second,
4675 60 * time.Second,
4676 60 * time.Second,
4677}
4678
David Benjamin83f90402015-01-27 01:09:43 -05004679func addDTLSRetransmitTests() {
4680 // Test that this is indeed the timeout schedule. Stress all
4681 // four patterns of handshake.
4682 for i := 1; i < len(timeouts); i++ {
4683 number := strconv.Itoa(i)
4684 testCases = append(testCases, testCase{
4685 protocol: dtls,
4686 name: "DTLS-Retransmit-Client-" + number,
4687 config: Config{
4688 Bugs: ProtocolBugs{
4689 TimeoutSchedule: timeouts[:i],
4690 },
4691 },
4692 resumeSession: true,
4693 flags: []string{"-async"},
4694 })
4695 testCases = append(testCases, testCase{
4696 protocol: dtls,
4697 testType: serverTest,
4698 name: "DTLS-Retransmit-Server-" + number,
4699 config: Config{
4700 Bugs: ProtocolBugs{
4701 TimeoutSchedule: timeouts[:i],
4702 },
4703 },
4704 resumeSession: true,
4705 flags: []string{"-async"},
4706 })
4707 }
4708
4709 // Test that exceeding the timeout schedule hits a read
4710 // timeout.
4711 testCases = append(testCases, testCase{
4712 protocol: dtls,
4713 name: "DTLS-Retransmit-Timeout",
4714 config: Config{
4715 Bugs: ProtocolBugs{
4716 TimeoutSchedule: timeouts,
4717 },
4718 },
4719 resumeSession: true,
4720 flags: []string{"-async"},
4721 shouldFail: true,
4722 expectedError: ":READ_TIMEOUT_EXPIRED:",
4723 })
4724
4725 // Test that timeout handling has a fudge factor, due to API
4726 // problems.
4727 testCases = append(testCases, testCase{
4728 protocol: dtls,
4729 name: "DTLS-Retransmit-Fudge",
4730 config: Config{
4731 Bugs: ProtocolBugs{
4732 TimeoutSchedule: []time.Duration{
4733 timeouts[0] - 10*time.Millisecond,
4734 },
4735 },
4736 },
4737 resumeSession: true,
4738 flags: []string{"-async"},
4739 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004740
4741 // Test that the final Finished retransmitting isn't
4742 // duplicated if the peer badly fragments everything.
4743 testCases = append(testCases, testCase{
4744 testType: serverTest,
4745 protocol: dtls,
4746 name: "DTLS-Retransmit-Fragmented",
4747 config: Config{
4748 Bugs: ProtocolBugs{
4749 TimeoutSchedule: []time.Duration{timeouts[0]},
4750 MaxHandshakeRecordLength: 2,
4751 },
4752 },
4753 flags: []string{"-async"},
4754 })
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004755
4756 // Test the timeout schedule when a shorter initial timeout duration is set.
4757 testCases = append(testCases, testCase{
4758 protocol: dtls,
4759 name: "DTLS-Retransmit-Short-Client",
4760 config: Config{
4761 Bugs: ProtocolBugs{
4762 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
4763 },
4764 },
4765 resumeSession: true,
4766 flags: []string{"-async", "-initial-timeout-duration-ms", "250"},
4767 })
4768 testCases = append(testCases, testCase{
4769 protocol: dtls,
4770 testType: serverTest,
4771 name: "DTLS-Retransmit-Short-Server",
4772 config: Config{
4773 Bugs: ProtocolBugs{
4774 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
4775 },
4776 },
4777 resumeSession: true,
4778 flags: []string{"-async", "-initial-timeout-duration-ms", "250"},
4779 })
David Benjamin83f90402015-01-27 01:09:43 -05004780}
4781
David Benjaminc565ebb2015-04-03 04:06:36 -04004782func addExportKeyingMaterialTests() {
4783 for _, vers := range tlsVersions {
4784 if vers.version == VersionSSL30 {
4785 continue
4786 }
4787 testCases = append(testCases, testCase{
4788 name: "ExportKeyingMaterial-" + vers.name,
4789 config: Config{
4790 MaxVersion: vers.version,
4791 },
4792 exportKeyingMaterial: 1024,
4793 exportLabel: "label",
4794 exportContext: "context",
4795 useExportContext: true,
4796 })
4797 testCases = append(testCases, testCase{
4798 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4799 config: Config{
4800 MaxVersion: vers.version,
4801 },
4802 exportKeyingMaterial: 1024,
4803 })
4804 testCases = append(testCases, testCase{
4805 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4806 config: Config{
4807 MaxVersion: vers.version,
4808 },
4809 exportKeyingMaterial: 1024,
4810 useExportContext: true,
4811 })
4812 testCases = append(testCases, testCase{
4813 name: "ExportKeyingMaterial-Small-" + vers.name,
4814 config: Config{
4815 MaxVersion: vers.version,
4816 },
4817 exportKeyingMaterial: 1,
4818 exportLabel: "label",
4819 exportContext: "context",
4820 useExportContext: true,
4821 })
4822 }
4823 testCases = append(testCases, testCase{
4824 name: "ExportKeyingMaterial-SSL3",
4825 config: Config{
4826 MaxVersion: VersionSSL30,
4827 },
4828 exportKeyingMaterial: 1024,
4829 exportLabel: "label",
4830 exportContext: "context",
4831 useExportContext: true,
4832 shouldFail: true,
4833 expectedError: "failed to export keying material",
4834 })
4835}
4836
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004837func addTLSUniqueTests() {
4838 for _, isClient := range []bool{false, true} {
4839 for _, isResumption := range []bool{false, true} {
4840 for _, hasEMS := range []bool{false, true} {
4841 var suffix string
4842 if isResumption {
4843 suffix = "Resume-"
4844 } else {
4845 suffix = "Full-"
4846 }
4847
4848 if hasEMS {
4849 suffix += "EMS-"
4850 } else {
4851 suffix += "NoEMS-"
4852 }
4853
4854 if isClient {
4855 suffix += "Client"
4856 } else {
4857 suffix += "Server"
4858 }
4859
4860 test := testCase{
4861 name: "TLSUnique-" + suffix,
4862 testTLSUnique: true,
4863 config: Config{
4864 Bugs: ProtocolBugs{
4865 NoExtendedMasterSecret: !hasEMS,
4866 },
4867 },
4868 }
4869
4870 if isResumption {
4871 test.resumeSession = true
4872 test.resumeConfig = &Config{
4873 Bugs: ProtocolBugs{
4874 NoExtendedMasterSecret: !hasEMS,
4875 },
4876 }
4877 }
4878
4879 if isResumption && !hasEMS {
4880 test.shouldFail = true
4881 test.expectedError = "failed to get tls-unique"
4882 }
4883
4884 testCases = append(testCases, test)
4885 }
4886 }
4887 }
4888}
4889
Adam Langley09505632015-07-30 18:10:13 -07004890func addCustomExtensionTests() {
4891 expectedContents := "custom extension"
4892 emptyString := ""
4893
4894 for _, isClient := range []bool{false, true} {
4895 suffix := "Server"
4896 flag := "-enable-server-custom-extension"
4897 testType := serverTest
4898 if isClient {
4899 suffix = "Client"
4900 flag = "-enable-client-custom-extension"
4901 testType = clientTest
4902 }
4903
4904 testCases = append(testCases, testCase{
4905 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004906 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004907 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004908 Bugs: ProtocolBugs{
4909 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004910 ExpectedCustomExtension: &expectedContents,
4911 },
4912 },
4913 flags: []string{flag},
4914 })
4915
4916 // If the parse callback fails, the handshake should also fail.
4917 testCases = append(testCases, testCase{
4918 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004919 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004920 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004921 Bugs: ProtocolBugs{
4922 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004923 ExpectedCustomExtension: &expectedContents,
4924 },
4925 },
David Benjamin399e7c92015-07-30 23:01:27 -04004926 flags: []string{flag},
4927 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004928 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4929 })
4930
4931 // If the add callback fails, the handshake should also fail.
4932 testCases = append(testCases, testCase{
4933 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004934 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004935 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004936 Bugs: ProtocolBugs{
4937 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004938 ExpectedCustomExtension: &expectedContents,
4939 },
4940 },
David Benjamin399e7c92015-07-30 23:01:27 -04004941 flags: []string{flag, "-custom-extension-fail-add"},
4942 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004943 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4944 })
4945
4946 // If the add callback returns zero, no extension should be
4947 // added.
4948 skipCustomExtension := expectedContents
4949 if isClient {
4950 // For the case where the client skips sending the
4951 // custom extension, the server must not “echo” it.
4952 skipCustomExtension = ""
4953 }
4954 testCases = append(testCases, testCase{
4955 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004956 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004957 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004958 Bugs: ProtocolBugs{
4959 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004960 ExpectedCustomExtension: &emptyString,
4961 },
4962 },
4963 flags: []string{flag, "-custom-extension-skip"},
4964 })
4965 }
4966
4967 // The custom extension add callback should not be called if the client
4968 // doesn't send the extension.
4969 testCases = append(testCases, testCase{
4970 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004971 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004972 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004973 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004974 ExpectedCustomExtension: &emptyString,
4975 },
4976 },
4977 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4978 })
Adam Langley2deb9842015-08-07 11:15:37 -07004979
4980 // Test an unknown extension from the server.
4981 testCases = append(testCases, testCase{
4982 testType: clientTest,
4983 name: "UnknownExtension-Client",
4984 config: Config{
4985 Bugs: ProtocolBugs{
4986 CustomExtension: expectedContents,
4987 },
4988 },
4989 shouldFail: true,
4990 expectedError: ":UNEXPECTED_EXTENSION:",
4991 })
Adam Langley09505632015-07-30 18:10:13 -07004992}
4993
David Benjaminb36a3952015-12-01 18:53:13 -05004994func addRSAClientKeyExchangeTests() {
4995 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4996 testCases = append(testCases, testCase{
4997 testType: serverTest,
4998 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4999 config: Config{
5000 // Ensure the ClientHello version and final
5001 // version are different, to detect if the
5002 // server uses the wrong one.
5003 MaxVersion: VersionTLS11,
5004 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5005 Bugs: ProtocolBugs{
5006 BadRSAClientKeyExchange: bad,
5007 },
5008 },
5009 shouldFail: true,
5010 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5011 })
5012 }
5013}
5014
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005015var testCurves = []struct {
5016 name string
5017 id CurveID
5018}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005019 {"P-256", CurveP256},
5020 {"P-384", CurveP384},
5021 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005022 {"X25519", CurveX25519},
Matt Braithwaitee25775b2016-05-16 16:31:05 -07005023 {"CECPQ1", CurveCECPQ1},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005024}
5025
5026func addCurveTests() {
5027 for _, curve := range testCurves {
5028 testCases = append(testCases, testCase{
5029 name: "CurveTest-Client-" + curve.name,
5030 config: Config{
5031 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5032 CurvePreferences: []CurveID{curve.id},
5033 },
5034 flags: []string{"-enable-all-curves"},
5035 })
5036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "CurveTest-Server-" + curve.name,
5039 config: Config{
5040 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5041 CurvePreferences: []CurveID{curve.id},
5042 },
5043 flags: []string{"-enable-all-curves"},
5044 })
5045 }
David Benjamin241ae832016-01-15 03:04:54 -05005046
5047 // The server must be tolerant to bogus curves.
5048 const bogusCurve = 0x1234
5049 testCases = append(testCases, testCase{
5050 testType: serverTest,
5051 name: "UnknownCurve",
5052 config: Config{
5053 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5054 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5055 },
5056 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005057}
5058
David Benjamin4cc36ad2015-12-19 14:23:26 -05005059func addKeyExchangeInfoTests() {
5060 testCases = append(testCases, testCase{
5061 name: "KeyExchangeInfo-RSA-Client",
5062 config: Config{
5063 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5064 },
5065 // key.pem is a 1024-bit RSA key.
5066 flags: []string{"-expect-key-exchange-info", "1024"},
5067 })
5068 // TODO(davidben): key_exchange_info doesn't work for plain RSA on the
5069 // server. Either fix this or change the API as it's not very useful in
5070 // this case.
5071
5072 testCases = append(testCases, testCase{
5073 name: "KeyExchangeInfo-DHE-Client",
5074 config: Config{
5075 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5076 Bugs: ProtocolBugs{
5077 // This is a 1234-bit prime number, generated
5078 // with:
5079 // openssl gendh 1234 | openssl asn1parse -i
5080 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5081 },
5082 },
5083 flags: []string{"-expect-key-exchange-info", "1234"},
5084 })
5085 testCases = append(testCases, testCase{
5086 testType: serverTest,
5087 name: "KeyExchangeInfo-DHE-Server",
5088 config: Config{
5089 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5090 },
5091 // bssl_shim as a server configures a 2048-bit DHE group.
5092 flags: []string{"-expect-key-exchange-info", "2048"},
5093 })
5094
5095 testCases = append(testCases, testCase{
5096 name: "KeyExchangeInfo-ECDHE-Client",
5097 config: Config{
5098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5099 CurvePreferences: []CurveID{CurveX25519},
5100 },
5101 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5102 })
5103 testCases = append(testCases, testCase{
5104 testType: serverTest,
5105 name: "KeyExchangeInfo-ECDHE-Server",
5106 config: Config{
5107 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5108 CurvePreferences: []CurveID{CurveX25519},
5109 },
5110 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5111 })
5112}
5113
Adam Langley7c803a62015-06-15 15:35:05 -07005114func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005115 defer wg.Done()
5116
5117 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005118 var err error
5119
5120 if *mallocTest < 0 {
5121 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005122 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005123 } else {
5124 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5125 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005126 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005127 if err != nil {
5128 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5129 }
5130 break
5131 }
5132 }
5133 }
Adam Langley95c29f32014-06-20 12:00:00 -07005134 statusChan <- statusMsg{test: test, err: err}
5135 }
5136}
5137
5138type statusMsg struct {
5139 test *testCase
5140 started bool
5141 err error
5142}
5143
David Benjamin5f237bc2015-02-11 17:14:15 -05005144func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005145 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005146
David Benjamin5f237bc2015-02-11 17:14:15 -05005147 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005148 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005149 if !*pipe {
5150 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005151 var erase string
5152 for i := 0; i < lineLen; i++ {
5153 erase += "\b \b"
5154 }
5155 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005156 }
5157
Adam Langley95c29f32014-06-20 12:00:00 -07005158 if msg.started {
5159 started++
5160 } else {
5161 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005162
5163 if msg.err != nil {
5164 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5165 failed++
5166 testOutput.addResult(msg.test.name, "FAIL")
5167 } else {
5168 if *pipe {
5169 // Print each test instead of a status line.
5170 fmt.Printf("PASSED (%s)\n", msg.test.name)
5171 }
5172 testOutput.addResult(msg.test.name, "PASS")
5173 }
Adam Langley95c29f32014-06-20 12:00:00 -07005174 }
5175
David Benjamin5f237bc2015-02-11 17:14:15 -05005176 if !*pipe {
5177 // Print a new status line.
5178 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5179 lineLen = len(line)
5180 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005181 }
Adam Langley95c29f32014-06-20 12:00:00 -07005182 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005183
5184 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005185}
5186
5187func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005188 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005189 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005190
Adam Langley7c803a62015-06-15 15:35:05 -07005191 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005192 addCipherSuiteTests()
5193 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005194 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005195 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005196 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005197 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005198 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005199 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005200 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005201 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005202 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005203 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005204 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05005205 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05005206 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005207 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005208 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005209 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005210 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005211 addCurveTests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005212 addKeyExchangeInfoTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04005213 for _, async := range []bool{false, true} {
5214 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04005215 for _, protocol := range []protocol{tls, dtls} {
5216 addStateMachineCoverageTests(async, splitHandshake, protocol)
5217 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005218 }
5219 }
Adam Langley95c29f32014-06-20 12:00:00 -07005220
5221 var wg sync.WaitGroup
5222
Adam Langley7c803a62015-06-15 15:35:05 -07005223 statusChan := make(chan statusMsg, *numWorkers)
5224 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005225 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005226
David Benjamin025b3d32014-07-01 19:53:04 -04005227 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005228
Adam Langley7c803a62015-06-15 15:35:05 -07005229 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005230 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005231 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005232 }
5233
David Benjamin270f0a72016-03-17 14:41:36 -04005234 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005235 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005236 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005237 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005238 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005239 }
5240 }
David Benjamin270f0a72016-03-17 14:41:36 -04005241 if !foundTest {
5242 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5243 os.Exit(1)
5244 }
Adam Langley95c29f32014-06-20 12:00:00 -07005245
5246 close(testChan)
5247 wg.Wait()
5248 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005249 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005250
5251 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005252
5253 if *jsonOutput != "" {
5254 if err := testOutput.writeTo(*jsonOutput); err != nil {
5255 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5256 }
5257 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005258
5259 if !testOutput.allPassed {
5260 os.Exit(1)
5261 }
Adam Langley95c29f32014-06-20 12:00:00 -07005262}