blob: c10987e120b2ce5e09be05dd2cf9ff6fb9a84613 [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},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700918 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
919 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
920 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
921 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400922 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
923 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700924 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
925 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500926 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -0400927 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700928 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400929 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700930 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700931}
932
David Benjamin8b8c0062014-11-23 02:47:52 -0500933func hasComponent(suiteName, component string) bool {
934 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
935}
936
David Benjamin4298d772015-12-19 00:18:25 -0500937func isTLSOnly(suiteName string) bool {
938 // BoringSSL doesn't support ECDHE without a curves extension, and
939 // SSLv3 doesn't contain extensions.
940 return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName)
941}
942
David Benjaminf7768e42014-08-31 02:06:47 -0400943func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500944 return hasComponent(suiteName, "GCM") ||
945 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400946 hasComponent(suiteName, "SHA384") ||
947 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500948}
949
950func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700951 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400952}
953
Adam Langleya7997f12015-05-14 17:38:50 -0700954func bigFromHex(hex string) *big.Int {
955 ret, ok := new(big.Int).SetString(hex, 16)
956 if !ok {
957 panic("failed to parse hex number 0x" + hex)
958 }
959 return ret
960}
961
Adam Langley7c803a62015-06-15 15:35:05 -0700962func addBasicTests() {
963 basicTests := []testCase{
964 {
965 name: "BadRSASignature",
966 config: Config{
967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
968 Bugs: ProtocolBugs{
969 InvalidSKXSignature: true,
970 },
971 },
972 shouldFail: true,
973 expectedError: ":BAD_SIGNATURE:",
974 },
975 {
976 name: "BadECDSASignature",
977 config: Config{
978 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
979 Bugs: ProtocolBugs{
980 InvalidSKXSignature: true,
981 },
982 Certificates: []Certificate{getECDSACertificate()},
983 },
984 shouldFail: true,
985 expectedError: ":BAD_SIGNATURE:",
986 },
987 {
David Benjamin6de0e532015-07-28 22:43:19 -0400988 testType: serverTest,
989 name: "BadRSASignature-ClientAuth",
990 config: Config{
991 Bugs: ProtocolBugs{
992 InvalidCertVerifySignature: true,
993 },
994 Certificates: []Certificate{getRSACertificate()},
995 },
996 shouldFail: true,
997 expectedError: ":BAD_SIGNATURE:",
998 flags: []string{"-require-any-client-certificate"},
999 },
1000 {
1001 testType: serverTest,
1002 name: "BadECDSASignature-ClientAuth",
1003 config: Config{
1004 Bugs: ProtocolBugs{
1005 InvalidCertVerifySignature: true,
1006 },
1007 Certificates: []Certificate{getECDSACertificate()},
1008 },
1009 shouldFail: true,
1010 expectedError: ":BAD_SIGNATURE:",
1011 flags: []string{"-require-any-client-certificate"},
1012 },
1013 {
Adam Langley7c803a62015-06-15 15:35:05 -07001014 name: "BadECDSACurve",
1015 config: Config{
1016 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1017 Bugs: ProtocolBugs{
1018 InvalidSKXCurve: true,
1019 },
1020 Certificates: []Certificate{getECDSACertificate()},
1021 },
1022 shouldFail: true,
1023 expectedError: ":WRONG_CURVE:",
1024 },
1025 {
Adam Langley7c803a62015-06-15 15:35:05 -07001026 name: "NoFallbackSCSV",
1027 config: Config{
1028 Bugs: ProtocolBugs{
1029 FailIfNotFallbackSCSV: true,
1030 },
1031 },
1032 shouldFail: true,
1033 expectedLocalError: "no fallback SCSV found",
1034 },
1035 {
1036 name: "SendFallbackSCSV",
1037 config: Config{
1038 Bugs: ProtocolBugs{
1039 FailIfNotFallbackSCSV: true,
1040 },
1041 },
1042 flags: []string{"-fallback-scsv"},
1043 },
1044 {
1045 name: "ClientCertificateTypes",
1046 config: Config{
1047 ClientAuth: RequestClientCert,
1048 ClientCertificateTypes: []byte{
1049 CertTypeDSSSign,
1050 CertTypeRSASign,
1051 CertTypeECDSASign,
1052 },
1053 },
1054 flags: []string{
1055 "-expect-certificate-types",
1056 base64.StdEncoding.EncodeToString([]byte{
1057 CertTypeDSSSign,
1058 CertTypeRSASign,
1059 CertTypeECDSASign,
1060 }),
1061 },
1062 },
1063 {
1064 name: "NoClientCertificate",
1065 config: Config{
1066 ClientAuth: RequireAnyClientCert,
1067 },
1068 shouldFail: true,
1069 expectedLocalError: "client didn't provide a certificate",
1070 },
1071 {
1072 name: "UnauthenticatedECDH",
1073 config: Config{
1074 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1075 Bugs: ProtocolBugs{
1076 UnauthenticatedECDH: true,
1077 },
1078 },
1079 shouldFail: true,
1080 expectedError: ":UNEXPECTED_MESSAGE:",
1081 },
1082 {
1083 name: "SkipCertificateStatus",
1084 config: Config{
1085 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1086 Bugs: ProtocolBugs{
1087 SkipCertificateStatus: true,
1088 },
1089 },
1090 flags: []string{
1091 "-enable-ocsp-stapling",
1092 },
1093 },
1094 {
1095 name: "SkipServerKeyExchange",
1096 config: Config{
1097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1098 Bugs: ProtocolBugs{
1099 SkipServerKeyExchange: true,
1100 },
1101 },
1102 shouldFail: true,
1103 expectedError: ":UNEXPECTED_MESSAGE:",
1104 },
1105 {
1106 name: "SkipChangeCipherSpec-Client",
1107 config: Config{
1108 Bugs: ProtocolBugs{
1109 SkipChangeCipherSpec: true,
1110 },
1111 },
1112 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001113 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001114 },
1115 {
1116 testType: serverTest,
1117 name: "SkipChangeCipherSpec-Server",
1118 config: Config{
1119 Bugs: ProtocolBugs{
1120 SkipChangeCipherSpec: true,
1121 },
1122 },
1123 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001124 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001125 },
1126 {
1127 testType: serverTest,
1128 name: "SkipChangeCipherSpec-Server-NPN",
1129 config: Config{
1130 NextProtos: []string{"bar"},
1131 Bugs: ProtocolBugs{
1132 SkipChangeCipherSpec: true,
1133 },
1134 },
1135 flags: []string{
1136 "-advertise-npn", "\x03foo\x03bar\x03baz",
1137 },
1138 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001139 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001140 },
1141 {
1142 name: "FragmentAcrossChangeCipherSpec-Client",
1143 config: Config{
1144 Bugs: ProtocolBugs{
1145 FragmentAcrossChangeCipherSpec: true,
1146 },
1147 },
1148 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001149 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001150 },
1151 {
1152 testType: serverTest,
1153 name: "FragmentAcrossChangeCipherSpec-Server",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 FragmentAcrossChangeCipherSpec: true,
1157 },
1158 },
1159 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001160 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001161 },
1162 {
1163 testType: serverTest,
1164 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1165 config: Config{
1166 NextProtos: []string{"bar"},
1167 Bugs: ProtocolBugs{
1168 FragmentAcrossChangeCipherSpec: true,
1169 },
1170 },
1171 flags: []string{
1172 "-advertise-npn", "\x03foo\x03bar\x03baz",
1173 },
1174 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001175 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001176 },
1177 {
1178 testType: serverTest,
1179 name: "Alert",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 SendSpuriousAlert: alertRecordOverflow,
1183 },
1184 },
1185 shouldFail: true,
1186 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1187 },
1188 {
1189 protocol: dtls,
1190 testType: serverTest,
1191 name: "Alert-DTLS",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 SendSpuriousAlert: alertRecordOverflow,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1199 },
1200 {
1201 testType: serverTest,
1202 name: "FragmentAlert",
1203 config: Config{
1204 Bugs: ProtocolBugs{
1205 FragmentAlert: true,
1206 SendSpuriousAlert: alertRecordOverflow,
1207 },
1208 },
1209 shouldFail: true,
1210 expectedError: ":BAD_ALERT:",
1211 },
1212 {
1213 protocol: dtls,
1214 testType: serverTest,
1215 name: "FragmentAlert-DTLS",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 FragmentAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001227 name: "DoubleAlert",
1228 config: Config{
1229 Bugs: ProtocolBugs{
1230 DoubleAlert: true,
1231 SendSpuriousAlert: alertRecordOverflow,
1232 },
1233 },
1234 shouldFail: true,
1235 expectedError: ":BAD_ALERT:",
1236 },
1237 {
1238 protocol: dtls,
1239 testType: serverTest,
1240 name: "DoubleAlert-DTLS",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 DoubleAlert: true,
1244 SendSpuriousAlert: alertRecordOverflow,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":BAD_ALERT:",
1249 },
1250 {
1251 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001252 name: "EarlyChangeCipherSpec-server-1",
1253 config: Config{
1254 Bugs: ProtocolBugs{
1255 EarlyChangeCipherSpec: 1,
1256 },
1257 },
1258 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001259 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001260 },
1261 {
1262 testType: serverTest,
1263 name: "EarlyChangeCipherSpec-server-2",
1264 config: Config{
1265 Bugs: ProtocolBugs{
1266 EarlyChangeCipherSpec: 2,
1267 },
1268 },
1269 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001270 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001271 },
1272 {
1273 name: "SkipNewSessionTicket",
1274 config: Config{
1275 Bugs: ProtocolBugs{
1276 SkipNewSessionTicket: true,
1277 },
1278 },
1279 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001280 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001281 },
1282 {
1283 testType: serverTest,
1284 name: "FallbackSCSV",
1285 config: Config{
1286 MaxVersion: VersionTLS11,
1287 Bugs: ProtocolBugs{
1288 SendFallbackSCSV: true,
1289 },
1290 },
1291 shouldFail: true,
1292 expectedError: ":INAPPROPRIATE_FALLBACK:",
1293 },
1294 {
1295 testType: serverTest,
1296 name: "FallbackSCSV-VersionMatch",
1297 config: Config{
1298 Bugs: ProtocolBugs{
1299 SendFallbackSCSV: true,
1300 },
1301 },
1302 },
1303 {
1304 testType: serverTest,
1305 name: "FragmentedClientVersion",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxHandshakeRecordLength: 1,
1309 FragmentClientVersion: true,
1310 },
1311 },
1312 expectedVersion: VersionTLS12,
1313 },
1314 {
1315 testType: serverTest,
1316 name: "MinorVersionTolerance",
1317 config: Config{
1318 Bugs: ProtocolBugs{
1319 SendClientVersion: 0x03ff,
1320 },
1321 },
1322 expectedVersion: VersionTLS12,
1323 },
1324 {
1325 testType: serverTest,
1326 name: "MajorVersionTolerance",
1327 config: Config{
1328 Bugs: ProtocolBugs{
1329 SendClientVersion: 0x0400,
1330 },
1331 },
1332 expectedVersion: VersionTLS12,
1333 },
1334 {
1335 testType: serverTest,
1336 name: "VersionTooLow",
1337 config: Config{
1338 Bugs: ProtocolBugs{
1339 SendClientVersion: 0x0200,
1340 },
1341 },
1342 shouldFail: true,
1343 expectedError: ":UNSUPPORTED_PROTOCOL:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpGET",
1348 sendPrefix: "GET / HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTP_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "HttpPOST",
1355 sendPrefix: "POST / HTTP/1.0\n",
1356 shouldFail: true,
1357 expectedError: ":HTTP_REQUEST:",
1358 },
1359 {
1360 testType: serverTest,
1361 name: "HttpHEAD",
1362 sendPrefix: "HEAD / HTTP/1.0\n",
1363 shouldFail: true,
1364 expectedError: ":HTTP_REQUEST:",
1365 },
1366 {
1367 testType: serverTest,
1368 name: "HttpPUT",
1369 sendPrefix: "PUT / HTTP/1.0\n",
1370 shouldFail: true,
1371 expectedError: ":HTTP_REQUEST:",
1372 },
1373 {
1374 testType: serverTest,
1375 name: "HttpCONNECT",
1376 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1377 shouldFail: true,
1378 expectedError: ":HTTPS_PROXY_REQUEST:",
1379 },
1380 {
1381 testType: serverTest,
1382 name: "Garbage",
1383 sendPrefix: "blah",
1384 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001385 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001386 },
1387 {
1388 name: "SkipCipherVersionCheck",
1389 config: Config{
1390 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1391 MaxVersion: VersionTLS11,
1392 Bugs: ProtocolBugs{
1393 SkipCipherVersionCheck: true,
1394 },
1395 },
1396 shouldFail: true,
1397 expectedError: ":WRONG_CIPHER_RETURNED:",
1398 },
1399 {
1400 name: "RSAEphemeralKey",
1401 config: Config{
1402 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1403 Bugs: ProtocolBugs{
1404 RSAEphemeralKey: true,
1405 },
1406 },
1407 shouldFail: true,
1408 expectedError: ":UNEXPECTED_MESSAGE:",
1409 },
1410 {
1411 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001412 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001413 shouldFail: true,
1414 expectedError: ":WRONG_SSL_VERSION:",
1415 },
1416 {
1417 protocol: dtls,
1418 name: "DisableEverything-DTLS",
1419 flags: []string{"-no-tls12", "-no-tls1"},
1420 shouldFail: true,
1421 expectedError: ":WRONG_SSL_VERSION:",
1422 },
1423 {
1424 name: "NoSharedCipher",
1425 config: Config{
1426 CipherSuites: []uint16{},
1427 },
1428 shouldFail: true,
1429 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1430 },
1431 {
1432 protocol: dtls,
1433 testType: serverTest,
1434 name: "MTU",
1435 config: Config{
1436 Bugs: ProtocolBugs{
1437 MaxPacketLength: 256,
1438 },
1439 },
1440 flags: []string{"-mtu", "256"},
1441 },
1442 {
1443 protocol: dtls,
1444 testType: serverTest,
1445 name: "MTUExceeded",
1446 config: Config{
1447 Bugs: ProtocolBugs{
1448 MaxPacketLength: 255,
1449 },
1450 },
1451 flags: []string{"-mtu", "256"},
1452 shouldFail: true,
1453 expectedLocalError: "dtls: exceeded maximum packet length",
1454 },
1455 {
1456 name: "CertMismatchRSA",
1457 config: Config{
1458 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1459 Certificates: []Certificate{getECDSACertificate()},
1460 Bugs: ProtocolBugs{
1461 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1462 },
1463 },
1464 shouldFail: true,
1465 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1466 },
1467 {
1468 name: "CertMismatchECDSA",
1469 config: Config{
1470 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1471 Certificates: []Certificate{getRSACertificate()},
1472 Bugs: ProtocolBugs{
1473 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1474 },
1475 },
1476 shouldFail: true,
1477 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1478 },
1479 {
1480 name: "EmptyCertificateList",
1481 config: Config{
1482 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1483 Bugs: ProtocolBugs{
1484 EmptyCertificateList: true,
1485 },
1486 },
1487 shouldFail: true,
1488 expectedError: ":DECODE_ERROR:",
1489 },
1490 {
1491 name: "TLSFatalBadPackets",
1492 damageFirstWrite: true,
1493 shouldFail: true,
1494 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1495 },
1496 {
1497 protocol: dtls,
1498 name: "DTLSIgnoreBadPackets",
1499 damageFirstWrite: true,
1500 },
1501 {
1502 protocol: dtls,
1503 name: "DTLSIgnoreBadPackets-Async",
1504 damageFirstWrite: true,
1505 flags: []string{"-async"},
1506 },
1507 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001508 name: "AppDataBeforeHandshake",
1509 config: Config{
1510 Bugs: ProtocolBugs{
1511 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1512 },
1513 },
1514 shouldFail: true,
1515 expectedError: ":UNEXPECTED_RECORD:",
1516 },
1517 {
1518 name: "AppDataBeforeHandshake-Empty",
1519 config: Config{
1520 Bugs: ProtocolBugs{
1521 AppDataBeforeHandshake: []byte{},
1522 },
1523 },
1524 shouldFail: true,
1525 expectedError: ":UNEXPECTED_RECORD:",
1526 },
1527 {
1528 protocol: dtls,
1529 name: "AppDataBeforeHandshake-DTLS",
1530 config: Config{
1531 Bugs: ProtocolBugs{
1532 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1533 },
1534 },
1535 shouldFail: true,
1536 expectedError: ":UNEXPECTED_RECORD:",
1537 },
1538 {
1539 protocol: dtls,
1540 name: "AppDataBeforeHandshake-DTLS-Empty",
1541 config: Config{
1542 Bugs: ProtocolBugs{
1543 AppDataBeforeHandshake: []byte{},
1544 },
1545 },
1546 shouldFail: true,
1547 expectedError: ":UNEXPECTED_RECORD:",
1548 },
1549 {
Adam Langley7c803a62015-06-15 15:35:05 -07001550 name: "AppDataAfterChangeCipherSpec",
1551 config: Config{
1552 Bugs: ProtocolBugs{
1553 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1554 },
1555 },
1556 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001557 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001558 },
1559 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001560 name: "AppDataAfterChangeCipherSpec-Empty",
1561 config: Config{
1562 Bugs: ProtocolBugs{
1563 AppDataAfterChangeCipherSpec: []byte{},
1564 },
1565 },
1566 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001567 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001568 },
1569 {
Adam Langley7c803a62015-06-15 15:35:05 -07001570 protocol: dtls,
1571 name: "AppDataAfterChangeCipherSpec-DTLS",
1572 config: Config{
1573 Bugs: ProtocolBugs{
1574 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1575 },
1576 },
1577 // BoringSSL's DTLS implementation will drop the out-of-order
1578 // application data.
1579 },
1580 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001581 protocol: dtls,
1582 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1583 config: Config{
1584 Bugs: ProtocolBugs{
1585 AppDataAfterChangeCipherSpec: []byte{},
1586 },
1587 },
1588 // BoringSSL's DTLS implementation will drop the out-of-order
1589 // application data.
1590 },
1591 {
Adam Langley7c803a62015-06-15 15:35:05 -07001592 name: "AlertAfterChangeCipherSpec",
1593 config: Config{
1594 Bugs: ProtocolBugs{
1595 AlertAfterChangeCipherSpec: alertRecordOverflow,
1596 },
1597 },
1598 shouldFail: true,
1599 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1600 },
1601 {
1602 protocol: dtls,
1603 name: "AlertAfterChangeCipherSpec-DTLS",
1604 config: Config{
1605 Bugs: ProtocolBugs{
1606 AlertAfterChangeCipherSpec: alertRecordOverflow,
1607 },
1608 },
1609 shouldFail: true,
1610 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1611 },
1612 {
1613 protocol: dtls,
1614 name: "ReorderHandshakeFragments-Small-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 ReorderHandshakeFragments: true,
1618 // Small enough that every handshake message is
1619 // fragmented.
1620 MaxHandshakeRecordLength: 2,
1621 },
1622 },
1623 },
1624 {
1625 protocol: dtls,
1626 name: "ReorderHandshakeFragments-Large-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 ReorderHandshakeFragments: true,
1630 // Large enough that no handshake message is
1631 // fragmented.
1632 MaxHandshakeRecordLength: 2048,
1633 },
1634 },
1635 },
1636 {
1637 protocol: dtls,
1638 name: "MixCompleteMessageWithFragments-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 ReorderHandshakeFragments: true,
1642 MixCompleteMessageWithFragments: true,
1643 MaxHandshakeRecordLength: 2,
1644 },
1645 },
1646 },
1647 {
1648 name: "SendInvalidRecordType",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SendInvalidRecordType-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SendInvalidRecordType: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":UNEXPECTED_RECORD:",
1667 },
1668 {
1669 name: "FalseStart-SkipServerSecondLeg",
1670 config: Config{
1671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1672 NextProtos: []string{"foo"},
1673 Bugs: ProtocolBugs{
1674 SkipNewSessionTicket: true,
1675 SkipChangeCipherSpec: true,
1676 SkipFinished: true,
1677 ExpectFalseStart: true,
1678 },
1679 },
1680 flags: []string{
1681 "-false-start",
1682 "-handshake-never-done",
1683 "-advertise-alpn", "\x03foo",
1684 },
1685 shimWritesFirst: true,
1686 shouldFail: true,
1687 expectedError: ":UNEXPECTED_RECORD:",
1688 },
1689 {
1690 name: "FalseStart-SkipServerSecondLeg-Implicit",
1691 config: Config{
1692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1693 NextProtos: []string{"foo"},
1694 Bugs: ProtocolBugs{
1695 SkipNewSessionTicket: true,
1696 SkipChangeCipherSpec: true,
1697 SkipFinished: true,
1698 },
1699 },
1700 flags: []string{
1701 "-implicit-handshake",
1702 "-false-start",
1703 "-handshake-never-done",
1704 "-advertise-alpn", "\x03foo",
1705 },
1706 shouldFail: true,
1707 expectedError: ":UNEXPECTED_RECORD:",
1708 },
1709 {
1710 testType: serverTest,
1711 name: "FailEarlyCallback",
1712 flags: []string{"-fail-early-callback"},
1713 shouldFail: true,
1714 expectedError: ":CONNECTION_REJECTED:",
1715 expectedLocalError: "remote error: access denied",
1716 },
1717 {
1718 name: "WrongMessageType",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 WrongCertificateMessageType: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":UNEXPECTED_MESSAGE:",
1726 expectedLocalError: "remote error: unexpected message",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "WrongMessageType-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 WrongCertificateMessageType: true,
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":UNEXPECTED_MESSAGE:",
1738 expectedLocalError: "remote error: unexpected message",
1739 },
1740 {
1741 protocol: dtls,
1742 name: "FragmentMessageTypeMismatch-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 MaxHandshakeRecordLength: 2,
1746 FragmentMessageTypeMismatch: true,
1747 },
1748 },
1749 shouldFail: true,
1750 expectedError: ":FRAGMENT_MISMATCH:",
1751 },
1752 {
1753 protocol: dtls,
1754 name: "FragmentMessageLengthMismatch-DTLS",
1755 config: Config{
1756 Bugs: ProtocolBugs{
1757 MaxHandshakeRecordLength: 2,
1758 FragmentMessageLengthMismatch: true,
1759 },
1760 },
1761 shouldFail: true,
1762 expectedError: ":FRAGMENT_MISMATCH:",
1763 },
1764 {
1765 protocol: dtls,
1766 name: "SplitFragments-Header-DTLS",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SplitFragments: 2,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":UNEXPECTED_MESSAGE:",
1774 },
1775 {
1776 protocol: dtls,
1777 name: "SplitFragments-Boundary-DTLS",
1778 config: Config{
1779 Bugs: ProtocolBugs{
1780 SplitFragments: dtlsRecordHeaderLen,
1781 },
1782 },
1783 shouldFail: true,
1784 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1785 },
1786 {
1787 protocol: dtls,
1788 name: "SplitFragments-Body-DTLS",
1789 config: Config{
1790 Bugs: ProtocolBugs{
1791 SplitFragments: dtlsRecordHeaderLen + 1,
1792 },
1793 },
1794 shouldFail: true,
1795 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1796 },
1797 {
1798 protocol: dtls,
1799 name: "SendEmptyFragments-DTLS",
1800 config: Config{
1801 Bugs: ProtocolBugs{
1802 SendEmptyFragments: true,
1803 },
1804 },
1805 },
1806 {
1807 name: "UnsupportedCipherSuite",
1808 config: Config{
1809 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1810 Bugs: ProtocolBugs{
1811 IgnorePeerCipherPreferences: true,
1812 },
1813 },
1814 flags: []string{"-cipher", "DEFAULT:!RC4"},
1815 shouldFail: true,
1816 expectedError: ":WRONG_CIPHER_RETURNED:",
1817 },
1818 {
1819 name: "UnsupportedCurve",
1820 config: Config{
David Benjamin64d92502015-12-19 02:20:57 -05001821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1822 CurvePreferences: []CurveID{CurveP256},
Adam Langley7c803a62015-06-15 15:35:05 -07001823 Bugs: ProtocolBugs{
1824 IgnorePeerCurvePreferences: true,
1825 },
1826 },
David Benjamin64d92502015-12-19 02:20:57 -05001827 flags: []string{"-p384-only"},
Adam Langley7c803a62015-06-15 15:35:05 -07001828 shouldFail: true,
1829 expectedError: ":WRONG_CURVE:",
1830 },
1831 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001832 name: "BadFinished-Client",
1833 config: Config{
1834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 },
1837 },
1838 shouldFail: true,
1839 expectedError: ":DIGEST_CHECK_FAILED:",
1840 },
1841 {
1842 testType: serverTest,
1843 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001844 config: Config{
1845 Bugs: ProtocolBugs{
1846 BadFinished: true,
1847 },
1848 },
1849 shouldFail: true,
1850 expectedError: ":DIGEST_CHECK_FAILED:",
1851 },
1852 {
1853 name: "FalseStart-BadFinished",
1854 config: Config{
1855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1856 NextProtos: []string{"foo"},
1857 Bugs: ProtocolBugs{
1858 BadFinished: true,
1859 ExpectFalseStart: true,
1860 },
1861 },
1862 flags: []string{
1863 "-false-start",
1864 "-handshake-never-done",
1865 "-advertise-alpn", "\x03foo",
1866 },
1867 shimWritesFirst: true,
1868 shouldFail: true,
1869 expectedError: ":DIGEST_CHECK_FAILED:",
1870 },
1871 {
1872 name: "NoFalseStart-NoALPN",
1873 config: Config{
1874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 },
1883 shimWritesFirst: true,
1884 shouldFail: true,
1885 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1886 expectedLocalError: "tls: peer did not false start: EOF",
1887 },
1888 {
1889 name: "NoFalseStart-NoAEAD",
1890 config: Config{
1891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1892 NextProtos: []string{"foo"},
1893 Bugs: ProtocolBugs{
1894 ExpectFalseStart: true,
1895 AlertBeforeFalseStartTest: alertAccessDenied,
1896 },
1897 },
1898 flags: []string{
1899 "-false-start",
1900 "-advertise-alpn", "\x03foo",
1901 },
1902 shimWritesFirst: true,
1903 shouldFail: true,
1904 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1905 expectedLocalError: "tls: peer did not false start: EOF",
1906 },
1907 {
1908 name: "NoFalseStart-RSA",
1909 config: Config{
1910 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
1927 name: "NoFalseStart-DHE_RSA",
1928 config: Config{
1929 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1930 NextProtos: []string{"foo"},
1931 Bugs: ProtocolBugs{
1932 ExpectFalseStart: true,
1933 AlertBeforeFalseStartTest: alertAccessDenied,
1934 },
1935 },
1936 flags: []string{
1937 "-false-start",
1938 "-advertise-alpn", "\x03foo",
1939 },
1940 shimWritesFirst: true,
1941 shouldFail: true,
1942 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1943 expectedLocalError: "tls: peer did not false start: EOF",
1944 },
1945 {
1946 testType: serverTest,
1947 name: "NoSupportedCurves",
1948 config: Config{
1949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1950 Bugs: ProtocolBugs{
1951 NoSupportedCurves: true,
1952 },
1953 },
David Benjamin4298d772015-12-19 00:18:25 -05001954 shouldFail: true,
1955 expectedError: ":NO_SHARED_CIPHER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001956 },
1957 {
1958 testType: serverTest,
1959 name: "NoCommonCurves",
1960 config: Config{
1961 CipherSuites: []uint16{
1962 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1963 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1964 },
1965 CurvePreferences: []CurveID{CurveP224},
1966 },
1967 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1968 },
1969 {
1970 protocol: dtls,
1971 name: "SendSplitAlert-Sync",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 SendSplitAlert: true,
1975 },
1976 },
1977 },
1978 {
1979 protocol: dtls,
1980 name: "SendSplitAlert-Async",
1981 config: Config{
1982 Bugs: ProtocolBugs{
1983 SendSplitAlert: true,
1984 },
1985 },
1986 flags: []string{"-async"},
1987 },
1988 {
1989 protocol: dtls,
1990 name: "PackDTLSHandshake",
1991 config: Config{
1992 Bugs: ProtocolBugs{
1993 MaxHandshakeRecordLength: 2,
1994 PackHandshakeFragments: 20,
1995 PackHandshakeRecords: 200,
1996 },
1997 },
1998 },
1999 {
2000 testType: serverTest,
2001 protocol: dtls,
2002 name: "NoRC4-DTLS",
2003 config: Config{
2004 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2005 Bugs: ProtocolBugs{
2006 EnableAllCiphersInDTLS: true,
2007 },
2008 },
2009 shouldFail: true,
2010 expectedError: ":NO_SHARED_CIPHER:",
2011 },
2012 {
2013 name: "SendEmptyRecords-Pass",
2014 sendEmptyRecords: 32,
2015 },
2016 {
2017 name: "SendEmptyRecords",
2018 sendEmptyRecords: 33,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2021 },
2022 {
2023 name: "SendEmptyRecords-Async",
2024 sendEmptyRecords: 33,
2025 flags: []string{"-async"},
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2028 },
2029 {
2030 name: "SendWarningAlerts-Pass",
2031 sendWarningAlerts: 4,
2032 },
2033 {
2034 protocol: dtls,
2035 name: "SendWarningAlerts-DTLS-Pass",
2036 sendWarningAlerts: 4,
2037 },
2038 {
2039 name: "SendWarningAlerts",
2040 sendWarningAlerts: 5,
2041 shouldFail: true,
2042 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2043 },
2044 {
2045 name: "SendWarningAlerts-Async",
2046 sendWarningAlerts: 5,
2047 flags: []string{"-async"},
2048 shouldFail: true,
2049 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2050 },
David Benjaminba4594a2015-06-18 18:36:15 -04002051 {
2052 name: "EmptySessionID",
2053 config: Config{
2054 SessionTicketsDisabled: true,
2055 },
2056 noSessionCache: true,
2057 flags: []string{"-expect-no-session"},
2058 },
David Benjamin30789da2015-08-29 22:56:45 -04002059 {
2060 name: "Unclean-Shutdown",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 NoCloseNotify: true,
2064 ExpectCloseNotify: true,
2065 },
2066 },
2067 shimShutsDown: true,
2068 flags: []string{"-check-close-notify"},
2069 shouldFail: true,
2070 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2071 },
2072 {
2073 name: "Unclean-Shutdown-Ignored",
2074 config: Config{
2075 Bugs: ProtocolBugs{
2076 NoCloseNotify: true,
2077 },
2078 },
2079 shimShutsDown: true,
2080 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002081 {
David Benjaminfa214e42016-05-10 17:03:10 -04002082 name: "Unclean-Shutdown-Alert",
2083 config: Config{
2084 Bugs: ProtocolBugs{
2085 SendAlertOnShutdown: alertDecompressionFailure,
2086 ExpectCloseNotify: true,
2087 },
2088 },
2089 shimShutsDown: true,
2090 flags: []string{"-check-close-notify"},
2091 shouldFail: true,
2092 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2093 },
2094 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002095 name: "LargePlaintext",
2096 config: Config{
2097 Bugs: ProtocolBugs{
2098 SendLargeRecords: true,
2099 },
2100 },
2101 messageLen: maxPlaintext + 1,
2102 shouldFail: true,
2103 expectedError: ":DATA_LENGTH_TOO_LONG:",
2104 },
2105 {
2106 protocol: dtls,
2107 name: "LargePlaintext-DTLS",
2108 config: Config{
2109 Bugs: ProtocolBugs{
2110 SendLargeRecords: true,
2111 },
2112 },
2113 messageLen: maxPlaintext + 1,
2114 shouldFail: true,
2115 expectedError: ":DATA_LENGTH_TOO_LONG:",
2116 },
2117 {
2118 name: "LargeCiphertext",
2119 config: Config{
2120 Bugs: ProtocolBugs{
2121 SendLargeRecords: true,
2122 },
2123 },
2124 messageLen: maxPlaintext * 2,
2125 shouldFail: true,
2126 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2127 },
2128 {
2129 protocol: dtls,
2130 name: "LargeCiphertext-DTLS",
2131 config: Config{
2132 Bugs: ProtocolBugs{
2133 SendLargeRecords: true,
2134 },
2135 },
2136 messageLen: maxPlaintext * 2,
2137 // Unlike the other four cases, DTLS drops records which
2138 // are invalid before authentication, so the connection
2139 // does not fail.
2140 expectMessageDropped: true,
2141 },
David Benjamindd6fed92015-10-23 17:41:12 -04002142 {
2143 name: "SendEmptySessionTicket",
2144 config: Config{
2145 Bugs: ProtocolBugs{
2146 SendEmptySessionTicket: true,
2147 FailIfSessionOffered: true,
2148 },
2149 },
2150 flags: []string{"-expect-no-session"},
2151 resumeSession: true,
2152 expectResumeRejected: true,
2153 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002154 {
2155 name: "CheckLeafCurve",
2156 config: Config{
2157 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2158 Certificates: []Certificate{getECDSACertificate()},
2159 },
2160 flags: []string{"-p384-only"},
2161 shouldFail: true,
2162 expectedError: ":BAD_ECC_CERT:",
2163 },
David Benjamin8411b242015-11-26 12:07:28 -05002164 {
2165 name: "BadChangeCipherSpec-1",
2166 config: Config{
2167 Bugs: ProtocolBugs{
2168 BadChangeCipherSpec: []byte{2},
2169 },
2170 },
2171 shouldFail: true,
2172 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2173 },
2174 {
2175 name: "BadChangeCipherSpec-2",
2176 config: Config{
2177 Bugs: ProtocolBugs{
2178 BadChangeCipherSpec: []byte{1, 1},
2179 },
2180 },
2181 shouldFail: true,
2182 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2183 },
2184 {
2185 protocol: dtls,
2186 name: "BadChangeCipherSpec-DTLS-1",
2187 config: Config{
2188 Bugs: ProtocolBugs{
2189 BadChangeCipherSpec: []byte{2},
2190 },
2191 },
2192 shouldFail: true,
2193 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2194 },
2195 {
2196 protocol: dtls,
2197 name: "BadChangeCipherSpec-DTLS-2",
2198 config: Config{
2199 Bugs: ProtocolBugs{
2200 BadChangeCipherSpec: []byte{1, 1},
2201 },
2202 },
2203 shouldFail: true,
2204 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2205 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002206 {
2207 name: "BadHelloRequest-1",
2208 renegotiate: 1,
2209 config: Config{
2210 Bugs: ProtocolBugs{
2211 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2212 },
2213 },
2214 flags: []string{
2215 "-renegotiate-freely",
2216 "-expect-total-renegotiations", "1",
2217 },
2218 shouldFail: true,
2219 expectedError: ":BAD_HELLO_REQUEST:",
2220 },
2221 {
2222 name: "BadHelloRequest-2",
2223 renegotiate: 1,
2224 config: Config{
2225 Bugs: ProtocolBugs{
2226 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2227 },
2228 },
2229 flags: []string{
2230 "-renegotiate-freely",
2231 "-expect-total-renegotiations", "1",
2232 },
2233 shouldFail: true,
2234 expectedError: ":BAD_HELLO_REQUEST:",
2235 },
David Benjaminef1b0092015-11-21 14:05:44 -05002236 {
2237 testType: serverTest,
2238 name: "SupportTicketsWithSessionID",
2239 config: Config{
2240 SessionTicketsDisabled: true,
2241 },
2242 resumeConfig: &Config{},
2243 resumeSession: true,
2244 },
David Benjamin2b07fa42016-03-02 00:23:57 -05002245 {
2246 name: "InvalidECDHPoint-Client",
2247 config: Config{
2248 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2249 CurvePreferences: []CurveID{CurveP256},
2250 Bugs: ProtocolBugs{
2251 InvalidECDHPoint: true,
2252 },
2253 },
2254 shouldFail: true,
2255 expectedError: ":INVALID_ENCODING:",
2256 },
2257 {
2258 testType: serverTest,
2259 name: "InvalidECDHPoint-Server",
2260 config: Config{
2261 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2262 CurvePreferences: []CurveID{CurveP256},
2263 Bugs: ProtocolBugs{
2264 InvalidECDHPoint: true,
2265 },
2266 },
2267 shouldFail: true,
2268 expectedError: ":INVALID_ENCODING:",
2269 },
Adam Langley7c803a62015-06-15 15:35:05 -07002270 }
Adam Langley7c803a62015-06-15 15:35:05 -07002271 testCases = append(testCases, basicTests...)
2272}
2273
Adam Langley95c29f32014-06-20 12:00:00 -07002274func addCipherSuiteTests() {
2275 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002276 const psk = "12345"
2277 const pskIdentity = "luggage combo"
2278
Adam Langley95c29f32014-06-20 12:00:00 -07002279 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002280 var certFile string
2281 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002282 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002283 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002284 certFile = ecdsaCertificateFile
2285 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002286 } else {
2287 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002288 certFile = rsaCertificateFile
2289 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002290 }
2291
David Benjamin48cae082014-10-27 01:06:24 -04002292 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002293 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002294 flags = append(flags,
2295 "-psk", psk,
2296 "-psk-identity", pskIdentity)
2297 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002298 if hasComponent(suite.name, "NULL") {
2299 // NULL ciphers must be explicitly enabled.
2300 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2301 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002302 if hasComponent(suite.name, "CECPQ1") {
2303 // CECPQ1 ciphers must be explicitly enabled.
2304 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2305 }
David Benjamin48cae082014-10-27 01:06:24 -04002306
Adam Langley95c29f32014-06-20 12:00:00 -07002307 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002308 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002309 continue
2310 }
2311
David Benjamin4298d772015-12-19 00:18:25 -05002312 shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30
2313
2314 expectedError := ""
2315 if shouldFail {
2316 expectedError = ":NO_SHARED_CIPHER:"
2317 }
David Benjamin025b3d32014-07-01 19:53:04 -04002318
David Benjamin76d8abe2014-08-14 16:25:34 -04002319 testCases = append(testCases, testCase{
2320 testType: serverTest,
2321 name: ver.name + "-" + suite.name + "-server",
2322 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002323 MinVersion: ver.version,
2324 MaxVersion: ver.version,
2325 CipherSuites: []uint16{suite.id},
2326 Certificates: []Certificate{cert},
2327 PreSharedKey: []byte(psk),
2328 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002329 },
2330 certFile: certFile,
2331 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002332 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002333 resumeSession: true,
David Benjamin4298d772015-12-19 00:18:25 -05002334 shouldFail: shouldFail,
2335 expectedError: expectedError,
2336 })
2337
2338 if shouldFail {
2339 continue
2340 }
2341
2342 testCases = append(testCases, testCase{
2343 testType: clientTest,
2344 name: ver.name + "-" + suite.name + "-client",
2345 config: Config{
2346 MinVersion: ver.version,
2347 MaxVersion: ver.version,
2348 CipherSuites: []uint16{suite.id},
2349 Certificates: []Certificate{cert},
2350 PreSharedKey: []byte(psk),
2351 PreSharedKeyIdentity: pskIdentity,
2352 },
2353 flags: flags,
2354 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002355 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002356
David Benjamin8b8c0062014-11-23 02:47:52 -05002357 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002358 testCases = append(testCases, testCase{
2359 testType: clientTest,
2360 protocol: dtls,
2361 name: "D" + ver.name + "-" + suite.name + "-client",
2362 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002363 MinVersion: ver.version,
2364 MaxVersion: ver.version,
2365 CipherSuites: []uint16{suite.id},
2366 Certificates: []Certificate{cert},
2367 PreSharedKey: []byte(psk),
2368 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002369 },
David Benjamin48cae082014-10-27 01:06:24 -04002370 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002371 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002372 })
2373 testCases = append(testCases, testCase{
2374 testType: serverTest,
2375 protocol: dtls,
2376 name: "D" + ver.name + "-" + suite.name + "-server",
2377 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002378 MinVersion: ver.version,
2379 MaxVersion: ver.version,
2380 CipherSuites: []uint16{suite.id},
2381 Certificates: []Certificate{cert},
2382 PreSharedKey: []byte(psk),
2383 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002384 },
2385 certFile: certFile,
2386 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002387 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002388 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002389 })
2390 }
Adam Langley95c29f32014-06-20 12:00:00 -07002391 }
David Benjamin2c99d282015-09-01 10:23:00 -04002392
2393 // Ensure both TLS and DTLS accept their maximum record sizes.
2394 testCases = append(testCases, testCase{
2395 name: suite.name + "-LargeRecord",
2396 config: Config{
2397 CipherSuites: []uint16{suite.id},
2398 Certificates: []Certificate{cert},
2399 PreSharedKey: []byte(psk),
2400 PreSharedKeyIdentity: pskIdentity,
2401 },
2402 flags: flags,
2403 messageLen: maxPlaintext,
2404 })
David Benjamin2c99d282015-09-01 10:23:00 -04002405 if isDTLSCipher(suite.name) {
2406 testCases = append(testCases, testCase{
2407 protocol: dtls,
2408 name: suite.name + "-LargeRecord-DTLS",
2409 config: Config{
2410 CipherSuites: []uint16{suite.id},
2411 Certificates: []Certificate{cert},
2412 PreSharedKey: []byte(psk),
2413 PreSharedKeyIdentity: pskIdentity,
2414 },
2415 flags: flags,
2416 messageLen: maxPlaintext,
2417 })
2418 }
Adam Langley95c29f32014-06-20 12:00:00 -07002419 }
Adam Langleya7997f12015-05-14 17:38:50 -07002420
2421 testCases = append(testCases, testCase{
2422 name: "WeakDH",
2423 config: Config{
2424 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2425 Bugs: ProtocolBugs{
2426 // This is a 1023-bit prime number, generated
2427 // with:
2428 // openssl gendh 1023 | openssl asn1parse -i
2429 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2430 },
2431 },
2432 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002433 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002434 })
Adam Langleycef75832015-09-03 14:51:12 -07002435
David Benjamincd24a392015-11-11 13:23:05 -08002436 testCases = append(testCases, testCase{
2437 name: "SillyDH",
2438 config: Config{
2439 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2440 Bugs: ProtocolBugs{
2441 // This is a 4097-bit prime number, generated
2442 // with:
2443 // openssl gendh 4097 | openssl asn1parse -i
2444 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2445 },
2446 },
2447 shouldFail: true,
2448 expectedError: ":DH_P_TOO_LONG:",
2449 })
2450
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002451 // This test ensures that Diffie-Hellman public values are padded with
2452 // zeros so that they're the same length as the prime. This is to avoid
2453 // hitting a bug in yaSSL.
2454 testCases = append(testCases, testCase{
2455 testType: serverTest,
2456 name: "DHPublicValuePadded",
2457 config: Config{
2458 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2459 Bugs: ProtocolBugs{
2460 RequireDHPublicValueLen: (1025 + 7) / 8,
2461 },
2462 },
2463 flags: []string{"-use-sparse-dh-prime"},
2464 })
David Benjamincd24a392015-11-11 13:23:05 -08002465
David Benjamin241ae832016-01-15 03:04:54 -05002466 // The server must be tolerant to bogus ciphers.
2467 const bogusCipher = 0x1234
2468 testCases = append(testCases, testCase{
2469 testType: serverTest,
2470 name: "UnknownCipher",
2471 config: Config{
2472 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2473 },
2474 })
2475
Adam Langleycef75832015-09-03 14:51:12 -07002476 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2477 // 1.1 specific cipher suite settings. A server is setup with the given
2478 // cipher lists and then a connection is made for each member of
2479 // expectations. The cipher suite that the server selects must match
2480 // the specified one.
2481 var versionSpecificCiphersTest = []struct {
2482 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2483 // expectations is a map from TLS version to cipher suite id.
2484 expectations map[uint16]uint16
2485 }{
2486 {
2487 // Test that the null case (where no version-specific ciphers are set)
2488 // works as expected.
2489 "RC4-SHA:AES128-SHA", // default ciphers
2490 "", // no ciphers specifically for TLS ≥ 1.0
2491 "", // no ciphers specifically for TLS ≥ 1.1
2492 map[uint16]uint16{
2493 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2494 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2495 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2496 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2497 },
2498 },
2499 {
2500 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2501 // cipher.
2502 "RC4-SHA:AES128-SHA", // default
2503 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2504 "", // no ciphers specifically for TLS ≥ 1.1
2505 map[uint16]uint16{
2506 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2507 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2508 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2509 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2510 },
2511 },
2512 {
2513 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2514 // cipher.
2515 "RC4-SHA:AES128-SHA", // default
2516 "", // no ciphers specifically for TLS ≥ 1.0
2517 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2518 map[uint16]uint16{
2519 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2520 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2521 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2522 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2523 },
2524 },
2525 {
2526 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2527 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2528 "RC4-SHA:AES128-SHA", // default
2529 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2530 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2531 map[uint16]uint16{
2532 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2533 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2534 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2535 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2536 },
2537 },
2538 }
2539
2540 for i, test := range versionSpecificCiphersTest {
2541 for version, expectedCipherSuite := range test.expectations {
2542 flags := []string{"-cipher", test.ciphersDefault}
2543 if len(test.ciphersTLS10) > 0 {
2544 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2545 }
2546 if len(test.ciphersTLS11) > 0 {
2547 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2548 }
2549
2550 testCases = append(testCases, testCase{
2551 testType: serverTest,
2552 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2553 config: Config{
2554 MaxVersion: version,
2555 MinVersion: version,
2556 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2557 },
2558 flags: flags,
2559 expectedCipher: expectedCipherSuite,
2560 })
2561 }
2562 }
Adam Langley95c29f32014-06-20 12:00:00 -07002563}
2564
2565func addBadECDSASignatureTests() {
2566 for badR := BadValue(1); badR < NumBadValues; badR++ {
2567 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002568 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002569 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2570 config: Config{
2571 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2572 Certificates: []Certificate{getECDSACertificate()},
2573 Bugs: ProtocolBugs{
2574 BadECDSAR: badR,
2575 BadECDSAS: badS,
2576 },
2577 },
2578 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002579 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002580 })
2581 }
2582 }
2583}
2584
Adam Langley80842bd2014-06-20 12:00:00 -07002585func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002586 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002587 name: "MaxCBCPadding",
2588 config: Config{
2589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2590 Bugs: ProtocolBugs{
2591 MaxPadding: true,
2592 },
2593 },
2594 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2595 })
David Benjamin025b3d32014-07-01 19:53:04 -04002596 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002597 name: "BadCBCPadding",
2598 config: Config{
2599 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2600 Bugs: ProtocolBugs{
2601 PaddingFirstByteBad: true,
2602 },
2603 },
2604 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002605 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002606 })
2607 // OpenSSL previously had an issue where the first byte of padding in
2608 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002609 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002610 name: "BadCBCPadding255",
2611 config: Config{
2612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2613 Bugs: ProtocolBugs{
2614 MaxPadding: true,
2615 PaddingFirstByteBadIf255: true,
2616 },
2617 },
2618 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2619 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002620 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002621 })
2622}
2623
Kenny Root7fdeaf12014-08-05 15:23:37 -07002624func addCBCSplittingTests() {
2625 testCases = append(testCases, testCase{
2626 name: "CBCRecordSplitting",
2627 config: Config{
2628 MaxVersion: VersionTLS10,
2629 MinVersion: VersionTLS10,
2630 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2631 },
David Benjaminac8302a2015-09-01 17:18:15 -04002632 messageLen: -1, // read until EOF
2633 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002634 flags: []string{
2635 "-async",
2636 "-write-different-record-sizes",
2637 "-cbc-record-splitting",
2638 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002639 })
2640 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002641 name: "CBCRecordSplittingPartialWrite",
2642 config: Config{
2643 MaxVersion: VersionTLS10,
2644 MinVersion: VersionTLS10,
2645 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2646 },
2647 messageLen: -1, // read until EOF
2648 flags: []string{
2649 "-async",
2650 "-write-different-record-sizes",
2651 "-cbc-record-splitting",
2652 "-partial-write",
2653 },
2654 })
2655}
2656
David Benjamin636293b2014-07-08 17:59:18 -04002657func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002658 // Add a dummy cert pool to stress certificate authority parsing.
2659 // TODO(davidben): Add tests that those values parse out correctly.
2660 certPool := x509.NewCertPool()
2661 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2662 if err != nil {
2663 panic(err)
2664 }
2665 certPool.AddCert(cert)
2666
David Benjamin636293b2014-07-08 17:59:18 -04002667 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002668 testCases = append(testCases, testCase{
2669 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002670 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002671 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002672 MinVersion: ver.version,
2673 MaxVersion: ver.version,
2674 ClientAuth: RequireAnyClientCert,
2675 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002676 },
2677 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002678 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2679 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002680 },
2681 })
2682 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002683 testType: serverTest,
2684 name: ver.name + "-Server-ClientAuth-RSA",
2685 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002686 MinVersion: ver.version,
2687 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002688 Certificates: []Certificate{rsaCertificate},
2689 },
2690 flags: []string{"-require-any-client-certificate"},
2691 })
David Benjamine098ec22014-08-27 23:13:20 -04002692 if ver.version != VersionSSL30 {
2693 testCases = append(testCases, testCase{
2694 testType: serverTest,
2695 name: ver.name + "-Server-ClientAuth-ECDSA",
2696 config: Config{
2697 MinVersion: ver.version,
2698 MaxVersion: ver.version,
2699 Certificates: []Certificate{ecdsaCertificate},
2700 },
2701 flags: []string{"-require-any-client-certificate"},
2702 })
2703 testCases = append(testCases, testCase{
2704 testType: clientTest,
2705 name: ver.name + "-Client-ClientAuth-ECDSA",
2706 config: Config{
2707 MinVersion: ver.version,
2708 MaxVersion: ver.version,
2709 ClientAuth: RequireAnyClientCert,
2710 ClientCAs: certPool,
2711 },
2712 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002713 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2714 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002715 },
2716 })
2717 }
David Benjamin636293b2014-07-08 17:59:18 -04002718 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002719
2720 testCases = append(testCases, testCase{
2721 testType: serverTest,
2722 name: "RequireAnyClientCertificate",
2723 flags: []string{"-require-any-client-certificate"},
2724 shouldFail: true,
2725 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2726 })
2727
2728 testCases = append(testCases, testCase{
2729 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002730 name: "RequireAnyClientCertificate-SSL3",
2731 config: Config{
2732 MaxVersion: VersionSSL30,
2733 },
2734 flags: []string{"-require-any-client-certificate"},
2735 shouldFail: true,
2736 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2737 })
2738
2739 testCases = append(testCases, testCase{
2740 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002741 name: "SkipClientCertificate",
2742 config: Config{
2743 Bugs: ProtocolBugs{
2744 SkipClientCertificate: true,
2745 },
2746 },
2747 // Setting SSL_VERIFY_PEER allows anonymous clients.
2748 flags: []string{"-verify-peer"},
2749 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002750 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002751 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002752
2753 // Client auth is only legal in certificate-based ciphers.
2754 testCases = append(testCases, testCase{
2755 testType: clientTest,
2756 name: "ClientAuth-PSK",
2757 config: Config{
2758 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2759 PreSharedKey: []byte("secret"),
2760 ClientAuth: RequireAnyClientCert,
2761 },
2762 flags: []string{
2763 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2764 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2765 "-psk", "secret",
2766 },
2767 shouldFail: true,
2768 expectedError: ":UNEXPECTED_MESSAGE:",
2769 })
2770 testCases = append(testCases, testCase{
2771 testType: clientTest,
2772 name: "ClientAuth-ECDHE_PSK",
2773 config: Config{
2774 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2775 PreSharedKey: []byte("secret"),
2776 ClientAuth: RequireAnyClientCert,
2777 },
2778 flags: []string{
2779 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2780 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2781 "-psk", "secret",
2782 },
2783 shouldFail: true,
2784 expectedError: ":UNEXPECTED_MESSAGE:",
2785 })
David Benjamin636293b2014-07-08 17:59:18 -04002786}
2787
Adam Langley75712922014-10-10 16:23:43 -07002788func addExtendedMasterSecretTests() {
2789 const expectEMSFlag = "-expect-extended-master-secret"
2790
2791 for _, with := range []bool{false, true} {
2792 prefix := "No"
2793 var flags []string
2794 if with {
2795 prefix = ""
2796 flags = []string{expectEMSFlag}
2797 }
2798
2799 for _, isClient := range []bool{false, true} {
2800 suffix := "-Server"
2801 testType := serverTest
2802 if isClient {
2803 suffix = "-Client"
2804 testType = clientTest
2805 }
2806
2807 for _, ver := range tlsVersions {
2808 test := testCase{
2809 testType: testType,
2810 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2811 config: Config{
2812 MinVersion: ver.version,
2813 MaxVersion: ver.version,
2814 Bugs: ProtocolBugs{
2815 NoExtendedMasterSecret: !with,
2816 RequireExtendedMasterSecret: with,
2817 },
2818 },
David Benjamin48cae082014-10-27 01:06:24 -04002819 flags: flags,
2820 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002821 }
2822 if test.shouldFail {
2823 test.expectedLocalError = "extended master secret required but not supported by peer"
2824 }
2825 testCases = append(testCases, test)
2826 }
2827 }
2828 }
2829
Adam Langleyba5934b2015-06-02 10:50:35 -07002830 for _, isClient := range []bool{false, true} {
2831 for _, supportedInFirstConnection := range []bool{false, true} {
2832 for _, supportedInResumeConnection := range []bool{false, true} {
2833 boolToWord := func(b bool) string {
2834 if b {
2835 return "Yes"
2836 }
2837 return "No"
2838 }
2839 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2840 if isClient {
2841 suffix += "Client"
2842 } else {
2843 suffix += "Server"
2844 }
2845
2846 supportedConfig := Config{
2847 Bugs: ProtocolBugs{
2848 RequireExtendedMasterSecret: true,
2849 },
2850 }
2851
2852 noSupportConfig := Config{
2853 Bugs: ProtocolBugs{
2854 NoExtendedMasterSecret: true,
2855 },
2856 }
2857
2858 test := testCase{
2859 name: "ExtendedMasterSecret-" + suffix,
2860 resumeSession: true,
2861 }
2862
2863 if !isClient {
2864 test.testType = serverTest
2865 }
2866
2867 if supportedInFirstConnection {
2868 test.config = supportedConfig
2869 } else {
2870 test.config = noSupportConfig
2871 }
2872
2873 if supportedInResumeConnection {
2874 test.resumeConfig = &supportedConfig
2875 } else {
2876 test.resumeConfig = &noSupportConfig
2877 }
2878
2879 switch suffix {
2880 case "YesToYes-Client", "YesToYes-Server":
2881 // When a session is resumed, it should
2882 // still be aware that its master
2883 // secret was generated via EMS and
2884 // thus it's safe to use tls-unique.
2885 test.flags = []string{expectEMSFlag}
2886 case "NoToYes-Server":
2887 // If an original connection did not
2888 // contain EMS, but a resumption
2889 // handshake does, then a server should
2890 // not resume the session.
2891 test.expectResumeRejected = true
2892 case "YesToNo-Server":
2893 // Resuming an EMS session without the
2894 // EMS extension should cause the
2895 // server to abort the connection.
2896 test.shouldFail = true
2897 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2898 case "NoToYes-Client":
2899 // A client should abort a connection
2900 // where the server resumed a non-EMS
2901 // session but echoed the EMS
2902 // extension.
2903 test.shouldFail = true
2904 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2905 case "YesToNo-Client":
2906 // A client should abort a connection
2907 // where the server didn't echo EMS
2908 // when the session used it.
2909 test.shouldFail = true
2910 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2911 }
2912
2913 testCases = append(testCases, test)
2914 }
2915 }
2916 }
Adam Langley75712922014-10-10 16:23:43 -07002917}
2918
David Benjamin43ec06f2014-08-05 02:28:57 -04002919// Adds tests that try to cover the range of the handshake state machine, under
2920// various conditions. Some of these are redundant with other tests, but they
2921// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002922func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002923 var tests []testCase
2924
2925 // Basic handshake, with resumption. Client and server,
2926 // session ID and session ticket.
2927 tests = append(tests, testCase{
2928 name: "Basic-Client",
2929 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002930 // Ensure session tickets are used, not session IDs.
2931 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002932 })
2933 tests = append(tests, testCase{
2934 name: "Basic-Client-RenewTicket",
2935 config: Config{
2936 Bugs: ProtocolBugs{
2937 RenewTicketOnResume: true,
2938 },
2939 },
David Benjaminba4594a2015-06-18 18:36:15 -04002940 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002941 resumeSession: true,
2942 })
2943 tests = append(tests, testCase{
2944 name: "Basic-Client-NoTicket",
2945 config: Config{
2946 SessionTicketsDisabled: true,
2947 },
2948 resumeSession: true,
2949 })
2950 tests = append(tests, testCase{
2951 name: "Basic-Client-Implicit",
2952 flags: []string{"-implicit-handshake"},
2953 resumeSession: true,
2954 })
2955 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002956 testType: serverTest,
2957 name: "Basic-Server",
2958 config: Config{
2959 Bugs: ProtocolBugs{
2960 RequireSessionTickets: true,
2961 },
2962 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002963 resumeSession: true,
2964 })
2965 tests = append(tests, testCase{
2966 testType: serverTest,
2967 name: "Basic-Server-NoTickets",
2968 config: Config{
2969 SessionTicketsDisabled: true,
2970 },
2971 resumeSession: true,
2972 })
2973 tests = append(tests, testCase{
2974 testType: serverTest,
2975 name: "Basic-Server-Implicit",
2976 flags: []string{"-implicit-handshake"},
2977 resumeSession: true,
2978 })
2979 tests = append(tests, testCase{
2980 testType: serverTest,
2981 name: "Basic-Server-EarlyCallback",
2982 flags: []string{"-use-early-callback"},
2983 resumeSession: true,
2984 })
2985
2986 // TLS client auth.
2987 tests = append(tests, testCase{
2988 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002989 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002990 config: Config{
2991 ClientAuth: RequestClientCert,
2992 },
2993 })
2994 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002995 testType: serverTest,
2996 name: "ClientAuth-NoCertificate-Server",
2997 // Setting SSL_VERIFY_PEER allows anonymous clients.
2998 flags: []string{"-verify-peer"},
2999 })
3000 if protocol == tls {
3001 tests = append(tests, testCase{
3002 testType: clientTest,
3003 name: "ClientAuth-NoCertificate-Client-SSL3",
3004 config: Config{
3005 MaxVersion: VersionSSL30,
3006 ClientAuth: RequestClientCert,
3007 },
3008 })
3009 tests = append(tests, testCase{
3010 testType: serverTest,
3011 name: "ClientAuth-NoCertificate-Server-SSL3",
3012 config: Config{
3013 MaxVersion: VersionSSL30,
3014 },
3015 // Setting SSL_VERIFY_PEER allows anonymous clients.
3016 flags: []string{"-verify-peer"},
3017 })
3018 }
3019 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003020 testType: clientTest,
3021 name: "ClientAuth-NoCertificate-OldCallback",
3022 config: Config{
3023 ClientAuth: RequestClientCert,
3024 },
3025 flags: []string{"-use-old-client-cert-callback"},
3026 })
3027 tests = append(tests, testCase{
3028 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003029 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003030 config: Config{
3031 ClientAuth: RequireAnyClientCert,
3032 },
3033 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003034 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3035 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003036 },
3037 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003038 tests = append(tests, testCase{
3039 testType: clientTest,
3040 name: "ClientAuth-ECDSA-Client",
3041 config: Config{
3042 ClientAuth: RequireAnyClientCert,
3043 },
3044 flags: []string{
3045 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3046 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3047 },
3048 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003049 tests = append(tests, testCase{
3050 testType: clientTest,
3051 name: "ClientAuth-OldCallback",
3052 config: Config{
3053 ClientAuth: RequireAnyClientCert,
3054 },
3055 flags: []string{
3056 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3057 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3058 "-use-old-client-cert-callback",
3059 },
3060 })
3061
David Benjaminb4d65fd2015-05-29 17:11:21 -04003062 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003063 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04003064 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003065 testType: serverTest,
3066 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04003067 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003068 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04003069 },
3070 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07003071 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3072 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04003073 },
3074 })
nagendra modadugu601448a2015-07-24 09:31:31 -07003075 tests = append(tests, testCase{
3076 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003077 name: "Basic-Server-ECDHE-RSA",
3078 config: Config{
3079 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3080 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003081 flags: []string{
3082 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3083 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003084 },
3085 })
3086 tests = append(tests, testCase{
3087 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003088 name: "Basic-Server-ECDHE-ECDSA",
3089 config: Config{
3090 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3091 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003092 flags: []string{
3093 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3094 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003095 },
3096 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04003097 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003098 tests = append(tests, testCase{
3099 testType: serverTest,
3100 name: "ClientAuth-Server",
3101 config: Config{
3102 Certificates: []Certificate{rsaCertificate},
3103 },
3104 flags: []string{"-require-any-client-certificate"},
3105 })
3106
3107 // No session ticket support; server doesn't send NewSessionTicket.
3108 tests = append(tests, testCase{
3109 name: "SessionTicketsDisabled-Client",
3110 config: Config{
3111 SessionTicketsDisabled: true,
3112 },
3113 })
3114 tests = append(tests, testCase{
3115 testType: serverTest,
3116 name: "SessionTicketsDisabled-Server",
3117 config: Config{
3118 SessionTicketsDisabled: true,
3119 },
3120 })
3121
3122 // Skip ServerKeyExchange in PSK key exchange if there's no
3123 // identity hint.
3124 tests = append(tests, testCase{
3125 name: "EmptyPSKHint-Client",
3126 config: Config{
3127 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3128 PreSharedKey: []byte("secret"),
3129 },
3130 flags: []string{"-psk", "secret"},
3131 })
3132 tests = append(tests, testCase{
3133 testType: serverTest,
3134 name: "EmptyPSKHint-Server",
3135 config: Config{
3136 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3137 PreSharedKey: []byte("secret"),
3138 },
3139 flags: []string{"-psk", "secret"},
3140 })
3141
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003142 tests = append(tests, testCase{
3143 testType: clientTest,
3144 name: "OCSPStapling-Client",
3145 flags: []string{
3146 "-enable-ocsp-stapling",
3147 "-expect-ocsp-response",
3148 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003149 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003150 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003151 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003152 })
3153
3154 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04003155 testType: serverTest,
3156 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003157 expectedOCSPResponse: testOCSPResponse,
3158 flags: []string{
3159 "-ocsp-response",
3160 base64.StdEncoding.EncodeToString(testOCSPResponse),
3161 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003162 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003163 })
3164
Paul Lietar8f1c2682015-08-18 12:21:54 +01003165 tests = append(tests, testCase{
3166 testType: clientTest,
3167 name: "CertificateVerificationSucceed",
3168 flags: []string{
3169 "-verify-peer",
3170 },
3171 })
3172
3173 tests = append(tests, testCase{
3174 testType: clientTest,
3175 name: "CertificateVerificationFail",
3176 flags: []string{
3177 "-verify-fail",
3178 "-verify-peer",
3179 },
3180 shouldFail: true,
3181 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3182 })
3183
3184 tests = append(tests, testCase{
3185 testType: clientTest,
3186 name: "CertificateVerificationSoftFail",
3187 flags: []string{
3188 "-verify-fail",
3189 "-expect-verify-result",
3190 },
3191 })
3192
David Benjamin760b1dd2015-05-15 23:33:48 -04003193 if protocol == tls {
3194 tests = append(tests, testCase{
3195 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003196 renegotiate: 1,
3197 flags: []string{
3198 "-renegotiate-freely",
3199 "-expect-total-renegotiations", "1",
3200 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003201 })
3202 // NPN on client and server; results in post-handshake message.
3203 tests = append(tests, testCase{
3204 name: "NPN-Client",
3205 config: Config{
3206 NextProtos: []string{"foo"},
3207 },
3208 flags: []string{"-select-next-proto", "foo"},
3209 expectedNextProto: "foo",
3210 expectedNextProtoType: npn,
3211 })
3212 tests = append(tests, testCase{
3213 testType: serverTest,
3214 name: "NPN-Server",
3215 config: Config{
3216 NextProtos: []string{"bar"},
3217 },
3218 flags: []string{
3219 "-advertise-npn", "\x03foo\x03bar\x03baz",
3220 "-expect-next-proto", "bar",
3221 },
3222 expectedNextProto: "bar",
3223 expectedNextProtoType: npn,
3224 })
3225
3226 // TODO(davidben): Add tests for when False Start doesn't trigger.
3227
3228 // Client does False Start and negotiates NPN.
3229 tests = append(tests, testCase{
3230 name: "FalseStart",
3231 config: Config{
3232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3233 NextProtos: []string{"foo"},
3234 Bugs: ProtocolBugs{
3235 ExpectFalseStart: true,
3236 },
3237 },
3238 flags: []string{
3239 "-false-start",
3240 "-select-next-proto", "foo",
3241 },
3242 shimWritesFirst: true,
3243 resumeSession: true,
3244 })
3245
3246 // Client does False Start and negotiates ALPN.
3247 tests = append(tests, testCase{
3248 name: "FalseStart-ALPN",
3249 config: Config{
3250 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3251 NextProtos: []string{"foo"},
3252 Bugs: ProtocolBugs{
3253 ExpectFalseStart: true,
3254 },
3255 },
3256 flags: []string{
3257 "-false-start",
3258 "-advertise-alpn", "\x03foo",
3259 },
3260 shimWritesFirst: true,
3261 resumeSession: true,
3262 })
3263
3264 // Client does False Start but doesn't explicitly call
3265 // SSL_connect.
3266 tests = append(tests, testCase{
3267 name: "FalseStart-Implicit",
3268 config: Config{
3269 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3270 NextProtos: []string{"foo"},
3271 },
3272 flags: []string{
3273 "-implicit-handshake",
3274 "-false-start",
3275 "-advertise-alpn", "\x03foo",
3276 },
3277 })
3278
3279 // False Start without session tickets.
3280 tests = append(tests, testCase{
3281 name: "FalseStart-SessionTicketsDisabled",
3282 config: Config{
3283 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3284 NextProtos: []string{"foo"},
3285 SessionTicketsDisabled: true,
3286 Bugs: ProtocolBugs{
3287 ExpectFalseStart: true,
3288 },
3289 },
3290 flags: []string{
3291 "-false-start",
3292 "-select-next-proto", "foo",
3293 },
3294 shimWritesFirst: true,
3295 })
3296
3297 // Server parses a V2ClientHello.
3298 tests = append(tests, testCase{
3299 testType: serverTest,
3300 name: "SendV2ClientHello",
3301 config: Config{
3302 // Choose a cipher suite that does not involve
3303 // elliptic curves, so no extensions are
3304 // involved.
3305 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3306 Bugs: ProtocolBugs{
3307 SendV2ClientHello: true,
3308 },
3309 },
3310 })
3311
3312 // Client sends a Channel ID.
3313 tests = append(tests, testCase{
3314 name: "ChannelID-Client",
3315 config: Config{
3316 RequestChannelID: true,
3317 },
Adam Langley7c803a62015-06-15 15:35:05 -07003318 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003319 resumeSession: true,
3320 expectChannelID: true,
3321 })
3322
3323 // Server accepts a Channel ID.
3324 tests = append(tests, testCase{
3325 testType: serverTest,
3326 name: "ChannelID-Server",
3327 config: Config{
3328 ChannelID: channelIDKey,
3329 },
3330 flags: []string{
3331 "-expect-channel-id",
3332 base64.StdEncoding.EncodeToString(channelIDBytes),
3333 },
3334 resumeSession: true,
3335 expectChannelID: true,
3336 })
David Benjamin30789da2015-08-29 22:56:45 -04003337
3338 // Bidirectional shutdown with the runner initiating.
3339 tests = append(tests, testCase{
3340 name: "Shutdown-Runner",
3341 config: Config{
3342 Bugs: ProtocolBugs{
3343 ExpectCloseNotify: true,
3344 },
3345 },
3346 flags: []string{"-check-close-notify"},
3347 })
3348
3349 // Bidirectional shutdown with the shim initiating. The runner,
3350 // in the meantime, sends garbage before the close_notify which
3351 // the shim must ignore.
3352 tests = append(tests, testCase{
3353 name: "Shutdown-Shim",
3354 config: Config{
3355 Bugs: ProtocolBugs{
3356 ExpectCloseNotify: true,
3357 },
3358 },
3359 shimShutsDown: true,
3360 sendEmptyRecords: 1,
3361 sendWarningAlerts: 1,
3362 flags: []string{"-check-close-notify"},
3363 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003364 } else {
3365 tests = append(tests, testCase{
3366 name: "SkipHelloVerifyRequest",
3367 config: Config{
3368 Bugs: ProtocolBugs{
3369 SkipHelloVerifyRequest: true,
3370 },
3371 },
3372 })
3373 }
3374
David Benjamin760b1dd2015-05-15 23:33:48 -04003375 for _, test := range tests {
3376 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003377 if protocol == dtls {
3378 test.name += "-DTLS"
3379 }
3380 if async {
3381 test.name += "-Async"
3382 test.flags = append(test.flags, "-async")
3383 } else {
3384 test.name += "-Sync"
3385 }
3386 if splitHandshake {
3387 test.name += "-SplitHandshakeRecords"
3388 test.config.Bugs.MaxHandshakeRecordLength = 1
3389 if protocol == dtls {
3390 test.config.Bugs.MaxPacketLength = 256
3391 test.flags = append(test.flags, "-mtu", "256")
3392 }
3393 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003394 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003395 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003396}
3397
Adam Langley524e7172015-02-20 16:04:00 -08003398func addDDoSCallbackTests() {
3399 // DDoS callback.
3400
3401 for _, resume := range []bool{false, true} {
3402 suffix := "Resume"
3403 if resume {
3404 suffix = "No" + suffix
3405 }
3406
3407 testCases = append(testCases, testCase{
3408 testType: serverTest,
3409 name: "Server-DDoS-OK-" + suffix,
3410 flags: []string{"-install-ddos-callback"},
3411 resumeSession: resume,
3412 })
3413
3414 failFlag := "-fail-ddos-callback"
3415 if resume {
3416 failFlag = "-fail-second-ddos-callback"
3417 }
3418 testCases = append(testCases, testCase{
3419 testType: serverTest,
3420 name: "Server-DDoS-Reject-" + suffix,
3421 flags: []string{"-install-ddos-callback", failFlag},
3422 resumeSession: resume,
3423 shouldFail: true,
3424 expectedError: ":CONNECTION_REJECTED:",
3425 })
3426 }
3427}
3428
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003429func addVersionNegotiationTests() {
3430 for i, shimVers := range tlsVersions {
3431 // Assemble flags to disable all newer versions on the shim.
3432 var flags []string
3433 for _, vers := range tlsVersions[i+1:] {
3434 flags = append(flags, vers.flag)
3435 }
3436
3437 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003438 protocols := []protocol{tls}
3439 if runnerVers.hasDTLS && shimVers.hasDTLS {
3440 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003441 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003442 for _, protocol := range protocols {
3443 expectedVersion := shimVers.version
3444 if runnerVers.version < shimVers.version {
3445 expectedVersion = runnerVers.version
3446 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003447
David Benjamin8b8c0062014-11-23 02:47:52 -05003448 suffix := shimVers.name + "-" + runnerVers.name
3449 if protocol == dtls {
3450 suffix += "-DTLS"
3451 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003452
David Benjamin1eb367c2014-12-12 18:17:51 -05003453 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3454
David Benjamin1e29a6b2014-12-10 02:27:24 -05003455 clientVers := shimVers.version
3456 if clientVers > VersionTLS10 {
3457 clientVers = VersionTLS10
3458 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003459 testCases = append(testCases, testCase{
3460 protocol: protocol,
3461 testType: clientTest,
3462 name: "VersionNegotiation-Client-" + suffix,
3463 config: Config{
3464 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003465 Bugs: ProtocolBugs{
3466 ExpectInitialRecordVersion: clientVers,
3467 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003468 },
3469 flags: flags,
3470 expectedVersion: expectedVersion,
3471 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003472 testCases = append(testCases, testCase{
3473 protocol: protocol,
3474 testType: clientTest,
3475 name: "VersionNegotiation-Client2-" + suffix,
3476 config: Config{
3477 MaxVersion: runnerVers.version,
3478 Bugs: ProtocolBugs{
3479 ExpectInitialRecordVersion: clientVers,
3480 },
3481 },
3482 flags: []string{"-max-version", shimVersFlag},
3483 expectedVersion: expectedVersion,
3484 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003485
3486 testCases = append(testCases, testCase{
3487 protocol: protocol,
3488 testType: serverTest,
3489 name: "VersionNegotiation-Server-" + suffix,
3490 config: Config{
3491 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003492 Bugs: ProtocolBugs{
3493 ExpectInitialRecordVersion: expectedVersion,
3494 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003495 },
3496 flags: flags,
3497 expectedVersion: expectedVersion,
3498 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003499 testCases = append(testCases, testCase{
3500 protocol: protocol,
3501 testType: serverTest,
3502 name: "VersionNegotiation-Server2-" + suffix,
3503 config: Config{
3504 MaxVersion: runnerVers.version,
3505 Bugs: ProtocolBugs{
3506 ExpectInitialRecordVersion: expectedVersion,
3507 },
3508 },
3509 flags: []string{"-max-version", shimVersFlag},
3510 expectedVersion: expectedVersion,
3511 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003512 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003513 }
3514 }
3515}
3516
David Benjaminaccb4542014-12-12 23:44:33 -05003517func addMinimumVersionTests() {
3518 for i, shimVers := range tlsVersions {
3519 // Assemble flags to disable all older versions on the shim.
3520 var flags []string
3521 for _, vers := range tlsVersions[:i] {
3522 flags = append(flags, vers.flag)
3523 }
3524
3525 for _, runnerVers := range tlsVersions {
3526 protocols := []protocol{tls}
3527 if runnerVers.hasDTLS && shimVers.hasDTLS {
3528 protocols = append(protocols, dtls)
3529 }
3530 for _, protocol := range protocols {
3531 suffix := shimVers.name + "-" + runnerVers.name
3532 if protocol == dtls {
3533 suffix += "-DTLS"
3534 }
3535 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3536
David Benjaminaccb4542014-12-12 23:44:33 -05003537 var expectedVersion uint16
3538 var shouldFail bool
3539 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003540 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003541 if runnerVers.version >= shimVers.version {
3542 expectedVersion = runnerVers.version
3543 } else {
3544 shouldFail = true
3545 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamina565d292015-12-30 16:51:32 -05003546 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05003547 }
3548
3549 testCases = append(testCases, testCase{
3550 protocol: protocol,
3551 testType: clientTest,
3552 name: "MinimumVersion-Client-" + suffix,
3553 config: Config{
3554 MaxVersion: runnerVers.version,
3555 },
David Benjamin87909c02014-12-13 01:55:01 -05003556 flags: flags,
3557 expectedVersion: expectedVersion,
3558 shouldFail: shouldFail,
3559 expectedError: expectedError,
3560 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003561 })
3562 testCases = append(testCases, testCase{
3563 protocol: protocol,
3564 testType: clientTest,
3565 name: "MinimumVersion-Client2-" + suffix,
3566 config: Config{
3567 MaxVersion: runnerVers.version,
3568 },
David Benjamin87909c02014-12-13 01:55:01 -05003569 flags: []string{"-min-version", shimVersFlag},
3570 expectedVersion: expectedVersion,
3571 shouldFail: shouldFail,
3572 expectedError: expectedError,
3573 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003574 })
3575
3576 testCases = append(testCases, testCase{
3577 protocol: protocol,
3578 testType: serverTest,
3579 name: "MinimumVersion-Server-" + suffix,
3580 config: Config{
3581 MaxVersion: runnerVers.version,
3582 },
David Benjamin87909c02014-12-13 01:55:01 -05003583 flags: flags,
3584 expectedVersion: expectedVersion,
3585 shouldFail: shouldFail,
3586 expectedError: expectedError,
3587 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003588 })
3589 testCases = append(testCases, testCase{
3590 protocol: protocol,
3591 testType: serverTest,
3592 name: "MinimumVersion-Server2-" + suffix,
3593 config: Config{
3594 MaxVersion: runnerVers.version,
3595 },
David Benjamin87909c02014-12-13 01:55:01 -05003596 flags: []string{"-min-version", shimVersFlag},
3597 expectedVersion: expectedVersion,
3598 shouldFail: shouldFail,
3599 expectedError: expectedError,
3600 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003601 })
3602 }
3603 }
3604 }
3605}
3606
David Benjamine78bfde2014-09-06 12:45:15 -04003607func addExtensionTests() {
3608 testCases = append(testCases, testCase{
3609 testType: clientTest,
3610 name: "DuplicateExtensionClient",
3611 config: Config{
3612 Bugs: ProtocolBugs{
3613 DuplicateExtension: true,
3614 },
3615 },
3616 shouldFail: true,
3617 expectedLocalError: "remote error: error decoding message",
3618 })
3619 testCases = append(testCases, testCase{
3620 testType: serverTest,
3621 name: "DuplicateExtensionServer",
3622 config: Config{
3623 Bugs: ProtocolBugs{
3624 DuplicateExtension: true,
3625 },
3626 },
3627 shouldFail: true,
3628 expectedLocalError: "remote error: error decoding message",
3629 })
3630 testCases = append(testCases, testCase{
3631 testType: clientTest,
3632 name: "ServerNameExtensionClient",
3633 config: Config{
3634 Bugs: ProtocolBugs{
3635 ExpectServerName: "example.com",
3636 },
3637 },
3638 flags: []string{"-host-name", "example.com"},
3639 })
3640 testCases = append(testCases, testCase{
3641 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003642 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003643 config: Config{
3644 Bugs: ProtocolBugs{
3645 ExpectServerName: "mismatch.com",
3646 },
3647 },
3648 flags: []string{"-host-name", "example.com"},
3649 shouldFail: true,
3650 expectedLocalError: "tls: unexpected server name",
3651 })
3652 testCases = append(testCases, testCase{
3653 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003654 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003655 config: Config{
3656 Bugs: ProtocolBugs{
3657 ExpectServerName: "missing.com",
3658 },
3659 },
3660 shouldFail: true,
3661 expectedLocalError: "tls: unexpected server name",
3662 })
3663 testCases = append(testCases, testCase{
3664 testType: serverTest,
3665 name: "ServerNameExtensionServer",
3666 config: Config{
3667 ServerName: "example.com",
3668 },
3669 flags: []string{"-expect-server-name", "example.com"},
3670 resumeSession: true,
3671 })
David Benjaminae2888f2014-09-06 12:58:58 -04003672 testCases = append(testCases, testCase{
3673 testType: clientTest,
3674 name: "ALPNClient",
3675 config: Config{
3676 NextProtos: []string{"foo"},
3677 },
3678 flags: []string{
3679 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3680 "-expect-alpn", "foo",
3681 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003682 expectedNextProto: "foo",
3683 expectedNextProtoType: alpn,
3684 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003685 })
3686 testCases = append(testCases, testCase{
3687 testType: serverTest,
3688 name: "ALPNServer",
3689 config: Config{
3690 NextProtos: []string{"foo", "bar", "baz"},
3691 },
3692 flags: []string{
3693 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3694 "-select-alpn", "foo",
3695 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003696 expectedNextProto: "foo",
3697 expectedNextProtoType: alpn,
3698 resumeSession: true,
3699 })
David Benjamin594e7d22016-03-17 17:49:56 -04003700 testCases = append(testCases, testCase{
3701 testType: serverTest,
3702 name: "ALPNServer-Decline",
3703 config: Config{
3704 NextProtos: []string{"foo", "bar", "baz"},
3705 },
3706 flags: []string{"-decline-alpn"},
3707 expectNoNextProto: true,
3708 resumeSession: true,
3709 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003710 // Test that the server prefers ALPN over NPN.
3711 testCases = append(testCases, testCase{
3712 testType: serverTest,
3713 name: "ALPNServer-Preferred",
3714 config: Config{
3715 NextProtos: []string{"foo", "bar", "baz"},
3716 },
3717 flags: []string{
3718 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3719 "-select-alpn", "foo",
3720 "-advertise-npn", "\x03foo\x03bar\x03baz",
3721 },
3722 expectedNextProto: "foo",
3723 expectedNextProtoType: alpn,
3724 resumeSession: true,
3725 })
3726 testCases = append(testCases, testCase{
3727 testType: serverTest,
3728 name: "ALPNServer-Preferred-Swapped",
3729 config: Config{
3730 NextProtos: []string{"foo", "bar", "baz"},
3731 Bugs: ProtocolBugs{
3732 SwapNPNAndALPN: true,
3733 },
3734 },
3735 flags: []string{
3736 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3737 "-select-alpn", "foo",
3738 "-advertise-npn", "\x03foo\x03bar\x03baz",
3739 },
3740 expectedNextProto: "foo",
3741 expectedNextProtoType: alpn,
3742 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003743 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003744 var emptyString string
3745 testCases = append(testCases, testCase{
3746 testType: clientTest,
3747 name: "ALPNClient-EmptyProtocolName",
3748 config: Config{
3749 NextProtos: []string{""},
3750 Bugs: ProtocolBugs{
3751 // A server returning an empty ALPN protocol
3752 // should be rejected.
3753 ALPNProtocol: &emptyString,
3754 },
3755 },
3756 flags: []string{
3757 "-advertise-alpn", "\x03foo",
3758 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003759 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003760 expectedError: ":PARSE_TLSEXT:",
3761 })
3762 testCases = append(testCases, testCase{
3763 testType: serverTest,
3764 name: "ALPNServer-EmptyProtocolName",
3765 config: Config{
3766 // A ClientHello containing an empty ALPN protocol
3767 // should be rejected.
3768 NextProtos: []string{"foo", "", "baz"},
3769 },
3770 flags: []string{
3771 "-select-alpn", "foo",
3772 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003773 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003774 expectedError: ":PARSE_TLSEXT:",
3775 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003776 // Test that negotiating both NPN and ALPN is forbidden.
3777 testCases = append(testCases, testCase{
3778 name: "NegotiateALPNAndNPN",
3779 config: Config{
3780 NextProtos: []string{"foo", "bar", "baz"},
3781 Bugs: ProtocolBugs{
3782 NegotiateALPNAndNPN: true,
3783 },
3784 },
3785 flags: []string{
3786 "-advertise-alpn", "\x03foo",
3787 "-select-next-proto", "foo",
3788 },
3789 shouldFail: true,
3790 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3791 })
3792 testCases = append(testCases, testCase{
3793 name: "NegotiateALPNAndNPN-Swapped",
3794 config: Config{
3795 NextProtos: []string{"foo", "bar", "baz"},
3796 Bugs: ProtocolBugs{
3797 NegotiateALPNAndNPN: true,
3798 SwapNPNAndALPN: true,
3799 },
3800 },
3801 flags: []string{
3802 "-advertise-alpn", "\x03foo",
3803 "-select-next-proto", "foo",
3804 },
3805 shouldFail: true,
3806 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3807 })
David Benjamin091c4b92015-10-26 13:33:21 -04003808 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3809 testCases = append(testCases, testCase{
3810 name: "DisableNPN",
3811 config: Config{
3812 NextProtos: []string{"foo"},
3813 },
3814 flags: []string{
3815 "-select-next-proto", "foo",
3816 "-disable-npn",
3817 },
3818 expectNoNextProto: true,
3819 })
Adam Langley38311732014-10-16 19:04:35 -07003820 // Resume with a corrupt ticket.
3821 testCases = append(testCases, testCase{
3822 testType: serverTest,
3823 name: "CorruptTicket",
3824 config: Config{
3825 Bugs: ProtocolBugs{
3826 CorruptTicket: true,
3827 },
3828 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003829 resumeSession: true,
3830 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003831 })
David Benjamind98452d2015-06-16 14:16:23 -04003832 // Test the ticket callback, with and without renewal.
3833 testCases = append(testCases, testCase{
3834 testType: serverTest,
3835 name: "TicketCallback",
3836 resumeSession: true,
3837 flags: []string{"-use-ticket-callback"},
3838 })
3839 testCases = append(testCases, testCase{
3840 testType: serverTest,
3841 name: "TicketCallback-Renew",
3842 config: Config{
3843 Bugs: ProtocolBugs{
3844 ExpectNewTicket: true,
3845 },
3846 },
3847 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3848 resumeSession: true,
3849 })
Adam Langley38311732014-10-16 19:04:35 -07003850 // Resume with an oversized session id.
3851 testCases = append(testCases, testCase{
3852 testType: serverTest,
3853 name: "OversizedSessionId",
3854 config: Config{
3855 Bugs: ProtocolBugs{
3856 OversizedSessionId: true,
3857 },
3858 },
3859 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003860 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003861 expectedError: ":DECODE_ERROR:",
3862 })
David Benjaminca6c8262014-11-15 19:06:08 -05003863 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3864 // are ignored.
3865 testCases = append(testCases, testCase{
3866 protocol: dtls,
3867 name: "SRTP-Client",
3868 config: Config{
3869 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3870 },
3871 flags: []string{
3872 "-srtp-profiles",
3873 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3874 },
3875 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3876 })
3877 testCases = append(testCases, testCase{
3878 protocol: dtls,
3879 testType: serverTest,
3880 name: "SRTP-Server",
3881 config: Config{
3882 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3883 },
3884 flags: []string{
3885 "-srtp-profiles",
3886 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3887 },
3888 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3889 })
3890 // Test that the MKI is ignored.
3891 testCases = append(testCases, testCase{
3892 protocol: dtls,
3893 testType: serverTest,
3894 name: "SRTP-Server-IgnoreMKI",
3895 config: Config{
3896 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3897 Bugs: ProtocolBugs{
3898 SRTPMasterKeyIdentifer: "bogus",
3899 },
3900 },
3901 flags: []string{
3902 "-srtp-profiles",
3903 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3904 },
3905 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3906 })
3907 // Test that SRTP isn't negotiated on the server if there were
3908 // no matching profiles.
3909 testCases = append(testCases, testCase{
3910 protocol: dtls,
3911 testType: serverTest,
3912 name: "SRTP-Server-NoMatch",
3913 config: Config{
3914 SRTPProtectionProfiles: []uint16{100, 101, 102},
3915 },
3916 flags: []string{
3917 "-srtp-profiles",
3918 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3919 },
3920 expectedSRTPProtectionProfile: 0,
3921 })
3922 // Test that the server returning an invalid SRTP profile is
3923 // flagged as an error by the client.
3924 testCases = append(testCases, testCase{
3925 protocol: dtls,
3926 name: "SRTP-Client-NoMatch",
3927 config: Config{
3928 Bugs: ProtocolBugs{
3929 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3930 },
3931 },
3932 flags: []string{
3933 "-srtp-profiles",
3934 "SRTP_AES128_CM_SHA1_80",
3935 },
3936 shouldFail: true,
3937 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3938 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003939 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003940 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003941 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003942 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003943 flags: []string{
3944 "-enable-signed-cert-timestamps",
3945 "-expect-signed-cert-timestamps",
3946 base64.StdEncoding.EncodeToString(testSCTList),
3947 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003948 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003949 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003950 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04003951 name: "SendSCTListOnResume",
3952 config: Config{
3953 Bugs: ProtocolBugs{
3954 SendSCTListOnResume: []byte("bogus"),
3955 },
3956 },
3957 flags: []string{
3958 "-enable-signed-cert-timestamps",
3959 "-expect-signed-cert-timestamps",
3960 base64.StdEncoding.EncodeToString(testSCTList),
3961 },
3962 resumeSession: true,
3963 })
3964 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003965 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003966 testType: serverTest,
3967 flags: []string{
3968 "-signed-cert-timestamps",
3969 base64.StdEncoding.EncodeToString(testSCTList),
3970 },
3971 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003972 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003973 })
3974 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003975 testType: clientTest,
3976 name: "ClientHelloPadding",
3977 config: Config{
3978 Bugs: ProtocolBugs{
3979 RequireClientHelloSize: 512,
3980 },
3981 },
3982 // This hostname just needs to be long enough to push the
3983 // ClientHello into F5's danger zone between 256 and 511 bytes
3984 // long.
3985 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3986 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003987
3988 // Extensions should not function in SSL 3.0.
3989 testCases = append(testCases, testCase{
3990 testType: serverTest,
3991 name: "SSLv3Extensions-NoALPN",
3992 config: Config{
3993 MaxVersion: VersionSSL30,
3994 NextProtos: []string{"foo", "bar", "baz"},
3995 },
3996 flags: []string{
3997 "-select-alpn", "foo",
3998 },
3999 expectNoNextProto: true,
4000 })
4001
4002 // Test session tickets separately as they follow a different codepath.
4003 testCases = append(testCases, testCase{
4004 testType: serverTest,
4005 name: "SSLv3Extensions-NoTickets",
4006 config: Config{
4007 MaxVersion: VersionSSL30,
4008 Bugs: ProtocolBugs{
4009 // Historically, session tickets in SSL 3.0
4010 // failed in different ways depending on whether
4011 // the client supported renegotiation_info.
4012 NoRenegotiationInfo: true,
4013 },
4014 },
4015 resumeSession: true,
4016 })
4017 testCases = append(testCases, testCase{
4018 testType: serverTest,
4019 name: "SSLv3Extensions-NoTickets2",
4020 config: Config{
4021 MaxVersion: VersionSSL30,
4022 },
4023 resumeSession: true,
4024 })
4025
4026 // But SSL 3.0 does send and process renegotiation_info.
4027 testCases = append(testCases, testCase{
4028 testType: serverTest,
4029 name: "SSLv3Extensions-RenegotiationInfo",
4030 config: Config{
4031 MaxVersion: VersionSSL30,
4032 Bugs: ProtocolBugs{
4033 RequireRenegotiationInfo: true,
4034 },
4035 },
4036 })
4037 testCases = append(testCases, testCase{
4038 testType: serverTest,
4039 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4040 config: Config{
4041 MaxVersion: VersionSSL30,
4042 Bugs: ProtocolBugs{
4043 NoRenegotiationInfo: true,
4044 SendRenegotiationSCSV: true,
4045 RequireRenegotiationInfo: true,
4046 },
4047 },
4048 })
David Benjamine78bfde2014-09-06 12:45:15 -04004049}
4050
David Benjamin01fe8202014-09-24 15:21:44 -04004051func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004052 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004053 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004054 protocols := []protocol{tls}
4055 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4056 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004057 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004058 for _, protocol := range protocols {
4059 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4060 if protocol == dtls {
4061 suffix += "-DTLS"
4062 }
4063
David Benjaminece3de92015-03-16 18:02:20 -04004064 if sessionVers.version == resumeVers.version {
4065 testCases = append(testCases, testCase{
4066 protocol: protocol,
4067 name: "Resume-Client" + suffix,
4068 resumeSession: true,
4069 config: Config{
4070 MaxVersion: sessionVers.version,
4071 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004072 },
David Benjaminece3de92015-03-16 18:02:20 -04004073 expectedVersion: sessionVers.version,
4074 expectedResumeVersion: resumeVers.version,
4075 })
4076 } else {
4077 testCases = append(testCases, testCase{
4078 protocol: protocol,
4079 name: "Resume-Client-Mismatch" + suffix,
4080 resumeSession: true,
4081 config: Config{
4082 MaxVersion: sessionVers.version,
4083 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004084 },
David Benjaminece3de92015-03-16 18:02:20 -04004085 expectedVersion: sessionVers.version,
4086 resumeConfig: &Config{
4087 MaxVersion: resumeVers.version,
4088 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4089 Bugs: ProtocolBugs{
4090 AllowSessionVersionMismatch: true,
4091 },
4092 },
4093 expectedResumeVersion: resumeVers.version,
4094 shouldFail: true,
4095 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4096 })
4097 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004098
4099 testCases = append(testCases, testCase{
4100 protocol: protocol,
4101 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004102 resumeSession: true,
4103 config: Config{
4104 MaxVersion: sessionVers.version,
4105 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4106 },
4107 expectedVersion: sessionVers.version,
4108 resumeConfig: &Config{
4109 MaxVersion: resumeVers.version,
4110 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4111 },
4112 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004113 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004114 expectedResumeVersion: resumeVers.version,
4115 })
4116
David Benjamin8b8c0062014-11-23 02:47:52 -05004117 testCases = append(testCases, testCase{
4118 protocol: protocol,
4119 testType: serverTest,
4120 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004121 resumeSession: true,
4122 config: Config{
4123 MaxVersion: sessionVers.version,
4124 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4125 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004126 expectedVersion: sessionVers.version,
4127 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004128 resumeConfig: &Config{
4129 MaxVersion: resumeVers.version,
4130 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4131 },
4132 expectedResumeVersion: resumeVers.version,
4133 })
4134 }
David Benjamin01fe8202014-09-24 15:21:44 -04004135 }
4136 }
David Benjaminece3de92015-03-16 18:02:20 -04004137
4138 testCases = append(testCases, testCase{
4139 name: "Resume-Client-CipherMismatch",
4140 resumeSession: true,
4141 config: Config{
4142 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4143 },
4144 resumeConfig: &Config{
4145 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4146 Bugs: ProtocolBugs{
4147 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4148 },
4149 },
4150 shouldFail: true,
4151 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4152 })
David Benjamin01fe8202014-09-24 15:21:44 -04004153}
4154
Adam Langley2ae77d22014-10-28 17:29:33 -07004155func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004156 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004157 testCases = append(testCases, testCase{
4158 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04004159 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004160 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004161 shouldFail: true,
4162 expectedError: ":NO_RENEGOTIATION:",
4163 expectedLocalError: "remote error: no renegotiation",
4164 })
Adam Langley5021b222015-06-12 18:27:58 -07004165 // The server shouldn't echo the renegotiation extension unless
4166 // requested by the client.
4167 testCases = append(testCases, testCase{
4168 testType: serverTest,
4169 name: "Renegotiate-Server-NoExt",
4170 config: Config{
4171 Bugs: ProtocolBugs{
4172 NoRenegotiationInfo: true,
4173 RequireRenegotiationInfo: true,
4174 },
4175 },
4176 shouldFail: true,
4177 expectedLocalError: "renegotiation extension missing",
4178 })
4179 // The renegotiation SCSV should be sufficient for the server to echo
4180 // the extension.
4181 testCases = append(testCases, testCase{
4182 testType: serverTest,
4183 name: "Renegotiate-Server-NoExt-SCSV",
4184 config: Config{
4185 Bugs: ProtocolBugs{
4186 NoRenegotiationInfo: true,
4187 SendRenegotiationSCSV: true,
4188 RequireRenegotiationInfo: true,
4189 },
4190 },
4191 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004192 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004193 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004194 config: Config{
4195 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004196 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004197 },
4198 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004199 renegotiate: 1,
4200 flags: []string{
4201 "-renegotiate-freely",
4202 "-expect-total-renegotiations", "1",
4203 },
David Benjamincdea40c2015-03-19 14:09:43 -04004204 })
4205 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004206 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004207 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004208 config: Config{
4209 Bugs: ProtocolBugs{
4210 EmptyRenegotiationInfo: true,
4211 },
4212 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004213 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004214 shouldFail: true,
4215 expectedError: ":RENEGOTIATION_MISMATCH:",
4216 })
4217 testCases = append(testCases, testCase{
4218 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004219 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004220 config: Config{
4221 Bugs: ProtocolBugs{
4222 BadRenegotiationInfo: true,
4223 },
4224 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004225 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004226 shouldFail: true,
4227 expectedError: ":RENEGOTIATION_MISMATCH:",
4228 })
4229 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004230 name: "Renegotiate-Client-Downgrade",
4231 renegotiate: 1,
4232 config: Config{
4233 Bugs: ProtocolBugs{
4234 NoRenegotiationInfoAfterInitial: true,
4235 },
4236 },
4237 flags: []string{"-renegotiate-freely"},
4238 shouldFail: true,
4239 expectedError: ":RENEGOTIATION_MISMATCH:",
4240 })
4241 testCases = append(testCases, testCase{
4242 name: "Renegotiate-Client-Upgrade",
4243 renegotiate: 1,
4244 config: Config{
4245 Bugs: ProtocolBugs{
4246 NoRenegotiationInfoInInitial: true,
4247 },
4248 },
4249 flags: []string{"-renegotiate-freely"},
4250 shouldFail: true,
4251 expectedError: ":RENEGOTIATION_MISMATCH:",
4252 })
4253 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004254 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004255 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004256 config: Config{
4257 Bugs: ProtocolBugs{
4258 NoRenegotiationInfo: true,
4259 },
4260 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004261 flags: []string{
4262 "-renegotiate-freely",
4263 "-expect-total-renegotiations", "1",
4264 },
David Benjamincff0b902015-05-15 23:09:47 -04004265 })
4266 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004267 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004268 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004269 config: Config{
4270 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4271 },
4272 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004273 flags: []string{
4274 "-renegotiate-freely",
4275 "-expect-total-renegotiations", "1",
4276 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004277 })
4278 testCases = append(testCases, testCase{
4279 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004280 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004281 config: Config{
4282 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4283 },
4284 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004285 flags: []string{
4286 "-renegotiate-freely",
4287 "-expect-total-renegotiations", "1",
4288 },
David Benjaminb16346b2015-04-08 19:16:58 -04004289 })
4290 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004291 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004292 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004293 config: Config{
4294 MaxVersion: VersionTLS10,
4295 Bugs: ProtocolBugs{
4296 RequireSameRenegoClientVersion: true,
4297 },
4298 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004299 flags: []string{
4300 "-renegotiate-freely",
4301 "-expect-total-renegotiations", "1",
4302 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004303 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004304 testCases = append(testCases, testCase{
4305 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004306 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004307 config: Config{
4308 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4309 NextProtos: []string{"foo"},
4310 },
4311 flags: []string{
4312 "-false-start",
4313 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004314 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004315 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004316 },
4317 shimWritesFirst: true,
4318 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004319
4320 // Client-side renegotiation controls.
4321 testCases = append(testCases, testCase{
4322 name: "Renegotiate-Client-Forbidden-1",
4323 renegotiate: 1,
4324 shouldFail: true,
4325 expectedError: ":NO_RENEGOTIATION:",
4326 expectedLocalError: "remote error: no renegotiation",
4327 })
4328 testCases = append(testCases, testCase{
4329 name: "Renegotiate-Client-Once-1",
4330 renegotiate: 1,
4331 flags: []string{
4332 "-renegotiate-once",
4333 "-expect-total-renegotiations", "1",
4334 },
4335 })
4336 testCases = append(testCases, testCase{
4337 name: "Renegotiate-Client-Freely-1",
4338 renegotiate: 1,
4339 flags: []string{
4340 "-renegotiate-freely",
4341 "-expect-total-renegotiations", "1",
4342 },
4343 })
4344 testCases = append(testCases, testCase{
4345 name: "Renegotiate-Client-Once-2",
4346 renegotiate: 2,
4347 flags: []string{"-renegotiate-once"},
4348 shouldFail: true,
4349 expectedError: ":NO_RENEGOTIATION:",
4350 expectedLocalError: "remote error: no renegotiation",
4351 })
4352 testCases = append(testCases, testCase{
4353 name: "Renegotiate-Client-Freely-2",
4354 renegotiate: 2,
4355 flags: []string{
4356 "-renegotiate-freely",
4357 "-expect-total-renegotiations", "2",
4358 },
4359 })
Adam Langley27a0d082015-11-03 13:34:10 -08004360 testCases = append(testCases, testCase{
4361 name: "Renegotiate-Client-NoIgnore",
4362 config: Config{
4363 Bugs: ProtocolBugs{
4364 SendHelloRequestBeforeEveryAppDataRecord: true,
4365 },
4366 },
4367 shouldFail: true,
4368 expectedError: ":NO_RENEGOTIATION:",
4369 })
4370 testCases = append(testCases, testCase{
4371 name: "Renegotiate-Client-Ignore",
4372 config: Config{
4373 Bugs: ProtocolBugs{
4374 SendHelloRequestBeforeEveryAppDataRecord: true,
4375 },
4376 },
4377 flags: []string{
4378 "-renegotiate-ignore",
4379 "-expect-total-renegotiations", "0",
4380 },
4381 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004382}
4383
David Benjamin5e961c12014-11-07 01:48:35 -05004384func addDTLSReplayTests() {
4385 // Test that sequence number replays are detected.
4386 testCases = append(testCases, testCase{
4387 protocol: dtls,
4388 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004389 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004390 replayWrites: true,
4391 })
4392
David Benjamin8e6db492015-07-25 18:29:23 -04004393 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004394 // than the retransmit window.
4395 testCases = append(testCases, testCase{
4396 protocol: dtls,
4397 name: "DTLS-Replay-LargeGaps",
4398 config: Config{
4399 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004400 SequenceNumberMapping: func(in uint64) uint64 {
4401 return in * 127
4402 },
David Benjamin5e961c12014-11-07 01:48:35 -05004403 },
4404 },
David Benjamin8e6db492015-07-25 18:29:23 -04004405 messageCount: 200,
4406 replayWrites: true,
4407 })
4408
4409 // Test the incoming sequence number changing non-monotonically.
4410 testCases = append(testCases, testCase{
4411 protocol: dtls,
4412 name: "DTLS-Replay-NonMonotonic",
4413 config: Config{
4414 Bugs: ProtocolBugs{
4415 SequenceNumberMapping: func(in uint64) uint64 {
4416 return in ^ 31
4417 },
4418 },
4419 },
4420 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004421 replayWrites: true,
4422 })
4423}
4424
David Benjamin000800a2014-11-14 01:43:59 -05004425var testHashes = []struct {
4426 name string
4427 id uint8
4428}{
4429 {"SHA1", hashSHA1},
David Benjamin000800a2014-11-14 01:43:59 -05004430 {"SHA256", hashSHA256},
4431 {"SHA384", hashSHA384},
4432 {"SHA512", hashSHA512},
4433}
4434
4435func addSigningHashTests() {
4436 // Make sure each hash works. Include some fake hashes in the list and
4437 // ensure they're ignored.
4438 for _, hash := range testHashes {
4439 testCases = append(testCases, testCase{
4440 name: "SigningHash-ClientAuth-" + hash.name,
4441 config: Config{
4442 ClientAuth: RequireAnyClientCert,
4443 SignatureAndHashes: []signatureAndHash{
4444 {signatureRSA, 42},
4445 {signatureRSA, hash.id},
4446 {signatureRSA, 255},
4447 },
4448 },
4449 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004450 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4451 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004452 },
4453 })
4454
4455 testCases = append(testCases, testCase{
4456 testType: serverTest,
4457 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4458 config: Config{
4459 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4460 SignatureAndHashes: []signatureAndHash{
4461 {signatureRSA, 42},
4462 {signatureRSA, hash.id},
4463 {signatureRSA, 255},
4464 },
4465 },
4466 })
David Benjamin6e807652015-11-02 12:02:20 -05004467
4468 testCases = append(testCases, testCase{
4469 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4470 config: Config{
4471 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4472 SignatureAndHashes: []signatureAndHash{
4473 {signatureRSA, 42},
4474 {signatureRSA, hash.id},
4475 {signatureRSA, 255},
4476 },
4477 },
4478 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4479 })
David Benjamin000800a2014-11-14 01:43:59 -05004480 }
4481
4482 // Test that hash resolution takes the signature type into account.
4483 testCases = append(testCases, testCase{
4484 name: "SigningHash-ClientAuth-SignatureType",
4485 config: Config{
4486 ClientAuth: RequireAnyClientCert,
4487 SignatureAndHashes: []signatureAndHash{
4488 {signatureECDSA, hashSHA512},
4489 {signatureRSA, hashSHA384},
4490 {signatureECDSA, hashSHA1},
4491 },
4492 },
4493 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004494 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4495 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004496 },
4497 })
4498
4499 testCases = append(testCases, testCase{
4500 testType: serverTest,
4501 name: "SigningHash-ServerKeyExchange-SignatureType",
4502 config: Config{
4503 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4504 SignatureAndHashes: []signatureAndHash{
4505 {signatureECDSA, hashSHA512},
4506 {signatureRSA, hashSHA384},
4507 {signatureECDSA, hashSHA1},
4508 },
4509 },
4510 })
4511
4512 // Test that, if the list is missing, the peer falls back to SHA-1.
4513 testCases = append(testCases, testCase{
4514 name: "SigningHash-ClientAuth-Fallback",
4515 config: Config{
4516 ClientAuth: RequireAnyClientCert,
4517 SignatureAndHashes: []signatureAndHash{
4518 {signatureRSA, hashSHA1},
4519 },
4520 Bugs: ProtocolBugs{
4521 NoSignatureAndHashes: true,
4522 },
4523 },
4524 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004525 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4526 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004527 },
4528 })
4529
4530 testCases = append(testCases, testCase{
4531 testType: serverTest,
4532 name: "SigningHash-ServerKeyExchange-Fallback",
4533 config: Config{
4534 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4535 SignatureAndHashes: []signatureAndHash{
4536 {signatureRSA, hashSHA1},
4537 },
4538 Bugs: ProtocolBugs{
4539 NoSignatureAndHashes: true,
4540 },
4541 },
4542 })
David Benjamin72dc7832015-03-16 17:49:43 -04004543
4544 // Test that hash preferences are enforced. BoringSSL defaults to
4545 // rejecting MD5 signatures.
4546 testCases = append(testCases, testCase{
4547 testType: serverTest,
4548 name: "SigningHash-ClientAuth-Enforced",
4549 config: Config{
4550 Certificates: []Certificate{rsaCertificate},
4551 SignatureAndHashes: []signatureAndHash{
4552 {signatureRSA, hashMD5},
4553 // Advertise SHA-1 so the handshake will
4554 // proceed, but the shim's preferences will be
4555 // ignored in CertificateVerify generation, so
4556 // MD5 will be chosen.
4557 {signatureRSA, hashSHA1},
4558 },
4559 Bugs: ProtocolBugs{
4560 IgnorePeerSignatureAlgorithmPreferences: true,
4561 },
4562 },
4563 flags: []string{"-require-any-client-certificate"},
4564 shouldFail: true,
4565 expectedError: ":WRONG_SIGNATURE_TYPE:",
4566 })
4567
4568 testCases = append(testCases, testCase{
4569 name: "SigningHash-ServerKeyExchange-Enforced",
4570 config: Config{
4571 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4572 SignatureAndHashes: []signatureAndHash{
4573 {signatureRSA, hashMD5},
4574 },
4575 Bugs: ProtocolBugs{
4576 IgnorePeerSignatureAlgorithmPreferences: true,
4577 },
4578 },
4579 shouldFail: true,
4580 expectedError: ":WRONG_SIGNATURE_TYPE:",
4581 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004582
4583 // Test that the agreed upon digest respects the client preferences and
4584 // the server digests.
4585 testCases = append(testCases, testCase{
4586 name: "Agree-Digest-Fallback",
4587 config: Config{
4588 ClientAuth: RequireAnyClientCert,
4589 SignatureAndHashes: []signatureAndHash{
4590 {signatureRSA, hashSHA512},
4591 {signatureRSA, hashSHA1},
4592 },
4593 },
4594 flags: []string{
4595 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4596 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4597 },
4598 digestPrefs: "SHA256",
4599 expectedClientCertSignatureHash: hashSHA1,
4600 })
4601 testCases = append(testCases, testCase{
4602 name: "Agree-Digest-SHA256",
4603 config: Config{
4604 ClientAuth: RequireAnyClientCert,
4605 SignatureAndHashes: []signatureAndHash{
4606 {signatureRSA, hashSHA1},
4607 {signatureRSA, hashSHA256},
4608 },
4609 },
4610 flags: []string{
4611 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4612 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4613 },
4614 digestPrefs: "SHA256,SHA1",
4615 expectedClientCertSignatureHash: hashSHA256,
4616 })
4617 testCases = append(testCases, testCase{
4618 name: "Agree-Digest-SHA1",
4619 config: Config{
4620 ClientAuth: RequireAnyClientCert,
4621 SignatureAndHashes: []signatureAndHash{
4622 {signatureRSA, hashSHA1},
4623 },
4624 },
4625 flags: []string{
4626 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4627 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4628 },
4629 digestPrefs: "SHA512,SHA256,SHA1",
4630 expectedClientCertSignatureHash: hashSHA1,
4631 })
4632 testCases = append(testCases, testCase{
4633 name: "Agree-Digest-Default",
4634 config: Config{
4635 ClientAuth: RequireAnyClientCert,
4636 SignatureAndHashes: []signatureAndHash{
4637 {signatureRSA, hashSHA256},
4638 {signatureECDSA, hashSHA256},
4639 {signatureRSA, hashSHA1},
4640 {signatureECDSA, hashSHA1},
4641 },
4642 },
4643 flags: []string{
4644 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4645 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4646 },
4647 expectedClientCertSignatureHash: hashSHA256,
4648 })
David Benjamin000800a2014-11-14 01:43:59 -05004649}
4650
David Benjamin83f90402015-01-27 01:09:43 -05004651// timeouts is the retransmit schedule for BoringSSL. It doubles and
4652// caps at 60 seconds. On the 13th timeout, it gives up.
4653var timeouts = []time.Duration{
4654 1 * time.Second,
4655 2 * time.Second,
4656 4 * time.Second,
4657 8 * time.Second,
4658 16 * time.Second,
4659 32 * time.Second,
4660 60 * time.Second,
4661 60 * time.Second,
4662 60 * time.Second,
4663 60 * time.Second,
4664 60 * time.Second,
4665 60 * time.Second,
4666 60 * time.Second,
4667}
4668
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004669// shortTimeouts is an alternate set of timeouts which would occur if the
4670// initial timeout duration was set to 250ms.
4671var shortTimeouts = []time.Duration{
4672 250 * time.Millisecond,
4673 500 * time.Millisecond,
4674 1 * time.Second,
4675 2 * time.Second,
4676 4 * time.Second,
4677 8 * time.Second,
4678 16 * time.Second,
4679 32 * time.Second,
4680 60 * time.Second,
4681 60 * time.Second,
4682 60 * time.Second,
4683 60 * time.Second,
4684 60 * time.Second,
4685}
4686
David Benjamin83f90402015-01-27 01:09:43 -05004687func addDTLSRetransmitTests() {
4688 // Test that this is indeed the timeout schedule. Stress all
4689 // four patterns of handshake.
4690 for i := 1; i < len(timeouts); i++ {
4691 number := strconv.Itoa(i)
4692 testCases = append(testCases, testCase{
4693 protocol: dtls,
4694 name: "DTLS-Retransmit-Client-" + number,
4695 config: Config{
4696 Bugs: ProtocolBugs{
4697 TimeoutSchedule: timeouts[:i],
4698 },
4699 },
4700 resumeSession: true,
4701 flags: []string{"-async"},
4702 })
4703 testCases = append(testCases, testCase{
4704 protocol: dtls,
4705 testType: serverTest,
4706 name: "DTLS-Retransmit-Server-" + number,
4707 config: Config{
4708 Bugs: ProtocolBugs{
4709 TimeoutSchedule: timeouts[:i],
4710 },
4711 },
4712 resumeSession: true,
4713 flags: []string{"-async"},
4714 })
4715 }
4716
4717 // Test that exceeding the timeout schedule hits a read
4718 // timeout.
4719 testCases = append(testCases, testCase{
4720 protocol: dtls,
4721 name: "DTLS-Retransmit-Timeout",
4722 config: Config{
4723 Bugs: ProtocolBugs{
4724 TimeoutSchedule: timeouts,
4725 },
4726 },
4727 resumeSession: true,
4728 flags: []string{"-async"},
4729 shouldFail: true,
4730 expectedError: ":READ_TIMEOUT_EXPIRED:",
4731 })
4732
4733 // Test that timeout handling has a fudge factor, due to API
4734 // problems.
4735 testCases = append(testCases, testCase{
4736 protocol: dtls,
4737 name: "DTLS-Retransmit-Fudge",
4738 config: Config{
4739 Bugs: ProtocolBugs{
4740 TimeoutSchedule: []time.Duration{
4741 timeouts[0] - 10*time.Millisecond,
4742 },
4743 },
4744 },
4745 resumeSession: true,
4746 flags: []string{"-async"},
4747 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004748
4749 // Test that the final Finished retransmitting isn't
4750 // duplicated if the peer badly fragments everything.
4751 testCases = append(testCases, testCase{
4752 testType: serverTest,
4753 protocol: dtls,
4754 name: "DTLS-Retransmit-Fragmented",
4755 config: Config{
4756 Bugs: ProtocolBugs{
4757 TimeoutSchedule: []time.Duration{timeouts[0]},
4758 MaxHandshakeRecordLength: 2,
4759 },
4760 },
4761 flags: []string{"-async"},
4762 })
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004763
4764 // Test the timeout schedule when a shorter initial timeout duration is set.
4765 testCases = append(testCases, testCase{
4766 protocol: dtls,
4767 name: "DTLS-Retransmit-Short-Client",
4768 config: Config{
4769 Bugs: ProtocolBugs{
4770 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
4771 },
4772 },
4773 resumeSession: true,
4774 flags: []string{"-async", "-initial-timeout-duration-ms", "250"},
4775 })
4776 testCases = append(testCases, testCase{
4777 protocol: dtls,
4778 testType: serverTest,
4779 name: "DTLS-Retransmit-Short-Server",
4780 config: Config{
4781 Bugs: ProtocolBugs{
4782 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
4783 },
4784 },
4785 resumeSession: true,
4786 flags: []string{"-async", "-initial-timeout-duration-ms", "250"},
4787 })
David Benjamin83f90402015-01-27 01:09:43 -05004788}
4789
David Benjaminc565ebb2015-04-03 04:06:36 -04004790func addExportKeyingMaterialTests() {
4791 for _, vers := range tlsVersions {
4792 if vers.version == VersionSSL30 {
4793 continue
4794 }
4795 testCases = append(testCases, testCase{
4796 name: "ExportKeyingMaterial-" + vers.name,
4797 config: Config{
4798 MaxVersion: vers.version,
4799 },
4800 exportKeyingMaterial: 1024,
4801 exportLabel: "label",
4802 exportContext: "context",
4803 useExportContext: true,
4804 })
4805 testCases = append(testCases, testCase{
4806 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4807 config: Config{
4808 MaxVersion: vers.version,
4809 },
4810 exportKeyingMaterial: 1024,
4811 })
4812 testCases = append(testCases, testCase{
4813 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4814 config: Config{
4815 MaxVersion: vers.version,
4816 },
4817 exportKeyingMaterial: 1024,
4818 useExportContext: true,
4819 })
4820 testCases = append(testCases, testCase{
4821 name: "ExportKeyingMaterial-Small-" + vers.name,
4822 config: Config{
4823 MaxVersion: vers.version,
4824 },
4825 exportKeyingMaterial: 1,
4826 exportLabel: "label",
4827 exportContext: "context",
4828 useExportContext: true,
4829 })
4830 }
4831 testCases = append(testCases, testCase{
4832 name: "ExportKeyingMaterial-SSL3",
4833 config: Config{
4834 MaxVersion: VersionSSL30,
4835 },
4836 exportKeyingMaterial: 1024,
4837 exportLabel: "label",
4838 exportContext: "context",
4839 useExportContext: true,
4840 shouldFail: true,
4841 expectedError: "failed to export keying material",
4842 })
4843}
4844
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004845func addTLSUniqueTests() {
4846 for _, isClient := range []bool{false, true} {
4847 for _, isResumption := range []bool{false, true} {
4848 for _, hasEMS := range []bool{false, true} {
4849 var suffix string
4850 if isResumption {
4851 suffix = "Resume-"
4852 } else {
4853 suffix = "Full-"
4854 }
4855
4856 if hasEMS {
4857 suffix += "EMS-"
4858 } else {
4859 suffix += "NoEMS-"
4860 }
4861
4862 if isClient {
4863 suffix += "Client"
4864 } else {
4865 suffix += "Server"
4866 }
4867
4868 test := testCase{
4869 name: "TLSUnique-" + suffix,
4870 testTLSUnique: true,
4871 config: Config{
4872 Bugs: ProtocolBugs{
4873 NoExtendedMasterSecret: !hasEMS,
4874 },
4875 },
4876 }
4877
4878 if isResumption {
4879 test.resumeSession = true
4880 test.resumeConfig = &Config{
4881 Bugs: ProtocolBugs{
4882 NoExtendedMasterSecret: !hasEMS,
4883 },
4884 }
4885 }
4886
4887 if isResumption && !hasEMS {
4888 test.shouldFail = true
4889 test.expectedError = "failed to get tls-unique"
4890 }
4891
4892 testCases = append(testCases, test)
4893 }
4894 }
4895 }
4896}
4897
Adam Langley09505632015-07-30 18:10:13 -07004898func addCustomExtensionTests() {
4899 expectedContents := "custom extension"
4900 emptyString := ""
4901
4902 for _, isClient := range []bool{false, true} {
4903 suffix := "Server"
4904 flag := "-enable-server-custom-extension"
4905 testType := serverTest
4906 if isClient {
4907 suffix = "Client"
4908 flag = "-enable-client-custom-extension"
4909 testType = clientTest
4910 }
4911
4912 testCases = append(testCases, testCase{
4913 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004914 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004915 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004916 Bugs: ProtocolBugs{
4917 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004918 ExpectedCustomExtension: &expectedContents,
4919 },
4920 },
4921 flags: []string{flag},
4922 })
4923
4924 // If the parse callback fails, the handshake should also fail.
4925 testCases = append(testCases, testCase{
4926 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004927 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004928 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004929 Bugs: ProtocolBugs{
4930 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004931 ExpectedCustomExtension: &expectedContents,
4932 },
4933 },
David Benjamin399e7c92015-07-30 23:01:27 -04004934 flags: []string{flag},
4935 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004936 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4937 })
4938
4939 // If the add callback fails, the handshake should also fail.
4940 testCases = append(testCases, testCase{
4941 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004942 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004943 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004944 Bugs: ProtocolBugs{
4945 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004946 ExpectedCustomExtension: &expectedContents,
4947 },
4948 },
David Benjamin399e7c92015-07-30 23:01:27 -04004949 flags: []string{flag, "-custom-extension-fail-add"},
4950 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004951 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4952 })
4953
4954 // If the add callback returns zero, no extension should be
4955 // added.
4956 skipCustomExtension := expectedContents
4957 if isClient {
4958 // For the case where the client skips sending the
4959 // custom extension, the server must not “echo” it.
4960 skipCustomExtension = ""
4961 }
4962 testCases = append(testCases, testCase{
4963 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004964 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004965 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004966 Bugs: ProtocolBugs{
4967 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004968 ExpectedCustomExtension: &emptyString,
4969 },
4970 },
4971 flags: []string{flag, "-custom-extension-skip"},
4972 })
4973 }
4974
4975 // The custom extension add callback should not be called if the client
4976 // doesn't send the extension.
4977 testCases = append(testCases, testCase{
4978 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004979 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004980 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004981 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004982 ExpectedCustomExtension: &emptyString,
4983 },
4984 },
4985 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4986 })
Adam Langley2deb9842015-08-07 11:15:37 -07004987
4988 // Test an unknown extension from the server.
4989 testCases = append(testCases, testCase{
4990 testType: clientTest,
4991 name: "UnknownExtension-Client",
4992 config: Config{
4993 Bugs: ProtocolBugs{
4994 CustomExtension: expectedContents,
4995 },
4996 },
4997 shouldFail: true,
4998 expectedError: ":UNEXPECTED_EXTENSION:",
4999 })
Adam Langley09505632015-07-30 18:10:13 -07005000}
5001
David Benjaminb36a3952015-12-01 18:53:13 -05005002func addRSAClientKeyExchangeTests() {
5003 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5004 testCases = append(testCases, testCase{
5005 testType: serverTest,
5006 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5007 config: Config{
5008 // Ensure the ClientHello version and final
5009 // version are different, to detect if the
5010 // server uses the wrong one.
5011 MaxVersion: VersionTLS11,
5012 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5013 Bugs: ProtocolBugs{
5014 BadRSAClientKeyExchange: bad,
5015 },
5016 },
5017 shouldFail: true,
5018 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5019 })
5020 }
5021}
5022
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005023var testCurves = []struct {
5024 name string
5025 id CurveID
5026}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005027 {"P-256", CurveP256},
5028 {"P-384", CurveP384},
5029 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005030 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005031}
5032
5033func addCurveTests() {
5034 for _, curve := range testCurves {
5035 testCases = append(testCases, testCase{
5036 name: "CurveTest-Client-" + curve.name,
5037 config: Config{
5038 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5039 CurvePreferences: []CurveID{curve.id},
5040 },
5041 flags: []string{"-enable-all-curves"},
5042 })
5043 testCases = append(testCases, testCase{
5044 testType: serverTest,
5045 name: "CurveTest-Server-" + curve.name,
5046 config: Config{
5047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5048 CurvePreferences: []CurveID{curve.id},
5049 },
5050 flags: []string{"-enable-all-curves"},
5051 })
5052 }
David Benjamin241ae832016-01-15 03:04:54 -05005053
5054 // The server must be tolerant to bogus curves.
5055 const bogusCurve = 0x1234
5056 testCases = append(testCases, testCase{
5057 testType: serverTest,
5058 name: "UnknownCurve",
5059 config: Config{
5060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5061 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5062 },
5063 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005064}
5065
David Benjamin4cc36ad2015-12-19 14:23:26 -05005066func addKeyExchangeInfoTests() {
5067 testCases = append(testCases, testCase{
5068 name: "KeyExchangeInfo-RSA-Client",
5069 config: Config{
5070 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5071 },
5072 // key.pem is a 1024-bit RSA key.
5073 flags: []string{"-expect-key-exchange-info", "1024"},
5074 })
5075 // TODO(davidben): key_exchange_info doesn't work for plain RSA on the
5076 // server. Either fix this or change the API as it's not very useful in
5077 // this case.
5078
5079 testCases = append(testCases, testCase{
5080 name: "KeyExchangeInfo-DHE-Client",
5081 config: Config{
5082 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5083 Bugs: ProtocolBugs{
5084 // This is a 1234-bit prime number, generated
5085 // with:
5086 // openssl gendh 1234 | openssl asn1parse -i
5087 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5088 },
5089 },
5090 flags: []string{"-expect-key-exchange-info", "1234"},
5091 })
5092 testCases = append(testCases, testCase{
5093 testType: serverTest,
5094 name: "KeyExchangeInfo-DHE-Server",
5095 config: Config{
5096 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5097 },
5098 // bssl_shim as a server configures a 2048-bit DHE group.
5099 flags: []string{"-expect-key-exchange-info", "2048"},
5100 })
5101
5102 testCases = append(testCases, testCase{
5103 name: "KeyExchangeInfo-ECDHE-Client",
5104 config: Config{
5105 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5106 CurvePreferences: []CurveID{CurveX25519},
5107 },
5108 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5109 })
5110 testCases = append(testCases, testCase{
5111 testType: serverTest,
5112 name: "KeyExchangeInfo-ECDHE-Server",
5113 config: Config{
5114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5115 CurvePreferences: []CurveID{CurveX25519},
5116 },
5117 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5118 })
5119}
5120
Adam Langley7c803a62015-06-15 15:35:05 -07005121func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005122 defer wg.Done()
5123
5124 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005125 var err error
5126
5127 if *mallocTest < 0 {
5128 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005129 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005130 } else {
5131 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5132 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005133 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005134 if err != nil {
5135 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5136 }
5137 break
5138 }
5139 }
5140 }
Adam Langley95c29f32014-06-20 12:00:00 -07005141 statusChan <- statusMsg{test: test, err: err}
5142 }
5143}
5144
5145type statusMsg struct {
5146 test *testCase
5147 started bool
5148 err error
5149}
5150
David Benjamin5f237bc2015-02-11 17:14:15 -05005151func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005152 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005153
David Benjamin5f237bc2015-02-11 17:14:15 -05005154 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005155 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005156 if !*pipe {
5157 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005158 var erase string
5159 for i := 0; i < lineLen; i++ {
5160 erase += "\b \b"
5161 }
5162 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005163 }
5164
Adam Langley95c29f32014-06-20 12:00:00 -07005165 if msg.started {
5166 started++
5167 } else {
5168 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005169
5170 if msg.err != nil {
5171 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5172 failed++
5173 testOutput.addResult(msg.test.name, "FAIL")
5174 } else {
5175 if *pipe {
5176 // Print each test instead of a status line.
5177 fmt.Printf("PASSED (%s)\n", msg.test.name)
5178 }
5179 testOutput.addResult(msg.test.name, "PASS")
5180 }
Adam Langley95c29f32014-06-20 12:00:00 -07005181 }
5182
David Benjamin5f237bc2015-02-11 17:14:15 -05005183 if !*pipe {
5184 // Print a new status line.
5185 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5186 lineLen = len(line)
5187 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005188 }
Adam Langley95c29f32014-06-20 12:00:00 -07005189 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005190
5191 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005192}
5193
5194func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005195 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005196 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005197
Adam Langley7c803a62015-06-15 15:35:05 -07005198 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005199 addCipherSuiteTests()
5200 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005201 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005202 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005203 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005204 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005205 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005206 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005207 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005208 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005209 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005210 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005211 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05005212 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05005213 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005214 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005215 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005216 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005217 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005218 addCurveTests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005219 addKeyExchangeInfoTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04005220 for _, async := range []bool{false, true} {
5221 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04005222 for _, protocol := range []protocol{tls, dtls} {
5223 addStateMachineCoverageTests(async, splitHandshake, protocol)
5224 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005225 }
5226 }
Adam Langley95c29f32014-06-20 12:00:00 -07005227
5228 var wg sync.WaitGroup
5229
Adam Langley7c803a62015-06-15 15:35:05 -07005230 statusChan := make(chan statusMsg, *numWorkers)
5231 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005232 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005233
David Benjamin025b3d32014-07-01 19:53:04 -04005234 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005235
Adam Langley7c803a62015-06-15 15:35:05 -07005236 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005237 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005238 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005239 }
5240
David Benjamin270f0a72016-03-17 14:41:36 -04005241 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005242 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005243 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005244 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005245 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005246 }
5247 }
David Benjamin270f0a72016-03-17 14:41:36 -04005248 if !foundTest {
5249 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5250 os.Exit(1)
5251 }
Adam Langley95c29f32014-06-20 12:00:00 -07005252
5253 close(testChan)
5254 wg.Wait()
5255 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005256 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005257
5258 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005259
5260 if *jsonOutput != "" {
5261 if err := testOutput.writeTo(*jsonOutput); err != nil {
5262 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5263 }
5264 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005265
5266 if !testOutput.allPassed {
5267 os.Exit(1)
5268 }
Adam Langley95c29f32014-06-20 12:00:00 -07005269}