blob: 64ec39f7d6fe85754ffea1e6335ecb586562e4ea [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
Nick Harper60edffd2016-06-21 15:19:24 -0700146type testCert int
147
148const (
149 testCertRSA testCert = iota
150 testCertECDSA
151)
152
153func getRunnerCertificate(t testCert) Certificate {
154 switch t {
155 case testCertRSA:
156 return getRSACertificate()
157 case testCertECDSA:
158 return getECDSACertificate()
159 default:
160 panic("Unknown test certificate")
161 }
162}
163
164func getShimCertificate(t testCert) string {
165 switch t {
166 case testCertRSA:
167 return rsaCertificateFile
168 case testCertECDSA:
169 return ecdsaCertificateFile
170 default:
171 panic("Unknown test certificate")
172 }
173}
174
175func getShimKey(t testCert) string {
176 switch t {
177 case testCertRSA:
178 return rsaKeyFile
179 case testCertECDSA:
180 return ecdsaKeyFile
181 default:
182 panic("Unknown test certificate")
183 }
184}
185
Adam Langley95c29f32014-06-20 12:00:00 -0700186type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400187 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400188 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700189 name string
190 config Config
191 shouldFail bool
192 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700193 // expectedLocalError, if not empty, contains a substring that must be
194 // found in the local error.
195 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400196 // expectedVersion, if non-zero, specifies the TLS version that must be
197 // negotiated.
198 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400199 // expectedResumeVersion, if non-zero, specifies the TLS version that
200 // must be negotiated on resumption. If zero, expectedVersion is used.
201 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400202 // expectedCipher, if non-zero, specifies the TLS cipher suite that
203 // should be negotiated.
204 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400205 // expectChannelID controls whether the connection should have
206 // negotiated a Channel ID with channelIDKey.
207 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400208 // expectedNextProto controls whether the connection should
209 // negotiate a next protocol via NPN or ALPN.
210 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400211 // expectNoNextProto, if true, means that no next protocol should be
212 // negotiated.
213 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400214 // expectedNextProtoType, if non-zero, is the expected next
215 // protocol negotiation mechanism.
216 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500217 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
218 // should be negotiated. If zero, none should be negotiated.
219 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100220 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
221 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100222 // expectedSCTList, if not nil, is the expected SCT list to be received.
223 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700224 // expectedPeerSignatureAlgorithm, if not zero, is the signature
225 // algorithm that the peer should have used in the handshake.
226 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700227 // messageLen is the length, in bytes, of the test message that will be
228 // sent.
229 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400230 // messageCount is the number of test messages that will be sent.
231 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400232 // digestPrefs is the list of digest preferences from the client.
233 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400234 // certFile is the path to the certificate to use for the server.
235 certFile string
236 // keyFile is the path to the private key to use for the server.
237 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400238 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400239 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400240 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700241 // expectResumeRejected, if true, specifies that the attempted
242 // resumption must be rejected by the client. This is only valid for a
243 // serverTest.
244 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400245 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500246 // resumption. Unless newSessionsOnResume is set,
247 // SessionTicketKey, ServerSessionCache, and
248 // ClientSessionCache are copied from the initial connection's
249 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400250 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500251 // newSessionsOnResume, if true, will cause resumeConfig to
252 // use a different session resumption context.
253 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400254 // noSessionCache, if true, will cause the server to run without a
255 // session cache.
256 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400257 // sendPrefix sends a prefix on the socket before actually performing a
258 // handshake.
259 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400260 // shimWritesFirst controls whether the shim sends an initial "hello"
261 // message before doing a roundtrip with the runner.
262 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400263 // shimShutsDown, if true, runs a test where the shim shuts down the
264 // connection immediately after the handshake rather than echoing
265 // messages from the runner.
266 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400267 // renegotiate indicates the number of times the connection should be
268 // renegotiated during the exchange.
269 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700270 // renegotiateCiphers is a list of ciphersuite ids that will be
271 // switched in just before renegotiation.
272 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500273 // replayWrites, if true, configures the underlying transport
274 // to replay every write it makes in DTLS tests.
275 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500276 // damageFirstWrite, if true, configures the underlying transport to
277 // damage the final byte of the first application data write.
278 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400279 // exportKeyingMaterial, if non-zero, configures the test to exchange
280 // keying material and verify they match.
281 exportKeyingMaterial int
282 exportLabel string
283 exportContext string
284 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400285 // flags, if not empty, contains a list of command-line flags that will
286 // be passed to the shim program.
287 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700288 // testTLSUnique, if true, causes the shim to send the tls-unique value
289 // which will be compared against the expected value.
290 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400291 // sendEmptyRecords is the number of consecutive empty records to send
292 // before and after the test message.
293 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400294 // sendWarningAlerts is the number of consecutive warning alerts to send
295 // before and after the test message.
296 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400297 // expectMessageDropped, if true, means the test message is expected to
298 // be dropped by the client rather than echoed back.
299 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700300}
301
Adam Langley7c803a62015-06-15 15:35:05 -0700302var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700303
David Benjamin9867b7d2016-03-01 23:25:48 -0500304func writeTranscript(test *testCase, isResume bool, data []byte) {
305 if len(data) == 0 {
306 return
307 }
308
309 protocol := "tls"
310 if test.protocol == dtls {
311 protocol = "dtls"
312 }
313
314 side := "client"
315 if test.testType == serverTest {
316 side = "server"
317 }
318
319 dir := path.Join(*transcriptDir, protocol, side)
320 if err := os.MkdirAll(dir, 0755); err != nil {
321 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
322 return
323 }
324
325 name := test.name
326 if isResume {
327 name += "-Resume"
328 } else {
329 name += "-Normal"
330 }
331
332 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
333 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
334 }
335}
336
David Benjamin3ed59772016-03-08 12:50:21 -0500337// A timeoutConn implements an idle timeout on each Read and Write operation.
338type timeoutConn struct {
339 net.Conn
340 timeout time.Duration
341}
342
343func (t *timeoutConn) Read(b []byte) (int, error) {
344 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
345 return 0, err
346 }
347 return t.Conn.Read(b)
348}
349
350func (t *timeoutConn) Write(b []byte) (int, error) {
351 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
352 return 0, err
353 }
354 return t.Conn.Write(b)
355}
356
David Benjamin8e6db492015-07-25 18:29:23 -0400357func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400358 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500359
David Benjamin6fd297b2014-08-11 18:43:38 -0400360 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500361 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
362 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500363 }
364
David Benjamin9867b7d2016-03-01 23:25:48 -0500365 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500366 local, peer := "client", "server"
367 if test.testType == clientTest {
368 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500369 }
David Benjaminebda9b32015-11-02 15:33:18 -0500370 connDebug := &recordingConn{
371 Conn: conn,
372 isDatagram: test.protocol == dtls,
373 local: local,
374 peer: peer,
375 }
376 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500377 if *flagDebug {
378 defer connDebug.WriteTo(os.Stdout)
379 }
380 if len(*transcriptDir) != 0 {
381 defer func() {
382 writeTranscript(test, isResume, connDebug.Transcript())
383 }()
384 }
David Benjaminebda9b32015-11-02 15:33:18 -0500385
386 if config.Bugs.PacketAdaptor != nil {
387 config.Bugs.PacketAdaptor.debug = connDebug
388 }
389 }
390
391 if test.replayWrites {
392 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400393 }
394
David Benjamin3ed59772016-03-08 12:50:21 -0500395 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500396 if test.damageFirstWrite {
397 connDamage = newDamageAdaptor(conn)
398 conn = connDamage
399 }
400
David Benjamin6fd297b2014-08-11 18:43:38 -0400401 if test.sendPrefix != "" {
402 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
403 return err
404 }
David Benjamin98e882e2014-08-08 13:24:34 -0400405 }
406
David Benjamin1d5c83e2014-07-22 19:20:02 -0400407 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400408 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400409 if test.protocol == dtls {
410 tlsConn = DTLSServer(conn, config)
411 } else {
412 tlsConn = Server(conn, config)
413 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400414 } else {
415 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400416 if test.protocol == dtls {
417 tlsConn = DTLSClient(conn, config)
418 } else {
419 tlsConn = Client(conn, config)
420 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400421 }
David Benjamin30789da2015-08-29 22:56:45 -0400422 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400423
Adam Langley95c29f32014-06-20 12:00:00 -0700424 if err := tlsConn.Handshake(); err != nil {
425 return err
426 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700427
David Benjamin01fe8202014-09-24 15:21:44 -0400428 // TODO(davidben): move all per-connection expectations into a dedicated
429 // expectations struct that can be specified separately for the two
430 // legs.
431 expectedVersion := test.expectedVersion
432 if isResume && test.expectedResumeVersion != 0 {
433 expectedVersion = test.expectedResumeVersion
434 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700435 connState := tlsConn.ConnectionState()
436 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400437 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400438 }
439
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700440 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400441 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
442 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700443 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
444 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
445 }
David Benjamin90da8c82015-04-20 14:57:57 -0400446
David Benjamina08e49d2014-08-24 01:46:07 -0400447 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700448 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400449 if channelID == nil {
450 return fmt.Errorf("no channel ID negotiated")
451 }
452 if channelID.Curve != channelIDKey.Curve ||
453 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
454 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
455 return fmt.Errorf("incorrect channel ID")
456 }
457 }
458
David Benjaminae2888f2014-09-06 12:58:58 -0400459 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700460 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400461 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
462 }
463 }
464
David Benjaminc7ce9772015-10-09 19:32:41 -0400465 if test.expectNoNextProto {
466 if actual := connState.NegotiatedProtocol; actual != "" {
467 return fmt.Errorf("got unexpected next proto %s", actual)
468 }
469 }
470
David Benjaminfc7b0862014-09-06 13:21:53 -0400471 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700472 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400473 return fmt.Errorf("next proto type mismatch")
474 }
475 }
476
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700477 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500478 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
479 }
480
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100481 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
482 return fmt.Errorf("OCSP Response mismatch")
483 }
484
Paul Lietar4fac72e2015-09-09 13:44:55 +0100485 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
486 return fmt.Errorf("SCT list mismatch")
487 }
488
Nick Harper60edffd2016-06-21 15:19:24 -0700489 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
490 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400491 }
492
David Benjaminc565ebb2015-04-03 04:06:36 -0400493 if test.exportKeyingMaterial > 0 {
494 actual := make([]byte, test.exportKeyingMaterial)
495 if _, err := io.ReadFull(tlsConn, actual); err != nil {
496 return err
497 }
498 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
499 if err != nil {
500 return err
501 }
502 if !bytes.Equal(actual, expected) {
503 return fmt.Errorf("keying material mismatch")
504 }
505 }
506
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700507 if test.testTLSUnique {
508 var peersValue [12]byte
509 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
510 return err
511 }
512 expected := tlsConn.ConnectionState().TLSUnique
513 if !bytes.Equal(peersValue[:], expected) {
514 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
515 }
516 }
517
David Benjamine58c4f52014-08-24 03:47:07 -0400518 if test.shimWritesFirst {
519 var buf [5]byte
520 _, err := io.ReadFull(tlsConn, buf[:])
521 if err != nil {
522 return err
523 }
524 if string(buf[:]) != "hello" {
525 return fmt.Errorf("bad initial message")
526 }
527 }
528
David Benjamina8ebe222015-06-06 03:04:39 -0400529 for i := 0; i < test.sendEmptyRecords; i++ {
530 tlsConn.Write(nil)
531 }
532
David Benjamin24f346d2015-06-06 03:28:08 -0400533 for i := 0; i < test.sendWarningAlerts; i++ {
534 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
535 }
536
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400537 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700538 if test.renegotiateCiphers != nil {
539 config.CipherSuites = test.renegotiateCiphers
540 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400541 for i := 0; i < test.renegotiate; i++ {
542 if err := tlsConn.Renegotiate(); err != nil {
543 return err
544 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700545 }
546 } else if test.renegotiateCiphers != nil {
547 panic("renegotiateCiphers without renegotiate")
548 }
549
David Benjamin5fa3eba2015-01-22 16:35:40 -0500550 if test.damageFirstWrite {
551 connDamage.setDamage(true)
552 tlsConn.Write([]byte("DAMAGED WRITE"))
553 connDamage.setDamage(false)
554 }
555
David Benjamin8e6db492015-07-25 18:29:23 -0400556 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700557 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400558 if test.protocol == dtls {
559 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
560 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700561 // Read until EOF.
562 _, err := io.Copy(ioutil.Discard, tlsConn)
563 return err
564 }
David Benjamin4417d052015-04-05 04:17:25 -0400565 if messageLen == 0 {
566 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700567 }
Adam Langley95c29f32014-06-20 12:00:00 -0700568
David Benjamin8e6db492015-07-25 18:29:23 -0400569 messageCount := test.messageCount
570 if messageCount == 0 {
571 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400572 }
573
David Benjamin8e6db492015-07-25 18:29:23 -0400574 for j := 0; j < messageCount; j++ {
575 testMessage := make([]byte, messageLen)
576 for i := range testMessage {
577 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400578 }
David Benjamin8e6db492015-07-25 18:29:23 -0400579 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700580
David Benjamin8e6db492015-07-25 18:29:23 -0400581 for i := 0; i < test.sendEmptyRecords; i++ {
582 tlsConn.Write(nil)
583 }
584
585 for i := 0; i < test.sendWarningAlerts; i++ {
586 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
587 }
588
David Benjamin4f75aaf2015-09-01 16:53:10 -0400589 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400590 // The shim will not respond.
591 continue
592 }
593
David Benjamin8e6db492015-07-25 18:29:23 -0400594 buf := make([]byte, len(testMessage))
595 if test.protocol == dtls {
596 bufTmp := make([]byte, len(buf)+1)
597 n, err := tlsConn.Read(bufTmp)
598 if err != nil {
599 return err
600 }
601 if n != len(buf) {
602 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
603 }
604 copy(buf, bufTmp)
605 } else {
606 _, err := io.ReadFull(tlsConn, buf)
607 if err != nil {
608 return err
609 }
610 }
611
612 for i, v := range buf {
613 if v != testMessage[i]^0xff {
614 return fmt.Errorf("bad reply contents at byte %d", i)
615 }
Adam Langley95c29f32014-06-20 12:00:00 -0700616 }
617 }
618
619 return nil
620}
621
David Benjamin325b5c32014-07-01 19:40:31 -0400622func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
623 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700624 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400625 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700626 }
David Benjamin325b5c32014-07-01 19:40:31 -0400627 valgrindArgs = append(valgrindArgs, path)
628 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700629
David Benjamin325b5c32014-07-01 19:40:31 -0400630 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700631}
632
David Benjamin325b5c32014-07-01 19:40:31 -0400633func gdbOf(path string, args ...string) *exec.Cmd {
634 xtermArgs := []string{"-e", "gdb", "--args"}
635 xtermArgs = append(xtermArgs, path)
636 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700637
David Benjamin325b5c32014-07-01 19:40:31 -0400638 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700639}
640
David Benjamind16bf342015-12-18 00:53:12 -0500641func lldbOf(path string, args ...string) *exec.Cmd {
642 xtermArgs := []string{"-e", "lldb", "--"}
643 xtermArgs = append(xtermArgs, path)
644 xtermArgs = append(xtermArgs, args...)
645
646 return exec.Command("xterm", xtermArgs...)
647}
648
Adam Langley69a01602014-11-17 17:26:55 -0800649type moreMallocsError struct{}
650
651func (moreMallocsError) Error() string {
652 return "child process did not exhaust all allocation calls"
653}
654
655var errMoreMallocs = moreMallocsError{}
656
David Benjamin87c8a642015-02-21 01:54:29 -0500657// accept accepts a connection from listener, unless waitChan signals a process
658// exit first.
659func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
660 type connOrError struct {
661 conn net.Conn
662 err error
663 }
664 connChan := make(chan connOrError, 1)
665 go func() {
666 conn, err := listener.Accept()
667 connChan <- connOrError{conn, err}
668 close(connChan)
669 }()
670 select {
671 case result := <-connChan:
672 return result.conn, result.err
673 case childErr := <-waitChan:
674 waitChan <- childErr
675 return nil, fmt.Errorf("child exited early: %s", childErr)
676 }
677}
678
Adam Langley7c803a62015-06-15 15:35:05 -0700679func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700680 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
681 panic("Error expected without shouldFail in " + test.name)
682 }
683
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700684 if test.expectResumeRejected && !test.resumeSession {
685 panic("expectResumeRejected without resumeSession in " + test.name)
686 }
687
David Benjamin87c8a642015-02-21 01:54:29 -0500688 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
689 if err != nil {
690 panic(err)
691 }
692 defer func() {
693 if listener != nil {
694 listener.Close()
695 }
696 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin87c8a642015-02-21 01:54:29 -0500698 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400699 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400700 flags = append(flags, "-server")
701
David Benjamin025b3d32014-07-01 19:53:04 -0400702 flags = append(flags, "-key-file")
703 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700704 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400705 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700706 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400707 }
708
709 flags = append(flags, "-cert-file")
710 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700711 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400712 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700713 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400714 }
715 }
David Benjamin5a593af2014-08-11 19:51:50 -0400716
Steven Valdez0d62f262015-09-04 12:41:04 -0400717 if test.digestPrefs != "" {
718 flags = append(flags, "-digest-prefs")
719 flags = append(flags, test.digestPrefs)
720 }
721
David Benjamin6fd297b2014-08-11 18:43:38 -0400722 if test.protocol == dtls {
723 flags = append(flags, "-dtls")
724 }
725
David Benjamin5a593af2014-08-11 19:51:50 -0400726 if test.resumeSession {
727 flags = append(flags, "-resume")
728 }
729
David Benjamine58c4f52014-08-24 03:47:07 -0400730 if test.shimWritesFirst {
731 flags = append(flags, "-shim-writes-first")
732 }
733
David Benjamin30789da2015-08-29 22:56:45 -0400734 if test.shimShutsDown {
735 flags = append(flags, "-shim-shuts-down")
736 }
737
David Benjaminc565ebb2015-04-03 04:06:36 -0400738 if test.exportKeyingMaterial > 0 {
739 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
740 flags = append(flags, "-export-label", test.exportLabel)
741 flags = append(flags, "-export-context", test.exportContext)
742 if test.useExportContext {
743 flags = append(flags, "-use-export-context")
744 }
745 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700746 if test.expectResumeRejected {
747 flags = append(flags, "-expect-session-miss")
748 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400749
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700750 if test.testTLSUnique {
751 flags = append(flags, "-tls-unique")
752 }
753
David Benjamin025b3d32014-07-01 19:53:04 -0400754 flags = append(flags, test.flags...)
755
756 var shim *exec.Cmd
757 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700758 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700759 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700760 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500761 } else if *useLLDB {
762 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400763 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700764 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400765 }
David Benjamin025b3d32014-07-01 19:53:04 -0400766 shim.Stdin = os.Stdin
767 var stdoutBuf, stderrBuf bytes.Buffer
768 shim.Stdout = &stdoutBuf
769 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800770 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500771 shim.Env = os.Environ()
772 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800773 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400774 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800775 }
776 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
777 }
David Benjamin025b3d32014-07-01 19:53:04 -0400778
779 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700780 panic(err)
781 }
David Benjamin87c8a642015-02-21 01:54:29 -0500782 waitChan := make(chan error, 1)
783 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700784
785 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400786 if !test.noSessionCache {
787 config.ClientSessionCache = NewLRUClientSessionCache(1)
788 config.ServerSessionCache = NewLRUServerSessionCache(1)
789 }
David Benjamin025b3d32014-07-01 19:53:04 -0400790 if test.testType == clientTest {
791 if len(config.Certificates) == 0 {
792 config.Certificates = []Certificate{getRSACertificate()}
793 }
David Benjamin87c8a642015-02-21 01:54:29 -0500794 } else {
795 // Supply a ServerName to ensure a constant session cache key,
796 // rather than falling back to net.Conn.RemoteAddr.
797 if len(config.ServerName) == 0 {
798 config.ServerName = "test"
799 }
David Benjamin025b3d32014-07-01 19:53:04 -0400800 }
David Benjaminf2b83632016-03-01 22:57:46 -0500801 if *fuzzer {
802 config.Bugs.NullAllCiphers = true
803 }
David Benjamin2e045a92016-06-08 13:09:56 -0400804 if *deterministic {
805 config.Rand = &deterministicRand{}
806 }
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 conn, err := acceptOrWait(listener, waitChan)
809 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400810 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500811 conn.Close()
812 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500813
David Benjamin1d5c83e2014-07-22 19:20:02 -0400814 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400815 var resumeConfig Config
816 if test.resumeConfig != nil {
817 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500818 if len(resumeConfig.ServerName) == 0 {
819 resumeConfig.ServerName = config.ServerName
820 }
David Benjamin01fe8202014-09-24 15:21:44 -0400821 if len(resumeConfig.Certificates) == 0 {
822 resumeConfig.Certificates = []Certificate{getRSACertificate()}
823 }
David Benjaminba4594a2015-06-18 18:36:15 -0400824 if test.newSessionsOnResume {
825 if !test.noSessionCache {
826 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
827 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
828 }
829 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500830 resumeConfig.SessionTicketKey = config.SessionTicketKey
831 resumeConfig.ClientSessionCache = config.ClientSessionCache
832 resumeConfig.ServerSessionCache = config.ServerSessionCache
833 }
David Benjaminf2b83632016-03-01 22:57:46 -0500834 if *fuzzer {
835 resumeConfig.Bugs.NullAllCiphers = true
836 }
David Benjamin2e045a92016-06-08 13:09:56 -0400837 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400838 } else {
839 resumeConfig = config
840 }
David Benjamin87c8a642015-02-21 01:54:29 -0500841 var connResume net.Conn
842 connResume, err = acceptOrWait(listener, waitChan)
843 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400844 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500845 connResume.Close()
846 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400847 }
848
David Benjamin87c8a642015-02-21 01:54:29 -0500849 // Close the listener now. This is to avoid hangs should the shim try to
850 // open more connections than expected.
851 listener.Close()
852 listener = nil
853
854 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800855 if exitError, ok := childErr.(*exec.ExitError); ok {
856 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
857 return errMoreMallocs
858 }
859 }
Adam Langley95c29f32014-06-20 12:00:00 -0700860
David Benjamin9bea3492016-03-02 10:59:16 -0500861 // Account for Windows line endings.
862 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
863 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500864
865 // Separate the errors from the shim and those from tools like
866 // AddressSanitizer.
867 var extraStderr string
868 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
869 stderr = stderrParts[0]
870 extraStderr = stderrParts[1]
871 }
872
Adam Langley95c29f32014-06-20 12:00:00 -0700873 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400874 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700875 localError := "none"
876 if err != nil {
877 localError = err.Error()
878 }
879 if len(test.expectedLocalError) != 0 {
880 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
881 }
Adam Langley95c29f32014-06-20 12:00:00 -0700882
883 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700884 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700885 if childErr != nil {
886 childError = childErr.Error()
887 }
888
889 var msg string
890 switch {
891 case failed && !test.shouldFail:
892 msg = "unexpected failure"
893 case !failed && test.shouldFail:
894 msg = "unexpected success"
895 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700896 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700897 default:
898 panic("internal error")
899 }
900
David Benjaminc565ebb2015-04-03 04:06:36 -0400901 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 -0700902 }
903
David Benjaminff3a1492016-03-02 10:12:06 -0500904 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
905 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700906 }
907
908 return nil
909}
910
911var tlsVersions = []struct {
912 name string
913 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400914 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500915 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700916}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500917 {"SSL3", VersionSSL30, "-no-ssl3", false},
918 {"TLS1", VersionTLS10, "-no-tls1", true},
919 {"TLS11", VersionTLS11, "-no-tls11", false},
920 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700921 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
922 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700923}
924
925var testCipherSuites = []struct {
926 name string
927 id uint16
928}{
929 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400930 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700931 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400932 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400933 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700934 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400935 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400936 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
937 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400938 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400939 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
940 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400941 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700942 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
943 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400944 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
945 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700946 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400947 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500948 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500949 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700950 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700951 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700952 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400953 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400954 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700955 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400956 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500957 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500958 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700959 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700960 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
961 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
962 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
963 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400964 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
965 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700966 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
967 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500968 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400969 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
970 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400971 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400973 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700974 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700975}
976
David Benjamin8b8c0062014-11-23 02:47:52 -0500977func hasComponent(suiteName, component string) bool {
978 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
979}
980
David Benjaminf7768e42014-08-31 02:06:47 -0400981func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500982 return hasComponent(suiteName, "GCM") ||
983 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400984 hasComponent(suiteName, "SHA384") ||
985 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500986}
987
Nick Harper1fd39d82016-06-14 18:14:35 -0700988func isTLS13Suite(suiteName string) bool {
989 return (hasComponent(suiteName, "GCM") || hasComponent(suiteName, "POLY1305")) && hasComponent(suiteName, "ECDHE") && !hasComponent(suiteName, "OLD")
990}
991
David Benjamin8b8c0062014-11-23 02:47:52 -0500992func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700993 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400994}
995
Adam Langleya7997f12015-05-14 17:38:50 -0700996func bigFromHex(hex string) *big.Int {
997 ret, ok := new(big.Int).SetString(hex, 16)
998 if !ok {
999 panic("failed to parse hex number 0x" + hex)
1000 }
1001 return ret
1002}
1003
Adam Langley7c803a62015-06-15 15:35:05 -07001004func addBasicTests() {
1005 basicTests := []testCase{
1006 {
1007 name: "BadRSASignature",
1008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001009 // TODO(davidben): Add a TLS 1.3 version of this.
1010 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1012 Bugs: ProtocolBugs{
1013 InvalidSKXSignature: true,
1014 },
1015 },
1016 shouldFail: true,
1017 expectedError: ":BAD_SIGNATURE:",
1018 },
1019 {
1020 name: "BadECDSASignature",
1021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001022 // TODO(davidben): Add a TLS 1.3 version of this.
1023 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001024 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1025 Bugs: ProtocolBugs{
1026 InvalidSKXSignature: true,
1027 },
1028 Certificates: []Certificate{getECDSACertificate()},
1029 },
1030 shouldFail: true,
1031 expectedError: ":BAD_SIGNATURE:",
1032 },
1033 {
David Benjamin6de0e532015-07-28 22:43:19 -04001034 testType: serverTest,
1035 name: "BadRSASignature-ClientAuth",
1036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001037 // TODO(davidben): Add a TLS 1.3 version of this.
1038 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001039 Bugs: ProtocolBugs{
1040 InvalidCertVerifySignature: true,
1041 },
1042 Certificates: []Certificate{getRSACertificate()},
1043 },
1044 shouldFail: true,
1045 expectedError: ":BAD_SIGNATURE:",
1046 flags: []string{"-require-any-client-certificate"},
1047 },
1048 {
1049 testType: serverTest,
1050 name: "BadECDSASignature-ClientAuth",
1051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001052 // TODO(davidben): Add a TLS 1.3 version of this.
1053 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001054 Bugs: ProtocolBugs{
1055 InvalidCertVerifySignature: true,
1056 },
1057 Certificates: []Certificate{getECDSACertificate()},
1058 },
1059 shouldFail: true,
1060 expectedError: ":BAD_SIGNATURE:",
1061 flags: []string{"-require-any-client-certificate"},
1062 },
1063 {
Adam Langley7c803a62015-06-15 15:35:05 -07001064 name: "NoFallbackSCSV",
1065 config: Config{
1066 Bugs: ProtocolBugs{
1067 FailIfNotFallbackSCSV: true,
1068 },
1069 },
1070 shouldFail: true,
1071 expectedLocalError: "no fallback SCSV found",
1072 },
1073 {
1074 name: "SendFallbackSCSV",
1075 config: Config{
1076 Bugs: ProtocolBugs{
1077 FailIfNotFallbackSCSV: true,
1078 },
1079 },
1080 flags: []string{"-fallback-scsv"},
1081 },
1082 {
1083 name: "ClientCertificateTypes",
1084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001085 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001086 ClientAuth: RequestClientCert,
1087 ClientCertificateTypes: []byte{
1088 CertTypeDSSSign,
1089 CertTypeRSASign,
1090 CertTypeECDSASign,
1091 },
1092 },
1093 flags: []string{
1094 "-expect-certificate-types",
1095 base64.StdEncoding.EncodeToString([]byte{
1096 CertTypeDSSSign,
1097 CertTypeRSASign,
1098 CertTypeECDSASign,
1099 }),
1100 },
1101 },
1102 {
Adam Langley7c803a62015-06-15 15:35:05 -07001103 name: "UnauthenticatedECDH",
1104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001105 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1107 Bugs: ProtocolBugs{
1108 UnauthenticatedECDH: true,
1109 },
1110 },
1111 shouldFail: true,
1112 expectedError: ":UNEXPECTED_MESSAGE:",
1113 },
1114 {
1115 name: "SkipCertificateStatus",
1116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1119 Bugs: ProtocolBugs{
1120 SkipCertificateStatus: true,
1121 },
1122 },
1123 flags: []string{
1124 "-enable-ocsp-stapling",
1125 },
1126 },
1127 {
1128 name: "SkipServerKeyExchange",
1129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001130 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001131 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1132 Bugs: ProtocolBugs{
1133 SkipServerKeyExchange: true,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":UNEXPECTED_MESSAGE:",
1138 },
1139 {
Adam Langley7c803a62015-06-15 15:35:05 -07001140 testType: serverTest,
1141 name: "Alert",
1142 config: Config{
1143 Bugs: ProtocolBugs{
1144 SendSpuriousAlert: alertRecordOverflow,
1145 },
1146 },
1147 shouldFail: true,
1148 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1149 },
1150 {
1151 protocol: dtls,
1152 testType: serverTest,
1153 name: "Alert-DTLS",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 SendSpuriousAlert: alertRecordOverflow,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1161 },
1162 {
1163 testType: serverTest,
1164 name: "FragmentAlert",
1165 config: Config{
1166 Bugs: ProtocolBugs{
1167 FragmentAlert: true,
1168 SendSpuriousAlert: alertRecordOverflow,
1169 },
1170 },
1171 shouldFail: true,
1172 expectedError: ":BAD_ALERT:",
1173 },
1174 {
1175 protocol: dtls,
1176 testType: serverTest,
1177 name: "FragmentAlert-DTLS",
1178 config: Config{
1179 Bugs: ProtocolBugs{
1180 FragmentAlert: true,
1181 SendSpuriousAlert: alertRecordOverflow,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":BAD_ALERT:",
1186 },
1187 {
1188 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001189 name: "DoubleAlert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 DoubleAlert: true,
1193 SendSpuriousAlert: alertRecordOverflow,
1194 },
1195 },
1196 shouldFail: true,
1197 expectedError: ":BAD_ALERT:",
1198 },
1199 {
1200 protocol: dtls,
1201 testType: serverTest,
1202 name: "DoubleAlert-DTLS",
1203 config: Config{
1204 Bugs: ProtocolBugs{
1205 DoubleAlert: true,
1206 SendSpuriousAlert: alertRecordOverflow,
1207 },
1208 },
1209 shouldFail: true,
1210 expectedError: ":BAD_ALERT:",
1211 },
1212 {
Adam Langley7c803a62015-06-15 15:35:05 -07001213 name: "SkipNewSessionTicket",
1214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001215 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001216 Bugs: ProtocolBugs{
1217 SkipNewSessionTicket: true,
1218 },
1219 },
1220 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001221 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001222 },
1223 {
1224 testType: serverTest,
1225 name: "FallbackSCSV",
1226 config: Config{
1227 MaxVersion: VersionTLS11,
1228 Bugs: ProtocolBugs{
1229 SendFallbackSCSV: true,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":INAPPROPRIATE_FALLBACK:",
1234 },
1235 {
1236 testType: serverTest,
1237 name: "FallbackSCSV-VersionMatch",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 SendFallbackSCSV: true,
1241 },
1242 },
1243 },
1244 {
1245 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001246 name: "FallbackSCSV-VersionMatch-TLS12",
1247 config: Config{
1248 MaxVersion: VersionTLS12,
1249 Bugs: ProtocolBugs{
1250 SendFallbackSCSV: true,
1251 },
1252 },
1253 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1254 },
1255 {
1256 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "FragmentedClientVersion",
1258 config: Config{
1259 Bugs: ProtocolBugs{
1260 MaxHandshakeRecordLength: 1,
1261 FragmentClientVersion: true,
1262 },
1263 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001264 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001265 },
1266 {
Adam Langley7c803a62015-06-15 15:35:05 -07001267 testType: serverTest,
1268 name: "HttpGET",
1269 sendPrefix: "GET / HTTP/1.0\n",
1270 shouldFail: true,
1271 expectedError: ":HTTP_REQUEST:",
1272 },
1273 {
1274 testType: serverTest,
1275 name: "HttpPOST",
1276 sendPrefix: "POST / HTTP/1.0\n",
1277 shouldFail: true,
1278 expectedError: ":HTTP_REQUEST:",
1279 },
1280 {
1281 testType: serverTest,
1282 name: "HttpHEAD",
1283 sendPrefix: "HEAD / HTTP/1.0\n",
1284 shouldFail: true,
1285 expectedError: ":HTTP_REQUEST:",
1286 },
1287 {
1288 testType: serverTest,
1289 name: "HttpPUT",
1290 sendPrefix: "PUT / HTTP/1.0\n",
1291 shouldFail: true,
1292 expectedError: ":HTTP_REQUEST:",
1293 },
1294 {
1295 testType: serverTest,
1296 name: "HttpCONNECT",
1297 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1298 shouldFail: true,
1299 expectedError: ":HTTPS_PROXY_REQUEST:",
1300 },
1301 {
1302 testType: serverTest,
1303 name: "Garbage",
1304 sendPrefix: "blah",
1305 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001306 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001307 },
1308 {
Adam Langley7c803a62015-06-15 15:35:05 -07001309 name: "RSAEphemeralKey",
1310 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001311 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001312 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1313 Bugs: ProtocolBugs{
1314 RSAEphemeralKey: true,
1315 },
1316 },
1317 shouldFail: true,
1318 expectedError: ":UNEXPECTED_MESSAGE:",
1319 },
1320 {
1321 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001322 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001323 shouldFail: true,
1324 expectedError: ":WRONG_SSL_VERSION:",
1325 },
1326 {
1327 protocol: dtls,
1328 name: "DisableEverything-DTLS",
1329 flags: []string{"-no-tls12", "-no-tls1"},
1330 shouldFail: true,
1331 expectedError: ":WRONG_SSL_VERSION:",
1332 },
1333 {
Adam Langley7c803a62015-06-15 15:35:05 -07001334 protocol: dtls,
1335 testType: serverTest,
1336 name: "MTU",
1337 config: Config{
1338 Bugs: ProtocolBugs{
1339 MaxPacketLength: 256,
1340 },
1341 },
1342 flags: []string{"-mtu", "256"},
1343 },
1344 {
1345 protocol: dtls,
1346 testType: serverTest,
1347 name: "MTUExceeded",
1348 config: Config{
1349 Bugs: ProtocolBugs{
1350 MaxPacketLength: 255,
1351 },
1352 },
1353 flags: []string{"-mtu", "256"},
1354 shouldFail: true,
1355 expectedLocalError: "dtls: exceeded maximum packet length",
1356 },
1357 {
1358 name: "CertMismatchRSA",
1359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001360 // TODO(davidben): Add a TLS 1.3 version of this test.
1361 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001362 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1363 Certificates: []Certificate{getECDSACertificate()},
1364 Bugs: ProtocolBugs{
1365 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1370 },
1371 {
1372 name: "CertMismatchECDSA",
1373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001374 // TODO(davidben): Add a TLS 1.3 version of this test.
1375 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1377 Certificates: []Certificate{getRSACertificate()},
1378 Bugs: ProtocolBugs{
1379 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1384 },
1385 {
1386 name: "EmptyCertificateList",
1387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001388 // TODO(davidben): Add a TLS 1.3 version of this test.
1389 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001390 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1391 Bugs: ProtocolBugs{
1392 EmptyCertificateList: true,
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":DECODE_ERROR:",
1397 },
1398 {
1399 name: "TLSFatalBadPackets",
1400 damageFirstWrite: true,
1401 shouldFail: true,
1402 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1403 },
1404 {
1405 protocol: dtls,
1406 name: "DTLSIgnoreBadPackets",
1407 damageFirstWrite: true,
1408 },
1409 {
1410 protocol: dtls,
1411 name: "DTLSIgnoreBadPackets-Async",
1412 damageFirstWrite: true,
1413 flags: []string{"-async"},
1414 },
1415 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001416 name: "AppDataBeforeHandshake",
1417 config: Config{
1418 Bugs: ProtocolBugs{
1419 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":UNEXPECTED_RECORD:",
1424 },
1425 {
1426 name: "AppDataBeforeHandshake-Empty",
1427 config: Config{
1428 Bugs: ProtocolBugs{
1429 AppDataBeforeHandshake: []byte{},
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":UNEXPECTED_RECORD:",
1434 },
1435 {
1436 protocol: dtls,
1437 name: "AppDataBeforeHandshake-DTLS",
1438 config: Config{
1439 Bugs: ProtocolBugs{
1440 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1441 },
1442 },
1443 shouldFail: true,
1444 expectedError: ":UNEXPECTED_RECORD:",
1445 },
1446 {
1447 protocol: dtls,
1448 name: "AppDataBeforeHandshake-DTLS-Empty",
1449 config: Config{
1450 Bugs: ProtocolBugs{
1451 AppDataBeforeHandshake: []byte{},
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":UNEXPECTED_RECORD:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "AppDataAfterChangeCipherSpec",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 Bugs: ProtocolBugs{
1462 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1463 },
1464 },
1465 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001466 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001467 },
1468 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001469 name: "AppDataAfterChangeCipherSpec-Empty",
1470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001471 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001472 Bugs: ProtocolBugs{
1473 AppDataAfterChangeCipherSpec: []byte{},
1474 },
1475 },
1476 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001477 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001478 },
1479 {
Adam Langley7c803a62015-06-15 15:35:05 -07001480 protocol: dtls,
1481 name: "AppDataAfterChangeCipherSpec-DTLS",
1482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001483 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001484 Bugs: ProtocolBugs{
1485 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1486 },
1487 },
1488 // BoringSSL's DTLS implementation will drop the out-of-order
1489 // application data.
1490 },
1491 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001492 protocol: dtls,
1493 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001495 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001496 Bugs: ProtocolBugs{
1497 AppDataAfterChangeCipherSpec: []byte{},
1498 },
1499 },
1500 // BoringSSL's DTLS implementation will drop the out-of-order
1501 // application data.
1502 },
1503 {
Adam Langley7c803a62015-06-15 15:35:05 -07001504 name: "AlertAfterChangeCipherSpec",
1505 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001506 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001507 Bugs: ProtocolBugs{
1508 AlertAfterChangeCipherSpec: alertRecordOverflow,
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AlertAfterChangeCipherSpec-DTLS",
1517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001518 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001519 Bugs: ProtocolBugs{
1520 AlertAfterChangeCipherSpec: alertRecordOverflow,
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1525 },
1526 {
1527 protocol: dtls,
1528 name: "ReorderHandshakeFragments-Small-DTLS",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 ReorderHandshakeFragments: true,
1532 // Small enough that every handshake message is
1533 // fragmented.
1534 MaxHandshakeRecordLength: 2,
1535 },
1536 },
1537 },
1538 {
1539 protocol: dtls,
1540 name: "ReorderHandshakeFragments-Large-DTLS",
1541 config: Config{
1542 Bugs: ProtocolBugs{
1543 ReorderHandshakeFragments: true,
1544 // Large enough that no handshake message is
1545 // fragmented.
1546 MaxHandshakeRecordLength: 2048,
1547 },
1548 },
1549 },
1550 {
1551 protocol: dtls,
1552 name: "MixCompleteMessageWithFragments-DTLS",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 ReorderHandshakeFragments: true,
1556 MixCompleteMessageWithFragments: true,
1557 MaxHandshakeRecordLength: 2,
1558 },
1559 },
1560 },
1561 {
1562 name: "SendInvalidRecordType",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 SendInvalidRecordType: true,
1566 },
1567 },
1568 shouldFail: true,
1569 expectedError: ":UNEXPECTED_RECORD:",
1570 },
1571 {
1572 protocol: dtls,
1573 name: "SendInvalidRecordType-DTLS",
1574 config: Config{
1575 Bugs: ProtocolBugs{
1576 SendInvalidRecordType: true,
1577 },
1578 },
1579 shouldFail: true,
1580 expectedError: ":UNEXPECTED_RECORD:",
1581 },
1582 {
1583 name: "FalseStart-SkipServerSecondLeg",
1584 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1587 NextProtos: []string{"foo"},
1588 Bugs: ProtocolBugs{
1589 SkipNewSessionTicket: true,
1590 SkipChangeCipherSpec: true,
1591 SkipFinished: true,
1592 ExpectFalseStart: true,
1593 },
1594 },
1595 flags: []string{
1596 "-false-start",
1597 "-handshake-never-done",
1598 "-advertise-alpn", "\x03foo",
1599 },
1600 shimWritesFirst: true,
1601 shouldFail: true,
1602 expectedError: ":UNEXPECTED_RECORD:",
1603 },
1604 {
1605 name: "FalseStart-SkipServerSecondLeg-Implicit",
1606 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1609 NextProtos: []string{"foo"},
1610 Bugs: ProtocolBugs{
1611 SkipNewSessionTicket: true,
1612 SkipChangeCipherSpec: true,
1613 SkipFinished: true,
1614 },
1615 },
1616 flags: []string{
1617 "-implicit-handshake",
1618 "-false-start",
1619 "-handshake-never-done",
1620 "-advertise-alpn", "\x03foo",
1621 },
1622 shouldFail: true,
1623 expectedError: ":UNEXPECTED_RECORD:",
1624 },
1625 {
1626 testType: serverTest,
1627 name: "FailEarlyCallback",
1628 flags: []string{"-fail-early-callback"},
1629 shouldFail: true,
1630 expectedError: ":CONNECTION_REJECTED:",
1631 expectedLocalError: "remote error: access denied",
1632 },
1633 {
1634 name: "WrongMessageType",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 WrongCertificateMessageType: true,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":UNEXPECTED_MESSAGE:",
1642 expectedLocalError: "remote error: unexpected message",
1643 },
1644 {
1645 protocol: dtls,
1646 name: "WrongMessageType-DTLS",
1647 config: Config{
1648 Bugs: ProtocolBugs{
1649 WrongCertificateMessageType: true,
1650 },
1651 },
1652 shouldFail: true,
1653 expectedError: ":UNEXPECTED_MESSAGE:",
1654 expectedLocalError: "remote error: unexpected message",
1655 },
1656 {
1657 protocol: dtls,
1658 name: "FragmentMessageTypeMismatch-DTLS",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 MaxHandshakeRecordLength: 2,
1662 FragmentMessageTypeMismatch: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":FRAGMENT_MISMATCH:",
1667 },
1668 {
1669 protocol: dtls,
1670 name: "FragmentMessageLengthMismatch-DTLS",
1671 config: Config{
1672 Bugs: ProtocolBugs{
1673 MaxHandshakeRecordLength: 2,
1674 FragmentMessageLengthMismatch: true,
1675 },
1676 },
1677 shouldFail: true,
1678 expectedError: ":FRAGMENT_MISMATCH:",
1679 },
1680 {
1681 protocol: dtls,
1682 name: "SplitFragments-Header-DTLS",
1683 config: Config{
1684 Bugs: ProtocolBugs{
1685 SplitFragments: 2,
1686 },
1687 },
1688 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001689 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001690 },
1691 {
1692 protocol: dtls,
1693 name: "SplitFragments-Boundary-DTLS",
1694 config: Config{
1695 Bugs: ProtocolBugs{
1696 SplitFragments: dtlsRecordHeaderLen,
1697 },
1698 },
1699 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001700 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
1703 protocol: dtls,
1704 name: "SplitFragments-Body-DTLS",
1705 config: Config{
1706 Bugs: ProtocolBugs{
1707 SplitFragments: dtlsRecordHeaderLen + 1,
1708 },
1709 },
1710 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001711 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001712 },
1713 {
1714 protocol: dtls,
1715 name: "SendEmptyFragments-DTLS",
1716 config: Config{
1717 Bugs: ProtocolBugs{
1718 SendEmptyFragments: true,
1719 },
1720 },
1721 },
1722 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001723 name: "BadFinished-Client",
1724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001725 // TODO(davidben): Add a TLS 1.3 version of this.
1726 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001727 Bugs: ProtocolBugs{
1728 BadFinished: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":DIGEST_CHECK_FAILED:",
1733 },
1734 {
1735 testType: serverTest,
1736 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001738 // TODO(davidben): Add a TLS 1.3 version of this.
1739 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001740 Bugs: ProtocolBugs{
1741 BadFinished: true,
1742 },
1743 },
1744 shouldFail: true,
1745 expectedError: ":DIGEST_CHECK_FAILED:",
1746 },
1747 {
1748 name: "FalseStart-BadFinished",
1749 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001750 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1752 NextProtos: []string{"foo"},
1753 Bugs: ProtocolBugs{
1754 BadFinished: true,
1755 ExpectFalseStart: true,
1756 },
1757 },
1758 flags: []string{
1759 "-false-start",
1760 "-handshake-never-done",
1761 "-advertise-alpn", "\x03foo",
1762 },
1763 shimWritesFirst: true,
1764 shouldFail: true,
1765 expectedError: ":DIGEST_CHECK_FAILED:",
1766 },
1767 {
1768 name: "NoFalseStart-NoALPN",
1769 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001770 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1772 Bugs: ProtocolBugs{
1773 ExpectFalseStart: true,
1774 AlertBeforeFalseStartTest: alertAccessDenied,
1775 },
1776 },
1777 flags: []string{
1778 "-false-start",
1779 },
1780 shimWritesFirst: true,
1781 shouldFail: true,
1782 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1783 expectedLocalError: "tls: peer did not false start: EOF",
1784 },
1785 {
1786 name: "NoFalseStart-NoAEAD",
1787 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001788 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1790 NextProtos: []string{"foo"},
1791 Bugs: ProtocolBugs{
1792 ExpectFalseStart: true,
1793 AlertBeforeFalseStartTest: alertAccessDenied,
1794 },
1795 },
1796 flags: []string{
1797 "-false-start",
1798 "-advertise-alpn", "\x03foo",
1799 },
1800 shimWritesFirst: true,
1801 shouldFail: true,
1802 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1803 expectedLocalError: "tls: peer did not false start: EOF",
1804 },
1805 {
1806 name: "NoFalseStart-RSA",
1807 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1810 NextProtos: []string{"foo"},
1811 Bugs: ProtocolBugs{
1812 ExpectFalseStart: true,
1813 AlertBeforeFalseStartTest: alertAccessDenied,
1814 },
1815 },
1816 flags: []string{
1817 "-false-start",
1818 "-advertise-alpn", "\x03foo",
1819 },
1820 shimWritesFirst: true,
1821 shouldFail: true,
1822 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1823 expectedLocalError: "tls: peer did not false start: EOF",
1824 },
1825 {
1826 name: "NoFalseStart-DHE_RSA",
1827 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001828 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001829 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1830 NextProtos: []string{"foo"},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1843 expectedLocalError: "tls: peer did not false start: EOF",
1844 },
1845 {
Adam Langley7c803a62015-06-15 15:35:05 -07001846 protocol: dtls,
1847 name: "SendSplitAlert-Sync",
1848 config: Config{
1849 Bugs: ProtocolBugs{
1850 SendSplitAlert: true,
1851 },
1852 },
1853 },
1854 {
1855 protocol: dtls,
1856 name: "SendSplitAlert-Async",
1857 config: Config{
1858 Bugs: ProtocolBugs{
1859 SendSplitAlert: true,
1860 },
1861 },
1862 flags: []string{"-async"},
1863 },
1864 {
1865 protocol: dtls,
1866 name: "PackDTLSHandshake",
1867 config: Config{
1868 Bugs: ProtocolBugs{
1869 MaxHandshakeRecordLength: 2,
1870 PackHandshakeFragments: 20,
1871 PackHandshakeRecords: 200,
1872 },
1873 },
1874 },
1875 {
Adam Langley7c803a62015-06-15 15:35:05 -07001876 name: "SendEmptyRecords-Pass",
1877 sendEmptyRecords: 32,
1878 },
1879 {
1880 name: "SendEmptyRecords",
1881 sendEmptyRecords: 33,
1882 shouldFail: true,
1883 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1884 },
1885 {
1886 name: "SendEmptyRecords-Async",
1887 sendEmptyRecords: 33,
1888 flags: []string{"-async"},
1889 shouldFail: true,
1890 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1891 },
1892 {
1893 name: "SendWarningAlerts-Pass",
1894 sendWarningAlerts: 4,
1895 },
1896 {
1897 protocol: dtls,
1898 name: "SendWarningAlerts-DTLS-Pass",
1899 sendWarningAlerts: 4,
1900 },
1901 {
1902 name: "SendWarningAlerts",
1903 sendWarningAlerts: 5,
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Async",
1909 sendWarningAlerts: 5,
1910 flags: []string{"-async"},
1911 shouldFail: true,
1912 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1913 },
David Benjaminba4594a2015-06-18 18:36:15 -04001914 {
1915 name: "EmptySessionID",
1916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001917 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001918 SessionTicketsDisabled: true,
1919 },
1920 noSessionCache: true,
1921 flags: []string{"-expect-no-session"},
1922 },
David Benjamin30789da2015-08-29 22:56:45 -04001923 {
1924 name: "Unclean-Shutdown",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 NoCloseNotify: true,
1928 ExpectCloseNotify: true,
1929 },
1930 },
1931 shimShutsDown: true,
1932 flags: []string{"-check-close-notify"},
1933 shouldFail: true,
1934 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1935 },
1936 {
1937 name: "Unclean-Shutdown-Ignored",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 NoCloseNotify: true,
1941 },
1942 },
1943 shimShutsDown: true,
1944 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001945 {
David Benjaminfa214e42016-05-10 17:03:10 -04001946 name: "Unclean-Shutdown-Alert",
1947 config: Config{
1948 Bugs: ProtocolBugs{
1949 SendAlertOnShutdown: alertDecompressionFailure,
1950 ExpectCloseNotify: true,
1951 },
1952 },
1953 shimShutsDown: true,
1954 flags: []string{"-check-close-notify"},
1955 shouldFail: true,
1956 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1957 },
1958 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001959 name: "LargePlaintext",
1960 config: Config{
1961 Bugs: ProtocolBugs{
1962 SendLargeRecords: true,
1963 },
1964 },
1965 messageLen: maxPlaintext + 1,
1966 shouldFail: true,
1967 expectedError: ":DATA_LENGTH_TOO_LONG:",
1968 },
1969 {
1970 protocol: dtls,
1971 name: "LargePlaintext-DTLS",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 SendLargeRecords: true,
1975 },
1976 },
1977 messageLen: maxPlaintext + 1,
1978 shouldFail: true,
1979 expectedError: ":DATA_LENGTH_TOO_LONG:",
1980 },
1981 {
1982 name: "LargeCiphertext",
1983 config: Config{
1984 Bugs: ProtocolBugs{
1985 SendLargeRecords: true,
1986 },
1987 },
1988 messageLen: maxPlaintext * 2,
1989 shouldFail: true,
1990 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1991 },
1992 {
1993 protocol: dtls,
1994 name: "LargeCiphertext-DTLS",
1995 config: Config{
1996 Bugs: ProtocolBugs{
1997 SendLargeRecords: true,
1998 },
1999 },
2000 messageLen: maxPlaintext * 2,
2001 // Unlike the other four cases, DTLS drops records which
2002 // are invalid before authentication, so the connection
2003 // does not fail.
2004 expectMessageDropped: true,
2005 },
David Benjamindd6fed92015-10-23 17:41:12 -04002006 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002007 // In TLS 1.2 and below, empty NewSessionTicket messages
2008 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002009 name: "SendEmptySessionTicket",
2010 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002011 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002012 Bugs: ProtocolBugs{
2013 SendEmptySessionTicket: true,
2014 FailIfSessionOffered: true,
2015 },
2016 },
2017 flags: []string{"-expect-no-session"},
2018 resumeSession: true,
2019 expectResumeRejected: true,
2020 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002021 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002022 name: "BadHelloRequest-1",
2023 renegotiate: 1,
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002026 Bugs: ProtocolBugs{
2027 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2028 },
2029 },
2030 flags: []string{
2031 "-renegotiate-freely",
2032 "-expect-total-renegotiations", "1",
2033 },
2034 shouldFail: true,
2035 expectedError: ":BAD_HELLO_REQUEST:",
2036 },
2037 {
2038 name: "BadHelloRequest-2",
2039 renegotiate: 1,
2040 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002041 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002042 Bugs: ProtocolBugs{
2043 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2044 },
2045 },
2046 flags: []string{
2047 "-renegotiate-freely",
2048 "-expect-total-renegotiations", "1",
2049 },
2050 shouldFail: true,
2051 expectedError: ":BAD_HELLO_REQUEST:",
2052 },
David Benjaminef1b0092015-11-21 14:05:44 -05002053 {
2054 testType: serverTest,
2055 name: "SupportTicketsWithSessionID",
2056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002057 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002058 SessionTicketsDisabled: true,
2059 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002060 resumeConfig: &Config{
2061 MaxVersion: VersionTLS12,
2062 },
David Benjaminef1b0092015-11-21 14:05:44 -05002063 resumeSession: true,
2064 },
Adam Langley7c803a62015-06-15 15:35:05 -07002065 }
Adam Langley7c803a62015-06-15 15:35:05 -07002066 testCases = append(testCases, basicTests...)
2067}
2068
Adam Langley95c29f32014-06-20 12:00:00 -07002069func addCipherSuiteTests() {
2070 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002071 const psk = "12345"
2072 const pskIdentity = "luggage combo"
2073
Adam Langley95c29f32014-06-20 12:00:00 -07002074 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002075 var certFile string
2076 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002077 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002078 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002079 certFile = ecdsaCertificateFile
2080 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002081 } else {
2082 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002083 certFile = rsaCertificateFile
2084 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002085 }
2086
David Benjamin48cae082014-10-27 01:06:24 -04002087 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002088 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002089 flags = append(flags,
2090 "-psk", psk,
2091 "-psk-identity", pskIdentity)
2092 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002093 if hasComponent(suite.name, "NULL") {
2094 // NULL ciphers must be explicitly enabled.
2095 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2096 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002097 if hasComponent(suite.name, "CECPQ1") {
2098 // CECPQ1 ciphers must be explicitly enabled.
2099 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2100 }
David Benjamin48cae082014-10-27 01:06:24 -04002101
Adam Langley95c29f32014-06-20 12:00:00 -07002102 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002103 for _, protocol := range []protocol{tls, dtls} {
2104 var prefix string
2105 if protocol == dtls {
2106 if !ver.hasDTLS {
2107 continue
2108 }
2109 prefix = "D"
2110 }
Adam Langley95c29f32014-06-20 12:00:00 -07002111
David Benjamin0407e762016-06-17 16:41:18 -04002112 var shouldServerFail, shouldClientFail bool
2113 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2114 // BoringSSL clients accept ECDHE on SSLv3, but
2115 // a BoringSSL server will never select it
2116 // because the extension is missing.
2117 shouldServerFail = true
2118 }
2119 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2120 shouldClientFail = true
2121 shouldServerFail = true
2122 }
Nick Harper1fd39d82016-06-14 18:14:35 -07002123 if !isTLS13Suite(suite.name) && ver.version == VersionTLS13 {
2124 shouldClientFail = true
2125 shouldServerFail = true
2126 }
David Benjamin0407e762016-06-17 16:41:18 -04002127 if !isDTLSCipher(suite.name) && protocol == dtls {
2128 shouldClientFail = true
2129 shouldServerFail = true
2130 }
David Benjamin4298d772015-12-19 00:18:25 -05002131
David Benjamin0407e762016-06-17 16:41:18 -04002132 var expectedServerError, expectedClientError string
2133 if shouldServerFail {
2134 expectedServerError = ":NO_SHARED_CIPHER:"
2135 }
2136 if shouldClientFail {
2137 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2138 }
David Benjamin025b3d32014-07-01 19:53:04 -04002139
David Benjamin6fd297b2014-08-11 18:43:38 -04002140 testCases = append(testCases, testCase{
2141 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002142 protocol: protocol,
2143
2144 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002145 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002146 MinVersion: ver.version,
2147 MaxVersion: ver.version,
2148 CipherSuites: []uint16{suite.id},
2149 Certificates: []Certificate{cert},
2150 PreSharedKey: []byte(psk),
2151 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002152 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002153 EnableAllCiphers: shouldServerFail,
2154 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002155 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002156 },
2157 certFile: certFile,
2158 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002159 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002160 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002161 shouldFail: shouldServerFail,
2162 expectedError: expectedServerError,
2163 })
2164
2165 testCases = append(testCases, testCase{
2166 testType: clientTest,
2167 protocol: protocol,
2168 name: prefix + ver.name + "-" + suite.name + "-client",
2169 config: Config{
2170 MinVersion: ver.version,
2171 MaxVersion: ver.version,
2172 CipherSuites: []uint16{suite.id},
2173 Certificates: []Certificate{cert},
2174 PreSharedKey: []byte(psk),
2175 PreSharedKeyIdentity: pskIdentity,
2176 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002177 EnableAllCiphers: shouldClientFail,
2178 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002179 },
2180 },
2181 flags: flags,
2182 resumeSession: true,
2183 shouldFail: shouldClientFail,
2184 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002185 })
David Benjamin2c99d282015-09-01 10:23:00 -04002186
Nick Harper1fd39d82016-06-14 18:14:35 -07002187 if !shouldClientFail {
2188 // Ensure the maximum record size is accepted.
2189 testCases = append(testCases, testCase{
2190 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2191 config: Config{
2192 MinVersion: ver.version,
2193 MaxVersion: ver.version,
2194 CipherSuites: []uint16{suite.id},
2195 Certificates: []Certificate{cert},
2196 PreSharedKey: []byte(psk),
2197 PreSharedKeyIdentity: pskIdentity,
2198 },
2199 flags: flags,
2200 messageLen: maxPlaintext,
2201 })
2202 }
2203 }
David Benjamin2c99d282015-09-01 10:23:00 -04002204 }
Adam Langley95c29f32014-06-20 12:00:00 -07002205 }
Adam Langleya7997f12015-05-14 17:38:50 -07002206
2207 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002208 name: "NoSharedCipher",
2209 config: Config{
2210 // TODO(davidben): Add a TLS 1.3 version of this test.
2211 MaxVersion: VersionTLS12,
2212 CipherSuites: []uint16{},
2213 },
2214 shouldFail: true,
2215 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2216 })
2217
2218 testCases = append(testCases, testCase{
2219 name: "UnsupportedCipherSuite",
2220 config: Config{
2221 MaxVersion: VersionTLS12,
2222 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2223 Bugs: ProtocolBugs{
2224 IgnorePeerCipherPreferences: true,
2225 },
2226 },
2227 flags: []string{"-cipher", "DEFAULT:!RC4"},
2228 shouldFail: true,
2229 expectedError: ":WRONG_CIPHER_RETURNED:",
2230 })
2231
2232 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002233 name: "WeakDH",
2234 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002235 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002236 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2237 Bugs: ProtocolBugs{
2238 // This is a 1023-bit prime number, generated
2239 // with:
2240 // openssl gendh 1023 | openssl asn1parse -i
2241 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2242 },
2243 },
2244 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002245 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002246 })
Adam Langleycef75832015-09-03 14:51:12 -07002247
David Benjamincd24a392015-11-11 13:23:05 -08002248 testCases = append(testCases, testCase{
2249 name: "SillyDH",
2250 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002251 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002252 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2253 Bugs: ProtocolBugs{
2254 // This is a 4097-bit prime number, generated
2255 // with:
2256 // openssl gendh 4097 | openssl asn1parse -i
2257 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2258 },
2259 },
2260 shouldFail: true,
2261 expectedError: ":DH_P_TOO_LONG:",
2262 })
2263
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002264 // This test ensures that Diffie-Hellman public values are padded with
2265 // zeros so that they're the same length as the prime. This is to avoid
2266 // hitting a bug in yaSSL.
2267 testCases = append(testCases, testCase{
2268 testType: serverTest,
2269 name: "DHPublicValuePadded",
2270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002271 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002272 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2273 Bugs: ProtocolBugs{
2274 RequireDHPublicValueLen: (1025 + 7) / 8,
2275 },
2276 },
2277 flags: []string{"-use-sparse-dh-prime"},
2278 })
David Benjamincd24a392015-11-11 13:23:05 -08002279
David Benjamin241ae832016-01-15 03:04:54 -05002280 // The server must be tolerant to bogus ciphers.
2281 const bogusCipher = 0x1234
2282 testCases = append(testCases, testCase{
2283 testType: serverTest,
2284 name: "UnknownCipher",
2285 config: Config{
2286 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2287 },
2288 })
2289
Adam Langleycef75832015-09-03 14:51:12 -07002290 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2291 // 1.1 specific cipher suite settings. A server is setup with the given
2292 // cipher lists and then a connection is made for each member of
2293 // expectations. The cipher suite that the server selects must match
2294 // the specified one.
2295 var versionSpecificCiphersTest = []struct {
2296 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2297 // expectations is a map from TLS version to cipher suite id.
2298 expectations map[uint16]uint16
2299 }{
2300 {
2301 // Test that the null case (where no version-specific ciphers are set)
2302 // works as expected.
2303 "RC4-SHA:AES128-SHA", // default ciphers
2304 "", // no ciphers specifically for TLS ≥ 1.0
2305 "", // no ciphers specifically for TLS ≥ 1.1
2306 map[uint16]uint16{
2307 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2308 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2309 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2310 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2311 },
2312 },
2313 {
2314 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2315 // cipher.
2316 "RC4-SHA:AES128-SHA", // default
2317 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2318 "", // no ciphers specifically for TLS ≥ 1.1
2319 map[uint16]uint16{
2320 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2321 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2322 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2323 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2324 },
2325 },
2326 {
2327 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2328 // cipher.
2329 "RC4-SHA:AES128-SHA", // default
2330 "", // no ciphers specifically for TLS ≥ 1.0
2331 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2332 map[uint16]uint16{
2333 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2334 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2335 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2336 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2337 },
2338 },
2339 {
2340 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2341 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2342 "RC4-SHA:AES128-SHA", // default
2343 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2344 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2345 map[uint16]uint16{
2346 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2347 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2348 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2349 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2350 },
2351 },
2352 }
2353
2354 for i, test := range versionSpecificCiphersTest {
2355 for version, expectedCipherSuite := range test.expectations {
2356 flags := []string{"-cipher", test.ciphersDefault}
2357 if len(test.ciphersTLS10) > 0 {
2358 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2359 }
2360 if len(test.ciphersTLS11) > 0 {
2361 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2362 }
2363
2364 testCases = append(testCases, testCase{
2365 testType: serverTest,
2366 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2367 config: Config{
2368 MaxVersion: version,
2369 MinVersion: version,
2370 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2371 },
2372 flags: flags,
2373 expectedCipher: expectedCipherSuite,
2374 })
2375 }
2376 }
Adam Langley95c29f32014-06-20 12:00:00 -07002377}
2378
2379func addBadECDSASignatureTests() {
2380 for badR := BadValue(1); badR < NumBadValues; badR++ {
2381 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002382 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002383 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2384 config: Config{
2385 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2386 Certificates: []Certificate{getECDSACertificate()},
2387 Bugs: ProtocolBugs{
2388 BadECDSAR: badR,
2389 BadECDSAS: badS,
2390 },
2391 },
2392 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002393 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002394 })
2395 }
2396 }
2397}
2398
Adam Langley80842bd2014-06-20 12:00:00 -07002399func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002400 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002401 name: "MaxCBCPadding",
2402 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002403 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2405 Bugs: ProtocolBugs{
2406 MaxPadding: true,
2407 },
2408 },
2409 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2410 })
David Benjamin025b3d32014-07-01 19:53:04 -04002411 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002412 name: "BadCBCPadding",
2413 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002414 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2416 Bugs: ProtocolBugs{
2417 PaddingFirstByteBad: true,
2418 },
2419 },
2420 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002421 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002422 })
2423 // OpenSSL previously had an issue where the first byte of padding in
2424 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002425 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002426 name: "BadCBCPadding255",
2427 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002428 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002429 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2430 Bugs: ProtocolBugs{
2431 MaxPadding: true,
2432 PaddingFirstByteBadIf255: true,
2433 },
2434 },
2435 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2436 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002437 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002438 })
2439}
2440
Kenny Root7fdeaf12014-08-05 15:23:37 -07002441func addCBCSplittingTests() {
2442 testCases = append(testCases, testCase{
2443 name: "CBCRecordSplitting",
2444 config: Config{
2445 MaxVersion: VersionTLS10,
2446 MinVersion: VersionTLS10,
2447 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2448 },
David Benjaminac8302a2015-09-01 17:18:15 -04002449 messageLen: -1, // read until EOF
2450 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002451 flags: []string{
2452 "-async",
2453 "-write-different-record-sizes",
2454 "-cbc-record-splitting",
2455 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002456 })
2457 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002458 name: "CBCRecordSplittingPartialWrite",
2459 config: Config{
2460 MaxVersion: VersionTLS10,
2461 MinVersion: VersionTLS10,
2462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2463 },
2464 messageLen: -1, // read until EOF
2465 flags: []string{
2466 "-async",
2467 "-write-different-record-sizes",
2468 "-cbc-record-splitting",
2469 "-partial-write",
2470 },
2471 })
2472}
2473
David Benjamin636293b2014-07-08 17:59:18 -04002474func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002475 // Add a dummy cert pool to stress certificate authority parsing.
2476 // TODO(davidben): Add tests that those values parse out correctly.
2477 certPool := x509.NewCertPool()
2478 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2479 if err != nil {
2480 panic(err)
2481 }
2482 certPool.AddCert(cert)
2483
David Benjamin636293b2014-07-08 17:59:18 -04002484 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002485 testCases = append(testCases, testCase{
2486 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002487 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002488 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002489 MinVersion: ver.version,
2490 MaxVersion: ver.version,
2491 ClientAuth: RequireAnyClientCert,
2492 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002493 },
2494 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002495 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2496 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002497 },
2498 })
2499 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002500 testType: serverTest,
2501 name: ver.name + "-Server-ClientAuth-RSA",
2502 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002503 MinVersion: ver.version,
2504 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002505 Certificates: []Certificate{rsaCertificate},
2506 },
2507 flags: []string{"-require-any-client-certificate"},
2508 })
David Benjamine098ec22014-08-27 23:13:20 -04002509 if ver.version != VersionSSL30 {
2510 testCases = append(testCases, testCase{
2511 testType: serverTest,
2512 name: ver.name + "-Server-ClientAuth-ECDSA",
2513 config: Config{
2514 MinVersion: ver.version,
2515 MaxVersion: ver.version,
2516 Certificates: []Certificate{ecdsaCertificate},
2517 },
2518 flags: []string{"-require-any-client-certificate"},
2519 })
2520 testCases = append(testCases, testCase{
2521 testType: clientTest,
2522 name: ver.name + "-Client-ClientAuth-ECDSA",
2523 config: Config{
2524 MinVersion: ver.version,
2525 MaxVersion: ver.version,
2526 ClientAuth: RequireAnyClientCert,
2527 ClientCAs: certPool,
2528 },
2529 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002530 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2531 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002532 },
2533 })
2534 }
David Benjamin636293b2014-07-08 17:59:18 -04002535 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002536
Nick Harper1fd39d82016-06-14 18:14:35 -07002537 // TODO(davidben): These tests will need TLS 1.3 versions when the
2538 // handshake is separate.
2539
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002540 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002541 name: "NoClientCertificate",
2542 config: Config{
2543 MaxVersion: VersionTLS12,
2544 ClientAuth: RequireAnyClientCert,
2545 },
2546 shouldFail: true,
2547 expectedLocalError: "client didn't provide a certificate",
2548 })
2549
2550 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002551 testType: serverTest,
2552 name: "RequireAnyClientCertificate",
2553 config: Config{
2554 MaxVersion: VersionTLS12,
2555 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002556 flags: []string{"-require-any-client-certificate"},
2557 shouldFail: true,
2558 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2559 })
2560
2561 testCases = append(testCases, testCase{
2562 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002563 name: "RequireAnyClientCertificate-SSL3",
2564 config: Config{
2565 MaxVersion: VersionSSL30,
2566 },
2567 flags: []string{"-require-any-client-certificate"},
2568 shouldFail: true,
2569 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2570 })
2571
2572 testCases = append(testCases, testCase{
2573 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002574 name: "SkipClientCertificate",
2575 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002576 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002577 Bugs: ProtocolBugs{
2578 SkipClientCertificate: true,
2579 },
2580 },
2581 // Setting SSL_VERIFY_PEER allows anonymous clients.
2582 flags: []string{"-verify-peer"},
2583 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002584 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002585 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002586
2587 // Client auth is only legal in certificate-based ciphers.
2588 testCases = append(testCases, testCase{
2589 testType: clientTest,
2590 name: "ClientAuth-PSK",
2591 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002592 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002593 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2594 PreSharedKey: []byte("secret"),
2595 ClientAuth: RequireAnyClientCert,
2596 },
2597 flags: []string{
2598 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2599 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2600 "-psk", "secret",
2601 },
2602 shouldFail: true,
2603 expectedError: ":UNEXPECTED_MESSAGE:",
2604 })
2605 testCases = append(testCases, testCase{
2606 testType: clientTest,
2607 name: "ClientAuth-ECDHE_PSK",
2608 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002609 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002610 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2611 PreSharedKey: []byte("secret"),
2612 ClientAuth: RequireAnyClientCert,
2613 },
2614 flags: []string{
2615 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2616 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2617 "-psk", "secret",
2618 },
2619 shouldFail: true,
2620 expectedError: ":UNEXPECTED_MESSAGE:",
2621 })
David Benjamin636293b2014-07-08 17:59:18 -04002622}
2623
Adam Langley75712922014-10-10 16:23:43 -07002624func addExtendedMasterSecretTests() {
2625 const expectEMSFlag = "-expect-extended-master-secret"
2626
2627 for _, with := range []bool{false, true} {
2628 prefix := "No"
2629 var flags []string
2630 if with {
2631 prefix = ""
2632 flags = []string{expectEMSFlag}
2633 }
2634
2635 for _, isClient := range []bool{false, true} {
2636 suffix := "-Server"
2637 testType := serverTest
2638 if isClient {
2639 suffix = "-Client"
2640 testType = clientTest
2641 }
2642
David Benjamin4c3ddf72016-06-29 18:13:53 -04002643 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2644 // test that the extension is irrelevant, but the API
2645 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002646 for _, ver := range tlsVersions {
2647 test := testCase{
2648 testType: testType,
2649 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2650 config: Config{
2651 MinVersion: ver.version,
2652 MaxVersion: ver.version,
2653 Bugs: ProtocolBugs{
2654 NoExtendedMasterSecret: !with,
2655 RequireExtendedMasterSecret: with,
2656 },
2657 },
David Benjamin48cae082014-10-27 01:06:24 -04002658 flags: flags,
2659 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002660 }
2661 if test.shouldFail {
2662 test.expectedLocalError = "extended master secret required but not supported by peer"
2663 }
2664 testCases = append(testCases, test)
2665 }
2666 }
2667 }
2668
Adam Langleyba5934b2015-06-02 10:50:35 -07002669 for _, isClient := range []bool{false, true} {
2670 for _, supportedInFirstConnection := range []bool{false, true} {
2671 for _, supportedInResumeConnection := range []bool{false, true} {
2672 boolToWord := func(b bool) string {
2673 if b {
2674 return "Yes"
2675 }
2676 return "No"
2677 }
2678 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2679 if isClient {
2680 suffix += "Client"
2681 } else {
2682 suffix += "Server"
2683 }
2684
2685 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002686 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002687 Bugs: ProtocolBugs{
2688 RequireExtendedMasterSecret: true,
2689 },
2690 }
2691
2692 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002693 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002694 Bugs: ProtocolBugs{
2695 NoExtendedMasterSecret: true,
2696 },
2697 }
2698
2699 test := testCase{
2700 name: "ExtendedMasterSecret-" + suffix,
2701 resumeSession: true,
2702 }
2703
2704 if !isClient {
2705 test.testType = serverTest
2706 }
2707
2708 if supportedInFirstConnection {
2709 test.config = supportedConfig
2710 } else {
2711 test.config = noSupportConfig
2712 }
2713
2714 if supportedInResumeConnection {
2715 test.resumeConfig = &supportedConfig
2716 } else {
2717 test.resumeConfig = &noSupportConfig
2718 }
2719
2720 switch suffix {
2721 case "YesToYes-Client", "YesToYes-Server":
2722 // When a session is resumed, it should
2723 // still be aware that its master
2724 // secret was generated via EMS and
2725 // thus it's safe to use tls-unique.
2726 test.flags = []string{expectEMSFlag}
2727 case "NoToYes-Server":
2728 // If an original connection did not
2729 // contain EMS, but a resumption
2730 // handshake does, then a server should
2731 // not resume the session.
2732 test.expectResumeRejected = true
2733 case "YesToNo-Server":
2734 // Resuming an EMS session without the
2735 // EMS extension should cause the
2736 // server to abort the connection.
2737 test.shouldFail = true
2738 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2739 case "NoToYes-Client":
2740 // A client should abort a connection
2741 // where the server resumed a non-EMS
2742 // session but echoed the EMS
2743 // extension.
2744 test.shouldFail = true
2745 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2746 case "YesToNo-Client":
2747 // A client should abort a connection
2748 // where the server didn't echo EMS
2749 // when the session used it.
2750 test.shouldFail = true
2751 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2752 }
2753
2754 testCases = append(testCases, test)
2755 }
2756 }
2757 }
Adam Langley75712922014-10-10 16:23:43 -07002758}
2759
David Benjamin582ba042016-07-07 12:33:25 -07002760type stateMachineTestConfig struct {
2761 protocol protocol
2762 async bool
2763 splitHandshake, packHandshakeFlight bool
2764}
2765
David Benjamin43ec06f2014-08-05 02:28:57 -04002766// Adds tests that try to cover the range of the handshake state machine, under
2767// various conditions. Some of these are redundant with other tests, but they
2768// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002769func addAllStateMachineCoverageTests() {
2770 for _, async := range []bool{false, true} {
2771 for _, protocol := range []protocol{tls, dtls} {
2772 addStateMachineCoverageTests(stateMachineTestConfig{
2773 protocol: protocol,
2774 async: async,
2775 })
2776 addStateMachineCoverageTests(stateMachineTestConfig{
2777 protocol: protocol,
2778 async: async,
2779 splitHandshake: true,
2780 })
2781 if protocol == tls {
2782 addStateMachineCoverageTests(stateMachineTestConfig{
2783 protocol: protocol,
2784 async: async,
2785 packHandshakeFlight: true,
2786 })
2787 }
2788 }
2789 }
2790}
2791
2792func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002793 var tests []testCase
2794
2795 // Basic handshake, with resumption. Client and server,
2796 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002797 //
2798 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2799 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002800 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002801 name: "Basic-Client",
2802 config: Config{
2803 MaxVersion: VersionTLS12,
2804 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002805 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002806 // Ensure session tickets are used, not session IDs.
2807 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002808 })
2809 tests = append(tests, testCase{
2810 name: "Basic-Client-RenewTicket",
2811 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002812 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002813 Bugs: ProtocolBugs{
2814 RenewTicketOnResume: true,
2815 },
2816 },
David Benjaminba4594a2015-06-18 18:36:15 -04002817 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002818 resumeSession: true,
2819 })
2820 tests = append(tests, testCase{
2821 name: "Basic-Client-NoTicket",
2822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002823 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002824 SessionTicketsDisabled: true,
2825 },
2826 resumeSession: true,
2827 })
2828 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002829 name: "Basic-Client-Implicit",
2830 config: Config{
2831 MaxVersion: VersionTLS12,
2832 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002833 flags: []string{"-implicit-handshake"},
2834 resumeSession: true,
2835 })
2836 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002837 testType: serverTest,
2838 name: "Basic-Server",
2839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002840 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002841 Bugs: ProtocolBugs{
2842 RequireSessionTickets: true,
2843 },
2844 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002845 resumeSession: true,
2846 })
2847 tests = append(tests, testCase{
2848 testType: serverTest,
2849 name: "Basic-Server-NoTickets",
2850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002851 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002852 SessionTicketsDisabled: true,
2853 },
2854 resumeSession: true,
2855 })
2856 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002857 testType: serverTest,
2858 name: "Basic-Server-Implicit",
2859 config: Config{
2860 MaxVersion: VersionTLS12,
2861 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002862 flags: []string{"-implicit-handshake"},
2863 resumeSession: true,
2864 })
2865 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002866 testType: serverTest,
2867 name: "Basic-Server-EarlyCallback",
2868 config: Config{
2869 MaxVersion: VersionTLS12,
2870 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002871 flags: []string{"-use-early-callback"},
2872 resumeSession: true,
2873 })
2874
2875 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002876 //
2877 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002878 tests = append(tests, testCase{
2879 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002880 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002882 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002883 ClientAuth: RequestClientCert,
2884 },
2885 })
2886 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002887 testType: serverTest,
2888 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002889 config: Config{
2890 MaxVersion: VersionTLS12,
2891 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002892 // Setting SSL_VERIFY_PEER allows anonymous clients.
2893 flags: []string{"-verify-peer"},
2894 })
David Benjamin582ba042016-07-07 12:33:25 -07002895 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002896 tests = append(tests, testCase{
2897 testType: clientTest,
2898 name: "ClientAuth-NoCertificate-Client-SSL3",
2899 config: Config{
2900 MaxVersion: VersionSSL30,
2901 ClientAuth: RequestClientCert,
2902 },
2903 })
2904 tests = append(tests, testCase{
2905 testType: serverTest,
2906 name: "ClientAuth-NoCertificate-Server-SSL3",
2907 config: Config{
2908 MaxVersion: VersionSSL30,
2909 },
2910 // Setting SSL_VERIFY_PEER allows anonymous clients.
2911 flags: []string{"-verify-peer"},
2912 })
2913 }
2914 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002915 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002916 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002918 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002919 ClientAuth: RequireAnyClientCert,
2920 },
2921 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002922 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2923 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002924 },
2925 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002926 tests = append(tests, testCase{
2927 testType: clientTest,
2928 name: "ClientAuth-ECDSA-Client",
2929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002930 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002931 ClientAuth: RequireAnyClientCert,
2932 },
2933 flags: []string{
2934 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2935 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2936 },
2937 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002938 tests = append(tests, testCase{
2939 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002940 name: "ClientAuth-NoCertificate-OldCallback",
2941 config: Config{
2942 MaxVersion: VersionTLS12,
2943 ClientAuth: RequestClientCert,
2944 },
2945 flags: []string{"-use-old-client-cert-callback"},
2946 })
2947 tests = append(tests, testCase{
2948 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002949 name: "ClientAuth-OldCallback",
2950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-use-old-client-cert-callback",
2958 },
2959 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002960 tests = append(tests, testCase{
2961 testType: serverTest,
2962 name: "ClientAuth-Server",
2963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002964 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002965 Certificates: []Certificate{rsaCertificate},
2966 },
2967 flags: []string{"-require-any-client-certificate"},
2968 })
2969
David Benjamin4c3ddf72016-06-29 18:13:53 -04002970 // Test each key exchange on the server side for async keys.
2971 //
2972 // TODO(davidben): Add TLS 1.3 versions of these.
2973 tests = append(tests, testCase{
2974 testType: serverTest,
2975 name: "Basic-Server-RSA",
2976 config: Config{
2977 MaxVersion: VersionTLS12,
2978 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2979 },
2980 flags: []string{
2981 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2982 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2983 },
2984 })
2985 tests = append(tests, testCase{
2986 testType: serverTest,
2987 name: "Basic-Server-ECDHE-RSA",
2988 config: Config{
2989 MaxVersion: VersionTLS12,
2990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2991 },
2992 flags: []string{
2993 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2994 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2995 },
2996 })
2997 tests = append(tests, testCase{
2998 testType: serverTest,
2999 name: "Basic-Server-ECDHE-ECDSA",
3000 config: Config{
3001 MaxVersion: VersionTLS12,
3002 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3003 },
3004 flags: []string{
3005 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3006 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3007 },
3008 })
3009
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 // No session ticket support; server doesn't send NewSessionTicket.
3011 tests = append(tests, testCase{
3012 name: "SessionTicketsDisabled-Client",
3013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003014 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003015 SessionTicketsDisabled: true,
3016 },
3017 })
3018 tests = append(tests, testCase{
3019 testType: serverTest,
3020 name: "SessionTicketsDisabled-Server",
3021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003022 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 SessionTicketsDisabled: true,
3024 },
3025 })
3026
3027 // Skip ServerKeyExchange in PSK key exchange if there's no
3028 // identity hint.
3029 tests = append(tests, testCase{
3030 name: "EmptyPSKHint-Client",
3031 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003032 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003033 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3034 PreSharedKey: []byte("secret"),
3035 },
3036 flags: []string{"-psk", "secret"},
3037 })
3038 tests = append(tests, testCase{
3039 testType: serverTest,
3040 name: "EmptyPSKHint-Server",
3041 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003042 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3044 PreSharedKey: []byte("secret"),
3045 },
3046 flags: []string{"-psk", "secret"},
3047 })
3048
David Benjamin4c3ddf72016-06-29 18:13:53 -04003049 // OCSP stapling tests.
3050 //
3051 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003052 tests = append(tests, testCase{
3053 testType: clientTest,
3054 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003055 config: Config{
3056 MaxVersion: VersionTLS12,
3057 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003058 flags: []string{
3059 "-enable-ocsp-stapling",
3060 "-expect-ocsp-response",
3061 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003062 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003063 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003064 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003065 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003066 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 testType: serverTest,
3068 name: "OCSPStapling-Server",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003072 expectedOCSPResponse: testOCSPResponse,
3073 flags: []string{
3074 "-ocsp-response",
3075 base64.StdEncoding.EncodeToString(testOCSPResponse),
3076 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003077 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003078 })
3079
David Benjamin4c3ddf72016-06-29 18:13:53 -04003080 // Certificate verification tests.
3081 //
3082 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003083 tests = append(tests, testCase{
3084 testType: clientTest,
3085 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003086 config: Config{
3087 MaxVersion: VersionTLS12,
3088 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003089 flags: []string{
3090 "-verify-peer",
3091 },
3092 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003093 tests = append(tests, testCase{
3094 testType: clientTest,
3095 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 config: Config{
3097 MaxVersion: VersionTLS12,
3098 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003099 flags: []string{
3100 "-verify-fail",
3101 "-verify-peer",
3102 },
3103 shouldFail: true,
3104 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3105 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003106 tests = append(tests, testCase{
3107 testType: clientTest,
3108 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 config: Config{
3110 MaxVersion: VersionTLS12,
3111 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003112 flags: []string{
3113 "-verify-fail",
3114 "-expect-verify-result",
3115 },
3116 })
3117
David Benjamin582ba042016-07-07 12:33:25 -07003118 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003119 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003120 name: "Renegotiate-Client",
3121 config: Config{
3122 MaxVersion: VersionTLS12,
3123 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003124 renegotiate: 1,
3125 flags: []string{
3126 "-renegotiate-freely",
3127 "-expect-total-renegotiations", "1",
3128 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003129 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003130
David Benjamin760b1dd2015-05-15 23:33:48 -04003131 // NPN on client and server; results in post-handshake message.
3132 tests = append(tests, testCase{
3133 name: "NPN-Client",
3134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003135 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003136 NextProtos: []string{"foo"},
3137 },
3138 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003139 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003140 expectedNextProto: "foo",
3141 expectedNextProtoType: npn,
3142 })
3143 tests = append(tests, testCase{
3144 testType: serverTest,
3145 name: "NPN-Server",
3146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003147 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003148 NextProtos: []string{"bar"},
3149 },
3150 flags: []string{
3151 "-advertise-npn", "\x03foo\x03bar\x03baz",
3152 "-expect-next-proto", "bar",
3153 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003154 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003155 expectedNextProto: "bar",
3156 expectedNextProtoType: npn,
3157 })
3158
3159 // TODO(davidben): Add tests for when False Start doesn't trigger.
3160
3161 // Client does False Start and negotiates NPN.
3162 tests = append(tests, testCase{
3163 name: "FalseStart",
3164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003165 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3167 NextProtos: []string{"foo"},
3168 Bugs: ProtocolBugs{
3169 ExpectFalseStart: true,
3170 },
3171 },
3172 flags: []string{
3173 "-false-start",
3174 "-select-next-proto", "foo",
3175 },
3176 shimWritesFirst: true,
3177 resumeSession: true,
3178 })
3179
3180 // Client does False Start and negotiates ALPN.
3181 tests = append(tests, testCase{
3182 name: "FalseStart-ALPN",
3183 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003184 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003185 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3186 NextProtos: []string{"foo"},
3187 Bugs: ProtocolBugs{
3188 ExpectFalseStart: true,
3189 },
3190 },
3191 flags: []string{
3192 "-false-start",
3193 "-advertise-alpn", "\x03foo",
3194 },
3195 shimWritesFirst: true,
3196 resumeSession: true,
3197 })
3198
3199 // Client does False Start but doesn't explicitly call
3200 // SSL_connect.
3201 tests = append(tests, testCase{
3202 name: "FalseStart-Implicit",
3203 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003204 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3206 NextProtos: []string{"foo"},
3207 },
3208 flags: []string{
3209 "-implicit-handshake",
3210 "-false-start",
3211 "-advertise-alpn", "\x03foo",
3212 },
3213 })
3214
3215 // False Start without session tickets.
3216 tests = append(tests, testCase{
3217 name: "FalseStart-SessionTicketsDisabled",
3218 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003219 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3221 NextProtos: []string{"foo"},
3222 SessionTicketsDisabled: true,
3223 Bugs: ProtocolBugs{
3224 ExpectFalseStart: true,
3225 },
3226 },
3227 flags: []string{
3228 "-false-start",
3229 "-select-next-proto", "foo",
3230 },
3231 shimWritesFirst: true,
3232 })
3233
3234 // Server parses a V2ClientHello.
3235 tests = append(tests, testCase{
3236 testType: serverTest,
3237 name: "SendV2ClientHello",
3238 config: Config{
3239 // Choose a cipher suite that does not involve
3240 // elliptic curves, so no extensions are
3241 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003242 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003243 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3244 Bugs: ProtocolBugs{
3245 SendV2ClientHello: true,
3246 },
3247 },
3248 })
3249
3250 // Client sends a Channel ID.
3251 tests = append(tests, testCase{
3252 name: "ChannelID-Client",
3253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003254 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003255 RequestChannelID: true,
3256 },
Adam Langley7c803a62015-06-15 15:35:05 -07003257 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 resumeSession: true,
3259 expectChannelID: true,
3260 })
3261
3262 // Server accepts a Channel ID.
3263 tests = append(tests, testCase{
3264 testType: serverTest,
3265 name: "ChannelID-Server",
3266 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003267 MaxVersion: VersionTLS12,
3268 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003269 },
3270 flags: []string{
3271 "-expect-channel-id",
3272 base64.StdEncoding.EncodeToString(channelIDBytes),
3273 },
3274 resumeSession: true,
3275 expectChannelID: true,
3276 })
David Benjamin30789da2015-08-29 22:56:45 -04003277
David Benjaminf8fcdf32016-06-08 15:56:13 -04003278 // Channel ID and NPN at the same time, to ensure their relative
3279 // ordering is correct.
3280 tests = append(tests, testCase{
3281 name: "ChannelID-NPN-Client",
3282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003283 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003284 RequestChannelID: true,
3285 NextProtos: []string{"foo"},
3286 },
3287 flags: []string{
3288 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3289 "-select-next-proto", "foo",
3290 },
3291 resumeSession: true,
3292 expectChannelID: true,
3293 expectedNextProto: "foo",
3294 expectedNextProtoType: npn,
3295 })
3296 tests = append(tests, testCase{
3297 testType: serverTest,
3298 name: "ChannelID-NPN-Server",
3299 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003300 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003301 ChannelID: channelIDKey,
3302 NextProtos: []string{"bar"},
3303 },
3304 flags: []string{
3305 "-expect-channel-id",
3306 base64.StdEncoding.EncodeToString(channelIDBytes),
3307 "-advertise-npn", "\x03foo\x03bar\x03baz",
3308 "-expect-next-proto", "bar",
3309 },
3310 resumeSession: true,
3311 expectChannelID: true,
3312 expectedNextProto: "bar",
3313 expectedNextProtoType: npn,
3314 })
3315
David Benjamin30789da2015-08-29 22:56:45 -04003316 // Bidirectional shutdown with the runner initiating.
3317 tests = append(tests, testCase{
3318 name: "Shutdown-Runner",
3319 config: Config{
3320 Bugs: ProtocolBugs{
3321 ExpectCloseNotify: true,
3322 },
3323 },
3324 flags: []string{"-check-close-notify"},
3325 })
3326
3327 // Bidirectional shutdown with the shim initiating. The runner,
3328 // in the meantime, sends garbage before the close_notify which
3329 // the shim must ignore.
3330 tests = append(tests, testCase{
3331 name: "Shutdown-Shim",
3332 config: Config{
3333 Bugs: ProtocolBugs{
3334 ExpectCloseNotify: true,
3335 },
3336 },
3337 shimShutsDown: true,
3338 sendEmptyRecords: 1,
3339 sendWarningAlerts: 1,
3340 flags: []string{"-check-close-notify"},
3341 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003342 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003343 // TODO(davidben): DTLS 1.3 will want a similar thing for
3344 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 tests = append(tests, testCase{
3346 name: "SkipHelloVerifyRequest",
3347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003349 Bugs: ProtocolBugs{
3350 SkipHelloVerifyRequest: true,
3351 },
3352 },
3353 })
3354 }
3355
David Benjamin760b1dd2015-05-15 23:33:48 -04003356 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003357 test.protocol = config.protocol
3358 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003359 test.name += "-DTLS"
3360 }
David Benjamin582ba042016-07-07 12:33:25 -07003361 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003362 test.name += "-Async"
3363 test.flags = append(test.flags, "-async")
3364 } else {
3365 test.name += "-Sync"
3366 }
David Benjamin582ba042016-07-07 12:33:25 -07003367 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003368 test.name += "-SplitHandshakeRecords"
3369 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003370 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003371 test.config.Bugs.MaxPacketLength = 256
3372 test.flags = append(test.flags, "-mtu", "256")
3373 }
3374 }
David Benjamin582ba042016-07-07 12:33:25 -07003375 if config.packHandshakeFlight {
3376 test.name += "-PackHandshakeFlight"
3377 test.config.Bugs.PackHandshakeFlight = true
3378 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003379 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003380 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003381}
3382
Adam Langley524e7172015-02-20 16:04:00 -08003383func addDDoSCallbackTests() {
3384 // DDoS callback.
3385
3386 for _, resume := range []bool{false, true} {
3387 suffix := "Resume"
3388 if resume {
3389 suffix = "No" + suffix
3390 }
3391
David Benjamin4c3ddf72016-06-29 18:13:53 -04003392 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3393
Adam Langley524e7172015-02-20 16:04:00 -08003394 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003395 testType: serverTest,
3396 name: "Server-DDoS-OK-" + suffix,
3397 config: Config{
3398 MaxVersion: VersionTLS12,
3399 },
Adam Langley524e7172015-02-20 16:04:00 -08003400 flags: []string{"-install-ddos-callback"},
3401 resumeSession: resume,
3402 })
3403
3404 failFlag := "-fail-ddos-callback"
3405 if resume {
3406 failFlag = "-fail-second-ddos-callback"
3407 }
3408 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003409 testType: serverTest,
3410 name: "Server-DDoS-Reject-" + suffix,
3411 config: Config{
3412 MaxVersion: VersionTLS12,
3413 },
Adam Langley524e7172015-02-20 16:04:00 -08003414 flags: []string{"-install-ddos-callback", failFlag},
3415 resumeSession: resume,
3416 shouldFail: true,
3417 expectedError: ":CONNECTION_REJECTED:",
3418 })
3419 }
3420}
3421
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003422func addVersionNegotiationTests() {
3423 for i, shimVers := range tlsVersions {
3424 // Assemble flags to disable all newer versions on the shim.
3425 var flags []string
3426 for _, vers := range tlsVersions[i+1:] {
3427 flags = append(flags, vers.flag)
3428 }
3429
3430 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003431 protocols := []protocol{tls}
3432 if runnerVers.hasDTLS && shimVers.hasDTLS {
3433 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003434 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003435 for _, protocol := range protocols {
3436 expectedVersion := shimVers.version
3437 if runnerVers.version < shimVers.version {
3438 expectedVersion = runnerVers.version
3439 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003440
David Benjamin8b8c0062014-11-23 02:47:52 -05003441 suffix := shimVers.name + "-" + runnerVers.name
3442 if protocol == dtls {
3443 suffix += "-DTLS"
3444 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003445
David Benjamin1eb367c2014-12-12 18:17:51 -05003446 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3447
David Benjamin1e29a6b2014-12-10 02:27:24 -05003448 clientVers := shimVers.version
3449 if clientVers > VersionTLS10 {
3450 clientVers = VersionTLS10
3451 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003452 serverVers := expectedVersion
3453 if expectedVersion >= VersionTLS13 {
3454 serverVers = VersionTLS10
3455 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003456 testCases = append(testCases, testCase{
3457 protocol: protocol,
3458 testType: clientTest,
3459 name: "VersionNegotiation-Client-" + suffix,
3460 config: Config{
3461 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003462 Bugs: ProtocolBugs{
3463 ExpectInitialRecordVersion: clientVers,
3464 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003465 },
3466 flags: flags,
3467 expectedVersion: expectedVersion,
3468 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003469 testCases = append(testCases, testCase{
3470 protocol: protocol,
3471 testType: clientTest,
3472 name: "VersionNegotiation-Client2-" + suffix,
3473 config: Config{
3474 MaxVersion: runnerVers.version,
3475 Bugs: ProtocolBugs{
3476 ExpectInitialRecordVersion: clientVers,
3477 },
3478 },
3479 flags: []string{"-max-version", shimVersFlag},
3480 expectedVersion: expectedVersion,
3481 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003482
3483 testCases = append(testCases, testCase{
3484 protocol: protocol,
3485 testType: serverTest,
3486 name: "VersionNegotiation-Server-" + suffix,
3487 config: Config{
3488 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003489 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003490 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003491 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003492 },
3493 flags: flags,
3494 expectedVersion: expectedVersion,
3495 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003496 testCases = append(testCases, testCase{
3497 protocol: protocol,
3498 testType: serverTest,
3499 name: "VersionNegotiation-Server2-" + suffix,
3500 config: Config{
3501 MaxVersion: runnerVers.version,
3502 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003503 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003504 },
3505 },
3506 flags: []string{"-max-version", shimVersFlag},
3507 expectedVersion: expectedVersion,
3508 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003509 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003510 }
3511 }
David Benjamin95c69562016-06-29 18:15:03 -04003512
3513 // Test for version tolerance.
3514 testCases = append(testCases, testCase{
3515 testType: serverTest,
3516 name: "MinorVersionTolerance",
3517 config: Config{
3518 Bugs: ProtocolBugs{
3519 SendClientVersion: 0x03ff,
3520 },
3521 },
3522 expectedVersion: VersionTLS13,
3523 })
3524 testCases = append(testCases, testCase{
3525 testType: serverTest,
3526 name: "MajorVersionTolerance",
3527 config: Config{
3528 Bugs: ProtocolBugs{
3529 SendClientVersion: 0x0400,
3530 },
3531 },
3532 expectedVersion: VersionTLS13,
3533 })
3534 testCases = append(testCases, testCase{
3535 protocol: dtls,
3536 testType: serverTest,
3537 name: "MinorVersionTolerance-DTLS",
3538 config: Config{
3539 Bugs: ProtocolBugs{
3540 SendClientVersion: 0x03ff,
3541 },
3542 },
3543 expectedVersion: VersionTLS12,
3544 })
3545 testCases = append(testCases, testCase{
3546 protocol: dtls,
3547 testType: serverTest,
3548 name: "MajorVersionTolerance-DTLS",
3549 config: Config{
3550 Bugs: ProtocolBugs{
3551 SendClientVersion: 0x0400,
3552 },
3553 },
3554 expectedVersion: VersionTLS12,
3555 })
3556
3557 // Test that versions below 3.0 are rejected.
3558 testCases = append(testCases, testCase{
3559 testType: serverTest,
3560 name: "VersionTooLow",
3561 config: Config{
3562 Bugs: ProtocolBugs{
3563 SendClientVersion: 0x0200,
3564 },
3565 },
3566 shouldFail: true,
3567 expectedError: ":UNSUPPORTED_PROTOCOL:",
3568 })
3569 testCases = append(testCases, testCase{
3570 protocol: dtls,
3571 testType: serverTest,
3572 name: "VersionTooLow-DTLS",
3573 config: Config{
3574 Bugs: ProtocolBugs{
3575 // 0x0201 is the lowest version expressable in
3576 // DTLS.
3577 SendClientVersion: 0x0201,
3578 },
3579 },
3580 shouldFail: true,
3581 expectedError: ":UNSUPPORTED_PROTOCOL:",
3582 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003583}
3584
David Benjaminaccb4542014-12-12 23:44:33 -05003585func addMinimumVersionTests() {
3586 for i, shimVers := range tlsVersions {
3587 // Assemble flags to disable all older versions on the shim.
3588 var flags []string
3589 for _, vers := range tlsVersions[:i] {
3590 flags = append(flags, vers.flag)
3591 }
3592
3593 for _, runnerVers := range tlsVersions {
3594 protocols := []protocol{tls}
3595 if runnerVers.hasDTLS && shimVers.hasDTLS {
3596 protocols = append(protocols, dtls)
3597 }
3598 for _, protocol := range protocols {
3599 suffix := shimVers.name + "-" + runnerVers.name
3600 if protocol == dtls {
3601 suffix += "-DTLS"
3602 }
3603 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3604
David Benjaminaccb4542014-12-12 23:44:33 -05003605 var expectedVersion uint16
3606 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003607 var expectedClientError, expectedServerError string
3608 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003609 if runnerVers.version >= shimVers.version {
3610 expectedVersion = runnerVers.version
3611 } else {
3612 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003613 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3614 expectedServerLocalError = "remote error: protocol version not supported"
3615 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3616 // If the client's minimum version is TLS 1.3 and the runner's
3617 // maximum is below TLS 1.2, the runner will fail to select a
3618 // cipher before the shim rejects the selected version.
3619 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3620 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3621 } else {
3622 expectedClientError = expectedServerError
3623 expectedClientLocalError = expectedServerLocalError
3624 }
David Benjaminaccb4542014-12-12 23:44:33 -05003625 }
3626
3627 testCases = append(testCases, testCase{
3628 protocol: protocol,
3629 testType: clientTest,
3630 name: "MinimumVersion-Client-" + suffix,
3631 config: Config{
3632 MaxVersion: runnerVers.version,
3633 },
David Benjamin87909c02014-12-13 01:55:01 -05003634 flags: flags,
3635 expectedVersion: expectedVersion,
3636 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003637 expectedError: expectedClientError,
3638 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003639 })
3640 testCases = append(testCases, testCase{
3641 protocol: protocol,
3642 testType: clientTest,
3643 name: "MinimumVersion-Client2-" + suffix,
3644 config: Config{
3645 MaxVersion: runnerVers.version,
3646 },
David Benjamin87909c02014-12-13 01:55:01 -05003647 flags: []string{"-min-version", shimVersFlag},
3648 expectedVersion: expectedVersion,
3649 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003650 expectedError: expectedClientError,
3651 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003652 })
3653
3654 testCases = append(testCases, testCase{
3655 protocol: protocol,
3656 testType: serverTest,
3657 name: "MinimumVersion-Server-" + suffix,
3658 config: Config{
3659 MaxVersion: runnerVers.version,
3660 },
David Benjamin87909c02014-12-13 01:55:01 -05003661 flags: flags,
3662 expectedVersion: expectedVersion,
3663 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003664 expectedError: expectedServerError,
3665 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003666 })
3667 testCases = append(testCases, testCase{
3668 protocol: protocol,
3669 testType: serverTest,
3670 name: "MinimumVersion-Server2-" + suffix,
3671 config: Config{
3672 MaxVersion: runnerVers.version,
3673 },
David Benjamin87909c02014-12-13 01:55:01 -05003674 flags: []string{"-min-version", shimVersFlag},
3675 expectedVersion: expectedVersion,
3676 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003677 expectedError: expectedServerError,
3678 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003679 })
3680 }
3681 }
3682 }
3683}
3684
David Benjamine78bfde2014-09-06 12:45:15 -04003685func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003686 // TODO(davidben): Extensions, where applicable, all move their server
3687 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3688 // tests for both. Also test interaction with 0-RTT when implemented.
3689
David Benjamine78bfde2014-09-06 12:45:15 -04003690 testCases = append(testCases, testCase{
3691 testType: clientTest,
3692 name: "DuplicateExtensionClient",
3693 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003694 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003695 Bugs: ProtocolBugs{
3696 DuplicateExtension: true,
3697 },
3698 },
3699 shouldFail: true,
3700 expectedLocalError: "remote error: error decoding message",
3701 })
3702 testCases = append(testCases, testCase{
3703 testType: serverTest,
3704 name: "DuplicateExtensionServer",
3705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003706 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003707 Bugs: ProtocolBugs{
3708 DuplicateExtension: true,
3709 },
3710 },
3711 shouldFail: true,
3712 expectedLocalError: "remote error: error decoding message",
3713 })
3714 testCases = append(testCases, testCase{
3715 testType: clientTest,
3716 name: "ServerNameExtensionClient",
3717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003718 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003719 Bugs: ProtocolBugs{
3720 ExpectServerName: "example.com",
3721 },
3722 },
3723 flags: []string{"-host-name", "example.com"},
3724 })
3725 testCases = append(testCases, testCase{
3726 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003727 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003728 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003729 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003730 Bugs: ProtocolBugs{
3731 ExpectServerName: "mismatch.com",
3732 },
3733 },
3734 flags: []string{"-host-name", "example.com"},
3735 shouldFail: true,
3736 expectedLocalError: "tls: unexpected server name",
3737 })
3738 testCases = append(testCases, testCase{
3739 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003740 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003742 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003743 Bugs: ProtocolBugs{
3744 ExpectServerName: "missing.com",
3745 },
3746 },
3747 shouldFail: true,
3748 expectedLocalError: "tls: unexpected server name",
3749 })
3750 testCases = append(testCases, testCase{
3751 testType: serverTest,
3752 name: "ServerNameExtensionServer",
3753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003754 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003755 ServerName: "example.com",
3756 },
3757 flags: []string{"-expect-server-name", "example.com"},
3758 resumeSession: true,
3759 })
David Benjaminae2888f2014-09-06 12:58:58 -04003760 testCases = append(testCases, testCase{
3761 testType: clientTest,
3762 name: "ALPNClient",
3763 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003764 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003765 NextProtos: []string{"foo"},
3766 },
3767 flags: []string{
3768 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3769 "-expect-alpn", "foo",
3770 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003771 expectedNextProto: "foo",
3772 expectedNextProtoType: alpn,
3773 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003774 })
3775 testCases = append(testCases, testCase{
3776 testType: serverTest,
3777 name: "ALPNServer",
3778 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003779 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003780 NextProtos: []string{"foo", "bar", "baz"},
3781 },
3782 flags: []string{
3783 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3784 "-select-alpn", "foo",
3785 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003786 expectedNextProto: "foo",
3787 expectedNextProtoType: alpn,
3788 resumeSession: true,
3789 })
David Benjamin594e7d22016-03-17 17:49:56 -04003790 testCases = append(testCases, testCase{
3791 testType: serverTest,
3792 name: "ALPNServer-Decline",
3793 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003794 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003795 NextProtos: []string{"foo", "bar", "baz"},
3796 },
3797 flags: []string{"-decline-alpn"},
3798 expectNoNextProto: true,
3799 resumeSession: true,
3800 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003801 // Test that the server prefers ALPN over NPN.
3802 testCases = append(testCases, testCase{
3803 testType: serverTest,
3804 name: "ALPNServer-Preferred",
3805 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003806 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003807 NextProtos: []string{"foo", "bar", "baz"},
3808 },
3809 flags: []string{
3810 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3811 "-select-alpn", "foo",
3812 "-advertise-npn", "\x03foo\x03bar\x03baz",
3813 },
3814 expectedNextProto: "foo",
3815 expectedNextProtoType: alpn,
3816 resumeSession: true,
3817 })
3818 testCases = append(testCases, testCase{
3819 testType: serverTest,
3820 name: "ALPNServer-Preferred-Swapped",
3821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003822 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003823 NextProtos: []string{"foo", "bar", "baz"},
3824 Bugs: ProtocolBugs{
3825 SwapNPNAndALPN: true,
3826 },
3827 },
3828 flags: []string{
3829 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3830 "-select-alpn", "foo",
3831 "-advertise-npn", "\x03foo\x03bar\x03baz",
3832 },
3833 expectedNextProto: "foo",
3834 expectedNextProtoType: alpn,
3835 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003836 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003837 var emptyString string
3838 testCases = append(testCases, testCase{
3839 testType: clientTest,
3840 name: "ALPNClient-EmptyProtocolName",
3841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003842 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003843 NextProtos: []string{""},
3844 Bugs: ProtocolBugs{
3845 // A server returning an empty ALPN protocol
3846 // should be rejected.
3847 ALPNProtocol: &emptyString,
3848 },
3849 },
3850 flags: []string{
3851 "-advertise-alpn", "\x03foo",
3852 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003853 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003854 expectedError: ":PARSE_TLSEXT:",
3855 })
3856 testCases = append(testCases, testCase{
3857 testType: serverTest,
3858 name: "ALPNServer-EmptyProtocolName",
3859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003860 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003861 // A ClientHello containing an empty ALPN protocol
3862 // should be rejected.
3863 NextProtos: []string{"foo", "", "baz"},
3864 },
3865 flags: []string{
3866 "-select-alpn", "foo",
3867 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003868 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003869 expectedError: ":PARSE_TLSEXT:",
3870 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003871 // Test that negotiating both NPN and ALPN is forbidden.
3872 testCases = append(testCases, testCase{
3873 name: "NegotiateALPNAndNPN",
3874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003875 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003876 NextProtos: []string{"foo", "bar", "baz"},
3877 Bugs: ProtocolBugs{
3878 NegotiateALPNAndNPN: true,
3879 },
3880 },
3881 flags: []string{
3882 "-advertise-alpn", "\x03foo",
3883 "-select-next-proto", "foo",
3884 },
3885 shouldFail: true,
3886 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3887 })
3888 testCases = append(testCases, testCase{
3889 name: "NegotiateALPNAndNPN-Swapped",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003892 NextProtos: []string{"foo", "bar", "baz"},
3893 Bugs: ProtocolBugs{
3894 NegotiateALPNAndNPN: true,
3895 SwapNPNAndALPN: true,
3896 },
3897 },
3898 flags: []string{
3899 "-advertise-alpn", "\x03foo",
3900 "-select-next-proto", "foo",
3901 },
3902 shouldFail: true,
3903 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3904 })
David Benjamin091c4b92015-10-26 13:33:21 -04003905 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3906 testCases = append(testCases, testCase{
3907 name: "DisableNPN",
3908 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003909 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003910 NextProtos: []string{"foo"},
3911 },
3912 flags: []string{
3913 "-select-next-proto", "foo",
3914 "-disable-npn",
3915 },
3916 expectNoNextProto: true,
3917 })
Adam Langley38311732014-10-16 19:04:35 -07003918 // Resume with a corrupt ticket.
3919 testCases = append(testCases, testCase{
3920 testType: serverTest,
3921 name: "CorruptTicket",
3922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003924 Bugs: ProtocolBugs{
3925 CorruptTicket: true,
3926 },
3927 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003928 resumeSession: true,
3929 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003930 })
David Benjamind98452d2015-06-16 14:16:23 -04003931 // Test the ticket callback, with and without renewal.
3932 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003933 testType: serverTest,
3934 name: "TicketCallback",
3935 config: Config{
3936 MaxVersion: VersionTLS12,
3937 },
David Benjamind98452d2015-06-16 14:16:23 -04003938 resumeSession: true,
3939 flags: []string{"-use-ticket-callback"},
3940 })
3941 testCases = append(testCases, testCase{
3942 testType: serverTest,
3943 name: "TicketCallback-Renew",
3944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003945 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04003946 Bugs: ProtocolBugs{
3947 ExpectNewTicket: true,
3948 },
3949 },
3950 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3951 resumeSession: true,
3952 })
Adam Langley38311732014-10-16 19:04:35 -07003953 // Resume with an oversized session id.
3954 testCases = append(testCases, testCase{
3955 testType: serverTest,
3956 name: "OversizedSessionId",
3957 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003958 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003959 Bugs: ProtocolBugs{
3960 OversizedSessionId: true,
3961 },
3962 },
3963 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003964 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003965 expectedError: ":DECODE_ERROR:",
3966 })
David Benjaminca6c8262014-11-15 19:06:08 -05003967 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3968 // are ignored.
3969 testCases = append(testCases, testCase{
3970 protocol: dtls,
3971 name: "SRTP-Client",
3972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003973 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05003974 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3975 },
3976 flags: []string{
3977 "-srtp-profiles",
3978 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3979 },
3980 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3981 })
3982 testCases = append(testCases, testCase{
3983 protocol: dtls,
3984 testType: serverTest,
3985 name: "SRTP-Server",
3986 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003987 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05003988 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3989 },
3990 flags: []string{
3991 "-srtp-profiles",
3992 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3993 },
3994 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3995 })
3996 // Test that the MKI is ignored.
3997 testCases = append(testCases, testCase{
3998 protocol: dtls,
3999 testType: serverTest,
4000 name: "SRTP-Server-IgnoreMKI",
4001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004002 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004003 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4004 Bugs: ProtocolBugs{
4005 SRTPMasterKeyIdentifer: "bogus",
4006 },
4007 },
4008 flags: []string{
4009 "-srtp-profiles",
4010 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4011 },
4012 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4013 })
4014 // Test that SRTP isn't negotiated on the server if there were
4015 // no matching profiles.
4016 testCases = append(testCases, testCase{
4017 protocol: dtls,
4018 testType: serverTest,
4019 name: "SRTP-Server-NoMatch",
4020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004022 SRTPProtectionProfiles: []uint16{100, 101, 102},
4023 },
4024 flags: []string{
4025 "-srtp-profiles",
4026 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4027 },
4028 expectedSRTPProtectionProfile: 0,
4029 })
4030 // Test that the server returning an invalid SRTP profile is
4031 // flagged as an error by the client.
4032 testCases = append(testCases, testCase{
4033 protocol: dtls,
4034 name: "SRTP-Client-NoMatch",
4035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004037 Bugs: ProtocolBugs{
4038 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4039 },
4040 },
4041 flags: []string{
4042 "-srtp-profiles",
4043 "SRTP_AES128_CM_SHA1_80",
4044 },
4045 shouldFail: true,
4046 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4047 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004048 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004049 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004050 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004051 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004052 config: Config{
4053 MaxVersion: VersionTLS12,
4054 },
David Benjamin61f95272014-11-25 01:55:35 -05004055 flags: []string{
4056 "-enable-signed-cert-timestamps",
4057 "-expect-signed-cert-timestamps",
4058 base64.StdEncoding.EncodeToString(testSCTList),
4059 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004060 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004061 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004062 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004063 name: "SendSCTListOnResume",
4064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004065 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004066 Bugs: ProtocolBugs{
4067 SendSCTListOnResume: []byte("bogus"),
4068 },
4069 },
4070 flags: []string{
4071 "-enable-signed-cert-timestamps",
4072 "-expect-signed-cert-timestamps",
4073 base64.StdEncoding.EncodeToString(testSCTList),
4074 },
4075 resumeSession: true,
4076 })
4077 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004078 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004079 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004080 config: Config{
4081 MaxVersion: VersionTLS12,
4082 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004083 flags: []string{
4084 "-signed-cert-timestamps",
4085 base64.StdEncoding.EncodeToString(testSCTList),
4086 },
4087 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004088 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004089 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004090
Paul Lietar4fac72e2015-09-09 13:44:55 +01004091 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004092 testType: clientTest,
4093 name: "ClientHelloPadding",
4094 config: Config{
4095 Bugs: ProtocolBugs{
4096 RequireClientHelloSize: 512,
4097 },
4098 },
4099 // This hostname just needs to be long enough to push the
4100 // ClientHello into F5's danger zone between 256 and 511 bytes
4101 // long.
4102 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4103 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004104
4105 // Extensions should not function in SSL 3.0.
4106 testCases = append(testCases, testCase{
4107 testType: serverTest,
4108 name: "SSLv3Extensions-NoALPN",
4109 config: Config{
4110 MaxVersion: VersionSSL30,
4111 NextProtos: []string{"foo", "bar", "baz"},
4112 },
4113 flags: []string{
4114 "-select-alpn", "foo",
4115 },
4116 expectNoNextProto: true,
4117 })
4118
4119 // Test session tickets separately as they follow a different codepath.
4120 testCases = append(testCases, testCase{
4121 testType: serverTest,
4122 name: "SSLv3Extensions-NoTickets",
4123 config: Config{
4124 MaxVersion: VersionSSL30,
4125 Bugs: ProtocolBugs{
4126 // Historically, session tickets in SSL 3.0
4127 // failed in different ways depending on whether
4128 // the client supported renegotiation_info.
4129 NoRenegotiationInfo: true,
4130 },
4131 },
4132 resumeSession: true,
4133 })
4134 testCases = append(testCases, testCase{
4135 testType: serverTest,
4136 name: "SSLv3Extensions-NoTickets2",
4137 config: Config{
4138 MaxVersion: VersionSSL30,
4139 },
4140 resumeSession: true,
4141 })
4142
4143 // But SSL 3.0 does send and process renegotiation_info.
4144 testCases = append(testCases, testCase{
4145 testType: serverTest,
4146 name: "SSLv3Extensions-RenegotiationInfo",
4147 config: Config{
4148 MaxVersion: VersionSSL30,
4149 Bugs: ProtocolBugs{
4150 RequireRenegotiationInfo: true,
4151 },
4152 },
4153 })
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4157 config: Config{
4158 MaxVersion: VersionSSL30,
4159 Bugs: ProtocolBugs{
4160 NoRenegotiationInfo: true,
4161 SendRenegotiationSCSV: true,
4162 RequireRenegotiationInfo: true,
4163 },
4164 },
4165 })
David Benjamine78bfde2014-09-06 12:45:15 -04004166}
4167
David Benjamin01fe8202014-09-24 15:21:44 -04004168func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004169 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004170 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004171 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4172 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4173 // TLS 1.3 only shares ciphers with TLS 1.2, so
4174 // we skip certain combinations and use a
4175 // different cipher to test with.
4176 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4177 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4178 continue
4179 }
4180 }
4181
David Benjamin8b8c0062014-11-23 02:47:52 -05004182 protocols := []protocol{tls}
4183 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4184 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004185 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004186 for _, protocol := range protocols {
4187 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4188 if protocol == dtls {
4189 suffix += "-DTLS"
4190 }
4191
David Benjaminece3de92015-03-16 18:02:20 -04004192 if sessionVers.version == resumeVers.version {
4193 testCases = append(testCases, testCase{
4194 protocol: protocol,
4195 name: "Resume-Client" + suffix,
4196 resumeSession: true,
4197 config: Config{
4198 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004199 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004200 },
David Benjaminece3de92015-03-16 18:02:20 -04004201 expectedVersion: sessionVers.version,
4202 expectedResumeVersion: resumeVers.version,
4203 })
4204 } else {
4205 testCases = append(testCases, testCase{
4206 protocol: protocol,
4207 name: "Resume-Client-Mismatch" + suffix,
4208 resumeSession: true,
4209 config: Config{
4210 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004211 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004212 },
David Benjaminece3de92015-03-16 18:02:20 -04004213 expectedVersion: sessionVers.version,
4214 resumeConfig: &Config{
4215 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004216 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004217 Bugs: ProtocolBugs{
4218 AllowSessionVersionMismatch: true,
4219 },
4220 },
4221 expectedResumeVersion: resumeVers.version,
4222 shouldFail: true,
4223 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4224 })
4225 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004226
4227 testCases = append(testCases, testCase{
4228 protocol: protocol,
4229 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004230 resumeSession: true,
4231 config: Config{
4232 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004233 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004234 },
4235 expectedVersion: sessionVers.version,
4236 resumeConfig: &Config{
4237 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004238 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004239 },
4240 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004241 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004242 expectedResumeVersion: resumeVers.version,
4243 })
4244
David Benjamin8b8c0062014-11-23 02:47:52 -05004245 testCases = append(testCases, testCase{
4246 protocol: protocol,
4247 testType: serverTest,
4248 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004249 resumeSession: true,
4250 config: Config{
4251 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004252 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004253 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004254 expectedVersion: sessionVers.version,
4255 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004256 resumeConfig: &Config{
4257 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004258 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004259 },
4260 expectedResumeVersion: resumeVers.version,
4261 })
4262 }
David Benjamin01fe8202014-09-24 15:21:44 -04004263 }
4264 }
David Benjaminece3de92015-03-16 18:02:20 -04004265
Nick Harper1fd39d82016-06-14 18:14:35 -07004266 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004267 testCases = append(testCases, testCase{
4268 name: "Resume-Client-CipherMismatch",
4269 resumeSession: true,
4270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004271 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004272 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4273 },
4274 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004275 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004276 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4277 Bugs: ProtocolBugs{
4278 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4279 },
4280 },
4281 shouldFail: true,
4282 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4283 })
David Benjamin01fe8202014-09-24 15:21:44 -04004284}
4285
Adam Langley2ae77d22014-10-28 17:29:33 -07004286func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004287 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004288 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004289 testType: serverTest,
4290 name: "Renegotiate-Server-Forbidden",
4291 config: Config{
4292 MaxVersion: VersionTLS12,
4293 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004294 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004295 shouldFail: true,
4296 expectedError: ":NO_RENEGOTIATION:",
4297 expectedLocalError: "remote error: no renegotiation",
4298 })
Adam Langley5021b222015-06-12 18:27:58 -07004299 // The server shouldn't echo the renegotiation extension unless
4300 // requested by the client.
4301 testCases = append(testCases, testCase{
4302 testType: serverTest,
4303 name: "Renegotiate-Server-NoExt",
4304 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004305 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004306 Bugs: ProtocolBugs{
4307 NoRenegotiationInfo: true,
4308 RequireRenegotiationInfo: true,
4309 },
4310 },
4311 shouldFail: true,
4312 expectedLocalError: "renegotiation extension missing",
4313 })
4314 // The renegotiation SCSV should be sufficient for the server to echo
4315 // the extension.
4316 testCases = append(testCases, testCase{
4317 testType: serverTest,
4318 name: "Renegotiate-Server-NoExt-SCSV",
4319 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004320 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004321 Bugs: ProtocolBugs{
4322 NoRenegotiationInfo: true,
4323 SendRenegotiationSCSV: true,
4324 RequireRenegotiationInfo: true,
4325 },
4326 },
4327 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004328 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004329 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004330 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004331 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004332 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004333 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004334 },
4335 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004336 renegotiate: 1,
4337 flags: []string{
4338 "-renegotiate-freely",
4339 "-expect-total-renegotiations", "1",
4340 },
David Benjamincdea40c2015-03-19 14:09:43 -04004341 })
4342 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004343 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004344 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004345 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004346 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004347 Bugs: ProtocolBugs{
4348 EmptyRenegotiationInfo: true,
4349 },
4350 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004351 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004352 shouldFail: true,
4353 expectedError: ":RENEGOTIATION_MISMATCH:",
4354 })
4355 testCases = append(testCases, testCase{
4356 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004357 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004359 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004360 Bugs: ProtocolBugs{
4361 BadRenegotiationInfo: true,
4362 },
4363 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004364 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004365 shouldFail: true,
4366 expectedError: ":RENEGOTIATION_MISMATCH:",
4367 })
4368 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004369 name: "Renegotiate-Client-Downgrade",
4370 renegotiate: 1,
4371 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004372 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004373 Bugs: ProtocolBugs{
4374 NoRenegotiationInfoAfterInitial: true,
4375 },
4376 },
4377 flags: []string{"-renegotiate-freely"},
4378 shouldFail: true,
4379 expectedError: ":RENEGOTIATION_MISMATCH:",
4380 })
4381 testCases = append(testCases, testCase{
4382 name: "Renegotiate-Client-Upgrade",
4383 renegotiate: 1,
4384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004385 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004386 Bugs: ProtocolBugs{
4387 NoRenegotiationInfoInInitial: true,
4388 },
4389 },
4390 flags: []string{"-renegotiate-freely"},
4391 shouldFail: true,
4392 expectedError: ":RENEGOTIATION_MISMATCH:",
4393 })
4394 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004395 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004396 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004398 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004399 Bugs: ProtocolBugs{
4400 NoRenegotiationInfo: true,
4401 },
4402 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004403 flags: []string{
4404 "-renegotiate-freely",
4405 "-expect-total-renegotiations", "1",
4406 },
David Benjamincff0b902015-05-15 23:09:47 -04004407 })
4408 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004409 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004410 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004412 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004413 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4414 },
4415 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004416 flags: []string{
4417 "-renegotiate-freely",
4418 "-expect-total-renegotiations", "1",
4419 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004420 })
4421 testCases = append(testCases, testCase{
4422 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004423 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004424 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004425 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4427 },
4428 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004429 flags: []string{
4430 "-renegotiate-freely",
4431 "-expect-total-renegotiations", "1",
4432 },
David Benjaminb16346b2015-04-08 19:16:58 -04004433 })
4434 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004435 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004436 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004437 config: Config{
4438 MaxVersion: VersionTLS10,
4439 Bugs: ProtocolBugs{
4440 RequireSameRenegoClientVersion: true,
4441 },
4442 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004443 flags: []string{
4444 "-renegotiate-freely",
4445 "-expect-total-renegotiations", "1",
4446 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004447 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004448 testCases = append(testCases, testCase{
4449 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004450 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004451 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004452 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004453 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4454 NextProtos: []string{"foo"},
4455 },
4456 flags: []string{
4457 "-false-start",
4458 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004459 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004460 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004461 },
4462 shimWritesFirst: true,
4463 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004464
4465 // Client-side renegotiation controls.
4466 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004467 name: "Renegotiate-Client-Forbidden-1",
4468 config: Config{
4469 MaxVersion: VersionTLS12,
4470 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004471 renegotiate: 1,
4472 shouldFail: true,
4473 expectedError: ":NO_RENEGOTIATION:",
4474 expectedLocalError: "remote error: no renegotiation",
4475 })
4476 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004477 name: "Renegotiate-Client-Once-1",
4478 config: Config{
4479 MaxVersion: VersionTLS12,
4480 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004481 renegotiate: 1,
4482 flags: []string{
4483 "-renegotiate-once",
4484 "-expect-total-renegotiations", "1",
4485 },
4486 })
4487 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004488 name: "Renegotiate-Client-Freely-1",
4489 config: Config{
4490 MaxVersion: VersionTLS12,
4491 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004492 renegotiate: 1,
4493 flags: []string{
4494 "-renegotiate-freely",
4495 "-expect-total-renegotiations", "1",
4496 },
4497 })
4498 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 name: "Renegotiate-Client-Once-2",
4500 config: Config{
4501 MaxVersion: VersionTLS12,
4502 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004503 renegotiate: 2,
4504 flags: []string{"-renegotiate-once"},
4505 shouldFail: true,
4506 expectedError: ":NO_RENEGOTIATION:",
4507 expectedLocalError: "remote error: no renegotiation",
4508 })
4509 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004510 name: "Renegotiate-Client-Freely-2",
4511 config: Config{
4512 MaxVersion: VersionTLS12,
4513 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004514 renegotiate: 2,
4515 flags: []string{
4516 "-renegotiate-freely",
4517 "-expect-total-renegotiations", "2",
4518 },
4519 })
Adam Langley27a0d082015-11-03 13:34:10 -08004520 testCases = append(testCases, testCase{
4521 name: "Renegotiate-Client-NoIgnore",
4522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004523 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004524 Bugs: ProtocolBugs{
4525 SendHelloRequestBeforeEveryAppDataRecord: true,
4526 },
4527 },
4528 shouldFail: true,
4529 expectedError: ":NO_RENEGOTIATION:",
4530 })
4531 testCases = append(testCases, testCase{
4532 name: "Renegotiate-Client-Ignore",
4533 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004534 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004535 Bugs: ProtocolBugs{
4536 SendHelloRequestBeforeEveryAppDataRecord: true,
4537 },
4538 },
4539 flags: []string{
4540 "-renegotiate-ignore",
4541 "-expect-total-renegotiations", "0",
4542 },
4543 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004544
4545 // TODO(davidben): Add a test that HelloRequests are illegal in TLS 1.3.
Adam Langley2ae77d22014-10-28 17:29:33 -07004546}
4547
David Benjamin5e961c12014-11-07 01:48:35 -05004548func addDTLSReplayTests() {
4549 // Test that sequence number replays are detected.
4550 testCases = append(testCases, testCase{
4551 protocol: dtls,
4552 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004553 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004554 replayWrites: true,
4555 })
4556
David Benjamin8e6db492015-07-25 18:29:23 -04004557 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004558 // than the retransmit window.
4559 testCases = append(testCases, testCase{
4560 protocol: dtls,
4561 name: "DTLS-Replay-LargeGaps",
4562 config: Config{
4563 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004564 SequenceNumberMapping: func(in uint64) uint64 {
4565 return in * 127
4566 },
David Benjamin5e961c12014-11-07 01:48:35 -05004567 },
4568 },
David Benjamin8e6db492015-07-25 18:29:23 -04004569 messageCount: 200,
4570 replayWrites: true,
4571 })
4572
4573 // Test the incoming sequence number changing non-monotonically.
4574 testCases = append(testCases, testCase{
4575 protocol: dtls,
4576 name: "DTLS-Replay-NonMonotonic",
4577 config: Config{
4578 Bugs: ProtocolBugs{
4579 SequenceNumberMapping: func(in uint64) uint64 {
4580 return in ^ 31
4581 },
4582 },
4583 },
4584 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004585 replayWrites: true,
4586 })
4587}
4588
Nick Harper60edffd2016-06-21 15:19:24 -07004589var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004590 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004591 id signatureAlgorithm
4592 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004593}{
Nick Harper60edffd2016-06-21 15:19:24 -07004594 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4595 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4596 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4597 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
4598 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSA},
4599 // TODO(davidben): These signature algorithms are paired with a curve in
4600 // TLS 1.3. Test that, in TLS 1.3, the curves must match and, in TLS
4601 // 1.2, mismatches are tolerated.
4602 {"ECDSA-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSA},
4603 {"ECDSA-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSA},
4604 {"ECDSA-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSA},
David Benjamin000800a2014-11-14 01:43:59 -05004605}
4606
Nick Harper60edffd2016-06-21 15:19:24 -07004607const fakeSigAlg1 signatureAlgorithm = 0x2a01
4608const fakeSigAlg2 signatureAlgorithm = 0xff01
4609
4610func addSignatureAlgorithmTests() {
4611 // Make sure each signature algorithm works. Include some fake values in
4612 // the list and ensure they're ignored.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004613 //
4614 // TODO(davidben): Test each of these against both TLS 1.2 and TLS 1.3.
Nick Harper60edffd2016-06-21 15:19:24 -07004615 for _, alg := range testSignatureAlgorithms {
David Benjamin000800a2014-11-14 01:43:59 -05004616 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004617 name: "SigningHash-ClientAuth-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004619 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004620 // SignatureAlgorithms is shared, so we must
4621 // configure a matching server certificate too.
4622 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4623 ClientAuth: RequireAnyClientCert,
4624 SignatureAlgorithms: []signatureAlgorithm{
4625 fakeSigAlg1,
4626 alg.id,
4627 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004628 },
4629 },
4630 flags: []string{
Nick Harper60edffd2016-06-21 15:19:24 -07004631 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4632 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4633 },
4634 expectedPeerSignatureAlgorithm: alg.id,
4635 })
4636
4637 testCases = append(testCases, testCase{
4638 testType: serverTest,
4639 name: "SigningHash-ClientAuth-Verify-" + alg.name,
4640 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004641 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004642 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4643 SignatureAlgorithms: []signatureAlgorithm{
4644 alg.id,
4645 },
4646 },
4647 flags: []string{
4648 "-require-any-client-certificate",
4649 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4650 // SignatureAlgorithms is shared, so we must
4651 // configure a matching server certificate too.
4652 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4653 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin000800a2014-11-14 01:43:59 -05004654 },
4655 })
4656
4657 testCases = append(testCases, testCase{
4658 testType: serverTest,
Nick Harper60edffd2016-06-21 15:19:24 -07004659 name: "SigningHash-ServerKeyExchange-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004661 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004662 CipherSuites: []uint16{
4663 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4664 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4665 },
4666 SignatureAlgorithms: []signatureAlgorithm{
4667 fakeSigAlg1,
4668 alg.id,
4669 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004670 },
4671 },
Nick Harper60edffd2016-06-21 15:19:24 -07004672 flags: []string{
4673 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4674 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4675 },
4676 expectedPeerSignatureAlgorithm: alg.id,
David Benjamin000800a2014-11-14 01:43:59 -05004677 })
David Benjamin6e807652015-11-02 12:02:20 -05004678
4679 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004680 name: "SigningHash-ServerKeyExchange-Verify-" + alg.name,
David Benjamin6e807652015-11-02 12:02:20 -05004681 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004682 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004683 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4684 CipherSuites: []uint16{
4685 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4686 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4687 },
4688 SignatureAlgorithms: []signatureAlgorithm{
4689 alg.id,
David Benjamin6e807652015-11-02 12:02:20 -05004690 },
4691 },
Nick Harper60edffd2016-06-21 15:19:24 -07004692 flags: []string{"-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id))},
David Benjamin6e807652015-11-02 12:02:20 -05004693 })
David Benjamin000800a2014-11-14 01:43:59 -05004694 }
4695
Nick Harper60edffd2016-06-21 15:19:24 -07004696 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004697 //
4698 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004699 testCases = append(testCases, testCase{
4700 name: "SigningHash-ClientAuth-SignatureType",
4701 config: Config{
4702 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004703 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004704 SignatureAlgorithms: []signatureAlgorithm{
4705 signatureECDSAWithP521AndSHA512,
4706 signatureRSAPKCS1WithSHA384,
4707 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004708 },
4709 },
4710 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004711 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4712 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004713 },
Nick Harper60edffd2016-06-21 15:19:24 -07004714 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004715 })
4716
4717 testCases = append(testCases, testCase{
4718 testType: serverTest,
4719 name: "SigningHash-ServerKeyExchange-SignatureType",
4720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004721 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004722 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004723 SignatureAlgorithms: []signatureAlgorithm{
4724 signatureECDSAWithP521AndSHA512,
4725 signatureRSAPKCS1WithSHA384,
4726 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004727 },
4728 },
Nick Harper60edffd2016-06-21 15:19:24 -07004729 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004730 })
4731
4732 // Test that, if the list is missing, the peer falls back to SHA-1.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004733 //
4734 // TODO(davidben): Test this does not happen in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004735 testCases = append(testCases, testCase{
4736 name: "SigningHash-ClientAuth-Fallback",
4737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004738 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004739 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004740 SignatureAlgorithms: []signatureAlgorithm{
4741 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004742 },
4743 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004744 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004745 },
4746 },
4747 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004748 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4749 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004750 },
4751 })
4752
4753 testCases = append(testCases, testCase{
4754 testType: serverTest,
4755 name: "SigningHash-ServerKeyExchange-Fallback",
4756 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004757 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004758 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004759 SignatureAlgorithms: []signatureAlgorithm{
4760 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004761 },
4762 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004763 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004764 },
4765 },
4766 })
David Benjamin72dc7832015-03-16 17:49:43 -04004767
4768 // Test that hash preferences are enforced. BoringSSL defaults to
4769 // rejecting MD5 signatures.
4770 testCases = append(testCases, testCase{
4771 testType: serverTest,
4772 name: "SigningHash-ClientAuth-Enforced",
4773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004774 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004775 Certificates: []Certificate{rsaCertificate},
Nick Harper60edffd2016-06-21 15:19:24 -07004776 SignatureAlgorithms: []signatureAlgorithm{
4777 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004778 // Advertise SHA-1 so the handshake will
4779 // proceed, but the shim's preferences will be
4780 // ignored in CertificateVerify generation, so
4781 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07004782 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04004783 },
4784 Bugs: ProtocolBugs{
4785 IgnorePeerSignatureAlgorithmPreferences: true,
4786 },
4787 },
4788 flags: []string{"-require-any-client-certificate"},
4789 shouldFail: true,
4790 expectedError: ":WRONG_SIGNATURE_TYPE:",
4791 })
4792
4793 testCases = append(testCases, testCase{
4794 name: "SigningHash-ServerKeyExchange-Enforced",
4795 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004796 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004798 SignatureAlgorithms: []signatureAlgorithm{
4799 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004800 },
4801 Bugs: ProtocolBugs{
4802 IgnorePeerSignatureAlgorithmPreferences: true,
4803 },
4804 },
4805 shouldFail: true,
4806 expectedError: ":WRONG_SIGNATURE_TYPE:",
4807 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004808
4809 // Test that the agreed upon digest respects the client preferences and
4810 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004811 //
4812 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04004813 testCases = append(testCases, testCase{
4814 name: "Agree-Digest-Fallback",
4815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004816 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004817 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004818 SignatureAlgorithms: []signatureAlgorithm{
4819 signatureRSAPKCS1WithSHA512,
4820 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004821 },
4822 },
4823 flags: []string{
4824 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4825 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4826 },
Nick Harper60edffd2016-06-21 15:19:24 -07004827 digestPrefs: "SHA256",
4828 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004829 })
4830 testCases = append(testCases, testCase{
4831 name: "Agree-Digest-SHA256",
4832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004833 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004834 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004835 SignatureAlgorithms: []signatureAlgorithm{
4836 signatureRSAPKCS1WithSHA1,
4837 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004838 },
4839 },
4840 flags: []string{
4841 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4842 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4843 },
Nick Harper60edffd2016-06-21 15:19:24 -07004844 digestPrefs: "SHA256,SHA1",
4845 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004846 })
4847 testCases = append(testCases, testCase{
4848 name: "Agree-Digest-SHA1",
4849 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004850 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004851 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004852 SignatureAlgorithms: []signatureAlgorithm{
4853 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004854 },
4855 },
4856 flags: []string{
4857 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4858 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4859 },
Nick Harper60edffd2016-06-21 15:19:24 -07004860 digestPrefs: "SHA512,SHA256,SHA1",
4861 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004862 })
4863 testCases = append(testCases, testCase{
4864 name: "Agree-Digest-Default",
4865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004866 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004867 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004868 SignatureAlgorithms: []signatureAlgorithm{
4869 signatureRSAPKCS1WithSHA256,
4870 signatureECDSAWithP256AndSHA256,
4871 signatureRSAPKCS1WithSHA1,
4872 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004873 },
4874 },
4875 flags: []string{
4876 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4877 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4878 },
Nick Harper60edffd2016-06-21 15:19:24 -07004879 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004880 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004881
4882 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
4883 // signature algorithms.
4884 //
4885 // TODO(davidben): Add a TLS 1.3 version of this test where the mismatch
4886 // is allowed.
4887 testCases = append(testCases, testCase{
4888 name: "CheckLeafCurve",
4889 config: Config{
4890 MaxVersion: VersionTLS12,
4891 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4892 Certificates: []Certificate{getECDSACertificate()},
4893 },
4894 flags: []string{"-p384-only"},
4895 shouldFail: true,
4896 expectedError: ":BAD_ECC_CERT:",
4897 })
David Benjamin000800a2014-11-14 01:43:59 -05004898}
4899
David Benjamin83f90402015-01-27 01:09:43 -05004900// timeouts is the retransmit schedule for BoringSSL. It doubles and
4901// caps at 60 seconds. On the 13th timeout, it gives up.
4902var timeouts = []time.Duration{
4903 1 * time.Second,
4904 2 * time.Second,
4905 4 * time.Second,
4906 8 * time.Second,
4907 16 * time.Second,
4908 32 * time.Second,
4909 60 * time.Second,
4910 60 * time.Second,
4911 60 * time.Second,
4912 60 * time.Second,
4913 60 * time.Second,
4914 60 * time.Second,
4915 60 * time.Second,
4916}
4917
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07004918// shortTimeouts is an alternate set of timeouts which would occur if the
4919// initial timeout duration was set to 250ms.
4920var shortTimeouts = []time.Duration{
4921 250 * time.Millisecond,
4922 500 * time.Millisecond,
4923 1 * time.Second,
4924 2 * time.Second,
4925 4 * time.Second,
4926 8 * time.Second,
4927 16 * time.Second,
4928 32 * time.Second,
4929 60 * time.Second,
4930 60 * time.Second,
4931 60 * time.Second,
4932 60 * time.Second,
4933 60 * time.Second,
4934}
4935
David Benjamin83f90402015-01-27 01:09:43 -05004936func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04004937 // These tests work by coordinating some behavior on both the shim and
4938 // the runner.
4939 //
4940 // TimeoutSchedule configures the runner to send a series of timeout
4941 // opcodes to the shim (see packetAdaptor) immediately before reading
4942 // each peer handshake flight N. The timeout opcode both simulates a
4943 // timeout in the shim and acts as a synchronization point to help the
4944 // runner bracket each handshake flight.
4945 //
4946 // We assume the shim does not read from the channel eagerly. It must
4947 // first wait until it has sent flight N and is ready to receive
4948 // handshake flight N+1. At this point, it will process the timeout
4949 // opcode. It must then immediately respond with a timeout ACK and act
4950 // as if the shim was idle for the specified amount of time.
4951 //
4952 // The runner then drops all packets received before the ACK and
4953 // continues waiting for flight N. This ordering results in one attempt
4954 // at sending flight N to be dropped. For the test to complete, the
4955 // shim must send flight N again, testing that the shim implements DTLS
4956 // retransmit on a timeout.
4957
David Benjamin4c3ddf72016-06-29 18:13:53 -04004958 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
4959 // likely be more epochs to cross and the final message's retransmit may
4960 // be more complex.
4961
David Benjamin585d7a42016-06-02 14:58:00 -04004962 for _, async := range []bool{true, false} {
4963 var tests []testCase
4964
4965 // Test that this is indeed the timeout schedule. Stress all
4966 // four patterns of handshake.
4967 for i := 1; i < len(timeouts); i++ {
4968 number := strconv.Itoa(i)
4969 tests = append(tests, testCase{
4970 protocol: dtls,
4971 name: "DTLS-Retransmit-Client-" + number,
4972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004973 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04004974 Bugs: ProtocolBugs{
4975 TimeoutSchedule: timeouts[:i],
4976 },
4977 },
4978 resumeSession: true,
4979 })
4980 tests = append(tests, testCase{
4981 protocol: dtls,
4982 testType: serverTest,
4983 name: "DTLS-Retransmit-Server-" + number,
4984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04004986 Bugs: ProtocolBugs{
4987 TimeoutSchedule: timeouts[:i],
4988 },
4989 },
4990 resumeSession: true,
4991 })
4992 }
4993
4994 // Test that exceeding the timeout schedule hits a read
4995 // timeout.
4996 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05004997 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04004998 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05004999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005000 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005001 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005002 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005003 },
5004 },
5005 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005006 shouldFail: true,
5007 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005008 })
David Benjamin585d7a42016-06-02 14:58:00 -04005009
5010 if async {
5011 // Test that timeout handling has a fudge factor, due to API
5012 // problems.
5013 tests = append(tests, testCase{
5014 protocol: dtls,
5015 name: "DTLS-Retransmit-Fudge",
5016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005017 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005018 Bugs: ProtocolBugs{
5019 TimeoutSchedule: []time.Duration{
5020 timeouts[0] - 10*time.Millisecond,
5021 },
5022 },
5023 },
5024 resumeSession: true,
5025 })
5026 }
5027
5028 // Test that the final Finished retransmitting isn't
5029 // duplicated if the peer badly fragments everything.
5030 tests = append(tests, testCase{
5031 testType: serverTest,
5032 protocol: dtls,
5033 name: "DTLS-Retransmit-Fragmented",
5034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005035 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005036 Bugs: ProtocolBugs{
5037 TimeoutSchedule: []time.Duration{timeouts[0]},
5038 MaxHandshakeRecordLength: 2,
5039 },
5040 },
5041 })
5042
5043 // Test the timeout schedule when a shorter initial timeout duration is set.
5044 tests = append(tests, testCase{
5045 protocol: dtls,
5046 name: "DTLS-Retransmit-Short-Client",
5047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005048 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005049 Bugs: ProtocolBugs{
5050 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5051 },
5052 },
5053 resumeSession: true,
5054 flags: []string{"-initial-timeout-duration-ms", "250"},
5055 })
5056 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005057 protocol: dtls,
5058 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005059 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005062 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005063 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005064 },
5065 },
5066 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005067 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005068 })
David Benjamin585d7a42016-06-02 14:58:00 -04005069
5070 for _, test := range tests {
5071 if async {
5072 test.name += "-Async"
5073 test.flags = append(test.flags, "-async")
5074 }
5075
5076 testCases = append(testCases, test)
5077 }
David Benjamin83f90402015-01-27 01:09:43 -05005078 }
David Benjamin83f90402015-01-27 01:09:43 -05005079}
5080
David Benjaminc565ebb2015-04-03 04:06:36 -04005081func addExportKeyingMaterialTests() {
5082 for _, vers := range tlsVersions {
5083 if vers.version == VersionSSL30 {
5084 continue
5085 }
5086 testCases = append(testCases, testCase{
5087 name: "ExportKeyingMaterial-" + vers.name,
5088 config: Config{
5089 MaxVersion: vers.version,
5090 },
5091 exportKeyingMaterial: 1024,
5092 exportLabel: "label",
5093 exportContext: "context",
5094 useExportContext: true,
5095 })
5096 testCases = append(testCases, testCase{
5097 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5098 config: Config{
5099 MaxVersion: vers.version,
5100 },
5101 exportKeyingMaterial: 1024,
5102 })
5103 testCases = append(testCases, testCase{
5104 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5105 config: Config{
5106 MaxVersion: vers.version,
5107 },
5108 exportKeyingMaterial: 1024,
5109 useExportContext: true,
5110 })
5111 testCases = append(testCases, testCase{
5112 name: "ExportKeyingMaterial-Small-" + vers.name,
5113 config: Config{
5114 MaxVersion: vers.version,
5115 },
5116 exportKeyingMaterial: 1,
5117 exportLabel: "label",
5118 exportContext: "context",
5119 useExportContext: true,
5120 })
5121 }
5122 testCases = append(testCases, testCase{
5123 name: "ExportKeyingMaterial-SSL3",
5124 config: Config{
5125 MaxVersion: VersionSSL30,
5126 },
5127 exportKeyingMaterial: 1024,
5128 exportLabel: "label",
5129 exportContext: "context",
5130 useExportContext: true,
5131 shouldFail: true,
5132 expectedError: "failed to export keying material",
5133 })
5134}
5135
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005136func addTLSUniqueTests() {
5137 for _, isClient := range []bool{false, true} {
5138 for _, isResumption := range []bool{false, true} {
5139 for _, hasEMS := range []bool{false, true} {
5140 var suffix string
5141 if isResumption {
5142 suffix = "Resume-"
5143 } else {
5144 suffix = "Full-"
5145 }
5146
5147 if hasEMS {
5148 suffix += "EMS-"
5149 } else {
5150 suffix += "NoEMS-"
5151 }
5152
5153 if isClient {
5154 suffix += "Client"
5155 } else {
5156 suffix += "Server"
5157 }
5158
5159 test := testCase{
5160 name: "TLSUnique-" + suffix,
5161 testTLSUnique: true,
5162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005163 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005164 Bugs: ProtocolBugs{
5165 NoExtendedMasterSecret: !hasEMS,
5166 },
5167 },
5168 }
5169
5170 if isResumption {
5171 test.resumeSession = true
5172 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005173 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005174 Bugs: ProtocolBugs{
5175 NoExtendedMasterSecret: !hasEMS,
5176 },
5177 }
5178 }
5179
5180 if isResumption && !hasEMS {
5181 test.shouldFail = true
5182 test.expectedError = "failed to get tls-unique"
5183 }
5184
5185 testCases = append(testCases, test)
5186 }
5187 }
5188 }
5189}
5190
Adam Langley09505632015-07-30 18:10:13 -07005191func addCustomExtensionTests() {
5192 expectedContents := "custom extension"
5193 emptyString := ""
5194
David Benjamin4c3ddf72016-06-29 18:13:53 -04005195 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005196 for _, isClient := range []bool{false, true} {
5197 suffix := "Server"
5198 flag := "-enable-server-custom-extension"
5199 testType := serverTest
5200 if isClient {
5201 suffix = "Client"
5202 flag = "-enable-client-custom-extension"
5203 testType = clientTest
5204 }
5205
5206 testCases = append(testCases, testCase{
5207 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005208 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005210 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005211 Bugs: ProtocolBugs{
5212 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005213 ExpectedCustomExtension: &expectedContents,
5214 },
5215 },
5216 flags: []string{flag},
5217 })
5218
5219 // If the parse callback fails, the handshake should also fail.
5220 testCases = append(testCases, testCase{
5221 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005222 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005224 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005225 Bugs: ProtocolBugs{
5226 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005227 ExpectedCustomExtension: &expectedContents,
5228 },
5229 },
David Benjamin399e7c92015-07-30 23:01:27 -04005230 flags: []string{flag},
5231 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005232 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5233 })
5234
5235 // If the add callback fails, the handshake should also fail.
5236 testCases = append(testCases, testCase{
5237 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005238 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005241 Bugs: ProtocolBugs{
5242 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005243 ExpectedCustomExtension: &expectedContents,
5244 },
5245 },
David Benjamin399e7c92015-07-30 23:01:27 -04005246 flags: []string{flag, "-custom-extension-fail-add"},
5247 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005248 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5249 })
5250
5251 // If the add callback returns zero, no extension should be
5252 // added.
5253 skipCustomExtension := expectedContents
5254 if isClient {
5255 // For the case where the client skips sending the
5256 // custom extension, the server must not “echo” it.
5257 skipCustomExtension = ""
5258 }
5259 testCases = append(testCases, testCase{
5260 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005261 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005263 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005264 Bugs: ProtocolBugs{
5265 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005266 ExpectedCustomExtension: &emptyString,
5267 },
5268 },
5269 flags: []string{flag, "-custom-extension-skip"},
5270 })
5271 }
5272
5273 // The custom extension add callback should not be called if the client
5274 // doesn't send the extension.
5275 testCases = append(testCases, testCase{
5276 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005277 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005279 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005280 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005281 ExpectedCustomExtension: &emptyString,
5282 },
5283 },
5284 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5285 })
Adam Langley2deb9842015-08-07 11:15:37 -07005286
5287 // Test an unknown extension from the server.
5288 testCases = append(testCases, testCase{
5289 testType: clientTest,
5290 name: "UnknownExtension-Client",
5291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005292 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005293 Bugs: ProtocolBugs{
5294 CustomExtension: expectedContents,
5295 },
5296 },
5297 shouldFail: true,
5298 expectedError: ":UNEXPECTED_EXTENSION:",
5299 })
Adam Langley09505632015-07-30 18:10:13 -07005300}
5301
David Benjaminb36a3952015-12-01 18:53:13 -05005302func addRSAClientKeyExchangeTests() {
5303 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5304 testCases = append(testCases, testCase{
5305 testType: serverTest,
5306 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5307 config: Config{
5308 // Ensure the ClientHello version and final
5309 // version are different, to detect if the
5310 // server uses the wrong one.
5311 MaxVersion: VersionTLS11,
5312 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5313 Bugs: ProtocolBugs{
5314 BadRSAClientKeyExchange: bad,
5315 },
5316 },
5317 shouldFail: true,
5318 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5319 })
5320 }
5321}
5322
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005323var testCurves = []struct {
5324 name string
5325 id CurveID
5326}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005327 {"P-256", CurveP256},
5328 {"P-384", CurveP384},
5329 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005330 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005331}
5332
5333func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005334 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005335 for _, curve := range testCurves {
5336 testCases = append(testCases, testCase{
5337 name: "CurveTest-Client-" + curve.name,
5338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005339 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005340 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5341 CurvePreferences: []CurveID{curve.id},
5342 },
5343 flags: []string{"-enable-all-curves"},
5344 })
5345 testCases = append(testCases, testCase{
5346 testType: serverTest,
5347 name: "CurveTest-Server-" + curve.name,
5348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005349 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005350 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5351 CurvePreferences: []CurveID{curve.id},
5352 },
5353 flags: []string{"-enable-all-curves"},
5354 })
5355 }
David Benjamin241ae832016-01-15 03:04:54 -05005356
5357 // The server must be tolerant to bogus curves.
5358 const bogusCurve = 0x1234
5359 testCases = append(testCases, testCase{
5360 testType: serverTest,
5361 name: "UnknownCurve",
5362 config: Config{
5363 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5364 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5365 },
5366 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005367
5368 // The server must not consider ECDHE ciphers when there are no
5369 // supported curves.
5370 testCases = append(testCases, testCase{
5371 testType: serverTest,
5372 name: "NoSupportedCurves",
5373 config: Config{
5374 // TODO(davidben): Add a TLS 1.3 version of this.
5375 MaxVersion: VersionTLS12,
5376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5377 Bugs: ProtocolBugs{
5378 NoSupportedCurves: true,
5379 },
5380 },
5381 shouldFail: true,
5382 expectedError: ":NO_SHARED_CIPHER:",
5383 })
5384
5385 // The server must fall back to another cipher when there are no
5386 // supported curves.
5387 testCases = append(testCases, testCase{
5388 testType: serverTest,
5389 name: "NoCommonCurves",
5390 config: Config{
5391 MaxVersion: VersionTLS12,
5392 CipherSuites: []uint16{
5393 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5394 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5395 },
5396 CurvePreferences: []CurveID{CurveP224},
5397 },
5398 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5399 })
5400
5401 // The client must reject bogus curves and disabled curves.
5402 testCases = append(testCases, testCase{
5403 name: "BadECDHECurve",
5404 config: Config{
5405 // TODO(davidben): Add a TLS 1.3 version of this.
5406 MaxVersion: VersionTLS12,
5407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5408 Bugs: ProtocolBugs{
5409 SendCurve: bogusCurve,
5410 },
5411 },
5412 shouldFail: true,
5413 expectedError: ":WRONG_CURVE:",
5414 })
5415
5416 testCases = append(testCases, testCase{
5417 name: "UnsupportedCurve",
5418 config: Config{
5419 // TODO(davidben): Add a TLS 1.3 version of this.
5420 MaxVersion: VersionTLS12,
5421 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5422 CurvePreferences: []CurveID{CurveP256},
5423 Bugs: ProtocolBugs{
5424 IgnorePeerCurvePreferences: true,
5425 },
5426 },
5427 flags: []string{"-p384-only"},
5428 shouldFail: true,
5429 expectedError: ":WRONG_CURVE:",
5430 })
5431
5432 // Test invalid curve points.
5433 testCases = append(testCases, testCase{
5434 name: "InvalidECDHPoint-Client",
5435 config: Config{
5436 // TODO(davidben): Add a TLS 1.3 version of this test.
5437 MaxVersion: VersionTLS12,
5438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5439 CurvePreferences: []CurveID{CurveP256},
5440 Bugs: ProtocolBugs{
5441 InvalidECDHPoint: true,
5442 },
5443 },
5444 shouldFail: true,
5445 expectedError: ":INVALID_ENCODING:",
5446 })
5447 testCases = append(testCases, testCase{
5448 testType: serverTest,
5449 name: "InvalidECDHPoint-Server",
5450 config: Config{
5451 // TODO(davidben): Add a TLS 1.3 version of this test.
5452 MaxVersion: VersionTLS12,
5453 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5454 CurvePreferences: []CurveID{CurveP256},
5455 Bugs: ProtocolBugs{
5456 InvalidECDHPoint: true,
5457 },
5458 },
5459 shouldFail: true,
5460 expectedError: ":INVALID_ENCODING:",
5461 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005462}
5463
Matt Braithwaite54217e42016-06-13 13:03:47 -07005464func addCECPQ1Tests() {
5465 testCases = append(testCases, testCase{
5466 testType: clientTest,
5467 name: "CECPQ1-Client-BadX25519Part",
5468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005469 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005470 MinVersion: VersionTLS12,
5471 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5472 Bugs: ProtocolBugs{
5473 CECPQ1BadX25519Part: true,
5474 },
5475 },
5476 flags: []string{"-cipher", "kCECPQ1"},
5477 shouldFail: true,
5478 expectedLocalError: "local error: bad record MAC",
5479 })
5480 testCases = append(testCases, testCase{
5481 testType: clientTest,
5482 name: "CECPQ1-Client-BadNewhopePart",
5483 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005484 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005485 MinVersion: VersionTLS12,
5486 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5487 Bugs: ProtocolBugs{
5488 CECPQ1BadNewhopePart: true,
5489 },
5490 },
5491 flags: []string{"-cipher", "kCECPQ1"},
5492 shouldFail: true,
5493 expectedLocalError: "local error: bad record MAC",
5494 })
5495 testCases = append(testCases, testCase{
5496 testType: serverTest,
5497 name: "CECPQ1-Server-BadX25519Part",
5498 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005499 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005500 MinVersion: VersionTLS12,
5501 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5502 Bugs: ProtocolBugs{
5503 CECPQ1BadX25519Part: true,
5504 },
5505 },
5506 flags: []string{"-cipher", "kCECPQ1"},
5507 shouldFail: true,
5508 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5509 })
5510 testCases = append(testCases, testCase{
5511 testType: serverTest,
5512 name: "CECPQ1-Server-BadNewhopePart",
5513 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005514 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005515 MinVersion: VersionTLS12,
5516 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5517 Bugs: ProtocolBugs{
5518 CECPQ1BadNewhopePart: true,
5519 },
5520 },
5521 flags: []string{"-cipher", "kCECPQ1"},
5522 shouldFail: true,
5523 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5524 })
5525}
5526
David Benjamin4cc36ad2015-12-19 14:23:26 -05005527func addKeyExchangeInfoTests() {
5528 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005529 name: "KeyExchangeInfo-DHE-Client",
5530 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005531 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005532 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5533 Bugs: ProtocolBugs{
5534 // This is a 1234-bit prime number, generated
5535 // with:
5536 // openssl gendh 1234 | openssl asn1parse -i
5537 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5538 },
5539 },
David Benjamin9e68f192016-06-30 14:55:33 -04005540 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005541 })
5542 testCases = append(testCases, testCase{
5543 testType: serverTest,
5544 name: "KeyExchangeInfo-DHE-Server",
5545 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005546 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005547 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5548 },
5549 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005550 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005551 })
5552
Nick Harper1fd39d82016-06-14 18:14:35 -07005553 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5554 // handshake is separate.
5555
David Benjamin4cc36ad2015-12-19 14:23:26 -05005556 testCases = append(testCases, testCase{
5557 name: "KeyExchangeInfo-ECDHE-Client",
5558 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005559 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005560 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5561 CurvePreferences: []CurveID{CurveX25519},
5562 },
David Benjamin9e68f192016-06-30 14:55:33 -04005563 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005564 })
5565 testCases = append(testCases, testCase{
5566 testType: serverTest,
5567 name: "KeyExchangeInfo-ECDHE-Server",
5568 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005569 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005570 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5571 CurvePreferences: []CurveID{CurveX25519},
5572 },
David Benjamin9e68f192016-06-30 14:55:33 -04005573 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005574 })
5575}
5576
David Benjaminc9ae27c2016-06-24 22:56:37 -04005577func addTLS13RecordTests() {
5578 testCases = append(testCases, testCase{
5579 name: "TLS13-RecordPadding",
5580 config: Config{
5581 MaxVersion: VersionTLS13,
5582 MinVersion: VersionTLS13,
5583 Bugs: ProtocolBugs{
5584 RecordPadding: 10,
5585 },
5586 },
5587 })
5588
5589 testCases = append(testCases, testCase{
5590 name: "TLS13-EmptyRecords",
5591 config: Config{
5592 MaxVersion: VersionTLS13,
5593 MinVersion: VersionTLS13,
5594 Bugs: ProtocolBugs{
5595 OmitRecordContents: true,
5596 },
5597 },
5598 shouldFail: true,
5599 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5600 })
5601
5602 testCases = append(testCases, testCase{
5603 name: "TLS13-OnlyPadding",
5604 config: Config{
5605 MaxVersion: VersionTLS13,
5606 MinVersion: VersionTLS13,
5607 Bugs: ProtocolBugs{
5608 OmitRecordContents: true,
5609 RecordPadding: 10,
5610 },
5611 },
5612 shouldFail: true,
5613 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5614 })
5615
5616 testCases = append(testCases, testCase{
5617 name: "TLS13-WrongOuterRecord",
5618 config: Config{
5619 MaxVersion: VersionTLS13,
5620 MinVersion: VersionTLS13,
5621 Bugs: ProtocolBugs{
5622 OuterRecordType: recordTypeHandshake,
5623 },
5624 },
5625 shouldFail: true,
5626 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5627 })
5628}
5629
David Benjamin82261be2016-07-07 14:32:50 -07005630func addChangeCipherSpecTests() {
5631 // Test missing ChangeCipherSpecs.
5632 testCases = append(testCases, testCase{
5633 name: "SkipChangeCipherSpec-Client",
5634 config: Config{
5635 MaxVersion: VersionTLS12,
5636 Bugs: ProtocolBugs{
5637 SkipChangeCipherSpec: true,
5638 },
5639 },
5640 shouldFail: true,
5641 expectedError: ":UNEXPECTED_RECORD:",
5642 })
5643 testCases = append(testCases, testCase{
5644 testType: serverTest,
5645 name: "SkipChangeCipherSpec-Server",
5646 config: Config{
5647 MaxVersion: VersionTLS12,
5648 Bugs: ProtocolBugs{
5649 SkipChangeCipherSpec: true,
5650 },
5651 },
5652 shouldFail: true,
5653 expectedError: ":UNEXPECTED_RECORD:",
5654 })
5655 testCases = append(testCases, testCase{
5656 testType: serverTest,
5657 name: "SkipChangeCipherSpec-Server-NPN",
5658 config: Config{
5659 MaxVersion: VersionTLS12,
5660 NextProtos: []string{"bar"},
5661 Bugs: ProtocolBugs{
5662 SkipChangeCipherSpec: true,
5663 },
5664 },
5665 flags: []string{
5666 "-advertise-npn", "\x03foo\x03bar\x03baz",
5667 },
5668 shouldFail: true,
5669 expectedError: ":UNEXPECTED_RECORD:",
5670 })
5671
5672 // Test synchronization between the handshake and ChangeCipherSpec.
5673 // Partial post-CCS handshake messages before ChangeCipherSpec should be
5674 // rejected. Test both with and without handshake packing to handle both
5675 // when the partial post-CCS message is in its own record and when it is
5676 // attached to the pre-CCS message.
5677 //
5678 // TODO(davidben): Fix and test DTLS as well.
5679 for _, packed := range []bool{false, true} {
5680 var suffix string
5681 if packed {
5682 suffix = "-Packed"
5683 }
5684
5685 testCases = append(testCases, testCase{
5686 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
5687 config: Config{
5688 MaxVersion: VersionTLS12,
5689 Bugs: ProtocolBugs{
5690 FragmentAcrossChangeCipherSpec: true,
5691 PackHandshakeFlight: packed,
5692 },
5693 },
5694 shouldFail: true,
5695 expectedError: ":UNEXPECTED_RECORD:",
5696 })
5697 testCases = append(testCases, testCase{
5698 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
5699 config: Config{
5700 MaxVersion: VersionTLS12,
5701 },
5702 resumeSession: true,
5703 resumeConfig: &Config{
5704 MaxVersion: VersionTLS12,
5705 Bugs: ProtocolBugs{
5706 FragmentAcrossChangeCipherSpec: true,
5707 PackHandshakeFlight: packed,
5708 },
5709 },
5710 shouldFail: true,
5711 expectedError: ":UNEXPECTED_RECORD:",
5712 })
5713 testCases = append(testCases, testCase{
5714 testType: serverTest,
5715 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
5716 config: Config{
5717 MaxVersion: VersionTLS12,
5718 Bugs: ProtocolBugs{
5719 FragmentAcrossChangeCipherSpec: true,
5720 PackHandshakeFlight: packed,
5721 },
5722 },
5723 shouldFail: true,
5724 expectedError: ":UNEXPECTED_RECORD:",
5725 })
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
5729 config: Config{
5730 MaxVersion: VersionTLS12,
5731 },
5732 resumeSession: true,
5733 resumeConfig: &Config{
5734 MaxVersion: VersionTLS12,
5735 Bugs: ProtocolBugs{
5736 FragmentAcrossChangeCipherSpec: true,
5737 PackHandshakeFlight: packed,
5738 },
5739 },
5740 shouldFail: true,
5741 expectedError: ":UNEXPECTED_RECORD:",
5742 })
5743 testCases = append(testCases, testCase{
5744 testType: serverTest,
5745 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
5746 config: Config{
5747 MaxVersion: VersionTLS12,
5748 NextProtos: []string{"bar"},
5749 Bugs: ProtocolBugs{
5750 FragmentAcrossChangeCipherSpec: true,
5751 PackHandshakeFlight: packed,
5752 },
5753 },
5754 flags: []string{
5755 "-advertise-npn", "\x03foo\x03bar\x03baz",
5756 },
5757 shouldFail: true,
5758 expectedError: ":UNEXPECTED_RECORD:",
5759 })
5760 }
5761
5762 // Test that early ChangeCipherSpecs are handled correctly.
5763 testCases = append(testCases, testCase{
5764 testType: serverTest,
5765 name: "EarlyChangeCipherSpec-server-1",
5766 config: Config{
5767 MaxVersion: VersionTLS12,
5768 Bugs: ProtocolBugs{
5769 EarlyChangeCipherSpec: 1,
5770 },
5771 },
5772 shouldFail: true,
5773 expectedError: ":UNEXPECTED_RECORD:",
5774 })
5775 testCases = append(testCases, testCase{
5776 testType: serverTest,
5777 name: "EarlyChangeCipherSpec-server-2",
5778 config: Config{
5779 MaxVersion: VersionTLS12,
5780 Bugs: ProtocolBugs{
5781 EarlyChangeCipherSpec: 2,
5782 },
5783 },
5784 shouldFail: true,
5785 expectedError: ":UNEXPECTED_RECORD:",
5786 })
5787 testCases = append(testCases, testCase{
5788 protocol: dtls,
5789 name: "StrayChangeCipherSpec",
5790 config: Config{
5791 // TODO(davidben): Once DTLS 1.3 exists, test
5792 // that stray ChangeCipherSpec messages are
5793 // rejected.
5794 MaxVersion: VersionTLS12,
5795 Bugs: ProtocolBugs{
5796 StrayChangeCipherSpec: true,
5797 },
5798 },
5799 })
5800
5801 // Test that the contents of ChangeCipherSpec are checked.
5802 testCases = append(testCases, testCase{
5803 name: "BadChangeCipherSpec-1",
5804 config: Config{
5805 MaxVersion: VersionTLS12,
5806 Bugs: ProtocolBugs{
5807 BadChangeCipherSpec: []byte{2},
5808 },
5809 },
5810 shouldFail: true,
5811 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5812 })
5813 testCases = append(testCases, testCase{
5814 name: "BadChangeCipherSpec-2",
5815 config: Config{
5816 MaxVersion: VersionTLS12,
5817 Bugs: ProtocolBugs{
5818 BadChangeCipherSpec: []byte{1, 1},
5819 },
5820 },
5821 shouldFail: true,
5822 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5823 })
5824 testCases = append(testCases, testCase{
5825 protocol: dtls,
5826 name: "BadChangeCipherSpec-DTLS-1",
5827 config: Config{
5828 MaxVersion: VersionTLS12,
5829 Bugs: ProtocolBugs{
5830 BadChangeCipherSpec: []byte{2},
5831 },
5832 },
5833 shouldFail: true,
5834 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5835 })
5836 testCases = append(testCases, testCase{
5837 protocol: dtls,
5838 name: "BadChangeCipherSpec-DTLS-2",
5839 config: Config{
5840 MaxVersion: VersionTLS12,
5841 Bugs: ProtocolBugs{
5842 BadChangeCipherSpec: []byte{1, 1},
5843 },
5844 },
5845 shouldFail: true,
5846 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5847 })
5848}
5849
Adam Langley7c803a62015-06-15 15:35:05 -07005850func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005851 defer wg.Done()
5852
5853 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005854 var err error
5855
5856 if *mallocTest < 0 {
5857 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005858 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005859 } else {
5860 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5861 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005862 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005863 if err != nil {
5864 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5865 }
5866 break
5867 }
5868 }
5869 }
Adam Langley95c29f32014-06-20 12:00:00 -07005870 statusChan <- statusMsg{test: test, err: err}
5871 }
5872}
5873
5874type statusMsg struct {
5875 test *testCase
5876 started bool
5877 err error
5878}
5879
David Benjamin5f237bc2015-02-11 17:14:15 -05005880func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005881 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005882
David Benjamin5f237bc2015-02-11 17:14:15 -05005883 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005884 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005885 if !*pipe {
5886 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005887 var erase string
5888 for i := 0; i < lineLen; i++ {
5889 erase += "\b \b"
5890 }
5891 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005892 }
5893
Adam Langley95c29f32014-06-20 12:00:00 -07005894 if msg.started {
5895 started++
5896 } else {
5897 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005898
5899 if msg.err != nil {
5900 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5901 failed++
5902 testOutput.addResult(msg.test.name, "FAIL")
5903 } else {
5904 if *pipe {
5905 // Print each test instead of a status line.
5906 fmt.Printf("PASSED (%s)\n", msg.test.name)
5907 }
5908 testOutput.addResult(msg.test.name, "PASS")
5909 }
Adam Langley95c29f32014-06-20 12:00:00 -07005910 }
5911
David Benjamin5f237bc2015-02-11 17:14:15 -05005912 if !*pipe {
5913 // Print a new status line.
5914 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5915 lineLen = len(line)
5916 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005917 }
Adam Langley95c29f32014-06-20 12:00:00 -07005918 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005919
5920 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005921}
5922
5923func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005924 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005925 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005926
Adam Langley7c803a62015-06-15 15:35:05 -07005927 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005928 addCipherSuiteTests()
5929 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005930 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005931 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005932 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005933 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005934 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005935 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005936 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005937 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005938 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005939 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005940 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07005941 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05005942 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005943 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005944 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005945 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005946 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005947 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07005948 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005949 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04005950 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07005951 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07005952 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005953
5954 var wg sync.WaitGroup
5955
Adam Langley7c803a62015-06-15 15:35:05 -07005956 statusChan := make(chan statusMsg, *numWorkers)
5957 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005958 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005959
David Benjamin025b3d32014-07-01 19:53:04 -04005960 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005961
Adam Langley7c803a62015-06-15 15:35:05 -07005962 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005963 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005964 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005965 }
5966
David Benjamin270f0a72016-03-17 14:41:36 -04005967 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005968 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005969 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005970 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005971 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005972 }
5973 }
David Benjamin270f0a72016-03-17 14:41:36 -04005974 if !foundTest {
5975 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5976 os.Exit(1)
5977 }
Adam Langley95c29f32014-06-20 12:00:00 -07005978
5979 close(testChan)
5980 wg.Wait()
5981 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005982 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005983
5984 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005985
5986 if *jsonOutput != "" {
5987 if err := testOutput.writeTo(*jsonOutput); err != nil {
5988 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5989 }
5990 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005991
5992 if !testOutput.allPassed {
5993 os.Exit(1)
5994 }
Adam Langley95c29f32014-06-20 12:00:00 -07005995}