blob: 8ea71725bce9fdef6950fd765919cf0455f9cb51 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin025b3d32014-07-01 19:53:04 -040060const (
61 rsaCertificateFile = "cert.pem"
62 ecdsaCertificateFile = "ecdsa_cert.pem"
63)
64
65const (
David Benjamina08e49d2014-08-24 01:46:07 -040066 rsaKeyFile = "key.pem"
67 ecdsaKeyFile = "ecdsa_key.pem"
68 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040069)
70
Adam Langley95c29f32014-06-20 12:00:00 -070071var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040072var channelIDKey *ecdsa.PrivateKey
73var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070074
David Benjamin61f95272014-11-25 01:55:35 -050075var testOCSPResponse = []byte{1, 2, 3, 4}
76var testSCTList = []byte{5, 6, 7, 8}
77
Adam Langley95c29f32014-06-20 12:00:00 -070078func initCertificates() {
79 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070080 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070081 if err != nil {
82 panic(err)
83 }
David Benjamin61f95272014-11-25 01:55:35 -050084 rsaCertificate.OCSPStaple = testOCSPResponse
85 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070086
Adam Langley7c803a62015-06-15 15:35:05 -070087 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070088 if err != nil {
89 panic(err)
90 }
David Benjamin61f95272014-11-25 01:55:35 -050091 ecdsaCertificate.OCSPStaple = testOCSPResponse
92 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040093
Adam Langley7c803a62015-06-15 15:35:05 -070094 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040095 if err != nil {
96 panic(err)
97 }
98 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
99 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
100 panic("bad key type")
101 }
102 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
103 if err != nil {
104 panic(err)
105 }
106 if channelIDKey.Curve != elliptic.P256() {
107 panic("bad curve")
108 }
109
110 channelIDBytes = make([]byte, 64)
111 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
112 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700113}
114
115var certificateOnce sync.Once
116
117func getRSACertificate() Certificate {
118 certificateOnce.Do(initCertificates)
119 return rsaCertificate
120}
121
122func getECDSACertificate() Certificate {
123 certificateOnce.Do(initCertificates)
124 return ecdsaCertificate
125}
126
David Benjamin025b3d32014-07-01 19:53:04 -0400127type testType int
128
129const (
130 clientTest testType = iota
131 serverTest
132)
133
David Benjamin6fd297b2014-08-11 18:43:38 -0400134type protocol int
135
136const (
137 tls protocol = iota
138 dtls
139)
140
David Benjaminfc7b0862014-09-06 13:21:53 -0400141const (
142 alpn = 1
143 npn = 2
144)
145
Adam Langley95c29f32014-06-20 12:00:00 -0700146type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400147 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400148 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700149 name string
150 config Config
151 shouldFail bool
152 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700153 // expectedLocalError, if not empty, contains a substring that must be
154 // found in the local error.
155 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400156 // expectedVersion, if non-zero, specifies the TLS version that must be
157 // negotiated.
158 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400159 // expectedResumeVersion, if non-zero, specifies the TLS version that
160 // must be negotiated on resumption. If zero, expectedVersion is used.
161 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400162 // expectedCipher, if non-zero, specifies the TLS cipher suite that
163 // should be negotiated.
164 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400165 // expectChannelID controls whether the connection should have
166 // negotiated a Channel ID with channelIDKey.
167 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400168 // expectedNextProto controls whether the connection should
169 // negotiate a next protocol via NPN or ALPN.
170 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400171 // expectNoNextProto, if true, means that no next protocol should be
172 // negotiated.
173 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400174 // expectedNextProtoType, if non-zero, is the expected next
175 // protocol negotiation mechanism.
176 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500177 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
178 // should be negotiated. If zero, none should be negotiated.
179 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100180 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
181 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100182 // expectedSCTList, if not nil, is the expected SCT list to be received.
183 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400184 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
185 // hash function that the client should have used when signing the
186 // handshake with a client certificate.
187 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700188 // messageLen is the length, in bytes, of the test message that will be
189 // sent.
190 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400191 // messageCount is the number of test messages that will be sent.
192 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400193 // digestPrefs is the list of digest preferences from the client.
194 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400195 // certFile is the path to the certificate to use for the server.
196 certFile string
197 // keyFile is the path to the private key to use for the server.
198 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400199 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400200 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400201 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700202 // expectResumeRejected, if true, specifies that the attempted
203 // resumption must be rejected by the client. This is only valid for a
204 // serverTest.
205 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400206 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500207 // resumption. Unless newSessionsOnResume is set,
208 // SessionTicketKey, ServerSessionCache, and
209 // ClientSessionCache are copied from the initial connection's
210 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400211 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500212 // newSessionsOnResume, if true, will cause resumeConfig to
213 // use a different session resumption context.
214 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400215 // noSessionCache, if true, will cause the server to run without a
216 // session cache.
217 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400218 // sendPrefix sends a prefix on the socket before actually performing a
219 // handshake.
220 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400221 // shimWritesFirst controls whether the shim sends an initial "hello"
222 // message before doing a roundtrip with the runner.
223 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400224 // shimShutsDown, if true, runs a test where the shim shuts down the
225 // connection immediately after the handshake rather than echoing
226 // messages from the runner.
227 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400228 // renegotiate indicates the number of times the connection should be
229 // renegotiated during the exchange.
230 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700231 // renegotiateCiphers is a list of ciphersuite ids that will be
232 // switched in just before renegotiation.
233 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500234 // replayWrites, if true, configures the underlying transport
235 // to replay every write it makes in DTLS tests.
236 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500237 // damageFirstWrite, if true, configures the underlying transport to
238 // damage the final byte of the first application data write.
239 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400240 // exportKeyingMaterial, if non-zero, configures the test to exchange
241 // keying material and verify they match.
242 exportKeyingMaterial int
243 exportLabel string
244 exportContext string
245 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400246 // flags, if not empty, contains a list of command-line flags that will
247 // be passed to the shim program.
248 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700249 // testTLSUnique, if true, causes the shim to send the tls-unique value
250 // which will be compared against the expected value.
251 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400252 // sendEmptyRecords is the number of consecutive empty records to send
253 // before and after the test message.
254 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400255 // sendWarningAlerts is the number of consecutive warning alerts to send
256 // before and after the test message.
257 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400258 // expectMessageDropped, if true, means the test message is expected to
259 // be dropped by the client rather than echoed back.
260 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700261}
262
Adam Langley7c803a62015-06-15 15:35:05 -0700263var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700264
David Benjamin9867b7d2016-03-01 23:25:48 -0500265func writeTranscript(test *testCase, isResume bool, data []byte) {
266 if len(data) == 0 {
267 return
268 }
269
270 protocol := "tls"
271 if test.protocol == dtls {
272 protocol = "dtls"
273 }
274
275 side := "client"
276 if test.testType == serverTest {
277 side = "server"
278 }
279
280 dir := path.Join(*transcriptDir, protocol, side)
281 if err := os.MkdirAll(dir, 0755); err != nil {
282 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
283 return
284 }
285
286 name := test.name
287 if isResume {
288 name += "-Resume"
289 } else {
290 name += "-Normal"
291 }
292
293 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
294 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
295 }
296}
297
David Benjamin3ed59772016-03-08 12:50:21 -0500298// A timeoutConn implements an idle timeout on each Read and Write operation.
299type timeoutConn struct {
300 net.Conn
301 timeout time.Duration
302}
303
304func (t *timeoutConn) Read(b []byte) (int, error) {
305 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
306 return 0, err
307 }
308 return t.Conn.Read(b)
309}
310
311func (t *timeoutConn) Write(b []byte) (int, error) {
312 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
313 return 0, err
314 }
315 return t.Conn.Write(b)
316}
317
David Benjamin8e6db492015-07-25 18:29:23 -0400318func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400319 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500320
David Benjamin6fd297b2014-08-11 18:43:38 -0400321 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500322 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
323 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500324 }
325
David Benjamin9867b7d2016-03-01 23:25:48 -0500326 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500327 local, peer := "client", "server"
328 if test.testType == clientTest {
329 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500330 }
David Benjaminebda9b32015-11-02 15:33:18 -0500331 connDebug := &recordingConn{
332 Conn: conn,
333 isDatagram: test.protocol == dtls,
334 local: local,
335 peer: peer,
336 }
337 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500338 if *flagDebug {
339 defer connDebug.WriteTo(os.Stdout)
340 }
341 if len(*transcriptDir) != 0 {
342 defer func() {
343 writeTranscript(test, isResume, connDebug.Transcript())
344 }()
345 }
David Benjaminebda9b32015-11-02 15:33:18 -0500346
347 if config.Bugs.PacketAdaptor != nil {
348 config.Bugs.PacketAdaptor.debug = connDebug
349 }
350 }
351
352 if test.replayWrites {
353 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400354 }
355
David Benjamin3ed59772016-03-08 12:50:21 -0500356 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500357 if test.damageFirstWrite {
358 connDamage = newDamageAdaptor(conn)
359 conn = connDamage
360 }
361
David Benjamin6fd297b2014-08-11 18:43:38 -0400362 if test.sendPrefix != "" {
363 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
364 return err
365 }
David Benjamin98e882e2014-08-08 13:24:34 -0400366 }
367
David Benjamin1d5c83e2014-07-22 19:20:02 -0400368 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400369 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400370 if test.protocol == dtls {
371 tlsConn = DTLSServer(conn, config)
372 } else {
373 tlsConn = Server(conn, config)
374 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400375 } else {
376 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400377 if test.protocol == dtls {
378 tlsConn = DTLSClient(conn, config)
379 } else {
380 tlsConn = Client(conn, config)
381 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400382 }
David Benjamin30789da2015-08-29 22:56:45 -0400383 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400384
Adam Langley95c29f32014-06-20 12:00:00 -0700385 if err := tlsConn.Handshake(); err != nil {
386 return err
387 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700388
David Benjamin01fe8202014-09-24 15:21:44 -0400389 // TODO(davidben): move all per-connection expectations into a dedicated
390 // expectations struct that can be specified separately for the two
391 // legs.
392 expectedVersion := test.expectedVersion
393 if isResume && test.expectedResumeVersion != 0 {
394 expectedVersion = test.expectedResumeVersion
395 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700396 connState := tlsConn.ConnectionState()
397 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400398 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400399 }
400
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700401 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400402 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
403 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700404 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
405 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
406 }
David Benjamin90da8c82015-04-20 14:57:57 -0400407
David Benjamina08e49d2014-08-24 01:46:07 -0400408 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700409 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400410 if channelID == nil {
411 return fmt.Errorf("no channel ID negotiated")
412 }
413 if channelID.Curve != channelIDKey.Curve ||
414 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
415 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
416 return fmt.Errorf("incorrect channel ID")
417 }
418 }
419
David Benjaminae2888f2014-09-06 12:58:58 -0400420 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700421 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400422 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
423 }
424 }
425
David Benjaminc7ce9772015-10-09 19:32:41 -0400426 if test.expectNoNextProto {
427 if actual := connState.NegotiatedProtocol; actual != "" {
428 return fmt.Errorf("got unexpected next proto %s", actual)
429 }
430 }
431
David Benjaminfc7b0862014-09-06 13:21:53 -0400432 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700433 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400434 return fmt.Errorf("next proto type mismatch")
435 }
436 }
437
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700438 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500439 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
440 }
441
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100442 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
443 return fmt.Errorf("OCSP Response mismatch")
444 }
445
Paul Lietar4fac72e2015-09-09 13:44:55 +0100446 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
447 return fmt.Errorf("SCT list mismatch")
448 }
449
Steven Valdez0d62f262015-09-04 12:41:04 -0400450 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
451 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
452 }
453
David Benjaminc565ebb2015-04-03 04:06:36 -0400454 if test.exportKeyingMaterial > 0 {
455 actual := make([]byte, test.exportKeyingMaterial)
456 if _, err := io.ReadFull(tlsConn, actual); err != nil {
457 return err
458 }
459 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
460 if err != nil {
461 return err
462 }
463 if !bytes.Equal(actual, expected) {
464 return fmt.Errorf("keying material mismatch")
465 }
466 }
467
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700468 if test.testTLSUnique {
469 var peersValue [12]byte
470 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
471 return err
472 }
473 expected := tlsConn.ConnectionState().TLSUnique
474 if !bytes.Equal(peersValue[:], expected) {
475 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
476 }
477 }
478
David Benjamine58c4f52014-08-24 03:47:07 -0400479 if test.shimWritesFirst {
480 var buf [5]byte
481 _, err := io.ReadFull(tlsConn, buf[:])
482 if err != nil {
483 return err
484 }
485 if string(buf[:]) != "hello" {
486 return fmt.Errorf("bad initial message")
487 }
488 }
489
David Benjamina8ebe222015-06-06 03:04:39 -0400490 for i := 0; i < test.sendEmptyRecords; i++ {
491 tlsConn.Write(nil)
492 }
493
David Benjamin24f346d2015-06-06 03:28:08 -0400494 for i := 0; i < test.sendWarningAlerts; i++ {
495 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
496 }
497
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400498 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700499 if test.renegotiateCiphers != nil {
500 config.CipherSuites = test.renegotiateCiphers
501 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400502 for i := 0; i < test.renegotiate; i++ {
503 if err := tlsConn.Renegotiate(); err != nil {
504 return err
505 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700506 }
507 } else if test.renegotiateCiphers != nil {
508 panic("renegotiateCiphers without renegotiate")
509 }
510
David Benjamin5fa3eba2015-01-22 16:35:40 -0500511 if test.damageFirstWrite {
512 connDamage.setDamage(true)
513 tlsConn.Write([]byte("DAMAGED WRITE"))
514 connDamage.setDamage(false)
515 }
516
David Benjamin8e6db492015-07-25 18:29:23 -0400517 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700518 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400519 if test.protocol == dtls {
520 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
521 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700522 // Read until EOF.
523 _, err := io.Copy(ioutil.Discard, tlsConn)
524 return err
525 }
David Benjamin4417d052015-04-05 04:17:25 -0400526 if messageLen == 0 {
527 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700528 }
Adam Langley95c29f32014-06-20 12:00:00 -0700529
David Benjamin8e6db492015-07-25 18:29:23 -0400530 messageCount := test.messageCount
531 if messageCount == 0 {
532 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400533 }
534
David Benjamin8e6db492015-07-25 18:29:23 -0400535 for j := 0; j < messageCount; j++ {
536 testMessage := make([]byte, messageLen)
537 for i := range testMessage {
538 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400539 }
David Benjamin8e6db492015-07-25 18:29:23 -0400540 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700541
David Benjamin8e6db492015-07-25 18:29:23 -0400542 for i := 0; i < test.sendEmptyRecords; i++ {
543 tlsConn.Write(nil)
544 }
545
546 for i := 0; i < test.sendWarningAlerts; i++ {
547 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
548 }
549
David Benjamin4f75aaf2015-09-01 16:53:10 -0400550 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400551 // The shim will not respond.
552 continue
553 }
554
David Benjamin8e6db492015-07-25 18:29:23 -0400555 buf := make([]byte, len(testMessage))
556 if test.protocol == dtls {
557 bufTmp := make([]byte, len(buf)+1)
558 n, err := tlsConn.Read(bufTmp)
559 if err != nil {
560 return err
561 }
562 if n != len(buf) {
563 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
564 }
565 copy(buf, bufTmp)
566 } else {
567 _, err := io.ReadFull(tlsConn, buf)
568 if err != nil {
569 return err
570 }
571 }
572
573 for i, v := range buf {
574 if v != testMessage[i]^0xff {
575 return fmt.Errorf("bad reply contents at byte %d", i)
576 }
Adam Langley95c29f32014-06-20 12:00:00 -0700577 }
578 }
579
580 return nil
581}
582
David Benjamin325b5c32014-07-01 19:40:31 -0400583func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
584 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700585 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400586 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700587 }
David Benjamin325b5c32014-07-01 19:40:31 -0400588 valgrindArgs = append(valgrindArgs, path)
589 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700590
David Benjamin325b5c32014-07-01 19:40:31 -0400591 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700592}
593
David Benjamin325b5c32014-07-01 19:40:31 -0400594func gdbOf(path string, args ...string) *exec.Cmd {
595 xtermArgs := []string{"-e", "gdb", "--args"}
596 xtermArgs = append(xtermArgs, path)
597 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700598
David Benjamin325b5c32014-07-01 19:40:31 -0400599 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700600}
601
David Benjamind16bf342015-12-18 00:53:12 -0500602func lldbOf(path string, args ...string) *exec.Cmd {
603 xtermArgs := []string{"-e", "lldb", "--"}
604 xtermArgs = append(xtermArgs, path)
605 xtermArgs = append(xtermArgs, args...)
606
607 return exec.Command("xterm", xtermArgs...)
608}
609
Adam Langley69a01602014-11-17 17:26:55 -0800610type moreMallocsError struct{}
611
612func (moreMallocsError) Error() string {
613 return "child process did not exhaust all allocation calls"
614}
615
616var errMoreMallocs = moreMallocsError{}
617
David Benjamin87c8a642015-02-21 01:54:29 -0500618// accept accepts a connection from listener, unless waitChan signals a process
619// exit first.
620func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
621 type connOrError struct {
622 conn net.Conn
623 err error
624 }
625 connChan := make(chan connOrError, 1)
626 go func() {
627 conn, err := listener.Accept()
628 connChan <- connOrError{conn, err}
629 close(connChan)
630 }()
631 select {
632 case result := <-connChan:
633 return result.conn, result.err
634 case childErr := <-waitChan:
635 waitChan <- childErr
636 return nil, fmt.Errorf("child exited early: %s", childErr)
637 }
638}
639
Adam Langley7c803a62015-06-15 15:35:05 -0700640func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700641 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
642 panic("Error expected without shouldFail in " + test.name)
643 }
644
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700645 if test.expectResumeRejected && !test.resumeSession {
646 panic("expectResumeRejected without resumeSession in " + test.name)
647 }
648
Steven Valdez0d62f262015-09-04 12:41:04 -0400649 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
650 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
651 }
652
David Benjamin87c8a642015-02-21 01:54:29 -0500653 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
654 if err != nil {
655 panic(err)
656 }
657 defer func() {
658 if listener != nil {
659 listener.Close()
660 }
661 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700662
David Benjamin87c8a642015-02-21 01:54:29 -0500663 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400664 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400665 flags = append(flags, "-server")
666
David Benjamin025b3d32014-07-01 19:53:04 -0400667 flags = append(flags, "-key-file")
668 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700669 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400670 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700671 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400672 }
673
674 flags = append(flags, "-cert-file")
675 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700676 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400677 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700678 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400679 }
680 }
David Benjamin5a593af2014-08-11 19:51:50 -0400681
Steven Valdez0d62f262015-09-04 12:41:04 -0400682 if test.digestPrefs != "" {
683 flags = append(flags, "-digest-prefs")
684 flags = append(flags, test.digestPrefs)
685 }
686
David Benjamin6fd297b2014-08-11 18:43:38 -0400687 if test.protocol == dtls {
688 flags = append(flags, "-dtls")
689 }
690
David Benjamin5a593af2014-08-11 19:51:50 -0400691 if test.resumeSession {
692 flags = append(flags, "-resume")
693 }
694
David Benjamine58c4f52014-08-24 03:47:07 -0400695 if test.shimWritesFirst {
696 flags = append(flags, "-shim-writes-first")
697 }
698
David Benjamin30789da2015-08-29 22:56:45 -0400699 if test.shimShutsDown {
700 flags = append(flags, "-shim-shuts-down")
701 }
702
David Benjaminc565ebb2015-04-03 04:06:36 -0400703 if test.exportKeyingMaterial > 0 {
704 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
705 flags = append(flags, "-export-label", test.exportLabel)
706 flags = append(flags, "-export-context", test.exportContext)
707 if test.useExportContext {
708 flags = append(flags, "-use-export-context")
709 }
710 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700711 if test.expectResumeRejected {
712 flags = append(flags, "-expect-session-miss")
713 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400714
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700715 if test.testTLSUnique {
716 flags = append(flags, "-tls-unique")
717 }
718
David Benjamin025b3d32014-07-01 19:53:04 -0400719 flags = append(flags, test.flags...)
720
721 var shim *exec.Cmd
722 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700723 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700724 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700725 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500726 } else if *useLLDB {
727 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400728 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700729 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400730 }
David Benjamin025b3d32014-07-01 19:53:04 -0400731 shim.Stdin = os.Stdin
732 var stdoutBuf, stderrBuf bytes.Buffer
733 shim.Stdout = &stdoutBuf
734 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800735 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500736 shim.Env = os.Environ()
737 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800738 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400739 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800740 }
741 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
742 }
David Benjamin025b3d32014-07-01 19:53:04 -0400743
744 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700745 panic(err)
746 }
David Benjamin87c8a642015-02-21 01:54:29 -0500747 waitChan := make(chan error, 1)
748 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700749
750 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400751 if !test.noSessionCache {
752 config.ClientSessionCache = NewLRUClientSessionCache(1)
753 config.ServerSessionCache = NewLRUServerSessionCache(1)
754 }
David Benjamin025b3d32014-07-01 19:53:04 -0400755 if test.testType == clientTest {
756 if len(config.Certificates) == 0 {
757 config.Certificates = []Certificate{getRSACertificate()}
758 }
David Benjamin87c8a642015-02-21 01:54:29 -0500759 } else {
760 // Supply a ServerName to ensure a constant session cache key,
761 // rather than falling back to net.Conn.RemoteAddr.
762 if len(config.ServerName) == 0 {
763 config.ServerName = "test"
764 }
David Benjamin025b3d32014-07-01 19:53:04 -0400765 }
David Benjaminf2b83632016-03-01 22:57:46 -0500766 if *fuzzer {
767 config.Bugs.NullAllCiphers = true
768 }
David Benjamin2e045a92016-06-08 13:09:56 -0400769 if *deterministic {
770 config.Rand = &deterministicRand{}
771 }
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin87c8a642015-02-21 01:54:29 -0500773 conn, err := acceptOrWait(listener, waitChan)
774 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400775 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500776 conn.Close()
777 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500778
David Benjamin1d5c83e2014-07-22 19:20:02 -0400779 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400780 var resumeConfig Config
781 if test.resumeConfig != nil {
782 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500783 if len(resumeConfig.ServerName) == 0 {
784 resumeConfig.ServerName = config.ServerName
785 }
David Benjamin01fe8202014-09-24 15:21:44 -0400786 if len(resumeConfig.Certificates) == 0 {
787 resumeConfig.Certificates = []Certificate{getRSACertificate()}
788 }
David Benjaminba4594a2015-06-18 18:36:15 -0400789 if test.newSessionsOnResume {
790 if !test.noSessionCache {
791 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
792 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
793 }
794 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500795 resumeConfig.SessionTicketKey = config.SessionTicketKey
796 resumeConfig.ClientSessionCache = config.ClientSessionCache
797 resumeConfig.ServerSessionCache = config.ServerSessionCache
798 }
David Benjaminf2b83632016-03-01 22:57:46 -0500799 if *fuzzer {
800 resumeConfig.Bugs.NullAllCiphers = true
801 }
David Benjamin2e045a92016-06-08 13:09:56 -0400802 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400803 } else {
804 resumeConfig = config
805 }
David Benjamin87c8a642015-02-21 01:54:29 -0500806 var connResume net.Conn
807 connResume, err = acceptOrWait(listener, waitChan)
808 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400809 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500810 connResume.Close()
811 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400812 }
813
David Benjamin87c8a642015-02-21 01:54:29 -0500814 // Close the listener now. This is to avoid hangs should the shim try to
815 // open more connections than expected.
816 listener.Close()
817 listener = nil
818
819 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800820 if exitError, ok := childErr.(*exec.ExitError); ok {
821 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
822 return errMoreMallocs
823 }
824 }
Adam Langley95c29f32014-06-20 12:00:00 -0700825
David Benjamin9bea3492016-03-02 10:59:16 -0500826 // Account for Windows line endings.
827 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
828 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500829
830 // Separate the errors from the shim and those from tools like
831 // AddressSanitizer.
832 var extraStderr string
833 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
834 stderr = stderrParts[0]
835 extraStderr = stderrParts[1]
836 }
837
Adam Langley95c29f32014-06-20 12:00:00 -0700838 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400839 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700840 localError := "none"
841 if err != nil {
842 localError = err.Error()
843 }
844 if len(test.expectedLocalError) != 0 {
845 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
846 }
Adam Langley95c29f32014-06-20 12:00:00 -0700847
848 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700849 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700850 if childErr != nil {
851 childError = childErr.Error()
852 }
853
854 var msg string
855 switch {
856 case failed && !test.shouldFail:
857 msg = "unexpected failure"
858 case !failed && test.shouldFail:
859 msg = "unexpected success"
860 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700861 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700862 default:
863 panic("internal error")
864 }
865
David Benjaminc565ebb2015-04-03 04:06:36 -0400866 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 -0700867 }
868
David Benjaminff3a1492016-03-02 10:12:06 -0500869 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
870 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700871 }
872
873 return nil
874}
875
876var tlsVersions = []struct {
877 name string
878 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400879 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500880 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700881}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500882 {"SSL3", VersionSSL30, "-no-ssl3", false},
883 {"TLS1", VersionTLS10, "-no-tls1", true},
884 {"TLS11", VersionTLS11, "-no-tls11", false},
885 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700886}
887
888var testCipherSuites = []struct {
889 name string
890 id uint16
891}{
892 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400893 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700894 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400895 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400896 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700897 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400898 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400899 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
900 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400901 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400902 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
903 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400904 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700905 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
906 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400907 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
908 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700909 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400910 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500911 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500912 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700913 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700914 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700915 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400916 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400917 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700918 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400919 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500920 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500921 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700922 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700923 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
924 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
925 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
926 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400927 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
928 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700929 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
930 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500931 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400932 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
933 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400934 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700935 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400936 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700937 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700938}
939
David Benjamin8b8c0062014-11-23 02:47:52 -0500940func hasComponent(suiteName, component string) bool {
941 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
942}
943
David Benjamin4298d772015-12-19 00:18:25 -0500944func isTLSOnly(suiteName string) bool {
945 // BoringSSL doesn't support ECDHE without a curves extension, and
946 // SSLv3 doesn't contain extensions.
947 return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName)
948}
949
David Benjaminf7768e42014-08-31 02:06:47 -0400950func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500951 return hasComponent(suiteName, "GCM") ||
952 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400953 hasComponent(suiteName, "SHA384") ||
954 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500955}
956
957func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700958 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400959}
960
Adam Langleya7997f12015-05-14 17:38:50 -0700961func bigFromHex(hex string) *big.Int {
962 ret, ok := new(big.Int).SetString(hex, 16)
963 if !ok {
964 panic("failed to parse hex number 0x" + hex)
965 }
966 return ret
967}
968
Adam Langley7c803a62015-06-15 15:35:05 -0700969func addBasicTests() {
970 basicTests := []testCase{
971 {
972 name: "BadRSASignature",
973 config: Config{
974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
975 Bugs: ProtocolBugs{
976 InvalidSKXSignature: true,
977 },
978 },
979 shouldFail: true,
980 expectedError: ":BAD_SIGNATURE:",
981 },
982 {
983 name: "BadECDSASignature",
984 config: Config{
985 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
986 Bugs: ProtocolBugs{
987 InvalidSKXSignature: true,
988 },
989 Certificates: []Certificate{getECDSACertificate()},
990 },
991 shouldFail: true,
992 expectedError: ":BAD_SIGNATURE:",
993 },
994 {
David Benjamin6de0e532015-07-28 22:43:19 -0400995 testType: serverTest,
996 name: "BadRSASignature-ClientAuth",
997 config: Config{
998 Bugs: ProtocolBugs{
999 InvalidCertVerifySignature: true,
1000 },
1001 Certificates: []Certificate{getRSACertificate()},
1002 },
1003 shouldFail: true,
1004 expectedError: ":BAD_SIGNATURE:",
1005 flags: []string{"-require-any-client-certificate"},
1006 },
1007 {
1008 testType: serverTest,
1009 name: "BadECDSASignature-ClientAuth",
1010 config: Config{
1011 Bugs: ProtocolBugs{
1012 InvalidCertVerifySignature: true,
1013 },
1014 Certificates: []Certificate{getECDSACertificate()},
1015 },
1016 shouldFail: true,
1017 expectedError: ":BAD_SIGNATURE:",
1018 flags: []string{"-require-any-client-certificate"},
1019 },
1020 {
Adam Langley7c803a62015-06-15 15:35:05 -07001021 name: "BadECDSACurve",
1022 config: Config{
1023 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1024 Bugs: ProtocolBugs{
1025 InvalidSKXCurve: true,
1026 },
1027 Certificates: []Certificate{getECDSACertificate()},
1028 },
1029 shouldFail: true,
1030 expectedError: ":WRONG_CURVE:",
1031 },
1032 {
Adam Langley7c803a62015-06-15 15:35:05 -07001033 name: "NoFallbackSCSV",
1034 config: Config{
1035 Bugs: ProtocolBugs{
1036 FailIfNotFallbackSCSV: true,
1037 },
1038 },
1039 shouldFail: true,
1040 expectedLocalError: "no fallback SCSV found",
1041 },
1042 {
1043 name: "SendFallbackSCSV",
1044 config: Config{
1045 Bugs: ProtocolBugs{
1046 FailIfNotFallbackSCSV: true,
1047 },
1048 },
1049 flags: []string{"-fallback-scsv"},
1050 },
1051 {
1052 name: "ClientCertificateTypes",
1053 config: Config{
1054 ClientAuth: RequestClientCert,
1055 ClientCertificateTypes: []byte{
1056 CertTypeDSSSign,
1057 CertTypeRSASign,
1058 CertTypeECDSASign,
1059 },
1060 },
1061 flags: []string{
1062 "-expect-certificate-types",
1063 base64.StdEncoding.EncodeToString([]byte{
1064 CertTypeDSSSign,
1065 CertTypeRSASign,
1066 CertTypeECDSASign,
1067 }),
1068 },
1069 },
1070 {
1071 name: "NoClientCertificate",
1072 config: Config{
1073 ClientAuth: RequireAnyClientCert,
1074 },
1075 shouldFail: true,
1076 expectedLocalError: "client didn't provide a certificate",
1077 },
1078 {
1079 name: "UnauthenticatedECDH",
1080 config: Config{
1081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1082 Bugs: ProtocolBugs{
1083 UnauthenticatedECDH: true,
1084 },
1085 },
1086 shouldFail: true,
1087 expectedError: ":UNEXPECTED_MESSAGE:",
1088 },
1089 {
1090 name: "SkipCertificateStatus",
1091 config: Config{
1092 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1093 Bugs: ProtocolBugs{
1094 SkipCertificateStatus: true,
1095 },
1096 },
1097 flags: []string{
1098 "-enable-ocsp-stapling",
1099 },
1100 },
1101 {
1102 name: "SkipServerKeyExchange",
1103 config: Config{
1104 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1105 Bugs: ProtocolBugs{
1106 SkipServerKeyExchange: true,
1107 },
1108 },
1109 shouldFail: true,
1110 expectedError: ":UNEXPECTED_MESSAGE:",
1111 },
1112 {
1113 name: "SkipChangeCipherSpec-Client",
1114 config: Config{
1115 Bugs: ProtocolBugs{
1116 SkipChangeCipherSpec: true,
1117 },
1118 },
1119 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001120 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001121 },
1122 {
1123 testType: serverTest,
1124 name: "SkipChangeCipherSpec-Server",
1125 config: Config{
1126 Bugs: ProtocolBugs{
1127 SkipChangeCipherSpec: true,
1128 },
1129 },
1130 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001131 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001132 },
1133 {
1134 testType: serverTest,
1135 name: "SkipChangeCipherSpec-Server-NPN",
1136 config: Config{
1137 NextProtos: []string{"bar"},
1138 Bugs: ProtocolBugs{
1139 SkipChangeCipherSpec: true,
1140 },
1141 },
1142 flags: []string{
1143 "-advertise-npn", "\x03foo\x03bar\x03baz",
1144 },
1145 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001146 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001147 },
1148 {
1149 name: "FragmentAcrossChangeCipherSpec-Client",
1150 config: Config{
1151 Bugs: ProtocolBugs{
1152 FragmentAcrossChangeCipherSpec: true,
1153 },
1154 },
1155 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001156 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001157 },
1158 {
1159 testType: serverTest,
1160 name: "FragmentAcrossChangeCipherSpec-Server",
1161 config: Config{
1162 Bugs: ProtocolBugs{
1163 FragmentAcrossChangeCipherSpec: true,
1164 },
1165 },
1166 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001167 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001168 },
1169 {
1170 testType: serverTest,
1171 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1172 config: Config{
1173 NextProtos: []string{"bar"},
1174 Bugs: ProtocolBugs{
1175 FragmentAcrossChangeCipherSpec: true,
1176 },
1177 },
1178 flags: []string{
1179 "-advertise-npn", "\x03foo\x03bar\x03baz",
1180 },
1181 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001182 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001183 },
1184 {
1185 testType: serverTest,
1186 name: "Alert",
1187 config: Config{
1188 Bugs: ProtocolBugs{
1189 SendSpuriousAlert: alertRecordOverflow,
1190 },
1191 },
1192 shouldFail: true,
1193 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1194 },
1195 {
1196 protocol: dtls,
1197 testType: serverTest,
1198 name: "Alert-DTLS",
1199 config: Config{
1200 Bugs: ProtocolBugs{
1201 SendSpuriousAlert: alertRecordOverflow,
1202 },
1203 },
1204 shouldFail: true,
1205 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1206 },
1207 {
1208 testType: serverTest,
1209 name: "FragmentAlert",
1210 config: Config{
1211 Bugs: ProtocolBugs{
1212 FragmentAlert: true,
1213 SendSpuriousAlert: alertRecordOverflow,
1214 },
1215 },
1216 shouldFail: true,
1217 expectedError: ":BAD_ALERT:",
1218 },
1219 {
1220 protocol: dtls,
1221 testType: serverTest,
1222 name: "FragmentAlert-DTLS",
1223 config: Config{
1224 Bugs: ProtocolBugs{
1225 FragmentAlert: true,
1226 SendSpuriousAlert: alertRecordOverflow,
1227 },
1228 },
1229 shouldFail: true,
1230 expectedError: ":BAD_ALERT:",
1231 },
1232 {
1233 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001234 name: "DoubleAlert",
1235 config: Config{
1236 Bugs: ProtocolBugs{
1237 DoubleAlert: true,
1238 SendSpuriousAlert: alertRecordOverflow,
1239 },
1240 },
1241 shouldFail: true,
1242 expectedError: ":BAD_ALERT:",
1243 },
1244 {
1245 protocol: dtls,
1246 testType: serverTest,
1247 name: "DoubleAlert-DTLS",
1248 config: Config{
1249 Bugs: ProtocolBugs{
1250 DoubleAlert: true,
1251 SendSpuriousAlert: alertRecordOverflow,
1252 },
1253 },
1254 shouldFail: true,
1255 expectedError: ":BAD_ALERT:",
1256 },
1257 {
1258 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001259 name: "EarlyChangeCipherSpec-server-1",
1260 config: Config{
1261 Bugs: ProtocolBugs{
1262 EarlyChangeCipherSpec: 1,
1263 },
1264 },
1265 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001266 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001267 },
1268 {
1269 testType: serverTest,
1270 name: "EarlyChangeCipherSpec-server-2",
1271 config: Config{
1272 Bugs: ProtocolBugs{
1273 EarlyChangeCipherSpec: 2,
1274 },
1275 },
1276 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001277 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001278 },
1279 {
1280 name: "SkipNewSessionTicket",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 SkipNewSessionTicket: true,
1284 },
1285 },
1286 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001287 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001288 },
1289 {
1290 testType: serverTest,
1291 name: "FallbackSCSV",
1292 config: Config{
1293 MaxVersion: VersionTLS11,
1294 Bugs: ProtocolBugs{
1295 SendFallbackSCSV: true,
1296 },
1297 },
1298 shouldFail: true,
1299 expectedError: ":INAPPROPRIATE_FALLBACK:",
1300 },
1301 {
1302 testType: serverTest,
1303 name: "FallbackSCSV-VersionMatch",
1304 config: Config{
1305 Bugs: ProtocolBugs{
1306 SendFallbackSCSV: true,
1307 },
1308 },
1309 },
1310 {
1311 testType: serverTest,
1312 name: "FragmentedClientVersion",
1313 config: Config{
1314 Bugs: ProtocolBugs{
1315 MaxHandshakeRecordLength: 1,
1316 FragmentClientVersion: true,
1317 },
1318 },
1319 expectedVersion: VersionTLS12,
1320 },
1321 {
1322 testType: serverTest,
1323 name: "MinorVersionTolerance",
1324 config: Config{
1325 Bugs: ProtocolBugs{
1326 SendClientVersion: 0x03ff,
1327 },
1328 },
1329 expectedVersion: VersionTLS12,
1330 },
1331 {
1332 testType: serverTest,
1333 name: "MajorVersionTolerance",
1334 config: Config{
1335 Bugs: ProtocolBugs{
1336 SendClientVersion: 0x0400,
1337 },
1338 },
1339 expectedVersion: VersionTLS12,
1340 },
1341 {
1342 testType: serverTest,
1343 name: "VersionTooLow",
1344 config: Config{
1345 Bugs: ProtocolBugs{
1346 SendClientVersion: 0x0200,
1347 },
1348 },
1349 shouldFail: true,
1350 expectedError: ":UNSUPPORTED_PROTOCOL:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "HttpGET",
1355 sendPrefix: "GET / HTTP/1.0\n",
1356 shouldFail: true,
1357 expectedError: ":HTTP_REQUEST:",
1358 },
1359 {
1360 testType: serverTest,
1361 name: "HttpPOST",
1362 sendPrefix: "POST / HTTP/1.0\n",
1363 shouldFail: true,
1364 expectedError: ":HTTP_REQUEST:",
1365 },
1366 {
1367 testType: serverTest,
1368 name: "HttpHEAD",
1369 sendPrefix: "HEAD / HTTP/1.0\n",
1370 shouldFail: true,
1371 expectedError: ":HTTP_REQUEST:",
1372 },
1373 {
1374 testType: serverTest,
1375 name: "HttpPUT",
1376 sendPrefix: "PUT / HTTP/1.0\n",
1377 shouldFail: true,
1378 expectedError: ":HTTP_REQUEST:",
1379 },
1380 {
1381 testType: serverTest,
1382 name: "HttpCONNECT",
1383 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1384 shouldFail: true,
1385 expectedError: ":HTTPS_PROXY_REQUEST:",
1386 },
1387 {
1388 testType: serverTest,
1389 name: "Garbage",
1390 sendPrefix: "blah",
1391 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001392 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001393 },
1394 {
1395 name: "SkipCipherVersionCheck",
1396 config: Config{
1397 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1398 MaxVersion: VersionTLS11,
1399 Bugs: ProtocolBugs{
1400 SkipCipherVersionCheck: true,
1401 },
1402 },
1403 shouldFail: true,
1404 expectedError: ":WRONG_CIPHER_RETURNED:",
1405 },
1406 {
1407 name: "RSAEphemeralKey",
1408 config: Config{
1409 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1410 Bugs: ProtocolBugs{
1411 RSAEphemeralKey: true,
1412 },
1413 },
1414 shouldFail: true,
1415 expectedError: ":UNEXPECTED_MESSAGE:",
1416 },
1417 {
1418 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001419 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001420 shouldFail: true,
1421 expectedError: ":WRONG_SSL_VERSION:",
1422 },
1423 {
1424 protocol: dtls,
1425 name: "DisableEverything-DTLS",
1426 flags: []string{"-no-tls12", "-no-tls1"},
1427 shouldFail: true,
1428 expectedError: ":WRONG_SSL_VERSION:",
1429 },
1430 {
1431 name: "NoSharedCipher",
1432 config: Config{
1433 CipherSuites: []uint16{},
1434 },
1435 shouldFail: true,
1436 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1437 },
1438 {
1439 protocol: dtls,
1440 testType: serverTest,
1441 name: "MTU",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 MaxPacketLength: 256,
1445 },
1446 },
1447 flags: []string{"-mtu", "256"},
1448 },
1449 {
1450 protocol: dtls,
1451 testType: serverTest,
1452 name: "MTUExceeded",
1453 config: Config{
1454 Bugs: ProtocolBugs{
1455 MaxPacketLength: 255,
1456 },
1457 },
1458 flags: []string{"-mtu", "256"},
1459 shouldFail: true,
1460 expectedLocalError: "dtls: exceeded maximum packet length",
1461 },
1462 {
1463 name: "CertMismatchRSA",
1464 config: Config{
1465 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1466 Certificates: []Certificate{getECDSACertificate()},
1467 Bugs: ProtocolBugs{
1468 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1473 },
1474 {
1475 name: "CertMismatchECDSA",
1476 config: Config{
1477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1478 Certificates: []Certificate{getRSACertificate()},
1479 Bugs: ProtocolBugs{
1480 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1485 },
1486 {
1487 name: "EmptyCertificateList",
1488 config: Config{
1489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1490 Bugs: ProtocolBugs{
1491 EmptyCertificateList: true,
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":DECODE_ERROR:",
1496 },
1497 {
1498 name: "TLSFatalBadPackets",
1499 damageFirstWrite: true,
1500 shouldFail: true,
1501 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1502 },
1503 {
1504 protocol: dtls,
1505 name: "DTLSIgnoreBadPackets",
1506 damageFirstWrite: true,
1507 },
1508 {
1509 protocol: dtls,
1510 name: "DTLSIgnoreBadPackets-Async",
1511 damageFirstWrite: true,
1512 flags: []string{"-async"},
1513 },
1514 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001515 name: "AppDataBeforeHandshake",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":UNEXPECTED_RECORD:",
1523 },
1524 {
1525 name: "AppDataBeforeHandshake-Empty",
1526 config: Config{
1527 Bugs: ProtocolBugs{
1528 AppDataBeforeHandshake: []byte{},
1529 },
1530 },
1531 shouldFail: true,
1532 expectedError: ":UNEXPECTED_RECORD:",
1533 },
1534 {
1535 protocol: dtls,
1536 name: "AppDataBeforeHandshake-DTLS",
1537 config: Config{
1538 Bugs: ProtocolBugs{
1539 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_RECORD:",
1544 },
1545 {
1546 protocol: dtls,
1547 name: "AppDataBeforeHandshake-DTLS-Empty",
1548 config: Config{
1549 Bugs: ProtocolBugs{
1550 AppDataBeforeHandshake: []byte{},
1551 },
1552 },
1553 shouldFail: true,
1554 expectedError: ":UNEXPECTED_RECORD:",
1555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 name: "AppDataAfterChangeCipherSpec",
1558 config: Config{
1559 Bugs: ProtocolBugs{
1560 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1561 },
1562 },
1563 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001564 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001565 },
1566 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001567 name: "AppDataAfterChangeCipherSpec-Empty",
1568 config: Config{
1569 Bugs: ProtocolBugs{
1570 AppDataAfterChangeCipherSpec: []byte{},
1571 },
1572 },
1573 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001574 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 },
1576 {
Adam Langley7c803a62015-06-15 15:35:05 -07001577 protocol: dtls,
1578 name: "AppDataAfterChangeCipherSpec-DTLS",
1579 config: Config{
1580 Bugs: ProtocolBugs{
1581 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1582 },
1583 },
1584 // BoringSSL's DTLS implementation will drop the out-of-order
1585 // application data.
1586 },
1587 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001588 protocol: dtls,
1589 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 AppDataAfterChangeCipherSpec: []byte{},
1593 },
1594 },
1595 // BoringSSL's DTLS implementation will drop the out-of-order
1596 // application data.
1597 },
1598 {
Adam Langley7c803a62015-06-15 15:35:05 -07001599 name: "AlertAfterChangeCipherSpec",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 AlertAfterChangeCipherSpec: alertRecordOverflow,
1603 },
1604 },
1605 shouldFail: true,
1606 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "AlertAfterChangeCipherSpec-DTLS",
1611 config: Config{
1612 Bugs: ProtocolBugs{
1613 AlertAfterChangeCipherSpec: alertRecordOverflow,
1614 },
1615 },
1616 shouldFail: true,
1617 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1618 },
1619 {
1620 protocol: dtls,
1621 name: "ReorderHandshakeFragments-Small-DTLS",
1622 config: Config{
1623 Bugs: ProtocolBugs{
1624 ReorderHandshakeFragments: true,
1625 // Small enough that every handshake message is
1626 // fragmented.
1627 MaxHandshakeRecordLength: 2,
1628 },
1629 },
1630 },
1631 {
1632 protocol: dtls,
1633 name: "ReorderHandshakeFragments-Large-DTLS",
1634 config: Config{
1635 Bugs: ProtocolBugs{
1636 ReorderHandshakeFragments: true,
1637 // Large enough that no handshake message is
1638 // fragmented.
1639 MaxHandshakeRecordLength: 2048,
1640 },
1641 },
1642 },
1643 {
1644 protocol: dtls,
1645 name: "MixCompleteMessageWithFragments-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 ReorderHandshakeFragments: true,
1649 MixCompleteMessageWithFragments: true,
1650 MaxHandshakeRecordLength: 2,
1651 },
1652 },
1653 },
1654 {
1655 name: "SendInvalidRecordType",
1656 config: Config{
1657 Bugs: ProtocolBugs{
1658 SendInvalidRecordType: true,
1659 },
1660 },
1661 shouldFail: true,
1662 expectedError: ":UNEXPECTED_RECORD:",
1663 },
1664 {
1665 protocol: dtls,
1666 name: "SendInvalidRecordType-DTLS",
1667 config: Config{
1668 Bugs: ProtocolBugs{
1669 SendInvalidRecordType: true,
1670 },
1671 },
1672 shouldFail: true,
1673 expectedError: ":UNEXPECTED_RECORD:",
1674 },
1675 {
1676 name: "FalseStart-SkipServerSecondLeg",
1677 config: Config{
1678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1679 NextProtos: []string{"foo"},
1680 Bugs: ProtocolBugs{
1681 SkipNewSessionTicket: true,
1682 SkipChangeCipherSpec: true,
1683 SkipFinished: true,
1684 ExpectFalseStart: true,
1685 },
1686 },
1687 flags: []string{
1688 "-false-start",
1689 "-handshake-never-done",
1690 "-advertise-alpn", "\x03foo",
1691 },
1692 shimWritesFirst: true,
1693 shouldFail: true,
1694 expectedError: ":UNEXPECTED_RECORD:",
1695 },
1696 {
1697 name: "FalseStart-SkipServerSecondLeg-Implicit",
1698 config: Config{
1699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1700 NextProtos: []string{"foo"},
1701 Bugs: ProtocolBugs{
1702 SkipNewSessionTicket: true,
1703 SkipChangeCipherSpec: true,
1704 SkipFinished: true,
1705 },
1706 },
1707 flags: []string{
1708 "-implicit-handshake",
1709 "-false-start",
1710 "-handshake-never-done",
1711 "-advertise-alpn", "\x03foo",
1712 },
1713 shouldFail: true,
1714 expectedError: ":UNEXPECTED_RECORD:",
1715 },
1716 {
1717 testType: serverTest,
1718 name: "FailEarlyCallback",
1719 flags: []string{"-fail-early-callback"},
1720 shouldFail: true,
1721 expectedError: ":CONNECTION_REJECTED:",
1722 expectedLocalError: "remote error: access denied",
1723 },
1724 {
1725 name: "WrongMessageType",
1726 config: Config{
1727 Bugs: ProtocolBugs{
1728 WrongCertificateMessageType: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":UNEXPECTED_MESSAGE:",
1733 expectedLocalError: "remote error: unexpected message",
1734 },
1735 {
1736 protocol: dtls,
1737 name: "WrongMessageType-DTLS",
1738 config: Config{
1739 Bugs: ProtocolBugs{
1740 WrongCertificateMessageType: true,
1741 },
1742 },
1743 shouldFail: true,
1744 expectedError: ":UNEXPECTED_MESSAGE:",
1745 expectedLocalError: "remote error: unexpected message",
1746 },
1747 {
1748 protocol: dtls,
1749 name: "FragmentMessageTypeMismatch-DTLS",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 MaxHandshakeRecordLength: 2,
1753 FragmentMessageTypeMismatch: true,
1754 },
1755 },
1756 shouldFail: true,
1757 expectedError: ":FRAGMENT_MISMATCH:",
1758 },
1759 {
1760 protocol: dtls,
1761 name: "FragmentMessageLengthMismatch-DTLS",
1762 config: Config{
1763 Bugs: ProtocolBugs{
1764 MaxHandshakeRecordLength: 2,
1765 FragmentMessageLengthMismatch: true,
1766 },
1767 },
1768 shouldFail: true,
1769 expectedError: ":FRAGMENT_MISMATCH:",
1770 },
1771 {
1772 protocol: dtls,
1773 name: "SplitFragments-Header-DTLS",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 SplitFragments: 2,
1777 },
1778 },
1779 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001780 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001781 },
1782 {
1783 protocol: dtls,
1784 name: "SplitFragments-Boundary-DTLS",
1785 config: Config{
1786 Bugs: ProtocolBugs{
1787 SplitFragments: dtlsRecordHeaderLen,
1788 },
1789 },
1790 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001791 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001792 },
1793 {
1794 protocol: dtls,
1795 name: "SplitFragments-Body-DTLS",
1796 config: Config{
1797 Bugs: ProtocolBugs{
1798 SplitFragments: dtlsRecordHeaderLen + 1,
1799 },
1800 },
1801 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001802 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001803 },
1804 {
1805 protocol: dtls,
1806 name: "SendEmptyFragments-DTLS",
1807 config: Config{
1808 Bugs: ProtocolBugs{
1809 SendEmptyFragments: true,
1810 },
1811 },
1812 },
1813 {
1814 name: "UnsupportedCipherSuite",
1815 config: Config{
1816 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1817 Bugs: ProtocolBugs{
1818 IgnorePeerCipherPreferences: true,
1819 },
1820 },
1821 flags: []string{"-cipher", "DEFAULT:!RC4"},
1822 shouldFail: true,
1823 expectedError: ":WRONG_CIPHER_RETURNED:",
1824 },
1825 {
1826 name: "UnsupportedCurve",
1827 config: Config{
David Benjamin64d92502015-12-19 02:20:57 -05001828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1829 CurvePreferences: []CurveID{CurveP256},
Adam Langley7c803a62015-06-15 15:35:05 -07001830 Bugs: ProtocolBugs{
1831 IgnorePeerCurvePreferences: true,
1832 },
1833 },
David Benjamin64d92502015-12-19 02:20:57 -05001834 flags: []string{"-p384-only"},
Adam Langley7c803a62015-06-15 15:35:05 -07001835 shouldFail: true,
1836 expectedError: ":WRONG_CURVE:",
1837 },
1838 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001839 name: "BadFinished-Client",
1840 config: Config{
1841 Bugs: ProtocolBugs{
1842 BadFinished: true,
1843 },
1844 },
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 testType: serverTest,
1850 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001851 config: Config{
1852 Bugs: ProtocolBugs{
1853 BadFinished: true,
1854 },
1855 },
1856 shouldFail: true,
1857 expectedError: ":DIGEST_CHECK_FAILED:",
1858 },
1859 {
1860 name: "FalseStart-BadFinished",
1861 config: Config{
1862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1863 NextProtos: []string{"foo"},
1864 Bugs: ProtocolBugs{
1865 BadFinished: true,
1866 ExpectFalseStart: true,
1867 },
1868 },
1869 flags: []string{
1870 "-false-start",
1871 "-handshake-never-done",
1872 "-advertise-alpn", "\x03foo",
1873 },
1874 shimWritesFirst: true,
1875 shouldFail: true,
1876 expectedError: ":DIGEST_CHECK_FAILED:",
1877 },
1878 {
1879 name: "NoFalseStart-NoALPN",
1880 config: Config{
1881 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1882 Bugs: ProtocolBugs{
1883 ExpectFalseStart: true,
1884 AlertBeforeFalseStartTest: alertAccessDenied,
1885 },
1886 },
1887 flags: []string{
1888 "-false-start",
1889 },
1890 shimWritesFirst: true,
1891 shouldFail: true,
1892 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1893 expectedLocalError: "tls: peer did not false start: EOF",
1894 },
1895 {
1896 name: "NoFalseStart-NoAEAD",
1897 config: Config{
1898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1899 NextProtos: []string{"foo"},
1900 Bugs: ProtocolBugs{
1901 ExpectFalseStart: true,
1902 AlertBeforeFalseStartTest: alertAccessDenied,
1903 },
1904 },
1905 flags: []string{
1906 "-false-start",
1907 "-advertise-alpn", "\x03foo",
1908 },
1909 shimWritesFirst: true,
1910 shouldFail: true,
1911 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1912 expectedLocalError: "tls: peer did not false start: EOF",
1913 },
1914 {
1915 name: "NoFalseStart-RSA",
1916 config: Config{
1917 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1918 NextProtos: []string{"foo"},
1919 Bugs: ProtocolBugs{
1920 ExpectFalseStart: true,
1921 AlertBeforeFalseStartTest: alertAccessDenied,
1922 },
1923 },
1924 flags: []string{
1925 "-false-start",
1926 "-advertise-alpn", "\x03foo",
1927 },
1928 shimWritesFirst: true,
1929 shouldFail: true,
1930 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1931 expectedLocalError: "tls: peer did not false start: EOF",
1932 },
1933 {
1934 name: "NoFalseStart-DHE_RSA",
1935 config: Config{
1936 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1937 NextProtos: []string{"foo"},
1938 Bugs: ProtocolBugs{
1939 ExpectFalseStart: true,
1940 AlertBeforeFalseStartTest: alertAccessDenied,
1941 },
1942 },
1943 flags: []string{
1944 "-false-start",
1945 "-advertise-alpn", "\x03foo",
1946 },
1947 shimWritesFirst: true,
1948 shouldFail: true,
1949 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1950 expectedLocalError: "tls: peer did not false start: EOF",
1951 },
1952 {
1953 testType: serverTest,
1954 name: "NoSupportedCurves",
1955 config: Config{
1956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1957 Bugs: ProtocolBugs{
1958 NoSupportedCurves: true,
1959 },
1960 },
David Benjamin4298d772015-12-19 00:18:25 -05001961 shouldFail: true,
1962 expectedError: ":NO_SHARED_CIPHER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001963 },
1964 {
1965 testType: serverTest,
1966 name: "NoCommonCurves",
1967 config: Config{
1968 CipherSuites: []uint16{
1969 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1970 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1971 },
1972 CurvePreferences: []CurveID{CurveP224},
1973 },
1974 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1975 },
1976 {
1977 protocol: dtls,
1978 name: "SendSplitAlert-Sync",
1979 config: Config{
1980 Bugs: ProtocolBugs{
1981 SendSplitAlert: true,
1982 },
1983 },
1984 },
1985 {
1986 protocol: dtls,
1987 name: "SendSplitAlert-Async",
1988 config: Config{
1989 Bugs: ProtocolBugs{
1990 SendSplitAlert: true,
1991 },
1992 },
1993 flags: []string{"-async"},
1994 },
1995 {
1996 protocol: dtls,
1997 name: "PackDTLSHandshake",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 MaxHandshakeRecordLength: 2,
2001 PackHandshakeFragments: 20,
2002 PackHandshakeRecords: 200,
2003 },
2004 },
2005 },
2006 {
2007 testType: serverTest,
2008 protocol: dtls,
2009 name: "NoRC4-DTLS",
2010 config: Config{
2011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2012 Bugs: ProtocolBugs{
2013 EnableAllCiphersInDTLS: true,
2014 },
2015 },
2016 shouldFail: true,
2017 expectedError: ":NO_SHARED_CIPHER:",
2018 },
2019 {
2020 name: "SendEmptyRecords-Pass",
2021 sendEmptyRecords: 32,
2022 },
2023 {
2024 name: "SendEmptyRecords",
2025 sendEmptyRecords: 33,
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2028 },
2029 {
2030 name: "SendEmptyRecords-Async",
2031 sendEmptyRecords: 33,
2032 flags: []string{"-async"},
2033 shouldFail: true,
2034 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2035 },
2036 {
2037 name: "SendWarningAlerts-Pass",
2038 sendWarningAlerts: 4,
2039 },
2040 {
2041 protocol: dtls,
2042 name: "SendWarningAlerts-DTLS-Pass",
2043 sendWarningAlerts: 4,
2044 },
2045 {
2046 name: "SendWarningAlerts",
2047 sendWarningAlerts: 5,
2048 shouldFail: true,
2049 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2050 },
2051 {
2052 name: "SendWarningAlerts-Async",
2053 sendWarningAlerts: 5,
2054 flags: []string{"-async"},
2055 shouldFail: true,
2056 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2057 },
David Benjaminba4594a2015-06-18 18:36:15 -04002058 {
2059 name: "EmptySessionID",
2060 config: Config{
2061 SessionTicketsDisabled: true,
2062 },
2063 noSessionCache: true,
2064 flags: []string{"-expect-no-session"},
2065 },
David Benjamin30789da2015-08-29 22:56:45 -04002066 {
2067 name: "Unclean-Shutdown",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 NoCloseNotify: true,
2071 ExpectCloseNotify: true,
2072 },
2073 },
2074 shimShutsDown: true,
2075 flags: []string{"-check-close-notify"},
2076 shouldFail: true,
2077 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2078 },
2079 {
2080 name: "Unclean-Shutdown-Ignored",
2081 config: Config{
2082 Bugs: ProtocolBugs{
2083 NoCloseNotify: true,
2084 },
2085 },
2086 shimShutsDown: true,
2087 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002088 {
David Benjaminfa214e42016-05-10 17:03:10 -04002089 name: "Unclean-Shutdown-Alert",
2090 config: Config{
2091 Bugs: ProtocolBugs{
2092 SendAlertOnShutdown: alertDecompressionFailure,
2093 ExpectCloseNotify: true,
2094 },
2095 },
2096 shimShutsDown: true,
2097 flags: []string{"-check-close-notify"},
2098 shouldFail: true,
2099 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2100 },
2101 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002102 name: "LargePlaintext",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendLargeRecords: true,
2106 },
2107 },
2108 messageLen: maxPlaintext + 1,
2109 shouldFail: true,
2110 expectedError: ":DATA_LENGTH_TOO_LONG:",
2111 },
2112 {
2113 protocol: dtls,
2114 name: "LargePlaintext-DTLS",
2115 config: Config{
2116 Bugs: ProtocolBugs{
2117 SendLargeRecords: true,
2118 },
2119 },
2120 messageLen: maxPlaintext + 1,
2121 shouldFail: true,
2122 expectedError: ":DATA_LENGTH_TOO_LONG:",
2123 },
2124 {
2125 name: "LargeCiphertext",
2126 config: Config{
2127 Bugs: ProtocolBugs{
2128 SendLargeRecords: true,
2129 },
2130 },
2131 messageLen: maxPlaintext * 2,
2132 shouldFail: true,
2133 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2134 },
2135 {
2136 protocol: dtls,
2137 name: "LargeCiphertext-DTLS",
2138 config: Config{
2139 Bugs: ProtocolBugs{
2140 SendLargeRecords: true,
2141 },
2142 },
2143 messageLen: maxPlaintext * 2,
2144 // Unlike the other four cases, DTLS drops records which
2145 // are invalid before authentication, so the connection
2146 // does not fail.
2147 expectMessageDropped: true,
2148 },
David Benjamindd6fed92015-10-23 17:41:12 -04002149 {
2150 name: "SendEmptySessionTicket",
2151 config: Config{
2152 Bugs: ProtocolBugs{
2153 SendEmptySessionTicket: true,
2154 FailIfSessionOffered: true,
2155 },
2156 },
2157 flags: []string{"-expect-no-session"},
2158 resumeSession: true,
2159 expectResumeRejected: true,
2160 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002161 {
2162 name: "CheckLeafCurve",
2163 config: Config{
2164 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2165 Certificates: []Certificate{getECDSACertificate()},
2166 },
2167 flags: []string{"-p384-only"},
2168 shouldFail: true,
2169 expectedError: ":BAD_ECC_CERT:",
2170 },
David Benjamin8411b242015-11-26 12:07:28 -05002171 {
2172 name: "BadChangeCipherSpec-1",
2173 config: Config{
2174 Bugs: ProtocolBugs{
2175 BadChangeCipherSpec: []byte{2},
2176 },
2177 },
2178 shouldFail: true,
2179 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2180 },
2181 {
2182 name: "BadChangeCipherSpec-2",
2183 config: Config{
2184 Bugs: ProtocolBugs{
2185 BadChangeCipherSpec: []byte{1, 1},
2186 },
2187 },
2188 shouldFail: true,
2189 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2190 },
2191 {
2192 protocol: dtls,
2193 name: "BadChangeCipherSpec-DTLS-1",
2194 config: Config{
2195 Bugs: ProtocolBugs{
2196 BadChangeCipherSpec: []byte{2},
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2201 },
2202 {
2203 protocol: dtls,
2204 name: "BadChangeCipherSpec-DTLS-2",
2205 config: Config{
2206 Bugs: ProtocolBugs{
2207 BadChangeCipherSpec: []byte{1, 1},
2208 },
2209 },
2210 shouldFail: true,
2211 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2212 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002213 {
2214 name: "BadHelloRequest-1",
2215 renegotiate: 1,
2216 config: Config{
2217 Bugs: ProtocolBugs{
2218 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2219 },
2220 },
2221 flags: []string{
2222 "-renegotiate-freely",
2223 "-expect-total-renegotiations", "1",
2224 },
2225 shouldFail: true,
2226 expectedError: ":BAD_HELLO_REQUEST:",
2227 },
2228 {
2229 name: "BadHelloRequest-2",
2230 renegotiate: 1,
2231 config: Config{
2232 Bugs: ProtocolBugs{
2233 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2234 },
2235 },
2236 flags: []string{
2237 "-renegotiate-freely",
2238 "-expect-total-renegotiations", "1",
2239 },
2240 shouldFail: true,
2241 expectedError: ":BAD_HELLO_REQUEST:",
2242 },
David Benjaminef1b0092015-11-21 14:05:44 -05002243 {
2244 testType: serverTest,
2245 name: "SupportTicketsWithSessionID",
2246 config: Config{
2247 SessionTicketsDisabled: true,
2248 },
2249 resumeConfig: &Config{},
2250 resumeSession: true,
2251 },
David Benjamin2b07fa42016-03-02 00:23:57 -05002252 {
2253 name: "InvalidECDHPoint-Client",
2254 config: Config{
2255 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2256 CurvePreferences: []CurveID{CurveP256},
2257 Bugs: ProtocolBugs{
2258 InvalidECDHPoint: true,
2259 },
2260 },
2261 shouldFail: true,
2262 expectedError: ":INVALID_ENCODING:",
2263 },
2264 {
2265 testType: serverTest,
2266 name: "InvalidECDHPoint-Server",
2267 config: Config{
2268 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2269 CurvePreferences: []CurveID{CurveP256},
2270 Bugs: ProtocolBugs{
2271 InvalidECDHPoint: true,
2272 },
2273 },
2274 shouldFail: true,
2275 expectedError: ":INVALID_ENCODING:",
2276 },
Adam Langley7c803a62015-06-15 15:35:05 -07002277 }
Adam Langley7c803a62015-06-15 15:35:05 -07002278 testCases = append(testCases, basicTests...)
2279}
2280
Adam Langley95c29f32014-06-20 12:00:00 -07002281func addCipherSuiteTests() {
2282 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002283 const psk = "12345"
2284 const pskIdentity = "luggage combo"
2285
Adam Langley95c29f32014-06-20 12:00:00 -07002286 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002287 var certFile string
2288 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002289 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002290 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002291 certFile = ecdsaCertificateFile
2292 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002293 } else {
2294 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002295 certFile = rsaCertificateFile
2296 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002297 }
2298
David Benjamin48cae082014-10-27 01:06:24 -04002299 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002300 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002301 flags = append(flags,
2302 "-psk", psk,
2303 "-psk-identity", pskIdentity)
2304 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002305 if hasComponent(suite.name, "NULL") {
2306 // NULL ciphers must be explicitly enabled.
2307 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2308 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002309 if hasComponent(suite.name, "CECPQ1") {
2310 // CECPQ1 ciphers must be explicitly enabled.
2311 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2312 }
David Benjamin48cae082014-10-27 01:06:24 -04002313
Adam Langley95c29f32014-06-20 12:00:00 -07002314 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002315 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002316 continue
2317 }
2318
David Benjamin4298d772015-12-19 00:18:25 -05002319 shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30
2320
2321 expectedError := ""
2322 if shouldFail {
2323 expectedError = ":NO_SHARED_CIPHER:"
2324 }
David Benjamin025b3d32014-07-01 19:53:04 -04002325
David Benjamin76d8abe2014-08-14 16:25:34 -04002326 testCases = append(testCases, testCase{
2327 testType: serverTest,
2328 name: ver.name + "-" + suite.name + "-server",
2329 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002330 MinVersion: ver.version,
2331 MaxVersion: ver.version,
2332 CipherSuites: []uint16{suite.id},
2333 Certificates: []Certificate{cert},
2334 PreSharedKey: []byte(psk),
2335 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002336 },
2337 certFile: certFile,
2338 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002339 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002340 resumeSession: true,
David Benjamin4298d772015-12-19 00:18:25 -05002341 shouldFail: shouldFail,
2342 expectedError: expectedError,
2343 })
2344
2345 if shouldFail {
2346 continue
2347 }
2348
2349 testCases = append(testCases, testCase{
2350 testType: clientTest,
2351 name: ver.name + "-" + suite.name + "-client",
2352 config: Config{
2353 MinVersion: ver.version,
2354 MaxVersion: ver.version,
2355 CipherSuites: []uint16{suite.id},
2356 Certificates: []Certificate{cert},
2357 PreSharedKey: []byte(psk),
2358 PreSharedKeyIdentity: pskIdentity,
2359 },
2360 flags: flags,
2361 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002362 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002363
David Benjamin8b8c0062014-11-23 02:47:52 -05002364 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002365 testCases = append(testCases, testCase{
2366 testType: clientTest,
2367 protocol: dtls,
2368 name: "D" + ver.name + "-" + suite.name + "-client",
2369 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002370 MinVersion: ver.version,
2371 MaxVersion: ver.version,
2372 CipherSuites: []uint16{suite.id},
2373 Certificates: []Certificate{cert},
2374 PreSharedKey: []byte(psk),
2375 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002376 },
David Benjamin48cae082014-10-27 01:06:24 -04002377 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002378 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002379 })
2380 testCases = append(testCases, testCase{
2381 testType: serverTest,
2382 protocol: dtls,
2383 name: "D" + ver.name + "-" + suite.name + "-server",
2384 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002385 MinVersion: ver.version,
2386 MaxVersion: ver.version,
2387 CipherSuites: []uint16{suite.id},
2388 Certificates: []Certificate{cert},
2389 PreSharedKey: []byte(psk),
2390 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002391 },
2392 certFile: certFile,
2393 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002394 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002395 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002396 })
2397 }
Adam Langley95c29f32014-06-20 12:00:00 -07002398 }
David Benjamin2c99d282015-09-01 10:23:00 -04002399
2400 // Ensure both TLS and DTLS accept their maximum record sizes.
2401 testCases = append(testCases, testCase{
2402 name: suite.name + "-LargeRecord",
2403 config: Config{
2404 CipherSuites: []uint16{suite.id},
2405 Certificates: []Certificate{cert},
2406 PreSharedKey: []byte(psk),
2407 PreSharedKeyIdentity: pskIdentity,
2408 },
2409 flags: flags,
2410 messageLen: maxPlaintext,
2411 })
David Benjamin2c99d282015-09-01 10:23:00 -04002412 if isDTLSCipher(suite.name) {
2413 testCases = append(testCases, testCase{
2414 protocol: dtls,
2415 name: suite.name + "-LargeRecord-DTLS",
2416 config: Config{
2417 CipherSuites: []uint16{suite.id},
2418 Certificates: []Certificate{cert},
2419 PreSharedKey: []byte(psk),
2420 PreSharedKeyIdentity: pskIdentity,
2421 },
2422 flags: flags,
2423 messageLen: maxPlaintext,
2424 })
2425 }
Adam Langley95c29f32014-06-20 12:00:00 -07002426 }
Adam Langleya7997f12015-05-14 17:38:50 -07002427
2428 testCases = append(testCases, testCase{
2429 name: "WeakDH",
2430 config: Config{
2431 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2432 Bugs: ProtocolBugs{
2433 // This is a 1023-bit prime number, generated
2434 // with:
2435 // openssl gendh 1023 | openssl asn1parse -i
2436 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2437 },
2438 },
2439 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002440 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002441 })
Adam Langleycef75832015-09-03 14:51:12 -07002442
David Benjamincd24a392015-11-11 13:23:05 -08002443 testCases = append(testCases, testCase{
2444 name: "SillyDH",
2445 config: Config{
2446 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2447 Bugs: ProtocolBugs{
2448 // This is a 4097-bit prime number, generated
2449 // with:
2450 // openssl gendh 4097 | openssl asn1parse -i
2451 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2452 },
2453 },
2454 shouldFail: true,
2455 expectedError: ":DH_P_TOO_LONG:",
2456 })
2457
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002458 // This test ensures that Diffie-Hellman public values are padded with
2459 // zeros so that they're the same length as the prime. This is to avoid
2460 // hitting a bug in yaSSL.
2461 testCases = append(testCases, testCase{
2462 testType: serverTest,
2463 name: "DHPublicValuePadded",
2464 config: Config{
2465 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2466 Bugs: ProtocolBugs{
2467 RequireDHPublicValueLen: (1025 + 7) / 8,
2468 },
2469 },
2470 flags: []string{"-use-sparse-dh-prime"},
2471 })
David Benjamincd24a392015-11-11 13:23:05 -08002472
David Benjamin241ae832016-01-15 03:04:54 -05002473 // The server must be tolerant to bogus ciphers.
2474 const bogusCipher = 0x1234
2475 testCases = append(testCases, testCase{
2476 testType: serverTest,
2477 name: "UnknownCipher",
2478 config: Config{
2479 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2480 },
2481 })
2482
Adam Langleycef75832015-09-03 14:51:12 -07002483 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2484 // 1.1 specific cipher suite settings. A server is setup with the given
2485 // cipher lists and then a connection is made for each member of
2486 // expectations. The cipher suite that the server selects must match
2487 // the specified one.
2488 var versionSpecificCiphersTest = []struct {
2489 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2490 // expectations is a map from TLS version to cipher suite id.
2491 expectations map[uint16]uint16
2492 }{
2493 {
2494 // Test that the null case (where no version-specific ciphers are set)
2495 // works as expected.
2496 "RC4-SHA:AES128-SHA", // default ciphers
2497 "", // no ciphers specifically for TLS ≥ 1.0
2498 "", // no ciphers specifically for TLS ≥ 1.1
2499 map[uint16]uint16{
2500 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2501 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2502 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2503 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2504 },
2505 },
2506 {
2507 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2508 // cipher.
2509 "RC4-SHA:AES128-SHA", // default
2510 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2511 "", // no ciphers specifically for TLS ≥ 1.1
2512 map[uint16]uint16{
2513 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2514 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2515 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2516 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2517 },
2518 },
2519 {
2520 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2521 // cipher.
2522 "RC4-SHA:AES128-SHA", // default
2523 "", // no ciphers specifically for TLS ≥ 1.0
2524 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2525 map[uint16]uint16{
2526 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2527 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2528 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2529 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2530 },
2531 },
2532 {
2533 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2534 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2535 "RC4-SHA:AES128-SHA", // default
2536 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2537 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2538 map[uint16]uint16{
2539 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2540 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2541 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2542 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2543 },
2544 },
2545 }
2546
2547 for i, test := range versionSpecificCiphersTest {
2548 for version, expectedCipherSuite := range test.expectations {
2549 flags := []string{"-cipher", test.ciphersDefault}
2550 if len(test.ciphersTLS10) > 0 {
2551 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2552 }
2553 if len(test.ciphersTLS11) > 0 {
2554 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2555 }
2556
2557 testCases = append(testCases, testCase{
2558 testType: serverTest,
2559 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2560 config: Config{
2561 MaxVersion: version,
2562 MinVersion: version,
2563 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2564 },
2565 flags: flags,
2566 expectedCipher: expectedCipherSuite,
2567 })
2568 }
2569 }
Adam Langley95c29f32014-06-20 12:00:00 -07002570}
2571
2572func addBadECDSASignatureTests() {
2573 for badR := BadValue(1); badR < NumBadValues; badR++ {
2574 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002575 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002576 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2577 config: Config{
2578 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2579 Certificates: []Certificate{getECDSACertificate()},
2580 Bugs: ProtocolBugs{
2581 BadECDSAR: badR,
2582 BadECDSAS: badS,
2583 },
2584 },
2585 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002586 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002587 })
2588 }
2589 }
2590}
2591
Adam Langley80842bd2014-06-20 12:00:00 -07002592func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002593 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002594 name: "MaxCBCPadding",
2595 config: Config{
2596 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2597 Bugs: ProtocolBugs{
2598 MaxPadding: true,
2599 },
2600 },
2601 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2602 })
David Benjamin025b3d32014-07-01 19:53:04 -04002603 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002604 name: "BadCBCPadding",
2605 config: Config{
2606 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2607 Bugs: ProtocolBugs{
2608 PaddingFirstByteBad: true,
2609 },
2610 },
2611 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002612 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002613 })
2614 // OpenSSL previously had an issue where the first byte of padding in
2615 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002616 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002617 name: "BadCBCPadding255",
2618 config: Config{
2619 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2620 Bugs: ProtocolBugs{
2621 MaxPadding: true,
2622 PaddingFirstByteBadIf255: true,
2623 },
2624 },
2625 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2626 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002627 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002628 })
2629}
2630
Kenny Root7fdeaf12014-08-05 15:23:37 -07002631func addCBCSplittingTests() {
2632 testCases = append(testCases, testCase{
2633 name: "CBCRecordSplitting",
2634 config: Config{
2635 MaxVersion: VersionTLS10,
2636 MinVersion: VersionTLS10,
2637 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2638 },
David Benjaminac8302a2015-09-01 17:18:15 -04002639 messageLen: -1, // read until EOF
2640 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002641 flags: []string{
2642 "-async",
2643 "-write-different-record-sizes",
2644 "-cbc-record-splitting",
2645 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002646 })
2647 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002648 name: "CBCRecordSplittingPartialWrite",
2649 config: Config{
2650 MaxVersion: VersionTLS10,
2651 MinVersion: VersionTLS10,
2652 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2653 },
2654 messageLen: -1, // read until EOF
2655 flags: []string{
2656 "-async",
2657 "-write-different-record-sizes",
2658 "-cbc-record-splitting",
2659 "-partial-write",
2660 },
2661 })
2662}
2663
David Benjamin636293b2014-07-08 17:59:18 -04002664func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002665 // Add a dummy cert pool to stress certificate authority parsing.
2666 // TODO(davidben): Add tests that those values parse out correctly.
2667 certPool := x509.NewCertPool()
2668 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2669 if err != nil {
2670 panic(err)
2671 }
2672 certPool.AddCert(cert)
2673
David Benjamin636293b2014-07-08 17:59:18 -04002674 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002675 testCases = append(testCases, testCase{
2676 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002677 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002678 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002679 MinVersion: ver.version,
2680 MaxVersion: ver.version,
2681 ClientAuth: RequireAnyClientCert,
2682 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002683 },
2684 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002687 },
2688 })
2689 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002690 testType: serverTest,
2691 name: ver.name + "-Server-ClientAuth-RSA",
2692 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002693 MinVersion: ver.version,
2694 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002695 Certificates: []Certificate{rsaCertificate},
2696 },
2697 flags: []string{"-require-any-client-certificate"},
2698 })
David Benjamine098ec22014-08-27 23:13:20 -04002699 if ver.version != VersionSSL30 {
2700 testCases = append(testCases, testCase{
2701 testType: serverTest,
2702 name: ver.name + "-Server-ClientAuth-ECDSA",
2703 config: Config{
2704 MinVersion: ver.version,
2705 MaxVersion: ver.version,
2706 Certificates: []Certificate{ecdsaCertificate},
2707 },
2708 flags: []string{"-require-any-client-certificate"},
2709 })
2710 testCases = append(testCases, testCase{
2711 testType: clientTest,
2712 name: ver.name + "-Client-ClientAuth-ECDSA",
2713 config: Config{
2714 MinVersion: ver.version,
2715 MaxVersion: ver.version,
2716 ClientAuth: RequireAnyClientCert,
2717 ClientCAs: certPool,
2718 },
2719 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002720 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2721 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002722 },
2723 })
2724 }
David Benjamin636293b2014-07-08 17:59:18 -04002725 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002726
2727 testCases = append(testCases, testCase{
2728 testType: serverTest,
2729 name: "RequireAnyClientCertificate",
2730 flags: []string{"-require-any-client-certificate"},
2731 shouldFail: true,
2732 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2733 })
2734
2735 testCases = append(testCases, testCase{
2736 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002737 name: "RequireAnyClientCertificate-SSL3",
2738 config: Config{
2739 MaxVersion: VersionSSL30,
2740 },
2741 flags: []string{"-require-any-client-certificate"},
2742 shouldFail: true,
2743 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2744 })
2745
2746 testCases = append(testCases, testCase{
2747 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002748 name: "SkipClientCertificate",
2749 config: Config{
2750 Bugs: ProtocolBugs{
2751 SkipClientCertificate: true,
2752 },
2753 },
2754 // Setting SSL_VERIFY_PEER allows anonymous clients.
2755 flags: []string{"-verify-peer"},
2756 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002757 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002758 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002759
2760 // Client auth is only legal in certificate-based ciphers.
2761 testCases = append(testCases, testCase{
2762 testType: clientTest,
2763 name: "ClientAuth-PSK",
2764 config: Config{
2765 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2766 PreSharedKey: []byte("secret"),
2767 ClientAuth: RequireAnyClientCert,
2768 },
2769 flags: []string{
2770 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2771 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2772 "-psk", "secret",
2773 },
2774 shouldFail: true,
2775 expectedError: ":UNEXPECTED_MESSAGE:",
2776 })
2777 testCases = append(testCases, testCase{
2778 testType: clientTest,
2779 name: "ClientAuth-ECDHE_PSK",
2780 config: Config{
2781 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2782 PreSharedKey: []byte("secret"),
2783 ClientAuth: RequireAnyClientCert,
2784 },
2785 flags: []string{
2786 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2787 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2788 "-psk", "secret",
2789 },
2790 shouldFail: true,
2791 expectedError: ":UNEXPECTED_MESSAGE:",
2792 })
David Benjamin636293b2014-07-08 17:59:18 -04002793}
2794
Adam Langley75712922014-10-10 16:23:43 -07002795func addExtendedMasterSecretTests() {
2796 const expectEMSFlag = "-expect-extended-master-secret"
2797
2798 for _, with := range []bool{false, true} {
2799 prefix := "No"
2800 var flags []string
2801 if with {
2802 prefix = ""
2803 flags = []string{expectEMSFlag}
2804 }
2805
2806 for _, isClient := range []bool{false, true} {
2807 suffix := "-Server"
2808 testType := serverTest
2809 if isClient {
2810 suffix = "-Client"
2811 testType = clientTest
2812 }
2813
2814 for _, ver := range tlsVersions {
2815 test := testCase{
2816 testType: testType,
2817 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2818 config: Config{
2819 MinVersion: ver.version,
2820 MaxVersion: ver.version,
2821 Bugs: ProtocolBugs{
2822 NoExtendedMasterSecret: !with,
2823 RequireExtendedMasterSecret: with,
2824 },
2825 },
David Benjamin48cae082014-10-27 01:06:24 -04002826 flags: flags,
2827 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002828 }
2829 if test.shouldFail {
2830 test.expectedLocalError = "extended master secret required but not supported by peer"
2831 }
2832 testCases = append(testCases, test)
2833 }
2834 }
2835 }
2836
Adam Langleyba5934b2015-06-02 10:50:35 -07002837 for _, isClient := range []bool{false, true} {
2838 for _, supportedInFirstConnection := range []bool{false, true} {
2839 for _, supportedInResumeConnection := range []bool{false, true} {
2840 boolToWord := func(b bool) string {
2841 if b {
2842 return "Yes"
2843 }
2844 return "No"
2845 }
2846 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2847 if isClient {
2848 suffix += "Client"
2849 } else {
2850 suffix += "Server"
2851 }
2852
2853 supportedConfig := Config{
2854 Bugs: ProtocolBugs{
2855 RequireExtendedMasterSecret: true,
2856 },
2857 }
2858
2859 noSupportConfig := Config{
2860 Bugs: ProtocolBugs{
2861 NoExtendedMasterSecret: true,
2862 },
2863 }
2864
2865 test := testCase{
2866 name: "ExtendedMasterSecret-" + suffix,
2867 resumeSession: true,
2868 }
2869
2870 if !isClient {
2871 test.testType = serverTest
2872 }
2873
2874 if supportedInFirstConnection {
2875 test.config = supportedConfig
2876 } else {
2877 test.config = noSupportConfig
2878 }
2879
2880 if supportedInResumeConnection {
2881 test.resumeConfig = &supportedConfig
2882 } else {
2883 test.resumeConfig = &noSupportConfig
2884 }
2885
2886 switch suffix {
2887 case "YesToYes-Client", "YesToYes-Server":
2888 // When a session is resumed, it should
2889 // still be aware that its master
2890 // secret was generated via EMS and
2891 // thus it's safe to use tls-unique.
2892 test.flags = []string{expectEMSFlag}
2893 case "NoToYes-Server":
2894 // If an original connection did not
2895 // contain EMS, but a resumption
2896 // handshake does, then a server should
2897 // not resume the session.
2898 test.expectResumeRejected = true
2899 case "YesToNo-Server":
2900 // Resuming an EMS session without the
2901 // EMS extension should cause the
2902 // server to abort the connection.
2903 test.shouldFail = true
2904 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2905 case "NoToYes-Client":
2906 // A client should abort a connection
2907 // where the server resumed a non-EMS
2908 // session but echoed the EMS
2909 // extension.
2910 test.shouldFail = true
2911 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2912 case "YesToNo-Client":
2913 // A client should abort a connection
2914 // where the server didn't echo EMS
2915 // when the session used it.
2916 test.shouldFail = true
2917 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2918 }
2919
2920 testCases = append(testCases, test)
2921 }
2922 }
2923 }
Adam Langley75712922014-10-10 16:23:43 -07002924}
2925
David Benjamin43ec06f2014-08-05 02:28:57 -04002926// Adds tests that try to cover the range of the handshake state machine, under
2927// various conditions. Some of these are redundant with other tests, but they
2928// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002929func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002930 var tests []testCase
2931
2932 // Basic handshake, with resumption. Client and server,
2933 // session ID and session ticket.
2934 tests = append(tests, testCase{
2935 name: "Basic-Client",
2936 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002937 // Ensure session tickets are used, not session IDs.
2938 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002939 })
2940 tests = append(tests, testCase{
2941 name: "Basic-Client-RenewTicket",
2942 config: Config{
2943 Bugs: ProtocolBugs{
2944 RenewTicketOnResume: true,
2945 },
2946 },
David Benjaminba4594a2015-06-18 18:36:15 -04002947 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002948 resumeSession: true,
2949 })
2950 tests = append(tests, testCase{
2951 name: "Basic-Client-NoTicket",
2952 config: Config{
2953 SessionTicketsDisabled: true,
2954 },
2955 resumeSession: true,
2956 })
2957 tests = append(tests, testCase{
2958 name: "Basic-Client-Implicit",
2959 flags: []string{"-implicit-handshake"},
2960 resumeSession: true,
2961 })
2962 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002963 testType: serverTest,
2964 name: "Basic-Server",
2965 config: Config{
2966 Bugs: ProtocolBugs{
2967 RequireSessionTickets: true,
2968 },
2969 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002970 resumeSession: true,
2971 })
2972 tests = append(tests, testCase{
2973 testType: serverTest,
2974 name: "Basic-Server-NoTickets",
2975 config: Config{
2976 SessionTicketsDisabled: true,
2977 },
2978 resumeSession: true,
2979 })
2980 tests = append(tests, testCase{
2981 testType: serverTest,
2982 name: "Basic-Server-Implicit",
2983 flags: []string{"-implicit-handshake"},
2984 resumeSession: true,
2985 })
2986 tests = append(tests, testCase{
2987 testType: serverTest,
2988 name: "Basic-Server-EarlyCallback",
2989 flags: []string{"-use-early-callback"},
2990 resumeSession: true,
2991 })
2992
2993 // TLS client auth.
2994 tests = append(tests, testCase{
2995 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002996 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002997 config: Config{
2998 ClientAuth: RequestClientCert,
2999 },
3000 })
3001 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003002 testType: serverTest,
3003 name: "ClientAuth-NoCertificate-Server",
3004 // Setting SSL_VERIFY_PEER allows anonymous clients.
3005 flags: []string{"-verify-peer"},
3006 })
3007 if protocol == tls {
3008 tests = append(tests, testCase{
3009 testType: clientTest,
3010 name: "ClientAuth-NoCertificate-Client-SSL3",
3011 config: Config{
3012 MaxVersion: VersionSSL30,
3013 ClientAuth: RequestClientCert,
3014 },
3015 })
3016 tests = append(tests, testCase{
3017 testType: serverTest,
3018 name: "ClientAuth-NoCertificate-Server-SSL3",
3019 config: Config{
3020 MaxVersion: VersionSSL30,
3021 },
3022 // Setting SSL_VERIFY_PEER allows anonymous clients.
3023 flags: []string{"-verify-peer"},
3024 })
3025 }
3026 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003027 testType: clientTest,
3028 name: "ClientAuth-NoCertificate-OldCallback",
3029 config: Config{
3030 ClientAuth: RequestClientCert,
3031 },
3032 flags: []string{"-use-old-client-cert-callback"},
3033 })
3034 tests = append(tests, testCase{
3035 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003036 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003037 config: Config{
3038 ClientAuth: RequireAnyClientCert,
3039 },
3040 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003041 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3042 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 },
3044 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003045 tests = append(tests, testCase{
3046 testType: clientTest,
3047 name: "ClientAuth-ECDSA-Client",
3048 config: Config{
3049 ClientAuth: RequireAnyClientCert,
3050 },
3051 flags: []string{
3052 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3053 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3054 },
3055 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003056 tests = append(tests, testCase{
3057 testType: clientTest,
3058 name: "ClientAuth-OldCallback",
3059 config: Config{
3060 ClientAuth: RequireAnyClientCert,
3061 },
3062 flags: []string{
3063 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3064 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3065 "-use-old-client-cert-callback",
3066 },
3067 })
3068
David Benjaminb4d65fd2015-05-29 17:11:21 -04003069 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003070 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04003071 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003072 testType: serverTest,
3073 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04003074 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003075 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04003076 },
3077 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07003078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04003080 },
3081 })
nagendra modadugu601448a2015-07-24 09:31:31 -07003082 tests = append(tests, testCase{
3083 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003084 name: "Basic-Server-ECDHE-RSA",
3085 config: Config{
3086 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3087 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003088 flags: []string{
3089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003091 },
3092 })
3093 tests = append(tests, testCase{
3094 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003095 name: "Basic-Server-ECDHE-ECDSA",
3096 config: Config{
3097 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3098 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003099 flags: []string{
3100 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3101 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003102 },
3103 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04003104 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003105 tests = append(tests, testCase{
3106 testType: serverTest,
3107 name: "ClientAuth-Server",
3108 config: Config{
3109 Certificates: []Certificate{rsaCertificate},
3110 },
3111 flags: []string{"-require-any-client-certificate"},
3112 })
3113
3114 // No session ticket support; server doesn't send NewSessionTicket.
3115 tests = append(tests, testCase{
3116 name: "SessionTicketsDisabled-Client",
3117 config: Config{
3118 SessionTicketsDisabled: true,
3119 },
3120 })
3121 tests = append(tests, testCase{
3122 testType: serverTest,
3123 name: "SessionTicketsDisabled-Server",
3124 config: Config{
3125 SessionTicketsDisabled: true,
3126 },
3127 })
3128
3129 // Skip ServerKeyExchange in PSK key exchange if there's no
3130 // identity hint.
3131 tests = append(tests, testCase{
3132 name: "EmptyPSKHint-Client",
3133 config: Config{
3134 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3135 PreSharedKey: []byte("secret"),
3136 },
3137 flags: []string{"-psk", "secret"},
3138 })
3139 tests = append(tests, testCase{
3140 testType: serverTest,
3141 name: "EmptyPSKHint-Server",
3142 config: Config{
3143 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3144 PreSharedKey: []byte("secret"),
3145 },
3146 flags: []string{"-psk", "secret"},
3147 })
3148
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003149 tests = append(tests, testCase{
3150 testType: clientTest,
3151 name: "OCSPStapling-Client",
3152 flags: []string{
3153 "-enable-ocsp-stapling",
3154 "-expect-ocsp-response",
3155 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003156 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003157 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003158 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003159 })
3160
3161 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04003162 testType: serverTest,
3163 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003164 expectedOCSPResponse: testOCSPResponse,
3165 flags: []string{
3166 "-ocsp-response",
3167 base64.StdEncoding.EncodeToString(testOCSPResponse),
3168 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003169 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003170 })
3171
Paul Lietar8f1c2682015-08-18 12:21:54 +01003172 tests = append(tests, testCase{
3173 testType: clientTest,
3174 name: "CertificateVerificationSucceed",
3175 flags: []string{
3176 "-verify-peer",
3177 },
3178 })
3179
3180 tests = append(tests, testCase{
3181 testType: clientTest,
3182 name: "CertificateVerificationFail",
3183 flags: []string{
3184 "-verify-fail",
3185 "-verify-peer",
3186 },
3187 shouldFail: true,
3188 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3189 })
3190
3191 tests = append(tests, testCase{
3192 testType: clientTest,
3193 name: "CertificateVerificationSoftFail",
3194 flags: []string{
3195 "-verify-fail",
3196 "-expect-verify-result",
3197 },
3198 })
3199
David Benjamin760b1dd2015-05-15 23:33:48 -04003200 if protocol == tls {
3201 tests = append(tests, testCase{
3202 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003203 renegotiate: 1,
3204 flags: []string{
3205 "-renegotiate-freely",
3206 "-expect-total-renegotiations", "1",
3207 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003208 })
3209 // NPN on client and server; results in post-handshake message.
3210 tests = append(tests, testCase{
3211 name: "NPN-Client",
3212 config: Config{
3213 NextProtos: []string{"foo"},
3214 },
3215 flags: []string{"-select-next-proto", "foo"},
3216 expectedNextProto: "foo",
3217 expectedNextProtoType: npn,
3218 })
3219 tests = append(tests, testCase{
3220 testType: serverTest,
3221 name: "NPN-Server",
3222 config: Config{
3223 NextProtos: []string{"bar"},
3224 },
3225 flags: []string{
3226 "-advertise-npn", "\x03foo\x03bar\x03baz",
3227 "-expect-next-proto", "bar",
3228 },
3229 expectedNextProto: "bar",
3230 expectedNextProtoType: npn,
3231 })
3232
3233 // TODO(davidben): Add tests for when False Start doesn't trigger.
3234
3235 // Client does False Start and negotiates NPN.
3236 tests = append(tests, testCase{
3237 name: "FalseStart",
3238 config: Config{
3239 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3240 NextProtos: []string{"foo"},
3241 Bugs: ProtocolBugs{
3242 ExpectFalseStart: true,
3243 },
3244 },
3245 flags: []string{
3246 "-false-start",
3247 "-select-next-proto", "foo",
3248 },
3249 shimWritesFirst: true,
3250 resumeSession: true,
3251 })
3252
3253 // Client does False Start and negotiates ALPN.
3254 tests = append(tests, testCase{
3255 name: "FalseStart-ALPN",
3256 config: Config{
3257 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3258 NextProtos: []string{"foo"},
3259 Bugs: ProtocolBugs{
3260 ExpectFalseStart: true,
3261 },
3262 },
3263 flags: []string{
3264 "-false-start",
3265 "-advertise-alpn", "\x03foo",
3266 },
3267 shimWritesFirst: true,
3268 resumeSession: true,
3269 })
3270
3271 // Client does False Start but doesn't explicitly call
3272 // SSL_connect.
3273 tests = append(tests, testCase{
3274 name: "FalseStart-Implicit",
3275 config: Config{
3276 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3277 NextProtos: []string{"foo"},
3278 },
3279 flags: []string{
3280 "-implicit-handshake",
3281 "-false-start",
3282 "-advertise-alpn", "\x03foo",
3283 },
3284 })
3285
3286 // False Start without session tickets.
3287 tests = append(tests, testCase{
3288 name: "FalseStart-SessionTicketsDisabled",
3289 config: Config{
3290 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3291 NextProtos: []string{"foo"},
3292 SessionTicketsDisabled: true,
3293 Bugs: ProtocolBugs{
3294 ExpectFalseStart: true,
3295 },
3296 },
3297 flags: []string{
3298 "-false-start",
3299 "-select-next-proto", "foo",
3300 },
3301 shimWritesFirst: true,
3302 })
3303
3304 // Server parses a V2ClientHello.
3305 tests = append(tests, testCase{
3306 testType: serverTest,
3307 name: "SendV2ClientHello",
3308 config: Config{
3309 // Choose a cipher suite that does not involve
3310 // elliptic curves, so no extensions are
3311 // involved.
3312 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3313 Bugs: ProtocolBugs{
3314 SendV2ClientHello: true,
3315 },
3316 },
3317 })
3318
3319 // Client sends a Channel ID.
3320 tests = append(tests, testCase{
3321 name: "ChannelID-Client",
3322 config: Config{
3323 RequestChannelID: true,
3324 },
Adam Langley7c803a62015-06-15 15:35:05 -07003325 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003326 resumeSession: true,
3327 expectChannelID: true,
3328 })
3329
3330 // Server accepts a Channel ID.
3331 tests = append(tests, testCase{
3332 testType: serverTest,
3333 name: "ChannelID-Server",
3334 config: Config{
3335 ChannelID: channelIDKey,
3336 },
3337 flags: []string{
3338 "-expect-channel-id",
3339 base64.StdEncoding.EncodeToString(channelIDBytes),
3340 },
3341 resumeSession: true,
3342 expectChannelID: true,
3343 })
David Benjamin30789da2015-08-29 22:56:45 -04003344
3345 // Bidirectional shutdown with the runner initiating.
3346 tests = append(tests, testCase{
3347 name: "Shutdown-Runner",
3348 config: Config{
3349 Bugs: ProtocolBugs{
3350 ExpectCloseNotify: true,
3351 },
3352 },
3353 flags: []string{"-check-close-notify"},
3354 })
3355
3356 // Bidirectional shutdown with the shim initiating. The runner,
3357 // in the meantime, sends garbage before the close_notify which
3358 // the shim must ignore.
3359 tests = append(tests, testCase{
3360 name: "Shutdown-Shim",
3361 config: Config{
3362 Bugs: ProtocolBugs{
3363 ExpectCloseNotify: true,
3364 },
3365 },
3366 shimShutsDown: true,
3367 sendEmptyRecords: 1,
3368 sendWarningAlerts: 1,
3369 flags: []string{"-check-close-notify"},
3370 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003371 } else {
3372 tests = append(tests, testCase{
3373 name: "SkipHelloVerifyRequest",
3374 config: Config{
3375 Bugs: ProtocolBugs{
3376 SkipHelloVerifyRequest: true,
3377 },
3378 },
3379 })
3380 }
3381
David Benjamin760b1dd2015-05-15 23:33:48 -04003382 for _, test := range tests {
3383 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003384 if protocol == dtls {
3385 test.name += "-DTLS"
3386 }
3387 if async {
3388 test.name += "-Async"
3389 test.flags = append(test.flags, "-async")
3390 } else {
3391 test.name += "-Sync"
3392 }
3393 if splitHandshake {
3394 test.name += "-SplitHandshakeRecords"
3395 test.config.Bugs.MaxHandshakeRecordLength = 1
3396 if protocol == dtls {
3397 test.config.Bugs.MaxPacketLength = 256
3398 test.flags = append(test.flags, "-mtu", "256")
3399 }
3400 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003401 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003402 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003403}
3404
Adam Langley524e7172015-02-20 16:04:00 -08003405func addDDoSCallbackTests() {
3406 // DDoS callback.
3407
3408 for _, resume := range []bool{false, true} {
3409 suffix := "Resume"
3410 if resume {
3411 suffix = "No" + suffix
3412 }
3413
3414 testCases = append(testCases, testCase{
3415 testType: serverTest,
3416 name: "Server-DDoS-OK-" + suffix,
3417 flags: []string{"-install-ddos-callback"},
3418 resumeSession: resume,
3419 })
3420
3421 failFlag := "-fail-ddos-callback"
3422 if resume {
3423 failFlag = "-fail-second-ddos-callback"
3424 }
3425 testCases = append(testCases, testCase{
3426 testType: serverTest,
3427 name: "Server-DDoS-Reject-" + suffix,
3428 flags: []string{"-install-ddos-callback", failFlag},
3429 resumeSession: resume,
3430 shouldFail: true,
3431 expectedError: ":CONNECTION_REJECTED:",
3432 })
3433 }
3434}
3435
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003436func addVersionNegotiationTests() {
3437 for i, shimVers := range tlsVersions {
3438 // Assemble flags to disable all newer versions on the shim.
3439 var flags []string
3440 for _, vers := range tlsVersions[i+1:] {
3441 flags = append(flags, vers.flag)
3442 }
3443
3444 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003445 protocols := []protocol{tls}
3446 if runnerVers.hasDTLS && shimVers.hasDTLS {
3447 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003448 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003449 for _, protocol := range protocols {
3450 expectedVersion := shimVers.version
3451 if runnerVers.version < shimVers.version {
3452 expectedVersion = runnerVers.version
3453 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003454
David Benjamin8b8c0062014-11-23 02:47:52 -05003455 suffix := shimVers.name + "-" + runnerVers.name
3456 if protocol == dtls {
3457 suffix += "-DTLS"
3458 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003459
David Benjamin1eb367c2014-12-12 18:17:51 -05003460 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3461
David Benjamin1e29a6b2014-12-10 02:27:24 -05003462 clientVers := shimVers.version
3463 if clientVers > VersionTLS10 {
3464 clientVers = VersionTLS10
3465 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003466 testCases = append(testCases, testCase{
3467 protocol: protocol,
3468 testType: clientTest,
3469 name: "VersionNegotiation-Client-" + suffix,
3470 config: Config{
3471 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003472 Bugs: ProtocolBugs{
3473 ExpectInitialRecordVersion: clientVers,
3474 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003475 },
3476 flags: flags,
3477 expectedVersion: expectedVersion,
3478 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003479 testCases = append(testCases, testCase{
3480 protocol: protocol,
3481 testType: clientTest,
3482 name: "VersionNegotiation-Client2-" + suffix,
3483 config: Config{
3484 MaxVersion: runnerVers.version,
3485 Bugs: ProtocolBugs{
3486 ExpectInitialRecordVersion: clientVers,
3487 },
3488 },
3489 flags: []string{"-max-version", shimVersFlag},
3490 expectedVersion: expectedVersion,
3491 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003492
3493 testCases = append(testCases, testCase{
3494 protocol: protocol,
3495 testType: serverTest,
3496 name: "VersionNegotiation-Server-" + suffix,
3497 config: Config{
3498 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003499 Bugs: ProtocolBugs{
3500 ExpectInitialRecordVersion: expectedVersion,
3501 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003502 },
3503 flags: flags,
3504 expectedVersion: expectedVersion,
3505 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003506 testCases = append(testCases, testCase{
3507 protocol: protocol,
3508 testType: serverTest,
3509 name: "VersionNegotiation-Server2-" + suffix,
3510 config: Config{
3511 MaxVersion: runnerVers.version,
3512 Bugs: ProtocolBugs{
3513 ExpectInitialRecordVersion: expectedVersion,
3514 },
3515 },
3516 flags: []string{"-max-version", shimVersFlag},
3517 expectedVersion: expectedVersion,
3518 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003519 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003520 }
3521 }
3522}
3523
David Benjaminaccb4542014-12-12 23:44:33 -05003524func addMinimumVersionTests() {
3525 for i, shimVers := range tlsVersions {
3526 // Assemble flags to disable all older versions on the shim.
3527 var flags []string
3528 for _, vers := range tlsVersions[:i] {
3529 flags = append(flags, vers.flag)
3530 }
3531
3532 for _, runnerVers := range tlsVersions {
3533 protocols := []protocol{tls}
3534 if runnerVers.hasDTLS && shimVers.hasDTLS {
3535 protocols = append(protocols, dtls)
3536 }
3537 for _, protocol := range protocols {
3538 suffix := shimVers.name + "-" + runnerVers.name
3539 if protocol == dtls {
3540 suffix += "-DTLS"
3541 }
3542 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3543
David Benjaminaccb4542014-12-12 23:44:33 -05003544 var expectedVersion uint16
3545 var shouldFail bool
3546 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003547 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003548 if runnerVers.version >= shimVers.version {
3549 expectedVersion = runnerVers.version
3550 } else {
3551 shouldFail = true
3552 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamina565d292015-12-30 16:51:32 -05003553 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05003554 }
3555
3556 testCases = append(testCases, testCase{
3557 protocol: protocol,
3558 testType: clientTest,
3559 name: "MinimumVersion-Client-" + suffix,
3560 config: Config{
3561 MaxVersion: runnerVers.version,
3562 },
David Benjamin87909c02014-12-13 01:55:01 -05003563 flags: flags,
3564 expectedVersion: expectedVersion,
3565 shouldFail: shouldFail,
3566 expectedError: expectedError,
3567 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003568 })
3569 testCases = append(testCases, testCase{
3570 protocol: protocol,
3571 testType: clientTest,
3572 name: "MinimumVersion-Client2-" + suffix,
3573 config: Config{
3574 MaxVersion: runnerVers.version,
3575 },
David Benjamin87909c02014-12-13 01:55:01 -05003576 flags: []string{"-min-version", shimVersFlag},
3577 expectedVersion: expectedVersion,
3578 shouldFail: shouldFail,
3579 expectedError: expectedError,
3580 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003581 })
3582
3583 testCases = append(testCases, testCase{
3584 protocol: protocol,
3585 testType: serverTest,
3586 name: "MinimumVersion-Server-" + suffix,
3587 config: Config{
3588 MaxVersion: runnerVers.version,
3589 },
David Benjamin87909c02014-12-13 01:55:01 -05003590 flags: flags,
3591 expectedVersion: expectedVersion,
3592 shouldFail: shouldFail,
3593 expectedError: expectedError,
3594 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003595 })
3596 testCases = append(testCases, testCase{
3597 protocol: protocol,
3598 testType: serverTest,
3599 name: "MinimumVersion-Server2-" + suffix,
3600 config: Config{
3601 MaxVersion: runnerVers.version,
3602 },
David Benjamin87909c02014-12-13 01:55:01 -05003603 flags: []string{"-min-version", shimVersFlag},
3604 expectedVersion: expectedVersion,
3605 shouldFail: shouldFail,
3606 expectedError: expectedError,
3607 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003608 })
3609 }
3610 }
3611 }
3612}
3613
David Benjamine78bfde2014-09-06 12:45:15 -04003614func addExtensionTests() {
3615 testCases = append(testCases, testCase{
3616 testType: clientTest,
3617 name: "DuplicateExtensionClient",
3618 config: Config{
3619 Bugs: ProtocolBugs{
3620 DuplicateExtension: true,
3621 },
3622 },
3623 shouldFail: true,
3624 expectedLocalError: "remote error: error decoding message",
3625 })
3626 testCases = append(testCases, testCase{
3627 testType: serverTest,
3628 name: "DuplicateExtensionServer",
3629 config: Config{
3630 Bugs: ProtocolBugs{
3631 DuplicateExtension: true,
3632 },
3633 },
3634 shouldFail: true,
3635 expectedLocalError: "remote error: error decoding message",
3636 })
3637 testCases = append(testCases, testCase{
3638 testType: clientTest,
3639 name: "ServerNameExtensionClient",
3640 config: Config{
3641 Bugs: ProtocolBugs{
3642 ExpectServerName: "example.com",
3643 },
3644 },
3645 flags: []string{"-host-name", "example.com"},
3646 })
3647 testCases = append(testCases, testCase{
3648 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003649 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003650 config: Config{
3651 Bugs: ProtocolBugs{
3652 ExpectServerName: "mismatch.com",
3653 },
3654 },
3655 flags: []string{"-host-name", "example.com"},
3656 shouldFail: true,
3657 expectedLocalError: "tls: unexpected server name",
3658 })
3659 testCases = append(testCases, testCase{
3660 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003661 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003662 config: Config{
3663 Bugs: ProtocolBugs{
3664 ExpectServerName: "missing.com",
3665 },
3666 },
3667 shouldFail: true,
3668 expectedLocalError: "tls: unexpected server name",
3669 })
3670 testCases = append(testCases, testCase{
3671 testType: serverTest,
3672 name: "ServerNameExtensionServer",
3673 config: Config{
3674 ServerName: "example.com",
3675 },
3676 flags: []string{"-expect-server-name", "example.com"},
3677 resumeSession: true,
3678 })
David Benjaminae2888f2014-09-06 12:58:58 -04003679 testCases = append(testCases, testCase{
3680 testType: clientTest,
3681 name: "ALPNClient",
3682 config: Config{
3683 NextProtos: []string{"foo"},
3684 },
3685 flags: []string{
3686 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3687 "-expect-alpn", "foo",
3688 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003689 expectedNextProto: "foo",
3690 expectedNextProtoType: alpn,
3691 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003692 })
3693 testCases = append(testCases, testCase{
3694 testType: serverTest,
3695 name: "ALPNServer",
3696 config: Config{
3697 NextProtos: []string{"foo", "bar", "baz"},
3698 },
3699 flags: []string{
3700 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3701 "-select-alpn", "foo",
3702 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003703 expectedNextProto: "foo",
3704 expectedNextProtoType: alpn,
3705 resumeSession: true,
3706 })
David Benjamin594e7d22016-03-17 17:49:56 -04003707 testCases = append(testCases, testCase{
3708 testType: serverTest,
3709 name: "ALPNServer-Decline",
3710 config: Config{
3711 NextProtos: []string{"foo", "bar", "baz"},
3712 },
3713 flags: []string{"-decline-alpn"},
3714 expectNoNextProto: true,
3715 resumeSession: true,
3716 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003717 // Test that the server prefers ALPN over NPN.
3718 testCases = append(testCases, testCase{
3719 testType: serverTest,
3720 name: "ALPNServer-Preferred",
3721 config: Config{
3722 NextProtos: []string{"foo", "bar", "baz"},
3723 },
3724 flags: []string{
3725 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3726 "-select-alpn", "foo",
3727 "-advertise-npn", "\x03foo\x03bar\x03baz",
3728 },
3729 expectedNextProto: "foo",
3730 expectedNextProtoType: alpn,
3731 resumeSession: true,
3732 })
3733 testCases = append(testCases, testCase{
3734 testType: serverTest,
3735 name: "ALPNServer-Preferred-Swapped",
3736 config: Config{
3737 NextProtos: []string{"foo", "bar", "baz"},
3738 Bugs: ProtocolBugs{
3739 SwapNPNAndALPN: true,
3740 },
3741 },
3742 flags: []string{
3743 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3744 "-select-alpn", "foo",
3745 "-advertise-npn", "\x03foo\x03bar\x03baz",
3746 },
3747 expectedNextProto: "foo",
3748 expectedNextProtoType: alpn,
3749 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003750 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003751 var emptyString string
3752 testCases = append(testCases, testCase{
3753 testType: clientTest,
3754 name: "ALPNClient-EmptyProtocolName",
3755 config: Config{
3756 NextProtos: []string{""},
3757 Bugs: ProtocolBugs{
3758 // A server returning an empty ALPN protocol
3759 // should be rejected.
3760 ALPNProtocol: &emptyString,
3761 },
3762 },
3763 flags: []string{
3764 "-advertise-alpn", "\x03foo",
3765 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003766 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003767 expectedError: ":PARSE_TLSEXT:",
3768 })
3769 testCases = append(testCases, testCase{
3770 testType: serverTest,
3771 name: "ALPNServer-EmptyProtocolName",
3772 config: Config{
3773 // A ClientHello containing an empty ALPN protocol
3774 // should be rejected.
3775 NextProtos: []string{"foo", "", "baz"},
3776 },
3777 flags: []string{
3778 "-select-alpn", "foo",
3779 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003780 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003781 expectedError: ":PARSE_TLSEXT:",
3782 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003783 // Test that negotiating both NPN and ALPN is forbidden.
3784 testCases = append(testCases, testCase{
3785 name: "NegotiateALPNAndNPN",
3786 config: Config{
3787 NextProtos: []string{"foo", "bar", "baz"},
3788 Bugs: ProtocolBugs{
3789 NegotiateALPNAndNPN: true,
3790 },
3791 },
3792 flags: []string{
3793 "-advertise-alpn", "\x03foo",
3794 "-select-next-proto", "foo",
3795 },
3796 shouldFail: true,
3797 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3798 })
3799 testCases = append(testCases, testCase{
3800 name: "NegotiateALPNAndNPN-Swapped",
3801 config: Config{
3802 NextProtos: []string{"foo", "bar", "baz"},
3803 Bugs: ProtocolBugs{
3804 NegotiateALPNAndNPN: true,
3805 SwapNPNAndALPN: true,
3806 },
3807 },
3808 flags: []string{
3809 "-advertise-alpn", "\x03foo",
3810 "-select-next-proto", "foo",
3811 },
3812 shouldFail: true,
3813 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3814 })
David Benjamin091c4b92015-10-26 13:33:21 -04003815 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3816 testCases = append(testCases, testCase{
3817 name: "DisableNPN",
3818 config: Config{
3819 NextProtos: []string{"foo"},
3820 },
3821 flags: []string{
3822 "-select-next-proto", "foo",
3823 "-disable-npn",
3824 },
3825 expectNoNextProto: true,
3826 })
Adam Langley38311732014-10-16 19:04:35 -07003827 // Resume with a corrupt ticket.
3828 testCases = append(testCases, testCase{
3829 testType: serverTest,
3830 name: "CorruptTicket",
3831 config: Config{
3832 Bugs: ProtocolBugs{
3833 CorruptTicket: true,
3834 },
3835 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003836 resumeSession: true,
3837 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003838 })
David Benjamind98452d2015-06-16 14:16:23 -04003839 // Test the ticket callback, with and without renewal.
3840 testCases = append(testCases, testCase{
3841 testType: serverTest,
3842 name: "TicketCallback",
3843 resumeSession: true,
3844 flags: []string{"-use-ticket-callback"},
3845 })
3846 testCases = append(testCases, testCase{
3847 testType: serverTest,
3848 name: "TicketCallback-Renew",
3849 config: Config{
3850 Bugs: ProtocolBugs{
3851 ExpectNewTicket: true,
3852 },
3853 },
3854 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3855 resumeSession: true,
3856 })
Adam Langley38311732014-10-16 19:04:35 -07003857 // Resume with an oversized session id.
3858 testCases = append(testCases, testCase{
3859 testType: serverTest,
3860 name: "OversizedSessionId",
3861 config: Config{
3862 Bugs: ProtocolBugs{
3863 OversizedSessionId: true,
3864 },
3865 },
3866 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003867 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003868 expectedError: ":DECODE_ERROR:",
3869 })
David Benjaminca6c8262014-11-15 19:06:08 -05003870 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3871 // are ignored.
3872 testCases = append(testCases, testCase{
3873 protocol: dtls,
3874 name: "SRTP-Client",
3875 config: Config{
3876 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3877 },
3878 flags: []string{
3879 "-srtp-profiles",
3880 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3881 },
3882 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3883 })
3884 testCases = append(testCases, testCase{
3885 protocol: dtls,
3886 testType: serverTest,
3887 name: "SRTP-Server",
3888 config: Config{
3889 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3890 },
3891 flags: []string{
3892 "-srtp-profiles",
3893 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3894 },
3895 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3896 })
3897 // Test that the MKI is ignored.
3898 testCases = append(testCases, testCase{
3899 protocol: dtls,
3900 testType: serverTest,
3901 name: "SRTP-Server-IgnoreMKI",
3902 config: Config{
3903 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3904 Bugs: ProtocolBugs{
3905 SRTPMasterKeyIdentifer: "bogus",
3906 },
3907 },
3908 flags: []string{
3909 "-srtp-profiles",
3910 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3911 },
3912 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3913 })
3914 // Test that SRTP isn't negotiated on the server if there were
3915 // no matching profiles.
3916 testCases = append(testCases, testCase{
3917 protocol: dtls,
3918 testType: serverTest,
3919 name: "SRTP-Server-NoMatch",
3920 config: Config{
3921 SRTPProtectionProfiles: []uint16{100, 101, 102},
3922 },
3923 flags: []string{
3924 "-srtp-profiles",
3925 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3926 },
3927 expectedSRTPProtectionProfile: 0,
3928 })
3929 // Test that the server returning an invalid SRTP profile is
3930 // flagged as an error by the client.
3931 testCases = append(testCases, testCase{
3932 protocol: dtls,
3933 name: "SRTP-Client-NoMatch",
3934 config: Config{
3935 Bugs: ProtocolBugs{
3936 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3937 },
3938 },
3939 flags: []string{
3940 "-srtp-profiles",
3941 "SRTP_AES128_CM_SHA1_80",
3942 },
3943 shouldFail: true,
3944 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3945 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003946 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003947 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003948 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003949 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003950 flags: []string{
3951 "-enable-signed-cert-timestamps",
3952 "-expect-signed-cert-timestamps",
3953 base64.StdEncoding.EncodeToString(testSCTList),
3954 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003955 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003956 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003957 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04003958 name: "SendSCTListOnResume",
3959 config: Config{
3960 Bugs: ProtocolBugs{
3961 SendSCTListOnResume: []byte("bogus"),
3962 },
3963 },
3964 flags: []string{
3965 "-enable-signed-cert-timestamps",
3966 "-expect-signed-cert-timestamps",
3967 base64.StdEncoding.EncodeToString(testSCTList),
3968 },
3969 resumeSession: true,
3970 })
3971 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003972 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003973 testType: serverTest,
3974 flags: []string{
3975 "-signed-cert-timestamps",
3976 base64.StdEncoding.EncodeToString(testSCTList),
3977 },
3978 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003979 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003980 })
3981 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003982 testType: clientTest,
3983 name: "ClientHelloPadding",
3984 config: Config{
3985 Bugs: ProtocolBugs{
3986 RequireClientHelloSize: 512,
3987 },
3988 },
3989 // This hostname just needs to be long enough to push the
3990 // ClientHello into F5's danger zone between 256 and 511 bytes
3991 // long.
3992 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3993 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003994
3995 // Extensions should not function in SSL 3.0.
3996 testCases = append(testCases, testCase{
3997 testType: serverTest,
3998 name: "SSLv3Extensions-NoALPN",
3999 config: Config{
4000 MaxVersion: VersionSSL30,
4001 NextProtos: []string{"foo", "bar", "baz"},
4002 },
4003 flags: []string{
4004 "-select-alpn", "foo",
4005 },
4006 expectNoNextProto: true,
4007 })
4008
4009 // Test session tickets separately as they follow a different codepath.
4010 testCases = append(testCases, testCase{
4011 testType: serverTest,
4012 name: "SSLv3Extensions-NoTickets",
4013 config: Config{
4014 MaxVersion: VersionSSL30,
4015 Bugs: ProtocolBugs{
4016 // Historically, session tickets in SSL 3.0
4017 // failed in different ways depending on whether
4018 // the client supported renegotiation_info.
4019 NoRenegotiationInfo: true,
4020 },
4021 },
4022 resumeSession: true,
4023 })
4024 testCases = append(testCases, testCase{
4025 testType: serverTest,
4026 name: "SSLv3Extensions-NoTickets2",
4027 config: Config{
4028 MaxVersion: VersionSSL30,
4029 },
4030 resumeSession: true,
4031 })
4032
4033 // But SSL 3.0 does send and process renegotiation_info.
4034 testCases = append(testCases, testCase{
4035 testType: serverTest,
4036 name: "SSLv3Extensions-RenegotiationInfo",
4037 config: Config{
4038 MaxVersion: VersionSSL30,
4039 Bugs: ProtocolBugs{
4040 RequireRenegotiationInfo: true,
4041 },
4042 },
4043 })
4044 testCases = append(testCases, testCase{
4045 testType: serverTest,
4046 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4047 config: Config{
4048 MaxVersion: VersionSSL30,
4049 Bugs: ProtocolBugs{
4050 NoRenegotiationInfo: true,
4051 SendRenegotiationSCSV: true,
4052 RequireRenegotiationInfo: true,
4053 },
4054 },
4055 })
David Benjamine78bfde2014-09-06 12:45:15 -04004056}
4057
David Benjamin01fe8202014-09-24 15:21:44 -04004058func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004059 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004060 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004061 protocols := []protocol{tls}
4062 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4063 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004064 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004065 for _, protocol := range protocols {
4066 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4067 if protocol == dtls {
4068 suffix += "-DTLS"
4069 }
4070
David Benjaminece3de92015-03-16 18:02:20 -04004071 if sessionVers.version == resumeVers.version {
4072 testCases = append(testCases, testCase{
4073 protocol: protocol,
4074 name: "Resume-Client" + suffix,
4075 resumeSession: true,
4076 config: Config{
4077 MaxVersion: sessionVers.version,
4078 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004079 },
David Benjaminece3de92015-03-16 18:02:20 -04004080 expectedVersion: sessionVers.version,
4081 expectedResumeVersion: resumeVers.version,
4082 })
4083 } else {
4084 testCases = append(testCases, testCase{
4085 protocol: protocol,
4086 name: "Resume-Client-Mismatch" + suffix,
4087 resumeSession: true,
4088 config: Config{
4089 MaxVersion: sessionVers.version,
4090 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004091 },
David Benjaminece3de92015-03-16 18:02:20 -04004092 expectedVersion: sessionVers.version,
4093 resumeConfig: &Config{
4094 MaxVersion: resumeVers.version,
4095 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4096 Bugs: ProtocolBugs{
4097 AllowSessionVersionMismatch: true,
4098 },
4099 },
4100 expectedResumeVersion: resumeVers.version,
4101 shouldFail: true,
4102 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4103 })
4104 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004105
4106 testCases = append(testCases, testCase{
4107 protocol: protocol,
4108 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004109 resumeSession: true,
4110 config: Config{
4111 MaxVersion: sessionVers.version,
4112 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4113 },
4114 expectedVersion: sessionVers.version,
4115 resumeConfig: &Config{
4116 MaxVersion: resumeVers.version,
4117 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4118 },
4119 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004120 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004121 expectedResumeVersion: resumeVers.version,
4122 })
4123
David Benjamin8b8c0062014-11-23 02:47:52 -05004124 testCases = append(testCases, testCase{
4125 protocol: protocol,
4126 testType: serverTest,
4127 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004128 resumeSession: true,
4129 config: Config{
4130 MaxVersion: sessionVers.version,
4131 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4132 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004133 expectedVersion: sessionVers.version,
4134 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004135 resumeConfig: &Config{
4136 MaxVersion: resumeVers.version,
4137 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4138 },
4139 expectedResumeVersion: resumeVers.version,
4140 })
4141 }
David Benjamin01fe8202014-09-24 15:21:44 -04004142 }
4143 }
David Benjaminece3de92015-03-16 18:02:20 -04004144
4145 testCases = append(testCases, testCase{
4146 name: "Resume-Client-CipherMismatch",
4147 resumeSession: true,
4148 config: Config{
4149 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4150 },
4151 resumeConfig: &Config{
4152 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4153 Bugs: ProtocolBugs{
4154 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4155 },
4156 },
4157 shouldFail: true,
4158 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4159 })
David Benjamin01fe8202014-09-24 15:21:44 -04004160}
4161
Adam Langley2ae77d22014-10-28 17:29:33 -07004162func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004163 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004164 testCases = append(testCases, testCase{
4165 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04004166 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004167 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004168 shouldFail: true,
4169 expectedError: ":NO_RENEGOTIATION:",
4170 expectedLocalError: "remote error: no renegotiation",
4171 })
Adam Langley5021b222015-06-12 18:27:58 -07004172 // The server shouldn't echo the renegotiation extension unless
4173 // requested by the client.
4174 testCases = append(testCases, testCase{
4175 testType: serverTest,
4176 name: "Renegotiate-Server-NoExt",
4177 config: Config{
4178 Bugs: ProtocolBugs{
4179 NoRenegotiationInfo: true,
4180 RequireRenegotiationInfo: true,
4181 },
4182 },
4183 shouldFail: true,
4184 expectedLocalError: "renegotiation extension missing",
4185 })
4186 // The renegotiation SCSV should be sufficient for the server to echo
4187 // the extension.
4188 testCases = append(testCases, testCase{
4189 testType: serverTest,
4190 name: "Renegotiate-Server-NoExt-SCSV",
4191 config: Config{
4192 Bugs: ProtocolBugs{
4193 NoRenegotiationInfo: true,
4194 SendRenegotiationSCSV: true,
4195 RequireRenegotiationInfo: true,
4196 },
4197 },
4198 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004199 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004200 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004201 config: Config{
4202 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004203 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004204 },
4205 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004206 renegotiate: 1,
4207 flags: []string{
4208 "-renegotiate-freely",
4209 "-expect-total-renegotiations", "1",
4210 },
David Benjamincdea40c2015-03-19 14:09:43 -04004211 })
4212 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004213 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004214 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004215 config: Config{
4216 Bugs: ProtocolBugs{
4217 EmptyRenegotiationInfo: true,
4218 },
4219 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004220 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004221 shouldFail: true,
4222 expectedError: ":RENEGOTIATION_MISMATCH:",
4223 })
4224 testCases = append(testCases, testCase{
4225 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004226 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004227 config: Config{
4228 Bugs: ProtocolBugs{
4229 BadRenegotiationInfo: true,
4230 },
4231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004232 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004233 shouldFail: true,
4234 expectedError: ":RENEGOTIATION_MISMATCH:",
4235 })
4236 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004237 name: "Renegotiate-Client-Downgrade",
4238 renegotiate: 1,
4239 config: Config{
4240 Bugs: ProtocolBugs{
4241 NoRenegotiationInfoAfterInitial: true,
4242 },
4243 },
4244 flags: []string{"-renegotiate-freely"},
4245 shouldFail: true,
4246 expectedError: ":RENEGOTIATION_MISMATCH:",
4247 })
4248 testCases = append(testCases, testCase{
4249 name: "Renegotiate-Client-Upgrade",
4250 renegotiate: 1,
4251 config: Config{
4252 Bugs: ProtocolBugs{
4253 NoRenegotiationInfoInInitial: true,
4254 },
4255 },
4256 flags: []string{"-renegotiate-freely"},
4257 shouldFail: true,
4258 expectedError: ":RENEGOTIATION_MISMATCH:",
4259 })
4260 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004261 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004262 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004263 config: Config{
4264 Bugs: ProtocolBugs{
4265 NoRenegotiationInfo: true,
4266 },
4267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004268 flags: []string{
4269 "-renegotiate-freely",
4270 "-expect-total-renegotiations", "1",
4271 },
David Benjamincff0b902015-05-15 23:09:47 -04004272 })
4273 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004274 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004275 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004276 config: Config{
4277 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4278 },
4279 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004280 flags: []string{
4281 "-renegotiate-freely",
4282 "-expect-total-renegotiations", "1",
4283 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004284 })
4285 testCases = append(testCases, testCase{
4286 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004287 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004288 config: Config{
4289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4290 },
4291 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004292 flags: []string{
4293 "-renegotiate-freely",
4294 "-expect-total-renegotiations", "1",
4295 },
David Benjaminb16346b2015-04-08 19:16:58 -04004296 })
4297 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004298 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004299 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004300 config: Config{
4301 MaxVersion: VersionTLS10,
4302 Bugs: ProtocolBugs{
4303 RequireSameRenegoClientVersion: true,
4304 },
4305 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004306 flags: []string{
4307 "-renegotiate-freely",
4308 "-expect-total-renegotiations", "1",
4309 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004310 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004311 testCases = append(testCases, testCase{
4312 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004313 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004314 config: Config{
4315 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4316 NextProtos: []string{"foo"},
4317 },
4318 flags: []string{
4319 "-false-start",
4320 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004321 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004322 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004323 },
4324 shimWritesFirst: true,
4325 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004326
4327 // Client-side renegotiation controls.
4328 testCases = append(testCases, testCase{
4329 name: "Renegotiate-Client-Forbidden-1",
4330 renegotiate: 1,
4331 shouldFail: true,
4332 expectedError: ":NO_RENEGOTIATION:",
4333 expectedLocalError: "remote error: no renegotiation",
4334 })
4335 testCases = append(testCases, testCase{
4336 name: "Renegotiate-Client-Once-1",
4337 renegotiate: 1,
4338 flags: []string{
4339 "-renegotiate-once",
4340 "-expect-total-renegotiations", "1",
4341 },
4342 })
4343 testCases = append(testCases, testCase{
4344 name: "Renegotiate-Client-Freely-1",
4345 renegotiate: 1,
4346 flags: []string{
4347 "-renegotiate-freely",
4348 "-expect-total-renegotiations", "1",
4349 },
4350 })
4351 testCases = append(testCases, testCase{
4352 name: "Renegotiate-Client-Once-2",
4353 renegotiate: 2,
4354 flags: []string{"-renegotiate-once"},
4355 shouldFail: true,
4356 expectedError: ":NO_RENEGOTIATION:",
4357 expectedLocalError: "remote error: no renegotiation",
4358 })
4359 testCases = append(testCases, testCase{
4360 name: "Renegotiate-Client-Freely-2",
4361 renegotiate: 2,
4362 flags: []string{
4363 "-renegotiate-freely",
4364 "-expect-total-renegotiations", "2",
4365 },
4366 })
Adam Langley27a0d082015-11-03 13:34:10 -08004367 testCases = append(testCases, testCase{
4368 name: "Renegotiate-Client-NoIgnore",
4369 config: Config{
4370 Bugs: ProtocolBugs{
4371 SendHelloRequestBeforeEveryAppDataRecord: true,
4372 },
4373 },
4374 shouldFail: true,
4375 expectedError: ":NO_RENEGOTIATION:",
4376 })
4377 testCases = append(testCases, testCase{
4378 name: "Renegotiate-Client-Ignore",
4379 config: Config{
4380 Bugs: ProtocolBugs{
4381 SendHelloRequestBeforeEveryAppDataRecord: true,
4382 },
4383 },
4384 flags: []string{
4385 "-renegotiate-ignore",
4386 "-expect-total-renegotiations", "0",
4387 },
4388 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004389}
4390
David Benjamin5e961c12014-11-07 01:48:35 -05004391func addDTLSReplayTests() {
4392 // Test that sequence number replays are detected.
4393 testCases = append(testCases, testCase{
4394 protocol: dtls,
4395 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004396 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004397 replayWrites: true,
4398 })
4399
David Benjamin8e6db492015-07-25 18:29:23 -04004400 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004401 // than the retransmit window.
4402 testCases = append(testCases, testCase{
4403 protocol: dtls,
4404 name: "DTLS-Replay-LargeGaps",
4405 config: Config{
4406 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004407 SequenceNumberMapping: func(in uint64) uint64 {
4408 return in * 127
4409 },
David Benjamin5e961c12014-11-07 01:48:35 -05004410 },
4411 },
David Benjamin8e6db492015-07-25 18:29:23 -04004412 messageCount: 200,
4413 replayWrites: true,
4414 })
4415
4416 // Test the incoming sequence number changing non-monotonically.
4417 testCases = append(testCases, testCase{
4418 protocol: dtls,
4419 name: "DTLS-Replay-NonMonotonic",
4420 config: Config{
4421 Bugs: ProtocolBugs{
4422 SequenceNumberMapping: func(in uint64) uint64 {
4423 return in ^ 31
4424 },
4425 },
4426 },
4427 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004428 replayWrites: true,
4429 })
4430}
4431
David Benjamin000800a2014-11-14 01:43:59 -05004432var testHashes = []struct {
4433 name string
4434 id uint8
4435}{
4436 {"SHA1", hashSHA1},
David Benjamin000800a2014-11-14 01:43:59 -05004437 {"SHA256", hashSHA256},
4438 {"SHA384", hashSHA384},
4439 {"SHA512", hashSHA512},
4440}
4441
4442func addSigningHashTests() {
4443 // Make sure each hash works. Include some fake hashes in the list and
4444 // ensure they're ignored.
4445 for _, hash := range testHashes {
4446 testCases = append(testCases, testCase{
4447 name: "SigningHash-ClientAuth-" + hash.name,
4448 config: Config{
4449 ClientAuth: RequireAnyClientCert,
4450 SignatureAndHashes: []signatureAndHash{
4451 {signatureRSA, 42},
4452 {signatureRSA, hash.id},
4453 {signatureRSA, 255},
4454 },
4455 },
4456 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004459 },
4460 })
4461
4462 testCases = append(testCases, testCase{
4463 testType: serverTest,
4464 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4465 config: Config{
4466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4467 SignatureAndHashes: []signatureAndHash{
4468 {signatureRSA, 42},
4469 {signatureRSA, hash.id},
4470 {signatureRSA, 255},
4471 },
4472 },
4473 })
David Benjamin6e807652015-11-02 12:02:20 -05004474
4475 testCases = append(testCases, testCase{
4476 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4477 config: Config{
4478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4479 SignatureAndHashes: []signatureAndHash{
4480 {signatureRSA, 42},
4481 {signatureRSA, hash.id},
4482 {signatureRSA, 255},
4483 },
4484 },
4485 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4486 })
David Benjamin000800a2014-11-14 01:43:59 -05004487 }
4488
4489 // Test that hash resolution takes the signature type into account.
4490 testCases = append(testCases, testCase{
4491 name: "SigningHash-ClientAuth-SignatureType",
4492 config: Config{
4493 ClientAuth: RequireAnyClientCert,
4494 SignatureAndHashes: []signatureAndHash{
4495 {signatureECDSA, hashSHA512},
4496 {signatureRSA, hashSHA384},
4497 {signatureECDSA, hashSHA1},
4498 },
4499 },
4500 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004501 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4502 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004503 },
4504 })
4505
4506 testCases = append(testCases, testCase{
4507 testType: serverTest,
4508 name: "SigningHash-ServerKeyExchange-SignatureType",
4509 config: Config{
4510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4511 SignatureAndHashes: []signatureAndHash{
4512 {signatureECDSA, hashSHA512},
4513 {signatureRSA, hashSHA384},
4514 {signatureECDSA, hashSHA1},
4515 },
4516 },
4517 })
4518
4519 // Test that, if the list is missing, the peer falls back to SHA-1.
4520 testCases = append(testCases, testCase{
4521 name: "SigningHash-ClientAuth-Fallback",
4522 config: Config{
4523 ClientAuth: RequireAnyClientCert,
4524 SignatureAndHashes: []signatureAndHash{
4525 {signatureRSA, hashSHA1},
4526 },
4527 Bugs: ProtocolBugs{
4528 NoSignatureAndHashes: true,
4529 },
4530 },
4531 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004532 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4533 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004534 },
4535 })
4536
4537 testCases = append(testCases, testCase{
4538 testType: serverTest,
4539 name: "SigningHash-ServerKeyExchange-Fallback",
4540 config: Config{
4541 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4542 SignatureAndHashes: []signatureAndHash{
4543 {signatureRSA, hashSHA1},
4544 },
4545 Bugs: ProtocolBugs{
4546 NoSignatureAndHashes: true,
4547 },
4548 },
4549 })
David Benjamin72dc7832015-03-16 17:49:43 -04004550
4551 // Test that hash preferences are enforced. BoringSSL defaults to
4552 // rejecting MD5 signatures.
4553 testCases = append(testCases, testCase{
4554 testType: serverTest,
4555 name: "SigningHash-ClientAuth-Enforced",
4556 config: Config{
4557 Certificates: []Certificate{rsaCertificate},
4558 SignatureAndHashes: []signatureAndHash{
4559 {signatureRSA, hashMD5},
4560 // Advertise SHA-1 so the handshake will
4561 // proceed, but the shim's preferences will be
4562 // ignored in CertificateVerify generation, so
4563 // MD5 will be chosen.
4564 {signatureRSA, hashSHA1},
4565 },
4566 Bugs: ProtocolBugs{
4567 IgnorePeerSignatureAlgorithmPreferences: true,
4568 },
4569 },
4570 flags: []string{"-require-any-client-certificate"},
4571 shouldFail: true,
4572 expectedError: ":WRONG_SIGNATURE_TYPE:",
4573 })
4574
4575 testCases = append(testCases, testCase{
4576 name: "SigningHash-ServerKeyExchange-Enforced",
4577 config: Config{
4578 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4579 SignatureAndHashes: []signatureAndHash{
4580 {signatureRSA, hashMD5},
4581 },
4582 Bugs: ProtocolBugs{
4583 IgnorePeerSignatureAlgorithmPreferences: true,
4584 },
4585 },
4586 shouldFail: true,
4587 expectedError: ":WRONG_SIGNATURE_TYPE:",
4588 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004589
4590 // Test that the agreed upon digest respects the client preferences and
4591 // the server digests.
4592 testCases = append(testCases, testCase{
4593 name: "Agree-Digest-Fallback",
4594 config: Config{
4595 ClientAuth: RequireAnyClientCert,
4596 SignatureAndHashes: []signatureAndHash{
4597 {signatureRSA, hashSHA512},
4598 {signatureRSA, hashSHA1},
4599 },
4600 },
4601 flags: []string{
4602 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4603 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4604 },
4605 digestPrefs: "SHA256",
4606 expectedClientCertSignatureHash: hashSHA1,
4607 })
4608 testCases = append(testCases, testCase{
4609 name: "Agree-Digest-SHA256",
4610 config: Config{
4611 ClientAuth: RequireAnyClientCert,
4612 SignatureAndHashes: []signatureAndHash{
4613 {signatureRSA, hashSHA1},
4614 {signatureRSA, hashSHA256},
4615 },
4616 },
4617 flags: []string{
4618 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4619 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4620 },
4621 digestPrefs: "SHA256,SHA1",
4622 expectedClientCertSignatureHash: hashSHA256,
4623 })
4624 testCases = append(testCases, testCase{
4625 name: "Agree-Digest-SHA1",
4626 config: Config{
4627 ClientAuth: RequireAnyClientCert,
4628 SignatureAndHashes: []signatureAndHash{
4629 {signatureRSA, hashSHA1},
4630 },
4631 },
4632 flags: []string{
4633 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4634 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4635 },
4636 digestPrefs: "SHA512,SHA256,SHA1",
4637 expectedClientCertSignatureHash: hashSHA1,
4638 })
4639 testCases = append(testCases, testCase{
4640 name: "Agree-Digest-Default",
4641 config: Config{
4642 ClientAuth: RequireAnyClientCert,
4643 SignatureAndHashes: []signatureAndHash{
4644 {signatureRSA, hashSHA256},
4645 {signatureECDSA, hashSHA256},
4646 {signatureRSA, hashSHA1},
4647 {signatureECDSA, hashSHA1},
4648 },
4649 },
4650 flags: []string{
4651 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4652 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4653 },
4654 expectedClientCertSignatureHash: hashSHA256,
4655 })
David Benjamin000800a2014-11-14 01:43:59 -05004656}
4657
David Benjamin83f90402015-01-27 01:09:43 -05004658// timeouts is the retransmit schedule for BoringSSL. It doubles and
4659// caps at 60 seconds. On the 13th timeout, it gives up.
4660var timeouts = []time.Duration{
4661 1 * time.Second,
4662 2 * time.Second,
4663 4 * time.Second,
4664 8 * time.Second,
4665 16 * time.Second,
4666 32 * time.Second,
4667 60 * time.Second,
4668 60 * time.Second,
4669 60 * time.Second,
4670 60 * time.Second,
4671 60 * time.Second,
4672 60 * time.Second,
4673 60 * time.Second,
4674}
4675
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004676// shortTimeouts is an alternate set of timeouts which would occur if the
4677// initial timeout duration was set to 250ms.
4678var shortTimeouts = []time.Duration{
4679 250 * time.Millisecond,
4680 500 * time.Millisecond,
4681 1 * time.Second,
4682 2 * time.Second,
4683 4 * time.Second,
4684 8 * time.Second,
4685 16 * time.Second,
4686 32 * time.Second,
4687 60 * time.Second,
4688 60 * time.Second,
4689 60 * time.Second,
4690 60 * time.Second,
4691 60 * time.Second,
4692}
4693
David Benjamin83f90402015-01-27 01:09:43 -05004694func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04004695 // These tests work by coordinating some behavior on both the shim and
4696 // the runner.
4697 //
4698 // TimeoutSchedule configures the runner to send a series of timeout
4699 // opcodes to the shim (see packetAdaptor) immediately before reading
4700 // each peer handshake flight N. The timeout opcode both simulates a
4701 // timeout in the shim and acts as a synchronization point to help the
4702 // runner bracket each handshake flight.
4703 //
4704 // We assume the shim does not read from the channel eagerly. It must
4705 // first wait until it has sent flight N and is ready to receive
4706 // handshake flight N+1. At this point, it will process the timeout
4707 // opcode. It must then immediately respond with a timeout ACK and act
4708 // as if the shim was idle for the specified amount of time.
4709 //
4710 // The runner then drops all packets received before the ACK and
4711 // continues waiting for flight N. This ordering results in one attempt
4712 // at sending flight N to be dropped. For the test to complete, the
4713 // shim must send flight N again, testing that the shim implements DTLS
4714 // retransmit on a timeout.
4715
4716 for _, async := range []bool{true, false} {
4717 var tests []testCase
4718
4719 // Test that this is indeed the timeout schedule. Stress all
4720 // four patterns of handshake.
4721 for i := 1; i < len(timeouts); i++ {
4722 number := strconv.Itoa(i)
4723 tests = append(tests, testCase{
4724 protocol: dtls,
4725 name: "DTLS-Retransmit-Client-" + number,
4726 config: Config{
4727 Bugs: ProtocolBugs{
4728 TimeoutSchedule: timeouts[:i],
4729 },
4730 },
4731 resumeSession: true,
4732 })
4733 tests = append(tests, testCase{
4734 protocol: dtls,
4735 testType: serverTest,
4736 name: "DTLS-Retransmit-Server-" + number,
4737 config: Config{
4738 Bugs: ProtocolBugs{
4739 TimeoutSchedule: timeouts[:i],
4740 },
4741 },
4742 resumeSession: true,
4743 })
4744 }
4745
4746 // Test that exceeding the timeout schedule hits a read
4747 // timeout.
4748 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05004749 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04004750 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05004751 config: Config{
4752 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04004753 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05004754 },
4755 },
4756 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04004757 shouldFail: true,
4758 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05004759 })
David Benjamin585d7a42016-06-02 14:58:00 -04004760
4761 if async {
4762 // Test that timeout handling has a fudge factor, due to API
4763 // problems.
4764 tests = append(tests, testCase{
4765 protocol: dtls,
4766 name: "DTLS-Retransmit-Fudge",
4767 config: Config{
4768 Bugs: ProtocolBugs{
4769 TimeoutSchedule: []time.Duration{
4770 timeouts[0] - 10*time.Millisecond,
4771 },
4772 },
4773 },
4774 resumeSession: true,
4775 })
4776 }
4777
4778 // Test that the final Finished retransmitting isn't
4779 // duplicated if the peer badly fragments everything.
4780 tests = append(tests, testCase{
4781 testType: serverTest,
4782 protocol: dtls,
4783 name: "DTLS-Retransmit-Fragmented",
4784 config: Config{
4785 Bugs: ProtocolBugs{
4786 TimeoutSchedule: []time.Duration{timeouts[0]},
4787 MaxHandshakeRecordLength: 2,
4788 },
4789 },
4790 })
4791
4792 // Test the timeout schedule when a shorter initial timeout duration is set.
4793 tests = append(tests, testCase{
4794 protocol: dtls,
4795 name: "DTLS-Retransmit-Short-Client",
4796 config: Config{
4797 Bugs: ProtocolBugs{
4798 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
4799 },
4800 },
4801 resumeSession: true,
4802 flags: []string{"-initial-timeout-duration-ms", "250"},
4803 })
4804 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05004805 protocol: dtls,
4806 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04004807 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05004808 config: Config{
4809 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04004810 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05004811 },
4812 },
4813 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04004814 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05004815 })
David Benjamin585d7a42016-06-02 14:58:00 -04004816
4817 for _, test := range tests {
4818 if async {
4819 test.name += "-Async"
4820 test.flags = append(test.flags, "-async")
4821 }
4822
4823 testCases = append(testCases, test)
4824 }
David Benjamin83f90402015-01-27 01:09:43 -05004825 }
David Benjamin83f90402015-01-27 01:09:43 -05004826}
4827
David Benjaminc565ebb2015-04-03 04:06:36 -04004828func addExportKeyingMaterialTests() {
4829 for _, vers := range tlsVersions {
4830 if vers.version == VersionSSL30 {
4831 continue
4832 }
4833 testCases = append(testCases, testCase{
4834 name: "ExportKeyingMaterial-" + vers.name,
4835 config: Config{
4836 MaxVersion: vers.version,
4837 },
4838 exportKeyingMaterial: 1024,
4839 exportLabel: "label",
4840 exportContext: "context",
4841 useExportContext: true,
4842 })
4843 testCases = append(testCases, testCase{
4844 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4845 config: Config{
4846 MaxVersion: vers.version,
4847 },
4848 exportKeyingMaterial: 1024,
4849 })
4850 testCases = append(testCases, testCase{
4851 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4852 config: Config{
4853 MaxVersion: vers.version,
4854 },
4855 exportKeyingMaterial: 1024,
4856 useExportContext: true,
4857 })
4858 testCases = append(testCases, testCase{
4859 name: "ExportKeyingMaterial-Small-" + vers.name,
4860 config: Config{
4861 MaxVersion: vers.version,
4862 },
4863 exportKeyingMaterial: 1,
4864 exportLabel: "label",
4865 exportContext: "context",
4866 useExportContext: true,
4867 })
4868 }
4869 testCases = append(testCases, testCase{
4870 name: "ExportKeyingMaterial-SSL3",
4871 config: Config{
4872 MaxVersion: VersionSSL30,
4873 },
4874 exportKeyingMaterial: 1024,
4875 exportLabel: "label",
4876 exportContext: "context",
4877 useExportContext: true,
4878 shouldFail: true,
4879 expectedError: "failed to export keying material",
4880 })
4881}
4882
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004883func addTLSUniqueTests() {
4884 for _, isClient := range []bool{false, true} {
4885 for _, isResumption := range []bool{false, true} {
4886 for _, hasEMS := range []bool{false, true} {
4887 var suffix string
4888 if isResumption {
4889 suffix = "Resume-"
4890 } else {
4891 suffix = "Full-"
4892 }
4893
4894 if hasEMS {
4895 suffix += "EMS-"
4896 } else {
4897 suffix += "NoEMS-"
4898 }
4899
4900 if isClient {
4901 suffix += "Client"
4902 } else {
4903 suffix += "Server"
4904 }
4905
4906 test := testCase{
4907 name: "TLSUnique-" + suffix,
4908 testTLSUnique: true,
4909 config: Config{
4910 Bugs: ProtocolBugs{
4911 NoExtendedMasterSecret: !hasEMS,
4912 },
4913 },
4914 }
4915
4916 if isResumption {
4917 test.resumeSession = true
4918 test.resumeConfig = &Config{
4919 Bugs: ProtocolBugs{
4920 NoExtendedMasterSecret: !hasEMS,
4921 },
4922 }
4923 }
4924
4925 if isResumption && !hasEMS {
4926 test.shouldFail = true
4927 test.expectedError = "failed to get tls-unique"
4928 }
4929
4930 testCases = append(testCases, test)
4931 }
4932 }
4933 }
4934}
4935
Adam Langley09505632015-07-30 18:10:13 -07004936func addCustomExtensionTests() {
4937 expectedContents := "custom extension"
4938 emptyString := ""
4939
4940 for _, isClient := range []bool{false, true} {
4941 suffix := "Server"
4942 flag := "-enable-server-custom-extension"
4943 testType := serverTest
4944 if isClient {
4945 suffix = "Client"
4946 flag = "-enable-client-custom-extension"
4947 testType = clientTest
4948 }
4949
4950 testCases = append(testCases, testCase{
4951 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004952 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004953 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004954 Bugs: ProtocolBugs{
4955 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004956 ExpectedCustomExtension: &expectedContents,
4957 },
4958 },
4959 flags: []string{flag},
4960 })
4961
4962 // If the parse callback fails, the handshake should also fail.
4963 testCases = append(testCases, testCase{
4964 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004965 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004966 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004967 Bugs: ProtocolBugs{
4968 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004969 ExpectedCustomExtension: &expectedContents,
4970 },
4971 },
David Benjamin399e7c92015-07-30 23:01:27 -04004972 flags: []string{flag},
4973 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004974 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4975 })
4976
4977 // If the add callback fails, the handshake should also fail.
4978 testCases = append(testCases, testCase{
4979 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004980 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004981 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004982 Bugs: ProtocolBugs{
4983 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004984 ExpectedCustomExtension: &expectedContents,
4985 },
4986 },
David Benjamin399e7c92015-07-30 23:01:27 -04004987 flags: []string{flag, "-custom-extension-fail-add"},
4988 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004989 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4990 })
4991
4992 // If the add callback returns zero, no extension should be
4993 // added.
4994 skipCustomExtension := expectedContents
4995 if isClient {
4996 // For the case where the client skips sending the
4997 // custom extension, the server must not “echo” it.
4998 skipCustomExtension = ""
4999 }
5000 testCases = append(testCases, testCase{
5001 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005002 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005003 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04005004 Bugs: ProtocolBugs{
5005 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005006 ExpectedCustomExtension: &emptyString,
5007 },
5008 },
5009 flags: []string{flag, "-custom-extension-skip"},
5010 })
5011 }
5012
5013 // The custom extension add callback should not be called if the client
5014 // doesn't send the extension.
5015 testCases = append(testCases, testCase{
5016 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005017 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005018 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04005019 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005020 ExpectedCustomExtension: &emptyString,
5021 },
5022 },
5023 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5024 })
Adam Langley2deb9842015-08-07 11:15:37 -07005025
5026 // Test an unknown extension from the server.
5027 testCases = append(testCases, testCase{
5028 testType: clientTest,
5029 name: "UnknownExtension-Client",
5030 config: Config{
5031 Bugs: ProtocolBugs{
5032 CustomExtension: expectedContents,
5033 },
5034 },
5035 shouldFail: true,
5036 expectedError: ":UNEXPECTED_EXTENSION:",
5037 })
Adam Langley09505632015-07-30 18:10:13 -07005038}
5039
David Benjaminb36a3952015-12-01 18:53:13 -05005040func addRSAClientKeyExchangeTests() {
5041 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5042 testCases = append(testCases, testCase{
5043 testType: serverTest,
5044 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5045 config: Config{
5046 // Ensure the ClientHello version and final
5047 // version are different, to detect if the
5048 // server uses the wrong one.
5049 MaxVersion: VersionTLS11,
5050 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5051 Bugs: ProtocolBugs{
5052 BadRSAClientKeyExchange: bad,
5053 },
5054 },
5055 shouldFail: true,
5056 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5057 })
5058 }
5059}
5060
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005061var testCurves = []struct {
5062 name string
5063 id CurveID
5064}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005065 {"P-256", CurveP256},
5066 {"P-384", CurveP384},
5067 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005068 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005069}
5070
5071func addCurveTests() {
5072 for _, curve := range testCurves {
5073 testCases = append(testCases, testCase{
5074 name: "CurveTest-Client-" + curve.name,
5075 config: Config{
5076 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5077 CurvePreferences: []CurveID{curve.id},
5078 },
5079 flags: []string{"-enable-all-curves"},
5080 })
5081 testCases = append(testCases, testCase{
5082 testType: serverTest,
5083 name: "CurveTest-Server-" + curve.name,
5084 config: Config{
5085 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5086 CurvePreferences: []CurveID{curve.id},
5087 },
5088 flags: []string{"-enable-all-curves"},
5089 })
5090 }
David Benjamin241ae832016-01-15 03:04:54 -05005091
5092 // The server must be tolerant to bogus curves.
5093 const bogusCurve = 0x1234
5094 testCases = append(testCases, testCase{
5095 testType: serverTest,
5096 name: "UnknownCurve",
5097 config: Config{
5098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5099 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5100 },
5101 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005102}
5103
Matt Braithwaite54217e42016-06-13 13:03:47 -07005104func addCECPQ1Tests() {
5105 testCases = append(testCases, testCase{
5106 testType: clientTest,
5107 name: "CECPQ1-Client-BadX25519Part",
5108 config: Config{
5109 MinVersion: VersionTLS12,
5110 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5111 Bugs: ProtocolBugs{
5112 CECPQ1BadX25519Part: true,
5113 },
5114 },
5115 flags: []string{"-cipher", "kCECPQ1"},
5116 shouldFail: true,
5117 expectedLocalError: "local error: bad record MAC",
5118 })
5119 testCases = append(testCases, testCase{
5120 testType: clientTest,
5121 name: "CECPQ1-Client-BadNewhopePart",
5122 config: Config{
5123 MinVersion: VersionTLS12,
5124 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5125 Bugs: ProtocolBugs{
5126 CECPQ1BadNewhopePart: true,
5127 },
5128 },
5129 flags: []string{"-cipher", "kCECPQ1"},
5130 shouldFail: true,
5131 expectedLocalError: "local error: bad record MAC",
5132 })
5133 testCases = append(testCases, testCase{
5134 testType: serverTest,
5135 name: "CECPQ1-Server-BadX25519Part",
5136 config: Config{
5137 MinVersion: VersionTLS12,
5138 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5139 Bugs: ProtocolBugs{
5140 CECPQ1BadX25519Part: true,
5141 },
5142 },
5143 flags: []string{"-cipher", "kCECPQ1"},
5144 shouldFail: true,
5145 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5146 })
5147 testCases = append(testCases, testCase{
5148 testType: serverTest,
5149 name: "CECPQ1-Server-BadNewhopePart",
5150 config: Config{
5151 MinVersion: VersionTLS12,
5152 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5153 Bugs: ProtocolBugs{
5154 CECPQ1BadNewhopePart: true,
5155 },
5156 },
5157 flags: []string{"-cipher", "kCECPQ1"},
5158 shouldFail: true,
5159 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5160 })
5161}
5162
David Benjamin4cc36ad2015-12-19 14:23:26 -05005163func addKeyExchangeInfoTests() {
5164 testCases = append(testCases, testCase{
5165 name: "KeyExchangeInfo-RSA-Client",
5166 config: Config{
5167 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5168 },
5169 // key.pem is a 1024-bit RSA key.
5170 flags: []string{"-expect-key-exchange-info", "1024"},
5171 })
5172 // TODO(davidben): key_exchange_info doesn't work for plain RSA on the
5173 // server. Either fix this or change the API as it's not very useful in
5174 // this case.
5175
5176 testCases = append(testCases, testCase{
5177 name: "KeyExchangeInfo-DHE-Client",
5178 config: Config{
5179 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5180 Bugs: ProtocolBugs{
5181 // This is a 1234-bit prime number, generated
5182 // with:
5183 // openssl gendh 1234 | openssl asn1parse -i
5184 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5185 },
5186 },
5187 flags: []string{"-expect-key-exchange-info", "1234"},
5188 })
5189 testCases = append(testCases, testCase{
5190 testType: serverTest,
5191 name: "KeyExchangeInfo-DHE-Server",
5192 config: Config{
5193 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5194 },
5195 // bssl_shim as a server configures a 2048-bit DHE group.
5196 flags: []string{"-expect-key-exchange-info", "2048"},
5197 })
5198
5199 testCases = append(testCases, testCase{
5200 name: "KeyExchangeInfo-ECDHE-Client",
5201 config: Config{
5202 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5203 CurvePreferences: []CurveID{CurveX25519},
5204 },
5205 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5206 })
5207 testCases = append(testCases, testCase{
5208 testType: serverTest,
5209 name: "KeyExchangeInfo-ECDHE-Server",
5210 config: Config{
5211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5212 CurvePreferences: []CurveID{CurveX25519},
5213 },
5214 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
5215 })
5216}
5217
Adam Langley7c803a62015-06-15 15:35:05 -07005218func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005219 defer wg.Done()
5220
5221 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005222 var err error
5223
5224 if *mallocTest < 0 {
5225 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005226 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005227 } else {
5228 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5229 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005230 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005231 if err != nil {
5232 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5233 }
5234 break
5235 }
5236 }
5237 }
Adam Langley95c29f32014-06-20 12:00:00 -07005238 statusChan <- statusMsg{test: test, err: err}
5239 }
5240}
5241
5242type statusMsg struct {
5243 test *testCase
5244 started bool
5245 err error
5246}
5247
David Benjamin5f237bc2015-02-11 17:14:15 -05005248func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005249 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005250
David Benjamin5f237bc2015-02-11 17:14:15 -05005251 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005252 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005253 if !*pipe {
5254 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005255 var erase string
5256 for i := 0; i < lineLen; i++ {
5257 erase += "\b \b"
5258 }
5259 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005260 }
5261
Adam Langley95c29f32014-06-20 12:00:00 -07005262 if msg.started {
5263 started++
5264 } else {
5265 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005266
5267 if msg.err != nil {
5268 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5269 failed++
5270 testOutput.addResult(msg.test.name, "FAIL")
5271 } else {
5272 if *pipe {
5273 // Print each test instead of a status line.
5274 fmt.Printf("PASSED (%s)\n", msg.test.name)
5275 }
5276 testOutput.addResult(msg.test.name, "PASS")
5277 }
Adam Langley95c29f32014-06-20 12:00:00 -07005278 }
5279
David Benjamin5f237bc2015-02-11 17:14:15 -05005280 if !*pipe {
5281 // Print a new status line.
5282 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5283 lineLen = len(line)
5284 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005285 }
Adam Langley95c29f32014-06-20 12:00:00 -07005286 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005287
5288 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005289}
5290
5291func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005292 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005293 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005294
Adam Langley7c803a62015-06-15 15:35:05 -07005295 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005296 addCipherSuiteTests()
5297 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005298 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005299 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005300 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005301 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005302 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005303 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005304 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005305 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005306 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005307 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005308 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05005309 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05005310 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005311 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005312 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005313 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005314 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005315 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07005316 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005317 addKeyExchangeInfoTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04005318 for _, async := range []bool{false, true} {
5319 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04005320 for _, protocol := range []protocol{tls, dtls} {
5321 addStateMachineCoverageTests(async, splitHandshake, protocol)
5322 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005323 }
5324 }
Adam Langley95c29f32014-06-20 12:00:00 -07005325
5326 var wg sync.WaitGroup
5327
Adam Langley7c803a62015-06-15 15:35:05 -07005328 statusChan := make(chan statusMsg, *numWorkers)
5329 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005330 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005331
David Benjamin025b3d32014-07-01 19:53:04 -04005332 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005333
Adam Langley7c803a62015-06-15 15:35:05 -07005334 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005335 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005336 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005337 }
5338
David Benjamin270f0a72016-03-17 14:41:36 -04005339 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005340 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005341 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005342 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005343 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005344 }
5345 }
David Benjamin270f0a72016-03-17 14:41:36 -04005346 if !foundTest {
5347 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5348 os.Exit(1)
5349 }
Adam Langley95c29f32014-06-20 12:00:00 -07005350
5351 close(testChan)
5352 wg.Wait()
5353 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005354 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005355
5356 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005357
5358 if *jsonOutput != "" {
5359 if err := testOutput.writeTo(*jsonOutput); err != nil {
5360 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5361 }
5362 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005363
5364 if !testOutput.allPassed {
5365 os.Exit(1)
5366 }
Adam Langley95c29f32014-06-20 12:00:00 -07005367}